1 #include <../../nrnconf.h>
22 int64_t* num_3d_indices_per_grid,
23 int64_t* hybrid_indices1d,
24 int64_t* hybrid_indices3d,
25 int64_t* num_3d_indices_per_1d_seg,
26 int64_t* hybrid_grid_ids,
33 int grid_id_check = 0;
38 int num_grid_3d_indices;
39 int num_grid_1d_indices;
46 if (
id == hybrid_grid_ids[grid_id_check]) {
47 num_grid_1d_indices = num_1d_indices_per_grid[grid_id_check];
48 num_grid_3d_indices = num_3d_indices_per_grid[grid_id_check];
58 grid->
hybrid_data->
rates = (
double*) malloc(
sizeof(
double) * num_grid_3d_indices);
65 for (
i = 0,
k = 0;
i < num_grid_1d_indices;
i++, index_ctr_1d++) {
68 num_3d_indices_per_1d_seg[index_ctr_1d];
71 for (
j = 0;
j < num_3d_indices_per_1d_seg[index_ctr_1d];
j++, index_ctr_3d++,
k++) {
75 ((
ICS_Grid_node*) grid)->_ics_alphas[hybrid_indices3d[index_ctr_3d]] =
76 volumes3d[index_ctr_3d] / dx;
102 c[0] = u_diag[0] /
diag[0];
103 b[0] = b[0] /
diag[0];
105 for (
i = 1;
i < N - 1;
i++) {
106 c[
i] = u_diag[
i] / (
diag[
i] - l_diag[
i - 1] *
c[
i - 1]);
107 b[
i] = (b[
i] - l_diag[
i - 1] * b[
i - 1]) / (
diag[
i] - l_diag[
i - 1] *
c[
i - 1]);
109 b[N - 1] = (b[N - 1] - l_diag[N - 2] * b[N - 2]) / (
diag[N - 1] - l_diag[N - 2] *
c[N - 2]);
113 for (
i = N - 2;
i >= 0;
i--) {
114 b[
i] = b[
i] -
c[
i] * b[
i + 1];
129 long ordered_index = node_start;
130 long current_index = -1;
131 long next_index = -1;
133 double current_state;
136 double current_alpha;
138 for (
int i = start;
i < stop - 1;
i += 2) {
139 long line_start = ordered_nodes[ordered_index];
140 int line_length = line_defs[
i + 1];
141 if (line_length > 1) {
142 current_index = line_start;
144 next_index = ordered_nodes[ordered_index];
145 current_state =
states[current_index];
146 next_state =
states[next_index];
147 current_alpha = alphas[current_index];
148 next_alpha = alphas[next_index];
149 delta[current_index] = dc * next_alpha * current_alpha * (next_state - current_state) /
150 (next_alpha + current_alpha);
152 for (
int j = 1;
j < line_length - 1;
j++) {
153 prev_state = current_state;
154 current_index = next_index;
155 next_index = ordered_nodes[ordered_index];
156 current_state = next_state;
157 next_state =
states[next_index];
158 prev_alpha = current_alpha;
159 current_alpha = next_alpha;
160 next_alpha = alphas[next_index];
161 delta[current_index] =
162 dc * ((next_alpha * current_alpha / (next_alpha + current_alpha)) *
163 (next_state - current_state) -
164 (prev_alpha * current_alpha / (prev_alpha + current_alpha)) *
165 (current_state - prev_state));
169 delta[next_index] = dc * (next_alpha * current_alpha) * (current_state - next_state) /
170 (next_alpha + current_alpha);
173 delta[line_start] = 0.0;
188 long ordered_index = node_start;
189 long current_index = -1;
190 long next_index = -1;
192 double current_state;
195 double current_alpha;
197 for (
int i = start;
i < stop - 1;
i += 2) {
198 long line_start = ordered_nodes[ordered_index];
199 int line_length = line_defs[
i + 1];
200 if (line_length > 1) {
201 current_index = line_start;
203 next_index = ordered_nodes[ordered_index];
204 current_state =
states[current_index];
205 next_state =
states[next_index];
206 current_alpha = alphas[current_index];
207 next_alpha = alphas[next_index];
208 delta[current_index] = dc[next_index] * next_alpha * current_alpha *
209 (next_state - current_state) / (next_alpha + current_alpha);
211 for (
int j = 1;
j < line_length - 1;
j++) {
212 prev_state = current_state;
213 current_index = next_index;
214 next_index = ordered_nodes[ordered_index];
215 current_state = next_state;
216 next_state =
states[next_index];
217 prev_alpha = current_alpha;
218 current_alpha = next_alpha;
219 next_alpha = alphas[next_index];
220 delta[current_index] =
221 dc[next_index] * (next_alpha * current_alpha * (next_state - current_state) /
222 (next_alpha + current_alpha)) -
223 dc[current_index] * (prev_alpha * current_alpha * (current_state - prev_state) /
224 (prev_alpha + current_alpha));
228 delta[next_index] = dc[next_index] * (next_alpha * current_alpha) *
229 (current_state - next_state) / (next_alpha + current_alpha);
232 delta[line_start] = 0.0;
241 int line_start =
data->line_start;
242 int line_stop =
data->line_stop;
243 int node_start =
data->ordered_start;
245 double* deltas = ics_adi_dir->
deltas;
318 long next_index = -1;
319 long prev_index = -1;
327 long ordered_index = node_start;
328 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
329 long N = x_lines[
i + 1];
330 long ordered_index_start = ordered_index;
331 for (
int j = 0;
j < N;
j++) {
332 current_index = ordered_nodes[ordered_index];
333 RHS[
j] = (
dt / alphas[current_index]) *
334 (delta_x[current_index] /
SQ(dx) + 2.0 * delta_y[current_index] /
SQ(dy) +
335 2.0 * delta_z[current_index] /
SQ(dz)) +
336 states[current_index] + states_cur[current_index];
340 ordered_index = ordered_index_start;
341 current_index = ordered_nodes[ordered_index];
343 next_index = ordered_nodes[ordered_index];
344 next = alphas[next_index] * dc[next_index] / (alphas[next_index] + alphas[current_index]);
348 for (
int c = 1;
c < N - 1;
c++) {
349 prev_index = current_index;
350 current_index = next_index;
351 next_index = ordered_nodes[ordered_index];
352 prev = alphas[prev_index] * dc[current_index] /
353 (alphas[prev_index] + alphas[current_index]);
354 next = alphas[next_index] * dc[next_index] /
355 (alphas[next_index] + alphas[current_index]);
361 prev = alphas[current_index] * dc[next_index] /
362 (alphas[current_index] + alphas[next_index]);
364 l_diag[N - 2] = -
dt *
prev /
SQ(dx);
369 ordered_index = ordered_index_start;
370 for (
int k = 0;
k < N;
k++) {
371 current_index = ordered_nodes[ordered_index];
395 long next_index = -1;
396 long prev_index = -1;
402 long ordered_index = node_start;
404 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
405 long N = lines[
i + 1];
406 long ordered_index_start = ordered_index;
408 for (
int j = 0;
j < N;
j++) {
409 current_index = ordered_y_nodes[ordered_index];
411 dt * delta[current_index] / (alphas[current_index] *
SQ(dy));
415 ordered_index = ordered_index_start;
416 current_index = ordered_y_nodes[ordered_index];
418 next_index = ordered_y_nodes[ordered_index];
419 next = alphas[next_index] * dc[next_index] / (alphas[next_index] + alphas[current_index]);
423 for (
int c = 1;
c < N - 1;
c++) {
424 prev_index = current_index;
425 current_index = next_index;
426 next_index = ordered_y_nodes[ordered_index];
427 prev = alphas[prev_index] * dc[prev_index] /
428 (alphas[prev_index] + alphas[current_index]);
429 next = alphas[next_index] * dc[next_index] /
430 (alphas[next_index] + alphas[current_index]);
436 prev = alphas[current_index] * dc[current_index] /
437 (alphas[current_index] + alphas[next_index]);
439 l_diag[N - 2] = -
dt *
prev /
SQ(dy);
443 ordered_index = ordered_index_start;
444 for (
int k = 0;
k < N;
k++) {
445 current_index = ordered_y_nodes[ordered_index];
469 long next_index = -1;
470 long prev_index = -1;
475 long ordered_index = node_start;
476 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
477 long N = lines[
i + 1];
478 long ordered_index_start = ordered_index;
480 for (
int j = 0;
j < N;
j++) {
481 current_index = ordered_z_nodes[ordered_index];
483 dt * delta[current_index] / (
SQ(dz) * alphas[current_index]);
487 ordered_index = ordered_index_start;
488 current_index = ordered_z_nodes[ordered_index];
490 next_index = ordered_z_nodes[ordered_index];
491 next = alphas[next_index] * dc[next_index] / (alphas[next_index] + alphas[current_index]);
495 for (
int c = 1;
c < N - 1;
c++) {
496 prev_index = current_index;
497 current_index = next_index;
498 next_index = ordered_z_nodes[ordered_index];
499 prev = alphas[prev_index] * dc[prev_index] /
500 (alphas[prev_index] + alphas[current_index]);
501 next = alphas[next_index] * dc[next_index] /
502 (alphas[next_index] + alphas[current_index]);
508 prev = alphas[current_index] * dc[current_index] /
509 (alphas[current_index] + alphas[next_index]);
511 l_diag[N - 2] = -
dt *
prev /
SQ(dz);
514 ordered_index = ordered_index_start;
515 for (
int k = 0;
k < N;
k++) {
516 current_index = ordered_z_nodes[ordered_index];
545 long next_index = -1;
546 long prev_index = -1;
554 long ordered_index = node_start;
555 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
556 long N = x_lines[
i + 1];
557 long ordered_index_start = ordered_index;
558 for (
int j = 0;
j < N;
j++) {
559 current_index = ordered_nodes[ordered_index];
560 RHS[
j] = (
dt / alphas[current_index]) *
561 (delta_x[current_index] / (
SQ(dx)) + 2 * delta_y[current_index] /
SQ(dy) +
562 2 * delta_z[current_index] /
SQ(dz)) +
563 states[current_index] + states_cur[current_index];
567 ordered_index = ordered_index_start;
568 current_index = ordered_nodes[ordered_index];
570 next_index = ordered_nodes[ordered_index];
571 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
575 for (
int c = 1;
c < N - 1;
c++) {
576 prev_index = current_index;
577 current_index = next_index;
578 next_index = ordered_nodes[ordered_index];
579 prev = alphas[prev_index] * dc / (alphas[prev_index] + alphas[current_index]);
580 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
586 prev = alphas[current_index] * dc / (alphas[current_index] + alphas[next_index]);
588 l_diag[N - 2] = -
dt *
prev /
SQ(dx);
593 ordered_index = ordered_index_start;
594 for (
int k = 0;
k < N;
k++) {
595 current_index = ordered_nodes[ordered_index];
619 long next_index = -1;
620 long prev_index = -1;
626 long ordered_index = node_start;
628 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
629 long N = lines[
i + 1];
630 long ordered_index_start = ordered_index;
632 for (
int j = 0;
j < N;
j++) {
633 current_index = ordered_y_nodes[ordered_index];
635 dt * delta[current_index] / (alphas[current_index] *
SQ(dy));
639 ordered_index = ordered_index_start;
640 current_index = ordered_y_nodes[ordered_index];
642 next_index = ordered_y_nodes[ordered_index];
643 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
647 for (
int c = 1;
c < N - 1;
c++) {
648 prev_index = current_index;
649 current_index = next_index;
650 next_index = ordered_y_nodes[ordered_index];
651 prev = alphas[prev_index] * dc / (alphas[prev_index] + alphas[current_index]);
652 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
658 prev = alphas[current_index] * dc / (alphas[current_index] + alphas[next_index]);
660 l_diag[N - 2] = -
dt *
prev /
SQ(dy);
664 ordered_index = ordered_index_start;
665 for (
int k = 0;
k < N;
k++) {
666 current_index = ordered_y_nodes[ordered_index];
690 long next_index = -1;
691 long prev_index = -1;
696 long ordered_index = node_start;
697 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
698 long N = lines[
i + 1];
699 long ordered_index_start = ordered_index;
701 for (
int j = 0;
j < N;
j++) {
702 current_index = ordered_z_nodes[ordered_index];
704 dt * delta[current_index] / (
SQ(dz) * alphas[current_index]);
708 ordered_index = ordered_index_start;
709 current_index = ordered_z_nodes[ordered_index];
711 next_index = ordered_z_nodes[ordered_index];
712 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
716 for (
int c = 1;
c < N - 1;
c++) {
717 prev_index = current_index;
718 current_index = next_index;
719 next_index = ordered_z_nodes[ordered_index];
720 prev = alphas[prev_index] * dc / (alphas[prev_index] + alphas[current_index]);
721 next = alphas[next_index] * dc / (alphas[next_index] + alphas[current_index]);
727 prev = alphas[current_index] * dc / (alphas[current_index] + alphas[next_index]);
729 l_diag[N - 2] = -
dt *
prev /
SQ(dz);
732 ordered_index = ordered_index_start;
733 for (
int k = 0;
k < N;
k++) {
734 current_index = ordered_z_nodes[ordered_index];
756 int line_start =
data->line_start;
757 int line_stop =
data->line_stop;
758 int node_start =
data->ordered_start;
760 double r =
dt / (ics_adi_dir->
d * ics_adi_dir->
d);
798 static inline double flux(
const double alphai,
801 const double statej) {
802 return 2.0 * alphai * alphaj * (statei - statej) / ((alphai + alphaj));
811 double const*
const states,
814 long ordered_index = node_start;
815 long current_index = -1;
816 long next_index = -1;
818 double current_state;
821 double current_alpha;
823 for (
int i = start;
i < stop - 1;
i += 2) {
824 long line_start = ordered_nodes[ordered_index];
825 int line_length = line_defs[
i + 1];
826 if (line_length > 1) {
827 current_index = line_start;
829 next_index = ordered_nodes[ordered_index];
830 current_state =
states[current_index];
831 next_state =
states[next_index];
832 current_alpha = alphas[current_index];
833 next_alpha = alphas[next_index];
834 ydot[current_index] += (r / current_alpha) *
835 flux(next_alpha, current_alpha, next_state, current_state);
837 for (
int j = 1;
j < line_length - 1;
j++) {
838 prev_state = current_state;
839 current_index = next_index;
840 next_index = ordered_nodes[ordered_index];
841 current_state = next_state;
842 next_state =
states[next_index];
843 prev_alpha = current_alpha;
844 current_alpha = next_alpha;
845 next_alpha = alphas[next_index];
846 ydot[current_index] += (r / current_alpha) *
847 (
flux(prev_alpha, current_alpha, prev_state, current_state) +
848 flux(next_alpha, current_alpha, next_state, current_state));
851 ydot[next_index] += r *
flux(current_alpha, next_alpha, current_state, next_state) /
866 double const*
const states,
870 long ordered_index = node_start;
871 long current_index = -1;
872 long next_index = -1;
874 double current_state;
877 double current_alpha;
879 double current_dc, next_dc;
880 for (
int i = start;
i < stop - 1;
i += 2) {
881 long line_start = ordered_nodes[ordered_index];
882 int line_length = line_defs[
i + 1];
883 if (line_length > 1) {
884 current_index = line_start;
886 next_index = ordered_nodes[ordered_index];
887 current_state =
states[current_index];
888 next_state =
states[next_index];
889 current_alpha = alphas[current_index];
890 next_alpha = alphas[next_index];
891 current_dc = dcs[current_index];
892 next_dc = dcs[next_index];
893 ydot[current_index] += (r / current_alpha) * next_dc *
894 flux(next_alpha, current_alpha, next_state, current_state);
896 for (
int j = 1;
j < line_length - 1;
j++) {
897 prev_state = current_state;
898 current_index = next_index;
899 next_index = ordered_nodes[ordered_index];
900 current_state = next_state;
901 next_state =
states[next_index];
902 prev_alpha = current_alpha;
903 current_alpha = next_alpha;
904 next_alpha = alphas[next_index];
905 current_dc = next_dc;
906 next_dc = dcs[next_index];
907 ydot[current_index] +=
908 (r / current_alpha) *
909 (current_dc *
flux(prev_alpha, current_alpha, prev_state, current_state) +
910 next_dc *
flux(next_alpha, current_alpha, next_state, current_state));
913 ydot[next_index] += r * next_dc *
914 flux(current_alpha, next_alpha, current_state, next_state) /
923 double rate_x, rate_y, rate_z;
982 rate_x = 1.0 / (dx * dx);
983 rate_y = 1.0 / (dy * dy);
984 rate_z = 1.0 / (dz * dz);
1042 long next_index = -1;
1043 long prev_index = -1;
1051 long ordered_index = node_start;
1052 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1053 long N = x_lines[
i + 1];
1054 long ordered_index_start = ordered_index;
1055 for (
int j = 0;
j < N;
j++) {
1056 current_index = ordered_nodes[ordered_index];
1057 RHS[
j] = CVodeRHS[current_index] -
1059 (delta_x[current_index] /
SQ(dx) + delta_y[current_index] /
SQ(dy) +
1060 delta_z[current_index] /
SQ(dz)) /
1061 alphas[current_index];
1065 ordered_index = ordered_index_start;
1066 current_index = ordered_nodes[ordered_index];
1068 next_index = ordered_nodes[ordered_index];
1069 next = alphas[next_index] * dcs[next_index] / (alphas[next_index] + alphas[current_index]);
1073 for (
int c = 1;
c < N - 1;
c++) {
1074 prev_index = current_index;
1075 current_index = next_index;
1076 next_index = ordered_nodes[ordered_index];
1077 prev = alphas[prev_index] * dcs[current_index] /
1078 (alphas[prev_index] + alphas[current_index]);
1079 next = alphas[next_index] * dcs[next_index] /
1080 (alphas[next_index] + alphas[current_index]);
1086 prev = alphas[current_index] * dcs[current_index] /
1087 (alphas[current_index] + alphas[next_index]);
1089 l_diag[N - 2] = -
dt *
prev /
SQ(dx);
1093 ordered_index = ordered_index_start;
1094 for (
int k = 0;
k < N;
k++) {
1095 current_index = ordered_nodes[ordered_index];
1118 long next_index = -1;
1119 long prev_index = -1;
1126 long ordered_index = node_start;
1128 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1129 long N = lines[
i + 1];
1130 long ordered_index_start = ordered_index;
1132 for (
int j = 0;
j < N;
j++) {
1133 current_index = ordered_y_nodes[ordered_index];
1135 dt * delta[current_index] / (alphas[current_index] *
SQ(dy));
1139 ordered_index = ordered_index_start;
1140 current_index = ordered_y_nodes[ordered_index];
1142 next_index = ordered_y_nodes[ordered_index];
1143 next = alphas[next_index] * dcs[next_index] / (alphas[next_index] + alphas[current_index]);
1147 for (
int c = 1;
c < N - 1;
c++) {
1148 prev_index = current_index;
1149 current_index = next_index;
1150 next_index = ordered_y_nodes[ordered_index];
1151 prev = alphas[prev_index] * dcs[current_index] /
1152 (alphas[prev_index] + alphas[current_index]);
1153 next = alphas[next_index] * dcs[next_index] /
1154 (alphas[next_index] + alphas[current_index]);
1160 prev = alphas[current_index] * dcs[current_index] /
1161 (alphas[current_index] + alphas[next_index]);
1163 l_diag[N - 2] = -
dt *
prev /
SQ(dy);
1167 ordered_index = ordered_index_start;
1168 for (
int k = 0;
k < N;
k++) {
1169 current_index = ordered_y_nodes[ordered_index];
1193 long next_index = -1;
1194 long prev_index = -1;
1200 long ordered_index = node_start;
1201 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1202 long N = lines[
i + 1];
1203 long ordered_index_start = ordered_index;
1205 for (
int j = 0;
j < N;
j++) {
1206 current_index = ordered_z_nodes[ordered_index];
1208 dt * delta[current_index] / (alphas[current_index] *
SQ(dz));
1212 ordered_index = ordered_index_start;
1213 current_index = ordered_z_nodes[ordered_index];
1215 next_index = ordered_z_nodes[ordered_index];
1216 next = alphas[next_index] * dcs[next_index] / (alphas[next_index] + alphas[current_index]);
1220 for (
int c = 1;
c < N - 1;
c++) {
1221 prev_index = current_index;
1222 current_index = next_index;
1223 next_index = ordered_z_nodes[ordered_index];
1224 prev = alphas[prev_index] * dcs[current_index] /
1225 (alphas[prev_index] + alphas[current_index]);
1226 next = alphas[next_index] * dcs[next_index] /
1227 (alphas[next_index] + alphas[current_index]);
1233 prev = alphas[current_index] * dcs[current_index] /
1234 (alphas[current_index] + alphas[next_index]);
1236 l_diag[N - 2] = -
dt *
prev /
SQ(dz);
1239 ordered_index = ordered_index_start;
1240 for (
int k = 0;
k < N;
k++) {
1241 current_index = ordered_z_nodes[ordered_index];
1267 long next_index = -1;
1268 long prev_index = -1;
1276 double r =
dt * dc /
SQ(dx);
1279 long ordered_index = node_start;
1280 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1281 long N = x_lines[
i + 1];
1282 long ordered_index_start = ordered_index;
1283 for (
int j = 0;
j < N;
j++) {
1284 current_index = ordered_nodes[ordered_index];
1285 RHS[
j] = CVodeRHS[current_index] -
1287 (delta_x[current_index] /
SQ(dx) + delta_y[current_index] /
SQ(dy) +
1288 delta_z[current_index] /
SQ(dz)) /
1289 alphas[current_index];
1293 ordered_index = ordered_index_start;
1294 current_index = ordered_nodes[ordered_index];
1296 next_index = ordered_nodes[ordered_index];
1297 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1301 for (
int c = 1;
c < N - 1;
c++) {
1302 prev_index = current_index;
1303 current_index = next_index;
1304 next_index = ordered_nodes[ordered_index];
1305 prev = alphas[prev_index] * r / (alphas[prev_index] + alphas[current_index]);
1306 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1307 l_diag[
c - 1] = -
prev;
1312 prev = alphas[current_index] * r / (alphas[current_index] + alphas[next_index]);
1314 l_diag[N - 2] = -
prev;
1318 ordered_index = ordered_index_start;
1319 for (
int k = 0;
k < N;
k++) {
1320 current_index = ordered_nodes[ordered_index];
1342 long next_index = -1;
1343 long prev_index = -1;
1349 double r =
dt * dc /
SQ(dy);
1353 long ordered_index = node_start;
1355 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1356 long N = lines[
i + 1];
1357 long ordered_index_start = ordered_index;
1359 for (
int j = 0;
j < N;
j++) {
1360 current_index = ordered_y_nodes[ordered_index];
1362 dt * delta[current_index] / (alphas[current_index] *
SQ(dy));
1366 ordered_index = ordered_index_start;
1367 current_index = ordered_y_nodes[ordered_index];
1369 next_index = ordered_y_nodes[ordered_index];
1370 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1374 for (
int c = 1;
c < N - 1;
c++) {
1375 prev_index = current_index;
1376 current_index = next_index;
1377 next_index = ordered_y_nodes[ordered_index];
1378 prev = alphas[prev_index] * r / (alphas[prev_index] + alphas[current_index]);
1379 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1380 l_diag[
c - 1] = -
prev;
1385 prev = alphas[current_index] * r / (alphas[current_index] + alphas[next_index]);
1387 l_diag[N - 2] = -
prev;
1391 ordered_index = ordered_index_start;
1392 for (
int k = 0;
k < N;
k++) {
1393 current_index = ordered_y_nodes[ordered_index];
1416 long next_index = -1;
1417 long prev_index = -1;
1422 double r =
dt * dc /
SQ(dz);
1426 long ordered_index = node_start;
1427 for (
int i = line_start;
i < line_stop - 1;
i += 2) {
1428 long N = lines[
i + 1];
1429 long ordered_index_start = ordered_index;
1431 for (
int j = 0;
j < N;
j++) {
1432 current_index = ordered_z_nodes[ordered_index];
1434 dt * delta[current_index] / (alphas[current_index] *
SQ(dz));
1438 ordered_index = ordered_index_start;
1439 current_index = ordered_z_nodes[ordered_index];
1441 next_index = ordered_z_nodes[ordered_index];
1442 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1446 for (
int c = 1;
c < N - 1;
c++) {
1447 prev_index = current_index;
1448 current_index = next_index;
1449 next_index = ordered_z_nodes[ordered_index];
1450 prev = alphas[prev_index] * r / (alphas[prev_index] + alphas[current_index]);
1451 next = alphas[next_index] * r / (alphas[next_index] + alphas[current_index]);
1452 l_diag[
c - 1] = -
prev;
1457 prev = alphas[current_index] * r / (alphas[current_index] + alphas[next_index]);
1459 l_diag[N - 2] = -
prev;
1462 ordered_index = ordered_index_start;
1463 for (
int k = 0;
k < N;
k++) {
1464 current_index = ordered_z_nodes[ordered_index];
1498 double* CVode_states_copy = (
double*) calloc(
num_states,
sizeof(
double));
1499 memcpy(CVode_states_copy, CVodeRHS,
sizeof(
double) *
num_states);
1624 memcpy(CVodeRHS, CVode_states_copy,
sizeof(
double) *
num_states);
1625 free(CVode_states_copy);
1638 double vol_1d, vol_3d, rate, conc_1d;
1639 int my_3d_index, my_1d_index;
1642 int total_num_3d_indices_per_1d_seg = 0;
1643 for (
int i = 0;
i < num_1d_indices;
i++) {
1644 total_num_3d_indices_per_1d_seg += num_3d_indices_per_1d_seg[
i];
1648 double* old_g_states = (
double*) malloc(
sizeof(
double) * total_num_3d_indices_per_1d_seg);
1651 for (
int i = 0;
i < num_1d_indices;
i++) {
1652 for (
int j = 0;
j < num_3d_indices_per_1d_seg[
i];
j++, vol_3d_index++) {
1653 old_g_states[vol_3d_index] = g->
states[indices3d[vol_3d_index]];
1658 for (
int i = 0;
i < num_1d_indices;
i++) {
1659 vol_1d = volumes1d[
i];
1660 my_1d_index = indices1d[
i];
1661 conc_1d =
states[my_1d_index];
1666 for (
int j = 0;
j < num_3d_indices_per_1d_seg[
i];
j++, vol_3d_index++) {
1667 vol_3d = volumes3d[vol_3d_index];
1669 my_3d_index = indices3d[vol_3d_index];
1670 rate = (rates[vol_3d_index]) * (old_g_states[vol_3d_index] - conc_1d);
1672 g->
states[my_3d_index] -=
dt * rate;
1673 states[my_1d_index] +=
dt * rate * vol_3d / vol_1d;
1683 const double* cvode_states_3d,
1684 double*
const ydot_3d,
1685 const double* cvode_states_1d,
1686 double*
const ydot_1d) {
1695 double vol_1d, vol_3d, rate, conc_1d;
1696 int my_3d_index, my_1d_index;
1697 int vol_3d_index = 0;
1699 for (
int i = 0;
i < num_1d_indices;
i++) {
1700 vol_1d = volumes1d[
i];
1701 my_1d_index = indices1d[
i];
1702 conc_1d = cvode_states_1d[my_1d_index];
1703 for (
int j = 0;
j < num_3d_indices_per_1d_seg[
i];
j++, vol_3d_index++) {
1704 vol_3d = volumes3d[vol_3d_index];
1706 my_3d_index = indices3d[vol_3d_index];
1707 rate = (rates[vol_3d_index]) * (cvode_states_3d[my_3d_index] - conc_1d);
1709 ydot_3d[my_3d_index] -= rate;
1710 ydot_1d[my_1d_index] += rate * vol_3d / vol_1d;
Hybrid_data * hybrid_data
struct ICSAdiDirection * ics_adi_dir_x
void run_threaded_ics_dg_adi(struct ICSAdiDirection *)
struct ICSAdiDirection * ics_adi_dir_y
struct ICSAdiGridData * ics_tasks
struct ICSAdiDirection * ics_adi_dir_z
Grid_node * Parallel_grids[100]
void TaskQueue_add_task(TaskQueue *q, void *(*task)(void *), void *args, void *result)
void TaskQueue_sync(TaskQueue *q)
static void variable_step_delta(long start, long stop, long node_start, double *ydot, long *line_defs, long *ordered_nodes, double const *const states, double r, double *alphas)
static void * do_ics_deltas(void *dataptr)
void ics_dg_adi_x_inhom(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
void _ics_rhs_variable_step_helper(ICS_Grid_node *g, double const *const states, double *ydot)
void run_threaded_deltas(ICS_Grid_node *g, ICSAdiDirection *ics_adi_dir)
void ics_dg_adi_z(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
static void variable_step_z(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double *states, double *RHS, double *scratchpad, double *alphas, double *dcs, double dt)
static void variable_step_y(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double *states, double *RHS, double *scratchpad, double *alphas, double *dcs, double dt)
static int solve_dd_tridiag(int N, const double *l_diag, const double *diag, const double *u_diag, double *b, double *c)
static double flux(const double alphai, const double alphaj, const double statei, const double statej)
void _ics_variable_hybrid_helper(ICS_Grid_node *g, const double *cvode_states_3d, double *const ydot_3d, const double *cvode_states_1d, double *const ydot_1d)
void ics_ode_solve_helper(ICS_Grid_node *g, double dt, double *CVodeRHS)
NRN_EXPORT void set_hybrid_data(int64_t *num_1d_indices_per_grid, int64_t *num_3d_indices_per_grid, int64_t *hybrid_indices1d, int64_t *hybrid_indices3d, int64_t *num_3d_indices_per_1d_seg, int64_t *hybrid_grid_ids, double *rates, double *volumes1d, double *volumes3d, double *dxs)
void ics_find_deltas(long start, long stop, long node_start, double *delta, long *line_defs, long *ordered_nodes, double *states, double dc, double *alphas)
void ics_dg_adi_y(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
static void variable_step_x(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double *states, double *CVodeRHS, double *RHS, double *scratchpad, double *alphas, double *dcs, double dt)
void _ics_hybrid_helper(ICS_Grid_node *g)
void ics_dg_adi_x(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
void * do_ics_dg_adi(void *dataptr)
void ics_dg_adi_z_inhom(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
void ics_dg_adi_y_inhom(ICS_Grid_node *g, int line_start, int line_stop, int node_start, double, double *states, double *RHS, double *scratchpad, double *u_diag, double *diag, double *l_diag)
long * num_3d_indices_per_1d_seg
long * ordered_start_stop_indices
void(* ics_dg_adi_dir)(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
long * line_start_stop_indices
ICSAdiDirection * ics_adi_dir