8 #include "xtensor-python/pyarray.hpp"
21 inline double Sign(
const double&
z){
22 return (
z >= 0.0 ? 1.0 : -1.0);
38 template<
class CompKernelType,
40 int nQuadraturePoints_element,
41 int nDOF_mesh_trial_element,
42 int nDOF_trial_element,
43 int nDOF_test_element,
44 int nQuadraturePoints_elementBoundary>
57 const double df[nSpace],
63 for(
int I=0;I<nSpace;I++)
71 const double grad_u[nSpace],
80 for (
int I=0; I < nSpace; I++)
90 const double dH[nSpace],
94 double h,nrm_v,oneByAbsdt;
97 for(
int I=0;I<nSpace;I++)
101 oneByAbsdt = fabs(dmt);
102 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
108 const double G[nSpace*nSpace],
110 const double Ai[nSpace],
115 for(
int I=0;I<nSpace;I++)
116 for (
int J=0;J<nSpace;J++)
117 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
119 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv + 1.0e-8);
125 const double velocity[nSpace],
126 const double velocity_movingDomain[nSpace],
129 double flow_total=0.0,flow_fluid=0.0,flow_movingDomain=0.0;
130 for (
int I=0; I < nSpace; I++)
132 flow_fluid +=
n[I]*velocity[I];
135 flow_total = flow_fluid+flow_movingDomain;
136 if (flow_total > 0.0)
138 flux =
u*flow_movingDomain;
143 flux = bc_u*flow_movingDomain - flow_fluid*(
u-bc_u);
150 const double velocity[nSpace],
151 const double velocity_movingDomain[nSpace],
154 double flow_total=0.0,flow_fluid=0.0,flow_movingDomain=0.0;
155 for (
int I=0; I < nSpace; I++)
157 flow_fluid +=
n[I]*velocity[I];
160 flow_total=flow_fluid+flow_movingDomain;
161 if (flow_total > 0.0)
163 dflux = flow_movingDomain;
173 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
174 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
175 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
176 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
177 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
178 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
179 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
180 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
181 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
182 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
183 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
184 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
185 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
186 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
187 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
188 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
189 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
190 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
191 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
192 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
193 int nElements_global = args.
scalar<
int>(
"nElements_global");
194 double useMetrics = args.
scalar<
double>(
"useMetrics");
195 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
196 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
197 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
198 double sc_uref = args.
scalar<
double>(
"sc_uref");
199 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
200 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
201 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
202 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
203 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
204 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
205 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
206 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
207 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
208 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
209 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
210 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
211 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
212 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
213 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
214 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
215 int offset_u = args.
scalar<
int>(
"offset_u");
216 int stride_u = args.
scalar<
int>(
"stride_u");
217 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
218 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
219 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
220 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
221 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
222 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
223 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
224 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
225 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
226 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
227 xt::pyarray<double>& cell_interface_locator = args.
array<
double>(
"cell_interface_locator");
228 xt::pyarray<double>& interface_locator = args.
array<
double>(
"interface_locator");
229 int EXPLICIT_METHOD = args.
scalar<
int>(
"EXPLICIT_METHOD");
230 double degree_polynomial = args.
scalar<
double>(
"degree_polynomial");
231 int stage = args.
scalar<
int>(
"stage");
232 xt::pyarray<double>& uTilde_dof = args.
array<
double>(
"uTilde_dof");
233 double dt = args.
scalar<
double>(
"dt");
234 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
235 double meanEntropy = 0., meanOmega = 0., maxEntropy = -1E10, minEntropy = 1E10;
236 register double maxVel[nElements_global], maxEntRes[nElements_global];
249 for(
int eN=0;eN<nElements_global;eN++)
255 register double elementResidual_u[nDOF_test_element];
256 for (
int i=0;i<nDOF_test_element;i++)
258 elementResidual_u[i]=0.0;
261 for (
int k=0;k<nQuadraturePoints_element;k++)
264 register int eN_k = eN*nQuadraturePoints_element+k,
265 eN_k_nSpace = eN_k*nSpace,
266 eN_nDOF_trial_element = eN*nDOF_trial_element;
267 register double u=0.0,grad_u[nSpace],grad_u_old[nSpace],
268 un=0.0, Hn=0.0, HTilde=0.0, grad_uTilde[nSpace],
271 f[nSpace],
df[nSpace],
274 Lstar_u[nDOF_test_element],
276 tau=0.0,tau0=0.0,tau1=0.0,
277 numDiff0=0.0,numDiff1=0.0,
280 jacInv[nSpace*nSpace],
281 u_grad_trial[nDOF_trial_element*nSpace],
282 u_test_dV[nDOF_trial_element],
283 u_grad_test_dV[nDOF_test_element*nSpace],
285 G[nSpace*nSpace],G_dd_G,tr_G;
289 ck.calculateMapping_element(eN,
293 mesh_trial_ref.data(),
294 mesh_grad_trial_ref.data(),
299 ck.calculateMappingVelocity_element(eN,
301 mesh_velocity_dof.data(),
303 mesh_trial_ref.data(),
306 dV = fabs(jacDet)*dV_ref[k];
307 ck.calculateG(jacInv,G,G_dd_G,tr_G);
309 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],
313 ck.valFromDOF(u_dof.data(),
314 &u_l2g[eN_nDOF_trial_element],
315 &u_trial_ref[k*nDOF_trial_element],
317 ck.valFromDOF(u_dof_old.data(),
318 &u_l2g[eN_nDOF_trial_element],
319 &u_trial_ref[k*nDOF_trial_element],
322 ck.gradFromDOF(u_dof.data(),
323 &u_l2g[eN_nDOF_trial_element],
326 ck.gradFromDOF(u_dof_old.data(),
327 &u_l2g[eN_nDOF_trial_element],
330 ck.gradFromDOF(uTilde_dof.data(),
331 &u_l2g[eN_nDOF_trial_element],
335 for (
int j=0;j<nDOF_trial_element;j++)
337 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
338 for (
int I=0;I<nSpace;I++)
340 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
345 for (
int I=0;I<nSpace;I++)
346 q_n[eN_k_nSpace+I] = grad_u[I];
360 double mesh_velocity[3];
361 mesh_velocity[0] =
xt;
362 mesh_velocity[1] = yt;
363 mesh_velocity[2] = zt;
364 for (
int I=0;I<nSpace;I++)
366 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
367 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
372 if (q_dV_last[eN_k] <= -100)
373 q_dV_last[eN_k] = dV;
381 if (EXPLICIT_METHOD==1)
384 double relVelocity[nSpace];
385 for (
int I=0;I<nSpace;I++)
387 Hn += velocity[eN_k_nSpace+I]*grad_u_old[I];
388 HTilde += velocity[eN_k_nSpace+I]*grad_uTilde[I];
389 H += velocity[eN_k_nSpace+I]*grad_u[I];
390 relVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
391 normVel += relVelocity[I]*relVelocity[I];
393 normVel = std::sqrt(normVel);
396 calculateCFL(elementDiameter[eN]/degree_polynomial,relVelocity,cfl[eN_k]);
399 maxVel[eN] = fmax(normVel,maxVel[eN]);
404 maxEntRes[eN] = fmax(maxEntRes[eN],fabs(entRes));
409 maxEntropy = fmax(maxEntropy,
ENTROPY(
u));
410 minEntropy = fmin(minEntropy,
ENTROPY(
u));
418 pdeResidual_u =
ck.Mass_strong(m_t) +
419 ck.Hamiltonian_strong(dH,grad_u)+
420 MOVING_DOMAIN*
ck.Advection_strong(
df,grad_u);
423 for (
int i=0;i<nDOF_test_element;i++)
427 register int i_nSpace = i*nSpace;
428 Lstar_u[i] =
ck.Hamiltonian_adjoint(dH,&u_grad_test_dV[i_nSpace])
429 + MOVING_DOMAIN*
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
432 double subgridErrorVelocity[nSpace];
433 for (
int I=0;I<nSpace;I++)
434 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
438 subgridErrorVelocity,
445 subgridErrorVelocity,
449 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
451 subgridError_u = -tau*pdeResidual_u;
455 ck.calculateNumericalDiffusion(shockCapturingDiffusion,
461 ck.calculateNumericalDiffusion(shockCapturingDiffusion,
469 q_numDiff_u[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
477 for(
int i=0;i<nDOF_test_element;i++)
479 int gi = offset_u+stride_u*u_l2g[eN*nDOF_test_element+i];
482 else if (same_sign==1)
484 same_sign =
sign ==
Sign(u_dof[gi]) ? 1 : 0;
489 register int i_nSpace=i*nSpace;
490 if (EXPLICIT_METHOD==1)
493 elementResidual_u[i] +=
495 ck.Mass_weak(dt*m_t,u_test_dV[i]) +
496 1./3*dt*
ck.Hamiltonian_weak(Hn,u_test_dV[i]) +
497 1./9*dt*dt*
ck.NumericalDiffusion(Hn,dH,&u_grad_test_dV[i_nSpace]) +
498 1./3*dt*
ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
500 &u_grad_test_dV[i_nSpace]);
503 elementResidual_u[i] +=
505 ck.Mass_weak(dt*m_t,u_test_dV[i]) +
506 dt*
ck.Hamiltonian_weak(Hn,u_test_dV[i]) +
507 0.5*dt*dt*
ck.NumericalDiffusion(HTilde,dH,&u_grad_test_dV[i_nSpace]) +
508 dt*
ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
510 &u_grad_test_dV[i_nSpace]);
518 elementResidual_u[i] +=
519 ck.Mass_weak(m_t,u_test_dV[i]) +
520 ck.Hamiltonian_weak(
H,u_test_dV[i]) +
521 MOVING_DOMAIN*
ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace])+
522 (PURE_BDF == 1 ? 0. : 1.)*
523 (
ck.SubgridError(subgridError_u,Lstar_u[i]) +
524 ck.NumericalDiffusion(q_numDiff_u_last[eN_k],
526 &u_grad_test_dV[i_nSpace]));
531 cell_interface_locator[eN] = 1.0;
532 for(
int i=0;i<nDOF_test_element;i++)
534 int gi = offset_u+stride_u*u_l2g[eN*nDOF_test_element+i];
535 interface_locator[gi] = 1.0;
545 for (
int I=0;I<nSpace;I++)
547 int eN_k_I = eN_k*nSpace+I;
548 q_dH[eN_k_I] = dH[I];
554 for(
int i=0;i<nDOF_test_element;i++)
556 register int eN_i=eN*nDOF_test_element+i;
557 globalResidual[offset_u+stride_u*u_l2g[eN_i]] += elementResidual_u[i];
560 if (EXPLICIT_METHOD==1)
562 meanEntropy /= meanOmega;
563 double norm_factor = fmax(fabs(maxEntropy - meanEntropy), fabs(meanEntropy-minEntropy));
564 for(
int eN=0;eN<nElements_global;eN++)
566 double hK=elementDiameter[eN]/degree_polynomial;
567 double linear_viscosity =
cMax*hK*maxVel[eN];
568 double entropy_viscosity =
cE*hK*hK*maxEntRes[eN]/norm_factor;
569 for (
int k=0;k<nQuadraturePoints_element;k++)
571 register int eN_k = eN*nQuadraturePoints_element+k;
572 q_numDiff_u[eN_k] = fmin(linear_viscosity,entropy_viscosity);
583 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
585 register int ebN = exteriorElementBoundariesArray[ebNE],
586 eN = elementBoundaryElementsArray[ebN*2+0],
587 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
588 eN_nDOF_trial_element = eN*nDOF_trial_element;
589 register double elementResidual_u[nDOF_test_element];
590 for (
int i=0;i<nDOF_test_element;i++)
592 elementResidual_u[i]=0.0;
594 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
596 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
597 ebNE_kb_nSpace = ebNE_kb*nSpace,
598 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
599 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
600 register double u_ext=0.0,
610 bc_grad_u_ext[nSpace],
615 jac_ext[nSpace*nSpace],
617 jacInv_ext[nSpace*nSpace],
618 boundaryJac[nSpace*(nSpace-1)],
619 metricTensor[(nSpace-1)*(nSpace-1)],
622 u_test_dS[nDOF_test_element],
623 u_grad_trial_trace[nDOF_trial_element*nSpace],
624 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
625 G[nSpace*nSpace],G_dd_G,tr_G,flux_ext;
630 ck.calculateMapping_elementBoundary(eN,
636 mesh_trial_trace_ref.data(),
637 mesh_grad_trial_trace_ref.data(),
638 boundaryJac_ref.data(),
648 ck.calculateMappingVelocity_elementBoundary(eN,
652 mesh_velocity_dof.data(),
654 mesh_trial_trace_ref.data(),
655 xt_ext,yt_ext,zt_ext,
660 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
663 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
666 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],
670 if (EXPLICIT_METHOD==1)
672 ck.valFromDOF(u_dof_old.data(),
673 &u_l2g[eN_nDOF_trial_element],
674 &u_trial_trace_ref[ebN_local_kb*nDOF_test_element],
676 ck.gradFromDOF(u_dof_old.data(),
677 &u_l2g[eN_nDOF_trial_element],
683 ck.valFromDOF(u_dof.data(),
684 &u_l2g[eN_nDOF_trial_element],
685 &u_trial_trace_ref[ebN_local_kb*nDOF_test_element],
687 ck.gradFromDOF(u_dof.data(),
688 &u_l2g[eN_nDOF_trial_element],
693 for (
int j=0;j<nDOF_trial_element;j++)
695 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
700 bc_u_ext = (isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]
701 +(1-isDOFBoundary_u[ebNE_kb])*ebqe_rd_u_ext[ebNE_kb]);
722 double velocity_ext[nSpace];
723 double mesh_velocity[3];
724 mesh_velocity[0] = xt_ext;
725 mesh_velocity[1] = yt_ext;
726 mesh_velocity[2] = zt_ext;
727 for (
int I=0;I<nSpace;I++)
728 velocity_ext[I] = - MOVING_DOMAIN*mesh_velocity[I];
738 ebqe_u[ebNE_kb] = u_ext;
740 if (EXPLICIT_METHOD==1)
749 for (
int i=0;i<nDOF_test_element;i++)
752 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
758 for (
int i=0;i<nDOF_test_element;i++)
760 int eN_i = eN*nDOF_test_element+i;
762 globalResidual[offset_u+stride_u*u_l2g[eN_i]] += elementResidual_u[i];
770 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
771 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
772 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
773 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
774 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
775 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
776 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
777 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
778 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
779 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
780 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
781 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
782 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
783 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
784 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
785 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
786 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
787 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
788 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
789 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
790 int nElements_global = args.
scalar<
int>(
"nElements_global");
791 double useMetrics = args.
scalar<
double>(
"useMetrics");
792 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
793 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
794 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
795 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
796 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
797 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
798 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
799 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
800 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
801 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
802 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
803 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
804 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
805 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
806 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
807 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
808 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
809 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
810 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
811 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
812 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
813 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
814 int EXPLICIT_METHOD = args.
scalar<
int>(
"EXPLICIT_METHOD");
815 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
821 for(
int eN=0;eN<nElements_global;eN++)
823 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
824 for (
int i=0;i<nDOF_test_element;i++)
825 for (
int j=0;j<nDOF_trial_element;j++)
827 elementJacobian_u_u[i][j]=0.0;
829 for (
int k=0;k<nQuadraturePoints_element;k++)
831 int eN_k = eN*nQuadraturePoints_element+k,
832 eN_k_nSpace = eN_k*nSpace,
833 eN_nDOF_trial_element = eN*nDOF_trial_element;
836 register double u=0.0,
840 f[nSpace],
df[nSpace],
842 dpdeResidual_u_u[nDOF_trial_element],
843 Lstar_u[nDOF_test_element],
844 dsubgridError_u_u[nDOF_trial_element],
845 tau=0.0,tau0=0.0,tau1=0.0,
848 jacInv[nSpace*nSpace],
849 u_grad_trial[nDOF_trial_element*nSpace],
851 u_test_dV[nDOF_test_element],
852 u_grad_test_dV[nDOF_test_element*nSpace],
854 G[nSpace*nSpace],G_dd_G,tr_G;
859 ck.calculateMapping_element(eN,
863 mesh_trial_ref.data(),
864 mesh_grad_trial_ref.data(),
869 ck.calculateMappingVelocity_element(eN,
871 mesh_velocity_dof.data(),
873 mesh_trial_ref.data(),
876 dV = fabs(jacDet)*dV_ref[k];
877 ck.calculateG(jacInv,G,G_dd_G,tr_G);
879 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
881 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],
u);
883 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_u);
885 for (
int j=0;j<nDOF_trial_element;j++)
887 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
888 for (
int I=0;I<nSpace;I++)
890 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
906 double mesh_velocity[3];
907 mesh_velocity[0] =
xt;
908 mesh_velocity[1] = yt;
909 mesh_velocity[2] = zt;
910 for (
int I=0;I<nSpace;I++)
912 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
913 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
928 for (
int i=0;i<nDOF_test_element;i++)
932 register int i_nSpace = i*nSpace;
933 Lstar_u[i]=
ck.Hamiltonian_adjoint(dH,&u_grad_test_dV[i_nSpace]) + MOVING_DOMAIN*
ck.Advection_adjoint(
df,&u_grad_test_dV[i_nSpace]);
937 for (
int j=0;j<nDOF_trial_element;j++)
941 int j_nSpace = j*nSpace;
942 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref[k*nDOF_trial_element+j]) +
943 ck.HamiltonianJacobian_strong(dH,&u_grad_trial[j_nSpace]) +
944 MOVING_DOMAIN*
ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
948 double subgridErrorVelocity[nSpace];
949 for (
int I=0;I<nSpace;I++)
950 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
954 subgridErrorVelocity,
961 subgridErrorVelocity,
964 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
966 for(
int j=0;j<nDOF_trial_element;j++)
967 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
968 for(
int i=0;i<nDOF_test_element;i++)
972 for(
int j=0;j<nDOF_trial_element;j++)
976 int j_nSpace = j*nSpace;
977 int i_nSpace = i*nSpace;
978 if (EXPLICIT_METHOD==1)
980 elementJacobian_u_u[i][j] +=
981 ck.MassJacobian_weak(1.0,
982 u_trial_ref[k*nDOF_trial_element+j],
992 elementJacobian_u_u[i][j] +=
993 ck.MassJacobian_weak(dm_t,
994 u_trial_ref[k*nDOF_trial_element+j],
996 ck.HamiltonianJacobian_weak(dH,&u_grad_trial[j_nSpace],u_test_dV[i]) +
997 MOVING_DOMAIN*
ck.AdvectionJacobian_weak(
df,
998 u_trial_ref[k*nDOF_trial_element+j],
999 &u_grad_test_dV[i_nSpace]) +
1000 (PURE_BDF == 1 ? 0. : 1.)*
1001 (
ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
1002 ck.NumericalDiffusionJacobian(q_numDiff_u_last[eN_k],
1003 &u_grad_trial[j_nSpace],
1004 &u_grad_test_dV[i_nSpace]));
1011 for (
int i=0;i<nDOF_test_element;i++)
1013 int eN_i = eN*nDOF_test_element+i;
1014 for (
int j=0;j<nDOF_trial_element;j++)
1016 int eN_i_j = eN_i*nDOF_trial_element+j;
1017 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_u_u[eN_i_j]] += elementJacobian_u_u[i][j];
1024 if (EXPLICIT_METHOD==0)
1025 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1027 register int ebN = exteriorElementBoundariesArray[ebNE];
1028 register int eN = elementBoundaryElementsArray[ebN*2+0],
1029 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
1030 eN_nDOF_trial_element = eN*nDOF_trial_element;
1031 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1033 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1034 ebNE_kb_nSpace = ebNE_kb*nSpace,
1035 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1036 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1038 register double u_ext=0.0,
1044 bc_grad_u_ext[nSpace],
1056 fluxJacobian_u_u[nDOF_trial_element],
1057 jac_ext[nSpace*nSpace],
1059 jacInv_ext[nSpace*nSpace],
1060 boundaryJac[nSpace*(nSpace-1)],
1061 metricTensor[(nSpace-1)*(nSpace-1)],
1062 metricTensorDetSqrt,
1064 u_test_dS[nDOF_test_element],
1065 u_grad_trial_trace[nDOF_trial_element*nSpace],
1066 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
1067 G[nSpace*nSpace],G_dd_G,tr_G;
1089 ck.calculateMapping_elementBoundary(eN,
1095 mesh_trial_trace_ref.data(),
1096 mesh_grad_trial_trace_ref.data(),
1097 boundaryJac_ref.data(),
1103 metricTensorDetSqrt,
1107 ck.calculateMappingVelocity_elementBoundary(eN,
1111 mesh_velocity_dof.data(),
1113 mesh_trial_trace_ref.data(),
1114 xt_ext,yt_ext,zt_ext,
1119 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
1121 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1124 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1126 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_ext);
1127 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1129 for (
int j=0;j<nDOF_trial_element;j++)
1131 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
1136 bc_u_ext = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*ebqe_rd_u_ext[ebNE_kb];
1157 double velocity_ext[nSpace];
1158 double mesh_velocity[3];
1159 mesh_velocity[0] = xt_ext;
1160 mesh_velocity[1] = yt_ext;
1161 mesh_velocity[2] = zt_ext;
1162 for (
int I=0;I<nSpace;I++)
1164 velocity_ext[I] = - MOVING_DOMAIN*mesh_velocity[I];
1176 for (
int j=0;j<nDOF_trial_element;j++)
1179 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1181 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_u_u_ext,u_trial_trace_ref[ebN_local_kb_j]);
1186 for (
int i=0;i<nDOF_test_element;i++)
1188 register int eN_i = eN*nDOF_test_element+i;
1190 for (
int j=0;j<nDOF_trial_element;j++)
1193 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_eb_u_u[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i];
1203 xt::pyarray<int>& wlc = args.
array<
int>(
"wlc");
1204 xt::pyarray<double>& waterline = args.
array<
double>(
"waterline");
1205 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1206 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1207 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1208 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1209 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1210 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1211 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1212 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1213 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1214 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1215 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1216 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1217 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1218 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1219 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1220 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1221 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1222 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1223 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1224 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1225 int nElements_global = args.
scalar<
int>(
"nElements_global");
1226 double useMetrics = args.
scalar<
double>(
"useMetrics");
1227 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1228 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1229 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1230 double sc_uref = args.
scalar<
double>(
"sc_uref");
1231 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
1232 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1233 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1234 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1235 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1236 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1237 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1238 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1239 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1240 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
1241 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1242 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1243 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1244 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1245 int offset_u = args.
scalar<
int>(
"offset_u");
1246 int stride_u = args.
scalar<
int>(
"stride_u");
1247 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1248 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1249 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1250 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1251 xt::pyarray<int>& elementBoundaryMaterialTypes = args.
array<
int>(
"elementBoundaryMaterialTypes");
1252 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1253 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1254 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1255 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1263 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1265 register int ebN = exteriorElementBoundariesArray[ebNE];
1266 register int eN = elementBoundaryElementsArray[ebN*2+0];
1267 register int bN = elementBoundaryLocalElementBoundariesArray[ebN*2+0];
1269 if (elementBoundaryMaterialTypes[ebN] >6)
1274 double xn=0.0, yn=0.0, zn=0.0, vn=0.0;
1275 double xp=0.0, yp=0.0, zp=0.0, vp=0.0;
1277 for (
int j=0;j<nDOF_trial_element;j++)
1280 int eN_nDOF_trial_element_j = eN*nDOF_trial_element + j;
1281 int eN_nDOF_mesh_trial_element_j = eN*nDOF_mesh_trial_element + j;
1282 val = u_dof[u_l2g[eN_nDOF_trial_element_j]];
1283 x = mesh_dof[mesh_l2g[eN_nDOF_mesh_trial_element_j]*3+0];
1284 y = mesh_dof[mesh_l2g[eN_nDOF_mesh_trial_element_j]*3+1];
1285 z = mesh_dof[mesh_l2g[eN_nDOF_mesh_trial_element_j]*3+2];
1307 if ((
pos > 0) && (
neg > 0) )
1312 double alpha = vp/(vp -vn);
1314 waterline[wlc[0]*3 + 0] = alpha*(xn/
neg) + (1.0-alpha)*(xp/
pos);
1315 waterline[wlc[0]*3 + 1] = alpha*(yn/
neg) + (1.0-alpha)*(yp/
pos);
1316 waterline[wlc[0]*3 + 2] = alpha*(zn/
neg) + (1.0-alpha)*(zp/
pos);
1331 int nQuadraturePoints_elementIn,
1332 int nDOF_mesh_trial_elementIn,
1333 int nDOF_trial_elementIn,
1334 int nDOF_test_elementIn,
1335 int nQuadraturePoints_elementBoundaryIn,
1339 return proteus::chooseAndAllocateDiscretization2D<cppNCLS3P_base,cppNCLS3P,CompKernel>(nSpaceIn,
1340 nQuadraturePoints_elementIn,
1341 nDOF_mesh_trial_elementIn,
1342 nDOF_trial_elementIn,
1343 nDOF_test_elementIn,
1344 nQuadraturePoints_elementBoundaryIn,
1347 return proteus::chooseAndAllocateDiscretization<cppNCLS3P_base,cppNCLS3P,CompKernel>(nSpaceIn,
1348 nQuadraturePoints_elementIn,
1349 nDOF_mesh_trial_elementIn,
1350 nDOF_trial_elementIn,
1351 nDOF_test_elementIn,
1352 nQuadraturePoints_elementBoundaryIn,