10 #include "xtensor-python/pyarray.hpp"
12 namespace py = pybind11;
14 #define SINGLE_POTENTIAL 1
20 return (
z>0 ? 1. : (
z<0 ? 0. : 0.5));
23 template<
int nSpace,
int nP,
int nQ,
int nEBQ>
40 template<
class CompKernelType,
42 int nQuadraturePoints_element,
43 int nDOF_mesh_trial_element,
44 int nDOF_trial_element,
45 int nDOF_test_element,
46 int nQuadraturePoints_elementBoundary>
60 const double& u_levelSet,
62 const double grad_u[nSpace],
70 double normGradU=0.0,Si=0.0;
74 Si=
gf.H(eps,u_levelSet) -
gf.ImH(eps,u_levelSet);
82 for (I=0; I < nSpace; I++)
84 normGradU += grad_u[I]*grad_u[I];
86 normGradU = sqrt(normGradU);
88 for (I=0; I < nSpace; I++)
90 dH[I] = Si*grad_u[I]/(normGradU+1.0e-12);
97 const double dH[nSpace],
101 double h,nrm_v,oneByAbsdt;
104 for(
int I=0;I<nSpace;I++)
112 tau = 1.0/sqrt(4.0*nrm_v*nrm_v/(h*h) + oneByAbsdt*oneByAbsdt + 1.0e-8);
117 const double Ai[nSpace],
122 for(
int I=0;I<nSpace;I++)
123 for (
int J=0;J<nSpace;J++)
124 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
126 tau_v = 1.0/(sqrt(v_d_Gv) + 1.0e-8);
133 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
134 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
135 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
136 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
137 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
138 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
139 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
140 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
141 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
142 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
143 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
144 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
145 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
146 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
147 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
148 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
149 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
150 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
151 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
152 int nElements_global = args.
scalar<
int>(
"nElements_global");
153 double useMetrics = args.
scalar<
double>(
"useMetrics");
154 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
155 double epsFact_redist = args.
scalar<
double>(
"epsFact_redist");
156 double backgroundDiffusionFactor = args.
scalar<
double>(
"backgroundDiffusionFactor");
157 double weakDirichletFactor = args.
scalar<
double>(
"weakDirichletFactor");
158 int freezeLevelSet = args.
scalar<
int>(
"freezeLevelSet");
159 int useTimeIntegration = args.
scalar<
int>(
"useTimeIntegration");
160 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
161 int lag_subgridError = args.
scalar<
int>(
"lag_subgridError");
162 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
163 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
164 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
165 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
166 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
167 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
168 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
169 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
170 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
171 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
172 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
173 xt::pyarray<double>& u_weak_internal_bc_dofs = args.
array<
double>(
"u_weak_internal_bc_dofs");
174 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
175 xt::pyarray<double>& q_dH_last = args.
array<
double>(
"q_dH_last");
176 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
177 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
178 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
179 xt::pyarray<int>& weakDirichletConditionFlags = args.
array<
int>(
"weakDirichletConditionFlags");
180 int offset_u = args.
scalar<
int>(
"offset_u");
181 int stride_u = args.
scalar<
int>(
"stride_u");
182 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
183 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
184 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
185 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
186 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
187 xt::pyarray<double>& ebqe_phi_ls_ext = args.
array<
double>(
"ebqe_phi_ls_ext");
188 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
189 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
190 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
191 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
192 int ELLIPTIC_REDISTANCING = args.
scalar<
int>(
"ELLIPTIC_REDISTANCING");
193 double backgroundDissipationEllipticRedist = args.
scalar<
double>(
"backgroundDissipationEllipticRedist");
194 xt::pyarray<double>& lumped_qx = args.
array<
double>(
"lumped_qx");
195 xt::pyarray<double>& lumped_qy = args.
array<
double>(
"lumped_qy");
196 xt::pyarray<double>& lumped_qz = args.
array<
double>(
"lumped_qz");
197 double alpha = args.
scalar<
double>(
"alpha");
198 double circbc=0.0,circ=0.0;
199 gf.useExact=useExact;
200 gfu.useExact=useExact;
202 std::cout<<
"stuff"<<
"\t"
204 <<epsFact_redist<<
"\t"
205 <<freezeLevelSet<<
"\t"
206 <<useTimeIntegration<<
"\t"
207 <<lag_shockCapturing<<
"\t"
208 <<lag_subgridError<<std::endl;
220 double timeIntegrationScale = 1.0;
221 if (useTimeIntegration == 0)
222 timeIntegrationScale = 0.0;
223 double lag_shockCapturingScale = 1.0;
224 if (lag_shockCapturing == 0)
225 lag_shockCapturingScale = 0.0;
226 for(
int eN=0;eN<nElements_global;eN++)
229 register int dummy_l2g[nDOF_mesh_trial_element];
230 register double elementResidual_u[nDOF_test_element],element_phi[nDOF_trial_element];
231 double epsilon_redist,h_phi, dir[nSpace], norm;
232 for (
int i=0;i<nDOF_test_element;i++)
234 register int eN_i=eN*nDOF_trial_element+i;
235 elementResidual_u[i]=0.0;
236 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]];
239 double element_nodes[nDOF_mesh_trial_element*3];
240 for (
int i=0;i<nDOF_mesh_trial_element;i++)
242 register int eN_i=eN*nDOF_mesh_trial_element+i;
244 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
246 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
258 for (
int k=0;k<nQuadraturePoints_element;k++)
262 register int eN_k = eN*nQuadraturePoints_element+k,
263 eN_k_nSpace = eN_k*nSpace,
264 eN_nDOF_trial_element = eN*nDOF_trial_element;
265 register double u=0.0,grad_u[nSpace],u0=0.0, grad_phi[nSpace],
273 Lstar_u[nDOF_test_element],
275 tau=0.0,tau0=0.0,tau1=0.0,
276 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;
286 ck.calculateMapping_element(eN,
290 mesh_trial_ref.data(),
291 mesh_grad_trial_ref.data(),
296 ck.calculateH_element(eN,
298 nodeDiametersArray.data(),
300 mesh_trial_ref.data(),
303 dV = fabs(jacDet)*dV_ref.data()[k];
304 ck.calculateG(jacInv,G,G_dd_G,tr_G);
307 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
309 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
310 ck.valFromDOF(
gf.exact.phi_dof_corrected,dummy_l2g,&u_trial_ref.data()[k*nDOF_trial_element],u0);
313 u0 = phi_ls.data()[eN_k];
329 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
331 for (
int j=0;j<nDOF_trial_element;j++)
333 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
334 for (
int I=0;I<nSpace;I++)
336 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
352 epsilon_redist = epsFact_redist*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
366 for (
int I=0; I < nSpace; I++)
369 dH_strong[I] = dH[I];
371 if (lag_subgridError > 0)
373 for (
int I=0; I < nSpace; I++)
375 dH_tau[I] = q_dH_last.data()[eN_k_nSpace+I];
378 if (lag_subgridError > 1)
380 for (
int I=0; I < nSpace; I++)
382 dH_strong[I] = q_dH_last.data()[eN_k_nSpace+I];
388 q_m.data()[eN_k] = m;
389 q_u.data()[eN_k] =
u;
390 for (
int I=0;I<nSpace;I++)
391 q_n.data()[eN_k_nSpace+I] = dir[I];
393 for (
int I=0;I<nSpace;I++)
395 int eN_k_nSpace_I = eN_k_nSpace+I;
396 q_dH.data()[eN_k_nSpace_I] = dH[I];
407 q_m_betaBDF.data()[eN_k],
414 m *= timeIntegrationScale; dm *= timeIntegrationScale; m_t *= timeIntegrationScale;
415 dm_t *= timeIntegrationScale;
417 std::cout<<
"alpha "<<alphaBDF<<
"\t"<<q_m_betaBDF.data()[eN_k]<<
"\t"<<m_t<<
'\t'<<m<<
'\t'<<alphaBDF*m<<std::endl;
423 pdeResidual_u =
ck.Mass_strong(m_t) +
424 ck.Hamiltonian_strong(dH_strong,grad_u) +
425 ck.Reaction_strong(
r);
427 std::cout<<
"dH_strong "<<dH_strong[0]<<
'\t'<<dH_strong[1]<<
'\t'<<dH_strong[2]<<std::endl;
430 for (
int i=0;i<nDOF_test_element;i++)
433 register int i_nSpace=i*nSpace;
434 Lstar_u[i] =
ck.Hamiltonian_adjoint(dH_strong,&u_grad_test_dV[i_nSpace]);
447 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
452 subgridError_u = -tau*pdeResidual_u;
456 ck.calculateNumericalDiffusion(shockCapturingDiffusion,elementDiameter.data()[eN],pdeResidual_u,grad_u,numDiff0);
457 ck.calculateNumericalDiffusion(shockCapturingDiffusion,G,pdeResidual_u,grad_u,numDiff1);
459 q_numDiff_u.data()[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
462 std::cout<<
"q_numDiff_u[eN_k] "<<q_numDiff_u.data()[eN_k]<<
" q_numDiff_u_last[eN_k] "<<q_numDiff_u_last.data()[eN_k]<<
" lag "<<lag_shockCapturingScale<<std::endl;
464 nu_sc = q_numDiff_u.data()[eN_k]*(1.0-lag_shockCapturingScale) + q_numDiff_u_last.data()[eN_k]*lag_shockCapturingScale;
469 double epsilon_background_diffusion = 2.0*epsFact_redist*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
470 if (fabs(phi_ls.data()[eN_k]) > epsilon_background_diffusion)
471 nu_sc += backgroundDiffusionFactor*elementDiameter.data()[eN];
474 for(
int i=0;i<nDOF_test_element;i++)
476 register int i_nSpace = i*nSpace;
477 double FREEZE=double(freezeLevelSet);
483 std::cout<<
"shock capturing input nu_sc "<<nu_sc<<
'\t'<<grad_u[0]<<
'\t'<<grad_u[1]<<
'\t'<<grad_u[1]<<
'\t'<<u_grad_test_dV[i_nSpace]<<std::endl;
487 circbc +=
ck.Reaction_weak(
gf.D(epsilon_redist,u0)*(
u-u0), u_test_dV[i]);
488 elementResidual_u[i] +=
ck.Mass_weak(m_t,u_test_dV[i]) +
489 ck.Hamiltonian_weak(
H,u_test_dV[i]) +
490 ck.Reaction_weak(
r,u_test_dV[i]) +
491 (1.0-FREEZE)*(weakDirichletFactor/h_phi)*
ck.Reaction_weak(
gf.D(epsilon_redist,u0)*(u0-
u),
493 ck.SubgridError(subgridError_u,Lstar_u[i]) +
494 ck.NumericalDiffusion(nu_sc,grad_u,&u_grad_test_dV[i_nSpace]);
496 std::cout<<
ck.Mass_weak(m_t,u_test_dV[i])<<
'\t'
497 <<
ck.Hamiltonian_weak(
H,u_test_dV[i]) <<
'\t'
498 <<
ck.Reaction_weak(
r,u_test_dV[i])<<
'\t'
499 <<
ck.SubgridError(subgridError_u,Lstar_u[i])<<
'\t'
500 <<
ck.NumericalDiffusion(nu_sc,grad_u,&u_grad_test_dV[i_nSpace])<<std::endl;
511 for (
int j = 0; j < nDOF_trial_element; j++)
513 const int eN_j = eN*nDOF_trial_element+j;
514 const int J = u_l2g.data()[eN_j];
516 if (fabs(u_weak_internal_bc_dofs.data()[J]) < epsilon_redist)
518 elementResidual_u[j] = (u_dof.data()[J]-u_weak_internal_bc_dofs.data()[J])*weakDirichletFactor*elementDiameter.data()[eN];
526 for(
int i=0;i<nDOF_test_element;i++)
528 register int eN_i=eN*nDOF_test_element+i;
531 std::cout<<
"element residual i = "<<i<<
"\t"<<elementResidual_u[i]<<std::endl;
533 globalResidual.data()[offset_u+stride_u*u_l2g.data()[eN_i]]+=elementResidual_u[i];
542 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
544 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
545 eN = elementBoundaryElementsArray.data()[ebN*2+0],
546 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
547 eN_nDOF_trial_element = eN*nDOF_trial_element;
548 double epsilon_redist, h_phi;
549 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
551 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
552 ebNE_kb_nSpace = ebNE_kb*nSpace,
553 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
554 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
555 register double u_ext=0.0,
557 jac_ext[nSpace*nSpace],
559 jacInv_ext[nSpace*nSpace],
560 boundaryJac[nSpace*(nSpace-1)],
561 metricTensor[(nSpace-1)*(nSpace-1)],
563 u_test_dS[nDOF_test_element],
564 u_grad_trial_trace[nDOF_trial_element*nSpace],
565 normal[nSpace],x_ext,y_ext,z_ext,
567 ck.calculateMapping_elementBoundary(eN,
573 mesh_trial_trace_ref.data(),
574 mesh_grad_trial_trace_ref.data(),
575 boundaryJac_ref.data(),
587 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
589 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);
590 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
592 for (
int I=0;I<nSpace;I++)
593 norm += grad_u_ext[I]*grad_u_ext[I];
595 for (
int I=0;I<nSpace;I++)
596 dir[I] = grad_u_ext[I]/norm;
598 ebqe_u.data()[ebNE_kb] = u_ext;
599 for (
int I=0;I<nSpace;I++)
600 ebqe_n.data()[ebNE_kb_nSpace+I] = dir[I];
612 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
613 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
614 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
615 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
616 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
617 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
618 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
619 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
620 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
621 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
622 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
623 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
624 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
625 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
626 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
627 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
628 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
629 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
630 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
631 int nElements_global = args.
scalar<
int>(
"nElements_global");
632 double useMetrics = args.
scalar<
double>(
"useMetrics");
633 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
634 double epsFact_redist = args.
scalar<
double>(
"epsFact_redist");
635 double backgroundDiffusionFactor = args.
scalar<
double>(
"backgroundDiffusionFactor");
636 double weakDirichletFactor = args.
scalar<
double>(
"weakDirichletFactor");
637 int freezeLevelSet = args.
scalar<
int>(
"freezeLevelSet");
638 int useTimeIntegration = args.
scalar<
int>(
"useTimeIntegration");
639 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
640 int lag_subgridError = args.
scalar<
int>(
"lag_subgridError");
641 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
642 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
643 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
644 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
645 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
646 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
647 xt::pyarray<double>& u_weak_internal_bc_dofs = args.
array<
double>(
"u_weak_internal_bc_dofs");
648 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
649 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
650 xt::pyarray<double>& q_dH_last = args.
array<
double>(
"q_dH_last");
651 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
652 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
653 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
654 xt::pyarray<int>& weakDirichletConditionFlags = args.
array<
int>(
"weakDirichletConditionFlags");
655 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
656 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
657 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
658 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
659 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
660 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
661 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
662 xt::pyarray<double>& ebqe_phi_ls_ext = args.
array<
double>(
"ebqe_phi_ls_ext");
663 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
664 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
665 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
666 int ELLIPTIC_REDISTANCING = args.
scalar<
int>(
"ELLIPTIC_REDISTANCING");
667 double backgroundDissipationEllipticRedist = args.
scalar<
double>(
"backgroundDissipationEllipticRedist");
668 double alpha = args.
scalar<
double>(
"alpha");
670 gf.useExact=useExact;
674 double timeIntegrationScale = 1.0;
675 if (useTimeIntegration == 0)
676 timeIntegrationScale = 0.0;
677 double lag_shockCapturingScale = 1.0;
678 if (lag_shockCapturing == 0)
679 lag_shockCapturingScale = 0.0;
680 for(
int eN=0;eN<nElements_global;eN++)
682 register int dummy_l2g[nDOF_mesh_trial_element];
683 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element],element_phi[nDOF_trial_element];
684 double epsilon_redist,h_phi, dir[nSpace], norm;
685 for (
int i=0;i<nDOF_test_element;i++)
687 register int eN_i=eN*nDOF_trial_element+i;
688 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]];
690 for (
int j=0;j<nDOF_trial_element;j++)
692 elementJacobian_u_u[i][j]=0.0;
695 double element_nodes[nDOF_mesh_trial_element*3];
696 for (
int i=0;i<nDOF_mesh_trial_element;i++)
698 register int eN_i=eN*nDOF_mesh_trial_element+i;
700 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
702 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
703 for (
int k=0;k<nQuadraturePoints_element;k++)
706 int eN_k = eN*nQuadraturePoints_element+k,
707 eN_k_nSpace = eN_k*nSpace,
708 eN_nDOF_trial_element = eN*nDOF_trial_element;
711 register double u=0.0,u0=0.0,
715 m_t=0.0,dm_t=0.0,
r=0.0,
718 dpdeResidual_u_u[nDOF_trial_element],
719 Lstar_u[nDOF_test_element],
720 dsubgridError_u_u[nDOF_trial_element],
721 tau=0.0,tau0=0.0,tau1=0.0,
725 jacInv[nSpace*nSpace],
726 u_grad_trial[nDOF_trial_element*nSpace],
728 u_test_dV[nDOF_test_element],
729 u_grad_test_dV[nDOF_test_element*nSpace],
731 G[nSpace*nSpace],G_dd_G,tr_G;
735 ck.calculateMapping_element(eN,
739 mesh_trial_ref.data(),
740 mesh_grad_trial_ref.data(),
745 ck.calculateH_element(eN,
747 nodeDiametersArray.data(),
749 mesh_trial_ref.data(),
752 dV = fabs(jacDet)*dV_ref.data()[k];
753 ck.calculateG(jacInv,G,G_dd_G,tr_G);
755 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
757 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
758 ck.valFromDOF(
gf.exact.phi_dof_corrected,dummy_l2g,&u_trial_ref.data()[k*nDOF_trial_element],u0);
760 u0 = phi_ls.data()[eN_k];
775 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
777 for (
int j=0;j<nDOF_trial_element;j++)
779 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
780 for (
int I=0;I<nSpace;I++)
782 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
797 epsilon_redist = epsFact_redist*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
811 for (
int I=0; I < nSpace; I++)
814 dH_strong[I] = dH[I];
816 if (lag_subgridError > 0)
818 for (
int I=0; I < nSpace; I++)
820 dH_tau[I] = q_dH_last.data()[eN_k_nSpace+I];
823 if (lag_subgridError > 1)
825 for (
int I=0; I < nSpace; I++)
827 dH_strong[I] = q_dH_last.data()[eN_k_nSpace+I];
838 q_m_betaBDF.data()[eN_k],
844 m *= timeIntegrationScale; dm *= timeIntegrationScale; m_t *= timeIntegrationScale;
845 dm_t *= timeIntegrationScale;
851 for (
int i=0;i<nDOF_test_element;i++)
854 int i_nSpace=i*nSpace;
856 Lstar_u[i]=
ck.Hamiltonian_adjoint(dH_strong,&u_grad_test_dV[i_nSpace]);
860 for (
int j=0;j<nDOF_trial_element;j++)
864 int j_nSpace = j*nSpace;
865 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j]) +
866 ck.HamiltonianJacobian_strong(dH_strong,&u_grad_trial[j_nSpace]);
879 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
881 for (
int j=0;j<nDOF_trial_element;j++)
882 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
884 nu_sc = q_numDiff_u.data()[eN_k]*(1.0-lag_shockCapturingScale) + q_numDiff_u_last.data()[eN_k]*lag_shockCapturingScale;
888 double epsilon_background_diffusion = 2.0*epsFact_redist*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
889 if (fabs(phi_ls.data()[eN_k]) > epsilon_background_diffusion)
890 nu_sc += backgroundDiffusionFactor*elementDiameter.data()[eN];
891 for(
int i=0;i<nDOF_test_element;i++)
895 circ +=
ck.Reaction_weak(
gf.D(epsilon_redist, phi_ls.data()[eN_k]), u_test_dV[i]);
896 for(
int j=0;j<nDOF_trial_element;j++)
900 int j_nSpace = j*nSpace;
901 int i_nSpace = i*nSpace;
902 double FREEZE=double(freezeLevelSet);
905 elementJacobian_u_u[i][j] +=
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]) +
906 ck.HamiltonianJacobian_weak(dH,&u_grad_trial[j_nSpace],u_test_dV[i]) +
907 (1.0-FREEZE)*(weakDirichletFactor/h_phi)*
ck.ReactionJacobian_weak(-
gf.D(epsilon_redist,u0),
908 u_trial_ref.data()[k*nDOF_trial_element+j],
910 ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
911 ck.NumericalDiffusionJacobian(nu_sc,&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]);
923 for (
int j = 0; j < nDOF_trial_element; j++)
925 const int J = u_l2g.data()[eN*nDOF_trial_element+j];
926 if (fabs(u_weak_internal_bc_dofs.data()[J]) < epsilon_redist)
930 for (
int jj=0; jj < nDOF_trial_element; jj++)
931 elementJacobian_u_u[j][jj] = 0.0;
932 elementJacobian_u_u[j][j] = weakDirichletFactor*elementDiameter.data()[eN];
936 for (
int i=0;i<nDOF_test_element;i++)
938 int eN_i = eN*nDOF_test_element+i;
939 for (
int j=0;j<nDOF_trial_element;j++)
941 int eN_i_j = eN_i*nDOF_trial_element+j;
943 std::cout<<
"element jacobian i = "<<i<<
"\t"<<
"j = "<<j<<
"\t"<<elementJacobian_u_u[i][j]<<std::endl;
945 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
1105 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1106 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1107 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1108 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1109 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1110 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1111 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1112 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1113 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1114 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1115 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1116 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1117 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1118 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1119 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1120 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1121 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1122 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1123 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1124 int nElements_global = args.
scalar<
int>(
"nElements_global");
1125 double useMetrics = args.
scalar<
double>(
"useMetrics");
1126 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1127 double epsFact_redist = args.
scalar<
double>(
"epsFact_redist");
1128 double backgroundDiffusionFactor = args.
scalar<
double>(
"backgroundDiffusionFactor");
1129 double weakDirichletFactor = args.
scalar<
double>(
"weakDirichletFactor");
1130 int freezeLevelSet = args.
scalar<
int>(
"freezeLevelSet");
1131 int useTimeIntegration = args.
scalar<
int>(
"useTimeIntegration");
1132 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1133 int lag_subgridError = args.
scalar<
int>(
"lag_subgridError");
1134 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1135 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1136 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1137 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1138 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1139 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
1140 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
1141 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
1142 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1143 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1144 xt::pyarray<double>& q_dH = args.
array<
double>(
"q_dH");
1145 xt::pyarray<double>& u_weak_internal_bc_dofs = args.
array<
double>(
"u_weak_internal_bc_dofs");
1146 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1147 xt::pyarray<double>& q_dH_last = args.
array<
double>(
"q_dH_last");
1148 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
1149 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1150 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1151 xt::pyarray<int>& weakDirichletConditionFlags = args.
array<
int>(
"weakDirichletConditionFlags");
1152 int offset_u = args.
scalar<
int>(
"offset_u");
1153 int stride_u = args.
scalar<
int>(
"stride_u");
1154 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1155 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1156 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1157 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1158 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1159 xt::pyarray<double>& ebqe_phi_ls_ext = args.
array<
double>(
"ebqe_phi_ls_ext");
1160 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1161 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1162 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1163 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
1164 int ELLIPTIC_REDISTANCING = args.
scalar<
int>(
"ELLIPTIC_REDISTANCING");
1165 double backgroundDissipationEllipticRedist = args.
scalar<
double>(
"backgroundDissipationEllipticRedist");
1166 xt::pyarray<double>& lumped_qx = args.
array<
double>(
"lumped_qx");
1167 xt::pyarray<double>& lumped_qy = args.
array<
double>(
"lumped_qy");
1168 xt::pyarray<double>& lumped_qz = args.
array<
double>(
"lumped_qz");
1169 double alpha = args.
scalar<
double>(
"alpha");
1170 gf.useExact=useExact;
1181 for(
int eN=0;eN<nElements_global;eN++)
1184 register double elementResidual_u[nDOF_test_element],element_phi[nDOF_trial_element];
1185 double epsilon_redist,h_phi, norm;
1186 for (
int i=0;i<nDOF_test_element;i++)
1188 register int eN_i=eN*nDOF_trial_element+i;
1189 elementResidual_u[i]=0.0;
1190 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]];
1192 double element_nodes[nDOF_mesh_trial_element*3];
1193 for (
int i=0;i<nDOF_mesh_trial_element;i++)
1195 register int eN_i=eN*nDOF_mesh_trial_element+i;
1196 for(
int I=0;I<3;I++)
1197 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
1199 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
1201 for (
int k=0;k<nQuadraturePoints_element;k++)
1205 register int eN_k = eN*nQuadraturePoints_element+k,
1206 eN_k_nSpace = eN_k*nSpace,
1207 eN_nDOF_trial_element = eN*nDOF_trial_element;
1213 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1214 u_grad_trial[nDOF_trial_element*nSpace],
1215 u_test_dV[nDOF_trial_element], u_grad_test_dV[nDOF_test_element*nSpace],
1216 dV,x,y,
z,G[nSpace*nSpace],G_dd_G,tr_G;
1217 ck.calculateMapping_element(eN,
1221 mesh_trial_ref.data(),
1222 mesh_grad_trial_ref.data(),
1227 ck.calculateH_element(eN,
1229 nodeDiametersArray.data(),
1231 mesh_trial_ref.data(),
1234 dV = fabs(jacDet)*dV_ref.data()[k];
1235 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1237 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],
1241 ck.valFromDOF(u_dof.data(),
1242 &u_l2g.data()[eN_nDOF_trial_element],
1243 &u_trial_ref.data()[k*nDOF_trial_element],
1246 ck.gradFromDOF(u_dof.data(),
1247 &u_l2g.data()[eN_nDOF_trial_element],
1250 if (ELLIPTIC_REDISTANCING > 1)
1252 ck.valFromDOF(lumped_qx.data(),
1253 &u_l2g.data()[eN_nDOF_trial_element],
1254 &u_trial_ref.data()[k*nDOF_trial_element],
1256 ck.valFromDOF(lumped_qy.data(),
1257 &u_l2g.data()[eN_nDOF_trial_element],
1258 &u_trial_ref.data()[k*nDOF_trial_element],
1260 ck.valFromDOF(lumped_qz.data(),
1261 &u_l2g.data()[eN_nDOF_trial_element],
1262 &u_trial_ref.data()[k*nDOF_trial_element],
1270 for (
int j=0;j<nDOF_trial_element;j++)
1272 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1273 for (
int I=0;I<nSpace;I++)
1274 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1278 double norm_grad_u = 0.;
1279 for (
int I=0;I<nSpace;I++)
1280 norm_grad_u += grad_u[I]*grad_u[I];
1281 norm_grad_u = std::sqrt(norm_grad_u) + 1.0E-10;
1284 q_m.data()[eN_k] =
u;
1285 q_u.data()[eN_k] =
u;
1286 for (
int I=0;I<nSpace;I++)
1287 q_n.data()[eN_k_nSpace+I] = grad_u[I]/norm_grad_u;
1291 coeff = 1.0-1.0/norm_grad_u;
1293 coeff = 1.0+2*std::pow(norm_grad_u,2)-3*norm_grad_u;
1296 epsilon_redist = epsFact_redist*(useMetrics*h_phi
1297 +(1.0-useMetrics)*elementDiameter.data()[eN]);
1298 delta =
gf.D(epsilon_redist,phi_ls.data()[eN_k]);
1301 double Si = -1.0+2.0*
gf.H(epsilon_redist,phi_ls.data()[eN_k]);
1302 double residualEikonal = Si*(norm_grad_u-1.0);
1303 double backgroundDissipation = backgroundDissipationEllipticRedist*elementDiameter.data()[eN];
1306 for(
int i=0;i<nDOF_test_element;i++)
1308 register int i_nSpace = i*nSpace;
1310 int gi = offset_u+stride_u*u_l2g.data()[eN*nDOF_test_element+i];
1312 if (ELLIPTIC_REDISTANCING > 1)
1314 elementResidual_u[i] +=
1315 residualEikonal*u_test_dV[i]
1316 +
ck.NumericalDiffusion(1.0+backgroundDissipation,
1318 &u_grad_test_dV[i_nSpace])
1319 -
ck.NumericalDiffusion(1.0,
1321 &u_grad_test_dV[i_nSpace])
1322 +alpha*(u_dof.data()[gi]-phi_dof.data()[gi])*delta*u_test_dV[i];
1326 elementResidual_u[i] +=
1327 residualEikonal*u_test_dV[i]
1328 +
ck.NumericalDiffusion(
coeff+backgroundDissipation,
1330 &u_grad_test_dV[i_nSpace])
1331 + alpha*(u_dof.data()[gi]-phi_dof.data()[gi])*delta*u_test_dV[i];
1338 for(
int i=0;i<nDOF_test_element;i++)
1340 register int eN_i=eN*nDOF_test_element+i;
1341 globalResidual.data()[offset_u+stride_u*u_l2g.data()[eN_i]]+=elementResidual_u[i];
1347 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1349 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
1350 eN = elementBoundaryElementsArray.data()[ebN*2+0],
1351 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
1352 eN_nDOF_trial_element = eN*nDOF_trial_element;
1353 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1355 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1356 ebNE_kb_nSpace = ebNE_kb*nSpace,
1357 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1358 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1362 jac_ext[nSpace*nSpace],jacDet_ext,jacInv_ext[nSpace*nSpace],
1363 boundaryJac[nSpace*(nSpace-1)],
1364 metricTensor[(nSpace-1)*(nSpace-1)],metricTensorDetSqrt,
1365 u_grad_trial_trace[nDOF_trial_element*nSpace],
1366 normal[nSpace],x_ext,y_ext,z_ext,
1368 ck.calculateMapping_elementBoundary(eN,
1374 mesh_trial_trace_ref.data(),
1375 mesh_grad_trial_trace_ref.data(),
1376 boundaryJac_ref.data(),
1382 metricTensorDetSqrt,
1388 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],
1390 u_grad_trial_trace);
1392 ck.valFromDOF(u_dof.data(),
1393 &u_l2g.data()[eN_nDOF_trial_element],
1394 &u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],
1396 ck.gradFromDOF(u_dof.data(),
1397 &u_l2g.data()[eN_nDOF_trial_element],
1401 for (
int I=0;I<nSpace;I++)
1402 norm += grad_u_ext[I]*grad_u_ext[I];
1403 norm = sqrt(norm) + 1.0E-10;
1404 for (
int I=0;I<nSpace;I++)
1405 dir[I] = grad_u_ext[I]/norm;
1408 ebqe_u.data()[ebNE_kb] = u_ext;
1410 for (
int I=0;I<nSpace;I++)
1411 ebqe_n.data()[ebNE_kb_nSpace+I] = dir[I];
1419 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1420 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1421 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1422 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1423 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1424 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1425 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1426 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1427 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1428 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1429 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1430 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1431 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1432 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1433 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1434 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1435 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1436 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1437 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1438 int nElements_global = args.
scalar<
int>(
"nElements_global");
1439 double useMetrics = args.
scalar<
double>(
"useMetrics");
1440 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1441 double epsFact_redist = args.
scalar<
double>(
"epsFact_redist");
1442 double backgroundDiffusionFactor = args.
scalar<
double>(
"backgroundDiffusionFactor");
1443 double weakDirichletFactor = args.
scalar<
double>(
"weakDirichletFactor");
1444 int freezeLevelSet = args.
scalar<
int>(
"freezeLevelSet");
1445 int useTimeIntegration = args.
scalar<
int>(
"useTimeIntegration");
1446 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1447 int lag_subgridError = args.
scalar<
int>(
"lag_subgridError");
1448 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1449 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1450 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1451 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1452 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1453 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
1454 xt::pyarray<double>& u_weak_internal_bc_dofs = args.
array<
double>(
"u_weak_internal_bc_dofs");
1455 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
1456 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1457 xt::pyarray<double>& q_dH_last = args.
array<
double>(
"q_dH_last");
1458 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
1459 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1460 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1461 xt::pyarray<int>& weakDirichletConditionFlags = args.
array<
int>(
"weakDirichletConditionFlags");
1462 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
1463 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
1464 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
1465 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1466 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1467 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1468 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1469 xt::pyarray<double>& ebqe_phi_ls_ext = args.
array<
double>(
"ebqe_phi_ls_ext");
1470 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1471 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1472 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
1473 int ELLIPTIC_REDISTANCING = args.
scalar<
int>(
"ELLIPTIC_REDISTANCING");
1474 double backgroundDissipationEllipticRedist = args.
scalar<
double>(
"backgroundDissipationEllipticRedist");
1475 double alpha = args.
scalar<
double>(
"alpha");
1476 gf.useExact=useExact;
1480 for(
int eN=0;eN<nElements_global;eN++)
1482 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element],element_phi[nDOF_trial_element];
1483 double epsilon_redist,h_phi, norm;
1484 for (
int i=0;i<nDOF_test_element;i++)
1486 register int eN_i=eN*nDOF_trial_element+i;
1487 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]];
1488 for (
int j=0;j<nDOF_trial_element;j++)
1490 elementJacobian_u_u[i][j]=0.0;
1493 double element_nodes[nDOF_mesh_trial_element*3];
1494 for (
int i=0;i<nDOF_mesh_trial_element;i++)
1496 register int eN_i=eN*nDOF_mesh_trial_element+i;
1497 for(
int I=0;I<3;I++)
1498 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
1500 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
1501 for (
int k=0;k<nQuadraturePoints_element;k++)
1504 int eN_k = eN*nQuadraturePoints_element+k,
1505 eN_k_nSpace = eN_k*nSpace,
1506 eN_nDOF_trial_element = eN*nDOF_trial_element;
1510 coeff1, coeff2, delta,
1512 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1513 u_grad_trial[nDOF_trial_element*nSpace],
1514 dV, u_test_dV[nDOF_test_element], u_grad_test_dV[nDOF_test_element*nSpace],
1515 x,y,
z,G[nSpace*nSpace],G_dd_G,tr_G;
1519 ck.calculateMapping_element(eN,
1523 mesh_trial_ref.data(),
1524 mesh_grad_trial_ref.data(),
1529 ck.calculateH_element(eN,
1531 nodeDiametersArray.data(),
1533 mesh_trial_ref.data(),
1536 dV = fabs(jacDet)*dV_ref.data()[k];
1537 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1539 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],
1543 ck.gradFromDOF(u_dof.data(),
1544 &u_l2g.data()[eN_nDOF_trial_element],
1548 for (
int j=0;j<nDOF_trial_element;j++)
1550 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1551 for (
int I=0;I<nSpace;I++)
1552 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1556 double norm_grad_u = 0;
1557 for(
int I=0;I<nSpace;I++)
1558 norm_grad_u += grad_u[I]*grad_u[I];
1559 norm_grad_u = std::sqrt(norm_grad_u) + 1.0E-10;
1565 coeff2 = 1./std::pow(norm_grad_u,3);
1569 coeff1 = fmax(1.0E-10, 2*std::pow(norm_grad_u,2)-3*norm_grad_u);
1570 coeff2 = fmax(1.0E-10, 4.-3./norm_grad_u);
1574 epsilon_redist = epsFact_redist*(useMetrics*h_phi
1575 +(1.0-useMetrics)*elementDiameter.data()[eN]);
1576 delta =
gf.D(epsilon_redist,phi_ls.data()[eN_k]);
1579 double Si = -1.0+2.0*
gf.H(epsilon_redist,phi_ls.data()[eN_k]);
1581 for (
int I=0; I<nSpace;I++)
1582 dH[I] = Si*grad_u[I]/norm_grad_u;
1583 double backgroundDissipation = backgroundDissipationEllipticRedist*elementDiameter.data()[eN];
1586 for(
int i=0;i<nDOF_test_element;i++)
1588 int i_nSpace = i*nSpace;
1589 for(
int j=0;j<nDOF_trial_element;j++)
1591 int j_nSpace = j*nSpace;
1592 elementJacobian_u_u[i][j] +=
1593 ck.HamiltonianJacobian_weak(dH,&u_grad_trial[j_nSpace],u_test_dV[i])
1594 +
ck.NumericalDiffusionJacobian(1.0+backgroundDissipation,
1595 &u_grad_trial[j_nSpace],
1596 &u_grad_test_dV[i_nSpace])
1597 + (ELLIPTIC_REDISTANCING == 1 ? 1. : 0.)*
1598 (
ck.NumericalDiffusionJacobian(coeff1,
1599 &u_grad_trial[j_nSpace],
1600 &u_grad_test_dV[i_nSpace])
1602 ck.NumericalDiffusion(1.0,grad_u,&u_grad_trial[i_nSpace])*
1603 ck.NumericalDiffusion(1.0,grad_u,&u_grad_trial[j_nSpace]) )
1604 + (i == j ? alpha*delta*u_test_dV[i] : 0.);
1611 for (
int i=0;i<nDOF_test_element;i++)
1613 int eN_i = eN*nDOF_test_element+i;
1614 for (
int j=0;j<nDOF_trial_element;j++)
1616 int eN_i_j = eN_i*nDOF_trial_element+j;
1617 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i]
1618 + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
1626 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1627 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1628 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1629 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1630 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1631 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1632 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1633 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1634 int nElements_global = args.
scalar<
int>(
"nElements_global");
1635 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1636 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1637 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1638 int offset_u = args.
scalar<
int>(
"offset_u");
1639 int stride_u = args.
scalar<
int>(
"stride_u");
1640 int numDOFs = args.
scalar<
int>(
"numDOFs");
1641 xt::pyarray<double>& lumped_qx = args.
array<
double>(
"lumped_qx");
1642 xt::pyarray<double>& lumped_qy = args.
array<
double>(
"lumped_qy");
1643 xt::pyarray<double>& lumped_qz = args.
array<
double>(
"lumped_qz");
1645 for (
int i=0; i<numDOFs; i++)
1648 lumped_qx.data()[i]=0.;
1649 lumped_qy.data()[i]=0.;
1650 lumped_qz.data()[i]=0.;
1654 for(
int eN=0;eN<nElements_global;eN++)
1658 element_weighted_lumped_mass_matrix[nDOF_test_element],
1659 element_rhsx_normal_reconstruction[nDOF_test_element],
1660 element_rhsy_normal_reconstruction[nDOF_test_element],
1661 element_rhsz_normal_reconstruction[nDOF_test_element];
1662 for (
int i=0;i<nDOF_test_element;i++)
1664 element_weighted_lumped_mass_matrix[i]=0.0;
1665 element_rhsx_normal_reconstruction[i]=0.0;
1666 element_rhsy_normal_reconstruction[i]=0.0;
1667 element_rhsz_normal_reconstruction[i]=0.0;
1670 for (
int k=0;k<nQuadraturePoints_element;k++)
1673 register int eN_k = eN*nQuadraturePoints_element+k,
1674 eN_k_nSpace = eN_k*nSpace,
1675 eN_nDOF_trial_element = eN*nDOF_trial_element;
1679 u_grad_trial[nDOF_trial_element*nSpace],
1680 u_test_dV[nDOF_trial_element],
1682 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1685 ck.calculateMapping_element(eN,
1689 mesh_trial_ref.data(),
1690 mesh_grad_trial_ref.data(),
1695 dV = fabs(jacDet)*dV_ref.data()[k];
1696 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],
1699 ck.gradFromDOF(u_dof.data(),
1700 &u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,
1703 for (
int j=0;j<nDOF_trial_element;j++)
1704 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
1706 double rhsx = grad_u[0];
1707 double rhsy = grad_u[1];
1712 double norm_grad_u = 0;
1713 for (
int I=0;I<nSpace; I++)
1714 norm_grad_u += grad_u[I]*grad_u[I];
1715 norm_grad_u = std::sqrt(norm_grad_u) + 1.0E-10;
1717 for(
int i=0;i<nDOF_test_element;i++)
1719 element_weighted_lumped_mass_matrix[i] += norm_grad_u*u_test_dV[i];
1720 element_rhsx_normal_reconstruction[i] += rhsx*u_test_dV[i];
1721 element_rhsy_normal_reconstruction[i] += rhsy*u_test_dV[i];
1722 element_rhsz_normal_reconstruction[i] += rhsz*u_test_dV[i];
1726 for(
int i=0;i<nDOF_test_element;i++)
1728 int eN_i=eN*nDOF_test_element+i;
1729 int gi = offset_u+stride_u*u_l2g.data()[eN_i];
1732 lumped_qx.data()[gi] += element_rhsx_normal_reconstruction[i];
1733 lumped_qy.data()[gi] += element_rhsy_normal_reconstruction[i];
1734 lumped_qz.data()[gi] += element_rhsz_normal_reconstruction[i];
1738 for (
int i=0; i<numDOFs; i++)
1742 lumped_qx.data()[i] /= weighted_mi;
1743 lumped_qy.data()[i] /= weighted_mi;
1744 lumped_qz.data()[i] /= weighted_mi;
1750 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1751 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1752 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1753 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1754 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1755 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1756 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1757 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1758 int nElements_global = args.
scalar<
int>(
"nElements_global");
1759 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1760 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1761 double degree_polynomial = args.
scalar<
double>(
"degree_polynomial");
1762 double epsFact_redist = args.
scalar<
double>(
"epsFact_redist");
1763 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1764 xt::pyarray<double>& u_exact = args.
array<
double>(
"u_exact");
1765 int offset_u = args.
scalar<
int>(
"offset_u");
1766 int stride_u = args.
scalar<
int>(
"stride_u)");
1767 double global_V = 0.;
1768 double global_V0 = 0.;
1769 double global_I_err = 0.0;
1770 double global_V_err = 0.0;
1771 double global_D_err = 0.0;
1775 for(
int eN=0;eN<nElements_global;eN++)
1779 elementResidual_u[nDOF_test_element];
1781 cell_mass_error = 0., cell_mass_exact = 0.,
1783 cell_V = 0., cell_V0 = 0.,
1787 for (
int k=0;k<nQuadraturePoints_element;k++)
1790 register int eN_k = eN*nQuadraturePoints_element+k,
1791 eN_k_nSpace = eN_k*nSpace,
1792 eN_nDOF_trial_element = eN*nDOF_trial_element;
1795 u_grad_trial[nDOF_trial_element*nSpace],
1798 jac[nSpace*nSpace], jacDet, jacInv[nSpace*nSpace],
1801 ck.calculateMapping_element(eN,
1805 mesh_trial_ref.data(),
1806 mesh_grad_trial_ref.data(),
1811 dV = fabs(jacDet)*dV_ref.data()[k];
1813 ck.valFromDOF(u_dof.data(),
1814 &u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
1816 u = u_exact.data()[eN_k];
1818 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],
1821 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_uh);
1823 double epsHeaviside = epsFact_redist*elementDiameter.data()[eN]/degree_polynomial;
1828 cell_I_err += fabs(Hu - Huh)*dV;
1832 double norm2_grad_uh = 0.;
1833 for (
int I=0; I<nSpace; I++)
1834 norm2_grad_uh += grad_uh[I]*grad_uh[I];
1835 cell_D_err += std::pow(std::sqrt(norm2_grad_uh) - 1, 2.)*dV;
1838 global_V0 += cell_V0;
1840 global_I_err += cell_I_err;
1841 global_D_err += cell_D_err;
1843 global_V_err = fabs(global_V0 - global_V)/global_V0;
1844 global_D_err *= 0.5;
1845 return std::tuple<double, double, double>(global_I_err, global_V_err, global_D_err);
1850 int nQuadraturePoints_elementIn,
1851 int nDOF_mesh_trial_elementIn,
1852 int nDOF_trial_elementIn,
1853 int nDOF_test_elementIn,
1854 int nQuadraturePoints_elementBoundaryIn,
1858 return proteus::chooseAndAllocateDiscretization2D<RDLS_base,RDLS,CompKernel>(nSpaceIn,
1859 nQuadraturePoints_elementIn,
1860 nDOF_mesh_trial_elementIn,
1861 nDOF_trial_elementIn,
1862 nDOF_test_elementIn,
1863 nQuadraturePoints_elementBoundaryIn,
1866 return proteus::chooseAndAllocateDiscretization<RDLS_base,RDLS,CompKernel>(nSpaceIn,
1867 nQuadraturePoints_elementIn,
1868 nDOF_mesh_trial_elementIn,
1869 nDOF_trial_elementIn,
1870 nDOF_test_elementIn,
1871 nQuadraturePoints_elementBoundaryIn,