9 #include "xtensor-python/pyarray.hpp"
11 #define POWER_SMOOTHNESS_INDICATOR 2
12 #define IS_BETAij_ONE 0
26 inline double ENTROPY(
const double&
phi,
const double& phiL,
const double& phiR){
27 return 1./2.*std::pow(fabs(
phi),2.);
29 inline double DENTROPY(
const double&
phi,
const double& phiL,
const double& phiR){
30 return fabs(
phi)*(
phi>=0 ? 1 : -1);
33 inline double ENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
34 return std::log(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
36 inline double DENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
37 return (phiL+phiR-2*
phi)*((
phi-phiL)*(phiR-
phi)>=0 ? 1 : -1)/(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
58 template<
class CompKernelType,
60 int nQuadraturePoints_element,
61 int nDOF_mesh_trial_element,
62 int nDOF_trial_element,
63 int nDOF_test_element,
64 int nQuadraturePoints_elementBoundary>
77 const double df[nSpace],
83 for(
int I=0;I<nSpace;I++)
92 const double& porosity,
100 for (
int I=0; I < nSpace; I++)
102 f[I] =
v[I]*porosity*
u;
103 df[I] =
v[I]*porosity;
110 const double dH[nSpace],
114 double h,nrm_v,oneByAbsdt;
117 for(
int I=0;I<nSpace;I++)
121 oneByAbsdt = fabs(dmt);
122 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
127 const double G[nSpace*nSpace],
129 const double Ai[nSpace],
134 for(
int I=0;I<nSpace;I++)
135 for (
int J=0;J<nSpace;J++)
136 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
138 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv + 1.0e-8);
143 const double& elementDiameter,
144 const double& strong_residual,
145 const double grad_u[nSpace],
154 for (
int I=0;I<nSpace;I++)
155 n_grad_u += grad_u[I]*grad_u[I];
156 num = shockCapturingDiffusion*0.5*h*fabs(strong_residual);
157 den = sqrt(n_grad_u) + 1.0e-8;
163 const int& isFluxBoundary_u,
164 const double n[nSpace],
166 const double& bc_flux_u,
168 const double velocity[nSpace],
173 for (
int I=0; I < nSpace; I++)
174 flow +=
n[I]*velocity[I];
176 if (isDOFBoundary_u == 1)
190 else if (isFluxBoundary_u == 1)
204 std::cout<<
"warning: VOF open boundary with no external trace, setting to zero for inflow"<<std::endl;
213 const int& isFluxBoundary_u,
214 const double n[nSpace],
215 const double velocity[nSpace],
219 for (
int I=0; I < nSpace; I++)
220 flow +=
n[I]*velocity[I];
223 if (isDOFBoundary_u == 1)
234 else if (isFluxBoundary_u == 1)
249 double dt = args.
scalar<
double>(
"dt");
250 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
251 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
252 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
253 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
254 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
255 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
256 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
257 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
258 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
259 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
260 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
261 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
262 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
263 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
264 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
265 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
266 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
267 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
268 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
269 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
270 int nElements_global = args.
scalar<
int>(
"nElements_global");
271 double useMetrics = args.
scalar<
double>(
"useMetrics");
272 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
273 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
274 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
275 double sc_uref = args.
scalar<
double>(
"sc_uref");
276 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
277 const xt::pyarray<double>& q_vos = args.
array<
double>(
"q_vos");
278 const xt::pyarray<double>& vos_dof = args.
array<
double>(
"vos_dof");
279 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
280 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
281 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
282 double degree_polynomial = args.
scalar<
double>(
"degree_polynomial");
283 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
284 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
285 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
286 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
287 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
288 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
289 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
290 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
291 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
292 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
293 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
294 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
295 int offset_u = args.
scalar<
int>(
"offset_u");
296 int stride_u = args.
scalar<
int>(
"stride_u");
297 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
298 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
299 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
300 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
301 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
302 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
303 const xt::pyarray<double>& ebqe_vos_ext = args.
array<
double>(
"ebqe_vos_ext");
304 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
305 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
306 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
307 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
308 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
309 double epsFact = args.
scalar<
double>(
"epsFact");
310 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
311 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
312 int stage = args.
scalar<
int>(
"stage");
313 xt::pyarray<double>& uTilde_dof = args.
array<
double>(
"uTilde_dof");
314 double cE = args.
scalar<
double>(
"cE");
316 double cK = args.
scalar<
double>(
"cK");
317 double uL = args.
scalar<
double>(
"uL");
318 double uR = args.
scalar<
double>(
"uR");
319 int numDOFs = args.
scalar<
int>(
"numDOFs");
320 int NNZ = args.
scalar<
int>(
"NNZ");
321 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
322 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
323 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
324 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
325 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
326 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
327 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
328 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
329 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
330 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
331 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
332 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
333 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
334 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
335 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
336 double meanEntropy = 0., meanOmega = 0., maxEntropy = -1E10, minEntropy = 1E10;
337 register double maxVel[nElements_global], maxEntRes[nElements_global];
349 for(
int eN=0;eN<nElements_global;eN++)
355 register double elementResidual_u[nDOF_test_element];
356 for (
int i=0;i<nDOF_test_element;i++)
358 elementResidual_u[i]=0.0;
361 for (
int k=0;k<nQuadraturePoints_element;k++)
364 register int eN_k = eN*nQuadraturePoints_element+k,
365 eN_k_nSpace = eN_k*nSpace,
366 eN_nDOF_trial_element = eN*nDOF_trial_element;
368 entVisc_minus_artComp,
370 grad_u[nSpace],grad_u_old[nSpace],grad_uTilde[nSpace],
372 H=0.0,Hn=0.0,HTilde=0.0,
373 f[nSpace],fn[nSpace],
df[nSpace],
376 Lstar_u[nDOF_test_element],
378 tau=0.0,tau0=0.0,tau1=0.0,
379 numDiff0=0.0,numDiff1=0.0,
382 jacInv[nSpace*nSpace],
383 u_grad_trial[nDOF_trial_element*nSpace],
384 u_test_dV[nDOF_trial_element],
385 u_grad_test_dV[nDOF_test_element*nSpace],
390 G[nSpace*nSpace],G_dd_G,tr_G;
410 ck.calculateMapping_element(eN,
414 mesh_trial_ref.data(),
415 mesh_grad_trial_ref.data(),
420 ck.calculateMappingVelocity_element(eN,
422 mesh_velocity_dof.data(),
424 mesh_trial_ref.data(),
427 dV = fabs(jacDet)*dV_ref[k];
428 ck.calculateG(jacInv,G,G_dd_G,tr_G);
430 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],
434 ck.valFromDOF(u_dof.data(),
435 &u_l2g[eN_nDOF_trial_element],
436 &u_trial_ref[k*nDOF_trial_element],
438 ck.valFromDOF(u_dof_old.data(),
439 &u_l2g[eN_nDOF_trial_element],
440 &u_trial_ref[k*nDOF_trial_element],
443 ck.gradFromDOF(u_dof.data(),
444 &u_l2g[eN_nDOF_trial_element],
447 ck.gradFromDOF(u_dof_old.data(),
448 &u_l2g[eN_nDOF_trial_element],
451 ck.gradFromDOF(uTilde_dof.data(),
452 &u_l2g[eN_nDOF_trial_element],
456 for (
int j=0;j<nDOF_trial_element;j++)
458 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
459 for (
int I=0;I<nSpace;I++)
461 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
465 porosity = 1.0 - q_vos[eN_k];
482 double mesh_velocity[3];
483 mesh_velocity[0] =
xt;
484 mesh_velocity[1] = yt;
485 mesh_velocity[2] = zt;
487 for (
int I=0;I<nSpace;I++)
489 f[I] -= MOVING_DOMAIN*m*mesh_velocity[I];
490 df[I] -= MOVING_DOMAIN*dm*mesh_velocity[I];
495 if (q_dV_last[eN_k] <= -100)
496 q_dV_last[eN_k] = dV;
499 q_m_betaBDF[eN_k]*q_dV_last[eN_k]/dV,
505 if (STABILIZATION_TYPE==1)
507 double normVel=0., norm_grad_un=0.;
508 for (
int I=0;I<nSpace;I++)
510 Hn +=
df[I]*grad_u_old[I];
511 HTilde +=
df[I]*grad_uTilde[I];
512 fn[I] = porosity*
df[I]*un-MOVING_DOMAIN*m*mesh_velocity[I];
513 H +=
df[I]*grad_u[I];
514 normVel +=
df[I]*
df[I];
515 norm_grad_un += grad_u_old[I]*grad_u_old[I];
517 normVel = std::sqrt(normVel);
518 norm_grad_un = std::sqrt(norm_grad_un)+1E-10;
525 maxVel[eN] = fmax(normVel,maxVel[eN]);
530 maxEntRes[eN] = fmax(maxEntRes[eN],fabs(entRes));
535 maxEntropy = fmax(maxEntropy,
ENTROPY(
u,0,1));
536 minEntropy = fmin(minEntropy,
ENTROPY(
u,0,1));
539 double hK=elementDiameter[eN]/degree_polynomial;
540 entVisc_minus_artComp = fmax(1-cK*fmax(un*(1-un),0)/hK/norm_grad_un,0);
548 pdeResidual_u =
ck.Mass_strong(m_t) +
ck.Advection_strong(
df,grad_u);
550 for (
int i=0;i<nDOF_test_element;i++)
554 register int i_nSpace = i*nSpace;
555 Lstar_u[i] =
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
565 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
567 subgridError_u = -tau*pdeResidual_u;
572 ck.calculateNumericalDiffusion(shockCapturingDiffusion,
578 ck.calculateNumericalDiffusion(shockCapturingDiffusion,
586 q_numDiff_u[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
603 for(
int i=0;i<nDOF_test_element;i++)
607 register int i_nSpace=i*nSpace;
608 if (STABILIZATION_TYPE==1)
611 elementResidual_u[i] +=
612 ck.Mass_weak(dt*m_t,u_test_dV[i]) +
613 1./3*dt*
ck.Advection_weak(fn,&u_grad_test_dV[i_nSpace]) +
614 1./9*dt*dt*
ck.NumericalDiffusion(Hn,
df,&u_grad_test_dV[i_nSpace]) +
615 1./3*dt*entVisc_minus_artComp*
ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
617 &u_grad_test_dV[i_nSpace]);
620 elementResidual_u[i] +=
621 ck.Mass_weak(dt*m_t,u_test_dV[i]) +
622 dt*
ck.Advection_weak(fn,&u_grad_test_dV[i_nSpace]) +
623 0.5*dt*dt*
ck.NumericalDiffusion(HTilde,
df,&u_grad_test_dV[i_nSpace]) +
624 dt*entVisc_minus_artComp*
ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
626 &u_grad_test_dV[i_nSpace]);
630 elementResidual_u[i] +=
631 ck.Mass_weak(m_t,u_test_dV[i]) +
632 ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace]) +
633 ck.SubgridError(subgridError_u,Lstar_u[i]) +
634 ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
636 &u_grad_test_dV[i_nSpace]);
650 for(
int i=0;i<nDOF_test_element;i++)
652 register int eN_i=eN*nDOF_test_element+i;
653 globalResidual[offset_u+stride_u*r_l2g[eN_i]] += elementResidual_u[i];
662 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
664 register int ebN = exteriorElementBoundariesArray[ebNE],
665 eN = elementBoundaryElementsArray[ebN*2+0],
666 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
667 eN_nDOF_trial_element = eN*nDOF_trial_element;
668 register double elementResidual_u[nDOF_test_element];
669 for (
int i=0;i<nDOF_test_element;i++)
671 elementResidual_u[i]=0.0;
673 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
675 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
676 ebNE_kb_nSpace = ebNE_kb*nSpace,
677 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
678 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
679 register double u_ext=0.0,
692 jac_ext[nSpace*nSpace],
694 jacInv_ext[nSpace*nSpace],
695 boundaryJac[nSpace*(nSpace-1)],
696 metricTensor[(nSpace-1)*(nSpace-1)],
699 u_test_dS[nDOF_test_element],
700 u_grad_trial_trace[nDOF_trial_element*nSpace],
701 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
705 G[nSpace*nSpace],G_dd_G,tr_G;
710 ck.calculateMapping_elementBoundary(eN,
716 mesh_trial_trace_ref.data(),
717 mesh_grad_trial_trace_ref.data(),
718 boundaryJac_ref.data(),
728 ck.calculateMappingVelocity_elementBoundary(eN,
732 mesh_velocity_dof.data(),
734 mesh_trial_trace_ref.data(),
735 xt_ext,yt_ext,zt_ext,
742 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
745 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
748 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],
752 if (STABILIZATION_TYPE==1)
754 ck.valFromDOF(u_dof_old.data(),
755 &u_l2g[eN_nDOF_trial_element],
756 &u_trial_trace_ref[ebN_local_kb*nDOF_test_element],
758 ck.gradFromDOF(u_dof_old.data(),
759 &u_l2g[eN_nDOF_trial_element],
765 ck.valFromDOF(u_dof.data(),
766 &u_l2g[eN_nDOF_trial_element],
767 &u_trial_trace_ref[ebN_local_kb*nDOF_test_element],
769 ck.gradFromDOF(u_dof.data(),
770 &u_l2g[eN_nDOF_trial_element],
775 for (
int j=0;j<nDOF_trial_element;j++)
777 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
782 bc_u_ext = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*u_ext;
784 porosity_ext = 1.0 - ebqe_vos_ext[ebNE_kb];
810 double mesh_velocity[3];
811 mesh_velocity[0] = xt_ext;
812 mesh_velocity[1] = yt_ext;
813 mesh_velocity[2] = zt_ext;
815 for (
int I=0;I<nSpace;I++)
818 f_ext[I] -= MOVING_DOMAIN*m_ext*mesh_velocity[I];
819 df_ext[I] -= MOVING_DOMAIN*dm_ext*mesh_velocity[I];
820 bc_f_ext[I] -= MOVING_DOMAIN*bc_m_ext*mesh_velocity[I];
821 bc_df_ext[I] -= MOVING_DOMAIN*bc_dm_ext*mesh_velocity[I];
827 isFluxBoundary_u[ebNE_kb],
830 ebqe_bc_flux_u_ext[ebNE_kb],
834 ebqe_flux[ebNE_kb] = flux_ext;
837 ebqe_u[ebNE_kb] = u_ext;
839 ebqe_u[ebNE_kb] = bc_u_ext;
841 if (STABILIZATION_TYPE==1)
850 for (
int i=0;i<nDOF_test_element;i++)
853 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
859 for (
int i=0;i<nDOF_test_element;i++)
861 int eN_i = eN*nDOF_test_element+i;
862 globalResidual[offset_u+stride_u*r_l2g[eN_i]] += elementResidual_u[i];
865 if (STABILIZATION_TYPE==1)
867 meanEntropy /= meanOmega;
868 double norm_factor = fmax(fabs(maxEntropy - meanEntropy), fabs(meanEntropy-minEntropy));
869 for(
int eN=0;eN<nElements_global;eN++)
871 double hK=elementDiameter[eN]/degree_polynomial;
872 double linear_viscosity =
cMax*hK*maxVel[eN];
873 double entropy_viscosity =
cE*hK*hK*maxEntRes[eN]/norm_factor;
874 for (
int k=0;k<nQuadraturePoints_element;k++)
876 register int eN_k = eN*nQuadraturePoints_element+k;
877 q_numDiff_u[eN_k] = fmin(linear_viscosity,entropy_viscosity);
886 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
887 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
888 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
889 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
890 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
891 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
892 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
893 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
894 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
895 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
896 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
897 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
898 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
899 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
900 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
901 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
902 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
903 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
904 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
905 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
906 int nElements_global = args.
scalar<
int>(
"nElements_global");
907 double useMetrics = args.
scalar<
double>(
"useMetrics");
908 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
909 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
910 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
911 const xt::pyarray<double>& q_vos = args.
array<
double>(
"q_vos");
912 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
913 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
914 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
915 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
916 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
917 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
918 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
919 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
920 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
921 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
922 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
923 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
924 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
925 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
926 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
927 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
928 const xt::pyarray<double>& ebqe_vos_ext = args.
array<
double>(
"ebqe_vos_ext");
929 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
930 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
931 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
932 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
933 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
934 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
940 for(
int eN=0;eN<nElements_global;eN++)
942 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
943 for (
int i=0;i<nDOF_test_element;i++)
944 for (
int j=0;j<nDOF_trial_element;j++)
946 elementJacobian_u_u[i][j]=0.0;
948 for (
int k=0;k<nQuadraturePoints_element;k++)
950 int eN_k = eN*nQuadraturePoints_element+k,
951 eN_k_nSpace = eN_k*nSpace,
952 eN_nDOF_trial_element = eN*nDOF_trial_element;
955 register double u=0.0,
958 f[nSpace],
df[nSpace],
960 dpdeResidual_u_u[nDOF_trial_element],
961 Lstar_u[nDOF_test_element],
962 dsubgridError_u_u[nDOF_trial_element],
963 tau=0.0,tau0=0.0,tau1=0.0,
966 jacInv[nSpace*nSpace],
967 u_grad_trial[nDOF_trial_element*nSpace],
969 u_test_dV[nDOF_test_element],
970 u_grad_test_dV[nDOF_test_element*nSpace],
975 G[nSpace*nSpace],G_dd_G,tr_G;
997 ck.calculateMapping_element(eN,
1001 mesh_trial_ref.data(),
1002 mesh_grad_trial_ref.data(),
1007 ck.calculateMappingVelocity_element(eN,
1009 mesh_velocity_dof.data(),
1011 mesh_trial_ref.data(),
1014 dV = fabs(jacDet)*dV_ref[k];
1015 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1017 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1019 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],
u);
1021 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_u);
1023 for (
int j=0;j<nDOF_trial_element;j++)
1025 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
1026 for (
int I=0;I<nSpace;I++)
1028 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1032 porosity = 1.0 - q_vos[eN_k];
1049 double mesh_velocity[3];
1050 mesh_velocity[0] =
xt;
1051 mesh_velocity[1] = yt;
1052 mesh_velocity[2] = zt;
1054 for(
int I=0;I<nSpace;I++)
1057 f[I] -= MOVING_DOMAIN*m*mesh_velocity[I];
1058 df[I] -= MOVING_DOMAIN*dm*mesh_velocity[I];
1073 for (
int i=0;i<nDOF_test_element;i++)
1077 register int i_nSpace = i*nSpace;
1078 Lstar_u[i]=
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
1081 for (
int j=0;j<nDOF_trial_element;j++)
1085 int j_nSpace = j*nSpace;
1086 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref[k*nDOF_trial_element+j]) +
1087 ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
1102 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
1104 for(
int j=0;j<nDOF_trial_element;j++)
1105 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
1107 for(
int i=0;i<nDOF_test_element;i++)
1111 for(
int j=0;j<nDOF_trial_element;j++)
1115 int j_nSpace = j*nSpace;
1116 int i_nSpace = i*nSpace;
1117 if (STABILIZATION_TYPE==0)
1119 elementJacobian_u_u[i][j] +=
1120 ck.MassJacobian_weak(dm_t,
1121 u_trial_ref[k*nDOF_trial_element+j],
1123 ck.AdvectionJacobian_weak(
df,
1124 u_trial_ref[k*nDOF_trial_element+j],
1125 &u_grad_test_dV[i_nSpace]) +
1126 ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
1127 ck.NumericalDiffusionJacobian(q_numDiff_u_last[eN_k],
1128 &u_grad_trial[j_nSpace],
1129 &u_grad_test_dV[i_nSpace]);
1133 elementJacobian_u_u[i][j] +=
1134 ck.MassJacobian_weak(1.0,
1135 u_trial_ref[k*nDOF_trial_element+j],
1144 for (
int i=0;i<nDOF_test_element;i++)
1146 int eN_i = eN*nDOF_test_element+i;
1147 for (
int j=0;j<nDOF_trial_element;j++)
1149 int eN_i_j = eN_i*nDOF_trial_element+j;
1150 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_u_u[eN_i_j]] += elementJacobian_u_u[i][j];
1157 if (STABILIZATION_TYPE==0)
1158 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1160 register int ebN = exteriorElementBoundariesArray[ebNE];
1161 register int eN = elementBoundaryElementsArray[ebN*2+0],
1162 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
1163 eN_nDOF_trial_element = eN*nDOF_trial_element;
1164 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1166 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1167 ebNE_kb_nSpace = ebNE_kb*nSpace,
1168 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1169 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1170 register double u_ext=0.0,
1183 fluxJacobian_u_u[nDOF_trial_element],
1184 jac_ext[nSpace*nSpace],
1186 jacInv_ext[nSpace*nSpace],
1187 boundaryJac[nSpace*(nSpace-1)],
1188 metricTensor[(nSpace-1)*(nSpace-1)],
1189 metricTensorDetSqrt,
1191 u_test_dS[nDOF_test_element],
1192 u_grad_trial_trace[nDOF_trial_element*nSpace],
1193 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
1197 G[nSpace*nSpace],G_dd_G,tr_G;
1219 ck.calculateMapping_elementBoundary(eN,
1225 mesh_trial_trace_ref.data(),
1226 mesh_grad_trial_trace_ref.data(),
1227 boundaryJac_ref.data(),
1233 metricTensorDetSqrt,
1237 ck.calculateMappingVelocity_elementBoundary(eN,
1241 mesh_velocity_dof.data(),
1243 mesh_trial_trace_ref.data(),
1244 xt_ext,yt_ext,zt_ext,
1250 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
1252 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1255 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1257 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_ext);
1258 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1260 for (
int j=0;j<nDOF_trial_element;j++)
1262 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
1267 bc_u_ext = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*u_ext;
1269 porosity_ext = 1.0 - ebqe_vos_ext[ebNE_kb];
1295 double mesh_velocity[3];
1296 mesh_velocity[0] = xt_ext;
1297 mesh_velocity[1] = yt_ext;
1298 mesh_velocity[2] = zt_ext;
1300 for (
int I=0;I<nSpace;I++)
1303 f_ext[I] -= MOVING_DOMAIN*m_ext*mesh_velocity[I];
1304 df_ext[I] -= MOVING_DOMAIN*dm_ext*mesh_velocity[I];
1305 bc_f_ext[I] -= MOVING_DOMAIN*bc_m_ext*mesh_velocity[I];
1306 bc_df_ext[I] -= MOVING_DOMAIN*bc_dm_ext*mesh_velocity[I];
1312 isFluxBoundary_u[ebNE_kb],
1319 for (
int j=0;j<nDOF_trial_element;j++)
1322 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1323 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_u_u_ext,u_trial_trace_ref[ebN_local_kb_j]);
1328 for (
int i=0;i<nDOF_test_element;i++)
1330 register int eN_i = eN*nDOF_test_element+i;
1332 for (
int j=0;j<nDOF_trial_element;j++)
1335 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_eb_u_u[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i];
1344 double dt = args.
scalar<
double>(
"dt");
1345 int NNZ = args.
scalar<
int>(
"NNZ");
1346 int numDOFs = args.
scalar<
int>(
"numDOFs");
1347 xt::pyarray<double>& lumped_mass_matrix = args.
array<
double>(
"lumped_mass_matrix");
1348 xt::pyarray<double>& soln = args.
array<
double>(
"soln");
1349 xt::pyarray<double>& solH = args.
array<
double>(
"solH");
1350 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
1351 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
1352 xt::pyarray<double>& limited_solution = args.
array<
double>(
"limited_solution");
1353 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1354 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1355 xt::pyarray<double>& MassMatrix = args.
array<
double>(
"MassMatrix");
1356 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
1357 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
1358 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
1359 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1360 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
1361 Rpos.resize(numDOFs,0.0),
Rneg.resize(numDOFs,0.0);
1367 for (
int i=0; i<numDOFs; i++)
1370 double solHi = solH[i];
1371 double solni = soln[i];
1372 double mi = lumped_mass_matrix[i];
1373 double uLowi = uLow[i];
1374 double uDotLowi = (uLowi - solni)/dt;
1375 double mini=min_u_bc[i], maxi=max_u_bc[i];
1382 double Pposi=0, Pnegi=0;
1384 for (
int offset=csrRowIndeces_DofLoops[i]; offset<csrRowIndeces_DofLoops[i+1]; offset++)
1386 int j = csrColumnOffsets_DofLoops[offset];
1387 double solnj = soln[j];
1393 mini = fmin(mini,solnj);
1394 maxi = fmax(maxi,solnj);
1396 double uLowj = uLow[j];
1397 double uDotLowj = (uLowj - solnj)/dt;
1399 if (STABILIZATION_TYPE==4)
1402 + dLow[ij]*(uLowi-uLowj));
1406 double ML_minus_MC =
1407 (LUMPED_MASS_MATRIX == 1 ? 0. : (i==j ? 1. : 0.)*mi - MassMatrix[ij]);
1409 + dt_times_dH_minus_dL[ij]*(solnj-solni);
1424 double Qposi = mi*(maxi-uLow[i]);
1425 double Qnegi = mi*(mini-uLow[i]);
1430 Rpos[i] = ((Pposi==0) ? 1. : fmin(1.0,Qposi/Pposi));
1431 Rneg[i] = ((Pnegi==0) ? 1. : fmin(1.0,Qnegi/Pnegi));
1438 for (
int i=0; i<numDOFs; i++)
1440 double ith_Limiter_times_FluxCorrectionMatrix = 0.;
1441 double Rposi =
Rpos[i], Rnegi =
Rneg[i];
1443 for (
int offset=csrRowIndeces_DofLoops[i]; offset<csrRowIndeces_DofLoops[i+1]; offset++)
1445 int j = csrColumnOffsets_DofLoops[offset];
1452 limited_solution[i] = uLow[i] + 1./lumped_mass_matrix[i]*ith_Limiter_times_FluxCorrectionMatrix;
1458 double dt = args.
scalar<
double>(
"dt");
1459 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1460 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1461 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1462 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1463 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1464 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1465 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1466 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1467 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1468 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1469 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1470 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1471 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1472 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1473 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1474 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1475 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1476 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1477 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1478 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1479 int nElements_global = args.
scalar<
int>(
"nElements_global");
1480 double useMetrics = args.
scalar<
double>(
"useMetrics");
1481 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1482 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1483 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1484 double sc_uref = args.
scalar<
double>(
"sc_uref");
1485 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
1486 const xt::pyarray<double>& q_vos = args.
array<
double>(
"q_vos");
1487 const xt::pyarray<double>& vos_dof = args.
array<
double>(
"vos_dof");
1488 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1489 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1490 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1491 double degree_polynomial = args.
scalar<
double>(
"degree_polynomial");
1492 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1493 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1494 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1495 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1496 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1497 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1498 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
1499 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
1500 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1501 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
1502 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1503 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1504 int offset_u = args.
scalar<
int>(
"offset_u");
1505 int stride_u = args.
scalar<
int>(
"stride_u");
1506 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1507 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1508 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1509 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1510 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1511 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1512 const xt::pyarray<double>& ebqe_vos_ext = args.
array<
double>(
"ebqe_vos_ext");
1513 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1514 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1515 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
1516 xt::pyarray<double>& ebqe_bc_flux_u_ext = args.
array<
double>(
"ebqe_bc_flux_u_ext");
1517 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1518 double epsFact = args.
scalar<
double>(
"epsFact");
1519 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1520 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
1521 int stage = args.
scalar<
int>(
"stage");
1522 xt::pyarray<double>& uTilde_dof = args.
array<
double>(
"uTilde_dof");
1523 double cE = args.
scalar<
double>(
"cE");
1525 double cK = args.
scalar<
double>(
"cK");
1526 double uL = args.
scalar<
double>(
"uL");
1527 double uR = args.
scalar<
double>(
"uR");
1528 int numDOFs = args.
scalar<
int>(
"numDOFs");
1529 int NNZ = args.
scalar<
int>(
"NNZ");
1530 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1531 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1532 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
1533 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
1534 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
1535 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
1536 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1537 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
1538 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
1539 xt::pyarray<double>& uLow = args.
array<
double>(
"uLow");
1540 xt::pyarray<double>& dLow = args.
array<
double>(
"dLow");
1541 xt::pyarray<double>& dt_times_dH_minus_dL = args.
array<
double>(
"dt_times_dH_minus_dL");
1542 xt::pyarray<double>& min_u_bc = args.
array<
double>(
"min_u_bc");
1543 xt::pyarray<double>& max_u_bc = args.
array<
double>(
"max_u_bc");
1544 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
1549 for (
int i=0; i<NNZ; i++)
1556 psi.resize(numDOFs,0.0);
1557 eta.resize(numDOFs,0.0);
1560 for (
int i=0; i<numDOFs; i++)
1563 if (STABILIZATION_TYPE==2)
1565 double porosity_times_solni = (1.0-vos_dof[i])*u_dof_old[i];
1566 eta[i] = ENTROPY_TYPE == 0 ?
ENTROPY(porosity_times_solni,uL,uR) :
ENTROPY_LOG(porosity_times_solni,uL,uR);
1580 for(
int eN=0;eN<nElements_global;eN++)
1584 elementResidual_u[nDOF_test_element],
1585 element_entropy_residual[nDOF_test_element];
1586 register double elementTransport[nDOF_test_element][nDOF_trial_element];
1587 register double elementTransposeTransport[nDOF_test_element][nDOF_trial_element];
1588 for (
int i=0;i<nDOF_test_element;i++)
1590 elementResidual_u[i]=0.0;
1591 element_entropy_residual[i]=0.0;
1592 for (
int j=0;j<nDOF_trial_element;j++)
1594 elementTransport[i][j]=0.0;
1595 elementTransposeTransport[i][j]=0.0;
1599 for (
int k=0;k<nQuadraturePoints_element;k++)
1602 register int eN_k = eN*nQuadraturePoints_element+k,
1603 eN_k_nSpace = eN_k*nSpace,
1604 eN_nDOF_trial_element = eN*nDOF_trial_element;
1607 aux_entropy_residual=0., DENTROPY_un, DENTROPY_uni,
1609 u=0.0, un=0.0, grad_un[nSpace], porosity_times_velocity[nSpace],
1610 u_test_dV[nDOF_trial_element],
1611 u_grad_trial[nDOF_trial_element*nSpace],
1612 u_grad_test_dV[nDOF_test_element*nSpace],
1614 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1619 ck.calculateMapping_element(eN,
1623 mesh_trial_ref.data(),
1624 mesh_grad_trial_ref.data(),
1629 ck.calculateMappingVelocity_element(eN,
1631 mesh_velocity_dof.data(),
1633 mesh_trial_ref.data(),
1635 dV = fabs(jacDet)*dV_ref[k];
1637 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],
u);
1639 ck.valFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],un);
1641 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1642 ck.gradFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_un);
1645 for (
int j=0;j<nDOF_trial_element;j++)
1647 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
1648 for (
int I=0;I<nSpace;I++)
1649 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1653 if (q_dV_last[eN_k] <= -100)
1654 q_dV_last[eN_k] = dV;
1657 porosity = 1.-q_vos[eN_k];
1661 double mesh_velocity[3];
1662 mesh_velocity[0] =
xt;
1663 mesh_velocity[1] = yt;
1664 mesh_velocity[2] = zt;
1666 for (
int I=0;I<nSpace;I++)
1667 porosity_times_velocity[I] = porosity*(velocity[eN_k_nSpace+I]-MOVING_DOMAIN*mesh_velocity[I]);
1672 calculateCFL(elementDiameter[eN]/degree_polynomial,porosity_times_velocity,cfl[eN_k]);
1677 if (STABILIZATION_TYPE==2)
1679 for (
int I=0;I<nSpace;I++)
1680 aux_entropy_residual += porosity_times_velocity[I]*grad_un[I];
1686 for(
int i=0;i<nDOF_test_element;i++)
1689 int eN_i=eN*nDOF_test_element+i;
1690 if (STABILIZATION_TYPE==2)
1692 int gi = offset_u+stride_u*u_l2g[eN_i];
1693 double porosity_times_uni = (1.-vos_dof[gi])*u_dof_old[gi];
1694 DENTROPY_uni = ENTROPY_TYPE == 0 ?
DENTROPY(porosity_times_uni,uL,uR) :
DENTROPY_LOG(porosity_times_uni,uL,uR);
1695 element_entropy_residual[i] += (DENTROPY_un - DENTROPY_uni)*aux_entropy_residual*u_test_dV[i];
1697 elementResidual_u[i] += porosity*(
u-un)*u_test_dV[i];
1701 for(
int j=0;j<nDOF_trial_element;j++)
1703 int j_nSpace = j*nSpace;
1704 int i_nSpace = i*nSpace;
1705 elementTransport[i][j] +=
1706 ck.AdvectionJacobian_weak(porosity_times_velocity,
1707 u_trial_ref[k*nDOF_trial_element+j],&u_grad_test_dV[i_nSpace]);
1708 elementTransposeTransport[i][j] +=
1709 ck.AdvectionJacobian_weak(porosity_times_velocity,
1710 u_trial_ref[k*nDOF_trial_element+i],&u_grad_test_dV[j_nSpace]);
1715 q_m[eN_k] = porosity*
u;
1720 for(
int i=0;i<nDOF_test_element;i++)
1722 int eN_i=eN*nDOF_test_element+i;
1723 int gi = offset_u+stride_u*u_l2g[eN_i];
1726 globalResidual[gi] += elementResidual_u[i];
1728 if (STABILIZATION_TYPE==2)
1732 for (
int j=0;j<nDOF_trial_element;j++)
1734 int eN_i_j = eN_i*nDOF_trial_element+j;
1736 csrColumnOffsets_CellLoops[eN_i_j]] += elementTransport[i][j];
1738 csrColumnOffsets_CellLoops[eN_i_j]]
1739 += elementTransposeTransport[i][j];
1748 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1750 double min_u_bc_local = 1E10, max_u_bc_local = -1E10;
1751 register int ebN = exteriorElementBoundariesArray[ebNE];
1752 register int eN = elementBoundaryElementsArray[ebN*2+0],
1753 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
1754 eN_nDOF_trial_element = eN*nDOF_trial_element;
1755 register double elementResidual_u[nDOF_test_element];
1756 for (
int i=0;i<nDOF_test_element;i++)
1757 elementResidual_u[i]=0.0;
1759 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1761 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1762 ebNE_kb_nSpace = ebNE_kb*nSpace,
1763 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1764 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1766 u_ext=0.0, bc_u_ext=0.0,
1767 porosity_times_velocity[nSpace],
1768 flux_ext=0.0, dflux_ext=0.0,
1769 fluxTransport[nDOF_trial_element],
1770 jac_ext[nSpace*nSpace],
1772 jacInv_ext[nSpace*nSpace],
1773 boundaryJac[nSpace*(nSpace-1)],
1774 metricTensor[(nSpace-1)*(nSpace-1)],
1775 metricTensorDetSqrt,
1777 u_test_dS[nDOF_test_element],
1778 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,porosity_ext;
1780 ck.calculateMapping_elementBoundary(eN,
1786 mesh_trial_trace_ref.data(),
1787 mesh_grad_trial_trace_ref.data(),
1788 boundaryJac_ref.data(),
1794 metricTensorDetSqrt,
1798 ck.calculateMappingVelocity_elementBoundary(eN,
1802 mesh_velocity_dof.data(),
1804 mesh_trial_trace_ref.data(),
1805 xt_ext,yt_ext,zt_ext,
1810 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
1812 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_ext);
1814 for (
int j=0;j<nDOF_trial_element;j++)
1815 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
1818 porosity_ext = 1.0-ebqe_vos_ext[ebNE_kb];
1822 double mesh_velocity[3];
1823 mesh_velocity[0] = xt_ext;
1824 mesh_velocity[1] = yt_ext;
1825 mesh_velocity[2] = zt_ext;
1827 for (
int I=0;I<nSpace;I++)
1828 porosity_times_velocity[I] = porosity_ext*(ebqe_velocity_ext[ebNE_kb_nSpace+I] - MOVING_DOMAIN*mesh_velocity[I]);
1833 for (
int I=0; I < nSpace; I++)
1834 flow += normal[I]*porosity_times_velocity[I];
1841 ebqe_u[ebNE_kb] = u_ext;
1847 ebqe_u[ebNE_kb] = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*u_ext;
1848 if (isDOFBoundary_u[ebNE_kb] == 1)
1849 flux_ext = ebqe_bc_u_ext[ebNE_kb]*flow;
1850 else if (isFluxBoundary_u[ebNE_kb] == 1)
1851 flux_ext = ebqe_bc_flux_u_ext[ebNE_kb];
1854 std::cout<<
"warning: VOF open boundary with no external trace, setting to zero for inflow"<<std::endl;
1859 for (
int j=0;j<nDOF_trial_element;j++)
1863 elementResidual_u[j] += flux_ext*u_test_dS[j];
1864 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1865 fluxTransport[j] = dflux_ext*u_trial_trace_ref[ebN_local_kb_j];
1870 for (
int i=0;i<nDOF_test_element;i++)
1872 register int eN_i = eN*nDOF_test_element+i;
1873 for (
int j=0;j<nDOF_trial_element;j++)
1876 TransportMatrix[csrRowIndeces_CellLoops[eN_i] + csrColumnOffsets_eb_CellLoops[ebN_i_j]]
1877 += fluxTransport[j]*u_test_dS[i];
1879 += fluxTransport[i]*u_test_dS[j];
1883 min_u_bc_local = fmin(ebqe_u[ebNE_kb], min_u_bc_local);
1884 max_u_bc_local = fmax(ebqe_u[ebNE_kb], max_u_bc_local);
1887 for (
int i=0;i<nDOF_test_element;i++)
1889 int eN_i = eN*nDOF_test_element+i;
1890 int gi = offset_u+stride_u*u_l2g[eN_i];
1891 globalResidual[gi] += dt*elementResidual_u[i];
1893 min_u_bc[gi] = fmin(min_u_bc_local,min_u_bc[gi]);
1894 max_u_bc[gi] = fmax(max_u_bc_local,max_u_bc[gi]);
1904 for (
int i=0; i<numDOFs; i++)
1906 double etaMaxi, etaMini;
1907 if (STABILIZATION_TYPE==2)
1910 etaMaxi = fabs(
eta[i]);
1911 etaMini = fabs(
eta[i]);
1913 double porosity_times_solni = (1.-vos_dof[i])*u_dof_old[i];
1915 double alpha_numerator = 0., alpha_denominator = 0.;
1916 for (
int offset=csrRowIndeces_DofLoops[i]; offset<csrRowIndeces_DofLoops[i+1]; offset++)
1918 int j = csrColumnOffsets_DofLoops[offset];
1919 if (STABILIZATION_TYPE==2)
1922 etaMaxi = fmax(etaMaxi,fabs(
eta[j]));
1923 etaMini = fmin(etaMini,fabs(
eta[j]));
1925 double porosity_times_solnj = (1.-vos_dof[i])*u_dof_old[j];
1926 alpha_numerator += porosity_times_solni - porosity_times_solnj;
1927 alpha_denominator += fabs(porosity_times_solni - porosity_times_solnj);
1931 if (STABILIZATION_TYPE==2)
1938 double alphai = alpha_numerator/(alpha_denominator+1E-15);
1939 quantDOFs[i] = alphai;
1950 for (
int i=0; i<numDOFs; i++)
1953 double solni = u_dof_old[i];
1954 double porosityi = 1.-vos_dof[i];
1955 double ith_dissipative_term = 0;
1956 double ith_low_order_dissipative_term = 0;
1957 double ith_flux_term = 0;
1961 for (
int offset=csrRowIndeces_DofLoops[i]; offset<csrRowIndeces_DofLoops[i+1]; offset++)
1963 int j = csrColumnOffsets_DofLoops[offset];
1964 double solnj = u_dof_old[j];
1965 double porosityj = 1.-vos_dof[j];
1966 double dLowij, dLij, dEVij, dHij;
1972 double solij = 0.5*(porosityi*solni+porosityj*solnj);
1973 double Compij = cK*fmax(solij*(1.0-solij),0.0)/(fabs(porosityi*solni-porosityj*solnj)+1E-14);
1978 dLij = dLowij*fmax(
psi[i],
psi[j]);
1979 if (STABILIZATION_TYPE==2)
1983 dHij = fmin(dLowij,dEVij) * fmax(1.0-Compij,0.0);
1987 dHij = dLij * fmax(1.0-Compij,0.0);
1990 ith_dissipative_term += dHij*(solnj-solni);
1991 ith_low_order_dissipative_term += dLowij*(solnj-solni);
1993 dt_times_dH_minus_dL[ij] = dt*(dHij - dLowij);
2001 dt_times_dH_minus_dL[ij]=0;
2009 edge_based_cfl[i] = 2.*fabs(dLii)/mi;
2010 uLow[i] = u_dof_old[i] - dt/mi*(ith_flux_term
2012 - ith_low_order_dissipative_term);
2015 if (LUMPED_MASS_MATRIX==1)
2016 globalResidual[i] = u_dof_old[i] - dt/mi*(ith_flux_term
2018 - ith_dissipative_term);
2020 globalResidual[i] += dt*(ith_flux_term - ith_dissipative_term);
2026 int nQuadraturePoints_elementIn,
2027 int nDOF_mesh_trial_elementIn,
2028 int nDOF_trial_elementIn,
2029 int nDOF_test_elementIn,
2030 int nQuadraturePoints_elementBoundaryIn,
2034 return proteus::chooseAndAllocateDiscretization2D<cppVOF3P_base,cppVOF,CompKernel>(nSpaceIn,
2035 nQuadraturePoints_elementIn,
2036 nDOF_mesh_trial_elementIn,
2037 nDOF_trial_elementIn,
2038 nDOF_test_elementIn,
2039 nQuadraturePoints_elementBoundaryIn,
2042 return proteus::chooseAndAllocateDiscretization<cppVOF3P_base,cppVOF,CompKernel>(nSpaceIn,
2043 nQuadraturePoints_elementIn,
2044 nDOF_mesh_trial_elementIn,
2045 nDOF_trial_elementIn,
2046 nDOF_test_elementIn,
2047 nQuadraturePoints_elementBoundaryIn,