9 #include "xtensor-python/pyarray.hpp"
11 namespace py = pybind11;
36 double mu_fr_limiter){}
41 template<
class CompKernelType,
43 int nQuadraturePoints_element,
44 int nDOF_mesh_trial_element,
45 int nDOF_trial_element,
46 int nDOF_test_element,
47 int nQuadraturePoints_elementBoundary>
118 const double grad_k[nSpace],
119 const double grad_omega[nSpace],
120 const double grad_vx[nSpace],
121 const double grad_vy[nSpace],
122 double& inverse_sigma_k,
123 double& inverse_sigma_omega,
131 inverse_sigma_k = 2.0; inverse_sigma_omega=2.0; gamma = 13.0/25.0;
132 const double beta0_star = 0.09;
const double beta0 = 9.0/125.0;
133 double Omega[nSpace][nSpace] = {{0.,0.},
135 double S[nSpace][nSpace] = {{0.,0.},
140 Omega[0][1] = 0.5*(grad_vx[1]-grad_vy[0]);
141 Omega[1][0] =-Omega[0][1];
144 S[0][0] = grad_vx[0]; S[0][1] = 0.5*(grad_vx[1]+grad_vy[0]);
145 S[1][0] = S[0][1]; S[1][1] = grad_vy[1];
147 double chi_omega = 0.0;
148 for (
int i=0; i < nSpace; i++)
149 for (
int k=0; k < nSpace; k++)
150 for (
int j=0; j < nSpace; j++)
151 chi_omega += Omega[i][j]*Omega[j][k]*S[k][i];
153 if (fabs(omega) > div_eps)
155 chi_omega = fabs(chi_omega/(beta0_star*omega*beta0_star*omega*beta0_star*omega));
157 const double f_beta = (1.0+70.0*chi_omega)/(1.0 + 80.0*chi_omega);
165 double chi_k = grad_k[0]*grad_omega[0] + grad_k[1]*grad_omega[1];
166 double f_beta_star = 1.0;
168 const double omega3 = omega*omega*omega;
169 if (fabs(omega3) > div_eps)
171 chi_k = chi_k/omega3;
172 f_beta_star = (1.0 + 680.0*chi_k*chi_k)/(1.0 + 400.0*chi_k*chi_k);
174 else if (chi_k > 0.0)
175 f_beta_star = 680.0/400.0;
177 beta_star = beta0_star*f_beta_star;
182 beta = fmax(0.875*beta0,fmin(beta,beta0));
187 beta_star = fmax(beta0_star,fmin(beta_star,(680.0/400.0)*beta0_star));
199 const double sigma_k,
201 const double grad_vx[nSpace],
202 const double grad_vy[nSpace],
207 const double& porosity,
211 double q_vos_gradc[nSpace],
217 int dissipation_model_flag,
218 const double grad_k_old[nSpace],
219 const double grad_dissipation[nSpace],
230 double nu_t=0.0,dnu_t_dk=0.0,PiD4=0.0;
231 double gamma_k=0.0,F_k=0.0,sigma_a=sigma_k,kSed=0.,dkSed=0.;
233 const double isKEpsilon = (dissipation_model_flag>=2) ? 0.0 : 1.0;
237 for (
int I=0; I < nSpace; I++)
239 f[I] =
v[I]*k*porosity;
240 df[I] =
v[I]*porosity;
243 double nu = (1.0-H_mu)*
nu_0 + H_mu*
nu_1;
244 const double div_eps = 1.0e-2*fmin(
nu_0,
nu_1);
246 nu_t = isKEpsilon*c_mu*k_old*k_old/(fabs(dissipation)+div_eps)
247 + (1.0-isKEpsilon)*k_old/(fabs(dissipation)+div_eps);
253 nu_t = fmax(nu_t,1.e-4*nu);
255 nu_t = fmin(nu_t,1.0e6*nu);
260 PiD4 = 2.0*(grad_vx[0]*grad_vx[0] +
261 grad_vy[1]*grad_vy[1])
263 (grad_vx[1] + grad_vy[0])*(grad_vx[1] + grad_vy[0]);
266 double theta = 1e-10;
270 if (sedFlag == 1 && isKEpsilon > 0)
306 if (dissipation_model_flag==2)
309 double sigma_omega=1.,beta_star=1.,beta=1.,gamma=1.;
324 gamma_k=fmax(beta_star*dissipation,0.0);
327 else if (dissipation_model_flag==3)
330 double beta_star = 0.09;
331 gamma_k=fmax(beta_star*dissipation,0.0);
336 gamma_k = fmax(c_mu*k_old/nu_t,0.0);
341 a = porosity*(nu_t/sigma_a + nu);
342 da_dk = porosity*dnu_t_dk/sigma_a;
346 r = -porosity*F_k + porosity*gamma_k*k +porosity*kSed;
347 dr_dk = porosity*(gamma_k+dkSed);
355 const double dH[nSpace],
359 double h,nrm_v,oneByAbsdt;
362 for(
int I=0;I<nSpace;I++)
366 oneByAbsdt = fabs(dmt);
367 tau = 1.0/(2.0*nrm_v/h + oneByAbsdt + 1.0e-8);
373 const double G[nSpace*nSpace],
375 const double Ai[nSpace],
380 for(
int I=0;I<nSpace;I++)
381 for (
int J=0;J<nSpace;J++)
382 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
384 tau_v = 1.0/sqrt(Ct_sge*A0*A0 + v_d_Gv);
391 const double& elementDiameter,
392 const double& strong_residual,
393 const double grad_u[nSpace],
402 for (
int I=0;I<nSpace;I++)
403 n_grad_u += grad_u[I]*grad_u[I];
404 num = shockCapturingDiffusion*0.5*h*fabs(strong_residual);
405 den = sqrt(n_grad_u) + 1.0e-8;
411 const int& isAdvectiveFluxBoundary_u,
412 const double n[nSpace],
414 const double& bc_flux_u,
416 const double velocity[nSpace],
421 for (
int I=0; I < nSpace; I++)
422 flow +=
n[I]*velocity[I];
424 if (isDOFBoundary_u == 1)
438 else if (isAdvectiveFluxBoundary_u == 1)
471 H = 0.5*(1.0 +
phi/eps + sin(M_PI*
phi/eps)/M_PI);
477 const int& isAdvectiveFluxBoundary_u,
478 const double n[nSpace],
479 const double velocity[nSpace],
483 for (
int I=0; I < nSpace; I++)
484 flow +=
n[I]*velocity[I];
487 if (isDOFBoundary_u == 1)
498 else if (isAdvectiveFluxBoundary_u == 1)
512 const int& isDOFBoundary,
513 const int& isDiffusiveFluxBoundary,
517 double grad_psi[nSpace],
524 if (isDiffusiveFluxBoundary)
528 else if (isDOFBoundary)
531 for(
int I=0;I<nSpace;I++)
533 v_I = -a*grad_psi[I];
536 flux += penalty*(
u-bc_u);
546 const int& isDiffusiveFluxBoundary,
550 double grad_psi[nSpace],
551 const double grad_v[nSpace],
554 double& fluxJacobian)
556 if (isDiffusiveFluxBoundary == 0 && isDOFBoundary == 1)
559 for(
int I=0;I<nSpace;I++)
561 fluxJacobian -= (a*grad_v[I] + da*
v*grad_psi[I])*
n[I];
563 fluxJacobian += penalty*
v;
571 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
572 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
573 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
574 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
575 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
576 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
577 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
578 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
579 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
580 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
581 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
582 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
583 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
584 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
585 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
586 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
587 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
588 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
589 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
590 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
591 int nElements_global = args.
scalar<
int>(
"nElements_global");
594 double sigma_k = args.
scalar<
double>(
"sigma_k");
595 double c_mu = args.
scalar<
double>(
"c_mu");
598 double sedFlag = args.
scalar<
int>(
"sedFlag");
599 xt::pyarray<double>& q_vos = args.
array<
double>(
"q_vos");
600 xt::pyarray<double>& q_vos_gradc = args.
array<
double>(
"q_vos_gradc");
601 xt::pyarray<double>& ebqe_q_vos = args.
array<
double>(
"ebqe_q_vos");
602 xt::pyarray<double>& ebqe_q_vos_gradc = args.
array<
double>(
"ebqe_q_vos_gradc");
603 double rho_f = args.
scalar<
double>(
"rho_f");
604 double rho_s = args.
scalar<
double>(
"rho_s");
605 xt::pyarray<double>& vs = args.
array<
double>(
"vs");
606 xt::pyarray<double>& ebqe_vs = args.
array<
double>(
"ebqe_vs");
607 xt::pyarray<double>& g = args.
array<
double>(
"g");
608 int dissipation_model_flag = args.
scalar<
int>(
"dissipation_model_flag");
609 double useMetrics = args.
scalar<
double>(
"useMetrics");
610 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
611 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
612 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
613 double sc_uref = args.
scalar<
double>(
"sc_uref");
614 double sc_alpha = args.
scalar<
double>(
"sc_alpha");
615 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
616 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
617 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
618 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
619 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
620 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
621 xt::pyarray<double>& q_dissipation = args.
array<
double>(
"q_dissipation");
622 xt::pyarray<double>& q_grad_dissipation = args.
array<
double>(
"q_grad_dissipation");
623 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
624 xt::pyarray<double>& velocity_dof_u = args.
array<
double>(
"velocity_dof_u");
625 xt::pyarray<double>& velocity_dof_v = args.
array<
double>(
"velocity_dof_v");
626 xt::pyarray<double>& velocity_dof_w = args.
array<
double>(
"velocity_dof_w");
627 xt::pyarray<double>& q_m = args.
array<
double>(
"q_m");
628 xt::pyarray<double>& q_u = args.
array<
double>(
"q_u");
629 xt::pyarray<double>& q_grad_u = args.
array<
double>(
"q_grad_u");
630 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
631 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
632 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
633 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
634 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
635 int offset_u = args.
scalar<
int>(
"offset_u");
636 int stride_u = args.
scalar<
int>(
"stride_u");
637 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
638 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
639 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
640 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
641 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
642 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
643 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
644 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
645 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.
array<
int>(
"isAdvectiveFluxBoundary_u");
646 xt::pyarray<double>& ebqe_bc_advectiveFlux_u_ext = args.
array<
double>(
"ebqe_bc_advectiveFlux_u_ext");
647 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.
array<
int>(
"isDiffusiveFluxBoundary_u");
648 xt::pyarray<double>& ebqe_bc_diffusiveFlux_u_ext = args.
array<
double>(
"ebqe_bc_diffusiveFlux_u_ext");
649 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
650 double epsFact = args.
scalar<
double>(
"epsFact");
651 xt::pyarray<double>& ebqe_dissipation = args.
array<
double>(
"ebqe_dissipation");
652 xt::pyarray<double>& ebqe_porosity = args.
array<
double>(
"ebqe_porosity");
653 xt::pyarray<double>& ebqe_u = args.
array<
double>(
"ebqe_u");
654 xt::pyarray<double>& ebqe_flux = args.
array<
double>(
"ebqe_flux");
666 for(
int eN=0;eN<nElements_global;eN++)
669 register double elementResidual_u[nDOF_test_element];
670 for (
int i=0;i<nDOF_test_element;i++)
672 elementResidual_u[i]=0.0;
675 for (
int k=0;k<nQuadraturePoints_element;k++)
678 register int eN_k = eN*nQuadraturePoints_element+k,
679 eN_k_nSpace = eN_k*nSpace,
680 eN_nDOF_trial_element = eN*nDOF_trial_element;
681 register double u=0.0,u_old=0.0,grad_u[nSpace],grad_u_old[nSpace],
683 f[nSpace],
df[nSpace],df_minus_da_grad_u[nSpace],
687 grad_vx[nSpace],grad_vy[nSpace],
689 Lstar_u[nDOF_test_element],
691 tau=0.0,tau0=0.0,tau1=0.0,
692 numDiff0=0.0,numDiff1=0.0,
695 jacInv[nSpace*nSpace],
696 u_grad_trial[nDOF_trial_element*nSpace],
697 u_test_dV[nDOF_trial_element],
698 u_grad_test_dV[nDOF_test_element*nSpace],
700 G[nSpace*nSpace],G_dd_G,tr_G,norm_Rv;
720 ck.calculateMapping_element(eN,
724 mesh_trial_ref.data(),
725 mesh_grad_trial_ref.data(),
730 ck.calculateMappingVelocity_element(eN,
732 mesh_velocity_dof.data(),
734 mesh_trial_ref.data(),
737 dV = fabs(jacDet)*dV_ref[k];
738 ck.calculateG(jacInv,G,G_dd_G,tr_G);
740 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
742 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],
u);
743 ck.valFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],u_old);
746 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_u);
747 ck.gradFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_u_old);
750 ck.gradFromDOF(velocity_dof_u.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_vx);
751 ck.gradFromDOF(velocity_dof_v.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_vy);
757 for (
int j=0;j<nDOF_trial_element;j++)
759 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
760 for (
int I=0;I<nSpace;I++)
762 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
785 &q_vos_gradc[eN_k_nSpace],
791 dissipation_model_flag,
793 &q_grad_dissipation[eN_k_nSpace],
805 f[0] -= MOVING_DOMAIN*m*
xt;
806 f[1] -= MOVING_DOMAIN*m*yt;
808 df[0] -= MOVING_DOMAIN*dm*
xt;
809 df[1] -= MOVING_DOMAIN*dm*yt;
813 df_minus_da_grad_u[0] =
df[0] - da*grad_u[0];
814 df_minus_da_grad_u[1] =
df[1] - da*grad_u[1];
829 pdeResidual_u =
ck.Mass_strong(m_t) +
ck.Advection_strong(df_minus_da_grad_u,grad_u)
830 +
ck.Reaction_strong(
r);
832 for (
int i=0;i<nDOF_test_element;i++)
836 register int i_nSpace = i*nSpace;
837 Lstar_u[i] =
ck.Advection_adjoint(df_minus_da_grad_u,&u_grad_test_dV[i_nSpace]) +
838 ck.Reaction_adjoint(dr,u_test_dV[i]);
849 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
851 subgridError_u = -tau*pdeResidual_u;
857 ck.calculateNumericalDiffusion(shockCapturingDiffusion,elementDiameter[eN],pdeResidual_u,grad_u,numDiff0);
858 ck.calculateNumericalDiffusion(shockCapturingDiffusion,sc_uref, sc_alpha,G,G_dd_G,pdeResidual_u,grad_u,numDiff1);
859 q_numDiff_u[eN_k] = useMetrics*numDiff1+(1.0-useMetrics)*numDiff0;
864 for(
int i=0;i<nDOF_test_element;i++)
866 register int eN_k_i=eN_k*nDOF_test_element+i,
867 eN_k_i_nSpace = eN_k_i*nSpace,
870 elementResidual_u[i] +=
ck.Mass_weak(m_t,u_test_dV[i]) +
871 ck.Advection_weak(
f,&u_grad_test_dV[i_nSpace]) +
872 ck.SubgridError(subgridError_u,Lstar_u[i]) +
873 ck.NumericalDiffusion(a,grad_u,&u_grad_test_dV[i_nSpace]) +
874 ck.NumericalDiffusion(q_numDiff_u_last[eN_k],grad_u,&u_grad_test_dV[i_nSpace]) +
875 ck.Reaction_weak(
r,u_test_dV[i]);
885 for (
int I=0; I < nSpace; I++)
887 q_grad_u[eN_k_nSpace + I] = grad_u[I];
893 for(
int i=0;i<nDOF_test_element;i++)
895 register int eN_i=eN*nDOF_test_element+i;
897 globalResidual[offset_u+stride_u*u_l2g[eN_i]] += elementResidual_u[i];
906 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
908 register int ebN = exteriorElementBoundariesArray[ebNE],
909 eN = elementBoundaryElementsArray[ebN*2+0],
910 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
911 eN_nDOF_trial_element = eN*nDOF_trial_element;
912 register double elementResidual_u[nDOF_test_element];
913 for (
int i=0;i<nDOF_test_element;i++)
915 elementResidual_u[i]=0.0;
917 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
919 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
920 ebNE_kb_nSpace = ebNE_kb*nSpace,
921 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
922 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
923 register double u_ext=0.0,u_old_ext,
924 grad_u_ext[nSpace],grad_vx_ext[nSpace],grad_vy_ext[nSpace],
925 grad_u_old_ext[nSpace],grad_dissipation_ext_dummy[nSpace],
930 a_ext=0.0,da_ext=0.0,
931 r_ext=0.0,dr_ext=0.0,
933 diffusive_flux_ext=0.0,
935 bc_grad_u_ext[nSpace],
940 jac_ext[nSpace*nSpace],
942 jacInv_ext[nSpace*nSpace],
943 boundaryJac[nSpace*(nSpace-1)],
944 metricTensor[(nSpace-1)*(nSpace-1)],
947 u_test_dS[nDOF_test_element],
948 u_grad_trial_trace[nDOF_trial_element*nSpace],
949 normal[3],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
950 G[nSpace*nSpace],G_dd_G,tr_G;
955 ck.calculateMapping_elementBoundary(eN,
961 mesh_trial_trace_ref.data(),
962 mesh_grad_trial_trace_ref.data(),
963 boundaryJac_ref.data(),
973 ck.calculateMappingVelocity_elementBoundary(eN,
977 mesh_velocity_dof.data(),
979 mesh_trial_trace_ref.data(),
980 xt_ext,yt_ext,zt_ext,
985 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
988 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
991 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
993 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_ext);
994 ck.valFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_old_ext);
995 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
996 ck.gradFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_old_ext);
999 grad_dissipation_ext_dummy[0] = 0.0; grad_dissipation_ext_dummy[1] = 0.0;
1002 ck.gradFromDOF(velocity_dof_u.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_vx_ext);
1003 ck.gradFromDOF(velocity_dof_v.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_vy_ext);
1008 for (
int j=0;j<nDOF_trial_element;j++)
1010 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
1015 bc_u_ext = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*u_ext;
1031 ebqe_dissipation[ebNE_kb],
1032 ebqe_porosity[ebNE_kb],
1035 ebqe_q_vos[ebNE_kb],
1036 &ebqe_q_vos_gradc[ebNE_kb_nSpace],
1039 &ebqe_vs[ebNE_kb_nSpace],
1042 dissipation_model_flag,
1044 grad_dissipation_ext_dummy,
1065 ebqe_dissipation[ebNE_kb],
1066 ebqe_porosity[ebNE_kb],
1069 ebqe_q_vos[ebNE_kb],
1070 &ebqe_q_vos_gradc[ebNE_kb_nSpace],
1073 &ebqe_vs[ebNE_kb_nSpace],
1076 dissipation_model_flag,
1078 grad_dissipation_ext_dummy,
1090 double velocity_ext[nSpace];
1091 velocity_ext[0] = ebqe_velocity_ext[ebNE_kb_nSpace+0] - MOVING_DOMAIN*xt_ext;
1092 velocity_ext[1] = ebqe_velocity_ext[ebNE_kb_nSpace+1] - MOVING_DOMAIN*yt_ext;
1098 isAdvectiveFluxBoundary_u[ebNE_kb],
1101 ebqe_bc_advectiveFlux_u_ext[ebNE_kb],
1107 const double bc_diffusive_flux = ebqe_bc_diffusiveFlux_u_ext[ebNE_kb];
1109 isDOFBoundary_u[ebNE_kb],
1110 isDiffusiveFluxBoundary_u[ebNE_kb],
1116 ebqe_penalty_ext[ebNE_kb],
1117 diffusive_flux_ext);
1120 flux_ext += diffusive_flux_ext;
1121 ebqe_flux[ebNE_kb] = flux_ext;
1124 ebqe_u[ebNE_kb] = u_ext;
1126 ebqe_u[ebNE_kb] = bc_u_ext;
1130 for (
int i=0;i<nDOF_test_element;i++)
1132 int ebNE_kb_i = ebNE_kb*nDOF_test_element+i;
1134 elementResidual_u[i] +=
ck.ExteriorElementBoundaryFlux(flux_ext,u_test_dS[i]);
1140 for (
int i=0;i<nDOF_test_element;i++)
1142 int eN_i = eN*nDOF_test_element+i;
1144 globalResidual[offset_u+stride_u*u_l2g[eN_i]] += elementResidual_u[i];
1151 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1152 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1153 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1154 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1155 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1156 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1157 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1158 xt::pyarray<double>& u_trial_ref = args.
array<
double>(
"u_trial_ref");
1159 xt::pyarray<double>& u_grad_trial_ref = args.
array<
double>(
"u_grad_trial_ref");
1160 xt::pyarray<double>& u_test_ref = args.
array<
double>(
"u_test_ref");
1161 xt::pyarray<double>& u_grad_test_ref = args.
array<
double>(
"u_grad_test_ref");
1162 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1163 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1164 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1165 xt::pyarray<double>& u_trial_trace_ref = args.
array<
double>(
"u_trial_trace_ref");
1166 xt::pyarray<double>& u_grad_trial_trace_ref = args.
array<
double>(
"u_grad_trial_trace_ref");
1167 xt::pyarray<double>& u_test_trace_ref = args.
array<
double>(
"u_test_trace_ref");
1168 xt::pyarray<double>& u_grad_test_trace_ref = args.
array<
double>(
"u_grad_test_trace_ref");
1169 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1170 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1171 int nElements_global = args.
scalar<
int>(
"nElements_global");
1174 double sigma_k = args.
scalar<
double>(
"sigma_k");
1175 double c_mu = args.
scalar<
double>(
"c_mu");
1178 int dissipation_model_flag = args.
scalar<
int>(
"dissipation_model_flag");
1179 double useMetrics = args.
scalar<
double>(
"useMetrics");
1180 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1181 int lag_shockCapturing = args.
scalar<
int>(
"lag_shockCapturing");
1182 double shockCapturingDiffusion = args.
scalar<
double>(
"shockCapturingDiffusion");
1183 xt::pyarray<int>& u_l2g = args.
array<
int>(
"u_l2g");
1184 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1185 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1186 xt::pyarray<double>& u_dof_old = args.
array<
double>(
"u_dof_old");
1187 xt::pyarray<double>& velocity = args.
array<
double>(
"velocity");
1188 xt::pyarray<double>& phi_ls = args.
array<
double>(
"phi_ls");
1189 xt::pyarray<double>& q_dissipation = args.
array<
double>(
"q_dissipation");
1190 xt::pyarray<double>& q_grad_dissipation = args.
array<
double>(
"q_grad_dissipation");
1191 xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1192 double sedFlag = args.
scalar<
int>(
"sedFlag");
1193 xt::pyarray<double>& q_vos = args.
array<
double>(
"q_vos");
1194 xt::pyarray<double>& q_vos_gradc = args.
array<
double>(
"q_vos_gradc");
1195 xt::pyarray<double>& ebqe_q_vos = args.
array<
double>(
"ebqe_q_vos");
1196 xt::pyarray<double>& ebqe_q_vos_gradc = args.
array<
double>(
"ebqe_q_vos_gradc");
1197 double rho_f = args.
scalar<
double>(
"rho_f");
1198 double rho_s = args.
scalar<
double>(
"rho_s");
1199 xt::pyarray<double>& vs = args.
array<
double>(
"vs");
1200 xt::pyarray<double>& ebqe_vs = args.
array<
double>(
"ebqe_vs");
1201 xt::pyarray<double>& g = args.
array<
double>(
"g");
1202 xt::pyarray<double>& velocity_dof_u = args.
array<
double>(
"velocity_dof_u");
1203 xt::pyarray<double>& velocity_dof_v = args.
array<
double>(
"velocity_dof_v");
1204 xt::pyarray<double>& velocity_dof_w = args.
array<
double>(
"velocity_dof_w");
1205 xt::pyarray<double>& q_m_betaBDF = args.
array<
double>(
"q_m_betaBDF");
1206 xt::pyarray<double>& cfl = args.
array<
double>(
"cfl");
1207 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1208 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
1209 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
1210 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
1211 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
1212 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1213 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1214 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1215 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1216 xt::pyarray<double>& ebqe_velocity_ext = args.
array<
double>(
"ebqe_velocity_ext");
1217 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1218 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1219 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.
array<
int>(
"isAdvectiveFluxBoundary_u");
1220 xt::pyarray<double>& ebqe_bc_advectiveFlux_u_ext = args.
array<
double>(
"ebqe_bc_advectiveFlux_u_ext");
1221 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.
array<
int>(
"isDiffusiveFluxBoundary_u");
1222 xt::pyarray<double>& ebqe_bc_diffusiveFlux_u_ext = args.
array<
double>(
"ebqe_bc_diffusiveFlux_u_ext");
1223 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
1224 xt::pyarray<double>& ebqe_phi = args.
array<
double>(
"ebqe_phi");
1225 double epsFact = args.
scalar<
double>(
"epsFact");
1226 xt::pyarray<double>& ebqe_dissipation = args.
array<
double>(
"ebqe_dissipation");
1227 xt::pyarray<double>& ebqe_porosity = args.
array<
double>(
"ebqe_porosity");
1228 double Ct_sge = 4.0;
1232 for(
int eN=0;eN<nElements_global;eN++)
1234 register double elementJacobian_u_u[nDOF_test_element][nDOF_trial_element];
1235 for (
int i=0;i<nDOF_test_element;i++)
1236 for (
int j=0;j<nDOF_trial_element;j++)
1238 elementJacobian_u_u[i][j]=0.0;
1240 for (
int k=0;k<nQuadraturePoints_element;k++)
1242 int eN_k = eN*nQuadraturePoints_element+k,
1243 eN_k_nSpace = eN_k*nSpace,
1244 eN_nDOF_trial_element = eN*nDOF_trial_element;
1247 register double u=0.0,u_old,
1248 grad_u[nSpace],grad_vx[nSpace],grad_vy[nSpace],grad_u_old[nSpace],
1249 m=0.0,dm=0.0,a=0.0,da=0.0,
r=0.0,dr=0.0,
1250 f[nSpace],
df[nSpace],df_minus_da_grad_u[nSpace],
1252 dpdeResidual_u_u[nDOF_trial_element],
1253 Lstar_u[nDOF_test_element],
1254 dsubgridError_u_u[nDOF_trial_element],
1255 tau=0.0,tau0=0.0,tau1=0.0,
1258 jacInv[nSpace*nSpace],
1259 u_grad_trial[nDOF_trial_element*nSpace],
1261 u_test_dV[nDOF_test_element],
1262 u_grad_test_dV[nDOF_test_element*nSpace],
1264 G[nSpace*nSpace],G_dd_G,tr_G;
1286 ck.calculateMapping_element(eN,
1290 mesh_trial_ref.data(),
1291 mesh_grad_trial_ref.data(),
1296 ck.calculateMappingVelocity_element(eN,
1298 mesh_velocity_dof.data(),
1300 mesh_trial_ref.data(),
1303 dV = fabs(jacDet)*dV_ref[k];
1304 ck.calculateG(jacInv,G,G_dd_G,tr_G);
1306 ck.gradTrialFromRef(&u_grad_trial_ref[k*nDOF_trial_element*nSpace],jacInv,u_grad_trial);
1308 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],
u);
1309 ck.valFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_ref[k*nDOF_trial_element],u_old);
1311 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_u);
1314 ck.gradFromDOF(velocity_dof_u.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_vx);
1315 ck.gradFromDOF(velocity_dof_v.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial,grad_vy);
1320 for (
int j=0;j<nDOF_trial_element;j++)
1322 u_test_dV[j] = u_test_ref[k*nDOF_trial_element+j]*dV;
1323 for (
int I=0;I<nSpace;I++)
1325 u_grad_test_dV[j*nSpace+I] = u_grad_trial[j*nSpace+I]*dV;
1343 q_dissipation[eN_k],
1348 &q_vos_gradc[eN_k_nSpace],
1354 dissipation_model_flag,
1356 &q_grad_dissipation[eN_k_nSpace],
1368 f[0] -= MOVING_DOMAIN*m*
xt;
1369 f[1] -= MOVING_DOMAIN*m*yt;
1371 df[0] -= MOVING_DOMAIN*dm*
xt;
1372 df[1] -= MOVING_DOMAIN*dm*yt;
1378 df_minus_da_grad_u[0] =
df[0] - da*grad_u[0];
1379 df_minus_da_grad_u[1] =
df[1] - da*grad_u[1];
1395 for (
int i=0;i<nDOF_test_element;i++)
1399 register int i_nSpace = i*nSpace;
1400 Lstar_u[i]=
ck.Advection_adjoint(df_minus_da_grad_u,&u_grad_test_dV[i_nSpace])
1401 +
ck.Reaction_adjoint(dr,u_test_dV[i]);
1404 for (
int j=0;j<nDOF_trial_element;j++)
1408 int j_nSpace = j*nSpace;
1409 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dm_t,u_trial_ref[k*nDOF_trial_element+j]) +
1410 ck.AdvectionJacobian_strong(df_minus_da_grad_u,&u_grad_trial[j_nSpace]) +
1411 ck.ReactionJacobian_strong(dr,u_trial_ref[k*nDOF_trial_element+j]);
1426 tau = useMetrics*tau1+(1.0-useMetrics)*tau0;
1428 for(
int j=0;j<nDOF_trial_element;j++)
1429 dsubgridError_u_u[j] = -tau*dpdeResidual_u_u[j];
1430 for(
int i=0;i<nDOF_test_element;i++)
1434 for(
int j=0;j<nDOF_trial_element;j++)
1438 int j_nSpace = j*nSpace;
1439 int i_nSpace = i*nSpace;
1440 elementJacobian_u_u[i][j] +=
ck.MassJacobian_weak(dm_t,u_trial_ref[k*nDOF_trial_element+j],u_test_dV[i]) +
1441 ck.AdvectionJacobian_weak(df_minus_da_grad_u,u_trial_ref[k*nDOF_trial_element+j],&u_grad_test_dV[i_nSpace]) +
1442 ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u[i]) +
1443 ck.NumericalDiffusionJacobian(a,&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]) +
1444 ck.NumericalDiffusionJacobian(q_numDiff_u_last[eN_k],&u_grad_trial[j_nSpace],&u_grad_test_dV[i_nSpace]) +
1445 ck.ReactionJacobian_weak(dr,u_trial_ref[k*nDOF_trial_element+j],u_test_dV[i]);
1452 for (
int i=0;i<nDOF_test_element;i++)
1454 int eN_i = eN*nDOF_test_element+i;
1455 for (
int j=0;j<nDOF_trial_element;j++)
1457 int eN_i_j = eN_i*nDOF_trial_element+j;
1458 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_u_u[eN_i_j]] += elementJacobian_u_u[i][j];
1465 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
1467 register int ebN = exteriorElementBoundariesArray[ebNE];
1468 register int eN = elementBoundaryElementsArray[ebN*2+0],
1469 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+0],
1470 eN_nDOF_trial_element = eN*nDOF_trial_element;
1471 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
1473 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
1474 ebNE_kb_nSpace = ebNE_kb*nSpace,
1475 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
1476 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
1478 register double u_ext=0.0,u_old_ext=0.0,
1480 grad_vx_ext[nSpace],grad_vy_ext[nSpace],
1481 grad_u_old_ext[nSpace],grad_dissipation_ext_dummy[nSpace],
1487 a_ext=0.0,da_ext=0.0,r_ext=0.0,dr_ext=0.0,
1494 fluxJacobian_u_u[nDOF_trial_element],
1495 diffusiveFluxJacobian_u_u[nDOF_trial_element],
1496 jac_ext[nSpace*nSpace],
1498 jacInv_ext[nSpace*nSpace],
1499 boundaryJac[nSpace*(nSpace-1)],
1500 metricTensor[(nSpace-1)*(nSpace-1)],
1501 metricTensorDetSqrt,
1503 u_test_dS[nDOF_test_element],
1504 u_grad_trial_trace[nDOF_trial_element*nSpace],
1505 normal[3],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
1506 G[nSpace*nSpace],G_dd_G,tr_G;
1528 ck.calculateMapping_elementBoundary(eN,
1534 mesh_trial_trace_ref.data(),
1535 mesh_grad_trial_trace_ref.data(),
1536 boundaryJac_ref.data(),
1542 metricTensorDetSqrt,
1546 ck.calculateMappingVelocity_elementBoundary(eN,
1550 mesh_velocity_dof.data(),
1552 mesh_trial_trace_ref.data(),
1553 xt_ext,yt_ext,zt_ext,
1558 dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref[kb];
1560 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
1563 ck.gradTrialFromRef(&u_grad_trial_trace_ref[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,u_grad_trial_trace);
1565 ck.valFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_ext);
1566 ck.valFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],&u_trial_trace_ref[ebN_local_kb*nDOF_test_element],u_old_ext);
1567 ck.gradFromDOF(u_dof.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_ext);
1568 ck.gradFromDOF(u_dof_old.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_u_old_ext);
1571 grad_dissipation_ext_dummy[0] = 0.0; grad_dissipation_ext_dummy[1] = 0.0;
1574 ck.gradFromDOF(velocity_dof_u.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_vx_ext);
1575 ck.gradFromDOF(velocity_dof_v.data(),&u_l2g[eN_nDOF_trial_element],u_grad_trial_trace,grad_vy_ext);
1580 for (
int j=0;j<nDOF_trial_element;j++)
1582 u_test_dS[j] = u_test_trace_ref[ebN_local_kb*nDOF_test_element+j]*dS;
1587 bc_u_ext = isDOFBoundary_u[ebNE_kb]*ebqe_bc_u_ext[ebNE_kb]+(1-isDOFBoundary_u[ebNE_kb])*u_ext;
1603 ebqe_dissipation[ebNE_kb],
1604 ebqe_porosity[ebNE_kb],
1607 ebqe_q_vos[ebNE_kb],
1608 &ebqe_q_vos_gradc[ebNE_kb_nSpace],
1611 &ebqe_vs[ebNE_kb_nSpace],
1614 dissipation_model_flag,
1616 grad_dissipation_ext_dummy,
1637 ebqe_dissipation[ebNE_kb],
1638 ebqe_porosity[ebNE_kb],
1641 ebqe_q_vos[ebNE_kb],
1642 &ebqe_q_vos_gradc[ebNE_kb_nSpace],
1645 &ebqe_vs[ebNE_kb_nSpace],
1648 dissipation_model_flag,
1650 grad_dissipation_ext_dummy,
1662 double velocity_ext[nSpace];
1663 velocity_ext[0] = ebqe_velocity_ext[ebNE_kb_nSpace+0] - MOVING_DOMAIN*xt_ext;
1664 velocity_ext[1] = ebqe_velocity_ext[ebNE_kb_nSpace+1] - MOVING_DOMAIN*yt_ext;
1670 isAdvectiveFluxBoundary_u[ebNE_kb],
1677 for (
int j=0;j<nDOF_trial_element;j++)
1680 register int ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
1683 isDiffusiveFluxBoundary_u[ebNE_kb],
1688 &u_grad_trial_trace[j*nSpace],
1689 u_trial_trace_ref[ebN_local_kb_j],
1690 ebqe_penalty_ext[ebNE_kb],
1691 diffusiveFluxJacobian_u_u[j]);
1694 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_u_u_ext,u_trial_trace_ref[ebN_local_kb_j]);
1699 for (
int i=0;i<nDOF_test_element;i++)
1701 register int eN_i = eN*nDOF_test_element+i;
1703 for (
int j=0;j<nDOF_trial_element;j++)
1707 globalJacobian[csrRowIndeces_u_u[eN_i] + csrColumnOffsets_eb_u_u[ebN_i_j]] += fluxJacobian_u_u[j]*u_test_dS[i]
1708 + diffusiveFluxJacobian_u_u[j]*u_test_dS[i];
1717 int nQuadraturePoints_elementIn,
1718 int nDOF_mesh_trial_elementIn,
1719 int nDOF_trial_elementIn,
1720 int nDOF_test_elementIn,
1721 int nQuadraturePoints_elementBoundaryIn,
1726 double packFraction,
1739 double mu_fr_limiter)
1743 proteus::chooseAndAllocateDiscretization2D<Kappa2D_base,Kappa2D,CompKernel>
1745 nQuadraturePoints_elementIn,
1746 nDOF_mesh_trial_elementIn,
1747 nDOF_trial_elementIn,
1748 nDOF_test_elementIn,
1749 nQuadraturePoints_elementBoundaryIn,