13 #include "xtensor/xarray.hpp"
14 #include "xtensor/xview.hpp"
15 #include "xtensor/xfixed.hpp"
16 #include "xtensor-python/pyarray.hpp"
20 namespace py = pybind11;
22 #define ZEROVEC {0.,0.}
31 inline double enorm(
double*
v)
33 return std::sqrt(
v[0]*
v[0] +
v[1]*
v[1] +
v[2]*
v[2]);
35 inline double rnorm(
double*
r)
38 for (
int i=0;i<18;i++)
40 return std::sqrt(
rnorm);
42 inline void F6DOF(
double DT,
double mass,
double* Iref,
double* last_u,
double* FT,
double* last_FT,
double* last_mom,
double*
u,
43 double* mom,
double*
r,
double* J)
48 *last_omega = &last_u[3],
53 register double Omega[9] = { 0.0, -omega[2], omega[1],
54 omega[2], 0.0, -omega[0],
55 -omega[1], omega[0], 0.0},
56 last_Omega[9] = { 0.0, -last_omega[2], last_omega[1],
57 last_omega[2], 0.0, -last_omega[0],
58 -last_omega[1], last_omega[0], 0.0},
60 for (
int i=0;i<18;i++)
63 for (
int j=0;j<18;j++)
67 for (
int i=0; i < 3; i++)
68 for (
int j=0; j < 3; j++)
69 for (
int k=0; k < 3; k++)
70 I[i*3 + j] +=
Q[i*3 + k]*Iref[k*3 +j];
71 for (
int i=0; i < 3; i++)
72 for (
int j=0; j < 3; j++)
73 for (
int k=0; k < 3; k++)
74 I[i*3 + j] += I[i*3 + k]*
Q[j*3 + k];
76 for (
int i=0; i< 3; i++)
81 for (
int j=0; j<3; j++)
83 M[(3+i)*6 + (3+j)] = I[i*3 + j];
84 mom[3+i] += I[i*3 + j]*
u[3+j];
91 for (
int i=0; i < 6; i++)
93 r[i] = - last_mom[i] - DT*0.5*(FT[i] + last_FT[i]);
94 for (
int j=0; j < 6; j++)
96 r[i] += M[i*6 + j]*
u[j];
97 J[i*18 + j] = M[i*6 + j];
101 for (
int i=0; i < 3; i++)
103 r[6+i] = h[i] - last_h[i] - DT*0.5*(
v[i] + last_v[i]);
104 J[(6+i)*18 + (6+i)] = 1.0;
105 J[(6+i)*18 + i] = -DT*0.5;
108 for (
int i=0; i < 3; i++)
109 for (
int j=0; j < 3; j++)
111 r[9 + i*3 + j] =
Q[i*3 + j] - last_Q[i*3 + j];
112 J[(9+i*3+j)*18 + (9+i*3+j)] = 1.0;
113 for (
int k=0; k < 3; k++)
115 r[9 + i*3 + j] -= DT*0.25*(Omega[i*3 + k] + last_Omega[i*3 +k])*(
Q[k*3 + j]+last_Q[k*3 + j]);
116 J[(9 + i*3 + j)*18 + 9+k*3+j] -= DT*0.25*(Omega[i*3 + k] + last_Omega[i*3 + k]);
121 template<
int nSpace,
int nP,
int nQ,
int nEBQ>
136 py::gil_scoped_release release;
138 xt::pyarray<double>& ball_FT = args.
array<
double>(
"ball_FT");
139 xt::pyarray<double>& ball_last_FT = args.
array<
double>(
"ball_last_FT");
140 xt::pyarray<double>& ball_h = args.
array<
double>(
"ball_h");
141 xt::pyarray<double>& ball_last_h = args.
array<
double>(
"ball_last_h");
142 xt::pyarray<double>& ball_center = args.
array<
double>(
"ball_center");
143 xt::pyarray<double>& ball_center_last = args.
array<
double>(
"ball_center_last");
145 xt::pyarray<double>& ball_velocity = args.
array<
double>(
"ball_velocity");
146 xt::pyarray<double>& ball_angular_velocity = args.
array<
double>(
"ball_angular_velocity");
148 xt::pyarray<double>& ball_last_velocity = args.
array<
double>(
"ball_last_velocity");
149 xt::pyarray<double>& ball_last_angular_velocity = args.
array<
double>(
"ball_last_angular_velocity");
150 xt::pyarray<double>& ball_Q = args.
array<
double>(
"ball_Q");
151 xt::pyarray<double>& ball_last_Q = args.
array<
double>(
"ball_last_Q");
152 xt::pyarray<double>& ball_Omega = args.
array<
double>(
"ball_Omega");
153 xt::pyarray<double>& ball_last_Omega = args.
array<
double>(
"ball_last_Omega");
154 xt::pyarray<double>& ball_u = args.
array<
double>(
"ball_u");
155 xt::pyarray<double>& ball_last_u = args.
array<
double>(
"ball_last_u");
156 xt::pyarray<double>& ball_mom = args.
array<
double>(
"ball_mom");
157 xt::pyarray<double>& ball_last_mom = args.
array<
double>(
"ball_last_mom");
158 xt::pyarray<double>& ball_a = args.
array<
double>(
"ball_a");
159 xt::pyarray<double>& ball_I = args.
array<
double>(
"ball_I");
160 xt::pyarray<double>& ball_mass = args.
array<
double>(
"ball_mass");
161 xt::pyarray<double>& ball_radius = args.
array<
double>(
"ball_radius");
162 xt::pyarray<double>& ball_f = args.
array<
double>(
"ball_f");
163 xt::pyarray<double>& wall_f = args.
array<
double>(
"wall_f");
164 xt::pyarray<double>& particle_netForces = args.
array<
double>(
"particle_netForces");
165 xt::pyarray<double>& particle_netMoments = args.
array<
double>(
"particle_netMoments");
166 xt::pyarray<double>& last_particle_netForces = args.
array<
double>(
"last_particle_netForces");
167 xt::pyarray<double>& last_particle_netMoments = args.
array<
double>(
"last_particle_netMoments");
168 xt::pyarray<double>& g = args.
array<
double>(
"g");
169 xt::pyarray<double>&
L = args.
array<
double>(
"L");
170 const double ball_force_range = args.
scalar<
double>(
"ball_force_range");
171 const double ball_stiffness = args.
scalar<
double>(
"ball_stiffness");
172 const double particle_cfl = args.
scalar<
double>(
"particle_cfl");
173 const double dt = args.
scalar<
double>(
"dt");
174 double& min_dt(*args.
array<
double>(
"min_dt").data());
175 int& nSteps(*args.
array<
int>(
"nSteps").data());
176 const int nParticles = ball_center.shape(0);
184 xt::xarray<double> cfl=xt::zeros<double>({nParticles});
185 #pragma omp parallel for
186 for (
int ip=0; ip < nParticles; ip++)
187 for (
int i=0; i < 3; i++)
189 ball_velocity(ip,i) = 0.0;
190 ball_angular_velocity(ip,i) = 0.0;
197 #pragma omp parallel for
198 for (
int ip=0; ip < nParticles; ip++)
200 double vnorm =
enorm(&ball_last_velocity.data()[ip*3]);
201 double vp[3], vpnorm;
202 for (
int i=0; i< 3; i++)
204 ball_last_FT(ip, i) = particle_netForces(ip,i) + ball_mass(ip)*g[i] + ball_f(ip,i) + wall_f(ip,i);
205 ball_last_FT(ip, 3+i) = particle_netMoments(ip,i);
206 vp[i] = ball_last_velocity(ip,i) + ball_a(ip,i)*DT;
209 double wall_range = 2.0*ball_radius(ip) + ball_force_range;
210 double wall_stiffness = ball_stiffness/2.0;
211 double dx0 = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,0))));
212 double dxL = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,0)-
L(0))));
213 wall_f(ip,0) = (1.0/wall_stiffness)*( pow(wall_range - dx0,2) * (fmax(0.0, ball_center(ip,0)) + ball_radius(ip)) +
214 pow(wall_range - dxL,2) * (fmin(
L(0), ball_center(ip,0)) - (
L(0) + ball_radius(ip))));
215 double dy0 = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,1))));
216 double dyL = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,1)-
L(1))));
217 wall_f(ip,1) = (1.0/wall_stiffness)*( pow(wall_range - dy0,2) * (fmax(0.0, ball_center(ip,1)) + ball_radius(ip)) +
218 pow(wall_range - dyL,2) * (fmin(
L(1), ball_center(ip,1)) - (
L(1) + ball_radius(ip))));
221 for (
int i=0; i< 3;i++)
223 for (
int jp=0; jp < nParticles; jp++)
225 double ball_range, d;
226 double f[3], h_ipjp[3];
227 ball_range = ball_radius(ip) + ball_radius(jp) + ball_force_range;
229 h_ipjp[i] = ball_center(ip,i) - ball_center(jp,i);
230 d = ball_range - fmin(ball_range, fmax(ball_radius(ip) + ball_radius(jp),
enorm(h_ipjp)));
231 for (
int i=0;i<3;i++)
232 f[i] = (1.0/ball_stiffness)*h_ipjp[i]*pow(d,2.0);
234 for (
int i=0;i<3;i++)
235 ball_f(ip,i) +=
f[i];
237 cfl(ip) = fmax(vnorm*DT/ball_force_range, vpnorm*DT/ball_force_range);
239 double max_cfl = xt::amax(cfl,{0})(0);
240 if (max_cfl > particle_cfl)
241 DT = (particle_cfl/max_cfl)*DT;
242 if (DT > dt - td - dt*1.0e-8)
249 min_dt =fmin(DT, min_dt);
251 #pragma omp parallel for
252 for (
int ip=0; ip < nParticles; ip++)
257 for (
int i=0; i<3; i++)
259 ball_FT(ip, i) = particle_netForces(ip, i) + ball_mass(ip)*g[i] + ball_f(ip, i) + wall_f(ip, i);
260 ball_FT(ip, 3+i) = particle_netMoments(ip, i);
262 F6DOF(DT, ball_mass(ip), &ball_I.data()[ip*9], &ball_last_u.data()[ip*18], &ball_FT.data()[ip*6], &ball_last_FT.data()[ip*6], &ball_last_mom.data()[ip*6], &ball_u.data()[ip*18],
263 &ball_mom.data()[ip*6],
r, J);
266 while ((its==0 ||
rnorm(
r) > 1.0e-10) && its < maxits)
268 int info,N=18,nrhs=1;
270 dgetrf_(&N,&N,J,&N,pivots,&info);
271 dgetrs_(&trans, &N,&nrhs,J,&N,pivots,
r,&N,&info);
272 for (
int i=0;i<18;i++)
273 ball_u(ip,i) -=
r[i];
274 F6DOF(DT, ball_mass(ip), &ball_I.data()[ip*9], &ball_last_u.data()[ip*18], &ball_FT.data()[ip*6], &ball_last_FT.data()[ip*6], &ball_last_mom.data()[ip*6], &ball_u.data()[ip*18],
275 &ball_mom.data()[ip*6],
r, J);
278 for (
int i=0; i< 3; i++)
280 ball_center(ip,i) += (ball_u(ip,6+i) - ball_last_u(ip,6+i));
281 ball_a(ip,i) = (ball_u(ip,i) - ball_last_velocity(ip,i))/DT;
282 ball_last_velocity(ip,i) = ball_u(ip,i);
283 ball_last_mom(ip,i) = ball_mom(ip,i);
284 ball_last_mom(ip,3+i) = ball_mom(ip,3+i);
286 ball_velocity(ip,i) += DT*ball_u(ip,i)/dt;
287 ball_angular_velocity(ip,i) += DT*ball_u(ip,3+i)/dt;
289 for (
int i=0; i< 18; i++)
290 ball_last_u(ip,i) = ball_u(ip,i);
296 template<
class CompKernelType,
297 class CompKernelType_v,
299 int nQuadraturePoints_element,
300 int nDOF_mesh_trial_element,
301 int nDOF_trial_element,
302 int nDOF_test_element,
303 int nDOF_v_trial_element,
304 int nDOF_v_test_element,
305 int nQuadraturePoints_elementBoundary>
337 const double smagorinskyConstant,
338 const int turbulenceClosureModel,
339 const double g[nSpace],
343 const double n[nSpace],
345 const double porosity,
346 const double phi_solid,
351 const double grad_p_old[nSpace],
352 const double grad_u_old[nSpace],
353 const double grad_v_old[nSpace],
354 const double grad_w_old[nSpace],
356 const double grad_p[nSpace],
357 const double grad_u[nSpace],
358 const double grad_v[nSpace],
359 const double grad_w[nSpace],
363 const double LAG_LES,
364 double& eddy_viscosity,
365 double& eddy_viscosity_last,
367 double& dmom_u_acc_u,
369 double& dmom_v_acc_v,
371 double& dmom_w_acc_w,
372 double mass_adv[nSpace],
373 double dmass_adv_u[nSpace],
374 double dmass_adv_v[nSpace],
375 double dmass_adv_w[nSpace],
376 double mom_u_adv[nSpace],
377 double dmom_u_adv_u[nSpace],
378 double dmom_u_adv_v[nSpace],
379 double dmom_u_adv_w[nSpace],
380 double mom_v_adv[nSpace],
381 double dmom_v_adv_u[nSpace],
382 double dmom_v_adv_v[nSpace],
383 double dmom_v_adv_w[nSpace],
384 double mom_w_adv[nSpace],
385 double dmom_w_adv_u[nSpace],
386 double dmom_w_adv_v[nSpace],
387 double dmom_w_adv_w[nSpace],
388 double mom_uu_diff_ten[nSpace],
389 double mom_vv_diff_ten[nSpace],
390 double mom_ww_diff_ten[nSpace],
391 double mom_uv_diff_ten[1],
392 double mom_uw_diff_ten[1],
393 double mom_vu_diff_ten[1],
394 double mom_vw_diff_ten[1],
395 double mom_wu_diff_ten[1],
396 double mom_wv_diff_ten[1],
397 double& mom_u_source,
398 double& mom_v_source,
399 double& mom_w_source,
401 double dmom_u_ham_grad_p[nSpace],
402 double dmom_u_ham_grad_u[nSpace],
403 double& dmom_u_ham_u,
404 double& dmom_u_ham_v,
405 double& dmom_u_ham_w,
407 double dmom_v_ham_grad_p[nSpace],
408 double dmom_v_ham_grad_v[nSpace],
409 double& dmom_v_ham_u,
410 double& dmom_v_ham_v,
411 double& dmom_v_ham_w,
413 double dmom_w_ham_grad_p[nSpace],
414 double dmom_w_ham_grad_w[nSpace],
415 double& dmom_w_ham_u,
416 double& dmom_w_ham_v,
417 double& dmom_w_ham_w,
422 double mu,norm_n,nu_t;
424 switch (turbulenceClosureModel)
429 norm_S = sqrt(2.0*(grad_u[0]*grad_u[0] + grad_v[1]*grad_v[1] +
430 0.5*(grad_u[1]+grad_v[0])*(grad_u[1]+grad_v[0])));
431 nu_t = smagorinskyConstant*smagorinskyConstant*h_e*h_e*norm_S;
437 norm_S = sqrt(2.0*(grad_u[0]*grad_u[0] + grad_v[1]*grad_v[1] +
438 0.5*(grad_u[1]+grad_v[0])*(grad_u[1]+grad_v[0])));
439 re = h_e*h_e*norm_S/nu;
441 cs=0.027*pow(10.0,-3.23*pow(re,-0.92));
442 nu_t =
cs*h_e*h_e*norm_S;
450 eddy_viscosity = nu_t;
451 nu += (1.0-LAG_LES)*nu_t + LAG_LES*eddy_viscosity_last;
453 if (NONCONSERVATIVE_FORM > 0.0)
457 dmom_u_acc_u=rho*porosity;
461 dmom_v_acc_v=rho*porosity;
464 mass_adv[0]=porosity*
u;
465 mass_adv[1]=porosity*
v;
467 dmass_adv_u[0]=porosity;
471 dmass_adv_v[1]=porosity;
497 mom_uu_diff_ten[0] = 2.0*porosity*mu;
498 mom_uu_diff_ten[1] = porosity*mu;
500 mom_uv_diff_ten[0]=porosity*mu;
503 mom_vv_diff_ten[0] = porosity*mu;
504 mom_vv_diff_ten[1] = 2.0*porosity*mu;
506 mom_vu_diff_ten[0]=porosity*mu;
509 norm_n = sqrt(
n[0]*
n[0]+
n[1]*
n[1]);
510 mom_u_source = -porosity*rho*g[0];
511 mom_v_source = -porosity*rho*g[1];
514 mom_u_ham = porosity*grad_p[0];
515 dmom_u_ham_grad_p[0]=porosity;
516 dmom_u_ham_grad_p[1]=0.0;
519 mom_v_ham = porosity*grad_p[1];
520 dmom_v_ham_grad_p[0]=0.0;
521 dmom_v_ham_grad_p[1] = porosity;
524 mom_u_ham +=
inertial_term*rho * porosity * (
u * grad_u[0] +
v * grad_u[1]);
531 mom_v_ham +=
inertial_term*rho * porosity * (
u * grad_v[0] +
v * grad_v[1]);
540 mom_u_acc=porosity*
u;
541 dmom_u_acc_u=porosity;
544 mom_v_acc=porosity*
v;
545 dmom_v_acc_v=porosity;
548 mass_adv[0]=porosity*
u;
549 mass_adv[1]=porosity*
v;
551 dmass_adv_u[0]=porosity;
555 dmass_adv_v[1]=porosity;
578 mom_uu_diff_ten[0] = 2.0*porosity*nu;
579 mom_uu_diff_ten[1] = porosity*nu;
581 mom_uv_diff_ten[0]=porosity*nu;
584 mom_vv_diff_ten[0] = porosity*nu;
585 mom_vv_diff_ten[1] = 2.0*porosity*nu;
587 mom_vu_diff_ten[0]=porosity*nu;
590 norm_n = sqrt(
n[0]*
n[0]+
n[1]*
n[1]);
591 mom_u_source = -porosity*g[0];
592 mom_v_source = -porosity*g[1];
595 mom_u_ham = porosity*grad_p[0]/rho;
596 dmom_u_ham_grad_p[0]=porosity/rho;
597 dmom_u_ham_grad_p[1]=0.0;
600 mom_v_ham = porosity*grad_p[1]/rho;
601 dmom_v_ham_grad_p[0]=0.0;
602 dmom_v_ham_grad_p[1]=porosity/rho;
605 dmom_u_ham_grad_u[0]=0.0;
606 dmom_u_ham_grad_u[1]=0.0;
611 dmom_v_ham_grad_v[0]=0.0;
612 dmom_v_ham_grad_v[1]=0.0;
616 mom_u_source -= forcex;
617 mom_v_source -= forcey;
620 int get_distance_to_ball(
int n_balls,
const double* ball_center,
const double* ball_radius,
const double x,
const double y,
const double z,
double& distance)
625 for (
int i=0; i<n_balls; ++i)
627 d_ball_i = std::sqrt((ball_center[i*3+0]-x)*(ball_center[i*3+0]-x)
628 +(ball_center[i*3+1]-y)*(ball_center[i*3+1]-y)
630 if(d_ball_i<distance)
641 const double x,
const double y,
const double z,
644 distance = std::sqrt((ball_center[I*3+0]-x)*(ball_center[I*3+0]-x)
645 + (ball_center[I*3+1]-y)*(ball_center[I*3+1]-y)
650 const double x,
const double y,
const double z,
651 double& nx,
double& ny)
653 double distance = std::sqrt((ball_center[I*3+0]-x)*(ball_center[I*3+0]-x)
654 + (ball_center[I*3+1]-y)*(ball_center[I*3+1]-y)
656 if (distance > 1.0e-8)
658 nx = (x - ball_center[I*3+0])/distance;
659 ny = (y - ball_center[I*3+1])/distance;
660 assert(std::fabs(std::sqrt(nx*nx + ny*ny) - 1.0) < 1.0e-10);
669 const double* ball_velocity,
const double* ball_angular_velocity,
671 const double x,
const double y,
const double z,
672 double&
vx,
double&
vy)
674 vx = ball_velocity[3*I + 0] - ball_angular_velocity[3*I + 2]*(y-ball_center[3*I + 1]);
675 vy = ball_velocity[3*I + 1] + ball_angular_velocity[3*I + 2]*(x-ball_center[3*I + 0]);
678 const double NONCONSERVATIVE_FORM,
680 const double particle_nitsche,
682 const int nParticles,
684 double* particle_signed_distances,
685 double* particle_signed_distance_normals,
686 double* particle_velocities,
687 double* particle_centroids,
688 const int use_ball_as_particle,
689 const double* ball_center,
690 const double* ball_radius,
691 const double* ball_velocity,
692 const double* ball_angular_velocity,
693 const double* ball_density,
694 const double porosity,
695 const double penalty,
698 const double eps_rho,
718 const double grad_u[nSpace],
719 const double grad_v[nSpace],
720 const double grad_w[nSpace],
722 double &mom_u_source,
723 double &mom_v_source,
724 double &mom_w_source,
725 double dmom_u_source[nSpace],
726 double dmom_v_source[nSpace],
727 double dmom_w_source[nSpace],
728 double mom_u_adv[nSpace],
729 double mom_v_adv[nSpace],
730 double mom_w_adv[nSpace],
731 double dmom_u_adv_u[nSpace],
732 double dmom_v_adv_v[nSpace],
733 double dmom_w_adv_w[nSpace],
735 double dmom_u_ham_grad_u[nSpace],
736 double dmom_u_ham_grad_v[nSpace],
737 double &dmom_u_ham_u,
738 double &dmom_u_ham_v,
739 double &dmom_u_ham_w,
741 double dmom_v_ham_grad_u[nSpace],
742 double dmom_v_ham_grad_v[nSpace],
743 double &dmom_v_ham_u,
744 double &dmom_v_ham_v,
745 double &dmom_v_ham_w,
747 double dmom_w_ham_grad_w[nSpace],
748 double &dmom_w_ham_u,
749 double &dmom_w_ham_v,
750 double &dmom_w_ham_w,
755 double *particle_netForces,
756 double *particle_netMoments,
757 double *particle_surfaceArea)
759 double C, rho, mu, nu, H_mu, ImH_mu, uc, duc_du, duc_dv, duc_dw, H_s, ImH_s, D_s, phi_s, u_s, v_s, w_s;
760 double force_x, force_y, r_x, r_y, force_p_x, force_p_y, force_stress_x, force_stress_y;
761 double phi_s_normal[nSpace]=
ZEROVEC;
762 double fluid_outward_normal[nSpace]=
ZEROVEC;
765 H_mu = (1.0 - useVF) *
gf.H(eps_mu,
phi) + useVF * fmin(1.0, fmax(0.0, vf));
766 ImH_mu = (1.0 - useVF) *
gf.ImH(eps_mu,
phi) + useVF * (1.0-fmin(1.0, fmax(0.0, vf)));
771 for (
int i = particle_index; i < particle_index+1; i++)
773 if(use_ball_as_particle==1)
777 ball_velocity,ball_angular_velocity,
780 center[0] = ball_center[3*i+0];
781 center[1] = ball_center[3*i+1];
782 particle_velocities[0] =
vel[0];
783 particle_velocities[1] =
vel[1];
787 phi_s = particle_signed_distances[i * sd_offset];
788 vel[0] = particle_velocities[i * sd_offset * 3 + 0];
789 vel[1] = particle_velocities[i * sd_offset * 3 + 1];
790 center[0] = particle_centroids[3*i+0];
791 center[1] = particle_centroids[3*i+1];
793 for (
int I=0;I<nSpace;I++)
794 phi_s_normal[I] = particle_signed_distance_normals[I];
795 assert(std::fabs(1.0-std::sqrt(phi_s_normal[0]*phi_s_normal[0] + phi_s_normal[1]*phi_s_normal[1])) < 1.0e-8);
811 fluid_outward_normal[0] = -phi_s_normal[0];
812 fluid_outward_normal[1] = -phi_s_normal[1];
813 assert(std::fabs(1.0-std::sqrt(fluid_outward_normal[0]*fluid_outward_normal[0] + fluid_outward_normal[1]*fluid_outward_normal[1])) < 1.0e-8);
817 D_s =
gf_s.D(eps_s, phi_s);
819 double rel_vel_norm = sqrt((uStar - u_s) * (uStar - u_s) +
820 (vStar - v_s) * (vStar - v_s) +
821 (wStar - w_s) * (wStar - w_s));
822 force_p_x = porosity * dV * D_s * p * fluid_outward_normal[0];
823 force_p_y = porosity * dV * D_s * p * fluid_outward_normal[1];
824 force_stress_x = porosity * dV * D_s * (-mu * (fluid_outward_normal[0] * 2* grad_u[0] + fluid_outward_normal[1] * (grad_u[1]+grad_v[0]))
825 +mu*penalty*(
u-u_s));
826 force_stress_y = porosity * dV * D_s * (-mu * (fluid_outward_normal[0] * (grad_u[1]+grad_v[0]) + fluid_outward_normal[1] * 2* grad_v[1])
827 +mu*penalty*(
v-v_s));
828 force_x = force_p_x + force_stress_x;
829 force_y = force_p_y + force_stress_y;
836 particle_surfaceArea[i] += dV * D_s;
837 particle_netForces[i * 3 + 0] += force_x;
838 particle_netForces[i * 3 + 1] += force_y;
839 particle_netForces[(i+ nParticles)*3+0]+= force_stress_x;
840 particle_netForces[(i+2*nParticles)*3+0]+= force_p_x;
841 particle_netForces[(i+ nParticles)*3+1]+= force_stress_y;
842 particle_netForces[(i+2*nParticles)*3+1]+= force_p_y;
843 particle_netMoments[i * 3 + 2] += (r_x * force_y - r_y * force_x);
847 mass_source += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
849 if (NONCONSERVATIVE_FORM > 0.0)
852 if (!
UPWIND_DIRICHLET || (fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s) < 0.0)
854 mom_u_source += rho*D_s*(u_s -
u)*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
855 mom_v_source += rho*D_s*(v_s -
v)*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
856 dmom_u_source[0] -= rho*D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
857 dmom_v_source[1] -= rho*D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
861 mom_u_ham -= D_s * porosity * mu * (fluid_outward_normal[0] * 2* grad_u[0] + fluid_outward_normal[1] * (grad_u[1]+grad_v[0]));
862 dmom_u_ham_grad_u[0] -= D_s * porosity * mu * 2 * fluid_outward_normal[0];
863 dmom_u_ham_grad_u[1] -= D_s * porosity * mu * fluid_outward_normal[1];
864 dmom_u_ham_grad_v[0] -= D_s * porosity * mu * fluid_outward_normal[1];
866 mom_v_ham -= D_s * porosity * mu * (fluid_outward_normal[0] * (grad_u[1]+grad_v[0]) + fluid_outward_normal[1] * 2* grad_v[1]);
867 dmom_v_ham_grad_u[1] -= D_s * porosity * mu * fluid_outward_normal[0];
868 dmom_v_ham_grad_v[0] -= D_s * porosity * mu * fluid_outward_normal[0];
869 dmom_v_ham_grad_v[1] -= D_s * porosity * mu * 2 * fluid_outward_normal[1];
872 mom_u_source += D_s*mu*penalty * (
u - u_s);
873 dmom_u_source[0] += D_s*mu*penalty;
875 mom_v_source += D_s*mu*penalty * (
v - v_s);
876 dmom_v_source[1] += D_s*mu*penalty;
879 mom_u_adv[0] += D_s * porosity * mu * fluid_outward_normal[0] * (
u - u_s);
880 mom_u_adv[1] += D_s * porosity * mu * fluid_outward_normal[1] * (
u - u_s);
881 dmom_u_adv_u[0] += D_s * porosity * mu * fluid_outward_normal[0];
882 dmom_u_adv_u[1] += D_s * porosity * mu * fluid_outward_normal[1];
884 mom_v_adv[0] += D_s * porosity * mu * fluid_outward_normal[0] * (
v - v_s);
885 mom_v_adv[1] += D_s * porosity * mu * fluid_outward_normal[1] * (
v - v_s);
886 dmom_v_adv_v[0] += D_s * porosity * mu * fluid_outward_normal[0];
887 dmom_v_adv_v[1] += D_s * porosity * mu * fluid_outward_normal[1];
893 if (!
UPWIND_DIRICHLET || (fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s) < 0.0)
895 mom_u_source += D_s*u_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
896 mom_v_source += D_s*v_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
900 mom_u_source += D_s*
u*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
901 dmom_u_source[0] += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
902 mom_v_source += D_s*
v*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
903 dmom_v_source[1] += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s);
907 mom_u_ham -= D_s * porosity * nu * (fluid_outward_normal[0] * 2* grad_u[0] + fluid_outward_normal[1] * (grad_u[1]+grad_v[0]));
908 dmom_u_ham_grad_u[0] -= D_s * porosity * nu * 2 * fluid_outward_normal[0];
909 dmom_u_ham_grad_u[1] -= D_s * porosity * nu * fluid_outward_normal[1];
910 dmom_u_ham_grad_v[0] -= D_s * porosity * nu * fluid_outward_normal[1];
912 mom_v_ham -= D_s * porosity * nu * (fluid_outward_normal[0] * (grad_u[1]+grad_v[0]) + fluid_outward_normal[1] * 2* grad_v[1]);
913 dmom_v_ham_grad_u[1] -= D_s * porosity * nu * fluid_outward_normal[0];
914 dmom_v_ham_grad_v[0] -= D_s * porosity * nu * fluid_outward_normal[0];
915 dmom_v_ham_grad_v[1] -= D_s * porosity * nu * 2 * fluid_outward_normal[1];
918 mom_u_source += D_s*nu*penalty * (
u - u_s);
919 dmom_u_source[0] += D_s*nu*penalty;
921 mom_v_source += D_s*nu*penalty * (
v - v_s);
922 dmom_v_source[1] += D_s*nu*penalty;
925 mom_u_adv[0] += D_s * porosity * nu * fluid_outward_normal[0] * (
u - u_s);
926 mom_u_adv[1] += D_s * porosity * nu * fluid_outward_normal[1] * (
u - u_s);
927 dmom_u_adv_u[0] += D_s * porosity * nu * fluid_outward_normal[0];
928 dmom_u_adv_u[1] += D_s * porosity * nu * fluid_outward_normal[1];
930 mom_v_adv[0] += D_s * porosity * nu * fluid_outward_normal[0] * (
v - v_s);
931 mom_v_adv[1] += D_s * porosity * nu * fluid_outward_normal[1] * (
v - v_s);
932 dmom_v_adv_v[0] += D_s * porosity * nu * fluid_outward_normal[0];
933 dmom_v_adv_v[1] += D_s * porosity * nu * fluid_outward_normal[1];
946 const double eps_rho,
961 const double eps_porous,
962 const double phi_porous,
963 const double u_porous,
964 const double v_porous,
965 const double w_porous,
966 double& mom_u_source,
967 double& mom_v_source,
968 double& mom_w_source,
969 double dmom_u_source[nSpace],
970 double dmom_v_source[nSpace],
971 double dmom_w_source[nSpace])
973 double rho,mu,nu,H_mu,ImH_mu, uc,duc_du,duc_dv,duc_dw,viscosity,H_porous;
974 H_mu = (1.0-useVF)*
gf.H(eps_mu,
phi)+useVF*fmin(1.0,fmax(0.0,vf));
975 ImH_mu = (1.0-useVF)*
gf.ImH(eps_mu,
phi)+useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
979 if (NONCONSERVATIVE_FORM > 0.0)
987 double x = fmax(0.0, fmin( 1.0, 0.5+phi_porous/(2.0*eps_porous)));
990 H_porous = (exp(pow(x,3.5)) - 1.)/ (exp(1.) - 1.);
998 uc = sqrt(uStar*uStar+vStar*vStar);
1002 mom_u_source += H_porous*viscosity*(alpha + beta*uc)*(
u-u_porous);
1003 mom_v_source += H_porous*viscosity*(alpha + beta*uc)*(
v-v_porous);
1005 dmom_u_source[0] = H_porous*viscosity*(alpha + beta*uc + beta*duc_du*(
u-u_porous));
1006 dmom_u_source[1] = H_porous*viscosity*beta*duc_dv*(
u-u_porous);
1008 dmom_v_source[0] = H_porous*viscosity*beta*duc_du*(
v-v_porous);
1009 dmom_v_source[1] = H_porous*viscosity*(alpha + beta*uc + beta*duc_dv*(
v-v_porous));
1014 const int turbulenceClosureModel,
1015 const double eps_rho,
1016 const double eps_mu,
1024 const double porosity,
1025 const double eddy_visc_coef_0,
1026 const double turb_var_0,
1027 const double turb_var_1,
1028 const double turb_grad_0[nSpace],
1029 double& eddy_viscosity,
1030 double mom_uu_diff_ten[nSpace],
1031 double mom_vv_diff_ten[nSpace],
1032 double mom_ww_diff_ten[nSpace],
1033 double mom_uv_diff_ten[1],
1034 double mom_uw_diff_ten[1],
1035 double mom_vu_diff_ten[1],
1036 double mom_vw_diff_ten[1],
1037 double mom_wu_diff_ten[1],
1038 double mom_wv_diff_ten[1],
1039 double& mom_u_source,
1040 double& mom_v_source,
1041 double& mom_w_source)
1049 assert (turbulenceClosureModel >=3);
1050 double rho,nu,H_mu,ImH_mu, nu_t=0.0,nu_t_keps =0.0, nu_t_komega=0.0;
1051 double isKEpsilon = 1.0, dynamic_eddy_viscosity = 0.0;
1053 if (turbulenceClosureModel == 4)
1055 H_mu = (1.0-useVF)*
gf.H(eps_mu,
phi)+useVF*fmin(1.0,fmax(0.0,vf));
1056 ImH_mu = (1.0-useVF)*
gf.ImH(eps_mu,
phi)+useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
1060 const double twoThirds = 2.0/3.0;
const double div_zero = 1.0e-2*fmin(
nu_0,
nu_1);
1061 mom_u_source += twoThirds*turb_grad_0[0];
1062 mom_v_source += twoThirds*turb_grad_0[1];
1066 nu_t_keps = eddy_visc_coef_0*turb_var_0*turb_var_0/(fabs(turb_var_1) + div_zero);
1068 nu_t_komega = turb_var_0/(fabs(turb_var_1) + div_zero);
1070 nu_t = isKEpsilon*nu_t_keps + (1.0-isKEpsilon)*nu_t_komega;
1072 nu_t = fmax(nu_t,1.0e-4*nu);
1074 nu_t = fmin(nu_t,1.0e6*nu);
1075 eddy_viscosity = nu_t;
1076 if (NONCONSERVATIVE_FORM > 0.0)
1078 dynamic_eddy_viscosity = nu_t*rho;
1080 mom_uu_diff_ten[0] += 2.0*porosity*dynamic_eddy_viscosity;
1081 mom_uu_diff_ten[1] += porosity*dynamic_eddy_viscosity;
1083 mom_uv_diff_ten[0] +=porosity*dynamic_eddy_viscosity;
1086 mom_vv_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1087 mom_vv_diff_ten[1] += 2.0*porosity*dynamic_eddy_viscosity;
1089 mom_vu_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1094 mom_uu_diff_ten[0] += 2.0*porosity*eddy_viscosity;
1095 mom_uu_diff_ten[1] += porosity*eddy_viscosity;
1097 mom_uv_diff_ten[0]+=porosity*eddy_viscosity;
1100 mom_vv_diff_ten[0] += porosity*eddy_viscosity;
1101 mom_vv_diff_ten[1] += 2.0*porosity*eddy_viscosity;
1103 mom_vu_diff_ten[0]+=porosity*eddy_viscosity;
1109 const double& elementDiameter,
1112 const double df[nSpace],
1119 double h,oneByAbsdt,density,viscosity,nrm_df;
1120 h = hFactor*elementDiameter;
1124 for(
int I=0;I<nSpace;I++)
1125 nrm_df+=
df[I]*
df[I];
1126 nrm_df = sqrt(nrm_df);
1127 cfl = nrm_df/(h*density);
1128 oneByAbsdt = fabs(dmt);
1129 tau_v = 1.0/(4.0*viscosity/(h*h) +
inertial_term*(2.0*nrm_df/h + oneByAbsdt));
1130 tau_p = (4.0*viscosity +
inertial_term*(2.0*nrm_df*h + oneByAbsdt*h*h))/pfac;
1135 const double& Cd_sge,
1136 const double G[nSpace*nSpace],
1137 const double& G_dd_G,
1140 const double Ai[nSpace],
1148 for(
int I=0;I<nSpace;I++)
1149 for (
int J=0;J<nSpace;J++)
1150 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
1151 tau_v = 1.0/sqrt(
inertial_term*(Ct_sge*A0*A0 + v_d_Gv + 1.0e-12) + Cd_sge*Kij*Kij*G_dd_G);
1152 tau_p = 1.0/(pfac*tr_G*tau_v);
1157 const double& tau_v,
1158 const double& pdeResidualP,
1159 const double& pdeResidualU,
1160 const double& pdeResidualV,
1161 const double& pdeResidualW,
1162 double& subgridErrorP,
1163 double& subgridErrorU,
1164 double& subgridErrorV,
1165 double& subgridErrorW)
1168 subgridErrorP = -tau_p*pdeResidualP;
1170 subgridErrorU = -tau_v*pdeResidualU;
1171 subgridErrorV = -tau_v*pdeResidualV;
1176 const double& tau_v,
1177 const double dpdeResidualP_du[nDOF_v_trial_element],
1178 const double dpdeResidualP_dv[nDOF_v_trial_element],
1179 const double dpdeResidualP_dw[nDOF_v_trial_element],
1180 const double dpdeResidualU_dp[nDOF_trial_element],
1181 const double dpdeResidualU_du[nDOF_v_trial_element],
1182 const double dpdeResidualV_dp[nDOF_trial_element],
1183 const double dpdeResidualV_dv[nDOF_v_trial_element],
1184 const double dpdeResidualW_dp[nDOF_trial_element],
1185 const double dpdeResidualW_dw[nDOF_v_trial_element],
1186 double dsubgridErrorP_du[nDOF_v_trial_element],
1187 double dsubgridErrorP_dv[nDOF_v_trial_element],
1188 double dsubgridErrorP_dw[nDOF_v_trial_element],
1189 double dsubgridErrorU_dp[nDOF_trial_element],
1190 double dsubgridErrorU_du[nDOF_v_trial_element],
1191 double dsubgridErrorV_dp[nDOF_trial_element],
1192 double dsubgridErrorV_dv[nDOF_v_trial_element],
1193 double dsubgridErrorW_dp[nDOF_trial_element],
1194 double dsubgridErrorW_dw[nDOF_v_trial_element])
1196 for (
int j=0;j<nDOF_v_trial_element;j++)
1199 dsubgridErrorP_du[j] = -tau_p*dpdeResidualP_du[j];
1200 dsubgridErrorP_dv[j] = -tau_p*dpdeResidualP_dv[j];
1203 dsubgridErrorU_du[j] = -tau_v*dpdeResidualU_du[j];
1205 dsubgridErrorV_dv[j] = -tau_v*dpdeResidualV_dv[j];
1207 for (
int j=0;j<nDOF_trial_element;j++)
1211 dsubgridErrorU_dp[j] = -tau_v*dpdeResidualU_dp[j];
1213 dsubgridErrorV_dp[j] = -tau_v*dpdeResidualV_dp[j];
1219 const int& isDOFBoundary_p,
1220 const int& isDOFBoundary_u,
1221 const int& isDOFBoundary_v,
1222 const int& isDOFBoundary_w,
1223 const int& isFluxBoundary_p,
1224 const int& isFluxBoundary_u,
1225 const int& isFluxBoundary_v,
1226 const int& isFluxBoundary_w,
1227 const double& oneByRho,
1228 const double& bc_oneByRho,
1229 const double n[nSpace],
1233 const double bc_f_mass[nSpace],
1234 const double bc_f_umom[nSpace],
1235 const double bc_f_vmom[nSpace],
1236 const double bc_f_wmom[nSpace],
1237 const double& bc_flux_mass,
1238 const double& bc_flux_umom,
1239 const double& bc_flux_vmom,
1240 const double& bc_flux_wmom,
1244 const double f_mass[nSpace],
1245 const double f_umom[nSpace],
1246 const double f_vmom[nSpace],
1247 const double f_wmom[nSpace],
1248 const double df_mass_du[nSpace],
1249 const double df_mass_dv[nSpace],
1250 const double df_mass_dw[nSpace],
1251 const double df_umom_dp[nSpace],
1252 const double dham_grad[nSpace],
1253 const double df_umom_du[nSpace],
1254 const double df_umom_dv[nSpace],
1255 const double df_umom_dw[nSpace],
1256 const double df_vmom_dp[nSpace],
1257 const double df_vmom_du[nSpace],
1258 const double df_vmom_dv[nSpace],
1259 const double df_vmom_dw[nSpace],
1260 const double df_wmom_dp[nSpace],
1261 const double df_wmom_du[nSpace],
1262 const double df_wmom_dv[nSpace],
1263 const double df_wmom_dw[nSpace],
1270 double flowSpeedNormal;
1274 if (NONCONSERVATIVE_FORM > 0.0)
1276 flowSpeedNormal =
n[0] * df_vmom_dv[0] +
n[1] * df_umom_du[1];
1277 flowSpeedNormal +=
n[0] * dham_grad[0] +
n[1] * dham_grad[1];
1280 flowSpeedNormal =
n[0] * df_vmom_dv[0] +
n[1] * df_umom_du[1];
1281 if (isDOFBoundary_u != 1)
1283 flux_mass +=
n[0] * f_mass[0];
1284 velocity[0] = f_mass[0];
1285 if (flowSpeedNormal >= 0.0)
1287 flux_umom +=
n[0] * f_umom[0];
1288 flux_vmom +=
n[0] * f_vmom[0];
1292 if (NONCONSERVATIVE_FORM > 0.0)
1294 flux_umom += (0.0 -
u) * flowSpeedNormal;
1300 flux_mass +=
n[0] * f_mass[0];
1301 velocity[0] = f_mass[0];
1304 flux_umom +=
n[0] * f_umom[0];
1305 flux_vmom +=
n[0] * f_vmom[0];
1309 if (NONCONSERVATIVE_FORM > 0.0)
1311 flux_umom += (bc_u -
u) * flowSpeedNormal;
1315 flux_umom +=
n[0] * bc_f_umom[0];
1316 flux_vmom +=
n[0] * bc_f_vmom[0];
1320 if (isDOFBoundary_v != 1)
1322 flux_mass +=
n[1] * f_mass[1];
1323 velocity[1] = f_mass[1];
1324 if (flowSpeedNormal >= 0.0)
1326 flux_umom +=
n[1] * f_umom[1];
1327 flux_vmom +=
n[1] * f_vmom[1];
1331 if (NONCONSERVATIVE_FORM > 0.0)
1333 flux_vmom += (0.0 -
v) * flowSpeedNormal;
1339 flux_mass +=
n[1] * f_mass[1];
1340 velocity[1] = f_mass[1];
1343 flux_umom +=
n[1] * f_umom[1];
1344 flux_vmom +=
n[1] * f_vmom[1];
1348 if (NONCONSERVATIVE_FORM > 0.0)
1350 flux_vmom += (bc_v -
v) * flowSpeedNormal;
1354 flux_umom +=
n[1] * bc_f_umom[1];
1355 flux_vmom +=
n[1] * bc_f_vmom[1];
1359 if (isDOFBoundary_p == 1)
1361 if (NONCONSERVATIVE_FORM > 0.0)
1363 flux_umom +=
n[0] * (bc_p - p);
1364 flux_vmom +=
n[1] * (bc_p - p);
1368 flux_umom +=
n[0] * (bc_p * bc_oneByRho - p * oneByRho);
1369 flux_vmom +=
n[1] * (bc_p * bc_oneByRho - p * oneByRho);
1372 if (isFluxBoundary_p == 1)
1374 velocity[0] += (bc_flux_mass - flux_mass) *
n[0];
1375 velocity[1] += (bc_flux_mass - flux_mass) *
n[1];
1376 flux_mass = bc_flux_mass;
1378 if (isFluxBoundary_u == 1)
1380 flux_umom = bc_flux_umom;
1382 if (isFluxBoundary_v == 1)
1384 flux_vmom = bc_flux_vmom;
1390 const int& isDOFBoundary_p,
1391 const int& isDOFBoundary_u,
1392 const int& isDOFBoundary_v,
1393 const int& isDOFBoundary_w,
1394 const int& isFluxBoundary_p,
1395 const int& isFluxBoundary_u,
1396 const int& isFluxBoundary_v,
1397 const int& isFluxBoundary_w,
1398 const double& oneByRho,
1399 const double n[nSpace],
1403 const double bc_f_mass[nSpace],
1404 const double bc_f_umom[nSpace],
1405 const double bc_f_vmom[nSpace],
1406 const double bc_f_wmom[nSpace],
1407 const double& bc_flux_mass,
1408 const double& bc_flux_umom,
1409 const double& bc_flux_vmom,
1410 const double& bc_flux_wmom,
1414 const double& dmom_u_acc_u,
1415 const double f_mass[nSpace],
1416 const double f_umom[nSpace],
1417 const double f_vmom[nSpace],
1418 const double f_wmom[nSpace],
1419 const double df_mass_du[nSpace],
1420 const double df_mass_dv[nSpace],
1421 const double df_mass_dw[nSpace],
1422 const double df_umom_dp[nSpace],
1423 const double dham_grad[nSpace],
1424 const double df_umom_du[nSpace],
1425 const double df_umom_dv[nSpace],
1426 const double df_umom_dw[nSpace],
1427 const double df_vmom_dp[nSpace],
1428 const double df_vmom_du[nSpace],
1429 const double df_vmom_dv[nSpace],
1430 const double df_vmom_dw[nSpace],
1431 const double df_wmom_dp[nSpace],
1432 const double df_wmom_du[nSpace],
1433 const double df_wmom_dv[nSpace],
1434 const double df_wmom_dw[nSpace],
1435 double& dflux_mass_du,
1436 double& dflux_mass_dv,
1437 double& dflux_mass_dw,
1438 double& dflux_umom_dp,
1439 double& dflux_umom_du,
1440 double& dflux_umom_dv,
1441 double& dflux_umom_dw,
1442 double& dflux_vmom_dp,
1443 double& dflux_vmom_du,
1444 double& dflux_vmom_dv,
1445 double& dflux_vmom_dw,
1446 double& dflux_wmom_dp,
1447 double& dflux_wmom_du,
1448 double& dflux_wmom_dv,
1449 double& dflux_wmom_dw)
1451 double flowSpeedNormal;
1452 dflux_mass_du = 0.0;
1453 dflux_mass_dv = 0.0;
1455 dflux_umom_dp = 0.0;
1456 dflux_umom_du = 0.0;
1457 dflux_umom_dv = 0.0;
1459 dflux_vmom_dp = 0.0;
1460 dflux_vmom_du = 0.0;
1461 dflux_vmom_dv = 0.0;
1463 dflux_wmom_dp = 0.0;
1464 dflux_wmom_du = 0.0;
1465 dflux_wmom_dv = 0.0;
1467 flowSpeedNormal=
n[0]*df_vmom_dv[0]+
n[1]*df_umom_du[1];
1468 flowSpeedNormal+=NONCONSERVATIVE_FORM*(
n[0]*dham_grad[0]+
n[1]*dham_grad[1]);
1469 if (isDOFBoundary_u != 1)
1471 dflux_mass_du +=
n[0] * df_mass_du[0];
1472 if (flowSpeedNormal >= 0.0)
1474 dflux_umom_du +=
n[0] * df_umom_du[0];
1475 dflux_umom_dv +=
n[0] * df_umom_dv[0];
1477 dflux_vmom_du +=
n[0] * df_vmom_du[0];
1478 dflux_vmom_dv +=
n[0] * df_vmom_dv[0];
1482 if (NONCONSERVATIVE_FORM > 0.0)
1484 dflux_umom_du += dmom_u_acc_u *
n[0] * (0.0 -
u) - flowSpeedNormal;
1485 dflux_umom_dv += dmom_u_acc_u *
n[1] * (0.0 -
u) ;
1492 dflux_mass_du +=
n[0] * df_mass_du[0];
1495 dflux_umom_du +=
n[0] * df_umom_du[0];
1496 dflux_umom_dv +=
n[0] * df_umom_dv[0];
1498 dflux_vmom_du +=
n[0] * df_vmom_du[0];
1499 dflux_vmom_dv +=
n[0] * df_vmom_dv[0];
1503 if (NONCONSERVATIVE_FORM > 0.0)
1505 dflux_umom_du += dmom_u_acc_u *
n[0] * (bc_u -
u) - flowSpeedNormal;
1506 dflux_umom_dv += dmom_u_acc_u *
n[1] * (bc_u -
u) ;
1510 if (isDOFBoundary_v != 1)
1511 dflux_vmom_dv +=
n[0] * df_vmom_dv[0];
1515 if (isDOFBoundary_v != 1)
1517 dflux_mass_dv +=
n[1] * df_mass_dv[1];
1518 if (flowSpeedNormal >= 0.0)
1520 dflux_umom_du +=
n[1] * df_umom_du[1];
1521 dflux_umom_dv +=
n[1] * df_umom_dv[1];
1523 dflux_vmom_du +=
n[1] * df_vmom_du[1];
1524 dflux_vmom_dv +=
n[1] * df_vmom_dv[1];
1528 if (NONCONSERVATIVE_FORM > 0.0)
1530 dflux_vmom_du += dmom_u_acc_u *
n[0] * (0.0 -
v);
1531 dflux_vmom_dv += dmom_u_acc_u *
n[1] * (0.0 -
v) - flowSpeedNormal;
1538 dflux_mass_dv +=
n[1] * df_mass_dv[1];
1541 dflux_umom_du +=
n[1] * df_umom_du[1];
1542 dflux_umom_dv +=
n[1] * df_umom_dv[1];
1544 dflux_vmom_du +=
n[1] * df_vmom_du[1];
1545 dflux_vmom_dv +=
n[1] * df_vmom_dv[1];
1549 if (NONCONSERVATIVE_FORM > 0.0)
1551 dflux_vmom_du += dmom_u_acc_u *
n[0] * (bc_v -
v);
1552 dflux_vmom_dv += dmom_u_acc_u *
n[1] * (bc_v -
v) - flowSpeedNormal;
1556 if (isDOFBoundary_u != 1)
1557 dflux_umom_du +=
n[1] * df_umom_du[1];
1561 if (isDOFBoundary_p == 1)
1563 if (NONCONSERVATIVE_FORM > 0.0)
1565 dflux_umom_dp = -
n[0];
1566 dflux_vmom_dp = -
n[1];
1570 dflux_umom_dp = -
n[0] * oneByRho;
1571 dflux_vmom_dp = -
n[1] * oneByRho;
1574 if (isFluxBoundary_p == 1)
1576 dflux_mass_du = 0.0;
1577 dflux_mass_dv = 0.0;
1579 if (isFluxBoundary_u == 1)
1581 dflux_umom_dp = 0.0;
1582 dflux_umom_du = 0.0;
1583 dflux_umom_dv = 0.0;
1585 if (isFluxBoundary_v == 1)
1587 dflux_vmom_dp = 0.0;
1588 dflux_vmom_du = 0.0;
1589 dflux_vmom_dv = 0.0;
1598 const int& isDOFBoundary,
1599 const int& isFluxBoundary,
1600 const double n[nSpace],
1603 const double& bc_flux,
1605 const double grad_potential[nSpace],
1607 const double& penalty,
1610 double diffusiveVelocityComponent_I,penaltyFlux,max_a;
1611 if(isFluxBoundary == 1)
1615 else if(isDOFBoundary == 1)
1619 for(
int I=0;I<nSpace;I++)
1621 diffusiveVelocityComponent_I=0.0;
1622 for(
int m=rowptr[I];m<rowptr[I+1];m++)
1624 diffusiveVelocityComponent_I -= a[m]*grad_potential[colind[m]];
1625 max_a = fmax(max_a,a[m]);
1627 flux+= diffusiveVelocityComponent_I*
n[I];
1629 penaltyFlux = max_a*penalty*(
u-bc_u);
1630 flux += penaltyFlux;
1637 std::cerr<<
"RANS2P2D: warning, diffusion term with no boundary condition set, setting diffusive flux to 0.0"<<std::endl;
1648 const int& isDOFBoundary,
1649 const int& isFluxBoundary,
1650 const double n[nSpace],
1653 const double grad_v[nSpace],
1654 const double& penalty)
1656 double dvel_I,tmp=0.0,max_a=0.0;
1657 if(isFluxBoundary==0 && isDOFBoundary==1)
1659 for(
int I=0;I<nSpace;I++)
1662 for(
int m=rowptr[I];m<rowptr[I+1];m++)
1664 dvel_I -= a[m]*grad_v[colind[m]];
1665 max_a = fmax(max_a,a[m]);
1669 tmp +=max_a*penalty*
v;
1679 double NONCONSERVATIVE_FORM = args.
scalar<
double>(
"NONCONSERVATIVE_FORM");
1680 double MOMENTUM_SGE = args.
scalar<
double>(
"MOMENTUM_SGE");
1681 double PRESSURE_SGE = args.
scalar<
double>(
"PRESSURE_SGE");
1682 double VELOCITY_SGE = args.
scalar<
double>(
"VELOCITY_SGE");
1683 double PRESSURE_PROJECTION_STABILIZATION = args.
scalar<
double>(
"PRESSURE_PROJECTION_STABILIZATION");
1684 xt::pyarray<double>& numerical_viscosity = args.
array<
double>(
"numerical_viscosity");
1685 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
1686 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
1687 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
1688 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
1689 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
1690 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
1691 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
1692 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
1693 xt::pyarray<double>& p_trial_ref = args.
array<
double>(
"p_trial_ref");
1694 xt::pyarray<double>& p_grad_trial_ref = args.
array<
double>(
"p_grad_trial_ref");
1695 xt::pyarray<double>& p_test_ref = args.
array<
double>(
"p_test_ref");
1696 xt::pyarray<double>& p_grad_test_ref = args.
array<
double>(
"p_grad_test_ref");
1697 xt::pyarray<double>& vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
1698 xt::pyarray<double>& vel_grad_trial_ref = args.
array<
double>(
"vel_grad_trial_ref");
1699 xt::pyarray<double>& vel_test_ref = args.
array<
double>(
"vel_test_ref");
1700 xt::pyarray<double>& vel_grad_test_ref = args.
array<
double>(
"vel_grad_test_ref");
1701 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
1702 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
1703 xt::pyarray<double>& xb_ref = args.
array<
double>(
"xb_ref");
1704 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
1705 xt::pyarray<double>& p_trial_trace_ref = args.
array<
double>(
"p_trial_trace_ref");
1706 xt::pyarray<double>& p_grad_trial_trace_ref = args.
array<
double>(
"p_grad_trial_trace_ref");
1707 xt::pyarray<double>& p_test_trace_ref = args.
array<
double>(
"p_test_trace_ref");
1708 xt::pyarray<double>& p_grad_test_trace_ref = args.
array<
double>(
"p_grad_test_trace_ref");
1709 xt::pyarray<double>& vel_trial_trace_ref = args.
array<
double>(
"vel_trial_trace_ref");
1710 xt::pyarray<double>& vel_grad_trial_trace_ref = args.
array<
double>(
"vel_grad_trial_trace_ref");
1711 xt::pyarray<double>& vel_test_trace_ref = args.
array<
double>(
"vel_test_trace_ref");
1712 xt::pyarray<double>& vel_grad_test_trace_ref = args.
array<
double>(
"vel_grad_test_trace_ref");
1713 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
1714 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
1715 double eb_adjoint_sigma = args.
scalar<
double>(
"eb_adjoint_sigma");
1716 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
1717 xt::pyarray<double>& elementBoundaryDiameter = args.
array<
double>(
"elementBoundaryDiameter");
1718 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
1719 double hFactor = args.
scalar<
double>(
"hFactor");
1720 int nElements_global = args.
scalar<
int>(
"nElements_global");
1721 int nElementBoundaries_owned = args.
scalar<
int>(
"nElementBoundaries_owned");
1722 double useRBLES = args.
scalar<
double>(
"useRBLES");
1723 double useMetrics = args.
scalar<
double>(
"useMetrics");
1724 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
1725 double epsFact_rho = args.
scalar<
double>(
"epsFact_rho");
1726 double epsFact_mu = args.
scalar<
double>(
"epsFact_mu");
1727 double sigma = args.
scalar<
double>(
"sigma");
1732 double smagorinskyConstant = args.
scalar<
double>(
"smagorinskyConstant");
1733 int turbulenceClosureModel = args.
scalar<
int>(
"turbulenceClosureModel");
1734 double Ct_sge = args.
scalar<
double>(
"Ct_sge");
1735 double Cd_sge = args.
scalar<
double>(
"Cd_sge");
1736 double C_dc = args.
scalar<
double>(
"C_dc");
1737 double C_b = args.
scalar<
double>(
"C_b");
1738 const xt::pyarray<double>& eps_solid = args.
array<
double>(
"eps_solid");
1739 xt::pyarray<double>& phi_solid = args.
array<
double>(
"phi_solid");
1740 const xt::pyarray<double>& eps_porous = args.
array<
double>(
"eps_porous");
1741 xt::pyarray<double>& phi_porous = args.
array<
double>(
"phi_porous");
1742 const xt::pyarray<double>& q_velocity_porous = args.
array<
double>(
"q_velocity_porous");
1743 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
1744 const xt::pyarray<double>& q_dragAlpha = args.
array<
double>(
"q_dragAlpha");
1745 const xt::pyarray<double>& q_dragBeta = args.
array<
double>(
"q_dragBeta");
1746 const xt::pyarray<double>& q_mass_source = args.
array<
double>(
"q_mass_source");
1747 const xt::pyarray<double>& q_turb_var_0 = args.
array<
double>(
"q_turb_var_0");
1748 const xt::pyarray<double>& q_turb_var_1 = args.
array<
double>(
"q_turb_var_1");
1749 const xt::pyarray<double>& q_turb_var_grad_0 = args.
array<
double>(
"q_turb_var_grad_0");
1750 const double LAG_LES = args.
scalar<
double>(
"LAG_LES");
1751 xt::pyarray<double> & q_eddy_viscosity = args.
array<
double>(
"q_eddy_viscosity");
1752 xt::pyarray<double> & q_eddy_viscosity_last = args.
array<
double>(
"q_eddy_viscosity_last");
1753 xt::pyarray<double> & ebqe_eddy_viscosity = args.
array<
double>(
"ebqe_eddy_viscosity");
1754 xt::pyarray<double> & ebqe_eddy_viscosity_last = args.
array<
double>(
"ebqe_eddy_viscosity_last");
1755 xt::pyarray<int>& p_l2g = args.
array<
int>(
"p_l2g");
1756 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
1757 xt::pyarray<int>& rp_l2g = args.
array<
int>(
"rp_l2g");
1758 xt::pyarray<int>& rvel_l2g = args.
array<
int>(
"rvel_l2g");
1759 xt::pyarray<double>& p_dof = args.
array<
double>(
"p_dof");
1760 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
1761 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
1762 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
1763 xt::pyarray<double>& p_old_dof = args.
array<
double>(
"p_old_dof");
1764 xt::pyarray<double>& u_old_dof = args.
array<
double>(
"u_old_dof");
1765 xt::pyarray<double>& v_old_dof = args.
array<
double>(
"v_old_dof");
1766 xt::pyarray<double>& w_old_dof = args.
array<
double>(
"w_old_dof");
1767 xt::pyarray<double>& g = args.
array<
double>(
"g");
1768 const double useVF = args.
scalar<
double>(
"useVF");
1769 xt::pyarray<double>& q_rho = args.
array<
double>(
"q_rho");
1770 xt::pyarray<double>& vf = args.
array<
double>(
"vf");
1771 xt::pyarray<double>&
phi = args.
array<
double>(
"phi");
1772 xt::pyarray<double>& phi_nodes = args.
array<
double>(
"phi_nodes");
1773 xt::pyarray<double>& normal_phi = args.
array<
double>(
"normal_phi");
1774 xt::pyarray<double>& kappa_phi = args.
array<
double>(
"kappa_phi");
1775 xt::pyarray<double>& q_mom_u_acc = args.
array<
double>(
"q_mom_u_acc");
1776 xt::pyarray<double>& q_mom_v_acc = args.
array<
double>(
"q_mom_v_acc");
1777 xt::pyarray<double>& q_mom_w_acc = args.
array<
double>(
"q_mom_w_acc");
1778 xt::pyarray<double>& q_mass_adv = args.
array<
double>(
"q_mass_adv");
1779 xt::pyarray<double>& q_mom_u_acc_beta_bdf = args.
array<
double>(
"q_mom_u_acc_beta_bdf");
1780 xt::pyarray<double>& q_mom_v_acc_beta_bdf = args.
array<
double>(
"q_mom_v_acc_beta_bdf");
1781 xt::pyarray<double>& q_mom_w_acc_beta_bdf = args.
array<
double>(
"q_mom_w_acc_beta_bdf");
1782 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
1783 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
1784 xt::pyarray<double>& q_velocity_sge = args.
array<
double>(
"q_velocity_sge");
1785 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
1786 xt::pyarray<double>& q_numDiff_u = args.
array<
double>(
"q_numDiff_u");
1787 xt::pyarray<double>& q_numDiff_v = args.
array<
double>(
"q_numDiff_v");
1788 xt::pyarray<double>& q_numDiff_w = args.
array<
double>(
"q_numDiff_w");
1789 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
1790 xt::pyarray<double>& q_numDiff_v_last = args.
array<
double>(
"q_numDiff_v_last");
1791 xt::pyarray<double>& q_numDiff_w_last = args.
array<
double>(
"q_numDiff_w_last");
1792 xt::pyarray<int>& sdInfo_u_u_rowptr = args.
array<
int>(
"sdInfo_u_u_rowptr");
1793 xt::pyarray<int>& sdInfo_u_u_colind = args.
array<
int>(
"sdInfo_u_u_colind");
1794 xt::pyarray<int>& sdInfo_u_v_rowptr = args.
array<
int>(
"sdInfo_u_v_rowptr");
1795 xt::pyarray<int>& sdInfo_u_v_colind = args.
array<
int>(
"sdInfo_u_v_colind");
1796 xt::pyarray<int>& sdInfo_u_w_rowptr = args.
array<
int>(
"sdInfo_u_w_rowptr");
1797 xt::pyarray<int>& sdInfo_u_w_colind = args.
array<
int>(
"sdInfo_u_w_colind");
1798 xt::pyarray<int>& sdInfo_v_v_rowptr = args.
array<
int>(
"sdInfo_v_v_rowptr");
1799 xt::pyarray<int>& sdInfo_v_v_colind = args.
array<
int>(
"sdInfo_v_v_colind");
1800 xt::pyarray<int>& sdInfo_v_u_rowptr = args.
array<
int>(
"sdInfo_v_u_rowptr");
1801 xt::pyarray<int>& sdInfo_v_u_colind = args.
array<
int>(
"sdInfo_v_u_colind");
1802 xt::pyarray<int>& sdInfo_v_w_rowptr = args.
array<
int>(
"sdInfo_v_w_rowptr");
1803 xt::pyarray<int>& sdInfo_v_w_colind = args.
array<
int>(
"sdInfo_v_w_colind");
1804 xt::pyarray<int>& sdInfo_w_w_rowptr = args.
array<
int>(
"sdInfo_w_w_rowptr");
1805 xt::pyarray<int>& sdInfo_w_w_colind = args.
array<
int>(
"sdInfo_w_w_colind");
1806 xt::pyarray<int>& sdInfo_w_u_rowptr = args.
array<
int>(
"sdInfo_w_u_rowptr");
1807 xt::pyarray<int>& sdInfo_w_u_colind = args.
array<
int>(
"sdInfo_w_u_colind");
1808 xt::pyarray<int>& sdInfo_w_v_rowptr = args.
array<
int>(
"sdInfo_w_v_rowptr");
1809 xt::pyarray<int>& sdInfo_w_v_colind = args.
array<
int>(
"sdInfo_w_v_colind");
1810 int offset_p = args.
scalar<
int>(
"offset_p");
1811 int offset_u = args.
scalar<
int>(
"offset_u");
1812 int offset_v = args.
scalar<
int>(
"offset_v");
1813 int offset_w = args.
scalar<
int>(
"offset_w");
1814 int stride_p = args.
scalar<
int>(
"stride_p");
1815 int stride_u = args.
scalar<
int>(
"stride_u");
1816 int stride_v = args.
scalar<
int>(
"stride_v");
1817 int stride_w = args.
scalar<
int>(
"stride_w");
1818 xt::pyarray<double>& globalResidual = args.
array<
double>(
"globalResidual");
1819 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
1820 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
1821 xt::pyarray<int>& elementBoundariesArray = args.
array<
int>(
"elementBoundariesArray");
1822 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
1823 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
1824 xt::pyarray<double>& ebqe_vf_ext = args.
array<
double>(
"ebqe_vf_ext");
1825 xt::pyarray<double>& bc_ebqe_vf_ext = args.
array<
double>(
"bc_ebqe_vf_ext");
1826 xt::pyarray<double>& ebqe_phi_ext = args.
array<
double>(
"ebqe_phi_ext");
1827 xt::pyarray<double>& bc_ebqe_phi_ext = args.
array<
double>(
"bc_ebqe_phi_ext");
1828 xt::pyarray<double>& ebqe_normal_phi_ext = args.
array<
double>(
"ebqe_normal_phi_ext");
1829 xt::pyarray<double>& ebqe_kappa_phi_ext = args.
array<
double>(
"ebqe_kappa_phi_ext");
1830 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
1831 const xt::pyarray<double>& ebqe_turb_var_0 = args.
array<
double>(
"ebqe_turb_var_0");
1832 const xt::pyarray<double>& ebqe_turb_var_1 = args.
array<
double>(
"ebqe_turb_var_1");
1833 xt::pyarray<int>& isDOFBoundary_p = args.
array<
int>(
"isDOFBoundary_p");
1834 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
1835 xt::pyarray<int>& isDOFBoundary_v = args.
array<
int>(
"isDOFBoundary_v");
1836 xt::pyarray<int>& isDOFBoundary_w = args.
array<
int>(
"isDOFBoundary_w");
1837 xt::pyarray<int>& isAdvectiveFluxBoundary_p = args.
array<
int>(
"isAdvectiveFluxBoundary_p");
1838 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.
array<
int>(
"isAdvectiveFluxBoundary_u");
1839 xt::pyarray<int>& isAdvectiveFluxBoundary_v = args.
array<
int>(
"isAdvectiveFluxBoundary_v");
1840 xt::pyarray<int>& isAdvectiveFluxBoundary_w = args.
array<
int>(
"isAdvectiveFluxBoundary_w");
1841 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.
array<
int>(
"isDiffusiveFluxBoundary_u");
1842 xt::pyarray<int>& isDiffusiveFluxBoundary_v = args.
array<
int>(
"isDiffusiveFluxBoundary_v");
1843 xt::pyarray<int>& isDiffusiveFluxBoundary_w = args.
array<
int>(
"isDiffusiveFluxBoundary_w");
1844 xt::pyarray<double>& ebqe_bc_p_ext = args.
array<
double>(
"ebqe_bc_p_ext");
1845 xt::pyarray<double>& ebqe_bc_flux_mass_ext = args.
array<
double>(
"ebqe_bc_flux_mass_ext");
1846 xt::pyarray<double>& ebqe_bc_flux_mom_u_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_u_adv_ext");
1847 xt::pyarray<double>& ebqe_bc_flux_mom_v_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_v_adv_ext");
1848 xt::pyarray<double>& ebqe_bc_flux_mom_w_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_w_adv_ext");
1849 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
1850 xt::pyarray<double>& ebqe_bc_flux_u_diff_ext = args.
array<
double>(
"ebqe_bc_flux_u_diff_ext");
1851 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
1852 xt::pyarray<double>& ebqe_bc_v_ext = args.
array<
double>(
"ebqe_bc_v_ext");
1853 xt::pyarray<double>& ebqe_bc_flux_v_diff_ext = args.
array<
double>(
"ebqe_bc_flux_v_diff_ext");
1854 xt::pyarray<double>& ebqe_bc_w_ext = args.
array<
double>(
"ebqe_bc_w_ext");
1855 xt::pyarray<double>& ebqe_bc_flux_w_diff_ext = args.
array<
double>(
"ebqe_bc_flux_w_diff_ext");
1856 xt::pyarray<double>& q_x = args.
array<
double>(
"q_x");
1857 xt::pyarray<double>& q_u_0 = args.
array<
double>(
"q_u_0");
1858 xt::pyarray<double>& q_u_1 = args.
array<
double>(
"q_u_1");
1859 xt::pyarray<double>& q_u_2 = args.
array<
double>(
"q_u_2");
1860 xt::pyarray<double>& q_u_3 = args.
array<
double>(
"q_u_3");
1861 xt::pyarray<double>& q_velocity = args.
array<
double>(
"q_velocity");
1862 xt::pyarray<double>& ebqe_velocity = args.
array<
double>(
"ebqe_velocity");
1863 xt::pyarray<double>& flux = args.
array<
double>(
"flux");
1864 xt::pyarray<double>& elementResidual_p_save = args.
array<
double>(
"elementResidual_p_save");
1865 xt::pyarray<int>& elementFlags = args.
array<
int>(
"elementFlags");
1866 xt::pyarray<int>& boundaryFlags = args.
array<
int>(
"boundaryFlags");
1867 xt::pyarray<double>& barycenters = args.
array<
double>(
"barycenters");
1868 xt::pyarray<double>& wettedAreas = args.
array<
double>(
"wettedAreas");
1869 xt::pyarray<double>& netForces_p = args.
array<
double>(
"netForces_p");
1870 xt::pyarray<double>& netForces_v = args.
array<
double>(
"netForces_v");
1871 xt::pyarray<double>& netMoments = args.
array<
double>(
"netMoments");
1872 xt::pyarray<double>& velocityError = args.
array<
double>(
"velocityError");
1873 xt::pyarray<double>& velocityErrorNodal = args.
array<
double>(
"velocityErrorNodal");
1874 xt::pyarray<double>& forcex = args.
array<
double>(
"forcex");
1875 xt::pyarray<double>& forcey = args.
array<
double>(
"forcey");
1876 xt::pyarray<double>& forcez = args.
array<
double>(
"forcez");
1877 int use_ball_as_particle = args.
scalar<
int>(
"use_ball_as_particle");
1878 xt::pyarray<double>& ball_center = args.
array<
double>(
"ball_center");
1879 xt::pyarray<double>& ball_radius = args.
array<
double>(
"ball_radius");
1880 xt::pyarray<double>& ball_velocity = args.
array<
double>(
"ball_velocity");
1881 xt::pyarray<double>& ball_angular_velocity = args.
array<
double>(
"ball_angular_velocity");
1882 xt::pyarray<double>& ball_density = args.
array<
double>(
"ball_density");
1883 xt::pyarray<double>& particle_signed_distances = args.
array<
double>(
"particle_signed_distances");
1884 xt::pyarray<double>& particle_signed_distance_normals = args.
array<
double>(
"particle_signed_distance_normals");
1885 xt::pyarray<double>& particle_velocities = args.
array<
double>(
"particle_velocities");
1886 xt::pyarray<double>& particle_centroids = args.
array<
double>(
"particle_centroids");
1887 xt::pyarray<double>& ebqe_phi_s = args.
array<
double>(
"ebqe_phi_s");
1888 xt::pyarray<double>& ebq_global_grad_phi_s = args.
array<
double>(
"ebq_global_grad_phi_s");
1889 xt::pyarray<double>& ebq_particle_velocity_s = args.
array<
double>(
"ebq_particle_velocity_s");
1890 int nParticles = args.
scalar<
int>(
"nParticles");
1891 xt::pyarray<double>& particle_netForces = args.
array<
double>(
"particle_netForces");
1892 xt::pyarray<double>& particle_netMoments = args.
array<
double>(
"particle_netMoments");
1893 xt::pyarray<double>& particle_surfaceArea = args.
array<
double>(
"particle_surfaceArea");
1894 int nElements_owned = args.
scalar<
int>(
"nElements_owned");
1895 double particle_nitsche = args.
scalar<
double>(
"particle_nitsche");
1896 double particle_epsFact = args.
scalar<
double>(
"particle_epsFact");
1897 double particle_alpha = args.
scalar<
double>(
"particle_alpha");
1898 double particle_beta = args.
scalar<
double>(
"particle_beta");
1899 double particle_penalty_constant = args.
scalar<
double>(
"particle_penalty_constant");
1900 double ghost_penalty_constant = args.
scalar<
double>(
"ghost_penalty_constant");
1901 xt::pyarray<double>& phi_solid_nodes = args.
array<
double>(
"phi_solid_nodes");
1902 xt::pyarray<double>& distance_to_solids = args.
array<
double>(
"distance_to_solids");
1903 bool useExact = args.
scalar<
int>(
"useExact");
1904 xt::pyarray<double>& isActiveR = args.
array<
double>(
"isActiveR");
1905 xt::pyarray<double>& isActiveDOF_p = args.
array<
double>(
"isActiveDOF_p");
1906 xt::pyarray<double>& isActiveDOF_vel = args.
array<
double>(
"isActiveDOF_vel");
1907 const bool normalize_pressure = args.
scalar<
int>(
"normalize_pressure");
1908 xt::pyarray<double>& errors = args.
array<
double>(
"errors");
1909 xt::pyarray<double>& ball_u = args.
array<
double>(
"ball_u");
1910 xt::pyarray<double>& ball_v = args.
array<
double>(
"ball_v");
1911 xt::pyarray<int>& isActiveElement = args.
array<
int>(
"isActiveElement");
1912 xt::pyarray<int>& isActiveElement_last = args.
array<
int>(
"isActiveElement_last");
1913 logEvent(
"Entered mprans calculateResidual",6);
1914 gf.useExact =
false;
1915 gf_p.useExact =
false;
1916 gf_s.useExact = useExact;
1921 const int nQuadraturePoints_global(nElements_global*nQuadraturePoints_element);
1925 double p_dv=0.0,pa_dv=0.0,total_volume=0.0,total_surface_area=0.0,total_flux=0.0;
1926 double mesh_volume_conservation=0.0,
1927 mesh_volume_conservation_weak=0.0,
1928 mesh_volume_conservation_err_max=0.0,
1929 mesh_volume_conservation_err_max_weak=0.0,
1931 &p_L1=errors(0,0),&u_L1=errors(0,1),&v_L1=errors(0,2),&w_L1=errors(0,2),&velocity_L1=errors(0,4),
1932 &p_L2=errors(1,0),&u_L2=errors(1,1),&v_L2=errors(1,2),&w_L2=errors(1,2),&velocity_L2=errors(1,4),
1933 &p_LI=errors(2,0),&u_LI=errors(2,1),&v_LI=errors(2,2),&w_LI=errors(2,2),&velocity_LI=errors(2,4);
1934 p_L1=0.0; u_L1=0.0; v_L1=0.0; w_L1=0.0; velocity_L1=0.0;
1935 p_L2=0.0; u_L2=0.0; v_L2=0.0; w_L2=0.0; velocity_L2=0.0;
1936 p_LI=0.0; u_LI=0.0; v_LI=0.0; w_LI=0.0; velocity_LI=0.0;
1937 double globalConservationError=0.0;
1942 for(
int eN=0;eN<nElements_global;eN++)
1945 register double elementResidual_p[nDOF_test_element],elementResidual_p_check[nDOF_test_element],elementResidual_mesh[nDOF_test_element],
1946 elementResidual_u[nDOF_v_test_element],
1947 elementResidual_v[nDOF_v_test_element],
1948 pelementResidual_u[nDOF_v_test_element],
1949 pelementResidual_v[nDOF_v_test_element],
1950 velocityErrorElement[nDOF_v_test_element],
1952 bool element_active=
false;
1953 isActiveElement[eN]=0;
1954 const double* elementResidual_w(NULL);
1955 double mesh_volume_conservation_element=0.0,
1956 mesh_volume_conservation_element_weak=0.0;
1957 int particle_index=0;
1958 for (
int i=0;i<nDOF_test_element;i++)
1960 int eN_i = eN*nDOF_test_element+i;
1961 elementResidual_p_save.data()[eN_i]=0.0;
1962 elementResidual_mesh[i]=0.0;
1963 elementResidual_p[i]=0.0;
1964 elementResidual_p_check[i]=0.0;
1966 for (
int i=0;i<nDOF_v_test_element;i++)
1968 elementResidual_u[i]=0.0;
1969 elementResidual_v[i]=0.0;
1970 pelementResidual_u[i]=0.0;
1971 pelementResidual_v[i]=0.0;
1972 velocityErrorElement[i]=0.0;
1975 if(use_ball_as_particle==1 && nParticles > 0)
1977 double min_d = 1e10;
1978 for (
int I=0;I<nDOF_mesh_trial_element;I++)
1981 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+0],
1982 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+1],
1983 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+2],
1984 phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]]);
1985 if (phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]] < min_d)
1987 min_d = phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]];
1988 particle_index = index;
1996 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
1997 for (
int j=0;j<nDOF_mesh_trial_element;j++)
1999 register int eN_j = eN*nDOF_mesh_trial_element+j;
2000 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
2001 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
2003 double element_nodes[nDOF_mesh_trial_element*3];
2004 for (
int i=0;i<nDOF_mesh_trial_element;i++)
2006 register int eN_i=eN*nDOF_mesh_trial_element+i;
2007 for(
int I=0;I<3;I++)
2008 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
2010 int icase_s =
gf_s.calculate(element_phi_s, element_nodes, x_ref.data(),
false);
2013 element_active=
true;
2014 isActiveElement[eN]=1;
2016 for (
int ebN_element=0;ebN_element < nDOF_mesh_trial_element; ebN_element++)
2018 const int ebN = elementBoundariesArray.data()[eN*nDOF_mesh_trial_element+ebN_element];
2021 if (elementBoundaryElementsArray[ebN*2+1] != -1 && element_phi_s[(ebN_element+1)%nDOF_mesh_trial_element]*element_phi_s[(ebN_element+2)%nDOF_mesh_trial_element] <= 0.0)
2024 if (elementBoundaryElementsArray[ebN*2 + 0] == eN)
2029 else if (icase_s == 1)
2031 element_active=
true;
2032 isActiveElement[eN]=1;
2035 int icase_p =
gf_p.calculate(element_phi, element_nodes, x_ref.data(), -
rho_1*g.data()[1], -
rho_0*g.data()[1],
false,
true);
2036 int icase =
gf.calculate(element_phi, element_nodes, x_ref.data(),
rho_1*
nu_1,
rho_0*
nu_0,
false,
false);
2038 int icase_p =
gf_p.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,
false,
false);
2039 int icase =
gf.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,
false,
false);
2044 for (
int ebN_element=0;ebN_element < nDOF_mesh_trial_element; ebN_element++)
2046 const int ebN = elementBoundariesArray.data()[eN*nDOF_mesh_trial_element+ebN_element];
2055 double numDiffMax=0.0;
2056 for(
int fluid_phase=0;fluid_phase < 2 - abs(icase);fluid_phase++)
2058 for(
int k=0;k<nQuadraturePoints_element;k++)
2061 register int eN_k = eN*nQuadraturePoints_element+k,
2062 eN_k_nSpace = eN_k*nSpace,
2064 eN_nDOF_trial_element = eN*nDOF_trial_element,
2065 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element;
2066 register double p=0.0,
u=0.0,
v=0.0,
w=0.0,
2068 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
2096 mom_uu_diff_ten[nSpace]=
ZEROVEC,
2097 mom_vv_diff_ten[nSpace]=
ZEROVEC,
2098 mom_ww_diff_ten[nSpace]=
ZEROVEC,
2109 dmom_u_ham_grad_p[nSpace]=
ZEROVEC,
2110 dmom_u_ham_grad_u[nSpace]=
ZEROVEC,
2111 dmom_u_ham_grad_v[nSpace]=
ZEROVEC,
2116 dmom_v_ham_grad_p[nSpace]=
ZEROVEC,
2117 dmom_v_ham_grad_u[nSpace]=
ZEROVEC,
2118 dmom_v_ham_grad_v[nSpace]=
ZEROVEC,
2123 dmom_w_ham_grad_p[nSpace]=
ZEROVEC,
2124 dmom_w_ham_grad_w[nSpace]=
ZEROVEC,
2138 Lstar_u_p[nDOF_test_element],
2139 Lstar_v_p[nDOF_test_element],
2140 Lstar_w_p[nDOF_test_element],
2141 Lstar_u_u[nDOF_v_test_element],
2142 Lstar_v_v[nDOF_v_test_element],
2143 Lstar_w_w[nDOF_v_test_element],
2144 Lstar_p_u[nDOF_v_test_element],
2145 Lstar_p_v[nDOF_v_test_element],
2146 Lstar_p_w[nDOF_v_test_element],
2151 tau_p=0.0,tau_p0=0.0,tau_p1=0.0,
2152 tau_v=0.0,tau_v0=0.0,tau_v1=0.0,
2155 jacInv[nSpace*nSpace],
2156 p_trial[nDOF_trial_element], vel_trial[nDOF_v_trial_element],
2157 p_grad_trial_ib[nDOF_trial_element*nSpace], vel_grad_trial_ib[nDOF_v_trial_element*nSpace],
2158 p_grad_trial[nDOF_trial_element*nSpace],vel_grad_trial[nDOF_v_trial_element*nSpace],
2159 p_test_dV[nDOF_trial_element],vel_test_dV[nDOF_v_test_element],
2160 p_grad_test_dV[nDOF_test_element*nSpace],vel_grad_test_dV[nDOF_v_test_element*nSpace],
2167 dmom_u_source[nSpace]=
ZEROVEC,
2168 dmom_v_source[nSpace]=
ZEROVEC,
2169 dmom_w_source[nSpace]=
ZEROVEC,
2171 G[nSpace*nSpace],G_dd_G,tr_G,norm_Rv,h_phi, dmom_adv_star[nSpace]=
ZEROVEC,dmom_adv_sge[nSpace]=
ZEROVEC,dmom_ham_grad_sge[nSpace]=
ZEROVEC,
2177 dmom_u_source_s[nSpace]=
ZEROVEC,
2178 dmom_v_source_s[nSpace]=
ZEROVEC,
2179 dmom_w_source_s[nSpace]=
ZEROVEC,
2183 dmom_u_adv_u_s[nSpace]=
ZEROVEC,
2184 dmom_v_adv_v_s[nSpace]=
ZEROVEC,
2185 dmom_w_adv_w_s[nSpace]=
ZEROVEC,
2187 dmom_u_ham_grad_u_s[nSpace]=
ZEROVEC,
2188 dmom_u_ham_grad_v_s[nSpace]=
ZEROVEC,
2193 dmom_v_ham_grad_u_s[nSpace]=
ZEROVEC,
2194 dmom_v_ham_grad_v_s[nSpace]=
ZEROVEC,
2199 dmom_w_ham_grad_w_s[nSpace]=
ZEROVEC,
2211 ck.calculateMapping_element(eN,
2215 mesh_trial_ref.data(),
2216 mesh_grad_trial_ref.data(),
2221 ck.calculateH_element(eN,
2223 nodeDiametersArray.data(),
2225 mesh_trial_ref.data(),
2228 ck.calculateMappingVelocity_element(eN,
2230 mesh_velocity_dof.data(),
2232 mesh_trial_ref.data(),
2237 dV = fabs(jacDet)*dV_ref.data()[k];
2238 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2241 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2242 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2245 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
2246 ck_v.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_v_trial_element*nSpace],jacInv,vel_grad_trial);
2247 for (
int i=0; i < nDOF_trial_element; i++)
2249 p_trial[i] = p_trial_ref.data()[k*nDOF_trial_element + i];
2250 p_grad_trial_ib[i*nSpace + 0] = p_grad_trial[i*nSpace+0];
2251 p_grad_trial_ib[i*nSpace + 1] = p_grad_trial[i*nSpace+1];
2253 for (
int i=0; i < nDOF_v_trial_element; i++)
2255 vel_trial[i] = vel_trial_ref.data()[k*nDOF_v_trial_element + i];
2256 vel_grad_trial_ib[i*nSpace + 0] = vel_grad_trial[i*nSpace+0];
2257 vel_grad_trial_ib[i*nSpace + 1] = vel_grad_trial[i*nSpace+1];
2262 for (
int i=0; i < nDOF_trial_element; i++)
2264 if (fluid_phase == 0)
2266 if (not std::isnan(
gf_p.VA(i)))
2268 p_trial[i] =
gf_p.VA(i);
2269 p_grad_trial_ib[i*nSpace + 0] =
gf_p.VA_x(i);
2270 p_grad_trial_ib[i*nSpace + 1] =
gf_p.VA_y(i);
2275 if (not std::isnan(
gf_p.VB(i)))
2277 p_trial[i] =
gf_p.VB(i);
2278 p_grad_trial_ib[i*nSpace + 0] =
gf_p.VB_x(i);
2279 p_grad_trial_ib[i*nSpace + 1] =
gf_p.VB_y(i);
2283 if(nDOF_v_trial_element == nDOF_trial_element)
2285 for (
int vi=0; vi < nDOF_v_trial_element; vi++)
2287 if (fluid_phase == 0)
2289 if (not std::isnan(
gf.VA(vi)))
2291 vel_trial[vi] =
gf.VA(vi);
2292 vel_grad_trial_ib[vi*nSpace + 0] =
gf.VA_x(vi);
2293 vel_grad_trial_ib[vi*nSpace + 1] =
gf.VA_y(vi);
2298 if (not std::isnan(
gf.VB(vi)))
2300 vel_trial[vi] =
gf.VB(vi);
2301 vel_grad_trial_ib[vi*nSpace + 0] =
gf.VB_x(vi);
2302 vel_grad_trial_ib[vi*nSpace + 1] =
gf.VB_y(vi);
2310 for (
int vi=0; vi < nDOF_v_trial_element; vi++)
2313 if (fabs(p_trial_ref.data()[k*nDOF_trial_element + vi] - p_trial[vi]) > 1.0e-8)
2315 for (
int vj=0; vj < nDOF_trial_element; vj++)
2316 std::cout<<
"Trial "<<p_trial_ref.data()[k*nDOF_trial_element + vj]<<
'\t'<<
gf_p.VA(vj)<<
'\t'<<
gf_p.VB(vj)<<std::endl;
2319 if (fabs(p_grad_trial[vi*nSpace + 0] - p_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
2321 for (
int vj=0; vj < nDOF_trial_element; vj++)
2322 std::cout<<
"Grad Trial x"<<p_grad_trial[vj*nSpace + 0]<<
'\t'<<
gf_p.VA_x(vj)<<
'\t'<<
gf_p.VB_x(vj)<<std::endl;
2325 if (fabs(p_grad_trial[vi*nSpace + 1] - p_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
2327 for (
int vj=0; vj < nDOF_trial_element; vj++)
2328 std::cout<<
"Grad Trial y "<<p_grad_trial[vj*nSpace + 1]<<
'\t'<<
gf_p.VA_y(vj)<<
'\t'<<
gf_p.VB_y(vj)<<std::endl;
2332 if (fabs(vel_trial_ref.data()[k*nDOF_v_trial_element + vi] - vel_trial[vi]) > 1.0e-8)
2334 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
2335 std::cout<<
"Trial "<<vel_trial_ref.data()[k*nDOF_v_trial_element + vj]<<
'\t'<<
gf.VA(vj)<<
'\t'<<
gf.VB(vj)<<std::endl;
2338 if (fabs(vel_grad_trial[vi*nSpace + 0] - vel_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
2340 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
2341 std::cout<<
"Grad Trial x"<<vel_grad_trial[vj*nSpace + 0]<<
'\t'<<
gf.VA_x(vj)<<
'\t'<<
gf.VB_x(vj)<<std::endl;
2344 if (fabs(vel_grad_trial[vi*nSpace + 1] - vel_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
2346 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
2347 std::cout<<
"Grad Trial y "<<vel_grad_trial[vj*nSpace + 1]<<
'\t'<<
gf.VA_y(vj)<<
'\t'<<
gf.VB_y(vj)<<std::endl;
2357 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_trial,p);
2358 ck_v.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,
u);
2359 ck_v.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,
v);
2360 ck.valFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_trial,p_old);
2361 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,u_old);
2362 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,v_old);
2364 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_ib,grad_p);
2365 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u);
2366 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v);
2367 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_ib,grad_p_old);
2368 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u_old);
2369 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v_old);
2371 if (PRESSURE_PROJECTION_STABILIZATION)
2372 ck.DOFaverage(p_dof.data(), &p_l2g.data()[eN_nDOF_trial_element],p_element_avg);
2375 for (
int j=0;j<nDOF_test_element;j++)
2377 p_test_dV[j] = p_trial[j]*dV;
2378 for (
int I=0;I<nSpace;I++)
2380 p_grad_test_dV[j*nSpace+I] = p_grad_trial_ib[j*nSpace+I]*dV;
2384 for (
int j=0;j<nDOF_v_test_element;j++)
2386 vel_test_dV[j] = vel_trial[j]*dV;
2387 for (
int I=0;I<nSpace;I++)
2389 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial_ib[j*nSpace+I]*dV;
2393 for (
int j=0;j<nDOF_test_element;j++)
2395 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element+j]*dV;
2396 for (
int I=0;I<nSpace;I++)
2398 p_grad_test_dV[j*nSpace+I] = p_grad_trial[j*nSpace+I]*dV;
2402 for (
int j=0;j<nDOF_v_test_element;j++)
2404 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_v_trial_element+j]*dV;
2405 for (
int I=0;I<nSpace;I++)
2407 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial[j*nSpace+I]*dV;
2412 double div_mesh_velocity=0.0;
2413 for (
int j=0;j<nDOF_trial_element;j++)
2415 int eN_j=eN*nDOF_trial_element+j;
2416 div_mesh_velocity +=
2417 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+0]*p_grad_trial[j*nSpace+0] +
2418 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+1]*p_grad_trial[j*nSpace+1];
2420 mesh_volume_conservation_element += (alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity)*dV;
2421 div_mesh_velocity =
DM3*div_mesh_velocity + (1.0-
DM3)*alphaBDF*(dV-q_dV_last.data()[eN_k])/dV;
2423 porosity = q_porosity.data()[eN_k];
2425 q_velocity.data()[eN_k_nSpace+0]=
u;
2426 q_velocity.data()[eN_k_nSpace+1]=
v;
2427 q_x.data()[eN_k_3d + 0] = x;
2428 q_x.data()[eN_k_3d + 1] = y;
2429 double ball_n[nSpace];
2430 if (use_ball_as_particle == 1 && nParticles > 0)
2432 int ball_index=
get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x,y,
z,distance_to_solids.data()[eN_k]);
2433 get_normal_to_ith_ball(nParticles, ball_center.data(), ball_radius.data(),ball_index,x,y,
z,ball_n[0],ball_n[1]);
2440 phi_solid.data()[eN_k] = distance_to_solids.data()[eN_k];
2441 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2445 const double H_s =
gf_s.H(particle_eps,phi_solid.data()[eN_k]);
2446 const double D_s =
gf_s.D(particle_eps,phi_solid.data()[eN_k]);
2448 double p_e = q_u_0.data()[eN_k] - p,
2449 u_e = q_u_1.data()[eN_k] -
u,
2450 v_e = q_u_2.data()[eN_k] -
v,
2451 velocity_e=sqrt(u_e*u_e + v_e*v_e);
2464 if (fluid_phase == 0)
2475 else if (icase == -1)
2480 else if (icase == 1)
2490 double H = (1.0-useVF)*
gf.H(eps_rho,
phi[eN_k]) + useVF*fmin(1.0,fmax(0.0,vf[eN_k]));
2491 double ImH = (1.0-useVF)*
gf.ImH(eps_rho,
phi[eN_k]) + useVF*(1.0-fmin(1.0,fmax(0.0,vf[eN_k])));
2500 elementDiameter.data()[eN],
2501 smagorinskyConstant,
2502 turbulenceClosureModel,
2507 &normal_phi.data()[eN_k_nSpace],
2508 kappa_phi.data()[eN_k],
2511 phi_solid.data()[eN_k],
2530 q_eddy_viscosity.data()[eN_k],
2531 q_eddy_viscosity_last.data()[eN_k],
2584 forcex.data()[eN_k],
2585 forcey.data()[eN_k],
2586 forcez.data()[eN_k]);
2587 q_rho.data()[eN_k] = rho;
2589 mass_source = q_mass_source.data()[eN_k];
2596 q_dragAlpha.data()[eN_k],
2597 q_dragBeta.data()[eN_k],
2610 q_velocity_sge.data()[eN_k_nSpace+0],
2611 q_velocity_sge.data()[eN_k_nSpace+1],
2612 q_velocity_sge.data()[eN_k_nSpace+1],
2613 eps_porous.data()[elementFlags.data()[eN]],
2614 phi_porous.data()[eN_k],
2615 q_velocity_porous.data()[eN_k_nSpace+0],
2616 q_velocity_porous.data()[eN_k_nSpace+1],
2617 q_velocity_porous.data()[eN_k_nSpace+1],
2625 if (turbulenceClosureModel >= 3)
2627 const double c_mu = 0.09;
2629 turbulenceClosureModel,
2641 q_turb_var_0.data()[eN_k],
2642 q_turb_var_1.data()[eN_k],
2643 &q_turb_var_grad_0.data()[eN_k_nSpace],
2644 q_eddy_viscosity.data()[eN_k],
2661 if (NONCONSERVATIVE_FORM > 0.0)
2663 mom_u_ham -= MOVING_DOMAIN*dmom_u_acc_u*(grad_u[0]*
xt + grad_u[1]*yt);
2664 dmom_u_ham_grad_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*
xt;
2665 dmom_u_ham_grad_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
2669 mom_u_adv[0] -= MOVING_DOMAIN*mom_u_acc*
xt;
2670 mom_u_adv[1] -= MOVING_DOMAIN*mom_u_acc*yt;
2671 dmom_u_adv_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*
xt;
2672 dmom_u_adv_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
2675 if (NONCONSERVATIVE_FORM > 0.0)
2677 mom_v_ham -= MOVING_DOMAIN*dmom_v_acc_v*(grad_v[0]*
xt + grad_v[1]*yt);
2678 dmom_v_ham_grad_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*
xt;
2679 dmom_v_ham_grad_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
2683 mom_v_adv[0] -= MOVING_DOMAIN*mom_v_acc*
xt;
2684 mom_v_adv[1] -= MOVING_DOMAIN*mom_v_acc*yt;
2685 dmom_v_adv_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*
xt;
2686 dmom_v_adv_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
2692 if (q_dV_last.data()[eN_k] <= -100)
2693 q_dV_last.data()[eN_k] = dV;
2694 q_dV.data()[eN_k] = dV;
2696 q_mom_u_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
2702 q_mom_v_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
2708 if (NONCONSERVATIVE_FORM > 0.0)
2710 mom_u_acc_t *= dmom_u_acc_u;
2711 mom_v_acc_t *= dmom_v_acc_v;
2717 pdeResidual_p =
ck.Advection_strong(dmass_adv_u,grad_u) +
2718 ck.Advection_strong(dmass_adv_v,grad_v) +
2719 DM2*MOVING_DOMAIN*
ck.Reaction_strong(alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity) +
2720 ck.Reaction_strong(mass_source);
2722 if (NONCONSERVATIVE_FORM > 0.0)
2724 dmom_adv_sge[0] = 0.0;
2725 dmom_adv_sge[1] = 0.0;
2726 dmom_ham_grad_sge[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt);
2727 dmom_ham_grad_sge[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
2731 dmom_adv_sge[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt);
2732 dmom_adv_sge[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
2733 dmom_ham_grad_sge[0] = 0.0;
2734 dmom_ham_grad_sge[1] = 0.0;
2736 double mv_tau[nSpace]=
ZEROVEC;
2737 mv_tau[0] = dmom_adv_sge[0] + dmom_ham_grad_sge[0];
2738 mv_tau[1] = dmom_adv_sge[1] + dmom_ham_grad_sge[1];
2740 pdeResidual_u =
ck.Mass_strong(mom_u_acc_t) +
2741 ck.Advection_strong(dmom_adv_sge,grad_u) +
2742 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_u) +
2743 ck.Hamiltonian_strong(dmom_u_ham_grad_p,grad_p) +
2744 ck.Reaction_strong(mom_u_source) -
2745 ck.Reaction_strong(dmom_u_acc_u*
u*div_mesh_velocity);
2747 pdeResidual_v =
ck.Mass_strong(mom_v_acc_t) +
2748 ck.Advection_strong(dmom_adv_sge,grad_v) +
2749 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_v) +
2750 ck.Hamiltonian_strong(dmom_v_ham_grad_p,grad_p) +
2751 ck.Reaction_strong(mom_v_source) -
2752 ck.Reaction_strong(dmom_v_acc_v*
v*div_mesh_velocity);
2756 double tmpR=dmom_u_acc_u_t + dmom_u_source[0];
2758 elementDiameter.data()[eN],
2763 dmom_u_ham_grad_p[0],
2766 q_cfl.data()[eN_k]);
2773 dmom_u_ham_grad_p[0],
2776 q_cfl.data()[eN_k]);
2778 tau_v = useMetrics*tau_v1+(1.0-useMetrics)*tau_v0;
2779 tau_p = useMetrics*tau_p1+(1.0-useMetrics)*tau_p0;
2792 dmom_adv_star[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt + useRBLES*subgridError_u);
2793 dmom_adv_star[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt + useRBLES*subgridError_v);
2795 mom_u_adv[0] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u*q_velocity_sge.data()[eN_k_nSpace+0]);
2796 mom_u_adv[1] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v*q_velocity_sge.data()[eN_k_nSpace+0]);
2798 mom_v_adv[0] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u*q_velocity_sge.data()[eN_k_nSpace+1]);
2799 mom_v_adv[1] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v*q_velocity_sge.data()[eN_k_nSpace+1]);
2802 for (
int i=0;i<nDOF_test_element;i++)
2804 register int i_nSpace = i*nSpace;
2805 Lstar_u_p[i]=
ck.Advection_adjoint(dmass_adv_u,&p_grad_test_dV[i_nSpace]);
2806 Lstar_v_p[i]=
ck.Advection_adjoint(dmass_adv_v,&p_grad_test_dV[i_nSpace]);
2808 for (
int i=0;i<nDOF_v_test_element;i++)
2810 register int i_nSpace = i*nSpace;
2812 Lstar_u_u[i]=
ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
2813 Lstar_v_v[i]=
ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
2814 Lstar_p_u[i]=
ck.Hamiltonian_adjoint(dmom_u_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
2815 Lstar_p_v[i]=
ck.Hamiltonian_adjoint(dmom_v_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
2818 Lstar_u_u[i]+=
ck.Reaction_adjoint(dmom_u_source[0],vel_test_dV[i]);
2819 Lstar_v_v[i]+=
ck.Reaction_adjoint(dmom_v_source[1],vel_test_dV[i]);
2823 norm_Rv = sqrt(pdeResidual_u*pdeResidual_u + pdeResidual_v*pdeResidual_v);
2824 q_numDiff_u.data()[eN_k] = C_dc*norm_Rv*(useMetrics/sqrt(G_dd_G+1.0e-12) +
2825 (1.0-useMetrics)*hFactor*hFactor*elementDiameter.data()[eN]*elementDiameter.data()[eN]);
2826 q_numDiff_v.data()[eN_k] = q_numDiff_u.data()[eN_k];
2827 q_numDiff_w.data()[eN_k] = q_numDiff_u.data()[eN_k];
2828 numDiffMax = std::fmax(q_numDiff_u.data()[eN_k], numDiffMax);
2832 double level_set_normal[nSpace];
2836 double norm_exact=0.0,norm_cut=0.0;
2837 if (use_ball_as_particle)
2839 for (
int I=0;I<nSpace;I++)
2841 sign += ball_n[I]*
gf_s.get_normal()[I];
2842 level_set_normal[I] =
gf_s.get_normal()[I];
2843 norm_cut += level_set_normal[I]*level_set_normal[I];
2844 norm_exact += ball_n[I]*ball_n[I];
2849 for (
int I=0;I<nSpace;I++)
2851 sign += particle_signed_distance_normals.data()[eN_k_3d+I]*
gf_s.get_normal()[I];
2852 level_set_normal[I] =
gf_s.get_normal()[I];
2853 norm_cut += level_set_normal[I]*level_set_normal[I];
2854 norm_exact += particle_signed_distance_normals.data()[eN_k_3d+I]*particle_signed_distance_normals.data()[eN_k_3d+I];
2857 norm_cut = std::sqrt(norm_cut);
2858 norm_exact = std::sqrt(norm_exact);
2859 assert(std::fabs(1.0-norm_cut) < 1.0e-8);
2860 assert(std::fabs(1.0-norm_exact) < 1.0e-8);
2862 for (
int I=0;I<nSpace;I++)
2863 level_set_normal[I]*=-1.0;
2873 if (use_ball_as_particle)
2874 for (
int I=0;I<nSpace;I++)
2875 level_set_normal[I] = ball_n[I];
2877 for (
int I=0;I<nSpace;I++)
2878 level_set_normal[I] = particle_signed_distance_normals.data()[eN_k_3d+I];
2881 NONCONSERVATIVE_FORM,
2882 eN < nElements_owned,
2886 nQuadraturePoints_global,
2887 &particle_signed_distances.data()[eN_k],
2889 &particle_velocities.data()[eN_k_3d],
2890 particle_centroids.data(),
2891 use_ball_as_particle,
2894 ball_velocity.data(),
2895 ball_angular_velocity.data(),
2896 ball_density.data(),
2898 particle_penalty_constant/h_phi,
2917 q_velocity_sge.data()[eN_k_nSpace+0],
2918 q_velocity_sge.data()[eN_k_nSpace+1],
2919 q_velocity_sge.data()[eN_k_nSpace+1],
2938 dmom_u_ham_grad_u_s,
2939 dmom_u_ham_grad_v_s,
2944 dmom_v_ham_grad_u_s,
2945 dmom_v_ham_grad_v_s,
2950 dmom_w_ham_grad_w_s,
2958 particle_netForces.data(),
2959 particle_netMoments.data(),
2960 particle_surfaceArea.data());
2976 q_mom_u_acc.data()[eN_k] = mom_u_acc;
2977 q_mom_v_acc.data()[eN_k] = mom_v_acc;
2979 q_mass_adv.data()[eN_k_nSpace+0] =
u;
2980 q_mass_adv.data()[eN_k_nSpace+1] =
v;
2984 if (use_ball_as_particle)
2986 q_mom_u_acc.data()[eN_k] = particle_velocities.data()[eN_k_3d+0];
2987 q_mom_v_acc.data()[eN_k] = particle_velocities.data()[eN_k_3d+1];
2988 q_mass_adv.data()[eN_k_nSpace+0] = particle_velocities.data()[eN_k_3d+0];
2989 q_mass_adv.data()[eN_k_nSpace+1] = particle_velocities.data()[eN_k_3d+1];
2993 q_mom_u_acc.data()[eN_k] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+0];
2994 q_mom_v_acc.data()[eN_k] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+1];
2995 q_mass_adv.data()[eN_k_nSpace+0] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+0];
2996 q_mass_adv.data()[eN_k_nSpace+1] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+1];
3002 double mesh_vel[nSpace];
3006 if (
gf.useExact && icase == 0)
3008 if (fluid_phase == 0)
3009 H_f =
gf.ImH(0.,0.);
3023 if ((eN < nElements_owned) && isActiveElement[eN])
3025 domain_volume += H_s*dV*H_f;
3026 p_L1 += fabs(p_e)*H_s*dV*H_f;
3027 u_L1 += fabs(u_e)*H_s*dV*H_f;
3028 v_L1 += fabs(v_e)*H_s*dV*H_f;
3029 velocity_L1 += fabs(velocity_e)*H_s*dV*H_f;
3031 p_L2 += p_e*p_e*H_s*dV*H_f;
3032 u_L2 += u_e*u_e*H_s*dV*H_f;
3033 v_L2 += v_e*v_e*H_s*dV*H_f;
3034 velocity_L2 += velocity_e*velocity_e*H_s*dV*H_f;
3035 p_dv += p*H_s*H_f*dV;
3036 pa_dv += q_u_0.data()[eN_k]*H_s*H_f*dV;
3037 total_volume+=H_s*H_f*dV;
3038 total_surface_area+=D_s*H_f*dV;
3039 if (phi_solid.data()[eN_k] >= 0.0)
3041 p_LI = fmax(p_LI, fabs(p_e));
3042 u_LI = fmax(u_LI, fabs(u_e));
3043 v_LI = fmax(v_LI, fabs(v_e));
3044 velocity_LI = fmax(velocity_LI, fabs(velocity_e));
3047 for(
int i=0;i<nDOF_test_element;i++)
3049 register int i_nSpace=i*nSpace;
3050 elementResidual_mesh[i] += H_s*H_f*(
ck.Reaction_weak(1.0,p_test_dV[i]) -
3051 ck.Reaction_weak(1.0,p_test_dV[i]*q_dV_last.data()[eN_k]/dV) -
3052 ck.Advection_weak(mesh_vel,&p_grad_test_dV[i_nSpace]));
3053 elementResidual_p[i] += H_s*H_f*(
ck.Advection_weak(mass_adv,&p_grad_test_dV[i_nSpace])
3054 +
ck.Hamiltonian_weak(mass_ham, p_test_dV[i])
3055 +
DM*MOVING_DOMAIN*(
ck.Reaction_weak(alphaBDF*1.0,p_test_dV[i]) -
3056 ck.Reaction_weak(alphaBDF*1.0,p_test_dV[i]*q_dV_last.data()[eN_k]/dV) -
3057 ck.Advection_weak(mesh_vel,&p_grad_test_dV[i_nSpace])) +
3058 ck.Reaction_weak(mass_source,p_test_dV[i]));
3059 if (nDOF_test_element == nDOF_v_test_element)
3061 elementResidual_p[i] +=
3062 H_s*H_f*(PRESSURE_PROJECTION_STABILIZATION *
ck.pressureProjection_weak(mom_uu_diff_ten[1], p, p_element_avg, p_test_ref.data()[k*nDOF_test_element+i], dV) +
3063 (1 - PRESSURE_PROJECTION_STABILIZATION) *
ck.SubgridError(subgridError_u,Lstar_u_p[i]) +
3064 (1 - PRESSURE_PROJECTION_STABILIZATION) *
ck.SubgridError(subgridError_v,Lstar_v_p[i]));
3066 if (PRESSURE_PROJECTION_STABILIZATION==1. && mom_uu_diff_ten[1]==0.)
3068 printf(
"Warning the Bochev-Dohrnmann-Gunzburger stabilization cannot be applied to inviscid fluids.");
3072 if (
gf_s.D(0.,0.) == 0.0)
3073 assert(mass_source_s == 0.0);
3074 elementResidual_p[i] += H_f*(
ck.Reaction_weak(mass_source_s,p_test_dV[i]));
3077 for(
int i=0;i<nDOF_v_test_element;i++)
3079 register int i_nSpace=i*nSpace;
3080 elementResidual_u[i] += H_s*H_f*(
ck.Mass_weak(mom_u_acc_t,vel_test_dV[i]) +
3081 ck.Advection_weak(mom_u_adv,&vel_grad_test_dV[i_nSpace]) +
3082 ck.Diffusion_weak(sdInfo_u_u_rowptr.data(),sdInfo_u_u_colind.data(),mom_uu_diff_ten,grad_u,&vel_grad_test_dV[i_nSpace]) +
3083 ck.Diffusion_weak(sdInfo_u_v_rowptr.data(),sdInfo_u_v_colind.data(),mom_uv_diff_ten,grad_v,&vel_grad_test_dV[i_nSpace]) +
3084 ck.Reaction_weak(mom_u_source+NONCONSERVATIVE_FORM*dmom_u_acc_u*
u*div_mesh_velocity,vel_test_dV[i]) +
3085 ck.Hamiltonian_weak(mom_u_ham,vel_test_dV[i]) +
3086 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridError(subgridError_u,Lstar_u_u[i]) +
3087 ck.NumericalDiffusion(q_numDiff_u_last.data()[eN_k],grad_u,&vel_grad_test_dV[i_nSpace]));
3088 elementResidual_v[i] += H_s*H_f*(
ck.Mass_weak(mom_v_acc_t,vel_test_dV[i]) +
3089 ck.Advection_weak(mom_v_adv,&vel_grad_test_dV[i_nSpace]) +
3090 ck.Diffusion_weak(sdInfo_v_u_rowptr.data(),sdInfo_v_u_colind.data(),mom_vu_diff_ten,grad_u,&vel_grad_test_dV[i_nSpace]) +
3091 ck.Diffusion_weak(sdInfo_v_v_rowptr.data(),sdInfo_v_v_colind.data(),mom_vv_diff_ten,grad_v,&vel_grad_test_dV[i_nSpace]) +
3092 ck.Reaction_weak(mom_v_source+NONCONSERVATIVE_FORM*dmom_v_acc_v*
v*div_mesh_velocity,vel_test_dV[i]) +
3093 ck.Hamiltonian_weak(mom_v_ham,vel_test_dV[i]) +
3094 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridError(subgridError_v,Lstar_v_v[i]) +
3095 ck.NumericalDiffusion(q_numDiff_v_last.data()[eN_k],grad_v,&vel_grad_test_dV[i_nSpace]));
3096 elementResidual_u[i] += H_s*H_f*MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridError(subgridError_p,Lstar_p_u[i]);
3097 elementResidual_v[i] += H_s*H_f*MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridError(subgridError_p,Lstar_p_v[i]);
3100 elementResidual_u[i] += H_f*(
ck.Advection_weak(mom_u_adv_s,&vel_grad_test_dV[i_nSpace]) +
3101 ck.Reaction_weak(mom_u_source_s,vel_test_dV[i]) +
3102 ck.Hamiltonian_weak(mom_u_ham_s,vel_test_dV[i]));
3103 elementResidual_v[i] += H_f*(
ck.Advection_weak(mom_v_adv_s,&vel_grad_test_dV[i_nSpace]) +
3104 ck.Reaction_weak(mom_v_source_s,vel_test_dV[i]) +
3105 ck.Hamiltonian_weak(mom_v_ham_s,vel_test_dV[i]));
3109 numerical_viscosity.data()[eN_k] = q_numDiff_u_last.data()[eN_k] + MOMENTUM_SGE*VELOCITY_SGE*tau_v*(dmom_adv_star[0]*dmom_adv_star[0]+
3110 dmom_adv_star[1]*dmom_adv_star[1]);
3111 if (!isActiveElement[eN])
3113 assert(std::fabs(
gf_s.H(particle_eps,phi_solid.data()[eN_k])) == 0.0);
3114 assert(std::fabs(
gf_s.D(particle_eps,phi_solid.data()[eN_k])) == 0.0);
3119 for(
int k=0;k<nQuadraturePoints_element;k++)
3122 register int eN_k = eN*nQuadraturePoints_element+k;
3123 q_numDiff_u.data()[eN_k] = numDiffMax;
3124 q_numDiff_v.data()[eN_k] = numDiffMax;
3125 q_numDiff_w.data()[eN_k] = numDiffMax;
3131 for(
int i=0;i<nDOF_test_element;i++)
3133 register int eN_i=eN*nDOF_test_element+i;
3134 elementResidual_p_save.data()[eN_i] += elementResidual_p[i];
3135 mesh_volume_conservation_element_weak += elementResidual_mesh[i];
3136 if (!isActiveElement[eN])
3138 assert(elementResidual_p[i]==0.0);
3140 globalResidual.data()[offset_p+stride_p*rp_l2g.data()[eN_i]]+=elementResidual_p[i];
3143 isActiveR.data()[offset_p+stride_p*rp_l2g.data()[eN_i]] = 1.0;
3144 isActiveDOF_p.data()[p_l2g.data()[eN_i]] = 1.0;
3147 for(
int i=0;i<nDOF_v_test_element;i++)
3149 register int eN_i=eN*nDOF_v_test_element+i;
3150 if (!isActiveElement[eN])
3152 assert(elementResidual_u[i]==0.0);
3153 assert(elementResidual_v[i]==0.0);
3155 globalResidual.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]]+=elementResidual_u[i];
3156 globalResidual.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]]+=elementResidual_v[i];
3159 isActiveR.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]] = 1.0;
3160 isActiveR.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]] = 1.0;
3161 isActiveDOF_vel.data()[vel_l2g.data()[eN_i]] = 1.0;
3163 double x = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+0],
3164 y = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+1],
3165 z = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+2];
3168 ball_velocity.data(),ball_angular_velocity.data(),
3169 particle_index,x,y,
z,
3170 ball_u.data()[vel_l2g.data()[eN_i]],ball_v.data()[vel_l2g.data()[eN_i]]);
3172 mesh_volume_conservation += mesh_volume_conservation_element;
3173 mesh_volume_conservation_weak += mesh_volume_conservation_element_weak;
3174 mesh_volume_conservation_err_max=fmax(mesh_volume_conservation_err_max,fabs(mesh_volume_conservation_element));
3175 mesh_volume_conservation_err_max_weak=fmax(mesh_volume_conservation_err_max_weak,fabs(mesh_volume_conservation_element_weak));
3180 if(isActiveElement[elementBoundaryElementsArray[(*it)*2+0]] && isActiveElement[elementBoundaryElementsArray[(*it)*2+1]])
3182 std::map<int,double> DWp_Dn_jump, DW_Dn_jump;
3183 register double gamma_cutfem=ghost_penalty_constant,gamma_cutfem_p=ghost_penalty_constant,h_cutfem=elementBoundaryDiameter.data()[*it];
3184 int eN_nDOF_v_trial_element = elementBoundaryElementsArray.data()[(*it)*2+0]*nDOF_v_trial_element;
3188 for (
int i_offset=1;i_offset<nDOF_v_trial_element;i_offset++)
3191 double u=u_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
3192 v=v_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]];
3193 norm_v=fmax(norm_v,sqrt(
u*
u+
v*
v));
3195 double gamma_v_dim =
rho_0*(
nu_0 + norm_v*h_cutfem + alphaBDF*h_cutfem*h_cutfem);
3196 gamma_cutfem_p *= h_cutfem*h_cutfem/gamma_v_dim;
3197 if (NONCONSERVATIVE_FORM)
3198 gamma_cutfem*=gamma_v_dim;
3200 gamma_cutfem*=(gamma_v_dim/
rho_0);
3201 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
3203 register double Dp_Dn_jump=0.0, Du_Dn_jump=0.0, Dv_Dn_jump=0.0,dS;
3204 for (
int eN_side=0;eN_side < 2; eN_side++)
3206 register int ebN = *it,
3207 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
3208 for (
int i=0;i<nDOF_test_element;i++)
3210 DWp_Dn_jump[rp_l2g.data()[eN*nDOF_test_element+i]] = 0.0;
3212 for (
int i=0;i<nDOF_v_test_element;i++)
3214 DW_Dn_jump[rvel_l2g.data()[eN*nDOF_v_test_element+i]] = 0.0;
3217 for (
int eN_side=0;eN_side < 2; eN_side++)
3219 register int ebN = *it,
3220 eN = elementBoundaryElementsArray[ebN*2+eN_side],
3221 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+eN_side],
3222 eN_nDOF_trial_element = eN*nDOF_trial_element,
3223 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
3224 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
3225 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
3226 register double p_int=0.0,
3232 jac_int[nSpace*nSpace],
3234 jacInv_int[nSpace*nSpace],
3235 boundaryJac[nSpace*(nSpace-1)],
3236 metricTensor[(nSpace-1)*(nSpace-1)],
3237 metricTensorDetSqrt,
3238 p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
3239 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
3240 p_grad_test_dS[nDOF_trial_element*nSpace],vel_grad_test_dS[nDOF_v_trial_element*nSpace],
3241 normal[nSpace],x_int,y_int,z_int,xt_int,yt_int,zt_int,integralScaling,
3242 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
3243 force_x,force_y,force_z,force_p_x,force_p_y,force_p_z,force_v_x,force_v_y,force_v_z,r_x,r_y,r_z;
3245 ck.calculateMapping_elementBoundary(eN,
3251 mesh_trial_trace_ref.data(),
3252 mesh_grad_trial_trace_ref.data(),
3253 boundaryJac_ref.data(),
3259 metricTensorDetSqrt,
3264 ck.calculateMappingVelocity_elementBoundary(eN,
3268 mesh_velocity_dof.data(),
3270 mesh_trial_trace_ref.data(),
3271 xt_int,yt_int,zt_int,
3276 dS = metricTensorDetSqrt*dS_ref.data()[kb];
3279 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_int,p_grad_trial_trace);
3280 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_int,vel_grad_trial_trace);
3282 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],p_int);
3283 ck_v.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],u_int);
3284 ck_v.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],v_int);
3285 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_int);
3286 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_int);
3287 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_int);
3288 for (
int I=0;I<nSpace;I++)
3290 Dp_Dn_jump += grad_p_int[I]*normal[I];
3291 Du_Dn_jump += grad_u_int[I]*normal[I];
3292 Dv_Dn_jump += grad_v_int[I]*normal[I];
3294 for (
int i=0;i<nDOF_test_element;i++)
3296 for (
int I=0;I<nSpace;I++)
3297 DWp_Dn_jump[rp_l2g[eN_nDOF_trial_element+i]] += p_grad_trial_trace[i*nSpace+I]*normal[I];
3299 for (
int i=0;i<nDOF_v_test_element;i++)
3301 for (
int I=0;I<nSpace;I++)
3302 DW_Dn_jump[rvel_l2g[eN_nDOF_v_trial_element+i]] += vel_grad_trial_trace[i*nSpace+I]*normal[I];
3305 for (std::map<int,double>::iterator W_it=DWp_Dn_jump.begin(); W_it!=DWp_Dn_jump.end(); ++W_it)
3307 int i_global = W_it->first;
3308 double DWp_Dn_jump_i = W_it->second;
3309 globalResidual.data()[offset_p+stride_p*i_global]+=gamma_cutfem_p*h_cutfem*Dp_Dn_jump*DWp_Dn_jump_i*dS;
3311 for (std::map<int,double>::iterator W_it=DW_Dn_jump.begin(); W_it!=DW_Dn_jump.end(); ++W_it)
3313 int i_global = W_it->first;
3314 double DW_Dn_jump_i = W_it->second;
3315 globalResidual.data()[offset_u+stride_u*i_global]+=gamma_cutfem*h_cutfem*Du_Dn_jump*DW_Dn_jump_i*dS;
3316 globalResidual.data()[offset_v+stride_v*i_global]+=gamma_cutfem*h_cutfem*Dv_Dn_jump*DW_Dn_jump_i*dS;
3332 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
3334 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
3335 eN = elementBoundaryElementsArray.data()[ebN*2+0],
3336 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
3337 eN_nDOF_trial_element = eN*nDOF_trial_element,
3338 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element;
3339 if (boundaryFlags[ebN] < 1)
3341 register double elementResidual_mesh[nDOF_test_element],
3342 elementResidual_p[nDOF_test_element],
3343 elementResidual_u[nDOF_v_test_element],
3344 elementResidual_v[nDOF_v_test_element],
3346 const double* elementResidual_w(NULL);
3347 for (
int i=0;i<nDOF_test_element;i++)
3349 elementResidual_mesh[i]=0.0;
3350 elementResidual_p[i]=0.0;
3352 for (
int i=0;i<nDOF_v_test_element;i++)
3354 elementResidual_u[i]=0.0;
3355 elementResidual_v[i]=0.0;
3357 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
3358 for (
int j=0;j<nDOF_mesh_trial_element;j++)
3360 register int eN_j = eN*nDOF_mesh_trial_element+j;
3361 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
3362 element_phi_s[j] = phi_solid_nodes[p_l2g.data()[eN_j]];
3364 double element_nodes[nDOF_mesh_trial_element*3];
3365 for (
int i=0;i<nDOF_mesh_trial_element;i++)
3367 register int eN_i=eN*nDOF_mesh_trial_element+i;
3368 for(
int I=0;I<3;I++)
3369 element_nodes[i*3 + I] = mesh_dof[mesh_l2g.data()[eN_i]*3 + I];
3371 double mesh_dof_ref[nDOF_mesh_trial_element*3]={0.,0.,0.,1.,0.,0.,0.,1.,0.};
3372 double xb_ref_calc[nQuadraturePoints_elementBoundary*3];
3373 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
3375 double x=0.0,y=0.0,
z=0.0;
3376 for (
int j=0;j<nDOF_mesh_trial_element;j++)
3378 int ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb;
3379 int ebN_local_kb_j = ebN_local_kb*nDOF_mesh_trial_element+j;
3380 x += mesh_dof_ref[j*3+0]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
3381 y += mesh_dof_ref[j*3+1]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
3382 z += mesh_dof_ref[j*3+2]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
3384 xb_ref_calc[3*kb+0] = x;
3385 xb_ref_calc[3*kb+1] = y;
3386 xb_ref_calc[3*kb+2] =
z;
3388 int icase_s =
gf_s.calculate(element_phi_s, element_nodes, xb_ref_calc,
true);
3390 int icase =
gf.calculate(element_phi, element_nodes, xb_ref.data(), -
rho_1*g.data()[1], -
rho_0*g.data()[1],
true,
true);
3392 int icase =
gf.calculate(element_phi, element_nodes, xb_ref.data(), 1.0,1.0,
true,
false);
3395 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
3397 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
3398 ebNE_kb_nSpace = ebNE_kb*nSpace,
3399 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
3400 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
3401 register double phi_s_ext=0.0,
3410 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
3413 dmom_u_acc_u_ext=0.0,
3415 dmom_v_acc_v_ext=0.0,
3417 dmom_w_acc_w_ext=0.0,
3419 dmass_adv_u_ext[nSpace]=
ZEROVEC,
3420 dmass_adv_v_ext[nSpace]=
ZEROVEC,
3421 dmass_adv_w_ext[nSpace]=
ZEROVEC,
3422 mom_u_adv_ext[nSpace]=
ZEROVEC,
3423 dmom_u_adv_u_ext[nSpace]=
ZEROVEC,
3424 dmom_u_adv_v_ext[nSpace]=
ZEROVEC,
3425 dmom_u_adv_w_ext[nSpace]=
ZEROVEC,
3426 mom_v_adv_ext[nSpace]=
ZEROVEC,
3427 dmom_v_adv_u_ext[nSpace]=
ZEROVEC,
3428 dmom_v_adv_v_ext[nSpace]=
ZEROVEC,
3429 dmom_v_adv_w_ext[nSpace]=
ZEROVEC,
3430 mom_w_adv_ext[nSpace]=
ZEROVEC,
3431 dmom_w_adv_u_ext[nSpace]=
ZEROVEC,
3432 dmom_w_adv_v_ext[nSpace]=
ZEROVEC,
3433 dmom_w_adv_w_ext[nSpace]=
ZEROVEC,
3434 mom_uu_diff_ten_ext[nSpace]=
ZEROVEC,
3435 mom_vv_diff_ten_ext[nSpace]=
ZEROVEC,
3436 mom_ww_diff_ten_ext[nSpace]=
ZEROVEC,
3437 mom_uv_diff_ten_ext[1],
3438 mom_uw_diff_ten_ext[1],
3439 mom_vu_diff_ten_ext[1],
3440 mom_vw_diff_ten_ext[1],
3441 mom_wu_diff_ten_ext[1],
3442 mom_wv_diff_ten_ext[1],
3443 mom_u_source_ext=0.0,
3444 mom_v_source_ext=0.0,
3445 mom_w_source_ext=0.0,
3447 dmom_u_ham_grad_p_ext[nSpace]=
ZEROVEC,
3448 dmom_u_ham_grad_u_ext[nSpace]=
ZEROVEC,
3449 dmom_u_ham_u_ext=0.0,
3450 dmom_u_ham_v_ext=0.0,
3451 dmom_u_ham_w_ext=0.0,
3453 dmom_v_ham_grad_p_ext[nSpace]=
ZEROVEC,
3454 dmom_v_ham_grad_v_ext[nSpace]=
ZEROVEC,
3455 dmom_v_ham_u_ext=0.0,
3456 dmom_v_ham_v_ext=0.0,
3457 dmom_v_ham_w_ext=0.0,
3459 dmom_w_ham_grad_p_ext[nSpace]=
ZEROVEC,
3460 dmom_w_ham_grad_w_ext[nSpace]=
ZEROVEC,
3461 dmom_w_ham_u_ext=0.0,
3462 dmom_w_ham_v_ext=0.0,
3463 dmom_w_ham_w_ext=0.0,
3464 dmom_u_adv_p_ext[nSpace]=
ZEROVEC,
3465 dmom_v_adv_p_ext[nSpace]=
ZEROVEC,
3466 dmom_w_adv_p_ext[nSpace]=
ZEROVEC,
3468 flux_mom_u_adv_ext=0.0,
3469 flux_mom_v_adv_ext=0.0,
3470 flux_mom_w_adv_ext=0.0,
3471 flux_mom_uu_diff_ext=0.0,
3472 flux_mom_uv_diff_ext=0.0,
3473 flux_mom_uw_diff_ext=0.0,
3474 flux_mom_vu_diff_ext=0.0,
3475 flux_mom_vv_diff_ext=0.0,
3476 flux_mom_vw_diff_ext=0.0,
3477 flux_mom_wu_diff_ext=0.0,
3478 flux_mom_wv_diff_ext=0.0,
3479 flux_mom_ww_diff_ext=0.0,
3484 bc_mom_u_acc_ext=0.0,
3485 bc_dmom_u_acc_u_ext=0.0,
3486 bc_mom_v_acc_ext=0.0,
3487 bc_dmom_v_acc_v_ext=0.0,
3488 bc_mom_w_acc_ext=0.0,
3489 bc_dmom_w_acc_w_ext=0.0,
3490 bc_mass_adv_ext[nSpace]=
ZEROVEC,
3491 bc_dmass_adv_u_ext[nSpace]=
ZEROVEC,
3492 bc_dmass_adv_v_ext[nSpace]=
ZEROVEC,
3493 bc_dmass_adv_w_ext[nSpace]=
ZEROVEC,
3494 bc_mom_u_adv_ext[nSpace]=
ZEROVEC,
3495 bc_dmom_u_adv_u_ext[nSpace]=
ZEROVEC,
3496 bc_dmom_u_adv_v_ext[nSpace]=
ZEROVEC,
3497 bc_dmom_u_adv_w_ext[nSpace]=
ZEROVEC,
3498 bc_mom_v_adv_ext[nSpace]=
ZEROVEC,
3499 bc_dmom_v_adv_u_ext[nSpace]=
ZEROVEC,
3500 bc_dmom_v_adv_v_ext[nSpace]=
ZEROVEC,
3501 bc_dmom_v_adv_w_ext[nSpace]=
ZEROVEC,
3502 bc_mom_w_adv_ext[nSpace]=
ZEROVEC,
3503 bc_dmom_w_adv_u_ext[nSpace]=
ZEROVEC,
3504 bc_dmom_w_adv_v_ext[nSpace]=
ZEROVEC,
3505 bc_dmom_w_adv_w_ext[nSpace]=
ZEROVEC,
3506 bc_mom_uu_diff_ten_ext[nSpace]=
ZEROVEC,
3507 bc_mom_vv_diff_ten_ext[nSpace]=
ZEROVEC,
3508 bc_mom_ww_diff_ten_ext[nSpace]=
ZEROVEC,
3509 bc_mom_uv_diff_ten_ext[1],
3510 bc_mom_uw_diff_ten_ext[1],
3511 bc_mom_vu_diff_ten_ext[1],
3512 bc_mom_vw_diff_ten_ext[1],
3513 bc_mom_wu_diff_ten_ext[1],
3514 bc_mom_wv_diff_ten_ext[1],
3515 bc_mom_u_source_ext=0.0,
3516 bc_mom_v_source_ext=0.0,
3517 bc_mom_w_source_ext=0.0,
3518 bc_mom_u_ham_ext=0.0,
3519 bc_dmom_u_ham_grad_p_ext[nSpace]=
ZEROVEC,
3520 bc_dmom_u_ham_grad_u_ext[nSpace]=
ZEROVEC,
3521 bc_dmom_u_ham_u_ext=0.0,
3522 bc_dmom_u_ham_v_ext=0.0,
3523 bc_dmom_u_ham_w_ext=0.0,
3524 bc_mom_v_ham_ext=0.0,
3525 bc_dmom_v_ham_grad_p_ext[nSpace]=
ZEROVEC,
3526 bc_dmom_v_ham_grad_v_ext[nSpace]=
ZEROVEC,
3527 bc_dmom_v_ham_u_ext=0.0,
3528 bc_dmom_v_ham_v_ext=0.0,
3529 bc_dmom_v_ham_w_ext=0.0,
3530 bc_mom_w_ham_ext=0.0,
3531 bc_dmom_w_ham_grad_p_ext[nSpace]=
ZEROVEC,
3532 bc_dmom_w_ham_grad_w_ext[nSpace]=
ZEROVEC,
3533 bc_dmom_w_ham_u_ext=0.0,
3534 bc_dmom_w_ham_v_ext=0.0,
3535 bc_dmom_w_ham_w_ext=0.0,
3536 jac_ext[nSpace*nSpace],
3538 jacInv_ext[nSpace*nSpace],
3539 boundaryJac[nSpace*(nSpace-1)],
3540 metricTensor[(nSpace-1)*(nSpace-1)],
3541 metricTensorDetSqrt,
3542 dS,p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
3543 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
3544 vel_grad_test_dS[nDOF_v_trial_element*nSpace],
3545 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
3549 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
3550 force_x,force_y,force_z,force_p_x,force_p_y,force_p_z,force_v_x,force_v_y,force_v_z,r_x,r_y,r_z;
3552 gf_s.set_boundary_quad(kb);
3553 gf.set_boundary_quad(kb);
3554 ck.calculateMapping_elementBoundary(eN,
3560 mesh_trial_trace_ref.data(),
3561 mesh_grad_trial_trace_ref.data(),
3562 boundaryJac_ref.data(),
3568 metricTensorDetSqrt,
3572 ck.calculateMappingVelocity_elementBoundary(eN,
3576 mesh_velocity_dof.data(),
3578 mesh_trial_trace_ref.data(),
3579 xt_ext,yt_ext,zt_ext,
3591 dS = metricTensorDetSqrt*dS_ref.data()[kb];
3594 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
3595 ck.calculateGScale(G,&ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],h_phi);
3597 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
3598 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
3602 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,p_grad_trial_trace);
3603 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_ext,vel_grad_trial_trace);
3605 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],p_ext);
3606 ck_v.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],u_ext);
3607 ck_v.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],v_ext);
3608 ck.valFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],p_old);
3609 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],u_old);
3610 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],v_old);
3611 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_ext);
3612 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_ext);
3613 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_ext);
3614 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_old);
3615 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_old);
3616 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_old);
3617 ck.valFromDOF(phi_solid_nodes.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],phi_s_ext);
3619 for (
int j=0;j<nDOF_test_element;j++)
3621 p_test_dS[j] = p_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
3623 for (
int j=0;j<nDOF_v_test_element;j++)
3625 vel_test_dS[j] = vel_test_trace_ref.data()[ebN_local_kb*nDOF_v_test_element+j]*dS;
3626 for (
int I=0;I<nSpace;I++)
3627 vel_grad_test_dS[j*nSpace+I] = vel_grad_trial_trace[j*nSpace+I]*dS;
3629 bc_p_ext = isDOFBoundary_p.data()[ebNE_kb]*ebqe_bc_p_ext.data()[ebNE_kb]+(1-isDOFBoundary_p.data()[ebNE_kb])*p_ext;
3631 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*(ebqe_bc_u_ext.data()[ebNE_kb] + MOVING_DOMAIN*xt_ext) + (1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
3632 bc_v_ext = isDOFBoundary_v.data()[ebNE_kb]*(ebqe_bc_v_ext.data()[ebNE_kb] + MOVING_DOMAIN*yt_ext) + (1-isDOFBoundary_v.data()[ebNE_kb])*v_ext;
3634 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
3638 double eddy_viscosity_ext(0.),bc_eddy_viscosity_ext(0.);
3639 if (use_ball_as_particle == 1 && nParticles > 0)
3641 get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x_ext,y_ext,z_ext,ebqe_phi_s.data()[ebNE_kb]);
3644 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
3647 double H = (1.0-useVF)*
gf.H(eps_rho,ebqe_phi_ext[ebNE_kb]) + useVF*fmin(1.0,fmax(0.0,ebqe_vf_ext[ebNE_kb]));
3648 double ImH = (1.0-useVF)*
gf.ImH(eps_rho,ebqe_phi_ext[ebNE_kb]) + useVF*(1.0-fmin(1.0,fmax(0.0,ebqe_vf_ext[ebNE_kb])));
3656 elementDiameter.data()[eN],
3657 smagorinskyConstant,
3658 turbulenceClosureModel,
3661 ebqe_vf_ext.data()[ebNE_kb],
3662 ebqe_phi_ext.data()[ebNE_kb],
3663 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
3664 ebqe_kappa_phi_ext.data()[ebNE_kb],
3668 ebqe_phi_s.data()[ebNE_kb],
3686 ebqe_eddy_viscosity.data()[ebNE_kb],
3687 ebqe_eddy_viscosity_last.data()[ebNE_kb],
3710 mom_uu_diff_ten_ext,
3711 mom_vv_diff_ten_ext,
3712 mom_ww_diff_ten_ext,
3713 mom_uv_diff_ten_ext,
3714 mom_uw_diff_ten_ext,
3715 mom_vu_diff_ten_ext,
3716 mom_vw_diff_ten_ext,
3717 mom_wu_diff_ten_ext,
3718 mom_wv_diff_ten_ext,
3723 dmom_u_ham_grad_p_ext,
3724 dmom_u_ham_grad_u_ext,
3729 dmom_v_ham_grad_p_ext,
3730 dmom_v_ham_grad_v_ext,
3735 dmom_w_ham_grad_p_ext,
3736 dmom_w_ham_grad_w_ext,
3744 H = (1.0-useVF)*
gf.H(eps_rho,bc_ebqe_phi_ext[ebNE_kb]) + useVF*fmin(1.0,fmax(0.0,bc_ebqe_vf_ext[ebNE_kb]));
3745 ImH = (1.0-useVF)*
gf.ImH(eps_rho,bc_ebqe_phi_ext[ebNE_kb]) + useVF*(1.0-fmin(1.0,fmax(0.0,bc_ebqe_vf_ext[ebNE_kb])));
3753 elementDiameter.data()[eN],
3754 smagorinskyConstant,
3755 turbulenceClosureModel,
3758 bc_ebqe_vf_ext.data()[ebNE_kb],
3759 bc_ebqe_phi_ext.data()[ebNE_kb],
3760 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
3761 ebqe_kappa_phi_ext.data()[ebNE_kb],
3765 ebqe_phi_s.data()[ebNE_kb],
3783 bc_eddy_viscosity_ext,
3784 ebqe_eddy_viscosity_last.data()[ebNE_kb],
3786 bc_dmom_u_acc_u_ext,
3788 bc_dmom_v_acc_v_ext,
3790 bc_dmom_w_acc_w_ext,
3796 bc_dmom_u_adv_u_ext,
3797 bc_dmom_u_adv_v_ext,
3798 bc_dmom_u_adv_w_ext,
3800 bc_dmom_v_adv_u_ext,
3801 bc_dmom_v_adv_v_ext,
3802 bc_dmom_v_adv_w_ext,
3804 bc_dmom_w_adv_u_ext,
3805 bc_dmom_w_adv_v_ext,
3806 bc_dmom_w_adv_w_ext,
3807 bc_mom_uu_diff_ten_ext,
3808 bc_mom_vv_diff_ten_ext,
3809 bc_mom_ww_diff_ten_ext,
3810 bc_mom_uv_diff_ten_ext,
3811 bc_mom_uw_diff_ten_ext,
3812 bc_mom_vu_diff_ten_ext,
3813 bc_mom_vw_diff_ten_ext,
3814 bc_mom_wu_diff_ten_ext,
3815 bc_mom_wv_diff_ten_ext,
3816 bc_mom_u_source_ext,
3817 bc_mom_v_source_ext,
3818 bc_mom_w_source_ext,
3820 bc_dmom_u_ham_grad_p_ext,
3821 bc_dmom_u_ham_grad_u_ext,
3822 bc_dmom_u_ham_u_ext,
3823 bc_dmom_u_ham_v_ext,
3824 bc_dmom_u_ham_w_ext,
3826 bc_dmom_v_ham_grad_p_ext,
3827 bc_dmom_v_ham_grad_v_ext,
3828 bc_dmom_v_ham_u_ext,
3829 bc_dmom_v_ham_v_ext,
3830 bc_dmom_v_ham_w_ext,
3832 bc_dmom_w_ham_grad_p_ext,
3833 bc_dmom_w_ham_grad_w_ext,
3834 bc_dmom_w_ham_u_ext,
3835 bc_dmom_w_ham_v_ext,
3836 bc_dmom_w_ham_w_ext,
3842 if (turbulenceClosureModel >= 3)
3844 const double turb_var_grad_0_dummy[nSpace] =
ZEROVEC;
3845 const double c_mu = 0.09;
3847 turbulenceClosureModel,
3855 ebqe_vf_ext.data()[ebNE_kb],
3856 ebqe_phi_ext.data()[ebNE_kb],
3859 ebqe_turb_var_0.data()[ebNE_kb],
3860 ebqe_turb_var_1.data()[ebNE_kb],
3861 turb_var_grad_0_dummy,
3862 ebqe_eddy_viscosity.data()[ebNE_kb],
3863 mom_uu_diff_ten_ext,
3864 mom_vv_diff_ten_ext,
3865 mom_ww_diff_ten_ext,
3866 mom_uv_diff_ten_ext,
3867 mom_uw_diff_ten_ext,
3868 mom_vu_diff_ten_ext,
3869 mom_vw_diff_ten_ext,
3870 mom_wu_diff_ten_ext,
3871 mom_wv_diff_ten_ext,
3877 turbulenceClosureModel,
3885 bc_ebqe_vf_ext.data()[ebNE_kb],
3886 bc_ebqe_phi_ext.data()[ebNE_kb],
3889 ebqe_turb_var_0.data()[ebNE_kb],
3890 ebqe_turb_var_1.data()[ebNE_kb],
3891 turb_var_grad_0_dummy,
3892 bc_eddy_viscosity_ext,
3893 bc_mom_uu_diff_ten_ext,
3894 bc_mom_vv_diff_ten_ext,
3895 bc_mom_ww_diff_ten_ext,
3896 bc_mom_uv_diff_ten_ext,
3897 bc_mom_uw_diff_ten_ext,
3898 bc_mom_vu_diff_ten_ext,
3899 bc_mom_vw_diff_ten_ext,
3900 bc_mom_wu_diff_ten_ext,
3901 bc_mom_wv_diff_ten_ext,
3902 bc_mom_u_source_ext,
3903 bc_mom_v_source_ext,
3904 bc_mom_w_source_ext);
3911 if (NONCONSERVATIVE_FORM > 0.0)
3913 mom_u_ham_ext -= MOVING_DOMAIN*dmom_u_acc_u_ext*(grad_u_ext[0]*xt_ext + grad_u_ext[1]*yt_ext);
3914 dmom_u_ham_grad_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
3915 dmom_u_ham_grad_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
3919 mom_u_adv_ext[0] -= MOVING_DOMAIN*mom_u_acc_ext*xt_ext;
3920 mom_u_adv_ext[1] -= MOVING_DOMAIN*mom_u_acc_ext*yt_ext;
3921 dmom_u_adv_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
3922 dmom_u_adv_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
3926 if (NONCONSERVATIVE_FORM > 0.0)
3928 mom_v_ham_ext -= MOVING_DOMAIN*dmom_v_acc_v_ext*(grad_v_ext[0]*xt_ext + grad_v_ext[1]*yt_ext);
3929 dmom_v_ham_grad_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
3930 dmom_v_ham_grad_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
3934 mom_v_adv_ext[0] -= MOVING_DOMAIN*mom_v_acc_ext*xt_ext;
3935 mom_v_adv_ext[1] -= MOVING_DOMAIN*mom_v_acc_ext*yt_ext;
3936 dmom_v_adv_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
3937 dmom_v_adv_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
3941 if (NONCONSERVATIVE_FORM < 1.0)
3943 bc_mom_u_adv_ext[0] -= MOVING_DOMAIN*bc_mom_u_acc_ext*xt_ext;
3944 bc_mom_u_adv_ext[1] -= MOVING_DOMAIN*bc_mom_u_acc_ext*yt_ext;
3946 bc_mom_v_adv_ext[0] -= MOVING_DOMAIN*bc_mom_v_acc_ext*xt_ext;
3947 bc_mom_v_adv_ext[1] -= MOVING_DOMAIN*bc_mom_v_acc_ext*yt_ext;
3952 ck.calculateGScale(G,normal,h_penalty);
3953 penalty = useMetrics*C_b/h_penalty + (1.0-useMetrics)*ebqe_penalty_ext.data()[ebNE_kb];
3955 isDOFBoundary_p.data()[ebNE_kb],
3956 isDOFBoundary_u.data()[ebNE_kb],
3957 isDOFBoundary_v.data()[ebNE_kb],
3958 isDOFBoundary_w.data()[ebNE_kb],
3959 isAdvectiveFluxBoundary_p.data()[ebNE_kb],
3960 isAdvectiveFluxBoundary_u.data()[ebNE_kb],
3961 isAdvectiveFluxBoundary_v.data()[ebNE_kb],
3962 isAdvectiveFluxBoundary_w.data()[ebNE_kb],
3963 dmom_u_ham_grad_p_ext[0],
3964 bc_dmom_u_ham_grad_p_ext[0],
3973 ebqe_bc_flux_mass_ext.data()[ebNE_kb]+MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]),
3974 ebqe_bc_flux_mom_u_adv_ext.data()[ebNE_kb],
3975 ebqe_bc_flux_mom_v_adv_ext.data()[ebNE_kb],
3976 ebqe_bc_flux_mom_w_adv_ext.data()[ebNE_kb],
3988 dmom_u_ham_grad_u_ext,
4004 &ebqe_velocity.data()[ebNE_kb_nSpace]);
4005 for (
int I=0;I<nSpace;I++)
4006 ebqe_velocity.data()[ebNE_kb_nSpace+I]/=porosity_ext;
4008 ebqe_phi_ext.data()[ebNE_kb],
4009 sdInfo_u_u_rowptr.data(),
4010 sdInfo_u_u_colind.data(),
4011 isDOFBoundary_u.data()[ebNE_kb],
4012 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4014 bc_mom_uu_diff_ten_ext,
4016 ebqe_bc_flux_u_diff_ext.data()[ebNE_kb],
4017 mom_uu_diff_ten_ext,
4021 flux_mom_uu_diff_ext);
4023 ebqe_phi_ext.data()[ebNE_kb],
4024 sdInfo_u_v_rowptr.data(),
4025 sdInfo_u_v_colind.data(),
4026 isDOFBoundary_v.data()[ebNE_kb],
4027 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4029 bc_mom_uv_diff_ten_ext,
4032 mom_uv_diff_ten_ext,
4036 flux_mom_uv_diff_ext);
4038 ebqe_phi_ext.data()[ebNE_kb],
4039 sdInfo_v_u_rowptr.data(),
4040 sdInfo_v_u_colind.data(),
4041 isDOFBoundary_u.data()[ebNE_kb],
4042 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4044 bc_mom_vu_diff_ten_ext,
4047 mom_vu_diff_ten_ext,
4051 flux_mom_vu_diff_ext);
4053 ebqe_phi_ext.data()[ebNE_kb],
4054 sdInfo_v_v_rowptr.data(),
4055 sdInfo_v_v_colind.data(),
4056 isDOFBoundary_v.data()[ebNE_kb],
4057 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4059 bc_mom_vv_diff_ten_ext,
4061 ebqe_bc_flux_v_diff_ext.data()[ebNE_kb],
4062 mom_vv_diff_ten_ext,
4066 flux_mom_vv_diff_ext);
4067 flux.data()[ebN*nQuadraturePoints_elementBoundary+kb] = flux_mass_ext;
4075 if (ebN < nElementBoundaries_owned)
4077 force_v_x = (flux_mom_u_adv_ext + flux_mom_uu_diff_ext + flux_mom_uv_diff_ext + flux_mom_uw_diff_ext)/dmom_u_ham_grad_p_ext[0];
4078 force_v_y = (flux_mom_v_adv_ext + flux_mom_vu_diff_ext + flux_mom_vv_diff_ext + flux_mom_vw_diff_ext)/dmom_u_ham_grad_p_ext[0];
4080 force_p_x = p_ext*normal[0];
4081 force_p_y = p_ext*normal[1];
4083 force_x = force_p_x + force_v_x;
4084 force_y = force_p_y + force_v_y;
4086 r_x = x_ext - barycenters.data()[3*boundaryFlags.data()[ebN]+0];
4087 r_y = y_ext - barycenters.data()[3*boundaryFlags.data()[ebN]+1];
4089 wettedAreas.data()[boundaryFlags.data()[ebN]] += dS*(1.0-ebqe_vf_ext.data()[ebNE_kb]);
4091 netForces_p.data()[3*boundaryFlags.data()[ebN]+0] += force_p_x*dS;
4092 netForces_p.data()[3*boundaryFlags.data()[ebN]+1] += force_p_y*dS;
4094 netForces_v.data()[3*boundaryFlags.data()[ebN]+0] += force_v_x*dS;
4095 netForces_v.data()[3*boundaryFlags.data()[ebN]+1] += force_v_y*dS;
4097 netMoments.data()[3*boundaryFlags.data()[ebN]+2] += (r_x*force_y - r_y*force_x)*dS;
4102 const double H_s =
gf_s.H(particle_eps, ebqe_phi_s.data()[ebNE_kb]);
4103 if (isActiveElement[eN])
4105 total_flux += flux_mass_ext*dS;
4106 for (
int i=0;i<nDOF_test_element;i++)
4108 elementResidual_mesh[i] -= H_s*
ck.ExteriorElementBoundaryFlux(MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]),p_test_dS[i]);
4109 elementResidual_p[i] += H_s*
ck.ExteriorElementBoundaryFlux(flux_mass_ext,p_test_dS[i]);
4110 elementResidual_p[i] -= H_s*
DM*
ck.ExteriorElementBoundaryFlux(MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]),p_test_dS[i]);
4111 globalConservationError += H_s*
ck.ExteriorElementBoundaryFlux(flux_mass_ext,p_test_dS[i]);
4113 for (
int i=0;i<nDOF_v_test_element;i++)
4115 elementResidual_u[i] += H_s*(
ck.ExteriorElementBoundaryFlux(flux_mom_u_adv_ext,vel_test_dS[i])+
4116 ck.ExteriorElementBoundaryFlux(flux_mom_uu_diff_ext,vel_test_dS[i])+
4117 ck.ExteriorElementBoundaryFlux(flux_mom_uv_diff_ext,vel_test_dS[i])+
4118 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_u.data()[ebNE_kb],
4119 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4124 sdInfo_u_u_rowptr.data(),
4125 sdInfo_u_u_colind.data(),
4126 mom_uu_diff_ten_ext,
4127 &vel_grad_test_dS[i*nSpace])+
4128 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_v.data()[ebNE_kb],
4129 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4134 sdInfo_u_v_rowptr.data(),
4135 sdInfo_u_v_colind.data(),
4136 mom_uv_diff_ten_ext,
4137 &vel_grad_test_dS[i*nSpace]));
4138 elementResidual_v[i] += H_s*(
ck.ExteriorElementBoundaryFlux(flux_mom_v_adv_ext,vel_test_dS[i]) +
4139 ck.ExteriorElementBoundaryFlux(flux_mom_vu_diff_ext,vel_test_dS[i])+
4140 ck.ExteriorElementBoundaryFlux(flux_mom_vv_diff_ext,vel_test_dS[i])+
4141 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_u.data()[ebNE_kb],
4142 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4147 sdInfo_v_u_rowptr.data(),
4148 sdInfo_v_u_colind.data(),
4149 mom_vu_diff_ten_ext,
4150 &vel_grad_test_dS[i*nSpace])+
4151 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_v.data()[ebNE_kb],
4152 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4157 sdInfo_v_v_rowptr.data(),
4158 sdInfo_v_v_colind.data(),
4159 mom_vv_diff_ten_ext,
4160 &vel_grad_test_dS[i*nSpace]));
4167 for (
int i=0;i<nDOF_test_element;i++)
4169 int eN_i = eN*nDOF_test_element+i;
4171 elementResidual_p_save.data()[eN_i] += elementResidual_p[i];
4172 mesh_volume_conservation_weak += elementResidual_mesh[i];
4173 globalResidual.data()[offset_p+stride_p*rp_l2g.data()[eN_i]]+=elementResidual_p[i];
4175 for (
int i=0;i<nDOF_v_test_element;i++)
4177 int eN_i = eN*nDOF_v_test_element+i;
4178 globalResidual.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]]+=elementResidual_u[i];
4179 globalResidual.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]]+=elementResidual_v[i];
4182 if (normalize_pressure)
4184 double send[4]={pa_dv,p_dv,total_volume, total_surface_area}, recv[4]={0.,0.,0.,0.};
4185 MPI_Allreduce(send, recv,4,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
4188 total_volume = recv[2];
4189 total_surface_area = recv[3];
4202 int nDOF_pressure=0;
4203 for(
int eN=0;eN<nElements_global;eN++)
4205 for (
int i=0;i<nDOF_test_element;i++)
4207 int eN_i = eN*nDOF_test_element+i;
4208 if (p_l2g.data()[eN_i] > nDOF_pressure)
4209 nDOF_pressure=p_l2g.data()[eN_i];
4213 assert(p_dof.shape(0) == nDOF_pressure);
4215 for (
int I=0;I<nDOF_pressure;I++)
4216 p_dof.data()[I] += (pa_dv - p_dv)/total_volume;
4217 double p_dv_new=0.0, pa_dv_new=0.0;
4221 for (
int eN=0 ; eN < nElements_owned ; ++eN)
4223 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
4224 for (
int j=0;j<nDOF_mesh_trial_element;j++)
4226 register int eN_j = eN*nDOF_mesh_trial_element+j;
4227 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
4228 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
4230 double element_nodes[nDOF_mesh_trial_element*3];
4231 for (
int i=0;i<nDOF_mesh_trial_element;i++)
4233 register int eN_i=eN*nDOF_mesh_trial_element+i;
4234 for(
int I=0;I<3;I++)
4235 element_nodes[i*3 + I] = mesh_dof[mesh_l2g[eN_i]*3 + I];
4237 int icase_s =
gf_s.calculate(element_phi_s, element_nodes, x_ref.data(),
false);
4238 for (
int k=0 ; k < nQuadraturePoints_element ; ++k)
4240 int eN_k = eN*nQuadraturePoints_element + k;
4241 int eN_nDOF_trial_element = eN*nDOF_trial_element;
4243 double jac[nSpace*nSpace];
4244 double jacInv[nSpace*nSpace];
4245 double p=0.0,
pe=0.0;
4246 double jacDet, x, y,
z, dV, h_phi;
4248 double H_s =
gf_s.H(0.,0.);
4249 ck.calculateMapping_element(eN,
4253 mesh_trial_ref.data(),
4254 mesh_grad_trial_ref.data(),
4259 dV = fabs(jacDet)*dV_ref.data()[k];
4260 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_ref.data()[k*nDOF_trial_element],p);
4261 if (isActiveElement[eN])
4263 p_dv_new += p*H_s*dV;
4264 pa_dv_new += q_u_0.data()[eN_k]*H_s*dV;
4265 pe = p-q_u_0.data()[eN_k];
4266 p_L1 += fabs(
pe)*H_s*dV;
4267 p_L2 +=
pe*
pe*H_s*dV;
4268 if (fabs(
pe) > p_LI)
4274 assert(errors.shape(0)*errors.shape(1) == 15);
4275 MPI_Allreduce(MPI_IN_PLACE, errors.data(),(errors.shape(0)-1)*errors.shape(1),MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
4276 MPI_Allreduce(MPI_IN_PLACE, errors.data()+(errors.shape(0)-1)*errors.shape(1),1*errors.shape(1),MPI_DOUBLE,MPI_MAX,MPI_COMM_WORLD);
4277 assert(p_L2 >= 0.0);
4278 assert(u_L2 >= 0.0);
4279 assert(v_L2 >= 0.0);
4280 assert(velocity_L2 >= 0.0);
4284 velocity_L2 = sqrt(velocity_L2);
4289 double NONCONSERVATIVE_FORM = args.
scalar<
double>(
"NONCONSERVATIVE_FORM");
4290 double MOMENTUM_SGE = args.
scalar<
double>(
"MOMENTUM_SGE");
4291 double PRESSURE_SGE = args.
scalar<
double>(
"PRESSURE_SGE");
4292 double VELOCITY_SGE = args.
scalar<
double>(
"VELOCITY_SGE");
4293 double PRESSURE_PROJECTION_STABILIZATION = args.
scalar<
double>(
"PRESSURE_PROJECTION_STABILIZATION");
4294 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
4295 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
4296 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
4297 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
4298 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
4299 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
4300 xt::pyarray<double>& x_ref = args.
array<
double>(
"x_ref");
4301 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
4302 xt::pyarray<double>& p_trial_ref = args.
array<
double>(
"p_trial_ref");
4303 xt::pyarray<double>& p_grad_trial_ref = args.
array<
double>(
"p_grad_trial_ref");
4304 xt::pyarray<double>& p_test_ref = args.
array<
double>(
"p_test_ref");
4305 xt::pyarray<double>& p_grad_test_ref = args.
array<
double>(
"p_grad_test_ref");
4306 xt::pyarray<double>& vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
4307 xt::pyarray<double>& vel_grad_trial_ref = args.
array<
double>(
"vel_grad_trial_ref");
4308 xt::pyarray<double>& vel_test_ref = args.
array<
double>(
"vel_test_ref");
4309 xt::pyarray<double>& vel_grad_test_ref = args.
array<
double>(
"vel_grad_test_ref");
4310 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
4311 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
4312 xt::pyarray<double>& xb_ref = args.
array<
double>(
"xb_ref");
4313 xt::pyarray<double>& dS_ref = args.
array<
double>(
"dS_ref");
4314 xt::pyarray<double>& p_trial_trace_ref = args.
array<
double>(
"p_trial_trace_ref");
4315 xt::pyarray<double>& p_grad_trial_trace_ref = args.
array<
double>(
"p_grad_trial_trace_ref");
4316 xt::pyarray<double>& p_test_trace_ref = args.
array<
double>(
"p_test_trace_ref");
4317 xt::pyarray<double>& p_grad_test_trace_ref = args.
array<
double>(
"p_grad_test_trace_ref");
4318 xt::pyarray<double>& vel_trial_trace_ref = args.
array<
double>(
"vel_trial_trace_ref");
4319 xt::pyarray<double>& vel_grad_trial_trace_ref = args.
array<
double>(
"vel_grad_trial_trace_ref");
4320 xt::pyarray<double>& vel_test_trace_ref = args.
array<
double>(
"vel_test_trace_ref");
4321 xt::pyarray<double>& vel_grad_test_trace_ref = args.
array<
double>(
"vel_grad_test_trace_ref");
4322 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
4323 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
4324 double eb_adjoint_sigma = args.
scalar<
double>(
"eb_adjoint_sigma");
4325 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
4326 xt::pyarray<double>& elementBoundaryDiameter = args.
array<
double>(
"elementBoundaryDiameter");
4327 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
4328 double hFactor = args.
scalar<
double>(
"hFactor");
4329 int nElements_global = args.
scalar<
int>(
"nElements_global");
4330 double useRBLES = args.
scalar<
double>(
"useRBLES");
4331 double useMetrics = args.
scalar<
double>(
"useMetrics");
4332 double alphaBDF = args.
scalar<
double>(
"alphaBDF");
4333 double epsFact_rho = args.
scalar<
double>(
"epsFact_rho");
4334 double epsFact_mu = args.
scalar<
double>(
"epsFact_mu");
4335 double sigma = args.
scalar<
double>(
"sigma");
4340 double smagorinskyConstant = args.
scalar<
double>(
"smagorinskyConstant");
4341 int turbulenceClosureModel = args.
scalar<
int>(
"turbulenceClosureModel");
4342 double Ct_sge = args.
scalar<
double>(
"Ct_sge");
4343 double Cd_sge = args.
scalar<
double>(
"Cd_sge");
4344 double C_dg = args.
scalar<
double>(
"C_dg");
4345 double C_b = args.
scalar<
double>(
"C_b");
4346 const xt::pyarray<double>& eps_solid = args.
array<
double>(
"eps_solid");
4347 const xt::pyarray<double>& phi_solid = args.
array<
double>(
"phi_solid");
4348 const xt::pyarray<double>& eps_porous = args.
array<
double>(
"eps_porous");
4349 const xt::pyarray<double>& phi_porous = args.
array<
double>(
"phi_porous");
4350 const xt::pyarray<double>& q_velocity_porous = args.
array<
double>(
"q_velocity_porous");
4351 const xt::pyarray<double>& q_porosity = args.
array<
double>(
"q_porosity");
4352 const xt::pyarray<double>& q_dragAlpha = args.
array<
double>(
"q_dragAlpha");
4353 const xt::pyarray<double>& q_dragBeta = args.
array<
double>(
"q_dragBeta");
4354 const xt::pyarray<double>& q_mass_source = args.
array<
double>(
"q_mass_source");
4355 const xt::pyarray<double>& q_turb_var_0 = args.
array<
double>(
"q_turb_var_0");
4356 const xt::pyarray<double>& q_turb_var_1 = args.
array<
double>(
"q_turb_var_1");
4357 const xt::pyarray<double>& q_turb_var_grad_0 = args.
array<
double>(
"q_turb_var_grad_0");
4358 const double LAG_LES = args.
scalar<
double>(
"LAG_LES");
4359 xt::pyarray<double> & q_eddy_viscosity_last = args.
array<
double>(
"q_eddy_viscosity_last");
4360 xt::pyarray<double> & ebqe_eddy_viscosity_last = args.
array<
double>(
"ebqe_eddy_viscosity_last");
4361 xt::pyarray<int>& p_l2g = args.
array<
int>(
"p_l2g");
4362 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
4363 xt::pyarray<double>& p_dof = args.
array<
double>(
"p_dof");
4364 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
4365 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
4366 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
4367 xt::pyarray<double>& p_old_dof = args.
array<
double>(
"p_old_dof");
4368 xt::pyarray<double>& u_old_dof = args.
array<
double>(
"u_old_dof");
4369 xt::pyarray<double>& v_old_dof = args.
array<
double>(
"v_old_dof");
4370 xt::pyarray<double>& w_old_dof = args.
array<
double>(
"w_old_dof");
4371 xt::pyarray<double>& g = args.
array<
double>(
"g");
4372 const double useVF = args.
scalar<
double>(
"useVF");
4373 xt::pyarray<double>& vf = args.
array<
double>(
"vf");
4374 xt::pyarray<double>&
phi = args.
array<
double>(
"phi");
4375 xt::pyarray<double>& phi_nodes = args.
array<
double>(
"phi_nodes");
4376 xt::pyarray<double>& normal_phi = args.
array<
double>(
"normal_phi");
4377 xt::pyarray<double>& kappa_phi = args.
array<
double>(
"kappa_phi");
4378 xt::pyarray<double>& q_mom_u_acc_beta_bdf = args.
array<
double>(
"q_mom_u_acc_beta_bdf");
4379 xt::pyarray<double>& q_mom_v_acc_beta_bdf = args.
array<
double>(
"q_mom_v_acc_beta_bdf");
4380 xt::pyarray<double>& q_mom_w_acc_beta_bdf = args.
array<
double>(
"q_mom_w_acc_beta_bdf");
4381 xt::pyarray<double>& q_dV = args.
array<
double>(
"q_dV");
4382 xt::pyarray<double>& q_dV_last = args.
array<
double>(
"q_dV_last");
4383 xt::pyarray<double>& q_velocity_sge = args.
array<
double>(
"q_velocity_sge");
4384 xt::pyarray<double>& q_cfl = args.
array<
double>(
"q_cfl");
4385 xt::pyarray<double>& q_numDiff_u_last = args.
array<
double>(
"q_numDiff_u_last");
4386 xt::pyarray<double>& q_numDiff_v_last = args.
array<
double>(
"q_numDiff_v_last");
4387 xt::pyarray<double>& q_numDiff_w_last = args.
array<
double>(
"q_numDiff_w_last");
4388 xt::pyarray<int>& sdInfo_u_u_rowptr = args.
array<
int>(
"sdInfo_u_u_rowptr");
4389 xt::pyarray<int>& sdInfo_u_u_colind = args.
array<
int>(
"sdInfo_u_u_colind");
4390 xt::pyarray<int>& sdInfo_u_v_rowptr = args.
array<
int>(
"sdInfo_u_v_rowptr");
4391 xt::pyarray<int>& sdInfo_u_v_colind = args.
array<
int>(
"sdInfo_u_v_colind");
4392 xt::pyarray<int>& sdInfo_u_w_rowptr = args.
array<
int>(
"sdInfo_u_w_rowptr");
4393 xt::pyarray<int>& sdInfo_u_w_colind = args.
array<
int>(
"sdInfo_u_w_colind");
4394 xt::pyarray<int>& sdInfo_v_v_rowptr = args.
array<
int>(
"sdInfo_v_v_rowptr");
4395 xt::pyarray<int>& sdInfo_v_v_colind = args.
array<
int>(
"sdInfo_v_v_colind");
4396 xt::pyarray<int>& sdInfo_v_u_rowptr = args.
array<
int>(
"sdInfo_v_u_rowptr");
4397 xt::pyarray<int>& sdInfo_v_u_colind = args.
array<
int>(
"sdInfo_v_u_colind");
4398 xt::pyarray<int>& sdInfo_v_w_rowptr = args.
array<
int>(
"sdInfo_v_w_rowptr");
4399 xt::pyarray<int>& sdInfo_v_w_colind = args.
array<
int>(
"sdInfo_v_w_colind");
4400 xt::pyarray<int>& sdInfo_w_w_rowptr = args.
array<
int>(
"sdInfo_w_w_rowptr");
4401 xt::pyarray<int>& sdInfo_w_w_colind = args.
array<
int>(
"sdInfo_w_w_colind");
4402 xt::pyarray<int>& sdInfo_w_u_rowptr = args.
array<
int>(
"sdInfo_w_u_rowptr");
4403 xt::pyarray<int>& sdInfo_w_u_colind = args.
array<
int>(
"sdInfo_w_u_colind");
4404 xt::pyarray<int>& sdInfo_w_v_rowptr = args.
array<
int>(
"sdInfo_w_v_rowptr");
4405 xt::pyarray<int>& sdInfo_w_v_colind = args.
array<
int>(
"sdInfo_w_v_colind");
4406 xt::pyarray<int>& csrRowIndeces_p_p = args.
array<
int>(
"csrRowIndeces_p_p");
4407 xt::pyarray<int>& csrColumnOffsets_p_p = args.
array<
int>(
"csrColumnOffsets_p_p");
4408 xt::pyarray<int>& csrRowIndeces_p_u = args.
array<
int>(
"csrRowIndeces_p_u");
4409 xt::pyarray<int>& csrColumnOffsets_p_u = args.
array<
int>(
"csrColumnOffsets_p_u");
4410 xt::pyarray<int>& csrRowIndeces_p_v = args.
array<
int>(
"csrRowIndeces_p_v");
4411 xt::pyarray<int>& csrColumnOffsets_p_v = args.
array<
int>(
"csrColumnOffsets_p_v");
4412 xt::pyarray<int>& csrRowIndeces_p_w = args.
array<
int>(
"csrRowIndeces_p_w");
4413 xt::pyarray<int>& csrColumnOffsets_p_w = args.
array<
int>(
"csrColumnOffsets_p_w");
4414 xt::pyarray<int>& csrRowIndeces_u_p = args.
array<
int>(
"csrRowIndeces_u_p");
4415 xt::pyarray<int>& csrColumnOffsets_u_p = args.
array<
int>(
"csrColumnOffsets_u_p");
4416 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
4417 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
4418 xt::pyarray<int>& csrRowIndeces_u_v = args.
array<
int>(
"csrRowIndeces_u_v");
4419 xt::pyarray<int>& csrColumnOffsets_u_v = args.
array<
int>(
"csrColumnOffsets_u_v");
4420 xt::pyarray<int>& csrRowIndeces_u_w = args.
array<
int>(
"csrRowIndeces_u_w");
4421 xt::pyarray<int>& csrColumnOffsets_u_w = args.
array<
int>(
"csrColumnOffsets_u_w");
4422 xt::pyarray<int>& csrRowIndeces_v_p = args.
array<
int>(
"csrRowIndeces_v_p");
4423 xt::pyarray<int>& csrColumnOffsets_v_p = args.
array<
int>(
"csrColumnOffsets_v_p");
4424 xt::pyarray<int>& csrRowIndeces_v_u = args.
array<
int>(
"csrRowIndeces_v_u");
4425 xt::pyarray<int>& csrColumnOffsets_v_u = args.
array<
int>(
"csrColumnOffsets_v_u");
4426 xt::pyarray<int>& csrRowIndeces_v_v = args.
array<
int>(
"csrRowIndeces_v_v");
4427 xt::pyarray<int>& csrColumnOffsets_v_v = args.
array<
int>(
"csrColumnOffsets_v_v");
4428 xt::pyarray<int>& csrRowIndeces_v_w = args.
array<
int>(
"csrRowIndeces_v_w");
4429 xt::pyarray<int>& csrColumnOffsets_v_w = args.
array<
int>(
"csrColumnOffsets_v_w");
4430 xt::pyarray<int>& csrRowIndeces_w_p = args.
array<
int>(
"csrRowIndeces_w_p");
4431 xt::pyarray<int>& csrColumnOffsets_w_p = args.
array<
int>(
"csrColumnOffsets_w_p");
4432 xt::pyarray<int>& csrRowIndeces_w_u = args.
array<
int>(
"csrRowIndeces_w_u");
4433 xt::pyarray<int>& csrColumnOffsets_w_u = args.
array<
int>(
"csrColumnOffsets_w_u");
4434 xt::pyarray<int>& csrRowIndeces_w_v = args.
array<
int>(
"csrRowIndeces_w_v");
4435 xt::pyarray<int>& csrColumnOffsets_w_v = args.
array<
int>(
"csrColumnOffsets_w_v");
4436 xt::pyarray<int>& csrRowIndeces_w_w = args.
array<
int>(
"csrRowIndeces_w_w");
4437 xt::pyarray<int>& csrColumnOffsets_w_w = args.
array<
int>(
"csrColumnOffsets_w_w");
4438 xt::pyarray<double>& globalJacobian = args.
array<
double>(
"globalJacobian");
4439 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
4440 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
4441 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
4442 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
4443 xt::pyarray<double>& ebqe_vf_ext = args.
array<
double>(
"ebqe_vf_ext");
4444 xt::pyarray<double>& bc_ebqe_vf_ext = args.
array<
double>(
"bc_ebqe_vf_ext");
4445 xt::pyarray<double>& ebqe_phi_ext = args.
array<
double>(
"ebqe_phi_ext");
4446 xt::pyarray<double>& bc_ebqe_phi_ext = args.
array<
double>(
"bc_ebqe_phi_ext");
4447 xt::pyarray<double>& ebqe_normal_phi_ext = args.
array<
double>(
"ebqe_normal_phi_ext");
4448 xt::pyarray<double>& ebqe_kappa_phi_ext = args.
array<
double>(
"ebqe_kappa_phi_ext");
4449 const xt::pyarray<double>& ebqe_porosity_ext = args.
array<
double>(
"ebqe_porosity_ext");
4450 const xt::pyarray<double>& ebqe_turb_var_0 = args.
array<
double>(
"ebqe_turb_var_0");
4451 const xt::pyarray<double>& ebqe_turb_var_1 = args.
array<
double>(
"ebqe_turb_var_1");
4452 xt::pyarray<int>& isDOFBoundary_p = args.
array<
int>(
"isDOFBoundary_p");
4453 xt::pyarray<int>& isDOFBoundary_u = args.
array<
int>(
"isDOFBoundary_u");
4454 xt::pyarray<int>& isDOFBoundary_v = args.
array<
int>(
"isDOFBoundary_v");
4455 xt::pyarray<int>& isDOFBoundary_w = args.
array<
int>(
"isDOFBoundary_w");
4456 xt::pyarray<int>& isAdvectiveFluxBoundary_p = args.
array<
int>(
"isAdvectiveFluxBoundary_p");
4457 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.
array<
int>(
"isAdvectiveFluxBoundary_u");
4458 xt::pyarray<int>& isAdvectiveFluxBoundary_v = args.
array<
int>(
"isAdvectiveFluxBoundary_v");
4459 xt::pyarray<int>& isAdvectiveFluxBoundary_w = args.
array<
int>(
"isAdvectiveFluxBoundary_w");
4460 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.
array<
int>(
"isDiffusiveFluxBoundary_u");
4461 xt::pyarray<int>& isDiffusiveFluxBoundary_v = args.
array<
int>(
"isDiffusiveFluxBoundary_v");
4462 xt::pyarray<int>& isDiffusiveFluxBoundary_w = args.
array<
int>(
"isDiffusiveFluxBoundary_w");
4463 xt::pyarray<double>& ebqe_bc_p_ext = args.
array<
double>(
"ebqe_bc_p_ext");
4464 xt::pyarray<double>& ebqe_bc_flux_mass_ext = args.
array<
double>(
"ebqe_bc_flux_mass_ext");
4465 xt::pyarray<double>& ebqe_bc_flux_mom_u_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_u_adv_ext");
4466 xt::pyarray<double>& ebqe_bc_flux_mom_v_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_v_adv_ext");
4467 xt::pyarray<double>& ebqe_bc_flux_mom_w_adv_ext = args.
array<
double>(
"ebqe_bc_flux_mom_w_adv_ext");
4468 xt::pyarray<double>& ebqe_bc_u_ext = args.
array<
double>(
"ebqe_bc_u_ext");
4469 xt::pyarray<double>& ebqe_bc_flux_u_diff_ext = args.
array<
double>(
"ebqe_bc_flux_u_diff_ext");
4470 xt::pyarray<double>& ebqe_penalty_ext = args.
array<
double>(
"ebqe_penalty_ext");
4471 xt::pyarray<double>& ebqe_bc_v_ext = args.
array<
double>(
"ebqe_bc_v_ext");
4472 xt::pyarray<double>& ebqe_bc_flux_v_diff_ext = args.
array<
double>(
"ebqe_bc_flux_v_diff_ext");
4473 xt::pyarray<double>& ebqe_bc_w_ext = args.
array<
double>(
"ebqe_bc_w_ext");
4474 xt::pyarray<double>& ebqe_bc_flux_w_diff_ext = args.
array<
double>(
"ebqe_bc_flux_w_diff_ext");
4475 xt::pyarray<int>& csrColumnOffsets_eb_p_p = args.
array<
int>(
"csrColumnOffsets_eb_p_p");
4476 xt::pyarray<int>& csrColumnOffsets_eb_p_u = args.
array<
int>(
"csrColumnOffsets_eb_p_u");
4477 xt::pyarray<int>& csrColumnOffsets_eb_p_v = args.
array<
int>(
"csrColumnOffsets_eb_p_v");
4478 xt::pyarray<int>& csrColumnOffsets_eb_p_w = args.
array<
int>(
"csrColumnOffsets_eb_p_w");
4479 xt::pyarray<int>& csrColumnOffsets_eb_u_p = args.
array<
int>(
"csrColumnOffsets_eb_u_p");
4480 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.
array<
int>(
"csrColumnOffsets_eb_u_u");
4481 xt::pyarray<int>& csrColumnOffsets_eb_u_v = args.
array<
int>(
"csrColumnOffsets_eb_u_v");
4482 xt::pyarray<int>& csrColumnOffsets_eb_u_w = args.
array<
int>(
"csrColumnOffsets_eb_u_w");
4483 xt::pyarray<int>& csrColumnOffsets_eb_v_p = args.
array<
int>(
"csrColumnOffsets_eb_v_p");
4484 xt::pyarray<int>& csrColumnOffsets_eb_v_u = args.
array<
int>(
"csrColumnOffsets_eb_v_u");
4485 xt::pyarray<int>& csrColumnOffsets_eb_v_v = args.
array<
int>(
"csrColumnOffsets_eb_v_v");
4486 xt::pyarray<int>& csrColumnOffsets_eb_v_w = args.
array<
int>(
"csrColumnOffsets_eb_v_w");
4487 xt::pyarray<int>& csrColumnOffsets_eb_w_p = args.
array<
int>(
"csrColumnOffsets_eb_w_p");
4488 xt::pyarray<int>& csrColumnOffsets_eb_w_u = args.
array<
int>(
"csrColumnOffsets_eb_w_u");
4489 xt::pyarray<int>& csrColumnOffsets_eb_w_v = args.
array<
int>(
"csrColumnOffsets_eb_w_v");
4490 xt::pyarray<int>& csrColumnOffsets_eb_w_w = args.
array<
int>(
"csrColumnOffsets_eb_w_w");
4491 xt::pyarray<int>& elementFlags = args.
array<
int>(
"elementFlags");
4492 xt::pyarray<int>& boundaryFlags = args.
array<
int>(
"boundaryFlags");
4493 int use_ball_as_particle = args.
scalar<
int>(
"use_ball_as_particle");
4494 xt::pyarray<double>& ball_center = args.
array<
double>(
"ball_center");
4495 xt::pyarray<double>& ball_radius = args.
array<
double>(
"ball_radius");
4496 xt::pyarray<double>& ball_velocity = args.
array<
double>(
"ball_velocity");
4497 xt::pyarray<double>& ball_angular_velocity = args.
array<
double>(
"ball_angular_velocity");
4498 xt::pyarray<double>& ball_density = args.
array<
double>(
"ball_density");
4499 xt::pyarray<double>& particle_signed_distances = args.
array<
double>(
"particle_signed_distances");
4500 xt::pyarray<double>& particle_signed_distance_normals = args.
array<
double>(
"particle_signed_distance_normals");
4501 xt::pyarray<double>& particle_velocities = args.
array<
double>(
"particle_velocities");
4502 xt::pyarray<double>& particle_centroids = args.
array<
double>(
"particle_centroids");
4503 xt::pyarray<double>& ebqe_phi_s = args.
array<
double>(
"ebqe_phi_s");
4504 xt::pyarray<double>& ebq_global_grad_phi_s = args.
array<
double>(
"ebq_global_grad_phi_s");
4505 xt::pyarray<double>& ebq_particle_velocity_s = args.
array<
double>(
"ebq_particle_velocity_s");
4506 xt::pyarray<double>& phi_solid_nodes = args.
array<
double>(
"phi_solid_nodes");
4507 xt::pyarray<double>& distance_to_solids = args.
array<
double>(
"distance_to_solids");
4508 xt::pyarray<int>& isActiveElement = args.
array<
int>(
"isActiveElement");
4509 xt::pyarray<int>& isActiveElement_last = args.
array<
int>(
"isActiveElement_last");
4510 int nParticles = args.
scalar<
int>(
"nParticles");
4511 int nElements_owned = args.
scalar<
int>(
"nElements_owned");
4512 double particle_nitsche = args.
scalar<
double>(
"particle_nitsche");
4513 double particle_epsFact = args.
scalar<
double>(
"particle_epsFact");
4514 double particle_alpha = args.
scalar<
double>(
"particle_alpha");
4515 double particle_beta = args.
scalar<
double>(
"particle_beta");
4516 double particle_penalty_constant = args.
scalar<
double>(
"particle_penalty_constant");
4517 double ghost_penalty_constant = args.
scalar<
double>(
"ghost_penalty_constant");
4518 const bool useExact = args.
scalar<
int>(
"useExact");
4519 const int nQuadraturePoints_global(nElements_global*nQuadraturePoints_element);
4520 std::valarray<double> particle_surfaceArea_tmp(nParticles), particle_netForces_tmp(nParticles*3*3), particle_netMoments_tmp(nParticles*3);
4521 gf.useExact =
false;
4522 gf_p.useExact =
false;
4523 gf_s.useExact = useExact;
4527 for(
int eN=0;eN<nElements_global;eN++)
4529 register int particle_index=0;
4530 register double eps_rho,eps_mu;
4532 register double elementJacobian_p_p[nDOF_test_element][nDOF_trial_element],
4533 elementJacobian_p_u[nDOF_test_element][nDOF_v_trial_element],
4534 elementJacobian_p_v[nDOF_test_element][nDOF_v_trial_element],
4535 elementJacobian_p_w[nDOF_test_element][nDOF_v_trial_element],
4536 elementJacobian_u_p[nDOF_v_test_element][nDOF_trial_element],
4537 elementJacobian_u_u[nDOF_v_test_element][nDOF_v_trial_element],
4538 elementJacobian_u_v[nDOF_v_test_element][nDOF_v_trial_element],
4539 elementJacobian_u_w[nDOF_v_test_element][nDOF_v_trial_element],
4540 elementJacobian_v_p[nDOF_v_test_element][nDOF_trial_element],
4541 elementJacobian_v_u[nDOF_v_test_element][nDOF_v_trial_element],
4542 elementJacobian_v_v[nDOF_v_test_element][nDOF_v_trial_element],
4543 elementJacobian_v_w[nDOF_v_test_element][nDOF_v_trial_element],
4544 elementJacobian_w_p[nDOF_v_test_element][nDOF_trial_element],
4545 elementJacobian_w_u[nDOF_v_test_element][nDOF_v_trial_element],
4546 elementJacobian_w_v[nDOF_v_test_element][nDOF_v_trial_element],
4547 elementJacobian_w_w[nDOF_v_test_element][nDOF_v_trial_element];
4548 for (
int i=0;i<nDOF_test_element;i++)
4549 for (
int j=0;j<nDOF_trial_element;j++)
4551 elementJacobian_p_p[i][j]=0.0;
4553 for (
int i=0;i<nDOF_test_element;i++)
4554 for (
int j=0;j<nDOF_v_trial_element;j++)
4556 elementJacobian_p_u[i][j]=0.0;
4557 elementJacobian_p_v[i][j]=0.0;
4558 elementJacobian_p_w[i][j]=0.0;
4559 elementJacobian_u_p[j][i]=0.0;
4560 elementJacobian_v_p[j][i]=0.0;
4561 elementJacobian_w_p[j][i]=0.0;
4563 for (
int i=0;i<nDOF_v_test_element;i++)
4564 for (
int j=0;j<nDOF_v_trial_element;j++)
4566 elementJacobian_u_u[i][j]=0.0;
4567 elementJacobian_u_v[i][j]=0.0;
4568 elementJacobian_u_w[i][j]=0.0;
4569 elementJacobian_v_u[i][j]=0.0;
4570 elementJacobian_v_v[i][j]=0.0;
4571 elementJacobian_v_w[i][j]=0.0;
4572 elementJacobian_w_u[i][j]=0.0;
4573 elementJacobian_w_v[i][j]=0.0;
4574 elementJacobian_w_w[i][j]=0.0;
4576 if(use_ball_as_particle==1 && nParticles > 0)
4578 double min_d = 1e10;
4580 for (
int I=0;I<nDOF_mesh_trial_element;I++)
4583 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+0],
4584 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+1],
4585 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+2],
4586 phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]]);
4587 if (phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]] < min_d)
4589 min_d = phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]];
4590 particle_index = index;
4598 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
4599 for (
int j=0;j<nDOF_mesh_trial_element;j++)
4601 register int eN_j = eN*nDOF_mesh_trial_element+j;
4602 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
4603 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
4605 double element_nodes[nDOF_mesh_trial_element*3];
4606 for (
int i=0;i<nDOF_mesh_trial_element;i++)
4608 register int eN_i=eN*nDOF_mesh_trial_element+i;
4609 for(
int I=0;I<3;I++)
4610 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
4612 int icase_s =
gf_s.calculate(element_phi_s, element_nodes, x_ref.data(),
false);
4614 int icase_p =
gf_p.calculate(element_phi, element_nodes, x_ref.data(), -
rho_1*g.data()[1], -
rho_0*g.data()[1],
false,
true);
4615 int icase =
gf.calculate(element_phi, element_nodes, x_ref.data(),
rho_1*
nu_1,
rho_0*
nu_0,
false,
false);
4617 int icase_p =
gf_p.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,
false,
false);
4618 int icase =
gf.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,
false,
false);
4620 for (
int fluid_phase=0;fluid_phase < 2 - abs(icase); fluid_phase++)
4622 for (
int k=0;k<nQuadraturePoints_element;k++)
4624 int eN_k = eN*nQuadraturePoints_element+k,
4625 eN_k_nSpace = eN_k*nSpace,
4627 eN_nDOF_trial_element = eN*nDOF_trial_element,
4628 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element;
4631 register double p=0.0,
u=0.0,
v=0.0,
w=0.0,
4633 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
4661 mom_uu_diff_ten[nSpace]=
ZEROVEC,
4662 mom_vv_diff_ten[nSpace]=
ZEROVEC,
4663 mom_ww_diff_ten[nSpace]=
ZEROVEC,
4674 dmom_u_ham_grad_p[nSpace]=
ZEROVEC,
4675 dmom_u_ham_grad_u[nSpace]=
ZEROVEC,
4676 dmom_u_ham_grad_v[nSpace]=
ZEROVEC,
4681 dmom_v_ham_grad_p[nSpace]=
ZEROVEC,
4682 dmom_v_ham_grad_u[nSpace]=
ZEROVEC,
4683 dmom_v_ham_grad_v[nSpace]=
ZEROVEC,
4688 dmom_w_ham_grad_p[nSpace]=
ZEROVEC,
4689 dmom_w_ham_grad_w[nSpace]=
ZEROVEC,
4703 dpdeResidual_p_u[nDOF_v_trial_element],dpdeResidual_p_v[nDOF_v_trial_element],dpdeResidual_p_w[nDOF_v_trial_element],
4704 dpdeResidual_u_p[nDOF_trial_element],dpdeResidual_u_u[nDOF_v_trial_element],
4705 dpdeResidual_v_p[nDOF_trial_element],dpdeResidual_v_v[nDOF_v_trial_element],
4706 dpdeResidual_w_p[nDOF_trial_element],dpdeResidual_w_w[nDOF_v_trial_element],
4707 Lstar_u_p[nDOF_test_element],
4708 Lstar_v_p[nDOF_test_element],
4709 Lstar_w_p[nDOF_test_element],
4710 Lstar_u_u[nDOF_v_test_element],
4711 Lstar_v_v[nDOF_v_test_element],
4712 Lstar_w_w[nDOF_v_test_element],
4713 Lstar_p_u[nDOF_v_test_element],
4714 Lstar_p_v[nDOF_v_test_element],
4715 Lstar_p_w[nDOF_v_test_element],
4720 dsubgridError_p_u[nDOF_v_trial_element],
4721 dsubgridError_p_v[nDOF_v_trial_element],
4722 dsubgridError_p_w[nDOF_v_trial_element],
4723 dsubgridError_u_p[nDOF_trial_element],
4724 dsubgridError_u_u[nDOF_v_trial_element],
4725 dsubgridError_v_p[nDOF_trial_element],
4726 dsubgridError_v_v[nDOF_v_trial_element],
4727 dsubgridError_w_p[nDOF_trial_element],
4728 dsubgridError_w_w[nDOF_v_trial_element],
4729 tau_p=0.0,tau_p0=0.0,tau_p1=0.0,
4730 tau_v=0.0,tau_v0=0.0,tau_v1=0.0,
4733 jacInv[nSpace*nSpace],
4734 p_trial[nDOF_trial_element], vel_trial[nDOF_v_trial_element],
4735 p_grad_trial_ib[nDOF_trial_element*nSpace], vel_grad_trial_ib[nDOF_v_trial_element*nSpace],
4736 p_grad_trial[nDOF_trial_element*nSpace],vel_grad_trial[nDOF_v_trial_element*nSpace],
4738 p_test_dV[nDOF_test_element],vel_test_dV[nDOF_v_test_element],
4739 p_grad_test_dV[nDOF_test_element*nSpace],vel_grad_test_dV[nDOF_v_test_element*nSpace],
4744 dmom_u_source[nSpace]=
ZEROVEC,
4745 dmom_v_source[nSpace]=
ZEROVEC,
4746 dmom_w_source[nSpace]=
ZEROVEC,
4749 G[nSpace*nSpace],G_dd_G,tr_G,h_phi, dmom_adv_star[nSpace]=
ZEROVEC, dmom_adv_sge[nSpace]=
ZEROVEC, dmom_ham_grad_sge[nSpace]=
ZEROVEC,
4755 dmom_u_source_s[nSpace]=
ZEROVEC,
4756 dmom_v_source_s[nSpace]=
ZEROVEC,
4757 dmom_w_source_s[nSpace]=
ZEROVEC,
4761 dmom_u_adv_u_s[nSpace]=
ZEROVEC,
4762 dmom_v_adv_v_s[nSpace]=
ZEROVEC,
4763 dmom_w_adv_w_s[nSpace]=
ZEROVEC,
4765 dmom_u_ham_grad_u_s[nSpace]=
ZEROVEC,
4766 dmom_u_ham_grad_v_s[nSpace]=
ZEROVEC,
4771 dmom_v_ham_grad_u_s[nSpace]=
ZEROVEC,
4772 dmom_v_ham_grad_v_s[nSpace]=
ZEROVEC,
4777 dmom_w_ham_grad_w_s[nSpace]=
ZEROVEC,
4789 ck.calculateMapping_element(eN,
4793 mesh_trial_ref.data(),
4794 mesh_grad_trial_ref.data(),
4799 ck.calculateH_element(eN,
4801 nodeDiametersArray.data(),
4803 mesh_trial_ref.data(),
4805 ck.calculateMappingVelocity_element(eN,
4807 mesh_velocity_dof.data(),
4809 mesh_trial_ref.data(),
4814 dV = fabs(jacDet)*dV_ref.data()[k];
4815 ck.calculateG(jacInv,G,G_dd_G,tr_G);
4818 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
4819 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
4821 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
4822 ck_v.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_v_trial_element*nSpace],jacInv,vel_grad_trial);
4823 for (
int i=0; i < nDOF_trial_element; i++)
4825 p_trial[i] = p_trial_ref.data()[k*nDOF_trial_element + i];
4826 p_grad_trial_ib[i*nSpace + 0] = p_grad_trial[i*nSpace+0];
4827 p_grad_trial_ib[i*nSpace + 1] = p_grad_trial[i*nSpace+1];
4829 for (
int i=0; i < nDOF_v_trial_element; i++)
4831 vel_trial[i] = vel_trial_ref.data()[k*nDOF_v_trial_element + i];
4832 vel_grad_trial_ib[i*nSpace + 0] = vel_grad_trial[i*nSpace+0];
4833 vel_grad_trial_ib[i*nSpace + 1] = vel_grad_trial[i*nSpace+1];
4838 for (
int i=0; i < nDOF_trial_element; i++)
4840 if (fluid_phase == 0)
4842 if (not std::isnan(
gf_p.VA(i)))
4844 p_trial[i] =
gf_p.VA(i);
4845 p_grad_trial_ib[i*nSpace + 0] =
gf_p.VA_x(i);
4846 p_grad_trial_ib[i*nSpace + 1] =
gf_p.VA_y(i);
4851 if (not std::isnan(
gf_p.VB(i)))
4853 p_trial[i] =
gf_p.VB(i);
4854 p_grad_trial_ib[i*nSpace + 0] =
gf_p.VB_x(i);
4855 p_grad_trial_ib[i*nSpace + 1] =
gf_p.VB_y(i);
4859 if(nDOF_v_trial_element == nDOF_trial_element)
4861 for (
int vi=0; vi < nDOF_v_trial_element; vi++)
4863 if (fluid_phase == 0)
4865 if (not std::isnan(
gf.VA(vi)))
4867 vel_trial[vi] =
gf.VA(vi);
4868 vel_grad_trial_ib[vi*nSpace + 0] =
gf.VA_x(vi);
4869 vel_grad_trial_ib[vi*nSpace + 1] =
gf.VA_y(vi);
4874 if (not std::isnan(
gf.VB(vi)))
4876 vel_trial[vi] =
gf.VB(vi);
4877 vel_grad_trial_ib[vi*nSpace + 0] =
gf.VB_x(vi);
4878 vel_grad_trial_ib[vi*nSpace + 1] =
gf.VB_y(vi);
4886 for (
int vi=0; vi < nDOF_v_trial_element; vi++)
4889 if (fabs(p_trial_ref.data()[k*nDOF_trial_element + vi] - p_trial[vi]) > 1.0e-8)
4891 for (
int vj=0; vj < nDOF_trial_element; vj++)
4892 std::cout<<
"Trial "<<p_trial_ref.data()[k*nDOF_trial_element + vj]<<
'\t'<<
gf_p.VA(vj)<<
'\t'<<
gf_p.VB(vj)<<std::endl;
4895 if (fabs(p_grad_trial[vi*nSpace + 0] - p_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
4897 for (
int vj=0; vj < nDOF_trial_element; vj++)
4898 std::cout<<
"Grad Trial x"<<p_grad_trial[vj*nSpace + 0]<<
'\t'<<
gf_p.VA_x(vj)<<
'\t'<<
gf_p.VB_x(vj)<<std::endl;
4901 if (fabs(p_grad_trial[vi*nSpace + 1] - p_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
4903 for (
int vj=0; vj < nDOF_trial_element; vj++)
4904 std::cout<<
"Grad Trial y "<<p_grad_trial[vj*nSpace + 1]<<
'\t'<<
gf_p.VA_y(vj)<<
'\t'<<
gf_p.VB_y(vj)<<std::endl;
4908 if (fabs(vel_trial_ref.data()[k*nDOF_v_trial_element + vi] - vel_trial[vi]) > 1.0e-8)
4910 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
4911 std::cout<<
"Trial "<<vel_trial_ref.data()[k*nDOF_v_trial_element + vj]<<
'\t'<<
gf.VA(vj)<<
'\t'<<
gf.VB(vj)<<std::endl;
4914 if (fabs(vel_grad_trial[vi*nSpace + 0] - vel_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
4916 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
4917 std::cout<<
"Grad Trial x"<<vel_grad_trial[vj*nSpace + 0]<<
'\t'<<
gf.VA_x(vj)<<
'\t'<<
gf.VB_x(vj)<<std::endl;
4920 if (fabs(vel_grad_trial[vi*nSpace + 1] - vel_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
4922 for (
int vj=0; vj < nDOF_v_trial_element; vj++)
4923 std::cout<<
"Grad Trial y "<<vel_grad_trial[vj*nSpace + 1]<<
'\t'<<
gf.VA_y(vj)<<
'\t'<<
gf.VB_y(vj)<<std::endl;
4933 ck.valFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_trial,p);
4934 ck_v.valFromDOF(u_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,
u);
4935 ck_v.valFromDOF(v_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,
v);
4936 ck.valFromDOF(p_old_dof.data(),&p_l2g[eN_nDOF_trial_element],p_trial,p_old);
4937 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,u_old);
4938 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,v_old);
4940 ck.gradFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_grad_trial_ib,grad_p);
4941 ck_v.gradFromDOF(u_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u);
4942 ck_v.gradFromDOF(v_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v);
4943 ck.gradFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_grad_trial_ib,grad_p_old);
4944 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u_old);
4945 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v_old);
4948 for (
int j=0;j<nDOF_test_element;j++)
4950 p_test_dV[j] = p_trial[j]*dV;
4951 for (
int I=0;I<nSpace;I++)
4953 p_grad_test_dV[j*nSpace+I] = p_grad_trial_ib[j*nSpace+I]*dV;
4956 for (
int j=0;j<nDOF_v_test_element;j++)
4958 vel_test_dV[j] = vel_trial[j]*dV;
4959 for (
int I=0;I<nSpace;I++)
4961 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial_ib[j*nSpace+I]*dV;
4965 for (
int j=0;j<nDOF_test_element;j++)
4967 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element+j]*dV;
4968 for (
int I=0;I<nSpace;I++)
4970 p_grad_test_dV[j*nSpace+I] = p_grad_trial[j*nSpace+I]*dV;
4973 for (
int j=0;j<nDOF_v_test_element;j++)
4975 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_v_trial_element+j]*dV;
4976 for (
int I=0;I<nSpace;I++)
4978 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial[j*nSpace+I]*dV;
4983 double div_mesh_velocity=0.0;
4984 for (
int j=0;j<nDOF_trial_element;j++)
4986 int eN_j=eN*nDOF_trial_element+j;
4987 div_mesh_velocity +=
4988 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+0]*p_grad_trial[j*nSpace+0] +
4989 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+1]*p_grad_trial[j*nSpace+1];
4991 div_mesh_velocity =
DM3*div_mesh_velocity + (1.0-
DM3)*alphaBDF*(dV-q_dV_last.data()[eN_k])/dV;
4994 porosity = q_porosity.data()[eN_k];
4996 double ball_n[nSpace];
4997 if (use_ball_as_particle == 1 && nParticles > 0)
4999 int ball_index=
get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x,y,
z,distance_to_solids.data()[eN_k]);
5000 get_normal_to_ith_ball(nParticles, ball_center.data(), ball_radius.data(),ball_index,x,y,
z,ball_n[0],ball_n[1]);
5009 double eddy_viscosity(0.);
5010 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
5011 const double H_s =
gf_s.H(particle_eps, phi_solid.data()[eN_k]);
5017 if (fluid_phase == 0)
5028 else if (icase == -1)
5033 else if (icase == 1)
5043 double H = (1.0-useVF)*
gf.H(eps_rho,
phi[eN_k]) + useVF*fmin(1.0,fmax(0.0,vf[eN_k]));
5044 double ImH = (1.0-useVF)*
gf.ImH(eps_rho,
phi[eN_k]) + useVF*(1.0-fmin(1.0,fmax(0.0,vf[eN_k])));
5053 elementDiameter.data()[eN],
5054 smagorinskyConstant,
5055 turbulenceClosureModel,
5060 &normal_phi.data()[eN_k_nSpace],
5061 kappa_phi.data()[eN_k],
5065 phi_solid.data()[eN_k],
5084 q_eddy_viscosity_last.data()[eN_k],
5140 mass_source = q_mass_source.data()[eN_k];
5146 q_dragAlpha.data()[eN_k],
5147 q_dragBeta.data()[eN_k],
5160 q_velocity_sge.data()[eN_k_nSpace+0],
5161 q_velocity_sge.data()[eN_k_nSpace+1],
5162 q_velocity_sge.data()[eN_k_nSpace+1],
5163 eps_porous.data()[elementFlags.data()[eN]],
5164 phi_porous.data()[eN_k],
5165 q_velocity_porous.data()[eN_k_nSpace+0],
5166 q_velocity_porous.data()[eN_k_nSpace+1],
5167 q_velocity_porous.data()[eN_k_nSpace+1],
5176 if (turbulenceClosureModel >= 3)
5178 const double c_mu = 0.09;
5180 turbulenceClosureModel,
5192 q_turb_var_0.data()[eN_k],
5193 q_turb_var_1.data()[eN_k],
5194 &q_turb_var_grad_0.data()[eN_k_nSpace],
5214 if (NONCONSERVATIVE_FORM > 0.0)
5216 mom_u_ham -= MOVING_DOMAIN*dmom_u_acc_u*(grad_u[0]*
xt + grad_u[1]*yt);
5217 dmom_u_ham_grad_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*
xt;
5218 dmom_u_ham_grad_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
5222 mom_u_adv[0] -= MOVING_DOMAIN*mom_u_acc*
xt;
5223 mom_u_adv[1] -= MOVING_DOMAIN*mom_u_acc*yt;
5224 dmom_u_adv_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*
xt;
5225 dmom_u_adv_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
5228 if (NONCONSERVATIVE_FORM > 0.0)
5230 mom_v_ham -= MOVING_DOMAIN*dmom_v_acc_v*(grad_v[0]*
xt + grad_v[1]*yt);
5231 dmom_v_ham_grad_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*
xt;
5232 dmom_v_ham_grad_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
5236 mom_v_adv[0] -= MOVING_DOMAIN*mom_v_acc*
xt;
5237 mom_v_adv[1] -= MOVING_DOMAIN*mom_v_acc*yt;
5238 dmom_v_adv_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*
xt;
5239 dmom_v_adv_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
5245 q_mom_u_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
5251 q_mom_v_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
5256 if (NONCONSERVATIVE_FORM > 0.0)
5258 mom_u_acc_t *= dmom_u_acc_u;
5259 mom_v_acc_t *= dmom_v_acc_v;
5264 if (NONCONSERVATIVE_FORM > 0.0)
5266 dmom_adv_sge[0] = 0.0;
5267 dmom_adv_sge[1] = 0.0;
5268 dmom_ham_grad_sge[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt);
5269 dmom_ham_grad_sge[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
5273 dmom_adv_sge[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt);
5274 dmom_adv_sge[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
5275 dmom_ham_grad_sge[0] = 0.0;
5276 dmom_ham_grad_sge[1] = 0.0;
5278 double mv_tau[nSpace]=
ZEROVEC;
5279 mv_tau[0] = dmom_adv_sge[0] + dmom_ham_grad_sge[0];
5280 mv_tau[1] = dmom_adv_sge[1] + dmom_ham_grad_sge[1];
5284 pdeResidual_p =
ck.Advection_strong(dmass_adv_u,grad_u) +
5285 ck.Advection_strong(dmass_adv_v,grad_v) +
5286 DM2*MOVING_DOMAIN*
ck.Reaction_strong(alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity) +
5287 ck.Reaction_strong(mass_source);
5289 pdeResidual_u =
ck.Mass_strong(mom_u_acc_t) +
5290 ck.Advection_strong(dmom_adv_sge,grad_u) +
5291 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_u) +
5292 ck.Hamiltonian_strong(dmom_u_ham_grad_p,grad_p) +
5293 ck.Reaction_strong(mom_u_source) -
5294 ck.Reaction_strong(dmom_u_acc_u*
u*div_mesh_velocity);
5296 pdeResidual_v =
ck.Mass_strong(mom_v_acc_t) +
5297 ck.Advection_strong(dmom_adv_sge,grad_v) +
5298 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_v) +
5299 ck.Hamiltonian_strong(dmom_v_ham_grad_p,grad_p) +
5300 ck.Reaction_strong(mom_v_source) -
5301 ck.Reaction_strong(dmom_v_acc_v*
v*div_mesh_velocity);
5304 for (
int j=0;j<nDOF_v_trial_element;j++)
5306 register int j_nSpace = j*nSpace;
5307 dpdeResidual_p_u[j]=
ck.AdvectionJacobian_strong(dmass_adv_u,&vel_grad_trial_ib[j_nSpace]);
5308 dpdeResidual_p_v[j]=
ck.AdvectionJacobian_strong(dmass_adv_v,&vel_grad_trial_ib[j_nSpace]);
5309 dpdeResidual_u_u[j]=
ck.MassJacobian_strong(dmom_u_acc_u_t,vel_trial[j]) +
5310 ck.HamiltonianJacobian_strong(dmom_ham_grad_sge,&vel_grad_trial_ib[j_nSpace]) +
5311 ck.AdvectionJacobian_strong(dmom_adv_sge,&vel_grad_trial_ib[j_nSpace]) -
5312 ck.ReactionJacobian_strong(dmom_u_acc_u*div_mesh_velocity,vel_trial[j]);
5313 dpdeResidual_v_v[j]=
ck.MassJacobian_strong(dmom_v_acc_v_t,vel_trial[j]) +
5314 ck.HamiltonianJacobian_strong(dmom_ham_grad_sge,&vel_grad_trial_ib[j_nSpace]) +
5315 ck.AdvectionJacobian_strong(dmom_adv_sge,&vel_grad_trial_ib[j_nSpace]) -
5316 ck.ReactionJacobian_strong(dmom_v_acc_v*div_mesh_velocity,vel_trial[j]);
5318 dpdeResidual_u_u[j]+=
ck.ReactionJacobian_strong(dmom_u_source[0],vel_trial[j]);
5319 dpdeResidual_v_v[j]+=
ck.ReactionJacobian_strong(dmom_v_source[1],vel_trial[j]);
5321 for (
int j=0;j<nDOF_trial_element;j++)
5323 register int j_nSpace = j*nSpace;
5324 dpdeResidual_u_p[j]=
ck.HamiltonianJacobian_strong(dmom_u_ham_grad_p,&p_grad_trial_ib[j_nSpace]);
5325 dpdeResidual_v_p[j]=
ck.HamiltonianJacobian_strong(dmom_v_ham_grad_p,&p_grad_trial_ib[j_nSpace]);
5329 double tmpR=dmom_u_acc_u_t + dmom_u_source[0];
5331 elementDiameter.data()[eN],
5336 dmom_u_ham_grad_p[0],
5339 q_cfl.data()[eN_k]);
5346 dmom_u_ham_grad_p[0],
5349 q_cfl.data()[eN_k]);
5351 tau_v = useMetrics*tau_v1+(1.0-useMetrics)*tau_v0;
5352 tau_p = useMetrics*tau_p1+(1.0-useMetrics)*tau_p0;
5386 dmom_adv_star[0] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*
xt + useRBLES*subgridError_u);
5387 dmom_adv_star[1] =
inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt + useRBLES*subgridError_v);
5390 for (
int i=0;i<nDOF_test_element;i++)
5392 register int i_nSpace = i*nSpace;
5393 Lstar_u_p[i]=
ck.Advection_adjoint(dmass_adv_u,&p_grad_test_dV[i_nSpace]);
5394 Lstar_v_p[i]=
ck.Advection_adjoint(dmass_adv_v,&p_grad_test_dV[i_nSpace]);
5397 for (
int i=0;i<nDOF_v_test_element;i++)
5399 register int i_nSpace = i*nSpace;
5400 Lstar_u_u[i]=
ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
5401 Lstar_v_v[i]=
ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
5402 Lstar_p_u[i]=
ck.Hamiltonian_adjoint(dmom_u_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
5403 Lstar_p_v[i]=
ck.Hamiltonian_adjoint(dmom_v_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
5405 Lstar_u_u[i]+=
ck.Reaction_adjoint(dmom_u_source[0],vel_test_dV[i]);
5406 Lstar_v_v[i]+=
ck.Reaction_adjoint(dmom_v_source[1],vel_test_dV[i]);
5410 dmom_u_adv_u[0] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u);
5411 dmom_u_adv_u[1] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v);
5413 dmom_v_adv_v[0] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u);
5414 dmom_v_adv_v[1] +=
inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v);
5419 double level_set_normal[nSpace];
5423 double norm_exact=0.0,norm_cut=0.0;
5424 if (use_ball_as_particle)
5426 for (
int I=0;I<nSpace;I++)
5428 sign += ball_n[I]*
gf_s.get_normal()[I];
5429 level_set_normal[I] =
gf_s.get_normal()[I];
5430 norm_cut += level_set_normal[I]*level_set_normal[I];
5431 norm_exact += ball_n[I]*ball_n[I];
5436 for (
int I=0;I<nSpace;I++)
5438 sign += particle_signed_distance_normals.data()[eN_k_3d+I]*
gf_s.get_normal()[I];
5439 level_set_normal[I] =
gf_s.get_normal()[I];
5440 norm_cut += level_set_normal[I]*level_set_normal[I];
5441 norm_exact += particle_signed_distance_normals.data()[eN_k_3d+I]*particle_signed_distance_normals.data()[eN_k_3d+I];
5444 assert(std::fabs(1.0-norm_cut) < 1.0e-8);
5445 assert(std::fabs(1.0-norm_exact) < 1.0e-8);
5447 for (
int I=0;I<nSpace;I++)
5448 level_set_normal[I]*=-1.0;
5458 if (use_ball_as_particle)
5459 for (
int I=0;I<nSpace;I++)
5460 level_set_normal[I] = ball_n[I];
5462 for (
int I=0;I<nSpace;I++)
5463 level_set_normal[I] = particle_signed_distance_normals.data()[eN_k_3d+I];
5466 NONCONSERVATIVE_FORM,
5467 eN < nElements_owned,
5471 nQuadraturePoints_global,
5472 &particle_signed_distances.data()[eN_k],
5474 &particle_velocities.data()[eN_k_3d],
5475 particle_centroids.data(),
5476 use_ball_as_particle,
5479 ball_velocity.data(),
5480 ball_angular_velocity.data(),
5481 ball_density.data(),
5483 particle_penalty_constant/h_phi,
5502 q_velocity_sge.data()[eN_k_nSpace+0],
5503 q_velocity_sge.data()[eN_k_nSpace+1],
5504 q_velocity_sge.data()[eN_k_nSpace+1],
5523 dmom_u_ham_grad_u_s,
5524 dmom_u_ham_grad_v_s,
5529 dmom_v_ham_grad_u_s,
5530 dmom_v_ham_grad_v_s,
5535 dmom_w_ham_grad_w_s,
5543 &particle_netForces_tmp[0],
5544 &particle_netMoments_tmp[0],
5545 &particle_surfaceArea_tmp[0]);
5549 if (
gf.useExact && icase == 0)
5551 if (fluid_phase == 0)
5552 H_f =
gf.ImH(0.,0.);
5558 assert(fluid_phase == 0);
5561 for(
int i=0;i<nDOF_test_element;i++)
5563 register int i_nSpace = i*nSpace;
5564 for(
int j=0;j<nDOF_trial_element;j++)
5566 register int j_nSpace = j*nSpace;
5567 if (nDOF_test_element == nDOF_v_trial_element)
5569 elementJacobian_p_p[i][j] += H_s*H_f*((1-PRESSURE_PROJECTION_STABILIZATION)*
ck.SubgridErrorJacobian(dsubgridError_u_p[j],Lstar_u_p[i]) +
5570 (1-PRESSURE_PROJECTION_STABILIZATION)*
ck.SubgridErrorJacobian(dsubgridError_v_p[j],Lstar_v_p[i]) +
5571 PRESSURE_PROJECTION_STABILIZATION*
ck.pressureProjection_weak(mom_uu_diff_ten[1], p_trial[j], 1./3., p_test_ref.data()[k*nDOF_test_element +i],dV));
5575 for(
int i=0;i<nDOF_test_element;i++)
5577 register int i_nSpace = i*nSpace;
5578 for(
int j=0;j<nDOF_v_trial_element;j++)
5580 register int j_nSpace = j*nSpace;
5581 elementJacobian_p_u[i][j] += H_s*H_f*(
ck.AdvectionJacobian_weak(dmass_adv_u,vel_trial[j],&p_grad_test_dV[i_nSpace]) +
5582 ck.MassJacobian_weak(dmass_ham_u,vel_trial[j],p_test_dV[i]));
5583 elementJacobian_p_v[i][j] += H_s*H_f*(
ck.AdvectionJacobian_weak(dmass_adv_v,vel_trial[j],&p_grad_test_dV[i_nSpace]) +
5584 ck.MassJacobian_weak(dmass_ham_v,vel_trial[j],p_test_dV[i]));
5585 if (nDOF_test_element == nDOF_v_trial_element)
5587 elementJacobian_p_u[i][j] += H_s*H_f*(1-PRESSURE_PROJECTION_STABILIZATION)*
ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u_p[i]);
5588 elementJacobian_p_v[i][j] += H_s*H_f*(1-PRESSURE_PROJECTION_STABILIZATION)*
ck.SubgridErrorJacobian(dsubgridError_v_v[j],Lstar_v_p[i]);
5592 for(
int i=0;i<nDOF_v_test_element;i++)
5594 register int i_nSpace = i*nSpace;
5595 for(
int j=0;j<nDOF_trial_element;j++)
5597 register int j_nSpace = j*nSpace;
5598 elementJacobian_u_p[i][j] += H_s*H_f*(
ck.HamiltonianJacobian_weak(dmom_u_ham_grad_p,&p_grad_trial_ib[j_nSpace],vel_test_dV[i])+
5599 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridErrorJacobian(dsubgridError_u_p[j],Lstar_u_u[i]));
5600 elementJacobian_v_p[i][j] += H_s*H_f*(
ck.HamiltonianJacobian_weak(dmom_v_ham_grad_p,&p_grad_trial_ib[j_nSpace],vel_test_dV[i])+
5601 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridErrorJacobian(dsubgridError_v_p[j],Lstar_v_v[i]));
5604 for(
int i=0;i<nDOF_v_test_element;i++)
5606 register int i_nSpace = i*nSpace;
5607 for(
int j=0;j<nDOF_v_trial_element;j++)
5609 register int j_nSpace = j*nSpace;
5610 elementJacobian_u_u[i][j] += H_s*H_f*(
ck.MassJacobian_weak(dmom_u_acc_u_t,vel_trial[j],vel_test_dV[i]) +
5611 ck.MassJacobian_weak(dmom_u_ham_u,vel_trial[j],vel_test_dV[i]) +
5612 ck.HamiltonianJacobian_weak(dmom_u_ham_grad_u,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5613 ck.AdvectionJacobian_weak(dmom_u_adv_u,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5614 ck.SimpleDiffusionJacobian_weak(sdInfo_u_u_rowptr.data(),sdInfo_u_u_colind.data(),mom_uu_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
5615 ck.ReactionJacobian_weak(dmom_u_source[0]+NONCONSERVATIVE_FORM*dmom_u_acc_u*div_mesh_velocity,vel_trial[j],vel_test_dV[i]) +
5616 MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridErrorJacobian(dsubgridError_p_u[j],Lstar_p_u[i]) +
5617 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u_u[i]) +
5618 ck.NumericalDiffusionJacobian(q_numDiff_u_last.data()[eN_k],&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]));
5619 elementJacobian_u_v[i][j] += H_s*H_f*(
ck.HamiltonianJacobian_weak(dmom_u_ham_grad_v,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5620 ck.AdvectionJacobian_weak(dmom_u_adv_v,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5621 ck.MassJacobian_weak(dmom_u_ham_v,vel_trial[j],vel_test_dV[i]) +
5622 ck.SimpleDiffusionJacobian_weak(sdInfo_u_v_rowptr.data(),sdInfo_u_v_colind.data(),mom_uv_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
5623 ck.ReactionJacobian_weak(dmom_u_source[1],vel_trial[j],vel_test_dV[i]) +
5624 MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridErrorJacobian(dsubgridError_p_v[j],Lstar_p_u[i]));
5625 elementJacobian_v_u[i][j] += H_s*H_f*(
ck.HamiltonianJacobian_weak(dmom_v_ham_grad_u,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5626 ck.AdvectionJacobian_weak(dmom_v_adv_u,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5627 ck.MassJacobian_weak(dmom_v_ham_u,vel_trial[j],vel_test_dV[i]) +
5628 ck.SimpleDiffusionJacobian_weak(sdInfo_v_u_rowptr.data(),sdInfo_v_u_colind.data(),mom_vu_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
5629 ck.ReactionJacobian_weak(dmom_v_source[0],vel_trial[j],vel_test_dV[i]) +
5630 MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridErrorJacobian(dsubgridError_p_u[j],Lstar_p_v[i]));
5631 elementJacobian_v_v[i][j] += H_s*H_f*(
ck.MassJacobian_weak(dmom_v_acc_v_t,vel_trial[j],vel_test_dV[i]) +
5632 ck.MassJacobian_weak(dmom_v_ham_v,vel_trial[j],vel_test_dV[i]) +
5633 ck.HamiltonianJacobian_weak(dmom_v_ham_grad_v,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5634 ck.AdvectionJacobian_weak(dmom_v_adv_v,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5635 ck.SimpleDiffusionJacobian_weak(sdInfo_v_v_rowptr.data(),sdInfo_v_v_colind.data(),mom_vv_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
5636 ck.ReactionJacobian_weak(dmom_v_source[1]+NONCONSERVATIVE_FORM*dmom_v_acc_v*div_mesh_velocity,vel_trial[j],vel_test_dV[i]) +
5637 MOMENTUM_SGE*PRESSURE_SGE*
ck.SubgridErrorJacobian(dsubgridError_p_v[j],Lstar_p_v[i]) +
5638 MOMENTUM_SGE*VELOCITY_SGE*
ck.SubgridErrorJacobian(dsubgridError_v_v[j],Lstar_v_v[i]) +
5639 ck.NumericalDiffusionJacobian(q_numDiff_v_last.data()[eN_k],&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]));
5644 for(
int i=0;i<nDOF_v_test_element;i++)
5646 register int i_nSpace = i*nSpace;
5647 for(
int j=0;j<nDOF_v_trial_element;j++)
5649 register int j_nSpace = j*nSpace;
5650 elementJacobian_u_u[i][j] += H_f*(
ck.MassJacobian_weak(dmom_u_ham_u_s,vel_trial[j],vel_test_dV[i]) +
5651 ck.HamiltonianJacobian_weak(dmom_u_ham_grad_u_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5652 ck.AdvectionJacobian_weak(dmom_u_adv_u_s,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5653 ck.ReactionJacobian_weak(dmom_u_source_s[0],vel_trial[j],vel_test_dV[i]));
5655 elementJacobian_u_v[i][j] += H_f*(
ck.HamiltonianJacobian_weak(dmom_u_ham_grad_v_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5656 ck.ReactionJacobian_weak(dmom_u_source_s[1],vel_trial[j],vel_test_dV[i]));
5658 elementJacobian_v_u[i][j] += H_f*(
ck.HamiltonianJacobian_weak(dmom_v_ham_grad_u_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5659 ck.ReactionJacobian_weak(dmom_v_source_s[0],vel_trial[j],vel_test_dV[i]));
5661 elementJacobian_v_v[i][j] += H_f*(
ck.MassJacobian_weak(dmom_v_ham_v_s,vel_trial[j],vel_test_dV[i]) +
5662 ck.HamiltonianJacobian_weak(dmom_v_ham_grad_v_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
5663 ck.AdvectionJacobian_weak(dmom_v_adv_v_s,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
5664 ck.ReactionJacobian_weak(dmom_v_source_s[1],vel_trial[j],vel_test_dV[i]));
5673 for (
int i=0;i<nDOF_test_element;i++)
5675 register int eN_i = eN*nDOF_test_element+i;
5676 for (
int j=0;j<nDOF_trial_element;j++)
5678 register int eN_i_j = eN_i*nDOF_trial_element+j;
5679 globalJacobian.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += elementJacobian_p_p[i][j];
5682 for (
int i=0;i<nDOF_test_element;i++)
5684 register int eN_i = eN*nDOF_test_element+i;
5685 for (
int j=0;j<nDOF_v_trial_element;j++)
5687 register int eN_i_j = eN_i*nDOF_v_trial_element+j;
5688 globalJacobian.data()[csrRowIndeces_p_u.data()[eN_i] + csrColumnOffsets_p_u.data()[eN_i_j]] += elementJacobian_p_u[i][j];
5689 globalJacobian.data()[csrRowIndeces_p_v.data()[eN_i] + csrColumnOffsets_p_v.data()[eN_i_j]] += elementJacobian_p_v[i][j];
5692 for (
int i=0;i<nDOF_v_test_element;i++)
5694 register int eN_i = eN*nDOF_v_test_element+i;
5695 for (
int j=0;j<nDOF_trial_element;j++)
5697 register int eN_i_j = eN_i*nDOF_trial_element+j;
5698 globalJacobian.data()[csrRowIndeces_u_p.data()[eN_i] + csrColumnOffsets_u_p.data()[eN_i_j]] += elementJacobian_u_p[i][j];
5699 globalJacobian.data()[csrRowIndeces_v_p.data()[eN_i] + csrColumnOffsets_v_p.data()[eN_i_j]] += elementJacobian_v_p[i][j];
5702 for (
int i=0;i<nDOF_v_test_element;i++)
5704 register int eN_i = eN*nDOF_v_test_element+i;
5705 for (
int j=0;j<nDOF_v_trial_element;j++)
5707 register int eN_i_j = eN_i*nDOF_v_trial_element+j;
5708 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
5709 globalJacobian.data()[csrRowIndeces_u_v.data()[eN_i] + csrColumnOffsets_u_v.data()[eN_i_j]] += elementJacobian_u_v[i][j];
5711 globalJacobian.data()[csrRowIndeces_v_u.data()[eN_i] + csrColumnOffsets_v_u.data()[eN_i_j]] += elementJacobian_v_u[i][j];
5712 globalJacobian.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += elementJacobian_v_v[i][j];
5719 std::map<int,double> DWp_Dn_jump,DW_Dn_jump;
5720 std::map<std::pair<int, int>,
int> p_p_nz, u_u_nz, v_v_nz;
5721 register double gamma_cutfem=ghost_penalty_constant,gamma_cutfem_p=ghost_penalty_constant,h_cutfem=elementBoundaryDiameter.data()[*it];
5722 int eN_nDOF_v_trial_element = elementBoundaryElementsArray.data()[(*it)*2+0]*nDOF_v_trial_element;
5726 for (
int i_offset=1;i_offset<nDOF_v_trial_element;i_offset++)
5729 double u=u_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
5730 v=v_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]];
5731 norm_v=fmax(norm_v,sqrt(
u*
u+
v*
v));
5733 double gamma_v_dim =
rho_0*(
nu_0 + norm_v*h_cutfem + alphaBDF*h_cutfem*h_cutfem);
5734 gamma_cutfem_p *= h_cutfem*h_cutfem/gamma_v_dim;
5735 if (NONCONSERVATIVE_FORM)
5736 gamma_cutfem*=gamma_v_dim;
5738 gamma_cutfem*=(gamma_v_dim/
rho_0);
5739 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
5741 register double Dp_Dn_jump=0.0, Du_Dn_jump=0.0, Dv_Dn_jump=0.0,dS;
5742 for (
int eN_side=0;eN_side < 2; eN_side++)
5744 register int ebN = *it,
5745 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
5746 for (
int i=0;i<nDOF_test_element;i++)
5747 DWp_Dn_jump[p_l2g.data()[eN*nDOF_test_element+i]] = 0.0;
5748 for (
int i=0;i<nDOF_v_test_element;i++)
5749 DW_Dn_jump[vel_l2g.data()[eN*nDOF_v_test_element+i]] = 0.0;
5751 for (
int eN_side=0;eN_side < 2; eN_side++)
5753 register int ebN = *it,
5754 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side],
5755 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+eN_side],
5756 eN_nDOF_trial_element = eN*nDOF_trial_element,
5757 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
5758 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
5759 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
5760 register double p_int=0.0,
5766 jac_int[nSpace*nSpace],
5768 jacInv_int[nSpace*nSpace],
5769 boundaryJac[nSpace*(nSpace-1)],
5770 metricTensor[(nSpace-1)*(nSpace-1)],
5771 metricTensorDetSqrt,
5772 p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
5773 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
5774 p_grad_test_dS[nDOF_trial_element*nSpace],vel_grad_test_dS[nDOF_v_trial_element*nSpace],
5775 normal[nSpace],x_int,y_int,z_int,xt_int,yt_int,zt_int,integralScaling,
5776 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
5777 force_x,force_y,force_z,force_p_x,force_p_y,force_p_z,force_v_x,force_v_y,force_v_z,r_x,r_y,r_z;
5779 ck.calculateMapping_elementBoundary(eN,
5785 mesh_trial_trace_ref.data(),
5786 mesh_grad_trial_trace_ref.data(),
5787 boundaryJac_ref.data(),
5793 metricTensorDetSqrt,
5798 ck.calculateMappingVelocity_elementBoundary(eN,
5802 mesh_velocity_dof.data(),
5804 mesh_trial_trace_ref.data(),
5805 xt_int,yt_int,zt_int,
5810 dS = metricTensorDetSqrt*dS_ref.data()[kb];
5813 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_int,p_grad_trial_trace);
5814 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_int,vel_grad_trial_trace);
5815 for (
int i=0;i<nDOF_test_element;i++)
5817 int eN_i = eN*nDOF_test_element + i;
5818 for (
int I=0;I<nSpace;I++)
5819 DWp_Dn_jump[p_l2g.data()[eN_i]] += p_grad_trial_trace[i*nSpace+I]*normal[I];
5821 for (
int i=0;i<nDOF_v_test_element;i++)
5823 int eN_i = eN*nDOF_v_test_element + i;
5824 for (
int I=0;I<nSpace;I++)
5825 DW_Dn_jump[vel_l2g.data()[eN_i]] += vel_grad_trial_trace[i*nSpace+I]*normal[I];
5828 for (
int eN_side=0;eN_side < 2; eN_side++)
5830 register int ebN = *it,
5831 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
5832 for (
int i=0;i<nDOF_test_element;i++)
5834 register int eN_i = eN*nDOF_test_element+i;
5835 for (
int eN_side2=0;eN_side2 < 2; eN_side2++)
5837 register int eN2 = elementBoundaryElementsArray.data()[ebN*2+eN_side2];
5838 for (
int j=0;j<nDOF_test_element;j++)
5840 int eN_i_j = eN_i*nDOF_test_element + j;
5841 int eN2_j = eN2*nDOF_test_element + j;
5845 i*nDOF_trial_element +
5847 std::pair<int,int> ij = std::make_pair(p_l2g.data()[eN_i], p_l2g.data()[eN2_j]);
5848 if (p_p_nz.count(ij))
5850 assert(p_p_nz[ij] == csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_eb_p_p.data()[ebN_i_j]);
5853 p_p_nz[ij] = csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_eb_p_p.data()[ebN_i_j];
5857 for (
int i=0;i<nDOF_v_test_element;i++)
5859 register int eN_i = eN*nDOF_v_test_element+i;
5860 for (
int eN_side2=0;eN_side2 < 2; eN_side2++)
5862 register int eN2 = elementBoundaryElementsArray.data()[ebN*2+eN_side2];
5863 for (
int j=0;j<nDOF_v_test_element;j++)
5865 int eN_i_j = eN_i*nDOF_v_test_element + j;
5866 int eN2_j = eN2*nDOF_v_test_element + j;
5870 i*nDOF_v_trial_element +
5872 std::pair<int,int> ij = std::make_pair(vel_l2g.data()[eN_i], vel_l2g.data()[eN2_j]);
5873 if (u_u_nz.count(ij))
5875 assert(u_u_nz[ij] == csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]);
5878 u_u_nz[ij] = csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j];
5879 if (v_v_nz.count(ij))
5881 assert(v_v_nz[ij] == csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j]);
5884 v_v_nz[ij] = csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j];
5889 for (std::map<int,double>::iterator Wi_it=DWp_Dn_jump.begin(); Wi_it!=DWp_Dn_jump.end(); ++Wi_it)
5890 for (std::map<int,double>::iterator Wj_it=DWp_Dn_jump.begin(); Wj_it!=DWp_Dn_jump.end(); ++Wj_it)
5892 int i_global = Wi_it->first,
5893 j_global = Wj_it->first;
5894 double DWp_Dn_jump_i = Wi_it->second,
5895 DWp_Dn_jump_j = Wj_it->second;
5896 std::pair<int,int> ij = std::make_pair(i_global, j_global);
5897 globalJacobian.data()[p_p_nz.at(ij)] += gamma_cutfem_p*h_cutfem*DWp_Dn_jump_j*DWp_Dn_jump_i*dS;
5899 for (std::map<int,double>::iterator Wi_it=DW_Dn_jump.begin(); Wi_it!=DW_Dn_jump.end(); ++Wi_it)
5900 for (std::map<int,double>::iterator Wj_it=DW_Dn_jump.begin(); Wj_it!=DW_Dn_jump.end(); ++Wj_it)
5902 int i_global = Wi_it->first,
5903 j_global = Wj_it->first;
5904 double DW_Dn_jump_i = Wi_it->second,
5905 DW_Dn_jump_j = Wj_it->second;
5906 std::pair<int,int> ij = std::make_pair(i_global, j_global);
5907 globalJacobian.data()[u_u_nz.at(ij)] += gamma_cutfem*h_cutfem*DW_Dn_jump_j*DW_Dn_jump_i*dS;
5908 globalJacobian.data()[v_v_nz.at(ij)] += gamma_cutfem*h_cutfem*DW_Dn_jump_j*DW_Dn_jump_i*dS;
5916 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
5918 register int ebN = exteriorElementBoundariesArray.data()[ebNE],
5919 eN = elementBoundaryElementsArray.data()[ebN*2+0],
5920 eN_nDOF_trial_element = eN*nDOF_trial_element,
5921 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
5922 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0];
5923 if (boundaryFlags[ebN] < 1)
5925 register double eps_rho,eps_mu;
5926 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
5927 for (
int j=0;j<nDOF_mesh_trial_element;j++)
5929 register int eN_j = eN*nDOF_mesh_trial_element+j;
5930 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
5931 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
5933 double element_nodes[nDOF_mesh_trial_element*3];
5934 for (
int i=0;i<nDOF_mesh_trial_element;i++)
5936 register int eN_i=eN*nDOF_mesh_trial_element+i;
5937 for(
int I=0;I<3;I++)
5938 element_nodes[i*3 + I] = mesh_dof[mesh_l2g.data()[eN_i]*3 + I];
5940 double mesh_dof_ref[nDOF_mesh_trial_element*3]={0.,0.,0.,1.,0.,0.,0.,1.,0.};
5941 double xb_ref_calc[nQuadraturePoints_elementBoundary*3];
5942 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
5944 double x=0.0,y=0.0,
z=0.0;
5945 for (
int j=0;j<nDOF_mesh_trial_element;j++)
5947 int ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb;
5948 int ebN_local_kb_j = ebN_local_kb*nDOF_mesh_trial_element+j;
5949 x += mesh_dof_ref[j*3+0]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
5950 y += mesh_dof_ref[j*3+1]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
5951 z += mesh_dof_ref[j*3+2]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
5953 xb_ref_calc[3*kb+0] = x;
5954 xb_ref_calc[3*kb+1] = y;
5955 xb_ref_calc[3*kb+2] =
z;
5957 int icase_s =
gf_s.calculate(element_phi_s, element_nodes, xb_ref_calc,
true);
5959 int icase =
gf.calculate(element_phi, element_nodes, xb_ref.data(),
rho_1*
nu_1,
rho_0*
nu_0,
true,
false);
5961 int icase =
gf.calculate(element_phi, element_nodes, xb_ref.data(), 1.0,1.0,
true,
false);
5963 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
5965 register int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
5966 ebNE_kb_nSpace = ebNE_kb*nSpace,
5967 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
5968 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
5970 register double phi_s_ext=0.0,
5979 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
5982 dmom_u_acc_u_ext=0.0,
5984 dmom_v_acc_v_ext=0.0,
5986 dmom_w_acc_w_ext=0.0,
5988 dmass_adv_u_ext[nSpace]=
ZEROVEC,
5989 dmass_adv_v_ext[nSpace]=
ZEROVEC,
5990 dmass_adv_w_ext[nSpace]=
ZEROVEC,
5991 mom_u_adv_ext[nSpace]=
ZEROVEC,
5992 dmom_u_adv_u_ext[nSpace]=
ZEROVEC,
5993 dmom_u_adv_v_ext[nSpace]=
ZEROVEC,
5994 dmom_u_adv_w_ext[nSpace]=
ZEROVEC,
5995 mom_v_adv_ext[nSpace]=
ZEROVEC,
5996 dmom_v_adv_u_ext[nSpace]=
ZEROVEC,
5997 dmom_v_adv_v_ext[nSpace]=
ZEROVEC,
5998 dmom_v_adv_w_ext[nSpace]=
ZEROVEC,
5999 mom_w_adv_ext[nSpace]=
ZEROVEC,
6000 dmom_w_adv_u_ext[nSpace]=
ZEROVEC,
6001 dmom_w_adv_v_ext[nSpace]=
ZEROVEC,
6002 dmom_w_adv_w_ext[nSpace]=
ZEROVEC,
6003 mom_uu_diff_ten_ext[nSpace]=
ZEROVEC,
6004 mom_vv_diff_ten_ext[nSpace]=
ZEROVEC,
6005 mom_ww_diff_ten_ext[nSpace]=
ZEROVEC,
6006 mom_uv_diff_ten_ext[1],
6007 mom_uw_diff_ten_ext[1],
6008 mom_vu_diff_ten_ext[1],
6009 mom_vw_diff_ten_ext[1],
6010 mom_wu_diff_ten_ext[1],
6011 mom_wv_diff_ten_ext[1],
6012 mom_u_source_ext=0.0,
6013 mom_v_source_ext=0.0,
6014 mom_w_source_ext=0.0,
6016 dmom_u_ham_grad_p_ext[nSpace]=
ZEROVEC,
6017 dmom_u_ham_grad_u_ext[nSpace]=
ZEROVEC,
6018 dmom_u_ham_u_ext=0.0,
6019 dmom_u_ham_v_ext=0.0,
6020 dmom_u_ham_w_ext=0.0,
6022 dmom_v_ham_grad_p_ext[nSpace]=
ZEROVEC,
6023 dmom_v_ham_grad_v_ext[nSpace]=
ZEROVEC,
6024 dmom_v_ham_u_ext=0.0,
6025 dmom_v_ham_v_ext=0.0,
6026 dmom_v_ham_w_ext=0.0,
6028 dmom_w_ham_grad_p_ext[nSpace]=
ZEROVEC,
6029 dmom_w_ham_grad_w_ext[nSpace]=
ZEROVEC,
6030 dmom_w_ham_u_ext=0.0,
6031 dmom_w_ham_v_ext=0.0,
6032 dmom_w_ham_w_ext=0.0,
6033 dmom_u_adv_p_ext[nSpace]=
ZEROVEC,
6034 dmom_v_adv_p_ext[nSpace]=
ZEROVEC,
6035 dmom_w_adv_p_ext[nSpace]=
ZEROVEC,
6036 dflux_mass_u_ext=0.0,
6037 dflux_mass_v_ext=0.0,
6038 dflux_mass_w_ext=0.0,
6039 dflux_mom_u_adv_p_ext=0.0,
6040 dflux_mom_u_adv_u_ext=0.0,
6041 dflux_mom_u_adv_v_ext=0.0,
6042 dflux_mom_u_adv_w_ext=0.0,
6043 dflux_mom_v_adv_p_ext=0.0,
6044 dflux_mom_v_adv_u_ext=0.0,
6045 dflux_mom_v_adv_v_ext=0.0,
6046 dflux_mom_v_adv_w_ext=0.0,
6047 dflux_mom_w_adv_p_ext=0.0,
6048 dflux_mom_w_adv_u_ext=0.0,
6049 dflux_mom_w_adv_v_ext=0.0,
6050 dflux_mom_w_adv_w_ext=0.0,
6055 bc_mom_u_acc_ext=0.0,
6056 bc_dmom_u_acc_u_ext=0.0,
6057 bc_mom_v_acc_ext=0.0,
6058 bc_dmom_v_acc_v_ext=0.0,
6059 bc_mom_w_acc_ext=0.0,
6060 bc_dmom_w_acc_w_ext=0.0,
6061 bc_mass_adv_ext[nSpace]=
ZEROVEC,
6062 bc_dmass_adv_u_ext[nSpace]=
ZEROVEC,
6063 bc_dmass_adv_v_ext[nSpace]=
ZEROVEC,
6064 bc_dmass_adv_w_ext[nSpace]=
ZEROVEC,
6065 bc_mom_u_adv_ext[nSpace]=
ZEROVEC,
6066 bc_dmom_u_adv_u_ext[nSpace]=
ZEROVEC,
6067 bc_dmom_u_adv_v_ext[nSpace]=
ZEROVEC,
6068 bc_dmom_u_adv_w_ext[nSpace]=
ZEROVEC,
6069 bc_mom_v_adv_ext[nSpace]=
ZEROVEC,
6070 bc_dmom_v_adv_u_ext[nSpace]=
ZEROVEC,
6071 bc_dmom_v_adv_v_ext[nSpace]=
ZEROVEC,
6072 bc_dmom_v_adv_w_ext[nSpace]=
ZEROVEC,
6073 bc_mom_w_adv_ext[nSpace]=
ZEROVEC,
6074 bc_dmom_w_adv_u_ext[nSpace]=
ZEROVEC,
6075 bc_dmom_w_adv_v_ext[nSpace]=
ZEROVEC,
6076 bc_dmom_w_adv_w_ext[nSpace]=
ZEROVEC,
6077 bc_mom_uu_diff_ten_ext[nSpace]=
ZEROVEC,
6078 bc_mom_vv_diff_ten_ext[nSpace]=
ZEROVEC,
6079 bc_mom_ww_diff_ten_ext[nSpace]=
ZEROVEC,
6080 bc_mom_uv_diff_ten_ext[1],
6081 bc_mom_uw_diff_ten_ext[1],
6082 bc_mom_vu_diff_ten_ext[1],
6083 bc_mom_vw_diff_ten_ext[1],
6084 bc_mom_wu_diff_ten_ext[1],
6085 bc_mom_wv_diff_ten_ext[1],
6086 bc_mom_u_source_ext=0.0,
6087 bc_mom_v_source_ext=0.0,
6088 bc_mom_w_source_ext=0.0,
6089 bc_mom_u_ham_ext=0.0,
6090 bc_dmom_u_ham_grad_p_ext[nSpace]=
ZEROVEC,
6091 bc_dmom_u_ham_grad_u_ext[nSpace]=
ZEROVEC,
6092 bc_dmom_u_ham_u_ext=0.0,
6093 bc_dmom_u_ham_v_ext=0.0,
6094 bc_dmom_u_ham_w_ext=0.0,
6095 bc_mom_v_ham_ext=0.0,
6096 bc_dmom_v_ham_grad_p_ext[nSpace]=
ZEROVEC,
6097 bc_dmom_v_ham_grad_v_ext[nSpace]=
ZEROVEC,
6098 bc_dmom_v_ham_u_ext=0.0,
6099 bc_dmom_v_ham_v_ext=0.0,
6100 bc_dmom_v_ham_w_ext=0.0,
6101 bc_mom_w_ham_ext=0.0,
6102 bc_dmom_w_ham_grad_p_ext[nSpace]=
ZEROVEC,
6103 bc_dmom_w_ham_grad_w_ext[nSpace]=
ZEROVEC,
6104 bc_dmom_w_ham_u_ext=0.0,
6105 bc_dmom_w_ham_v_ext=0.0,
6106 bc_dmom_w_ham_w_ext=0.0,
6107 fluxJacobian_p_p[nDOF_trial_element],
6108 fluxJacobian_p_u[nDOF_v_trial_element],
6109 fluxJacobian_p_v[nDOF_v_trial_element],
6110 fluxJacobian_p_w[nDOF_v_trial_element],
6111 fluxJacobian_u_p[nDOF_trial_element],
6112 fluxJacobian_u_u[nDOF_v_trial_element],
6113 fluxJacobian_u_v[nDOF_v_trial_element],
6114 fluxJacobian_u_w[nDOF_v_trial_element],
6115 fluxJacobian_v_p[nDOF_trial_element],
6116 fluxJacobian_v_u[nDOF_v_trial_element],
6117 fluxJacobian_v_v[nDOF_v_trial_element],
6118 fluxJacobian_v_w[nDOF_v_trial_element],
6119 fluxJacobian_w_p[nDOF_trial_element],
6120 fluxJacobian_w_u[nDOF_v_trial_element],
6121 fluxJacobian_w_v[nDOF_v_trial_element],
6122 fluxJacobian_w_w[nDOF_v_trial_element],
6123 jac_ext[nSpace*nSpace],
6125 jacInv_ext[nSpace*nSpace],
6126 boundaryJac[nSpace*(nSpace-1)],
6127 metricTensor[(nSpace-1)*(nSpace-1)],
6128 metricTensorDetSqrt,
6129 p_grad_trial_trace[nDOF_trial_element*nSpace],
6130 vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
6132 p_test_dS[nDOF_test_element],
6133 vel_test_dS[nDOF_v_test_element],
6135 x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
6136 vel_grad_test_dS[nDOF_v_trial_element*nSpace],
6140 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty;
6141 gf_s.set_boundary_quad(kb);
6142 gf.set_boundary_quad(kb);
6143 ck.calculateMapping_elementBoundary(eN,
6149 mesh_trial_trace_ref.data(),
6150 mesh_grad_trial_trace_ref.data(),
6151 boundaryJac_ref.data(),
6157 metricTensorDetSqrt,
6161 ck.calculateMappingVelocity_elementBoundary(eN,
6165 mesh_velocity_dof.data(),
6167 mesh_trial_trace_ref.data(),
6168 xt_ext,yt_ext,zt_ext,
6174 dS = metricTensorDetSqrt*dS_ref.data()[kb];
6175 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
6176 ck.calculateGScale(G,&ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],h_phi);
6178 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
6179 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
6183 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,p_grad_trial_trace);
6184 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_ext,vel_grad_trial_trace);
6186 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],p_ext);
6187 ck_v.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],u_ext);
6188 ck_v.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],v_ext);
6189 ck.valFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],p_old);
6190 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],u_old);
6191 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],v_old);
6192 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_ext);
6193 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_ext);
6194 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_ext);
6195 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_old);
6196 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_old);
6197 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_old);
6198 ck.valFromDOF(phi_solid_nodes.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_trace_ref.data()[ebN_local_kb*nDOF_test_element],phi_s_ext);
6200 for (
int j=0;j<nDOF_test_element;j++)
6202 p_test_dS[j] = p_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
6205 for (
int j=0;j<nDOF_v_test_element;j++)
6207 vel_test_dS[j] = vel_test_trace_ref.data()[ebN_local_kb*nDOF_v_test_element+j]*dS;
6208 for (
int I=0;I<nSpace;I++)
6209 vel_grad_test_dS[j*nSpace+I] = vel_grad_trial_trace[j*nSpace+I]*dS;
6214 bc_p_ext = isDOFBoundary_p.data()[ebNE_kb]*ebqe_bc_p_ext.data()[ebNE_kb]+(1-isDOFBoundary_p.data()[ebNE_kb])*p_ext;
6216 bc_u_ext = isDOFBoundary_u.data()[ebNE_kb]*(ebqe_bc_u_ext.data()[ebNE_kb] + MOVING_DOMAIN*xt_ext) + (1-isDOFBoundary_u.data()[ebNE_kb])*u_ext;
6217 bc_v_ext = isDOFBoundary_v.data()[ebNE_kb]*(ebqe_bc_v_ext.data()[ebNE_kb] + MOVING_DOMAIN*yt_ext) + (1-isDOFBoundary_v.data()[ebNE_kb])*v_ext;
6219 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
6223 double eddy_viscosity_ext(0.),bc_eddy_viscosity_ext(0.);
6224 if (use_ball_as_particle == 1 && nParticles > 0)
6226 get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x_ext,y_ext,z_ext,ebqe_phi_s.data()[ebNE_kb]);
6229 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
6231 double H = (1.0-useVF)*
gf.H(eps_rho,ebqe_phi_ext.data()[ebNE_kb]) + useVF*fmin(1.0,fmax(0.0,ebqe_vf_ext.data()[ebNE_kb]));
6232 double ImH = (1.0-useVF)*
gf.ImH(eps_rho,ebqe_phi_ext.data()[ebNE_kb]) + useVF*(1.0-fmin(1.0,fmax(0.0,ebqe_vf_ext.data()[ebNE_kb])));
6240 elementDiameter.data()[eN],
6241 smagorinskyConstant,
6242 turbulenceClosureModel,
6245 ebqe_vf_ext.data()[ebNE_kb],
6246 ebqe_phi_ext.data()[ebNE_kb],
6247 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
6248 ebqe_kappa_phi_ext.data()[ebNE_kb],
6252 ebqe_phi_s.data()[ebNE_kb],
6271 ebqe_eddy_viscosity_last.data()[ebNE_kb],
6294 mom_uu_diff_ten_ext,
6295 mom_vv_diff_ten_ext,
6296 mom_ww_diff_ten_ext,
6297 mom_uv_diff_ten_ext,
6298 mom_uw_diff_ten_ext,
6299 mom_vu_diff_ten_ext,
6300 mom_vw_diff_ten_ext,
6301 mom_wu_diff_ten_ext,
6302 mom_wv_diff_ten_ext,
6307 dmom_u_ham_grad_p_ext,
6308 dmom_u_ham_grad_u_ext,
6313 dmom_v_ham_grad_p_ext,
6314 dmom_v_ham_grad_v_ext,
6319 dmom_w_ham_grad_p_ext,
6320 dmom_w_ham_grad_w_ext,
6328 H = (1.0-useVF)*
gf.H(eps_rho,bc_ebqe_phi_ext.data()[ebNE_kb]) + useVF*fmin(1.0,fmax(0.0,bc_ebqe_vf_ext.data()[ebNE_kb]));
6329 ImH = (1.0-useVF)*
gf.ImH(eps_rho,bc_ebqe_phi_ext.data()[ebNE_kb]) + useVF*(1.0-fmin(1.0,fmax(0.0,bc_ebqe_vf_ext.data()[ebNE_kb])));
6337 elementDiameter.data()[eN],
6338 smagorinskyConstant,
6339 turbulenceClosureModel,
6342 bc_ebqe_vf_ext.data()[ebNE_kb],
6343 bc_ebqe_phi_ext.data()[ebNE_kb],
6344 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
6345 ebqe_kappa_phi_ext.data()[ebNE_kb],
6349 ebqe_phi_s.data()[ebNE_kb],
6367 bc_eddy_viscosity_ext,
6368 ebqe_eddy_viscosity_last.data()[ebNE_kb],
6370 bc_dmom_u_acc_u_ext,
6372 bc_dmom_v_acc_v_ext,
6374 bc_dmom_w_acc_w_ext,
6380 bc_dmom_u_adv_u_ext,
6381 bc_dmom_u_adv_v_ext,
6382 bc_dmom_u_adv_w_ext,
6384 bc_dmom_v_adv_u_ext,
6385 bc_dmom_v_adv_v_ext,
6386 bc_dmom_v_adv_w_ext,
6388 bc_dmom_w_adv_u_ext,
6389 bc_dmom_w_adv_v_ext,
6390 bc_dmom_w_adv_w_ext,
6391 bc_mom_uu_diff_ten_ext,
6392 bc_mom_vv_diff_ten_ext,
6393 bc_mom_ww_diff_ten_ext,
6394 bc_mom_uv_diff_ten_ext,
6395 bc_mom_uw_diff_ten_ext,
6396 bc_mom_vu_diff_ten_ext,
6397 bc_mom_vw_diff_ten_ext,
6398 bc_mom_wu_diff_ten_ext,
6399 bc_mom_wv_diff_ten_ext,
6400 bc_mom_u_source_ext,
6401 bc_mom_v_source_ext,
6402 bc_mom_w_source_ext,
6404 bc_dmom_u_ham_grad_p_ext,
6405 bc_dmom_u_ham_grad_u_ext,
6406 bc_dmom_u_ham_u_ext,
6407 bc_dmom_u_ham_v_ext,
6408 bc_dmom_u_ham_w_ext,
6410 bc_dmom_v_ham_grad_p_ext,
6411 bc_dmom_v_ham_grad_v_ext,
6412 bc_dmom_v_ham_u_ext,
6413 bc_dmom_v_ham_v_ext,
6414 bc_dmom_v_ham_w_ext,
6416 bc_dmom_w_ham_grad_p_ext,
6417 bc_dmom_w_ham_grad_w_ext,
6418 bc_dmom_w_ham_u_ext,
6419 bc_dmom_w_ham_v_ext,
6420 bc_dmom_w_ham_w_ext,
6425 if (turbulenceClosureModel >= 3)
6427 const double turb_var_grad_0_dummy[nSpace] =
ZEROVEC;
6428 const double c_mu = 0.09;
6430 turbulenceClosureModel,
6438 ebqe_vf_ext.data()[ebNE_kb],
6439 ebqe_phi_ext.data()[ebNE_kb],
6442 ebqe_turb_var_0.data()[ebNE_kb],
6443 ebqe_turb_var_1.data()[ebNE_kb],
6444 turb_var_grad_0_dummy,
6446 mom_uu_diff_ten_ext,
6447 mom_vv_diff_ten_ext,
6448 mom_ww_diff_ten_ext,
6449 mom_uv_diff_ten_ext,
6450 mom_uw_diff_ten_ext,
6451 mom_vu_diff_ten_ext,
6452 mom_vw_diff_ten_ext,
6453 mom_wu_diff_ten_ext,
6454 mom_wv_diff_ten_ext,
6460 turbulenceClosureModel,
6468 ebqe_vf_ext.data()[ebNE_kb],
6469 ebqe_phi_ext.data()[ebNE_kb],
6472 ebqe_turb_var_0.data()[ebNE_kb],
6473 ebqe_turb_var_1.data()[ebNE_kb],
6474 turb_var_grad_0_dummy,
6475 bc_eddy_viscosity_ext,
6476 bc_mom_uu_diff_ten_ext,
6477 bc_mom_vv_diff_ten_ext,
6478 bc_mom_ww_diff_ten_ext,
6479 bc_mom_uv_diff_ten_ext,
6480 bc_mom_uw_diff_ten_ext,
6481 bc_mom_vu_diff_ten_ext,
6482 bc_mom_vw_diff_ten_ext,
6483 bc_mom_wu_diff_ten_ext,
6484 bc_mom_wv_diff_ten_ext,
6485 bc_mom_u_source_ext,
6486 bc_mom_v_source_ext,
6487 bc_mom_w_source_ext);
6492 if (NONCONSERVATIVE_FORM > 0.0)
6494 mom_u_ham_ext -= MOVING_DOMAIN*dmom_u_acc_u_ext*(grad_u_ext[0]*xt_ext +
6495 grad_u_ext[1]*yt_ext);
6496 dmom_u_ham_grad_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
6497 dmom_u_ham_grad_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
6501 mom_u_adv_ext[0] -= MOVING_DOMAIN*mom_u_acc_ext*xt_ext;
6502 mom_u_adv_ext[1] -= MOVING_DOMAIN*mom_u_acc_ext*yt_ext;
6503 dmom_u_adv_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
6504 dmom_u_adv_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
6507 if (NONCONSERVATIVE_FORM > 0.0)
6509 mom_v_ham_ext -= MOVING_DOMAIN*dmom_v_acc_v_ext*(grad_v_ext[0]*xt_ext +
6510 grad_v_ext[1]*yt_ext);
6511 dmom_v_ham_grad_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
6512 dmom_v_ham_grad_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
6516 mom_v_adv_ext[0] -= MOVING_DOMAIN*mom_v_acc_ext*xt_ext;
6517 mom_v_adv_ext[1] -= MOVING_DOMAIN*mom_v_acc_ext*yt_ext;
6518 dmom_v_adv_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
6519 dmom_v_adv_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
6523 if (NONCONSERVATIVE_FORM < 1.0)
6525 bc_mom_u_adv_ext[0] -= MOVING_DOMAIN*bc_mom_u_acc_ext*xt_ext;
6526 bc_mom_u_adv_ext[1] -= MOVING_DOMAIN*bc_mom_u_acc_ext*yt_ext;
6528 bc_mom_v_adv_ext[0] -= MOVING_DOMAIN*bc_mom_v_acc_ext*xt_ext;
6529 bc_mom_v_adv_ext[1] -= MOVING_DOMAIN*bc_mom_v_acc_ext*yt_ext;
6535 isDOFBoundary_p.data()[ebNE_kb],
6536 isDOFBoundary_u.data()[ebNE_kb],
6537 isDOFBoundary_v.data()[ebNE_kb],
6538 isDOFBoundary_w.data()[ebNE_kb],
6539 isAdvectiveFluxBoundary_p.data()[ebNE_kb],
6540 isAdvectiveFluxBoundary_u.data()[ebNE_kb],
6541 isAdvectiveFluxBoundary_v.data()[ebNE_kb],
6542 isAdvectiveFluxBoundary_w.data()[ebNE_kb],
6543 dmom_u_ham_grad_p_ext[0],
6552 ebqe_bc_flux_mass_ext.data()[ebNE_kb]+MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]),
6553 ebqe_bc_flux_mom_u_adv_ext.data()[ebNE_kb],
6554 ebqe_bc_flux_mom_v_adv_ext.data()[ebNE_kb],
6555 ebqe_bc_flux_mom_w_adv_ext.data()[ebNE_kb],
6568 dmom_u_ham_grad_u_ext,
6583 dflux_mom_u_adv_p_ext,
6584 dflux_mom_u_adv_u_ext,
6585 dflux_mom_u_adv_v_ext,
6586 dflux_mom_u_adv_w_ext,
6587 dflux_mom_v_adv_p_ext,
6588 dflux_mom_v_adv_u_ext,
6589 dflux_mom_v_adv_v_ext,
6590 dflux_mom_v_adv_w_ext,
6591 dflux_mom_w_adv_p_ext,
6592 dflux_mom_w_adv_u_ext,
6593 dflux_mom_w_adv_v_ext,
6594 dflux_mom_w_adv_w_ext);
6598 ck.calculateGScale(G,normal,h_penalty);
6599 penalty = useMetrics*C_b/h_penalty + (1.0-useMetrics)*ebqe_penalty_ext.data()[ebNE_kb];
6600 if (isActiveElement[eN])
6603 for (
int j=0;j<nDOF_trial_element;j++)
6605 register int j_nSpace = j*nSpace,ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
6606 fluxJacobian_p_p[j]=0.0;
6607 fluxJacobian_u_p[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_p_ext,p_trial_trace_ref.data()[ebN_local_kb_j]);
6608 fluxJacobian_v_p[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_p_ext,p_trial_trace_ref.data()[ebN_local_kb_j]);
6610 for (
int j=0;j<nDOF_v_trial_element;j++)
6612 register int j_nSpace = j*nSpace,ebN_local_kb_j=ebN_local_kb*nDOF_v_trial_element+j;
6613 fluxJacobian_p_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mass_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]);
6614 fluxJacobian_p_v[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mass_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]);
6615 fluxJacobian_u_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
6617 ebqe_phi_ext.data()[ebNE_kb],
6618 sdInfo_u_u_rowptr.data(),
6619 sdInfo_u_u_colind.data(),
6620 isDOFBoundary_u.data()[ebNE_kb],
6621 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
6623 mom_uu_diff_ten_ext,
6624 vel_trial_trace_ref.data()[ebN_local_kb_j],
6625 &vel_grad_trial_trace[j_nSpace],
6627 fluxJacobian_u_v[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
6629 ebqe_phi_ext.data()[ebNE_kb],
6630 sdInfo_u_v_rowptr.data(),
6631 sdInfo_u_v_colind.data(),
6632 isDOFBoundary_v.data()[ebNE_kb],
6633 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
6635 mom_uv_diff_ten_ext,
6636 vel_trial_trace_ref.data()[ebN_local_kb_j],
6637 &vel_grad_trial_trace[j_nSpace],
6640 fluxJacobian_v_u[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
6642 ebqe_phi_ext.data()[ebNE_kb],
6643 sdInfo_v_u_rowptr.data(),
6644 sdInfo_v_u_colind.data(),
6645 isDOFBoundary_u.data()[ebNE_kb],
6646 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
6648 mom_vu_diff_ten_ext,
6649 vel_trial_trace_ref.data()[ebN_local_kb_j],
6650 &vel_grad_trial_trace[j_nSpace],
6652 fluxJacobian_v_v[j]=
ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
6654 ebqe_phi_ext.data()[ebNE_kb],
6655 sdInfo_v_v_rowptr.data(),
6656 sdInfo_v_v_colind.data(),
6657 isDOFBoundary_v.data()[ebNE_kb],
6658 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
6660 mom_vv_diff_ten_ext,
6661 vel_trial_trace_ref.data()[ebN_local_kb_j],
6662 &vel_grad_trial_trace[j_nSpace],
6669 const double H_s =
gf_s.H(particle_eps, ebqe_phi_s[ebNE_kb]);
6670 if (isActiveElement[eN])
6672 for (
int i=0;i<nDOF_test_element;i++)
6674 register int eN_i = eN*nDOF_test_element+i;
6675 for (
int j=0;j<nDOF_trial_element;j++)
6677 register int eN_j = eN*nDOF_trial_element+j;
6678 register int ebN_i_j = ebN*4*
nDOF_test_X_trial_element + i*nDOF_trial_element + j,ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
6680 globalJacobian.data()[csrRowIndeces_p_p[eN_i] + csrColumnOffsets_eb_p_p.data()[ebN_i_j]] += H_s*fluxJacobian_p_p[j]*p_test_dS[i];
6683 for (
int i=0;i<nDOF_test_element;i++)
6685 register int eN_i = eN*nDOF_test_element+i;
6686 for (
int j=0;j<nDOF_v_trial_element;j++)
6688 register int eN_j = eN*nDOF_v_trial_element+j;
6689 register int ebN_i_j = ebN*4*
nDOF_test_X_v_trial_element + i*nDOF_v_trial_element + j,ebN_local_kb_j=ebN_local_kb*nDOF_v_trial_element+j;
6690 globalJacobian.data()[csrRowIndeces_p_u.data()[eN_i] + csrColumnOffsets_eb_p_u.data()[ebN_i_j]] += H_s*fluxJacobian_p_u[j]*p_test_dS[i];
6691 globalJacobian.data()[csrRowIndeces_p_v.data()[eN_i] + csrColumnOffsets_eb_p_v.data()[ebN_i_j]] += H_s*fluxJacobian_p_v[j]*p_test_dS[i];
6694 for (
int i=0;i<nDOF_v_test_element;i++)
6696 register int eN_i = eN*nDOF_v_test_element+i;
6697 for (
int j=0;j<nDOF_trial_element;j++)
6699 register int ebN_i_j = ebN*4*
nDOF_v_test_X_trial_element + i*nDOF_trial_element + j,ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
6700 globalJacobian.data()[csrRowIndeces_u_p.data()[eN_i] + csrColumnOffsets_eb_u_p.data()[ebN_i_j]] += H_s*fluxJacobian_u_p[j]*vel_test_dS[i];
6701 globalJacobian.data()[csrRowIndeces_v_p.data()[eN_i] + csrColumnOffsets_eb_v_p.data()[ebN_i_j]] += H_s*fluxJacobian_v_p[j]*vel_test_dS[i];
6704 for (
int i=0;i<nDOF_v_test_element;i++)
6706 register int eN_i = eN*nDOF_v_test_element+i;
6707 for (
int j=0;j<nDOF_v_trial_element;j++)
6709 register int eN_j = eN*nDOF_v_trial_element+j;
6711 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]] +=
6712 H_s*(fluxJacobian_u_u[j]*vel_test_dS[i]+
6713 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_u.data()[ebNE_kb],
6714 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
6716 vel_trial_trace_ref.data()[ebN_local_kb_j],
6718 sdInfo_u_u_rowptr.data(),
6719 sdInfo_u_u_colind.data(),
6720 mom_uu_diff_ten_ext,
6721 &vel_grad_test_dS[i*nSpace]));
6722 globalJacobian.data()[csrRowIndeces_u_v.data()[eN_i] + csrColumnOffsets_eb_u_v.data()[ebN_i_j]] +=
6723 H_s*(fluxJacobian_u_v[j]*vel_test_dS[i]+
6724 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_v.data()[ebNE_kb],
6725 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
6727 vel_trial_trace_ref.data()[ebN_local_kb_j],
6729 sdInfo_u_v_rowptr.data(),
6730 sdInfo_u_v_colind.data(),
6731 mom_uv_diff_ten_ext,
6732 &vel_grad_test_dS[i*nSpace]));
6733 globalJacobian.data()[csrRowIndeces_v_u.data()[eN_i] + csrColumnOffsets_eb_v_u.data()[ebN_i_j]] +=
6734 H_s*(fluxJacobian_v_u[j]*vel_test_dS[i]+
6735 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_u.data()[ebNE_kb],
6736 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
6738 vel_trial_trace_ref.data()[ebN_local_kb_j],
6740 sdInfo_v_u_rowptr.data(),
6741 sdInfo_v_u_colind.data(),
6742 mom_vu_diff_ten_ext,
6743 &vel_grad_test_dS[i*nSpace]));
6744 globalJacobian.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j]] +=
6745 H_s*(fluxJacobian_v_v[j]*vel_test_dS[i]+
6746 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_v.data()[ebNE_kb],
6747 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
6749 vel_trial_trace_ref.data()[ebN_local_kb_j],
6751 sdInfo_v_v_rowptr.data(),
6752 sdInfo_v_v_colind.data(),
6753 mom_vv_diff_ten_ext,
6754 &vel_grad_test_dS[i*nSpace]));
6764 int nExteriorElementBoundaries_global = args.
scalar<
int>(
"nExteriorElementBoundaries_global");
6765 xt::pyarray<int>& exteriorElementBoundariesArray = args.
array<
int>(
"exteriorElementBoundariesArray");
6766 int nInteriorElementBoundaries_global = args.
scalar<
int>(
"nInteriorElementBoundaries_global");
6767 xt::pyarray<int>& interiorElementBoundariesArray = args.
array<
int>(
"interiorElementBoundariesArray");
6768 xt::pyarray<int>& elementBoundaryElementsArray = args.
array<
int>(
"elementBoundaryElementsArray");
6769 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.
array<
int>(
"elementBoundaryLocalElementBoundariesArray");
6770 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
6771 xt::pyarray<double>& mesh_velocity_dof = args.
array<
double>(
"mesh_velocity_dof");
6772 double MOVING_DOMAIN = args.
scalar<
double>(
"MOVING_DOMAIN");
6773 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
6774 xt::pyarray<double>& mesh_trial_trace_ref = args.
array<
double>(
"mesh_trial_trace_ref");
6775 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.
array<
double>(
"mesh_grad_trial_trace_ref");
6776 xt::pyarray<double>& normal_ref = args.
array<
double>(
"normal_ref");
6777 xt::pyarray<double>& boundaryJac_ref = args.
array<
double>(
"boundaryJac_ref");
6778 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
6779 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
6780 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
6781 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
6782 xt::pyarray<double>& vel_trial_trace_ref = args.
array<
double>(
"vel_trial_trace_ref");
6783 xt::pyarray<double>& ebqe_velocity = args.
array<
double>(
"ebqe_velocity");
6784 xt::pyarray<double>& velocityAverage = args.
array<
double>(
"velocityAverage");
6785 xt::pyarray<int>& elementMaterialTypes = args.
array<
int>(
"elementMaterialTypes");
6786 xt::pyarray<double>& porosityTypes = args.
array<
double>(
"porosityTypes");
6787 int permutations[nQuadraturePoints_elementBoundary];
6788 double xArray_left[nQuadraturePoints_elementBoundary*nSpace],
6789 xArray_right[nQuadraturePoints_elementBoundary*nSpace];
6790 for (
int i=0;i<nQuadraturePoints_elementBoundary;i++)
6792 for (
int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
6794 register int ebN = exteriorElementBoundariesArray.data()[ebNE];
6795 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6797 register int ebN_kb_nSpace = ebN*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace,
6798 ebNE_kb_nSpace = ebNE*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace;
6799 velocityAverage.data()[ebN_kb_nSpace+0]=ebqe_velocity.data()[ebNE_kb_nSpace+0];
6800 velocityAverage.data()[ebN_kb_nSpace+1]=ebqe_velocity.data()[ebNE_kb_nSpace+1];
6803 for (
int ebNI = 0; ebNI < nInteriorElementBoundaries_global; ebNI++)
6805 register int ebN = interiorElementBoundariesArray.data()[ebNI],
6806 left_eN_global = elementBoundaryElementsArray.data()[ebN*2+0],
6807 left_ebN_element = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
6808 right_eN_global = elementBoundaryElementsArray.data()[ebN*2+1],
6809 right_ebN_element = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+1],
6810 left_eN_nDOF_trial_element = left_eN_global*nDOF_trial_element,
6811 right_eN_nDOF_trial_element = right_eN_global*nDOF_trial_element;
6812 double jac[nSpace*nSpace],
6814 jacInv[nSpace*nSpace],
6815 boundaryJac[nSpace*(nSpace-1)],
6816 metricTensor[(nSpace-1)*(nSpace-1)],
6817 metricTensorDetSqrt,
6820 xt,yt,zt,integralScaling,
6821 left_porosity = porosityTypes[elementMaterialTypes[left_eN_global]],
6822 right_porosity = porosityTypes[elementMaterialTypes[right_eN_global]];
6824 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6826 ck.calculateMapping_elementBoundary(left_eN_global,
6829 left_ebN_element*nQuadraturePoints_elementBoundary+kb,
6832 mesh_trial_trace_ref.data(),
6833 mesh_grad_trial_trace_ref.data(),
6834 boundaryJac_ref.data(),
6840 metricTensorDetSqrt,
6844 xArray_left[kb*nSpace+0] = x;
6845 xArray_left[kb*nSpace+1] = y;
6846 ck.calculateMapping_elementBoundary(right_eN_global,
6849 right_ebN_element*nQuadraturePoints_elementBoundary+kb,
6852 mesh_trial_trace_ref.data(),
6853 mesh_grad_trial_trace_ref.data(),
6854 boundaryJac_ref.data(),
6860 metricTensorDetSqrt,
6864 ck.calculateMappingVelocity_elementBoundary(left_eN_global,
6867 left_ebN_element*nQuadraturePoints_elementBoundary+kb,
6868 mesh_velocity_dof.data(),
6870 mesh_trial_trace_ref.data(),
6876 xArray_right[kb*nSpace+0] = x;
6877 xArray_right[kb*nSpace+1] = y;
6879 for (
int kb_left=0;kb_left<nQuadraturePoints_elementBoundary;kb_left++)
6881 double errorNormMin = 1.0;
6882 for (
int kb_right=0;kb_right<nQuadraturePoints_elementBoundary;kb_right++)
6884 double errorNorm=0.0;
6885 for (
int I=0;I<nSpace;I++)
6887 errorNorm += fabs(xArray_left[kb_left*nSpace+I]
6889 xArray_right[kb_right*nSpace+I]);
6891 if (errorNorm < errorNormMin)
6893 permutations[kb_right] = kb_left;
6894 errorNormMin = errorNorm;
6898 for (
int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6900 register int ebN_kb_nSpace = ebN*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace;
6901 register double u_left=0.0,
6907 register int left_kb = kb,
6908 right_kb = permutations[kb],
6909 left_ebN_element_kb_nDOF_test_element=(left_ebN_element*nQuadraturePoints_elementBoundary+left_kb)*nDOF_test_element,
6910 right_ebN_element_kb_nDOF_test_element=(right_ebN_element*nQuadraturePoints_elementBoundary+right_kb)*nDOF_test_element;
6914 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[left_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[left_ebN_element_kb_nDOF_test_element],u_left);
6915 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[left_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[left_ebN_element_kb_nDOF_test_element],v_left);
6917 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[right_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[right_ebN_element_kb_nDOF_test_element],u_right);
6918 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[right_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[right_ebN_element_kb_nDOF_test_element],v_right);
6920 velocityAverage.data()[ebN_kb_nSpace+0]=0.5*(left_porosity*u_left + right_porosity*u_right);
6921 velocityAverage.data()[ebN_kb_nSpace+1]=0.5*(left_porosity*v_left + right_porosity*v_right);
6935 double dmass_adv_p[nSpace],
6936 double dmom_u_adv_u[nSpace],
6937 double dmom_v_adv_v[nSpace])
6939 double H_rho, ImH_rho, rho;
6941 H_rho = (1.0-useVF)*
gf.H(eps_rho,
phi) + useVF*fmin(1.0,fmax(0.0,vf));
6942 ImH_rho = (1.0-useVF)*
gf.ImH(eps_rho,
phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
6946 dmass_adv_p[0] = rho*
u;
6947 dmass_adv_p[1] = rho*
v;
6949 dmom_u_adv_u[0] = rho*
u;
6950 dmom_u_adv_u[1] = rho*
v;
6952 dmom_v_adv_v[0] = rho*
u;
6953 dmom_v_adv_v[1] = rho*
v;
6957 const double numerical_viscosity,
6958 const double eps_rho,
6959 const double eps_mu,
6971 double& dmom_p_acc_p,
6973 double& dmom_u_acc_u,
6975 double& dmom_v_acc_v)
6978 double H_rho, ImH_rho, H_mu, ImH_mu, rho, nu, mu;
6980 H_rho = (1.0-useVF)*
gf.H(eps_rho,
phi) + useVF*fmin(1.0,fmax(0.0,vf));
6981 ImH_rho = (1.0-useVF)*
gf.ImH(eps_rho,
phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
6982 H_mu = (1.0-useVF)*
gf.H(eps_mu,
phi) + useVF*fmin(1.0,fmax(0.0,vf));
6983 ImH_mu = (1.0-useVF)*
gf.ImH(eps_mu,
phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
6988 mu =
rho_0*
nu_0*ImH_mu +
rho_1*
nu_1*H_mu + use_numerical_viscosity*numerical_viscosity;
6992 dmom_p_acc_p = 1. / mu;
6995 dmom_u_acc_u = 1. / mu;
6998 dmom_v_acc_v = 1. / mu;
7011 double& dmom_p_acc_p,
7013 double& dmom_u_acc_u,
7015 double& dmom_v_acc_v)
7017 double H_rho, ImH_rho, rho;
7019 H_rho = (1.0-useVF)*
gf.H(eps_rho,
phi) + useVF*fmin(1.0,fmax(0.0,vf));
7020 ImH_rho = (1.0-useVF)*
gf.ImH(eps_rho,
phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
7024 mom_p_acc = p * rho;
7027 mom_u_acc =
u * rho;
7030 mom_v_acc =
v * rho;
7040 double mom_p_diff_ten[nSpace],
7041 double mom_u_diff_ten[nSpace],
7042 double mom_v_diff_ten[nSpace])
7044 double H_rho, ImH_rho, rho;
7046 H_rho = (1.0-useVF)*
gf.H(eps_rho,
phi) + useVF*fmin(1.0,fmax(0.0,vf));
7047 ImH_rho = (1.0-useVF)*
gf.ImH(eps_rho,
phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
7051 mom_p_diff_ten[0] = 1.0 / rho ;
7052 mom_p_diff_ten[1] = 1.0 / rho ;
7054 mom_u_diff_ten[0] = 1.0 / rho ;
7055 mom_u_diff_ten[1] = 1.0 / rho ;
7057 mom_v_diff_ten[0] = 1.0 / rho ;
7058 mom_v_diff_ten[1] = 1.0 / rho ;
7064 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
7065 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
7066 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
7067 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
7068 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
7069 xt::pyarray<double>& p_trial_ref = args.
array<
double>(
"p_trial_ref");
7070 xt::pyarray<double>& p_grad_trial_ref = args.
array<
double>(
"p_grad_trial_ref");
7071 xt::pyarray<double>& vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
7072 xt::pyarray<double>& vel_grad_trial_ref = args.
array<
double>(
"vel_grad_trial_ref");
7073 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
7074 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
7075 int nElements_global = args.
scalar<
int>(
"nElements_global");
7076 double useMetrics = args.
scalar<
double>(
"useMetrics");
7077 double epsFact_rho = args.
scalar<
double>(
"epsFact_rho");
7078 double epsFact_mu = args.
scalar<
double>(
"epsFact_mu");
7083 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
7084 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
7085 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
7086 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
7087 const double useVF = args.
scalar<
double>(
"useVF");
7088 xt::pyarray<double> &vf = args.
array<
double>(
"&vf");
7089 xt::pyarray<double> &
phi = args.
array<
double>(
"&phi");
7090 xt::pyarray<int>& csrRowIndeces_p_p = args.
array<
int>(
"csrRowIndeces_p_p");
7091 xt::pyarray<int>& csrColumnOffsets_p_p = args.
array<
int>(
"csrColumnOffsets_p_p");
7092 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
7093 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
7094 xt::pyarray<int>& csrRowIndeces_v_v = args.
array<
int>(
"csrRowIndeces_v_v");
7095 xt::pyarray<int>& csrColumnOffsets_v_v = args.
array<
int>(
"csrColumnOffsets_v_v");
7096 xt::pyarray<int>& csrRowIndeces_w_w = args.
array<
int>(
"csrRowIndeces_w_w");
7097 xt::pyarray<int>& csrColumnOffsets_w_w = args.
array<
int>(
"csrColumnOffsets_w_w");
7098 xt::pyarray<double>& advection_matrix = args.
array<
double>(
"advection_matrix");
7099 gf.useExact =
false;
7100 for (
int eN=0 ; eN < nElements_global ; ++eN)
7105 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
7106 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
7107 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
7110 for (
int i=0 ; i < nDOF_test_element ; ++i)
7111 for (
int j=0 ; j < nDOF_trial_element ; ++j){
7112 local_matrix_p_p[i][j] = 0. ;
7113 local_matrix_u_u[i][j] = 0. ;
7114 local_matrix_v_v[i][j] = 0. ;
7117 for (
int k=0 ; k < nQuadraturePoints_element ; ++k){
7119 int eN_k = eN*nQuadraturePoints_element + k;
7120 int eN_nDOF_trial_element = eN*nDOF_trial_element;
7122 double jac[nSpace*nSpace];
7123 double jacInv[nSpace*nSpace];
7124 double u=0.0,
v=0.0;
7125 double dmass_adv_p[nSpace], dmom_u_adv_u[nSpace], dmom_v_adv_v[nSpace];
7126 double p_grad_trial[nDOF_trial_element*nSpace],
7127 vel_grad_trial[nDOF_trial_element*nSpace];
7128 double p_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element];
7129 double p_grad_test_dV[nDOF_test_element*nSpace],
7130 vel_grad_test_dV[nDOF_test_element*nSpace];
7131 double jacDet, x, y,
z, dV, h_phi;
7133 ck.calculateMapping_element(eN,
7137 mesh_trial_ref.data(),
7138 mesh_grad_trial_ref.data(),
7144 ck.calculateH_element(eN,
7146 nodeDiametersArray.data(),
7148 mesh_trial_ref.data(),
7151 dV = fabs(jacDet)*dV_ref.data()[k];
7153 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7155 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
7156 ck.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,vel_grad_trial);
7158 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],
u);
7159 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],
v);
7161 for (
int j=0; j<nDOF_trial_element;++j)
7163 p_test_dV[j] = p_trial_ref.data()[k*nDOF_trial_element+j]*dV;
7164 vel_test_dV[j] = vel_trial_ref.data()[k*nDOF_trial_element+j]*dV;
7165 for (
int i=0; i<nSpace; ++i)
7167 p_grad_test_dV[j*nSpace+i] = p_grad_trial[j*nSpace+i]*dV;
7168 vel_grad_test_dV[j*nSpace+i] = vel_grad_trial[j*nSpace+i]*dV;
7186 for(
int i=0; i<nDOF_test_element;++i){
7187 int i_nSpace = i*nSpace;
7189 for(
int j=0; j<nDOF_trial_element;++j){
7191 int j_nSpace = j*nSpace;
7193 local_matrix_p_p[i][j] -=
ck.HamiltonianJacobian_weak(dmass_adv_p,&p_grad_test_dV[i_nSpace],p_trial_ref.data()[j]);
7195 local_matrix_u_u[i][j] +=
ck.HamiltonianJacobian_weak(dmom_u_adv_u,&vel_grad_trial[j_nSpace],vel_test_dV[i]);
7196 local_matrix_v_v[i][j] +=
ck.HamiltonianJacobian_weak(dmom_v_adv_v,&vel_grad_trial[j_nSpace],vel_test_dV[i]);
7204 for (
int i=0 ; i < nDOF_test_element ; ++i)
7206 int eN_i = eN*nDOF_test_element + i;
7207 for (
int j=0 ; j < nDOF_trial_element ; ++j)
7209 int eN_i_j = eN_i*nDOF_trial_element + j;
7210 advection_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
7211 advection_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
7212 advection_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
7221 xt::pyarray<double>& mesh_trial_ref = args.
array<
double>(
"mesh_trial_ref");
7222 xt::pyarray<double>& mesh_grad_trial_ref = args.
array<
double>(
"mesh_grad_trial_ref");
7223 xt::pyarray<double>& mesh_dof = args.
array<
double>(
"mesh_dof");
7224 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
7225 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
7226 xt::pyarray<double>& p_grad_trial_ref = args.
array<
double>(
"p_grad_trial_ref");
7227 xt::pyarray<double>& vel_grad_trial_ref = args.
array<
double>(
"vel_grad_trial_ref");
7228 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
7229 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
7230 int nElements_global = args.
scalar<
int>(
"nElements_global");
7231 double useMetrics = args.
scalar<
double>(
"useMetrics");
7232 double epsFact_rho = args.
scalar<
double>(
"epsFact_rho");
7233 double epsFact_mu = args.
scalar<
double>(
"epsFact_mu");
7238 xt::pyarray<int>& p_l2g = args.
array<
int>(
"p_l2g");
7239 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
7240 xt::pyarray<double>& p_dof = args.
array<
double>(
"p_dof");
7241 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
7242 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
7243 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
7244 const double useVF = args.
scalar<
double>(
"useVF");
7245 xt::pyarray<double>& vf = args.
array<
double>(
"vf");
7246 xt::pyarray<double>&
phi = args.
array<
double>(
"phi");
7247 xt::pyarray<int>& sdInfo_p_p_rowptr = args.
array<
int>(
"sdInfo_p_p_rowptr");
7248 xt::pyarray<int>& sdInfo_p_p_colind = args.
array<
int>(
"sdInfo_p_p_colind");
7249 xt::pyarray<int>& sdInfo_u_u_rowptr = args.
array<
int>(
"sdInfo_u_u_rowptr");
7250 xt::pyarray<int>& sdInfo_u_u_colind = args.
array<
int>(
"sdInfo_u_u_colind");
7251 xt::pyarray<int>& sdInfo_v_v_rowptr = args.
array<
int>(
"sdInfo_v_v_rowptr");
7252 xt::pyarray<int>& sdInfo_v_v_colind = args.
array<
int>(
"sdInfo_v_v_colind");
7253 xt::pyarray<int>& sdInfo_w_w_rowptr = args.
array<
int>(
"sdInfo_w_w_rowptr");
7254 xt::pyarray<int>& sdInfo_w_w_colind = args.
array<
int>(
"sdInfo_w_w_colind");
7255 xt::pyarray<int>& csrRowIndeces_p_p = args.
array<
int>(
"csrRowIndeces_p_p");
7256 xt::pyarray<int>& csrColumnOffsets_p_p = args.
array<
int>(
"csrColumnOffsets_p_p");
7257 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
7258 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
7259 xt::pyarray<int>& csrRowIndeces_v_v = args.
array<
int>(
"csrRowIndeces_v_v");
7260 xt::pyarray<int>& csrColumnOffsets_v_v = args.
array<
int>(
"csrColumnOffsets_v_v");
7261 xt::pyarray<int>& csrRowIndeces_w_w = args.
array<
int>(
"csrRowIndeces_w_w");
7262 xt::pyarray<int>& csrColumnOffsets_w_w = args.
array<
int>(
"csrColumnOffsets_w_w");
7263 xt::pyarray<double>& laplace_matrix = args.
array<
double>(
"laplace_matrix");
7264 gf.useExact =
false;
7265 for (
int eN=0 ; eN < nElements_global ; ++eN)
7268 double eps_rho, eps_mu;
7270 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
7271 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
7272 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
7275 for (
int i=0 ; i < nDOF_test_element ; ++i)
7276 for (
int j=0 ; j < nDOF_trial_element ; ++j){
7278 local_matrix_p_p[i][j] = 0.;
7279 local_matrix_u_u[i][j] = 0.;
7280 local_matrix_v_v[i][j] = 0.;
7284 for (
int k=0 ; k < nQuadraturePoints_element; ++k){
7286 int eN_k = eN*nQuadraturePoints_element + k;
7287 int eN_nDOF_trial_element = eN*nDOF_trial_element;
7289 double grad_p[nSpace], grad_u[nSpace], grad_v[nSpace];
7290 double jac[nSpace*nSpace];
7291 double jacInv[nSpace*nSpace];
7292 double mom_pp_diff_ten[nSpace];
7293 double mom_uu_diff_ten[nSpace];
7294 double mom_vv_diff_ten[nSpace];
7295 double p_grad_trial[nDOF_trial_element*nSpace],
7296 vel_grad_trial[nDOF_trial_element*nSpace];
7297 double p_grad_test_dV[nDOF_test_element*nSpace],
7298 vel_grad_test_dV[nDOF_test_element*nSpace];
7299 double jacDet, x, y,
z, dV, h_phi;
7301 ck.calculateMapping_element(eN,
7305 mesh_trial_ref.data(),
7306 mesh_grad_trial_ref.data(),
7312 ck.calculateH_element(eN,
7314 nodeDiametersArray.data(),
7316 mesh_trial_ref.data(),
7319 dV = fabs(jacDet)*dV_ref.data()[k];
7321 eps_mu = epsFact_mu * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7322 eps_rho = epsFact_rho * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7324 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
7325 ck.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,vel_grad_trial);
7327 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial,grad_p);
7328 ck.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],vel_grad_trial,grad_u);
7329 ck.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],vel_grad_trial,grad_v);
7331 for (
int j=0; j<nDOF_trial_element;++j)
7332 for (
int i=0; i<nSpace; ++i)
7334 p_grad_test_dV[j*nSpace+i] = p_grad_trial[j*nSpace+i]*dV;
7335 vel_grad_test_dV[j*nSpace+i] = vel_grad_trial[j*nSpace+i]*dV;
7349 for (
int i=0 ; i < nDOF_test_element ; ++i)
7351 int i_nSpace = i*nSpace ;
7352 for (
int j=0; j < nDOF_trial_element ; ++j){
7353 int j_nSpace = j*nSpace ;
7371 local_matrix_p_p[i][j] +=
ck.NumericalDiffusionJacobian(mom_pp_diff_ten[0],
7372 &p_grad_trial[j_nSpace],
7373 &p_grad_test_dV[i_nSpace]);
7375 local_matrix_u_u[i][j] +=
ck.NumericalDiffusionJacobian(mom_uu_diff_ten[0],
7376 &vel_grad_trial[j_nSpace],
7377 &vel_grad_test_dV[i_nSpace]);
7379 local_matrix_v_v[i][j] +=
ck.NumericalDiffusionJacobian(mom_vv_diff_ten[0],
7380 &vel_grad_trial[j_nSpace],
7381 &vel_grad_test_dV[i_nSpace]);
7389 for (
int i=0 ; i < nDOF_test_element ; ++i)
7391 int eN_i = eN*nDOF_test_element + i;
7392 for (
int j=0 ; j < nDOF_trial_element ; ++j)
7394 int eN_i_j = eN_i*nDOF_trial_element + j;
7395 laplace_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
7396 laplace_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
7397 laplace_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
7406 int scale_type = args.
scalar<
int>(
"scale_type");
7407 int use_numerical_viscosity = args.
scalar<
int>(
"use_numerical_viscosity");
7408 int lumped = args.
scalar<
int>(
"lumped");
7409 xt::pyarray<double> &mesh_trial_ref = args.
array<
double>(
"&mesh_trial_ref");
7410 xt::pyarray<double> &mesh_grad_trial_ref = args.
array<
double>(
"&mesh_grad_trial_ref");
7411 xt::pyarray<double> &mesh_dof = args.
array<
double>(
"&mesh_dof");
7412 xt::pyarray<int>& mesh_l2g = args.
array<
int>(
"mesh_l2g");
7413 xt::pyarray<double>& dV_ref = args.
array<
double>(
"dV_ref");
7414 xt::pyarray<double>& p_trial_ref = args.
array<
double>(
"p_trial_ref");
7415 xt::pyarray<double>& p_test_ref = args.
array<
double>(
"p_test_ref");
7416 xt::pyarray<double>& vel_trial_ref = args.
array<
double>(
"vel_trial_ref");
7417 xt::pyarray<double>& vel_test_ref = args.
array<
double>(
"vel_test_ref");
7418 xt::pyarray<double>& elementDiameter = args.
array<
double>(
"elementDiameter");
7419 xt::pyarray<double>& nodeDiametersArray = args.
array<
double>(
"nodeDiametersArray");
7420 xt::pyarray<double>& numerical_viscosity = args.
array<
double>(
"numerical_viscosity");
7421 int nElements_global = args.
scalar<
int>(
"nElements_global");
7422 double useMetrics = args.
scalar<
double>(
"useMetrics");
7423 double epsFact_rho = args.
scalar<
double>(
"epsFact_rho");
7424 double epsFact_mu = args.
scalar<
double>(
"epsFact_mu");
7429 xt::pyarray<int>& p_l2g = args.
array<
int>(
"p_l2g");
7430 xt::pyarray<int>& vel_l2g = args.
array<
int>(
"vel_l2g");
7431 xt::pyarray<double>& p_dof = args.
array<
double>(
"p_dof");
7432 xt::pyarray<double>& u_dof = args.
array<
double>(
"u_dof");
7433 xt::pyarray<double>& v_dof = args.
array<
double>(
"v_dof");
7434 xt::pyarray<double>& w_dof = args.
array<
double>(
"w_dof");
7435 const double useVF = args.
scalar<
double>(
"useVF");
7436 xt::pyarray<double>& vf = args.
array<
double>(
"vf");
7437 xt::pyarray<double>&
phi = args.
array<
double>(
"phi");
7438 xt::pyarray<int>& csrRowIndeces_p_p = args.
array<
int>(
"csrRowIndeces_p_p");
7439 xt::pyarray<int>& csrColumnOffsets_p_p = args.
array<
int>(
"csrColumnOffsets_p_p");
7440 xt::pyarray<int>& csrRowIndeces_u_u = args.
array<
int>(
"csrRowIndeces_u_u");
7441 xt::pyarray<int>& csrColumnOffsets_u_u = args.
array<
int>(
"csrColumnOffsets_u_u");
7442 xt::pyarray<int>& csrRowIndeces_v_v = args.
array<
int>(
"csrRowIndeces_v_v");
7443 xt::pyarray<int>& csrColumnOffsets_v_v = args.
array<
int>(
"csrColumnOffsets_v_v");
7444 xt::pyarray<int>& csrRowIndeces_w_w = args.
array<
int>(
"csrRowIndeces_w_w");
7445 xt::pyarray<int>& csrColumnOffsets_w_w = args.
array<
int>(
"csrColumnOffsets_w_w");
7446 xt::pyarray<double>& mass_matrix = args.
array<
double>(
"mass_matrix");
7449 for (
int eN=0 ; eN < nElements_global; ++eN){
7451 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
7452 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
7453 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
7454 double eps_rho, eps_mu;
7457 for (
int i=0; i<nDOF_test_element; ++i)
7458 for (
int j=0; j<nDOF_trial_element; ++j){
7459 local_matrix_p_p[i][j] = 0.0 ;
7460 local_matrix_u_u[i][j] = 0.0 ;
7461 local_matrix_v_v[i][j] = 0.0 ;
7464 for (
int k=0 ; k < nQuadraturePoints_element; ++k){
7466 int eN_k = eN*nQuadraturePoints_element+k;
7467 int eN_nDOF_trial_element = eN*nDOF_trial_element;
7469 double p = 0.0,
u = 0.0,
v= 0.0 ;
7471 double mom_p_acc = 0.0, dmom_p_acc_p = 0.0;
7472 double mom_u_acc = 0.0, dmom_u_acc_u = 0.0;
7473 double mom_v_acc = 0.0, dmom_v_acc_v = 0.0;
7474 double jac[nSpace*nSpace] ;
7475 double jacInv[nSpace*nSpace] ;
7476 double jacDet,x,y,
z ;
7477 double p_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element];
7482 ck.calculateMapping_element(eN,
7486 mesh_trial_ref.data(),
7487 mesh_grad_trial_ref.data(),
7493 ck.calculateH_element(eN,
7495 nodeDiametersArray.data(),
7497 mesh_trial_ref.data(),
7500 dV = fabs(jacDet)*dV_ref.data()[k];
7502 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_ref.data()[k*nDOF_trial_element],p);
7503 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],
u);
7504 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],
v);
7506 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7507 eps_mu = epsFact_mu * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7509 for (
int j=0 ; j<nDOF_trial_element ; ++j){
7510 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element + j]*dV;
7511 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_trial_element + j] * dV;
7517 numerical_viscosity.data()[eN_k],
7536 else if(scale_type==1){
7556 for (
int i=0 ; i < nDOF_test_element; ++i)
7558 int i_nSpace = i*nSpace;
7559 for (
int j=0 ; j < nDOF_trial_element; ++j)
7561 int j_nSpace = j*nSpace;
7562 local_matrix_p_p[i][j] +=
ck.MassJacobian_weak(dmom_p_acc_p,
7563 p_trial_ref.data()[k*nDOF_trial_element+j],
7565 local_matrix_u_u[i][j] +=
ck.MassJacobian_weak(dmom_u_acc_u,
7566 vel_trial_ref.data()[k*nDOF_trial_element+j],
7568 local_matrix_v_v[i][j] +=
ck.MassJacobian_weak(dmom_v_acc_v,
7569 vel_trial_ref.data()[k*nDOF_trial_element+j],
7578 for (
int i=0 ; i<nDOF_test_element; ++i)
7580 int eN_i = eN*nDOF_test_element+i;
7581 int eN_i_i = eN_i*nDOF_trial_element + i;
7582 for (
int j=0 ; j < nDOF_trial_element; ++j)
7584 int eN_i_j = eN_i*nDOF_trial_element + j;
7587 mass_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_i]] += local_matrix_p_p[i][j] ;
7588 mass_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_i]] += local_matrix_u_u[i][j] ;
7589 mass_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_i]] += local_matrix_v_v[i][j] ;
7593 mass_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
7594 mass_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
7595 mass_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
7605 int nQuadraturePoints_elementIn,
7606 int nDOF_mesh_trial_elementIn,
7607 int nDOF_trial_elementIn,
7608 int nDOF_test_elementIn,
7609 int nDOF_v_trial_elementIn,
7610 int nDOF_v_test_elementIn,
7611 int nQuadraturePoints_elementBoundaryIn,
7614 return proteus::chooseAndAllocateDiscretization2D<RANS2P2D_base,RANS2P2D,CompKernel,CompKernel>(nSpaceIn,
7615 nQuadraturePoints_elementIn,
7616 nDOF_mesh_trial_elementIn,
7617 nDOF_trial_elementIn,
7618 nDOF_test_elementIn,
7619 nDOF_v_trial_elementIn,
7620 nDOF_v_test_elementIn,
7621 nQuadraturePoints_elementBoundaryIn,