9 #include PROTEUS_LAPACK_H
11 #include "xtensor-python/pyarray.hpp"
13 namespace py = pybind11;
18 template<
int nSpace,
int nP,
int nQ,
int nEBQ>
42 template<
class CompKernelType,
44 int nQuadraturePoints_element,
45 int nDOF_mesh_trial_element,
46 int nDOF_trial_element,
47 int nDOF_test_element,
48 int nQuadraturePoints_elementBoundary>
60 const double& epsDirac,
64 const double& porosity,
68 r = porosity*(
gf.H(epsHeaviside,
phi+
u) -
H);
69 dr = porosity*
gf.D(epsDirac,
phi+
u);
73 double* mesh_trial_ref,
74 double* mesh_grad_trial_ref,
79 double* u_grad_trial_ref,
81 double* u_grad_test_ref,
83 double* mesh_trial_trace_ref,
84 double* mesh_grad_trial_trace_ref,
86 double* u_trial_trace_ref,
87 double* u_grad_trial_trace_ref,
88 double* u_test_trace_ref,
89 double* u_grad_test_trace_ref,
91 double* boundaryJac_ref,
95 double epsFactHeaviside,
97 double epsFactDiffusion,
99 double* elementDiameter,
100 double* nodeDiametersArray,
103 double* q_normal_phi,
105 double* ebqe_normal_phi,
113 int offset_u,
int stride_u,
114 double* elementResidual_u,
115 int nExteriorElementBoundaries_global,
116 int* exteriorElementBoundariesArray,
117 int* elementBoundaryElementsArray,
118 int* elementBoundaryLocalElementBoundariesArray,
122 for (
int i=0;i<nDOF_test_element;i++)
124 elementResidual_u[i]=0.0;
126 double epsHeaviside,epsDirac,epsDiffusion,norm;
128 for (
int k=0;k<nQuadraturePoints_element;k++)
131 register int eN_k = eN*nQuadraturePoints_element+k,
132 eN_k_nSpace = eN_k*nSpace;
134 register double u=0.0,grad_u[nSpace],
138 jacInv[nSpace*nSpace],
139 u_grad_trial[nDOF_trial_element*nSpace],
140 u_test_dV[nDOF_trial_element],
141 u_grad_test_dV[nDOF_test_element*nSpace],
143 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
148 ck.calculateMapping_element(eN,
158 ck.calculateH_element(eN,
165 dV = fabs(jacDet)*dV_ref[k];
166 ck.calculateG(jacInv,G,G_dd_G,tr_G);
178 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
180 ck.valFromElementDOF(element_u,&u_trial_ref[k*nDOF_trial_element],
u);
182 ck.gradFromElementDOF(element_u,u_grad_trial,grad_u);
184 for (
int j=0;j<nDOF_trial_element;j++)
186 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
187 for (
int I=0;I<nSpace;I++)
189 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
198 epsHeaviside = epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
199 epsDirac = epsFactDirac* (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
200 epsDiffusion = epsFactDiffusion*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
213 for(
int i=0;i<nDOF_test_element;i++)
217 register int i_nSpace=i*nSpace;
219 elementResidual_u[i] +=
ck.Reaction_weak(
r,u_test_dV[i]) +
220 ck.NumericalDiffusion(epsDiffusion,grad_u,&u_grad_test_dV[i_nSpace]);
232 for (
int I=0;I<nSpace;I++)
233 norm += grad_u[I]*grad_u[I];
235 for(
int I=0;I<nSpace;I++)
236 q_n[eN_k_nSpace+I] = grad_u[I]/norm;
242 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
243 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
244 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
245 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
246 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
247 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
248 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
249 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
250 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
251 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
252 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
253 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
254 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
255 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
256 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
257 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
258 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
259 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
260 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
261 int nElements_global = args.
scalar<
int>(
"nElements_global");
262 double useMetrics = args.
scalar<
double>(
"useMetrics");
263 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
264 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
265 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
266 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
267 xt::pyarray<int>& r_l2g = args.
array<
int>(
"r_l2g");
268 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
269 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
270 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
271 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
272 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
273 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
274 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
275 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
276 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
277 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
278 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
279 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
280 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
281 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
282 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
283 int offset_u = args.
scalar<
int>(
"offset_u");
284 int stride_u = args.
scalar<
int>(
"stride_u");
285 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
286 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
287 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
288 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
289 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
300 gf.useExact = useExact;
301 for(
int eN=0;eN<nElements_global;eN++)
304 register double elementResidual_u[nDOF_test_element],element_u[nDOF_trial_element],element_phi[nDOF_trial_element];
305 for (
int i=0;i<nDOF_test_element;i++)
307 register int eN_i=eN*nDOF_test_element+i;
308 element_u[i] = u_dof.data()[u_l2g.data()[eN_i]];
309 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]] + element_u[i];
311 double element_nodes[nDOF_mesh_trial_element*3];
312 for (
int i=0;i<nDOF_mesh_trial_element;i++)
314 register int eN_i=eN*nDOF_mesh_trial_element+i;
316 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
318 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
320 mesh_grad_trial_ref.data(),
325 u_grad_trial_ref.data(),
327 u_grad_test_ref.data(),
328 mesh_trial_trace_ref.data(),
329 mesh_grad_trial_trace_ref.data(),
331 u_trial_trace_ref.data(),
332 u_grad_trial_trace_ref.data(),
333 u_test_trace_ref.data(),
334 u_grad_test_trace_ref.data(),
336 boundaryJac_ref.data(),
343 elementDiameter.data(),
344 nodeDiametersArray.data(),
349 ebqe_normal_phi.data(),
359 nExteriorElementBoundaries_global,
360 exteriorElementBoundariesArray.data(),
361 elementBoundaryElementsArray.data(),
362 elementBoundaryLocalElementBoundariesArray.data(),
368 for(
int i=0;i<nDOF_test_element;i++)
370 register int eN_i=eN*nDOF_test_element+i;
372 globalResidual.data()[offset_u+stride_u*r_l2g.data()[eN_i]]+=elementResidual_u[i];
381 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
383 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
384 eN = elementBoundaryElementsArray.data()[ebN*2+0],
385 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0];
388 double element_u[nDOF_trial_element];
389 for (
int i=0;i<nDOF_test_element;i++)
391 register int eN_i=eN*nDOF_test_element+i;
392 element_u[i] = u_dof.data()[u_l2g.data()[eN_i]];
394 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
396 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
397 ebNE_kb_nSpace = ebNE_kb*nSpace,
398 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
399 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
400 register double u_ext=0.0,
413 jac_ext[nSpace*nSpace],
415 jacInv_ext[nSpace*nSpace],
416 boundaryJac[nSpace*(nSpace-1)],
417 metricTensor[(nSpace-1)*(nSpace-1)],
421 u_grad_trial_trace[nDOF_trial_element*nSpace],
422 normal[nSpace],x_ext,y_ext,z_ext,
423 G[nSpace*nSpace],G_dd_G,tr_G,norm;
427 ck.calculateMapping_elementBoundary(eN,
433 mesh_trial_trace_ref.data(),
434 mesh_grad_trial_trace_ref.data(),
435 boundaryJac_ref.data(),
445 dS = metricTensorDetSqrt*dS_ref.data()[kb];
448 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
451 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
453 ck.valFromElementDOF(element_u,&u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],u_ext);
454 ck.gradFromElementDOF(element_u,u_grad_trial_trace,grad_u_ext);
456 ebqe_u.data()[ebNE_kb] = u_ext;
458 for (
int I=0;I<nSpace;I++)
459 norm += grad_u_ext[I]*grad_u_ext[I];
461 for (
int I=0;I<nSpace;I++)
462 ebqe_n.data()[ebNE_kb_nSpace+I] = grad_u_ext[I]/norm;
468 double* mesh_trial_ref,
469 double* mesh_grad_trial_ref,
474 double* u_grad_trial_ref,
476 double* u_grad_test_ref,
478 double* mesh_trial_trace_ref,
479 double* mesh_grad_trial_trace_ref,
481 double* u_trial_trace_ref,
482 double* u_grad_trial_trace_ref,
483 double* u_test_trace_ref,
484 double* u_grad_test_trace_ref,
486 double* boundaryJac_ref,
488 int nElements_global,
490 double epsFactHeaviside,
492 double epsFactDiffusion,
494 double* elementDiameter,
495 double* nodeDiametersArray,
502 double* q_normal_phi,
505 double* elementJacobian_u_u,
509 for (
int i=0;i<nDOF_test_element;i++)
510 for (
int j=0;j<nDOF_trial_element;j++)
512 elementJacobian_u_u[i*nDOF_trial_element+j]=0.0;
514 double epsHeaviside,epsDirac,epsDiffusion;
515 for (
int k=0;k<nQuadraturePoints_element;k++)
517 int eN_k = eN*nQuadraturePoints_element+k,
518 eN_k_nSpace = eN_k*nSpace;
522 register double u=0.0,
527 jacInv[nSpace*nSpace],
528 u_grad_trial[nDOF_trial_element*nSpace],
530 u_test_dV[nDOF_test_element],
531 u_grad_test_dV[nDOF_test_element*nSpace],
533 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
537 ck.calculateMapping_element(eN,
547 ck.calculateH_element(eN,
554 dV = fabs(jacDet)*dV_ref[k];
555 ck.calculateG(jacInv,G,G_dd_G,tr_G);
568 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
570 ck.valFromElementDOF(element_u,&u_trial_ref[k*nDOF_trial_element],
u);
572 ck.gradFromElementDOF(element_u,u_grad_trial,grad_u);
574 for (
int j=0;j<nDOF_trial_element;j++)
576 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
577 for (
int I=0;I<nSpace;I++)
579 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
585 epsHeaviside=epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
586 epsDirac =epsFactDirac* (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
587 epsDiffusion=epsFactDiffusion*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
597 for(
int i=0;i<nDOF_test_element;i++)
601 int i_nSpace=i*nSpace;
602 for(
int j=0;j<nDOF_trial_element;j++)
606 int j_nSpace = j*nSpace;
607 elementJacobian_u_u[i*nDOF_trial_element+j] +=
608 ck.ReactionJacobian_weak(dr,u_trial_ref[k*nDOF_trial_element+j],u_test_dV[i]) +
609 ck.NumericalDiffusionJacobian(epsDiffusion,&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]);
618 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
619 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
620 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
621 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
622 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
623 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
624 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
625 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
626 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
627 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
628 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
629 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
630 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
631 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
632 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
633 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
634 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
635 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
636 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
637 int nElements_global = args.
scalar<
int>(
"nElements_global");
638 double useMetrics = args.
scalar<
double>(
"useMetrics");
639 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
640 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
641 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
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>& q_phi = args.
array<
double>(
"q_phi");
648 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
649 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
650 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
651 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
652 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
653 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
657 gf.useExact = useExact;
658 for(
int eN=0;eN<nElements_global;eN++)
660 register double elementJacobian_u_u[nDOF_test_element*nDOF_trial_element],element_u[nDOF_trial_element],element_phi[nDOF_trial_element];
661 for (
int j=0;j<nDOF_trial_element;j++)
663 register int eN_j = eN*nDOF_trial_element+j;
664 element_u[j] = u_dof.data()[u_l2g.data()[eN_j]];
665 element_phi[j] = phi_dof.data()[u_l2g.data()[eN_j]] + element_u[j];
667 double element_nodes[nDOF_mesh_trial_element*3];
668 for (
int i=0;i<nDOF_mesh_trial_element;i++)
670 register int eN_i=eN*nDOF_mesh_trial_element+i;
672 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
674 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
676 mesh_grad_trial_ref.data(),
681 u_grad_trial_ref.data(),
683 u_grad_test_ref.data(),
684 mesh_trial_trace_ref.data(),
685 mesh_grad_trial_trace_ref.data(),
687 u_trial_trace_ref.data(),
688 u_grad_trial_trace_ref.data(),
689 u_test_trace_ref.data(),
690 u_grad_test_trace_ref.data(),
692 boundaryJac_ref.data(),
699 elementDiameter.data(),
700 nodeDiametersArray.data(),
712 for (
int i=0;i<nDOF_test_element;i++)
714 int eN_i = eN*nDOF_test_element+i;
715 for (
int j=0;j<nDOF_trial_element;j++)
717 int eN_i_j = eN_i*nDOF_trial_element+j;
719 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i*nDOF_trial_element+j];
726 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
727 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
728 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
729 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
730 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
731 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
732 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
733 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
734 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
735 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
736 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
737 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
738 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
739 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
740 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
741 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
742 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
743 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
744 int nElements_global = args.
scalar<
int>(
"nElements_global");
745 double useMetrics = args.
scalar<
double>(
"useMetrics");
746 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
747 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
748 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
749 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
750 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
751 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
752 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
753 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
754 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
755 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
756 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
757 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
758 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
759 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
760 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
761 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
762 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
763 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
764 int offset_u = args.
scalar<
int>(
"offset_u");
765 int stride_u = args.
scalar<
int>(
"stride_u");
766 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
767 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
768 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
769 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
770 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
771 int maxIts = args.
scalar<
int>(
"maxIts");
772 double atol = args.
scalar<
double>(
"atol");
783 for(
int eN=0;eN<nElements_global;eN++)
786 register double element_u[nDOF_test_element],
787 element_du[nDOF_test_element],
788 elementResidual_u[nDOF_test_element],
789 elementJacobian_u_u[nDOF_test_element*nDOF_trial_element],scale=1.0;
790 register PROTEUS_LAPACK_INTEGER elementPivots[nDOF_test_element],
791 elementColPivots[nDOF_test_element];
793 for (
int i=0;i<nDOF_test_element;i++)
798 mesh_grad_trial_ref.data(),
803 u_grad_trial_ref.data(),
805 u_grad_test_ref.data(),
806 mesh_trial_trace_ref.data(),
807 mesh_grad_trial_trace_ref.data(),
809 u_trial_trace_ref.data(),
810 u_grad_trial_trace_ref.data(),
811 u_test_trace_ref.data(),
812 u_grad_test_trace_ref.data(),
814 boundaryJac_ref.data(),
821 elementDiameter.data(),
822 nodeDiametersArray.data(),
827 ebqe_normal_phi.data(),
837 nExteriorElementBoundaries_global,
838 exteriorElementBoundariesArray.data(),
839 elementBoundaryElementsArray.data(),
840 elementBoundaryLocalElementBoundariesArray.data(),
845 for (
int i=0;i<nDOF_test_element;i++)
847 resNorm += elementResidual_u[i];
849 resNorm = fabs(resNorm);
854 while (resNorm >= atol && its < maxIts)
858 mesh_grad_trial_ref.data(),
863 u_grad_trial_ref.data(),
865 u_grad_test_ref.data(),
866 mesh_trial_trace_ref.data(),
867 mesh_grad_trial_trace_ref.data(),
869 u_trial_trace_ref.data(),
870 u_grad_trial_trace_ref.data(),
871 u_test_trace_ref.data(),
872 u_grad_test_trace_ref.data(),
874 boundaryJac_ref.data(),
881 elementDiameter.data(),
882 nodeDiametersArray.data(),
891 for (
int i=0;i<nDOF_test_element;i++)
893 element_du[i] = -elementResidual_u[i];
894 elementPivots[i] = ((PROTEUS_LAPACK_INTEGER)0);
895 elementColPivots[i]=((PROTEUS_LAPACK_INTEGER)0);
904 PROTEUS_LAPACK_INTEGER La_N=((PROTEUS_LAPACK_INTEGER)nDOF_test_element),
920 double resNormNew = resNorm,lambda=1.0;
922 while (resNormNew > 0.99*resNorm && lsIts < 100)
925 for (
int i=0;i<nDOF_test_element;i++)
927 element_u[i] += lambda*element_du[i];
932 mesh_grad_trial_ref.data(),
937 u_grad_trial_ref.data(),
939 u_grad_test_ref.data(),
940 mesh_trial_trace_ref.data(),
941 mesh_grad_trial_trace_ref.data(),
943 u_trial_trace_ref.data(),
944 u_grad_trial_trace_ref.data(),
945 u_test_trace_ref.data(),
946 u_grad_test_trace_ref.data(),
948 boundaryJac_ref.data(),
955 elementDiameter.data(),
956 nodeDiametersArray.data(),
961 ebqe_normal_phi.data(),
971 nExteriorElementBoundaries_global,
972 exteriorElementBoundariesArray.data(),
973 elementBoundaryElementsArray.data(),
974 elementBoundaryLocalElementBoundariesArray.data(),
980 for (
int i=0;i<nDOF_test_element;i++)
982 resNormNew += elementResidual_u[i];
983 std::cout<<
"element_u["<<i<<
"] "<<element_u[i]<<std::endl;
984 std::cout<<
"elementResidual_u["<<i<<
"] "<<elementResidual_u[i]<<std::endl;
986 resNormNew = fabs(resNormNew);
988 resNorm = resNormNew;
989 std::cout<<
"INFO "<<INFO<<std::endl;
990 std::cout<<
"resNorm["<<its<<
"] "<<resNorm<<std::endl;
996 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
997 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
998 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
999 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1000 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1001 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1002 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1003 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1004 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1005 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1006 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1007 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1008 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1009 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1010 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1011 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1012 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1013 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1014 int nElements_global = args.
scalar<
int>(
"nElements_global");
1015 double useMetrics = args.
scalar<
double>(
"useMetrics");
1016 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1017 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1018 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1019 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1020 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1021 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1022 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1023 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1024 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1025 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1026 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
1027 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
1028 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1029 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1030 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1031 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
1032 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
1033 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1034 int offset_u = args.
scalar<
int>(
"offset_u");
1035 int stride_u = args.
scalar<
int>(
"stride_u");
1036 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1037 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1038 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1039 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1040 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1041 int maxIts = args.
scalar<
int>(
"maxIts");
1042 double atol = args.
scalar<
double>(
"atol");
1043 for(
int eN=0;eN<nElements_global;eN++)
1046 register double element_u[nDOF_test_element],elementConstant_u,
1047 elementResidual_u[nDOF_test_element],elementConstantResidual,
1048 elementJacobian_u_u[nDOF_test_element*nDOF_trial_element],elementConstantJacobian,resNorm;
1049 elementConstant_u=0.0;
1050 for (
int i=0;i<nDOF_test_element;i++)
1052 element_u[i]=elementConstant_u;
1055 mesh_grad_trial_ref.data(),
1060 u_grad_trial_ref.data(),
1062 u_grad_test_ref.data(),
1063 mesh_trial_trace_ref.data(),
1064 mesh_grad_trial_trace_ref.data(),
1066 u_trial_trace_ref.data(),
1067 u_grad_trial_trace_ref.data(),
1068 u_test_trace_ref.data(),
1069 u_grad_test_trace_ref.data(),
1071 boundaryJac_ref.data(),
1078 elementDiameter.data(),
1079 nodeDiametersArray.data(),
1082 q_normal_phi.data(),
1084 ebqe_normal_phi.data(),
1094 nExteriorElementBoundaries_global,
1095 exteriorElementBoundariesArray.data(),
1096 elementBoundaryElementsArray.data(),
1097 elementBoundaryLocalElementBoundariesArray.data(),
1101 elementConstantResidual=0.0;
1102 for (
int i=0;i<nDOF_test_element;i++)
1104 elementConstantResidual += elementResidual_u[i];
1106 resNorm = fabs(elementConstantResidual);
1111 while (resNorm >= atol && its < maxIts)
1115 mesh_grad_trial_ref.data(),
1120 u_grad_trial_ref.data(),
1122 u_grad_test_ref.data(),
1123 mesh_trial_trace_ref.data(),
1124 mesh_grad_trial_trace_ref.data(),
1126 u_trial_trace_ref.data(),
1127 u_grad_trial_trace_ref.data(),
1128 u_test_trace_ref.data(),
1129 u_grad_test_trace_ref.data(),
1131 boundaryJac_ref.data(),
1138 elementDiameter.data(),
1139 nodeDiametersArray.data(),
1142 q_normal_phi.data(),
1145 elementJacobian_u_u,
1148 elementConstantJacobian=0.0;
1149 for (
int i=0;i<nDOF_test_element;i++)
1151 for (
int j=0;j<nDOF_test_element;j++)
1153 elementConstantJacobian += elementJacobian_u_u[i*nDOF_trial_element+j];
1156 std::cout<<
"elementConstantJacobian "<<elementConstantJacobian<<std::endl;
1158 elementConstant_u -= elementConstantResidual/(elementConstantJacobian+1.0e-8);
1159 for (
int i=0;i<nDOF_test_element;i++)
1161 element_u[i] = elementConstant_u;
1165 mesh_grad_trial_ref.data(),
1170 u_grad_trial_ref.data(),
1172 u_grad_test_ref.data(),
1173 mesh_trial_trace_ref.data(),
1174 mesh_grad_trial_trace_ref.data(),
1176 u_trial_trace_ref.data(),
1177 u_grad_trial_trace_ref.data(),
1178 u_test_trace_ref.data(),
1179 u_grad_test_trace_ref.data(),
1181 boundaryJac_ref.data(),
1188 elementDiameter.data(),
1189 nodeDiametersArray.data(),
1192 q_normal_phi.data(),
1194 ebqe_normal_phi.data(),
1204 nExteriorElementBoundaries_global,
1205 exteriorElementBoundariesArray.data(),
1206 elementBoundaryElementsArray.data(),
1207 elementBoundaryLocalElementBoundariesArray.data(),
1211 elementConstantResidual=0.0;
1212 for (
int i=0;i<nDOF_test_element;i++)
1214 elementConstantResidual += elementResidual_u[i];
1216 resNorm = fabs(elementConstantResidual);
1217 std::cout<<
"resNorm["<<its<<
"] "<<resNorm<<std::endl;
1224 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1225 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1226 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1227 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1228 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1229 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1230 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1231 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1232 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1233 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1234 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1235 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1236 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1237 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1238 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1239 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1240 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1241 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1242 int nElements_owned = args.
scalar<
int>(
"nElements_owned");
1243 double useMetrics = args.
scalar<
double>(
"useMetrics");
1244 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1245 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1246 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1247 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1248 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1249 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1250 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1251 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1252 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1253 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1254 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
1255 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
1256 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1257 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1258 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1259 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
1260 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
1261 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1262 int offset_u = args.
scalar<
int>(
"offset_u");
1263 int stride_u = args.
scalar<
int>(
"stride_u");
1264 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1265 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1266 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1267 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1268 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1269 int maxIts = args.
scalar<
int>(
"maxIts");
1270 double atol = args.
scalar<
double>(
"atol");
1271 double constant_u = args.
scalar<
double>(
"constant_u");
1272 register double element_u[nDOF_test_element],
1273 elementResidual_u[nDOF_test_element],
1274 elementJacobian_u_u[nDOF_test_element*nDOF_trial_element];
1275 double constantResidual = 0.0;
1276 double constantJacobian = 0.0;
1277 for (
int i=0;i<nDOF_trial_element;i++)
1279 element_u[i]=constant_u;
1282 for(
int eN=0;eN<nElements_owned;eN++)
1285 mesh_grad_trial_ref.data(),
1290 u_grad_trial_ref.data(),
1292 u_grad_test_ref.data(),
1293 mesh_trial_trace_ref.data(),
1294 mesh_grad_trial_trace_ref.data(),
1296 u_trial_trace_ref.data(),
1297 u_grad_trial_trace_ref.data(),
1298 u_test_trace_ref.data(),
1299 u_grad_test_trace_ref.data(),
1301 boundaryJac_ref.data(),
1308 elementDiameter.data(),
1309 nodeDiametersArray.data(),
1312 q_normal_phi.data(),
1314 ebqe_normal_phi.data(),
1324 nExteriorElementBoundaries_global,
1325 exteriorElementBoundariesArray.data(),
1326 elementBoundaryElementsArray.data(),
1327 elementBoundaryLocalElementBoundariesArray.data(),
1331 for (
int i=0;i<nDOF_test_element;i++)
1333 constantResidual += elementResidual_u[i];
1336 mesh_grad_trial_ref.data(),
1341 u_grad_trial_ref.data(),
1343 u_grad_test_ref.data(),
1344 mesh_trial_trace_ref.data(),
1345 mesh_grad_trial_trace_ref.data(),
1347 u_trial_trace_ref.data(),
1348 u_grad_trial_trace_ref.data(),
1349 u_test_trace_ref.data(),
1350 u_grad_test_trace_ref.data(),
1352 boundaryJac_ref.data(),
1359 elementDiameter.data(),
1360 nodeDiametersArray.data(),
1363 q_normal_phi.data(),
1366 elementJacobian_u_u,
1369 for (
int i=0;i<nDOF_test_element;i++)
1371 for (
int j=0;j<nDOF_test_element;j++)
1373 constantJacobian += elementJacobian_u_u[i*nDOF_trial_element+j];
1377 return std::tuple<double, double>(constantResidual, constantJacobian);
1383 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1384 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1385 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1386 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1387 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1388 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1389 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1390 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1391 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1392 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1393 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1394 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1395 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1396 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1397 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1398 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1399 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1400 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1401 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1402 int nElements_owned = args.
scalar<
int>(
"nElements_owned");
1403 double useMetrics = args.
scalar<
double>(
"useMetrics");
1404 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1405 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1406 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1407 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1408 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1409 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1410 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1411 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
1412 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1413 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1414 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1415 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
1416 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
1417 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1418 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1419 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1420 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
1421 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
1422 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1423 int offset_u = args.
scalar<
int>(
"offset_u");
1424 int stride_u = args.
scalar<
int>(
"stride_u");
1425 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1426 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1427 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1428 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1429 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1430 double globalMass = 0.0;
1431 gf.useExact=useExact;
1432 for(
int eN=0;eN<nElements_owned;eN++)
1434 double epsHeaviside;
1437 register double element_phi[nDOF_trial_element];
1438 for (
int i=0;i<nDOF_test_element;i++)
1440 register int eN_i=eN*nDOF_test_element+i;
1441 element_phi[i] = phi_dof.data()[u_l2g.data()[eN_i]];
1443 double element_nodes[nDOF_mesh_trial_element*3];
1444 for (
int i=0;i<nDOF_mesh_trial_element;i++)
1446 register int eN_i=eN*nDOF_mesh_trial_element+i;
1447 for(
int I=0;I<3;I++)
1448 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
1450 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
1451 for (
int k=0;k<nQuadraturePoints_element;k++)
1454 register int eN_k = eN*nQuadraturePoints_element+k,
1455 eN_k_nSpace = eN_k*nSpace;
1458 double jac[nSpace*nSpace],
1460 jacInv[nSpace*nSpace],
1465 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
1470 ck.calculateMapping_element(eN,
1474 mesh_trial_ref.data(),
1475 mesh_grad_trial_ref.data(),
1480 ck.calculateH_element(eN,
1482 nodeDiametersArray.data(),
1484 mesh_trial_ref.data(),
1487 dV = fabs(jacDet)*dV_ref.data()[k];
1488 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1497 epsHeaviside=epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
1498 globalMass += q_porosity[eN_k]*
gf.H(epsHeaviside,q_phi.data()[eN_k])*dV;
1507 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1508 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1509 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1510 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1511 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1512 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1513 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1514 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1515 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1516 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1517 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1518 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1519 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1520 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1521 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1522 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1523 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1524 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1525 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1526 int nElements_global = args.
scalar<
int>(
"nElements_global");
1527 double useMetrics = args.
scalar<
double>(
"useMetrics");
1528 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1529 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1530 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1531 xt::pyarray<int>& phi_l2g = args.
array<
int>(
"phi_l2g");
1532 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1533 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1534 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
1535 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1536 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1537 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1538 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
1539 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
1540 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
1541 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
1542 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
1543 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
1544 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
1545 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1546 int offset_u = args.
scalar<
int>(
"offset_u");
1547 int stride_u = args.
scalar<
int>(
"stride_u");
1548 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1549 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1550 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1551 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1552 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1553 xt::pyarray<double>& H_dof = args.
array<
double>(
"H_dof");
1554 gf.useExact=useExact;
1556 for(
int eN=0;eN<nElements_global;eN++)
1558 double epsHeaviside;
1561 register double element_phi[nDOF_trial_element];
1562 for (
int i=0;i<nDOF_test_element;i++)
1564 register int eN_i=eN*nDOF_test_element+i;
1565 element_phi[i] = phi_dof.data()[phi_l2g.data()[eN_i]];
1567 double element_nodes[nDOF_mesh_trial_element*3];
1568 for (
int i=0;i<nDOF_mesh_trial_element;i++)
1570 register int eN_i=eN*nDOF_mesh_trial_element+i;
1571 for(
int I=0;I<3;I++)
1572 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
1574 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
1575 gf_nodes.calculate(element_phi, element_nodes, element_nodes,
false);
1576 for (
int k=0;k<nQuadraturePoints_element;k++)
1579 register int eN_k = eN*nQuadraturePoints_element+k,
1580 eN_k_nSpace = eN_k*nSpace;
1583 register double jac[nSpace*nSpace],
1585 jacInv[nSpace*nSpace],
1590 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
1595 ck.calculateMapping_element(eN,
1599 mesh_trial_ref.data(),
1600 mesh_grad_trial_ref.data(),
1605 ck.calculateH_element(eN,
1607 nodeDiametersArray.data(),
1609 mesh_trial_ref.data(),
1612 dV = fabs(jacDet)*dV_ref.data()[k];
1613 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1624 epsHeaviside=epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
1625 q_H.data()[eN_k] =
gf.H(epsHeaviside,q_phi.data()[eN_k]);
1628 for (
int i=0;i<nDOF_trial_element;i++)
1631 int eN_i = eN*nDOF_trial_element + i;
1632 int gi = phi_l2g.data()[eN_i];
1633 epsHeaviside = epsFactHeaviside*nodeDiametersArray.data()[mesh_l2g.data()[eN_i]];
1634 H_dof.data() [gi] =
gf_nodes.H(epsHeaviside,phi_dof.data()[gi]);
1641 int NNZ = args.
scalar<
int>(
"NNZ");
1642 int numDOFs = args.
scalar<
int>(
"numDOFs");
1643 xt::pyarray<double>& lumped_mass_matrix = args.
array<
double>(
"lumped_mass_matrix");
1644 xt::pyarray<double>& solH = args.
array<
double>(
"solH");
1645 xt::pyarray<double>& solL = args.
array<
double>(
"solL");
1646 xt::pyarray<double>& limited_solution = args.
array<
double>(
"limited_solution");
1647 xt::pyarray<int>& csrRowIndeces_DofLoops = args.
array<
int>(
"csrRowIndeces_DofLoops");
1648 xt::pyarray<int>& csrColumnOffsets_DofLoops = args.
array<
int>(
"csrColumnOffsets_DofLoops");
1649 xt::pyarray<double>& MassMatrix = args.
array<
double>(
"matrix");
1650 Rpos.resize(numDOFs,0.0),
Rneg.resize(numDOFs,0.0);
1656 for (
int i=0; i<numDOFs; i++)
1659 double solHi = solH.data()[i];
1660 double solLi = solL.data()[i];
1661 double mi = lumped_mass_matrix.data()[i];
1663 double mini=0., maxi=1.0;
1664 double Pposi=0, Pnegi=0;
1666 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1668 int j = csrColumnOffsets_DofLoops.data()[offset];
1670 FluxCorrectionMatrix[ij] = ((i==j ? 1. : 0.)*mi - MassMatrix.data()[ij]) * (solH.data()[j]-solHi);
1684 double Qposi = mi*(maxi-solLi);
1685 double Qnegi = mi*(mini-solLi);
1690 Rpos[i] = ((Pposi==0) ? 1. :
std::min(1.0,Qposi/Pposi));
1691 Rneg[i] = ((Pnegi==0) ? 1. :
std::min(1.0,Qnegi/Pnegi));
1698 for (
int i=0; i<numDOFs; i++)
1700 double ith_Limiter_times_FluxCorrectionMatrix = 0.;
1701 double Rposi =
Rpos[i], Rnegi =
Rneg[i];
1703 for (
int offset=csrRowIndeces_DofLoops.data()[i]; offset<csrRowIndeces_DofLoops.data()[i+1]; offset++)
1705 int j = csrColumnOffsets_DofLoops.data()[offset];
1706 ith_Limiter_times_FluxCorrectionMatrix +=
1713 limited_solution.data()[i] = fmax(0.0,solL.data()[i] + 1./lumped_mass_matrix.data()[i]*ith_Limiter_times_FluxCorrectionMatrix);
1719 double* mesh_trial_ref,
1720 double* mesh_grad_trial_ref,
1724 double* u_trial_ref,
1725 double* u_grad_trial_ref,
1727 double* u_grad_test_ref,
1729 double* mesh_trial_trace_ref,
1730 double* mesh_grad_trial_trace_ref,
1732 double* u_trial_trace_ref,
1733 double* u_grad_trial_trace_ref,
1734 double* u_test_trace_ref,
1735 double* u_grad_test_trace_ref,
1737 double* boundaryJac_ref,
1739 int nElements_global,
1741 double epsFactHeaviside,
1742 double epsFactDirac,
1743 double epsFactDiffusion,
1745 double* elementDiameter,
1746 double* nodeDiametersArray,
1753 double* q_normal_phi,
1756 double* elementMassMatrix,
1757 double* elementLumpedMassMatrix,
1761 for (
int i=0;i<nDOF_test_element;i++)
1763 elementLumpedMassMatrix[i] = 0.0;
1764 for (
int j=0;j<nDOF_trial_element;j++)
1766 elementMassMatrix[i*nDOF_trial_element+j]=0.0;
1769 double epsHeaviside,epsDirac,epsDiffusion;
1770 for (
int k=0;k<nQuadraturePoints_element;k++)
1772 int eN_k = eN*nQuadraturePoints_element+k,
1773 eN_k_nSpace = eN_k*nSpace;
1777 register double u=0.0,
1782 jacInv[nSpace*nSpace],
1783 u_grad_trial[nDOF_trial_element*nSpace],
1785 u_test_dV[nDOF_test_element],
1786 u_grad_test_dV[nDOF_test_element*nSpace],
1788 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
1792 ck.calculateMapping_element(eN,
1797 mesh_grad_trial_ref,
1802 ck.calculateH_element(eN,
1809 dV = fabs(jacDet)*dV_ref[k];
1810 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1823 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1825 ck.valFromElementDOF(element_u,&u_trial_ref[k*nDOF_trial_element],
u);
1827 ck.gradFromElementDOF(element_u,u_grad_trial,grad_u);
1829 for (
int j=0;j<nDOF_trial_element;j++)
1831 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
1832 for (
int I=0;I<nSpace;I++)
1834 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1840 epsHeaviside=epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
1841 epsDirac =epsFactDirac* (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
1842 epsDiffusion=epsFactDiffusion*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
1852 for(
int i=0;i<nDOF_test_element;i++)
1856 elementLumpedMassMatrix[i] += u_test_dV[i];
1857 for(
int j=0;j<nDOF_trial_element;j++)
1859 elementMassMatrix[i*nDOF_trial_element+j] += u_trial_ref[k*nDOF_trial_element+j]*u_test_dV[i];
1867 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1868 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1869 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1870 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1871 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1872 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1873 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1874 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1875 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1876 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1877 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1878 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1879 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1880 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1881 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1882 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1883 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1884 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1885 int nElements_global = args.
scalar<
int>(
"nElements_global");
1886 double useMetrics = args.
scalar<
double>(
"useMetrics");
1887 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1888 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1889 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1890 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1891 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1892 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1893 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1894 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1895 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1896 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
1897 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1898 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
1899 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
1900 xt::pyarray<double>& globalMassMatrix = args.
array<
double>(
"globalMassMatrix");
1901 xt::pyarray<double>& globalLumpedMassMatrix = args.
array<
double>(
"globalLumpedMassMatrix");
1905 for(
int eN=0;eN<nElements_global;eN++)
1907 register double elementMassMatrix[nDOF_test_element*nDOF_trial_element],element_u[nDOF_trial_element], elementLumpedMassMatrix[nDOF_trial_element];
1908 for (
int j=0;j<nDOF_trial_element;j++)
1910 register int eN_j = eN*nDOF_trial_element+j;
1911 element_u[j] = u_dof.data()[u_l2g.data()[eN_j]];
1914 mesh_grad_trial_ref.data(),
1919 u_grad_trial_ref.data(),
1921 u_grad_test_ref.data(),
1922 mesh_trial_trace_ref.data(),
1923 mesh_grad_trial_trace_ref.data(),
1925 u_trial_trace_ref.data(),
1926 u_grad_trial_trace_ref.data(),
1927 u_test_trace_ref.data(),
1928 u_grad_test_trace_ref.data(),
1930 boundaryJac_ref.data(),
1937 elementDiameter.data(),
1938 nodeDiametersArray.data(),
1941 q_normal_phi.data(),
1945 elementLumpedMassMatrix,
1951 for (
int i=0;i<nDOF_test_element;i++)
1953 int eN_i = eN*nDOF_test_element+i;
1954 int gi = u_l2g.data()[eN_i];
1955 globalLumpedMassMatrix.data()[gi] += elementLumpedMassMatrix[i];
1956 for (
int j=0;j<nDOF_trial_element;j++)
1958 int eN_i_j = eN_i*nDOF_trial_element+j;
1959 globalMassMatrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] +=
1960 elementMassMatrix[i*nDOF_trial_element+j];
1969 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1970 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1971 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1972 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1973 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1974 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1975 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1976 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1977 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1978 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1979 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1980 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1981 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1982 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1983 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1984 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1985 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1986 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1987 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1988 int nElements_global = args.
scalar<
int>(
"nElements_global");
1989 double useMetrics = args.
scalar<
double>(
"useMetrics");
1990 double epsFactHeaviside = args.
scalar<
double>(
"epsFactHeaviside");
1991 double epsFactDirac = args.
scalar<
double>(
"epsFactDirac");
1992 double epsFactDiffusion = args.
scalar<
double>(
"epsFactDiffusion");
1993 xt::pyarray<int>& phi_l2g = args.
array<
int>(
"phi_l2g");
1994 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1995 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1996 xt::pyarray<double>& phi_dof = args.
array<
double>(
"phi_dof");
1997 xt::pyarray<double>& q_phi = args.
array<
double>(
"q_phi");
1998 xt::pyarray<double>& q_normal_phi = args.
array<
double>(
"q_normal_phi");
1999 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
2000 xt::pyarray<double>& ebqe_normal_phi = args.
array<
double>(
"ebqe_normal_phi");
2001 xt::pyarray<double>& q_H = args.
array<
double>(
"q_H");
2002 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
2003 xt::pyarray<double>& q_n = args.
array<
double>(
"q_n");
2004 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
2005 xt::pyarray<double>& ebqe_n = args.
array<
double>(
"ebqe_n");
2006 xt::pyarray<double>& q_r = args.
array<
double>(
"q_r");
2007 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
2008 int offset_u = args.
scalar<
int>(
"offset_u");
2009 int stride_u = args.
scalar<
int>(
"stride_u");
2010 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
2011 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
2012 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
2013 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
2014 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
2015 xt::pyarray<double>& rhs_mass_correction = args.
array<
double>(
"rhs_mass_correction");
2016 xt::pyarray<double>& lumped_L2p_vof_mass_correction = args.
array<
double>(
"lumped_L2p_vof_mass_correction");
2017 xt::pyarray<double>& lumped_mass_matrix = args.
array<
double>(
"lumped_mass_matrix");
2018 int numDOFs = args.
scalar<
int>(
"numDOFs");
2019 gf.useExact=useExact;
2020 for(
int eN=0;eN<nElements_global;eN++)
2022 register double element_rhs_mass_correction[nDOF_test_element];
2023 for (
int i=0;i<nDOF_test_element;i++)
2024 element_rhs_mass_correction[i] = 0.;
2025 double epsHeaviside;
2027 double element_phi[nDOF_trial_element];
2028 for (
int i=0;i<nDOF_test_element;i++)
2030 register int eN_i=eN*nDOF_test_element+i;
2031 element_phi[i] = phi_dof.data()[phi_l2g.data()[eN_i]];
2033 double element_nodes[nDOF_mesh_trial_element*3];
2034 for (
int i=0;i<nDOF_mesh_trial_element;i++)
2036 register int eN_i=eN*nDOF_mesh_trial_element+i;
2037 for(
int I=0;I<3;I++)
2038 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
2040 gf.calculate(element_phi, element_nodes, x_ref.data(),
false);
2041 for (
int k=0;k<nQuadraturePoints_element;k++)
2044 register int eN_k = eN*nQuadraturePoints_element+k,
2045 eN_k_nSpace = eN_k*nSpace;
2048 register double jac[nSpace*nSpace],
2050 jacInv[nSpace*nSpace],
2055 u_test_dV[nDOF_test_element],
2056 G[nSpace*nSpace],G_dd_G,tr_G,h_phi;
2059 ck.calculateMapping_element(eN,
2063 mesh_trial_ref.data(),
2064 mesh_grad_trial_ref.data(),
2069 ck.calculateH_element(eN,
2071 nodeDiametersArray.data(),
2073 mesh_trial_ref.data(),
2076 dV = fabs(jacDet)*dV_ref.data()[k];
2077 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2080 for (
int j=0;j<nDOF_trial_element;j++)
2081 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
2092 epsHeaviside=epsFactHeaviside*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2093 q_H.data()[eN_k] =
gf.H(epsHeaviside,q_phi.data()[eN_k]);
2095 for (
int i=0;i<nDOF_trial_element;i++)
2096 element_rhs_mass_correction [i] += q_porosity.data()[eN_k]*q_H.data()[eN_k]*u_test_dV[i];
2099 for (
int i=0;i<nDOF_trial_element;i++)
2101 int eN_i = eN*nDOF_trial_element + i;
2102 int gi = phi_l2g.data()[eN_i];
2103 rhs_mass_correction.data()[gi] += element_rhs_mass_correction[i];
2107 for (
int i=0; i<numDOFs; i++)
2109 double mi = lumped_mass_matrix.data()[i];
2110 lumped_L2p_vof_mass_correction.data()[i] = 1./mi*rhs_mass_correction.data()[i];
2116 int nQuadraturePoints_elementIn,
2117 int nDOF_mesh_trial_elementIn,
2118 int nDOF_trial_elementIn,
2119 int nDOF_test_elementIn,
2120 int nQuadraturePoints_elementBoundaryIn,
2124 return proteus::chooseAndAllocateDiscretization2D<MCorr_base,MCorr,CompKernel>(nSpaceIn,
2125 nQuadraturePoints_elementIn,
2126 nDOF_mesh_trial_elementIn,
2127 nDOF_trial_elementIn,
2128 nDOF_test_elementIn,
2129 nQuadraturePoints_elementBoundaryIn,
2132 return proteus::chooseAndAllocateDiscretization<MCorr_base,MCorr,CompKernel>(nSpaceIn,
2133 nQuadraturePoints_elementIn,
2134 nDOF_mesh_trial_elementIn,
2135 nDOF_trial_elementIn,
2136 nDOF_test_elementIn,
2137 nQuadraturePoints_elementBoundaryIn,