9 #include "xtensor-python/pyarray.hpp"
11 namespace py = pybind11;
13 #define POWER_SMOOTHNESS_INDICATOR 2
14 #define IS_BETAij_ONE 0
18 inline double Sign(
const double&
z){
19 return (
z >= 0.0 ? 1.0 : -1.0);
22 inline double ENTROPY(
const double&
phi,
const double& dummyL,
const double& dummyR){
23 return 1./2.*std::pow(fabs(
phi),2.);
25 inline double DENTROPY(
const double&
phi,
const double& dummyL,
const double& dummyR){
26 return fabs(
phi)*(
phi >= 0. ? 1. : -1.);
29 inline double ENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
30 return std::log(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
32 inline double DENTROPY_LOG(
const double&
phi,
const double& phiL,
const double& phiR){
33 return (phiL+phiR-2*
phi)*((
phi-phiL)*(phiR-
phi)>=0 ? 1 : -1)/(fabs((
phi-phiL)*(phiR-
phi))+1E-14);
60 template<
class CompKernelType,
62 int nQuadraturePoints_element,
63 int nDOF_mesh_trial_element,
64 int nDOF_trial_element,
65 int nDOF_test_element,
66 int nQuadraturePoints_elementBoundary>
79 const double grad_u[nSpace],
88 for (
int I=0; I < nSpace; I++)
97 const double df[nSpace],
103 for(
int I=0;I<nSpace;I++)
112 const double dH[nSpace],
116 double h,nrm_v,oneByAbsdt;
119 for(
int I=0;I<nSpace;I++)
123 oneByAbsdt = fabs(dmt);
124 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
130 const double G[nSpace*nSpace],
132 const double Ai[nSpace],
137 for(
int I=0;I<nSpace;I++)
138 for (
int J=0;J<nSpace;J++)
139 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
141 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv + 1.0e-8);
147 const double velocity[nSpace],
148 const double velocity_movingDomain[nSpace],
151 double flow_total=0.0,flow_fluid=0.0,flow_movingDomain=0.0;
152 for (
int I=0; I < nSpace; I++)
154 flow_fluid +=
n[I]*velocity[I];
157 flow_total = flow_fluid+flow_movingDomain;
158 if (flow_total > 0.0)
160 flux =
u*flow_movingDomain;
164 flux = bc_u*flow_movingDomain - flow_fluid*(
u-bc_u);
170 const double velocity[nSpace],
171 const double velocity_movingDomain[nSpace],
174 double flow_total=0.0,flow_fluid=0.0,flow_movingDomain=0.0;
175 for (
int I=0; I < nSpace; I++)
177 flow_fluid +=
n[I]*velocity[I];
180 flow_total=flow_fluid+flow_movingDomain;
181 if (flow_total > 0.0)
183 dflux = flow_movingDomain;
203 H = 0.5*(1.0 +
phi/eps + std::sin(M_PI*
phi/eps)/M_PI);
212 double dt = args.
scalar<
double>(
"dt");
213 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
214 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
215 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
216 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
217 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
218 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
219 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
220 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
221 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
222 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
223 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
224 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
225 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
226 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
227 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
228 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
229 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
230 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
231 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
232 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
233 int nElements_global = args.
scalar<
int>(
"nElements_global");
234 double useMetrics = args.
scalar<
double>(
"useMetrics");
235 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
236 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
237 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
238 double sc_uref = args.
scalar<
double>(
"sc_uref");
239 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
240 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
241 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
242 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
243 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
244 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
245 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
246 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
247 xt::pyarray<double>& uStar_dof = args.
array<
double>(
"uStar_dof");
248 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
249 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
250 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
251 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
252 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
253 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
254 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
255 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
256 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
257 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
258 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
259 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
260 int offset_u = args.
scalar<
int>(
"offset_u");
261 int stride_u = args.
scalar<
int>(
"stride_u");
262 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
263 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
264 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
265 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
266 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
267 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
268 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
269 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
270 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
271 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
272 xt::pyarray<double>& ebqe_grad_u = args.
array<
double>(
"ebqe_grad_u");
273 xt::pyarray<double>& interface_locator = args.
array<
double>(
"interface_locator");
274 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
275 int numDOFs = args.
scalar<
int>(
"numDOFs");
276 int NNZ = args.
scalar<
int>(
"NNZ");
277 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
278 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
279 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
280 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
281 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
282 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
283 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
284 double lambda_coupez = args.
scalar<
double>(
"lambda_coupez");
285 double epsCoupez = args.
scalar<
double>(
"epsCoupez");
286 double epsFactRedistancing = args.
scalar<
double>(
"epsFactRedistancing");
287 int COUPEZ = args.
scalar<
int>(
"COUPEZ");
288 int SATURATED_LEVEL_SET = args.
scalar<
int>(
"SATURATED_LEVEL_SET");
289 xt::pyarray<double>& Cx = args.
array<
double>(
"Cx");
290 xt::pyarray<double>& Cy = args.
array<
double>(
"Cy");
291 xt::pyarray<double>& Cz = args.
array<
double>(
"Cz");
292 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
293 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
294 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
295 double cE = args.
scalar<
double>(
"cE");
308 for(
int eN=0;eN<nElements_global;eN++)
311 register double elementResidual_u[nDOF_test_element];
312 for (
int i=0;i<nDOF_test_element;i++)
314 elementResidual_u[i]=0.0;
317 for (
int k=0;k<nQuadraturePoints_element;k++)
320 register int eN_k = eN*nQuadraturePoints_element+k,
321 eN_k_nSpace = eN_k*nSpace,
322 eN_nDOF_trial_element = eN*nDOF_trial_element;
323 register double u=0.0, u_old=0.0, grad_u[nSpace], grad_u_old[nSpace],
326 f[nSpace],
df[nSpace],
329 Lstar_u[nDOF_test_element],
331 tau=0.0,tau0=0.0,tau1=0.0,
332 numDiff0=0.0,numDiff1=0.0,
335 jacInv[nSpace*nSpace],
336 u_grad_trial[nDOF_trial_element*nSpace],
337 u_test_dV[nDOF_trial_element],
338 u_grad_test_dV[nDOF_test_element*nSpace],
340 G[nSpace*nSpace],G_dd_G,tr_G;
344 ck.calculateMapping_element(eN,
348 mesh_trial_ref.data(),
349 mesh_grad_trial_ref.data(),
354 ck.calculateMappingVelocity_element(eN,
356 mesh_velocity_dof.data(),
358 mesh_trial_ref.data(),
361 dV = fabs(jacDet)*dV_ref.data()[k];
362 ck.calculateG(jacInv,G,G_dd_G,tr_G);
364 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
366 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
368 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
370 for (
int j=0;j<nDOF_trial_element;j++)
372 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
373 for (
int I=0;I<nSpace;I++)
375 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
380 for (
int I=0;I<nSpace;I++)
381 q_n.data()[eN_k_nSpace+I] = grad_u[I];
395 double mesh_velocity[3];
396 mesh_velocity[0] =
xt;
397 mesh_velocity[1] = yt;
398 mesh_velocity[2] = zt;
399 for (
int I=0;I<nSpace;I++)
401 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
402 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
407 if (q_dV_last.data()[eN_k] <= -100)
408 q_dV_last.data()[eN_k] = dV;
409 q_dV.data()[eN_k] = dV;
411 q_m_betaBDF.data()[eN_k],
421 ck.Mass_strong(m_t) +
422 ck.Hamiltonian_strong(dH,grad_u)+
423 MOVING_DOMAIN*
ck.Advection_strong(
df,grad_u);
426 for (
int i=0;i<nDOF_test_element;i++)
430 register int i_nSpace = i*nSpace;
431 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]);
434 double subgridErrorVelocity[nSpace];
435 for (
int I=0;I<nSpace;I++)
436 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
440 subgridErrorVelocity,
447 subgridErrorVelocity,
451 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
453 subgridError_u = -tau*pdeResidual_u;
457 ck.calculateNumericalDiffusion(shockCapturingDiffusion,elementDiameter.data()[eN],pdeResidual_u,grad_u,numDiff0);
458 ck.calculateNumericalDiffusion(shockCapturingDiffusion,sc_uref, sc_alpha,G,G_dd_G,pdeResidual_u,grad_u,numDiff1);
459 q_numDiff_u.data()[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
466 for(
int i=0;i<nDOF_test_element;i++)
468 int gi = offset_u+stride_u*u_l2g.data()[eN*nDOF_test_element+i];
471 else if (same_sign==1)
473 same_sign =
sign ==
Sign(u_dof.data()[gi]) ? 1 : 0;
478 register int i_nSpace=i*nSpace;
480 elementResidual_u[i] +=
481 ck.Mass_weak(m_t,u_test_dV[i]) +
482 ck.Hamiltonian_weak(
H,u_test_dV[i]) +
483 MOVING_DOMAIN*
ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace])+
484 (PURE_BDF == 1 ? 0. : 1.)*
485 (
ck.SubgridError(subgridError_u,Lstar_u[i]) +
486 ck.NumericalDiffusion(q_numDiff_u_last.data()[eN_k],
488 &u_grad_test_dV[i_nSpace]));
491 for(
int i=0;i<nDOF_test_element;i++)
493 int gi = offset_u+stride_u*u_l2g.data()[eN*nDOF_test_element+i];
494 interface_locator.data()[gi] = 1.0;
501 q_m.data()[eN_k] = m;
502 q_u.data()[eN_k] =
u;
503 for (
int I=0;I<nSpace;I++)
505 int eN_k_I = eN_k*nSpace+I;
506 q_dH.data()[eN_k_I] = dH[I];
512 for(
int i=0;i<nDOF_test_element;i++)
514 register int eN_i=eN*nDOF_test_element+i;
515 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] += elementResidual_u[i];
525 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
527 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
528 eN = elementBoundaryElementsArray.data()[ebN*2+0],
529 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
530 eN_nDOF_trial_element = eN*nDOF_trial_element;
531 register double elementResidual_u[nDOF_test_element];
532 for (
int i=0;i<nDOF_test_element;i++)
534 elementResidual_u[i]=0.0;
536 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
538 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
539 ebNE_kb_nSpace = ebNE_kb*nSpace,
540 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
541 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
542 register double u_ext=0.0,
552 bc_grad_u_ext[nSpace],
557 jac_ext[nSpace*nSpace],
559 jacInv_ext[nSpace*nSpace],
560 boundaryJac[nSpace*(nSpace-1)],
561 metricTensor[(nSpace-1)*(nSpace-1)],
564 u_test_dS[nDOF_test_element],
565 u_grad_trial_trace[nDOF_trial_element*nSpace],
566 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
567 G[nSpace*nSpace],G_dd_G,tr_G,flux_ext;
572 ck.calculateMapping_elementBoundary(eN,
578 mesh_trial_trace_ref.data(),
579 mesh_grad_trial_trace_ref.data(),
580 boundaryJac_ref.data(),
590 ck.calculateMappingVelocity_elementBoundary(eN,
594 mesh_velocity_dof.data(),
596 mesh_trial_trace_ref.data(),
597 xt_ext,yt_ext,zt_ext,
602 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
605 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
608 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
610 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);
611 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
613 for (
int j=0;j<nDOF_trial_element;j++)
615 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
620 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*ebqe_rd_u_ext.data()[ebNE_kb];
641 double velocity_ext[nSpace];
642 double mesh_velocity[3];
643 mesh_velocity[0] = xt_ext;
644 mesh_velocity[1] = yt_ext;
645 mesh_velocity[2] = zt_ext;
646 for (
int I=0;I<nSpace;I++)
647 velocity_ext[I] = - MOVING_DOMAIN*mesh_velocity[I];
657 ebqe_u.data()[ebNE_kb] = u_ext;
661 register double norm = 1.0e-8;
662 for (
int I=0;I<nSpace;I++)
663 norm += grad_u_ext[I]*grad_u_ext[I];
665 for (
int I=0;I<nSpace;I++)
666 ebqe_grad_u.data()[ebNE_kb_nSpace+I] = grad_u_ext[I]/norm;
671 for (
int i=0;i<nDOF_test_element;i++)
674 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
680 for (
int i=0;i<nDOF_test_element;i++)
682 int eN_i = eN*nDOF_test_element+i;
684 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] += elementResidual_u[i];
692 double dt = args.
scalar<
double>(
"dt");
693 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
694 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
695 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
696 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
697 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
698 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
699 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
700 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
701 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
702 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
703 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
704 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
705 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
706 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
707 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
708 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
709 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
710 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
711 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
712 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
713 int nElements_global = args.
scalar<
int>(
"nElements_global");
714 double useMetrics = args.
scalar<
double>(
"useMetrics");
715 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
716 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
717 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
718 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
719 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
720 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
721 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
722 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
723 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
724 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
725 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
726 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
727 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
728 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
729 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
730 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
731 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
732 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
733 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
734 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
735 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
736 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
737 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
738 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
739 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
740 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
746 for(
int eN=0;eN<nElements_global;eN++)
748 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
749 for (
int i=0;i<nDOF_test_element;i++)
750 for (
int j=0;j<nDOF_trial_element;j++)
752 elementJacobian_u_u[i][j]=0.0;
754 for (
int k=0;k<nQuadraturePoints_element;k++)
756 int eN_k = eN*nQuadraturePoints_element+k,
757 eN_k_nSpace = eN_k*nSpace,
758 eN_nDOF_trial_element = eN*nDOF_trial_element;
761 register double u=0.0,
765 f[nSpace],
df[nSpace],
767 dpdeResidual_u_u[nDOF_trial_element],
768 Lstar_u[nDOF_test_element],
769 dsubgridError_u_u[nDOF_trial_element],
770 tau=0.0,tau0=0.0,tau1=0.0,
773 jacInv[nSpace*nSpace],
774 u_grad_trial[nDOF_trial_element*nSpace],
776 u_test_dV[nDOF_test_element],
777 u_grad_test_dV[nDOF_test_element*nSpace],
779 G[nSpace*nSpace],G_dd_G,tr_G;
784 ck.calculateMapping_element(eN,
788 mesh_trial_ref.data(),
789 mesh_grad_trial_ref.data(),
794 ck.calculateMappingVelocity_element(eN,
796 mesh_velocity_dof.data(),
798 mesh_trial_ref.data(),
801 dV = fabs(jacDet)*dV_ref.data()[k];
802 ck.calculateG(jacInv,G,G_dd_G,tr_G);
804 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
806 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
808 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
810 for (
int j=0;j<nDOF_trial_element;j++)
812 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
813 for (
int I=0;I<nSpace;I++)
815 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
831 double mesh_velocity[3];
832 mesh_velocity[0] =
xt;
833 mesh_velocity[1] = yt;
834 mesh_velocity[2] = zt;
835 for (
int I=0;I<nSpace;I++)
837 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
838 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
844 q_m_betaBDF.data()[eN_k],
853 for (
int i=0;i<nDOF_test_element;i++)
857 register int i_nSpace = i*nSpace;
858 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]);
862 for (
int j=0;j<nDOF_trial_element;j++)
866 int j_nSpace = j*nSpace;
867 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
868 ck.HamiltonianJacobian_strong(dH,&u_grad_trial[j_nSpace]) +
869 MOVING_DOMAIN*
ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
873 double subgridErrorVelocity[nSpace];
874 for (
int I=0;I<nSpace;I++)
875 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
879 subgridErrorVelocity,
886 subgridErrorVelocity,
889 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
891 for(
int j=0;j<nDOF_trial_element;j++)
892 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
893 for(
int i=0;i<nDOF_test_element;i++)
897 for(
int j=0;j<nDOF_trial_element;j++)
901 int j_nSpace = j*nSpace;
902 int i_nSpace = i*nSpace;
903 elementJacobian_u_u[i][j] +=
904 ck.MassJacobian_weak(dm_t,
905 u_trial_ref.data()[k*nDOF_trial_element+j],
907 ck.HamiltonianJacobian_weak(dH,&u_grad_trial[j_nSpace],u_test_dV[i]) +
908 MOVING_DOMAIN*
ck.AdvectionJacobian_weak(
df,
909 u_trial_ref.data()[k*nDOF_trial_element+j],
910 &u_grad_test_dV[i_nSpace]) +
911 (PURE_BDF == 1 ? 0. : 1.)*
912 (
ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
913 ck.NumericalDiffusionJacobian(q_numDiff_u_last.data()[eN_k],
914 &u_grad_trial[j_nSpace],
915 &u_grad_test_dV[i_nSpace]));
922 for (
int i=0;i<nDOF_test_element;i++)
924 int eN_i = eN*nDOF_test_element+i;
925 for (
int j=0;j<nDOF_trial_element;j++)
927 int eN_i_j = eN_i*nDOF_trial_element+j;
928 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
935 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
937 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
938 register int eN = elementBoundaryElementsArray.data()[ebN*2+0],
939 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
940 eN_nDOF_trial_element = eN*nDOF_trial_element;
941 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
943 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
944 ebNE_kb_nSpace = ebNE_kb*nSpace,
945 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
946 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
948 register double u_ext=0.0,
954 bc_grad_u_ext[nSpace],
966 fluxJacobian_u_u[nDOF_trial_element],
967 jac_ext[nSpace*nSpace],
969 jacInv_ext[nSpace*nSpace],
970 boundaryJac[nSpace*(nSpace-1)],
971 metricTensor[(nSpace-1)*(nSpace-1)],
974 u_test_dS[nDOF_test_element],
975 u_grad_trial_trace[nDOF_trial_element*nSpace],
976 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
977 G[nSpace*nSpace],G_dd_G,tr_G;
999 ck.calculateMapping_elementBoundary(eN,
1005 mesh_trial_trace_ref.data(),
1006 mesh_grad_trial_trace_ref.data(),
1007 boundaryJac_ref.data(),
1013 metricTensorDetSqrt,
1017 ck.calculateMappingVelocity_elementBoundary(eN,
1021 mesh_velocity_dof.data(),
1023 mesh_trial_trace_ref.data(),
1024 xt_ext,yt_ext,zt_ext,
1029 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
1031 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1034 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1036 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);
1037 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1039 for (
int j=0;j<nDOF_trial_element;j++)
1041 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
1046 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*ebqe_rd_u_ext.data()[ebNE_kb];
1067 double velocity_ext[nSpace];
1068 double mesh_velocity[3];
1069 mesh_velocity[0] = xt_ext;
1070 mesh_velocity[1] = yt_ext;
1071 mesh_velocity[2] = zt_ext;
1072 for (
int I=0;I<nSpace;I++)
1074 velocity_ext[I] = - MOVING_DOMAIN*mesh_velocity[I];
1086 for (
int j=0;j<nDOF_trial_element;j++)
1089 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1090 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_u_u_ext,u_trial_trace_ref.data()[ebN_local_kb_j]);
1095 for (
int i=0;i<nDOF_test_element;i++)
1097 register int eN_i = eN*nDOF_test_element+i;
1099 for (
int j=0;j<nDOF_trial_element;j++)
1102 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i];
1112 xt::pyarray<int>& wlc = args.
array<
int>(
"wlc");
1113 xt::pyarray<double>& waterline = args.
array<
double>(
"waterline");
1114 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1115 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1116 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1117 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1118 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1119 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1120 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1121 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1122 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1123 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1124 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1125 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1126 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1127 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1128 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1129 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1130 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1131 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1132 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1133 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1134 int nElements_global = args.
scalar<
int>(
"nElements_global");
1135 double useMetrics = args.
scalar<
double>(
"useMetrics");
1136 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1137 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1138 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1139 double sc_uref = args.
scalar<
double>(
"sc_uref");
1140 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
1141 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1142 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1143 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1144 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1145 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1146 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1147 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1148 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1149 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1150 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
1151 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1152 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1153 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1154 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1155 int offset_u = args.
scalar<
int>(
"offset_u");
1156 int stride_u = args.
scalar<
int>(
"stride_u");
1157 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1158 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1159 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1160 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1161 xt::pyarray<int>& elementBoundaryMaterialTypes = args.
array<
int>(
"elementBoundaryMaterialTypes");
1162 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1163 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1164 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1165 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1173 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1175 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
1176 register int eN = elementBoundaryElementsArray.data()[ebN*2+0];
1177 register int bN = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0];
1179 if (elementBoundaryMaterialTypes.data()[ebN] >6)
1184 double xn=0.0, yn=0.0, zn=0.0, vn=0.0;
1185 double xp=0.0, yp=0.0, zp=0.0, vp=0.0;
1187 for (
int j=0;j<nDOF_trial_element;j++)
1190 int eN_nDOF_trial_element_j = eN*nDOF_trial_element + j;
1191 int eN_nDOF_mesh_trial_element_j = eN*nDOF_mesh_trial_element + j;
1192 val = u_dof.data()[u_l2g.data()[eN_nDOF_trial_element_j]];
1193 x = mesh_dof.data()[mesh_l2g.data()[eN_nDOF_mesh_trial_element_j]*3+0];
1194 y = mesh_dof.data()[mesh_l2g.data()[eN_nDOF_mesh_trial_element_j]*3+1];
1195 z = mesh_dof.data()[mesh_l2g.data()[eN_nDOF_mesh_trial_element_j]*3+2];
1217 if ((
pos > 0) && (
neg > 0) )
1222 double alpha = vp/(vp -vn);
1224 waterline.data()[wlc.data()[0]*3 + 0] = alpha*(xn/
neg) + (1.0-alpha)*(xp/
pos);
1225 waterline.data()[wlc.data()[0]*3 + 1] = alpha*(yn/
neg) + (1.0-alpha)*(yp/
pos);
1226 waterline.data()[wlc.data()[0]*3 + 2] = alpha*(zn/
neg) + (1.0-alpha)*(zp/
pos);
1240 double dt = args.
scalar<
double>(
"dt");
1241 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1242 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1243 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1244 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1245 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1246 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1247 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1248 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1249 int nElements_global = args.
scalar<
int>(
"nElements_global");
1250 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1251 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1252 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1253 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1254 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1255 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1256 xt::pyarray<double>& uStar_dof = args.
array<
double>(
"uStar_dof");
1257 int offset_u = args.
scalar<
int>(
"offset_u");
1258 int stride_u = args.
scalar<
int>(
"stride_u");
1259 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1260 int numDOFs = args.
scalar<
int>(
"numDOFs");
1261 int NNZ = args.
scalar<
int>(
"NNZ");
1262 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1263 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1264 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
1265 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
1266 double lambda_coupez = args.
scalar<
double>(
"lambda_coupez");
1267 double epsCoupez = args.
scalar<
double>(
"epsCoupez");
1268 double epsFactRedistancing = args.
scalar<
double>(
"epsFactRedistancing");
1269 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
1270 int SATURATED_LEVEL_SET = args.
scalar<
int>(
"SATURATED_LEVEL_SET");
1271 xt::pyarray<double>& Cx = args.
array<
double>(
"Cx");
1272 xt::pyarray<double>& Cy = args.
array<
double>(
"Cy");
1273 xt::pyarray<double>& Cz = args.
array<
double>(
"Cz");
1274 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
1277 for (
int i=0; i<numDOFs; i++)
1290 for(
int eN=0;eN<nElements_global;eN++)
1294 elementResidual_u[nDOF_test_element], element_L2_norm_per_node[nDOF_test_element];
1295 register double elementTransport[nDOF_test_element][nDOF_trial_element];
1296 register double elementTransposeTransport[nDOF_test_element][nDOF_trial_element];
1297 for (
int i=0;i<nDOF_test_element;i++)
1299 elementResidual_u[i]=0.0;
1300 element_L2_norm_per_node[i]=0.;
1301 for (
int j=0;j<nDOF_trial_element;j++)
1303 elementTransport[i][j]=0.0;
1304 elementTransposeTransport[i][j]=0.0;
1308 for (
int k=0;k<nQuadraturePoints_element;k++)
1311 register int eN_k = eN*nQuadraturePoints_element+k,
1312 eN_k_nSpace = eN_k*nSpace,
1313 eN_nDOF_trial_element = eN*nDOF_trial_element;
1315 hquad=0.0,
u=0.0, u_test_dV[nDOF_trial_element], uStar=0.0,
1317 un=0.0, grad_u[nSpace], grad_un[nSpace], vn[nSpace],
1318 u_grad_trial[nDOF_trial_element*nSpace],
1320 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1323 ck.calculateMapping_element(eN,k,mesh_dof.data(),mesh_l2g.data(),mesh_trial_ref.data(),mesh_grad_trial_ref.data(),jac,jacDet,jacInv,x,y,
z);
1324 dV = fabs(jacDet)*dV_ref.data()[k];
1326 ck.valFromDOF(nodeDiametersArray.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],hquad);
1328 ck.valFromDOF(uStar_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],uStar);
1330 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
1332 ck.valFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],un);
1334 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1335 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
1336 ck.gradFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_un);
1338 for (
int j=0;j<nDOF_trial_element;j++)
1339 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1341 double norm_grad_un = std::sqrt(std::pow(grad_un[0],2) + std::pow(grad_un[1],2)) + 1E-10;
1342 double norm_grad_u = std::sqrt(std::pow(grad_u[0],2) + std::pow(grad_u[1],2));
1343 double dist_error = norm_grad_u - (1-SATURATED_LEVEL_SET*std::pow(
u/epsCoupez,2));
1345 double sgn =
sign(uStar,epsFactRedistancing);
1346 vn[0] = lambda_coupez*
sgn*grad_un[0]/norm_grad_un;
1347 vn[1] = lambda_coupez*
sgn*grad_un[1]/norm_grad_un;
1352 double residual = (
u-un)
1353 - dt*lambda_coupez*
sgn*(1-SATURATED_LEVEL_SET*std::pow(un/epsCoupez,2));
1354 for(
int i=0;i<nDOF_test_element;i++)
1357 elementResidual_u[i] += residual*u_test_dV[i];
1358 element_L2_norm_per_node[i] += dist_error*u_test_dV[i];
1362 for(
int j=0;j<nDOF_trial_element;j++)
1364 int j_nSpace = j*nSpace;
1365 int i_nSpace = i*nSpace;
1367 elementTransport[i][j] +=
1368 ck.HamiltonianJacobian_weak(vn,&u_grad_trial[j_nSpace],u_test_dV[i]);
1369 elementTransposeTransport[i][j] +=
1370 ck.HamiltonianJacobian_weak(vn,&u_grad_trial[i_nSpace],u_test_dV[j]);
1378 for(
int i=0;i<nDOF_test_element;i++)
1380 int eN_i=eN*nDOF_test_element+i;
1381 int gi = offset_u+stride_u*r_l2g.data()[eN_i];
1384 globalResidual.data()[gi] += elementResidual_u[i];
1388 for (
int j=0;j<nDOF_trial_element;j++)
1390 int eN_i_j = eN_i*nDOF_trial_element+j;
1391 TransportMatrix[csrRowIndeces_CellLoops.data()[eN_i] + csrColumnOffsets_CellLoops.data()[eN_i_j]]
1392 += elementTransport[i][j];
1394 += elementTransposeTransport[i][j];
1404 psi.resize(numDOFs,0.0);
1405 for (
int i=0; i<numDOFs; i++)
1408 double solni = u_dof_old.data()[i];
1410 double alpha_numi=0;
1411 double alpha_deni=0;
1412 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1414 int j = csrColumnOffsets_DofLoops.data()[offset];
1415 double solnj = u_dof_old.data()[j];
1416 alpha_numi += solnj-solni;
1417 alpha_deni += fabs(solnj-solni);
1419 alphai = (fabs(alpha_numi) == alpha_deni ? 1. : fabs(alpha_numi)/(alpha_deni+1E-15));
1427 L2_norm = std::sqrt(L2_norm);
1434 for (
int i=0; i<numDOFs; i++)
1436 double solni = u_dof_old.data()[i];
1437 double ith_dissipative_term = 0;
1438 double ith_flux_term = 0;
1442 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1444 int j = csrColumnOffsets_DofLoops.data()[offset];
1445 double solnj = u_dof_old.data()[j];
1453 dLij *= fmax(
psi[i],
psi[j]);
1455 ith_dissipative_term += dLij*(solnj-solni);
1462 double mi = ML.data()[i];
1464 edge_based_cfl.data()[i] = 2*fabs(dLii)/mi;
1465 globalResidual.data()[i] += dt*(ith_flux_term - ith_dissipative_term);
1472 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1473 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1474 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1475 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1476 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1477 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1478 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1479 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1480 int nElements_global = args.
scalar<
int>(
"nElements_global");
1481 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1482 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1483 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1484 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1485 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1486 int offset_u = args.
scalar<
int>(
"offset_u");
1487 int stride_u = args.
scalar<
int>(
"stride_u");
1488 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1492 for(
int eN=0;eN<nElements_global;eN++)
1496 elementResidual_u[nDOF_test_element];
1497 for (
int i=0;i<nDOF_test_element;i++)
1498 elementResidual_u[i]=0.0;
1501 for (
int k=0;k<nQuadraturePoints_element;k++)
1504 register int eN_k = eN*nQuadraturePoints_element+k,
1505 eN_k_nSpace = eN_k*nSpace,
1506 eN_nDOF_trial_element = eN*nDOF_trial_element;
1508 un=0.0, u_test_dV[nDOF_trial_element], u_grad_trial[nDOF_trial_element*nSpace],
1510 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1513 ck.calculateMapping_element(eN,k,mesh_dof.data(),mesh_l2g.data(),mesh_trial_ref.data(),mesh_grad_trial_ref.data(),jac,jacDet,jacInv,x,y,
z);
1514 dV = fabs(jacDet)*dV_ref.data()[k];
1516 ck.valFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],un);
1518 for (
int j=0;j<nDOF_trial_element;j++)
1519 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1524 for(
int i=0;i<nDOF_test_element;i++)
1525 elementResidual_u[i] += un*u_test_dV[i];
1531 for(
int i=0;i<nDOF_test_element;i++)
1533 int eN_i=eN*nDOF_test_element+i;
1534 int gi = offset_u+stride_u*r_l2g.data()[eN_i];
1537 globalResidual.data()[gi] += elementResidual_u[i];
1544 double dt = args.
scalar<
double>(
"dt");
1545 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1546 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1547 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1548 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1549 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1550 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1551 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1552 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1553 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1554 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1555 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1556 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1557 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1558 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1559 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1560 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1561 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1562 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1563 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1564 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1565 int nElements_global = args.
scalar<
int>(
"nElements_global");
1566 double useMetrics = args.
scalar<
double>(
"useMetrics");
1567 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1568 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1569 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1570 double sc_uref = args.
scalar<
double>(
"sc_uref");
1571 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
1572 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1573 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
1574 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1575 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1576 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
1577 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1578 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1579 xt::pyarray<double>& uStar_dof = args.
array<
double>(
"uStar_dof");
1580 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1581 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1582 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1583 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1584 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
1585 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1586 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
1587 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
1588 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1589 xt::pyarray<double>& edge_based_cfl = args.
array<
double>(
"edge_based_cfl");
1590 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1591 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1592 int offset_u = args.
scalar<
int>(
"offset_u");
1593 int stride_u = args.
scalar<
int>(
"stride_u");
1594 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1595 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1596 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1597 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1598 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1599 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1600 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1601 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
1602 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1603 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1604 xt::pyarray<double>& ebqe_grad_u = args.
array<
double>(
"ebqe_grad_u");
1605 xt::pyarray<double>& interface_locator = args.
array<
double>(
"interface_locator");
1606 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
1607 int numDOFs = args.
scalar<
int>(
"numDOFs");
1608 int NNZ = args.
scalar<
int>(
"NNZ");
1609 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1610 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1611 xt::pyarray<int>& csrRowIndeces_CellLoops = args.
array<
int>(
"csrRowIndeces_CellLoops");
1612 xt::pyarray<int>& csrColumnOffsets_CellLoops = args.
array<
int>(
"csrColumnOffsets_CellLoops");
1613 xt::pyarray<int>& csrColumnOffsets_eb_CellLoops = args.
array<
int>(
"csrColumnOffsets_eb_CellLoops");
1614 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
1615 xt::pyarray<double>& quantDOFs = args.
array<
double>(
"quantDOFs");
1616 double lambda_coupez = args.
scalar<
double>(
"lambda_coupez");
1617 double epsCoupez = args.
scalar<
double>(
"epsCoupez");
1618 double epsFactRedistancing = args.
scalar<
double>(
"epsFactRedistancing");
1619 int COUPEZ = args.
scalar<
int>(
"COUPEZ");
1620 int SATURATED_LEVEL_SET = args.
scalar<
int>(
"SATURATED_LEVEL_SET");
1621 xt::pyarray<double>& Cx = args.
array<
double>(
"Cx");
1622 xt::pyarray<double>& Cy = args.
array<
double>(
"Cy");
1623 xt::pyarray<double>& Cz = args.
array<
double>(
"Cz");
1624 xt::pyarray<double>& ML = args.
array<
double>(
"ML");
1625 int STABILIZATION_TYPE = args.
scalar<
int>(
"STABILIZATION_TYPE");
1626 int ENTROPY_TYPE = args.
scalar<
int>(
"ENTROPY_TYPE");
1627 double cE = args.
scalar<
double>(
"cE");
1651 if (STABILIZATION_TYPE==1)
1652 for (
int i=0; i<numDOFs; i++)
1663 for(
int eN=0;eN<nElements_global;eN++)
1667 elementResidual_u[nDOF_test_element],
1668 element_entropy_residual[nDOF_test_element];
1669 register double elementTransport[nDOF_test_element][nDOF_trial_element];
1670 register double elementTransposeTransport[nDOF_test_element][nDOF_trial_element];
1672 for (
int i=0;i<nDOF_test_element;i++)
1674 elementResidual_u[i]=0.0;
1675 element_entropy_residual[i]=0.0;
1676 for (
int j=0;j<nDOF_trial_element;j++)
1678 elementTransport[i][j]=0.0;
1679 elementTransposeTransport[i][j]=0.0;
1685 for (
int k=0;k<nQuadraturePoints_element;k++)
1688 register int eN_k = eN*nQuadraturePoints_element+k,
1689 eN_k_nSpace = eN_k*nSpace,
1690 eN_nDOF_trial_element = eN*nDOF_trial_element;
1693 aux_entropy_residual=0., DENTROPY_un, DENTROPY_uni,
1695 u=0.0, uStar=0.0, hquad=0.0,
1696 u_test_dV[nDOF_trial_element],
1698 un=0.0, unm1=0.0, grad_u[nSpace], grad_un[nSpace], vn[nSpace],
1699 u_grad_trial[nDOF_trial_element*nSpace],
1701 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1704 ck.calculateMapping_element(eN,
1708 mesh_trial_ref.data(),
1709 mesh_grad_trial_ref.data(),
1713 ck.calculateMappingVelocity_element(eN,
1715 mesh_velocity_dof.data(),
1717 mesh_trial_ref.data(),
1719 dV = fabs(jacDet)*dV_ref.data()[k];
1720 JacDet = fabs(jacDet);
1722 ck.valFromDOF(nodeDiametersArray.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],hquad);
1724 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
1725 ck.valFromDOF(uStar_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],uStar);
1728 ck.valFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],un);
1730 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1731 ck.gradFromDOF(u_dof_old.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_un);
1733 for (
int j=0;j<nDOF_trial_element;j++)
1734 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1739 double mesh_velocity[3];
1740 mesh_velocity[0] =
xt;
1741 mesh_velocity[1] = yt;
1742 mesh_velocity[2] = zt;
1744 double norm_grad_un = 0.;
1745 for (
int I=0;I<nSpace;I++)
1746 norm_grad_un += std::pow(grad_un[I],2);
1747 norm_grad_un = std::sqrt(norm_grad_un) + 1E-10;
1748 double dist_error = fabs(norm_grad_un - (1-SATURATED_LEVEL_SET*std::pow(un/epsCoupez,2)));
1749 double sgn =
sign(uStar,epsFactRedistancing);
1752 for (
int I=0;I<nSpace;I++)
1753 vn[I] = (velocity.data()[eN_k_nSpace+I] - MOVING_DOMAIN*mesh_velocity[I]
1754 + dist_error*COUPEZ*lambda_coupez*
sgn*grad_un[I]/norm_grad_un);
1759 calculateCFL(elementDiameter.data()[eN]/degree_polynomial,vn,cfl.data()[eN_k]);
1764 if (STABILIZATION_TYPE==1)
1769 for (
int I=0;I<nSpace;I++)
1770 aux_entropy_residual += vn[I]*grad_un[I];
1771 aux_entropy_residual -= dist_error*COUPEZ*lambda_coupez*
sgn*(1-SATURATED_LEVEL_SET*std::pow(un/epsCoupez,2));
1772 DENTROPY_un = ENTROPY_TYPE==1 ?
DENTROPY(un,-epsCoupez,epsCoupez) :
DENTROPY_LOG(un,-epsCoupez,epsCoupez);
1777 double residual = (
u-un) - dt*dist_error*COUPEZ*lambda_coupez*
sgn*(1-SATURATED_LEVEL_SET*std::pow(un/epsCoupez,2));
1779 for(
int i=0;i<nDOF_test_element;i++)
1781 int eN_i=eN*nDOF_test_element+i;
1782 int gi = offset_u+stride_u*u_l2g.data()[eN_i];
1784 if (STABILIZATION_TYPE==1)
1786 DENTROPY_uni = ENTROPY_TYPE == 1 ?
DENTROPY(u_dof_old.data()[gi],-epsCoupez,epsCoupez) :
DENTROPY_LOG(u_dof_old.data()[gi],-epsCoupez,epsCoupez);
1787 element_entropy_residual[i] += (DENTROPY_un - DENTROPY_uni)*aux_entropy_residual*u_test_dV[i];
1790 elementResidual_u[i] += residual*u_test_dV[i];
1794 for(
int j=0;j<nDOF_trial_element;j++)
1796 int j_nSpace = j*nSpace;
1797 int i_nSpace = i*nSpace;
1799 elementTransport[i][j] +=
1800 ck.HamiltonianJacobian_weak(vn,&u_grad_trial[j_nSpace],u_test_dV[i]);
1801 elementTransposeTransport[i][j] +=
1802 ck.HamiltonianJacobian_weak(vn,&u_grad_trial[i_nSpace],u_test_dV[j]);
1807 q_m.data()[eN_k] =
u;
1808 for (
int I=0;I<nSpace;I++)
1809 q_n.data()[eN_k_nSpace+I] = grad_u[I];
1834 for(
int i=0;i<nDOF_test_element;i++)
1836 int eN_i=eN*nDOF_test_element+i;
1837 int gi = offset_u+stride_u*r_l2g.data()[eN_i];
1840 globalResidual.data()[gi] += elementResidual_u[i];
1842 if (STABILIZATION_TYPE==1)
1846 for (
int j=0;j<nDOF_trial_element;j++)
1848 int eN_i_j = eN_i*nDOF_trial_element+j;
1849 TransportMatrix[csrRowIndeces_CellLoops.data()[eN_i] + csrColumnOffsets_CellLoops.data()[eN_i_j]]
1850 += elementTransport[i][j];
1852 += elementTransposeTransport[i][j];
1861 gx.resize(numDOFs,0.0);
1862 gy.resize(numDOFs,0.0);
1863 gz.resize(numDOFs,0.0);
1864 eta.resize(numDOFs,0.0);
1870 for (
int i=0; i<numDOFs; i++)
1872 double solni = u_dof_old.data()[i];
1873 if (STABILIZATION_TYPE==1)
1874 eta[i] = ENTROPY_TYPE == 1 ?
ENTROPY(solni,-epsCoupez,epsCoupez) :
ENTROPY_LOG(solni,-epsCoupez,epsCoupez);
1886 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1888 int j = csrColumnOffsets_DofLoops.data()[offset];
1889 double solnj = u_dof_old.data()[j];
1892 gx[i] += Cx.data()[ij]*solnj;
1893 gy[i] += Cy.data()[ij]*solnj;
1895 gz[i] += Cz.data()[ij]*solnj;
1897 double alpha_num = solni - solnj;
1898 if (alpha_num >= 0.)
1911 gx[i] /= ML.data()[i];
1912 gy[i] /= ML.data()[i];
1914 gz[i] /= ML.data()[i];
1924 psi.resize(numDOFs,0.0);
1925 etaMax.resize(numDOFs,0.0);
1926 etaMin.resize(numDOFs,0.0);
1927 for (
int i=0; i<numDOFs; i++)
1929 double xi, yi, zi, SumPos=0., SumNeg=0.;
1930 if (STABILIZATION_TYPE==1)
1938 xi = mesh_dof.data()[i*3+0];
1939 yi = mesh_dof.data()[i*3+1];
1941 zi = mesh_dof.data()[i*3+2];
1944 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1946 int j = csrColumnOffsets_DofLoops.data()[offset];
1947 if (STABILIZATION_TYPE==1)
1957 double xj = mesh_dof.data()[j*3+0];
1958 double yj = mesh_dof.data()[j*3+1];
1961 zj = mesh_dof.data()[j*3+2];
1966 double gi_times_x =
gx[i]*(xi-xj) +
gy[i]*(yi-yj);
1968 gi_times_x +=
gz[i]*(zi-zj);
1970 SumPos += gi_times_x > 0 ? gi_times_x : 0;
1971 SumNeg += gi_times_x < 0 ? gi_times_x : 0;
1974 if (STABILIZATION_TYPE==1)
1983 double sigmaPosi = fmin(1.,(fabs(SumNeg)+1E-15)/(SumPos+1E-15));
1984 double sigmaNegi = fmin(1.,(SumPos+1E-15)/(fabs(SumNeg)+1E-15));
1992 double alphai = alpha_numi/(alpha_deni+1E-15);
1993 quantDOFs.data()[i] = alphai;
2007 for (
int i=0; i<numDOFs; i++)
2009 double solni = u_dof_old.data()[i];
2010 double ith_dissipative_term = 0;
2011 double ith_flux_term = 0;
2015 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
2017 int j = csrColumnOffsets_DofLoops.data()[offset];
2018 double solnj = u_dof_old.data()[j];
2019 double dLowij, dHij, dEVij;
2026 if (STABILIZATION_TYPE==1)
2030 dHij = fmin(dLowij,dEVij);
2033 dHij = dLowij*fmax(
psi[i],
psi[j]);
2036 ith_dissipative_term += dHij*(solnj-solni);
2043 double mi = ML.data()[i];
2045 edge_based_cfl.data()[i] = 2.*fabs(dLowii)/mi;
2047 if (LUMPED_MASS_MATRIX==1)
2050 globalResidual.data()[i] = u_dof_old.data()[i] - dt/mi*(ith_flux_term - ith_dissipative_term);
2053 globalResidual.data()[i] += dt*(ith_flux_term - ith_dissipative_term);
2059 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
2061 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
2062 eN = elementBoundaryElementsArray.data()[ebN*2+0],
2063 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
2064 eN_nDOF_trial_element = eN*nDOF_trial_element;
2065 register double elementResidual_u[nDOF_test_element];
2066 for (
int i=0;i<nDOF_test_element;i++)
2067 elementResidual_u[i]=0.0;
2068 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
2070 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
2071 ebNE_kb_nSpace = ebNE_kb*nSpace,
2072 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
2073 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
2074 register double u_ext=0.0,
2081 bc_grad_u_ext[nSpace],
2086 jac_ext[nSpace*nSpace],
2088 jacInv_ext[nSpace*nSpace],
2089 boundaryJac[nSpace*(nSpace-1)],
2090 metricTensor[(nSpace-1)*(nSpace-1)],
2091 metricTensorDetSqrt,
2093 u_test_dS[nDOF_test_element],
2094 u_grad_trial_trace[nDOF_trial_element*nSpace],
2095 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
2096 G[nSpace*nSpace],G_dd_G,tr_G,flux_ext;
2101 ck.calculateMapping_elementBoundary(eN,
2107 mesh_trial_trace_ref.data(),
2108 mesh_grad_trial_trace_ref.data(),
2109 boundaryJac_ref.data(),
2115 metricTensorDetSqrt,
2119 ck.calculateMappingVelocity_elementBoundary(eN,
2123 mesh_velocity_dof.data(),
2125 mesh_trial_trace_ref.data(),
2126 xt_ext,yt_ext,zt_ext,
2131 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
2134 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
2137 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
2139 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);
2140 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
2142 for (
int j=0;j<nDOF_trial_element;j++)
2143 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
2147 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*ebqe_rd_u_ext.data()[ebNE_kb];
2168 double velocity_ext[nSpace];
2169 double mesh_velocity[3];
2170 mesh_velocity[0] = xt_ext;
2171 mesh_velocity[1] = yt_ext;
2172 mesh_velocity[2] = zt_ext;
2173 for (
int I=0;I<nSpace;I++)
2174 velocity_ext[I] = - MOVING_DOMAIN*mesh_velocity[I];
2184 ebqe_u.data()[ebNE_kb] = u_ext;
2188 register double norm = 1.0e-8;
2189 for (
int I=0;I<nSpace;I++)
2190 norm += grad_u_ext[I]*grad_u_ext[I];
2192 for (
int I=0;I<nSpace;I++)
2193 ebqe_grad_u.data()[ebNE_kb_nSpace+I] = grad_u_ext[I]/norm;
2199 for (
int i=0;i<nDOF_test_element;i++)
2202 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
2208 for (
int i=0;i<nDOF_test_element;i++)
2210 int eN_i = eN*nDOF_test_element+i;
2211 double mi = ML.data()[offset_u+stride_u*u_l2g.data()[eN_i]];
2212 if (LUMPED_MASS_MATRIX==1)
2213 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] -= dt/mi*elementResidual_u[i];
2215 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]] += dt*elementResidual_u[i];
2223 double dt = args.
scalar<
double>(
"dt");
2224 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
2225 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
2226 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
2227 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
2228 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
2229 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
2230 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
2231 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
2232 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
2233 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
2234 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
2235 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
2236 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
2237 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
2238 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
2239 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
2240 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
2241 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
2242 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
2243 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
2244 int nElements_global = args.
scalar<
int>(
"nElements_global");
2245 double useMetrics = args.
scalar<
double>(
"useMetrics");
2246 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
2247 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
2248 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
2249 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
2250 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
2251 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
2252 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
2253 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
2254 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
2255 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
2256 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
2257 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
2258 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
2259 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
2260 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
2261 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2262 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
2263 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
2264 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2265 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
2266 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
2267 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
2268 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
2269 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
2270 int PURE_BDF = args.
scalar<
int>(
"PURE_BDF");
2271 int LUMPED_MASS_MATRIX = args.
scalar<
int>(
"LUMPED_MASS_MATRIX");
2272 double Ct_sge = 4.0;
2277 for(
int eN=0;eN<nElements_global;eN++)
2279 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
2280 for (
int i=0;i<nDOF_test_element;i++)
2281 for (
int j=0;j<nDOF_trial_element;j++)
2283 elementJacobian_u_u[i][j]=0.0;
2285 for (
int k=0;k<nQuadraturePoints_element;k++)
2287 int eN_k = eN*nQuadraturePoints_element+k,
2288 eN_k_nSpace = eN_k*nSpace,
2289 eN_nDOF_trial_element = eN*nDOF_trial_element;
2292 register double u=0.0,
2296 f[nSpace],
df[nSpace],
2298 dpdeResidual_u_u[nDOF_trial_element],
2299 Lstar_u[nDOF_test_element],
2300 dsubgridError_u_u[nDOF_trial_element],
2301 tau=0.0,tau0=0.0,tau1=0.0,
2304 jacInv[nSpace*nSpace],
2305 u_grad_trial[nDOF_trial_element*nSpace],
2307 u_test_dV[nDOF_test_element],
2308 u_grad_test_dV[nDOF_test_element*nSpace],
2310 G[nSpace*nSpace],G_dd_G,tr_G;
2315 ck.calculateMapping_element(eN,
2319 mesh_trial_ref.data(),
2320 mesh_grad_trial_ref.data(),
2325 ck.calculateMappingVelocity_element(eN,
2327 mesh_velocity_dof.data(),
2329 mesh_trial_ref.data(),
2332 dV = fabs(jacDet)*dV_ref.data()[k];
2333 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2335 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
2337 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
2339 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
2341 for (
int j=0;j<nDOF_trial_element;j++)
2343 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
2344 for (
int I=0;I<nSpace;I++)
2346 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
2362 double mesh_velocity[3];
2363 mesh_velocity[0] =
xt;
2364 mesh_velocity[1] = yt;
2365 mesh_velocity[2] = zt;
2366 for (
int I=0;I<nSpace;I++)
2368 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
2369 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
2375 q_m_betaBDF.data()[eN_k],
2384 for (
int i=0;i<nDOF_test_element;i++)
2388 register int i_nSpace = i*nSpace;
2389 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]);
2393 for (
int j=0;j<nDOF_trial_element;j++)
2397 int j_nSpace = j*nSpace;
2398 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
2399 ck.HamiltonianJacobian_strong(dH,&u_grad_trial[j_nSpace]) +
2400 MOVING_DOMAIN*
ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
2404 double subgridErrorVelocity[nSpace];
2405 for (
int I=0;I<nSpace;I++)
2406 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
2410 subgridErrorVelocity,
2417 subgridErrorVelocity,
2420 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
2422 for(
int j=0;j<nDOF_trial_element;j++)
2423 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
2425 for(
int i=0;i<nDOF_test_element;i++)
2429 for(
int j=0;j<nDOF_trial_element;j++)
2433 int j_nSpace = j*nSpace;
2434 int i_nSpace = i*nSpace;
2435 if (LUMPED_MASS_MATRIX==1)
2438 elementJacobian_u_u[i][j] += u_test_dV[i];
2442 elementJacobian_u_u[i][j] +=
2443 dt*
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]);
2451 for (
int i=0;i<nDOF_test_element;i++)
2453 int eN_i = eN*nDOF_test_element+i;
2454 for (
int j=0;j<nDOF_trial_element;j++)
2456 int eN_i_j = eN_i*nDOF_trial_element+j;
2457 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
2465 double dt = args.
scalar<
double>(
"dt");
2466 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
2467 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
2468 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
2469 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
2470 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
2471 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
2472 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
2473 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
2474 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
2475 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
2476 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
2477 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
2478 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
2479 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
2480 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
2481 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
2482 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
2483 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
2484 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
2485 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
2486 int nElements_global = args.
scalar<
int>(
"nElements_global");
2487 double useMetrics = args.
scalar<
double>(
"useMetrics");
2488 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
2489 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
2490 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
2491 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
2492 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
2493 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
2494 int degree_polynomial = args.
scalar<
int>(
"degree_polynomial");
2495 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
2496 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
2497 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
2498 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
2499 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
2500 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
2501 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
2502 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
2503 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2504 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
2505 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
2506 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2507 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
2508 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
2509 xt::pyarray<double>& ebqe_rd_u_ext = args.
array<
double>(
"ebqe_rd_u_ext");
2510 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
2511 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
2512 double he = args.
scalar<
double>(
"he");
2513 double Ct_sge = 4.0;
2518 for(
int eN=0;eN<nElements_global;eN++)
2520 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
2521 for (
int i=0;i<nDOF_test_element;i++)
2522 for (
int j=0;j<nDOF_trial_element;j++)
2524 elementJacobian_u_u[i][j]=0.0;
2526 for (
int k=0;k<nQuadraturePoints_element;k++)
2528 int eN_k = eN*nQuadraturePoints_element+k,
2529 eN_k_nSpace = eN_k*nSpace,
2530 eN_nDOF_trial_element = eN*nDOF_trial_element;
2533 register double u=0.0,
2537 f[nSpace],
df[nSpace],
2539 dpdeResidual_u_u[nDOF_trial_element],
2540 Lstar_u[nDOF_test_element],
2541 dsubgridError_u_u[nDOF_trial_element],
2542 tau=0.0,tau0=0.0,tau1=0.0,
2545 jacInv[nSpace*nSpace],
2546 u_grad_trial[nDOF_trial_element*nSpace],
2548 u_test_dV[nDOF_test_element],
2549 u_grad_test_dV[nDOF_test_element*nSpace],
2551 G[nSpace*nSpace],G_dd_G,tr_G;
2556 ck.calculateMapping_element(eN,
2560 mesh_trial_ref.data(),
2561 mesh_grad_trial_ref.data(),
2566 ck.calculateMappingVelocity_element(eN,
2568 mesh_velocity_dof.data(),
2570 mesh_trial_ref.data(),
2573 dV = fabs(jacDet)*dV_ref.data()[k];
2574 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2576 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
2578 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
2580 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
2582 for (
int j=0;j<nDOF_trial_element;j++)
2584 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
2585 for (
int I=0;I<nSpace;I++)
2587 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
2603 double mesh_velocity[3];
2604 mesh_velocity[0] =
xt;
2605 mesh_velocity[1] = yt;
2606 mesh_velocity[2] = zt;
2607 for (
int I=0;I<nSpace;I++)
2609 f[I] = -MOVING_DOMAIN*m*mesh_velocity[I];
2610 df[I] = -MOVING_DOMAIN*dm*mesh_velocity[I];
2616 q_m_betaBDF.data()[eN_k],
2625 for (
int i=0;i<nDOF_test_element;i++)
2629 register int i_nSpace = i*nSpace;
2630 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]);
2634 for (
int j=0;j<nDOF_trial_element;j++)
2638 int j_nSpace = j*nSpace;
2639 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
2640 ck.HamiltonianJacobian_strong(dH,&u_grad_trial[j_nSpace]) +
2641 MOVING_DOMAIN*
ck.AdvectionJacobian_strong(
df,&u_grad_trial[j_nSpace]);
2645 double subgridErrorVelocity[nSpace];
2646 for (
int I=0;I<nSpace;I++)
2647 subgridErrorVelocity[I] = dH[I] - MOVING_DOMAIN*
df[I];
2651 subgridErrorVelocity,
2658 subgridErrorVelocity,
2661 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
2663 for(
int j=0;j<nDOF_trial_element;j++)
2664 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
2666 for(
int i=0;i<nDOF_test_element;i++)
2670 for(
int j=0;j<nDOF_trial_element;j++)
2674 int j_nSpace = j*nSpace;
2675 int i_nSpace = i*nSpace;
2676 elementJacobian_u_u[i][j] +=
2677 dt*
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]) +
2678 ck.NumericalDiffusionJacobian(std::pow(he,2),&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]);
2685 for (
int i=0;i<nDOF_test_element;i++)
2687 int eN_i = eN*nDOF_test_element+i;
2688 for (
int j=0;j<nDOF_trial_element;j++)
2690 int eN_i_j = eN_i*nDOF_trial_element+j;
2691 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
2699 int nQuadraturePoints_elementIn,
2700 int nDOF_mesh_trial_elementIn,
2701 int nDOF_trial_elementIn,
2702 int nDOF_test_elementIn,
2703 int nQuadraturePoints_elementBoundaryIn,
2707 return proteus::chooseAndAllocateDiscretization2D<NCLS_base,NCLS,CompKernel>(nSpaceIn,
2708 nQuadraturePoints_elementIn,
2709 nDOF_mesh_trial_elementIn,
2710 nDOF_trial_elementIn,
2711 nDOF_test_elementIn,
2712 nQuadraturePoints_elementBoundaryIn,
2715 return proteus::chooseAndAllocateDiscretization<NCLS_base,NCLS,CompKernel>(nSpaceIn,
2716 nQuadraturePoints_elementIn,
2717 nDOF_mesh_trial_elementIn,
2718 nDOF_trial_elementIn,
2719 nDOF_test_elementIn,
2720 nQuadraturePoints_elementBoundaryIn,