9 #include "xtensor-python/pyarray.hpp"
11 namespace py = pybind11;
13 #define POWER_SMOOTHNESS_INDICATOR 2
14 #define IS_BETAij_ONE 0
20 inline double ENTROPY(
const double&
phi,
const double& phiL,
const double& phiR){
21 return 1./2.*std::pow(fabs(
phi),2.);
23 inline double DENTROPY(
const double&
phi,
const double& phiL,
const double& phiR){
24 return fabs(
phi)*(
phi>=0 ? 1 : -1);
27 inline double ENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
28 return std::log(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
30 inline double DENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
31 return (phiL+phiR-2*
phi)*((
phi-phiL)*(phiR-
phi)>=0 ? 1 : -1)/(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
43 std::valarray<double>
solL;
57 template<
class CompKernelType,
59 int nQuadraturePoints_element,
60 int nDOF_mesh_trial_element,
61 int nDOF_trial_element,
62 int nDOF_test_element,
63 int nQuadraturePoints_elementBoundary>
77 const double& porosity,
85 for (
int I=0; I < nSpace; I++)
87 f[I] =
v[I]*porosity*
u;
88 df[I] =
v[I]*porosity;
94 const double df[nSpace],
100 for(
int I=0;I<nSpace;I++)
109 const double dH[nSpace],
113 double h,nrm_v,oneByAbsdt;
116 for(
int I=0;I<nSpace;I++)
120 oneByAbsdt = fabs(dmt);
121 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
126 const double G[nSpace*nSpace],
128 const double Ai[nSpace],
133 for(
int I=0;I<nSpace;I++)
134 for (
int J=0;J<nSpace;J++)
135 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
137 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv + 1.0e-8);
142 const double& elementDiameter,
143 const double& strong_residual,
144 const double grad_u[nSpace],
153 for (
int I=0;I<nSpace;I++)
154 n_grad_u += grad_u[I]*grad_u[I];
155 num = shockCapturingDiffusion*0.5*h*fabs(strong_residual);
156 den = sqrt(n_grad_u) + 1.0e-8;
162 const int& isFluxBoundary_u,
163 const double n[nSpace],
165 const double& bc_flux_u,
167 const double velocity[nSpace],
172 for (
int I=0; I < nSpace; I++)
173 flow +=
n[I]*velocity[I];
174 if (isDOFBoundary_u == 1)
189 else if (isFluxBoundary_u == 1)
215 const int& isFluxBoundary_u,
216 const double n[nSpace],
217 const double velocity[nSpace],
221 for (
int I=0; I < nSpace; I++)
222 flow +=
n[I]*velocity[I];
225 if (isDOFBoundary_u == 1)
236 else if (isFluxBoundary_u == 1)
251 double dt = args.
scalar<
double>(
"dt");
252 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
253 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
254 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
255 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
256 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
257 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
258 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
259 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
260 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
261 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
262 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
263 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
264 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
265 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
266 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
267 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
268 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
269 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
270 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
271 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
272 int nElements_global = args.
scalar<
int>(
"nElements_global");
273 double useMetrics = args.
scalar<
double>(
"useMetrics");
274 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
275 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
276 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
277 double sc_uref = args.
scalar<
double>(
"sc_uref");
278 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
279 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
280 const xt::pyarray<double>& porosity_dof = args.
array<
double>(
"porosity_dof");
281 xt::pyarray<double>& q_dvos_dt = args.
array<
double>(
"q_dvos_dt");
282 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
283 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
284 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
285 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
286 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
287 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
288 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
289 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
290 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
291 xt::pyarray<double>& q_grad_u = args.
array<
double>(
"q_grad_u");
292 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
293 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
294 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
295 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
296 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
297 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
298 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
299 int offset_u = args.
scalar<
int>(
"offset_u");
300 int stride_u = args.
scalar<
int>(
"stride_u");
301 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
302 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
303 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
304 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
305 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
306 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
307 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
308 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
309 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
310 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
311 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
312 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
313 double epsFact = args.
scalar<
double>(
"epsFact");
314 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
315 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
316 double cE = args.
scalar<
double>(
"cE");
317 double cK = args.
scalar<
double>(
"cK");
318 double uL = args.
scalar<
double>(
"uL");
319 double uR = args.
scalar<
double>(
"uR");
320 int numDOFs = args.
scalar<
int>(
"numDOFs");
321 int NNZ = args.
scalar<
int>(
"NNZ");
322 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
323 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
324 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
325 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
326 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
327 xt::pyarray<double>& Cx = args.
array<
double>(
"Cx");
328 xt::pyarray<double>& Cy = args.
array<
double>(
"Cy");
329 xt::pyarray<double>& Cz = args.
array<
double>(
"Cz");
330 xt::pyarray<double>& CTx = args.
array<
double>(
"CTx");
331 xt::pyarray<double>& CTy = args.
array<
double>(
"CTy");
332 xt::pyarray<double>& CTz = args.
array<
double>(
"CTz");
333 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
334 xt::pyarray<double>& delta_x_ij = args.
array<
double>(
"delta_x_ij");
335 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
336 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
337 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
338 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
339 xt::pyarray<double>& fluxMatrix = args.
array<
double>(
"fluxMatrix");
340 xt::pyarray<double>& uDotLow = args.
array<
double>(
"uDotLow");
341 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
342 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
343 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
344 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
345 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
360 for(
int eN=0;eN<nElements_global;eN++)
363 register double elementResidual_u[nDOF_test_element];
364 for (
int i=0;i<nDOF_test_element;i++)
366 elementResidual_u[i]=0.0;
369 for (
int k=0;k<nQuadraturePoints_element;k++)
372 register int eN_k = eN*nQuadraturePoints_element+k,
373 eN_k_nSpace = eN_k*nSpace,
374 eN_nDOF_trial_element = eN*nDOF_trial_element;
375 register double u=0.0,grad_u[nSpace],grad_u_old[nSpace],
377 f[nSpace],
df[nSpace],
380 Lstar_u[nDOF_test_element],
382 tau=0.0,tau0=0.0,tau1=0.0,
383 numDiff0=0.0,numDiff1=0.0,
386 jacInv[nSpace*nSpace],
387 u_grad_trial[nDOF_trial_element*nSpace],
388 u_test_dV[nDOF_trial_element],
389 u_grad_test_dV[nDOF_test_element*nSpace],
394 G[nSpace*nSpace],G_dd_G,tr_G;
414 ck.calculateMapping_element(eN,
418 mesh_trial_ref.data(),
419 mesh_grad_trial_ref.data(),
424 ck.calculateMappingVelocity_element(eN,
426 mesh_velocity_dof.data(),
428 mesh_trial_ref.data(),
431 dV = fabs(jacDet)*dV_ref.data()[k];
432 ck.calculateG(jacInv,G,G_dd_G,tr_G);
434 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
436 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
438 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
439 ck.gradFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u_old);
441 for (
int j=0;j<nDOF_trial_element;j++)
443 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
444 for (
int I=0;I<nSpace;I++)
446 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
452 for(
int I=0;I<nSpace;I++)
454 q_grad_u.data()[eN_k_nSpace+I] = grad_u[I];
458 porosity = q_porosity.data()[eN_k];
475 double mesh_velocity[3];
476 mesh_velocity[0] =
xt;
477 mesh_velocity[1] = yt;
478 mesh_velocity[2] = zt;
480 for (
int I=0;I<nSpace;I++)
483 f[I] -= MOVING_DOMAIN*m*mesh_velocity[I];
484 df[I] -= MOVING_DOMAIN*dm*mesh_velocity[I];
489 if (q_dV_last.data()[eN_k] <= -100)
490 q_dV_last.data()[eN_k] = dV;
491 q_dV.data()[eN_k] = dV;
493 q_m_betaBDF.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
498 q_dvos_dt.data()[eN_k] = m_t;
503 pdeResidual_u =
ck.Mass_strong(m_t) +
ck.Advection_strong(
df,grad_u);
505 for (
int i=0;i<nDOF_test_element;i++)
509 register int i_nSpace = i*nSpace;
510 Lstar_u[i] =
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
521 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
523 subgridError_u = -tau*pdeResidual_u;
527 ck.calculateNumericalDiffusion(shockCapturingDiffusion,elementDiameter.data()[eN],pdeResidual_u,grad_u,numDiff0);
529 ck.calculateNumericalDiffusion(shockCapturingDiffusion,sc_uref, sc_alpha,G,G_dd_G,pdeResidual_u,grad_u,numDiff1);
530 q_numDiff_u.data()[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
543 for(
int i=0;i<nDOF_test_element;i++)
547 register int i_nSpace=i*nSpace;
548 elementResidual_u[i] +=
ck.Mass_weak(m_t,u_test_dV[i]) +
549 ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace]) +
550 ck.SubgridError(subgridError_u,Lstar_u[i]) +
551 ck.NumericalDiffusion(q_numDiff_u_last.data()[eN_k],grad_u,&u_grad_test_dV[i_nSpace]);
558 q_u.data()[eN_k] =
u;
559 q_m.data()[eN_k] = m;
565 for(
int i=0;i<nDOF_test_element;i++)
567 register int eN_i=eN*nDOF_test_element+i;
569 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] += elementResidual_u[i];
578 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
580 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
581 eN = elementBoundaryElementsArray.data()[ebN*2+0],
582 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
583 eN_nDOF_trial_element = eN*nDOF_trial_element;
584 register double elementResidual_u[nDOF_test_element];
585 for (
int i=0;i<nDOF_test_element;i++)
587 elementResidual_u[i]=0.0;
589 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
591 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
592 ebNE_kb_nSpace = ebNE_kb*nSpace,
593 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
594 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
595 register double u_ext=0.0,
608 jac_ext[nSpace*nSpace],
610 jacInv_ext[nSpace*nSpace],
611 boundaryJac[nSpace*(nSpace-1)],
612 metricTensor[(nSpace-1)*(nSpace-1)],
615 u_test_dS[nDOF_test_element],
616 u_grad_trial_trace[nDOF_trial_element*nSpace],
617 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
621 G[nSpace*nSpace],G_dd_G,tr_G;
626 ck.calculateMapping_elementBoundary(eN,
632 mesh_trial_trace_ref.data(),
633 mesh_grad_trial_trace_ref.data(),
634 boundaryJac_ref.data(),
644 ck.calculateMappingVelocity_elementBoundary(eN,
648 mesh_velocity_dof.data(),
650 mesh_trial_trace_ref.data(),
651 xt_ext,yt_ext,zt_ext,
657 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
660 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
663 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
665 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],u_ext);
666 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
668 for (
int j=0;j<nDOF_trial_element;j++)
670 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
675 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
677 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
703 double mesh_velocity[3];
704 mesh_velocity[0] = xt_ext;
705 mesh_velocity[1] = yt_ext;
706 mesh_velocity[2] = zt_ext;
708 for (
int I=0;I<nSpace;I++)
711 f_ext[I] -= MOVING_DOMAIN*m_ext*mesh_velocity[I];
712 df_ext[I] -= MOVING_DOMAIN*dm_ext*mesh_velocity[I];
713 bc_f_ext[I] -= MOVING_DOMAIN*bc_m_ext*mesh_velocity[I];
714 bc_df_ext[I] -= MOVING_DOMAIN*bc_dm_ext*mesh_velocity[I];
720 isFluxBoundary_u.data()[ebNE_kb],
723 ebqe_bc_flux_u_ext.data()[ebNE_kb],
727 ebqe_flux.data()[ebNE_kb] = flux_ext;
730 ebqe_u.data()[ebNE_kb] = u_ext;
732 ebqe_u.data()[ebNE_kb] = bc_u_ext;
736 for (
int i=0;i<nDOF_test_element;i++)
740 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
746 for (
int i=0;i<nDOF_test_element;i++)
748 int eN_i = eN*nDOF_test_element+i;
750 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] += elementResidual_u[i];
757 double dt = args.
scalar<
double>(
"dt");
758 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
759 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
760 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
761 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
762 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
763 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
764 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
765 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
766 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
767 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
768 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
769 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
770 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
771 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
772 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
773 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
774 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
775 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
776 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
777 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
778 int nElements_global = args.
scalar<
int>(
"nElements_global");
779 double useMetrics = args.
scalar<
double>(
"useMetrics");
780 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
781 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
782 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
783 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
784 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
785 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
786 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
787 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
788 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
789 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
790 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
791 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
792 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
793 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
794 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
795 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
796 xt::pyarray<double>& delta_x_ij = args.
array<
double>(
"delta_x_ij");
797 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
798 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
799 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
800 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
801 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
802 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
803 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
804 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
805 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
806 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
807 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
808 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
816 for(
int eN=0;eN<nElements_global;eN++)
818 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
819 for (
int i=0;i<nDOF_test_element;i++)
820 for (
int j=0;j<nDOF_trial_element;j++)
822 elementJacobian_u_u[i][j]=0.0;
824 for (
int k=0;k<nQuadraturePoints_element;k++)
826 int eN_k = eN*nQuadraturePoints_element+k,
827 eN_k_nSpace = eN_k*nSpace,
828 eN_nDOF_trial_element = eN*nDOF_trial_element;
831 register double u=0.0,
834 f[nSpace],
df[nSpace],
836 dpdeResidual_u_u[nDOF_trial_element],
837 Lstar_u[nDOF_test_element],
838 dsubgridError_u_u[nDOF_trial_element],
839 tau=0.0,tau0=0.0,tau1=0.0,
842 jacInv[nSpace*nSpace],
843 u_grad_trial[nDOF_trial_element*nSpace],
845 u_test_dV[nDOF_test_element],
846 u_grad_test_dV[nDOF_test_element*nSpace],
851 G[nSpace*nSpace],G_dd_G,tr_G;
873 ck.calculateMapping_element(eN,
877 mesh_trial_ref.data(),
878 mesh_grad_trial_ref.data(),
883 ck.calculateMappingVelocity_element(eN,
885 mesh_velocity_dof.data(),
887 mesh_trial_ref.data(),
890 dV = fabs(jacDet)*dV_ref.data()[k];
891 ck.calculateG(jacInv,G,G_dd_G,tr_G);
893 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
895 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
897 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
899 for (
int j=0;j<nDOF_trial_element;j++)
901 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
902 for (
int I=0;I<nSpace;I++)
904 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
908 porosity = q_porosity.data()[eN_k];
925 double mesh_velocity[3];
926 mesh_velocity[0] =
xt;
927 mesh_velocity[1] = yt;
928 mesh_velocity[2] = zt;
930 for(
int I=0;I<nSpace;I++)
933 f[I] -= MOVING_DOMAIN*m*mesh_velocity[I];
934 df[I] -= MOVING_DOMAIN*dm*mesh_velocity[I];
940 q_m_betaBDF.data()[eN_k],
949 for (
int i=0;i<nDOF_test_element;i++)
953 register int i_nSpace = i*nSpace;
954 Lstar_u[i]=
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
957 for (
int j=0;j<nDOF_trial_element;j++)
961 int j_nSpace = j*nSpace;
962 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
963 ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
978 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
980 for(
int j=0;j<nDOF_trial_element;j++)
981 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
983 for(
int i=0;i<nDOF_test_element;i++)
987 for(
int j=0;j<nDOF_trial_element;j++)
991 int j_nSpace = j*nSpace;
992 int i_nSpace = i*nSpace;
994 elementJacobian_u_u[i][j] +=
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]) +
995 ck.AdvectionJacobian_weak(
df,u_trial_ref.data()[k*nDOF_trial_element+j],&u_grad_test_dV[i_nSpace]) +
996 ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
997 ck.NumericalDiffusionJacobian(q_numDiff_u_last.data()[eN_k],&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]);
1004 for (
int i=0;i<nDOF_test_element;i++)
1006 int eN_i = eN*nDOF_test_element+i;
1007 for (
int j=0;j<nDOF_trial_element;j++)
1009 int eN_i_j = eN_i*nDOF_trial_element+j;
1010 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
1017 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1019 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
1020 register int eN = elementBoundaryElementsArray.data()[ebN*2+0],
1021 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
1022 eN_nDOF_trial_element = eN*nDOF_trial_element;
1023 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1025 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1026 ebNE_kb_nSpace = ebNE_kb*nSpace,
1027 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1028 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1030 register double u_ext=0.0,
1043 fluxJacobian_u_u[nDOF_trial_element],
1044 jac_ext[nSpace*nSpace],
1046 jacInv_ext[nSpace*nSpace],
1047 boundaryJac[nSpace*(nSpace-1)],
1048 metricTensor[(nSpace-1)*(nSpace-1)],
1049 metricTensorDetSqrt,
1051 u_test_dS[nDOF_test_element],
1052 u_grad_trial_trace[nDOF_trial_element*nSpace],
1053 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
1057 G[nSpace*nSpace],G_dd_G,tr_G;
1079 ck.calculateMapping_elementBoundary(eN,
1085 mesh_trial_trace_ref.data(),
1086 mesh_grad_trial_trace_ref.data(),
1087 boundaryJac_ref.data(),
1093 metricTensorDetSqrt,
1097 ck.calculateMappingVelocity_elementBoundary(eN,
1101 mesh_velocity_dof.data(),
1103 mesh_trial_trace_ref.data(),
1104 xt_ext,yt_ext,zt_ext,
1110 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
1112 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1115 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1117 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],u_ext);
1118 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1120 for (
int j=0;j<nDOF_trial_element;j++)
1122 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
1127 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
1129 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
1155 double mesh_velocity[3];
1156 mesh_velocity[0] = xt_ext;
1157 mesh_velocity[1] = yt_ext;
1158 mesh_velocity[2] = zt_ext;
1160 for (
int I=0;I<nSpace;I++)
1163 f_ext[I] -= MOVING_DOMAIN*m_ext*mesh_velocity[I];
1164 df_ext[I] -= MOVING_DOMAIN*dm_ext*mesh_velocity[I];
1165 bc_f_ext[I] -= MOVING_DOMAIN*bc_m_ext*mesh_velocity[I];
1166 bc_df_ext[I] -= MOVING_DOMAIN*bc_dm_ext*mesh_velocity[I];
1172 isFluxBoundary_u.data()[ebNE_kb],
1179 for (
int j=0;j<nDOF_trial_element;j++)
1182 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1184 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_u_u_ext,u_trial_trace_ref.data()[ebN_local_kb_j]);
1189 for (
int i=0;i<nDOF_test_element;i++)
1191 register int eN_i = eN*nDOF_test_element+i;
1193 for (
int j=0;j<nDOF_trial_element;j++)
1197 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i];
1205 int NNZ = args.
scalar<
int>(
"NNZ");
1206 int numDOFs = args.
scalar<
int>(
"numDOFs");
1207 xt::pyarray<double>& lumped_mass_matrix = args.
array<
double>(
"lumped_mass_matrix");
1208 xt::pyarray<double>& soln = args.
array<
double>(
"soln");
1209 xt::pyarray<double>& solH = args.
array<
double>(
"solH");
1210 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
1211 xt::pyarray<double>& limited_solution = args.
array<
double>(
"limited_solution");
1212 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1213 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1214 xt::pyarray<double>& MassMatrix = args.
array<
double>(
"MassMatrix");
1215 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
1216 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
1217 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
1218 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1219 Rpos.resize(numDOFs,0.0),
Rneg.resize(numDOFs,0.0);
1221 solL.resize(numDOFs,0.0);
1226 for (
int i=0; i<numDOFs; i++)
1229 double solHi = solH.data()[i];
1230 double solni = soln.data()[i];
1231 double mi = lumped_mass_matrix.data()[i];
1234 solL[i] = uLow.data()[i];
1236 double mini=min_u_bc.data()[i], maxi=max_u_bc.data()[i];
1243 double Pposi=0, Pnegi=0;
1245 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1247 int j = csrColumnOffsets_DofLoops.data()[offset];
1253 mini = fmin(mini,soln.data()[j]);
1254 maxi = fmax(maxi,soln.data()[j]);
1257 double ML_minus_MC = (LUMPED_MASS_MATRIX == 1 ? 0. : (i==j ? 1. : 0.)*mi - MassMatrix.data()[ij]);
1259 + dt_times_dH_minus_dL.data()[ij]*(soln.data()[j]-solni);
1273 double Qposi = mi*(maxi-
solL[i]);
1274 double Qnegi = mi*(mini-
solL[i]);
1279 Rpos[i] = ((Pposi==0) ? 1. : fmin(1.0,Qposi/Pposi));
1280 Rneg[i] = ((Pnegi==0) ? 1. : fmin(1.0,Qnegi/Pnegi));
1287 for (
int i=0; i<numDOFs; i++)
1289 double ith_Limiter_times_FluxCorrectionMatrix = 0.;
1290 double Rposi =
Rpos[i], Rnegi =
Rneg[i];
1292 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1294 int j = csrColumnOffsets_DofLoops.data()[offset];
1295 ith_Limiter_times_FluxCorrectionMatrix +=
1302 limited_solution.data()[i] =
solL[i] + 1./lumped_mass_matrix.data()[i]*ith_Limiter_times_FluxCorrectionMatrix;
1308 double dt = args.
scalar<
double>(
"dt");
1309 int num_fct_iter = args.
scalar<
int>(
"num_fct_iter");
1310 int NNZ = args.
scalar<
int>(
"NNZ");
1311 int numDOFs = args.
scalar<
int>(
"numDOFs");
1312 xt::pyarray<double>& MC = args.
array<
double>(
"MC");
1313 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
1314 xt::pyarray<double>& soln = args.
array<
double>(
"soln");
1315 xt::pyarray<double>& solLim = args.
array<
double>(
"solLim");
1316 xt::pyarray<double>& uDotLow = args.
array<
double>(
"uDotLow");
1317 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
1318 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
1319 xt::pyarray<double>& FluxMatrix = args.
array<
double>(
"FluxMatrix");
1320 xt::pyarray<double>& limitedFlux = args.
array<
double>(
"limitedFlux");
1321 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
1322 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
1323 double global_min_u = args.
scalar<
double>(
"global_min_u");
1324 double global_max_u = args.
scalar<
double>(
"global_max_u");
1325 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1326 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1327 Rpos.resize(numDOFs,0.0),
Rneg.resize(numDOFs,0.0);
1333 if (num_fct_iter == 0)
1335 for (
int i=0; i<numDOFs; i++)
1337 solLim.data()[i] = uLow.data()[i];
1342 for (
int iter=0; iter<num_fct_iter; iter++)
1345 for (
int i=0; i<numDOFs; i++)
1347 double Pposi=0, Pnegi=0;
1348 for (
int offset=csrRowIndeces_DofLoops.data()[i];
1349 offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1351 int j = csrColumnOffsets_DofLoops.data()[offset];
1353 double Fluxij = FluxMatrix.data()[ij] - limitedFlux.data()[ij];
1354 Pposi += Fluxij*((Fluxij > 0) ? 1. : 0.);
1355 Pnegi += Fluxij*((Fluxij < 0) ? 1. : 0.);
1360 double mi = ML.data()[i];
1361 double solLimi = solLim.data()[i];
1362 double Qposi = mi*(global_max_u-solLimi);
1363 double Qnegi = mi*(global_min_u-solLimi);
1365 Rpos[i] = ((Pposi==0) ? 1. : fmin(1.0,Qposi/Pposi));
1366 Rneg[i] = ((Pnegi==0) ? 1. : fmin(1.0,Qnegi/Pnegi));
1369 for (
int i=0; i<numDOFs; i++)
1371 double ith_Limiter_times_FluxCorrectionMatrix = 0.;
1372 double Rposi =
Rpos[i], Rnegi =
Rneg[i];
1373 for (
int offset=csrRowIndeces_DofLoops.data()[i];
1374 offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1376 int j = csrColumnOffsets_DofLoops.data()[offset];
1378 double Fluxij = FluxMatrix.data()[ij] - limitedFlux.data()[ij];
1382 Lij = (Fluxij>0 ? fmin(Rposi,
Rneg[j]) : fmin(Rnegi,
Rpos[j]));
1384 ith_Limiter_times_FluxCorrectionMatrix += Lij*Fluxij;
1388 limitedFlux.data()[ij] = Lij*Fluxij;
1391 FluxMatrix.data()[ij] = Fluxij;
1397 double mi = ML.data()[i];
1398 solLim.data()[i] += 1.0/mi*ith_Limiter_times_FluxCorrectionMatrix;
1407 for (
int i=0; i<numDOFs; i++)
1409 double mini=fmin(min_u_bc.data()[i],solLim.data()[i]), maxi=fmax(max_u_bc.data()[i],solLim.data()[i]);
1410 double Pposi = 0, Pnegi = 0.;
1411 for (
int offset=csrRowIndeces_DofLoops.data()[i];
1412 offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1414 int j = csrColumnOffsets_DofLoops.data()[offset];
1416 mini = fmin(mini,soln.data()[j]);
1417 maxi = fmax(maxi,soln.data()[j]);
1419 double fij = dt*(MC.data()[ij]*(uDotLow.data()[i]-uDotLow.data()[j]) + dLow.data()[ij]*(uLow.data()[i]-uLow.data()[j]));
1420 Pposi += fij * (fij > 0. ? 1. : 0.);
1421 Pnegi += fij * (fij < 0. ? 1. : 0.);
1426 double mi = ML.data()[i];
1427 double Qposi = mi*(maxi-solLim.data()[i]);
1428 double Qnegi = mi*(mini-solLim.data()[i]);
1431 Rpos[i] = ((Pposi==0) ? 1. : fmin(1.0,Qposi/Pposi));
1432 Rneg[i] = ((Pnegi==0) ? 1. : fmin(1.0,Qnegi/Pnegi));
1437 for (
int i=0; i<numDOFs; i++)
1439 double ith_limited_flux_correction = 0;
1440 double Rposi =
Rpos[i];
1441 double Rnegi =
Rneg[i];
1442 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1444 int j = csrColumnOffsets_DofLoops.data()[offset];
1446 double fij = dt*(MC.data()[ij]*(uDotLow.data()[i]-uDotLow.data()[j]) + dLow.data()[ij]*(uLow.data()[i]-uLow.data()[j]));
1449 Lij = fij > 0. ? fmin(Rposi,
Rneg[j]) : fmin(Rnegi,
Rpos[j]);
1451 ith_limited_flux_correction += Lij*fij;
1454 double mi = ML.data()[i];
1455 solLim.data()[i] += 1./mi*ith_limited_flux_correction;
1458 if (solLim.data()[i] > 1.0+1E-13)
1460 std::cout <<
"upper bound violated... " << 1.0-solLim.data()[i] << std::endl;
1463 else if (solLim.data()[i] < -1E-13)
1465 std::cout <<
"lower bound violated... " << solLim.data()[i] << std::endl;
1469 solLim.data()[i] = fmax(0.,fmin(solLim.data()[i],1.0));
1475 double dt = args.
scalar<
double>(
"dt");
1476 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1477 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1478 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1479 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1480 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1481 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1482 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1483 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1484 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1485 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1486 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1487 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1488 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1489 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1490 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1491 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1492 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1493 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1494 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1495 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1496 int nElements_global = args.
scalar<
int>(
"nElements_global");
1497 double useMetrics = args.
scalar<
double>(
"useMetrics");
1498 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1499 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1500 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1501 double sc_uref = args.
scalar<
double>(
"sc_uref");
1502 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
1503 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1504 const xt::pyarray<double>& porosity_dof = args.
array<
double>(
"porosity_dof");
1505 xt::pyarray<double>& q_dvos_dt = args.
array<
double>(
"q_dvos_dt");
1506 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1507 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1508 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1509 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
1510 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1511 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1512 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1513 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1514 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1515 xt::pyarray<double>& q_grad_u = args.
array<
double>(
"q_grad_u");
1516 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1517 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
1518 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
1519 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1520 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
1521 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1522 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1523 int offset_u = args.
scalar<
int>(
"offset_u");
1524 int stride_u = args.
scalar<
int>(
"stride_u");
1525 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1526 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1527 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1528 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1529 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1530 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1531 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
1532 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1533 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1534 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
1535 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
1536 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1537 double epsFact = args.
scalar<
double>(
"epsFact");
1538 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1539 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
1540 double cE = args.
scalar<
double>(
"cE");
1541 double cK = args.
scalar<
double>(
"cK");
1542 double uL = args.
scalar<
double>(
"uL");
1543 double uR = args.
scalar<
double>(
"uR");
1544 int numDOFs = args.
scalar<
int>(
"numDOFs");
1545 int NNZ = args.
scalar<
int>(
"NNZ");
1546 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1547 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1548 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
1549 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
1550 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
1551 xt::pyarray<double>& Cx = args.
array<
double>(
"Cx");
1552 xt::pyarray<double>& Cy = args.
array<
double>(
"Cy");
1553 xt::pyarray<double>& Cz = args.
array<
double>(
"Cz");
1554 xt::pyarray<double>& CTx = args.
array<
double>(
"CTx");
1555 xt::pyarray<double>& CTy = args.
array<
double>(
"CTy");
1556 xt::pyarray<double>& CTz = args.
array<
double>(
"CTz");
1557 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
1558 xt::pyarray<double>& delta_x_ij = args.
array<
double>(
"delta_x_ij");
1559 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1560 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
1561 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
1562 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
1563 xt::pyarray<double>& fluxMatrix = args.
array<
double>(
"fluxMatrix");
1564 xt::pyarray<double>& uDotLow = args.
array<
double>(
"uDotLow");
1565 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
1566 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
1567 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
1568 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
1569 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
1570 Rpos.resize(numDOFs,0.0),
Rneg.resize(numDOFs,0.0);
1577 for(
int eN=0;eN<nElements_global;eN++)
1578 for (
int j=0;j<nDOF_trial_element;j++)
1580 register int eN_nDOF_trial_element = eN*nDOF_trial_element;
1581 u_free_dof_old[r_l2g.data()[eN_nDOF_trial_element+j]] = u_dof_old.data()[u_l2g.data()[eN_nDOF_trial_element+j]];
1582 porosity_free_dof[r_l2g.data()[eN_nDOF_trial_element+j]] = porosity_dof.data()[u_l2g.data()[eN_nDOF_trial_element+j]];
1584 for (
int i=0; i<NNZ; i++)
1591 psi.resize(numDOFs,0.0);
1592 eta.resize(numDOFs,0.0);
1595 for (
int i=0; i<numDOFs; i++)
1598 if (STABILIZATION_TYPE==1)
1601 eta[i] = ENTROPY_TYPE == 1 ?
ENTROPY(porosity_times_solni,uL,uR) :
ENTROPY_LOG(porosity_times_solni,uL,uR);
1615 for(
int eN=0;eN<nElements_global;eN++)
1619 elementResidual_u[nDOF_test_element],
1620 element_entropy_residual[nDOF_test_element];
1621 register double elementTransport[nDOF_test_element][nDOF_trial_element];
1622 register double elementTransposeTransport[nDOF_test_element][nDOF_trial_element];
1623 for (
int i=0;i<nDOF_test_element;i++)
1625 elementResidual_u[i]=0.0;
1626 element_entropy_residual[i]=0.0;
1627 for (
int j=0;j<nDOF_trial_element;j++)
1629 elementTransport[i][j]=0.0;
1630 elementTransposeTransport[i][j]=0.0;
1634 for (
int k=0;k<nQuadraturePoints_element;k++)
1637 register int eN_k = eN*nQuadraturePoints_element+k,
1638 eN_k_nSpace = eN_k*nSpace,
1639 eN_nDOF_trial_element = eN*nDOF_trial_element;
1642 aux_entropy_residual=0., DENTROPY_un, DENTROPY_uni,
1644 u=0.0, un=0.0, grad_un[nSpace], porosity_times_velocity[nSpace],
1645 u_test_dV[nDOF_trial_element],
1646 u_grad_trial[nDOF_trial_element*nSpace],
1647 u_grad_test_dV[nDOF_test_element*nSpace],
1649 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1654 ck.calculateMapping_element(eN,
1658 mesh_trial_ref.data(),
1659 mesh_grad_trial_ref.data(),
1664 ck.calculateMappingVelocity_element(eN,
1666 mesh_velocity_dof.data(),
1668 mesh_trial_ref.data(),
1670 dV = fabs(jacDet)*dV_ref.data()[k];
1672 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
1674 ck.valFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],un);
1676 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1677 ck.gradFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_un);
1679 for (
int j=0;j<nDOF_trial_element;j++)
1681 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1682 for (
int I=0;I<nSpace;I++)
1683 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1687 if (q_dV_last.data()[eN_k] <= -100)
1688 q_dV_last.data()[eN_k] = dV;
1689 q_dV.data()[eN_k] = dV;
1691 porosity = q_porosity.data()[eN_k];
1695 double mesh_velocity[3];
1696 mesh_velocity[0] =
xt;
1697 mesh_velocity[1] = yt;
1698 mesh_velocity[2] = zt;
1700 for (
int I=0;I<nSpace;I++)
1701 porosity_times_velocity[I] = porosity*(velocity.data()[eN_k_nSpace+I]-MOVING_DOMAIN*mesh_velocity[I]);
1706 calculateCFL(elementDiameter.data()[eN]/degree_polynomial,porosity_times_velocity,cfl.data()[eN_k]);
1711 if (STABILIZATION_TYPE==1)
1713 for (
int I=0;I<nSpace;I++)
1714 aux_entropy_residual += porosity_times_velocity[I]*grad_un[I];
1720 for(
int i=0;i<nDOF_test_element;i++)
1723 int eN_i=eN*nDOF_test_element+i;
1724 if (STABILIZATION_TYPE==1)
1726 int gi = offset_u+stride_u*u_l2g.data()[eN_i];
1727 double porosity_times_uni = porosity_dof.data()[gi]*u_dof_old.data()[gi];
1728 DENTROPY_uni = ENTROPY_TYPE == 1 ?
DENTROPY(porosity_times_uni,uL,uR) :
DENTROPY_LOG(porosity_times_uni,uL,uR);
1729 element_entropy_residual[i] += (DENTROPY_un - DENTROPY_uni)*aux_entropy_residual*u_test_dV[i];
1731 elementResidual_u[i] += porosity*(
u-un)*u_test_dV[i];
1735 for(
int j=0;j<nDOF_trial_element;j++)
1737 int j_nSpace = j*nSpace;
1738 int i_nSpace = i*nSpace;
1739 elementTransport[i][j] +=
1740 ck.AdvectionJacobian_weak(porosity_times_velocity,
1741 u_trial_ref.data()[k*nDOF_trial_element+j],&u_grad_test_dV[i_nSpace]);
1742 elementTransposeTransport[i][j] +=
1743 ck.AdvectionJacobian_weak(porosity_times_velocity,
1744 u_trial_ref.data()[k*nDOF_trial_element+i],&u_grad_test_dV[j_nSpace]);
1748 q_u.data()[eN_k] =
u;
1749 q_m.data()[eN_k] = porosity*
u;
1754 for(
int I=0;I<nSpace;I++)
1756 q_grad_u.data()[eN_k_nSpace+I] = grad_un[I];
1758 q_dvos_dt.data()[eN_k] = 0.0;
1764 for(
int i=0;i<nDOF_test_element;i++)
1766 int eN_i=eN*nDOF_test_element+i;
1767 int gi = offset_u+stride_u*r_l2g.data()[eN_i];
1770 globalResidual.data()[gi] += elementResidual_u[i];
1772 if (STABILIZATION_TYPE==1)
1776 for (
int j=0;j<nDOF_trial_element;j++)
1778 int eN_i_j = eN_i*nDOF_trial_element+j;
1779 TransportMatrix[csrRowIndeces_CellLoops.data()[eN_i] + csrColumnOffsets_CellLoops.data()[eN_i_j]]
1780 += elementTransport[i][j];
1782 += elementTransposeTransport[i][j];
1791 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1793 double min_u_bc_local = 1E10, max_u_bc_local = -1E10;
1794 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
1795 register int eN = elementBoundaryElementsArray.data()[ebN*2+0],
1796 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
1797 eN_nDOF_trial_element = eN*nDOF_trial_element;
1798 register double elementResidual_u[nDOF_test_element];
1799 for (
int i=0;i<nDOF_test_element;i++)
1800 elementResidual_u[i]=0.0;
1802 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1804 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1805 ebNE_kb_nSpace = ebNE_kb*nSpace,
1806 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1807 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1809 u_ext=0.0, bc_u_ext=0.0,
1810 porosity_times_velocity[nSpace],
1811 flux_ext=0.0, dflux_ext=0.0,
1812 fluxTransport[nDOF_trial_element],
1813 jac_ext[nSpace*nSpace],
1815 jacInv_ext[nSpace*nSpace],
1816 boundaryJac[nSpace*(nSpace-1)],
1817 metricTensor[(nSpace-1)*(nSpace-1)],
1818 metricTensorDetSqrt,
1820 u_test_dS[nDOF_test_element],
1821 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,porosity_ext;
1823 ck.calculateMapping_elementBoundary(eN,
1829 mesh_trial_trace_ref.data(),
1830 mesh_grad_trial_trace_ref.data(),
1831 boundaryJac_ref.data(),
1837 metricTensorDetSqrt,
1841 ck.calculateMappingVelocity_elementBoundary(eN,
1845 mesh_velocity_dof.data(),
1847 mesh_trial_trace_ref.data(),
1848 xt_ext,yt_ext,zt_ext,
1853 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
1855 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],u_ext);
1857 for (
int j=0;j<nDOF_trial_element;j++)
1858 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
1861 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
1865 double mesh_velocity[3];
1866 mesh_velocity[0] = xt_ext;
1867 mesh_velocity[1] = yt_ext;
1868 mesh_velocity[2] = zt_ext;
1870 for (
int I=0;I<nSpace;I++)
1871 porosity_times_velocity[I] = porosity_ext*(ebqe_velocity_ext.data()[ebNE_kb_nSpace+I] - MOVING_DOMAIN*mesh_velocity[I]);
1876 for (
int I=0; I < nSpace; I++)
1877 flow += normal[I]*porosity_times_velocity[I];
1879 if (flow >= 0 && isFluxBoundary_u.data()[ebNE_kb] != 1 )
1886 ebqe_u.data()[ebNE_kb] = u_ext;
1892 ebqe_u.data()[ebNE_kb] = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
1893 if (isDOFBoundary_u.data()[ebNE_kb] == 1)
1894 flux_ext = ebqe_bc_u_ext.data()[ebNE_kb]*flow;
1895 else if (isFluxBoundary_u.data()[ebNE_kb] == 1)
1896 flux_ext = ebqe_bc_flux_u_ext.data()[ebNE_kb];
1899 std::cout<<
"warning: VOS open boundary with no external trace, setting to zero for inflow"<<std::endl;
1904 for (
int j=0;j<nDOF_trial_element;j++)
1908 elementResidual_u[j] += flux_ext*u_test_dS[j];
1909 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1910 fluxTransport[j] = dflux_ext*u_trial_trace_ref.data()[ebN_local_kb_j];
1915 for (
int i=0;i<nDOF_test_element;i++)
1917 register int eN_i = eN*nDOF_test_element+i;
1918 for (
int j=0;j<nDOF_trial_element;j++)
1921 TransportMatrix[csrRowIndeces_CellLoops.data()[eN_i] + csrColumnOffsets_eb_CellLoops.data()[ebN_i_j]]
1922 += fluxTransport[j]*u_test_dS[i];
1924 += fluxTransport[i]*u_test_dS[j];
1928 min_u_bc_local = fmin(ebqe_u.data()[ebNE_kb], min_u_bc_local);
1929 max_u_bc_local = fmax(ebqe_u.data()[ebNE_kb], max_u_bc_local);
1932 for (
int i=0;i<nDOF_test_element;i++)
1934 int eN_i = eN*nDOF_test_element+i;
1935 int gi = offset_u+stride_u*r_l2g.data()[eN_i];
1936 globalResidual.data()[gi] += dt*elementResidual_u[i];
1938 min_u_bc.data()[gi] = fmin(min_u_bc_local,min_u_bc.data()[gi]);
1939 max_u_bc.data()[gi] = fmax(max_u_bc_local,max_u_bc.data()[gi]);
1949 for (
int i=0; i<numDOFs; i++)
1951 double gi[nSpace], Cij[nSpace], xi[nSpace], etaMaxi, etaMini;
1952 if (STABILIZATION_TYPE==1)
1955 etaMaxi = fabs(
eta[i]);
1956 etaMini = fabs(
eta[i]);
1958 double porosity_times_solni = porosity_dof.data()[i]*
u_free_dof_old[i];
1960 for (
int I=0; I < nSpace; I++)
1963 xi[I] = mesh_dof.data()[i*3+I];
1966 double alpha_numerator_pos = 0., alpha_numerator_neg = 0., alpha_denominator_pos = 0., alpha_denominator_neg = 0.;
1967 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1969 int j = csrColumnOffsets_DofLoops.data()[offset];
1970 if (STABILIZATION_TYPE==1)
1973 etaMaxi = fmax(etaMaxi,fabs(
eta[j]));
1974 etaMini = fmin(etaMini,fabs(
eta[j]));
1978 Cij[0] = Cx.data()[ij];
1979 Cij[1] = Cy.data()[ij];
1981 Cij[2] = Cz.data()[ij];
1984 for (
int I=0; I < nSpace; I++)
1985 gi[I] += Cij[I]*porosity_times_solnj;
1988 double alpha_num = porosity_times_solni - porosity_times_solnj;
1989 if (alpha_num >= 0.)
1991 alpha_numerator_pos += alpha_num;
1992 alpha_denominator_pos += alpha_num;
1996 alpha_numerator_neg += alpha_num;
1997 alpha_denominator_neg += fabs(alpha_num);
2003 for (
int I=0; I < nSpace; I++)
2004 gi[I] /= ML.data()[i];
2005 if (STABILIZATION_TYPE==1)
2013 double SumPos=0., SumNeg=0.;
2014 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
2016 int j = csrColumnOffsets_DofLoops.data()[offset];
2019 for (
int I=0; I < nSpace; I++)
2020 xj[I] = mesh_dof.data()[j*3+I];
2022 double gi_times_x=0.;
2023 for (
int I=0; I < nSpace; I++)
2028 gi_times_x += gi[I]*delta_x_ij.data()[offset*3+I];
2031 SumPos += gi_times_x > 0 ? gi_times_x : 0;
2032 SumNeg += gi_times_x < 0 ? gi_times_x : 0;
2034 double sigmaPosi = fmin(1.,(fabs(SumNeg)+1E-15)/(SumPos+1E-15));
2035 double sigmaNegi = fmin(1.,(SumPos+1E-15)/(fabs(SumNeg)+1E-15));
2036 double alpha_numi = fabs(sigmaPosi*alpha_numerator_pos + sigmaNegi*alpha_numerator_neg);
2037 double alpha_deni = sigmaPosi*alpha_denominator_pos + sigmaNegi*alpha_denominator_neg;
2040 alpha_numi = fabs(alpha_numerator_pos + alpha_numerator_neg);
2041 alpha_deni = alpha_denominator_pos + alpha_denominator_neg;
2043 double alphai = alpha_numi/(alpha_deni+1E-15);
2044 quantDOFs.data()[i] = alphai;
2055 for (
int i=0; i<numDOFs; i++)
2060 double ith_dissipative_term = 0;
2061 double ith_low_order_dissipative_term = 0;
2062 double ith_flux_term = 0;
2066 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
2068 int j = csrColumnOffsets_DofLoops.data()[offset];
2071 double dLowij, dLij, dEVij, dHij;
2077 double solij = 0.5*(porosityi*solni+porosityj*solnj);
2078 double Compij = cK*fmax(solij*(1.0-solij),0.0)/(fabs(porosityi*solni-porosityj*solnj)+1E-14);
2083 dLij = dLowij*fmax(
psi[i],
psi[j]);
2084 if (STABILIZATION_TYPE==1)
2089 dHij = fmin(dLowij,dEVij) * fmax(1.0-Compij,0.0);
2093 dHij = dLij * fmax(1.0-Compij,0.0);
2106 dLow.data()[ij]=dLowij;
2109 ith_dissipative_term += dHij*(solnj-solni);
2110 ith_low_order_dissipative_term += dLij*(solnj-solni);
2112 dt_times_dH_minus_dL.data()[ij] = dt*(dHij - dLij);
2117 -dHij*(solnj-solni));
2121 dt_times_dH_minus_dL.data()[ij] = 0;
2122 fluxMatrix.data()[ij] = 0;
2128 double mi = ML.data()[i];
2130 edge_based_cfl.data()[i] = 2.*fabs(dLii)/mi;
2133 uDotLow.data()[i] = - 1.0/mi*(ith_flux_term
2135 - ith_low_order_dissipative_term);
2216 double dt = args.
scalar<
double>(
"dt");
2217 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
2218 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
2219 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
2220 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
2221 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
2222 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
2223 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
2224 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
2225 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
2226 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
2227 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
2228 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
2229 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
2230 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
2231 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
2232 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
2233 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
2234 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
2235 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
2236 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
2237 int nElements_global = args.
scalar<
int>(
"nElements_global");
2238 double useMetrics = args.
scalar<
double>(
"useMetrics");
2239 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
2240 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
2241 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
2242 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
2243 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
2244 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
2245 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
2246 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
2247 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
2248 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
2249 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
2250 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
2251 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
2252 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
2253 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
2254 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
2255 xt::pyarray<double>& delta_x_ij = args.
array<
double>(
"delta_x_ij");
2256 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2257 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
2258 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
2259 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2260 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
2261 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
2262 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
2263 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
2264 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
2265 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
2266 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
2267 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
2269 double Ct_sge = 4.0;
2273 for(
int eN=0;eN<nElements_global;eN++)
2275 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
2276 for (
int i=0;i<nDOF_test_element;i++)
2277 for (
int j=0;j<nDOF_trial_element;j++)
2279 elementJacobian_u_u[i][j]=0.0;
2281 for (
int k=0;k<nQuadraturePoints_element;k++)
2283 int eN_k = eN*nQuadraturePoints_element+k,
2284 eN_k_nSpace = eN_k*nSpace,
2285 eN_nDOF_trial_element = eN*nDOF_trial_element;
2288 register double u=0.0,
2291 f[nSpace],
df[nSpace],
2293 dpdeResidual_u_u[nDOF_trial_element],
2294 Lstar_u[nDOF_test_element],
2295 dsubgridError_u_u[nDOF_trial_element],
2296 tau=0.0,tau0=0.0,tau1=0.0,
2299 jacInv[nSpace*nSpace],
2300 u_grad_trial[nDOF_trial_element*nSpace],
2302 u_test_dV[nDOF_test_element],
2303 u_grad_test_dV[nDOF_test_element*nSpace],
2308 G[nSpace*nSpace],G_dd_G,tr_G;
2311 ck.calculateMapping_element(eN,
2315 mesh_trial_ref.data(),
2316 mesh_grad_trial_ref.data(),
2321 ck.calculateMappingVelocity_element(eN,
2323 mesh_velocity_dof.data(),
2325 mesh_trial_ref.data(),
2328 dV = fabs(jacDet)*dV_ref.data()[k];
2329 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2331 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
2333 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
2335 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
2337 for (
int j=0;j<nDOF_trial_element;j++)
2339 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
2340 for (
int I=0;I<nSpace;I++)
2342 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
2346 porosity = q_porosity.data()[eN_k];
2363 double mesh_velocity[3];
2364 mesh_velocity[0] =
xt;
2365 mesh_velocity[1] = yt;
2366 mesh_velocity[2] = zt;
2368 for(
int I=0;I<nSpace;I++)
2371 f[I] -= MOVING_DOMAIN*m*mesh_velocity[I];
2372 df[I] -= MOVING_DOMAIN*dm*mesh_velocity[I];
2378 q_m_betaBDF.data()[eN_k],
2387 for (
int i=0;i<nDOF_test_element;i++)
2391 register int i_nSpace = i*nSpace;
2392 Lstar_u[i]=
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
2395 for (
int j=0;j<nDOF_trial_element;j++)
2399 int j_nSpace = j*nSpace;
2400 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
2401 ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
2416 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
2418 for(
int j=0;j<nDOF_trial_element;j++)
2419 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
2421 for(
int i=0;i<nDOF_test_element;i++)
2425 for(
int j=0;j<nDOF_trial_element;j++)
2427 if (LUMPED_MASS_MATRIX==1)
2430 elementJacobian_u_u[i][j] += u_test_dV[i];
2436 int j_nSpace = j*nSpace;
2437 int i_nSpace = i*nSpace;
2439 elementJacobian_u_u[i][j] +=
2440 dt*
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]);
2448 for (
int i=0;i<nDOF_test_element;i++)
2450 int eN_i = eN*nDOF_test_element+i;
2451 int I = u_l2g.data()[eN_i];
2452 for (
int j=0;j<nDOF_trial_element;j++)
2454 int eN_i_j = eN_i*nDOF_trial_element+j;
2455 int J = u_l2g.data()[eN*nDOF_trial_element+j];
2456 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
2457 delta_x_ij.data()[3*(csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j])+0] = mesh_dof.data()[I*3+0] - mesh_dof.data()[J*3+0];
2458 delta_x_ij.data()[3*(csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j])+1] = mesh_dof.data()[I*3+1] - mesh_dof.data()[J*3+1];
2459 delta_x_ij.data()[3*(csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j])+2] = mesh_dof.data()[I*3+2] - mesh_dof.data()[J*3+2];
2467 int nQuadraturePoints_elementIn,
2468 int nDOF_mesh_trial_elementIn,
2469 int nDOF_trial_elementIn,
2470 int nDOF_test_elementIn,
2471 int nQuadraturePoints_elementBoundaryIn,
2475 return proteus::chooseAndAllocateDiscretization2D<cppVOS3P_base,cppVOS,CompKernel>(nSpaceIn,
2476 nQuadraturePoints_elementIn,
2477 nDOF_mesh_trial_elementIn,
2478 nDOF_trial_elementIn,
2479 nDOF_test_elementIn,
2480 nQuadraturePoints_elementBoundaryIn,
2483 return proteus::chooseAndAllocateDiscretization<cppVOS3P_base,cppVOS,CompKernel>(nSpaceIn,
2484 nQuadraturePoints_elementIn,
2485 nDOF_mesh_trial_elementIn,
2486 nDOF_trial_elementIn,
2487 nDOF_test_elementIn,
2488 nQuadraturePoints_elementBoundaryIn,