235 double dt = args.
scalar<
double>(
"dt");
236 int NNZ = args.
scalar<
int>(
"NNZ");
237 int numDOFs = args.
scalar<
int>(
"numDOFs");
238 xt::pyarray<double> &lumped_mass_matrix =
239 args.
array<
double>(
"lumped_mass_matrix");
240 xt::pyarray<double> &h_old = args.
array<
double>(
"h_old");
241 xt::pyarray<double> &hu_old = args.
array<
double>(
"hu_old");
242 xt::pyarray<double> &hv_old = args.
array<
double>(
"hv_old");
243 xt::pyarray<double> &b_dof = args.
array<
double>(
"b_dof");
244 xt::pyarray<double> &high_order_hnp1 =
245 args.
array<
double>(
"high_order_hnp1");
246 xt::pyarray<double> &high_order_hunp1 =
247 args.
array<
double>(
"high_order_hunp1");
248 xt::pyarray<double> &high_order_hvnp1 =
249 args.
array<
double>(
"high_order_hvnp1");
250 xt::pyarray<double> &extendedSourceTerm_hu =
251 args.
array<
double>(
"extendedSourceTerm_hu");
252 xt::pyarray<double> &extendedSourceTerm_hv =
253 args.
array<
double>(
"extendedSourceTerm_hv");
254 xt::pyarray<double> &limited_hnp1 = args.
array<
double>(
"limited_hnp1");
255 xt::pyarray<double> &limited_hunp1 = args.
array<
double>(
"limited_hunp1");
256 xt::pyarray<double> &limited_hvnp1 = args.
array<
double>(
"limited_hvnp1");
257 xt::pyarray<int> &csrRowIndeces_DofLoops =
258 args.
array<
int>(
"csrRowIndeces_DofLoops");
259 xt::pyarray<int> &csrColumnOffsets_DofLoops =
260 args.
array<
int>(
"csrColumnOffsets_DofLoops");
261 xt::pyarray<double> &MassMatrix = args.
array<
double>(
"MassMatrix");
262 xt::pyarray<double> &dH_minus_dL = args.
array<
double>(
"dH_minus_dL");
263 xt::pyarray<double> &muH_minus_muL = args.
array<
double>(
"muH_minus_muL");
264 double hEps = args.
scalar<
double>(
"hEps");
265 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
267 int NO_STAR_STATES = args.
scalar<
int>(
"NO_STAR_STATES");
268 xt::pyarray<double> &dLow = args.
array<
double>(
"dLow");
269 xt::pyarray<double> &new_SourceTerm_hu =
270 args.
array<
double>(
"new_SourceTerm_hu");
271 xt::pyarray<double> &new_SourceTerm_hv =
272 args.
array<
double>(
"new_SourceTerm_hv");
273 xt::pyarray<double> &hLow = args.
array<
double>(
"hLow");
274 xt::pyarray<double> &huLow = args.
array<
double>(
"huLow");
275 xt::pyarray<double> &hvLow = args.
array<
double>(
"hvLow");
276 xt::pyarray<double> &h_min = args.
array<
double>(
"h_min");
277 xt::pyarray<double> &h_max = args.
array<
double>(
"h_max");
278 xt::pyarray<double> &kin_max = args.
array<
double>(
"kin_max");
279 double KE_tiny = args.
scalar<
double>(
"KE_tiny");
287 const int limit_iter_arg = args.
scalar<
int>(
"limit_iter");
288 const int limit_stage = args.
scalar<
int>(
"limit_stage");
289 xt::pyarray<double> &FCT_all = args.
array<
double>(
"FCT_all");
290 xt::pyarray<double> &Rneg = args.
array<
double>(
"Rneg_dof");
291 xt::pyarray<double> &Rpos = args.
array<
double>(
"Rpos_dof");
294 xt::pyarray<double> &num_neighbours = args.
array<
double>(
"num_neighbours");
295 const bool first_call = (limit_iter_arg == 0 && limit_stage == 0);
298 std::valarray<double> FCT_h(0.0, dH_minus_dL.size()),
299 FCT_hu(0.0, dH_minus_dL.size()), FCT_hv(0.0, dH_minus_dL.size());
300 const std::size_t nnz_fct = dH_minus_dL.size();
306 for (
int i = 0; i < numDOFs && first_call; i++) {
308 double high_order_hnp1i = high_order_hnp1[i];
309 double high_order_hunp1i = high_order_hunp1[i];
310 double high_order_hvnp1i = high_order_hvnp1[i];
311 double hi = h_old[i];
312 double huni = hu_old[i];
313 double hvni = hv_old[i];
314 double Zi = b_dof[i];
315 double mi = lumped_mass_matrix[i];
316 double one_over_hiReg =
317 2 * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
320 for (
int offset = csrRowIndeces_DofLoops[i];
321 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
323 int j = csrColumnOffsets_DofLoops[offset];
327 double hj = h_old[j];
328 double hunj = hu_old[j];
329 double hvnj = hv_old[j];
330 double Zj = b_dof[j];
331 double one_over_hjReg =
332 2. * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
335 double hStarij = NO_STAR_STATES ? hi : fmax(0., hi + Zi - fmax(Zi, Zj));
336 double huStarij = huni * hStarij * one_over_hiReg;
337 double hvStarij = hvni * hStarij * one_over_hiReg;
339 double hStarji = NO_STAR_STATES ? hj : fmax(0., hj + Zj - fmax(Zi, Zj));
340 double huStarji = hunj * hStarji * one_over_hjReg;
341 double hvStarji = hvnj * hStarji * one_over_hjReg;
344 double ML_minus_MC = (LUMPED_MASS_MATRIX == 1
346 : (i == j ? 1. : 0.) * mi - MassMatrix[ij]);
350 (high_order_hnp1[j] - hj - (high_order_hnp1i - hi)) +
351 dt * (dH_minus_dL[ij] - muH_minus_muL[ij]) * (hStarji - hStarij) +
352 dt * muH_minus_muL[ij] * (hj - hi);
354 FCT_hu[ij] = ML_minus_MC * (high_order_hunp1[j] - hunj -
355 (high_order_hunp1i - huni)) +
356 dt * (dH_minus_dL[ij] - muH_minus_muL[ij]) *
357 (huStarji - huStarij) +
358 dt * muH_minus_muL[ij] * (hunj - huni);
360 FCT_hv[ij] = ML_minus_MC * (high_order_hvnp1[j] - hvnj -
361 (high_order_hvnp1i - hvni)) +
362 dt * (dH_minus_dL[ij] - muH_minus_muL[ij]) *
363 (hvStarji - hvStarij) +
364 dt * muH_minus_muL[ij] * (hvnj - hvni);
382 std::valarray<double> Lij_array(1.0, dH_minus_dL.size());
384 for (std::size_t k = 0; k < nnz_fct; k++) {
385 FCT_h[k] = FCT_all[0 * nnz_fct + k];
386 FCT_hu[k] = FCT_all[1 * nnz_fct + k];
387 FCT_hv[k] = FCT_all[2 * nnz_fct + k];
388 Lij_array[k] = FCT_all[3 * nnz_fct + k];
393 for (
int limit_iter = limit_iter_arg; limit_iter < limit_iter_arg + 1;
397 if (limit_stage == 0) {
399 for (
int i = 0; i < numDOFs; i++) {
401 double hi = h_old[i];
402 double mi = lumped_mass_matrix[i];
404 double Pnegi = 0., Pposi = 0.;
407 for (
int offset = csrRowIndeces_DofLoops[i];
408 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
410 int j = csrColumnOffsets_DofLoops[offset];
413 Pnegi += FCT_h[ij] * ((FCT_h[ij] < 0) ? 1. : 0.);
414 Pposi += FCT_h[ij] * ((FCT_h[ij] > 0) ? 1. : 0.);
420 double psmall_h = 1E-14 * fmax(fabs(Pnegi), fabs(Pposi));
425 double Qnegi = std::min(mi * (h_min[i] - hLow[i]), 0.0);
426 double Qposi = std::max(mi * (h_max[i] - hLow[i]), 0.0);
436 if (Pnegi >= -psmall_h) {
439 Rneg[i] = std::min(1.0, Qnegi / Pnegi);
441 if (Pposi <= psmall_h) {
444 Rpos[i] = std::min(1.0, Qposi / Pposi);
453 for (
int i = 0; i < numDOFs; i++) {
455 double mi = lumped_mass_matrix[i];
457 kin_max[i] * hLow[i] -
458 0.5 * (huLow[i] * huLow[i] + hvLow[i] * hvLow[i]);
461 for (
int offset = csrRowIndeces_DofLoops[i];
462 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
464 int j = csrColumnOffsets_DofLoops[offset];
469 if (FCT_h[ij] >= 0.) {
470 Lij_array[ij] = fmin(Lij_array[ij], std::min(Rneg[j], Rpos[i]));
472 Lij_array[ij] = fmin(Lij_array[ij], std::min(Rneg[i], Rpos[j]));
479 double Ph_ij = FCT_h[ij] / mi / lambdaj;
480 double Phu_ij = FCT_hu[ij] / mi / lambdaj;
481 double Phv_ij = FCT_hv[ij] / mi / lambdaj;
484 double KE_limiter = 1;
485 double neg_root_i = 1., neg_root_j = 1.;
488 if (kin_max[i] * hLow[i] <= KE_tiny)
492 double hi_with_lijPij = hLow[i] + Lij_array[ij] * Ph_ij;
493 double hui_with_lijPij = huLow[i] + Lij_array[ij] * Phu_ij;
494 double hvi_with_lijPij = hvLow[i] + Lij_array[ij] * Phv_ij;
495 double psi = kin_max[i] * hi_with_lijPij -
496 0.5 * (hui_with_lijPij * hui_with_lijPij +
497 hvi_with_lijPij * hvi_with_lijPij);
498 if (
psi > -KE_tiny) {
499 KE_limiter = fmin(KE_limiter, Lij_array[ij]);
504 double ai = -0.5 * (Phu_ij * Phu_ij + Phv_ij * Phv_ij);
506 kin_max[i] * Ph_ij - (huLow[i] * Phu_ij + hvLow[i] * Phv_ij);
507 double delta_i = bi * bi - 4. * ai * ci;
509 if (delta_i < 0. || ai >= -0.) {
510 KE_limiter = fmin(KE_limiter, Lij_array[ij]);
512 neg_root_i = (-bi - std::sqrt(delta_i)) / 2. / ai;
518 double mj = lumped_mass_matrix[j];
519 double cj = kin_max[j] * hLow[j] -
520 0.5 * (huLow[j] * huLow[j] + hvLow[j] * hvLow[j]);
521 double Ph_ji = -FCT_h[ij] / mj / lambdai;
522 double Phu_ji = -FCT_hu[ij] / mj / lambdai;
523 double Phv_ji = -FCT_hv[ij] / mj / lambdai;
524 double aj = -0.5 * (Phu_ji * Phu_ji + Phv_ji * Phv_ji);
526 kin_max[j] * Ph_ji - (huLow[j] * Phu_ji + hvLow[j] * Phv_ji);
527 double delta_j = bj * bj - 4. * aj * cj;
529 if (delta_j < 0. || aj >= -0.) {
530 KE_limiter = fmin(KE_limiter, Lij_array[ij]);
532 neg_root_j = (-bj - std::sqrt(delta_j)) / 2. / aj;
537 fmin(KE_limiter, fmin(fabs(neg_root_i), fabs(neg_root_j)));
540 Lij_array[ij] = fmin(KE_limiter, Lij_array[ij]);
554 for (
int i = 0; i < numDOFs; i++) {
555 for (
int offset = csrRowIndeces_DofLoops[i];
556 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
557 int j = csrColumnOffsets_DofLoops[offset];
560 for (
int offset_ji = csrRowIndeces_DofLoops[j];
561 offset_ji < csrRowIndeces_DofLoops[j + 1]; offset_ji++) {
562 if (csrColumnOffsets_DofLoops[offset_ji] == i) {
563 double l = fmin(Lij_array[offset], Lij_array[offset_ji]);
564 Lij_array[offset] = l;
565 Lij_array[offset_ji] = l;
574 for (
int i = 0; i < numDOFs; i++) {
576 double one_over_mi = 1.0 / lumped_mass_matrix[i];
577 double ith_Limiter_times_FluxCorrectionMatrix1 = 0.;
578 double ith_Limiter_times_FluxCorrectionMatrix2 = 0.;
579 double ith_Limiter_times_FluxCorrectionMatrix3 = 0.;
582 for (
int offset = csrRowIndeces_DofLoops[i];
583 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
585 int j = csrColumnOffsets_DofLoops[offset];
588 ith_Limiter_times_FluxCorrectionMatrix1 += Lij_array[ij] * FCT_h[ij];
589 ith_Limiter_times_FluxCorrectionMatrix2 += Lij_array[ij] * FCT_hu[ij];
590 ith_Limiter_times_FluxCorrectionMatrix3 += Lij_array[ij] * FCT_hv[ij];
597 hLow[i] += one_over_mi * ith_Limiter_times_FluxCorrectionMatrix1;
598 huLow[i] += one_over_mi * ith_Limiter_times_FluxCorrectionMatrix2;
599 hvLow[i] += one_over_mi * ith_Limiter_times_FluxCorrectionMatrix3;
602 limited_hnp1[i] = hLow[i];
603 limited_hunp1[i] = huLow[i] + dt * one_over_mi * new_SourceTerm_hu[i];
604 limited_hvnp1[i] = hvLow[i] + dt * one_over_mi * new_SourceTerm_hv[i];
606 if (limited_hnp1[i] < -hEps && dt < 1.0) {
607 std::cout <<
"Limited water height is negative: \n "
608 <<
"hLow: " << hLow[i] <<
"\n"
609 <<
"hHigh: " << limited_hnp1[i] <<
"\n"
610 <<
"hEps: " << hEps <<
"\n"
611 <<
" ... aborting!" << std::endl;
615 if (limited_hnp1[i] < hEps)
616 limited_hnp1[i] = 0.0;
617 double aux = fmax(limited_hnp1[i], hEps);
618 limited_hunp1[i] *= 2 * std::pow(limited_hnp1[i],
VEL_FIX_POWER) /
621 limited_hvnp1[i] *= 2 * std::pow(limited_hnp1[i],
VEL_FIX_POWER) /
628 FCT_h = (1.0 - Lij_array) * FCT_h;
629 FCT_hu = (1.0 - Lij_array) * FCT_hu;
630 FCT_hv = (1.0 - Lij_array) * FCT_hv;
633 for (std::size_t k = 0; k < nnz_fct; k++) {
634 FCT_all[0 * nnz_fct + k] = FCT_h[k];
635 FCT_all[1 * nnz_fct + k] = FCT_hu[k];
636 FCT_all[2 * nnz_fct + k] = FCT_hv[k];
637 FCT_all[3 * nnz_fct + k] = Lij_array[k];
1011 xt::pyarray<double> &mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1012 xt::pyarray<double> &mesh_grad_trial_ref =
1013 args.
array<
double>(
"mesh_grad_trial_ref");
1014 xt::pyarray<double> &mesh_dof = args.
array<
double>(
"mesh_dof");
1015 xt::pyarray<int> &mesh_l2g = args.
array<
int>(
"mesh_l2g");
1016 xt::pyarray<double> &dV_ref = args.
array<
double>(
"dV_ref");
1017 xt::pyarray<double> &h_trial_ref = args.
array<
double>(
"h_trial_ref");
1018 xt::pyarray<double> &h_grad_trial_ref =
1019 args.
array<
double>(
"h_grad_trial_ref");
1020 xt::pyarray<double> &h_test_ref = args.
array<
double>(
"h_test_ref");
1021 xt::pyarray<double> &h_grad_test_ref =
1022 args.
array<
double>(
"h_grad_test_ref");
1023 xt::pyarray<double> &vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
1024 xt::pyarray<double> &vel_grad_trial_ref =
1025 args.
array<
double>(
"vel_grad_trial_ref");
1026 xt::pyarray<double> &vel_test_ref = args.
array<
double>(
"vel_test_ref");
1027 xt::pyarray<double> &vel_grad_test_ref =
1028 args.
array<
double>(
"vel_grad_test_ref");
1029 xt::pyarray<double> &mesh_trial_trace_ref =
1030 args.
array<
double>(
"mesh_trial_trace_ref");
1031 xt::pyarray<double> &mesh_grad_trial_trace_ref =
1032 args.
array<
double>(
"mesh_grad_trial_trace_ref");
1033 xt::pyarray<double> &h_trial_trace_ref =
1034 args.
array<
double>(
"h_trial_trace_ref");
1035 xt::pyarray<double> &h_grad_trial_trace_ref =
1036 args.
array<
double>(
"h_grad_trial_trace_ref");
1037 xt::pyarray<double> &h_test_trace_ref =
1038 args.
array<
double>(
"h_test_trace_ref");
1039 xt::pyarray<double> &h_grad_test_trace_ref =
1040 args.
array<
double>(
"h_grad_test_trace_ref");
1041 xt::pyarray<double> &vel_trial_trace_ref =
1042 args.
array<
double>(
"vel_trial_trace_ref");
1043 xt::pyarray<double> &vel_grad_trial_trace_ref =
1044 args.
array<
double>(
"vel_grad_trial_trace_ref");
1045 xt::pyarray<double> &vel_test_trace_ref =
1046 args.
array<
double>(
"vel_test_trace_ref");
1047 xt::pyarray<double> &vel_grad_test_trace_ref =
1048 args.
array<
double>(
"vel_grad_test_trace_ref");
1049 xt::pyarray<double> &normal_ref = args.
array<
double>(
"normal_ref");
1050 xt::pyarray<double> &boundaryJac_ref =
1051 args.
array<
double>(
"boundaryJac_ref");
1052 xt::pyarray<double> &elementDiameter =
1053 args.
array<
double>(
"elementDiameter");
1054 int nElements_global = args.
scalar<
int>(
"nElements_global");
1055 double g = args.
scalar<
double>(
"g");
1056 xt::pyarray<int> &h_l2g = args.
array<
int>(
"h_l2g");
1057 xt::pyarray<int> &vel_l2g = args.
array<
int>(
"vel_l2g");
1058 xt::pyarray<double> &h_dof_old = args.
array<
double>(
"h_dof_old");
1059 xt::pyarray<double> &hu_dof_old = args.
array<
double>(
"hu_dof_old");
1060 xt::pyarray<double> &hv_dof_old = args.
array<
double>(
"hv_dof_old");
1061 xt::pyarray<double> &b_dof = args.
array<
double>(
"b_dof");
1062 xt::pyarray<double> &h_dof = args.
array<
double>(
"h_dof");
1063 xt::pyarray<double> &hu_dof = args.
array<
double>(
"hu_dof");
1064 xt::pyarray<double> &hv_dof = args.
array<
double>(
"hv_dof");
1065 xt::pyarray<double> &q_cfl = args.
array<
double>(
"q_cfl");
1066 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
1067 args.
array<
int>(
"sdInfo_hu_hu_rowptr");
1068 xt::pyarray<int> &sdInfo_hu_hu_colind =
1069 args.
array<
int>(
"sdInfo_hu_hu_colind");
1070 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
1071 args.
array<
int>(
"sdInfo_hu_hv_rowptr");
1072 xt::pyarray<int> &sdInfo_hu_hv_colind =
1073 args.
array<
int>(
"sdInfo_hu_hv_colind");
1074 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
1075 args.
array<
int>(
"sdInfo_hv_hv_rowptr");
1076 xt::pyarray<int> &sdInfo_hv_hv_colind =
1077 args.
array<
int>(
"sdInfo_hv_hv_colind");
1078 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
1079 args.
array<
int>(
"sdInfo_hv_hu_rowptr");
1080 xt::pyarray<int> &sdInfo_hv_hu_colind =
1081 args.
array<
int>(
"sdInfo_hv_hu_colind");
1082 int offset_h = args.
scalar<
int>(
"offset_h");
1083 int offset_hu = args.
scalar<
int>(
"offset_hu");
1084 int offset_hv = args.
scalar<
int>(
"offset_hv");
1085 int stride_h = args.
scalar<
int>(
"stride_h");
1086 int stride_hu = args.
scalar<
int>(
"stride_hu");
1087 int stride_hv = args.
scalar<
int>(
"stride_hv");
1088 xt::pyarray<double> &globalResidual = args.
array<
double>(
"globalResidual");
1089 int nExteriorElementBoundaries_global =
1090 args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1091 xt::pyarray<int> &exteriorElementBoundariesArray =
1092 args.
array<
int>(
"exteriorElementBoundariesArray");
1093 xt::pyarray<int> &elementBoundaryElementsArray =
1094 args.
array<
int>(
"elementBoundaryElementsArray");
1095 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
1096 args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1097 xt::pyarray<int> &isDOFBoundary_h = args.
array<
int>(
"isDOFBoundary_h");
1098 xt::pyarray<int> &isDOFBoundary_hu = args.
array<
int>(
"isDOFBoundary_hu");
1099 xt::pyarray<int> &isDOFBoundary_hv = args.
array<
int>(
"isDOFBoundary_hv");
1100 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
1101 args.
array<
int>(
"isAdvectiveFluxBoundary_h");
1102 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
1103 args.
array<
int>(
"isAdvectiveFluxBoundary_hu");
1104 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
1105 args.
array<
int>(
"isAdvectiveFluxBoundary_hv");
1106 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
1107 args.
array<
int>(
"isDiffusiveFluxBoundary_hu");
1108 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
1109 args.
array<
int>(
"isDiffusiveFluxBoundary_hv");
1110 xt::pyarray<double> &ebqe_bc_h_ext = args.
array<
double>(
"ebqe_bc_h_ext");
1111 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
1112 args.
array<
double>(
"ebqe_bc_flux_mass_ext");
1113 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
1114 args.
array<
double>(
"ebqe_bc_flux_mom_hu_adv_ext");
1115 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
1116 args.
array<
double>(
"ebqe_bc_flux_mom_hv_adv_ext");
1117 xt::pyarray<double> &ebqe_bc_hu_ext = args.
array<
double>(
"ebqe_bc_hu_ext");
1118 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
1119 args.
array<
double>(
"ebqe_bc_flux_hu_diff_ext");
1120 xt::pyarray<double> &ebqe_penalty_ext =
1121 args.
array<
double>(
"ebqe_penalty_ext");
1122 xt::pyarray<double> &ebqe_bc_hv_ext = args.
array<
double>(
"ebqe_bc_hv_ext");
1123 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
1124 args.
array<
double>(
"ebqe_bc_flux_hv_diff_ext");
1125 xt::pyarray<double> &q_velocity = args.
array<
double>(
"q_velocity");
1126 xt::pyarray<double> &ebqe_velocity = args.
array<
double>(
"ebqe_velocity");
1127 xt::pyarray<double> &flux = args.
array<
double>(
"flux");
1128 xt::pyarray<double> &elementResidual_h =
1129 args.
array<
double>(
"elementResidual_h");
1130 xt::pyarray<double> &Cx = args.
array<
double>(
"Cx");
1131 xt::pyarray<double> &Cy = args.
array<
double>(
"Cy");
1132 xt::pyarray<double> &CTx = args.
array<
double>(
"CTx");
1133 xt::pyarray<double> &CTy = args.
array<
double>(
"CTy");
1134 int numDOFsPerEqn = args.
scalar<
int>(
"numDOFsPerEqn");
1135 int NNZ = args.
scalar<
int>(
"NNZ");
1136 xt::pyarray<int> &csrRowIndeces_DofLoops =
1137 args.
array<
int>(
"csrRowIndeces_DofLoops");
1138 xt::pyarray<int> &csrColumnOffsets_DofLoops =
1139 args.
array<
int>(
"csrColumnOffsets_DofLoops");
1140 xt::pyarray<double> &lumped_mass_matrix =
1141 args.
array<
double>(
"lumped_mass_matrix");
1142 double cfl_run = args.
scalar<
double>(
"cfl_run");
1143 double eps = args.
scalar<
double>(
"eps");
1144 double hEps = args.
scalar<
double>(
"hEps");
1145 xt::pyarray<double> &hnp1_at_quad_point =
1146 args.
array<
double>(
"hnp1_at_quad_point");
1147 xt::pyarray<double> &hunp1_at_quad_point =
1148 args.
array<
double>(
"hunp1_at_quad_point");
1149 xt::pyarray<double> &hvnp1_at_quad_point =
1150 args.
array<
double>(
"hvnp1_at_quad_point");
1151 xt::pyarray<double> &extendedSourceTerm_hu =
1152 args.
array<
double>(
"extendedSourceTerm_hu");
1153 xt::pyarray<double> &extendedSourceTerm_hv =
1154 args.
array<
double>(
"extendedSourceTerm_hv");
1155 xt::pyarray<double> &dH_minus_dL = args.
array<
double>(
"dH_minus_dL");
1156 xt::pyarray<double> &muH_minus_muL = args.
array<
double>(
"muH_minus_muL");
1157 double cE = args.
scalar<
double>(
"cE");
1158 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1160 int NO_STAR_STATES = args.
scalar<
int>(
"NO_STAR_STATES");
1161 double dt = args.
scalar<
double>(
"dt");
1162 int LINEAR_FRICTION = args.
scalar<
int>(
"LINEAR_FRICTION");
1166 int BOUNDS_EXCLUDE_SELF = args.
scalar<
int>(
"BOUNDS_EXCLUDE_SELF");
1167 int NODAL_H_BOUNDS = args.
scalar<
int>(
"NODAL_H_BOUNDS");
1168 double mannings = args.
scalar<
double>(
"mannings");
1170 xt::pyarray<double> &wall_dof = args.
array<
double>(
"wall_dof");
1171 xt::pyarray<double> &tailwater_dof = args.
array<
double>(
"tailwater_dof");
1172 xt::pyarray<double> &tailwater_depth_dof =
1173 args.
array<
double>(
"tailwater_depth_dof");
1177 xt::pyarray<double> &porosity_dof = args.
array<
double>(
"porosity_dof");
1178 xt::pyarray<double> &drag_alpha_dof = args.
array<
double>(
"drag_alpha_dof");
1179 xt::pyarray<double> &drag_beta_dof = args.
array<
double>(
"drag_beta_dof");
1180 xt::pyarray<double> &quantDOFs = args.
array<
double>(
"quantDOFs");
1181 int SECOND_CALL_CALCULATE_RESIDUAL =
1182 args.
scalar<
int>(
"SECOND_CALL_CALCULATE_RESIDUAL");
1183 int COMPUTE_NORMALS = args.
scalar<
int>(
"COMPUTE_NORMALS");
1184 xt::pyarray<double> &normalx = args.
array<
double>(
"normalx");
1185 xt::pyarray<double> &normaly = args.
array<
double>(
"normaly");
1186 xt::pyarray<double> &dLow = args.
array<
double>(
"dLow");
1187 int lstage = args.
scalar<
int>(
"lstage");
1188 xt::pyarray<double> &new_SourceTerm_hu =
1189 args.
array<
double>(
"new_SourceTerm_hu");
1190 xt::pyarray<double> &new_SourceTerm_hv =
1191 args.
array<
double>(
"new_SourceTerm_hv");
1192 xt::pyarray<double> &global_entropy_residual =
1193 args.
array<
double>(
"global_entropy_residual");
1194 double dij_small = args.
scalar<
double>(
"dij_small");
1195 xt::pyarray<double> &hLow = args.
array<
double>(
"hLow");
1196 xt::pyarray<double> &huLow = args.
array<
double>(
"huLow");
1197 xt::pyarray<double> &hvLow = args.
array<
double>(
"hvLow");
1198 xt::pyarray<double> &h_min = args.
array<
double>(
"h_min");
1199 xt::pyarray<double> &h_max = args.
array<
double>(
"h_max");
1200 xt::pyarray<double> &kin_max = args.
array<
double>(
"kin_max");
1201 xt::pyarray<double> &urelax = args.
array<
double>(
"urelax");
1202 xt::pyarray<double> &drelax = args.
array<
double>(
"drelax");
1204 double n2 = std::pow(mannings, 2.);
1205 double gamma = 4. / 3;
1215 for (
int eN = 0; eN < nElements_global; eN++) {
1217 double elementResidual_h[nDOF_test_element],
1218 elementResidual_hu[nDOF_test_element],
1219 elementResidual_hv[nDOF_test_element];
1221 for (
int i = 0; i < nDOF_test_element; i++) {
1222 elementResidual_h[i] = 0.0;
1223 elementResidual_hu[i] = 0.0;
1224 elementResidual_hv[i] = 0.0;
1229 for (
int k = 0; k < nQuadraturePoints_element; k++) {
1231 int eN_k = eN * nQuadraturePoints_element + k,
1232 eN_k_nSpace = eN_k * nSpace,
1233 eN_nDOF_trial_element = eN * nDOF_trial_element;
1234 double h = 0.0, hu = 0.0,
1236 h_old = 0.0, hu_old = 0.0, hv_old = 0.0,
1237 jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
1238 h_test_dV[nDOF_trial_element], dV, x, y,
xt, yt;
1240 ck.calculateMapping_element(
1241 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
1242 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
1245 dV = fabs(jacDet) * dV_ref[k];
1248 ck.valFromDOF(porosity_dof.data(),
1249 &h_l2g.data()[eN_nDOF_trial_element],
1250 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
1254 ck.valFromDOF(h_dof.data(), &h_l2g.data()[eN_nDOF_trial_element],
1255 &h_trial_ref.data()[k * nDOF_trial_element], h);
1256 ck.valFromDOF(hu_dof.data(), &vel_l2g[eN_nDOF_trial_element],
1257 &vel_trial_ref.data()[k * nDOF_trial_element], hu);
1258 ck.valFromDOF(hv_dof.data(), &vel_l2g[eN_nDOF_trial_element],
1259 &vel_trial_ref.data()[k * nDOF_trial_element], hv);
1261 ck.valFromDOF(h_dof_old.data(), &h_l2g.data()[eN_nDOF_trial_element],
1262 &h_trial_ref.data()[k * nDOF_trial_element], h_old);
1263 ck.valFromDOF(hu_dof_old.data(), &vel_l2g.data()[eN_nDOF_trial_element],
1264 &vel_trial_ref.data()[k * nDOF_trial_element], hu_old);
1265 ck.valFromDOF(hv_dof_old.data(), &vel_l2g.data()[eN_nDOF_trial_element],
1266 &vel_trial_ref.data()[k * nDOF_trial_element], hv_old);
1268 calculateCFL(elementDiameter.data()[eN], g, h_old, hu_old, hv_old, hEps,
1271 for (
int j = 0; j < nDOF_trial_element; j++)
1272 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
1275 q_velocity[eN_k_nSpace + 0] =
1276 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hu;
1277 q_velocity[eN_k_nSpace + 1] =
1278 2 * h / (h * h + std::pow(fmax(h, hEps), 2)) * hv;
1279 hnp1_at_quad_point[eN_k] = h;
1280 hunp1_at_quad_point[eN_k] = hu;
1281 hvnp1_at_quad_point[eN_k] = hv;
1283 for (
int i = 0; i < nDOF_test_element; i++) {
1285 elementResidual_h[i] += (h - h_old) * h_test_dV[i];
1286 elementResidual_hu[i] += (hu - hu_old) * h_test_dV[i];
1287 elementResidual_hv[i] += (hv - hv_old) * h_test_dV[i];
1291 for (
int i = 0; i < nDOF_test_element; i++) {
1292 int eN_i = eN * nDOF_test_element + i;
1295 int h_gi = h_l2g[eN_i];
1298 globalResidual[offset_h + stride_h * h_gi] += elementResidual_h[i];
1299 globalResidual[offset_hu + stride_hu * h_gi] += elementResidual_hu[i];
1300 globalResidual[offset_hv + stride_hv * h_gi] += elementResidual_hv[i];
1305 if (SECOND_CALL_CALCULATE_RESIDUAL == 0)
1322 std::valarray<double> wall_nx(0.0, numDOFsPerEqn),
1323 wall_ny(0.0, numDOFsPerEqn);
1326 for (
int i = 0; i < numDOFsPerEqn; i++)
1327 for (
int offset = csrRowIndeces_DofLoops[i];
1328 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1329 if (wall_dof[i] > 0.5 || tailwater_dof[i] > 0.5) {
1330 wall_nx[i] += CTx[ij_w];
1331 wall_ny[i] += CTy[ij_w];
1342 xt::pyarray<double> &delta_Sqd_h = args.
array<
double>(
"delta_Sqd_h");
1343 xt::pyarray<double> &delta_Sqd_kin = args.
array<
double>(
"delta_Sqd_kin");
1344 std::valarray<double> bar_deltaSqd_h(0.0, numDOFsPerEqn),
1345 bar_deltaSqd_kin(0.0, numDOFsPerEqn);
1346 xt::pyarray<double> kin(numDOFsPerEqn), max_of_h_and_hEps(numDOFsPerEqn);
1349 max_of_h_and_hEps = xt::where(h_dof_old > hEps, h_dof_old, hEps);
1350 kin = 0.5 * (hu_dof_old * hu_dof_old + hv_dof_old * hv_dof_old);
1351 kin = kin * (2.0 * h_dof_old /
1352 (h_dof_old * h_dof_old + max_of_h_and_hEps * max_of_h_and_hEps));
1355 std::valarray<double> hBT(0.0, dH_minus_dL.size()),
1356 huBT(0.0, dH_minus_dL.size()), hvBT(0.0, dH_minus_dL.size());
1360 for (
int i = 0; i < numDOFsPerEqn; i++) {
1363 double hi = h_dof_old[i];
1364 double hui = hu_dof_old[i];
1365 double hvi = hv_dof_old[i];
1366 double Zi = b_dof[i];
1367 double mi = lumped_mass_matrix[i];
1368 double one_over_hiReg =
1369 2.0 * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
1370 double ui = hui * one_over_hiReg;
1371 double vi = hvi * one_over_hiReg;
1374 double pressure_i = 0.5 * g * hi * hi;
1375 double phi_i = porosity_dof[i];
1378 for (
int offset = csrRowIndeces_DofLoops[i];
1379 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1380 int j = csrColumnOffsets_DofLoops[offset];
1383 double hj = h_dof_old[j];
1384 double huj = hu_dof_old[j];
1385 double hvj = hv_dof_old[j];
1386 double Zj = b_dof[j];
1387 double one_over_hjReg =
1388 2.0 * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1389 double uj = huj * one_over_hjReg;
1390 double vj = hvj * one_over_hjReg;
1392 double cxa = wall_dof[i] > 0.5 ? -CTx[ij] : Cx[ij];
1393 double cya = wall_dof[i] > 0.5 ? -CTy[ij] : Cy[ij];
1396 double muLowij = 0., muLij = 0., dLowij = 0., dLij = 0.;
1400 bar_deltaSqd_h[i] += 0.5 * delta_Sqd_h[j] + 0.5 * delta_Sqd_h[i];
1401 bar_deltaSqd_kin[i] +=
1402 0.5 * delta_Sqd_kin[j] + 0.5 * delta_Sqd_kin[i];
1407 double cij_norm = sqrt(Cx[ij] * Cx[ij] + Cy[ij] * Cy[ij]);
1408 double cji_norm = sqrt(CTx[ij] * CTx[ij] + CTy[ij] * CTy[ij]);
1409 double nxij = Cx[ij] / cij_norm, nyij = Cy[ij] / cij_norm;
1410 double nxji = CTx[ij] / cji_norm, nyji = CTy[ij] / cji_norm;
1413 huj, hvj, hEps,
false) *
1416 hui, hvi, hEps,
false) *
1418 dLowij *=
phiBar(i, j, porosity_dof);
1424 muLij = fmax(fmax(0., -(ui * cxa + vi * cya)),
1425 fmax(0., (uj * cxa + vj * cya)));
1426 if (wall_dof[i] > 0.5 || wall_dof[j] > 0.5)
1428 wall_dof, Cx, Cy, CTx, CTy));
1429 muLij *=
phiBar(i, j, porosity_dof);
1432 dLij = fmax(dLowij, muLij);
1433 dLow[ij] = fmax(dLij, muLij);
1440 double pressure_j = 0.5 * g * hj * hj;
1443 double hStarij = NO_STAR_STATES ? hi : fmax(0., hi + Zi - fmax(Zi, Zj));
1444 double huStarij = hui * hStarij * one_over_hiReg;
1445 double hvStarij = hvi * hStarij * one_over_hiReg;
1446 double hStarji = NO_STAR_STATES ? hj : fmax(0., hj + Zj - fmax(Zi, Zj));
1447 double huStarji = huj * hStarji * one_over_hjReg;
1448 double hvStarji = hvj * hStarji * one_over_hjReg;
1450 double hBar_ij = 0., hTilde_ij = 0., huBar_ij = 0., huTilde_ij = 0.,
1451 hvBar_ij = 0., hvTilde_ij = 0.;
1454 double phi_j = porosity_dof[j];
1455 hBar_ij = -1. / (2.0 * fmax(dLij, dij_small)) *
1456 ((phi_j * uj * hj - phi_i * ui * hi) * cxa +
1457 (phi_j * vj * hj - phi_i * vi * hi) * cya) +
1459 hTilde_ij = (dLij - muLij) / (2.0 * fmax(dLij, dij_small)) *
1460 (hStarji - hj - (hStarij - hi));
1463 -1. / (2.0 * fmax(dLij, dij_small)) *
1464 ((phi_j * uj * huj - phi_i * ui * hui) * cxa +
1465 (phi_j * vj * huj - phi_i * vi * hui) * cya +
1466 phi_i * (pressure_j - pressure_i) * Cx[ij]) +
1468 huTilde_ij = (dLij - muLij) / (2.0 * fmax(dLij, dij_small)) *
1469 (huStarji - huj - (huStarij - hui));
1472 -1. / (2.0 * fmax(dLij, dij_small)) *
1473 ((phi_j * uj * hvj - phi_i * ui * hvi) * cxa +
1474 (phi_j * vj * hvj - phi_i * vi * hvi) * cya +
1475 phi_i * (pressure_j - pressure_i) * Cy[ij]) +
1477 hvTilde_ij = (dLij - muLij) / (2.0 * fmax(dLij, dij_small)) *
1478 (hvStarji - hvj - (hvStarij - hvi));
1481 hBT[ij] = hBar_ij + hTilde_ij;
1482 huBT[ij] = huBar_ij + huTilde_ij;
1483 hvBT[ij] = hvBar_ij + hvTilde_ij;
1499 (csrRowIndeces_DofLoops[i + 1] - csrRowIndeces_DofLoops[i] - 1) /
1501 bar_deltaSqd_kin[i] =
1502 bar_deltaSqd_kin[i] /
1503 (csrRowIndeces_DofLoops[i + 1] - csrRowIndeces_DofLoops[i] - 1) /
1510 for (
int i = 0; i < numDOFsPerEqn; i++) {
1513 double mi = lumped_mass_matrix[i];
1516 h_min[i] = h_dof_old[i];
1517 h_max[i] = h_dof_old[i];
1520 hLow[i] = h_dof_old[i];
1521 huLow[i] = hu_dof_old[i];
1522 hvLow[i] = hv_dof_old[i];
1523 kin_max[i] = kin[i];
1524 if (BOUNDS_EXCLUDE_SELF) {
1526 h_max[i] = -1.0e300;
1531 for (
int offset = csrRowIndeces_DofLoops[i];
1532 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1534 int j = csrColumnOffsets_DofLoops[offset];
1536 double one_over_hBT =
1538 (hBT[ij] * hBT[ij] + std::pow(fmax(hBT[ij], hEps), 2));
1539 double psi_ij = one_over_hBT *
1540 (huBT[ij] * huBT[ij] + hvBT[ij] * hvBT[ij]) /
1544 if (!(BOUNDS_EXCLUDE_SELF && j == i)) {
1545 kin_max[i] = fmax(psi_ij, kin_max[i]);
1546 if (!NODAL_H_BOUNDS) {
1547 h_min[i] = std::min(h_min[i], hBT[ij]);
1548 h_max[i] = std::max(h_max[i], hBT[ij]);
1553 if (NODAL_H_BOUNDS) {
1554 h_min[i] = std::min(h_min[i], h_dof_old[j]);
1555 h_max[i] = std::max(h_max[i], h_dof_old[j]);
1561 hLow[i] += h_dof_old[i] * (-dt / mi * 2 * dLow[ij]) +
1562 dt / mi * (2 * dLow[ij] * hBT[ij]);
1563 huLow[i] += hu_dof_old[i] * (-dt / mi * 2 * dLow[ij]) +
1564 dt / mi * (2 * dLow[ij] * huBT[ij]);
1565 hvLow[i] += hv_dof_old[i] * (-dt / mi * 2 * dLow[ij]) +
1566 dt / mi * (2 * dLow[ij] * hvBT[ij]);
1574 if (wall_dof[i] > 0.5) {
1575 double one_over_hiReg_w =
1576 2.0 * h_dof_old[i] /
1577 (h_dof_old[i] * h_dof_old[i] +
1578 std::pow(fmax(h_dof_old[i], hEps), 2));
1579 double un_i = (hu_dof_old[i] * wall_nx[i] + hv_dof_old[i] * wall_ny[i]) *
1581 un_i *= porosity_dof[i];
1582 hLow[i] += dt / mi * un_i * h_dof_old[i];
1583 huLow[i] += dt / mi * un_i * hu_dof_old[i];
1584 hvLow[i] += dt / mi * un_i * hv_dof_old[i];
1585 if (wall_dof[i] > 1.5) {
1586 double dp_w, rate_w;
1587 wallRiemann(g, h_dof_old[i], hu_dof_old[i], hv_dof_old[i],
1588 wall_nx[i], wall_ny[i], hEps, dp_w, rate_w);
1589 huLow[i] -= dt / mi * porosity_dof[i] * dp_w * wall_nx[i];
1590 hvLow[i] -= dt / mi * porosity_dof[i] * dp_w * wall_ny[i];
1594 h_min[i] = std::min(h_min[i], hLow[i]);
1595 h_max[i] = std::max(h_max[i], hLow[i]);
1596 const double one_over_hLow =
1598 (hLow[i] * hLow[i] + std::pow(fmax(hLow[i], hEps), 2));
1599 kin_max[i] = fmax(kin_max[i],
1600 0.5 * one_over_hLow *
1601 (huLow[i] * huLow[i] + hvLow[i] * hvLow[i]));
1606 if (tailwater_dof[i] > 0.5) {
1607 double dFh_t, dFhu_t, dFhv_t, rate_t;
1608 tailwaterFlux(g, h_dof_old[i], hu_dof_old[i], hv_dof_old[i],
1609 tailwater_depth_dof[i], wall_nx[i], wall_ny[i], hEps,
1610 dFh_t, dFhu_t, dFhv_t, rate_t);
1611 hLow[i] -= dt / mi * porosity_dof[i] * dFh_t;
1612 huLow[i] -= dt / mi * porosity_dof[i] * dFhu_t;
1613 hvLow[i] -= dt / mi * porosity_dof[i] * dFhv_t;
1614 hLow[i] = fmax(hLow[i], 0.);
1615 h_min[i] = std::min(h_min[i], hLow[i]);
1616 h_max[i] = std::max(h_max[i], hLow[i]);
1617 const double one_over_hLow_t =
1619 (hLow[i] * hLow[i] + std::pow(fmax(hLow[i], hEps), 2));
1620 kin_max[i] = fmax(kin_max[i],
1621 0.5 * one_over_hLow_t *
1622 (huLow[i] * huLow[i] + hvLow[i] * hvLow[i]));
1627 kin_max[i] = std::min(urelax[i] * kin_max[i],
1628 kin_max[i] + std::abs(bar_deltaSqd_kin[i]));
1629 if (!NODAL_H_BOUNDS) {
1630 h_min[i] = std::max(drelax[i] * h_min[i],
1631 h_min[i] - std::abs(bar_deltaSqd_h[i]));
1632 h_max[i] = std::min(urelax[i] * h_max[i],
1633 h_max[i] + std::abs(bar_deltaSqd_h[i]));
1650 std::valarray<double> hyp_flux_h(numDOFsPerEqn),
1651 hyp_flux_hu(numDOFsPerEqn), hyp_flux_hv(numDOFsPerEqn),
1652 psi(numDOFsPerEqn), etaMax(numDOFsPerEqn), etaMin(numDOFsPerEqn);
1654 for (
int i = 0; i < numDOFsPerEqn; i++) {
1656 double hi = h_dof_old[i];
1657 double hui = hu_dof_old[i];
1658 double hvi = hv_dof_old[i];
1659 double Zi = b_dof[i];
1661 double one_over_hiReg =
1662 2 * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
1663 double ui = hui * one_over_hiReg;
1664 double vi = hvi * one_over_hiReg;
1665 double mi = lumped_mass_matrix[i];
1673 double phi_i = porosity_dof[i];
1676 if (LINEAR_FRICTION == 1) {
1677 extendedSourceTerm_hu[i] = mannings * hui * mi;
1678 extendedSourceTerm_hv[i] = mannings * hvi * mi;
1681 new_SourceTerm_hu[i] = -mannings * hui * mi;
1682 new_SourceTerm_hv[i] = -mannings * hvi * mi;
1684 double veli_norm = std::sqrt(ui * ui + vi * vi);
1685 double hi_to_the_gamma = std::pow(fmax(hi, hEps), gamma);
1686 double friction_aux =
1689 : (2 * g * n2 * veli_norm * mi /
1691 fmax(hi_to_the_gamma, xi * g * n2 * dt * veli_norm)));
1692 extendedSourceTerm_hu[i] = friction_aux * hui;
1693 extendedSourceTerm_hv[i] = friction_aux * hvi;
1695 new_SourceTerm_hu[i] = -friction_aux * hui;
1696 new_SourceTerm_hv[i] = -friction_aux * hvi;
1704 double veli_norm = std::sqrt(ui * ui + vi * vi);
1705 double K = (drag_alpha_dof[i] + drag_beta_dof[i] * veli_norm) / phi_i;
1707 double drag_aux = 2. * K * mi / (1. + fmax(1., xi * dt * K));
1708 extendedSourceTerm_hu[i] += drag_aux * hui;
1709 extendedSourceTerm_hv[i] += drag_aux * hvi;
1710 new_SourceTerm_hu[i] -= drag_aux * hui;
1711 new_SourceTerm_hv[i] -= drag_aux * hvi;
1722 double alpha_numerator = 0;
1723 double alpha_denominator = 0;
1724 double alpha_zero = 0.5;
1725 double alpha_factor = 1.0 / (1.0 - alpha_zero);
1728 for (
int offset = csrRowIndeces_DofLoops[i];
1729 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1731 int j = csrColumnOffsets_DofLoops[offset];
1734 double hj = h_dof_old[j];
1735 double huj = hu_dof_old[j];
1736 double hvj = hv_dof_old[j];
1737 double Zj = b_dof[j];
1739 double one_over_hjReg =
1740 2.0 * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1741 double uj = huj * one_over_hjReg;
1742 double vj = hvj * one_over_hjReg;
1745 double cxa = wall_dof[i] > 0.5 ? -CTx[ij] : Cx[ij];
1746 double cya = wall_dof[i] > 0.5 ? -CTy[ij] : Cy[ij];
1747 double phi_j = porosity_dof[j];
1748 double aux_h = (phi_j * uj * hj - phi_i * ui * hi) * cxa +
1749 (phi_j * vj * hj - phi_i * vi * hi) * cya;
1750 double aux_hu = (phi_j * uj * huj - phi_i * ui * hui) * cxa +
1751 (phi_j * vj * huj - phi_i * vi * hui) * cya;
1752 double aux_hv = (phi_j * uj * hvj - phi_i * ui * hvi) * cxa +
1753 (phi_j * vj * hvj - phi_i * vi * hvi) * cya;
1756 hyp_flux_h[i] += aux_h;
1757 hyp_flux_hu[i] += aux_hu;
1758 hyp_flux_hv[i] += aux_hv;
1762 extendedSourceTerm_hu[i] += phi_i * g * hi * (hj + Zj) * Cx[ij];
1763 extendedSourceTerm_hv[i] += phi_i * g * hi * (hj + Zj) * Cy[ij];
1765 new_SourceTerm_hu[i] += phi_i * g *
1766 (-hi * (Zj - Zi) + 0.5 * std::pow(hj - hi, 2)) *
1768 new_SourceTerm_hv[i] += phi_i * g *
1769 (-hi * (Zj - Zi) + 0.5 * std::pow(hj - hi, 2)) *
1773 alpha_numerator += hj - hi;
1774 alpha_denominator += fabs(hj - hi);
1781 if (wall_dof[i] > 0.5) {
1782 double un_i = phi_i * (ui * wall_nx[i] + vi * wall_ny[i]);
1783 hyp_flux_h[i] -= un_i * hi;
1784 hyp_flux_hu[i] -= un_i * hui;
1785 hyp_flux_hv[i] -= un_i * hvi;
1786 if (wall_dof[i] > 1.5) {
1787 double dp_w, rate_w;
1788 wallRiemann(g, hi, hui, hvi, wall_nx[i], wall_ny[i], hEps, dp_w,
1790 hyp_flux_hu[i] += phi_i * dp_w * wall_nx[i];
1791 hyp_flux_hv[i] += phi_i * dp_w * wall_ny[i];
1796 if (tailwater_dof[i] > 0.5) {
1797 double dFh_t, dFhu_t, dFhv_t, rate_t;
1798 tailwaterFlux(g, hi, hui, hvi, tailwater_depth_dof[i], wall_nx[i],
1799 wall_ny[i], hEps, dFh_t, dFhu_t, dFhv_t, rate_t);
1800 hyp_flux_h[i] += phi_i * dFh_t;
1801 hyp_flux_hu[i] += phi_i * dFhu_t;
1802 hyp_flux_hv[i] += phi_i * dFhv_t;
1811 if (fabs(alpha_numerator) <= hEps) {
1815 (fabs(alpha_numerator) - hEps) / fabs(alpha_denominator - hEps);
1817 alphai = fmax(alphai - alpha_zero, 0.0) * alpha_factor;
1834 for (
int i = 0; i < numDOFsPerEqn; i++) {
1835 double hi = h_dof_old[i];
1836 double hui = hu_dof_old[i];
1837 double hvi = hv_dof_old[i];
1838 double Zi = b_dof[i];
1839 double mi = lumped_mass_matrix[i];
1841 double one_over_hiReg =
1842 2.0 * hi / (hi * hi + std::pow(fmax(hi, hEps), 2));
1843 double ui = hui * one_over_hiReg;
1844 double vi = hvi * one_over_hiReg;
1847 double pressure_i = 0.5 * g * hi * hi;
1850 double ith_dHij_minus_muHij_times_hStarStates = 0.,
1851 ith_dHij_minus_muHij_times_huStarStates = 0.,
1852 ith_dHij_minus_muHij_times_hvStarStates = 0.,
1853 ith_muHij_times_hStates = 0., ith_muHij_times_huStates = 0.,
1854 ith_muHij_times_hvStates = 0.;
1857 for (
int offset = csrRowIndeces_DofLoops[i];
1858 offset < csrRowIndeces_DofLoops[i + 1]; offset++) {
1859 int j = csrColumnOffsets_DofLoops[offset];
1860 double hj = h_dof_old[j];
1861 double huj = hu_dof_old[j];
1862 double hvj = hv_dof_old[j];
1863 double Zj = b_dof[j];
1864 double one_over_hjReg =
1865 2.0 * hj / (hj * hj + std::pow(fmax(hj, hEps), 2));
1866 double uj = huj * one_over_hjReg;
1867 double vj = hvj * one_over_hjReg;
1870 double pressure_j = 0.5 * g * hj * hj;
1873 double hStarij = NO_STAR_STATES ? hi : fmax(0., hi + Zi - fmax(Zi, Zj));
1874 double huStarij = hui * hStarij * one_over_hiReg;
1875 double hvStarij = hvi * hStarij * one_over_hiReg;
1877 double hStarji = NO_STAR_STATES ? hj : fmax(0., hj + Zj - fmax(Zi, Zj));
1878 double huStarji = huj * hStarji * one_over_hjReg;
1879 double hvStarji = hvj * hStarji * one_over_hjReg;
1882 double muLowij = 0., muLij = 0., muHij = 0.;
1883 double dLowij = 0., dLij = 0., dHij = 0.;
1893 double cij_norm = sqrt(Cx[ij] * Cx[ij] + Cy[ij] * Cy[ij]);
1894 double cji_norm = sqrt(CTx[ij] * CTx[ij] + CTy[ij] * CTy[ij]);
1895 double nxij = Cx[ij] / cij_norm, nyij = Cy[ij] / cij_norm;
1896 double nxji = CTx[ij] / cji_norm, nyji = CTy[ij] / cji_norm;
1899 huj, hvj, hEps,
false) *
1902 hui, hvi, hEps,
false) *
1904 dLowij *=
phiBar(i, j, porosity_dof);
1914 double cxa = wall_dof[i] > 0.5 ? -CTx[ij] : Cx[ij];
1915 double cya = wall_dof[i] > 0.5 ? -CTy[ij] : Cy[ij];
1916 muLowij = fmax(fmax(0., -(ui * cxa + vi * cya)),
1917 fmax(0., (uj * cxa + vj * cya)));
1918 if (wall_dof[i] > 0.5 || wall_dof[j] > 0.5)
1919 muLowij = fmax(muLowij,
1922 muLowij *=
phiBar(i, j, porosity_dof);
1927 dLij = fmax(dLowij, muLij);
1930 dLow[ij] = fmax(dLij, muLij);
1935 double dEVij =
cE * fmax(global_entropy_residual[i],
1936 global_entropy_residual[j]) *
1937 phiBar(i, j, porosity_dof);
1938 dHij = fmin(dLowij, dEVij);
1939 muHij = fmin(muLowij, dEVij);
1943 ith_dHij_minus_muHij_times_hStarStates +=
1944 (dHij - muHij) * (hStarji - hStarij);
1945 ith_dHij_minus_muHij_times_huStarStates +=
1946 (dHij - muHij) * (huStarji - huStarij);
1947 ith_dHij_minus_muHij_times_hvStarStates +=
1948 (dHij - muHij) * (hvStarji - hvStarij);
1951 ith_muHij_times_hStates += muHij * (hj - hi);
1952 ith_muHij_times_huStates += muHij * (huj - hui);
1953 ith_muHij_times_hvStates += muHij * (hvj - hvi);
1956 dH_minus_dL[ij] = dHij - dLij;
1957 muH_minus_muL[ij] = muHij - muLij;
1970 if (LUMPED_MASS_MATRIX == 1) {
1971 globalResidual[offset_h + stride_h * i] =
1973 (hyp_flux_h[i] - ith_dHij_minus_muHij_times_hStarStates -
1974 ith_muHij_times_hStates);
1975 globalResidual[offset_hu + stride_hu * i] =
1977 ((hyp_flux_hu[i] + extendedSourceTerm_hu[i]) -
1978 ith_dHij_minus_muHij_times_huStarStates -
1979 ith_muHij_times_huStates);
1980 globalResidual[offset_hv + stride_hv * i] =
1982 ((hyp_flux_hv[i] + extendedSourceTerm_hv[i]) -
1983 ith_dHij_minus_muHij_times_hvStarStates -
1984 ith_muHij_times_hvStates);
1986 if (globalResidual[offset_h + stride_h * i] >= -hEps &&
1987 globalResidual[offset_h + stride_h * i] < hEps)
1988 globalResidual[offset_h + stride_h * i] = 0;
1992 globalResidual[offset_h + stride_h * i] +=
1993 dt * (hyp_flux_h[i] - ith_dHij_minus_muHij_times_hStarStates -
1994 ith_muHij_times_hStates);
1995 globalResidual[offset_hu + stride_hu * i] +=
1996 dt * (hyp_flux_hu[i] + extendedSourceTerm_hu[i] -
1997 ith_dHij_minus_muHij_times_huStarStates -
1998 ith_muHij_times_huStates);
1999 globalResidual[offset_hv + stride_hv * i] +=
2000 dt * (hyp_flux_hv[i] + extendedSourceTerm_hv[i] -
2001 ith_dHij_minus_muHij_times_hvStarStates -
2002 ith_muHij_times_hvStates);
2009 if (COMPUTE_NORMALS == 1) {
2012 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++) {
2014 ebN = exteriorElementBoundariesArray[ebNE],
2015 eN = elementBoundaryElementsArray[ebN * 2 + 0],
2016 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN * 2 + 0];
2023 ebN_local * nQuadraturePoints_elementBoundary + kb;
2024 double jac_ext[nSpace * nSpace], jacDet_ext,
2025 jacInv_ext[nSpace * nSpace], boundaryJac[nSpace * (nSpace - 1)],
2026 metricTensor[(nSpace - 1) * (nSpace - 1)], metricTensorDetSqrt,
2030 ck.calculateMapping_elementBoundary(
2031 eN, ebN_local, kb, ebN_local_kb, mesh_dof.data(), mesh_l2g.data(),
2032 mesh_trial_trace_ref.data(), mesh_grad_trial_trace_ref.data(),
2033 boundaryJac_ref.data(), jac_ext, jacDet_ext, jacInv_ext,
2034 boundaryJac, metricTensor, metricTensorDetSqrt, normal_ref.data(),
2035 normal, x_ext, y_ext);
2038 for (
int i = 0; i < nDOF_test_element; i++) {
2039 int eN_i = eN * nDOF_test_element + i;
2040 int gi = h_l2g[eN_i];
2041 normalx[gi] += 0.5 * normal[0] * (i == ebN_local ? 0. : 1.);
2042 normaly[gi] += 0.5 * normal[1] * (i == ebN_local ? 0. : 1.);
2046 for (
int gi = 0; gi < numDOFsPerEqn; gi++) {
2047 double norm_factor =
2048 sqrt(std::pow(normalx[gi], 2) + std::pow(normaly[gi], 2));
2049 if (norm_factor != 0) {
2050 normalx[gi] /= norm_factor;
2051 normaly[gi] /= norm_factor;
2059 xt::pyarray<double> &mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
2060 xt::pyarray<double> &mesh_grad_trial_ref =
2061 args.
array<
double>(
"mesh_grad_trial_ref");
2062 xt::pyarray<double> &mesh_dof = args.
array<
double>(
"mesh_dof");
2063 xt::pyarray<double> &mesh_velocity_dof =
2064 args.
array<
double>(
"mesh_velocity_dof");
2065 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
2066 xt::pyarray<int> &mesh_l2g = args.
array<
int>(
"mesh_l2g");
2067 xt::pyarray<double> &dV_ref = args.
array<
double>(
"dV_ref");
2068 xt::pyarray<double> &h_trial_ref = args.
array<
double>(
"h_trial_ref");
2069 xt::pyarray<double> &h_grad_trial_ref =
2070 args.
array<
double>(
"h_grad_trial_ref");
2071 xt::pyarray<double> &h_test_ref = args.
array<
double>(
"h_test_ref");
2072 xt::pyarray<double> &h_grad_test_ref =
2073 args.
array<
double>(
"h_grad_test_ref");
2074 xt::pyarray<double> &vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
2075 xt::pyarray<double> &vel_grad_trial_ref =
2076 args.
array<
double>(
"vel_grad_trial_ref");
2077 xt::pyarray<double> &vel_test_ref = args.
array<
double>(
"vel_test_ref");
2078 xt::pyarray<double> &vel_grad_test_ref =
2079 args.
array<
double>(
"vel_grad_test_ref");
2080 xt::pyarray<double> &mesh_trial_trace_ref =
2081 args.
array<
double>(
"mesh_trial_trace_ref");
2082 xt::pyarray<double> &mesh_grad_trial_trace_ref =
2083 args.
array<
double>(
"mesh_grad_trial_trace_ref");
2084 xt::pyarray<double> &dS_ref = args.
array<
double>(
"dS_ref");
2085 xt::pyarray<double> &h_trial_trace_ref =
2086 args.
array<
double>(
"h_trial_trace_ref");
2087 xt::pyarray<double> &h_grad_trial_trace_ref =
2088 args.
array<
double>(
"h_grad_trial_trace_ref");
2089 xt::pyarray<double> &h_test_trace_ref =
2090 args.
array<
double>(
"h_test_trace_ref");
2091 xt::pyarray<double> &h_grad_test_trace_ref =
2092 args.
array<
double>(
"h_grad_test_trace_ref");
2093 xt::pyarray<double> &vel_trial_trace_ref =
2094 args.
array<
double>(
"vel_trial_trace_ref");
2095 xt::pyarray<double> &vel_grad_trial_trace_ref =
2096 args.
array<
double>(
"vel_grad_trial_trace_ref");
2097 xt::pyarray<double> &vel_test_trace_ref =
2098 args.
array<
double>(
"vel_test_trace_ref");
2099 xt::pyarray<double> &vel_grad_test_trace_ref =
2100 args.
array<
double>(
"vel_grad_test_trace_ref");
2101 xt::pyarray<double> &normal_ref = args.
array<
double>(
"normal_ref");
2102 xt::pyarray<double> &boundaryJac_ref =
2103 args.
array<
double>(
"boundaryJac_ref");
2104 xt::pyarray<double> &elementDiameter =
2105 args.
array<
double>(
"elementDiameter");
2106 int nElements_global = args.
scalar<
int>(
"nElements_global");
2107 double g = args.
scalar<
double>(
"g");
2108 xt::pyarray<int> &h_l2g = args.
array<
int>(
"h_l2g");
2109 xt::pyarray<int> &vel_l2g = args.
array<
int>(
"vel_l2g");
2110 xt::pyarray<double> &b_dof = args.
array<
double>(
"b_dof");
2111 xt::pyarray<double> &h_dof = args.
array<
double>(
"h_dof");
2112 xt::pyarray<double> &hu_dof = args.
array<
double>(
"hu_dof");
2113 xt::pyarray<double> &hv_dof = args.
array<
double>(
"hv_dof");
2114 xt::pyarray<double> &q_cfl = args.
array<
double>(
"q_cfl");
2115 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
2116 args.
array<
int>(
"sdInfo_hu_hu_rowptr");
2117 xt::pyarray<int> &sdInfo_hu_hu_colind =
2118 args.
array<
int>(
"sdInfo_hu_hu_colind");
2119 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
2120 args.
array<
int>(
"sdInfo_hu_hv_rowptr");
2121 xt::pyarray<int> &sdInfo_hu_hv_colind =
2122 args.
array<
int>(
"sdInfo_hu_hv_colind");
2123 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
2124 args.
array<
int>(
"sdInfo_hv_hv_rowptr");
2125 xt::pyarray<int> &sdInfo_hv_hv_colind =
2126 args.
array<
int>(
"sdInfo_hv_hv_colind");
2127 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
2128 args.
array<
int>(
"sdInfo_hv_hu_rowptr");
2129 xt::pyarray<int> &sdInfo_hv_hu_colind =
2130 args.
array<
int>(
"sdInfo_hv_hu_colind");
2131 xt::pyarray<int> &csrRowIndeces_h_h = args.
array<
int>(
"csrRowIndeces_h_h");
2132 xt::pyarray<int> &csrColumnOffsets_h_h =
2133 args.
array<
int>(
"csrColumnOffsets_h_h");
2134 xt::pyarray<int> &csrRowIndeces_h_hu =
2135 args.
array<
int>(
"csrRowIndeces_h_hu");
2136 xt::pyarray<int> &csrColumnOffsets_h_hu =
2137 args.
array<
int>(
"csrColumnOffsets_h_hu");
2138 xt::pyarray<int> &csrRowIndeces_h_hv =
2139 args.
array<
int>(
"csrRowIndeces_h_hv");
2140 xt::pyarray<int> &csrColumnOffsets_h_hv =
2141 args.
array<
int>(
"csrColumnOffsets_h_hv");
2142 xt::pyarray<int> &csrRowIndeces_hu_h =
2143 args.
array<
int>(
"csrRowIndeces_hu_h");
2144 xt::pyarray<int> &csrColumnOffsets_hu_h =
2145 args.
array<
int>(
"csrColumnOffsets_hu_h");
2146 xt::pyarray<int> &csrRowIndeces_hu_hu =
2147 args.
array<
int>(
"csrRowIndeces_hu_hu");
2148 xt::pyarray<int> &csrColumnOffsets_hu_hu =
2149 args.
array<
int>(
"csrColumnOffsets_hu_hu");
2150 xt::pyarray<int> &csrRowIndeces_hu_hv =
2151 args.
array<
int>(
"csrRowIndeces_hu_hv");
2152 xt::pyarray<int> &csrColumnOffsets_hu_hv =
2153 args.
array<
int>(
"csrColumnOffsets_hu_hv");
2154 xt::pyarray<int> &csrRowIndeces_hv_h =
2155 args.
array<
int>(
"csrRowIndeces_hv_h");
2156 xt::pyarray<int> &csrColumnOffsets_hv_h =
2157 args.
array<
int>(
"csrColumnOffsets_hv_h");
2158 xt::pyarray<int> &csrRowIndeces_hv_hu =
2159 args.
array<
int>(
"csrRowIndeces_hv_hu");
2160 xt::pyarray<int> &csrColumnOffsets_hv_hu =
2161 args.
array<
int>(
"csrColumnOffsets_hv_hu");
2162 xt::pyarray<int> &csrRowIndeces_hv_hv =
2163 args.
array<
int>(
"csrRowIndeces_hv_hv");
2164 xt::pyarray<int> &csrColumnOffsets_hv_hv =
2165 args.
array<
int>(
"csrColumnOffsets_hv_hv");
2166 xt::pyarray<double> &globalJacobian = args.
array<
double>(
"globalJacobian");
2167 xt::pyarray<double> &porosity_dof = args.
array<
double>(
"porosity_dof");
2168 int nExteriorElementBoundaries_global =
2169 args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2170 xt::pyarray<int> &exteriorElementBoundariesArray =
2171 args.
array<
int>(
"exteriorElementBoundariesArray");
2172 xt::pyarray<int> &elementBoundaryElementsArray =
2173 args.
array<
int>(
"elementBoundaryElementsArray");
2174 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
2175 args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2176 xt::pyarray<int> &isDOFBoundary_h = args.
array<
int>(
"isDOFBoundary_h");
2177 xt::pyarray<int> &isDOFBoundary_hu = args.
array<
int>(
"isDOFBoundary_hu");
2178 xt::pyarray<int> &isDOFBoundary_hv = args.
array<
int>(
"isDOFBoundary_hv");
2179 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
2180 args.
array<
int>(
"isAdvectiveFluxBoundary_h");
2181 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
2182 args.
array<
int>(
"isAdvectiveFluxBoundary_hu");
2183 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
2184 args.
array<
int>(
"isAdvectiveFluxBoundary_hv");
2185 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
2186 args.
array<
int>(
"isDiffusiveFluxBoundary_hu");
2187 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
2188 args.
array<
int>(
"isDiffusiveFluxBoundary_hv");
2189 xt::pyarray<double> &ebqe_bc_h_ext = args.
array<
double>(
"ebqe_bc_h_ext");
2190 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
2191 args.
array<
double>(
"ebqe_bc_flux_mass_ext");
2192 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
2193 args.
array<
double>(
"ebqe_bc_flux_mom_hu_adv_ext");
2194 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
2195 args.
array<
double>(
"ebqe_bc_flux_mom_hv_adv_ext");
2196 xt::pyarray<double> &ebqe_bc_hu_ext = args.
array<
double>(
"ebqe_bc_hu_ext");
2197 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
2198 args.
array<
double>(
"ebqe_bc_flux_hu_diff_ext");
2199 xt::pyarray<double> &ebqe_penalty_ext =
2200 args.
array<
double>(
"ebqe_penalty_ext");
2201 xt::pyarray<double> &ebqe_bc_hv_ext = args.
array<
double>(
"ebqe_bc_hv_ext");
2202 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
2203 args.
array<
double>(
"ebqe_bc_flux_hv_diff_ext");
2204 xt::pyarray<int> &csrColumnOffsets_eb_h_h =
2205 args.
array<
int>(
"csrColumnOffsets_eb_h_h");
2206 xt::pyarray<int> &csrColumnOffsets_eb_h_hu =
2207 args.
array<
int>(
"csrColumnOffsets_eb_h_hu");
2208 xt::pyarray<int> &csrColumnOffsets_eb_h_hv =
2209 args.
array<
int>(
"csrColumnOffsets_eb_h_hv");
2210 xt::pyarray<int> &csrColumnOffsets_eb_hu_h =
2211 args.
array<
int>(
"csrColumnOffsets_eb_hu_h");
2212 xt::pyarray<int> &csrColumnOffsets_eb_hu_hu =
2213 args.
array<
int>(
"csrColumnOffsets_eb_hu_hu");
2214 xt::pyarray<int> &csrColumnOffsets_eb_hu_hv =
2215 args.
array<
int>(
"csrColumnOffsets_eb_hu_hv");
2216 xt::pyarray<int> &csrColumnOffsets_eb_hv_h =
2217 args.
array<
int>(
"csrColumnOffsets_eb_hv_h");
2218 xt::pyarray<int> &csrColumnOffsets_eb_hv_hu =
2219 args.
array<
int>(
"csrColumnOffsets_eb_hv_hu");
2220 xt::pyarray<int> &csrColumnOffsets_eb_hv_hv =
2221 args.
array<
int>(
"csrColumnOffsets_eb_hv_hv");
2222 double dt = args.
scalar<
double>(
"dt");
2227 for (
int eN = 0; eN < nElements_global; eN++) {
2228 double elementJacobian_h_h[nDOF_test_element]
2229 [nDOF_trial_element],
2230 elementJacobian_hu_hu[nDOF_test_element][nDOF_trial_element],
2231 elementJacobian_hv_hv[nDOF_test_element][nDOF_trial_element];
2232 for (
int i = 0; i < nDOF_test_element; i++)
2233 for (
int j = 0; j < nDOF_trial_element; j++) {
2234 elementJacobian_h_h[i][j] = 0.0;
2235 elementJacobian_hu_hu[i][j] = 0.0;
2236 elementJacobian_hv_hv[i][j] = 0.0;
2238 for (
int k = 0; k < nQuadraturePoints_element; k++) {
2239 int eN_k = eN * nQuadraturePoints_element +
2241 eN_k_nSpace = eN_k * nSpace,
2242 eN_nDOF_trial_element =
2247 double jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
2248 dV, h_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element], x,
2251 ck.calculateMapping_element(
2252 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
2253 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
2256 dV = fabs(jacDet) * dV_ref[k];
2259 ck.valFromDOF(porosity_dof.data(),
2260 &h_l2g.data()[eN * nDOF_trial_element],
2261 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
2265 for (
int j = 0; j < nDOF_trial_element; j++) {
2266 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
2267 vel_test_dV[j] = vel_test_ref[k * nDOF_trial_element + j] * dV;
2269 for (
int i = 0; i < nDOF_test_element; i++) {
2270 int i_nSpace = i * nSpace;
2271 for (
int j = 0; j < nDOF_trial_element; j++) {
2272 int j_nSpace = j * nSpace;
2273 elementJacobian_h_h[i][j] +=
2274 h_trial_ref[k * nDOF_trial_element + j] * h_test_dV[i];
2275 elementJacobian_hu_hu[i][j] +=
2276 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2277 elementJacobian_hv_hv[i][j] +=
2278 vel_trial_ref[k * nDOF_trial_element + j] * vel_test_dV[i];
2285 for (
int i = 0; i < nDOF_test_element; i++) {
2286 int eN_i = eN * nDOF_test_element + i;
2287 for (
int j = 0; j < nDOF_trial_element; j++) {
2288 int eN_i_j = eN_i * nDOF_trial_element + j;
2289 globalJacobian[csrRowIndeces_h_h[eN_i] +
2290 csrColumnOffsets_h_h[eN_i_j]] +=
2291 elementJacobian_h_h[i][j];
2292 globalJacobian[csrRowIndeces_hu_hu[eN_i] +
2293 csrColumnOffsets_hu_hu[eN_i_j]] +=
2294 elementJacobian_hu_hu[i][j];
2295 globalJacobian[csrRowIndeces_hv_hv[eN_i] +
2296 csrColumnOffsets_hv_hv[eN_i_j]] +=
2297 elementJacobian_hv_hv[i][j];
2304 xt::pyarray<double> &mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
2305 xt::pyarray<double> &mesh_grad_trial_ref =
2306 args.
array<
double>(
"mesh_grad_trial_ref");
2307 xt::pyarray<double> &mesh_dof = args.
array<
double>(
"mesh_dof");
2308 xt::pyarray<double> &mesh_velocity_dof =
2309 args.
array<
double>(
"mesh_velocity_dof");
2310 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
2311 xt::pyarray<int> &mesh_l2g = args.
array<
int>(
"mesh_l2g");
2312 xt::pyarray<double> &dV_ref = args.
array<
double>(
"dV_ref");
2313 xt::pyarray<double> &h_trial_ref = args.
array<
double>(
"h_trial_ref");
2314 xt::pyarray<double> &h_grad_trial_ref =
2315 args.
array<
double>(
"h_grad_trial_ref");
2316 xt::pyarray<double> &h_test_ref = args.
array<
double>(
"h_test_ref");
2317 xt::pyarray<double> &h_grad_test_ref =
2318 args.
array<
double>(
"h_grad_test_ref");
2319 xt::pyarray<double> &vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
2320 xt::pyarray<double> &vel_grad_trial_ref =
2321 args.
array<
double>(
"vel_grad_trial_ref");
2322 xt::pyarray<double> &vel_test_ref = args.
array<
double>(
"vel_test_ref");
2323 xt::pyarray<double> &vel_grad_test_ref =
2324 args.
array<
double>(
"vel_grad_test_ref");
2325 xt::pyarray<double> &mesh_trial_trace_ref =
2326 args.
array<
double>(
"mesh_trial_trace_ref");
2327 xt::pyarray<double> &mesh_grad_trial_trace_ref =
2328 args.
array<
double>(
"mesh_grad_trial_trace_ref");
2329 xt::pyarray<double> &dS_ref = args.
array<
double>(
"dS_ref");
2330 xt::pyarray<double> &h_trial_trace_ref =
2331 args.
array<
double>(
"h_trial_trace_ref");
2332 xt::pyarray<double> &h_grad_trial_trace_ref =
2333 args.
array<
double>(
"h_grad_trial_trace_ref");
2334 xt::pyarray<double> &h_test_trace_ref =
2335 args.
array<
double>(
"h_test_trace_ref");
2336 xt::pyarray<double> &h_grad_test_trace_ref =
2337 args.
array<
double>(
"h_grad_test_trace_ref");
2338 xt::pyarray<double> &vel_trial_trace_ref =
2339 args.
array<
double>(
"vel_trial_trace_ref");
2340 xt::pyarray<double> &vel_grad_trial_trace_ref =
2341 args.
array<
double>(
"vel_grad_trial_trace_ref");
2342 xt::pyarray<double> &vel_test_trace_ref =
2343 args.
array<
double>(
"vel_test_trace_ref");
2344 xt::pyarray<double> &vel_grad_test_trace_ref =
2345 args.
array<
double>(
"vel_grad_test_trace_ref");
2346 xt::pyarray<double> &normal_ref = args.
array<
double>(
"normal_ref");
2347 xt::pyarray<double> &boundaryJac_ref =
2348 args.
array<
double>(
"boundaryJac_ref");
2349 xt::pyarray<double> &elementDiameter =
2350 args.
array<
double>(
"elementDiameter");
2351 int nElements_global = args.
scalar<
int>(
"nElements_global");
2352 double g = args.
scalar<
double>(
"g");
2353 xt::pyarray<int> &h_l2g = args.
array<
int>(
"h_l2g");
2354 xt::pyarray<int> &vel_l2g = args.
array<
int>(
"vel_l2g");
2355 xt::pyarray<double> &b_dof = args.
array<
double>(
"b_dof");
2356 xt::pyarray<double> &h_dof = args.
array<
double>(
"h_dof");
2357 xt::pyarray<double> &hu_dof = args.
array<
double>(
"hu_dof");
2358 xt::pyarray<double> &hv_dof = args.
array<
double>(
"hv_dof");
2359 xt::pyarray<double> &q_cfl = args.
array<
double>(
"q_cfl");
2360 xt::pyarray<int> &sdInfo_hu_hu_rowptr =
2361 args.
array<
int>(
"sdInfo_hu_hu_rowptr");
2362 xt::pyarray<int> &sdInfo_hu_hu_colind =
2363 args.
array<
int>(
"sdInfo_hu_hu_colind");
2364 xt::pyarray<int> &sdInfo_hu_hv_rowptr =
2365 args.
array<
int>(
"sdInfo_hu_hv_rowptr");
2366 xt::pyarray<int> &sdInfo_hu_hv_colind =
2367 args.
array<
int>(
"sdInfo_hu_hv_colind");
2368 xt::pyarray<int> &sdInfo_hv_hv_rowptr =
2369 args.
array<
int>(
"sdInfo_hv_hv_rowptr");
2370 xt::pyarray<int> &sdInfo_hv_hv_colind =
2371 args.
array<
int>(
"sdInfo_hv_hv_colind");
2372 xt::pyarray<int> &sdInfo_hv_hu_rowptr =
2373 args.
array<
int>(
"sdInfo_hv_hu_rowptr");
2374 xt::pyarray<int> &sdInfo_hv_hu_colind =
2375 args.
array<
int>(
"sdInfo_hv_hu_colind");
2376 xt::pyarray<int> &csrRowIndeces_h_h = args.
array<
int>(
"csrRowIndeces_h_h");
2377 xt::pyarray<int> &csrColumnOffsets_h_h =
2378 args.
array<
int>(
"csrColumnOffsets_h_h");
2379 xt::pyarray<int> &csrRowIndeces_h_hu =
2380 args.
array<
int>(
"csrRowIndeces_h_hu");
2381 xt::pyarray<int> &csrColumnOffsets_h_hu =
2382 args.
array<
int>(
"csrColumnOffsets_h_hu");
2383 xt::pyarray<int> &csrRowIndeces_h_hv =
2384 args.
array<
int>(
"csrRowIndeces_h_hv");
2385 xt::pyarray<int> &csrColumnOffsets_h_hv =
2386 args.
array<
int>(
"csrColumnOffsets_h_hv");
2387 xt::pyarray<int> &csrRowIndeces_hu_h =
2388 args.
array<
int>(
"csrRowIndeces_hu_h");
2389 xt::pyarray<int> &csrColumnOffsets_hu_h =
2390 args.
array<
int>(
"csrColumnOffsets_hu_h");
2391 xt::pyarray<int> &csrRowIndeces_hu_hu =
2392 args.
array<
int>(
"csrRowIndeces_hu_hu");
2393 xt::pyarray<int> &csrColumnOffsets_hu_hu =
2394 args.
array<
int>(
"csrColumnOffsets_hu_hu");
2395 xt::pyarray<int> &csrRowIndeces_hu_hv =
2396 args.
array<
int>(
"csrRowIndeces_hu_hv");
2397 xt::pyarray<int> &csrColumnOffsets_hu_hv =
2398 args.
array<
int>(
"csrColumnOffsets_hu_hv");
2399 xt::pyarray<int> &csrRowIndeces_hv_h =
2400 args.
array<
int>(
"csrRowIndeces_hv_h");
2401 xt::pyarray<int> &csrColumnOffsets_hv_h =
2402 args.
array<
int>(
"csrColumnOffsets_hv_h");
2403 xt::pyarray<int> &csrRowIndeces_hv_hu =
2404 args.
array<
int>(
"csrRowIndeces_hv_hu");
2405 xt::pyarray<int> &csrColumnOffsets_hv_hu =
2406 args.
array<
int>(
"csrColumnOffsets_hv_hu");
2407 xt::pyarray<int> &csrRowIndeces_hv_hv =
2408 args.
array<
int>(
"csrRowIndeces_hv_hv");
2409 xt::pyarray<int> &csrColumnOffsets_hv_hv =
2410 args.
array<
int>(
"csrColumnOffsets_hv_hv");
2411 xt::pyarray<double> &globalJacobian = args.
array<
double>(
"globalJacobian");
2412 xt::pyarray<double> &porosity_dof = args.
array<
double>(
"porosity_dof");
2413 int nExteriorElementBoundaries_global =
2414 args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2415 xt::pyarray<int> &exteriorElementBoundariesArray =
2416 args.
array<
int>(
"exteriorElementBoundariesArray");
2417 xt::pyarray<int> &elementBoundaryElementsArray =
2418 args.
array<
int>(
"elementBoundaryElementsArray");
2419 xt::pyarray<int> &elementBoundaryLocalElementBoundariesArray =
2420 args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2421 xt::pyarray<int> &isDOFBoundary_h = args.
array<
int>(
"isDOFBoundary_h");
2422 xt::pyarray<int> &isDOFBoundary_hu = args.
array<
int>(
"isDOFBoundary_hu");
2423 xt::pyarray<int> &isDOFBoundary_hv = args.
array<
int>(
"isDOFBoundary_hv");
2424 xt::pyarray<int> &isAdvectiveFluxBoundary_h =
2425 args.
array<
int>(
"isAdvectiveFluxBoundary_h");
2426 xt::pyarray<int> &isAdvectiveFluxBoundary_hu =
2427 args.
array<
int>(
"isAdvectiveFluxBoundary_hu");
2428 xt::pyarray<int> &isAdvectiveFluxBoundary_hv =
2429 args.
array<
int>(
"isAdvectiveFluxBoundary_hv");
2430 xt::pyarray<int> &isDiffusiveFluxBoundary_hu =
2431 args.
array<
int>(
"isDiffusiveFluxBoundary_hu");
2432 xt::pyarray<int> &isDiffusiveFluxBoundary_hv =
2433 args.
array<
int>(
"isDiffusiveFluxBoundary_hv");
2434 xt::pyarray<double> &ebqe_bc_h_ext = args.
array<
double>(
"ebqe_bc_h_ext");
2435 xt::pyarray<double> &ebqe_bc_flux_mass_ext =
2436 args.
array<
double>(
"ebqe_bc_flux_mass_ext");
2437 xt::pyarray<double> &ebqe_bc_flux_mom_hu_adv_ext =
2438 args.
array<
double>(
"ebqe_bc_flux_mom_hu_adv_ext");
2439 xt::pyarray<double> &ebqe_bc_flux_mom_hv_adv_ext =
2440 args.
array<
double>(
"ebqe_bc_flux_mom_hv_adv_ext");
2441 xt::pyarray<double> &ebqe_bc_hu_ext = args.
array<
double>(
"ebqe_bc_hu_ext");
2442 xt::pyarray<double> &ebqe_bc_flux_hu_diff_ext =
2443 args.
array<
double>(
"ebqe_bc_flux_hu_diff_ext");
2444 xt::pyarray<double> &ebqe_penalty_ext =
2445 args.
array<
double>(
"ebqe_penalty_ext");
2446 xt::pyarray<double> &ebqe_bc_hv_ext = args.
array<
double>(
"ebqe_bc_hv_ext");
2447 xt::pyarray<double> &ebqe_bc_flux_hv_diff_ext =
2448 args.
array<
double>(
"ebqe_bc_flux_hv_diff_ext");
2449 xt::pyarray<int> &csrColumnOffsets_eb_h_h =
2450 args.
array<
int>(
"csrColumnOffsets_eb_h_h");
2451 xt::pyarray<int> &csrColumnOffsets_eb_h_hu =
2452 args.
array<
int>(
"csrColumnOffsets_eb_h_hu");
2453 xt::pyarray<int> &csrColumnOffsets_eb_h_hv =
2454 args.
array<
int>(
"csrColumnOffsets_eb_h_hv");
2455 xt::pyarray<int> &csrColumnOffsets_eb_hu_h =
2456 args.
array<
int>(
"csrColumnOffsets_eb_hu_h");
2457 xt::pyarray<int> &csrColumnOffsets_eb_hu_hu =
2458 args.
array<
int>(
"csrColumnOffsets_eb_hu_hu");
2459 xt::pyarray<int> &csrColumnOffsets_eb_hu_hv =
2460 args.
array<
int>(
"csrColumnOffsets_eb_hu_hv");
2461 xt::pyarray<int> &csrColumnOffsets_eb_hv_h =
2462 args.
array<
int>(
"csrColumnOffsets_eb_hv_h");
2463 xt::pyarray<int> &csrColumnOffsets_eb_hv_hu =
2464 args.
array<
int>(
"csrColumnOffsets_eb_hv_hu");
2465 xt::pyarray<int> &csrColumnOffsets_eb_hv_hv =
2466 args.
array<
int>(
"csrColumnOffsets_eb_hv_hv");
2467 double dt = args.
scalar<
double>(
"dt");
2472 for (
int eN = 0; eN < nElements_global; eN++) {
2473 double elementJacobian_h_h[nDOF_test_element]
2474 [nDOF_trial_element],
2475 elementJacobian_hu_hu[nDOF_test_element][nDOF_trial_element],
2476 elementJacobian_hv_hv[nDOF_test_element][nDOF_trial_element];
2477 for (
int i = 0; i < nDOF_test_element; i++)
2478 for (
int j = 0; j < nDOF_trial_element; j++) {
2479 elementJacobian_h_h[i][j] = 0.0;
2480 elementJacobian_hu_hu[i][j] = 0.0;
2481 elementJacobian_hv_hv[i][j] = 0.0;
2483 for (
int k = 0; k < nQuadraturePoints_element; k++) {
2484 int eN_k = eN * nQuadraturePoints_element +
2486 eN_k_nSpace = eN_k * nSpace,
2487 eN_nDOF_trial_element =
2492 double jac[nSpace * nSpace], jacDet, jacInv[nSpace * nSpace],
2493 dV, h_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element], x,
2496 ck.calculateMapping_element(
2497 eN, k, mesh_dof.data(), mesh_l2g.data(), mesh_trial_ref.data(),
2498 mesh_grad_trial_ref.data(), jac, jacDet, jacInv, x, y);
2501 dV = fabs(jacDet) * dV_ref[k];
2504 ck.valFromDOF(porosity_dof.data(),
2505 &h_l2g.data()[eN * nDOF_trial_element],
2506 &h_trial_ref.data()[k * nDOF_trial_element], phi_q);
2510 for (
int j = 0; j < nDOF_trial_element; j++) {
2511 h_test_dV[j] = h_test_ref[k * nDOF_trial_element + j] * dV;
2512 vel_test_dV[j] = vel_test_ref[k * nDOF_trial_element + j] * dV;
2515 for (
int i = 0; i < nDOF_test_element; i++) {
2516 int i_nSpace = i * nSpace;
2517 for (
int j = 0; j < nDOF_trial_element; j++) {
2518 int j_nSpace = j * nSpace;
2519 elementJacobian_h_h[i][j] += (i == j ? 1.0 : 0.0) * h_test_dV[i];
2520 elementJacobian_hu_hu[i][j] +=
2521 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
2522 elementJacobian_hv_hv[i][j] +=
2523 (i == j ? 1.0 : 0.0) * vel_test_dV[i];
2530 for (
int i = 0; i < nDOF_test_element; i++) {
2531 int eN_i = eN * nDOF_test_element + i;
2532 for (
int j = 0; j < nDOF_trial_element; j++) {
2533 int eN_i_j = eN_i * nDOF_trial_element + j;
2534 globalJacobian[csrRowIndeces_h_h[eN_i] +
2535 csrColumnOffsets_h_h[eN_i_j]] +=
2536 elementJacobian_h_h[i][j];
2537 globalJacobian[csrRowIndeces_hu_hu[eN_i] +
2538 csrColumnOffsets_hu_hu[eN_i_j]] +=
2539 elementJacobian_hu_hu[i][j];
2540 globalJacobian[csrRowIndeces_hv_hv[eN_i] +
2541 csrColumnOffsets_hv_hv[eN_i_j]] +=
2542 elementJacobian_hv_hv[i][j];