-
Notifications
You must be signed in to change notification settings - Fork 28
/
calc_finite_difference_via_faces_old
745 lines (626 loc) · 24.2 KB
/
calc_finite_difference_via_faces_old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
void State::calc_finite_difference_via_faces_old(double deltaT){
real_t g = 9.80; // gravitational constant
real_t ghalf = HALF*g;
struct timespec tstart_cpu;
cpu_timer_start(&tstart_cpu);
size_t ncells = mesh->ncells;
size_t &ncells_ghost = mesh->ncells_ghost;
#ifdef _OPENMP
#pragma omp master
#endif
if (ncells_ghost < ncells) ncells_ghost = ncells;
#ifdef HAVE_MPI
// We need to populate the ghost regions since the calc neighbors has just been
// established for the mesh shortly before
if (mesh->numpe > 1) {
apply_boundary_conditions_local();
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
H=(state_t *)state_memory.memory_realloc(ncells_ghost, H);
U=(state_t *)state_memory.memory_realloc(ncells_ghost, U);
V=(state_t *)state_memory.memory_realloc(ncells_ghost, V);
L7_Update(&H[0], L7_STATE_T, mesh->cell_handle);
L7_Update(&U[0], L7_STATE_T, mesh->cell_handle);
L7_Update(&V[0], L7_STATE_T, mesh->cell_handle);
#ifdef _OPENMP
}
#pragma omp barrier
#endif
apply_boundary_conditions_ghost();
} else {
apply_boundary_conditions();
}
#else
apply_boundary_conditions();
#endif
int *nlft, *nrht, *nbot, *ntop, *level;
int flags = (RESTART_DATA | REZONE_DATA | LOAD_BALANCE_MEMORY);
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
mesh->calc_face_list_wbidirmap();
#ifdef _OPENMP
}
#pragma omp barrier
#endif
nlft = mesh->nlft;
nrht = mesh->nrht;
nbot = mesh->nbot;
ntop = mesh->ntop;
level = mesh->level;
vector<real_t> &lev_deltax = mesh->lev_deltax;
vector<real_t> &lev_deltay = mesh->lev_deltay;
static vector<state_t> Hx, Ux, Vx;
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
Hx.resize(mesh->nxface);
Ux.resize(mesh->nxface);
Vx.resize(mesh->nxface);
#ifdef _OPENMP
}
#pragma omp barrier
#endif
#ifdef _OPENMP
#pragma omp for
#endif
for (int iface = 0; iface < mesh->nxface; iface++){
int cell_lower = mesh->map_xface2cell_lower[iface];
int cell_upper = mesh->map_xface2cell_upper[iface];
int level_lower = level[cell_lower];
int level_upper = level[cell_upper];
if (level_lower == level_upper) {
#ifdef PATTERN_CHECK
switch(mesh->xcase[iface]){
case 0:
case 1:
case 81:
case 4:
case 84:
case 5:
case 82:
case 88:
break;
default:
printf("Face case %d at line %d is not handled \n",mesh->xcase[iface],__LINE__);
break;
}
#endif
int lev = level_upper;
real_t Cxhalf = 0.5*deltaT/mesh->lev_deltax[lev];
Hx[iface]=HALF*(H[cell_upper]+H[cell_lower]) - Cxhalf*( HXFLUX(cell_upper)-HXFLUX(cell_lower) );
Ux[iface]=HALF*(U[cell_upper]+U[cell_lower]) - Cxhalf*( UXFLUX(cell_upper)-UXFLUX(cell_lower) );
Vx[iface]=HALF*(V[cell_upper]+V[cell_lower]) - Cxhalf*( UVFLUX(cell_upper)-UVFLUX(cell_lower) );
} else {
#ifdef PATTERN_CHECK
switch(mesh->xcase[iface]){
case 17:
case 18:
case 98:
case 68:
case 72:
case 99:
case 152:
case 156:
break;
default:
printf("Face case %d at line %d is not handled \n",mesh->xcase[iface],__LINE__);
break;
}
#endif
real_t dx_lower = mesh->lev_deltax[level[cell_lower]];
real_t dx_upper = mesh->lev_deltax[level[cell_upper]];
real_t FA_lower = dx_lower;
real_t FA_upper = dx_upper;
real_t FA_lolim = FA_lower*min(ONE, FA_upper/FA_lower);
real_t FA_uplim = FA_upper*min(ONE, FA_lower/FA_upper);
real_t CV_lower = SQ(dx_lower);
real_t CV_upper = SQ(dx_upper);
real_t CV_lolim = CV_lower*min(HALF, CV_upper/CV_lower);
real_t CV_uplim = CV_upper*min(HALF, CV_lower/CV_upper);
// Weighted half-step calculation
//
// (dx_lower*H[cell_upper]+dx_upper*H[cell_lower])
// ----------------------------------------------- -
// (dx_lower+dx_upper)
//
// ( (FA_uplim*HXFLUX(cell_upper))-(FA_lolim*HXFLUX(cell_lower)) )
// 0.5*deltaT * ----------------------------------------------------------------
// (CV_uplim+CV_lolim)
//
Hx[iface]=(dx_lower*H[cell_upper]+dx_upper*H[cell_lower])/(dx_lower+dx_upper) -
HALF*deltaT*( (FA_uplim*HXFLUX(cell_upper))-(FA_lolim*HXFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
Ux[iface]=(dx_lower*U[cell_upper]+dx_upper*U[cell_lower])/(dx_lower+dx_upper) -
HALF*deltaT*( (FA_uplim*UXFLUX(cell_upper))-(FA_lolim*UXFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
Vx[iface]=(dx_lower*V[cell_upper]+dx_upper*V[cell_lower])/(dx_lower+dx_upper) -
HALF*deltaT*( (FA_uplim*UVFLUX(cell_upper))-(FA_lolim*UVFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
}
#if DEBUG >= 2
if (DEBUG >= 2) {
printf("1st pass x direction iface %d i %d j %d lev %d nzlower %d nzupper %d %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
iface, mesh->xface_i[iface], mesh->xface_j[iface], mesh->xface_level[iface],
mesh->map_xface2cell_lower[iface], mesh->map_xface2cell_upper[iface],
Hx[iface],Ux[iface],Vx[iface],
H[cell_upper],H[cell_lower],U[cell_upper],U[cell_lower],V[cell_upper],V[cell_lower]);
}
#endif
}
#if DEBUG >= 2
if (DEBUG >= 2) {
printf("\n");
}
#endif
#ifdef PATTERN_CHECK
free(mesh->xcase);
#endif
static vector<state_t> Hy, Uy, Vy;
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
Hy.resize(mesh->nyface);
Uy.resize(mesh->nyface);
Vy.resize(mesh->nyface);
#ifdef _OPENMP
}
#pragma omp barrier
#endif
#ifdef _OPENMP
#pragma omp for
#endif
for (int iface = 0; iface < mesh->nyface; iface++){
int cell_lower = mesh->map_yface2cell_lower[iface];
int cell_upper = mesh->map_yface2cell_upper[iface];
int level_lower = level[cell_lower];
int level_upper = level[cell_upper];
if (level_lower == level_upper) {
int lev = level_upper;
real_t Cyhalf = 0.5*deltaT/mesh->lev_deltay[lev];
Hy[iface]=HALF*(H[cell_upper]+H[cell_lower]) - Cyhalf*( HYFLUX(cell_upper)-HYFLUX(cell_lower) );
Uy[iface]=HALF*(U[cell_upper]+U[cell_lower]) - Cyhalf*( UVFLUX(cell_upper)-UVFLUX(cell_lower) );
Vy[iface]=HALF*(V[cell_upper]+V[cell_lower]) - Cyhalf*( VYFLUX(cell_upper)-VYFLUX(cell_lower) );
} else {
real_t dy_lower = mesh->lev_deltay[level[cell_lower]];
real_t dy_upper = mesh->lev_deltay[level[cell_upper]];
real_t FA_lower = dy_lower;
real_t FA_upper = dy_upper;
real_t FA_lolim = FA_lower*min(ONE, FA_upper/FA_lower);
real_t FA_uplim = FA_upper*min(ONE, FA_lower/FA_upper);
real_t CV_lower = SQ(dy_lower);
real_t CV_upper = SQ(dy_upper);
real_t CV_lolim = CV_lower*min(HALF, CV_upper/CV_lower);
real_t CV_uplim = CV_upper*min(HALF, CV_lower/CV_upper);
// Weighted half-step calculation
//
// (dy_lower*H[cell_upper]+dy_upper*H[cell_lower])
// ----------------------------------------------- -
// (dy_lower+dy_upper)
//
// ( (FA_uplim*HYFLUX(cell_upper))-(FA_lolim*HYFLUX(cell_lower)) )
// 0.5*deltaT * ----------------------------------------------------------------
// (CV_uplim+CV_lolim)
//
Hy[iface]=(dy_lower*H[cell_upper]+dy_upper*H[cell_lower])/(dy_lower+dy_upper) -
HALF*deltaT*( (FA_uplim*HYFLUX(cell_upper))-(FA_lolim*HYFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
Uy[iface]=(dy_lower*U[cell_upper]+dy_upper*U[cell_lower])/(dy_lower+dy_upper) -
HALF*deltaT*( (FA_uplim*UVFLUX(cell_upper))-(FA_lolim*UVFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
Vy[iface]=(dy_lower*V[cell_upper]+dy_upper*V[cell_lower])/(dy_lower+dy_upper) -
HALF*deltaT*( (FA_uplim*VYFLUX(cell_upper))-(FA_lolim*VYFLUX(cell_lower)) )/
(CV_uplim+CV_lolim);
}
#if DEBUG >= 2
if (DEBUG >= 2) {
printf("1st pass y direction iface %d i %d j %d lev %d nzlower %d nzupper %d %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
iface, mesh->yface_i[iface], mesh->yface_j[iface], mesh->yface_level[iface],
mesh->map_yface2cell_lower[iface], mesh->map_yface2cell_upper[iface],
Hy[iface],Uy[iface],Vy[iface],
H[cell_upper],H[cell_lower],U[cell_upper],U[cell_lower],V[cell_upper],V[cell_lower]);
}
#endif
}
#if DEBUG >= 2
if (DEBUG >= 2) {
printf("\n");
}
#endif
static state_t *H_new, *U_new, *V_new;
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
H_new = (state_t *)state_memory.memory_malloc(mesh->ncells_ghost, sizeof(state_t), "H_new", flags);
U_new = (state_t *)state_memory.memory_malloc(mesh->ncells_ghost, sizeof(state_t), "U_new", flags);
V_new = (state_t *)state_memory.memory_malloc(mesh->ncells_ghost, sizeof(state_t), "V_new", flags);
#ifdef _OPENMP
}
#pragma omp barrier
#endif
int lowerBound, upperBound;
mesh->get_bounds(lowerBound, upperBound);
for (int ic = lowerBound; ic < upperBound; ic++){
int lvl = level[ic];
int nl = nlft[ic];
int nr = nrht[ic];
int nt = ntop[ic];
int nb = nbot[ic];
real_t Hic = H[ic];
real_t Uic = U[ic];
real_t Vic = V[ic];
int nll = nlft[nl];
real_t Hl = H[nl];
real_t Ul = U[nl];
//real_t Vl = V[nl];
int nrr = nrht[nr];
real_t Hr = H[nr];
real_t Ur = U[nr];
//real_t Vr = V[nr];
int ntt = ntop[nt];
real_t Ht = H[nt];
//real_t Ut = U[nt];
real_t Vt = V[nt];
int nbb = nbot[nb];
real_t Hb = H[nb];
//real_t Ub = U[nb];
real_t Vb = V[nb];
int nlt = ntop[nl];
int nrt = ntop[nr];
int ntr = nrht[nt];
int nbr = nrht[nb];
real_t Hll = H[nll];
real_t Ull = U[nll];
//real_t Vll = V[nll];
real_t Hrr = H[nrr];
real_t Urr = U[nrr];
//real_t Vrr = V[nrr];
real_t Htt = H[ntt];
//real_t Utt = U[ntt];
real_t Vtt = V[ntt];
real_t Hbb = H[nbb];
//real_t Ubb = U[nbb];
real_t Vbb = V[nbb];
real_t dxic = lev_deltax[lvl];
//real_t dyic = lev_deltay[lvl];
real_t dxl = lev_deltax[level[nl]];
real_t dxr = lev_deltax[level[nr]];
real_t dyt = lev_deltay[level[nt]];
real_t dyb = lev_deltay[level[nb]];
//real_t drl = dxl;
//real_t drr = dxr;
//real_t drt = dyt;
//real_t drb = dyb;
real_t dric = dxic;
int nltl = 0;
real_t Hlt = 0.0, Ult = 0.0; // Vlt = 0.0;
real_t Hll2 = 0.0;
real_t Ull2 = 0.0;
if(lvl < level[nl]) {
Hlt = H[ ntop[nl] ];
Ult = U[ ntop[nl] ];
//Vlt = V[ ntop[nl] ];
nltl = nlft[nlt];
Hll2 = H[nltl];
Ull2 = U[nltl];
}
int nrtr = 0;
real_t Hrt = 0.0, Urt = 0.0; // Vrt = 0.0;
real_t Hrr2 = 0.0;
real_t Urr2 = 0.0;
if(lvl < level[nr]) {
Hrt = H[ ntop[nr] ];
Urt = U[ ntop[nr] ];
//Vrt = V[ ntop[nr] ];
nrtr = nrht[nrt];
Hrr2 = H[nrtr];
Urr2 = U[nrtr];
}
int nbrb = 0;
real_t Hbr = 0.0, Vbr = 0.0; // Ubr = 0.0
real_t Hbb2 = 0.0;
real_t Vbb2 = 0.0;
if(lvl < level[nb]) {
Hbr = H[ nrht[nb] ];
//Ubr = U[ nrht[nb] ];
Vbr = V[ nrht[nb] ];
nbrb = nbot[nbr];
Hbb2 = H[nbrb];
Vbb2 = V[nbrb];
}
int ntrt = 0;
real_t Htr = 0.0, Vtr = 0.0; // Utr = 0.0
real_t Htt2 = 0.0;
real_t Vtt2 = 0.0;
if(lvl < level[nt]) {
Htr = H[ nrht[nt] ];
//Utr = U[ nrht[nt] ];
Vtr = V[ nrht[nt] ];
ntrt = ntop[ntr];
Htt2 = H[ntrt];
Vtt2 = V[ntrt];
}
////////////////////////////////////////
/// Artificial Viscosity corrections ///
////////////////////////////////////////
real_t Hxminus = H[ic];
real_t Uxminus = 0.0;
real_t Vxminus = 0.0;
if (mesh->map_xcell2face_left1[ic] >= 0){
Hxminus = Hx[mesh->map_xcell2face_left1[ic]];
Uxminus = Ux[mesh->map_xcell2face_left1[ic]];
Vxminus = Vx[mesh->map_xcell2face_left1[ic]];
}
real_t Hxminus2 = 0.0;
if(lvl < level[nl]) Hxminus2 = H[ic];
real_t Uxminus2 = 0.0;
real_t Vxminus2 = 0.0;
if (mesh->map_xcell2face_left2[ic] >= 0) {
Hxminus2 = Hx[mesh->map_xcell2face_left2[ic]];
Uxminus2 = Ux[mesh->map_xcell2face_left2[ic]];
Vxminus2 = Vx[mesh->map_xcell2face_left2[ic]];
}
real_t Hxplus = H[ic];
real_t Uxplus = 0.0;
real_t Vxplus = 0.0;
if (mesh->map_xcell2face_right1[ic] >= 0){
Hxplus = Hx[mesh->map_xcell2face_right1[ic]];
Uxplus = Ux[mesh->map_xcell2face_right1[ic]];
Vxplus = Vx[mesh->map_xcell2face_right1[ic]];
}
real_t Hxplus2 = 0.0;
if(lvl < level[nr]) Hxplus2 = H[ic];
real_t Uxplus2 = 0.0;
real_t Vxplus2 = 0.0;
if (mesh->map_xcell2face_right2[ic] >= 0){
Hxplus2 = Hx[mesh->map_xcell2face_right2[ic]];
Uxplus2 = Ux[mesh->map_xcell2face_right2[ic]];
Vxplus2 = Vx[mesh->map_xcell2face_right2[ic]];
}
if(level[nl] < level[nll]) {
Hll = (Hll + H[ ntop[nll] ]) * HALF;
Ull = (Ull + U[ ntop[nll] ]) * HALF;
}
real_t Hr2 = Hr;
real_t Ur2 = Ur;
if(lvl < level[nr]) {
Hr2 = (Hr2 + Hrt) * HALF;
Ur2 = (Ur2 + Urt) * HALF;
}
real_t wminusx_H = w_corrector(deltaT, (dric+dxl)*HALF, fabs(Uxminus/Hxminus) + sqrt(g*Hxminus),
Hic-Hl, Hl-Hll, Hr2-Hic);
wminusx_H *= Hic - Hl;
if(lvl < level[nl]) {
if(level[nlt] < level[nltl])
Hll2 = (Hll2 + H[ ntop[nltl] ]) * HALF;
wminusx_H = ((w_corrector(deltaT, (dric+dxl)*HALF, fabs(Uxminus2/Hxminus2) +
sqrt(g*Hxminus2), Hic-Hlt, Hlt-Hll2, Hr2-Hic) *
(Hic - Hlt)) + wminusx_H)*HALF*HALF;
}
if(level[nr] < level[nrr]) {
Hrr = (Hrr + H[ ntop[nrr] ]) * HALF;
Urr = (Urr + U[ ntop[nrr] ]) * HALF;
}
real_t Hl2 = Hl;
real_t Ul2 = Ul;
if(lvl < level[nl]) {
Hl2 = (Hl2 + Hlt) * HALF;
Ul2 = (Ul2 + Ult) * HALF;
}
real_t wplusx_H = w_corrector(deltaT, (dric+dxr)*HALF, fabs(Uxplus/Hxplus) + sqrt(g*Hxplus),
Hr-Hic, Hic-Hl2, Hrr-Hr);
wplusx_H *= Hr - Hic;
if(lvl < level[nr]) {
if(level[nrt] < level[nrtr])
Hrr2 = (Hrr2 + H[ ntop[nrtr] ]) * HALF;
wplusx_H = ((w_corrector(deltaT, (dric+dxr)*HALF, fabs(Uxplus2/Hxplus2) +
sqrt(g*Hxplus2), Hrt-Hic, Hic-Hl2, Hrr2-Hrt) *
(Hrt - Hic))+wplusx_H)*HALF*HALF;
}
real_t wminusx_U = w_corrector(deltaT, (dric+dxl)*HALF, fabs(Uxminus/Hxminus) + sqrt(g*Hxminus),
Uic-Ul, Ul-Ull, Ur2-Uic);
wminusx_U *= Uic - Ul;
if(lvl < level[nl]) {
if(level[nlt] < level[nltl])
Ull2 = (Ull2 + U[ ntop[nltl] ]) * HALF;
wminusx_U = ((w_corrector(deltaT, (dric+dxl)*HALF, fabs(Uxminus2/Hxminus2) +
sqrt(g*Hxminus2), Uic-Ult, Ult-Ull2, Ur2-Uic) *
(Uic - Ult))+wminusx_U)*HALF*HALF;
}
real_t wplusx_U = w_corrector(deltaT, (dric+dxr)*HALF, fabs(Uxplus/Hxplus) + sqrt(g*Hxplus),
Ur-Uic, Uic-Ul2, Urr-Ur);
wplusx_U *= Ur - Uic;
if(lvl < level[nr]) {
if(level[nrt] < level[nrtr])
Urr2 = (Urr2 + U[ ntop[nrtr] ]) * HALF;
wplusx_U = ((w_corrector(deltaT, (dric+dxr)*HALF, fabs(Uxplus2/Hxplus2) +
sqrt(g*Hxplus2), Urt-Uic, Uic-Ul2, Urr2-Urt) *
(Urt - Uic))+wplusx_U)*HALF*HALF;
}
if(level[nb] < level[nbb]) {
Hbb = (Hbb + H[ nrht[nbb] ]) * HALF;
Vbb = (Vbb + V[ nrht[nbb] ]) * HALF;
}
real_t Ht2 = Ht;
real_t Vt2 = Vt;
if(lvl < level[nt]) {
Ht2 = (Ht2 + Htr) * HALF;
Vt2 = (Vt2 + Vtr) * HALF;
}
real_t Hyminus = H[ic];
real_t Uyminus = 0.0;
real_t Vyminus = 0.0;
if (mesh->map_ycell2face_bot1[ic] >= 0){
Hyminus = Hy[mesh->map_ycell2face_bot1[ic]];
Uyminus = Uy[mesh->map_ycell2face_bot1[ic]];
Vyminus = Vy[mesh->map_ycell2face_bot1[ic]];
}
real_t Hyminus2 = 0.0;
if(lvl < level[nb]) Hyminus2 = H[ic];
real_t Uyminus2 = 0.0;
real_t Vyminus2 = 0.0;
if (mesh->map_ycell2face_bot2[ic] >= 0){
Hyminus2 = Hy[mesh->map_ycell2face_bot2[ic]];
Uyminus2 = Uy[mesh->map_ycell2face_bot2[ic]];
Vyminus2 = Vy[mesh->map_ycell2face_bot2[ic]];
}
real_t Hyplus = H[ic];
real_t Uyplus = 0.0;
real_t Vyplus = 0.0;
if (mesh->map_ycell2face_top1[ic] >= 0){
Hyplus = Hy[mesh->map_ycell2face_top1[ic]];
Uyplus = Uy[mesh->map_ycell2face_top1[ic]];
Vyplus = Vy[mesh->map_ycell2face_top1[ic]];
}
real_t Hyplus2 = 0.0;
if(lvl < level[nt]) Hyplus2 = H[ic];
real_t Uyplus2 = 0.0;
real_t Vyplus2 = 0.0;
if (mesh->map_ycell2face_top2[ic] >= 0){
Hyplus2 = Hy[mesh->map_ycell2face_top2[ic]];
Uyplus2 = Uy[mesh->map_ycell2face_top2[ic]];
Vyplus2 = Vy[mesh->map_ycell2face_top2[ic]];
}
real_t wminusy_H = w_corrector(deltaT, (dric+dyb)*HALF, fabs(Vyminus/Hyminus) + sqrt(g*Hyminus),
Hic-Hb, Hb-Hbb, Ht2-Hic);
wminusy_H *= Hic - Hb;
if(lvl < level[nb]) {
if(level[nbr] < level[nbrb])
Hbb2 = (Hbb2 + H[ nrht[nbrb] ]) * HALF;
wminusy_H = ((w_corrector(deltaT, (dric+dyb)*HALF, fabs(Vyminus2/Hyminus2) +
sqrt(g*Hyminus2), Hic-Hbr, Hbr-Hbb2, Ht2-Hic) *
(Hic - Hbr))+wminusy_H)*HALF*HALF;
}
if(level[nt] < level[ntt]) {
Htt = (Htt + H[ nrht[ntt] ]) * HALF;
Vtt = (Vtt + V[ nrht[ntt] ]) * HALF;
}
real_t Hb2 = Hb;
real_t Vb2 = Vb;
if(lvl < level[nb]) {
Hb2 = (Hb2 + Hbr) * HALF;
Vb2 = (Vb2 + Vbr) * HALF;
}
real_t wplusy_H = w_corrector(deltaT, (dric+dyt)*HALF, fabs(Vyplus/Hyplus) + sqrt(g*Hyplus),
Ht-Hic, Hic-Hb2, Htt-Ht);
wplusy_H *= Ht - Hic;
if(lvl < level[nt]) {
if(level[ntr] < level[ntrt])
Htt2 = (Htt2 + H[ nrht[ntrt] ]) * HALF;
wplusy_H = ((w_corrector(deltaT, (dric+dyt)*HALF, fabs(Vyplus2/Hyplus2) +
sqrt(g*Hyplus2), Htr-Hic, Hic-Hb2, Htt2-Htr) *
(Htr - Hic))+wplusy_H)*HALF*HALF;
}
real_t wminusy_V = w_corrector(deltaT, (dric+dyb)*HALF, fabs(Vyminus/Hyminus) + sqrt(g*Hyminus),
Vic-Vb, Vb-Vbb, Vt2-Vic);
wminusy_V *= Vic - Vb;
if(lvl < level[nb]) {
if(level[nbr] < level[nbrb])
Vbb2 = (Vbb2 + V[ nrht[nbrb] ]) * HALF;
wminusy_V = ((w_corrector(deltaT, (dric+dyb)*HALF, fabs(Vyminus2/Hyminus2) +
sqrt(g*Hyminus2), Vic-Vbr, Vbr-Vbb2, Vt2-Vic) *
(Vic - Vbr))+wminusy_V)*HALF*HALF;
}
real_t wplusy_V = w_corrector(deltaT, (dric+dyt)*HALF, fabs(Vyplus/Hyplus) + sqrt(g*Hyplus),
Vt-Vic, Vic-Vb2, Vtt-Vt);
wplusy_V *= Vt - Vic;
if(lvl < level[nt]) {
if(level[ntr] < level[ntrt])
Vtt2 = (Vtt2 + V[ nrht[ntrt] ]) * HALF;
wplusy_V = ((w_corrector(deltaT, (dric+dyt)*HALF, fabs(Vyplus2/Hyplus2) +
sqrt(g*Hyplus2), Vtr-Vic, Vic-Vb2, Vtt2-Vtr) *
(Vtr - Vic))+wplusy_V)*HALF*HALF;
}
real_t Hxfluxminus = HNEWXFLUXMINUS;
real_t Uxfluxminus = UNEWXFLUXMINUS;
real_t Vxfluxminus = UVNEWFLUXMINUS;
real_t Hxfluxplus = HNEWXFLUXPLUS;
real_t Uxfluxplus = UNEWXFLUXPLUS;
real_t Vxfluxplus = UVNEWFLUXPLUS;
real_t Hyfluxminus = HNEWYFLUXMINUS;
real_t Uyfluxminus = VUNEWFLUXMINUS;
real_t Vyfluxminus = VNEWYFLUXMINUS;
real_t Hyfluxplus = HNEWYFLUXPLUS;
real_t Uyfluxplus = VUNEWFLUXPLUS;
real_t Vyfluxplus = VNEWYFLUXPLUS;
if(lvl < level[nl]) {
Hxfluxminus = (Hxfluxminus + HNEWXFLUXMINUS2) * HALF;
Uxfluxminus = (Uxfluxminus + UNEWXFLUXMINUS2) * HALF;
Vxfluxminus = (Vxfluxminus + UVNEWFLUXMINUS2) * HALF;
}
if(lvl < level[nr]) {
Hxfluxplus = (Hxfluxplus + HNEWXFLUXPLUS2) * HALF;
Uxfluxplus = (Uxfluxplus + UNEWXFLUXPLUS2) * HALF;
Vxfluxplus = (Vxfluxplus + UVNEWFLUXPLUS2) * HALF;
}
if(lvl < level[nb]) {
Hyfluxminus = (Hyfluxminus + HNEWYFLUXMINUS2) * HALF;
Uyfluxminus = (Uyfluxminus + VUNEWFLUXMINUS2) * HALF;
Vyfluxminus = (Vyfluxminus + VNEWYFLUXMINUS2) * HALF;
}
if(lvl < level[nt]) {
Hyfluxplus = (Hyfluxplus + HNEWYFLUXPLUS2) * HALF;
Uyfluxplus = (Uyfluxplus + VUNEWFLUXPLUS2) * HALF;
Vyfluxplus = (Vyfluxplus + VNEWYFLUXPLUS2) * HALF;
}
//wminusx_H = 0.0; wplusx_H = 0.0; wminusy_H = 0.0; wplusy_H = 0.0;
//wminusx_U = 0.0; wplusx_U = 0.0;
//wminusy_V = 0.0; wplusy_V = 0.0;
H_new[ic] = U_fullstep(deltaT, dxic, Hic,
Hxfluxplus, Hxfluxminus, Hyfluxplus, Hyfluxminus)
- wminusx_H + wplusx_H - wminusy_H + wplusy_H;
U_new[ic] = U_fullstep(deltaT, dxic, Uic,
Uxfluxplus, Uxfluxminus, Uyfluxplus, Uyfluxminus)
- wminusx_U + wplusx_U;
V_new[ic] = U_fullstep(deltaT, dxic, Vic,
Vxfluxplus, Vxfluxminus, Vyfluxplus, Vyfluxminus)
- wminusy_V + wplusy_V;
#if DEBUG >= 1
if (DEBUG >= 1) {
real_t U_tmp = U_new[ic];
real_t V_tmp = V_new[ic];
if (U_tmp == 0.0) U_tmp = 0.0;
if (V_tmp == 0.0) V_tmp = 0.0;
printf("DEBUG ic %d H_new %lf U_new %lf V_new %lf\n",ic,H_new[ic],U_tmp,V_tmp);
}
#endif
/*printf("\nDEBUG ic %d deltaT, %lf dxic, %lf Hic, %lf Hxfluxplus, %lf Hxfluxminus, %lf Hyfluxplus, %lf Hyfluxminus %lf\n",
ic, deltaT, dxic, Hic, Hxfluxplus, Hxfluxminus, Hyfluxplus, Hyfluxminus);
printf("DEBUG ic %d wminusx_H %lf wplusx_H %lf wminusy_H %lf wplusy_H %lf\n",ic, wminusx_H, wplusx_H, wminusy_H, wplusy_H);
printf("DEBUG ic %d deltaT, %lf dxic, %lf Vic, %lf Vxfluxplus, %lf Vxfluxminus, %lf Vyfluxplus, %lf Vyfluxminus %lf\n",
ic, deltaT, dxic, Vic, Vxfluxplus, Vxfluxminus, Vyfluxplus, Vyfluxminus);
printf("DEBUG ic %d wminusy_V %lf wplusy_V %lf\n\n\n",ic, wminusy_V, wplusy_V);*/
//printf("\n%d) %f %f\n", ic, wminusx_H, wplusx_H);
}//end forloop
#ifdef _OPENMP
#pragma omp barrier
#pragma omp master
{
#endif
// Replace H with H_new and deallocate H. New memory will have the characteristics
// of the new memory and the name of the old. Both return and arg1 will be reset to new memory
H = (state_t *)state_memory.memory_replace(H, H_new);
U = (state_t *)state_memory.memory_replace(U, U_new);
V = (state_t *)state_memory.memory_replace(V, V_new);
//state_memory.memory_report();
//printf("DEBUG end finite diff\n\n");
#ifdef _OPENMP
}
#pragma omp barrier
#endif
#ifdef _OPENMP
#pragma omp master
#endif
cpu_timers[STATE_TIMER_FINITE_DIFFERENCE] += cpu_timer_stop(tstart_cpu);
}