proteus 1.9.1
C/C++/Fortran libraries
Loading...
Searching...
No Matches
GN_SW2DCV.h
Go to the documentation of this file.
1#ifndef GN_SW2DCV_H
2#define GN_SW2DCV_H
3#include "ArgumentsDict.h"
4#include "CompKernel.h"
5#include "ModelFactory.h"
6#include "xtensor-python/pyarray.hpp"
7#include <assert.h>
8#include <cmath>
9#include <iostream>
10#include <valarray>
11
12namespace py = pybind11;
13
14#define VEL_FIX_POWER 2.
15#define LAMBDA_MGN 1.
16#define IF_BOTH_GAMMA_BRANCHES 0
17#define LIMITING_ITERATION 2
18#define IF_DEBUGGING 0
19#define IF_LIMITING_DEBUGGING 0
20
21/* inline functions */
22namespace proteus {
23
24// for Serre-Green-Naghdi "max" wave speeds
25inline double GN_nu1(const double &g, const double &hL, const double &uL,
26 const double &etaL, const double &inv_meshSizeL) {
27
28 double augL = LAMBDA_MGN / 3. * inv_meshSizeL * (6. * hL + 12. * (hL - etaL));
29 const double meshSizeL = 1. / inv_meshSizeL;
30
31 if (etaL >= hL) {
32 augL = LAMBDA_MGN / 3. * inv_meshSizeL * (6. * hL);
33 }
34 augL = augL * std::pow(meshSizeL / fmax(meshSizeL, hL), 2);
35
36 return uL - sqrt(g * hL) * sqrt(1. + augL);
37}
38inline double GN_nu3(const double &g, const double &hR, const double &uR,
39 const double &etaR, const double &inv_meshSizeR) {
40 double augR = LAMBDA_MGN / 3. * inv_meshSizeR * (6. * hR + 12. * (hR - etaR));
41 const double meshSizeR = 1. / inv_meshSizeR;
42
43 if (etaR >= hR) {
44 augR = LAMBDA_MGN / 3. * inv_meshSizeR * (6. * hR);
45 }
46 augR = augR * std::pow(meshSizeR / fmax(meshSizeR, hR), 2);
47 return uR + sqrt(g * hR) * sqrt(1 + augR);
48}
49// FOR CELL BASED ENTROPY VISCOSITY
50inline double ENTROPY(const double &g, const double &h, const double &hu,
51 const double &hv, const double &z,
52 const double &one_over_hReg) {
53 return 0.5 *
54 (g * h * h + one_over_hReg * (hu * hu + hv * hv) + 2. * g * h * z);
55}
56inline double DENTROPY_DH(const double &g, const double &h, const double &hu,
57 const double &hv, const double &z,
58 const double &one_over_hReg) {
59 return g * h - 0.5 * (hu * hu + hv * hv) * std::pow(one_over_hReg, 2) + g * z;
60}
61inline double DENTROPY_DHU(const double &g, const double &h, const double &hu,
62 const double &hv, const double &z,
63 const double &one_over_hReg) {
64 return hu * one_over_hReg;
65}
66inline double DENTROPY_DHV(const double &g, const double &h, const double &hu,
67 const double &hv, const double &z,
68 const double &one_over_hReg) {
69 return hv * one_over_hReg;
70}
71inline double ENTROPY_FLUX1(const double &g, const double &h, const double &hu,
72 const double &hv, const double &z,
73 const double &one_over_hReg) {
74 return (ENTROPY(g, h, hu, hv, z, one_over_hReg) + 0.5 * g * h * h +
75 g * h * z) *
76 hu * one_over_hReg;
77}
78inline double ENTROPY_FLUX2(const double &g, const double &h, const double &hu,
79 const double &hv, const double &z,
80 const double &one_over_hReg) {
81 return (ENTROPY(g, h, hu, hv, z, one_over_hReg) + 0.5 * g * h * h +
82 g * h * z) *
83 hv * one_over_hReg;
84}
85inline double relaxation(const double &xi, const double &alpha) {
86 double function = 0.;
87 if (xi < 1.) {
88 const double den = 1.0 - alpha;
89 const double num = std::exp(-std::abs(std::log(alpha)) * xi * xi) - alpha;
90 function = num / den;
91 }
92 return function;
93}
94} // namespace proteus
95
96namespace proteus {
97
99public:
100 virtual ~GN_SW2DCV_base() {}
101 virtual void convexLimiting(arguments_dict &args) = 0;
102 virtual double calculateEdgeBasedCFL(arguments_dict &args) = 0;
103 virtual void calculatePreStep(arguments_dict &args) = 0;
104 virtual void calculateEV(arguments_dict &args) = 0;
106 virtual void calculateResidual(arguments_dict &args) = 0;
107 virtual void calculateMassMatrix(arguments_dict &args) = 0;
109};
110
111template <class CompKernelType, int nSpace, int nQuadraturePoints_element,
112 int nDOF_mesh_trial_element, int nDOF_trial_element,
113 int nDOF_test_element, int nQuadraturePoints_elementBoundary>
114class GN_SW2DCV : public GN_SW2DCV_base {
115public:
117 CompKernelType ck;
119 : nDOF_test_X_trial_element(nDOF_test_element * nDOF_trial_element),
120 ck() {
121 std::cout << "Constructing GN_SW2DCV<CompKernelTemplate<" << nSpace << ","
122 << nQuadraturePoints_element << "," << nDOF_mesh_trial_element
123 << "," << nDOF_trial_element << "," << nDOF_test_element << ","
124 << nQuadraturePoints_elementBoundary << ">());" << std::endl
125 << std::flush;
126 }
127
129 const double g, const double nx, const double ny, const double hL,
130 const double huL, double hvL, const double hetaL, const double inv_MeshL,
131 const double hR, const double huR, const double hvR, const double hetaR,
132 const double inv_MeshR, const double hEps) {
133 const double one_over_hL =
134 2.0 * hL / (hL * hL + std::pow(fmax(hL, hEps), 2.0));
135 const double one_over_hR =
136 2.0 * hR / (hR * hR + std::pow(fmax(hR, hEps), 2.0));
137 const double hVelL = nx * huL + ny * hvL;
138 const double hVelR = nx * huR + ny * hvR;
139 const double velL = one_over_hL * hVelL;
140 const double velR = one_over_hR * hVelR;
141 const double etaL = one_over_hL * hetaL;
142 const double etaR = one_over_hR * hetaR;
143
144 /* See equation 4.12 JCP 2019 paper:
145 1-eigenvalue: uL-sqrt(g*hL)*sqrt(1 + augL)
146 3-eigenvalue: uR+sqrt(g*hR)*sqrt(1 + augR)
147 */
148 const double lambda1 = GN_nu1(g, hL, velL, etaL, inv_MeshL);
149 const double lambda3 = GN_nu3(g, hR, velR, etaR, inv_MeshR);
150
151 return fmax(fabs(lambda1), fabs(lambda3));
152 }
153
154 inline void calculateCFL(const double &elementDiameter, const double &g,
155 const double &h, const double &hu, const double &hv,
156 const double hEps, double &cfl) {
157 double cflx, cfly, c = sqrt(fmax(g * hEps, g * h));
158 const double u = 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hu;
159 const double v = 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hv;
160
161 if (u > 0.0)
162 cflx = (u + c) / elementDiameter;
163 else
164 cflx = fabs(u - c) / elementDiameter;
165
166 if (v > 0.0)
167 cfly = (v + c) / elementDiameter;
168 else
169 cfly = fabs(v - c) / elementDiameter;
170 cfl = sqrt(cflx * cflx + cfly * cfly); // hack, conservative estimate
171 }
172
174 const int numDOFs = args.scalar<int>("numDOFs");
175 const xt::pyarray<int> &csrRowIndeces_DofLoops =
176 args.array<int>("csrRowIndeces_DofLoops");
177 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
178 args.array<int>("csrColumnOffsets_DofLoops");
179 const xt::pyarray<double> &MassMatrix = args.array<double>("MassMatrix");
180 const xt::pyarray<double> &lumped_mass_matrix =
181 args.array<double>("lumped_mass_matrix");
182 const double dt = args.scalar<double>("dt");
183 const xt::pyarray<double> &h_old = args.array<double>("h_old");
184 const xt::pyarray<double> &hu_old = args.array<double>("hu_old");
185 const xt::pyarray<double> &hv_old = args.array<double>("hv_old");
186 const xt::pyarray<double> &heta_old = args.array<double>("heta_old");
187 const xt::pyarray<double> &hw_old = args.array<double>("hw_old");
188 const xt::pyarray<double> &hbeta_old = args.array<double>("hbeta_old");
189 const xt::pyarray<double> &b_dof = args.array<double>("b_dof");
190 xt::pyarray<double> &limited_hnp1 = args.array<double>("limited_hnp1");
191 xt::pyarray<double> &limited_hunp1 = args.array<double>("limited_hunp1");
192 xt::pyarray<double> &limited_hvnp1 = args.array<double>("limited_hvnp1");
193 xt::pyarray<double> &limited_hetanp1 =
194 args.array<double>("limited_hetanp1");
195 xt::pyarray<double> &limited_hwnp1 = args.array<double>("limited_hwnp1");
196 xt::pyarray<double> &limited_hbetanp1 =
197 args.array<double>("limited_hbetanp1");
198 const double hEps = args.scalar<double>("hEps");
199 xt::pyarray<double> &hLow = args.array<double>("hLow");
200 xt::pyarray<double> &huLow = args.array<double>("huLow");
201 xt::pyarray<double> &hvLow = args.array<double>("hvLow");
202 xt::pyarray<double> &hetaLow = args.array<double>("hetaLow");
203 xt::pyarray<double> &hwLow = args.array<double>("hwLow");
204 xt::pyarray<double> &hbetaLow = args.array<double>("hbetaLow");
205 const xt::pyarray<double> &h_min = args.array<double>("h_min");
206 const xt::pyarray<double> &h_max = args.array<double>("h_max");
207 const xt::pyarray<double> &heta_min = args.array<double>("heta_min");
208 const xt::pyarray<double> &heta_max = args.array<double>("heta_max");
209 const xt::pyarray<double> &kin_max = args.array<double>("kin_max");
210 const double KE_tiny = args.scalar<double>("KE_tiny");
211 const xt::pyarray<double> &SourceTerm_h =
212 args.array<double>("SourceTerm_h");
213 const xt::pyarray<double> &SourceTerm_hu =
214 args.array<double>("SourceTerm_hu");
215 const xt::pyarray<double> &SourceTerm_hv =
216 args.array<double>("SourceTerm_hv");
217 const xt::pyarray<double> &SourceTerm_heta =
218 args.array<double>("SourceTerm_heta");
219 const xt::pyarray<double> &SourceTerm_hw =
220 args.array<double>("SourceTerm_hw");
221 const xt::pyarray<double> &SourceTerm_hbeta =
222 args.array<double>("SourceTerm_hbeta");
223 const xt::pyarray<double> &global_entropy_residual =
224 args.array<double>("global_entropy_residual");
225 const xt::pyarray<double> &Cx = args.array<double>("Cx");
226 const xt::pyarray<double> &Cy = args.array<double>("Cy");
227 const xt::pyarray<double> &CTx = args.array<double>("CTx");
228 const xt::pyarray<double> &CTy = args.array<double>("CTy");
229 const xt::pyarray<double> &RHS_high_h = args.array<double>("RHS_high_h");
230 const xt::pyarray<double> &RHS_high_hu = args.array<double>("RHS_high_hu");
231 const xt::pyarray<double> &RHS_high_hv = args.array<double>("RHS_high_hv");
232 const xt::pyarray<double> &RHS_high_heta =
233 args.array<double>("RHS_high_heta");
234 const xt::pyarray<double> &RHS_high_hw = args.array<double>("RHS_high_hw");
235 const xt::pyarray<double> &RHS_high_hbeta =
236 args.array<double>("RHS_high_hbeta");
237 const xt::pyarray<double> &extendedSourceTerm_hu =
238 args.array<double>("extendedSourceTerm_hu");
239 const xt::pyarray<double> &extendedSourceTerm_hv =
240 args.array<double>("extendedSourceTerm_hv");
241 const xt::pyarray<double> &thetaj_inv = args.array<double>("thetaj_inv");
242 const xt::pyarray<double> &wall_dof = args.array<double>("wall_dof");
243 const xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
244 const double g = args.scalar<double>("g");
245 const xt::pyarray<double> &inverse_mesh =
246 args.array<double>("inverse_mesh");
247
248 // Create FCT component matrices in vector form
249 std::valarray<double> FCT_h(0., Cx.size()), FCT_hu(0., Cx.size()),
250 FCT_hv(0., Cx.size()), FCT_heta(0., Cx.size()), FCT_hw(0., Cx.size()),
251 FCT_hbeta(0., Cx.size());
252
253 // One limiting pass per call. Between passes the caller exchanges the
254 // low-order states with the ghost DOFs: pass 2 reads hLow[j] etc. at
255 // neighbours, and a ghost row's own pass-1 update uses an incomplete
256 // stencil. The FCT matrices persist in FCT_all (6 x nnz) across calls.
257 const int limit_iter_arg = args.scalar<int>("limit_iter");
258 const int n_limit_iter = args.scalar<int>("n_limit_iter");
259 xt::pyarray<double> &FCT_all = args.array<double>("FCT_all");
260 const std::size_t nnz_fct = Cx.size();
261
263 // Loop to define FCT matrices for each component //
265 int ij = 0;
266 for (int i = 0; i < numDOFs && limit_iter_arg == 0; i++) {
267 // Read un at ith node
268 const double hi = h_old[i];
269 const double one_over_hi =
270 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2)); // hEps
271 const double hui = hu_old[i];
272 const double ui = hui * one_over_hi;
273 const double hvi = hv_old[i];
274 const double vi = hvi * one_over_hi;
275 const double hetai = heta_old[i];
276 const double hwi = hw_old[i];
277 const double hbetai = hbeta_old[i];
278 const double Zi = b_dof[i];
279 const double mi = lumped_mass_matrix[i];
280 const double inv_meshSizei = inverse_mesh[i];
281
282 // LOOP OVER THE SPARSITY PATTERN (j-LOOP)//
283 for (int offset = csrRowIndeces_DofLoops[i];
284 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
285 int j = csrColumnOffsets_DofLoops[offset];
286
287 if (j == i) {
288 FCT_h[ij] = 0.;
289 FCT_hu[ij] = 0.;
290 FCT_hv[ij] = 0.;
291 FCT_heta[ij] = 0.;
292 FCT_hw[ij] = 0.;
293 FCT_hbeta[ij] = 0.;
294 } else {
295 // Read un stuff at jth node
296 const double hj = h_old[j];
297 const double one_over_hj =
298 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
299 const double huj = hu_old[j];
300 const double uj = huj * one_over_hj;
301 const double hvj = hv_old[j];
302 const double vj = hvj * one_over_hj;
303 const double hetaj = heta_old[j];
304 const double hwj = hw_old[j];
305 const double hbetaj = hbeta_old[j];
306 const double Zj = b_dof[j];
307 const double mj = lumped_mass_matrix[j];
308 const double inv_meshSizej = inverse_mesh[j];
309
310 // Compute star states
311 const double hStarij = fmax(0., hi + Zi - fmax(Zi, Zj));
312 const double hStarji = fmax(0., hj + Zj - fmax(Zi, Zj));
313 //
314 const double hStar_ratio_i = hStarij * one_over_hi;
315 const double hStar_ratio_j = hStarji * one_over_hj;
316 //
317 const double huStarij = hui * hStar_ratio_i;
318 const double hvStarij = hvi * hStar_ratio_i;
319 const double hetaStarij = hetai * std::pow(hStar_ratio_i, 2);
320 const double hwStarij = hwi * hStar_ratio_i;
321 const double hbetaStarij = hbetai * hStar_ratio_i;
322 //
323 const double huStarji = huj * hStar_ratio_j;
324 const double hvStarji = hvj * hStar_ratio_j;
325 const double hetaStarji = hetaj * std::pow(hStar_ratio_j, 2);
326 const double hwStarji = hwj * hStar_ratio_j;
327 const double hbetaStarji = hbetaj * hStar_ratio_j;
328
329 const double b_ij = 0. - MassMatrix[ij] / mj;
330 const double b_ji = 0. - MassMatrix[ij] / mi;
331
332 /* Redefine high-order viscosity. Note that this is not so expensive
333 since we are just accessing and multipying. */
334 const double cij_norm = sqrt(Cx[ij] * Cx[ij] + Cy[ij] * Cy[ij]);
335 const double cji_norm = sqrt(CTx[ij] * CTx[ij] + CTy[ij] * CTy[ij]);
336 const double nxij = Cx[ij] / cij_norm;
337 const double nyij = Cy[ij] / cij_norm;
338 const double nxji = CTx[ij] / cji_norm;
339 const double nyji = CTy[ij] / cji_norm;
340
341 double cxa, cya, cxaT, cyaT;
342 wallCoefficients(i, j, ij, wall_dof, Cx, Cy, CTx, CTy, cxa, cya,
343 cxaT, cyaT);
344 const double phibar_ij = phiBar(i, j, porosity_dof);
345 const double muijL = phibar_ij * fmax(std::abs(ui * cxa + vi * cya),
346 std::abs(uj * cxaT + vj * cyaT));
347 double dijL = phibar_ij * fmax(
348 maxWaveSpeedSharpInitialGuess(g, nxij, nyij, hi, hui, hvi, hetai,
349 inv_meshSizei, hj, huj, hvj, hetaj,
350 inv_meshSizej, hEps) *
351 cij_norm,
352 maxWaveSpeedSharpInitialGuess(g, nxji, nyji, hj, huj, hvj, hetaj,
353 inv_meshSizej, hi, hui, hvi, hetai,
354 inv_meshSizei, hEps) *
355 cji_norm);
356
357 // Take max with muij
358 dijL = std::max(dijL, muijL);
359
360 // Define high-order graph viscosity coefficients
361 const double dEVij =
362 phibar_ij *
363 std::max(global_entropy_residual[i], global_entropy_residual[j]);
364
365 const double dijH = std::min(dijL, dEVij);
366 const double muijH = std::min(muijL, dEVij);
367
368 const double diff_dij_muij = (dijH - dijL) - (muijH - muijL);
369 const double diff_muij = (muijH - muijL);
370
371 // h
372 double viscous_terms =
373 diff_dij_muij * (hStarji - hStarij) + diff_muij * (hj - hi);
374 FCT_h[ij] = dt * (b_ij * RHS_high_h[j] - b_ji * RHS_high_h[i] +
375 viscous_terms);
376 // hu
377 viscous_terms =
378 diff_dij_muij * (huStarji - huStarij) + diff_muij * (huj - hui);
379 FCT_hu[ij] = dt * (b_ij * RHS_high_hu[j] - b_ji * RHS_high_hu[i] +
380 viscous_terms);
381 // hv
382 viscous_terms =
383 diff_dij_muij * (hvStarji - hvStarij) + diff_muij * (hvj - hvi);
384 FCT_hv[ij] = dt * (b_ij * RHS_high_hv[j] - b_ji * RHS_high_hv[i] +
385 viscous_terms);
386 // heta
387 viscous_terms = diff_dij_muij * (hetaStarji - hetaStarij) +
388 diff_muij * (hetaj - hetai);
389 FCT_heta[ij] = dt * (b_ij * RHS_high_heta[j] -
390 b_ji * RHS_high_heta[i] + viscous_terms);
391 // hw
392 viscous_terms =
393 diff_dij_muij * (hwStarji - hwStarij) + diff_muij * (hwj - hwi);
394 FCT_hw[ij] = dt * (b_ij * RHS_high_hw[j] - b_ji * RHS_high_hw[i] +
395 viscous_terms);
396 // hbeta
397 viscous_terms = diff_dij_muij * (hbetaStarji - hbetaStarij) +
398 diff_muij * (hbetaj - hbetai);
399 FCT_hbeta[ij] = dt * (b_ij * RHS_high_hbeta[j] -
400 b_ji * RHS_high_hbeta[i] + viscous_terms);
401 }
402
403 // UPDATE ij //
404 ij += 1;
405 } // j loop ends here
406 } // i loop ends here
407
409 // Main loop to define limiters and compute limited solution //////
411
412 if (limit_iter_arg > 0) {
413 for (std::size_t k = 0; k < nnz_fct; k++) {
414 FCT_h[k] = FCT_all[0 * nnz_fct + k];
415 FCT_hu[k] = FCT_all[1 * nnz_fct + k];
416 FCT_hv[k] = FCT_all[2 * nnz_fct + k];
417 FCT_heta[k] = FCT_all[3 * nnz_fct + k];
418 FCT_hw[k] = FCT_all[4 * nnz_fct + k];
419 FCT_hbeta[k] = FCT_all[5 * nnz_fct + k];
420 }
421 }
422
423 // Create Lij_array and initialize with 1
424 std::valarray<double> Lij_array(1., Cx.size());
425
426 // define tolerance for limiting
427 const double eps = 1e-14;
428
429 /* Loop over # of limiting iterations */
430 for (int limit_iter = limit_iter_arg; limit_iter < limit_iter_arg + 1;
431 limit_iter++) {
432
433 /* Loop to compute limiter l^j_i and l^i_j */
434 ij = 0;
435 for (int i = 0; i < numDOFs; i++) {
436
437 // Get low order solution at ith node
438 const double hLowi = hLow[i];
439 const double huLowi = huLow[i];
440 const double hvLowi = hvLow[i];
441 const double hetaLowi = hetaLow[i];
442 const double kinMaxi = kin_max[i];
443 const double mi = lumped_mass_matrix[i];
444
445 // LOOP OVER THE SPARSITY PATTERN (j-LOOP)
446 for (int offset = csrRowIndeces_DofLoops[i];
447 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
448 int j = csrColumnOffsets_DofLoops[offset];
449
450 Lij_array[ij] = 1.;
451
452 // Get low order solution at jth node
453 const double hLowj = hLow[j];
454 const double huLowj = huLow[j];
455 const double hvLowj = hvLow[j];
456 const double hetaLowj = hetaLow[j];
457 const double kinMaxj = kin_max[j];
458 const double mj = lumped_mass_matrix[j];
459
460 // Compute Pij matrix and Pji
461 double denom = 1. / (mi * thetaj_inv[i]);
462 const double P_h = FCT_h[ij] * denom;
463 const double P_hu = FCT_hu[ij] * denom;
464 const double P_hv = FCT_hv[ij] * denom;
465 const double P_heta = FCT_heta[ij] * denom;
466
467 denom = 1. / (mj * thetaj_inv[j]);
468 const double P_h_tr = -FCT_h[ij] * denom;
469 const double P_hu_tr = -FCT_hu[ij] * denom;
470 const double P_hv_tr = -FCT_hv[ij] * denom;
471 const double P_heta_tr = -FCT_heta[ij] * denom;
472
473 /* h limiting -- to defne l_ji_h */
474 double l_ji_h = Lij_array[ij];
475 {
476 const double denominator = 1. / (std::abs(P_h) + eps * h_max[i]);
477
478 // Define limiter here
479 if (hLowi + P_h < h_min[i]) {
480 l_ji_h = std::min((std::abs(h_min[i] - hLowi) + eps * h_min[i]) *
481 denominator,
482 1.);
483 } else if (h_max[i] < hLowi + P_h) {
484 l_ji_h = std::min((std::abs(h_max[i] - hLowi) + eps * h_min[i]) *
485 denominator,
486 1.);
487 }
488
489 // Set limiter to 0 if water depth is close to 0
490 l_ji_h = (hLowi <= hEps) ? 0. : l_ji_h;
491
492 /* Box limiter to be safe? */
493 l_ji_h = std::min(l_ji_h, 1.);
494 l_ji_h = std::max(l_ji_h, 0.);
495
496#if IF_LIMITING_DEBUGGING
497 if ((hLowi + l_ji_h * P_h) - h_min[i] < -1e-12) {
498 std::cout << " MAJOR BUG 1a " << std::setprecision(15) << " \n "
499 << " Diff = " << (hLowi + l_ji_h * P_h) - h_min[i]
500 << " \n "
501 << " hLowi = " << hLowi << " \n "
502 << " h_min = " << h_min[i] << " \n "
503 << " h_max = " << h_max[i] << " \n "
504 << " l_ji_h = " << l_ji_h << std::endl;
505 std::cout << "LIMIT_ITER " << limit_iter << std::endl;
506 abort();
507 }
508
509 if (h_max[i] - (hLowi + l_ji_h * P_h) < -1e-12) {
510 std::cout << " MAJOR BUG 1b " << std::setprecision(15) << " \n "
511 << " Diff = " << h_max[i] - (hLowi + l_ji_h * P_h)
512 << " \n "
513 << " Soln = " << (hLowi + P_h) << " \n "
514 << " hLowi = " << hLowi << " \n "
515 << " h_min = " << h_min[i] << " \n "
516 << " h_max = " << h_max[i] << " \n "
517 << " P_h = " << P_h << " \n "
518 << " l_ji_h = " << l_ji_h << std::endl;
519 std::cout << "LIMIT_ITER " << limit_iter << std::endl;
520 abort();
521 }
522#endif
523 }
524
525 /* h limiting -- to define l_ij_h */
526 double l_ij_h = Lij_array[ij];
527 {
528 const double denominator_test =
529 1. / (std::abs(P_h_tr) + eps * h_max[j]);
530
531 if (hLowj + P_h_tr < h_min[j]) {
532 l_ij_h = std::min((std::abs(h_min[j] - hLowj) + eps * h_min[j]) *
533 denominator_test,
534 1.);
535 } else if (h_max[j] < hLowj + P_h_tr) {
536 l_ij_h = std::min((std::abs(h_max[j] - hLowj) + eps * h_min[j]) *
537 denominator_test,
538 1.);
539 }
540
541 // set limiter to 0 if water depth is close to 0
542 l_ij_h = (hLowj <= hEps) ? 0. : l_ij_h;
543
544 /* Box limiter to be safe? */
545 l_ij_h = std::min(l_ij_h, 1.);
546 l_ij_h = std::max(l_ij_h, 0.);
547
548#if IF_LIMITING_DEBUGGING
549 if ((hLowj + l_ij_h * P_h_tr) - h_min[j] < -1e-12) {
550 std::cout << " MAJOR BUG 2a " << std::setprecision(15) << " \n "
551 << " Diff = " << h_min[j] - (hLowj + l_ij_h * P_h_tr)
552 << " \n "
553 << " Soln = " << (hLowj + P_h_tr) << " \n "
554 << " hLowj = " << hLowj << " \n "
555 << " h_min = " << h_min[j] << " \n "
556 << " h_max = " << h_max[j] << " \n "
557 << " P_h_tr = " << P_h_tr << " \n "
558 << " l_ij_h = " << l_ij_h << std::endl;
559 std::cout << "LIMIT_ITER " << limit_iter << std::endl;
560 abort();
561 }
562
563 if (h_max[j] - (hLowj + l_ij_h * P_h_tr) < -1e-12) {
564 std::cout << " MAJOR BUG 2b " << std::setprecision(15) << " \n "
565 << " Diff = " << h_max[j] - (hLowj + l_ij_h * P_h_tr)
566 << " \n "
567 << " Soln = " << (hLowj + P_h_tr) << " \n "
568 << " hLowj = " << hLowj << " \n "
569 << " h_min = " << h_min[j] << " \n "
570 << " h_max = " << h_max[j] << " \n "
571 << " P_h_tr = " << P_h_tr << " \n "
572 << " l_ij_h = " << l_ij_h << std::endl;
573 std::cout << "LIMIT_ITER " << limit_iter << std::endl;
574 abort();
575 }
576#endif
577 }
578
579 /* q1 limiting -- to define l_ji_q1 */
580 double l_ji_q1 = l_ji_h;
581 {
582 const double denominator =
583 1. / (std::abs(P_heta) + eps * heta_max[i]);
584
585 // Define limiter here
586 if (hetaLowi + P_heta < heta_min[i]) {
587 l_ji_q1 = std::min(
588 (std::abs(heta_min[i] - hetaLowi) + eps * heta_min[i]) *
589 denominator,
590 1.);
591 } else if (heta_max[i] < hetaLowi + P_heta) {
592 l_ji_q1 = std::min(
593 (std::abs(heta_max[i] - hetaLowi) + eps * heta_min[i]) *
594 denominator,
595 1.);
596 }
597
598 // set limiter to 0 if water depth is close to 0
599 l_ji_q1 = (hLowi <= hEps) ? 0. : l_ji_q1;
600
601 // get min of l_ji_q1 and previous limiter
602 l_ji_q1 = std::min(l_ji_q1, l_ji_h);
603
604 /* Box limiter to be safe? */
605 l_ji_q1 = std::min(l_ji_q1, 1.);
606 l_ji_q1 = std::max(l_ji_q1, 0.);
607
608#if IF_LIMITING_DEBUGGING
609 if ((hetaLowi + l_ji_q1 * P_heta) - heta_min[i] < -hEps * hEps) {
610 std::cout << " MAJOR BUG 3a " << std::setprecision(15) << " \n "
611 << "New soln " << hetaLowi + l_ji_q1 * P_heta << " \n "
612 << "hetaLowi " << hetaLowi << " \n "
613 << "heta_min " << heta_min[i] << " \n "
614 << "heta_max " << heta_max[i] << " \n "
615 << "l_ji_q1 " << l_ji_q1 << " \n "
616 << "test hi " << hLowi << std::endl;
617 if (heta_max[i] > -hEps)
618 abort();
619 }
620
621 if (heta_max[i] - (hetaLowi + l_ji_q1 * P_heta) < -hEps * hEps) {
622 std::cout << " MAJOR BUG 3b " << std::setprecision(15) << " \n "
623 << "New soln " << hetaLowi + l_ji_q1 * P_heta << " \n "
624 << "hetaLowi " << hetaLowi << " \n "
625 << "heta_min " << heta_min[i] << " \n "
626 << "heta_max " << heta_max[i] << " \n "
627 << "l_ji_q1 " << l_ji_q1 << " \n "
628 << "test hi " << hLowi << std::endl;
629 if (heta_max[i] > -hEps)
630 abort();
631 }
632#endif
633 }
634
635 /* q1 limiting -- to define l_ij_q1 */
636 double l_ij_q1 = l_ij_h;
637 {
638 const double denominator =
639 1. / (std::abs(P_heta_tr) + eps * heta_max[j]);
640
641 if (hetaLowj + P_heta_tr < heta_min[j]) {
642 l_ij_q1 = std::min(
643 (std::abs(heta_min[j] - hetaLowj) + eps * heta_min[j]) *
644 denominator,
645 1.);
646 } else if (heta_max[j] < hetaLowj + P_heta_tr) {
647 l_ij_q1 = std::min(
648 (std::abs(heta_max[j] - hetaLowj) + eps * heta_min[j]) *
649 denominator,
650 1.);
651 }
652
653 // set limiter to 0 if water depth is close to 0
654 l_ij_q1 = (hLowj <= hEps) ? 0. : l_ij_q1;
655
656 // get min of l_ij_q1 and previous limiter
657 l_ij_q1 = std::min(l_ij_q1, l_ij_h);
658
659 /* Box limiter to be safe? */
660 l_ij_q1 = std::min(l_ij_q1, 1.0);
661 l_ij_q1 = std::max(l_ij_q1, 0.0);
662 }
663
664#if IF_LIMITING_DEBUGGING
665 if ((hetaLowj + l_ij_q1 * P_heta_tr) - heta_min[j] < -hEps * hEps) {
666 std::cout << " MAJOR BUG 4a " << std::setprecision(15) << " \n "
667 << "New soln " << hetaLowj + l_ij_q1 * P_heta_tr << " \n "
668 << "hetaLowj " << hetaLowj << " \n "
669 << "heta_min " << heta_min[j] << " \n "
670 << "heta_max " << heta_max[j] << " \n "
671 << "l_ij_q1 " << l_ij_q1 << " \n "
672 << "test hj " << hLowj << std::endl;
673 if (heta_max[j] > -hEps)
674 abort();
675 }
676
677 if (heta_max[j] - (hetaLowj + l_ij_q1 * P_heta_tr) < -hEps * hEps) {
678 std::cout << " MAJOR BUG 4b " << std::setprecision(15) << " \n "
679 << "New soln " << hetaLowj + l_ij_q1 * P_heta_tr << " \n "
680 << "hetaLowj " << hetaLowj << " \n "
681 << "heta_min " << heta_min[j] << " \n "
682 << "heta_max " << heta_max[j] << " \n "
683 << "l_ij_q1 " << l_ij_q1 << " \n "
684 << "test hj " << hLowj << std::endl;
685 if (heta_max[j] > -hEps)
686 abort();
687 }
688#endif
689
690 /* kinetic energy limiting -- to define l_ji_K */
691 double l_tmp = 0.;
692 double l_ji_K = l_ji_q1;
693 {
694 // We first check if current l_ji_K is a good state
695 const double h_r = hLowi + l_ji_K * P_h;
696 const double hu_r = huLowi + l_ji_K * P_hu;
697 const double hv_r = hvLowi + l_ji_K * P_hv;
698 const double psi =
699 kin_max[i] * h_r - 0.5 * (hu_r * hu_r + hv_r * hv_r);
700
701 l_tmp = (psi > -KE_tiny) ? l_ji_K : l_tmp;
702
703 const double ai = -0.5 * (P_hu * P_hu + P_hv * P_hv);
704 const double ai_nudged = std::min(ai, -KE_tiny);
705 const double bi = kinMaxi * P_h - (huLowi * P_hu + hvLowi * P_hv);
706 const double ci =
707 hLowi * kinMaxi - 0.5 * (huLowi * huLowi + hvLowi * hvLowi);
708
709 const double delta_i = bi * bi - 4. * ai * ci;
710 const double root_i =
711 0.5 / ai_nudged * (-bi - std::sqrt(std::abs(delta_i)));
712
713 // define l_ji_K
714 l_ji_K = (root_i > 0.) ? std::min(root_i, l_ji_K)
715 : std::min(l_tmp, l_ji_K);
716
717 /* if previous bound was already satisfied, we should take
718 l_tmp instead of l_ji_K */
719 l_tmp = std::max(l_tmp, l_ji_K);
720
721 // If we are in a "dry state", limiter should be 0
722 l_tmp = (hLowi * kinMaxi <= KE_tiny) ? 0. : l_tmp;
723
724 /* Then box to be safe */
725 l_tmp = std::min(l_tmp, 1.);
726 l_tmp = std::max(l_tmp, 0.);
727 }
728
729 /* Define final l_ji_K */
730 l_ji_K = std::min(l_tmp, l_ji_q1);
731
732 /* kinetic energy limiting -- to define l_ij_K */
733 l_tmp = 0.;
734 double l_ij_K = l_ij_q1;
735 {
736 // We first check if current l_ij_K is a good state
737 const double h_r = hLowj + l_ij_K * P_h_tr;
738 const double hu_r = huLowj + l_ij_K * P_hu_tr;
739 const double hv_r = hvLowj + l_ij_K * P_hv_tr;
740 const double psi =
741 kinMaxj * h_r - 0.5 * (hu_r * hu_r + hv_r * hv_r);
742
743 l_tmp = (psi > -KE_tiny) ? l_ij_K : l_tmp;
744
745 const double aj = -0.5 * (P_hu_tr * P_hu_tr + P_hv_tr * P_hv_tr);
746 const double aj_nudged = std::min(aj, -KE_tiny);
747 const double bj =
748 kinMaxj * P_h_tr - (huLowj * P_hu_tr + hvLowj * P_hv_tr);
749 const double cj =
750 hLowj * kinMaxj - 0.5 * (huLowj * huLowj + hvLowj * hvLowj);
751
752 const double delta_j = bj * bj - 4. * aj * cj;
753 const double root_j =
754 0.5 / aj_nudged * (-bj - std::sqrt(std::abs(delta_j)));
755
756 // define l_ij_K
757 l_ij_K = (root_j > 0.) ? std::min(root_j, l_ij_K)
758 : std::min(l_tmp, l_ij_K);
759
760 /* if previous bound was already satisfied, we should take l_tmp
761 instead of l_ij_K */
762 l_tmp = std::max(l_tmp, l_ij_K);
763
764 // If we are in a "dry state", limiter should be 0
765 l_tmp = (hLowj * kinMaxj <= KE_tiny) ? 0. : l_tmp;
766
767 /* Box limiter */
768 l_tmp = std::min(l_tmp, 1.);
769 l_tmp = std::max(l_tmp, 0.);
770 }
771
772 /* Get final l_ij_K*/
773 l_ij_K = std::min(l_tmp, l_ij_q1);
774
775 /* Then we get the final limiter lij */
776 Lij_array[ij] = std::min(l_ji_K, l_ij_K);
777
778#if IF_LIMITING_DEBUGGING
779 if (Lij_array[ij] > 1. || Lij_array[ij] < 0.) {
780 std::cout << "\n Problem with limiter! \n " << Lij_array[ij]
781 << "\n Aborting! " << std::endl;
782 }
783#endif
784 ij += 1;
785 } // end j loop
786 } // end i loop
787
788 /* Loop to define limited solution */
789 ij = 0;
790 for (int i = 0; i < numDOFs; i++) {
791
792 const double one_over_mi = 1. / lumped_mass_matrix[i];
793 double ith_Limiter_times_FCT_matrix1 = 0.;
794 double ith_Limiter_times_FCT_matrix2 = 0.;
795 double ith_Limiter_times_FCT_matrix3 = 0.;
796 double ith_Limiter_times_FCT_matrix4 = 0.;
797 double ith_Limiter_times_FCT_matrix5 = 0.;
798 double ith_Limiter_times_FCT_matrix6 = 0.;
799
800 // LOOP OVER THE SPARSITY PATTERN (j-LOOP)//
801 for (int offset = csrRowIndeces_DofLoops[i];
802 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
803 int j = csrColumnOffsets_DofLoops[offset];
804
805 // COMPUTE LIMITED FLUX //
806 ith_Limiter_times_FCT_matrix1 += Lij_array[ij] * FCT_h[ij];
807 ith_Limiter_times_FCT_matrix2 += Lij_array[ij] * FCT_hu[ij];
808 ith_Limiter_times_FCT_matrix3 += Lij_array[ij] * FCT_hv[ij];
809 ith_Limiter_times_FCT_matrix4 += Lij_array[ij] * FCT_heta[ij];
810 ith_Limiter_times_FCT_matrix5 += Lij_array[ij] * FCT_hw[ij];
811 ith_Limiter_times_FCT_matrix6 += Lij_array[ij] * FCT_hbeta[ij];
812
813 // update ij
814 ij += 1;
815 } // end j loop
816
817 // then we add lij*Aij to uLow
818 hLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix1;
819 huLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix2;
820 hvLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix3;
821 hetaLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix4;
822 hwLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix5;
823 hbetaLow[i] += one_over_mi * ith_Limiter_times_FCT_matrix6;
824
825#if IF_LIMITING_DEBUGGING
826 if (hLow[i] < -hEps) {
827 std::cout
828 << " \n New intermediated/limited water depth is negative! \n"
829 << "new hLow[i] = " << hLow[i] << " \n "
830 << "-hEps = " << -hEps << "\n"
831 << "h_min = " << h_min[i] << "\n"
832 << "h_max = " << h_max[i] << "\n"
833 << "... Aborting! \n"
834 << std::endl;
835 abort();
836 }
837 if (h_max[i] - hLow[i] < -1e-12 || hLow[i] - h_min[i] < -1e-12) {
838 std::cout
839 << std::setprecision(15)
840 << " --- We have a major problem (h limiting bounds) --- \n "
841 << "i = " << i << " \n "
842 << "hLow[i] = " << hLow[i] << " \n "
843 << "h_min[i] = " << h_min[i] << " \n "
844 << "h_max[i] = " << h_max[i] << " \n "
845 << "Diff max = " << h_max[i] - hLow[i] << " \n "
846 << "Diff min = " << hLow[i] - h_min[i] << " \n " << std::endl;
847 std::cout << "LIMIT_ITER " << limit_iter << std::endl;
848 abort();
849 }
850
851 if (heta_max[i] - hetaLow[i] < -hEps * hEps ||
852 hetaLow[i] - heta_min[i] < -hEps * hEps) {
853 std::cout
854 << std::setprecision(15)
855 << " --- We have a major problem (heta limiting bounds) --- \n
856 "
857 << "hetaLow[i] = " << hetaLow[i] << " \n "
858 << "heta_min[i] = " << heta_min[i] << " \n "
859 << "heta_max[i] = " << heta_max[i] << " \n "
860 << "Diff max = " << heta_max[i] - hetaLow[i] << " \n "
861 << "Diff min = " << hetaLow[i] - heta_min[i] << " \n "
862 << std::endl;
863 abort();
864 }
865#endif
866 } // end i loop
867
868 // update FCT matrices as Fct = (1 - Lij)*Fct
869 FCT_h = (1. - Lij_array) * FCT_h;
870 FCT_hu = (1. - Lij_array) * FCT_hu;
871 FCT_hv = (1. - Lij_array) * FCT_hv;
872 FCT_heta = (1. - Lij_array) * FCT_heta;
873 FCT_hw = (1. - Lij_array) * FCT_hw;
874 FCT_hbeta = (1. - Lij_array) * FCT_hbeta;
875 } // end loop for limiting iteration
876
877 if (limit_iter_arg < n_limit_iter - 1) {
878 for (std::size_t k = 0; k < nnz_fct; k++) {
879 FCT_all[0 * nnz_fct + k] = FCT_h[k];
880 FCT_all[1 * nnz_fct + k] = FCT_hu[k];
881 FCT_all[2 * nnz_fct + k] = FCT_hv[k];
882 FCT_all[3 * nnz_fct + k] = FCT_heta[k];
883 FCT_all[4 * nnz_fct + k] = FCT_hw[k];
884 FCT_all[5 * nnz_fct + k] = FCT_hbeta[k];
885 }
886 return; // the caller exchanges hLow etc. and calls the next pass
887 }
888
889 /* Update final solution */
890 for (int i = 0; i < numDOFs; i++) {
891
892 const double one_over_mi = 1. / lumped_mass_matrix[i];
893
894 limited_hnp1[i] = hLow[i] + dt * one_over_mi * SourceTerm_h[i];
895 limited_hunp1[i] = huLow[i] + dt * one_over_mi * extendedSourceTerm_hu[i];
896 limited_hvnp1[i] = hvLow[i] + dt * one_over_mi * extendedSourceTerm_hv[i];
897 limited_hetanp1[i] = hetaLow[i] + dt * one_over_mi * SourceTerm_heta[i];
898 limited_hwnp1[i] = hwLow[i] + dt * one_over_mi * SourceTerm_hw[i];
899 limited_hbetanp1[i] =
900 hbetaLow[i] + dt * one_over_mi * SourceTerm_hbeta[i];
901
902 if (limited_hnp1[i] < -hEps) {
903 std::cout << " \n "
904 << " !!!! Limited water height is negative: !!!! \n"
905 << " hLim = " << limited_hnp1[i] << "\n"
906 << " hEps = " << hEps << "\n"
907 << " h_min = " << h_min[i] << "\n"
908 << " h_max = " << h_max[i] << "\n"
909 << " !!!! ABORTING !!!! \n"
910 << std::endl;
911 abort();
912 } else {
913 // clean up uHigh from round off error
914 if (limited_hnp1[i] < hEps) {
915 limited_hnp1[i] = 0.;
916 }
917
918 const double aux = fmax(limited_hnp1[i], hEps);
919 limited_hunp1[i] *= 2. * std::pow(limited_hnp1[i], VEL_FIX_POWER) /
920 (std::pow(limited_hnp1[i], VEL_FIX_POWER) +
921 std::pow(aux, VEL_FIX_POWER));
922 limited_hvnp1[i] *= 2. * std::pow(limited_hnp1[i], VEL_FIX_POWER) /
923 (std::pow(limited_hnp1[i], VEL_FIX_POWER) +
924 std::pow(aux, VEL_FIX_POWER));
925 limited_hwnp1[i] *= 2. * std::pow(limited_hnp1[i], VEL_FIX_POWER) /
926 (std::pow(limited_hnp1[i], VEL_FIX_POWER) +
927 std::pow(aux, VEL_FIX_POWER));
928 limited_hbetanp1[i] *= 2. * std::pow(limited_hnp1[i], VEL_FIX_POWER) /
929 (std::pow(limited_hnp1[i], VEL_FIX_POWER) +
930 std::pow(aux, VEL_FIX_POWER));
931 }
932 }
933
934 } // end convex limiting function
935
936 // Walls: on rows with wall_dof = 1 the advective (inertial) terms are
937 // integrated by parts with zero advective flux through the wall, i.e. row i
938 // uses c'_ij = -c_ji in place of c_ij (they differ only on boundary edges).
939 // The pressure and bathymetry terms stay on c_ij. See SW2DCV.h.
940 static inline void wallCoefficients(int i, int j, int ij,
941 const xt::pyarray<double> &wall_dof,
942 const xt::pyarray<double> &Cx,
943 const xt::pyarray<double> &Cy,
944 const xt::pyarray<double> &CTx,
945 const xt::pyarray<double> &CTy,
946 double &cx_ij, double &cy_ij,
947 double &cx_ji, double &cy_ji) {
948 cx_ij = wall_dof[i] > 0.5 ? -CTx[ij] : Cx[ij];
949 cy_ij = wall_dof[i] > 0.5 ? -CTy[ij] : Cy[ij];
950 cx_ji = wall_dof[j] > 0.5 ? -Cx[ij] : CTx[ij];
951 cy_ji = wall_dof[j] > 0.5 ? -Cy[ij] : CTy[ij];
952 }
953
954 // Porous edges: graph viscosities carry max(phi_i, phi_j) (see SW2DCV.h).
955 static inline double phiBar(int i, int j,
956 const xt::pyarray<double> &porosity_dof) {
957 return fmax(porosity_dof[i], porosity_dof[j]);
958 }
959
961 const double g = args.scalar<double>("g");
962 const int numDOFsPerEqn = args.scalar<int>("numDOFsPerEqn");
963 const xt::pyarray<double> &lumped_mass_matrix =
964 args.array<double>("lumped_mass_matrix");
965 const xt::pyarray<double> &h_dof_old = args.array<double>("h_dof_old");
966 const xt::pyarray<double> &hu_dof_old = args.array<double>("hu_dof_old");
967 const xt::pyarray<double> &hv_dof_old = args.array<double>("hv_dof_old");
968 const xt::pyarray<double> &heta_dof_old =
969 args.array<double>("heta_dof_old");
970 const xt::pyarray<int> &csrRowIndeces_DofLoops =
971 args.array<int>("csrRowIndeces_DofLoops");
972 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
973 args.array<int>("csrColumnOffsets_DofLoops");
974 const double hEps = args.scalar<double>("hEps");
975 const xt::pyarray<double> &Cx = args.array<double>("Cx");
976 const xt::pyarray<double> &Cy = args.array<double>("Cy");
977 const xt::pyarray<double> &CTx = args.array<double>("CTx");
978 const xt::pyarray<double> &CTy = args.array<double>("CTy");
979 const xt::pyarray<double> &inverse_mesh =
980 args.array<double>("inverse_mesh");
981 xt::pyarray<double> &edge_based_cfl = args.array<double>("edge_based_cfl");
982 const xt::pyarray<double> &wall_dof = args.array<double>("wall_dof");
983 const xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
984
985 double max_edge_based_cfl = 0.;
986 double dLowij = 0.;
987
988 int ij = 0;
989 for (int i = 0; i < numDOFsPerEqn; i++) {
990
991 // solution at time tn for the ith DOF
992 const double hi = h_dof_old[i];
993 const double one_over_hi =
994 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
995 const double hui = hu_dof_old[i];
996 const double hvi = hv_dof_old[i];
997 const double ui = hui * one_over_hi;
998 const double vi = hvi * one_over_hi;
999 const double hetai = heta_dof_old[i];
1000 const double mi = lumped_mass_matrix[i];
1001 const double inv_meshSizei = inverse_mesh[i];
1002
1003 // Initialize diagonal entry
1004 double dLowii = 0.;
1005 // boundary vector n_i = sum_j c_ji = int_{dOmega} phi_i n (zero inside)
1006 double nix = 0., niy = 0.;
1007
1008 for (int offset = csrRowIndeces_DofLoops[i];
1009 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1010
1011 // loop in j (sparsity pattern)
1012 const int j = csrColumnOffsets_DofLoops[offset];
1013
1014 // solution at time tn for the jth DOF
1015 const double hj = h_dof_old[j];
1016 const double one_over_hj =
1017 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1018 const double huj = hu_dof_old[j];
1019 const double hvj = hv_dof_old[j];
1020 const double uj = huj * one_over_hj;
1021 const double vj = hvj * one_over_hj;
1022 const double hetaj = heta_dof_old[j];
1023 const double mj = lumped_mass_matrix[j];
1024 const double inv_meshSizej = inverse_mesh[j];
1025
1026 if (j != i) {
1028 // DISSIPATIVE MATRIX //
1030 const double cij_norm = sqrt(Cx[ij] * Cx[ij] + Cy[ij] * Cy[ij]);
1031 const double cji_norm = sqrt(CTx[ij] * CTx[ij] + CTy[ij] * CTy[ij]);
1032 const double nxij = Cx[ij] / cij_norm, nyij = Cy[ij] / cij_norm;
1033 const double nxji = CTx[ij] / cji_norm, nyji = CTy[ij] / cji_norm;
1034
1035 double cxa, cya, cxaT, cyaT;
1036 wallCoefficients(i, j, ij, wall_dof, Cx, Cy, CTx, CTy, cxa, cya,
1037 cxaT, cyaT);
1038 const double muijL = fmax(std::abs(ui * cxa + vi * cya),
1039 std::abs(uj * cxaT + vj * cyaT));
1040 dLowij = fmax(maxWaveSpeedSharpInitialGuess(
1041 g, nxij, nyij, hi, hui, hvi, hetai, inv_meshSizei,
1042 hj, huj, hvj, hetaj, inv_meshSizej, hEps) *
1043 cij_norm,
1045 g, nxji, nyji, hj, huj, hvj, hetaj, inv_meshSizej,
1046 hi, hui, hvi, hetai, inv_meshSizei, hEps) *
1047 cji_norm);
1048
1049 // Take max of dij and muij
1050 dLowij = fmax(dLowij, muijL) * phiBar(i, j, porosity_dof);
1051
1052 // Define diagonal entry
1053 dLowii -= dLowij;
1054 }
1055 nix += CTx[ij];
1056 niy += CTy[ij];
1057
1058 // update ij
1059 ij += 1;
1060 }
1062 // CALCULATE EDGE BASED CFL //
1064 // A wall row's boundary term adds (u_i.n_i) U_i to the update; flow
1065 // leaving the wall (u_i.n_i < 0) needs that much more room.
1066 double wall_margin = 0.;
1067 if (wall_dof[i] > 0.5)
1068 wall_margin =
1069 0.5 * fmax(0., -porosity_dof[i] * (ui * nix + vi * niy));
1070 edge_based_cfl[i] = (fabs(dLowii) + wall_margin) / mi;
1071 max_edge_based_cfl = fmax(max_edge_based_cfl, edge_based_cfl[i]);
1072 }
1073
1074 return max_edge_based_cfl;
1075 } // End calculateEdgeBasedCFL
1076
1078 const double g = args.scalar<double>("g");
1079 const xt::pyarray<double> &h_dof_old = args.array<double>("h_dof_old");
1080 const xt::pyarray<double> &hu_dof_old = args.array<double>("hu_dof_old");
1081 const xt::pyarray<double> &hv_dof_old = args.array<double>("hv_dof_old");
1082 const xt::pyarray<double> &heta_dof_old =
1083 args.array<double>("heta_dof_old");
1084 const double hEps = args.scalar<double>("hEps");
1085 const int numDOFsPerEqn = args.scalar<int>("numDOFsPerEqn");
1086 const xt::pyarray<int> &csrRowIndeces_DofLoops =
1087 args.array<int>("csrRowIndeces_DofLoops");
1088 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
1089 args.array<int>("csrColumnOffsets_DofLoops");
1090 xt::pyarray<double> &entropy = args.array<double>("entropy");
1091 xt::pyarray<double> &delta_Sqd_h = args.array<double>("delta_Sqd_h");
1092 xt::pyarray<double> &delta_Sqd_heta = args.array<double>("delta_Sqd_heta");
1093 xt::pyarray<double> &thetaj_inv = args.array<double>("thetaj_inv");
1094 double &dij_small = args.scalar<double>("dij_small");
1095 const double h0_max = args.scalar<double>("h0_max");
1096 const xt::pyarray<double> &Cx = args.array<double>("Cx");
1097 const xt::pyarray<double> &Cy = args.array<double>("Cy");
1098
1099 const double speed = std::sqrt(g * h0_max);
1100 dij_small = 0.;
1101
1103 // ********** LOOP ON DOFs ********** //
1105 // To compute:
1106 // * Entropy at i-th nodes
1107 // * thetaj_inv at i-th nodes
1108 // * second order differences at i-th node
1109 // * dij_small
1110
1111 int ij = 0;
1112 for (int i = 0; i < numDOFsPerEqn; i++) {
1113
1114 // Define things at ith node
1115 const double hi = h_dof_old[i];
1116 const double hu_i = hu_dof_old[i];
1117 const double hv_i = hv_dof_old[i];
1118 const double hetai = heta_dof_old[i];
1119 const double one_over_hi =
1120 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2)); // hEps
1121 const double u_i = hu_i * one_over_hi;
1122 const double v_i = hv_i * one_over_hi;
1123 const double kin_i = 0.5 * hi * (u_i * u_i + v_i * v_i);
1124
1125 // Compute entropy (with a flat bottom)
1126 entropy[i] = ENTROPY(g, hi, hu_i, hv_i, 0., one_over_hi);
1127
1128 // Define convex coefficients for each i
1129 thetaj_inv[i] =
1130 1. / (csrRowIndeces_DofLoops[i + 1] - csrRowIndeces_DofLoops[i] - 1);
1131
1132 // Initialize sum of differences
1133 double h_diff = 0.;
1134 double heta_diff = 0.;
1135 double kin_diff = 0.;
1136
1137 for (int offset = csrRowIndeces_DofLoops[i];
1138 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1139 const int j = csrColumnOffsets_DofLoops[offset];
1140
1141 // Define things at jth node
1142 const double hj = h_dof_old[j];
1143 const double hu_j = hu_dof_old[j];
1144 const double hv_j = hv_dof_old[j];
1145 const double hetaj = heta_dof_old[j];
1146 const double one_over_hj =
1147 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1148 const double u_j = hu_j * one_over_hj;
1149 const double v_j = hv_j * one_over_hj;
1150 const double kin_j = 0.5 * hj * (u_j * u_j + v_j * v_j);
1151
1152 /* To compute:
1153 * Second-difference relaxation quantities
1154 */
1155 if (j != i) {
1156 h_diff += hi - hj;
1157 heta_diff += hetai - hetaj;
1158 kin_diff += kin_i - kin_j;
1159 }
1160
1161 // Compute dij_small
1162 const double x = fabs(Cx[ij]) + fabs(Cy[ij]);
1163 dij_small = fmax(dij_small, x * speed);
1164
1165 ij += 1;
1166 } // j loop ends here
1167
1168 // Set differences
1169 delta_Sqd_h[i] = h_diff;
1170 delta_Sqd_heta[i] = heta_diff;
1171
1172 } // i loop ends here
1173
1174 // Define final dij_small
1175 dij_small = 1E-14 * dij_small;
1176
1177 } // end calculatePreStep
1178
1180 const double g = args.scalar<double>("g");
1181 const xt::pyarray<double> &h_dof_old = args.array<double>("h_dof_old");
1182 const xt::pyarray<double> &hu_dof_old = args.array<double>("hu_dof_old");
1183 const xt::pyarray<double> &hv_dof_old = args.array<double>("hv_dof_old");
1184 const xt::pyarray<double> &Cx = args.array<double>("Cx");
1185 const xt::pyarray<double> &Cy = args.array<double>("Cy");
1186 const xt::pyarray<double> &CTx = args.array<double>("CTx");
1187 const xt::pyarray<double> &CTy = args.array<double>("CTy");
1188 const int numDOFsPerEqn = args.scalar<int>("numDOFsPerEqn");
1189 const xt::pyarray<int> &csrRowIndeces_DofLoops =
1190 args.array<int>("csrRowIndeces_DofLoops");
1191 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
1192 args.array<int>("csrColumnOffsets_DofLoops");
1193 const xt::pyarray<double> &lumped_mass_matrix =
1194 args.array<double>("lumped_mass_matrix");
1195 const double hEps = args.scalar<double>("hEps");
1196 xt::pyarray<double> &global_entropy_residual =
1197 args.array<double>("global_entropy_residual");
1198 const xt::pyarray<double> &entropy = args.array<double>("entropy");
1199 const double h0_max = args.scalar<double>("h0_max");
1200
1202 // ********** FIRST LOOP ON DOFs ********** //
1204 // To compute:
1205 // * global entropy residual
1206
1207 int ij = 0;
1208 for (int i = 0; i < numDOFsPerEqn; i++) {
1209
1210 // solution at time tn for the ith DOF
1211 const double hi = h_dof_old[i];
1212 const double hui = hu_dof_old[i];
1213 const double hvi = hv_dof_old[i];
1214 const double one_over_hiReg =
1215 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2)); // hEps
1216 const double ui = hui * one_over_hiReg;
1217 const double vi = hvi * one_over_hiReg;
1218 const double mi = lumped_mass_matrix[i];
1219
1220 // initialize some things for entropy residual
1221 double etaMax_i = fabs(entropy[i]);
1222 double etaMin_i = fabs(entropy[i]);
1223
1224 double ith_flux_term1 = 0., ith_flux_term2 = 0., ith_flux_term3 = 0.;
1225 double entropy_flux = 0.;
1226 double sum_entprime_flux = 0.;
1227 const double eta_prime1 =
1228 DENTROPY_DH(g, hi, hui, hvi, 0., one_over_hiReg);
1229 const double eta_prime2 =
1230 DENTROPY_DHU(g, hi, hui, hvi, 0., one_over_hiReg);
1231 const double eta_prime3 =
1232 DENTROPY_DHV(g, hi, hui, hvi, 0., one_over_hiReg);
1233
1234 // loop in j (sparsity pattern)
1235 for (int offset = csrRowIndeces_DofLoops[i];
1236 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1237
1238 int j = csrColumnOffsets_DofLoops[offset];
1239
1240 // solution at time tn for the jth DOF
1241 const double hj = h_dof_old[j];
1242 const double huj = hu_dof_old[j];
1243 const double hvj = hv_dof_old[j];
1244 const double one_over_hjReg =
1245 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1246 const double uj = huj * one_over_hjReg;
1247 const double vj = hvj * one_over_hjReg;
1248
1249 // auxiliary functions to compute fluxes
1250 const double aux_h =
1251 (uj * hj - ui * hi) * Cx[ij] + (vj * hj - vi * hi) * Cy[ij];
1252 const double aux_hu =
1253 (uj * huj - ui * hui) * Cx[ij] + (vj * huj - vi * hui) * Cy[ij];
1254 const double aux_hv =
1255 (uj * hvj - ui * hvi) * Cx[ij] + (vj * hvj - vi * hvi) * Cy[ij];
1256
1257 // get regular flux
1258 ith_flux_term1 += aux_h;
1259 ith_flux_term2 += aux_hu + 0.5 * g * hj * hj * Cx[ij];
1260 ith_flux_term3 += aux_hv + 0.5 * g * hj * hj * Cy[ij];
1261
1262 // define entropy flux with flat topography
1263 entropy_flux +=
1264 (Cx[ij] * ENTROPY_FLUX1(g, hj, huj, hvj, 0., one_over_hjReg) +
1265 Cy[ij] * ENTROPY_FLUX2(g, hj, huj, hvj, 0., one_over_hjReg));
1266
1267 // compute eta_max and eta_min
1268 etaMax_i = fmax(etaMax_i, fabs(entropy[j]));
1269 etaMin_i = fmin(etaMin_i, fabs(entropy[j]));
1270
1271 // update ij
1272 ij += 1;
1273 } // end j loop
1274
1275 // define sum of entprime*flux
1276 sum_entprime_flux =
1277 (ith_flux_term1 * eta_prime1 + ith_flux_term2 * eta_prime2 +
1278 ith_flux_term3 * eta_prime3);
1279
1280 // define rescale for normalization
1281 const double small_rescale = g * hEps * h0_max;
1282 const double rescale =
1283 fmax(fabs(etaMax_i - etaMin_i) / 2., small_rescale);
1284
1285 // compute entropy residual
1286 const double one_over_entNormFactori = 1. / rescale;
1287 global_entropy_residual[i] =
1288 one_over_entNormFactori * fabs(entropy_flux - sum_entprime_flux);
1289
1290 // if "dry" state, set residual to 1
1291 if (hi <= hEps) {
1292 global_entropy_residual[i] = 1.;
1293 }
1294 } // end i loop
1295
1296 // ********** END OF LOOP IN DOFs ********** //
1297 } // end calculateEV
1298
1300 const double g = args.scalar<double>("g");
1301 const xt::pyarray<double> &h_dof_old = args.array<double>("h_dof_old");
1302 const xt::pyarray<double> &hu_dof_old = args.array<double>("hu_dof_old");
1303 const xt::pyarray<double> &hv_dof_old = args.array<double>("hv_dof_old");
1304 const xt::pyarray<double> &heta_dof_old =
1305 args.array<double>("heta_dof_old");
1306 const xt::pyarray<double> &hw_dof_old = args.array<double>("hw_dof_old");
1307 const xt::pyarray<double> &hbeta_dof_old =
1308 args.array<double>("hbeta_dof_old");
1309 const xt::pyarray<double> &b_dof = args.array<double>("b_dof");
1310 const xt::pyarray<double> &Cx = args.array<double>("Cx");
1311 const xt::pyarray<double> &Cy = args.array<double>("Cy");
1312 const xt::pyarray<double> &CTx = args.array<double>("CTx");
1313 const xt::pyarray<double> &CTy = args.array<double>("CTy");
1314 const int numDOFsPerEqn = args.scalar<int>("numDOFsPerEqn");
1315 const xt::pyarray<int> &csrRowIndeces_DofLoops =
1316 args.array<int>("csrRowIndeces_DofLoops");
1317 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
1318 args.array<int>("csrColumnOffsets_DofLoops");
1319 const xt::pyarray<double> &lumped_mass_matrix =
1320 args.array<double>("lumped_mass_matrix");
1321 const double hEps = args.scalar<double>("hEps");
1322 xt::pyarray<double> &SourceTerm_h = args.array<double>("SourceTerm_h");
1323 xt::pyarray<double> &SourceTerm_hu = args.array<double>("SourceTerm_hu");
1324 xt::pyarray<double> &SourceTerm_hv = args.array<double>("SourceTerm_hv");
1325 xt::pyarray<double> &SourceTerm_heta =
1326 args.array<double>("SourceTerm_heta");
1327 xt::pyarray<double> &SourceTerm_hw = args.array<double>("SourceTerm_hw");
1328 xt::pyarray<double> &SourceTerm_hbeta =
1329 args.array<double>("SourceTerm_hbeta");
1330 const double dt = args.scalar<double>("dt");
1331 const double mannings = args.scalar<double>("mannings");
1332 const int lstage = args.scalar<int>("lstage");
1333 xt::pyarray<double> &global_entropy_residual =
1334 args.array<double>("global_entropy_residual");
1335 const double dij_small = args.scalar<double>("dij_small");
1336 xt::pyarray<double> &hLow = args.array<double>("hLow");
1337 xt::pyarray<double> &huLow = args.array<double>("huLow");
1338 xt::pyarray<double> &hvLow = args.array<double>("hvLow");
1339 xt::pyarray<double> &hetaLow = args.array<double>("hetaLow");
1340 xt::pyarray<double> &hwLow = args.array<double>("hwLow");
1341 xt::pyarray<double> &hbetaLow = args.array<double>("hbetaLow");
1342 xt::pyarray<double> &h_min = args.array<double>("h_min");
1343 xt::pyarray<double> &h_max = args.array<double>("h_max");
1344 xt::pyarray<double> &heta_min = args.array<double>("heta_min");
1345 xt::pyarray<double> &heta_max = args.array<double>("heta_max");
1346 xt::pyarray<double> &kin_max = args.array<double>("kin_max");
1347 const xt::pyarray<double> &x_values = args.array<double>("x_values");
1348 const xt::pyarray<double> &inverse_mesh =
1349 args.array<double>("inverse_mesh");
1350 const double h0_max = args.scalar<double>("h0_max");
1351 xt::pyarray<double> &RHS_high_h = args.array<double>("RHS_high_h");
1352 xt::pyarray<double> &RHS_high_hu = args.array<double>("RHS_high_hu");
1353 xt::pyarray<double> &RHS_high_hv = args.array<double>("RHS_high_hv");
1354 xt::pyarray<double> &RHS_high_heta = args.array<double>("RHS_high_heta");
1355 xt::pyarray<double> &RHS_high_hw = args.array<double>("RHS_high_hw");
1356 xt::pyarray<double> &RHS_high_hbeta = args.array<double>("RHS_high_hbeta");
1357 xt::pyarray<double> &extendedSourceTerm_hu =
1358 args.array<double>("extendedSourceTerm_hu");
1359 xt::pyarray<double> &extendedSourceTerm_hv =
1360 args.array<double>("extendedSourceTerm_hv");
1361 double size_of_domain = args.scalar<double>("size_of_domain");
1362 xt::pyarray<double> &delta_Sqd_h = args.array<double>("delta_Sqd_h");
1363 xt::pyarray<double> &delta_Sqd_heta = args.array<double>("delta_Sqd_heta");
1364 const double gen_length = args.scalar<double>("gen_length");
1365 const double gen_start = args.scalar<double>("gen_start");
1366 const double abs_length = args.scalar<double>("abs_length");
1367 const double abs_start = args.scalar<double>("abs_start");
1368 // xt::pyarray<int> &relaxation_zone_nodes =
1369 // args.array<int>("relaxation_zone_nodes");
1370 xt::pyarray<double> &h_wave = args.array<double>("h_wave");
1371 xt::pyarray<double> &h_u_wave = args.array<double>("h_u_wave");
1372 xt::pyarray<double> &h_v_wave = args.array<double>("h_v_wave");
1373 xt::pyarray<double> &h_eta_wave = args.array<double>("h_eta_wave");
1374 xt::pyarray<double> &h_w_wave = args.array<double>("h_w_wave");
1375 xt::pyarray<double> &h_beta_wave = args.array<double>("h_beta_wave");
1376 // 1 on rows whose advective terms are integrated by parts (no-flux walls)
1377 const xt::pyarray<double> &wall_dof = args.array<double>("wall_dof");
1378 // Canopy: porosity (storage phi U, fluxes phi F, pressures phi_i grad p)
1379 // and Darcy-Forchheimer drag -(alpha + beta|u|) h u per unit plan area
1380 const xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
1381 const xt::pyarray<double> &drag_alpha_dof =
1382 args.array<double>("drag_alpha_dof");
1383 const xt::pyarray<double> &drag_beta_dof = args.array<double>("drag_beta_dof");
1384
1385 /* Define constants for sources here. Note that these do not depend on the
1386 * DOFs so we should only compute once */
1387 const double n2 = std::pow(mannings, 2.);
1388 const double gamma = 4. / 3;
1389 const double xi = 10.;
1390 const double alpha = 0.005;
1391 /* ---------------------------------- */
1392
1394 // ********** FIRST SET OF LOOP ON DOFs ********** //
1396 // To compute:
1397 // * Soure terms
1398 // * Low order solution (in terms of bar states)
1399 // * Local bounds for limiting
1400 // * High-order right hand side
1401
1402 /* ----------- Here we do some initial declaration --------------- */
1403 // Bar states
1404 std::valarray<double> hBT(0., Cx.size()), huBT(0., Cx.size()),
1405 hvBT(0., Cx.size()), hetaBT(0., Cx.size()), hwBT(0., Cx.size()),
1406 hbetaBT(0., Cx.size()), dLow(0., Cx.size());
1407
1408 // Relaxation quantities
1409 std::valarray<double> bar_deltaSqd_h(0., numDOFsPerEqn),
1410 bar_deltaSqd_heta(0., numDOFsPerEqn);
1411
1412 double high_viscosity_h, high_viscosity_hu, high_viscosity_hv,
1413 high_viscosity_heta, high_viscosity_hw, high_viscosity_hbeta;
1414
1415 // Boundary vectors n_i = sum_j c_ji = int_{dOmega} phi_i n on wall rows.
1416 // There R_i = -sum_j F_j.c_ji = sum_j (F_j - F_i).c'_ij - F_i.n_i, and
1417 // F_adv(U).n = (u.n) U, so the boundary term only rescales U_i.
1418 std::valarray<double> wall_nx(0., numDOFsPerEqn), wall_ny(0., numDOFsPerEqn);
1419 {
1420 int ij_w = 0;
1421 for (int i = 0; i < numDOFsPerEqn; i++)
1422 for (int offset = csrRowIndeces_DofLoops[i];
1423 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1424 if (wall_dof[i] > 0.5) {
1425 wall_nx[i] += CTx[ij_w];
1426 wall_ny[i] += CTy[ij_w];
1427 }
1428 ij_w++;
1429 }
1430 }
1431
1432 /* First loop to compute:
1433 1. bar states
1434 2. Sources
1435 3 high-order RHS
1436 */
1437 int ij = 0;
1438 for (int i = 0; i < numDOFsPerEqn; i++) {
1439
1440 // define things at ith node
1441 const double hi = h_dof_old[i];
1442 const double hui = hu_dof_old[i];
1443 const double hvi = hv_dof_old[i];
1444 const double hetai = heta_dof_old[i];
1445 const double hwi = hw_dof_old[i];
1446 const double hbetai = hbeta_dof_old[i];
1447 const double Zi = b_dof[i];
1448 const double mi = lumped_mass_matrix[i];
1449 const double one_over_hiReg =
1450 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
1451 const double ui = hui * one_over_hiReg;
1452 const double vi = hvi * one_over_hiReg;
1453 const double etai = hetai * one_over_hiReg;
1454 const double inv_meshSizei = inverse_mesh[i];
1455 const double x_i = x_values[i]; // x value at ith dof
1456
1457 // Initialize Sources to 0
1458 SourceTerm_h[i] = 0.;
1459 SourceTerm_hu[i] = 0.;
1460 SourceTerm_hv[i] = 0.;
1461 SourceTerm_heta[i] = 0.;
1462 SourceTerm_hw[i] = 0.;
1463 SourceTerm_hbeta[i] = 0.;
1464
1465 // Define pTilde at ith node here
1466 double pTildei =
1467 -(LAMBDA_MGN * g / 3. * inv_meshSizei) * 6. * hi * (hetai - hi * hi);
1469 double diff_over_h_i = (hetai - hi * hi) * one_over_hiReg;
1470 if (hetai > std::pow(hi, 2.0)) {
1471 pTildei = -(LAMBDA_MGN * g / 3.0 * inv_meshSizei) * 2.0 *
1472 diff_over_h_i * (etai * etai + etai * hi + hi * hi);
1473 }
1474 }
1475
1476 // Define full pressure
1477 const double pressure_i = 0.5 * g * hi * hi + pTildei;
1478
1479 // For extended topography source for bar state verison of low-order
1480 extendedSourceTerm_hu[i] = 0.;
1481 extendedSourceTerm_hv[i] = 0.;
1482
1483 /* ---- For nodal sources, part 1 (assuming source is on RHS) ---------*/
1484
1485 // Friction terms
1486 const double veli_norm = std::sqrt(ui * ui + vi * vi);
1487 const double hi_to_the_gamma = std::pow(fmax(hi, hEps), gamma);
1488 const double friction_aux =
1489 veli_norm == 0.
1490 ? 0.
1491 : (2 * g * n2 * veli_norm * mi /
1492 (hi_to_the_gamma +
1493 fmax(hi_to_the_gamma, xi * g * n2 * dt * veli_norm)));
1494 SourceTerm_hu[i] = -friction_aux * hui;
1495 SourceTerm_hv[i] = -friction_aux * hvi;
1496
1497 // Canopy drag, semi-implicit like the Manning term: K hu per unit
1498 // storage with K = (alpha + beta |u|) / phi
1499 const double phi_i = porosity_dof[i];
1500 {
1501 const double K =
1502 (drag_alpha_dof[i] + drag_beta_dof[i] * veli_norm) / phi_i;
1503 if (K > 0.) {
1504 const double drag_aux = 2. * K * mi / (1. + fmax(1., xi * dt * K));
1505 SourceTerm_hu[i] -= drag_aux * hui;
1506 SourceTerm_hv[i] -= drag_aux * hvi;
1507 }
1508 }
1509 // The limited update adds extendedSourceTerm (not SourceTerm) to hu and
1510 // hv, so friction and drag must be in it too; before this they only
1511 // reached the high-order RHS and had no net effect.
1512 extendedSourceTerm_hu[i] += SourceTerm_hu[i];
1513 extendedSourceTerm_hv[i] += SourceTerm_hv[i];
1514
1515 // Set flux sum terms to 0.
1516 double sum_flux_h = 0.;
1517 double sum_flux_hu = 0.;
1518 double sum_flux_hv = 0.;
1519 double sum_flux_heta = 0.;
1520 double sum_flux_hw = 0.;
1521 double sum_flux_hbeta = 0.;
1522
1523 // Initialize sum for high-order viscosity terms
1524 high_viscosity_h = 0.;
1525 high_viscosity_hu = 0.;
1526 high_viscosity_hv = 0.;
1527 high_viscosity_heta = 0.;
1528 high_viscosity_hw = 0.;
1529 high_viscosity_hbeta = 0.;
1530
1531 // Set some values to 0 for ith node
1532 double grad_Z_x_i = 0.;
1533 double grad_Z_y_i = 0.;
1534
1535 const double card_inv =
1536 1. / (csrRowIndeces_DofLoops[i + 1] - csrRowIndeces_DofLoops[i]);
1537
1538 // loop over the sparsity pattern of the i-th DOF
1539 for (int offset = csrRowIndeces_DofLoops[i];
1540 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1541 const int j = csrColumnOffsets_DofLoops[offset];
1542
1543 // define things at jth node
1544 const double hj = h_dof_old[j];
1545 const double huj = hu_dof_old[j];
1546 const double hvj = hv_dof_old[j];
1547 const double hetaj = heta_dof_old[j];
1548 const double hwj = hw_dof_old[j];
1549 const double hbetaj = hbeta_dof_old[j];
1550 const double Zj = b_dof[j];
1551 const double one_over_hjReg =
1552 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1553 const double uj = huj * one_over_hjReg;
1554 const double vj = hvj * one_over_hjReg;
1555 const double etaj = hetaj * one_over_hjReg;
1556 const double mj = lumped_mass_matrix[j];
1557 const double inv_meshSizej = inverse_mesh[j]; // local mesh size in 2d
1558
1559 // Define grad_Z_x and grad_Z_y
1560 grad_Z_x_i += Zj * Cx[ij];
1561 grad_Z_y_i += Zj * Cy[ij];
1562
1563 // Define pTilde at jth node
1564 double pTildej = -(LAMBDA_MGN * g / 3. * inv_meshSizej) * 6. * hj *
1565 (hetaj - hj * hj);
1567 double diff_over_h_j = (hetaj - hj * hj) * one_over_hjReg;
1568 if (hetaj > std::pow(hj, 2.0)) {
1569 pTildej = -(LAMBDA_MGN * g / 3.0 * inv_meshSizej) * 2.0 *
1570 diff_over_h_j * (etaj * etaj + etaj * hj + hj * hj);
1571 }
1572 }
1573
1574 // Define full pressure at jth node
1575 const double pressure_j = 0.5 * g * hj * hj + pTildej;
1576
1577 // Define extended source term for hu and hv (porous: times phi_i)
1578 extendedSourceTerm_hu[i] +=
1579 phi_i * g * (-hi * Zj + 0.5 * (hj - hi) * (hj - hi)) * Cx[ij];
1580 extendedSourceTerm_hv[i] +=
1581 phi_i * g * (-hi * Zj + 0.5 * (hj - hi) * (hj - hi)) * Cy[ij];
1582 const double phi_j = porosity_dof[j];
1583
1584 // advective coefficients: c'_ij for row i and c'_ji for row j
1585 double cxa, cya, cxaT, cyaT;
1586 wallCoefficients(i, j, ij, wall_dof, Cx, Cy, CTx, CTy, cxa, cya, cxaT,
1587 cyaT);
1588
1589 /* ------- Define hyperbolic fluxes (for bar states) ------------ */
1590 // (porous: advective fluxes phi_j F_j, pressure phi_i (p_j - p_i))
1591 const double flux_h = (phi_j * hj * uj - phi_i * hi * ui) * cxa +
1592 (phi_j * hj * vj - phi_i * hi * vi) * cya;
1593 //
1594 const double aux_hu = (phi_j * uj * huj - phi_i * ui * hui) * cxa +
1595 (phi_j * vj * huj - phi_i * vi * hui) * cya;
1596 const double flux_hu =
1597 aux_hu + phi_i * (pressure_j - pressure_i) * Cx[ij];
1598 //
1599 const double aux_hv = (phi_j * uj * hvj - phi_i * ui * hvi) * cxa +
1600 (phi_j * vj * hvj - phi_i * vi * hvi) * cya;
1601 const double flux_hv =
1602 aux_hv + phi_i * (pressure_j - pressure_i) * Cy[ij];
1603 //
1604 const double flux_heta =
1605 (phi_j * uj * hj * etaj - phi_i * ui * hi * etai) * cxa +
1606 (phi_j * vj * hj * etaj - phi_i * vi * hi * etai) * cya;
1607 const double flux_hw = (phi_j * uj * hwj - phi_i * ui * hwi) * cxa +
1608 (phi_j * vj * hwj - phi_i * vi * hwi) * cya;
1609 //
1610 const double flux_hbeta =
1611 (phi_j * uj * hbetaj - phi_i * ui * hbetai) * cxa +
1612 (phi_j * vj * hbetaj - phi_i * vi * hbetai) * cya;
1613 /* --------------------------------------------------------- */
1614
1615 /* ------ Sum flux terms with well-balancing term on hu,hv ---------- */
1616 sum_flux_h += flux_h;
1617 sum_flux_hu += aux_hu + phi_i * (g * hi * (hj + Zj) + pTildej) * Cx[ij];
1618 sum_flux_hv += aux_hv + phi_i * (g * hi * (hj + Zj) + pTildej) * Cy[ij];
1619 sum_flux_heta += flux_heta;
1620 sum_flux_hw += flux_hw;
1621 sum_flux_hbeta += flux_hbeta;
1622 /* -------------------------------------------- */
1623
1624 // Initialize low and high graph-viscosity coefficients to 0
1625 double muLij = 0., muHij = 0.;
1626 double dLowij = 0., dLij = 0., dHij = 0.;
1627
1628 if (j != i) {
1629 // Put these computations first before it gets messy
1630 bar_deltaSqd_h[i] += 0.5 * delta_Sqd_h[j] + 0.5 * delta_Sqd_h[i];
1631 bar_deltaSqd_heta[i] +=
1632 0.5 * delta_Sqd_heta[j] + 0.5 * delta_Sqd_heta[i];
1633
1634 /* ------------ Define viscosity ------------ */
1635 const double cij_norm = sqrt(Cx[ij] * Cx[ij] + Cy[ij] * Cy[ij]);
1636 const double cji_norm = sqrt(CTx[ij] * CTx[ij] + CTy[ij] * CTy[ij]);
1637 const double nxij = Cx[ij] / cij_norm;
1638 const double nyij = Cy[ij] / cij_norm;
1639 const double nxji = CTx[ij] / cji_norm;
1640 const double nyji = CTy[ij] / cji_norm;
1641 dLowij = fmax(maxWaveSpeedSharpInitialGuess(
1642 g, nxij, nyij, hi, hui, hvi, hetai, inv_meshSizei,
1643 hj, huj, hvj, hetaj, inv_meshSizej, hEps) *
1644 cij_norm,
1646 g, nxji, nyji, hj, huj, hvj, hetaj, inv_meshSizej,
1647 hi, hui, hvi, hetai, inv_meshSizei, hEps) *
1648 cji_norm);
1649
1650 // Low-order graph viscoscity coefficients (symmetric in i, j)
1651 muLij = fmax(std::abs(ui * cxa + vi * cya),
1652 std::abs(uj * cxaT + vj * cyaT));
1653 const double phibar_ij = phiBar(i, j, porosity_dof);
1654 dLowij *= phibar_ij;
1655 muLij *= phibar_ij;
1656 dLij = fmax(dLowij, muLij);
1657
1658 // Safe for computation of bounds below (do not pass to others)
1659 dLow[ij] = dLij;
1660
1661 // High-order graph viscosity coefficients
1662 const double dEVij =
1663 phibar_ij *
1664 fmax(global_entropy_residual[i], global_entropy_residual[j]);
1665 dHij = fmin(dLij, dEVij);
1666 muHij = fmin(muLij, dEVij);
1667 /* --------------------------------------------- */
1668
1669 /* ---------- Compute star states ------------ */
1670 const double hStarij = fmax(0., hi + Zi - fmax(Zi, Zj));
1671 const double hStarji = fmax(0., hj + Zj - fmax(Zi, Zj));
1672 const double hStar_ratio_i = hStarij * one_over_hiReg;
1673 const double hStar_ratio_j = hStarji * one_over_hjReg;
1674 //
1675 const double huStarij = hui * hStar_ratio_i;
1676 const double hvStarij = hvi * hStar_ratio_i;
1677 const double hetaStarij = hetai * std::pow(hStar_ratio_i, 2);
1678 const double hwStarij = hwi * hStar_ratio_i;
1679 const double hbetaStarij = hbetai * hStar_ratio_i;
1680 //
1681 const double huStarji = huj * hStar_ratio_j;
1682 const double hvStarji = hvj * hStar_ratio_j;
1683 const double hetaStarji = hetaj * std::pow(hStar_ratio_j, 2);
1684 const double hwStarji = hwj * hStar_ratio_j;
1685 const double hbetaStarji = hbetaj * hStar_ratio_j;
1686 /* ------------------------------------------- */
1687
1688 /* --------- Bar states for i not equal j --------- */
1689 double hBar_ij = 0., hTilde_ij = 0., huBar_ij = 0., huTilde_ij = 0.,
1690 hvBar_ij = 0., hvTilde_ij = 0., hetaBar_ij = 0.,
1691 hetaTilde_ij = 0., hwBar_ij = 0., hwTilde_ij = 0.,
1692 hbetaBar_ij = 0., hbetaTilde_ij = 0.;
1693
1694 const double half_dij_inv = -0.5 / fmax(dLij, dij_small);
1695 const double visc_ratio = -half_dij_inv * (dLij - muLij);
1696
1697 // h component
1698 hBar_ij = half_dij_inv * flux_h + 0.5 * (hj + hi);
1699 hTilde_ij = visc_ratio * (hStarji - hj - (hStarij - hi));
1700
1701 // hu component
1702 huBar_ij = half_dij_inv * flux_hu + 0.5 * (huj + hui);
1703 huTilde_ij = visc_ratio * (huStarji - huj - (huStarij - hui));
1704
1705 // hv component
1706 hvBar_ij = half_dij_inv * flux_hv + 0.5 * (hvj + hvi);
1707 hvTilde_ij = visc_ratio * (hvStarji - hvj - (hvStarij - hvi));
1708
1709 // heta component
1710 hetaBar_ij = half_dij_inv * flux_heta + 0.5 * (hetaj + hetai);
1711 hetaTilde_ij =
1712 visc_ratio * (hetaStarji - hetaj - (hetaStarij - hetai));
1713
1714 // hw component
1715 hwBar_ij = half_dij_inv * flux_hw + 0.5 * (hwj + hwi);
1716 hwTilde_ij = visc_ratio * (hwStarji - hwj - (hwStarij - hwi));
1717
1718 // hbeta component
1719 hbetaBar_ij = half_dij_inv * flux_hbeta + 0.5 * (hbetaj + hbetai);
1720 hbetaTilde_ij =
1721 visc_ratio * (hbetaStarji - hbetaj - (hbetaStarij - hbetai));
1722
1723 /* Define bar states here. Note we take max with 0 for hBT due to
1724 potential round off */
1725 hBT[ij] = std::max(hBar_ij + hTilde_ij, 0.);
1726 huBT[ij] = huBar_ij + huTilde_ij;
1727 hvBT[ij] = hvBar_ij + hvTilde_ij;
1728 hetaBT[ij] = hetaBar_ij + hetaTilde_ij;
1729 hwBT[ij] = hwBar_ij + hwTilde_ij;
1730 hbetaBT[ij] = hbetaBar_ij + hbetaTilde_ij;
1731 /* ------------------------------------------- */
1732
1733 /* --------- Sum high viscosity terms ------- */
1734 high_viscosity_h +=
1735 (dHij - muHij) * (hStarji - hStarij) + muHij * (hj - hi);
1736
1737 high_viscosity_hu +=
1738 (dHij - muHij) * (huStarji - huStarij) + muHij * (huj - hui);
1739
1740 high_viscosity_hv +=
1741 (dHij - muHij) * (hvStarji - hvStarij) + muHij * (hvj - hvi);
1742
1743 high_viscosity_heta += (dHij - muHij) * (hetaStarji - hetaStarij) +
1744 muHij * (hetaj - hetai);
1745
1746 high_viscosity_hw +=
1747 (dHij - muHij) * (hwStarji - hwStarij) + muHij * (hwj - hwi);
1748
1749 high_viscosity_hbeta += (dHij - muHij) * (hbetaStarji - hbetaStarij) +
1750 muHij * (hbetaj - hbetai);
1751 /* ------------------------------------------- */
1752
1753 } else {
1754 // Bar states by definition satisfy Utilde_ii + Ubar_ii = U_i
1755 hBT[ij] = hi;
1756 huBT[ij] = hui;
1757 hvBT[ij] = hvi;
1758 hetaBT[ij] = hetai;
1759 hwBT[ij] = hwi;
1760 hbetaBT[ij] = hbetai;
1761 }
1762
1763 // UPDATE ij //
1764 ij += 1;
1765 } // j loop ends here
1766
1767 // wall rows: advective boundary term -F_i . n_i = -(u_i . n_i) U_i
1768 if (wall_dof[i] > 0.5) {
1769 const double un_i = phi_i * (ui * wall_nx[i] + vi * wall_ny[i]);
1770 sum_flux_h -= un_i * hi;
1771 sum_flux_hu -= un_i * hui;
1772 sum_flux_hv -= un_i * hvi;
1773 sum_flux_heta -= un_i * hi * etai;
1774 sum_flux_hw -= un_i * hwi;
1775 sum_flux_hbeta -= un_i * hbetai;
1776 }
1777
1778 // for bar_deltaSqd_h, bar_deltaSqd_heta
1779 bar_deltaSqd_h[i] *= card_inv * 0.5;
1780 bar_deltaSqd_heta[i] *= card_inv * 0.5;
1781
1782 /* ---- For nodal sources, part 2 (assuming source is on RHS) ---------*/
1783 // PDE source terms
1784 double hSqd_GammaPi = 6.0 * (hetai - hi * hi);
1786 const double diff_over_h_i = (hetai - hi * hi) * one_over_hiReg;
1787 if (hetai > std::pow(hi, 2.0)) {
1788 hSqd_GammaPi = 6.0 * etai * diff_over_h_i;
1789 }
1790 }
1791
1792 // grad_Z_i / m_i must be per unit plan area: m_i is phi-weighted, so
1793 // scale by phi_i; the topography-dispersion force is a pressure term
1794 // and carries phi_i as well
1795 const double q_dot_gradZ =
1796 phi_i * (hui * grad_Z_x_i + hvi * grad_Z_y_i);
1797 const double R1 = hwi - 1.5 * q_dot_gradZ / mi;
1798 const double R2 = LAMBDA_MGN * g * inv_meshSizei * hSqd_GammaPi;
1799 const double R3 = LAMBDA_MGN * std::sqrt(g * h0_max) * inv_meshSizei *
1800 (q_dot_gradZ / mi - hbetai);
1801
1802 SourceTerm_h[i] += 0.;
1803 // topography-dispersion force, the momentum part of the PDE source R.
1804 // The limited update must put back all of tau (R_i + S_i) (Guermond et
1805 // al. 2022, Water Waves, eq. 6.13); it was only in the high-order RHS.
1806 const double topo_disp_x = phi_i * (0.5 * R2 - 0.25 * R3) * grad_Z_x_i;
1807 const double topo_disp_y = phi_i * (0.5 * R2 - 0.25 * R3) * grad_Z_y_i;
1808 SourceTerm_hu[i] += topo_disp_x;
1809 SourceTerm_hv[i] += topo_disp_y;
1810 extendedSourceTerm_hu[i] += topo_disp_x;
1811 extendedSourceTerm_hv[i] += topo_disp_y;
1812 SourceTerm_heta[i] += mi * R1;
1813 SourceTerm_hw[i] += -mi * R2;
1814 SourceTerm_hbeta[i] += mi * R3;
1815
1816 /* Generation/absorption sources */
1817 if (gen_length > 0.) {
1818 const double shift = -(gen_start - gen_length);
1819 const double xhat = (x_i + shift) / gen_length;
1820 const double function_gen = relaxation(xhat, alpha);
1821
1822 SourceTerm_h[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1823 function_gen * (hi - h_wave[i]);
1824 SourceTerm_hu[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1825 function_gen * (hui - h_u_wave[i]);
1826 SourceTerm_hv[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1827 function_gen * (hvi - h_v_wave[i]);
1828 SourceTerm_heta[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1829 function_gen * (hetai - h_eta_wave[i]);
1830 SourceTerm_hw[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1831 function_gen * (hwi - h_w_wave[i]);
1832 SourceTerm_hbeta[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1833 function_gen * (hbetai - 0.);
1834 // for hu and hv
1835 extendedSourceTerm_hu[i] += -mi * std::sqrt(g * h0_max) *
1836 inv_meshSizei * function_gen *
1837 (hui - h_u_wave[i]);
1838 extendedSourceTerm_hv[i] += -mi * std::sqrt(g * h0_max) *
1839 inv_meshSizei * function_gen *
1840 (hvi - h_v_wave[i]);
1841 }
1842
1843 if (abs_length > 0.) {
1844 const double shift = (abs_start + abs_length);
1845 const double xhat = (shift - x_i) / abs_length;
1846 const double function_gen = relaxation(xhat, alpha);
1847
1848 SourceTerm_hu[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1849 function_gen * (hui - 0.);
1850 SourceTerm_hv[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1851 function_gen * (hvi - 0.);
1852 SourceTerm_hw[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1853 function_gen * (hwi - 0.);
1854 SourceTerm_hbeta[i] += -mi * std::sqrt(g * h0_max) * inv_meshSizei *
1855 function_gen * (hbetai - 0.);
1856 // for hu and hv
1857 extendedSourceTerm_hu[i] += -mi * std::sqrt(g * h0_max) *
1858 inv_meshSizei * function_gen * (hui - 0.);
1859 extendedSourceTerm_hv[i] += -mi * std::sqrt(g * h0_max) *
1860 inv_meshSizei * function_gen * (hvi - 0.);
1861 }
1862 /* ----------------------------------------------------- */
1863
1864 /* ----------- Save high order RHS -------------------- */
1865 RHS_high_h[i] = SourceTerm_h[i] - sum_flux_h + high_viscosity_h;
1866 RHS_high_hu[i] = SourceTerm_hu[i] - sum_flux_hu + high_viscosity_hu;
1867 RHS_high_hv[i] = SourceTerm_hv[i] - sum_flux_hv + high_viscosity_hv;
1868 RHS_high_heta[i] =
1869 SourceTerm_heta[i] - sum_flux_heta + high_viscosity_heta;
1870 RHS_high_hw[i] = SourceTerm_hw[i] - sum_flux_hw + high_viscosity_hw;
1871 RHS_high_hbeta[i] =
1872 SourceTerm_hbeta[i] - sum_flux_hbeta + high_viscosity_hbeta;
1873 /* ----------------------------------------------------*/
1874
1875 } // i loops ends here
1876
1877 /* Then final loop to get low order solution and local bounds */
1878 ij = 0;
1879 for (int i = 0; i < numDOFsPerEqn; i++) {
1880
1881 /* Define things at ith node */
1882 const double hi = h_dof_old[i];
1883 const double hu_i = hu_dof_old[i];
1884 const double hv_i = hv_dof_old[i];
1885 const double hetai = heta_dof_old[i];
1886 const double hwi = hw_dof_old[i];
1887 const double hbetai = hbeta_dof_old[i];
1888 const double one_over_hi =
1889 2. * hi / (hi * hi + std::pow(fmax(hi, hEps), 2)); // hEps
1890 const double u_i = hu_i * one_over_hi;
1891 const double v_i = hv_i * one_over_hi;
1892 const double kin_i = 0.5 * hi * (u_i * u_i + v_i * v_i);
1893 const double mi = lumped_mass_matrix[i];
1894
1895 /* Initialize bounds */
1896 h_min[i] = hi;
1897 h_max[i] = hi;
1898 heta_min[i] = hetai;
1899 heta_max[i] = hetai;
1900 kin_max[i] = kin_i;
1901
1902 // For convex low-order update
1903 double sum_dij = 0.;
1904 double sum_dij_hbar = 0.;
1905 double sum_dij_hubar = 0.;
1906 double sum_dij_hvbar = 0.;
1907 double sum_dij_hetabar = 0.;
1908 double sum_dij_hwbar = 0.;
1909 double sum_dij_hbetabar = 0.;
1910
1911 // loop in j (sparsity pattern)
1912 for (int offset = csrRowIndeces_DofLoops[i];
1913 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1914 const int j = csrColumnOffsets_DofLoops[offset];
1915
1916 const double one_over_hBT =
1917 2. * hBT[ij] /
1918 (hBT[ij] * hBT[ij] + std::pow(fmax(hBT[ij], hEps), 2));
1919 const double psi_ij =
1920 0.5 * one_over_hBT * (huBT[ij] * huBT[ij] + hvBT[ij] * hvBT[ij]);
1921
1922 // compute local bounds
1923 h_min[i] = std::min(h_min[i], hBT[ij]);
1924 h_max[i] = std::max(h_max[i], hBT[ij]);
1925 heta_min[i] = std::min(heta_min[i], hetaBT[ij]);
1926 heta_max[i] = std::max(heta_max[i], hetaBT[ij]);
1927 kin_max[i] = fmax(psi_ij, kin_max[i]);
1928
1929 if (j != i) {
1930 sum_dij += dLow[ij];
1931 sum_dij_hbar += dLow[ij] * hBT[ij];
1932 sum_dij_hubar += dLow[ij] * huBT[ij];
1933 sum_dij_hvbar += dLow[ij] * hvBT[ij];
1934 sum_dij_hetabar += dLow[ij] * hetaBT[ij];
1935 sum_dij_hwbar += dLow[ij] * hwBT[ij];
1936 sum_dij_hbetabar += dLow[ij] * hbetaBT[ij];
1937 }
1938
1939 // update ij
1940 ij += 1;
1941 } // j loop ends here
1942
1943 const double cfl_condition = (1. - dt / mi * 2. * sum_dij);
1944
1945 // Here we define low-order convex update (WITHOUT SOURCES)
1946 hLow[i] = hi * cfl_condition + dt / mi * (2. * sum_dij_hbar);
1947 huLow[i] = hu_i * cfl_condition + dt / mi * (2. * sum_dij_hubar);
1948 hvLow[i] = hv_i * cfl_condition + dt / mi * (2. * sum_dij_hvbar);
1949 hetaLow[i] = hetai * cfl_condition + dt / mi * (2. * sum_dij_hetabar);
1950 hwLow[i] = hwi * cfl_condition + dt / mi * (2. * sum_dij_hwbar);
1951 hbetaLow[i] = hbetai * cfl_condition + dt / mi * (2. * sum_dij_hbetabar);
1952
1953 // wall rows: + dt/m_i (u_i . n_i) U_i from the advective boundary term.
1954 // This rescales U_i, so the low-order state is a positive (not convex)
1955 // combination; widen the local bounds to contain it.
1956 if (wall_dof[i] > 0.5) {
1957 const double un_i =
1958 porosity_dof[i] * (u_i * wall_nx[i] + v_i * wall_ny[i]);
1959 const double etai_w =
1960 hetai * one_over_hi; // F_heta = u h eta, as in flux_heta
1961 hLow[i] += dt / mi * un_i * hi;
1962 huLow[i] += dt / mi * un_i * hu_i;
1963 hvLow[i] += dt / mi * un_i * hv_i;
1964 hetaLow[i] += dt / mi * un_i * hi * etai_w;
1965 hwLow[i] += dt / mi * un_i * hwi;
1966 hbetaLow[i] += dt / mi * un_i * hbetai;
1967 h_min[i] = std::min(h_min[i], hLow[i]);
1968 h_max[i] = std::max(h_max[i], hLow[i]);
1969 heta_min[i] = std::min(heta_min[i], hetaLow[i]);
1970 heta_max[i] = std::max(heta_max[i], hetaLow[i]);
1971 const double one_over_hLow =
1972 2. * hLow[i] /
1973 (hLow[i] * hLow[i] + std::pow(fmax(hLow[i], hEps), 2));
1974 kin_max[i] = fmax(kin_max[i],
1975 0.5 * one_over_hLow *
1976 (huLow[i] * huLow[i] + hvLow[i] * hvLow[i]));
1977 }
1978
1979 // clean up hLow from round off error
1980 if (dt < 1e-2 && hLow[i] < -hEps) {
1981 std::cout << "Low-order water depth is negative !!! " << hLow[i] << "\n"
1982 << "hLow[i] + hEps !!! " << hLow[i] + hEps
1983 << "\n"
1984 << "hEps !!! " << hEps << "\n"
1985 << " ... aborting!" << std::endl;
1986 abort();
1987 } else {
1988 if (hLow[i] <= hEps) {
1989 // Clean up low-order h and heta
1990 hLow[i] = 0.;
1991 }
1992 }
1993
1994#if IF_DEBUGGING
1995 if (h_min[i] < 0.) {
1996 std::cout << " \n "
1997 << " Minimum water depth is negative !!! " << h_min[i]
1998 << "\n "
1999 << " hLow[i] !!! " << hLow[i] << "\n "
2000 << " ... aborting!"
2001 << "\n"
2002 << std::endl;
2003 } else {
2004 if (h_min[i] <= hEps) {
2005 // Clean up low-order h and heta
2006 h_min[i] = 0.;
2007 }
2008 }
2009
2010 if (h_max[i] < 0.) {
2011 std::cout << " Maximum water depth is negative !!! " << h_max[i] << "\n"
2012 << " hLow[i] !!! " << hLow[i] << "\n "
2013 << " ... aborting!" << std::endl;
2014 abort();
2015 } else {
2016 if (h_max[i] <= hEps) {
2017 // Clean up low-order h and heta
2018 h_max[i] = 0.;
2019 }
2020 }
2021#endif
2022
2023 /* Relaxation of bounds */
2024 const double s_i = std::pow(std::sqrt(std::sqrt(mi / size_of_domain)), 3);
2025 const double urelax_i = 1. + s_i;
2026 const double drelax_i = 1. - s_i;
2027
2028 kin_max[i] =
2029 std::max((1. + std::sqrt(mi / size_of_domain)) * kin_max[i], 0.);
2030 h_min[i] =
2031 std::max(drelax_i * h_min[i], h_min[i] - std::abs(bar_deltaSqd_h[i]));
2032 h_max[i] =
2033 std::min(urelax_i * h_max[i], h_max[i] + std::abs(bar_deltaSqd_h[i]));
2034 heta_min[i] = std::max(drelax_i * heta_min[i],
2035 heta_min[i] - std::abs(bar_deltaSqd_heta[i]));
2036 heta_max[i] = std::min(urelax_i * heta_max[i],
2037 heta_max[i] + std::abs(bar_deltaSqd_heta[i]));
2038
2039#if IF_DEBUGGING
2040 if (hLow[i] > h_max[i] || hLow[i] < h_min[i]) {
2041 std::cout << " --- We have a major problem (h bounds) --- "
2042 << std::setprecision(15) << std::endl;
2043 std::cout << "hLow[i] = " << hLow[i] << " \n "
2044 << "h_min[i] = " << h_min[i] << " \n "
2045 << "h_max[i] = " << h_max[i] << " \n "
2046 << "Diff max = " << h_max[i] - hLow[i] << " \n "
2047 << "Diff min = " << hLow[i] - h_min[i] << " \n " << std::endl;
2048 }
2049
2050 if (heta_max[i] - hetaLow[i] < -hEps * hEps ||
2051 hetaLow[i] - heta_min[i] < -hEps * hEps) {
2052 std::cout << " --- We have a major problem (heta bounds) --- "
2053 << std::setprecision(15) << std::endl;
2054 std::cout << "hetaLow[i] = " << hetaLow[i] << " \n "
2055 << "heta_min[i] = " << heta_min[i] << " \n "
2056 << "heta_max[i] = " << heta_max[i] << " \n "
2057 << "Diff max = " << heta_max[i] - hetaLow[i] << " \n "
2058 << "Diff min = " << hetaLow[i] - heta_min[i] << " \n "
2059 << std::endl;
2060 }
2061#endif
2062 } // i loop ends here
2063
2064 // ********** END OF LOOP IN DOFs ********** //
2065 } // end calculateBoundsAndHighOrderRHS
2066
2068 xt::pyarray<double> &mesh_trial_ref = args.array<double>("mesh_trial_ref");
2069 xt::pyarray<double> &mesh_grad_trial_ref =
2070 args.array<double>("mesh_grad_trial_ref");
2071 xt::pyarray<double> &mesh_dof = args.array<double>("mesh_dof");
2072 xt::pyarray<int> &mesh_l2g = args.array<int>("mesh_l2g");
2073 xt::pyarray<double> &dV_ref = args.array<double>("dV_ref");
2074 xt::pyarray<double> &h_trial_ref = args.array<double>("h_trial_ref");
2075 xt::pyarray<double> &h_grad_trial_ref =
2076 args.array<double>("h_grad_trial_ref");
2077 xt::pyarray<double> &h_test_ref = args.array<double>("h_test_ref");
2078 xt::pyarray<double> &h_grad_test_ref =
2079 args.array<double>("h_grad_test_ref");
2080 xt::pyarray<double> &vel_trial_ref = args.array<double>("vel_trial_ref");
2081 xt::pyarray<double> &vel_grad_trial_ref =
2082 args.array<double>("vel_grad_trial_ref");
2083 xt::pyarray<double> &vel_test_ref = args.array<double>("vel_test_ref");
2084 xt::pyarray<double> &vel_grad_test_ref =
2085 args.array<double>("vel_grad_test_ref");
2086 xt::pyarray<double> &mesh_trial_trace_ref =
2087 args.array<double>("mesh_trial_trace_ref");
2088 xt::pyarray<double> &mesh_grad_trial_trace_ref =
2089 args.array<double>("mesh_grad_trial_trace_ref");
2090 xt::pyarray<double> &h_trial_trace_ref =
2091 args.array<double>("h_trial_trace_ref");
2092 xt::pyarray<double> &h_grad_trial_trace_ref =
2093 args.array<double>("h_grad_trial_trace_ref");
2094 xt::pyarray<double> &h_test_trace_ref =
2095 args.array<double>("h_test_trace_ref");
2096 xt::pyarray<double> &h_grad_test_trace_ref =
2097 args.array<double>("h_grad_test_trace_ref");
2098 xt::pyarray<double> &vel_trial_trace_ref =
2099 args.array<double>("vel_trial_trace_ref");
2100 xt::pyarray<double> &vel_grad_trial_trace_ref =
2101 args.array<double>("vel_grad_trial_trace_ref");
2102 xt::pyarray<double> &vel_test_trace_ref =
2103 args.array<double>("vel_test_trace_ref");
2104 xt::pyarray<double> &vel_grad_test_trace_ref =
2105 args.array<double>("vel_grad_test_trace_ref");
2106 xt::pyarray<double> &normal_ref = args.array<double>("normal_ref");
2107 xt::pyarray<double> &boundaryJac_ref =
2108 args.array<double>("boundaryJac_ref");
2109 xt::pyarray<double> &elementDiameter =
2110 args.array<double>("elementDiameter");
2111 int nElements_global = args.scalar<int>("nElements_global");
2112 double g = args.scalar<double>("g");
2113 xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
2114 xt::pyarray<int> &h_l2g = args.array<int>("h_l2g");
2115 xt::pyarray<int> &vel_l2g = args.array<int>("vel_l2g");
2116 xt::pyarray<double> &h_dof_old = args.array<double>("h_dof_old");
2117 xt::pyarray<double> &hu_dof_old = args.array<double>("hu_dof_old");
2118 xt::pyarray<double> &hv_dof_old = args.array<double>("hv_dof_old");
2119 xt::pyarray<double> &heta_dof_old = args.array<double>("heta_dof_old");
2120 xt::pyarray<double> &hw_dof_old = args.array<double>("hw_dof_old");
2121 xt::pyarray<double> &hbeta_dof_old = args.array<double>("hbeta_dof_old");
2122 xt::pyarray<double> &b_dof = args.array<double>("b_dof");
2123 xt::pyarray<double> &h_dof = args.array<double>("h_dof");
2124 xt::pyarray<double> &hu_dof = args.array<double>("hu_dof");
2125 xt::pyarray<double> &hv_dof = args.array<double>("hv_dof");
2126 xt::pyarray<double> &heta_dof = args.array<double>("heta_dof");
2127 xt::pyarray<double> &hw_dof = args.array<double>("hw_dof");
2128 xt::pyarray<double> &hbeta_dof = args.array<double>("hbeta_dof");
2129 xt::pyarray<double> &q_cfl = args.array<double>("q_cfl");
2130 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
2131 args.array<int>("sdInfo_hu_hu_rowptr");
2132 xt::pyarray<int> &sdInfo_hu_hu_colind =
2133 args.array<int>("sdInfo_hu_hu_colind");
2134 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
2135 args.array<int>("sdInfo_hu_hv_rowptr");
2136 xt::pyarray<int> &sdInfo_hu_hv_colind =
2137 args.array<int>("sdInfo_hu_hv_colind");
2138 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
2139 args.array<int>("sdInfo_hv_hv_rowptr");
2140 xt::pyarray<int> &sdInfo_hv_hv_colind =
2141 args.array<int>("sdInfo_hv_hv_colind");
2142 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
2143 args.array<int>("sdInfo_hv_hu_rowptr");
2144 xt::pyarray<int> &sdInfo_hv_hu_colind =
2145 args.array<int>("sdInfo_hv_hu_colind");
2146 int offset_h = args.scalar<int>("offset_h");
2147 int offset_hu = args.scalar<int>("offset_hu");
2148 int offset_hv = args.scalar<int>("offset_hv");
2149 int offset_heta = args.scalar<int>("offset_heta");
2150 int offset_hw = args.scalar<int>("offset_hw");
2151 int offset_hbeta = args.scalar<int>("offset_hbeta");
2152 int stride_h = args.scalar<int>("stride_h");
2153 int stride_hu = args.scalar<int>("stride_hu");
2154 int stride_hv = args.scalar<int>("stride_hv");
2155 int stride_heta = args.scalar<int>("stride_heta");
2156 int stride_hw = args.scalar<int>("stride_hw");
2157 int stride_hbeta = args.scalar<int>("stride_hbeta");
2158 xt::pyarray<double> &globalResidual = args.array<double>("globalResidual");
2159 int nExteriorElementBoundaries_global =
2160 args.scalar<int>("nExteriorElementBoundaries_global");
2161 xt::pyarray<int> &exteriorElementBoundariesArray =
2162 args.array<int>("exteriorElementBoundariesArray");
2163 xt::pyarray<int> &elementBoundaryElementsArray =
2164 args.array<int>("elementBoundaryElementsArray");
2165 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
2166 args.array<int>("elementBoundaryLocalElementBoundariesArray");
2167 xt::pyarray<int> &isDOFBoundary_h = args.array<int>("isDOFBoundary_h");
2168 xt::pyarray<int> &isDOFBoundary_hu = args.array<int>("isDOFBoundary_hu");
2169 xt::pyarray<int> &isDOFBoundary_hv = args.array<int>("isDOFBoundary_hv");
2170 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
2171 args.array<int>("isAdvectiveFluxBoundary_h");
2172 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
2173 args.array<int>("isAdvectiveFluxBoundary_hu");
2174 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
2175 args.array<int>("isAdvectiveFluxBoundary_hv");
2176 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
2177 args.array<int>("isDiffusiveFluxBoundary_hu");
2178 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
2179 args.array<int>("isDiffusiveFluxBoundary_hv");
2180 xt::pyarray<double> &ebqe_bc_h_ext = args.array<double>("ebqe_bc_h_ext");
2181 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
2182 args.array<double>("ebqe_bc_flux_mass_ext");
2183 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
2184 args.array<double>("ebqe_bc_flux_mom_hu_adv_ext");
2185 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
2186 args.array<double>("ebqe_bc_flux_mom_hv_adv_ext");
2187 xt::pyarray<double> &ebqe_bc_hu_ext = args.array<double>("ebqe_bc_hu_ext");
2188 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
2189 args.array<double>("ebqe_bc_flux_hu_diff_ext");
2190 xt::pyarray<double> &ebqe_penalty_ext =
2191 args.array<double>("ebqe_penalty_ext");
2192 xt::pyarray<double> &ebqe_bc_hv_ext = args.array<double>("ebqe_bc_hv_ext");
2193 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
2194 args.array<double>("ebqe_bc_flux_hv_diff_ext");
2195 xt::pyarray<double> &q_velocity = args.array<double>("q_velocity");
2196 xt::pyarray<double> &ebqe_velocity = args.array<double>("ebqe_velocity");
2197 xt::pyarray<double> &flux = args.array<double>("flux");
2198 xt::pyarray<double> &elementResidual_h_save =
2199 args.array<double>("elementResidual_h_save");
2200 const xt::pyarray<double> &Cx = args.array<double>("Cx");
2201 const xt::pyarray<double> &Cy = args.array<double>("Cy");
2202 const xt::pyarray<double> &CTx = args.array<double>("CTx");
2203 const xt::pyarray<double> &CTy = args.array<double>("CTy");
2204 const int numDOFsPerEqn = args.scalar<int>("numDOFsPerEqn");
2205 const xt::pyarray<int> &csrRowIndeces_DofLoops =
2206 args.array<int>("csrRowIndeces_DofLoops");
2207 const xt::pyarray<int> &csrColumnOffsets_DofLoops =
2208 args.array<int>("csrColumnOffsets_DofLoops");
2209 const xt::pyarray<double> &lumped_mass_matrix =
2210 args.array<double>("lumped_mass_matrix");
2211 const double cfl_run = args.scalar<double>("cfl_run");
2212 const double hEps = args.scalar<double>("hEps");
2213 xt::pyarray<double> &hnp1_at_quad_point =
2214 args.array<double>("hnp1_at_quad_point");
2215 xt::pyarray<double> &hunp1_at_quad_point =
2216 args.array<double>("hunp1_at_quad_point");
2217 xt::pyarray<double> &hvnp1_at_quad_point =
2218 args.array<double>("hvnp1_at_quad_point");
2219 xt::pyarray<double> &hetanp1_at_quad_point =
2220 args.array<double>("hetanp1_at_quad_point");
2221 xt::pyarray<double> &hwnp1_at_quad_point =
2222 args.array<double>("hwnp1_at_quad_point");
2223 xt::pyarray<double> &hbetanp1_at_quad_point =
2224 args.array<double>("hbetanp1_at_quad_point");
2225 int LUMPED_MASS_MATRIX = args.scalar<int>("LUMPED_MASS_MATRIX");
2226 double dt = args.scalar<double>("dt");
2227 xt::pyarray<double> &quantDOFs = args.array<double>("quantDOFs");
2228 int SECOND_CALL_CALCULATE_RESIDUAL =
2229 args.scalar<int>("SECOND_CALL_CALCULATE_RESIDUAL");
2230 int COMPUTE_NORMALS = args.scalar<int>("COMPUTE_NORMALS");
2231 xt::pyarray<double> &normalx = args.array<double>("normalx");
2232 xt::pyarray<double> &normaly = args.array<double>("normaly");
2233 const int lstage = args.scalar<int>("lstage");
2234 const xt::pyarray<double> &MassMatrix = args.array<double>("MassMatrix");
2235 const xt::pyarray<double> &RHS_high_h = args.array<double>("RHS_high_h");
2236 const xt::pyarray<double> &RHS_high_hu = args.array<double>("RHS_high_hu");
2237 const xt::pyarray<double> &RHS_high_hv = args.array<double>("RHS_high_hv");
2238 const xt::pyarray<double> &RHS_high_heta =
2239 args.array<double>("RHS_high_heta");
2240 const xt::pyarray<double> &RHS_high_hw = args.array<double>("RHS_high_hw");
2241 const xt::pyarray<double> &RHS_high_hbeta =
2242 args.array<double>("RHS_high_hbeta");
2243
2245 // ********** CELL LOOPS ********** //
2247 // To compute:
2248 // * Time derivative term
2249 // * Cell based CFL
2250 // * Velocity and soln at quad points (for other models)
2251 for (int eN = 0; eN < nElements_global; eN++) {
2252 // declare local storage for element residual and initialize
2253 double elementResidual_h[nDOF_test_element],
2254 elementResidual_hu[nDOF_test_element],
2255 elementResidual_hv[nDOF_test_element],
2256 elementResidual_heta[nDOF_test_element],
2257 elementResidual_hw[nDOF_test_element],
2258 elementResidual_hbeta[nDOF_test_element];
2259
2260 for (int i = 0; i < nDOF_test_element; i++) {
2261 elementResidual_h[i] = 0.0;
2262 elementResidual_hu[i] = 0.0;
2263 elementResidual_hv[i] = 0.0;
2264 elementResidual_heta[i] = 0.0;
2265 elementResidual_hw[i] = 0.0;
2266 elementResidual_hbeta[i] = 0.0;
2267 }
2268 //
2269 // loop over quadrature points and compute integrands
2270 //
2271 for (int k = 0; k < nQuadraturePoints_element; k++) {
2272 // compute indices and declare local storage
2273 int eN_k = eN * nQuadraturePoints_element + k,
2274 eN_k_nSpace = eN_k * nSpace,
2275 eN_nDOF_trial_element = eN * nDOF_trial_element;
2276 double h = 0.0, hu = 0.0, hv = 0.0, heta = 0.0, hw = 0.0,
2277 hbeta = 0.0, // solution at current time
2278 h_old = 0.0, hu_old = 0.0, hv_old = 0.0, heta_old = 0.0,
2279 hw_old = 0.0,
2280 hbeta_old = 0.0, // solution at lstage
2281 jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
2282 h_test_dV[nDOF_trial_element], dV, x, y, xt, yt;
2283 // get jacobian, etc for mapping reference element
2284 ck.calculateMapping_element(
2285 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
2286 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
2287 // get the physical integration weight
2288 dV = fabs(jacDet) * dV_ref[k];
2289 {
2290 // porosity weighting: storage is phi U
2291 double phi_q = 0.;
2292 ck.valFromDOF(porosity_dof.data(),
2293 &h_l2g.data()[eN * nDOF_trial_element],
2294 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
2295 dV *= phi_q;
2296 }
2297 // get the solution at current time
2298 ck.valFromDOF(h_dof.data(), &h_l2g.data()[eN_nDOF_trial_element],
2299 &h_trial_ref.data()[k * nDOF_trial_element], h);
2300 ck.valFromDOF(hu_dof.data(), &vel_l2g[eN_nDOF_trial_element],
2301 &vel_trial_ref.data()[k * nDOF_trial_element], hu);
2302 ck.valFromDOF(hv_dof.data(), &vel_l2g[eN_nDOF_trial_element],
2303 &vel_trial_ref.data()[k * nDOF_trial_element], hv);
2304 ck.valFromDOF(heta_dof.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2305 &vel_trial_ref.data()[k * nDOF_trial_element], heta);
2306 ck.valFromDOF(hw_dof.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2307 &vel_trial_ref.data()[k * nDOF_trial_element], hw);
2308 ck.valFromDOF(hbeta_dof.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2309 &vel_trial_ref.data()[k * nDOF_trial_element], hbeta);
2310 // get the solution at the lstage
2311 ck.valFromDOF(h_dof_old.data(), &h_l2g.data()[eN_nDOF_trial_element],
2312 &h_trial_ref.data()[k * nDOF_trial_element], h_old);
2313 ck.valFromDOF(hu_dof_old.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2314 &vel_trial_ref.data()[k * nDOF_trial_element], hu_old);
2315 ck.valFromDOF(hv_dof_old.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2316 &vel_trial_ref.data()[k * nDOF_trial_element], hv_old);
2317 ck.valFromDOF(heta_dof_old.data(), &vel_l2g[eN_nDOF_trial_element],
2318 &vel_trial_ref.data()[k * nDOF_trial_element], heta_old);
2319 ck.valFromDOF(hw_dof_old.data(), &vel_l2g.data()[eN_nDOF_trial_element],
2320 &vel_trial_ref.data()[k * nDOF_trial_element], hw_old);
2321 ck.valFromDOF(hbeta_dof_old.data(),
2322 &vel_l2g.data()[eN_nDOF_trial_element],
2323 &vel_trial_ref.data()[k * nDOF_trial_element], hbeta_old);
2324 // calculate cell based CFL to keep a reference
2325 calculateCFL(elementDiameter.data()[eN], g, h_old, hu_old, hv_old, hEps,
2326 q_cfl[eN_k]);
2327 // precalculate test function products with integration weights
2328 for (int j = 0; j < nDOF_trial_element; j++)
2329 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
2330
2331 // SAVE VELOCITY // at quadrature points for other models to use
2332 q_velocity[eN_k_nSpace + 0] =
2333 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hu;
2334 q_velocity[eN_k_nSpace + 1] =
2335 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hv;
2336 hnp1_at_quad_point[eN_k] = h;
2337 hunp1_at_quad_point[eN_k] = hu;
2338 hvnp1_at_quad_point[eN_k] = hv;
2339 hetanp1_at_quad_point[eN_k] = heta;
2340 hwnp1_at_quad_point[eN_k] = hw;
2341 hbetanp1_at_quad_point[eN_k] = hbeta;
2342
2343 for (int i = 0; i < nDOF_test_element; i++) {
2344 // compute time derivative part of global residual. NOTE: no lumping
2345 elementResidual_h[i] += (h - h_old) * h_test_dV[i];
2346 elementResidual_hu[i] += (hu - hu_old) * h_test_dV[i];
2347 elementResidual_hv[i] += (hv - hv_old) * h_test_dV[i];
2348 elementResidual_heta[i] += (heta - heta_old) * h_test_dV[i];
2349 elementResidual_hw[i] += (hw - hw_old) * h_test_dV[i];
2350 elementResidual_hbeta[i] += (hbeta - hbeta_old) * h_test_dV[i];
2351 }
2352 }
2353 // distribute
2354 for (int i = 0; i < nDOF_test_element; i++) {
2355 int eN_i = eN * nDOF_test_element + i;
2356
2357 // global i-th index for h (this is same for vel_l2g)
2358 int h_gi = h_l2g[eN_i];
2359
2360 // distribute time derivative to global residual
2361 globalResidual[offset_h + stride_h * h_gi] += elementResidual_h[i];
2362 globalResidual[offset_hu + stride_hu * h_gi] += elementResidual_hu[i];
2363 globalResidual[offset_hv + stride_hv * h_gi] += elementResidual_hv[i];
2364 globalResidual[offset_heta + stride_heta * h_gi] +=
2365 elementResidual_heta[i];
2366 globalResidual[offset_hw + stride_hw * h_gi] += elementResidual_hw[i];
2367 globalResidual[offset_hbeta + stride_hbeta * h_gi] +=
2368 elementResidual_hbeta[i];
2369 }
2370 }
2371 // ********** END OF CELL LOOPS ********** //
2372
2373 if (SECOND_CALL_CALCULATE_RESIDUAL == 0) // This is to save some time
2374 {
2376 // ********** FIRST AND ONLY LOOP ON DOFs ********** //
2378 // To compute:
2379 // * High-order update with neumann series approximation
2380
2381 int ij = 0;
2382 for (int i = 0; i < numDOFsPerEqn; i++) {
2383
2384 // get things at ith node
2385 const double hi = h_dof_old[i];
2386 const double hui = hu_dof_old[i];
2387 const double hvi = hv_dof_old[i];
2388 const double hetai = heta_dof_old[i];
2389 const double hwi = hw_dof_old[i];
2390 const double hbetai = hbeta_dof_old[i];
2391 const double mi = lumped_mass_matrix[i];
2392
2393 double sum_RHS_h = 0.;
2394 double sum_RHS_hu = 0.;
2395 double sum_RHS_hv = 0.;
2396 double sum_RHS_heta = 0.;
2397 double sum_RHS_hw = 0.;
2398 double sum_RHS_hbeta = 0.;
2399
2400 double b_ij = 0., b_ji = 0.;
2401
2402 // loop over the sparsity pattern of the i-th DOF
2403 for (int offset = csrRowIndeces_DofLoops[i];
2404 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
2405
2406 int j = csrColumnOffsets_DofLoops[offset];
2407
2408 // get things at jth node
2409 const double mj = lumped_mass_matrix[j];
2410
2411 // define b_ij and b_ji
2412 if (j != i) {
2413 b_ij = (0. - MassMatrix[ij] / mj);
2414 b_ji = (0. - MassMatrix[ij] / mi);
2415 } else {
2416 b_ij = (1. - MassMatrix[ij] / mj);
2417 b_ji = (1. - MassMatrix[ij] / mi);
2418 }
2419
2420 // define sum for high-order RHS
2421 sum_RHS_h += b_ij * RHS_high_h[j] - b_ji * RHS_high_h[i];
2422 sum_RHS_hu += b_ij * RHS_high_hu[j] - b_ji * RHS_high_hu[i];
2423 sum_RHS_hv += b_ij * RHS_high_hv[j] - b_ji * RHS_high_hv[i];
2424 sum_RHS_heta += b_ij * RHS_high_heta[j] - b_ji * RHS_high_heta[i];
2425 sum_RHS_hw += b_ij * RHS_high_hw[j] - b_ji * RHS_high_hw[i];
2426 sum_RHS_hbeta += b_ij * RHS_high_hbeta[j] - b_ji * RHS_high_hbeta[i];
2427
2428 // update ij
2429 ij += 1;
2430 } // j loop ends here
2431
2432 /* Define global residual */
2433 // if (LUMPED_MASS_MATRIX == 1) {
2434 globalResidual[offset_h + stride_h * i] =
2435 hi + dt / mi * (RHS_high_h[i] + sum_RHS_h);
2436
2437 globalResidual[offset_hu + stride_hu * i] =
2438 hui + dt / mi * (RHS_high_hu[i] + sum_RHS_hu);
2439
2440 globalResidual[offset_hv + stride_hv * i] =
2441 hvi + dt / mi * (RHS_high_hv[i] + sum_RHS_hv);
2442
2443 globalResidual[offset_heta + stride_heta * i] =
2444 hetai + dt / mi * (RHS_high_heta[i] + sum_RHS_heta);
2445
2446 globalResidual[offset_hw + stride_hw * i] =
2447 hwi + dt / mi * (RHS_high_hw[i] + sum_RHS_hw);
2448
2449 globalResidual[offset_hbeta + stride_hbeta * i] =
2450 hbetai + dt / mi * (RHS_high_hbeta[i] + sum_RHS_hbeta);
2451
2452 // clean up potential negative water height due to machine precision
2453 if (globalResidual[offset_h + stride_h * i] >= -hEps &&
2454 globalResidual[offset_h + stride_h * i] < hEps) {
2455 globalResidual[offset_h + stride_h * i] = 0.;
2456 }
2457 }
2458 // ********** END OF LOOP IN DOFs ********** //
2459 } // end SECOND_CALL_CALCULATE_RESIDUAL
2460
2461 // ********** COMPUTE NORMALS ********** //
2462 if (COMPUTE_NORMALS == 1) {
2463 // This is to identify the normals and create a vector of normal
2464 // components
2465 for (int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++) {
2466 int
2467 ebN = exteriorElementBoundariesArray[ebNE],
2468 eN = elementBoundaryElementsArray[ebN * 2 + 0],
2469 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN * 2 + 0];
2470 double normal[3];
2471 { // "Loop" in quad points
2472 int kb = 0; // NOTE: I need to consider just one quad point since
2473 // the element is not curved so the normal is constant
2474 // per element
2475 int ebN_local_kb =
2476 ebN_local * nQuadraturePoints_elementBoundary + kb;
2477 double jac_ext[nSpace * nSpace], jacDet_ext,
2478 jacInv_ext[nSpace * nSpace], boundaryJac[nSpace * (nSpace - 1)],
2479 metricTensor[(nSpace - 1) * (nSpace - 1)], metricTensorDetSqrt,
2480 x_ext, y_ext;
2481 /* compute information about mapping from reference element to
2482 * physical element */
2483 ck.calculateMapping_elementBoundary(
2484 eN, ebN_local, kb, ebN_local_kb, mesh_dof.data(), mesh_l2g.data(),
2485 mesh_trial_trace_ref.data(), mesh_grad_trial_trace_ref.data(),
2486 boundaryJac_ref.data(), jac_ext, jacDet_ext, jacInv_ext,
2487 boundaryJac, metricTensor, metricTensorDetSqrt, normal_ref.data(),
2488 normal, x_ext, y_ext);
2489 }
2490 // distribute the normal vectors
2491 for (int i = 0; i < nDOF_test_element; i++) {
2492 int eN_i = eN * nDOF_test_element + i;
2493 int gi = h_l2g[eN_i];
2494 normalx[gi] += 0.5 * normal[0] * (i == ebN_local ? 0. : 1.);
2495 normaly[gi] += 0.5 * normal[1] * (i == ebN_local ? 0. : 1.);
2496 }
2497 }
2498 // normalize
2499 for (int gi = 0; gi < numDOFsPerEqn; gi++) {
2500 double norm_factor =
2501 sqrt(std::pow(normalx[gi], 2) + std::pow(normaly[gi], 2));
2502 if (norm_factor != 0) {
2503 normalx[gi] /= norm_factor;
2504 normaly[gi] /= norm_factor;
2505 }
2506 }
2507 }
2508 // ********** END OF COMPUTING NORMALS ********** //
2509 } // end calculateResidual
2510
2512 xt::pyarray<double> &mesh_trial_ref = args.array<double>("mesh_trial_ref");
2513 xt::pyarray<double> &mesh_grad_trial_ref =
2514 args.array<double>("mesh_grad_trial_ref");
2515 xt::pyarray<double> &mesh_dof = args.array<double>("mesh_dof");
2516 xt::pyarray<double> &mesh_velocity_dof =
2517 args.array<double>("mesh_velocity_dof");
2518 double MOVING_DOMAIN = args.scalar<double>("MOVING_DOMAIN");
2519 xt::pyarray<int> &mesh_l2g = args.array<int>("mesh_l2g");
2520 xt::pyarray<double> &dV_ref = args.array<double>("dV_ref");
2521 xt::pyarray<double> &h_trial_ref = args.array<double>("h_trial_ref");
2522 xt::pyarray<double> &h_grad_trial_ref =
2523 args.array<double>("h_grad_trial_ref");
2524 xt::pyarray<double> &h_test_ref = args.array<double>("h_test_ref");
2525 xt::pyarray<double> &h_grad_test_ref =
2526 args.array<double>("h_grad_test_ref");
2527 xt::pyarray<double> &vel_trial_ref = args.array<double>("vel_trial_ref");
2528 xt::pyarray<double> &vel_grad_trial_ref =
2529 args.array<double>("vel_grad_trial_ref");
2530 xt::pyarray<double> &vel_test_ref = args.array<double>("vel_test_ref");
2531 xt::pyarray<double> &vel_grad_test_ref =
2532 args.array<double>("vel_grad_test_ref");
2533 xt::pyarray<double> &mesh_trial_trace_ref =
2534 args.array<double>("mesh_trial_trace_ref");
2535 xt::pyarray<double> &mesh_grad_trial_trace_ref =
2536 args.array<double>("mesh_grad_trial_trace_ref");
2537 xt::pyarray<double> &dS_ref = args.array<double>("dS_ref");
2538 xt::pyarray<double> &h_trial_trace_ref =
2539 args.array<double>("h_trial_trace_ref");
2540 xt::pyarray<double> &h_grad_trial_trace_ref =
2541 args.array<double>("h_grad_trial_trace_ref");
2542 xt::pyarray<double> &h_test_trace_ref =
2543 args.array<double>("h_test_trace_ref");
2544 xt::pyarray<double> &h_grad_test_trace_ref =
2545 args.array<double>("h_grad_test_trace_ref");
2546 xt::pyarray<double> &vel_trial_trace_ref =
2547 args.array<double>("vel_trial_trace_ref");
2548 xt::pyarray<double> &vel_grad_trial_trace_ref =
2549 args.array<double>("vel_grad_trial_trace_ref");
2550 xt::pyarray<double> &vel_test_trace_ref =
2551 args.array<double>("vel_test_trace_ref");
2552 xt::pyarray<double> &vel_grad_test_trace_ref =
2553 args.array<double>("vel_grad_test_trace_ref");
2554 xt::pyarray<double> &normal_ref = args.array<double>("normal_ref");
2555 xt::pyarray<double> &boundaryJac_ref =
2556 args.array<double>("boundaryJac_ref");
2557 xt::pyarray<double> &elementDiameter =
2558 args.array<double>("elementDiameter");
2559 int nElements_global = args.scalar<int>("nElements_global");
2560 double g = args.scalar<double>("g");
2561 xt::pyarray<int> &h_l2g = args.array<int>("h_l2g");
2562 xt::pyarray<int> &vel_l2g = args.array<int>("vel_l2g");
2563 xt::pyarray<double> &b_dof = args.array<double>("b_dof");
2564 xt::pyarray<double> &h_dof = args.array<double>("h_dof");
2565 xt::pyarray<double> &hu_dof = args.array<double>("hu_dof");
2566 xt::pyarray<double> &hv_dof = args.array<double>("hv_dof");
2567 xt::pyarray<double> &heta_dof = args.array<double>("heta_dof");
2568 xt::pyarray<double> &hw_dof = args.array<double>("hw_dof");
2569 xt::pyarray<double> &hbeta_dof = args.array<double>("hbeta_dof");
2570 xt::pyarray<double> &q_cfl = args.array<double>("q_cfl");
2571 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
2572 args.array<int>("sdInfo_hu_hu_rowptr");
2573 xt::pyarray<int> &sdInfo_hu_hu_colind =
2574 args.array<int>("sdInfo_hu_hu_colind");
2575 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
2576 args.array<int>("sdInfo_hu_hv_rowptr");
2577 xt::pyarray<int> &sdInfo_hu_hv_colind =
2578 args.array<int>("sdInfo_hu_hv_colind");
2579 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
2580 args.array<int>("sdInfo_hv_hv_rowptr");
2581 xt::pyarray<int> &sdInfo_hv_hv_colind =
2582 args.array<int>("sdInfo_hv_hv_colind");
2583 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
2584 args.array<int>("sdInfo_hv_hu_rowptr");
2585 xt::pyarray<int> &sdInfo_hv_hu_colind =
2586 args.array<int>("sdInfo_hv_hu_colind");
2587 xt::pyarray<int> &csrRowIndeces_h_h = args.array<int>("csrRowIndeces_h_h");
2588 xt::pyarray<int> &csrColumnOffsets_h_h =
2589 args.array<int>("csrColumnOffsets_h_h");
2590 xt::pyarray<int> &csrRowIndeces_h_hu =
2591 args.array<int>("csrRowIndeces_h_hu");
2592 xt::pyarray<int> &csrColumnOffsets_h_hu =
2593 args.array<int>("csrColumnOffsets_h_hu");
2594 xt::pyarray<int> &csrRowIndeces_h_hv =
2595 args.array<int>("csrRowIndeces_h_hv");
2596 xt::pyarray<int> &csrColumnOffsets_h_hv =
2597 args.array<int>("csrColumnOffsets_h_hv");
2598 xt::pyarray<int> &csrRowIndeces_h_heta =
2599 args.array<int>("csrRowIndeces_h_heta");
2600 xt::pyarray<int> &csrColumnOffsets_h_heta =
2601 args.array<int>("csrColumnOffsets_h_heta");
2602 xt::pyarray<int> &csrRowIndeces_h_hw =
2603 args.array<int>("csrRowIndeces_h_hw");
2604 xt::pyarray<int> &csrColumnOffsets_h_hw =
2605 args.array<int>("csrColumnOffsets_h_hw");
2606 xt::pyarray<int> &csrRowIndeces_h_hbeta =
2607 args.array<int>("csrRowIndeces_h_hbeta");
2608 xt::pyarray<int> &csrColumnOffsets_h_hbeta =
2609 args.array<int>("csrColumnOffsets_h_hbeta");
2610 xt::pyarray<int> &csrRowIndeces_hu_h =
2611 args.array<int>("csrRowIndeces_hu_h");
2612 xt::pyarray<int> &csrColumnOffsets_hu_h =
2613 args.array<int>("csrColumnOffsets_hu_h");
2614 xt::pyarray<int> &csrRowIndeces_hu_hu =
2615 args.array<int>("csrRowIndeces_hu_hu");
2616 xt::pyarray<int> &csrColumnOffsets_hu_hu =
2617 args.array<int>("csrColumnOffsets_hu_hu");
2618 xt::pyarray<int> &csrRowIndeces_hu_hv =
2619 args.array<int>("csrRowIndeces_hu_hv");
2620 xt::pyarray<int> &csrColumnOffsets_hu_hv =
2621 args.array<int>("csrColumnOffsets_hu_hv");
2622 xt::pyarray<int> &csrRowIndeces_hu_heta =
2623 args.array<int>("csrRowIndeces_hu_heta");
2624 xt::pyarray<int> &csrColumnOffsets_hu_heta =
2625 args.array<int>("csrColumnOffsets_hu_heta");
2626 xt::pyarray<int> &csrRowIndeces_hu_hw =
2627 args.array<int>("csrRowIndeces_hu_hw");
2628 xt::pyarray<int> &csrColumnOffsets_hu_hw =
2629 args.array<int>("csrColumnOffsets_hu_hw");
2630 xt::pyarray<int> &csrRowIndeces_hu_hbeta =
2631 args.array<int>("csrRowIndeces_hu_hbeta");
2632 xt::pyarray<int> &csrColumnOffsets_hu_hbeta =
2633 args.array<int>("csrColumnOffsets_hu_hbeta");
2634 xt::pyarray<int> &csrRowIndeces_hv_h =
2635 args.array<int>("csrRowIndeces_hv_h");
2636 xt::pyarray<int> &csrColumnOffsets_hv_h =
2637 args.array<int>("csrColumnOffsets_hv_h");
2638 xt::pyarray<int> &csrRowIndeces_hv_hu =
2639 args.array<int>("csrRowIndeces_hv_hu");
2640 xt::pyarray<int> &csrColumnOffsets_hv_hu =
2641 args.array<int>("csrColumnOffsets_hv_hu");
2642 xt::pyarray<int> &csrRowIndeces_hv_hv =
2643 args.array<int>("csrRowIndeces_hv_hv");
2644 xt::pyarray<int> &csrColumnOffsets_hv_hv =
2645 args.array<int>("csrColumnOffsets_hv_hv");
2646 xt::pyarray<int> &csrRowIndeces_hv_heta =
2647 args.array<int>("csrRowIndeces_hv_heta");
2648 xt::pyarray<int> &csrColumnOffsets_hv_heta =
2649 args.array<int>("csrColumnOffsets_hv_heta");
2650 xt::pyarray<int> &csrRowIndeces_hv_hw =
2651 args.array<int>("csrRowIndeces_hv_hw");
2652 xt::pyarray<int> &csrColumnOffsets_hv_hw =
2653 args.array<int>("csrColumnOffsets_hv_hw");
2654 xt::pyarray<int> &csrRowIndeces_hv_hbeta =
2655 args.array<int>("csrRowIndeces_hv_hbeta");
2656 xt::pyarray<int> &csrColumnOffsets_hv_hbeta =
2657 args.array<int>("csrColumnOffsets_hv_hbeta");
2658 xt::pyarray<int> &csrRowIndeces_heta_h =
2659 args.array<int>("csrRowIndeces_heta_h");
2660 xt::pyarray<int> &csrColumnOffsets_heta_h =
2661 args.array<int>("csrColumnOffsets_heta_h");
2662 xt::pyarray<int> &csrRowIndeces_heta_hu =
2663 args.array<int>("csrRowIndeces_heta_hu");
2664 xt::pyarray<int> &csrColumnOffsets_heta_hu =
2665 args.array<int>("csrColumnOffsets_heta_hu");
2666 xt::pyarray<int> &csrRowIndeces_heta_hv =
2667 args.array<int>("csrRowIndeces_heta_hv");
2668 xt::pyarray<int> &csrColumnOffsets_heta_hv =
2669 args.array<int>("csrColumnOffsets_heta_hv");
2670 xt::pyarray<int> &csrRowIndeces_heta_heta =
2671 args.array<int>("csrRowIndeces_heta_heta");
2672 xt::pyarray<int> &csrColumnOffsets_heta_heta =
2673 args.array<int>("csrColumnOffsets_heta_heta");
2674 xt::pyarray<int> &csrRowIndeces_heta_hw =
2675 args.array<int>("csrRowIndeces_heta_hw");
2676 xt::pyarray<int> &csrColumnOffsets_heta_hw =
2677 args.array<int>("csrColumnOffsets_heta_hw");
2678 xt::pyarray<int> &csrRowIndeces_heta_hbeta =
2679 args.array<int>("csrRowIndeces_heta_hbeta");
2680 xt::pyarray<int> &csrColumnOffsets_heta_hbeta =
2681 args.array<int>("csrColumnOffsets_heta_hbeta");
2682 xt::pyarray<int> &csrRowIndeces_hw_h =
2683 args.array<int>("csrRowIndeces_hw_h");
2684 xt::pyarray<int> &csrColumnOffsets_hw_h =
2685 args.array<int>("csrColumnOffsets_hw_h");
2686 xt::pyarray<int> &csrRowIndeces_hw_hu =
2687 args.array<int>("csrRowIndeces_hw_hu");
2688 xt::pyarray<int> &csrColumnOffsets_hw_hu =
2689 args.array<int>("csrColumnOffsets_hw_hu");
2690 xt::pyarray<int> &csrRowIndeces_hw_hv =
2691 args.array<int>("csrRowIndeces_hw_hv");
2692 xt::pyarray<int> &csrColumnOffsets_hw_hv =
2693 args.array<int>("csrColumnOffsets_hw_hv");
2694 xt::pyarray<int> &csrRowIndeces_hw_heta =
2695 args.array<int>("csrRowIndeces_hw_heta");
2696 xt::pyarray<int> &csrColumnOffsets_hw_heta =
2697 args.array<int>("csrColumnOffsets_hw_heta");
2698 xt::pyarray<int> &csrRowIndeces_hw_hw =
2699 args.array<int>("csrRowIndeces_hw_hw");
2700 xt::pyarray<int> &csrColumnOffsets_hw_hw =
2701 args.array<int>("csrColumnOffsets_hw_hw");
2702 xt::pyarray<int> &csrRowIndeces_hw_hbeta =
2703 args.array<int>("csrRowIndeces_hw_hbeta");
2704 xt::pyarray<int> &csrColumnOffsets_hw_hbeta =
2705 args.array<int>("csrColumnOffsets_hw_hbeta");
2706 //
2707 xt::pyarray<int> &csrRowIndeces_hbeta_h =
2708 args.array<int>("csrRowIndeces_hbeta_h");
2709 xt::pyarray<int> &csrColumnOffsets_hbeta_h =
2710 args.array<int>("csrColumnOffsets_hbeta_h");
2711 xt::pyarray<int> &csrRowIndeces_hbeta_hu =
2712 args.array<int>("csrRowIndeces_hbeta_hu");
2713 xt::pyarray<int> &csrColumnOffsets_hbeta_hu =
2714 args.array<int>("csrColumnOffsets_hbeta_hu");
2715 xt::pyarray<int> &csrRowIndeces_hbeta_hv =
2716 args.array<int>("csrRowIndeces_hbeta_hv");
2717 xt::pyarray<int> &csrColumnOffsets_hbeta_hv =
2718 args.array<int>("csrColumnOffsets_hbeta_hv");
2719 xt::pyarray<int> &csrRowIndeces_hbeta_heta =
2720 args.array<int>("csrRowIndeces_hbeta_heta");
2721 xt::pyarray<int> &csrColumnOffsets_hbeta_heta =
2722 args.array<int>("csrColumnOffsets_hbeta_heta");
2723 xt::pyarray<int> &csrRowIndeces_hbeta_hw =
2724 args.array<int>("csrRowIndeces_hbeta_hw");
2725 xt::pyarray<int> &csrColumnOffsets_hbeta_hw =
2726 args.array<int>("csrColumnOffsets_hbeta_hw");
2727 xt::pyarray<int> &csrRowIndeces_hbeta_hbeta =
2728 args.array<int>("csrRowIndeces_hbeta_hbeta");
2729 xt::pyarray<int> &csrColumnOffsets_hbeta_hbeta =
2730 args.array<int>("csrColumnOffsets_hbeta_hbeta");
2731 xt::pyarray<double> &globalJacobian = args.array<double>("globalJacobian");
2732 xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
2733 int nExteriorElementBoundaries_global =
2734 args.scalar<int>("nExteriorElementBoundaries_global");
2735 xt::pyarray<int> &exteriorElementBoundariesArray =
2736 args.array<int>("exteriorElementBoundariesArray");
2737 xt::pyarray<int> &elementBoundaryElementsArray =
2738 args.array<int>("elementBoundaryElementsArray");
2739 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
2740 args.array<int>("elementBoundaryLocalElementBoundariesArray");
2741 xt::pyarray<int> &isDOFBoundary_h = args.array<int>("isDOFBoundary_h");
2742 xt::pyarray<int> &isDOFBoundary_hu = args.array<int>("isDOFBoundary_hu");
2743 xt::pyarray<int> &isDOFBoundary_hv = args.array<int>("isDOFBoundary_hv");
2744 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
2745 args.array<int>("isAdvectiveFluxBoundary_h");
2746 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
2747 args.array<int>("isAdvectiveFluxBoundary_hu");
2748 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
2749 args.array<int>("isAdvectiveFluxBoundary_hv");
2750 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
2751 args.array<int>("isDiffusiveFluxBoundary_hu");
2752 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
2753 args.array<int>("isDiffusiveFluxBoundary_hv");
2754 xt::pyarray<double> &ebqe_bc_h_ext = args.array<double>("ebqe_bc_h_ext");
2755 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
2756 args.array<double>("ebqe_bc_flux_mass_ext");
2757 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
2758 args.array<double>("ebqe_bc_flux_mom_hu_adv_ext");
2759 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
2760 args.array<double>("ebqe_bc_flux_mom_hv_adv_ext");
2761 xt::pyarray<double> &ebqe_bc_hu_ext = args.array<double>("ebqe_bc_hu_ext");
2762 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
2763 args.array<double>("ebqe_bc_flux_hu_diff_ext");
2764 xt::pyarray<double> &ebqe_penalty_ext =
2765 args.array<double>("ebqe_penalty_ext");
2766 xt::pyarray<double> &ebqe_bc_hv_ext = args.array<double>("ebqe_bc_hv_ext");
2767 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
2768 args.array<double>("ebqe_bc_flux_hv_diff_ext");
2769 xt::pyarray<int> &csrColumnOffsets_eb_h_h =
2770 args.array<int>("csrColumnOffsets_eb_h_h");
2771 xt::pyarray<int> &csrColumnOffsets_eb_h_hu =
2772 args.array<int>("csrColumnOffsets_eb_h_hu");
2773 xt::pyarray<int> &csrColumnOffsets_eb_h_hv =
2774 args.array<int>("csrColumnOffsets_eb_h_hv");
2775 xt::pyarray<int> &csrColumnOffsets_eb_hu_h =
2776 args.array<int>("csrColumnOffsets_eb_hu_h");
2777 xt::pyarray<int> &csrColumnOffsets_eb_hu_hu =
2778 args.array<int>("csrColumnOffsets_eb_hu_hu");
2779 xt::pyarray<int> &csrColumnOffsets_eb_hu_hv =
2780 args.array<int>("csrColumnOffsets_eb_hu_hv");
2781 xt::pyarray<int> &csrColumnOffsets_eb_hv_h =
2782 args.array<int>("csrColumnOffsets_eb_hv_h");
2783 xt::pyarray<int> &csrColumnOffsets_eb_hv_hu =
2784 args.array<int>("csrColumnOffsets_eb_hv_hu");
2785 xt::pyarray<int> &csrColumnOffsets_eb_hv_hv =
2786 args.array<int>("csrColumnOffsets_eb_hv_hv");
2787 double dt = args.scalar<double>("dt");
2788 //
2789 // loop over elements to compute volume integrals and load them into the
2790 // element Jacobians and global Jacobian
2791 //
2792 for (int eN = 0; eN < nElements_global; eN++) {
2793 double elementJacobian_h_h[nDOF_test_element]
2794 [nDOF_trial_element],
2795 elementJacobian_hu_hu[nDOF_test_element][nDOF_trial_element],
2796 elementJacobian_hv_hv[nDOF_test_element][nDOF_trial_element],
2797 elementJacobian_heta_heta[nDOF_test_element][nDOF_trial_element],
2798 elementJacobian_hw_hw[nDOF_test_element][nDOF_trial_element],
2799 elementJacobian_hbeta_hbeta[nDOF_test_element][nDOF_trial_element];
2800 for (int i = 0; i < nDOF_test_element; i++)
2801 for (int j = 0; j < nDOF_trial_element; j++) {
2802 elementJacobian_h_h[i][j] = 0.0;
2803 elementJacobian_hu_hu[i][j] = 0.0;
2804 elementJacobian_hv_hv[i][j] = 0.0;
2805 elementJacobian_heta_heta[i][j] = 0.0;
2806 elementJacobian_hw_hw[i][j] = 0.0;
2807 elementJacobian_hbeta_hbeta[i][j] = 0.0;
2808 }
2809 for (int k = 0; k < nQuadraturePoints_element; k++) {
2810 int eN_k = eN * nQuadraturePoints_element +
2811 k, // index to a scalar at a quadrature point
2812 eN_k_nSpace = eN_k * nSpace,
2813 eN_nDOF_trial_element =
2814 eN * nDOF_trial_element; // index to a vector at a
2815 // quadrature point
2816
2817 // declare local storage
2818 double jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
2819 dV, h_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element], x,
2820 y, xt, yt;
2821 // get jacobian, etc for mapping reference element
2822 ck.calculateMapping_element(
2823 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
2824 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
2825 // get the physical integration weight
2826 dV = fabs(jacDet) * dV_ref[k];
2827 {
2828 // porosity weighting: storage is phi U
2829 double phi_q = 0.;
2830 ck.valFromDOF(porosity_dof.data(),
2831 &h_l2g.data()[eN * nDOF_trial_element],
2832 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
2833 dV *= phi_q;
2834 }
2835 // precalculate test function products with integration weights
2836 for (int j = 0; j < nDOF_trial_element; j++) {
2837 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
2838 vel_test_dV[j] = vel_test_ref[k * nDOF_trial_element + j] * dV;
2839 }
2840 for (int i = 0; i < nDOF_test_element; i++) {
2841 int i_nSpace = i * nSpace;
2842 for (int j = 0; j < nDOF_trial_element; j++) {
2843 int j_nSpace = j * nSpace;
2844 elementJacobian_h_h[i][j] +=
2845 h_trial_ref[k * nDOF_trial_element + j] * h_test_dV[i];
2846 elementJacobian_hu_hu[i][j] +=
2847 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2848 elementJacobian_hv_hv[i][j] +=
2849 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2850 elementJacobian_heta_heta[i][j] +=
2851 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2852 elementJacobian_hw_hw[i][j] +=
2853 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2854 elementJacobian_hbeta_hbeta[i][j] +=
2855 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2856 } // j
2857 } // i
2858 } // k
2859 //
2860 // load into element Jacobian into global Jacobian
2861 //
2862 for (int i = 0; i < nDOF_test_element; i++) {
2863 int eN_i = eN * nDOF_test_element + i;
2864 for (int j = 0; j < nDOF_trial_element; j++) {
2865 int eN_i_j = eN_i * nDOF_trial_element + j;
2866 globalJacobian[csrRowIndeces_h_h[eN_i] +
2867 csrColumnOffsets_h_h[eN_i_j]] +=
2868 elementJacobian_h_h[i][j];
2869 globalJacobian[csrRowIndeces_hu_hu[eN_i] +
2870 csrColumnOffsets_hu_hu[eN_i_j]] +=
2871 elementJacobian_hu_hu[i][j];
2872 globalJacobian[csrRowIndeces_hv_hv[eN_i] +
2873 csrColumnOffsets_hv_hv[eN_i_j]] +=
2874 elementJacobian_hv_hv[i][j];
2875 globalJacobian[csrRowIndeces_heta_heta[eN_i] +
2876 csrColumnOffsets_heta_heta[eN_i_j]] +=
2877 elementJacobian_heta_heta[i][j];
2878 globalJacobian[csrRowIndeces_hw_hw[eN_i] +
2879 csrColumnOffsets_hw_hw[eN_i_j]] +=
2880 elementJacobian_hw_hw[i][j];
2881 globalJacobian[csrRowIndeces_hbeta_hbeta[eN_i] +
2882 csrColumnOffsets_hbeta_hbeta[eN_i_j]] +=
2883 elementJacobian_hbeta_hbeta[i][j];
2884 } // j
2885 } // i
2886 } // elements
2887 }
2888
2890 xt::pyarray<double> &mesh_trial_ref = args.array<double>("mesh_trial_ref");
2891 xt::pyarray<double> &mesh_grad_trial_ref =
2892 args.array<double>("mesh_grad_trial_ref");
2893 xt::pyarray<double> &mesh_dof = args.array<double>("mesh_dof");
2894 xt::pyarray<double> &mesh_velocity_dof =
2895 args.array<double>("mesh_velocity_dof");
2896 double MOVING_DOMAIN = args.scalar<double>("MOVING_DOMAIN");
2897 xt::pyarray<int> &mesh_l2g = args.array<int>("mesh_l2g");
2898 xt::pyarray<double> &dV_ref = args.array<double>("dV_ref");
2899 xt::pyarray<double> &h_trial_ref = args.array<double>("h_trial_ref");
2900 xt::pyarray<double> &h_grad_trial_ref =
2901 args.array<double>("h_grad_trial_ref");
2902 xt::pyarray<double> &h_test_ref = args.array<double>("h_test_ref");
2903 xt::pyarray<double> &h_grad_test_ref =
2904 args.array<double>("h_grad_test_ref");
2905 xt::pyarray<double> &vel_trial_ref = args.array<double>("vel_trial_ref");
2906 xt::pyarray<double> &vel_grad_trial_ref =
2907 args.array<double>("vel_grad_trial_ref");
2908 xt::pyarray<double> &vel_test_ref = args.array<double>("vel_test_ref");
2909 xt::pyarray<double> &vel_grad_test_ref =
2910 args.array<double>("vel_grad_test_ref");
2911 xt::pyarray<double> &mesh_trial_trace_ref =
2912 args.array<double>("mesh_trial_trace_ref");
2913 xt::pyarray<double> &mesh_grad_trial_trace_ref =
2914 args.array<double>("mesh_grad_trial_trace_ref");
2915 xt::pyarray<double> &dS_ref = args.array<double>("dS_ref");
2916 xt::pyarray<double> &h_trial_trace_ref =
2917 args.array<double>("h_trial_trace_ref");
2918 xt::pyarray<double> &h_grad_trial_trace_ref =
2919 args.array<double>("h_grad_trial_trace_ref");
2920 xt::pyarray<double> &h_test_trace_ref =
2921 args.array<double>("h_test_trace_ref");
2922 xt::pyarray<double> &h_grad_test_trace_ref =
2923 args.array<double>("h_grad_test_trace_ref");
2924 xt::pyarray<double> &vel_trial_trace_ref =
2925 args.array<double>("vel_trial_trace_ref");
2926 xt::pyarray<double> &vel_grad_trial_trace_ref =
2927 args.array<double>("vel_grad_trial_trace_ref");
2928 xt::pyarray<double> &vel_test_trace_ref =
2929 args.array<double>("vel_test_trace_ref");
2930 xt::pyarray<double> &vel_grad_test_trace_ref =
2931 args.array<double>("vel_grad_test_trace_ref");
2932 xt::pyarray<double> &normal_ref = args.array<double>("normal_ref");
2933 xt::pyarray<double> &boundaryJac_ref =
2934 args.array<double>("boundaryJac_ref");
2935 xt::pyarray<double> &elementDiameter =
2936 args.array<double>("elementDiameter");
2937 int nElements_global = args.scalar<int>("nElements_global");
2938 double g = args.scalar<double>("g");
2939 xt::pyarray<int> &h_l2g = args.array<int>("h_l2g");
2940 xt::pyarray<int> &vel_l2g = args.array<int>("vel_l2g");
2941 xt::pyarray<double> &b_dof = args.array<double>("b_dof");
2942 xt::pyarray<double> &h_dof = args.array<double>("h_dof");
2943 xt::pyarray<double> &hu_dof = args.array<double>("hu_dof");
2944 xt::pyarray<double> &hv_dof = args.array<double>("hv_dof");
2945 xt::pyarray<double> &q_cfl = args.array<double>("q_cfl");
2946 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
2947 args.array<int>("sdInfo_hu_hu_rowptr");
2948 xt::pyarray<int> &sdInfo_hu_hu_colind =
2949 args.array<int>("sdInfo_hu_hu_colind");
2950 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
2951 args.array<int>("sdInfo_hu_hv_rowptr");
2952 xt::pyarray<int> &sdInfo_hu_hv_colind =
2953 args.array<int>("sdInfo_hu_hv_colind");
2954 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
2955 args.array<int>("sdInfo_hv_hv_rowptr");
2956 xt::pyarray<int> &sdInfo_hv_hv_colind =
2957 args.array<int>("sdInfo_hv_hv_colind");
2958 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
2959 args.array<int>("sdInfo_hv_hu_rowptr");
2960 xt::pyarray<int> &sdInfo_hv_hu_colind =
2961 args.array<int>("sdInfo_hv_hu_colind");
2962 // h
2963 xt::pyarray<int> &csrRowIndeces_h_h = args.array<int>("csrRowIndeces_h_h");
2964 xt::pyarray<int> &csrColumnOffsets_h_h =
2965 args.array<int>("csrColumnOffsets_h_h");
2966 xt::pyarray<int> &csrRowIndeces_h_hu =
2967 args.array<int>("csrRowIndeces_h_hu");
2968 xt::pyarray<int> &csrColumnOffsets_h_hu =
2969 args.array<int>("csrColumnOffsets_h_hu");
2970 xt::pyarray<int> &csrRowIndeces_h_hv =
2971 args.array<int>("csrRowIndeces_h_hv");
2972 xt::pyarray<int> &csrColumnOffsets_h_hv =
2973 args.array<int>("csrColumnOffsets_h_hv");
2974 xt::pyarray<int> &csrRowIndeces_h_heta =
2975 args.array<int>("csrRowIndeces_h_heta");
2976 xt::pyarray<int> &csrColumnOffsets_h_heta =
2977 args.array<int>("csrColumnOffsets_h_heta");
2978 xt::pyarray<int> &csrRowIndeces_h_hw =
2979 args.array<int>("csrRowIndeces_h_hw");
2980 xt::pyarray<int> &csrColumnOffsets_h_hw =
2981 args.array<int>("csrColumnOffsets_h_hw");
2982 // hu
2983 xt::pyarray<int> &csrRowIndeces_hu_h =
2984 args.array<int>("csrRowIndeces_hu_h");
2985 xt::pyarray<int> &csrColumnOffsets_hu_h =
2986 args.array<int>("csrColumnOffsets_hu_h");
2987 xt::pyarray<int> &csrRowIndeces_hu_hu =
2988 args.array<int>("csrRowIndeces_hu_hu");
2989 xt::pyarray<int> &csrColumnOffsets_hu_hu =
2990 args.array<int>("csrColumnOffsets_hu_hu");
2991 xt::pyarray<int> &csrRowIndeces_hu_hv =
2992 args.array<int>("csrRowIndeces_hu_hv");
2993 xt::pyarray<int> &csrColumnOffsets_hu_hv =
2994 args.array<int>("csrColumnOffsets_hu_hv");
2995 xt::pyarray<int> &csrRowIndeces_hu_heta =
2996 args.array<int>("csrRowIndeces_hu_heta");
2997 xt::pyarray<int> &csrColumnOffsets_hu_heta =
2998 args.array<int>("csrColumnOffsets_hu_heta");
2999 xt::pyarray<int> &csrRowIndeces_hu_hw =
3000 args.array<int>("csrRowIndeces_hu_hw");
3001 xt::pyarray<int> &csrColumnOffsets_hu_hw =
3002 args.array<int>("csrColumnOffsets_hu_hw");
3003 // hv
3004 xt::pyarray<int> &csrRowIndeces_hv_h =
3005 args.array<int>("csrRowIndeces_hv_h");
3006 xt::pyarray<int> &csrColumnOffsets_hv_h =
3007 args.array<int>("csrColumnOffsets_hv_h");
3008 xt::pyarray<int> &csrRowIndeces_hv_hu =
3009 args.array<int>("csrRowIndeces_hv_hu");
3010 xt::pyarray<int> &csrColumnOffsets_hv_hu =
3011 args.array<int>("csrColumnOffsets_hv_hu");
3012 xt::pyarray<int> &csrRowIndeces_hv_hv =
3013 args.array<int>("csrRowIndeces_hv_hv");
3014 xt::pyarray<int> &csrColumnOffsets_hv_hv =
3015 args.array<int>("csrColumnOffsets_hv_hv");
3016 xt::pyarray<int> &csrRowIndeces_hv_heta =
3017 args.array<int>("csrRowIndeces_hv_heta");
3018 xt::pyarray<int> &csrColumnOffsets_hv_heta =
3019 args.array<int>("csrColumnOffsets_hv_heta");
3020 xt::pyarray<int> &csrRowIndeces_hv_hw =
3021 args.array<int>("csrRowIndeces_hv_hw");
3022 xt::pyarray<int> &csrColumnOffsets_hv_hw =
3023 args.array<int>("csrColumnOffsets_hv_hw");
3024 // heta
3025 xt::pyarray<int> &csrRowIndeces_heta_h =
3026 args.array<int>("csrRowIndeces_heta_h");
3027 xt::pyarray<int> &csrColumnOffsets_heta_h =
3028 args.array<int>("csrColumnOffsets_heta_h");
3029 xt::pyarray<int> &csrRowIndeces_heta_hu =
3030 args.array<int>("csrRowIndeces_heta_hu");
3031 xt::pyarray<int> &csrColumnOffsets_heta_hu =
3032 args.array<int>("csrColumnOffsets_heta_hu");
3033 xt::pyarray<int> &csrRowIndeces_heta_hv =
3034 args.array<int>("csrRowIndeces_heta_hv");
3035 xt::pyarray<int> &csrColumnOffsets_heta_hv =
3036 args.array<int>("csrColumnOffsets_heta_hv");
3037 xt::pyarray<int> &csrRowIndeces_heta_heta =
3038 args.array<int>("csrRowIndeces_heta_heta");
3039 xt::pyarray<int> &csrColumnOffsets_heta_heta =
3040 args.array<int>("csrColumnOffsets_heta_heta");
3041 xt::pyarray<int> &csrRowIndeces_heta_hw =
3042 args.array<int>("csrRowIndeces_heta_hw");
3043 xt::pyarray<int> &csrColumnOffsets_heta_hw =
3044 args.array<int>("csrColumnOffsets_heta_hw");
3045 // hw
3046 xt::pyarray<int> &csrRowIndeces_hw_h =
3047 args.array<int>("csrRowIndeces_hw_h");
3048 xt::pyarray<int> &csrColumnOffsets_hw_h =
3049 args.array<int>("csrColumnOffsets_hw_h");
3050 xt::pyarray<int> &csrRowIndeces_hw_hu =
3051 args.array<int>("csrRowIndeces_hw_hu");
3052 xt::pyarray<int> &csrColumnOffsets_hw_hu =
3053 args.array<int>("csrColumnOffsets_hw_hu");
3054 xt::pyarray<int> &csrRowIndeces_hw_hv =
3055 args.array<int>("csrRowIndeces_hw_hv");
3056 xt::pyarray<int> &csrColumnOffsets_hw_hv =
3057 args.array<int>("csrColumnOffsets_hw_hv");
3058 xt::pyarray<int> &csrRowIndeces_hw_heta =
3059 args.array<int>("csrRowIndeces_hw_heta");
3060 xt::pyarray<int> &csrColumnOffsets_hw_heta =
3061 args.array<int>("csrColumnOffsets_hw_heta");
3062 xt::pyarray<int> &csrRowIndeces_hw_hw =
3063 args.array<int>("csrRowIndeces_hw_hw");
3064 xt::pyarray<int> &csrColumnOffsets_hw_hw =
3065 args.array<int>("csrColumnOffsets_hw_hw");
3066 xt::pyarray<int> &csrRowIndeces_hbeta_hbeta =
3067 args.array<int>("csrRowIndeces_hbeta_hbeta");
3068 xt::pyarray<int> &csrColumnOffsets_hbeta_hbeta =
3069 args.array<int>("csrColumnOffsets_hbeta_hbeta");
3070 xt::pyarray<double> &globalJacobian = args.array<double>("globalJacobian");
3071 xt::pyarray<double> &porosity_dof = args.array<double>("porosity_dof");
3072 int nExteriorElementBoundaries_global =
3073 args.scalar<int>("nExteriorElementBoundaries_global");
3074 xt::pyarray<int> &exteriorElementBoundariesArray =
3075 args.array<int>("exteriorElementBoundariesArray");
3076 xt::pyarray<int> &elementBoundaryElementsArray =
3077 args.array<int>("elementBoundaryElementsArray");
3078 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
3079 args.array<int>("elementBoundaryLocalElementBoundariesArray");
3080 xt::pyarray<int> &isDOFBoundary_h = args.array<int>("isDOFBoundary_h");
3081 xt::pyarray<int> &isDOFBoundary_hu = args.array<int>("isDOFBoundary_hu");
3082 xt::pyarray<int> &isDOFBoundary_hv = args.array<int>("isDOFBoundary_hv");
3083 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
3084 args.array<int>("isAdvectiveFluxBoundary_h");
3085 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
3086 args.array<int>("isAdvectiveFluxBoundary_hu");
3087 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
3088 args.array<int>("isAdvectiveFluxBoundary_hv");
3089 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
3090 args.array<int>("isDiffusiveFluxBoundary_hu");
3091 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
3092 args.array<int>("isDiffusiveFluxBoundary_hv");
3093 xt::pyarray<double> &ebqe_bc_h_ext = args.array<double>("ebqe_bc_h_ext");
3094 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
3095 args.array<double>("ebqe_bc_flux_mass_ext");
3096 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
3097 args.array<double>("ebqe_bc_flux_mom_hu_adv_ext");
3098 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
3099 args.array<double>("ebqe_bc_flux_mom_hv_adv_ext");
3100 xt::pyarray<double> &ebqe_bc_hu_ext = args.array<double>("ebqe_bc_hu_ext");
3101 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
3102 args.array<double>("ebqe_bc_flux_hu_diff_ext");
3103 xt::pyarray<double> &ebqe_penalty_ext =
3104 args.array<double>("ebqe_penalty_ext");
3105 xt::pyarray<double> &ebqe_bc_hv_ext = args.array<double>("ebqe_bc_hv_ext");
3106 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
3107 args.array<double>("ebqe_bc_flux_hv_diff_ext");
3108 xt::pyarray<int> &csrColumnOffsets_eb_h_h =
3109 args.array<int>("csrColumnOffsets_eb_h_h");
3110 xt::pyarray<int> &csrColumnOffsets_eb_h_hu =
3111 args.array<int>("csrColumnOffsets_eb_h_hu");
3112 xt::pyarray<int> &csrColumnOffsets_eb_h_hv =
3113 args.array<int>("csrColumnOffsets_eb_h_hv");
3114 xt::pyarray<int> &csrColumnOffsets_eb_hu_h =
3115 args.array<int>("csrColumnOffsets_eb_hu_h");
3116 xt::pyarray<int> &csrColumnOffsets_eb_hu_hu =
3117 args.array<int>("csrColumnOffsets_eb_hu_hu");
3118 xt::pyarray<int> &csrColumnOffsets_eb_hu_hv =
3119 args.array<int>("csrColumnOffsets_eb_hu_hv");
3120 xt::pyarray<int> &csrColumnOffsets_eb_hv_h =
3121 args.array<int>("csrColumnOffsets_eb_hv_h");
3122 xt::pyarray<int> &csrColumnOffsets_eb_hv_hu =
3123 args.array<int>("csrColumnOffsets_eb_hv_hu");
3124 xt::pyarray<int> &csrColumnOffsets_eb_hv_hv =
3125 args.array<int>("csrColumnOffsets_eb_hv_hv");
3126 double dt = args.scalar<double>("dt");
3127 //
3128 // loop over elements to compute volume integrals and load them into the
3129 // element Jacobians and global Jacobian
3130 //
3131 for (int eN = 0; eN < nElements_global; eN++) {
3132 double elementJacobian_h_h[nDOF_test_element]
3133 [nDOF_trial_element],
3134 elementJacobian_hu_hu[nDOF_test_element][nDOF_trial_element],
3135 elementJacobian_hv_hv[nDOF_test_element][nDOF_trial_element],
3136 elementJacobian_heta_heta[nDOF_test_element][nDOF_trial_element],
3137 elementJacobian_hw_hw[nDOF_test_element][nDOF_trial_element],
3138 elementJacobian_hbeta_hbeta[nDOF_test_element][nDOF_trial_element];
3139 for (int i = 0; i < nDOF_test_element; i++)
3140 for (int j = 0; j < nDOF_trial_element; j++) {
3141 elementJacobian_h_h[i][j] = 0.0;
3142 elementJacobian_hu_hu[i][j] = 0.0;
3143 elementJacobian_hv_hv[i][j] = 0.0;
3144 elementJacobian_heta_heta[i][j] = 0.0;
3145 elementJacobian_hw_hw[i][j] = 0.0;
3146 elementJacobian_hbeta_hbeta[i][j] = 0.0;
3147 }
3148 for (int k = 0; k < nQuadraturePoints_element; k++) {
3149 int eN_k = eN * nQuadraturePoints_element +
3150 k, // index to a scalar at a quadrature point
3151 eN_k_nSpace = eN_k * nSpace,
3152 eN_nDOF_trial_element =
3153 eN * nDOF_trial_element; // index to a vector at a
3154 // quadrature point
3155
3156 // declare local storage
3157 double jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
3158 dV, h_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element], x,
3159 y, xt, yt;
3160 // get jacobian, etc for mapping reference element
3161 ck.calculateMapping_element(
3162 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
3163 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
3164 // get the physical integration weight
3165 dV = fabs(jacDet) * dV_ref[k];
3166 {
3167 // porosity weighting: storage is phi U
3168 double phi_q = 0.;
3169 ck.valFromDOF(porosity_dof.data(),
3170 &h_l2g.data()[eN * nDOF_trial_element],
3171 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
3172 dV *= phi_q;
3173 }
3174 // precalculate test function products with integration weights
3175 for (int j = 0; j < nDOF_trial_element; j++) {
3176 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
3177 vel_test_dV[j] = vel_test_ref[k * nDOF_trial_element + j] * dV;
3178 }
3179
3180 for (int i = 0; i < nDOF_test_element; i++) {
3181 int i_nSpace = i * nSpace;
3182 for (int j = 0; j < nDOF_trial_element; j++) {
3183 int j_nSpace = j * nSpace;
3184 elementJacobian_h_h[i][j] += (i == j ? 1.0 : 0.0) * h_test_dV[i];
3185 elementJacobian_hu_hu[i][j] +=
3186 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
3187 elementJacobian_hv_hv[i][j] +=
3188 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
3189 elementJacobian_heta_heta[i][j] +=
3190 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
3191 elementJacobian_hw_hw[i][j] +=
3192 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
3193 elementJacobian_hbeta_hbeta[i][j] +=
3194 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
3195 } // j
3196 } // i
3197 } // k
3198 //
3199 // load into element Jacobian into global Jacobian
3200 //
3201 for (int i = 0; i < nDOF_test_element; i++) {
3202 int eN_i = eN * nDOF_test_element + i;
3203 for (int j = 0; j < nDOF_trial_element; j++) {
3204 int eN_i_j = eN_i * nDOF_trial_element + j;
3205 globalJacobian[csrRowIndeces_h_h[eN_i] +
3206 csrColumnOffsets_h_h[eN_i_j]] +=
3207 elementJacobian_h_h[i][j];
3208 globalJacobian[csrRowIndeces_hu_hu[eN_i] +
3209 csrColumnOffsets_hu_hu[eN_i_j]] +=
3210 elementJacobian_hu_hu[i][j];
3211 globalJacobian[csrRowIndeces_hv_hv[eN_i] +
3212 csrColumnOffsets_hv_hv[eN_i_j]] +=
3213 elementJacobian_hv_hv[i][j];
3214 globalJacobian[csrRowIndeces_heta_heta[eN_i] +
3215 csrColumnOffsets_heta_heta[eN_i_j]] +=
3216 elementJacobian_heta_heta[i][j];
3217 globalJacobian[csrRowIndeces_hw_hw[eN_i] +
3218 csrColumnOffsets_hw_hw[eN_i_j]] +=
3219 elementJacobian_hw_hw[i][j];
3220 globalJacobian[csrRowIndeces_hbeta_hbeta[eN_i] +
3221 csrColumnOffsets_hbeta_hbeta[eN_i_j]] +=
3222 elementJacobian_hbeta_hbeta[i][j];
3223 } // j
3224 } // i
3225 } // elements
3226 }
3227}; // namespace proteus
3228
3229inline GN_SW2DCV_base *
3230newGN_SW2DCV(int nSpaceIn, int nQuadraturePoints_elementIn,
3231 int nDOF_mesh_trial_elementIn, int nDOF_trial_elementIn,
3232 int nDOF_test_elementIn, int nQuadraturePoints_elementBoundaryIn,
3233 int CompKernelFlag) {
3235 CompKernel>(
3236 nSpaceIn, nQuadraturePoints_elementIn, nDOF_mesh_trial_elementIn,
3237 nDOF_trial_elementIn, nDOF_test_elementIn,
3238 nQuadraturePoints_elementBoundaryIn, CompKernelFlag);
3239}
3240} // end namespace proteus
3241
3242#endif
#define VEL_FIX_POWER
Definition GN_SW2DCV.h:14
#define IF_BOTH_GAMMA_BRANCHES
Definition GN_SW2DCV.h:16
#define LAMBDA_MGN
Definition GN_SW2DCV.h:15
Double u
Definition Headers.h:89
Int num
Definition Headers.h:32
Double * z
Definition Headers.h:49
Double v
Definition Headers.h:95
Double psi
Definition Headers.h:78
virtual void calculateEV(arguments_dict &args)=0
virtual void calculateLumpedMassMatrix(arguments_dict &args)=0
virtual void calculateBoundsAndHighOrderRHS(arguments_dict &args)=0
virtual void convexLimiting(arguments_dict &args)=0
virtual double calculateEdgeBasedCFL(arguments_dict &args)=0
virtual void calculateResidual(arguments_dict &args)=0
virtual void calculatePreStep(arguments_dict &args)=0
virtual void calculateMassMatrix(arguments_dict &args)=0
static double phiBar(int i, int j, const xt::pyarray< double > &porosity_dof)
Definition GN_SW2DCV.h:955
void calculateEV(arguments_dict &args)
Definition GN_SW2DCV.h:1179
void convexLimiting(arguments_dict &args)
Definition GN_SW2DCV.h:173
static void wallCoefficients(int i, int j, int ij, const xt::pyarray< double > &wall_dof, const xt::pyarray< double > &Cx, const xt::pyarray< double > &Cy, const xt::pyarray< double > &CTx, const xt::pyarray< double > &CTy, double &cx_ij, double &cy_ij, double &cx_ji, double &cy_ji)
Definition GN_SW2DCV.h:940
const int nDOF_test_X_trial_element
Definition GN_SW2DCV.h:116
void calculateMassMatrix(arguments_dict &args)
Definition GN_SW2DCV.h:2511
void calculateCFL(const double &elementDiameter, const double &g, const double &h, const double &hu, const double &hv, const double hEps, double &cfl)
Definition GN_SW2DCV.h:154
void calculatePreStep(arguments_dict &args)
Definition GN_SW2DCV.h:1077
void calculateLumpedMassMatrix(arguments_dict &args)
Definition GN_SW2DCV.h:2889
double calculateEdgeBasedCFL(arguments_dict &args)
Definition GN_SW2DCV.h:960
double maxWaveSpeedSharpInitialGuess(const double g, const double nx, const double ny, const double hL, const double huL, double hvL, const double hetaL, const double inv_MeshL, const double hR, const double huR, const double hvR, const double hetaR, const double inv_MeshR, const double hEps)
Definition GN_SW2DCV.h:128
void calculateBoundsAndHighOrderRHS(arguments_dict &args)
Definition GN_SW2DCV.h:1299
void calculateResidual(arguments_dict &args)
Definition GN_SW2DCV.h:2067
CompKernelType ck
Definition GN_SW2DCV.h:117
#define c(i)
Definition jf.h:21
Definition ADR.h:21
double relaxation(const double &xi, const double &alpha)
Definition GN_SW2DCV.h:85
double ENTROPY_FLUX1(const double &g, const double &h, const double &hu, const double &hv, const double &z, const double &one_over_hReg)
Definition GN_SW2DCV.h:71
ENTROPY
Definition TADR.h:40
GN_SW2DCV_base * newGN_SW2DCV(int nSpaceIn, int nQuadraturePoints_elementIn, int nDOF_mesh_trial_elementIn, int nDOF_trial_elementIn, int nDOF_test_elementIn, int nQuadraturePoints_elementBoundaryIn, int CompKernelFlag)
Definition GN_SW2DCV.h:3230
double DENTROPY_DHU(const double &g, const double &h, const double &hu, const double &hv, const double &z, const double &one_over_hReg)
Definition GN_SW2DCV.h:61
double DENTROPY_DHV(const double &g, const double &h, const double &hu, const double &hv, const double &z, const double &one_over_hReg)
Definition GN_SW2DCV.h:66
double DENTROPY_DH(const double &g, const double &h, const double &hu, const double &hv, const double &z, const double &one_over_hReg)
Definition GN_SW2DCV.h:56
double ENTROPY_FLUX2(const double &g, const double &h, const double &hu, const double &hv, const double &z, const double &one_over_hReg)
Definition GN_SW2DCV.h:78
double GN_nu3(const double &g, const double &hR, const double &uR, const double &etaR, const double &inv_meshSizeR)
Definition GN_SW2DCV.h:38
Model_Base * chooseAndAllocateDiscretization2D(int nSpaceIn, int nQuadraturePoints_elementIn, int nDOF_mesh_trial_elementIn, int nDOF_trial_elementIn, int nDOF_test_elementIn, int nDOF_v_trial_elementIn, int nDOF_v_test_elementIn, int nQuadraturePoints_elementBoundaryIn, int CompKernelFlag)
double GN_nu1(const double &g, const double &hL, const double &uL, const double &etaL, const double &inv_meshSizeL)
Definition GN_SW2DCV.h:25
T & scalar(const std::string &key)
xt::pyarray< T > & array(const std::string &key)