7 #include "../mprans/ArgumentsDict.h"
8 #include "xtensor-python/pyarray.hpp"
11 namespace py = pybind11;
24 template<
class CompKernelType,
26 int nQuadraturePoints_element,
27 int nDOF_mesh_trial_element,
28 int nDOF_trial_element,
29 int nDOF_test_element,
30 int nQuadraturePoints_elementBoundary>
42 const int colind[
nnz],
45 const double gravity[nSpace],
50 const double KWs[
nnz],
59 const int nSpace2 = nSpace * nSpace;
65 double onePlus_pcBar_n;
76 double rho2 = rho * rho;
85 m_vg = 1.0 - 1.0 / n_vg;
86 thetaS = thetaR + thetaSR;
93 pcBar_nM2 = pow(pcBarStar, n_vg - 2);
94 pcBar_nM1 = pcBar_nM2 * pcBar;
95 pcBar_n = pcBar_nM1 * pcBar;
96 onePlus_pcBar_n = 1.0 + pcBar_n;
98 sBar = pow(onePlus_pcBar_n, -m_vg);
100 DsBar_DpsiC = alpha * (1.0 - n_vg) * (sBar/onePlus_pcBar_n)*pcBar_nM1;
102 vBar = 1.0-pcBar_nM1*sBar;
104 DvBar_DpsiC = -alpha*(n_vg-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
106 thetaW = thetaSR*sBar + thetaR;
107 DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
109 sqrt_sBar = sqrt(sBar);
110 sqrt_sBarStar = sqrt_sBar;
111 if (sqrt_sBar < 1.0e-8)
112 sqrt_sBarStar = 1.0e-8;
113 KWr= sqrt_sBar*vBar2;
114 DKWr_DpsiC= ((0.5/sqrt_sBarStar)*DsBar_DpsiC*vBar2
116 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
126 rhom = rho*exp(beta*
u);
129 dm = -rhom*DthetaW_DpsiC+drhom*thetaW;
130 for (
int I=0;I<nSpace;I++)
134 for (
int ii=rowptr[I]; ii < rowptr[I+1]; ii++)
136 f[I] += rho2*KWr*KWs[ii]*gravity[colind[ii]];
137 df[I] += -rho2*DKWr_DpsiC*KWs[ii]*gravity[colind[ii]];
138 a[ii] = rho*KWr*KWs[ii];
139 da[ii] = -rho*DKWr_DpsiC*KWs[ii];
147 const double dH[nSpace],
151 double h,nrm_v,oneByAbsdt;
154 for(
int I=0;I<nSpace;I++)
158 oneByAbsdt = fabs(dmt);
159 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
164 const double G[nSpace*nSpace],
166 const double Ai[nSpace],
171 for(
int I=0;I<nSpace;I++)
172 for (
int J=0;J<nSpace;J++)
173 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
175 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv);
180 const double& elementDiameter,
181 const double& strong_residual,
182 const double grad_u[nSpace],
191 for (
int I=0;I<nSpace;I++)
192 n_grad_u += grad_u[I]*grad_u[I];
193 num = shockCapturingDiffusion*0.5*h*fabs(strong_residual);
194 den = sqrt(n_grad_u) + 1.0e-8;
207 double grad_psi[nSpace],
209 double K_rho_g[nSpace],
213 double v_I,bc_u_seepage=0.0;
214 if (isSeepageFace || isDOFBoundary)
217 for(
int I=0;I<nSpace;I++)
222 for(
int m=rowptr[I];m<rowptr[I+1];m++)
224 v_I -= K[m]*grad_psi[colind[m]];
230 flux += penalty*(
u-bc_u);
267 const int colind[
nnz],
268 const int isDOFBoundary,
269 const double n[nSpace],
271 const double dK[
nnz],
272 const double grad_psi[nSpace],
273 const double grad_v[nSpace],
274 const double dK_rho_g[nSpace],
276 const double penalty,
277 double& fluxJacobian)
282 for(
int I=0;I<nSpace;I++)
285 fluxJacobian += dK_rho_g[I]*
v*
n[I];
287 for(
int m=rowptr[I]; m<rowptr[I+1]; m++)
289 fluxJacobian -= (K[m]*grad_v[colind[m]] + dK[m]*
v*grad_psi[colind[m]])*
n[I];
293 fluxJacobian += penalty*
v;
301 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
302 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
303 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
304 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
305 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
306 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
307 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
308 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
309 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
310 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
311 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
312 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
313 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
314 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
315 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
316 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
317 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
318 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
319 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
320 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
321 int nElements_global = args.
scalar<
int>(
"nElements_global");
322 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
323 xt::pyarray<int>& elementMaterialTypes = args.
array<
int>(
"elementMaterialTypes");
324 xt::pyarray<int>& isSeepageFace = args.
array<
int>(
"isSeepageFace");
325 xt::pyarray<int>& a_rowptr = args.
array<
int>(
"a_rowptr");
326 xt::pyarray<int>& a_colind = args.
array<
int>(
"a_colind");
327 double rho = args.
scalar<
double>(
"rho");
328 double beta = args.
scalar<
double>(
"beta");
329 xt::pyarray<double>& gravity = args.
array<
double>(
"gravity");
330 xt::pyarray<double>& alpha = args.
array<
double>(
"alpha");
331 xt::pyarray<double>&
n = args.
array<
double>(
"n");
332 xt::pyarray<double>& thetaR = args.
array<
double>(
"thetaR");
333 xt::pyarray<double>& thetaSR = args.
array<
double>(
"thetaSR");
334 xt::pyarray<double>& KWs = args.
array<
double>(
"KWs");
335 double useMetrics = args.
scalar<
double>(
"useMetrics");
336 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
337 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
338 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
339 double sc_uref = args.
scalar<
double>(
"sc_uref");
340 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
341 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
342 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
343 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
344 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
345 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
346 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
347 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
348 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
349 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
350 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
351 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
352 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
353 int offset_u = args.
scalar<
int>(
"offset_u");
354 int stride_u = args.
scalar<
int>(
"stride_u");
355 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
356 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
357 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
358 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
359 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
360 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
361 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
362 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
363 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
364 xt::pyarray<double>& ebqe_bc_flux_ext = args.
array<
double>(
"ebqe_bc_flux_ext");
365 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
366 double epsFact = args.
scalar<
double>(
"epsFact");
367 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
368 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
369 assert(a_rowptr.data()[nSpace] ==
nnz);
370 assert(a_rowptr.data()[nSpace] == nSpace);
383 for(
int eN=0;eN<nElements_global;eN++)
386 register double elementResidual_u[nDOF_test_element];
387 for (
int i=0;i<nDOF_test_element;i++)
389 elementResidual_u[i]=0.0;
392 for (
int k=0;k<nQuadraturePoints_element;k++)
395 register int eN_k = eN*nQuadraturePoints_element+k,
396 eN_k_nSpace = eN_k*nSpace,
397 eN_nDOF_trial_element = eN*nDOF_trial_element;
398 register double u=0.0,grad_u[nSpace],grad_u_old[nSpace],
400 f[nSpace],
df[nSpace],
404 Lstar_u[nDOF_test_element],
406 tau=0.0,tau0=0.0,tau1=0.0,
407 numDiff0=0.0,numDiff1=0.0,
410 jacInv[nSpace*nSpace],
411 u_grad_trial[nDOF_trial_element*nSpace],
412 u_test_dV[nDOF_trial_element],
413 u_grad_test_dV[nDOF_test_element*nSpace],
415 G[nSpace*nSpace],G_dd_G,tr_G,norm_Rv;
419 ck.calculateMapping_element(eN,
423 mesh_trial_ref.data(),
424 mesh_grad_trial_ref.data(),
429 ck.calculateMappingVelocity_element(eN,
431 mesh_velocity_dof.data(),
433 mesh_trial_ref.data(),
436 dV = fabs(jacDet)*dV_ref.data()[k];
437 q_dV.data()[eN_k] = dV;
438 ck.calculateG(jacInv,G,G_dd_G,tr_G);
440 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
442 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
444 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
446 for (
int j=0;j<nDOF_trial_element;j++)
448 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
449 for (
int I=0;I<nSpace;I++)
451 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
462 alpha.data()[elementMaterialTypes.data()[eN]],
463 n.data()[elementMaterialTypes.data()[eN]],
464 thetaR.data()[elementMaterialTypes.data()[eN]],
465 thetaSR.data()[elementMaterialTypes.data()[eN]],
466 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
478 q_m_betaBDF.data()[eN_k],
521 for(
int i=0;i<nDOF_test_element;i++)
523 register int eN_k_i=eN_k*nDOF_test_element+i,
524 eN_k_i_nSpace = eN_k_i*nSpace,
527 elementResidual_u[i] +=
ck.Mass_weak(m_t,u_test_dV[i]) +
528 ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace]) +
529 ck.Diffusion_weak(a_rowptr.data(),a_colind.data(),a,grad_u,&u_grad_test_dV[i_nSpace]);
535 q_m.data()[eN_k] = m;
536 q_u.data()[eN_k] =
u;
541 for(
int i=0;i<nDOF_test_element;i++)
543 register int eN_i=eN*nDOF_test_element+i;
545 globalResidual.data()[offset_u+stride_u*u_l2g.data()[eN_i]] += elementResidual_u[i];
554 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
556 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
557 eN = elementBoundaryElementsArray.data()[ebN*2+0],
558 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
559 eN_nDOF_trial_element = eN*nDOF_trial_element;
560 register double elementResidual_u[nDOF_test_element];
561 for (
int i=0;i<nDOF_test_element;i++)
563 elementResidual_u[i]=0.0;
565 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
567 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
568 ebNE_kb_nSpace = ebNE_kb*nSpace,
569 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
570 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
571 register double u_ext=0.0,
581 bc_grad_u_ext[nSpace],
588 jac_ext[nSpace*nSpace],
590 jacInv_ext[nSpace*nSpace],
591 boundaryJac[nSpace*(nSpace-1)],
592 metricTensor[(nSpace-1)*(nSpace-1)],
595 u_test_dS[nDOF_test_element],
596 u_grad_trial_trace[nDOF_trial_element*nSpace],
597 normal[3],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
598 G[nSpace*nSpace],G_dd_G,tr_G;
603 ck.calculateMapping_elementBoundary(eN,
609 mesh_trial_trace_ref.data(),
610 mesh_grad_trial_trace_ref.data(),
611 boundaryJac_ref.data(),
621 ck.calculateMappingVelocity_elementBoundary(eN,
625 mesh_velocity_dof.data(),
627 mesh_trial_trace_ref.data(),
628 xt_ext,yt_ext,zt_ext,
633 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
636 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
639 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
641 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);
642 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
644 for (
int j=0;j<nDOF_trial_element;j++)
646 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
651 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
660 alpha.data()[elementMaterialTypes.data()[eN]],
661 n.data()[elementMaterialTypes.data()[eN]],
662 thetaR.data()[elementMaterialTypes.data()[eN]],
663 thetaSR.data()[elementMaterialTypes.data()[eN]],
664 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
677 alpha.data()[elementMaterialTypes.data()[eN]],
678 n.data()[elementMaterialTypes.data()[eN]],
679 thetaR.data()[elementMaterialTypes.data()[eN]],
680 thetaSR.data()[elementMaterialTypes.data()[eN]],
681 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
695 isSeepageFace.data()[ebNE],
696 isDOFBoundary_u.data()[ebNE_kb],
703 ebqe_penalty_ext.data()[ebNE_kb],
705 ebqe_flux.data()[ebNE_kb] = flux_ext;
706 ebqe_u.data()[ebNE_kb] = u_ext;
710 for (
int i=0;i<nDOF_test_element;i++)
712 int ebNE_kb_i = ebNE_kb*nDOF_test_element+i;
714 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
720 for (
int i=0;i<nDOF_test_element;i++)
722 int eN_i = eN*nDOF_test_element+i;
724 globalResidual.data()[offset_u+stride_u*u_l2g.data()[eN_i]] += elementResidual_u[i];
731 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
732 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
733 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
734 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
735 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
736 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
737 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
738 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
739 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
740 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
741 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
742 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
743 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
744 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
745 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
746 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
747 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
748 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
749 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
750 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
751 int nElements_global = args.
scalar<
int>(
"nElements_global");
752 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
753 xt::pyarray<int>& elementMaterialTypes = args.
array<
int>(
"elementMaterialTypes");
754 xt::pyarray<int>& isSeepageFace = args.
array<
int>(
"isSeepageFace");
755 xt::pyarray<int>& a_rowptr = args.
array<
int>(
"a_rowptr");
756 xt::pyarray<int>& a_colind = args.
array<
int>(
"a_colind");
757 double rho = args.
scalar<
double>(
"rho");
758 double beta = args.
scalar<
double>(
"beta");
759 xt::pyarray<double>& gravity = args.
array<
double>(
"gravity");
760 xt::pyarray<double>& alpha = args.
array<
double>(
"alpha");
761 xt::pyarray<double>&
n = args.
array<
double>(
"n");
762 xt::pyarray<double>& thetaR = args.
array<
double>(
"thetaR");
763 xt::pyarray<double>& thetaSR = args.
array<
double>(
"thetaSR");
764 xt::pyarray<double>& KWs = args.
array<
double>(
"KWs");
765 double useMetrics = args.
scalar<
double>(
"useMetrics");
766 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
767 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
768 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
769 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
770 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
771 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
772 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
773 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
774 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
775 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
776 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
777 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
778 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
779 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
780 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
781 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
782 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
783 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
784 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
785 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
786 xt::pyarray<int>& isFluxBoundary_u = args.
array<
int>(
"isFluxBoundary_u");
787 xt::pyarray<double>& ebqe_bc_flux_ext = args.
array<
double>(
"ebqe_bc_flux_ext");
788 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
789 assert(a_rowptr.data()[nSpace] ==
nnz);
790 assert(a_rowptr.data()[nSpace] == nSpace);
796 for(
int eN=0;eN<nElements_global;eN++)
798 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
799 for (
int i=0;i<nDOF_test_element;i++)
801 for (
int j=0;j<nDOF_trial_element;j++)
803 elementJacobian_u_u[i][j]=0.0;
806 for (
int k=0;k<nQuadraturePoints_element;k++)
808 int eN_k = eN*nQuadraturePoints_element+k,
809 eN_k_nSpace = eN_k*nSpace,
810 eN_nDOF_trial_element = eN*nDOF_trial_element;
813 register double u=0.0,
816 f[nSpace],
df[nSpace],
819 dpdeResidual_u_u[nDOF_trial_element],
820 Lstar_u[nDOF_test_element],
821 dsubgridError_u_u[nDOF_trial_element],
822 tau=0.0,tau0=0.0,tau1=0.0,
825 jacInv[nSpace*nSpace],
826 u_grad_trial[nDOF_trial_element*nSpace],
828 u_test_dV[nDOF_test_element],
829 u_grad_test_dV[nDOF_test_element*nSpace],
831 G[nSpace*nSpace],G_dd_G,tr_G;
836 ck.calculateMapping_element(eN,
840 mesh_trial_ref.data(),
841 mesh_grad_trial_ref.data(),
846 ck.calculateMappingVelocity_element(eN,
848 mesh_velocity_dof.data(),
850 mesh_trial_ref.data(),
853 dV = fabs(jacDet)*dV_ref.data()[k];
854 ck.calculateG(jacInv,G,G_dd_G,tr_G);
856 ck.gradTrialFromRef(&u_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
858 ck.valFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],&u_trial_ref.data()[k*nDOF_trial_element],
u);
860 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial,grad_u);
862 for (
int j=0;j<nDOF_trial_element;j++)
864 u_test_dV[j] = u_test_ref.data()[k*nDOF_trial_element+j]*dV;
865 for (
int I=0;I<nSpace;I++)
867 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
878 alpha.data()[elementMaterialTypes.data()[eN]],
879 n.data()[elementMaterialTypes.data()[eN]],
880 thetaR.data()[elementMaterialTypes.data()[eN]],
881 thetaSR.data()[elementMaterialTypes.data()[eN]],
882 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
894 q_m_betaBDF.data()[eN_k],
934 for(
int i=0;i<nDOF_test_element;i++)
938 for(
int j=0;j<nDOF_trial_element;j++)
942 int j_nSpace = j*nSpace;
943 int i_nSpace = i*nSpace;
944 elementJacobian_u_u[i][j] +=
ck.MassJacobian_weak(dm_t,u_trial_ref.data()[k*nDOF_trial_element+j],u_test_dV[i]) +
945 ck.AdvectionJacobian_weak(
df,u_trial_ref.data()[k*nDOF_trial_element+j],&u_grad_test_dV[i_nSpace]) +
946 ck.DiffusionJacobian_weak(a_rowptr.data(),a_colind.data(),a,da,
947 grad_u,&u_grad_test_dV[i_nSpace],1.0,
948 u_trial_ref.data()[k*nDOF_trial_element+j],&u_grad_trial[j_nSpace]);
958 for (
int i=0;i<nDOF_test_element;i++)
960 int eN_i = eN*nDOF_test_element+i;
961 for (
int j=0;j<nDOF_trial_element;j++)
963 int eN_i_j = eN_i*nDOF_trial_element+j;
964 globalJacobian.data()[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_u_u[eN_i_j]] += elementJacobian_u_u[i][j];
971 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
973 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
974 register int eN = elementBoundaryElementsArray.data()[ebN*2+0],
975 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
976 eN_nDOF_trial_element = eN*nDOF_trial_element;
977 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
979 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
980 ebNE_kb_nSpace = ebNE_kb*nSpace,
981 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
982 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
984 register double u_ext=0.0,
1001 fluxJacobian_u_u[nDOF_trial_element],
1002 jac_ext[nSpace*nSpace],
1004 jacInv_ext[nSpace*nSpace],
1005 boundaryJac[nSpace*(nSpace-1)],
1006 metricTensor[(nSpace-1)*(nSpace-1)],
1007 metricTensorDetSqrt,
1009 u_test_dS[nDOF_test_element],
1010 u_grad_trial_trace[nDOF_trial_element*nSpace],
1011 normal[3],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
1012 G[nSpace*nSpace],G_dd_G,tr_G;
1016 ck.calculateMapping_elementBoundary(eN,
1022 mesh_trial_trace_ref.data(),
1023 mesh_grad_trial_trace_ref.data(),
1024 boundaryJac_ref.data(),
1030 metricTensorDetSqrt,
1034 ck.calculateMappingVelocity_elementBoundary(eN,
1038 mesh_velocity_dof.data(),
1040 mesh_trial_trace_ref.data(),
1041 xt_ext,yt_ext,zt_ext,
1046 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
1048 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1051 ck.gradTrialFromRef(&u_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1053 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);
1054 ck.gradFromDOF(u_dof.data(),&u_l2g.data()[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1056 for (
int j=0;j<nDOF_trial_element;j++)
1058 u_test_dS[j] = u_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
1063 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*ebqe_bc_u_ext.data()[ebNE_kb]+(1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
1072 alpha.data()[elementMaterialTypes.data()[eN]],
1073 n.data()[elementMaterialTypes.data()[eN]],
1074 thetaR.data()[elementMaterialTypes.data()[eN]],
1075 thetaSR.data()[elementMaterialTypes.data()[eN]],
1076 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
1089 alpha.data()[elementMaterialTypes.data()[eN]],
1090 n.data()[elementMaterialTypes.data()[eN]],
1091 thetaR.data()[elementMaterialTypes.data()[eN]],
1092 thetaSR.data()[elementMaterialTypes.data()[eN]],
1093 &KWs.data()[elementMaterialTypes.data()[eN]*
nnz],
1104 for (
int j=0;j<nDOF_trial_element;j++)
1107 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1110 isDOFBoundary_u.data()[ebNE_kb],
1115 &u_grad_trial_trace[j*nSpace],
1117 u_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element+j],
1118 ebqe_penalty_ext.data()[ebNE_kb],
1119 fluxJacobian_u_u[j]);
1124 for (
int i=0;i<nDOF_test_element;i++)
1126 register int eN_i = eN*nDOF_test_element+i;
1128 for (
int j=0;j<nDOF_trial_element;j++)
1131 globalJacobian.data()[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_eb_u_u[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i];
1140 int nQuadraturePoints_elementIn,
1141 int nDOF_mesh_trial_elementIn,
1142 int nDOF_trial_elementIn,
1143 int nDOF_test_elementIn,
1144 int nQuadraturePoints_elementBoundaryIn,
1147 return proteus::chooseAndAllocateDiscretization<Richards_base,Richards,CompKernel>(nSpaceIn,
1148 nQuadraturePoints_elementIn,
1149 nDOF_mesh_trial_elementIn,
1150 nDOF_trial_elementIn,
1151 nDOF_test_elementIn,
1152 nQuadraturePoints_elementBoundaryIn,