proteus 1.9.0
C/C++/Fortran libraries
Loading...
Searching...
No Matches
RANS2P.h
Go to the documentation of this file.
1#ifndef RANS2P_H
2#define RANS2P_H
3#include <valarray>
4#include <cmath>
5#include <iostream>
6#include <set>
7#include <map>
8#include "CompKernel.h"
9#include "MixedModelFactory.h"
10#include "PyEmbeddedFunctions.h"
12#include "ArgumentsDict.h"
13#include "xtensor/containers/xarray.hpp"
14#include "xtensor-python/pyarray.hpp"
15#include "mpi.h"
16#include "proteus_lapack.h"
17
18namespace py = pybind11;
19
20#define ZEROVEC {0.,0.,0.}
21const bool UPWIND_DIRICHLET=true;
22
23const double DM=0.0;//1-mesh conservation and divergence, 0 - weak div(v) only
24const double DM2=0.0;//1-point-wise mesh volume strong-residual, 0 - div(v) only
25const double DM3=1.0;//1-point-wise divergence, 0-point-wise rate of volume change
26const double inertial_term=1.0;
27namespace proteus
28{
29 inline double enorm(double* v)
30 {
31 return std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
32 }
33 inline double rnorm(double* r)
34 {
35 double rnorm=0.0;
36 for (int i=0;i<18;i++)
37 rnorm += r[i]*r[i];
38 return std::sqrt(rnorm);
39 }
40 inline void F6DOF(double DT, double mass, double* Iref, double* last_u, double* FT, double* last_FT, double* last_mom, double* u, //inputs
41 double* mom, double* r, double* J)//outputs
42 {
43 double *v = &u[0],
44 *last_v=&last_u[0],
45 *omega = &u[3],
46 *last_omega = &last_u[3],
47 *h = &u[6],
48 *last_h = &last_u[6],
49 *Q = &u[9],
50 *last_Q = &last_u[9];
51 double Omega[9] = { 0.0, -omega[2], omega[1],
52 omega[2], 0.0, -omega[0],
53 -omega[1], omega[0], 0.0},
54 last_Omega[9] = { 0.0, -last_omega[2], last_omega[1],
55 last_omega[2], 0.0, -last_omega[0],
56 -last_omega[1], last_omega[0], 0.0},
57 I[9] = {0.0};
58 for (int i=0;i<18;i++)
59 {
60 r[i] = 0.0;
61 for (int j=0;j<18;j++)
62 J[i*18+j] = 0.0;
63 }
64 //I = Q*Iref*Q^t
65 for (int i=0; i < 3; i++)
66 for (int j=0; j < 3; j++)
67 for (int k=0; k < 3; k++)
68 I[i*3 + j] += Q[i*3 + k]*Iref[k*3 +j];
69 for (int i=0; i < 3; i++)
70 for (int j=0; j < 3; j++)
71 for (int k=0; k < 3; k++)
72 I[i*3 + j] += I[i*3 + k]*Q[j*3 + k];
73 double M[36] = {0.0};
74 for (int i=0; i< 3; i++)
75 {
76 M[i*6 + i] = mass;
77 mom[i] = mass*u[i];//save for next time step--linear momentum
78 mom[3+i] = 0.0;
79 for (int j=0; j<3; j++)
80 {
81 M[(3+i)*6 + (3+j)] = I[i*3 + j];
82 mom[3+i] += I[i*3 + j]*u[3+j];//save for next time step--angular momentum
83 }
84 }
85 //could do added mass modification here
86 //
87 //residual
88 //momentum conservation residual
89 for (int i=0; i < 6; i++)
90 {
91 r[i] = - last_mom[i] - DT*0.5*(FT[i] + last_FT[i]);
92 for (int j=0; j < 6; j++)
93 {
94 r[i] += M[i*6 + j]*u[j];
95 J[i*18 + j] = M[i*6 + j];//all FT terms are explicit for now
96 }
97 }
98 //displacement residual
99 for (int i=0; i < 3; i++)
100 {
101 r[6+i] = h[i] - last_h[i] - DT*0.5*(v[i] + last_v[i]);
102 J[(6+i)*18 + (6+i)] = 1.0;
103 J[(6+i)*18 + i] = -DT*0.5;
104 }
105 //rotation residual
106 for (int i=0; i < 3; i++)
107 for (int j=0; j < 3; j++)
108 {
109 r[9 + i*3 + j] = Q[i*3 + j] - last_Q[i*3 + j];
110 J[(9+i*3+j)*18 + (9+i*3+j)] = 1.0;
111 for (int k=0; k < 3; k++)
112 {
113 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]);
114 J[(9 + i*3 + j)*18 + 9+k*3+j] -= DT*0.25*(Omega[i*3 + k] + last_Omega[i*3 + k]);
115 }
116 }
117 }
118
119 template<int nSpace, int nP, int nQ, int nEBQ>
120 // false, deliberately: the IFEM support in this file is the old, untested
121 // generation -- its activation macros (IFEMBASIS) are undefined, so the basis
122 // substitution it guards has never compiled. ADR.h carries the working,
123 // tested IFEM path and passes true there. Keeping that distinction explicit
124 // means RANS2P no longer inherits ADR's degenerate-cut behaviour: inside the
125 // gate, an element whose interface passes through an edge or corner node has
126 // D forced to 0 -- the interface measure the Nitsche term integrates over --
127 // and gets a different inside_out and root_node. Nothing here wants that.
129
131 {
132 public:
133 virtual ~RANS2P_base(){}
134 virtual void calculateResidual(arguments_dict& args) = 0;
135 virtual void calculateJacobian(arguments_dict& args) = 0;
141 {
142 py::gil_scoped_release release;
143 //py::gil_scoped_acquire acquire;
144 xt::pyarray<double>& ball_FT = args.array<double>("ball_FT");
145 xt::pyarray<double>& ball_last_FT = args.array<double>("ball_last_FT");
146 xt::pyarray<double>& ball_h = args.array<double>("ball_h");
147 xt::pyarray<double>& ball_last_h = args.array<double>("ball_last_h");
148 xt::pyarray<double>& ball_center = args.array<double>("ball_center");
149 xt::pyarray<double>& ball_center_last = args.array<double>("ball_center_last");
150 //note: these are only used for the fluid
151 xt::pyarray<double>& ball_velocity = args.array<double>("ball_velocity");
152 xt::pyarray<double>& ball_angular_velocity = args.array<double>("ball_angular_velocity");
153 //
154 xt::pyarray<double>& ball_last_velocity = args.array<double>("ball_last_velocity");
155 xt::pyarray<double>& ball_last_angular_velocity = args.array<double>("ball_last_angular_velocity");
156 xt::pyarray<double>& ball_Q = args.array<double>("ball_Q");
157 xt::pyarray<double>& ball_last_Q = args.array<double>("ball_last_Q");
158 xt::pyarray<double>& ball_Omega = args.array<double>("ball_Omega");
159 xt::pyarray<double>& ball_last_Omega = args.array<double>("ball_last_Omega");
160 xt::pyarray<double>& ball_u = args.array<double>("ball_u");
161 xt::pyarray<double>& ball_last_u = args.array<double>("ball_last_u");
162 xt::pyarray<double>& ball_mom = args.array<double>("ball_mom");
163 xt::pyarray<double>& ball_last_mom = args.array<double>("ball_last_mom");
164 xt::pyarray<double>& ball_a = args.array<double>("ball_a");
165 xt::pyarray<double>& ball_I = args.array<double>("ball_I");
166 xt::pyarray<double>& ball_mass = args.array<double>("ball_mass");
167 xt::pyarray<double>& ball_radius = args.array<double>("ball_radius");
168 xt::pyarray<double>& ball_f = args.array<double>("ball_f");
169 xt::pyarray<double>& wall_f = args.array<double>("wall_f");
170 xt::pyarray<double>& particle_netForces = args.array<double>("particle_netForces");
171 xt::pyarray<double>& particle_netMoments = args.array<double>("particle_netMoments");
172 xt::pyarray<double>& last_particle_netForces = args.array<double>("last_particle_netForces");
173 xt::pyarray<double>& last_particle_netMoments = args.array<double>("last_particle_netMoments");
174 xt::pyarray<double>& g = args.array<double>("g");
175 xt::pyarray<double>& L = args.array<double>("L");
176 const double ball_force_range = args.scalar<double>("ball_force_range");
177 const double ball_stiffness = args.scalar<double>("ball_stiffness");
178 const double particle_cfl = args.scalar<double>("particle_cfl");
179 const double dt = args.scalar<double>("dt");
180 double& min_dt(*args.array<double>("min_dt").data());
181 int& nSteps(*args.array<int>("nSteps").data());
182 const int nParticles = ball_center.shape(0);
183 double DT = dt;
184 double td = 0.0;
185 //double min_dt = dt;
186 //int nSteps=0;
187 min_dt = dt;
188 nSteps=0;
189 //double max_cfl=0.0;
190 xt::xarray<double> cfl=xt::zeros<double>({nParticles});
191#pragma omp parallel for
192 for (int ip=0; ip < nParticles; ip++)
193 for (int i=0; i < 3; i++)
194 {
195 ball_velocity(ip,i) = 0.0;
196 ball_angular_velocity(ip,i) = 0.0;
197 }
198
199 while (td < dt)
200 {
201 nSteps +=1;
202 //particle-wall and particle-particle collision forces
203#pragma omp parallel for
204 for (int ip=0; ip < nParticles; ip++)
205 {
206 double vnorm = enorm(&ball_last_velocity.data()[ip*3]);
207 double vp[3], vpnorm;
208 for (int i=0; i< 3; i++)
209 {
210 ball_last_FT(ip, i) = particle_netForces(ip,i) + ball_mass(ip)*g[i] + ball_f(ip,i) + wall_f(ip,i);// - 2.0*0.001*vnorm*ball_last_velocity(ip,i);
211 ball_last_FT(ip, 3+i) = particle_netMoments(ip,i);
212 vp[i] = ball_last_velocity(ip,i) + ball_a(ip,i)*DT;
213 }
214 vpnorm = enorm(vp);
215 double wall_range = 2.0*ball_radius(ip) + ball_force_range;
216 double wall_stiffness = ball_stiffness/2.0;
217 double dx0 = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,0))));
218 double dxL = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,0)-L(0))));
219 wall_f(ip,0) = (1.0/wall_stiffness)*( pow(wall_range - dx0,2) * (fmax(0.0, ball_center(ip,0)) + ball_radius(ip)) +
220 pow(wall_range - dxL,2) * (fmin(L(0), ball_center(ip,0)) - (L(0) + ball_radius(ip))));
221 double dy0 = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,1))));
222 double dyL = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,1)-L(1))));
223 wall_f(ip,1) = (1.0/wall_stiffness)*( pow(wall_range - dy0,2) * (fmax(0.0, ball_center(ip,1)) + ball_radius(ip)) +
224 pow(wall_range - dyL,2) * (fmin(L(1), ball_center(ip,1)) - (L(1) + ball_radius(ip))));
225 double dz0 = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,2))));
226 double dzL = fmin(wall_range, ball_radius(ip) + fmax(ball_radius(ip), fabs(ball_center(ip,2)-L(2))));
227 wall_f(ip,2) = (1.0/wall_stiffness)*( pow(wall_range - dz0,2) * (fmax(0.0, ball_center(ip,2)) + ball_radius(ip)) +
228 pow(wall_range - dzL,2) * (fmin(L(2), ball_center(ip,2)) - (L(2) + ball_radius(ip))));
229
230 for (int i=0; i< 3;i++)
231 ball_f(ip,i) = 0.0;
232 for (int jp=0; jp < nParticles; jp++)
233 {
234 double ball_range, d;
235 double f[3], h_ipjp[3];
236 ball_range = ball_radius(ip) + ball_radius(jp) + ball_force_range;
237 for(int i=0;i<3;i++)
238 h_ipjp[i] = ball_center(ip,i) - ball_center(jp,i);
239 d = ball_range - fmin(ball_range, fmax(ball_radius(ip) + ball_radius(jp), enorm(h_ipjp)));
240 for (int i=0;i<3;i++)
241 f[i] = (1.0/ball_stiffness)*h_ipjp[i]*pow(d,2.0);
242 if (ip != jp)
243 for (int i=0;i<3;i++)
244 ball_f(ip,i) += f[i];
245 }
246 cfl(ip) = fmax(vnorm*DT/ball_force_range, vpnorm*DT/ball_force_range);
247 }
248 double max_cfl = xt::amax(cfl,{0})(0);
249 if (max_cfl > particle_cfl)
250 DT = (particle_cfl/max_cfl)*DT;
251 if (DT > dt - td - dt*1.0e-8)
252 {
253 DT = dt-td;
254 td = dt;
255 }
256 else
257 td += DT;
258 min_dt =fmin(DT, min_dt);
259 //Newton iterations
260#pragma omp parallel for
261 for (int ip=0; ip < nParticles; ip++)
262 {
263 int pivots[18];
264 double r[18];
265 double J[18*18];
266 for (int i=0; i<3; i++)
267 {
268 ball_FT(ip, i) = particle_netForces(ip, i) + ball_mass(ip)*g[i] + ball_f(ip, i) + wall_f(ip, i);
269 ball_FT(ip, 3+i) = particle_netMoments(ip, i);
270 }
271 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],
272 &ball_mom.data()[ip*6], r, J);
273 int its=0;
274 int maxits=100;
275 while ((its==0 || rnorm(r) > 1.0e-10) && its < maxits)
276 {
277 int info,N=18,nrhs=1;
278 char trans='T';
279 dgetrf_(&N,&N,J,&N,pivots,&info);
280 dgetrs_(&trans, &N,&nrhs,J,&N,pivots,r,&N,&info);//J = LU now
281 for (int i=0;i<18;i++)
282 ball_u(ip,i) -= r[i];//r=du now
283 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],
284 &ball_mom.data()[ip*6], r, J);
285 its+=1;
286 }
287 for (int i=0; i< 3; i++)
288 {
289 ball_center(ip,i) += (ball_u(ip,6+i) - ball_last_u(ip,6+i));
290 ball_a(ip,i) = (ball_u(ip,i) - ball_last_velocity(ip,i))/DT;
291 ball_last_velocity(ip,i) = ball_u(ip,i);
292 ball_last_mom(ip,i) = ball_mom(ip,i);
293 ball_last_mom(ip,3+i) = ball_mom(ip,3+i);
294 //return averages over dt for the fluid velocities
295 ball_velocity(ip,i) += DT*ball_u(ip,i)/dt;
296 ball_angular_velocity(ip,i) += DT*ball_u(ip,3+i)/dt;
297 }
298 for (int i=0; i< 18; i++)
299 ball_last_u(ip,i) = ball_u(ip,i);
300 }
301 }
302 }
303 };
304
305 template<class CompKernelType,
306 class CompKernelType_v,
307 int nSpace,
308 int nQuadraturePoints_element,
309 int nDOF_mesh_trial_element,
310 int nDOF_trial_element,
311 int nDOF_test_element,
312 int nDOF_v_trial_element,
313 int nDOF_v_test_element,
314 int nQuadraturePoints_elementBoundary>
315 class RANS2P : public RANS2P_base
316 {
317 public:
320 std::map<int, int> cutfem_local_boundaries;
321
326 CompKernelType ck;
327 CompKernelType_v ck_v;
332 nDOF_test_X_trial_element(nDOF_test_element*nDOF_trial_element),
333 nDOF_test_X_v_trial_element(nDOF_test_element*nDOF_v_trial_element),
334 nDOF_v_test_X_trial_element(nDOF_v_test_element*nDOF_trial_element),
335 nDOF_v_test_X_v_trial_element(nDOF_v_test_element*nDOF_v_trial_element),
336 ck(),
337 ck_v()
338 {}
339
340 inline
341 void evaluateCoefficients(const double NONCONSERVATIVE_FORM,
342 const double sigma,
343 const double rho,
344 double nu,
345 const double h_e,
346 const double smagorinskyConstant,
347 const int turbulenceClosureModel,
348 const double g[nSpace],
349 const double useVF,
350 const double& vf,
351 const double& phi,
352 const double n[nSpace],
353 const double& kappa,
354 const double porosity,//VRANS specific
355 const double phi_solid,
356 const double p_old,
357 const double u_old,
358 const double v_old,
359 const double w_old,
360 const double grad_p_old[nSpace],
361 const double grad_u_old[nSpace],
362 const double grad_v_old[nSpace],
363 const double grad_w_old[nSpace],
364 const double& p,
365 const double grad_p[nSpace],
366 const double grad_u[nSpace],
367 const double grad_v[nSpace],
368 const double grad_w[nSpace],
369 const double& u,
370 const double& v,
371 const double& w,
372 const double LAG_LES,
373 double& eddy_viscosity,
374 double& eddy_viscosity_last,
375 double& mom_u_acc,
376 double& dmom_u_acc_u,
377 double& mom_v_acc,
378 double& dmom_v_acc_v,
379 double& mom_w_acc,
380 double& dmom_w_acc_w,
381 double mass_adv[nSpace],
382 double dmass_adv_u[nSpace],
383 double dmass_adv_v[nSpace],
384 double dmass_adv_w[nSpace],
385 double mom_u_adv[nSpace],
386 double dmom_u_adv_u[nSpace],
387 double dmom_u_adv_v[nSpace],
388 double dmom_u_adv_w[nSpace],
389 double mom_v_adv[nSpace],
390 double dmom_v_adv_u[nSpace],
391 double dmom_v_adv_v[nSpace],
392 double dmom_v_adv_w[nSpace],
393 double mom_w_adv[nSpace],
394 double dmom_w_adv_u[nSpace],
395 double dmom_w_adv_v[nSpace],
396 double dmom_w_adv_w[nSpace],
397 double mom_uu_diff_ten[nSpace],
398 double mom_vv_diff_ten[nSpace],
399 double mom_ww_diff_ten[nSpace],
400 double mom_uv_diff_ten[1],
401 double mom_uw_diff_ten[1],
402 double mom_vu_diff_ten[1],
403 double mom_vw_diff_ten[1],
404 double mom_wu_diff_ten[1],
405 double mom_wv_diff_ten[1],
406 double& mom_u_source,
407 double& mom_v_source,
408 double& mom_w_source,
409 double& mom_u_ham,
410 double dmom_u_ham_grad_p[nSpace],
411 double dmom_u_ham_grad_u[nSpace],
412 double& dmom_u_ham_u,
413 double& dmom_u_ham_v,
414 double& dmom_u_ham_w,
415 double& mom_v_ham,
416 double dmom_v_ham_grad_p[nSpace],
417 double dmom_v_ham_grad_v[nSpace],
418 double& dmom_v_ham_u,
419 double& dmom_v_ham_v,
420 double& dmom_v_ham_w,
421 double& mom_w_ham,
422 double dmom_w_ham_grad_p[nSpace],
423 double dmom_w_ham_grad_w[nSpace],
424 double& dmom_w_ham_u,
425 double& dmom_w_ham_v,
426 double& dmom_w_ham_w,
427 double forcex,
428 double forcey,
429 double forcez)
430 {
431 double mu,norm_n,nu_t;
432 //calculate eddy viscosity
433 switch (turbulenceClosureModel)
434 {
435 double norm_S;
436 case 1:
437 {
438 norm_S = sqrt(2.0*(grad_u[0]*grad_u[0] + grad_v[1]*grad_v[1] + grad_w[2]*grad_w[2] +
439 0.5*(grad_u[1]+grad_v[0])*(grad_u[1]+grad_v[0]) +
440 0.5*(grad_u[2]+grad_w[0])*(grad_u[2]+grad_w[0]) +
441 0.5*(grad_v[2]+grad_w[1])*(grad_v[2]+grad_w[1])));
442 nu_t = smagorinskyConstant*smagorinskyConstant*h_e*h_e*norm_S;
443 break;
444 }
445 case 2:
446 {
447 double re,cs=0.0;
448 norm_S = sqrt(2.0*(grad_u[0]*grad_u[0] + grad_v[1]*grad_v[1] + grad_w[2]*grad_w[2] +
449 0.5*(grad_u[1]+grad_v[0])*(grad_u[1]+grad_v[0]) +
450 0.5*(grad_u[2]+grad_w[0])*(grad_u[2]+grad_w[0]) +
451 0.5*(grad_v[2]+grad_w[1])*(grad_v[2]+grad_w[1])));
452 re = h_e*h_e*norm_S/nu;
453 if (re > 1.0)
454 cs=0.027*pow(10.0,-3.23*pow(re,-0.92));
455 nu_t = cs*h_e*h_e*norm_S;
456 break;
457 }
458 default:
459 {
460 nu_t=0.0;
461 }
462 }
463 eddy_viscosity = nu_t;
464 nu += (1.0-LAG_LES)*nu_t + LAG_LES*eddy_viscosity_last;
465 mu = rho*nu;
466 if (NONCONSERVATIVE_FORM > 0.0)
467 {
468 //u momentum accumulation
469 mom_u_acc=u;//trick for non-conservative form
470 dmom_u_acc_u=rho*porosity;
471
472 //v momentum accumulation
473 mom_v_acc=v;
474 dmom_v_acc_v=rho*porosity;
475
476 //w momentum accumulation
477 mom_w_acc=w;
478 dmom_w_acc_w=rho*porosity;
479
480 //mass advective flux
481 mass_adv[0]=porosity*u;
482 mass_adv[1]=porosity*v;
483 mass_adv[2]=porosity*w;
484
485 dmass_adv_u[0]=porosity;
486 dmass_adv_u[1]=0.0;
487 dmass_adv_u[2]=0.0;
488
489 dmass_adv_v[0]=0.0;
490 dmass_adv_v[1]=porosity;
491 dmass_adv_v[2]=0.0;
492
493 dmass_adv_w[0]=0.0;
494 dmass_adv_w[1]=0.0;
495 dmass_adv_w[2]=porosity;
496
497 //u momentum advective flux
498 mom_u_adv[0]=0.0;
499 mom_u_adv[1]=0.0;
500 mom_u_adv[2]=0.0;
501
502 dmom_u_adv_u[0]=0.0;
503 dmom_u_adv_u[1]=0.0;
504 dmom_u_adv_u[2]=0.0;
505
506 dmom_u_adv_v[0]=0.0;
507 dmom_u_adv_v[1]=0.0;
508 dmom_u_adv_v[2]=0.0;
509
510 dmom_u_adv_w[0]=0.0;
511 dmom_u_adv_w[1]=0.0;
512 dmom_u_adv_w[2]=0.0;
513
514 //v momentum advective_flux
515 mom_v_adv[0]=0.0;
516 mom_v_adv[1]=0.0;
517 mom_v_adv[2]=0.0;
518
519 dmom_v_adv_u[0]=0.0;
520 dmom_v_adv_u[1]=0.0;
521 dmom_v_adv_u[2]=0.0;
522
523 dmom_v_adv_w[0]=0.0;
524 dmom_v_adv_w[1]=0.0;
525 dmom_v_adv_w[2]=0.0;
526
527 dmom_v_adv_v[0]=0.0;
528 dmom_v_adv_v[1]=0.0;
529 dmom_v_adv_v[2]=0.0;
530
531 //w momentum advective_flux
532 mom_w_adv[0]=0.0;
533 mom_w_adv[1]=0.0;
534 mom_w_adv[2]=0.0;
535
536 dmom_w_adv_u[0]=0.0;
537 dmom_w_adv_u[1]=0.0;
538 dmom_w_adv_u[2]=0.0;
539
540 dmom_w_adv_v[0]=0.0;
541 dmom_w_adv_v[1]=0.0;
542 dmom_w_adv_v[2]=0.0;
543
544 dmom_w_adv_w[0]=0.0;
545 dmom_w_adv_w[1]=0.0;
546 dmom_w_adv_w[2]=0.0;
547
548 //u momentum diffusion tensor
549 mom_uu_diff_ten[0] = 2.0*porosity*mu;
550 mom_uu_diff_ten[1] = porosity*mu;
551 mom_uu_diff_ten[2] = porosity*mu;
552
553 mom_uv_diff_ten[0]=porosity*mu;
554
555 mom_uw_diff_ten[0]=porosity*mu;
556
557 //v momentum diffusion tensor
558 mom_vv_diff_ten[0] = porosity*mu;
559 mom_vv_diff_ten[1] = 2.0*porosity*mu;
560 mom_vv_diff_ten[2] = porosity*mu;
561
562 mom_vu_diff_ten[0]=porosity*mu;
563
564 mom_vw_diff_ten[0]=porosity*mu;
565
566 //w momentum diffusion tensor
567 mom_ww_diff_ten[0] = porosity*mu;
568 mom_ww_diff_ten[1] = porosity*mu;
569 mom_ww_diff_ten[2] = 2.0*porosity*mu;
570
571 mom_wu_diff_ten[0]=porosity*mu;
572
573 mom_wv_diff_ten[0]=porosity*mu;
574
575 //momentum sources
576 norm_n = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
577 mom_u_source = -porosity*rho*g[0];// - porosity*d_mu*sigma*kappa*n[0];
578 mom_v_source = -porosity*rho*g[1];// - porosity*d_mu*sigma*kappa*n[1];
579 mom_w_source = -porosity*rho*g[2];// - porosity*d_mu*sigma*kappa*n[2];
580
581 //u momentum Hamiltonian (pressure)
582 mom_u_ham = porosity*grad_p[0];
583 dmom_u_ham_grad_p[0]=porosity;
584 dmom_u_ham_grad_p[1]=0.0;
585 dmom_u_ham_grad_p[2]=0.0;
586
587 //v momentum Hamiltonian (pressure)
588 mom_v_ham = porosity*grad_p[1];
589 dmom_v_ham_grad_p[0]=0.0;
590 dmom_v_ham_grad_p[1]=porosity;
591 dmom_v_ham_grad_p[2]=0.0;
592
593 //w momentum Hamiltonian (pressure)
594 mom_w_ham = porosity*grad_p[2];
595 dmom_w_ham_grad_p[0]=0.0;
596 dmom_w_ham_grad_p[1]=0.0;
597 dmom_w_ham_grad_p[2]=porosity;
598
599 //u momentum Hamiltonian (advection)
600 mom_u_ham += inertial_term*rho*porosity*(u*grad_u[0]+v*grad_u[1]+w*grad_u[2]);
601 dmom_u_ham_grad_u[0]=inertial_term*rho*porosity*u;
602 dmom_u_ham_grad_u[1]=inertial_term*rho*porosity*v;
603 dmom_u_ham_grad_u[2]=inertial_term*rho*porosity*w;
604 dmom_u_ham_u =inertial_term*rho*porosity*grad_u[0];
605 dmom_u_ham_v =inertial_term*rho*porosity*grad_u[1];
606 dmom_u_ham_w =inertial_term*rho*porosity*grad_u[2];
607
608 //v momentum Hamiltonian (advection)
609 mom_v_ham += inertial_term*rho*porosity*(u*grad_v[0]+v*grad_v[1]+w*grad_v[2]);
610 dmom_v_ham_grad_v[0]=inertial_term*rho*porosity*u;
611 dmom_v_ham_grad_v[1]=inertial_term*rho*porosity*v;
612 dmom_v_ham_grad_v[2]=inertial_term*rho*porosity*w;
613 dmom_v_ham_u =inertial_term*rho*porosity*grad_v[0];
614 dmom_v_ham_v =inertial_term*rho*porosity*grad_v[1];
615 dmom_v_ham_w =inertial_term*rho*porosity*grad_v[2];
616
617 /* //w momentum Hamiltonian (advection) */
618 mom_w_ham += inertial_term*rho*porosity*(u*grad_w[0]+v*grad_w[1]+w*grad_w[2]);
619 dmom_w_ham_grad_w[0]=inertial_term*rho*porosity*u;
620 dmom_w_ham_grad_w[1]=inertial_term*rho*porosity*v;
621 dmom_w_ham_grad_w[2]=inertial_term*rho*porosity*w;
622 dmom_w_ham_u =inertial_term*rho*porosity*grad_w[0];
623 dmom_w_ham_v =inertial_term*rho*porosity*grad_w[1];
624 dmom_w_ham_w =inertial_term*rho*porosity*grad_w[2];
625
626 }
627 else
628 {
629 //u momentum accumulation
630 mom_u_acc=porosity*u;
631 dmom_u_acc_u=porosity;
632
633 //v momentum accumulation
634 mom_v_acc=porosity*v;
635 dmom_v_acc_v=porosity;
636
637 //w momentum accumulation
638 mom_w_acc=porosity*w;
639 dmom_w_acc_w=porosity;
640
641 //mass advective flux
642 mass_adv[0]=porosity*u;
643 mass_adv[1]=porosity*v;
644 mass_adv[2]=porosity*w;
645
646 dmass_adv_u[0]=porosity;
647 dmass_adv_u[1]=0.0;
648 dmass_adv_u[2]=0.0;
649
650 dmass_adv_v[0]=0.0;
651 dmass_adv_v[1]=porosity;
652 dmass_adv_v[2]=0.0;
653
654 dmass_adv_w[0]=0.0;
655 dmass_adv_w[1]=0.0;
656 dmass_adv_w[2]=porosity;
657
658 //u momentum advective flux
659 mom_u_adv[0]=inertial_term*porosity*u*u;
660 mom_u_adv[1]=inertial_term*porosity*u*v;
661 mom_u_adv[2]=inertial_term*porosity*u*w;
662
663 dmom_u_adv_u[0]=inertial_term*2.0*porosity*u;
664 dmom_u_adv_u[1]=inertial_term*porosity*v;
665 dmom_u_adv_u[2]=inertial_term*porosity*w;
666
667 dmom_u_adv_v[0]=0.0;
668 dmom_u_adv_v[1]=inertial_term*porosity*u;
669 dmom_u_adv_v[2]=0.0;
670
671 dmom_u_adv_w[0]=0.0;
672 dmom_u_adv_w[1]=0.0;
673 dmom_u_adv_w[2]=inertial_term*porosity*u;
674
675 //v momentum advective_flux
676 mom_v_adv[0]=inertial_term*porosity*v*u;
677 mom_v_adv[1]=inertial_term*porosity*v*v;
678 mom_v_adv[2]=inertial_term*porosity*v*w;
679
680 dmom_v_adv_u[0]=inertial_term*porosity*v;
681 dmom_v_adv_u[1]=0.0;
682 dmom_v_adv_u[2]=0.0;
683
684 dmom_v_adv_w[0]=0.0;
685 dmom_v_adv_w[1]=0.0;
686 dmom_v_adv_w[2]=inertial_term*porosity*v;
687
688 dmom_v_adv_v[0]=inertial_term*porosity*u;
689 dmom_v_adv_v[1]=inertial_term*2.0*porosity*v;
690 dmom_v_adv_v[2]=inertial_term*porosity*w;
691
692 //w momentum advective_flux
693 mom_w_adv[0]=inertial_term*porosity*w*u;
694 mom_w_adv[1]=inertial_term*porosity*w*v;
695 mom_w_adv[2]=inertial_term*porosity*w*w;
696
697 dmom_w_adv_u[0]=inertial_term*porosity*w;
698 dmom_w_adv_u[1]=0.0;
699 dmom_w_adv_u[2]=0.0;
700
701 dmom_w_adv_v[0]=0.0;
702 dmom_w_adv_v[1]=inertial_term*porosity*w;
703 dmom_w_adv_v[2]=0.0;
704
705 dmom_w_adv_w[0]=inertial_term*porosity*u;
706 dmom_w_adv_w[1]=inertial_term*porosity*v;
707 dmom_w_adv_w[2]=inertial_term*2.0*porosity*w;
708
709 //u momentum diffusion tensor
710 mom_uu_diff_ten[0] = 2.0*porosity*nu;
711 mom_uu_diff_ten[1] = porosity*nu;
712 mom_uu_diff_ten[2] = porosity*nu;
713
714 mom_uv_diff_ten[0]=porosity*nu;
715
716 mom_uw_diff_ten[0]=porosity*nu;
717
718 //v momentum diffusion tensor
719 mom_vv_diff_ten[0] = porosity*nu;
720 mom_vv_diff_ten[1] = 2.0*porosity*nu;
721 mom_vv_diff_ten[2] = porosity*nu;
722
723 mom_vu_diff_ten[0]=porosity*nu;
724
725 mom_vw_diff_ten[0]=porosity*nu;
726
727 //w momentum diffusion tensor
728 mom_ww_diff_ten[0] = porosity*nu;
729 mom_ww_diff_ten[1] = porosity*nu;
730 mom_ww_diff_ten[2] = 2.0*porosity*nu;
731
732 mom_wu_diff_ten[0]=porosity*nu;
733
734 mom_wv_diff_ten[0]=porosity*nu;
735
736 //momentum sources
737 norm_n = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
738 mom_u_source = -porosity*g[0];// - porosity*d_mu*sigma*kappa*n[0]/(rho*(norm_n+1.0e-8));
739 mom_v_source = -porosity*g[1];// - porosity*d_mu*sigma*kappa*n[1]/(rho*(norm_n+1.0e-8));
740 mom_w_source = -porosity*g[2];// - porosity*d_mu*sigma*kappa*n[2]/(rho*(norm_n+1.0e-8));
741
742 //u momentum Hamiltonian (pressure)
743 mom_u_ham = porosity*grad_p[0]/rho;
744 dmom_u_ham_grad_p[0]=porosity/rho;
745 dmom_u_ham_grad_p[1]=0.0;
746 dmom_u_ham_grad_p[2]=0.0;
747
748 //v momentum Hamiltonian (pressure)
749 mom_v_ham = porosity*grad_p[1]/rho;
750 dmom_v_ham_grad_p[0]=0.0;
751 dmom_v_ham_grad_p[1]=porosity/rho;
752 dmom_v_ham_grad_p[2]=0.0;
753
754 //w momentum Hamiltonian (pressure)
755 mom_w_ham = porosity*grad_p[2]/rho;
756 dmom_w_ham_grad_p[0]=0.0;
757 dmom_w_ham_grad_p[1]=0.0;
758 dmom_w_ham_grad_p[2]=porosity/rho;
759
760 //u momentum Hamiltonian (advection)
761 dmom_u_ham_grad_u[0]=0.0;
762 dmom_u_ham_grad_u[1]=0.0;
763 dmom_u_ham_grad_u[2]=0.0;
764 dmom_u_ham_u =0.0;
765 dmom_u_ham_v =0.0;
766 dmom_u_ham_w =0.0;
767
768 //v momentum Hamiltonian (advection)
769 dmom_v_ham_grad_v[0]=0.0;
770 dmom_v_ham_grad_v[1]=0.0;
771 dmom_v_ham_grad_v[2]=0.0;
772 dmom_v_ham_u =0.0;
773 dmom_v_ham_v =0.0;
774 dmom_v_ham_w =0.0;
775
776 //w momentum Hamiltonian (advection)
777 dmom_w_ham_grad_w[0]=0.0;
778 dmom_w_ham_grad_w[1]=0.0;
779 dmom_w_ham_grad_w[2]=0.0;
780 dmom_w_ham_u =0.0;
781 dmom_w_ham_v =0.0;
782 dmom_w_ham_w =0.0;
783 }
784 mom_u_source -= forcex;
785 mom_v_source -= forcey;
786 mom_w_source -= forcez;
787 }
788
789 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)
790 {
791 distance = 1e10;
792 int index = -1;
793 double d_ball_i;
794 for (int i=0; i<n_balls; ++i)
795 {
796 d_ball_i = std::sqrt((ball_center[i*3+0]-x)*(ball_center[i*3+0]-x)
797 +(ball_center[i*3+1]-y)*(ball_center[i*3+1]-y)
798 +(ball_center[i*3+2]-z)*(ball_center[i*3+2]-z)
799 ) - ball_radius[i];
800 if(d_ball_i<distance)
801 {
802 distance = d_ball_i;
803 index = i;
804 }
805 }
806 return index;
807 }
808
809 void get_distance_to_ith_ball(int n_balls,const double* ball_center, const double* ball_radius,
810 int I,
811 const double x, const double y, const double z,
812 double& distance)
813 {
814 distance = std::sqrt((ball_center[I*3+0]-x)*(ball_center[I*3+0]-x)
815 + (ball_center[I*3+1]-y)*(ball_center[I*3+1]-y)
816 + (ball_center[I*3+2]-z)*(ball_center[I*3+2]-z)
817 ) - ball_radius[I];
818 }
819 void get_normal_to_ith_ball(int n_balls,const double* ball_center, const double* ball_radius,
820 int I,
821 const double x, const double y, const double z,
822 double& nx, double& ny, double& nz)
823 {
824 double distance = std::sqrt((ball_center[I*3+0]-x)*(ball_center[I*3+0]-x)
825 + (ball_center[I*3+1]-y)*(ball_center[I*3+1]-y)
826 + (ball_center[I*3+2]-z)*(ball_center[I*3+2]-z)
827 );
828 if (distance > 1.0e-8)
829 {
830 nx = (x - ball_center[I*3+0])/distance;
831 ny = (y - ball_center[I*3+1])/distance;
832 nz = (z - ball_center[I*3+2])/distance;
833 assert(std::fabs(std::sqrt(nx*nx + ny*ny + nz*nz) - 1.0) < 1.0e-10);
834 }
835 else
836 {
837 nx = 1.0;
838 ny = 0.0;
839 nz = 0.0;
840 }
841 }
842 void get_cross_product(const double *u, const double *v,double res[3])
843 {
844 res[0] = u[1]*v[2]-u[2]*v[1];
845 res[1] = u[2]*v[0]-u[0]*v[2];
846 res[2] = u[0]*v[1]-u[1]*v[0];
847 }
848 void get_velocity_to_ith_ball(int n_balls,const double* ball_center, const double* ball_radius,
849 const double* ball_velocity, const double* ball_angular_velocity,
850 int I,
851 const double x, const double y, const double z,
852 double& vx, double& vy, double& vz)
853 {
854 double position[3]={x-ball_center[3*I + 0],y-ball_center[3*I + 1],z-ball_center[3*I + 2]};
855 double angular_cross_position[3];
856 get_cross_product(&ball_angular_velocity[3*I + 0],position,angular_cross_position);
857 vx = ball_velocity[3*I + 0] + angular_cross_position[0];
858 vy = ball_velocity[3*I + 1] + angular_cross_position[1];
859 vz = ball_velocity[3*I + 2] + angular_cross_position[2];
860
861 }
862 inline void updateSolidParticleTerms(int particle_index,
863 const double NONCONSERVATIVE_FORM,
864 bool element_owned,
865 const double particle_nitsche,
866 const double dV,
867 const int nParticles,
868 const int sd_offset,
869 double* particle_signed_distances,
870 double* particle_signed_distance_normals,
871 double* particle_velocities,
872 double* particle_centroids,
873 const int use_ball_as_particle,
874 const double* ball_center,
875 const double* ball_radius,
876 const double* ball_velocity,
877 const double* ball_angular_velocity,
878 const double* ball_density,
879 const double porosity, //VRANS specific
880 const double penalty,
881 const double alpha,
882 const double beta,
883 const double eps_rho,
884 const double eps_mu,
885 const double rho_0,
886 const double nu_0,
887 const double rho_1,
888 const double nu_1,
889 const double useVF,
890 const double vf,
891 const double phi,
892 const double x,
893 const double y,
894 const double z,
895 const double p,
896 const double u,
897 const double v,
898 const double w,
899 const double uStar,
900 const double vStar,
901 const double wStar,
902 const double eps_s,
903 const double grad_u[nSpace],
904 const double grad_v[nSpace],
905 const double grad_w[nSpace],
906 double &mass_source,
907 double &mom_u_source,
908 double &mom_v_source,
909 double &mom_w_source,
910 double dmom_u_source[nSpace],
911 double dmom_v_source[nSpace],
912 double dmom_w_source[nSpace],
913 double mom_u_adv[nSpace],
914 double mom_v_adv[nSpace],
915 double mom_w_adv[nSpace],
916 double dmom_u_adv_u[nSpace],
917 double dmom_v_adv_v[nSpace],
918 double dmom_w_adv_w[nSpace],
919 double &mom_u_ham,
920 double dmom_u_ham_grad_u[nSpace],
921 double dmom_u_ham_grad_v[nSpace],
922 double dmom_u_ham_grad_w[nSpace],
923 double &dmom_u_ham_u,
924 double &dmom_u_ham_v,
925 double &dmom_u_ham_w,
926 double &mom_v_ham,
927 double dmom_v_ham_grad_u[nSpace],
928 double dmom_v_ham_grad_v[nSpace],
929 double dmom_v_ham_grad_w[nSpace],
930 double &dmom_v_ham_u,
931 double &dmom_v_ham_v,
932 double &dmom_v_ham_w,
933 double &mom_w_ham,
934 double dmom_w_ham_grad_u[nSpace],
935 double dmom_w_ham_grad_v[nSpace],
936 double dmom_w_ham_grad_w[nSpace],
937 double &dmom_w_ham_u,
938 double &dmom_w_ham_v,
939 double &dmom_w_ham_w,
940 double &mass_ham,
941 double &dmass_ham_u,
942 double &dmass_ham_v,
943 double &dmass_ham_w,
944 double *particle_netForces,
945 double *particle_netMoments,
946 double *particle_surfaceArea,
947 double *particle_surfaceArea_projected,
948 double *projection_direction,
949 double *particle_volume)
950 {
951 double C, rho, mu, nu, H_mu, ImH_mu, uc, duc_du, duc_dv, duc_dw, ImH_s, D_s, phi_s, u_s, v_s, w_s;
952 double force_x, force_y, force_z, r_x, r_y, r_z, force_p_x, force_p_y, force_p_z, force_stress_x, force_stress_y, force_stress_z;
953 double phi_s_normal[nSpace]=ZEROVEC;
954 double fluid_outward_normal[nSpace]=ZEROVEC;
955 double vel[nSpace]=ZEROVEC;
956 double center[nSpace]=ZEROVEC;
957 H_mu = (1.0 - useVF) * gf.H(eps_mu, phi) + useVF * fmin(1.0, fmax(0.0, vf));
958 ImH_mu = (1.0 - useVF) * gf.ImH(eps_mu, phi) + useVF * (1.0-fmin(1.0, fmax(0.0, vf)));
959 nu = nu_0 * ImH_mu + nu_1 * H_mu;
960 rho = rho_0 * ImH_mu + rho_1 * H_mu;
961 mu = rho_0 * nu_0 * ImH_mu + rho_1 * nu_1 * H_mu;
962 C = 0.0;
963 for (int i = particle_index; i < particle_index+1; i++)//cek hack to leave loop for the moment
964 {
965 if(use_ball_as_particle==1)
966 {
967 get_distance_to_ith_ball(nParticles,ball_center,ball_radius,i,x,y,z,phi_s);
968 get_velocity_to_ith_ball(nParticles,ball_center,ball_radius,
969 ball_velocity,ball_angular_velocity,
970 i,x,y,z,
971 vel[0],vel[1],vel[2]);
972 center[0] = ball_center[3*i+0];
973 center[1] = ball_center[3*i+1];
974 center[2] = ball_center[3*i+2];
975 particle_velocities[0] = vel[0];
976 particle_velocities[1] = vel[1];
977 particle_velocities[2] = vel[2];
978 }
979 else
980 {
981 phi_s = particle_signed_distances[i * sd_offset];
982 vel[0] = particle_velocities[i * sd_offset * 3 + 0];
983 vel[1] = particle_velocities[i * sd_offset * 3 + 1];
984 vel[2] = particle_velocities[i * sd_offset * 3 + 2];
985 center[0] = particle_centroids[3*i+0];
986 center[1] = particle_centroids[3*i+1];
987 center[2] = particle_centroids[3*i+2];
988 }
989 for (int I=0;I<nSpace;I++)
990 phi_s_normal[I] = particle_signed_distance_normals[I];
991 assert(std::fabs(1.0-std::sqrt(phi_s_normal[0]*phi_s_normal[0] + phi_s_normal[1]*phi_s_normal[1] + phi_s_normal[2]*phi_s_normal[2])) < 1.0e-8);
992 /* if (fabs(vel[0] - particle_velocities[i * sd_offset * 3 + 0])> 1.0e-12) */
993 /* std::cout<<"vel[0] "<<vel[0]<<'\t'<<particle_velocities[3*i+0]<<std::endl; */
994 /* if(fabs(vel[1] - particle_velocities[i * sd_offset * 3 + 1])> 1.0e-12) */
995 /* std::cout<<"vel[1] "<<vel[1]<<'\t'<<particle_velocities[3*i+1]<<std::endl; */
996 /* if(fabs(center[0] - particle_centroids[3*i+0])> 1.0e-12) */
997 /* std::cout<<"center[0] "<<center[0]<<'\t'<<particle_centroids[3*i+0]<<std::endl; */
998 /* if(fabs(center[1] - particle_centroids[3*i+1])> 1.0e-12) */
999 /* std::cout<<"center[1] "<<center[1]<<'\t'<<particle_centroids[3*i+1]<<std::endl; */
1000 /* if(fabs(phi_s - particle_signed_distances[i * sd_offset]) > 1.0e-12) */
1001 /* std::cout<<"phi_s "<<phi_s<<'\t'<<particle_signed_distances[i * sd_offset]<<std::endl; */
1002 /* if(fabs(phi_s_normal[0] - particle_signed_distance_normals[i * sd_offset * 3 + 0]) > 1.0e-12) */
1003 /* std::cout<<"phi_s_normal[0] "<<phi_s_normal[0]<<'\t'<<particle_signed_distance_normals[i * sd_offset*3 + 0]<<std::endl; */
1004 /* if(fabs(phi_s_normal[1] - particle_signed_distance_normals[i * sd_offset * 3 + 1]) > 1.0e-12) */
1005 /* std::cout<<"phi_s_normal[1] "<<phi_s_normal[1]<<'\t'<<particle_signed_distance_normals[i * sd_offset*3 + 1]<<std::endl; */
1006
1007 fluid_outward_normal[0] = -phi_s_normal[0];
1008 fluid_outward_normal[1] = -phi_s_normal[1];
1009 fluid_outward_normal[2] = -phi_s_normal[2];
1010 assert(std::fabs(1.0-std::sqrt(fluid_outward_normal[0]*fluid_outward_normal[0] + fluid_outward_normal[1]*fluid_outward_normal[1] + fluid_outward_normal[2]*fluid_outward_normal[2])) < 1.0e-8);
1011 u_s = vel[0];
1012 v_s = vel[1];
1013 w_s = vel[2];
1014 D_s = gf_s.D(eps_s, phi_s);
1015 ImH_s = gf_s.ImH(eps_s, phi_s);
1016
1017 double rel_vel_norm = sqrt((uStar - u_s) * (uStar - u_s) +
1018 (vStar - v_s) * (vStar - v_s) +
1019 (wStar - w_s) * (wStar - w_s));
1020 force_p_x = porosity * dV * D_s * p * fluid_outward_normal[0];
1021 force_p_y = porosity * dV * D_s * p * fluid_outward_normal[1];
1022 force_p_z = porosity * dV * D_s * p * fluid_outward_normal[2];
1023 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]) + fluid_outward_normal[2]*(grad_u[2]+grad_w[0]))
1024 +mu*penalty*(u-u_s));
1025 force_stress_y = porosity * dV * D_s * (-mu*(fluid_outward_normal[0]*(grad_v[0]+grad_u[1]) + fluid_outward_normal[1]*2*grad_v[1] + fluid_outward_normal[2]*(grad_v[2]+grad_w[1]))
1026 +mu*penalty*(v-v_s));
1027 force_stress_z = porosity * dV * D_s * (-mu*(fluid_outward_normal[0]*(grad_w[0]+grad_u[2]) + fluid_outward_normal[1]*(grad_w[1]+grad_v[2]) + fluid_outward_normal[2]*2*grad_w[2])
1028 +mu*penalty*(w-w_s));
1029 force_x = force_p_x + force_stress_x;
1030 force_y = force_p_y + force_stress_y;
1031 force_z = force_p_z + force_stress_z;
1032 //always 3D for particle centroids
1033 r_x = x - center[0];
1034 r_y = y - center[1];
1035 r_z = z - center[2];
1036
1037 if (element_owned)
1038 {
1039 particle_surfaceArea[i] += dV * D_s;
1040 particle_volume[i] += dV * ImH_s;
1041 particle_surfaceArea_projected[i] += dV * D_s * fmax(fluid_outward_normal[0]*projection_direction[0] +
1042 fluid_outward_normal[1]*projection_direction[1] +
1043 fluid_outward_normal[2]*projection_direction[2],
1044 0.0);
1045 particle_netForces[i * 3 + 0] += force_x;
1046 particle_netForces[i * 3 + 1] += force_y;
1047 particle_netForces[i * 3 + 2] += force_z;
1048 particle_netForces[(i+ nParticles)*3+0]+= force_stress_x;
1049 particle_netForces[(i+2*nParticles)*3+0]+= force_p_x;
1050 particle_netForces[(i+ nParticles)*3+1]+= force_stress_y;
1051 particle_netForces[(i+2*nParticles)*3+1]+= force_p_y;
1052 particle_netForces[(i+ nParticles)*3+2]+= force_stress_z;
1053 particle_netForces[(i+2*nParticles)*3+2]+= force_p_z;
1054 particle_netMoments[i*3+0] += (r_y*force_z - r_z*force_y);
1055 particle_netMoments[i*3+1] += (r_z*force_x - r_x*force_z);
1056 particle_netMoments[i*3+2] += (r_x*force_y - r_y*force_x);
1057 }
1058
1059
1060 mass_source += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1061
1062 if (NONCONSERVATIVE_FORM > 0.0)
1063 {
1064 //upwinded advective flux
1065 if (!UPWIND_DIRICHLET || (fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s) < 0.0)
1066 {
1067 mom_u_source += rho*D_s*(u_s - u)*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1068 mom_v_source += rho*D_s*(v_s - v)*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1069 mom_w_source += rho*D_s*(w_s - w)*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1070 dmom_u_source[0] -= rho*D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1071 dmom_v_source[1] -= rho*D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1072 dmom_w_source[2] -= rho*D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1073 }
1074
1075 //viscous flux
1076 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]) + fluid_outward_normal[2] * (grad_u[2]+grad_w[0]));
1077 dmom_u_ham_grad_u[0] -= D_s * porosity * mu * 2 * fluid_outward_normal[0];
1078 dmom_u_ham_grad_u[1] -= D_s * porosity * mu * fluid_outward_normal[1];
1079 dmom_u_ham_grad_u[2] -= D_s * porosity * mu * fluid_outward_normal[2];
1080 dmom_u_ham_grad_v[0] -= D_s * porosity * mu * fluid_outward_normal[1];
1081 dmom_u_ham_grad_w[0] -= D_s * porosity * mu * fluid_outward_normal[2];
1082
1083 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] + fluid_outward_normal[2] * (grad_w[1]+grad_v[2]));
1084 dmom_v_ham_grad_u[1] -= D_s * porosity * mu * fluid_outward_normal[0];
1085 dmom_v_ham_grad_v[0] -= D_s * porosity * mu * fluid_outward_normal[0];
1086 dmom_v_ham_grad_v[1] -= D_s * porosity * mu * 2 * fluid_outward_normal[1];
1087 dmom_v_ham_grad_v[2] -= D_s * porosity * mu * fluid_outward_normal[2];
1088 dmom_v_ham_grad_w[1] -= D_s * porosity * mu * fluid_outward_normal[2];
1089
1090 mom_w_ham -= D_s * porosity * mu * (fluid_outward_normal[0] * (grad_u[2]+grad_w[0]) + fluid_outward_normal[1] * (grad_v[2]+grad_w[1]) + fluid_outward_normal[2]*2*grad_w[2]);
1091 dmom_w_ham_grad_u[2] -= D_s * porosity * mu * fluid_outward_normal[0];
1092 dmom_w_ham_grad_v[2] -= D_s * porosity * mu * fluid_outward_normal[1];
1093 dmom_w_ham_grad_w[0] -= D_s * porosity * mu * fluid_outward_normal[0];
1094 dmom_w_ham_grad_w[1] -= D_s * porosity * mu * fluid_outward_normal[1];
1095 dmom_w_ham_grad_w[2] -= D_s * porosity * mu * 2 * fluid_outward_normal[2];
1096
1097 //Nitsche Dirichlet penalty
1098 mom_u_source += D_s*mu*penalty * (u - u_s);
1099 dmom_u_source[0] += D_s*mu*penalty;
1100
1101 mom_v_source += D_s*mu*penalty * (v - v_s);
1102 dmom_v_source[1] += D_s*mu*penalty;
1103
1104 mom_w_source += D_s*mu*penalty * (w - w_s);
1105 dmom_w_source[2] += D_s*mu*penalty;
1106
1107 //Nitsche adjoint consistency
1108 mom_u_adv[0] += D_s * porosity * mu * fluid_outward_normal[0] * (u - u_s);
1109 mom_u_adv[1] += D_s * porosity * mu * fluid_outward_normal[1] * (u - u_s);
1110 mom_u_adv[2] += D_s * porosity * mu * fluid_outward_normal[2] * (u - u_s);
1111 dmom_u_adv_u[0] += D_s * porosity * mu * fluid_outward_normal[0];
1112 dmom_u_adv_u[1] += D_s * porosity * mu * fluid_outward_normal[1];
1113 dmom_u_adv_u[2] += D_s * porosity * mu * fluid_outward_normal[2];
1114
1115 mom_v_adv[0] += D_s * porosity * mu * fluid_outward_normal[0] * (v - v_s);
1116 mom_v_adv[1] += D_s * porosity * mu * fluid_outward_normal[1] * (v - v_s);
1117 mom_v_adv[2] += D_s * porosity * mu * fluid_outward_normal[2] * (v - v_s);
1118 dmom_v_adv_v[0] += D_s * porosity * mu * fluid_outward_normal[0];
1119 dmom_v_adv_v[1] += D_s * porosity * mu * fluid_outward_normal[1];
1120 dmom_v_adv_v[2] += D_s * porosity * mu * fluid_outward_normal[2];
1121
1122 mom_w_adv[0] += D_s * porosity * mu * fluid_outward_normal[0] * (w - w_s);
1123 mom_w_adv[1] += D_s * porosity * mu * fluid_outward_normal[1] * (w - w_s);
1124 mom_w_adv[2] += D_s * porosity * mu * fluid_outward_normal[2] * (w - w_s);
1125 dmom_w_adv_w[0] += D_s * porosity * mu * fluid_outward_normal[0];
1126 dmom_w_adv_w[1] += D_s * porosity * mu * fluid_outward_normal[1];
1127 dmom_w_adv_w[2] += D_s * porosity * mu * fluid_outward_normal[2];
1128 }
1129 else
1130 {
1131 //divided through by rho...
1132 //upwinded advective flux
1133 if (!UPWIND_DIRICHLET || (fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s) < 0.0)
1134 {
1135 mom_u_source += D_s*u_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1136 mom_v_source += D_s*v_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1137 mom_w_source += D_s*w_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1138 }
1139 else
1140 {
1141 mom_u_source += D_s*u*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1142 dmom_u_source[0] += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1143 mom_v_source += D_s*v*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1144 dmom_v_source[1] += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1145 mom_w_source += D_s*w*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1146 dmom_w_source[2] += D_s*(fluid_outward_normal[0]*u_s + fluid_outward_normal[1]*v_s + fluid_outward_normal[2]*w_s);
1147 }
1148
1149 //viscous flux
1150 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]) + fluid_outward_normal[2] * (grad_u[2]+grad_w[0]));
1151 dmom_u_ham_grad_u[0] -= D_s * porosity * nu * 2 * fluid_outward_normal[0];
1152 dmom_u_ham_grad_u[1] -= D_s * porosity * nu * fluid_outward_normal[1];
1153 dmom_u_ham_grad_u[2] -= D_s * porosity * nu * fluid_outward_normal[2];
1154 dmom_u_ham_grad_v[0] -= D_s * porosity * nu * fluid_outward_normal[1];
1155 dmom_u_ham_grad_w[0] -= D_s * porosity * nu * fluid_outward_normal[2];
1156
1157 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] + fluid_outward_normal[2] * (grad_v[2]+grad_w[1]));
1158 dmom_v_ham_grad_u[1] -= D_s * porosity * nu * fluid_outward_normal[0];
1159 dmom_v_ham_grad_v[0] -= D_s * porosity * nu * fluid_outward_normal[0];
1160 dmom_v_ham_grad_v[1] -= D_s * porosity * nu * 2 * fluid_outward_normal[1];
1161 dmom_v_ham_grad_v[2] -= D_s * porosity * nu * fluid_outward_normal[2];
1162 dmom_v_ham_grad_w[1] -= D_s * porosity * nu * fluid_outward_normal[2];
1163
1164 mom_w_ham -= D_s * porosity * nu * (fluid_outward_normal[0] * (grad_u[2]+grad_w[0]) + fluid_outward_normal[1] * (grad_v[2]+grad_w[1]) + fluid_outward_normal[2] * 2* grad_w[2] );
1165 dmom_w_ham_grad_u[2] -= D_s * porosity * nu * fluid_outward_normal[0];
1166 dmom_w_ham_grad_v[2] -= D_s * porosity * nu * fluid_outward_normal[1];
1167 dmom_w_ham_grad_w[0] -= D_s * porosity * nu * fluid_outward_normal[0];
1168 dmom_w_ham_grad_w[1] -= D_s * porosity * nu * fluid_outward_normal[1];
1169 dmom_w_ham_grad_w[2] -= D_s * porosity * nu * 2 * fluid_outward_normal[2];
1170
1171 //Nitsche Dirichlet penalty
1172 mom_u_source += D_s*nu*penalty * (u - u_s);
1173 dmom_u_source[0] += D_s*nu*penalty;
1174
1175 mom_v_source += D_s*nu*penalty * (v - v_s);
1176 dmom_v_source[1] += D_s*nu*penalty;
1177
1178 mom_w_source += D_s*nu*penalty * (w - w_s);
1179 dmom_w_source[2] += D_s*nu*penalty;
1180
1181 //Nitsche adjoint consistency
1182 mom_u_adv[0] += D_s * porosity * nu * fluid_outward_normal[0] * (u - u_s);
1183 mom_u_adv[1] += D_s * porosity * nu * fluid_outward_normal[1] * (u - u_s);
1184 mom_u_adv[2] += D_s * porosity * nu * fluid_outward_normal[2] * (u - u_s);
1185 dmom_u_adv_u[0] += D_s * porosity * nu * fluid_outward_normal[0];
1186 dmom_u_adv_u[1] += D_s * porosity * nu * fluid_outward_normal[1];
1187 dmom_u_adv_u[2] += D_s * porosity * nu * fluid_outward_normal[2];
1188
1189 mom_v_adv[0] += D_s * porosity * nu * fluid_outward_normal[0] * (v - v_s);
1190 mom_v_adv[1] += D_s * porosity * nu * fluid_outward_normal[1] * (v - v_s);
1191 mom_v_adv[2] += D_s * porosity * nu * fluid_outward_normal[2] * (v - v_s);
1192 dmom_v_adv_v[0] += D_s * porosity * nu * fluid_outward_normal[0];
1193 dmom_v_adv_v[1] += D_s * porosity * nu * fluid_outward_normal[1];
1194 dmom_v_adv_v[2] += D_s * porosity * nu * fluid_outward_normal[2];
1195
1196 mom_w_adv[0] += D_s * porosity * nu * fluid_outward_normal[0] * (w - w_s);
1197 mom_w_adv[1] += D_s * porosity * nu * fluid_outward_normal[1] * (w - w_s);
1198 mom_w_adv[2] += D_s * porosity * nu * fluid_outward_normal[2] * (w - w_s);
1199 dmom_w_adv_w[0] += D_s * porosity * nu * fluid_outward_normal[0];
1200 dmom_w_adv_w[1] += D_s * porosity * nu * fluid_outward_normal[1];
1201 dmom_w_adv_w[2] += D_s * porosity * nu * fluid_outward_normal[2];
1202 }
1203 }
1204 }
1205 //VRANS specific
1206 inline
1207 void updateDarcyForchheimerTerms_Ergun(const double NONCONSERVATIVE_FORM,
1208 /* const double linearDragFactor, */
1209 /* const double nonlinearDragFactor, */
1210 /* const double porosity, */
1211 /* const double meanGrainSize, */
1212 const double alpha,
1213 const double beta,
1214 const double eps_rho,
1215 const double eps_mu,
1216 const double rho_0,
1217 const double nu_0,
1218 const double rho_1,
1219 const double nu_1,
1220 const double useVF,
1221 const double vf,
1222 const double phi,
1223 const double u,
1224 const double v,
1225 const double w,
1226 const double uStar,
1227 const double vStar,
1228 const double wStar,
1229 const double eps_porous,
1230 const double phi_porous,
1231 const double u_porous,
1232 const double v_porous,
1233 const double w_porous,
1234 double& mom_u_source,
1235 double& mom_v_source,
1236 double& mom_w_source,
1237 double dmom_u_source[nSpace],
1238 double dmom_v_source[nSpace],
1239 double dmom_w_source[nSpace])
1240 {
1241 double rho,mu,nu,H_mu,ImH_mu, uc,duc_du,duc_dv,duc_dw,viscosity,H_porous;
1242 H_mu = (1.0-useVF)*gf.H(eps_mu,phi)+useVF*fmin(1.0,fmax(0.0,vf));
1243 ImH_mu = (1.0-useVF)*gf.ImH(eps_mu,phi)+useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
1244 nu = nu_0*ImH_mu+nu_1*H_mu;
1245 rho = rho_0*ImH_mu+rho_1*H_mu;
1246 mu = rho_0*nu_0*ImH_mu+rho_1*nu_1*H_mu;
1247 if (NONCONSERVATIVE_FORM > 0.0)
1248 {
1249 viscosity = mu;
1250 }
1251 else
1252 {
1253 viscosity = nu;
1254 }
1255 double x = fmax(0.0, fmin( 1.0, 0.5+phi_porous/(2.0*eps_porous)));//0 at phi_porous = -eps, 1 at phi_porous=eps
1256
1257 // Relaxation function, Jacobsen et al. 2011, Mayer et al 1998
1258 H_porous = (exp(pow(x,3.5)) - 1.)/ (exp(1.) - 1.);
1259
1260 //implicit
1261 /* uc = sqrt(u*u+v*v*+w*w); */
1262 /* duc_du = u/(uc+1.0e-12); */
1263 /* duc_dv = v/(uc+1.0e-12); */
1264 /* duc_dw = w/(uc+1.0e-12); */
1265 //semi-implicit quadratic term
1266 uc = sqrt(uStar*uStar+vStar*vStar+wStar*wStar);
1267 duc_du = 0.0;
1268 duc_dv = 0.0;
1269 duc_dw = 0.0;
1270
1271 mom_u_source += H_porous*viscosity*(alpha + beta*uc)*(u-u_porous);
1272 mom_v_source += H_porous*viscosity*(alpha + beta*uc)*(v-v_porous);
1273 mom_w_source += H_porous*viscosity*(alpha + beta*uc)*(w-w_porous);
1274
1275 dmom_u_source[0] = H_porous*viscosity*(alpha + beta*uc + beta*duc_du*(u-u_porous));
1276 dmom_u_source[1] = H_porous*viscosity*beta*duc_dv*(u-u_porous);
1277 dmom_u_source[2] = H_porous*viscosity*beta*duc_dw*(u-u_porous);
1278
1279 dmom_v_source[0] = H_porous*viscosity*beta*duc_du*(v-v_porous);
1280 dmom_v_source[1] = H_porous*viscosity*(alpha + beta*uc + beta*duc_dv*(v-v_porous));
1281 dmom_v_source[2] = H_porous*viscosity*beta*duc_dw*(v-v_porous);
1282
1283 dmom_w_source[0] = H_porous*viscosity*beta*duc_du*(w-w_porous);
1284 dmom_w_source[1] = H_porous*viscosity*beta*duc_dv*(w-w_porous);
1285 dmom_w_source[2] = H_porous*viscosity*(alpha + beta*uc + beta*duc_dw*(w-w_porous));
1286 }
1287
1288 inline
1289 void updateTurbulenceClosure(const double NONCONSERVATIVE_FORM,
1290 const int turbulenceClosureModel,
1291 const double eps_rho,
1292 const double eps_mu,
1293 const double rho_0,
1294 const double nu_0,
1295 const double rho_1,
1296 const double nu_1,
1297 const double useVF,
1298 const double vf,
1299 const double phi,
1300 const double porosity,
1301 const double eddy_visc_coef_0,
1302 const double turb_var_0, //k for k-eps or k-omega
1303 const double turb_var_1, //epsilon for k-epsilon, omega for k-omega
1304 const double turb_grad_0[nSpace],//grad k for k-eps,k-omega
1305 double& eddy_viscosity,
1306 double mom_uu_diff_ten[nSpace],
1307 double mom_vv_diff_ten[nSpace],
1308 double mom_ww_diff_ten[nSpace],
1309 double mom_uv_diff_ten[1],
1310 double mom_uw_diff_ten[1],
1311 double mom_vu_diff_ten[1],
1312 double mom_vw_diff_ten[1],
1313 double mom_wu_diff_ten[1],
1314 double mom_wv_diff_ten[1],
1315 double& mom_u_source,
1316 double& mom_v_source,
1317 double& mom_w_source)
1318 {
1319 /****
1320 eddy_visc_coef
1321 <= 2 LES (do nothing)
1322 == 3 k-epsilon
1323
1324 */
1325 assert (turbulenceClosureModel >=3);
1326 double rho,nu,H_mu,ImH_mu, nu_t=0.0,nu_t_keps =0.0, nu_t_komega=0.0;
1327 double isKEpsilon = 1.0, dynamic_eddy_viscosity = 0.0;
1328
1329 if (turbulenceClosureModel == 4)
1330 isKEpsilon = 0.0;
1331 H_mu = (1.0-useVF)*gf.H(eps_mu,phi)+useVF*fmin(1.0,fmax(0.0,vf));
1332 ImH_mu = (1.0-useVF)*gf.ImH(eps_mu,phi)+useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
1333 nu = nu_0*ImH_mu+nu_1*H_mu;
1334 rho = rho_0*ImH_mu+rho_1*H_mu;
1335
1336 const double twoThirds = 2.0/3.0; const double div_zero = 1.0e-2*fmin(nu_0,nu_1);
1337 mom_u_source += twoThirds*turb_grad_0[0];
1338 mom_v_source += twoThirds*turb_grad_0[1];
1339 mom_w_source += twoThirds*turb_grad_0[2];
1340
1341 //--- closure model specific ---
1342 //k-epsilon
1343 nu_t_keps = eddy_visc_coef_0*turb_var_0*turb_var_0/(fabs(turb_var_1) + div_zero);
1344 //k-omega
1345 nu_t_komega = turb_var_0/(fabs(turb_var_1) + div_zero);
1346 //
1347 nu_t = isKEpsilon*nu_t_keps + (1.0-isKEpsilon)*nu_t_komega;
1348
1349 nu_t = fmax(nu_t,1.0e-4*nu); //limit according to Lew, Buscaglia etal 01
1350 //mwf hack
1351 nu_t = fmin(nu_t,1.0e6*nu);
1352 eddy_viscosity = nu_t;
1353 if (NONCONSERVATIVE_FORM > 0.0)
1354 {
1355 dynamic_eddy_viscosity = nu_t*rho;
1356 //u momentum diffusion tensor
1357 mom_uu_diff_ten[0] += 2.0*porosity*dynamic_eddy_viscosity;
1358 mom_uu_diff_ten[1] += porosity*dynamic_eddy_viscosity;
1359 mom_uu_diff_ten[2] += porosity*dynamic_eddy_viscosity;
1360
1361 mom_uv_diff_ten[0] +=porosity*dynamic_eddy_viscosity;
1362
1363 mom_uw_diff_ten[0] +=porosity*dynamic_eddy_viscosity;
1364
1365 //v momentum diffusion tensor
1366 mom_vv_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1367 mom_vv_diff_ten[1] += 2.0*porosity*dynamic_eddy_viscosity;
1368 mom_vv_diff_ten[2] += porosity*dynamic_eddy_viscosity;
1369
1370 mom_vu_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1371
1372 mom_vw_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1373
1374 //w momentum diffusion tensor
1375 mom_ww_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1376 mom_ww_diff_ten[1] += porosity*dynamic_eddy_viscosity;
1377 mom_ww_diff_ten[2] += 2.0*porosity*dynamic_eddy_viscosity;
1378
1379 mom_wu_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1380
1381 mom_wv_diff_ten[0] += porosity*dynamic_eddy_viscosity;
1382 }
1383 else
1384 {
1385 //u momentum diffusion tensor
1386 mom_uu_diff_ten[0] += 2.0*porosity*eddy_viscosity;
1387 mom_uu_diff_ten[1] += porosity*eddy_viscosity;
1388 mom_uu_diff_ten[2] += porosity*eddy_viscosity;
1389
1390 mom_uv_diff_ten[0]+=porosity*eddy_viscosity;
1391
1392 mom_uw_diff_ten[0]+=porosity*eddy_viscosity;
1393
1394 //v momentum diffusion tensor
1395 mom_vv_diff_ten[0] += porosity*eddy_viscosity;
1396 mom_vv_diff_ten[1] += 2.0*porosity*eddy_viscosity;
1397 mom_vv_diff_ten[2] += porosity*eddy_viscosity;
1398
1399 mom_vu_diff_ten[0]+=porosity*eddy_viscosity;
1400
1401 mom_vw_diff_ten[0]+=porosity*eddy_viscosity;
1402
1403 //w momentum diffusion tensor
1404 mom_ww_diff_ten[0] += porosity*eddy_viscosity;
1405 mom_ww_diff_ten[1] += porosity*eddy_viscosity;
1406 mom_ww_diff_ten[2] += 2.0*porosity*eddy_viscosity;
1407
1408 mom_wu_diff_ten[0]+=porosity*eddy_viscosity;
1409
1410 mom_wv_diff_ten[0]+=porosity*eddy_viscosity;
1411 }
1412 }
1413
1414 inline
1415 void calculateSubgridError_tau(const double& hFactor,
1416 const double& elementDiameter,
1417 const double& dmt,
1418 const double& dm,
1419 const double df[nSpace],
1420 const double& a,
1421 const double& pfac,
1422 double& tau_v,
1423 double& tau_p,
1424 double& cfl)
1425 {
1426 double h,oneByAbsdt,density,viscosity,nrm_df;
1427 h = hFactor*elementDiameter;
1428 density = dm;
1429 viscosity = a;
1430 nrm_df=0.0;
1431 for(int I=0;I<nSpace;I++)
1432 nrm_df+=df[I]*df[I];
1433 nrm_df = sqrt(nrm_df);
1434 cfl = nrm_df/(h*density);//this is really cfl/dt, but that's what we want to know, the step controller expect this
1435 oneByAbsdt = fabs(dmt);
1436 tau_v = 1.0/(4.0*viscosity/(h*h) + inertial_term*(2.0*nrm_df/h + oneByAbsdt));
1437 tau_p = (4.0*viscosity + inertial_term*(2.0*nrm_df*h + oneByAbsdt*h*h))/pfac;
1438 }
1439
1440 inline
1441 void calculateSubgridError_tau( const double& Ct_sge,
1442 const double& Cd_sge,
1443 const double G[nSpace*nSpace],
1444 const double& G_dd_G,
1445 const double& tr_G,
1446 const double& A0,
1447 const double Ai[nSpace],
1448 const double& Kij,
1449 const double& pfac,
1450 double& tau_v,
1451 double& tau_p,
1452 double& q_cfl)
1453 {
1454 double v_d_Gv=0.0;
1455 for(int I=0;I<nSpace;I++)
1456 for (int J=0;J<nSpace;J++)
1457 v_d_Gv += Ai[I]*G[I*nSpace+J]*Ai[J];
1458 tau_v = 1.0/sqrt(inertial_term*(Ct_sge*A0*A0 + v_d_Gv + 1.0e-12) + Cd_sge*Kij*Kij*G_dd_G);
1459 tau_p = 1.0/(pfac*tr_G*tau_v);
1460 }
1461
1462 inline
1463 void calculateSubgridError_tauRes(const double& tau_p,
1464 const double& tau_v,
1465 const double& pdeResidualP,
1466 const double& pdeResidualU,
1467 const double& pdeResidualV,
1468 const double& pdeResidualW,
1469 double& subgridErrorP,
1470 double& subgridErrorU,
1471 double& subgridErrorV,
1472 double& subgridErrorW)
1473 {
1474 /* GLS pressure */
1475 subgridErrorP = -tau_p*pdeResidualP;
1476 /* GLS momentum */
1477 subgridErrorU = -tau_v*pdeResidualU;
1478 subgridErrorV = -tau_v*pdeResidualV;
1479 subgridErrorW = -tau_v*pdeResidualW;
1480 }
1481
1482 inline
1484 const double& tau_v,
1485 const double dpdeResidualP_du[nDOF_v_trial_element],
1486 const double dpdeResidualP_dv[nDOF_v_trial_element],
1487 const double dpdeResidualP_dw[nDOF_v_trial_element],
1488 const double dpdeResidualU_dp[nDOF_trial_element],
1489 const double dpdeResidualU_du[nDOF_v_trial_element],
1490 const double dpdeResidualV_dp[nDOF_trial_element],
1491 const double dpdeResidualV_dv[nDOF_v_trial_element],
1492 const double dpdeResidualW_dp[nDOF_trial_element],
1493 const double dpdeResidualW_dw[nDOF_v_trial_element],
1494 double dsubgridErrorP_du[nDOF_v_trial_element],
1495 double dsubgridErrorP_dv[nDOF_v_trial_element],
1496 double dsubgridErrorP_dw[nDOF_v_trial_element],
1497 double dsubgridErrorU_dp[nDOF_trial_element],
1498 double dsubgridErrorU_du[nDOF_v_trial_element],
1499 double dsubgridErrorV_dp[nDOF_trial_element],
1500 double dsubgridErrorV_dv[nDOF_v_trial_element],
1501 double dsubgridErrorW_dp[nDOF_trial_element],
1502 double dsubgridErrorW_dw[nDOF_v_trial_element])
1503 {
1504 for (int j=0;j<nDOF_v_trial_element;j++)
1505 {
1506 /* GLS pressure */
1507 dsubgridErrorP_du[j] = -tau_p*dpdeResidualP_du[j];
1508 dsubgridErrorP_dv[j] = -tau_p*dpdeResidualP_dv[j];
1509 dsubgridErrorP_dw[j] = -tau_p*dpdeResidualP_dw[j];
1510 /* GLS momentum*/
1511 /* u */
1512 dsubgridErrorU_du[j] = -tau_v*dpdeResidualU_du[j];
1513 /* v */
1514 dsubgridErrorV_dv[j] = -tau_v*dpdeResidualV_dv[j];
1515 /* w */
1516 dsubgridErrorW_dw[j] = -tau_v*dpdeResidualW_dw[j];
1517 }
1518 for (int j=0;j<nDOF_trial_element;j++)
1519 {
1520 /* GLS momentum*/
1521 /* u */
1522 dsubgridErrorU_dp[j] = -tau_v*dpdeResidualU_dp[j];
1523 /* v */
1524 dsubgridErrorV_dp[j] = -tau_v*dpdeResidualV_dp[j];
1525 /* w */
1526 dsubgridErrorW_dp[j] = -tau_v*dpdeResidualW_dp[j];
1527 }
1528 }
1529
1530 inline
1531 void exteriorNumericalAdvectiveFlux(const double NONCONSERVATIVE_FORM,
1532 const int& isDOFBoundary_p,
1533 const int& isDOFBoundary_u,
1534 const int& isDOFBoundary_v,
1535 const int& isDOFBoundary_w,
1536 const int& isFluxBoundary_p,
1537 const int& isFluxBoundary_u,
1538 const int& isFluxBoundary_v,
1539 const int& isFluxBoundary_w,
1540 const double& oneByRho,
1541 const double& bc_oneByRho,
1542 const double n[nSpace],
1543 const double& bc_p,
1544 const double& bc_u,
1545 const double& bc_v,
1546 const double& bc_w,
1547 const double bc_f_mass[nSpace],
1548 const double bc_f_umom[nSpace],
1549 const double bc_f_vmom[nSpace],
1550 const double bc_f_wmom[nSpace],
1551 const double& bc_flux_mass,
1552 const double& bc_flux_umom,
1553 const double& bc_flux_vmom,
1554 const double& bc_flux_wmom,
1555 const double& p,
1556 const double& u,
1557 const double& v,
1558 const double& w,
1559 const double f_mass[nSpace],
1560 const double f_umom[nSpace],
1561 const double f_vmom[nSpace],
1562 const double f_wmom[nSpace],
1563 const double df_mass_du[nSpace],
1564 const double df_mass_dv[nSpace],
1565 const double df_mass_dw[nSpace],
1566 const double df_umom_dp[nSpace],
1567 const double dham_grad[nSpace],
1568 const double df_umom_du[nSpace],
1569 const double df_umom_dv[nSpace],
1570 const double df_umom_dw[nSpace],
1571 const double df_vmom_dp[nSpace],
1572 const double df_vmom_du[nSpace],
1573 const double df_vmom_dv[nSpace],
1574 const double df_vmom_dw[nSpace],
1575 const double df_wmom_dp[nSpace],
1576 const double df_wmom_du[nSpace],
1577 const double df_wmom_dv[nSpace],
1578 const double df_wmom_dw[nSpace],
1579 double& flux_mass,
1580 double& flux_umom,
1581 double& flux_vmom,
1582 double& flux_wmom,
1583 double* velocity)
1584 {
1585 double flowSpeedNormal;
1586 flux_mass = 0.0;
1587 flux_umom = 0.0;
1588 flux_vmom = 0.0;
1589 flux_wmom = 0.0;
1590 if (NONCONSERVATIVE_FORM > 0.0)
1591 {
1592 flowSpeedNormal=n[0]*df_vmom_dv[0]+n[1]*df_umom_du[1]+n[2]*df_umom_du[2];//tricky, works for moving and fixed domains
1593 flowSpeedNormal+=n[0]*dham_grad[0]+n[1]*dham_grad[1]+n[2]*dham_grad[2];
1594 }
1595 else
1596 flowSpeedNormal=n[0]*df_vmom_dv[0]+n[1]*df_umom_du[1]+n[2]*df_umom_du[2];//tricky, works for moving and fixed domains
1597 if (isDOFBoundary_u != 1)
1598 {
1599 flux_mass += n[0] * f_mass[0];
1600 velocity[0] = f_mass[0];
1601 if (flowSpeedNormal >= 0.0)
1602 {
1603 flux_umom += n[0] * f_umom[0];
1604 flux_vmom += n[0] * f_vmom[0];
1605 flux_wmom += n[0] * f_wmom[0];
1606 }
1607 else
1608 {
1609 if (NONCONSERVATIVE_FORM > 0.0)
1610 {
1611 flux_umom += (0.0 - u) * flowSpeedNormal;
1612 }
1613 }
1614 }
1615 else
1616 {
1617 flux_mass += n[0] * f_mass[0];
1618 velocity[0] = f_mass[0];
1619 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
1620 {
1621 flux_umom += n[0] * f_umom[0];
1622 flux_vmom += n[0] * f_vmom[0];
1623 flux_wmom += n[0] * f_wmom[0];
1624 }
1625 else
1626 {
1627 if (NONCONSERVATIVE_FORM > 0.0)
1628 {
1629 flux_umom += (bc_u - u) * flowSpeedNormal;
1630 }
1631 else
1632 {
1633 flux_umom += n[0] * bc_f_umom[0];
1634 flux_vmom += n[0] * bc_f_vmom[0];
1635 flux_wmom += n[0] * bc_f_wmom[0];
1636 }
1637 }
1638 }
1639 if (isDOFBoundary_v != 1)
1640 {
1641 flux_mass += n[1] * f_mass[1];
1642 velocity[1] = f_mass[1];
1643 if (flowSpeedNormal >= 0.0)
1644 {
1645 flux_umom += n[1] * f_umom[1];
1646 flux_vmom += n[1] * f_vmom[1];
1647 flux_wmom += n[1] * f_wmom[1];
1648 }
1649 else
1650 {
1651 if (NONCONSERVATIVE_FORM > 0.0)
1652 {
1653 flux_vmom += (0.0 - v) * flowSpeedNormal;
1654 }
1655 }
1656 }
1657 else
1658 {
1659 flux_mass += n[1] * f_mass[1];
1660 velocity[1] = f_mass[1];
1661 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
1662 {
1663 flux_umom += n[1] * f_umom[1];
1664 flux_vmom += n[1] * f_vmom[1];
1665 flux_wmom += n[1] * f_wmom[1];
1666 }
1667 else
1668 {
1669 if (NONCONSERVATIVE_FORM > 0.0)
1670 {
1671 flux_vmom += (bc_v - v) * flowSpeedNormal;
1672 }
1673 else
1674 {
1675 flux_umom += n[1] * bc_f_umom[1];
1676 flux_vmom += n[1] * bc_f_vmom[1];
1677 flux_wmom += n[1] * bc_f_wmom[1];
1678 }
1679 }
1680 }
1681 if (isDOFBoundary_w != 1)
1682 {
1683 flux_mass+=n[2]*f_mass[2];
1684 velocity[2] = f_mass[2];
1685 if (flowSpeedNormal >= 0.0)
1686 {
1687 flux_umom += n[2] * f_umom[2];
1688 flux_vmom += n[2] * f_vmom[2];
1689 flux_wmom += n[2] * f_wmom[2];
1690 }
1691 else
1692 {
1693 if (NONCONSERVATIVE_FORM > 0.0)
1694 {
1695 flux_wmom += (0.0 - w) * flowSpeedNormal;
1696 }
1697 }
1698 }
1699 else
1700 {
1701 flux_mass +=n[2]*f_mass[2];
1702 velocity[2] = f_mass[2];
1703 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
1704 {
1705 flux_umom += n[2] * f_umom[2];
1706 flux_vmom += n[2] * f_vmom[2];
1707 flux_wmom += n[2] * f_wmom[2];
1708 }
1709 else
1710 {
1711 if (NONCONSERVATIVE_FORM > 0.0)
1712 {
1713 flux_wmom += (bc_w - w) * flowSpeedNormal;
1714 }
1715 else
1716 {
1717 flux_umom += n[2] * bc_f_umom[2];
1718 flux_vmom += n[2] * bc_f_vmom[2];
1719 flux_wmom += n[2] * bc_f_wmom[2];
1720 }
1721 }
1722 }
1723 if (isDOFBoundary_p == 1)
1724 {
1725 if (NONCONSERVATIVE_FORM > 0.0)
1726 {
1727 flux_umom += n[0] * (bc_p - p);
1728 flux_vmom += n[1] * (bc_p - p);
1729 flux_wmom += n[2] * (bc_p - p);
1730 }
1731 else
1732 {
1733 flux_umom += n[0] * (bc_p * bc_oneByRho - p * oneByRho);
1734 flux_vmom += n[1] * (bc_p * bc_oneByRho - p * oneByRho);
1735 flux_wmom += n[2] * (bc_p * bc_oneByRho - p * oneByRho);
1736 }
1737 }
1738 if (isFluxBoundary_p == 1)
1739 {
1740 velocity[0] += (bc_flux_mass - flux_mass) * n[0];
1741 velocity[1] += (bc_flux_mass - flux_mass) * n[1];
1742 velocity[2] += (bc_flux_mass - flux_mass) * n[2];
1743 flux_mass = bc_flux_mass;
1744 }
1745 if (isFluxBoundary_u == 1)
1746 {
1747 flux_umom = bc_flux_umom;
1748 }
1749 if (isFluxBoundary_v == 1)
1750 {
1751 flux_vmom = bc_flux_vmom;
1752 }
1753 if (isFluxBoundary_w == 1)
1754 {
1755 flux_wmom = bc_flux_wmom;
1756 }
1757 }
1758
1759 inline
1760 void exteriorNumericalAdvectiveFluxDerivatives(const double NONCONSERVATIVE_FORM,
1761 const int& isDOFBoundary_p,
1762 const int& isDOFBoundary_u,
1763 const int& isDOFBoundary_v,
1764 const int& isDOFBoundary_w,
1765 const int& isFluxBoundary_p,
1766 const int& isFluxBoundary_u,
1767 const int& isFluxBoundary_v,
1768 const int& isFluxBoundary_w,
1769 const double& oneByRho,
1770 const double n[nSpace],
1771 const double& bc_p,
1772 const double& bc_u,
1773 const double& bc_v,
1774 const double& bc_w,
1775 const double bc_f_mass[nSpace],
1776 const double bc_f_umom[nSpace],
1777 const double bc_f_vmom[nSpace],
1778 const double bc_f_wmom[nSpace],
1779 const double& bc_flux_mass,
1780 const double& bc_flux_umom,
1781 const double& bc_flux_vmom,
1782 const double& bc_flux_wmom,
1783 const double& p,
1784 const double& u,
1785 const double& v,
1786 const double& w,
1787 const double& dmom_u_acc_u,
1788 const double f_mass[nSpace],
1789 const double f_umom[nSpace],
1790 const double f_vmom[nSpace],
1791 const double f_wmom[nSpace],
1792 const double df_mass_du[nSpace],
1793 const double df_mass_dv[nSpace],
1794 const double df_mass_dw[nSpace],
1795 const double df_umom_dp[nSpace],
1796 const double dham_grad[nSpace],
1797 const double df_umom_du[nSpace],
1798 const double df_umom_dv[nSpace],
1799 const double df_umom_dw[nSpace],
1800 const double df_vmom_dp[nSpace],
1801 const double df_vmom_du[nSpace],
1802 const double df_vmom_dv[nSpace],
1803 const double df_vmom_dw[nSpace],
1804 const double df_wmom_dp[nSpace],
1805 const double df_wmom_du[nSpace],
1806 const double df_wmom_dv[nSpace],
1807 const double df_wmom_dw[nSpace],
1808 double& dflux_mass_du,
1809 double& dflux_mass_dv,
1810 double& dflux_mass_dw,
1811 double& dflux_umom_dp,
1812 double& dflux_umom_du,
1813 double& dflux_umom_dv,
1814 double& dflux_umom_dw,
1815 double& dflux_vmom_dp,
1816 double& dflux_vmom_du,
1817 double& dflux_vmom_dv,
1818 double& dflux_vmom_dw,
1819 double& dflux_wmom_dp,
1820 double& dflux_wmom_du,
1821 double& dflux_wmom_dv,
1822 double& dflux_wmom_dw)
1823 {
1824 double flowSpeedNormal;
1825 dflux_mass_du = 0.0;
1826 dflux_mass_dv = 0.0;
1827 dflux_mass_dw = 0.0;
1828
1829 dflux_umom_dp = 0.0;
1830 dflux_umom_du = 0.0;
1831 dflux_umom_dv = 0.0;
1832 dflux_umom_dw = 0.0;
1833
1834 dflux_vmom_dp = 0.0;
1835 dflux_vmom_du = 0.0;
1836 dflux_vmom_dv = 0.0;
1837 dflux_vmom_dw = 0.0;
1838
1839 dflux_wmom_dp = 0.0;
1840 dflux_wmom_du = 0.0;
1841 dflux_wmom_dv = 0.0;
1842 dflux_wmom_dw = 0.0;
1843
1844 flowSpeedNormal=n[0]*df_vmom_dv[0]+n[1]*df_umom_du[1]+n[2]*df_umom_du[2];//tricky, works for moving and fixed domains
1845 flowSpeedNormal+=NONCONSERVATIVE_FORM*(n[0]*dham_grad[0]+n[1]*dham_grad[1]+n[2]*dham_grad[2]);
1846 if (isDOFBoundary_u != 1)
1847 {
1848 dflux_mass_du += n[0] * df_mass_du[0];
1849 if (flowSpeedNormal >= 0.0)
1850 {
1851 dflux_umom_du += n[0] * df_umom_du[0];
1852 dflux_umom_dv += n[0] * df_umom_dv[0];
1853 dflux_umom_dw += n[0] * df_umom_dw[0];
1854
1855 dflux_vmom_du += n[0] * df_vmom_du[0];
1856 dflux_vmom_dv += n[0] * df_vmom_dv[0];
1857 dflux_vmom_dw += n[0] * df_vmom_dw[0];
1858
1859 dflux_wmom_du += n[0] * df_wmom_du[0];
1860 dflux_wmom_dv += n[0] * df_wmom_dv[0];
1861 dflux_wmom_dw += n[0] * df_wmom_dw[0];
1862 }
1863 else
1864 {
1865 if (NONCONSERVATIVE_FORM > 0.0)
1866 {
1867 dflux_umom_du += dmom_u_acc_u * n[0] * (0.0 - u) - flowSpeedNormal;
1868 dflux_umom_dv += dmom_u_acc_u * n[1] * (0.0 - u) ;
1869 dflux_umom_dw += dmom_u_acc_u * n[2] * (0.0 - u) ;
1870 }
1871 }
1872 }
1873 else
1874 {
1875 //cek still upwind the advection for Dirichlet?
1876 dflux_mass_du += n[0] * df_mass_du[0];
1877 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
1878 {
1879 dflux_umom_du += n[0] * df_umom_du[0];
1880 dflux_umom_dv += n[0] * df_umom_dv[0];
1881 dflux_umom_dw += n[0] * df_umom_dw[0];
1882
1883 dflux_vmom_du += n[0] * df_vmom_du[0];
1884 dflux_vmom_dv += n[0] * df_vmom_dv[0];
1885 dflux_vmom_dw += n[0] * df_vmom_dw[0];
1886
1887 dflux_wmom_du += n[0] * df_wmom_du[0];
1888 dflux_wmom_dv += n[0] * df_wmom_dv[0];
1889 dflux_wmom_dw += n[0] * df_wmom_dw[0];
1890 }
1891 else
1892 {
1893 if (NONCONSERVATIVE_FORM > 0.0)
1894 {
1895 dflux_umom_du += dmom_u_acc_u * n[0] * (bc_u - u) - flowSpeedNormal;
1896 dflux_umom_dv += dmom_u_acc_u * n[1] * (bc_u - u) ;
1897 dflux_umom_dw += dmom_u_acc_u * n[2] * (bc_u - u) ;
1898 }
1899 else
1900 {
1901 if (isDOFBoundary_v != 1)
1902 dflux_vmom_dv += n[0] * df_vmom_dv[0];
1903 if (isDOFBoundary_w != 1)
1904 dflux_wmom_dw += n[0] * df_wmom_dw[0];
1905 }
1906 }
1907 }
1908 if (isDOFBoundary_v != 1)
1909 {
1910 dflux_mass_dv += n[1] * df_mass_dv[1];
1911 if (flowSpeedNormal >= 0.0)
1912 {
1913 dflux_umom_du += n[1] * df_umom_du[1];
1914 dflux_umom_dv += n[1] * df_umom_dv[1];
1915 dflux_umom_dw += n[1] * df_umom_dw[1];
1916
1917 dflux_vmom_du += n[1] * df_vmom_du[1];
1918 dflux_vmom_dv += n[1] * df_vmom_dv[1];
1919 dflux_vmom_dw += n[1] * df_vmom_dw[1];
1920
1921 dflux_wmom_du += n[1] * df_wmom_du[1];
1922 dflux_wmom_dv += n[1] * df_wmom_dv[1];
1923 dflux_wmom_dw += n[1] * df_wmom_dw[1];
1924 }
1925 else
1926 {
1927 if (NONCONSERVATIVE_FORM > 0.0)
1928 {
1929 dflux_vmom_du += dmom_u_acc_u * n[0] * (0.0 - v);
1930 dflux_vmom_dv += dmom_u_acc_u * n[1] * (0.0 - v) - flowSpeedNormal;
1931 dflux_vmom_dw += dmom_u_acc_u * n[2] * (0.0 - v);
1932 }
1933 }
1934 }
1935 else
1936 {
1937 //cek still upwind the advection for Dirichlet?
1938 dflux_mass_dv += n[1] * df_mass_dv[1];
1939 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
1940 {
1941 dflux_umom_du += n[1] * df_umom_du[1];
1942 dflux_umom_dv += n[1] * df_umom_dv[1];
1943 dflux_umom_dw += n[1] * df_umom_dw[1];
1944
1945 dflux_vmom_du += n[1] * df_vmom_du[1];
1946 dflux_vmom_dv += n[1] * df_vmom_dv[1];
1947 dflux_vmom_dw += n[1] * df_vmom_dw[1];
1948
1949 dflux_wmom_du += n[1] * df_wmom_du[1];
1950 dflux_wmom_dv += n[1] * df_wmom_dv[1];
1951 dflux_wmom_dw += n[1] * df_wmom_dw[1];
1952 }
1953 else
1954 {
1955 if (NONCONSERVATIVE_FORM > 0.0)
1956 {
1957 dflux_vmom_du += dmom_u_acc_u * n[0] * (bc_v - v);
1958 dflux_vmom_dv += dmom_u_acc_u * n[1] * (bc_v - v) - flowSpeedNormal;
1959 dflux_vmom_dw += dmom_u_acc_u * n[2] * (bc_v - v);
1960 }
1961 else
1962 {
1963 if (isDOFBoundary_u != 1)
1964 dflux_umom_du += n[1] * df_umom_du[1];
1965 if (isDOFBoundary_w != 1)
1966 dflux_wmom_dw += n[1] * df_wmom_dw[1];
1967 }
1968 }
1969 }
1970 if (isDOFBoundary_w != 1)
1971 {
1972 dflux_mass_dw+=n[2]*df_mass_dw[2];
1973 if (flowSpeedNormal >= 0.0)
1974 {
1975 dflux_umom_du += n[2] * df_umom_du[2];
1976 dflux_umom_dv += n[2] * df_umom_dv[2];
1977 dflux_umom_dw += n[2] * df_umom_dw[2];
1978
1979 dflux_vmom_du += n[2] * df_vmom_du[2];
1980 dflux_vmom_dv += n[2] * df_vmom_dv[2];
1981 dflux_vmom_dw += n[2] * df_vmom_dw[2];
1982
1983 dflux_wmom_du += n[2] * df_wmom_du[2];
1984 dflux_wmom_dv += n[2] * df_wmom_dv[2];
1985 dflux_wmom_dw += n[2] * df_wmom_dw[2];
1986 }
1987 else
1988 {
1989 if (NONCONSERVATIVE_FORM > 0.0)
1990 {
1991 dflux_wmom_du += dmom_u_acc_u * n[0] * (0.0 - w);
1992 dflux_wmom_dv += dmom_u_acc_u * n[1] * (0.0 - w);
1993 dflux_wmom_dw += dmom_u_acc_u * n[2] * (0.0 - w) - flowSpeedNormal;
1994 }
1995 }
1996 }
1997 else
1998 {
1999 //cek still upwind the advection for Dirichlet?
2000 dflux_mass_dw += n[2]*df_mass_dw[2];
2001 if (UPWIND_DIRICHLET && flowSpeedNormal >= 0.0)
2002 {
2003 dflux_umom_du += n[2] * df_umom_du[2];
2004 dflux_umom_dv += n[2] * df_umom_dv[2];
2005 dflux_umom_dw += n[2] * df_umom_dw[2];
2006
2007 dflux_vmom_du += n[2] * df_vmom_du[2];
2008 dflux_vmom_dv += n[2] * df_vmom_dv[2];
2009 dflux_vmom_dw += n[2] * df_vmom_dw[2];
2010
2011 dflux_wmom_du += n[2] * df_wmom_du[2];
2012 dflux_wmom_dv += n[2] * df_wmom_dv[2];
2013 dflux_wmom_dw += n[2] * df_wmom_dw[2];
2014 }
2015 else
2016 {
2017 if (NONCONSERVATIVE_FORM > 0.0)
2018 {
2019 dflux_wmom_du += dmom_u_acc_u * n[0] * (0.0 - w);
2020 dflux_wmom_dv += dmom_u_acc_u * n[1] * (0.0 - w);
2021 dflux_wmom_dw += dmom_u_acc_u * n[2] * (0.0 - w) - flowSpeedNormal;
2022 }
2023 else
2024 {
2025 if (isDOFBoundary_u != 1)
2026 dflux_umom_du += n[2] * df_umom_du[2];
2027 if (isDOFBoundary_v != 1)
2028 dflux_vmom_dv += n[2] * df_vmom_dv[2];
2029 }
2030 }
2031 }
2032 if (isDOFBoundary_p == 1)
2033 {
2034 if (NONCONSERVATIVE_FORM > 0.0)
2035 {
2036 dflux_umom_dp = -n[0];
2037 dflux_vmom_dp = -n[1];
2038 dflux_wmom_dp = -n[2];
2039 }
2040 else
2041 {
2042 dflux_umom_dp = -n[0] * oneByRho;
2043 dflux_vmom_dp = -n[1] * oneByRho;
2044 dflux_wmom_dp = -n[2] * oneByRho;
2045 }
2046 }
2047 if (isFluxBoundary_p == 1)
2048 {
2049 dflux_mass_du = 0.0;
2050 dflux_mass_dv = 0.0;
2051 dflux_mass_dw = 0.0;
2052 }
2053 if (isFluxBoundary_u == 1)
2054 {
2055 dflux_umom_dp = 0.0;
2056 dflux_umom_du = 0.0;
2057 dflux_umom_dv = 0.0;
2058 dflux_umom_dw = 0.0;
2059 }
2060 if (isFluxBoundary_v == 1)
2061 {
2062 dflux_vmom_dp = 0.0;
2063 dflux_vmom_du = 0.0;
2064 dflux_vmom_dv = 0.0;
2065 dflux_vmom_dw = 0.0;
2066 }
2067 if (isFluxBoundary_w == 1)
2068 {
2069 dflux_wmom_dp = 0.0;
2070 dflux_wmom_du = 0.0;
2071 dflux_wmom_dv = 0.0;
2072 dflux_wmom_dw = 0.0;
2073 }
2074 }
2075
2076 inline
2077 void exteriorNumericalDiffusiveFlux(const double& eps,
2078 const double& phi,
2079 int* rowptr,
2080 int* colind,
2081 const int& isDOFBoundary,
2082 const int& isFluxBoundary,
2083 const double n[nSpace],
2084 double* bc_a,
2085 const double& bc_u,
2086 const double& bc_flux,
2087 double* a,
2088 const double grad_potential[nSpace],
2089 const double& u,
2090 const double& penalty,
2091 double& flux)
2092 {
2093 double diffusiveVelocityComponent_I,penaltyFlux,max_a;
2094 if(isFluxBoundary == 1)
2095 {
2096 flux = bc_flux;
2097 }
2098 else if(isDOFBoundary == 1)
2099 {
2100 flux = 0.0;
2101 max_a=0.0;
2102 for(int I=0;I<nSpace;I++)
2103 {
2104 diffusiveVelocityComponent_I=0.0;
2105 for(int m=rowptr[I];m<rowptr[I+1];m++)
2106 {
2107 diffusiveVelocityComponent_I -= a[m]*grad_potential[colind[m]];
2108 max_a = fmax(max_a,a[m]);
2109 }
2110 flux+= diffusiveVelocityComponent_I*n[I];
2111 }
2112 penaltyFlux = max_a*penalty*(u-bc_u);
2113 flux += penaltyFlux;
2114 //cek: need to investigate this issue more
2115 //contact line slip
2116 //flux*=(gf.D(eps,0) - gf.D(eps,phi))/gf.D(eps,0);
2117 }
2118 else
2119 {
2120 std::cerr<<"RANS2P: warning, diffusion term with no boundary condition set, setting diffusive flux to 0.0"<<std::endl;
2121 flux = 0.0;
2122 }
2123 }
2124
2125
2126 inline
2128 const double& phi,
2129 int* rowptr,
2130 int* colind,
2131 const int& isDOFBoundary,
2132 const int& isFluxBoundary,
2133 const double n[nSpace],
2134 double* a,
2135 const double& v,
2136 const double grad_v[nSpace],
2137 const double& penalty)
2138 {
2139 double dvel_I,tmp=0.0,max_a=0.0;
2140 if(isFluxBoundary==0 && isDOFBoundary==1)
2141 {
2142 for(int I=0;I<nSpace;I++)
2143 {
2144 dvel_I=0.0;
2145 for(int m=rowptr[I];m<rowptr[I+1];m++)
2146 {
2147 dvel_I -= a[m]*grad_v[colind[m]];
2148 max_a = fmax(max_a,a[m]);
2149 }
2150 tmp += dvel_I*n[I];
2151 }
2152 tmp +=max_a*penalty*v;
2153 //cek: need to investigate this issue more
2154 //contact line slip
2155 //tmp*=(gf.D(eps,0) - gf.D(eps,phi))/gf.D(eps,0);
2156 }
2157 return tmp;
2158 }
2159
2161 {
2162 double NONCONSERVATIVE_FORM = args.scalar<double>("NONCONSERVATIVE_FORM");
2163 double MOMENTUM_SGE = args.scalar<double>("MOMENTUM_SGE");
2164 double PRESSURE_SGE = args.scalar<double>("PRESSURE_SGE");
2165 double VELOCITY_SGE = args.scalar<double>("VELOCITY_SGE");
2166 double PRESSURE_PROJECTION_STABILIZATION = args.scalar<double>("PRESSURE_PROJECTION_STABILIZATION");
2167 xt::pyarray<double>& numerical_viscosity = args.array<double>("numerical_viscosity");
2168 xt::pyarray<double>& mesh_trial_ref = args.array<double>("mesh_trial_ref");
2169 xt::pyarray<double>& mesh_grad_trial_ref = args.array<double>("mesh_grad_trial_ref");
2170 xt::pyarray<double>& mesh_dof = args.array<double>("mesh_dof");
2171 xt::pyarray<double>& mesh_velocity_dof = args.array<double>("mesh_velocity_dof");
2172 double MOVING_DOMAIN = args.scalar<double>("MOVING_DOMAIN");
2173 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
2174 xt::pyarray<double>& x_ref = args.array<double>("x_ref");
2175 xt::pyarray<double>& dV_ref = args.array<double>("dV_ref");
2176 xt::pyarray<double>& p_trial_ref = args.array<double>("p_trial_ref");
2177 xt::pyarray<double>& p_grad_trial_ref = args.array<double>("p_grad_trial_ref");
2178 xt::pyarray<double>& p_test_ref = args.array<double>("p_test_ref");
2179 xt::pyarray<double>& p_grad_test_ref = args.array<double>("p_grad_test_ref");
2180 xt::pyarray<double>& vel_trial_ref = args.array<double>("vel_trial_ref");
2181 xt::pyarray<double>& vel_grad_trial_ref = args.array<double>("vel_grad_trial_ref");
2182 xt::pyarray<double>& vel_test_ref = args.array<double>("vel_test_ref");
2183 xt::pyarray<double>& vel_grad_test_ref = args.array<double>("vel_grad_test_ref");
2184 xt::pyarray<double>& mesh_trial_trace_ref = args.array<double>("mesh_trial_trace_ref");
2185 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.array<double>("mesh_grad_trial_trace_ref");
2186 xt::pyarray<double>& xb_ref = args.array<double>("xb_ref");
2187 xt::pyarray<double>& dS_ref = args.array<double>("dS_ref");
2188 xt::pyarray<double>& p_trial_trace_ref = args.array<double>("p_trial_trace_ref");
2189 xt::pyarray<double>& p_grad_trial_trace_ref = args.array<double>("p_grad_trial_trace_ref");
2190 xt::pyarray<double>& p_test_trace_ref = args.array<double>("p_test_trace_ref");
2191 xt::pyarray<double>& p_grad_test_trace_ref = args.array<double>("p_grad_test_trace_ref");
2192 xt::pyarray<double>& vel_trial_trace_ref = args.array<double>("vel_trial_trace_ref");
2193 xt::pyarray<double>& vel_grad_trial_trace_ref = args.array<double>("vel_grad_trial_trace_ref");
2194 xt::pyarray<double>& vel_test_trace_ref = args.array<double>("vel_test_trace_ref");
2195 xt::pyarray<double>& vel_grad_test_trace_ref = args.array<double>("vel_grad_test_trace_ref");
2196 xt::pyarray<double>& normal_ref = args.array<double>("normal_ref");
2197 xt::pyarray<double>& boundaryJac_ref = args.array<double>("boundaryJac_ref");
2198 double eb_adjoint_sigma = args.scalar<double>("eb_adjoint_sigma");
2199 xt::pyarray<double>& elementDiameter = args.array<double>("elementDiameter");
2200 xt::pyarray<double>& elementBoundaryDiameter = args.array<double>("elementBoundaryDiameter");
2201 xt::pyarray<double>& nodeDiametersArray = args.array<double>("nodeDiametersArray");
2202 double hFactor = args.scalar<double>("hFactor");
2203 int nElements_global = args.scalar<int>("nElements_global");
2204 int nElementBoundaries_owned = args.scalar<int>("nElementBoundaries_owned");
2205 double useRBLES = args.scalar<double>("useRBLES");
2206 double useMetrics = args.scalar<double>("useMetrics");
2207 double alphaBDF = args.scalar<double>("alphaBDF");
2208 double epsFact_rho = args.scalar<double>("epsFact_rho");
2209 double epsFact_mu = args.scalar<double>("epsFact_mu");
2210 double sigma = args.scalar<double>("sigma");
2211 double rho_0 = args.scalar<double>("rho_0");
2212 double nu_0 = args.scalar<double>("nu_0");
2213 double rho_1 = args.scalar<double>("rho_1");
2214 double nu_1 = args.scalar<double>("nu_1");
2215 double smagorinskyConstant = args.scalar<double>("smagorinskyConstant");
2216 int turbulenceClosureModel = args.scalar<int>("turbulenceClosureModel");
2217 double Ct_sge = args.scalar<double>("Ct_sge");
2218 double Cd_sge = args.scalar<double>("Cd_sge");
2219 double C_dc = args.scalar<double>("C_dc");
2220 double C_b = args.scalar<double>("C_b");
2221 const xt::pyarray<double>& eps_solid = args.array<double>("eps_solid");
2222 xt::pyarray<double>& phi_solid = args.array<double>("phi_solid");
2223 const xt::pyarray<double>& eps_porous = args.array<double>("eps_porous");
2224 xt::pyarray<double>& phi_porous = args.array<double>("phi_porous");
2225 const xt::pyarray<double>& q_velocity_porous = args.array<double>("q_velocity_porous");
2226 const xt::pyarray<double>& q_porosity = args.array<double>("q_porosity");
2227 const xt::pyarray<double>& q_dragAlpha = args.array<double>("q_dragAlpha");
2228 const xt::pyarray<double>& q_dragBeta = args.array<double>("q_dragBeta");
2229 const xt::pyarray<double>& q_mass_source = args.array<double>("q_mass_source");
2230 const xt::pyarray<double>& q_turb_var_0 = args.array<double>("q_turb_var_0");
2231 const xt::pyarray<double>& q_turb_var_1 = args.array<double>("q_turb_var_1");
2232 const xt::pyarray<double>& q_turb_var_grad_0 = args.array<double>("q_turb_var_grad_0");
2233 const double LAG_LES = args.scalar<double>("LAG_LES");
2234 xt::pyarray<double> & q_eddy_viscosity = args.array<double>("q_eddy_viscosity");
2235 xt::pyarray<double> & q_eddy_viscosity_last = args.array<double>("q_eddy_viscosity_last");
2236 xt::pyarray<double> & ebqe_eddy_viscosity = args.array<double>("ebqe_eddy_viscosity");
2237 xt::pyarray<double> & ebqe_eddy_viscosity_last = args.array<double>("ebqe_eddy_viscosity_last");
2238 xt::pyarray<int>& p_l2g = args.array<int>("p_l2g");
2239 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
2240 xt::pyarray<int>& rp_l2g = args.array<int>("rp_l2g");
2241 xt::pyarray<int>& rvel_l2g = args.array<int>("rvel_l2g");
2242 xt::pyarray<double>& p_dof = args.array<double>("p_dof");
2243 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
2244 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
2245 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
2246 xt::pyarray<double>& p_old_dof = args.array<double>("p_old_dof");
2247 xt::pyarray<double>& u_old_dof = args.array<double>("u_old_dof");
2248 xt::pyarray<double>& v_old_dof = args.array<double>("v_old_dof");
2249 xt::pyarray<double>& w_old_dof = args.array<double>("w_old_dof");
2250 xt::pyarray<double>& g = args.array<double>("g");
2251 const double useVF = args.scalar<double>("useVF");
2252 xt::pyarray<double>& q_rho = args.array<double>("q_rho");
2253 xt::pyarray<double>& vf = args.array<double>("vf");
2254 xt::pyarray<double>& phi = args.array<double>("phi");
2255 xt::pyarray<double>& phi_nodes = args.array<double>("phi_nodes");
2256 xt::pyarray<double>& normal_phi = args.array<double>("normal_phi");
2257 xt::pyarray<double>& kappa_phi = args.array<double>("kappa_phi");
2258 xt::pyarray<double>& q_mom_u_acc = args.array<double>("q_mom_u_acc");
2259 xt::pyarray<double>& q_mom_v_acc = args.array<double>("q_mom_v_acc");
2260 xt::pyarray<double>& q_mom_w_acc = args.array<double>("q_mom_w_acc");
2261 xt::pyarray<double>& q_mass_adv = args.array<double>("q_mass_adv");
2262 xt::pyarray<double>& q_mom_u_acc_beta_bdf = args.array<double>("q_mom_u_acc_beta_bdf");
2263 xt::pyarray<double>& q_mom_v_acc_beta_bdf = args.array<double>("q_mom_v_acc_beta_bdf");
2264 xt::pyarray<double>& q_mom_w_acc_beta_bdf = args.array<double>("q_mom_w_acc_beta_bdf");
2265 xt::pyarray<double>& q_dV = args.array<double>("q_dV");
2266 xt::pyarray<double>& q_dV_last = args.array<double>("q_dV_last");
2267 xt::pyarray<double>& q_velocity_sge = args.array<double>("q_velocity_sge");
2268 xt::pyarray<double>& q_cfl = args.array<double>("q_cfl");
2269 xt::pyarray<double>& q_numDiff_u = args.array<double>("q_numDiff_u");
2270 xt::pyarray<double>& q_numDiff_v = args.array<double>("q_numDiff_v");
2271 xt::pyarray<double>& q_numDiff_w = args.array<double>("q_numDiff_w");
2272 xt::pyarray<double>& q_numDiff_u_last = args.array<double>("q_numDiff_u_last");
2273 xt::pyarray<double>& q_numDiff_v_last = args.array<double>("q_numDiff_v_last");
2274 xt::pyarray<double>& q_numDiff_w_last = args.array<double>("q_numDiff_w_last");
2275 xt::pyarray<int>& sdInfo_u_u_rowptr = args.array<int>("sdInfo_u_u_rowptr");
2276 xt::pyarray<int>& sdInfo_u_u_colind = args.array<int>("sdInfo_u_u_colind");
2277 xt::pyarray<int>& sdInfo_u_v_rowptr = args.array<int>("sdInfo_u_v_rowptr");
2278 xt::pyarray<int>& sdInfo_u_v_colind = args.array<int>("sdInfo_u_v_colind");
2279 xt::pyarray<int>& sdInfo_u_w_rowptr = args.array<int>("sdInfo_u_w_rowptr");
2280 xt::pyarray<int>& sdInfo_u_w_colind = args.array<int>("sdInfo_u_w_colind");
2281 xt::pyarray<int>& sdInfo_v_v_rowptr = args.array<int>("sdInfo_v_v_rowptr");
2282 xt::pyarray<int>& sdInfo_v_v_colind = args.array<int>("sdInfo_v_v_colind");
2283 xt::pyarray<int>& sdInfo_v_u_rowptr = args.array<int>("sdInfo_v_u_rowptr");
2284 xt::pyarray<int>& sdInfo_v_u_colind = args.array<int>("sdInfo_v_u_colind");
2285 xt::pyarray<int>& sdInfo_v_w_rowptr = args.array<int>("sdInfo_v_w_rowptr");
2286 xt::pyarray<int>& sdInfo_v_w_colind = args.array<int>("sdInfo_v_w_colind");
2287 xt::pyarray<int>& sdInfo_w_w_rowptr = args.array<int>("sdInfo_w_w_rowptr");
2288 xt::pyarray<int>& sdInfo_w_w_colind = args.array<int>("sdInfo_w_w_colind");
2289 xt::pyarray<int>& sdInfo_w_u_rowptr = args.array<int>("sdInfo_w_u_rowptr");
2290 xt::pyarray<int>& sdInfo_w_u_colind = args.array<int>("sdInfo_w_u_colind");
2291 xt::pyarray<int>& sdInfo_w_v_rowptr = args.array<int>("sdInfo_w_v_rowptr");
2292 xt::pyarray<int>& sdInfo_w_v_colind = args.array<int>("sdInfo_w_v_colind");
2293 int offset_p = args.scalar<int>("offset_p");
2294 int offset_u = args.scalar<int>("offset_u");
2295 int offset_v = args.scalar<int>("offset_v");
2296 int offset_w = args.scalar<int>("offset_w");
2297 int stride_p = args.scalar<int>("stride_p");
2298 int stride_u = args.scalar<int>("stride_u");
2299 int stride_v = args.scalar<int>("stride_v");
2300 int stride_w = args.scalar<int>("stride_w");
2301 xt::pyarray<double>& globalResidual = args.array<double>("globalResidual");
2302 int nExteriorElementBoundaries_global = args.scalar<int>("nExteriorElementBoundaries_global");
2303 xt::pyarray<int>& exteriorElementBoundariesArray = args.array<int>("exteriorElementBoundariesArray");
2304 xt::pyarray<int>& elementBoundariesArray = args.array<int>("elementBoundariesArray");
2305 xt::pyarray<int>& elementBoundaryElementsArray = args.array<int>("elementBoundaryElementsArray");
2306 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.array<int>("elementBoundaryLocalElementBoundariesArray");
2307 xt::pyarray<double>& ebqe_vf_ext = args.array<double>("ebqe_vf_ext");
2308 xt::pyarray<double>& bc_ebqe_vf_ext = args.array<double>("bc_ebqe_vf_ext");
2309 xt::pyarray<double>& ebqe_phi_ext = args.array<double>("ebqe_phi_ext");
2310 xt::pyarray<double>& bc_ebqe_phi_ext = args.array<double>("bc_ebqe_phi_ext");
2311 xt::pyarray<double>& ebqe_normal_phi_ext = args.array<double>("ebqe_normal_phi_ext");
2312 xt::pyarray<double>& ebqe_kappa_phi_ext = args.array<double>("ebqe_kappa_phi_ext");
2313 const xt::pyarray<double>& ebqe_porosity_ext = args.array<double>("ebqe_porosity_ext");
2314 const xt::pyarray<double>& ebqe_turb_var_0 = args.array<double>("ebqe_turb_var_0");
2315 const xt::pyarray<double>& ebqe_turb_var_1 = args.array<double>("ebqe_turb_var_1");
2316 xt::pyarray<int>& isDOFBoundary_p = args.array<int>("isDOFBoundary_p");
2317 xt::pyarray<int>& isDOFBoundary_u = args.array<int>("isDOFBoundary_u");
2318 xt::pyarray<int>& isDOFBoundary_v = args.array<int>("isDOFBoundary_v");
2319 xt::pyarray<int>& isDOFBoundary_w = args.array<int>("isDOFBoundary_w");
2320 xt::pyarray<int>& isAdvectiveFluxBoundary_p = args.array<int>("isAdvectiveFluxBoundary_p");
2321 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.array<int>("isAdvectiveFluxBoundary_u");
2322 xt::pyarray<int>& isAdvectiveFluxBoundary_v = args.array<int>("isAdvectiveFluxBoundary_v");
2323 xt::pyarray<int>& isAdvectiveFluxBoundary_w = args.array<int>("isAdvectiveFluxBoundary_w");
2324 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.array<int>("isDiffusiveFluxBoundary_u");
2325 xt::pyarray<int>& isDiffusiveFluxBoundary_v = args.array<int>("isDiffusiveFluxBoundary_v");
2326 xt::pyarray<int>& isDiffusiveFluxBoundary_w = args.array<int>("isDiffusiveFluxBoundary_w");
2327 xt::pyarray<double>& ebqe_bc_p_ext = args.array<double>("ebqe_bc_p_ext");
2328 xt::pyarray<double>& ebqe_bc_flux_mass_ext = args.array<double>("ebqe_bc_flux_mass_ext");
2329 xt::pyarray<double>& ebqe_bc_flux_mom_u_adv_ext = args.array<double>("ebqe_bc_flux_mom_u_adv_ext");
2330 xt::pyarray<double>& ebqe_bc_flux_mom_v_adv_ext = args.array<double>("ebqe_bc_flux_mom_v_adv_ext");
2331 xt::pyarray<double>& ebqe_bc_flux_mom_w_adv_ext = args.array<double>("ebqe_bc_flux_mom_w_adv_ext");
2332 xt::pyarray<double>& ebqe_bc_u_ext = args.array<double>("ebqe_bc_u_ext");
2333 xt::pyarray<double>& ebqe_bc_flux_u_diff_ext = args.array<double>("ebqe_bc_flux_u_diff_ext");
2334 xt::pyarray<double>& ebqe_penalty_ext = args.array<double>("ebqe_penalty_ext");
2335 xt::pyarray<double>& ebqe_bc_v_ext = args.array<double>("ebqe_bc_v_ext");
2336 xt::pyarray<double>& ebqe_bc_flux_v_diff_ext = args.array<double>("ebqe_bc_flux_v_diff_ext");
2337 xt::pyarray<double>& ebqe_bc_w_ext = args.array<double>("ebqe_bc_w_ext");
2338 xt::pyarray<double>& ebqe_bc_flux_w_diff_ext = args.array<double>("ebqe_bc_flux_w_diff_ext");
2339 xt::pyarray<double>& q_x = args.array<double>("q_x");
2340 xt::pyarray<double>& q_u_0 = args.array<double>("q_u_0");
2341 xt::pyarray<double>& q_u_1 = args.array<double>("q_u_1");
2342 xt::pyarray<double>& q_u_2 = args.array<double>("q_u_2");
2343 xt::pyarray<double>& q_u_3 = args.array<double>("q_u_3");
2344 xt::pyarray<double>& q_velocity = args.array<double>("q_velocity");
2345 xt::pyarray<double>& ebqe_velocity = args.array<double>("ebqe_velocity");
2346 xt::pyarray<double>& flux = args.array<double>("flux");
2347 xt::pyarray<double>& elementResidual_p_save = args.array<double>("elementResidual_p_save");
2348 xt::pyarray<int>& elementFlags = args.array<int>("elementFlags");
2349 xt::pyarray<int>& boundaryFlags = args.array<int>("boundaryFlags");
2350 xt::pyarray<double>& barycenters = args.array<double>("barycenters");
2351 xt::pyarray<double>& wettedAreas = args.array<double>("wettedAreas");
2352 xt::pyarray<double>& netForces_p = args.array<double>("netForces_p");
2353 xt::pyarray<double>& netForces_v = args.array<double>("netForces_v");
2354 xt::pyarray<double>& netMoments = args.array<double>("netMoments");
2355 xt::pyarray<double>& velocityError = args.array<double>("velocityError");
2356 xt::pyarray<double>& velocityErrorNodal = args.array<double>("velocityErrorNodal");
2357 xt::pyarray<double>& forcex = args.array<double>("forcex");
2358 xt::pyarray<double>& forcey = args.array<double>("forcey");
2359 xt::pyarray<double>& forcez = args.array<double>("forcez");
2360 int use_ball_as_particle = args.scalar<int>("use_ball_as_particle");
2361 xt::pyarray<double>& ball_center = args.array<double>("ball_center");
2362 xt::pyarray<double>& ball_radius = args.array<double>("ball_radius");
2363 xt::pyarray<double>& ball_velocity = args.array<double>("ball_velocity");
2364 xt::pyarray<double>& ball_angular_velocity = args.array<double>("ball_angular_velocity");
2365 xt::pyarray<double>& ball_density = args.array<double>("ball_density");
2366 xt::pyarray<double>& particle_signed_distances = args.array<double>("particle_signed_distances");
2367 xt::pyarray<double>& particle_signed_distance_normals = args.array<double>("particle_signed_distance_normals");
2368 xt::pyarray<double>& particle_velocities = args.array<double>("particle_velocities");
2369 xt::pyarray<double>& particle_centroids = args.array<double>("particle_centroids");
2370 xt::pyarray<double>& ebqe_phi_s = args.array<double>("ebqe_phi_s");
2371 xt::pyarray<double>& ebq_global_grad_phi_s = args.array<double>("ebq_global_grad_phi_s");
2372 xt::pyarray<double>& ebq_particle_velocity_s = args.array<double>("ebq_particle_velocity_s");
2373 int nParticles = args.scalar<int>("nParticles");
2374 xt::pyarray<double>& particle_netForces = args.array<double>("particle_netForces");
2375 xt::pyarray<double>& particle_netMoments = args.array<double>("particle_netMoments");
2376 xt::pyarray<double>& particle_surfaceArea = args.array<double>("particle_surfaceArea");
2377 xt::pyarray<double>& particle_surfaceArea_projected = args.array<double>("particle_surfaceArea_projected");
2378 xt::pyarray<double>& projection_direction = args.array<double>("projection_direction");
2379 xt::pyarray<double>& particle_volume = args.array<double>("particle_volume");
2380 int nElements_owned = args.scalar<int>("nElements_owned");
2381 double particle_nitsche = args.scalar<double>("particle_nitsche");
2382 double particle_epsFact = args.scalar<double>("particle_epsFact");
2383 double particle_alpha = args.scalar<double>("particle_alpha");
2384 double particle_beta = args.scalar<double>("particle_beta");
2385 double particle_penalty_constant = args.scalar<double>("particle_penalty_constant");
2386 double ghost_penalty_constant = args.scalar<double>("ghost_penalty_constant");
2387 xt::pyarray<double>& phi_solid_nodes = args.array<double>("phi_solid_nodes");
2388 xt::pyarray<double>& distance_to_solids = args.array<double>("distance_to_solids");
2389 bool useExact = args.scalar<int>("useExact");
2390 xt::pyarray<double>& isActiveR = args.array<double>("isActiveR");
2391 xt::pyarray<double>& isActiveDOF_p = args.array<double>("isActiveDOF_p");
2392 xt::pyarray<double>& isActiveDOF_vel = args.array<double>("isActiveDOF_vel");
2393 const bool normalize_pressure = args.scalar<int>("normalize_pressure");
2394 xt::pyarray<double>& errors = args.array<double>("errors");
2395 xt::pyarray<double>& ball_u = args.array<double>("ball_u");
2396 xt::pyarray<double>& ball_v = args.array<double>("ball_v");
2397 xt::pyarray<double>& ball_w = args.array<double>("ball_w");
2398 xt::pyarray<int>& isActiveElement = args.array<int>("isActiveElement");
2399 xt::pyarray<int>& isActiveElement_last = args.array<int>("isActiveElement_last");
2400 logEvent("Entered mprans calculateResidual",6);
2401 gf.useExact = false;//useExact;
2402 gf_p.useExact = false;//useExact;
2403 gf_s.useExact = useExact;
2404 ifem_boundaries.clear();
2405 ifem_boundary_elements.clear();
2406 cutfem_boundaries.clear();
2408 const int nQuadraturePoints_global(nElements_global*nQuadraturePoints_element);
2409 //
2410 //loop over elements to compute volume integrals and load them into element and global residual
2411 //
2412 double p_dv=0.0,pa_dv=0.0,total_volume=0.0,total_surface_area=0.0,total_flux=0.0;
2413 double mesh_volume_conservation=0.0,
2414 mesh_volume_conservation_weak=0.0,
2415 mesh_volume_conservation_err_max=0.0,
2416 mesh_volume_conservation_err_max_weak=0.0,
2417 domain_volume=0.0,
2418 &p_L1=errors(0,0),&u_L1=errors(0,1),&v_L1=errors(0,2),&w_L1=errors(0,3),&velocity_L1=errors(0,4),
2419 &p_L2=errors(1,0),&u_L2=errors(1,1),&v_L2=errors(1,2),&w_L2=errors(1,3),&velocity_L2=errors(1,4),
2420 &p_LI=errors(2,0),&u_LI=errors(2,1),&v_LI=errors(2,2),&w_LI=errors(2,3),&velocity_LI=errors(2,4);
2421 p_L1=0.0; u_L1=0.0; v_L1=0.0; w_L1=0.0; velocity_L1=0.0;
2422 p_L2=0.0; u_L2=0.0; v_L2=0.0; w_L2=0.0; velocity_L2=0.0;
2423 p_LI=0.0; u_LI=0.0; v_LI=0.0; w_LI=0.0; velocity_LI=0.0;
2424 double globalConservationError=0.0;
2425 /* std::cout<<"Ball Info: center "<<ball_center[0]<<'\t'<<ball_center[1]<<std::endl */
2426 /* <<"Ball Info: radius "<<ball_radius[0]<<std::endl */
2427 /* <<"Ball Info: velocity "<<ball_velocity[0]<<'\t'<<ball_velocity[1]<<'\t'<<ball_velocity[2]<<std::endl */
2428 /* <<"Ball Info: angular "<<ball_angular_velocity[0]<<ball_angular_velocity[1]<<ball_angular_velocity[2]<<std::endl; */
2429 for(int eN=0;eN<nElements_global;eN++)
2430 {
2431 //declare local storage for element residual and initialize
2432 double elementResidual_p[nDOF_test_element],elementResidual_p_check[nDOF_test_element],elementResidual_mesh[nDOF_test_element],
2433 elementResidual_u[nDOF_v_test_element],
2434 elementResidual_v[nDOF_v_test_element],
2435 elementResidual_w[nDOF_v_test_element],
2436 pelementResidual_u[nDOF_v_test_element],
2437 pelementResidual_v[nDOF_v_test_element],
2438 pelementResidual_w[nDOF_v_test_element],
2439 velocityErrorElement[nDOF_v_test_element],
2440 eps_rho,eps_mu;
2441 bool element_active=false;
2442 isActiveElement[eN]=0;
2443 double mesh_volume_conservation_element=0.0,
2444 mesh_volume_conservation_element_weak=0.0;
2445 int particle_index=0;
2446 for (int i=0;i<nDOF_test_element;i++)
2447 {
2448 int eN_i = eN*nDOF_test_element+i;
2449 elementResidual_p_save.data()[eN_i]=0.0;
2450 elementResidual_mesh[i]=0.0;
2451 elementResidual_p[i]=0.0;
2452 elementResidual_p_check[i]=0.0;
2453 }
2454 for (int i=0;i<nDOF_v_test_element;i++)
2455 {
2456 elementResidual_u[i]=0.0;
2457 elementResidual_v[i]=0.0;
2458 elementResidual_w[i]=0.0;
2459 pelementResidual_u[i]=0.0;
2460 pelementResidual_v[i]=0.0;
2461 pelementResidual_w[i]=0.0;
2462 velocityErrorElement[i]=0.0;
2463 }//i
2464 //Use for plotting result
2465 if(use_ball_as_particle==1 && nParticles > 0)
2466 {
2467 double min_d = 1e10;
2468 for (int I=0;I<nDOF_mesh_trial_element;I++)
2469 {
2470 int index = get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),
2471 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+0],
2472 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+1],
2473 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+2],
2474 phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]]);
2475 if (phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]] < min_d)
2476 {
2477 min_d = phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]];
2478 particle_index = index;
2479 }
2480 }
2481 }
2482 else
2483 {
2484 //phi_solid_nodes is updated in PreStep
2485 }
2486 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
2487 for (int j=0;j<nDOF_mesh_trial_element;j++)
2488 {
2489 int eN_j = eN*nDOF_mesh_trial_element+j;
2490 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
2491 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
2492 }
2493 double element_nodes[nDOF_mesh_trial_element*3];
2494 for (int i=0;i<nDOF_mesh_trial_element;i++)
2495 {
2496 int eN_i=eN*nDOF_mesh_trial_element+i;
2497 for(int I=0;I<3;I++)
2498 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
2499 }//i
2500 int icase_s = gf_s.calculate(element_phi_s, element_nodes, x_ref.data(),false);
2501 if (icase_s == 0)
2502 {
2503 element_active=true;
2504 isActiveElement[eN]=1;
2505 //only works for simplices
2506 for (int ebN_element=0;ebN_element < nDOF_mesh_trial_element; ebN_element++)
2507 {
2508 const int ebN = elementBoundariesArray.data()[eN*nDOF_mesh_trial_element+ebN_element];
2509 //internal and actually a cut edge
2510 //if (elementBoundaryElementsArray.data()[ebN*2+1] != -1 && (ebN < nElementBoundaries_owned) && element_phi_s[(ebN_element+1)%nDOF_mesh_trial_element]*element_phi_s[(ebN_element+2)%nDOF_mesh_trial_element] < 0.0)
2511 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)
2512 {
2513 cutfem_boundaries.insert(ebN);
2514 if (elementBoundaryElementsArray[ebN*2 + 0] == eN)
2515 cutfem_local_boundaries[ebN] = ebN_element;
2516 }
2517 }
2518 }
2519 else if (icase_s == 1)
2520 {
2521 element_active=true;
2522 isActiveElement[eN]=1;
2523 }
2524#ifdef IFEM
2525 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);
2526 int icase = gf.calculate(element_phi, element_nodes, x_ref.data(), rho_1*nu_1, rho_0*nu_0,false,false);
2527#else
2528 int icase_p = gf_p.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,false,false);
2529 int icase = gf.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,false,false);
2530#endif
2531 if (icase == 0)
2532 {
2533 //only works for simplices
2534 for (int ebN_element=0;ebN_element < nDOF_mesh_trial_element; ebN_element++)
2535 {
2536 const int ebN = elementBoundariesArray.data()[eN*nDOF_mesh_trial_element+ebN_element];
2537 //if (elementBoundaryElementsArray.data()[ebN*2+1] != -1 && (ebN < nElementBoundaries_owned))
2538 // ifem_boundaries.insert(ebN);
2539 ifem_boundaries.insert(ebN);
2540 }
2541 }
2542 //
2543 //loop over quadrature points and compute integrands
2544 //
2545 double numDiffMax=0.0;
2546 for(int fluid_phase=0;fluid_phase < 2 - abs(icase);fluid_phase++)
2547 {
2548 for(int k=0;k<nQuadraturePoints_element;k++)
2549 {
2550 //compute indices and declare local storage
2551 int eN_k = eN*nQuadraturePoints_element+k,
2552 eN_k_nSpace = eN_k*nSpace,
2553 eN_k_3d = eN_k*3,
2554 eN_nDOF_trial_element = eN*nDOF_trial_element,
2555 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element;
2556 double p=0.0,u=0.0,v=0.0,w=0.0,
2557 grad_p[nSpace]=ZEROVEC,grad_u[nSpace]=ZEROVEC,grad_v[nSpace]=ZEROVEC,grad_w[nSpace]=ZEROVEC,
2558 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
2559 grad_p_old[nSpace]=ZEROVEC,grad_u_old[nSpace]=ZEROVEC,grad_v_old[nSpace]=ZEROVEC,grad_w_old[nSpace]=ZEROVEC,
2560 mom_u_acc=0.0,
2561 dmom_u_acc_u=0.0,
2562 mom_v_acc=0.0,
2563 dmom_v_acc_v=0.0,
2564 mom_w_acc=0.0,
2565 dmom_w_acc_w=0.0,
2566 mass_adv[nSpace]=ZEROVEC,
2567 dmass_adv_u[nSpace]=ZEROVEC,
2568 dmass_adv_v[nSpace]=ZEROVEC,
2569 dmass_adv_w[nSpace]=ZEROVEC,
2570 mass_ham=0.0,
2571 dmass_ham_u=0.0,
2572 dmass_ham_v=0.0,
2573 dmass_ham_w=0.0,
2574 mom_u_adv[nSpace]=ZEROVEC,
2575 dmom_u_adv_u[nSpace]=ZEROVEC,
2576 dmom_u_adv_v[nSpace]=ZEROVEC,
2577 dmom_u_adv_w[nSpace]=ZEROVEC,
2578 mom_v_adv[nSpace]=ZEROVEC,
2579 dmom_v_adv_u[nSpace]=ZEROVEC,
2580 dmom_v_adv_v[nSpace]=ZEROVEC,
2581 dmom_v_adv_w[nSpace]=ZEROVEC,
2582 mom_w_adv[nSpace]=ZEROVEC,
2583 dmom_w_adv_u[nSpace]=ZEROVEC,
2584 dmom_w_adv_v[nSpace]=ZEROVEC,
2585 dmom_w_adv_w[nSpace]=ZEROVEC,
2586 mom_uu_diff_ten[nSpace]=ZEROVEC,
2587 mom_vv_diff_ten[nSpace]=ZEROVEC,
2588 mom_ww_diff_ten[nSpace]=ZEROVEC,
2589 mom_uv_diff_ten[1],
2590 mom_uw_diff_ten[1],
2591 mom_vu_diff_ten[1],
2592 mom_vw_diff_ten[1],
2593 mom_wu_diff_ten[1],
2594 mom_wv_diff_ten[1],
2595 mom_u_source=0.0,
2596 mom_v_source=0.0,
2597 mom_w_source=0.0,
2598 mom_u_ham=0.0,
2599 dmom_u_ham_grad_p[nSpace]=ZEROVEC,
2600 dmom_u_ham_grad_u[nSpace]=ZEROVEC,
2601 dmom_u_ham_grad_v[nSpace]=ZEROVEC,
2602 dmom_u_ham_grad_w[nSpace]=ZEROVEC,
2603 dmom_u_ham_u=0.0,
2604 dmom_u_ham_v=0.0,
2605 dmom_u_ham_w=0.0,
2606 mom_v_ham=0.0,
2607 dmom_v_ham_grad_p[nSpace]=ZEROVEC,
2608 dmom_v_ham_grad_u[nSpace]=ZEROVEC,
2609 dmom_v_ham_grad_v[nSpace]=ZEROVEC,
2610 dmom_v_ham_grad_w[nSpace]=ZEROVEC,
2611 dmom_v_ham_u=0.0,
2612 dmom_v_ham_v=0.0,
2613 dmom_v_ham_w=0.0,
2614 mom_w_ham=0.0,
2615 dmom_w_ham_grad_p[nSpace]=ZEROVEC,
2616 dmom_w_ham_grad_u[nSpace]=ZEROVEC,
2617 dmom_w_ham_grad_v[nSpace]=ZEROVEC,
2618 dmom_w_ham_grad_w[nSpace]=ZEROVEC,
2619 dmom_w_ham_u=0.0,
2620 dmom_w_ham_v=0.0,
2621 dmom_w_ham_w=0.0,
2622 mom_u_acc_t=0.0,
2623 dmom_u_acc_u_t=0.0,
2624 mom_v_acc_t=0.0,
2625 dmom_v_acc_v_t=0.0,
2626 mom_w_acc_t=0.0,
2627 dmom_w_acc_w_t=0.0,
2628 pdeResidual_p=0.0,
2629 pdeResidual_u=0.0,
2630 pdeResidual_v=0.0,
2631 pdeResidual_w=0.0,
2632 Lstar_u_p[nDOF_test_element],
2633 Lstar_v_p[nDOF_test_element],
2634 Lstar_w_p[nDOF_test_element],
2635 Lstar_u_u[nDOF_v_test_element],
2636 Lstar_v_v[nDOF_v_test_element],
2637 Lstar_w_w[nDOF_v_test_element],
2638 Lstar_p_u[nDOF_v_test_element],
2639 Lstar_p_v[nDOF_v_test_element],
2640 Lstar_p_w[nDOF_v_test_element],
2641 subgridError_p=0.0,
2642 subgridError_u=0.0,
2643 subgridError_v=0.0,
2644 subgridError_w=0.0,
2645 tau_p=0.0,tau_p0=0.0,tau_p1=0.0,
2646 tau_v=0.0,tau_v0=0.0,tau_v1=0.0,
2647 jac[nSpace*nSpace],
2648 jacDet,
2649 jacInv[nSpace*nSpace],
2650 p_trial[nDOF_trial_element], vel_trial[nDOF_v_trial_element],
2651 p_grad_trial_ib[nDOF_trial_element*nSpace], vel_grad_trial_ib[nDOF_v_trial_element*nSpace],
2652 p_grad_trial[nDOF_trial_element*nSpace],vel_grad_trial[nDOF_v_trial_element*nSpace],
2653 p_test_dV[nDOF_trial_element],vel_test_dV[nDOF_v_test_element],
2654 p_grad_test_dV[nDOF_test_element*nSpace],vel_grad_test_dV[nDOF_v_test_element*nSpace],
2655 dV,x,y,z,xt,yt,zt,
2656 p_element_avg=0.0,
2657 //
2658 porosity,
2659 //meanGrainSize,
2660 mass_source,
2661 dmom_u_source[nSpace]=ZEROVEC,
2662 dmom_v_source[nSpace]=ZEROVEC,
2663 dmom_w_source[nSpace]=ZEROVEC,
2664 //
2665 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,
2666 //embedded solid terms
2667 mass_source_s=0.0,
2668 mom_u_source_s=0.0,
2669 mom_v_source_s=0.0,
2670 mom_w_source_s=0.0,
2671 dmom_u_source_s[nSpace]=ZEROVEC,
2672 dmom_v_source_s[nSpace]=ZEROVEC,
2673 dmom_w_source_s[nSpace]=ZEROVEC,
2674 mom_u_adv_s[nSpace]=ZEROVEC,
2675 mom_v_adv_s[nSpace]=ZEROVEC,
2676 mom_w_adv_s[nSpace]=ZEROVEC,
2677 dmom_u_adv_u_s[nSpace]=ZEROVEC,
2678 dmom_v_adv_v_s[nSpace]=ZEROVEC,
2679 dmom_w_adv_w_s[nSpace]=ZEROVEC,
2680 mom_u_ham_s=0.0,
2681 dmom_u_ham_grad_u_s[nSpace]=ZEROVEC,
2682 dmom_u_ham_grad_v_s[nSpace]=ZEROVEC,
2683 dmom_u_ham_grad_w_s[nSpace]=ZEROVEC,
2684 dmom_u_ham_u_s=0.0,
2685 dmom_u_ham_v_s=0.0,
2686 dmom_u_ham_w_s=0.0,
2687 mom_v_ham_s=0.0,
2688 dmom_v_ham_grad_u_s[nSpace]=ZEROVEC,
2689 dmom_v_ham_grad_v_s[nSpace]=ZEROVEC,
2690 dmom_v_ham_grad_w_s[nSpace]=ZEROVEC,
2691 dmom_v_ham_u_s=0.0,
2692 dmom_v_ham_v_s=0.0,
2693 dmom_v_ham_w_s=0.0,
2694 mom_w_ham_s=0.0,
2695 dmom_w_ham_grad_u_s[nSpace]=ZEROVEC,
2696 dmom_w_ham_grad_v_s[nSpace]=ZEROVEC,
2697 dmom_w_ham_grad_w_s[nSpace]=ZEROVEC,
2698 dmom_w_ham_u_s=0.0,
2699 dmom_w_ham_v_s=0.0,
2700 dmom_w_ham_w_s=0.0,
2701 mass_ham_s=0.0,
2702 dmass_ham_u_s=0.0,
2703 dmass_ham_v_s=0.0,
2704 dmass_ham_w_s=0.0;
2705 //get jacobian, etc for mapping reference element
2706 gf_s.set_quad(k);
2707 gf.set_quad(k);
2708 gf_p.set_quad(k);
2709 ck.calculateMapping_element(eN,
2710 k,
2711 mesh_dof.data(),
2712 mesh_l2g.data(),
2713 mesh_trial_ref.data(),
2714 mesh_grad_trial_ref.data(),
2715 jac,
2716 jacDet,
2717 jacInv,
2718 x,y,z);
2719 ck.calculateH_element(eN,
2720 k,
2721 nodeDiametersArray.data(),
2722 mesh_l2g.data(),
2723 mesh_trial_ref.data(),
2724 h_phi);
2725
2726 ck.calculateMappingVelocity_element(eN,
2727 k,
2728 mesh_velocity_dof.data(),
2729 mesh_l2g.data(),
2730 mesh_trial_ref.data(),
2731 xt,yt,zt);
2732 //xt=0.0;yt=0.0;zt=0.0;
2733 //std::cout<<"xt "<<xt<<'\t'<<yt<<'\t'<<zt<<std::endl;
2734 //get the physical integration weight
2735 dV = fabs(jacDet)*dV_ref.data()[k];
2736 ck.calculateG(jacInv,G,G_dd_G,tr_G);
2737 //ck.calculateGScale(G,&normal_phi.data()[eN_k_nSpace],h_phi);
2738
2739 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2740 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2741
2742 //get the trial function gradients
2743 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
2744 ck_v.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_v_trial_element*nSpace],jacInv,vel_grad_trial);
2745 for (int i=0; i < nDOF_trial_element; i++)
2746 {
2747 p_trial[i] = p_trial_ref.data()[k*nDOF_trial_element + i];
2748 p_grad_trial_ib[i*nSpace + 0] = p_grad_trial[i*nSpace+0];
2749 p_grad_trial_ib[i*nSpace + 1] = p_grad_trial[i*nSpace+1];
2750 p_grad_trial_ib[i*nSpace + 2] = p_grad_trial[i*nSpace+2];
2751 }
2752 for (int i=0; i < nDOF_v_trial_element; i++)
2753 {
2754 vel_trial[i] = vel_trial_ref.data()[k*nDOF_v_trial_element + i];
2755 vel_grad_trial_ib[i*nSpace + 0] = vel_grad_trial[i*nSpace+0];
2756 vel_grad_trial_ib[i*nSpace + 1] = vel_grad_trial[i*nSpace+1];
2757 vel_grad_trial_ib[i*nSpace + 2] = vel_grad_trial[i*nSpace+2];
2758 }
2759 if (icase == 0)
2760 {
2761#ifdef IFEMBASIS
2762 for (int i=0; i < nDOF_trial_element; i++)
2763 {
2764 if (fluid_phase == 0)
2765 {
2766 if (not std::isnan(gf_p.VA(i)))
2767 {
2768 p_trial[i] = gf_p.VA(i);
2769 p_grad_trial_ib[i*nSpace + 0] = gf_p.VA_x(i);
2770 p_grad_trial_ib[i*nSpace + 1] = gf_p.VA_y(i);
2771 p_grad_trial_ib[i*nSpace + 2] = gf_p.VA_z(i);
2772 }
2773 }
2774 else
2775 {
2776 if (not std::isnan(gf_p.VB(i)))
2777 {
2778 p_trial[i] = gf_p.VB(i);
2779 p_grad_trial_ib[i*nSpace + 0] = gf_p.VB_x(i);
2780 p_grad_trial_ib[i*nSpace + 1] = gf_p.VB_y(i);
2781 p_grad_trial_ib[i*nSpace + 2] = gf_p.VB_z(i);
2782 }
2783 }
2784 }
2785 if(nDOF_v_trial_element == nDOF_trial_element)
2786 {
2787 for (int vi=0; vi < nDOF_v_trial_element; vi++)
2788 {
2789 if (fluid_phase == 0)
2790 {
2791 if (not std::isnan(gf.VA(vi)))
2792 {
2793 vel_trial[vi] = gf.VA(vi);
2794 vel_grad_trial_ib[vi*nSpace + 0] = gf.VA_x(vi);
2795 vel_grad_trial_ib[vi*nSpace + 1] = gf.VA_y(vi);
2796 vel_grad_trial_ib[vi*nSpace + 2] = gf.VA_z(vi);
2797 }
2798 }
2799 else
2800 {
2801 if (not std::isnan(gf.VB(vi)))
2802 {
2803 vel_trial[vi] = gf.VB(vi);
2804 vel_grad_trial_ib[vi*nSpace + 0] = gf.VB_x(vi);
2805 vel_grad_trial_ib[vi*nSpace + 1] = gf.VB_y(vi);
2806 vel_grad_trial_ib[vi*nSpace + 2] = gf.VB_z(vi);
2807 }
2808 }
2809 }
2810 }
2811#endif
2812#ifndef IFEM
2813 bool prob=false;
2814 for (int vi=0; vi < nDOF_v_trial_element; vi++)
2815 {
2816 //pressure
2817 if (fabs(p_trial_ref.data()[k*nDOF_trial_element + vi] - p_trial[vi]) > 1.0e-8)
2818 {
2819 for (int vj=0; vj < nDOF_trial_element; vj++)
2820 std::cout<<"Trial "<<p_trial_ref.data()[k*nDOF_trial_element + vj]<<'\t'<<gf_p.VA(vj)<<'\t'<<gf_p.VB(vj)<<std::endl;
2821 prob=true;
2822 }
2823 if (fabs(p_grad_trial[vi*nSpace + 0] - p_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
2824 {
2825 for (int vj=0; vj < nDOF_trial_element; vj++)
2826 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;
2827 prob=true;
2828 }
2829 if (fabs(p_grad_trial[vi*nSpace + 1] - p_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
2830 {
2831 for (int vj=0; vj < nDOF_trial_element; vj++)
2832 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;
2833 prob=true;
2834 }
2835 if (fabs(p_grad_trial[vi*nSpace + 2] - p_grad_trial_ib[vi*nSpace+2]) > 1.0e-8)
2836 {
2837 for (int vj=0; vj < nDOF_trial_element; vj++)
2838 std::cout<<"Grad Trial z "<<p_grad_trial[vj*nSpace + 2]<<'\t'<<gf_p.VA_z(vj)<<'\t'<<gf_p.VB_z(vj)<<std::endl;
2839 prob=true;
2840 }
2841 //velocity
2842 if (fabs(vel_trial_ref.data()[k*nDOF_v_trial_element + vi] - vel_trial[vi]) > 1.0e-8)
2843 {
2844 for (int vj=0; vj < nDOF_v_trial_element; vj++)
2845 std::cout<<"Trial "<<vel_trial_ref.data()[k*nDOF_v_trial_element + vj]<<'\t'<<gf.VA(vj)<<'\t'<<gf.VB(vj)<<std::endl;
2846 prob=true;
2847 }
2848 if (fabs(vel_grad_trial[vi*nSpace + 0] - vel_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
2849 {
2850 for (int vj=0; vj < nDOF_v_trial_element; vj++)
2851 std::cout<<"Grad Trial x"<<vel_grad_trial[vj*nSpace + 0]<<'\t'<<gf.VA_x(vj)<<'\t'<<gf.VB_x(vj)<<std::endl;
2852 prob=true;
2853 }
2854 if (fabs(vel_grad_trial[vi*nSpace + 1] - vel_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
2855 {
2856 for (int vj=0; vj < nDOF_v_trial_element; vj++)
2857 std::cout<<"Grad Trial y "<<vel_grad_trial[vj*nSpace + 1]<<'\t'<<gf.VA_y(vj)<<'\t'<<gf.VB_y(vj)<<std::endl;
2858 prob=true;
2859 }
2860 if (fabs(vel_grad_trial[vi*nSpace + 2] - vel_grad_trial_ib[vi*nSpace+2]) > 1.0e-8)
2861 {
2862 for (int vj=0; vj < nDOF_v_trial_element; vj++)
2863 std::cout<<"Grad Trial z "<<vel_grad_trial[vj*nSpace + 2]<<'\t'<<gf.VA_z(vj)<<'\t'<<gf.VB_z(vj)<<std::endl;
2864 prob=true;
2865 }
2866 if (prob)
2867 break;
2868 }
2869 assert(!prob);
2870#endif
2871 }
2872 //get the solution
2873 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_trial,p);
2874 ck_v.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,u);
2875 ck_v.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,v);
2876 ck_v.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,w);
2877 ck.valFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_trial,p_old);
2878 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,u_old);
2879 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,v_old);
2880 ck_v.valFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_trial,w_old);
2881 //get the solution gradients
2882 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_ib,grad_p);
2883 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u);
2884 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v);
2885 ck_v.gradFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_w);
2886 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_ib,grad_p_old);
2887 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u_old);
2888 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v_old);
2889 ck_v.gradFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_w_old);
2890 // calculate the average pressure value
2891 if (PRESSURE_PROJECTION_STABILIZATION)
2892 ck.DOFaverage(p_dof.data(), &p_l2g.data()[eN_nDOF_trial_element],p_element_avg);
2893 //precalculate test function products with integration weights
2894#ifdef IFEMGALERKIN
2895 for (int j=0;j<nDOF_test_element;j++)
2896 {
2897 p_test_dV[j] = p_trial[j]*dV;
2898 for (int I=0;I<nSpace;I++)
2899 {
2900 p_grad_test_dV[j*nSpace+I] = p_grad_trial_ib[j*nSpace+I]*dV;
2901 }
2902 }
2903 //precalculate test function products with integration weights
2904 for (int j=0;j<nDOF_v_test_element;j++)
2905 {
2906 vel_test_dV[j] = vel_trial[j]*dV;
2907 for (int I=0;I<nSpace;I++)
2908 {
2909 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial_ib[j*nSpace+I]*dV;
2910 }
2911 }
2912#else
2913 for (int j=0;j<nDOF_test_element;j++)
2914 {
2915 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element+j]*dV;
2916 for (int I=0;I<nSpace;I++)
2917 {
2918 p_grad_test_dV[j*nSpace+I] = p_grad_trial[j*nSpace+I]*dV;//assume test_i = trial_i, not using ib basis here
2919 }
2920 }
2921 //precalculate test function products with integration weights
2922 for (int j=0;j<nDOF_v_test_element;j++)
2923 {
2924 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_v_trial_element+j]*dV;
2925 for (int I=0;I<nSpace;I++)
2926 {
2927 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial[j*nSpace+I]*dV;//assume test_i = trial_i
2928 }
2929 }
2930#endif
2931 //todo: extend this to higher-order meshes, for now assume mesh trial and p trial are same
2932 double div_mesh_velocity=0.0;
2933 for (int j=0;j<nDOF_trial_element;j++)
2934 {
2935 int eN_j=eN*nDOF_trial_element+j;
2936 div_mesh_velocity +=
2937 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+0]*p_grad_trial[j*nSpace+0] +
2938 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+1]*p_grad_trial[j*nSpace+1] +
2939 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+2]*p_grad_trial[j*nSpace+2];
2940 }
2941 mesh_volume_conservation_element += (alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity)*dV;
2942 div_mesh_velocity = DM3*div_mesh_velocity + (1.0-DM3)*alphaBDF*(dV-q_dV_last.data()[eN_k])/dV;
2943 //VRANS
2944 porosity = q_porosity.data()[eN_k];
2945 //
2946 q_velocity.data()[eN_k_nSpace+0]=u;
2947 q_velocity.data()[eN_k_nSpace+1]=v;
2948 q_velocity.data()[eN_k_nSpace+2]=w;
2949 q_x.data()[eN_k_3d + 0] = x;
2950 q_x.data()[eN_k_3d + 1] = y;
2951 q_x.data()[eN_k_3d + 2] = z;
2952 double ball_n[nSpace];
2953 if (use_ball_as_particle == 1 && nParticles > 0)
2954 {
2955 int ball_index=get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x,y,z,distance_to_solids.data()[eN_k]);
2956 get_normal_to_ith_ball(nParticles, ball_center.data(), ball_radius.data(),ball_index,x,y,z,ball_n[0],ball_n[1],ball_n[2]);
2957 }
2958 else
2959 {
2960 //distance_to_solids is given in Prestep
2961 }
2962 if (nParticles > 0)
2963 phi_solid.data()[eN_k] = distance_to_solids.data()[eN_k];
2964 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
2965 //
2966 //calculate pde coefficients at quadrature points
2967 //
2968 const double H_s = gf_s.H(particle_eps,phi_solid.data()[eN_k]);
2969 const double D_s = gf_s.D(particle_eps,phi_solid.data()[eN_k]);
2970 //save velocity at quadrature points for other models to use
2971 double p_e = q_u_0.data()[eN_k] - p,
2972 u_e = q_u_1.data()[eN_k] - u,
2973 v_e = q_u_2.data()[eN_k] - v,
2974 w_e = q_u_3.data()[eN_k] - w,
2975 velocity_e = sqrt(u_e*u_e + v_e*v_e + w_e*w_e);
2976
2977
2978 /* q_u_0.data()[eN_k] = p; */
2979 /* q_u_1.data()[eN_k] = u; */
2980 /* q_u_2.data()[eN_k] = v; */
2981 /* q_u_3.data()[eN_k] = w; */
2982
2983 double rho,nu;
2984 if (gf.useExact)
2985 {
2986 if (icase == 0)
2987 {
2988 if (fluid_phase == 0)
2989 {
2990 rho=rho_0;
2991 nu=nu_0;
2992 }
2993 else
2994 {
2995 rho=rho_1;
2996 nu=nu_1;
2997 }
2998 }
2999 else if (icase == -1)
3000 {
3001 rho=rho_0;
3002 nu=nu_0;
3003 }
3004 else if (icase == 1)
3005 {
3006 rho=rho_1;
3007 nu=nu_1;
3008 }
3009 else
3010 assert(false);
3011 }
3012 else
3013 {
3014 double H = (1.0-useVF)*gf.H(eps_rho,phi[eN_k]) + useVF*fmin(1.0,fmax(0.0,vf[eN_k]));
3015 double ImH = (1.0-useVF)*gf.ImH(eps_rho,phi[eN_k]) + useVF*(1.0-fmin(1.0,fmax(0.0,vf[eN_k])));
3016
3017 rho = rho_0*ImH + rho_1*H;
3018 nu = nu_0*ImH + nu_1*H;
3019 }
3020 evaluateCoefficients(NONCONSERVATIVE_FORM,
3021 sigma,
3022 rho,
3023 nu,
3024 elementDiameter.data()[eN],
3025 smagorinskyConstant,
3026 turbulenceClosureModel,
3027 g.data(),
3028 useVF,
3029 vf.data()[eN_k],
3030 phi.data()[eN_k],
3031 &normal_phi.data()[eN_k_nSpace],
3032 kappa_phi.data()[eN_k],
3033 //VRANS
3034 porosity,
3035 phi_solid.data()[eN_k],//distance to solid
3036 p_old,
3037 u_old,
3038 v_old,
3039 w_old,
3040 grad_p_old,
3041 grad_u_old,
3042 grad_v_old,
3043 grad_w_old,
3044 //
3045 p,
3046 grad_p,
3047 grad_u,
3048 grad_v,
3049 grad_w,
3050 u,
3051 v,
3052 w,
3053 LAG_LES,
3054 q_eddy_viscosity.data()[eN_k],
3055 q_eddy_viscosity_last.data()[eN_k],
3056 mom_u_acc,
3057 dmom_u_acc_u,
3058 mom_v_acc,
3059 dmom_v_acc_v,
3060 mom_w_acc,
3061 dmom_w_acc_w,
3062 mass_adv,
3063 dmass_adv_u,
3064 dmass_adv_v,
3065 dmass_adv_w,
3066 mom_u_adv,
3067 dmom_u_adv_u,
3068 dmom_u_adv_v,
3069 dmom_u_adv_w,
3070 mom_v_adv,
3071 dmom_v_adv_u,
3072 dmom_v_adv_v,
3073 dmom_v_adv_w,
3074 mom_w_adv,
3075 dmom_w_adv_u,
3076 dmom_w_adv_v,
3077 dmom_w_adv_w,
3078 mom_uu_diff_ten,
3079 mom_vv_diff_ten,
3080 mom_ww_diff_ten,
3081 mom_uv_diff_ten,
3082 mom_uw_diff_ten,
3083 mom_vu_diff_ten,
3084 mom_vw_diff_ten,
3085 mom_wu_diff_ten,
3086 mom_wv_diff_ten,
3087 mom_u_source,
3088 mom_v_source,
3089 mom_w_source,
3090 mom_u_ham,
3091 dmom_u_ham_grad_p,
3092 dmom_u_ham_grad_u,
3093 dmom_u_ham_u,
3094 dmom_u_ham_v,
3095 dmom_u_ham_w,
3096 mom_v_ham,
3097 dmom_v_ham_grad_p,
3098 dmom_v_ham_grad_v,
3099 dmom_v_ham_u,
3100 dmom_v_ham_v,
3101 dmom_v_ham_w,
3102 mom_w_ham,
3103 dmom_w_ham_grad_p,
3104 dmom_w_ham_grad_w,
3105 dmom_w_ham_u,
3106 dmom_w_ham_v,
3107 dmom_w_ham_w,
3108 forcex.data()[eN_k],
3109 forcey.data()[eN_k],
3110 forcez.data()[eN_k]);
3111 q_rho.data()[eN_k] = rho;
3112 //VRANS
3113 mass_source = q_mass_source.data()[eN_k];
3114 //todo: decide if these should be lagged or not?
3115 updateDarcyForchheimerTerms_Ergun(NONCONSERVATIVE_FORM,
3116 /* linearDragFactor, */
3117 /* nonlinearDragFactor, */
3118 /* porosity, */
3119 /* meanGrainSize, */
3120 q_dragAlpha.data()[eN_k],
3121 q_dragBeta.data()[eN_k],
3122 eps_rho,
3123 eps_mu,
3124 rho_0,
3125 nu_0,
3126 rho_1,
3127 nu_1,
3128 useVF,
3129 vf.data()[eN_k],
3130 phi.data()[eN_k],
3131 u,
3132 v,
3133 w,
3134 q_velocity_sge.data()[eN_k_nSpace+0],
3135 q_velocity_sge.data()[eN_k_nSpace+1],
3136 q_velocity_sge.data()[eN_k_nSpace+2],
3137 eps_porous.data()[elementFlags.data()[eN]],
3138 phi_porous.data()[eN_k],
3139 q_velocity_porous.data()[eN_k_nSpace+0],
3140 q_velocity_porous.data()[eN_k_nSpace+1],
3141 q_velocity_porous.data()[eN_k_nSpace+2],
3142 mom_u_source,
3143 mom_v_source,
3144 mom_w_source,
3145 dmom_u_source,
3146 dmom_v_source,
3147 dmom_w_source);
3148 //Turbulence closure model
3149 if (turbulenceClosureModel >= 3)
3150 {
3151 const double c_mu = 0.09;//mwf hack
3152 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
3153 turbulenceClosureModel,
3154 eps_rho,
3155 eps_mu,
3156 rho_0,
3157 nu_0,
3158 rho_1,
3159 nu_1,
3160 useVF,
3161 vf.data()[eN_k],
3162 phi.data()[eN_k],
3163 porosity,
3164 c_mu, //mwf hack
3165 q_turb_var_0.data()[eN_k],
3166 q_turb_var_1.data()[eN_k],
3167 &q_turb_var_grad_0.data()[eN_k_nSpace],
3168 q_eddy_viscosity.data()[eN_k],
3169 mom_uu_diff_ten,
3170 mom_vv_diff_ten,
3171 mom_ww_diff_ten,
3172 mom_uv_diff_ten,
3173 mom_uw_diff_ten,
3174 mom_vu_diff_ten,
3175 mom_vw_diff_ten,
3176 mom_wu_diff_ten,
3177 mom_wv_diff_ten,
3178 mom_u_source,
3179 mom_v_source,
3180 mom_w_source);
3181 }
3182 //
3183 //moving mesh
3184 //
3185 if (NONCONSERVATIVE_FORM > 0.0)
3186 {
3187 mom_u_ham -= MOVING_DOMAIN*dmom_u_acc_u*(grad_u[0]*xt + grad_u[1]*yt + grad_u[2]*zt);
3188 dmom_u_ham_grad_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*xt;
3189 dmom_u_ham_grad_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
3190 dmom_u_ham_grad_u[2] -= MOVING_DOMAIN*dmom_u_acc_u*zt;
3191 }
3192 else
3193 {
3194 mom_u_adv[0] -= MOVING_DOMAIN*mom_u_acc*xt;
3195 mom_u_adv[1] -= MOVING_DOMAIN*mom_u_acc*yt;
3196 mom_u_adv[2] -= MOVING_DOMAIN*mom_u_acc*zt;
3197 dmom_u_adv_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*xt;
3198 dmom_u_adv_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
3199 dmom_u_adv_u[2] -= MOVING_DOMAIN*dmom_u_acc_u*zt;
3200 }
3201
3202 if (NONCONSERVATIVE_FORM > 0.0)
3203 {
3204 mom_v_ham -= MOVING_DOMAIN*dmom_v_acc_v*(grad_v[0]*xt + grad_v[1]*yt + grad_v[2]*zt);
3205 dmom_v_ham_grad_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*xt;
3206 dmom_v_ham_grad_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
3207 dmom_v_ham_grad_v[2] -= MOVING_DOMAIN*dmom_v_acc_v*zt;
3208 }
3209 else
3210 {
3211 mom_v_adv[0] -= MOVING_DOMAIN*mom_v_acc*xt;
3212 mom_v_adv[1] -= MOVING_DOMAIN*mom_v_acc*yt;
3213 mom_v_adv[2] -= MOVING_DOMAIN*mom_v_acc*zt;
3214 dmom_v_adv_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*xt;
3215 dmom_v_adv_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
3216 dmom_v_adv_v[2] -= MOVING_DOMAIN*dmom_v_acc_v*zt;
3217 }
3218
3219 if (NONCONSERVATIVE_FORM > 0.0)
3220 {
3221 mom_w_ham -= MOVING_DOMAIN*dmom_w_acc_w*(grad_w[0]*xt + grad_w[1]*yt + grad_w[2]*zt);
3222 dmom_w_ham_grad_w[0] -= MOVING_DOMAIN*dmom_w_acc_w*xt;
3223 dmom_w_ham_grad_w[1] -= MOVING_DOMAIN*dmom_w_acc_w*yt;
3224 dmom_w_ham_grad_w[2] -= MOVING_DOMAIN*dmom_w_acc_w*zt;
3225 }
3226 else
3227 {
3228 mom_w_adv[0] -= MOVING_DOMAIN*mom_w_acc*xt;
3229 mom_w_adv[1] -= MOVING_DOMAIN*mom_w_acc*yt;
3230 mom_w_adv[2] -= MOVING_DOMAIN*mom_w_acc*zt;
3231 dmom_w_adv_w[0] -= MOVING_DOMAIN*dmom_w_acc_w*xt;
3232 dmom_w_adv_w[1] -= MOVING_DOMAIN*dmom_w_acc_w*yt;
3233 dmom_w_adv_w[2] -= MOVING_DOMAIN*dmom_w_acc_w*zt;
3234 }
3235 //
3236 //calculate time derivative at quadrature points
3237 //
3238 if (q_dV_last.data()[eN_k] <= -100)
3239 q_dV_last.data()[eN_k] = dV;
3240 q_dV.data()[eN_k] = dV;
3241 ck.bdf(alphaBDF,
3242 q_mom_u_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
3243 mom_u_acc,
3244 dmom_u_acc_u,
3245 mom_u_acc_t,
3246 dmom_u_acc_u_t);
3247 ck.bdf(alphaBDF,
3248 q_mom_v_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
3249 mom_v_acc,
3250 dmom_v_acc_v,
3251 mom_v_acc_t,
3252 dmom_v_acc_v_t);
3253 ck.bdf(alphaBDF,
3254 q_mom_w_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
3255 mom_w_acc,
3256 dmom_w_acc_w,
3257 mom_w_acc_t,
3258 dmom_w_acc_w_t);
3259
3260 if (NONCONSERVATIVE_FORM > 0.0)
3261 {
3262 mom_u_acc_t *= dmom_u_acc_u;
3263 mom_v_acc_t *= dmom_v_acc_v;
3264 mom_w_acc_t *= dmom_w_acc_w;
3265 }
3266 //
3267 //calculate subgrid error (strong residual and adjoint)
3268 //
3269 //calculate strong residual
3270 pdeResidual_p = ck.Advection_strong(dmass_adv_u,grad_u) +
3271 ck.Advection_strong(dmass_adv_v,grad_v) +
3272 ck.Advection_strong(dmass_adv_w,grad_w) +
3273 DM2*MOVING_DOMAIN*ck.Reaction_strong(alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity) +
3274 ck.Reaction_strong(mass_source);
3275
3276 if (NONCONSERVATIVE_FORM > 0.0)
3277 {
3278 dmom_adv_sge[0] = 0.0;
3279 dmom_adv_sge[1] = 0.0;
3280 dmom_adv_sge[2] = 0.0;
3281 dmom_ham_grad_sge[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt);
3282 dmom_ham_grad_sge[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
3283 dmom_ham_grad_sge[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt);
3284 }
3285 else
3286 {
3287 dmom_adv_sge[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt);
3288 dmom_adv_sge[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
3289 dmom_adv_sge[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt);
3290 dmom_ham_grad_sge[0] = 0.0;
3291 dmom_ham_grad_sge[1] = 0.0;
3292 dmom_ham_grad_sge[2] = 0.0;
3293 }
3294 double mv_tau[nSpace]=ZEROVEC;
3295 mv_tau[0] = dmom_adv_sge[0] + dmom_ham_grad_sge[0];
3296 mv_tau[1] = dmom_adv_sge[1] + dmom_ham_grad_sge[1];
3297 mv_tau[2] = dmom_adv_sge[2] + dmom_ham_grad_sge[2];
3298
3299 pdeResidual_u = ck.Mass_strong(mom_u_acc_t) +
3300 ck.Advection_strong(dmom_adv_sge,grad_u) +
3301 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_u) +
3302 ck.Hamiltonian_strong(dmom_u_ham_grad_p,grad_p) +
3303 ck.Reaction_strong(mom_u_source) -
3304 ck.Reaction_strong(dmom_u_acc_u*u*div_mesh_velocity);
3305
3306 pdeResidual_v = ck.Mass_strong(mom_v_acc_t) +
3307 ck.Advection_strong(dmom_adv_sge,grad_v) +
3308 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_v) +
3309 ck.Hamiltonian_strong(dmom_v_ham_grad_p,grad_p) +
3310 ck.Reaction_strong(mom_v_source) -
3311 ck.Reaction_strong(dmom_v_acc_v*v*div_mesh_velocity);
3312
3313 pdeResidual_w = ck.Mass_strong(mom_w_acc_t) +
3314 ck.Advection_strong(dmom_adv_sge,grad_w) +
3315 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_w) +
3316 ck.Hamiltonian_strong(dmom_w_ham_grad_p,grad_p) +
3317 ck.Reaction_strong(mom_w_source) -
3318 ck.Reaction_strong(dmom_w_acc_w*w*div_mesh_velocity);
3319
3320 //calculate tau and tau*Res
3321 //add contributions from mass and source terms
3322 double tmpR=dmom_u_acc_u_t + dmom_u_source[0];
3324 elementDiameter.data()[eN],
3325 tmpR,//dmom_u_acc_u_t,
3326 dmom_u_acc_u,
3327 mv_tau,//dmom_adv_sge,
3328 mom_uu_diff_ten[1],
3329 dmom_u_ham_grad_p[0],
3330 tau_v0,
3331 tau_p0,
3332 q_cfl.data()[eN_k]);
3333
3334 calculateSubgridError_tau(Ct_sge,Cd_sge,
3335 G,G_dd_G,tr_G,
3336 tmpR,//dmom_u_acc_u_t,
3337 mv_tau,//dmom_adv_sge,
3338 mom_uu_diff_ten[1],
3339 dmom_u_ham_grad_p[0],
3340 tau_v1,
3341 tau_p1,
3342 q_cfl.data()[eN_k]);
3343
3344 tau_v = useMetrics*tau_v1+(1.0-useMetrics)*tau_v0;
3345 tau_p = useMetrics*tau_p1+(1.0-useMetrics)*tau_p0;
3346
3348 tau_v,
3349 pdeResidual_p,
3350 pdeResidual_u,
3351 pdeResidual_v,
3352 pdeResidual_w,
3353 subgridError_p,
3354 subgridError_u,
3355 subgridError_v,
3356 subgridError_w);
3357 // velocity used in adjoint (VMS or RBLES, with or without lagging the grid scale velocity)
3358 dmom_adv_star[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt + useRBLES*subgridError_u);
3359 dmom_adv_star[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt + useRBLES*subgridError_v);
3360 dmom_adv_star[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt + useRBLES*subgridError_w);
3361
3362 mom_u_adv[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u*q_velocity_sge.data()[eN_k_nSpace+0]);
3363 mom_u_adv[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v*q_velocity_sge.data()[eN_k_nSpace+0]);
3364 mom_u_adv[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w*q_velocity_sge.data()[eN_k_nSpace+0]);
3365
3366 mom_v_adv[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u*q_velocity_sge.data()[eN_k_nSpace+1]);
3367 mom_v_adv[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v*q_velocity_sge.data()[eN_k_nSpace+1]);
3368 mom_v_adv[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w*q_velocity_sge.data()[eN_k_nSpace+1]);
3369
3370 mom_w_adv[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u*q_velocity_sge.data()[eN_k_nSpace+2]);
3371 mom_w_adv[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v*q_velocity_sge.data()[eN_k_nSpace+2]);
3372 mom_w_adv[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w*q_velocity_sge.data()[eN_k_nSpace+2]);
3373
3374 // adjoint times the test functions
3375 for (int i=0;i<nDOF_test_element;i++)
3376 {
3377 int i_nSpace = i*nSpace;
3378 Lstar_u_p[i]=ck.Advection_adjoint(dmass_adv_u,&p_grad_test_dV[i_nSpace]);
3379 Lstar_v_p[i]=ck.Advection_adjoint(dmass_adv_v,&p_grad_test_dV[i_nSpace]);
3380 Lstar_w_p[i]=ck.Advection_adjoint(dmass_adv_w,&p_grad_test_dV[i_nSpace]);
3381 }
3382 for (int i=0;i<nDOF_v_test_element;i++)
3383 {
3384 int i_nSpace = i*nSpace;
3385 //use the same advection adjoint for all three since we're approximating the linearized adjoint
3386 Lstar_u_u[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);//cek COMP/INCOMP form have same adjoint
3387 Lstar_v_v[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);//ditto
3388 Lstar_w_w[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);//ditto
3389 Lstar_p_u[i]=ck.Hamiltonian_adjoint(dmom_u_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
3390 Lstar_p_v[i]=ck.Hamiltonian_adjoint(dmom_v_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
3391 Lstar_p_w[i]=ck.Hamiltonian_adjoint(dmom_w_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
3392
3393 //VRANS account for drag terms, diagonal only here ... decide if need off diagonal terms too
3394 Lstar_u_u[i]+=ck.Reaction_adjoint(dmom_u_source[0],vel_test_dV[i]);
3395 Lstar_v_v[i]+=ck.Reaction_adjoint(dmom_v_source[1],vel_test_dV[i]);
3396 Lstar_w_w[i]+=ck.Reaction_adjoint(dmom_w_source[2],vel_test_dV[i]);
3397 //
3398 }
3399
3400 norm_Rv = sqrt(pdeResidual_u*pdeResidual_u + pdeResidual_v*pdeResidual_v + pdeResidual_w*pdeResidual_w);
3401 q_numDiff_u.data()[eN_k] = C_dc*norm_Rv*(useMetrics/sqrt(G_dd_G+1.0e-12) +
3402 (1.0-useMetrics)*hFactor*hFactor*elementDiameter.data()[eN]*elementDiameter.data()[eN]);
3403 q_numDiff_v.data()[eN_k] = q_numDiff_u.data()[eN_k];
3404 q_numDiff_w.data()[eN_k] = q_numDiff_u.data()[eN_k];
3405 numDiffMax = std::fmax(q_numDiff_u.data()[eN_k], numDiffMax);
3406 if(nParticles > 0)
3407 {
3408 //cek todo, this needs to be fixed for not exact
3409 double level_set_normal[nSpace];
3410 double sign=0.0;
3411 if (gf_s.useExact)
3412 {
3413 double norm_exact=0.0,norm_cut=0.0;
3414 if (use_ball_as_particle)
3415 {
3416 for (int I=0;I<nSpace;I++)
3417 {
3418 sign += ball_n[I]*gf_s.get_normal()[I];
3419 level_set_normal[I] = gf_s.get_normal()[I];
3420 norm_cut += level_set_normal[I]*level_set_normal[I];
3421 norm_exact += ball_n[I]*ball_n[I];
3422 }
3423 }
3424 else
3425 {
3426 for (int I=0;I<nSpace;I++)
3427 {
3428 sign += particle_signed_distance_normals.data()[eN_k_3d+I]*gf_s.get_normal()[I];
3429 level_set_normal[I] = gf_s.get_normal()[I];
3430 norm_cut += level_set_normal[I]*level_set_normal[I];
3431 norm_exact += particle_signed_distance_normals.data()[eN_k_3d+I]*particle_signed_distance_normals.data()[eN_k_3d+I];
3432 }
3433 }
3434 norm_cut = std::sqrt(norm_cut);
3435 norm_exact = std::sqrt(norm_exact);
3436 assert(std::fabs(1.0-norm_cut) < 1.0e-8);
3437 assert(std::fabs(1.0-norm_exact) < 1.0e-8);
3438 if (sign < 0.0)
3439 for (int I=0;I<nSpace;I++)
3440 level_set_normal[I]*=-1.0;
3441 /* if(icase_s==0)// && (1.0-sign*sign) > 1.0e-3) */
3442 /* { */
3443 /* std::cout<<"phi normal and cut normal divergent "<<eN<<'\t'<<k<<std::endl; */
3444 /* for (int I=0;I<nSpace;I++) */
3445 /* std::cout<<level_set_normal[I]<<'\t'<<particle_signed_distance_normals[eN_k_3d+I]<<std::endl; */
3446 /* } */
3447 }
3448 else
3449 {
3450 if (use_ball_as_particle)
3451 for (int I=0;I<nSpace;I++)
3452 level_set_normal[I] = ball_n[I];
3453 else
3454 for (int I=0;I<nSpace;I++)
3455 level_set_normal[I] = particle_signed_distance_normals.data()[eN_k_3d+I];
3456 }
3457 updateSolidParticleTerms(particle_index,
3458 NONCONSERVATIVE_FORM,
3459 eN < nElements_owned,
3460 particle_nitsche,
3461 dV,
3462 nParticles,
3463 nQuadraturePoints_global,
3464 &particle_signed_distances.data()[eN_k],
3465 level_set_normal,
3466 &particle_velocities.data()[eN_k_3d],
3467 particle_centroids.data(),
3468 use_ball_as_particle,
3469 ball_center.data(),
3470 ball_radius.data(),
3471 ball_velocity.data(),
3472 ball_angular_velocity.data(),
3473 ball_density.data(),
3474 porosity,
3475 particle_penalty_constant/h_phi,//penalty,
3476 particle_alpha,
3477 particle_beta,
3478 eps_rho,
3479 eps_mu,
3480 rho_0,
3481 nu_0,
3482 rho_1,
3483 nu_1,
3484 useVF,
3485 vf.data()[eN_k],
3486 phi.data()[eN_k],
3487 x,
3488 y,
3489 z,
3490 p,
3491 u,
3492 v,
3493 w,
3494 q_velocity_sge.data()[eN_k_nSpace+0],
3495 q_velocity_sge.data()[eN_k_nSpace+1],
3496 q_velocity_sge.data()[eN_k_nSpace+2],
3497 particle_eps,
3498 grad_u,
3499 grad_v,
3500 grad_w,
3501 mass_source_s,
3502 mom_u_source_s,
3503 mom_v_source_s,
3504 mom_w_source_s,
3505 dmom_u_source_s,
3506 dmom_v_source_s,
3507 dmom_w_source_s,
3508 mom_u_adv_s,
3509 mom_v_adv_s,
3510 mom_w_adv_s,
3511 dmom_u_adv_u_s,
3512 dmom_v_adv_v_s,
3513 dmom_w_adv_w_s,
3514 mom_u_ham_s,
3515 dmom_u_ham_grad_u_s,
3516 dmom_u_ham_grad_v_s,
3517 dmom_u_ham_grad_w_s,
3518 dmom_u_ham_u_s,
3519 dmom_u_ham_v_s,
3520 dmom_u_ham_w_s,
3521 mom_v_ham_s,
3522 dmom_v_ham_grad_u_s,
3523 dmom_v_ham_grad_v_s,
3524 dmom_v_ham_grad_w_s,
3525 dmom_v_ham_u_s,
3526 dmom_v_ham_v_s,
3527 dmom_v_ham_w_s,
3528 mom_w_ham_s,
3529 dmom_w_ham_grad_u_s,
3530 dmom_w_ham_grad_v_s,
3531 dmom_w_ham_grad_w_s,
3532 dmom_w_ham_u_s,
3533 dmom_w_ham_v_s,
3534 dmom_w_ham_w_s,
3535 mass_ham_s,
3536 dmass_ham_u_s,
3537 dmass_ham_v_s,
3538 dmass_ham_w_s,
3539 particle_netForces.data(),
3540 particle_netMoments.data(),
3541 particle_surfaceArea.data(),
3542 particle_surfaceArea_projected.data(),
3543 projection_direction.data(),
3544 particle_volume.data());
3545 }
3546 //
3547 //save momentum for time history and velocity for subgrid error
3548 //
3549 //cek this needs to go with the particle term updates if moved--or check particle_velocities[...] array
3550 //cek on cut cells this is getting set twice. For now it's identical because of our formulations (neither includes density so it's either velocity or porosity*velocity--same for both phases
3551 //cek but this won't be right when we use a modified basis because we'll need the whole phase velocity from its basis. hmm. special backward euler class that tracks both?
3552 //same situation with subgrid error velocity
3553 //cek since this is for the history, could try using the solid velocity inside the solid instead of just in inactive elements as before
3554 //this avoids using the fluid values inside the solid that necessarily over/undershoot to give the right values inside the fluid domain
3555 //but then the mass quadrature would represent a function that is no longer polynomial on the element so leaving it as element_active
3556 //for now--alternative would be:
3557 //if (phi_solid.data()[eN_k] > 0)
3558 if (element_active)
3559 {
3560 q_mom_u_acc.data()[eN_k] = mom_u_acc;
3561 q_mom_v_acc.data()[eN_k] = mom_v_acc;
3562 q_mom_w_acc.data()[eN_k] = mom_w_acc;
3563 //subgrid error uses grid scale velocity
3564 q_mass_adv.data()[eN_k_nSpace+0] = u;
3565 q_mass_adv.data()[eN_k_nSpace+1] = v;
3566 q_mass_adv.data()[eN_k_nSpace+2] = w;
3567 }
3568 else//use the solid velocity
3569 {
3570 if (use_ball_as_particle)
3571 {
3572 q_mom_u_acc.data()[eN_k] = particle_velocities.data()[eN_k_3d+0];
3573 q_mom_v_acc.data()[eN_k] = particle_velocities.data()[eN_k_3d+1];
3574 q_mom_w_acc.data()[eN_k] = particle_velocities.data()[eN_k_3d+2];
3575 q_mass_adv.data()[eN_k_nSpace+0] = particle_velocities.data()[eN_k_3d+0];
3576 q_mass_adv.data()[eN_k_nSpace+1] = particle_velocities.data()[eN_k_3d+1];
3577 q_mass_adv.data()[eN_k_nSpace+2] = particle_velocities.data()[eN_k_3d+2];
3578 }
3579 else
3580 {
3581 q_mom_u_acc.data()[eN_k] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+0];
3582 q_mom_v_acc.data()[eN_k] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+1];
3583 q_mom_w_acc.data()[eN_k] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+2];
3584 q_mass_adv.data()[eN_k_nSpace+0] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+0];
3585 q_mass_adv.data()[eN_k_nSpace+1] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+1];
3586 q_mass_adv.data()[eN_k_nSpace+2] = particle_velocities.data()[particle_index*nQuadraturePoints_global + eN_k_3d+2];
3587 }
3588 }
3589 //
3590 //update element residual
3591 //
3592 double mesh_vel[nSpace];
3593 mesh_vel[0] = xt;
3594 mesh_vel[1] = yt;
3595 mesh_vel[2] = zt;
3596 double H_f=1.0;
3597 if (gf.useExact && icase == 0)
3598 {
3599 if (fluid_phase == 0)
3600 H_f = gf.ImH(0.,0.);
3601 else
3602 H_f = gf.H(0.,0.);
3603 }
3604 else
3605 H_f = 1.0;
3606 if (icase == 0)
3607 {
3608 //std::cout<<"H_f "<<H_f<<" fluid_phase "<<fluid_phase<<" eN "<<eN<<std::endl;
3609 }
3610 else
3611 {
3612 assert(H_f == 1);
3613 }
3614 if ((eN < nElements_owned) && isActiveElement[eN])
3615 {
3616 domain_volume += H_s*dV*H_f;
3617 p_L1 += fabs(p_e)*H_s*dV*H_f;
3618 u_L1 += fabs(u_e)*H_s*dV*H_f;
3619 v_L1 += fabs(v_e)*H_s*dV*H_f;
3620 w_L1 += fabs(w_e)*H_s*dV*H_f;
3621 velocity_L1 += fabs(velocity_e)*H_s*dV*H_f;
3622
3623 p_L2 += p_e*p_e*H_s*dV*H_f;
3624 u_L2 += u_e*u_e*H_s*dV*H_f;
3625 v_L2 += v_e*v_e*H_s*dV*H_f;
3626 w_L2 += w_e*w_e*H_s*dV*H_f;
3627 velocity_L2 += velocity_e*velocity_e*H_s*dV*H_f;
3628 p_dv += p*H_s*H_f*dV;
3629 pa_dv += q_u_0.data()[eN_k]*H_s*H_f*dV;
3630 total_volume+=H_s*H_f*dV;
3631 total_surface_area+=D_s*H_f*dV;
3632 if (phi_solid.data()[eN_k] >= 0.0)
3633 {
3634 p_LI = fmax(p_LI, fabs(p_e));
3635 u_LI = fmax(u_LI, fabs(u_e));
3636 v_LI = fmax(v_LI, fabs(v_e));
3637 w_LI = fmax(w_LI, fabs(w_e));
3638 velocity_LI = fmax(velocity_LI, fabs(velocity_e));
3639 }
3640 }
3641 for(int i=0;i<nDOF_test_element;i++)
3642 {
3643 int i_nSpace=i*nSpace;
3644 elementResidual_mesh[i] += H_s*H_f*(ck.Reaction_weak(1.0,p_test_dV[i]) -
3645 ck.Reaction_weak(1.0,p_test_dV[i]*q_dV_last.data()[eN_k]/dV) -
3646 ck.Advection_weak(mesh_vel,&p_grad_test_dV[i_nSpace]));
3647 elementResidual_p[i] += H_s*H_f*(ck.Advection_weak(mass_adv,&p_grad_test_dV[i_nSpace])
3648 + ck.Hamiltonian_weak(mass_ham, p_test_dV[i])
3649 + DM*MOVING_DOMAIN*(ck.Reaction_weak(alphaBDF*1.0,p_test_dV[i]) -
3650 ck.Reaction_weak(alphaBDF*1.0,p_test_dV[i]*q_dV_last.data()[eN_k]/dV) -
3651 ck.Advection_weak(mesh_vel,&p_grad_test_dV[i_nSpace])) +
3652 ck.Reaction_weak(mass_source,p_test_dV[i]));
3653 if (nDOF_test_element == nDOF_v_test_element)
3654 {
3655 elementResidual_p[i] +=
3656 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) +
3657 (1 - PRESSURE_PROJECTION_STABILIZATION) * ck.SubgridError(subgridError_u,Lstar_u_p[i]) +
3658 (1 - PRESSURE_PROJECTION_STABILIZATION) * ck.SubgridError(subgridError_v,Lstar_v_p[i]) +
3659 (1 - PRESSURE_PROJECTION_STABILIZATION) * ck.SubgridError(subgridError_w,Lstar_w_p[i]));
3660 }
3661 if (PRESSURE_PROJECTION_STABILIZATION==1. && mom_uu_diff_ten[1]==0.)
3662 {
3663 printf("Warning the Bochev-Dohrnmann-Gunzburger stabilization cannot be applied to inviscid fluids.");
3664 }
3665 if (nParticles > 0)//solid boundary terms
3666 {
3667 if (gf_s.D(0.,0.) == 0.0)
3668 assert(mass_source_s == 0.0);
3669 elementResidual_p[i] += H_f*(ck.Reaction_weak(mass_source_s,p_test_dV[i]));
3670 }
3671 }
3672 for(int i=0;i<nDOF_v_test_element;i++)
3673 {
3674 int i_nSpace=i*nSpace;
3675 elementResidual_u[i] += H_s*H_f*(ck.Mass_weak(mom_u_acc_t,vel_test_dV[i]) +
3676 ck.Advection_weak(mom_u_adv,&vel_grad_test_dV[i_nSpace]) +
3677 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]) +
3678 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]) +
3679 ck.Diffusion_weak(sdInfo_u_w_rowptr.data(),sdInfo_u_w_colind.data(),mom_uw_diff_ten,grad_w,&vel_grad_test_dV[i_nSpace]) +
3680 ck.Reaction_weak(mom_u_source+NONCONSERVATIVE_FORM*dmom_u_acc_u*u*div_mesh_velocity,vel_test_dV[i]) +
3681 ck.Hamiltonian_weak(mom_u_ham,vel_test_dV[i]) +
3682 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridError(subgridError_u,Lstar_u_u[i]) +
3683 ck.NumericalDiffusion(q_numDiff_u_last.data()[eN_k],grad_u,&vel_grad_test_dV[i_nSpace]));
3684 elementResidual_v[i] += H_s*H_f*(ck.Mass_weak(mom_v_acc_t,vel_test_dV[i]) +
3685 ck.Advection_weak(mom_v_adv,&vel_grad_test_dV[i_nSpace]) +
3686 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]) +
3687 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]) +
3688 ck.Diffusion_weak(sdInfo_v_w_rowptr.data(),sdInfo_v_w_colind.data(),mom_vw_diff_ten,grad_w,&vel_grad_test_dV[i_nSpace]) +
3689 ck.Reaction_weak(mom_v_source+NONCONSERVATIVE_FORM*dmom_v_acc_v*v*div_mesh_velocity,vel_test_dV[i]) +
3690 ck.Hamiltonian_weak(mom_v_ham,vel_test_dV[i]) +
3691 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridError(subgridError_v,Lstar_v_v[i]) +
3692 ck.NumericalDiffusion(q_numDiff_v_last.data()[eN_k],grad_v,&vel_grad_test_dV[i_nSpace]));
3693 elementResidual_w[i] += H_s*H_f*(ck.Mass_weak(mom_w_acc_t,vel_test_dV[i]) +
3694 ck.Advection_weak(mom_w_adv,&vel_grad_test_dV[i_nSpace]) +
3695 ck.Diffusion_weak(sdInfo_w_u_rowptr.data(),sdInfo_w_u_colind.data(),mom_wu_diff_ten,grad_u,&vel_grad_test_dV[i_nSpace]) +
3696 ck.Diffusion_weak(sdInfo_w_v_rowptr.data(),sdInfo_w_v_colind.data(),mom_wv_diff_ten,grad_v,&vel_grad_test_dV[i_nSpace]) +
3697 ck.Diffusion_weak(sdInfo_w_w_rowptr.data(),sdInfo_w_w_colind.data(),mom_ww_diff_ten,grad_w,&vel_grad_test_dV[i_nSpace]) +
3698 ck.Reaction_weak(mom_w_source+NONCONSERVATIVE_FORM*dmom_w_acc_w*w*div_mesh_velocity,vel_test_dV[i]) +
3699 ck.Hamiltonian_weak(mom_w_ham,vel_test_dV[i]) +
3700 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridError(subgridError_w,Lstar_w_w[i]) +
3701 ck.NumericalDiffusion(q_numDiff_w_last.data()[eN_k],grad_w,&vel_grad_test_dV[i_nSpace]));
3702 elementResidual_u[i] += H_s*H_f*MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridError(subgridError_p,Lstar_p_u[i]);
3703 elementResidual_v[i] += H_s*H_f*MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridError(subgridError_p,Lstar_p_v[i]);
3704 elementResidual_w[i] += H_s*H_f*MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridError(subgridError_p,Lstar_p_w[i]);
3705 if (nParticles > 0)//solid boundary terms
3706 {
3707 elementResidual_u[i] += H_f*(ck.Advection_weak(mom_u_adv_s,&vel_grad_test_dV[i_nSpace]) +
3708 ck.Reaction_weak(mom_u_source_s,vel_test_dV[i]) +
3709 ck.Hamiltonian_weak(mom_u_ham_s,vel_test_dV[i]));
3710 elementResidual_v[i] += H_f*(ck.Advection_weak(mom_v_adv_s,&vel_grad_test_dV[i_nSpace]) +
3711 ck.Reaction_weak(mom_v_source_s,vel_test_dV[i]) +
3712 ck.Hamiltonian_weak(mom_v_ham_s,vel_test_dV[i]));
3713 elementResidual_w[i] += H_f*(ck.Advection_weak(mom_w_adv_s,&vel_grad_test_dV[i_nSpace]) +
3714 ck.Reaction_weak(mom_w_source_s,vel_test_dV[i]) +
3715 ck.Hamiltonian_weak(mom_w_ham_s,vel_test_dV[i]));
3716 }
3717 }//i
3718 //estimate the numerical viscosity combining shock capturing and VMS/SUPG
3719 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]+
3720 dmom_adv_star[1]*dmom_adv_star[1]+
3721 dmom_adv_star[2]*dmom_adv_star[2]);
3722 if (!isActiveElement[eN])
3723 {
3724 assert(std::fabs(gf_s.H(particle_eps,phi_solid.data()[eN_k])) == 0.0);
3725 assert(std::fabs(gf_s.D(particle_eps,phi_solid.data()[eN_k])) == 0.0);
3726 }
3727 }//k
3728 }//fluid_phase
3729#ifdef MAXNUMDIFF
3730 for(int k=0;k<nQuadraturePoints_element;k++)
3731 {
3732 //compute indices and declare local storage
3733 int eN_k = eN*nQuadraturePoints_element+k;
3734 q_numDiff_u.data()[eN_k] = numDiffMax;
3735 q_numDiff_v.data()[eN_k] = numDiffMax;
3736 q_numDiff_w.data()[eN_k] = numDiffMax;
3737 }
3738#endif
3739 //
3740 //load element into global residual and save element residual
3741 //
3742 for(int i=0;i<nDOF_test_element;i++)
3743 {
3744 int eN_i=eN*nDOF_test_element+i;
3745 elementResidual_p_save.data()[eN_i] += elementResidual_p[i];
3746 mesh_volume_conservation_element_weak += elementResidual_mesh[i];
3747 if (!isActiveElement[eN])
3748 {
3749 assert(elementResidual_p[i]==0.0);
3750 }
3751 globalResidual.data()[offset_p+stride_p*rp_l2g.data()[eN_i]]+=elementResidual_p[i];
3752 if (element_active)
3753 {
3754 isActiveR.data()[offset_p+stride_p*rp_l2g.data()[eN_i]] = 1.0;
3755 isActiveDOF_p.data()[p_l2g.data()[eN_i]] = 1.0;
3756 }
3757 }
3758 for(int i=0;i<nDOF_v_test_element;i++)
3759 {
3760 int eN_i=eN*nDOF_v_test_element+i;
3761 if (!isActiveElement[eN])
3762 {
3763 assert(elementResidual_u[i]==0.0);
3764 assert(elementResidual_v[i]==0.0);
3765 assert(elementResidual_w[i]==0.0);
3766 }
3767 globalResidual.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]]+=elementResidual_u[i];
3768 globalResidual.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]]+=elementResidual_v[i];
3769 globalResidual.data()[offset_w+stride_w*rvel_l2g.data()[eN_i]]+=elementResidual_w[i];
3770 if (element_active)
3771 {
3772 isActiveR.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]] = 1.0;
3773 isActiveR.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]] = 1.0;
3774 isActiveR.data()[offset_w+stride_w*rvel_l2g.data()[eN_i]] = 1.0;
3775 isActiveDOF_vel.data()[vel_l2g.data()[eN_i]] = 1.0;
3776 }
3777 double x = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+0],
3778 y = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+1],
3779 z = mesh_dof.data()[3*mesh_l2g.data()[eN_i]+2];//cek hack: need lagrange nodes for higher order
3780
3781 get_velocity_to_ith_ball(nParticles,ball_center.data(),ball_radius.data(),
3782 ball_velocity.data(),ball_angular_velocity.data(),
3783 particle_index,x,y,z,
3784 ball_u.data()[vel_l2g.data()[eN_i]], ball_v.data()[vel_l2g.data()[eN_i]], ball_w.data()[vel_l2g.data()[eN_i]]);
3785 }//i
3786 mesh_volume_conservation += mesh_volume_conservation_element;
3787 mesh_volume_conservation_weak += mesh_volume_conservation_element_weak;
3788 mesh_volume_conservation_err_max=fmax(mesh_volume_conservation_err_max,fabs(mesh_volume_conservation_element));
3789 mesh_volume_conservation_err_max_weak=fmax(mesh_volume_conservation_err_max_weak,fabs(mesh_volume_conservation_element_weak));
3790 }//elements
3791 std::set<int>::iterator it=cutfem_boundaries.begin();
3792 while(it!=cutfem_boundaries.end())
3793 {
3794 if(isActiveElement[elementBoundaryElementsArray[(*it)*2+0]] && isActiveElement[elementBoundaryElementsArray[(*it)*2+1]])
3795 {
3796 std::map<int,double> DWp_Dn_jump, DW_Dn_jump;
3797 double gamma_cutfem=ghost_penalty_constant,gamma_cutfem_p=ghost_penalty_constant,h_cutfem=elementBoundaryDiameter.data()[*it];
3798 int eN_nDOF_v_trial_element = elementBoundaryElementsArray.data()[(*it)*2+0]*nDOF_v_trial_element;
3799 //See Massing Schott Wall 2018
3800 //cek todo modify for two-fluids: rho_0 != rho_1
3801 double norm_v=0.0;
3802 for (int i_offset=1;i_offset<nDOF_v_trial_element;i_offset++)//MSW18 is just on face, so trying to just use face dof
3803 {
3804 int i = (cutfem_local_boundaries[*it] + i_offset)%nDOF_v_trial_element;
3805 double u=u_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
3806 v=v_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
3807 w=w_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]];
3808 norm_v=fmax(norm_v,sqrt(u*u+v*v+w*w));
3809 }
3810 double gamma_v_dim = rho_0*(nu_0 + norm_v*h_cutfem + alphaBDF*h_cutfem*h_cutfem);
3811 gamma_cutfem_p *= h_cutfem*h_cutfem/gamma_v_dim;
3812 if (NONCONSERVATIVE_FORM)
3813 gamma_cutfem*=gamma_v_dim;
3814 else
3815 gamma_cutfem*=(gamma_v_dim/rho_0);
3816 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
3817 {
3818 double Dp_Dn_jump=0.0, Du_Dn_jump=0.0, Dv_Dn_jump=0.0, Dw_Dn_jump=0.0, dS;
3819 for (int eN_side=0;eN_side < 2; eN_side++)
3820 {
3821 int ebN = *it,
3822 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
3823 for (int i=0;i<nDOF_test_element;i++)
3824 {
3825 DWp_Dn_jump[rp_l2g.data()[eN*nDOF_test_element+i]] = 0.0;
3826 }
3827 for (int i=0;i<nDOF_v_test_element;i++)
3828 {
3829 DW_Dn_jump[rvel_l2g.data()[eN*nDOF_v_test_element+i]] = 0.0;
3830 }
3831 }
3832 for (int eN_side=0;eN_side < 2; eN_side++)
3833 {
3834 int ebN = *it,
3835 eN = elementBoundaryElementsArray[ebN*2+eN_side],
3836 ebN_local = elementBoundaryLocalElementBoundariesArray[ebN*2+eN_side],
3837 eN_nDOF_trial_element = eN*nDOF_trial_element,
3838 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
3839 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
3840 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
3841 double p_int=0.0,
3842 u_int=0.0,
3843 v_int=0.0,
3844 w_int=0.0,
3845 grad_p_int[nSpace]=ZEROVEC,
3846 grad_u_int[nSpace]=ZEROVEC,
3847 grad_v_int[nSpace]=ZEROVEC,
3848 grad_w_int[nSpace]=ZEROVEC,
3849 jac_int[nSpace*nSpace],
3850 jacDet_int,
3851 jacInv_int[nSpace*nSpace],
3852 boundaryJac[nSpace*(nSpace-1)],
3853 metricTensor[(nSpace-1)*(nSpace-1)],
3854 metricTensorDetSqrt,
3855 p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
3856 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
3857 p_grad_test_dS[nDOF_trial_element*nSpace],vel_grad_test_dS[nDOF_v_trial_element*nSpace],
3858 normal[nSpace],x_int,y_int,z_int,xt_int,yt_int,zt_int,integralScaling,
3859 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
3860 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;
3861 //compute information about mapping from reference element to physical element
3862 ck.calculateMapping_elementBoundary(eN,
3863 ebN_local,
3864 kb,
3865 ebN_local_kb,
3866 mesh_dof.data(),
3867 mesh_l2g.data(),
3868 mesh_trial_trace_ref.data(),
3869 mesh_grad_trial_trace_ref.data(),
3870 boundaryJac_ref.data(),
3871 jac_int,
3872 jacDet_int,
3873 jacInv_int,
3874 boundaryJac,
3875 metricTensor,
3876 metricTensorDetSqrt,
3877 normal_ref.data(),
3878 normal,
3879 x_int,y_int,z_int);
3880 //todo: check that physical coordinates match
3881 ck.calculateMappingVelocity_elementBoundary(eN,
3882 ebN_local,
3883 kb,
3884 ebN_local_kb,
3885 mesh_velocity_dof.data(),
3886 mesh_l2g.data(),
3887 mesh_trial_trace_ref.data(),
3888 xt_int,yt_int,zt_int,
3889 normal,
3890 boundaryJac,
3891 metricTensor,
3892 integralScaling);
3893 dS = metricTensorDetSqrt*dS_ref.data()[kb];
3894 //compute shape and solution information
3895 //shape
3896 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_int,p_grad_trial_trace);
3897 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_int,vel_grad_trial_trace);
3898 //solution and gradients
3899 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);
3900 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);
3901 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);
3902 ck_v.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],w_int);
3903 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_int);
3904 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_int);
3905 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_int);
3906 ck_v.gradFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_w_int);
3907 for (int I=0;I<nSpace;I++)
3908 {
3909 Dp_Dn_jump += grad_p_int[I]*normal[I];
3910 Du_Dn_jump += grad_u_int[I]*normal[I];
3911 Dv_Dn_jump += grad_v_int[I]*normal[I];
3912 Dw_Dn_jump += grad_w_int[I]*normal[I];
3913 }
3914 for (int i=0;i<nDOF_test_element;i++)
3915 {
3916 for (int I=0;I<nSpace;I++)
3917 DWp_Dn_jump[rp_l2g[eN_nDOF_trial_element+i]] += p_grad_trial_trace[i*nSpace+I]*normal[I];
3918 }
3919 for (int i=0;i<nDOF_v_test_element;i++)
3920 {
3921 for (int I=0;I<nSpace;I++)
3922 DW_Dn_jump[rvel_l2g[eN_nDOF_v_trial_element+i]] += vel_grad_trial_trace[i*nSpace+I]*normal[I];
3923 }
3924 }//eN_side
3925 for (std::map<int,double>::iterator W_it=DWp_Dn_jump.begin(); W_it!=DWp_Dn_jump.end(); ++W_it)
3926 {
3927 int i_global = W_it->first;
3928 double DWp_Dn_jump_i = W_it->second;
3929 globalResidual.data()[offset_p+stride_p*i_global]+=gamma_cutfem_p*h_cutfem*Dp_Dn_jump*DWp_Dn_jump_i*dS;
3930 }
3931 for (std::map<int,double>::iterator W_it=DW_Dn_jump.begin(); W_it!=DW_Dn_jump.end(); ++W_it)
3932 {
3933 int i_global = W_it->first;
3934 double DW_Dn_jump_i = W_it->second;
3935 globalResidual.data()[offset_u+stride_u*i_global]+=gamma_cutfem*h_cutfem*Du_Dn_jump*DW_Dn_jump_i*dS;
3936 globalResidual.data()[offset_v+stride_v*i_global]+=gamma_cutfem*h_cutfem*Dv_Dn_jump*DW_Dn_jump_i*dS;
3937 globalResidual.data()[offset_w+stride_w*i_global]+=gamma_cutfem*h_cutfem*Dw_Dn_jump*DW_Dn_jump_i*dS;
3938 }//i
3939 }//kb
3940 it++;
3941 }
3942 else
3943 {
3944 it = cutfem_boundaries.erase(it);
3945 }
3946 }//cutfem element boundaries
3947 //
3948 //loop over exterior element boundaries to calculate surface integrals and load into element and global residuals
3949 //
3950 //ebNE is the Exterior element boundary INdex
3951 //ebN is the element boundary INdex
3952 //eN is the element index
3953 for (int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
3954 {
3955 int ebN = exteriorElementBoundariesArray.data()[ebNE],
3956 eN = elementBoundaryElementsArray.data()[ebN*2+0],
3957 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
3958 eN_nDOF_trial_element = eN*nDOF_trial_element,
3959 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element;
3960 if (boundaryFlags[ebN] < 1)
3961 continue;
3962 double elementResidual_mesh[nDOF_test_element],
3963 elementResidual_p[nDOF_test_element],
3964 elementResidual_u[nDOF_v_test_element],
3965 elementResidual_v[nDOF_v_test_element],
3966 elementResidual_w[nDOF_v_test_element],
3967 eps_rho,eps_mu;
3968 for (int i=0;i<nDOF_test_element;i++)
3969 {
3970 elementResidual_mesh[i]=0.0;
3971 elementResidual_p[i]=0.0;
3972 }
3973 for (int i=0;i<nDOF_v_test_element;i++)
3974 {
3975 elementResidual_u[i]=0.0;
3976 elementResidual_v[i]=0.0;
3977 elementResidual_w[i]=0.0;
3978 }
3979 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
3980 for (int j=0;j<nDOF_mesh_trial_element;j++)
3981 {
3982 int eN_j = eN*nDOF_mesh_trial_element+j;
3983 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
3984 element_phi_s[j] = phi_solid_nodes[p_l2g.data()[eN_j]];
3985 }
3986 double element_nodes[nDOF_mesh_trial_element*3];
3987 for (int i=0;i<nDOF_mesh_trial_element;i++)
3988 {
3989 int eN_i=eN*nDOF_mesh_trial_element+i;
3990 for(int I=0;I<3;I++)
3991 element_nodes[i*3 + I] = mesh_dof[mesh_l2g.data()[eN_i]*3 + I];
3992 }//i
3993 double mesh_dof_ref[nDOF_mesh_trial_element*3]={0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.};
3994 double xb_ref_calc[nQuadraturePoints_elementBoundary*3];
3995 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
3996 {
3997 double x=0.0,y=0.0,z=0.0;
3998 for (int j=0;j<nDOF_mesh_trial_element;j++)
3999 {
4000 int ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb;
4001 int ebN_local_kb_j = ebN_local_kb*nDOF_mesh_trial_element+j;
4002 x += mesh_dof_ref[j*3+0]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
4003 y += mesh_dof_ref[j*3+1]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
4004 z += mesh_dof_ref[j*3+2]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
4005 }
4006 xb_ref_calc[3*kb+0] = x;
4007 xb_ref_calc[3*kb+1] = y;
4008 xb_ref_calc[3*kb+2] = z;
4009 }
4010 int icase_s = gf_s.calculate(element_phi_s, element_nodes, xb_ref_calc, true);
4011#ifdef IFEM
4012 int icase = gf.calculate(element_phi, element_nodes, xb_ref.data(), -rho_1*g.data()[1], -rho_0*g.data()[1],true,true);
4013#else
4014 int icase = gf.calculate(element_phi, element_nodes, xb_ref.data(), 1.0,1.0,true,false);
4015#endif
4016 //cek todo needs modification for twophase flow ibm
4017 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
4018 {
4019 int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
4020 ebNE_kb_nSpace = ebNE_kb*nSpace,
4021 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
4022 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
4023 double phi_s_ext=0.0,
4024 p_ext=0.0,
4025 u_ext=0.0,
4026 v_ext=0.0,
4027 w_ext=0.0,
4028 grad_p_ext[nSpace]=ZEROVEC,
4029 grad_u_ext[nSpace]=ZEROVEC,
4030 grad_v_ext[nSpace]=ZEROVEC,
4031 grad_w_ext[nSpace]=ZEROVEC,
4032 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
4033 grad_p_old[nSpace]=ZEROVEC,grad_u_old[nSpace]=ZEROVEC,grad_v_old[nSpace]=ZEROVEC,grad_w_old[nSpace]=ZEROVEC,
4034 mom_u_acc_ext=0.0,
4035 dmom_u_acc_u_ext=0.0,
4036 mom_v_acc_ext=0.0,
4037 dmom_v_acc_v_ext=0.0,
4038 mom_w_acc_ext=0.0,
4039 dmom_w_acc_w_ext=0.0,
4040 mass_adv_ext[nSpace]=ZEROVEC,
4041 dmass_adv_u_ext[nSpace]=ZEROVEC,
4042 dmass_adv_v_ext[nSpace]=ZEROVEC,
4043 dmass_adv_w_ext[nSpace]=ZEROVEC,
4044 mom_u_adv_ext[nSpace]=ZEROVEC,
4045 dmom_u_adv_u_ext[nSpace]=ZEROVEC,
4046 dmom_u_adv_v_ext[nSpace]=ZEROVEC,
4047 dmom_u_adv_w_ext[nSpace]=ZEROVEC,
4048 mom_v_adv_ext[nSpace]=ZEROVEC,
4049 dmom_v_adv_u_ext[nSpace]=ZEROVEC,
4050 dmom_v_adv_v_ext[nSpace]=ZEROVEC,
4051 dmom_v_adv_w_ext[nSpace]=ZEROVEC,
4052 mom_w_adv_ext[nSpace]=ZEROVEC,
4053 dmom_w_adv_u_ext[nSpace]=ZEROVEC,
4054 dmom_w_adv_v_ext[nSpace]=ZEROVEC,
4055 dmom_w_adv_w_ext[nSpace]=ZEROVEC,
4056 mom_uu_diff_ten_ext[nSpace]=ZEROVEC,
4057 mom_vv_diff_ten_ext[nSpace]=ZEROVEC,
4058 mom_ww_diff_ten_ext[nSpace]=ZEROVEC,
4059 mom_uv_diff_ten_ext[1],
4060 mom_uw_diff_ten_ext[1],
4061 mom_vu_diff_ten_ext[1],
4062 mom_vw_diff_ten_ext[1],
4063 mom_wu_diff_ten_ext[1],
4064 mom_wv_diff_ten_ext[1],
4065 mom_u_source_ext=0.0,
4066 mom_v_source_ext=0.0,
4067 mom_w_source_ext=0.0,
4068 mom_u_ham_ext=0.0,
4069 dmom_u_ham_grad_p_ext[nSpace]=ZEROVEC,
4070 dmom_u_ham_grad_u_ext[nSpace]=ZEROVEC,
4071 dmom_u_ham_u_ext=0.0,
4072 dmom_u_ham_v_ext=0.0,
4073 dmom_u_ham_w_ext=0.0,
4074 mom_v_ham_ext=0.0,
4075 dmom_v_ham_grad_p_ext[nSpace]=ZEROVEC,
4076 dmom_v_ham_grad_v_ext[nSpace]=ZEROVEC,
4077 dmom_v_ham_u_ext=0.0,
4078 dmom_v_ham_v_ext=0.0,
4079 dmom_v_ham_w_ext=0.0,
4080 mom_w_ham_ext=0.0,
4081 dmom_w_ham_grad_p_ext[nSpace]=ZEROVEC,
4082 dmom_w_ham_grad_w_ext[nSpace]=ZEROVEC,
4083 dmom_w_ham_u_ext=0.0,
4084 dmom_w_ham_v_ext=0.0,
4085 dmom_w_ham_w_ext=0.0,
4086 dmom_u_adv_p_ext[nSpace]=ZEROVEC,
4087 dmom_v_adv_p_ext[nSpace]=ZEROVEC,
4088 dmom_w_adv_p_ext[nSpace]=ZEROVEC,
4089 flux_mass_ext=0.0,
4090 flux_mom_u_adv_ext=0.0,
4091 flux_mom_v_adv_ext=0.0,
4092 flux_mom_w_adv_ext=0.0,
4093 flux_mom_uu_diff_ext=0.0,
4094 flux_mom_uv_diff_ext=0.0,
4095 flux_mom_uw_diff_ext=0.0,
4096 flux_mom_vu_diff_ext=0.0,
4097 flux_mom_vv_diff_ext=0.0,
4098 flux_mom_vw_diff_ext=0.0,
4099 flux_mom_wu_diff_ext=0.0,
4100 flux_mom_wv_diff_ext=0.0,
4101 flux_mom_ww_diff_ext=0.0,
4102 bc_p_ext=0.0,
4103 bc_u_ext=0.0,
4104 bc_v_ext=0.0,
4105 bc_w_ext=0.0,
4106 bc_mom_u_acc_ext=0.0,
4107 bc_dmom_u_acc_u_ext=0.0,
4108 bc_mom_v_acc_ext=0.0,
4109 bc_dmom_v_acc_v_ext=0.0,
4110 bc_mom_w_acc_ext=0.0,
4111 bc_dmom_w_acc_w_ext=0.0,
4112 bc_mass_adv_ext[nSpace]=ZEROVEC,
4113 bc_dmass_adv_u_ext[nSpace]=ZEROVEC,
4114 bc_dmass_adv_v_ext[nSpace]=ZEROVEC,
4115 bc_dmass_adv_w_ext[nSpace]=ZEROVEC,
4116 bc_mom_u_adv_ext[nSpace]=ZEROVEC,
4117 bc_dmom_u_adv_u_ext[nSpace]=ZEROVEC,
4118 bc_dmom_u_adv_v_ext[nSpace]=ZEROVEC,
4119 bc_dmom_u_adv_w_ext[nSpace]=ZEROVEC,
4120 bc_mom_v_adv_ext[nSpace]=ZEROVEC,
4121 bc_dmom_v_adv_u_ext[nSpace]=ZEROVEC,
4122 bc_dmom_v_adv_v_ext[nSpace]=ZEROVEC,
4123 bc_dmom_v_adv_w_ext[nSpace]=ZEROVEC,
4124 bc_mom_w_adv_ext[nSpace]=ZEROVEC,
4125 bc_dmom_w_adv_u_ext[nSpace]=ZEROVEC,
4126 bc_dmom_w_adv_v_ext[nSpace]=ZEROVEC,
4127 bc_dmom_w_adv_w_ext[nSpace]=ZEROVEC,
4128 bc_mom_uu_diff_ten_ext[nSpace]=ZEROVEC,
4129 bc_mom_vv_diff_ten_ext[nSpace]=ZEROVEC,
4130 bc_mom_ww_diff_ten_ext[nSpace]=ZEROVEC,
4131 bc_mom_uv_diff_ten_ext[1],
4132 bc_mom_uw_diff_ten_ext[1],
4133 bc_mom_vu_diff_ten_ext[1],
4134 bc_mom_vw_diff_ten_ext[1],
4135 bc_mom_wu_diff_ten_ext[1],
4136 bc_mom_wv_diff_ten_ext[1],
4137 bc_mom_u_source_ext=0.0,
4138 bc_mom_v_source_ext=0.0,
4139 bc_mom_w_source_ext=0.0,
4140 bc_mom_u_ham_ext=0.0,
4141 bc_dmom_u_ham_grad_p_ext[nSpace]=ZEROVEC,
4142 bc_dmom_u_ham_grad_u_ext[nSpace]=ZEROVEC,
4143 bc_dmom_u_ham_u_ext=0.0,
4144 bc_dmom_u_ham_v_ext=0.0,
4145 bc_dmom_u_ham_w_ext=0.0,
4146 bc_mom_v_ham_ext=0.0,
4147 bc_dmom_v_ham_grad_p_ext[nSpace]=ZEROVEC,
4148 bc_dmom_v_ham_grad_v_ext[nSpace]=ZEROVEC,
4149 bc_dmom_v_ham_u_ext=0.0,
4150 bc_dmom_v_ham_v_ext=0.0,
4151 bc_dmom_v_ham_w_ext=0.0,
4152 bc_mom_w_ham_ext=0.0,
4153 bc_dmom_w_ham_grad_p_ext[nSpace]=ZEROVEC,
4154 bc_dmom_w_ham_grad_w_ext[nSpace]=ZEROVEC,
4155 bc_dmom_w_ham_u_ext=0.0,
4156 bc_dmom_w_ham_v_ext=0.0,
4157 bc_dmom_w_ham_w_ext=0.0,
4158 jac_ext[nSpace*nSpace],
4159 jacDet_ext,
4160 jacInv_ext[nSpace*nSpace],
4161 boundaryJac[nSpace*(nSpace-1)],
4162 metricTensor[(nSpace-1)*(nSpace-1)],
4163 metricTensorDetSqrt,
4164 dS,p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
4165 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
4166 vel_grad_test_dS[nDOF_v_trial_element*nSpace],
4167 normal[nSpace],x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
4168 //VRANS
4169 porosity_ext,
4170 //
4171 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
4172 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;
4173 //compute information about mapping from reference element to physical element
4176 ck.calculateMapping_elementBoundary(eN,
4177 ebN_local,
4178 kb,
4179 ebN_local_kb,
4180 mesh_dof.data(),
4181 mesh_l2g.data(),
4182 mesh_trial_trace_ref.data(),
4183 mesh_grad_trial_trace_ref.data(),
4184 boundaryJac_ref.data(),
4185 jac_ext,
4186 jacDet_ext,
4187 jacInv_ext,
4188 boundaryJac,
4189 metricTensor,
4190 metricTensorDetSqrt,
4191 normal_ref.data(),
4192 normal,
4193 x_ext,y_ext,z_ext);
4194 ck.calculateMappingVelocity_elementBoundary(eN,
4195 ebN_local,
4196 kb,
4197 ebN_local_kb,
4198 mesh_velocity_dof.data(),
4199 mesh_l2g.data(),
4200 mesh_trial_trace_ref.data(),
4201 xt_ext,yt_ext,zt_ext,
4202 normal,
4203 boundaryJac,
4204 metricTensor,
4205 integralScaling);
4206 //xt_ext=0.0;yt_ext=0.0;zt_ext=0.0;
4207 //std::cout<<"xt_ext "<<xt_ext<<'\t'<<yt_ext<<'\t'<<zt_ext<<std::endl;
4208 //std::cout<<"x_ext "<<x_ext<<'\t'<<y_ext<<'\t'<<z_ext<<std::endl;
4209 //std::cout<<"integralScaling - metricTensorDetSrt ==============================="<<integralScaling-metricTensorDetSqrt<<std::endl;
4210 /* std::cout<<"metricTensorDetSqrt "<<metricTensorDetSqrt */
4211 /* <<"dS_ref.data()[kb]"<<dS_ref.data()[kb]<<std::endl; */
4212 //dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];//cek need to test effect on accuracy
4213 dS = metricTensorDetSqrt*dS_ref.data()[kb];
4214 //get the metric tensor
4215 //cek todo use symmetry
4216 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
4217 ck.calculateGScale(G,&ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],h_phi);
4218
4219 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
4220 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
4221
4222 //compute shape and solution information
4223 //shape
4224 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,p_grad_trial_trace);
4225 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_ext,vel_grad_trial_trace);
4226 //solution and gradients
4227 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);
4228 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);
4229 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);
4230 ck_v.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],w_ext);
4231 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);
4232 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);
4233 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);
4234 ck_v.valFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],w_old);
4235 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_ext);
4236 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_ext);
4237 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_ext);
4238 ck_v.gradFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_w_ext);
4239 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_old);
4240 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_old);
4241 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_old);
4242 ck_v.gradFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_w_old);
4243 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);
4244 //precalculate test function products with integration weights
4245 for (int j=0;j<nDOF_test_element;j++)
4246 {
4247 p_test_dS[j] = p_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
4248 }
4249 for (int j=0;j<nDOF_v_test_element;j++)
4250 {
4251 vel_test_dS[j] = vel_test_trace_ref.data()[ebN_local_kb*nDOF_v_test_element+j]*dS;
4252 for (int I=0;I<nSpace;I++)
4253 vel_grad_test_dS[j*nSpace+I] = vel_grad_trial_trace[j*nSpace+I]*dS;//assume test_j = trial_j
4254 }
4255 bc_p_ext = isDOFBoundary_p.data()[ebNE_kb]*ebqe_bc_p_ext.data()[ebNE_kb]+(1-isDOFBoundary_p.data()[ebNE_kb])*p_ext;
4256 //note, our convention is that bc values at moving boundaries are relative to boundary velocity so we add it here
4257 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;
4258 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;
4259 bc_w_ext = isDOFBoundary_w.data()[ebNE_kb]*(ebqe_bc_w_ext.data()[ebNE_kb] + MOVING_DOMAIN*zt_ext) + (1-isDOFBoundary_w.data()[ebNE_kb])*w_ext;
4260 //VRANS
4261 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
4262 //
4263 //calculate the pde coefficients using the solution and the boundary values for the solution
4264 //
4265 double eddy_viscosity_ext(0.),bc_eddy_viscosity_ext(0.); //not interested in saving boundary eddy viscosity for now
4266 if (use_ball_as_particle == 1 && nParticles > 0)
4267 {
4268 get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x_ext,y_ext,z_ext,ebqe_phi_s.data()[ebNE_kb]);
4269 }
4270 //else ebqe_phi_s.data()[ebNE_kb] is computed in Prestep
4271 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter[eN]);
4272
4273 //cek needs to be fixed for two-phase ifem
4274 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]));
4275 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])));
4276 double rho = rho_0*ImH + rho_1*H;
4277 double nu = nu_0*ImH + nu_1*H;
4278 //
4279 evaluateCoefficients(NONCONSERVATIVE_FORM,
4280 sigma,
4281 rho,
4282 nu,
4283 elementDiameter.data()[eN],
4284 smagorinskyConstant,
4285 turbulenceClosureModel,
4286 g.data(),
4287 useVF,
4288 ebqe_vf_ext.data()[ebNE_kb],
4289 ebqe_phi_ext.data()[ebNE_kb],
4290 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
4291 ebqe_kappa_phi_ext.data()[ebNE_kb],
4292 //VRANS
4293 porosity_ext,
4294 //
4295 ebqe_phi_s.data()[ebNE_kb],
4296 p_old,
4297 u_old,
4298 v_old,
4299 w_old,
4300 grad_p_old,
4301 grad_u_old,
4302 grad_v_old,
4303 grad_w_old,
4304 p_ext,
4305 grad_p_ext,
4306 grad_u_ext,
4307 grad_v_ext,
4308 grad_w_ext,
4309 u_ext,
4310 v_ext,
4311 w_ext,
4312 LAG_LES,
4313 ebqe_eddy_viscosity.data()[ebNE_kb],
4314 ebqe_eddy_viscosity_last.data()[ebNE_kb],
4315 mom_u_acc_ext,
4316 dmom_u_acc_u_ext,
4317 mom_v_acc_ext,
4318 dmom_v_acc_v_ext,
4319 mom_w_acc_ext,
4320 dmom_w_acc_w_ext,
4321 mass_adv_ext,
4322 dmass_adv_u_ext,
4323 dmass_adv_v_ext,
4324 dmass_adv_w_ext,
4325 mom_u_adv_ext,
4326 dmom_u_adv_u_ext,
4327 dmom_u_adv_v_ext,
4328 dmom_u_adv_w_ext,
4329 mom_v_adv_ext,
4330 dmom_v_adv_u_ext,
4331 dmom_v_adv_v_ext,
4332 dmom_v_adv_w_ext,
4333 mom_w_adv_ext,
4334 dmom_w_adv_u_ext,
4335 dmom_w_adv_v_ext,
4336 dmom_w_adv_w_ext,
4337 mom_uu_diff_ten_ext,
4338 mom_vv_diff_ten_ext,
4339 mom_ww_diff_ten_ext,
4340 mom_uv_diff_ten_ext,
4341 mom_uw_diff_ten_ext,
4342 mom_vu_diff_ten_ext,
4343 mom_vw_diff_ten_ext,
4344 mom_wu_diff_ten_ext,
4345 mom_wv_diff_ten_ext,
4346 mom_u_source_ext,
4347 mom_v_source_ext,
4348 mom_w_source_ext,
4349 mom_u_ham_ext,
4350 dmom_u_ham_grad_p_ext,
4351 dmom_u_ham_grad_u_ext,
4352 dmom_u_ham_u_ext,
4353 dmom_u_ham_v_ext,
4354 dmom_u_ham_w_ext,
4355 mom_v_ham_ext,
4356 dmom_v_ham_grad_p_ext,
4357 dmom_v_ham_grad_v_ext,
4358 dmom_v_ham_u_ext,
4359 dmom_v_ham_v_ext,
4360 dmom_v_ham_w_ext,
4361 mom_w_ham_ext,
4362 dmom_w_ham_grad_p_ext,
4363 dmom_w_ham_grad_w_ext,
4364 dmom_w_ham_u_ext,
4365 dmom_w_ham_v_ext,
4366 dmom_w_ham_w_ext,
4367 0.0,
4368 0.0,
4369 0.0);
4370 //cek needs to be fixed for two-phase ifem
4371 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]));
4372 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])));
4373 rho = rho_0*ImH + rho_1*H;
4374 nu = nu_0*ImH + nu_1*H;
4375 //
4376 evaluateCoefficients(NONCONSERVATIVE_FORM,
4377 sigma,
4378 rho,
4379 nu,
4380 elementDiameter.data()[eN],
4381 smagorinskyConstant,
4382 turbulenceClosureModel,
4383 g.data(),
4384 useVF,
4385 bc_ebqe_vf_ext.data()[ebNE_kb],
4386 bc_ebqe_phi_ext.data()[ebNE_kb],
4387 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
4388 ebqe_kappa_phi_ext.data()[ebNE_kb],
4389 //VRANS
4390 porosity_ext,
4391 //
4392 ebqe_phi_s.data()[ebNE_kb],
4393 p_old,
4394 u_old,
4395 v_old,
4396 w_old,
4397 grad_p_old,
4398 grad_u_old,
4399 grad_v_old,
4400 grad_w_old,
4401 bc_p_ext,
4402 grad_p_ext,
4403 grad_u_ext,
4404 grad_v_ext,
4405 grad_w_ext,
4406 bc_u_ext,
4407 bc_v_ext,
4408 bc_w_ext,
4409 LAG_LES,
4410 bc_eddy_viscosity_ext,
4411 ebqe_eddy_viscosity_last.data()[ebNE_kb],
4412 bc_mom_u_acc_ext,
4413 bc_dmom_u_acc_u_ext,
4414 bc_mom_v_acc_ext,
4415 bc_dmom_v_acc_v_ext,
4416 bc_mom_w_acc_ext,
4417 bc_dmom_w_acc_w_ext,
4418 bc_mass_adv_ext,
4419 bc_dmass_adv_u_ext,
4420 bc_dmass_adv_v_ext,
4421 bc_dmass_adv_w_ext,
4422 bc_mom_u_adv_ext,
4423 bc_dmom_u_adv_u_ext,
4424 bc_dmom_u_adv_v_ext,
4425 bc_dmom_u_adv_w_ext,
4426 bc_mom_v_adv_ext,
4427 bc_dmom_v_adv_u_ext,
4428 bc_dmom_v_adv_v_ext,
4429 bc_dmom_v_adv_w_ext,
4430 bc_mom_w_adv_ext,
4431 bc_dmom_w_adv_u_ext,
4432 bc_dmom_w_adv_v_ext,
4433 bc_dmom_w_adv_w_ext,
4434 bc_mom_uu_diff_ten_ext,
4435 bc_mom_vv_diff_ten_ext,
4436 bc_mom_ww_diff_ten_ext,
4437 bc_mom_uv_diff_ten_ext,
4438 bc_mom_uw_diff_ten_ext,
4439 bc_mom_vu_diff_ten_ext,
4440 bc_mom_vw_diff_ten_ext,
4441 bc_mom_wu_diff_ten_ext,
4442 bc_mom_wv_diff_ten_ext,
4443 bc_mom_u_source_ext,
4444 bc_mom_v_source_ext,
4445 bc_mom_w_source_ext,
4446 bc_mom_u_ham_ext,
4447 bc_dmom_u_ham_grad_p_ext,
4448 bc_dmom_u_ham_grad_u_ext,
4449 bc_dmom_u_ham_u_ext,
4450 bc_dmom_u_ham_v_ext,
4451 bc_dmom_u_ham_w_ext,
4452 bc_mom_v_ham_ext,
4453 bc_dmom_v_ham_grad_p_ext,
4454 bc_dmom_v_ham_grad_v_ext,
4455 bc_dmom_v_ham_u_ext,
4456 bc_dmom_v_ham_v_ext,
4457 bc_dmom_v_ham_w_ext,
4458 bc_mom_w_ham_ext,
4459 bc_dmom_w_ham_grad_p_ext,
4460 bc_dmom_w_ham_grad_w_ext,
4461 bc_dmom_w_ham_u_ext,
4462 bc_dmom_w_ham_v_ext,
4463 bc_dmom_w_ham_w_ext,
4464 0.0,
4465 0.0,
4466 0.0);
4467
4468 //Turbulence closure model
4469 if (turbulenceClosureModel >= 3)
4470 {
4471 const double turb_var_grad_0_dummy[nSpace] = ZEROVEC;
4472 const double c_mu = 0.09;//mwf hack
4473 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
4474 turbulenceClosureModel,
4475 eps_rho,
4476 eps_mu,
4477 rho_0,
4478 nu_0,
4479 rho_1,
4480 nu_1,
4481 useVF,
4482 ebqe_vf_ext.data()[ebNE_kb],
4483 ebqe_phi_ext.data()[ebNE_kb],
4484 porosity_ext,
4485 c_mu, //mwf hack
4486 ebqe_turb_var_0.data()[ebNE_kb],
4487 ebqe_turb_var_1.data()[ebNE_kb],
4488 turb_var_grad_0_dummy, //not needed
4489 ebqe_eddy_viscosity.data()[ebNE_kb],
4490 mom_uu_diff_ten_ext,
4491 mom_vv_diff_ten_ext,
4492 mom_ww_diff_ten_ext,
4493 mom_uv_diff_ten_ext,
4494 mom_uw_diff_ten_ext,
4495 mom_vu_diff_ten_ext,
4496 mom_vw_diff_ten_ext,
4497 mom_wu_diff_ten_ext,
4498 mom_wv_diff_ten_ext,
4499 mom_u_source_ext,
4500 mom_v_source_ext,
4501 mom_w_source_ext);
4502
4503 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
4504 turbulenceClosureModel,
4505 eps_rho,
4506 eps_mu,
4507 rho_0,
4508 nu_0,
4509 rho_1,
4510 nu_1,
4511 useVF,
4512 bc_ebqe_vf_ext.data()[ebNE_kb],
4513 bc_ebqe_phi_ext.data()[ebNE_kb],
4514 porosity_ext,
4515 c_mu, //mwf hack
4516 ebqe_turb_var_0.data()[ebNE_kb],
4517 ebqe_turb_var_1.data()[ebNE_kb],
4518 turb_var_grad_0_dummy, //not needed
4519 bc_eddy_viscosity_ext,
4520 bc_mom_uu_diff_ten_ext,
4521 bc_mom_vv_diff_ten_ext,
4522 bc_mom_ww_diff_ten_ext,
4523 bc_mom_uv_diff_ten_ext,
4524 bc_mom_uw_diff_ten_ext,
4525 bc_mom_vu_diff_ten_ext,
4526 bc_mom_vw_diff_ten_ext,
4527 bc_mom_wu_diff_ten_ext,
4528 bc_mom_wv_diff_ten_ext,
4529 bc_mom_u_source_ext,
4530 bc_mom_v_source_ext,
4531 bc_mom_w_source_ext);
4532 }
4533
4534
4535 //
4536 //moving domain
4537 //
4538 if (NONCONSERVATIVE_FORM > 0.0)
4539 {
4540 mom_u_ham_ext -= MOVING_DOMAIN*dmom_u_acc_u_ext*(grad_u_ext[0]*xt_ext + grad_u_ext[1]*yt_ext + grad_u_ext[2]*zt_ext);
4541 dmom_u_ham_grad_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
4542 dmom_u_ham_grad_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
4543 dmom_u_ham_grad_u_ext[2] -= MOVING_DOMAIN*dmom_u_acc_u_ext*zt_ext;
4544 }
4545 else
4546 {
4547 mom_u_adv_ext[0] -= MOVING_DOMAIN*mom_u_acc_ext*xt_ext;
4548 mom_u_adv_ext[1] -= MOVING_DOMAIN*mom_u_acc_ext*yt_ext;
4549 mom_u_adv_ext[2] -= MOVING_DOMAIN*mom_u_acc_ext*zt_ext;
4550 dmom_u_adv_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
4551 dmom_u_adv_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
4552 dmom_u_adv_u_ext[2] -= MOVING_DOMAIN*dmom_u_acc_u_ext*zt_ext;
4553 }
4554
4555
4556 if (NONCONSERVATIVE_FORM > 0.0)
4557 {
4558 mom_v_ham_ext -= MOVING_DOMAIN*dmom_v_acc_v_ext*(grad_v_ext[0]*xt_ext + grad_v_ext[1]*yt_ext + grad_v_ext[2]*zt_ext);
4559 dmom_v_ham_grad_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
4560 dmom_v_ham_grad_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
4561 dmom_v_ham_grad_v_ext[2] -= MOVING_DOMAIN*dmom_v_acc_v_ext*zt_ext;
4562 }
4563 else
4564 {
4565 mom_v_adv_ext[0] -= MOVING_DOMAIN*mom_v_acc_ext*xt_ext;
4566 mom_v_adv_ext[1] -= MOVING_DOMAIN*mom_v_acc_ext*yt_ext;
4567 mom_v_adv_ext[2] -= MOVING_DOMAIN*mom_v_acc_ext*zt_ext;
4568 dmom_v_adv_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
4569 dmom_v_adv_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
4570 dmom_v_adv_v_ext[2] -= MOVING_DOMAIN*dmom_v_acc_v_ext*zt_ext;
4571 }
4572
4573
4574 if (NONCONSERVATIVE_FORM > 0.0)
4575 {
4576 mom_w_ham_ext -= MOVING_DOMAIN*dmom_w_acc_w_ext*(grad_w_ext[0]*xt_ext + grad_w_ext[1]*yt_ext + grad_w_ext[2]*zt_ext);
4577 dmom_w_ham_grad_w_ext[0] -= MOVING_DOMAIN*dmom_w_acc_w_ext*xt_ext;
4578 dmom_w_ham_grad_w_ext[1] -= MOVING_DOMAIN*dmom_w_acc_w_ext*yt_ext;
4579 dmom_w_ham_grad_w_ext[2] -= MOVING_DOMAIN*dmom_w_acc_w_ext*zt_ext;
4580 }
4581 else
4582 {
4583 mom_w_adv_ext[0] -= MOVING_DOMAIN*mom_w_acc_ext*xt_ext;
4584 mom_w_adv_ext[1] -= MOVING_DOMAIN*mom_w_acc_ext*yt_ext;
4585 mom_w_adv_ext[2] -= MOVING_DOMAIN*mom_w_acc_ext*zt_ext;
4586 dmom_w_adv_w_ext[0] -= MOVING_DOMAIN*dmom_w_acc_w_ext*xt_ext;
4587 dmom_w_adv_w_ext[1] -= MOVING_DOMAIN*dmom_w_acc_w_ext*yt_ext;
4588 dmom_w_adv_w_ext[2] -= MOVING_DOMAIN*dmom_w_acc_w_ext*zt_ext;
4589 }
4590
4591 //bc's
4592 if (NONCONSERVATIVE_FORM < 1.0)
4593 {
4594 bc_mom_u_adv_ext[0] -= MOVING_DOMAIN*bc_mom_u_acc_ext*xt_ext;
4595 bc_mom_u_adv_ext[1] -= MOVING_DOMAIN*bc_mom_u_acc_ext*yt_ext;
4596 bc_mom_u_adv_ext[2] -= MOVING_DOMAIN*bc_mom_u_acc_ext*zt_ext;
4597
4598 bc_mom_v_adv_ext[0] -= MOVING_DOMAIN*bc_mom_v_acc_ext*xt_ext;
4599 bc_mom_v_adv_ext[1] -= MOVING_DOMAIN*bc_mom_v_acc_ext*yt_ext;
4600 bc_mom_v_adv_ext[2] -= MOVING_DOMAIN*bc_mom_v_acc_ext*zt_ext;
4601
4602 bc_mom_w_adv_ext[0] -= MOVING_DOMAIN*bc_mom_w_acc_ext*xt_ext;
4603 bc_mom_w_adv_ext[1] -= MOVING_DOMAIN*bc_mom_w_acc_ext*yt_ext;
4604 bc_mom_w_adv_ext[2] -= MOVING_DOMAIN*bc_mom_w_acc_ext*zt_ext;
4605 }
4606 //
4607 //calculate the numerical fluxes
4608 //
4609 ck.calculateGScale(G,normal,h_penalty);
4610 penalty = useMetrics*C_b/h_penalty + (1.0-useMetrics)*ebqe_penalty_ext.data()[ebNE_kb];
4611 exteriorNumericalAdvectiveFlux(NONCONSERVATIVE_FORM,
4612 isDOFBoundary_p.data()[ebNE_kb],
4613 isDOFBoundary_u.data()[ebNE_kb],
4614 isDOFBoundary_v.data()[ebNE_kb],
4615 isDOFBoundary_w.data()[ebNE_kb],
4616 isAdvectiveFluxBoundary_p.data()[ebNE_kb],
4617 isAdvectiveFluxBoundary_u.data()[ebNE_kb],
4618 isAdvectiveFluxBoundary_v.data()[ebNE_kb],
4619 isAdvectiveFluxBoundary_w.data()[ebNE_kb],
4620 dmom_u_ham_grad_p_ext[0],//=1/rho,
4621 bc_dmom_u_ham_grad_p_ext[0],//=1/bc_rho,
4622 normal,
4623 bc_p_ext,
4624 bc_u_ext,
4625 bc_v_ext,
4626 bc_w_ext,
4627 bc_mass_adv_ext,
4628 bc_mom_u_adv_ext,
4629 bc_mom_v_adv_ext,
4630 bc_mom_w_adv_ext,
4631 ebqe_bc_flux_mass_ext.data()[ebNE_kb]+MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]+zt_ext*normal[2]),//BC is relative mass flux
4632 ebqe_bc_flux_mom_u_adv_ext.data()[ebNE_kb],
4633 ebqe_bc_flux_mom_v_adv_ext.data()[ebNE_kb],
4634 ebqe_bc_flux_mom_w_adv_ext.data()[ebNE_kb],
4635 p_ext,
4636 u_ext,
4637 v_ext,
4638 w_ext,
4639 mass_adv_ext,
4640 mom_u_adv_ext,
4641 mom_v_adv_ext,
4642 mom_w_adv_ext,
4643 dmass_adv_u_ext,
4644 dmass_adv_v_ext,
4645 dmass_adv_w_ext,
4646 dmom_u_adv_p_ext,
4647 dmom_u_ham_grad_u_ext,
4648 dmom_u_adv_u_ext,
4649 dmom_u_adv_v_ext,
4650 dmom_u_adv_w_ext,
4651 dmom_v_adv_p_ext,
4652 dmom_v_adv_u_ext,
4653 dmom_v_adv_v_ext,
4654 dmom_v_adv_w_ext,
4655 dmom_w_adv_p_ext,
4656 dmom_w_adv_u_ext,
4657 dmom_w_adv_v_ext,
4658 dmom_w_adv_w_ext,
4659 flux_mass_ext,
4660 flux_mom_u_adv_ext,
4661 flux_mom_v_adv_ext,
4662 flux_mom_w_adv_ext,
4663 &ebqe_velocity.data()[ebNE_kb_nSpace]);
4664 for (int I=0;I<nSpace;I++)
4665 ebqe_velocity.data()[ebNE_kb_nSpace+I]/=porosity_ext;
4667 ebqe_phi_ext.data()[ebNE_kb],
4668 sdInfo_u_u_rowptr.data(),
4669 sdInfo_u_u_colind.data(),
4670 isDOFBoundary_u.data()[ebNE_kb],
4671 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4672 normal,
4673 bc_mom_uu_diff_ten_ext,
4674 bc_u_ext,
4675 ebqe_bc_flux_u_diff_ext.data()[ebNE_kb],
4676 mom_uu_diff_ten_ext,
4677 grad_u_ext,
4678 u_ext,
4679 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4680 flux_mom_uu_diff_ext);
4682 ebqe_phi_ext.data()[ebNE_kb],
4683 sdInfo_u_v_rowptr.data(),
4684 sdInfo_u_v_colind.data(),
4685 isDOFBoundary_v.data()[ebNE_kb],
4686 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4687 normal,
4688 bc_mom_uv_diff_ten_ext,
4689 bc_v_ext,
4690 0.0,//assume all of the flux gets applied in diagonal component
4691 mom_uv_diff_ten_ext,
4692 grad_v_ext,
4693 v_ext,
4694 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4695 flux_mom_uv_diff_ext);
4697 ebqe_phi_ext.data()[ebNE_kb],
4698 sdInfo_u_w_rowptr.data(),
4699 sdInfo_u_w_colind.data(),
4700 isDOFBoundary_w.data()[ebNE_kb],
4701 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4702 normal,
4703 bc_mom_uw_diff_ten_ext,
4704 bc_w_ext,
4705 0.0,//see above
4706 mom_uw_diff_ten_ext,
4707 grad_w_ext,
4708 w_ext,
4709 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4710 flux_mom_uw_diff_ext);
4712 ebqe_phi_ext.data()[ebNE_kb],
4713 sdInfo_v_u_rowptr.data(),
4714 sdInfo_v_u_colind.data(),
4715 isDOFBoundary_u.data()[ebNE_kb],
4716 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4717 normal,
4718 bc_mom_vu_diff_ten_ext,
4719 bc_u_ext,
4720 0.0,//see above
4721 mom_vu_diff_ten_ext,
4722 grad_u_ext,
4723 u_ext,
4724 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4725 flux_mom_vu_diff_ext);
4727 ebqe_phi_ext.data()[ebNE_kb],
4728 sdInfo_v_v_rowptr.data(),
4729 sdInfo_v_v_colind.data(),
4730 isDOFBoundary_v.data()[ebNE_kb],
4731 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4732 normal,
4733 bc_mom_vv_diff_ten_ext,
4734 bc_v_ext,
4735 ebqe_bc_flux_v_diff_ext.data()[ebNE_kb],
4736 mom_vv_diff_ten_ext,
4737 grad_v_ext,
4738 v_ext,
4739 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4740 flux_mom_vv_diff_ext);
4742 ebqe_phi_ext.data()[ebNE_kb],
4743 sdInfo_v_w_rowptr.data(),
4744 sdInfo_v_w_colind.data(),
4745 isDOFBoundary_w.data()[ebNE_kb],
4746 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4747 normal,
4748 bc_mom_vw_diff_ten_ext,
4749 bc_w_ext,
4750 0.0,//see above
4751 mom_vw_diff_ten_ext,
4752 grad_w_ext,
4753 w_ext,
4754 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4755 flux_mom_vw_diff_ext);
4757 ebqe_phi_ext.data()[ebNE_kb],
4758 sdInfo_w_u_rowptr.data(),
4759 sdInfo_w_u_colind.data(),
4760 isDOFBoundary_u.data()[ebNE_kb],
4761 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4762 normal,
4763 bc_mom_wu_diff_ten_ext,
4764 bc_u_ext,
4765 0.0,//see above
4766 mom_wu_diff_ten_ext,
4767 grad_u_ext,
4768 u_ext,
4769 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4770 flux_mom_wu_diff_ext);
4772 ebqe_phi_ext.data()[ebNE_kb],
4773 sdInfo_w_v_rowptr.data(),
4774 sdInfo_w_v_colind.data(),
4775 isDOFBoundary_v.data()[ebNE_kb],
4776 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4777 normal,
4778 bc_mom_wv_diff_ten_ext,
4779 bc_v_ext,
4780 0.0,//see above
4781 mom_wv_diff_ten_ext,
4782 grad_v_ext,
4783 v_ext,
4784 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4785 flux_mom_wv_diff_ext);
4787 ebqe_phi_ext.data()[ebNE_kb],
4788 sdInfo_w_w_rowptr.data(),
4789 sdInfo_w_w_colind.data(),
4790 isDOFBoundary_w.data()[ebNE_kb],
4791 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4792 normal,
4793 bc_mom_ww_diff_ten_ext,
4794 bc_w_ext,
4795 ebqe_bc_flux_w_diff_ext.data()[ebNE_kb],
4796 mom_ww_diff_ten_ext,
4797 grad_w_ext,
4798 w_ext,
4799 penalty,//ebqe_penalty_ext.data()[ebNE_kb],
4800 flux_mom_ww_diff_ext);
4801 flux.data()[ebN*nQuadraturePoints_elementBoundary+kb] = flux_mass_ext;
4802 /* std::cout<<"external u,v,u_n " */
4803 /* <<ebqe_velocity.data()[ebNE_kb_nSpace+0]<<'\t' */
4804 /* <<ebqe_velocity.data()[ebNE_kb_nSpace+1]<<'\t' */
4805 /* <<flux.data()[ebN*nQuadraturePoints_elementBoundary+kb]<<std::endl; */
4806 //
4807 //integrate the net force and moment on flagged boundaries
4808 //
4809 if (ebN < nElementBoundaries_owned)
4810 {
4811 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];//same as *rho
4812 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];
4813 force_v_z = (flux_mom_w_adv_ext + flux_mom_wu_diff_ext + flux_mom_wv_diff_ext + flux_mom_ww_diff_ext)/dmom_u_ham_grad_p_ext[0];
4814
4815 force_p_x = p_ext*normal[0];
4816 force_p_y = p_ext*normal[1];
4817 force_p_z = p_ext*normal[2];
4818
4819 force_x = force_p_x + force_v_x;
4820 force_y = force_p_y + force_v_y;
4821 force_z = force_p_z + force_v_z;
4822
4823 r_x = x_ext - barycenters.data()[3*boundaryFlags.data()[ebN]+0];
4824 r_y = y_ext - barycenters.data()[3*boundaryFlags.data()[ebN]+1];
4825 r_z = z_ext - barycenters.data()[3*boundaryFlags.data()[ebN]+2];
4826
4827 wettedAreas.data()[boundaryFlags.data()[ebN]] += dS*(1.0-ebqe_vf_ext.data()[ebNE_kb]);
4828
4829 netForces_p.data()[3*boundaryFlags.data()[ebN]+0] += force_p_x*dS;
4830 netForces_p.data()[3*boundaryFlags.data()[ebN]+1] += force_p_y*dS;
4831 netForces_p.data()[3*boundaryFlags.data()[ebN]+2] += force_p_z*dS;
4832
4833 netForces_v.data()[3*boundaryFlags.data()[ebN]+0] += force_v_x*dS;
4834 netForces_v.data()[3*boundaryFlags.data()[ebN]+1] += force_v_y*dS;
4835 netForces_v.data()[3*boundaryFlags.data()[ebN]+2] += force_v_z*dS;
4836
4837 netMoments.data()[3*boundaryFlags.data()[ebN]+0] += (r_y*force_z - r_z*force_y)*dS;
4838 netMoments.data()[3*boundaryFlags.data()[ebN]+1] += (r_z*force_x - r_x*force_z)*dS;
4839 netMoments.data()[3*boundaryFlags.data()[ebN]+2] += (r_x*force_y - r_y*force_x)*dS;
4840 }
4841 //
4842 //update residuals
4843 //
4844 const double H_s = gf_s.H(particle_eps, ebqe_phi_s.data()[ebNE_kb]);
4845 if (isActiveElement[eN])
4846 { //if boundary flag positive, then include flux contributions on interpart boundaries
4847 total_flux += flux_mass_ext*dS;
4848 for (int i=0;i<nDOF_test_element;i++)
4849 {
4850 elementResidual_mesh[i] -= H_s*ck.ExteriorElementBoundaryFlux(MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]+zt_ext*normal[2]),p_test_dS[i]);
4851 elementResidual_p[i] += H_s*ck.ExteriorElementBoundaryFlux(flux_mass_ext,p_test_dS[i]);
4852 elementResidual_p[i] -= H_s*DM*ck.ExteriorElementBoundaryFlux(MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]+zt_ext*normal[2]),p_test_dS[i]);
4853 globalConservationError += H_s*ck.ExteriorElementBoundaryFlux(flux_mass_ext,p_test_dS[i]);
4854 }
4855 for (int i=0;i<nDOF_v_test_element;i++)
4856 {
4857 elementResidual_u[i] += H_s*(ck.ExteriorElementBoundaryFlux(flux_mom_u_adv_ext,vel_test_dS[i])+
4858 ck.ExteriorElementBoundaryFlux(flux_mom_uu_diff_ext,vel_test_dS[i])+
4859 ck.ExteriorElementBoundaryFlux(flux_mom_uv_diff_ext,vel_test_dS[i])+
4860 ck.ExteriorElementBoundaryFlux(flux_mom_uw_diff_ext,vel_test_dS[i])+
4861 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_u.data()[ebNE_kb],
4862 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4863 eb_adjoint_sigma,
4864 u_ext,
4865 bc_u_ext,
4866 normal,
4867 sdInfo_u_u_rowptr.data(),
4868 sdInfo_u_u_colind.data(),
4869 mom_uu_diff_ten_ext,
4870 &vel_grad_test_dS[i*nSpace])+
4871 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_v.data()[ebNE_kb],
4872 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4873 eb_adjoint_sigma,
4874 v_ext,
4875 bc_v_ext,
4876 normal,
4877 sdInfo_u_v_rowptr.data(),
4878 sdInfo_u_v_colind.data(),
4879 mom_uv_diff_ten_ext,
4880 &vel_grad_test_dS[i*nSpace])+
4881 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_w.data()[ebNE_kb],
4882 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
4883 eb_adjoint_sigma,
4884 w_ext,
4885 bc_w_ext,
4886 normal,
4887 sdInfo_u_w_rowptr.data(),
4888 sdInfo_u_w_colind.data(),
4889 mom_uw_diff_ten_ext,
4890 &vel_grad_test_dS[i*nSpace]));
4891 elementResidual_v[i] += H_s*(ck.ExteriorElementBoundaryFlux(flux_mom_v_adv_ext,vel_test_dS[i]) +
4892 ck.ExteriorElementBoundaryFlux(flux_mom_vu_diff_ext,vel_test_dS[i])+
4893 ck.ExteriorElementBoundaryFlux(flux_mom_vv_diff_ext,vel_test_dS[i])+
4894 ck.ExteriorElementBoundaryFlux(flux_mom_vw_diff_ext,vel_test_dS[i])+
4895 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_u.data()[ebNE_kb],
4896 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4897 eb_adjoint_sigma,
4898 u_ext,
4899 bc_u_ext,
4900 normal,
4901 sdInfo_v_u_rowptr.data(),
4902 sdInfo_v_u_colind.data(),
4903 mom_vu_diff_ten_ext,
4904 &vel_grad_test_dS[i*nSpace])+
4905 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_v.data()[ebNE_kb],
4906 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4907 eb_adjoint_sigma,
4908 v_ext,
4909 bc_v_ext,
4910 normal,
4911 sdInfo_v_v_rowptr.data(),
4912 sdInfo_v_v_colind.data(),
4913 mom_vv_diff_ten_ext,
4914 &vel_grad_test_dS[i*nSpace])+
4915 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_w.data()[ebNE_kb],
4916 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
4917 eb_adjoint_sigma,
4918 w_ext,
4919 bc_w_ext,
4920 normal,
4921 sdInfo_v_w_rowptr.data(),
4922 sdInfo_v_w_colind.data(),
4923 mom_vw_diff_ten_ext,
4924 &vel_grad_test_dS[i*nSpace]));
4925
4926 elementResidual_w[i] += H_s*(ck.ExteriorElementBoundaryFlux(flux_mom_w_adv_ext,vel_test_dS[i]) +
4927 ck.ExteriorElementBoundaryFlux(flux_mom_wu_diff_ext,vel_test_dS[i])+
4928 ck.ExteriorElementBoundaryFlux(flux_mom_wv_diff_ext,vel_test_dS[i])+
4929 ck.ExteriorElementBoundaryFlux(flux_mom_ww_diff_ext,vel_test_dS[i])+
4930 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_u.data()[ebNE_kb],
4931 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4932 eb_adjoint_sigma,
4933 u_ext,
4934 bc_u_ext,
4935 normal,
4936 sdInfo_w_u_rowptr.data(),
4937 sdInfo_w_u_colind.data(),
4938 mom_wu_diff_ten_ext,
4939 &vel_grad_test_dS[i*nSpace])+
4940 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_v.data()[ebNE_kb],
4941 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4942 eb_adjoint_sigma,
4943 v_ext,
4944 bc_v_ext,
4945 normal,
4946 sdInfo_w_v_rowptr.data(),
4947 sdInfo_w_v_colind.data(),
4948 mom_wv_diff_ten_ext,
4949 &vel_grad_test_dS[i*nSpace])+
4950 ck.ExteriorElementBoundaryDiffusionAdjoint(isDOFBoundary_w.data()[ebNE_kb],
4951 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
4952 eb_adjoint_sigma,
4953 w_ext,
4954 bc_w_ext,
4955 normal,
4956 sdInfo_w_w_rowptr.data(),
4957 sdInfo_w_w_colind.data(),
4958 mom_ww_diff_ten_ext,
4959 &vel_grad_test_dS[i*nSpace]));
4960 }//i
4961 }//if boundary flag positive
4962 }//kb
4963 //
4964 //update the element and global residual storage
4965 //
4966 for (int i=0;i<nDOF_test_element;i++)
4967 {
4968 int eN_i = eN*nDOF_test_element+i;
4969
4970 elementResidual_p_save.data()[eN_i] += elementResidual_p[i];
4971 mesh_volume_conservation_weak += elementResidual_mesh[i];
4972 globalResidual.data()[offset_p+stride_p*rp_l2g.data()[eN_i]]+=elementResidual_p[i];
4973 }
4974 for (int i=0;i<nDOF_v_test_element;i++)
4975 {
4976 int eN_i = eN*nDOF_v_test_element+i;
4977 globalResidual.data()[offset_u+stride_u*rvel_l2g.data()[eN_i]]+=elementResidual_u[i];
4978 globalResidual.data()[offset_v+stride_v*rvel_l2g.data()[eN_i]]+=elementResidual_v[i];
4979 globalResidual.data()[offset_w+stride_w*rvel_l2g.data()[eN_i]]+=elementResidual_w[i];
4980 }//i
4981 }//ebNE
4982 if (normalize_pressure)
4983 {
4984 double send[4]={pa_dv,p_dv,total_volume, total_surface_area}, recv[4]={0.,0.,0.,0.};
4985 MPI_Allreduce(send, recv,4,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
4986 pa_dv = recv[0];
4987 p_dv = recv[1];
4988 total_volume = recv[2];
4989 total_surface_area = recv[3];
4990 //std::cout<<"Domain Volume: "<<total_volume<<std::endl;
4991 //std::cout<<"Domain Surface Area: "<<total_surface_area<<std::endl;
4992 //cek hack
4993 // 1. This forces the pressure average to match the average of the analytical solution (or zero of no analytical solution is given)
4994 // 2. I'm manually figuring out how many pressure dof there are
4995 /* std::cout<<"mesh volume conservation = "<<mesh_volume_conservation<<std::endl; */
4996 /* std::cout<<"mesh volume conservation weak = "<<mesh_volume_conservation_weak<<std::endl; */
4997 /* std::cout<<"mesh volume conservation err max= "<<mesh_volume_conservation_err_max<<std::endl; */
4998 /* std::cout<<"mesh volume conservation err max weak = "<<mesh_volume_conservation_err_max_weak<<std::endl; */
4999 /* std::cout<<"Pressure Integral "<<p_dv<<std::endl */
5000 /* <<"Analytical Pressure Integral "<<pa_dv<<std::endl */
5001 /* <<"Total Boundary Flux "<<total_flux<<std::endl; */
5002 int nDOF_pressure=0;
5003 for(int eN=0;eN<nElements_global;eN++)
5004 {
5005 for (int i=0;i<nDOF_test_element;i++)
5006 {
5007 int eN_i = eN*nDOF_test_element+i;
5008 if (p_l2g.data()[eN_i] > nDOF_pressure)
5009 nDOF_pressure=p_l2g.data()[eN_i];
5010 }
5011 }
5012 nDOF_pressure +=1;
5013 assert(p_dof.shape(0) == nDOF_pressure);
5014 //std::cout<<"nDOF_pressure "<<nDOF_pressure<<std::endl;
5015 for (int I=0;I<nDOF_pressure;I++)
5016 p_dof.data()[I] += (pa_dv - p_dv)/total_volume;
5017 double p_dv_new=0.0, pa_dv_new=0.0;
5018 p_L1=0.0;
5019 p_L2=0.0;
5020 p_LI=0.0;
5021 for (int eN=0 ; eN < nElements_owned ; ++eN)
5022 {
5023 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
5024 for (int j=0;j<nDOF_mesh_trial_element;j++)
5025 {
5026 int eN_j = eN*nDOF_mesh_trial_element+j;
5027 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
5028 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
5029 }
5030 double element_nodes[nDOF_mesh_trial_element*3];
5031 for (int i=0;i<nDOF_mesh_trial_element;i++)
5032 {
5033 int eN_i=eN*nDOF_mesh_trial_element+i;
5034 for(int I=0;I<3;I++)
5035 element_nodes[i*3 + I] = mesh_dof[mesh_l2g[eN_i]*3 + I];
5036 }//i
5037 int icase_s = gf_s.calculate(element_phi_s, element_nodes, x_ref.data(), false);
5038 for (int k=0 ; k < nQuadraturePoints_element ; ++k)
5039 {
5040 int eN_k = eN*nQuadraturePoints_element + k;
5041 int eN_nDOF_trial_element = eN*nDOF_trial_element;
5042
5043 double jac[nSpace*nSpace];
5044 double jacInv[nSpace*nSpace];
5045 double p=0.0,pe=0.0;
5046 double jacDet, x, y, z, dV, h_phi;
5047 gf_s.set_quad(k);
5048 double H_s = gf_s.H(0.,0.);
5049 ck.calculateMapping_element(eN,
5050 k,
5051 mesh_dof.data(),
5052 mesh_l2g.data(),
5053 mesh_trial_ref.data(),
5054 mesh_grad_trial_ref.data(),
5055 jac,
5056 jacDet,
5057 jacInv,
5058 x,y,z);
5059 dV = fabs(jacDet)*dV_ref.data()[k];
5060 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_ref.data()[k*nDOF_trial_element],p);
5061 if (isActiveElement[eN])
5062 {
5063 p_dv_new += p*H_s*dV;
5064 pa_dv_new += q_u_0.data()[eN_k]*H_s*dV;
5065 pe = p-q_u_0.data()[eN_k];
5066 p_L1 += fabs(pe)*H_s*dV;
5067 p_L2 += pe*pe*H_s*dV;
5068 if (fabs(pe) > p_LI)
5069 p_LI = fabs(pe);
5070 }
5071 }
5072 }
5073 }
5074 assert(errors.shape(0)*errors.shape(1) == 15);
5075 MPI_Allreduce(MPI_IN_PLACE, errors.data(),(errors.shape(0)-1)*errors.shape(1),MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
5076 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);
5077 assert(p_L2 >= 0.0);
5078 assert(u_L2 >= 0.0);
5079 assert(v_L2 >= 0.0);
5080 assert(w_L2 >= 0.0);
5081 assert(velocity_L2 >= 0.0);
5082 p_L2 = sqrt(p_L2);
5083 u_L2 = sqrt(u_L2);
5084 v_L2 = sqrt(v_L2);
5085 w_L2 = sqrt(w_L2);
5086 velocity_L2 = sqrt(velocity_L2);
5087 }
5088
5090 {
5091 double NONCONSERVATIVE_FORM = args.scalar<double>("NONCONSERVATIVE_FORM");
5092 double MOMENTUM_SGE = args.scalar<double>("MOMENTUM_SGE");
5093 double PRESSURE_SGE = args.scalar<double>("PRESSURE_SGE");
5094 double VELOCITY_SGE = args.scalar<double>("VELOCITY_SGE");
5095 double PRESSURE_PROJECTION_STABILIZATION = args.scalar<double>("PRESSURE_PROJECTION_STABILIZATION");
5096 xt::pyarray<double>& mesh_trial_ref = args.array<double>("mesh_trial_ref");
5097 xt::pyarray<double>& mesh_grad_trial_ref = args.array<double>("mesh_grad_trial_ref");
5098 xt::pyarray<double>& mesh_dof = args.array<double>("mesh_dof");
5099 xt::pyarray<double>& mesh_velocity_dof = args.array<double>("mesh_velocity_dof");
5100 double MOVING_DOMAIN = args.scalar<double>("MOVING_DOMAIN");
5101 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
5102 xt::pyarray<double>& x_ref = args.array<double>("x_ref");
5103 xt::pyarray<double>& dV_ref = args.array<double>("dV_ref");
5104 xt::pyarray<double>& p_trial_ref = args.array<double>("p_trial_ref");
5105 xt::pyarray<double>& p_grad_trial_ref = args.array<double>("p_grad_trial_ref");
5106 xt::pyarray<double>& p_test_ref = args.array<double>("p_test_ref");
5107 xt::pyarray<double>& p_grad_test_ref = args.array<double>("p_grad_test_ref");
5108 xt::pyarray<double>& vel_trial_ref = args.array<double>("vel_trial_ref");
5109 xt::pyarray<double>& vel_grad_trial_ref = args.array<double>("vel_grad_trial_ref");
5110 xt::pyarray<double>& vel_test_ref = args.array<double>("vel_test_ref");
5111 xt::pyarray<double>& vel_grad_test_ref = args.array<double>("vel_grad_test_ref");
5112 xt::pyarray<double>& mesh_trial_trace_ref = args.array<double>("mesh_trial_trace_ref");
5113 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.array<double>("mesh_grad_trial_trace_ref");
5114 xt::pyarray<double>& xb_ref = args.array<double>("xb_ref");
5115 xt::pyarray<double>& dS_ref = args.array<double>("dS_ref");
5116 xt::pyarray<double>& p_trial_trace_ref = args.array<double>("p_trial_trace_ref");
5117 xt::pyarray<double>& p_grad_trial_trace_ref = args.array<double>("p_grad_trial_trace_ref");
5118 xt::pyarray<double>& p_test_trace_ref = args.array<double>("p_test_trace_ref");
5119 xt::pyarray<double>& p_grad_test_trace_ref = args.array<double>("p_grad_test_trace_ref");
5120 xt::pyarray<double>& vel_trial_trace_ref = args.array<double>("vel_trial_trace_ref");
5121 xt::pyarray<double>& vel_grad_trial_trace_ref = args.array<double>("vel_grad_trial_trace_ref");
5122 xt::pyarray<double>& vel_test_trace_ref = args.array<double>("vel_test_trace_ref");
5123 xt::pyarray<double>& vel_grad_test_trace_ref = args.array<double>("vel_grad_test_trace_ref");
5124 xt::pyarray<double>& normal_ref = args.array<double>("normal_ref");
5125 xt::pyarray<double>& boundaryJac_ref = args.array<double>("boundaryJac_ref");
5126 double eb_adjoint_sigma = args.scalar<double>("eb_adjoint_sigma");
5127 xt::pyarray<double>& elementDiameter = args.array<double>("elementDiameter");
5128 xt::pyarray<double>& elementBoundaryDiameter = args.array<double>("elementBoundaryDiameter");
5129 xt::pyarray<double>& nodeDiametersArray = args.array<double>("nodeDiametersArray");
5130 double hFactor = args.scalar<double>("hFactor");
5131 int nElements_global = args.scalar<int>("nElements_global");
5132 double useRBLES = args.scalar<double>("useRBLES");
5133 double useMetrics = args.scalar<double>("useMetrics");
5134 double alphaBDF = args.scalar<double>("alphaBDF");
5135 double epsFact_rho = args.scalar<double>("epsFact_rho");
5136 double epsFact_mu = args.scalar<double>("epsFact_mu");
5137 double sigma = args.scalar<double>("sigma");
5138 double rho_0 = args.scalar<double>("rho_0");
5139 double nu_0 = args.scalar<double>("nu_0");
5140 double rho_1 = args.scalar<double>("rho_1");
5141 double nu_1 = args.scalar<double>("nu_1");
5142 double smagorinskyConstant = args.scalar<double>("smagorinskyConstant");
5143 int turbulenceClosureModel = args.scalar<int>("turbulenceClosureModel");
5144 double Ct_sge = args.scalar<double>("Ct_sge");
5145 double Cd_sge = args.scalar<double>("Cd_sge");
5146 double C_dg = args.scalar<double>("C_dg");
5147 double C_b = args.scalar<double>("C_b");
5148 const xt::pyarray<double>& eps_solid = args.array<double>("eps_solid");
5149 const xt::pyarray<double>& phi_solid = args.array<double>("phi_solid");
5150 const xt::pyarray<double>& eps_porous = args.array<double>("eps_porous");
5151 const xt::pyarray<double>& phi_porous = args.array<double>("phi_porous");
5152 const xt::pyarray<double>& q_velocity_porous = args.array<double>("q_velocity_porous");
5153 const xt::pyarray<double>& q_porosity = args.array<double>("q_porosity");
5154 const xt::pyarray<double>& q_dragAlpha = args.array<double>("q_dragAlpha");
5155 const xt::pyarray<double>& q_dragBeta = args.array<double>("q_dragBeta");
5156 const xt::pyarray<double>& q_mass_source = args.array<double>("q_mass_source");
5157 const xt::pyarray<double>& q_turb_var_0 = args.array<double>("q_turb_var_0");
5158 const xt::pyarray<double>& q_turb_var_1 = args.array<double>("q_turb_var_1");
5159 const xt::pyarray<double>& q_turb_var_grad_0 = args.array<double>("q_turb_var_grad_0");
5160 const double LAG_LES = args.scalar<double>("LAG_LES");
5161 xt::pyarray<double> & q_eddy_viscosity_last = args.array<double>("q_eddy_viscosity_last");
5162 xt::pyarray<double> & ebqe_eddy_viscosity_last = args.array<double>("ebqe_eddy_viscosity_last");
5163 xt::pyarray<int>& p_l2g = args.array<int>("p_l2g");
5164 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
5165 xt::pyarray<double>& p_dof = args.array<double>("p_dof");
5166 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
5167 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
5168 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
5169 xt::pyarray<double>& p_old_dof = args.array<double>("p_old_dof");
5170 xt::pyarray<double>& u_old_dof = args.array<double>("u_old_dof");
5171 xt::pyarray<double>& v_old_dof = args.array<double>("v_old_dof");
5172 xt::pyarray<double>& w_old_dof = args.array<double>("w_old_dof");
5173 xt::pyarray<double>& g = args.array<double>("g");
5174 const double useVF = args.scalar<double>("useVF");
5175 xt::pyarray<double>& vf = args.array<double>("vf");
5176 xt::pyarray<double>& phi = args.array<double>("phi");
5177 xt::pyarray<double>& phi_nodes = args.array<double>("phi_nodes");
5178 xt::pyarray<double>& normal_phi = args.array<double>("normal_phi");
5179 xt::pyarray<double>& kappa_phi = args.array<double>("kappa_phi");
5180 xt::pyarray<double>& q_mom_u_acc_beta_bdf = args.array<double>("q_mom_u_acc_beta_bdf");
5181 xt::pyarray<double>& q_mom_v_acc_beta_bdf = args.array<double>("q_mom_v_acc_beta_bdf");
5182 xt::pyarray<double>& q_mom_w_acc_beta_bdf = args.array<double>("q_mom_w_acc_beta_bdf");
5183 xt::pyarray<double>& q_dV = args.array<double>("q_dV");
5184 xt::pyarray<double>& q_dV_last = args.array<double>("q_dV_last");
5185 xt::pyarray<double>& q_velocity_sge = args.array<double>("q_velocity_sge");
5186 xt::pyarray<double>& q_cfl = args.array<double>("q_cfl");
5187 xt::pyarray<double>& q_numDiff_u_last = args.array<double>("q_numDiff_u_last");
5188 xt::pyarray<double>& q_numDiff_v_last = args.array<double>("q_numDiff_v_last");
5189 xt::pyarray<double>& q_numDiff_w_last = args.array<double>("q_numDiff_w_last");
5190 xt::pyarray<int>& sdInfo_u_u_rowptr = args.array<int>("sdInfo_u_u_rowptr");
5191 xt::pyarray<int>& sdInfo_u_u_colind = args.array<int>("sdInfo_u_u_colind");
5192 xt::pyarray<int>& sdInfo_u_v_rowptr = args.array<int>("sdInfo_u_v_rowptr");
5193 xt::pyarray<int>& sdInfo_u_v_colind = args.array<int>("sdInfo_u_v_colind");
5194 xt::pyarray<int>& sdInfo_u_w_rowptr = args.array<int>("sdInfo_u_w_rowptr");
5195 xt::pyarray<int>& sdInfo_u_w_colind = args.array<int>("sdInfo_u_w_colind");
5196 xt::pyarray<int>& sdInfo_v_v_rowptr = args.array<int>("sdInfo_v_v_rowptr");
5197 xt::pyarray<int>& sdInfo_v_v_colind = args.array<int>("sdInfo_v_v_colind");
5198 xt::pyarray<int>& sdInfo_v_u_rowptr = args.array<int>("sdInfo_v_u_rowptr");
5199 xt::pyarray<int>& sdInfo_v_u_colind = args.array<int>("sdInfo_v_u_colind");
5200 xt::pyarray<int>& sdInfo_v_w_rowptr = args.array<int>("sdInfo_v_w_rowptr");
5201 xt::pyarray<int>& sdInfo_v_w_colind = args.array<int>("sdInfo_v_w_colind");
5202 xt::pyarray<int>& sdInfo_w_w_rowptr = args.array<int>("sdInfo_w_w_rowptr");
5203 xt::pyarray<int>& sdInfo_w_w_colind = args.array<int>("sdInfo_w_w_colind");
5204 xt::pyarray<int>& sdInfo_w_u_rowptr = args.array<int>("sdInfo_w_u_rowptr");
5205 xt::pyarray<int>& sdInfo_w_u_colind = args.array<int>("sdInfo_w_u_colind");
5206 xt::pyarray<int>& sdInfo_w_v_rowptr = args.array<int>("sdInfo_w_v_rowptr");
5207 xt::pyarray<int>& sdInfo_w_v_colind = args.array<int>("sdInfo_w_v_colind");
5208 xt::pyarray<int>& csrRowIndeces_p_p = args.array<int>("csrRowIndeces_p_p");
5209 xt::pyarray<int>& csrColumnOffsets_p_p = args.array<int>("csrColumnOffsets_p_p");
5210 xt::pyarray<int>& csrRowIndeces_p_u = args.array<int>("csrRowIndeces_p_u");
5211 xt::pyarray<int>& csrColumnOffsets_p_u = args.array<int>("csrColumnOffsets_p_u");
5212 xt::pyarray<int>& csrRowIndeces_p_v = args.array<int>("csrRowIndeces_p_v");
5213 xt::pyarray<int>& csrColumnOffsets_p_v = args.array<int>("csrColumnOffsets_p_v");
5214 xt::pyarray<int>& csrRowIndeces_p_w = args.array<int>("csrRowIndeces_p_w");
5215 xt::pyarray<int>& csrColumnOffsets_p_w = args.array<int>("csrColumnOffsets_p_w");
5216 xt::pyarray<int>& csrRowIndeces_u_p = args.array<int>("csrRowIndeces_u_p");
5217 xt::pyarray<int>& csrColumnOffsets_u_p = args.array<int>("csrColumnOffsets_u_p");
5218 xt::pyarray<int>& csrRowIndeces_u_u = args.array<int>("csrRowIndeces_u_u");
5219 xt::pyarray<int>& csrColumnOffsets_u_u = args.array<int>("csrColumnOffsets_u_u");
5220 xt::pyarray<int>& csrRowIndeces_u_v = args.array<int>("csrRowIndeces_u_v");
5221 xt::pyarray<int>& csrColumnOffsets_u_v = args.array<int>("csrColumnOffsets_u_v");
5222 xt::pyarray<int>& csrRowIndeces_u_w = args.array<int>("csrRowIndeces_u_w");
5223 xt::pyarray<int>& csrColumnOffsets_u_w = args.array<int>("csrColumnOffsets_u_w");
5224 xt::pyarray<int>& csrRowIndeces_v_p = args.array<int>("csrRowIndeces_v_p");
5225 xt::pyarray<int>& csrColumnOffsets_v_p = args.array<int>("csrColumnOffsets_v_p");
5226 xt::pyarray<int>& csrRowIndeces_v_u = args.array<int>("csrRowIndeces_v_u");
5227 xt::pyarray<int>& csrColumnOffsets_v_u = args.array<int>("csrColumnOffsets_v_u");
5228 xt::pyarray<int>& csrRowIndeces_v_v = args.array<int>("csrRowIndeces_v_v");
5229 xt::pyarray<int>& csrColumnOffsets_v_v = args.array<int>("csrColumnOffsets_v_v");
5230 xt::pyarray<int>& csrRowIndeces_v_w = args.array<int>("csrRowIndeces_v_w");
5231 xt::pyarray<int>& csrColumnOffsets_v_w = args.array<int>("csrColumnOffsets_v_w");
5232 xt::pyarray<int>& csrRowIndeces_w_p = args.array<int>("csrRowIndeces_w_p");
5233 xt::pyarray<int>& csrColumnOffsets_w_p = args.array<int>("csrColumnOffsets_w_p");
5234 xt::pyarray<int>& csrRowIndeces_w_u = args.array<int>("csrRowIndeces_w_u");
5235 xt::pyarray<int>& csrColumnOffsets_w_u = args.array<int>("csrColumnOffsets_w_u");
5236 xt::pyarray<int>& csrRowIndeces_w_v = args.array<int>("csrRowIndeces_w_v");
5237 xt::pyarray<int>& csrColumnOffsets_w_v = args.array<int>("csrColumnOffsets_w_v");
5238 xt::pyarray<int>& csrRowIndeces_w_w = args.array<int>("csrRowIndeces_w_w");
5239 xt::pyarray<int>& csrColumnOffsets_w_w = args.array<int>("csrColumnOffsets_w_w");
5240 xt::pyarray<double>& globalJacobian = args.array<double>("globalJacobian");
5241 int nExteriorElementBoundaries_global = args.scalar<int>("nExteriorElementBoundaries_global");
5242 xt::pyarray<int>& exteriorElementBoundariesArray = args.array<int>("exteriorElementBoundariesArray");
5243 xt::pyarray<int>& elementBoundaryElementsArray = args.array<int>("elementBoundaryElementsArray");
5244 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.array<int>("elementBoundaryLocalElementBoundariesArray");
5245 xt::pyarray<double>& ebqe_vf_ext = args.array<double>("ebqe_vf_ext");
5246 xt::pyarray<double>& bc_ebqe_vf_ext = args.array<double>("bc_ebqe_vf_ext");
5247 xt::pyarray<double>& ebqe_phi_ext = args.array<double>("ebqe_phi_ext");
5248 xt::pyarray<double>& bc_ebqe_phi_ext = args.array<double>("bc_ebqe_phi_ext");
5249 xt::pyarray<double>& ebqe_normal_phi_ext = args.array<double>("ebqe_normal_phi_ext");
5250 xt::pyarray<double>& ebqe_kappa_phi_ext = args.array<double>("ebqe_kappa_phi_ext");
5251 const xt::pyarray<double>& ebqe_porosity_ext = args.array<double>("ebqe_porosity_ext");
5252 const xt::pyarray<double>& ebqe_turb_var_0 = args.array<double>("ebqe_turb_var_0");
5253 const xt::pyarray<double>& ebqe_turb_var_1 = args.array<double>("ebqe_turb_var_1");
5254 xt::pyarray<int>& isDOFBoundary_p = args.array<int>("isDOFBoundary_p");
5255 xt::pyarray<int>& isDOFBoundary_u = args.array<int>("isDOFBoundary_u");
5256 xt::pyarray<int>& isDOFBoundary_v = args.array<int>("isDOFBoundary_v");
5257 xt::pyarray<int>& isDOFBoundary_w = args.array<int>("isDOFBoundary_w");
5258 xt::pyarray<int>& isAdvectiveFluxBoundary_p = args.array<int>("isAdvectiveFluxBoundary_p");
5259 xt::pyarray<int>& isAdvectiveFluxBoundary_u = args.array<int>("isAdvectiveFluxBoundary_u");
5260 xt::pyarray<int>& isAdvectiveFluxBoundary_v = args.array<int>("isAdvectiveFluxBoundary_v");
5261 xt::pyarray<int>& isAdvectiveFluxBoundary_w = args.array<int>("isAdvectiveFluxBoundary_w");
5262 xt::pyarray<int>& isDiffusiveFluxBoundary_u = args.array<int>("isDiffusiveFluxBoundary_u");
5263 xt::pyarray<int>& isDiffusiveFluxBoundary_v = args.array<int>("isDiffusiveFluxBoundary_v");
5264 xt::pyarray<int>& isDiffusiveFluxBoundary_w = args.array<int>("isDiffusiveFluxBoundary_w");
5265 xt::pyarray<double>& ebqe_bc_p_ext = args.array<double>("ebqe_bc_p_ext");
5266 xt::pyarray<double>& ebqe_bc_flux_mass_ext = args.array<double>("ebqe_bc_flux_mass_ext");
5267 xt::pyarray<double>& ebqe_bc_flux_mom_u_adv_ext = args.array<double>("ebqe_bc_flux_mom_u_adv_ext");
5268 xt::pyarray<double>& ebqe_bc_flux_mom_v_adv_ext = args.array<double>("ebqe_bc_flux_mom_v_adv_ext");
5269 xt::pyarray<double>& ebqe_bc_flux_mom_w_adv_ext = args.array<double>("ebqe_bc_flux_mom_w_adv_ext");
5270 xt::pyarray<double>& ebqe_bc_u_ext = args.array<double>("ebqe_bc_u_ext");
5271 xt::pyarray<double>& ebqe_bc_flux_u_diff_ext = args.array<double>("ebqe_bc_flux_u_diff_ext");
5272 xt::pyarray<double>& ebqe_penalty_ext = args.array<double>("ebqe_penalty_ext");
5273 xt::pyarray<double>& ebqe_bc_v_ext = args.array<double>("ebqe_bc_v_ext");
5274 xt::pyarray<double>& ebqe_bc_flux_v_diff_ext = args.array<double>("ebqe_bc_flux_v_diff_ext");
5275 xt::pyarray<double>& ebqe_bc_w_ext = args.array<double>("ebqe_bc_w_ext");
5276 xt::pyarray<double>& ebqe_bc_flux_w_diff_ext = args.array<double>("ebqe_bc_flux_w_diff_ext");
5277 xt::pyarray<int>& csrColumnOffsets_eb_p_p = args.array<int>("csrColumnOffsets_eb_p_p");
5278 xt::pyarray<int>& csrColumnOffsets_eb_p_u = args.array<int>("csrColumnOffsets_eb_p_u");
5279 xt::pyarray<int>& csrColumnOffsets_eb_p_v = args.array<int>("csrColumnOffsets_eb_p_v");
5280 xt::pyarray<int>& csrColumnOffsets_eb_p_w = args.array<int>("csrColumnOffsets_eb_p_w");
5281 xt::pyarray<int>& csrColumnOffsets_eb_u_p = args.array<int>("csrColumnOffsets_eb_u_p");
5282 xt::pyarray<int>& csrColumnOffsets_eb_u_u = args.array<int>("csrColumnOffsets_eb_u_u");
5283 xt::pyarray<int>& csrColumnOffsets_eb_u_v = args.array<int>("csrColumnOffsets_eb_u_v");
5284 xt::pyarray<int>& csrColumnOffsets_eb_u_w = args.array<int>("csrColumnOffsets_eb_u_w");
5285 xt::pyarray<int>& csrColumnOffsets_eb_v_p = args.array<int>("csrColumnOffsets_eb_v_p");
5286 xt::pyarray<int>& csrColumnOffsets_eb_v_u = args.array<int>("csrColumnOffsets_eb_v_u");
5287 xt::pyarray<int>& csrColumnOffsets_eb_v_v = args.array<int>("csrColumnOffsets_eb_v_v");
5288 xt::pyarray<int>& csrColumnOffsets_eb_v_w = args.array<int>("csrColumnOffsets_eb_v_w");
5289 xt::pyarray<int>& csrColumnOffsets_eb_w_p = args.array<int>("csrColumnOffsets_eb_w_p");
5290 xt::pyarray<int>& csrColumnOffsets_eb_w_u = args.array<int>("csrColumnOffsets_eb_w_u");
5291 xt::pyarray<int>& csrColumnOffsets_eb_w_v = args.array<int>("csrColumnOffsets_eb_w_v");
5292 xt::pyarray<int>& csrColumnOffsets_eb_w_w = args.array<int>("csrColumnOffsets_eb_w_w");
5293 xt::pyarray<int>& elementFlags = args.array<int>("elementFlags");
5294 xt::pyarray<int>& boundaryFlags = args.array<int>("boundaryFlags");
5295 int use_ball_as_particle = args.scalar<int>("use_ball_as_particle");
5296 xt::pyarray<double>& ball_center = args.array<double>("ball_center");
5297 xt::pyarray<double>& ball_radius = args.array<double>("ball_radius");
5298 xt::pyarray<double>& ball_velocity = args.array<double>("ball_velocity");
5299 xt::pyarray<double>& ball_angular_velocity = args.array<double>("ball_angular_velocity");
5300 xt::pyarray<double>& ball_density = args.array<double>("ball_density");
5301 xt::pyarray<double>& particle_signed_distances = args.array<double>("particle_signed_distances");
5302 xt::pyarray<double>& particle_signed_distance_normals = args.array<double>("particle_signed_distance_normals");
5303 xt::pyarray<double>& particle_velocities = args.array<double>("particle_velocities");
5304 xt::pyarray<double>& particle_centroids = args.array<double>("particle_centroids");
5305 xt::pyarray<double>& ebqe_phi_s = args.array<double>("ebqe_phi_s");
5306 xt::pyarray<double>& ebq_global_grad_phi_s = args.array<double>("ebq_global_grad_phi_s");
5307 xt::pyarray<double>& ebq_particle_velocity_s = args.array<double>("ebq_particle_velocity_s");
5308 xt::pyarray<double>& phi_solid_nodes = args.array<double>("phi_solid_nodes");
5309 xt::pyarray<double>& distance_to_solids = args.array<double>("distance_to_solids");
5310 xt::pyarray<int>& isActiveElement = args.array<int>("isActiveElement");
5311 xt::pyarray<int>& isActiveElement_last = args.array<int>("isActiveElement_last");
5312 int nParticles = args.scalar<int>("nParticles");
5313 int nElements_owned = args.scalar<int>("nElements_owned");
5314 double particle_nitsche = args.scalar<double>("particle_nitsche");
5315 double particle_epsFact = args.scalar<double>("particle_epsFact");
5316 double particle_alpha = args.scalar<double>("particle_alpha");
5317 double particle_beta = args.scalar<double>("particle_beta");
5318 double particle_penalty_constant = args.scalar<double>("particle_penalty_constant");
5319 double ghost_penalty_constant = args.scalar<double>("ghost_penalty_constant");
5320 const bool useExact = args.scalar<int>("useExact");
5321 const int nQuadraturePoints_global(nElements_global*nQuadraturePoints_element);
5322 std::valarray<double> particle_surfaceArea_tmp(nParticles), particle_surfaceArea_projected_tmp(nParticles), projection_direction_tmp(3),
5323 particle_netForces_tmp(nParticles*3*3), particle_netMoments_tmp(nParticles*3), particle_volume_tmp(nParticles);
5324 gf.useExact = false;//useExact;
5325 gf_p.useExact = false;//useExact;
5326 gf_s.useExact = useExact;
5327 //
5328 //loop over elements to compute volume integrals and load them into the element Jacobians and global Jacobian
5329 //
5330 for(int eN=0;eN<nElements_global;eN++)
5331 {
5332 int particle_index=0;
5333 double eps_rho,eps_mu;
5334
5335 double elementJacobian_p_p[nDOF_test_element][nDOF_trial_element],
5336 elementJacobian_p_u[nDOF_test_element][nDOF_v_trial_element],
5337 elementJacobian_p_v[nDOF_test_element][nDOF_v_trial_element],
5338 elementJacobian_p_w[nDOF_test_element][nDOF_v_trial_element],
5339 elementJacobian_u_p[nDOF_v_test_element][nDOF_trial_element],
5340 elementJacobian_u_u[nDOF_v_test_element][nDOF_v_trial_element],
5341 elementJacobian_u_v[nDOF_v_test_element][nDOF_v_trial_element],
5342 elementJacobian_u_w[nDOF_v_test_element][nDOF_v_trial_element],
5343 elementJacobian_v_p[nDOF_v_test_element][nDOF_trial_element],
5344 elementJacobian_v_u[nDOF_v_test_element][nDOF_v_trial_element],
5345 elementJacobian_v_v[nDOF_v_test_element][nDOF_v_trial_element],
5346 elementJacobian_v_w[nDOF_v_test_element][nDOF_v_trial_element],
5347 elementJacobian_w_p[nDOF_v_test_element][nDOF_trial_element],
5348 elementJacobian_w_u[nDOF_v_test_element][nDOF_v_trial_element],
5349 elementJacobian_w_v[nDOF_v_test_element][nDOF_v_trial_element],
5350 elementJacobian_w_w[nDOF_v_test_element][nDOF_v_trial_element];
5351 for (int i=0;i<nDOF_test_element;i++)
5352 for (int j=0;j<nDOF_trial_element;j++)
5353 {
5354 elementJacobian_p_p[i][j]=0.0;
5355 }
5356 for (int i=0;i<nDOF_test_element;i++)
5357 for (int j=0;j<nDOF_v_trial_element;j++)
5358 {
5359 elementJacobian_p_u[i][j]=0.0;
5360 elementJacobian_p_v[i][j]=0.0;
5361 elementJacobian_p_w[i][j]=0.0;
5362 elementJacobian_u_p[j][i]=0.0;
5363 elementJacobian_v_p[j][i]=0.0;
5364 elementJacobian_w_p[j][i]=0.0;
5365 }
5366 for (int i=0;i<nDOF_v_test_element;i++)
5367 for (int j=0;j<nDOF_v_trial_element;j++)
5368 {
5369 elementJacobian_u_u[i][j]=0.0;
5370 elementJacobian_u_v[i][j]=0.0;
5371 elementJacobian_u_w[i][j]=0.0;
5372 elementJacobian_v_u[i][j]=0.0;
5373 elementJacobian_v_v[i][j]=0.0;
5374 elementJacobian_v_w[i][j]=0.0;
5375 elementJacobian_w_u[i][j]=0.0;
5376 elementJacobian_w_v[i][j]=0.0;
5377 elementJacobian_w_w[i][j]=0.0;
5378 }
5379 if(use_ball_as_particle==1 && nParticles > 0)
5380 {
5381 double min_d = 1e10;
5382 particle_index=0;
5383 for (int I=0;I<nDOF_mesh_trial_element;I++)
5384 {
5385 int index = get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),
5386 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+0],
5387 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+1],
5388 mesh_dof.data()[3*mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]+2],
5389 phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]]);
5390 if (phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]] < min_d)
5391 {
5392 min_d = phi_solid_nodes.data()[mesh_l2g.data()[eN*nDOF_mesh_trial_element+I]];
5393 particle_index = index;
5394 }
5395 }
5396 }
5397 else
5398 {
5399 //phi_solid_nodes is updated in PreStep
5400 }
5401 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
5402 for (int j=0;j<nDOF_mesh_trial_element;j++)
5403 {
5404 int eN_j = eN*nDOF_mesh_trial_element+j;
5405 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
5406 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
5407 }
5408 double element_nodes[nDOF_mesh_trial_element*3];
5409 for (int i=0;i<nDOF_mesh_trial_element;i++)
5410 {
5411 int eN_i=eN*nDOF_mesh_trial_element+i;
5412 for(int I=0;I<3;I++)
5413 element_nodes[i*3 + I] = mesh_dof.data()[mesh_l2g.data()[eN_i]*3 + I];
5414 }//i
5415 int icase_s = gf_s.calculate(element_phi_s, element_nodes, x_ref.data(), false);
5416#ifdef IFEM
5417 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);
5418 int icase = gf.calculate(element_phi, element_nodes, x_ref.data(), rho_1*nu_1, rho_0*nu_0,false,false);
5419#else
5420 int icase_p = gf_p.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,false,false);
5421 int icase = gf.calculate(element_phi, element_nodes, x_ref.data(), 1.,1.,false,false);
5422#endif
5423 for (int fluid_phase=0;fluid_phase < 2 - abs(icase); fluid_phase++)
5424 {
5425 for (int k=0;k<nQuadraturePoints_element;k++)
5426 {
5427 int eN_k = eN*nQuadraturePoints_element+k, //index to a scalar at a quadrature point
5428 eN_k_nSpace = eN_k*nSpace,
5429 eN_k_3d = eN_k*3,
5430 eN_nDOF_trial_element = eN*nDOF_trial_element, //index to a vector at a quadrature point
5431 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element; //index to a vector at a quadrature point
5432
5433 //declare local storage
5434 double p=0.0,u=0.0,v=0.0,w=0.0,
5435 grad_p[nSpace]=ZEROVEC,grad_u[nSpace]=ZEROVEC,grad_v[nSpace]=ZEROVEC,grad_w[nSpace]=ZEROVEC,
5436 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
5437 grad_p_old[nSpace]=ZEROVEC,grad_u_old[nSpace]=ZEROVEC,grad_v_old[nSpace]=ZEROVEC,grad_w_old[nSpace]=ZEROVEC,
5438 mom_u_acc=0.0,
5439 dmom_u_acc_u=0.0,
5440 mom_v_acc=0.0,
5441 dmom_v_acc_v=0.0,
5442 mom_w_acc=0.0,
5443 dmom_w_acc_w=0.0,
5444 mass_adv[nSpace]=ZEROVEC,
5445 dmass_adv_u[nSpace]=ZEROVEC,
5446 dmass_adv_v[nSpace]=ZEROVEC,
5447 dmass_adv_w[nSpace]=ZEROVEC,
5448 mass_ham=0.0,
5449 dmass_ham_u=0.0,
5450 dmass_ham_v=0.0,
5451 dmass_ham_w=0.0,
5452 mom_u_adv[nSpace]=ZEROVEC,
5453 dmom_u_adv_u[nSpace]=ZEROVEC,
5454 dmom_u_adv_v[nSpace]=ZEROVEC,
5455 dmom_u_adv_w[nSpace]=ZEROVEC,
5456 mom_v_adv[nSpace]=ZEROVEC,
5457 dmom_v_adv_u[nSpace]=ZEROVEC,
5458 dmom_v_adv_v[nSpace]=ZEROVEC,
5459 dmom_v_adv_w[nSpace]=ZEROVEC,
5460 mom_w_adv[nSpace]=ZEROVEC,
5461 dmom_w_adv_u[nSpace]=ZEROVEC,
5462 dmom_w_adv_v[nSpace]=ZEROVEC,
5463 dmom_w_adv_w[nSpace]=ZEROVEC,
5464 mom_uu_diff_ten[nSpace]=ZEROVEC,
5465 mom_vv_diff_ten[nSpace]=ZEROVEC,
5466 mom_ww_diff_ten[nSpace]=ZEROVEC,
5467 mom_uv_diff_ten[1],
5468 mom_uw_diff_ten[1],
5469 mom_vu_diff_ten[1],
5470 mom_vw_diff_ten[1],
5471 mom_wu_diff_ten[1],
5472 mom_wv_diff_ten[1],
5473 mom_u_source=0.0,
5474 mom_v_source=0.0,
5475 mom_w_source=0.0,
5476 mom_u_ham=0.0,
5477 dmom_u_ham_grad_p[nSpace]=ZEROVEC,
5478 dmom_u_ham_grad_u[nSpace]=ZEROVEC,
5479 dmom_u_ham_grad_v[nSpace]=ZEROVEC,
5480 dmom_u_ham_grad_w[nSpace]=ZEROVEC,
5481 dmom_u_ham_u=0.0,
5482 dmom_u_ham_v=0.0,
5483 dmom_u_ham_w=0.0,
5484 mom_v_ham=0.0,
5485 dmom_v_ham_grad_p[nSpace]=ZEROVEC,
5486 dmom_v_ham_grad_u[nSpace]=ZEROVEC,
5487 dmom_v_ham_grad_v[nSpace]=ZEROVEC,
5488 dmom_v_ham_grad_w[nSpace]=ZEROVEC,
5489 dmom_v_ham_u=0.0,
5490 dmom_v_ham_v=0.0,
5491 dmom_v_ham_w=0.0,
5492 mom_w_ham=0.0,
5493 dmom_w_ham_grad_p[nSpace]=ZEROVEC,
5494 dmom_w_ham_grad_u[nSpace]=ZEROVEC,
5495 dmom_w_ham_grad_v[nSpace]=ZEROVEC,
5496 dmom_w_ham_grad_w[nSpace]=ZEROVEC,
5497 dmom_w_ham_u=0.0,
5498 dmom_w_ham_v=0.0,
5499 dmom_w_ham_w=0.0,
5500 mom_u_acc_t=0.0,
5501 dmom_u_acc_u_t=0.0,
5502 mom_v_acc_t=0.0,
5503 dmom_v_acc_v_t=0.0,
5504 mom_w_acc_t=0.0,
5505 dmom_w_acc_w_t=0.0,
5506 pdeResidual_p=0.0,
5507 pdeResidual_u=0.0,
5508 pdeResidual_v=0.0,
5509 pdeResidual_w=0.0,
5510 dpdeResidual_p_u[nDOF_v_trial_element],dpdeResidual_p_v[nDOF_v_trial_element],dpdeResidual_p_w[nDOF_v_trial_element],
5511 dpdeResidual_u_p[nDOF_trial_element],dpdeResidual_u_u[nDOF_v_trial_element],
5512 dpdeResidual_v_p[nDOF_trial_element],dpdeResidual_v_v[nDOF_v_trial_element],
5513 dpdeResidual_w_p[nDOF_trial_element],dpdeResidual_w_w[nDOF_v_trial_element],
5514 Lstar_u_p[nDOF_test_element],
5515 Lstar_v_p[nDOF_test_element],
5516 Lstar_w_p[nDOF_test_element],
5517 Lstar_u_u[nDOF_v_test_element],
5518 Lstar_v_v[nDOF_v_test_element],
5519 Lstar_w_w[nDOF_v_test_element],
5520 Lstar_p_u[nDOF_v_test_element],
5521 Lstar_p_v[nDOF_v_test_element],
5522 Lstar_p_w[nDOF_v_test_element],
5523 subgridError_p=0.0,
5524 subgridError_u=0.0,
5525 subgridError_v=0.0,
5526 subgridError_w=0.0,
5527 dsubgridError_p_u[nDOF_v_trial_element],
5528 dsubgridError_p_v[nDOF_v_trial_element],
5529 dsubgridError_p_w[nDOF_v_trial_element],
5530 dsubgridError_u_p[nDOF_trial_element],
5531 dsubgridError_u_u[nDOF_v_trial_element],
5532 dsubgridError_v_p[nDOF_trial_element],
5533 dsubgridError_v_v[nDOF_v_trial_element],
5534 dsubgridError_w_p[nDOF_trial_element],
5535 dsubgridError_w_w[nDOF_v_trial_element],
5536 tau_p=0.0,tau_p0=0.0,tau_p1=0.0,
5537 tau_v=0.0,tau_v0=0.0,tau_v1=0.0,
5538 jac[nSpace*nSpace],
5539 jacDet,
5540 jacInv[nSpace*nSpace],
5541 p_trial[nDOF_trial_element], vel_trial[nDOF_v_trial_element],
5542 p_grad_trial_ib[nDOF_trial_element*nSpace], vel_grad_trial_ib[nDOF_v_trial_element*nSpace],
5543 p_grad_trial[nDOF_trial_element*nSpace],vel_grad_trial[nDOF_v_trial_element*nSpace],
5544 dV,
5545 p_test_dV[nDOF_test_element],vel_test_dV[nDOF_v_test_element],
5546 p_grad_test_dV[nDOF_test_element*nSpace],vel_grad_test_dV[nDOF_v_test_element*nSpace],
5547 x,y,z,xt,yt,zt,
5548 //VRANS
5549 porosity,
5550 //meanGrainSize,
5551 dmom_u_source[nSpace]=ZEROVEC,
5552 dmom_v_source[nSpace]=ZEROVEC,
5553 dmom_w_source[nSpace]=ZEROVEC,
5554 mass_source,
5555 //
5556 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,
5557 //embedded solid terms
5558 mass_source_s=0.0,
5559 mom_u_source_s=0.0,
5560 mom_v_source_s=0.0,
5561 mom_w_source_s=0.0,
5562 dmom_u_source_s[nSpace]=ZEROVEC,
5563 dmom_v_source_s[nSpace]=ZEROVEC,
5564 dmom_w_source_s[nSpace]=ZEROVEC,
5565 mom_u_adv_s[nSpace]=ZEROVEC,
5566 mom_v_adv_s[nSpace]=ZEROVEC,
5567 mom_w_adv_s[nSpace]=ZEROVEC,
5568 dmom_u_adv_u_s[nSpace]=ZEROVEC,
5569 dmom_v_adv_v_s[nSpace]=ZEROVEC,
5570 dmom_w_adv_w_s[nSpace]=ZEROVEC,
5571 mom_u_ham_s=0.0,
5572 dmom_u_ham_grad_u_s[nSpace]=ZEROVEC,
5573 dmom_u_ham_grad_v_s[nSpace]=ZEROVEC,
5574 dmom_u_ham_grad_w_s[nSpace]=ZEROVEC,
5575 dmom_u_ham_u_s=0.0,
5576 dmom_u_ham_v_s=0.0,
5577 dmom_u_ham_w_s=0.0,
5578 mom_v_ham_s=0.0,
5579 dmom_v_ham_grad_u_s[nSpace]=ZEROVEC,
5580 dmom_v_ham_grad_v_s[nSpace]=ZEROVEC,
5581 dmom_v_ham_grad_w_s[nSpace]=ZEROVEC,
5582 dmom_v_ham_u_s=0.0,
5583 dmom_v_ham_v_s=0.0,
5584 dmom_v_ham_w_s=0.0,
5585 mom_w_ham_s=0.0,
5586 dmom_w_ham_grad_u_s[nSpace]=ZEROVEC,
5587 dmom_w_ham_grad_v_s[nSpace]=ZEROVEC,
5588 dmom_w_ham_grad_w_s[nSpace]=ZEROVEC,
5589 dmom_w_ham_u_s=0.0,
5590 dmom_w_ham_v_s=0.0,
5591 dmom_w_ham_w_s=0.0,
5592 mass_ham_s=0.0,
5593 dmass_ham_u_s=0.0,
5594 dmass_ham_v_s=0.0,
5595 dmass_ham_w_s=0.0;
5596 //get jacobian, etc for mapping reference element
5597 gf_s.set_quad(k);
5598 gf.set_quad(k);
5599 gf_p.set_quad(k);
5600 ck.calculateMapping_element(eN,
5601 k,
5602 mesh_dof.data(),
5603 mesh_l2g.data(),
5604 mesh_trial_ref.data(),
5605 mesh_grad_trial_ref.data(),
5606 jac,
5607 jacDet,
5608 jacInv,
5609 x,y,z);
5610 ck.calculateH_element(eN,
5611 k,
5612 nodeDiametersArray.data(),
5613 mesh_l2g.data(),
5614 mesh_trial_ref.data(),
5615 h_phi);
5616 ck.calculateMappingVelocity_element(eN,
5617 k,
5618 mesh_velocity_dof.data(),
5619 mesh_l2g.data(),
5620 mesh_trial_ref.data(),
5621 xt,yt,zt);
5622 //xt=0.0;yt=0.0;zt=0.0;
5623 //std::cout<<"xt "<<xt<<'\t'<<yt<<'\t'<<zt<<std::endl;
5624 //get the physical integration weight
5625 dV = fabs(jacDet)*dV_ref.data()[k];
5626 ck.calculateG(jacInv,G,G_dd_G,tr_G);
5627 //ck.calculateGScale(G,&normal_phi[eN_k_nSpace],h_phi);
5628
5629 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
5630 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
5631 //get the trial function gradients
5632 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
5633 ck_v.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_v_trial_element*nSpace],jacInv,vel_grad_trial);
5634 for (int i=0; i < nDOF_trial_element; i++)
5635 {
5636 p_trial[i] = p_trial_ref.data()[k*nDOF_trial_element + i];
5637 p_grad_trial_ib[i*nSpace + 0] = p_grad_trial[i*nSpace+0];
5638 p_grad_trial_ib[i*nSpace + 1] = p_grad_trial[i*nSpace+1];
5639 p_grad_trial_ib[i*nSpace + 2] = p_grad_trial[i*nSpace+2];
5640 }
5641 for (int i=0; i < nDOF_v_trial_element; i++)
5642 {
5643 vel_trial[i] = vel_trial_ref.data()[k*nDOF_v_trial_element + i];
5644 vel_grad_trial_ib[i*nSpace + 0] = vel_grad_trial[i*nSpace+0];
5645 vel_grad_trial_ib[i*nSpace + 1] = vel_grad_trial[i*nSpace+1];
5646 vel_grad_trial_ib[i*nSpace + 2] = vel_grad_trial[i*nSpace+2];
5647 }
5648 if (icase == 0)
5649 {
5650#ifdef IFEMBASIS
5651 for (int i=0; i < nDOF_trial_element; i++)
5652 {
5653 if (fluid_phase == 0)
5654 {
5655 if (not std::isnan(gf_p.VA(i)))
5656 {
5657 p_trial[i] = gf_p.VA(i);
5658 p_grad_trial_ib[i*nSpace + 0] = gf_p.VA_x(i);
5659 p_grad_trial_ib[i*nSpace + 1] = gf_p.VA_y(i);
5660 p_grad_trial_ib[i*nSpace + 2] = gf_p.VA_z(i);
5661 }
5662 }
5663 else
5664 {
5665 if (not std::isnan(gf_p.VB(i)))
5666 {
5667 p_trial[i] = gf_p.VB(i);
5668 p_grad_trial_ib[i*nSpace + 0] = gf_p.VB_x(i);
5669 p_grad_trial_ib[i*nSpace + 1] = gf_p.VB_y(i);
5670 p_grad_trial_ib[i*nSpace + 2] = gf_p.VB_z(i);
5671 }
5672 }
5673 }
5674 if(nDOF_v_trial_element == nDOF_trial_element)
5675 {
5676 for (int vi=0; vi < nDOF_v_trial_element; vi++)
5677 {
5678 if (fluid_phase == 0)
5679 {
5680 if (not std::isnan(gf.VA(vi)))
5681 {
5682 vel_trial[vi] = gf.VA(vi);
5683 vel_grad_trial_ib[vi*nSpace + 0] = gf.VA_x(vi);
5684 vel_grad_trial_ib[vi*nSpace + 1] = gf.VA_y(vi);
5685 vel_grad_trial_ib[vi*nSpace + 2] = gf.VA_z(vi);
5686 }
5687 }
5688 else
5689 {
5690 if (not std::isnan(gf.VB(vi)))
5691 {
5692 vel_trial[vi] = gf.VB(vi);
5693 vel_grad_trial_ib[vi*nSpace + 0] = gf.VB_x(vi);
5694 vel_grad_trial_ib[vi*nSpace + 1] = gf.VB_y(vi);
5695 vel_grad_trial_ib[vi*nSpace + 2] = gf.VB_z(vi);
5696 }
5697 }
5698 }
5699 }
5700#endif
5701#ifndef IFEM
5702 bool prob=false;
5703 for (int vi=0; vi < nDOF_v_trial_element; vi++)
5704 {
5705 //pressure
5706 if (fabs(p_trial_ref.data()[k*nDOF_trial_element + vi] - p_trial[vi]) > 1.0e-8)
5707 {
5708 for (int vj=0; vj < nDOF_trial_element; vj++)
5709 std::cout<<"Trial "<<p_trial_ref.data()[k*nDOF_trial_element + vj]<<'\t'<<gf_p.VA(vj)<<'\t'<<gf_p.VB(vj)<<std::endl;
5710 prob=true;
5711 }
5712 if (fabs(p_grad_trial[vi*nSpace + 0] - p_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
5713 {
5714 for (int vj=0; vj < nDOF_trial_element; vj++)
5715 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;
5716 prob=true;
5717 }
5718 if (fabs(p_grad_trial[vi*nSpace + 1] - p_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
5719 {
5720 for (int vj=0; vj < nDOF_trial_element; vj++)
5721 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;
5722 prob=true;
5723 }
5724 if (fabs(p_grad_trial[vi*nSpace + 2] - p_grad_trial_ib[vi*nSpace+2]) > 1.0e-8)
5725 {
5726 for (int vj=0; vj < nDOF_trial_element; vj++)
5727 std::cout<<"Grad Trial z "<<p_grad_trial[vj*nSpace + 2]<<'\t'<<gf_p.VA_z(vj)<<'\t'<<gf_p.VB_z(vj)<<std::endl;
5728 prob=true;
5729 }
5730 //velocity
5731 if (fabs(vel_trial_ref.data()[k*nDOF_v_trial_element + vi] - vel_trial[vi]) > 1.0e-8)
5732 {
5733 for (int vj=0; vj < nDOF_v_trial_element; vj++)
5734 std::cout<<"Trial "<<vel_trial_ref.data()[k*nDOF_v_trial_element + vj]<<'\t'<<gf.VA(vj)<<'\t'<<gf.VB(vj)<<std::endl;
5735 prob=true;
5736 }
5737 if (fabs(vel_grad_trial[vi*nSpace + 0] - vel_grad_trial_ib[vi*nSpace+0]) > 1.0e-8)
5738 {
5739 for (int vj=0; vj < nDOF_v_trial_element; vj++)
5740 std::cout<<"Grad Trial x"<<vel_grad_trial[vj*nSpace + 0]<<'\t'<<gf.VA_x(vj)<<'\t'<<gf.VB_x(vj)<<std::endl;
5741 prob=true;
5742 }
5743 if (fabs(vel_grad_trial[vi*nSpace + 1] - vel_grad_trial_ib[vi*nSpace+1]) > 1.0e-8)
5744 {
5745 for (int vj=0; vj < nDOF_v_trial_element; vj++)
5746 std::cout<<"Grad Trial y "<<vel_grad_trial[vj*nSpace + 1]<<'\t'<<gf.VA_y(vj)<<'\t'<<gf.VB_y(vj)<<std::endl;
5747 prob=true;
5748 }
5749 if (fabs(vel_grad_trial[vi*nSpace + 2] - vel_grad_trial_ib[vi*nSpace+2]) > 1.0e-8)
5750 {
5751 for (int vj=0; vj < nDOF_v_trial_element; vj++)
5752 std::cout<<"Grad Trial z "<<vel_grad_trial[vj*nSpace + 2]<<'\t'<<gf.VA_z(vj)<<'\t'<<gf.VB_z(vj)<<std::endl;
5753 prob=true;
5754 }
5755 if (prob)
5756 break;
5757 }
5758 assert(!prob);
5759#endif
5760 }
5761 //get the solution
5762 ck.valFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_trial,p);
5763 ck_v.valFromDOF(u_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,u);
5764 ck_v.valFromDOF(v_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,v);
5765 ck_v.valFromDOF(w_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,w);
5766 ck.valFromDOF(p_old_dof.data(),&p_l2g[eN_nDOF_trial_element],p_trial,p_old);
5767 ck_v.valFromDOF(u_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,u_old);
5768 ck_v.valFromDOF(v_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,v_old);
5769 ck_v.valFromDOF(w_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_trial,w_old);
5770 //get the solution gradients
5771 ck.gradFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_grad_trial_ib,grad_p);
5772 ck_v.gradFromDOF(u_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u);
5773 ck_v.gradFromDOF(v_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v);
5774 ck_v.gradFromDOF(w_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_w);
5775 ck.gradFromDOF(p_dof.data(),&p_l2g[eN_nDOF_trial_element],p_grad_trial_ib,grad_p_old);
5776 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_u_old);
5777 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_v_old);
5778 ck_v.gradFromDOF(w_old_dof.data(),&vel_l2g[eN_nDOF_v_trial_element],vel_grad_trial_ib,grad_w_old);
5779 //precalculate test function products with integration weights
5780#ifdef IFEMGALERKIN
5781 for (int j=0;j<nDOF_test_element;j++)
5782 {
5783 p_test_dV[j] = p_trial[j]*dV;
5784 for (int I=0;I<nSpace;I++)
5785 {
5786 p_grad_test_dV[j*nSpace+I] = p_grad_trial_ib[j*nSpace+I]*dV;
5787 }
5788 }
5789 for (int j=0;j<nDOF_v_test_element;j++)
5790 {
5791 vel_test_dV[j] = vel_trial[j]*dV;
5792 for (int I=0;I<nSpace;I++)
5793 {
5794 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial_ib[j*nSpace+I]*dV;
5795 }
5796 }
5797#else
5798 for (int j=0;j<nDOF_test_element;j++)
5799 {
5800 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element+j]*dV;
5801 for (int I=0;I<nSpace;I++)
5802 {
5803 p_grad_test_dV[j*nSpace+I] = p_grad_trial[j*nSpace+I]*dV;//assume test_j == trial_j, ok for ifem
5804 }
5805 }
5806 for (int j=0;j<nDOF_v_test_element;j++)
5807 {
5808 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_v_trial_element+j]*dV;
5809 for (int I=0;I<nSpace;I++)
5810 {
5811 vel_grad_test_dV[j*nSpace+I] = vel_grad_trial[j*nSpace+I]*dV;//assume test_j == trial_j, ok for ifem
5812 }
5813 }
5814#endif
5815 //needs to be fixed for higher-order meshes, assuming mesh trial is same as p trial
5816 double div_mesh_velocity=0.0;
5817 for (int j=0;j<nDOF_trial_element;j++)
5818 {
5819 int eN_j=eN*nDOF_trial_element+j;
5820 div_mesh_velocity +=
5821 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+0]*p_grad_trial[j*nSpace+0] +
5822 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+1]*p_grad_trial[j*nSpace+1] +
5823 mesh_velocity_dof.data()[mesh_l2g.data()[eN_j]*3+2]*p_grad_trial[j*nSpace+2];
5824 }
5825 div_mesh_velocity = DM3*div_mesh_velocity + (1.0-DM3)*alphaBDF*(dV-q_dV_last.data()[eN_k])/dV;
5826 //
5827 //VRANS
5828 porosity = q_porosity.data()[eN_k];
5829 //
5830 double ball_n[nSpace];
5831 if (use_ball_as_particle == 1 && nParticles > 0)
5832 {
5833 int ball_index=get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x,y,z,distance_to_solids.data()[eN_k]);
5834 get_normal_to_ith_ball(nParticles, ball_center.data(), ball_radius.data(),ball_index,x,y,z,ball_n[0],ball_n[1],ball_n[2]);
5835 }
5836 else
5837 {
5838 //distance_to_solids is given in Prestep
5839 }
5840 //
5841 //calculate pde coefficients and derivatives at quadrature points
5842 //
5843 double eddy_viscosity(0.);//not really interested in saving eddy_viscosity in jacobian
5844 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
5845 const double H_s = gf_s.H(particle_eps, phi_solid.data()[eN_k]);
5846 double rho,nu;
5847 if (gf.useExact)
5848 {
5849 if (icase == 0)
5850 {
5851 if (fluid_phase == 0)
5852 {
5853 rho=rho_0;
5854 nu=nu_0;
5855 }
5856 else
5857 {
5858 rho=rho_1;
5859 nu=nu_1;
5860 }
5861 }
5862 else if (icase == -1)
5863 {
5864 rho=rho_0;
5865 nu=nu_0;
5866 }
5867 else if (icase == 1)
5868 {
5869 rho=rho_1;
5870 nu=nu_1;
5871 }
5872 else
5873 assert(false);
5874 }
5875 else
5876 {
5877 double H = (1.0-useVF)*gf.H(eps_rho,phi[eN_k]) + useVF*fmin(1.0,fmax(0.0,vf[eN_k]));
5878 double ImH = (1.0-useVF)*gf.ImH(eps_rho,phi[eN_k]) + useVF*(1.0-fmin(1.0,fmax(0.0,vf[eN_k])));
5879
5880 rho = rho_0*ImH + rho_1*H;
5881 nu = nu_0*ImH + nu_1*H;
5882 }
5883 evaluateCoefficients(NONCONSERVATIVE_FORM,
5884 sigma,
5885 rho,
5886 nu,
5887 elementDiameter.data()[eN],
5888 smagorinskyConstant,
5889 turbulenceClosureModel,
5890 g.data(),
5891 useVF,
5892 vf.data()[eN_k],
5893 phi.data()[eN_k],
5894 &normal_phi.data()[eN_k_nSpace],
5895 kappa_phi.data()[eN_k],
5896 //VRANS
5897 porosity,
5898 //
5899 phi_solid.data()[eN_k],//updated in get residual
5900 p_old,
5901 u_old,
5902 v_old,
5903 w_old,
5904 grad_p_old,
5905 grad_u_old,
5906 grad_v_old,
5907 grad_w_old,
5908 p,
5909 grad_p,
5910 grad_u,
5911 grad_v,
5912 grad_w,
5913 u,
5914 v,
5915 w,
5916 LAG_LES,
5917 eddy_viscosity,
5918 q_eddy_viscosity_last.data()[eN_k],
5919 mom_u_acc,
5920 dmom_u_acc_u,
5921 mom_v_acc,
5922 dmom_v_acc_v,
5923 mom_w_acc,
5924 dmom_w_acc_w,
5925 mass_adv,
5926 dmass_adv_u,
5927 dmass_adv_v,
5928 dmass_adv_w,
5929 mom_u_adv,
5930 dmom_u_adv_u,
5931 dmom_u_adv_v,
5932 dmom_u_adv_w,
5933 mom_v_adv,
5934 dmom_v_adv_u,
5935 dmom_v_adv_v,
5936 dmom_v_adv_w,
5937 mom_w_adv,
5938 dmom_w_adv_u,
5939 dmom_w_adv_v,
5940 dmom_w_adv_w,
5941 mom_uu_diff_ten,
5942 mom_vv_diff_ten,
5943 mom_ww_diff_ten,
5944 mom_uv_diff_ten,
5945 mom_uw_diff_ten,
5946 mom_vu_diff_ten,
5947 mom_vw_diff_ten,
5948 mom_wu_diff_ten,
5949 mom_wv_diff_ten,
5950 mom_u_source,
5951 mom_v_source,
5952 mom_w_source,
5953 mom_u_ham,
5954 dmom_u_ham_grad_p,
5955 dmom_u_ham_grad_u,
5956 dmom_u_ham_u,
5957 dmom_u_ham_v,
5958 dmom_u_ham_w,
5959 mom_v_ham,
5960 dmom_v_ham_grad_p,
5961 dmom_v_ham_grad_v,
5962 dmom_v_ham_u,
5963 dmom_v_ham_v,
5964 dmom_v_ham_w,
5965 mom_w_ham,
5966 dmom_w_ham_grad_p,
5967 dmom_w_ham_grad_w,
5968 dmom_w_ham_u,
5969 dmom_w_ham_v,
5970 dmom_w_ham_w,
5971 0.0,
5972 0.0,
5973 0.0);
5974 mass_source = q_mass_source.data()[eN_k];
5975 updateDarcyForchheimerTerms_Ergun(NONCONSERVATIVE_FORM,
5976 /* linearDragFactor, */
5977 /* nonlinearDragFactor, */
5978 /* porosity, */
5979 /* meanGrainSize, */
5980 q_dragAlpha.data()[eN_k],
5981 q_dragBeta.data()[eN_k],
5982 eps_rho,
5983 eps_mu,
5984 rho_0,
5985 nu_0,
5986 rho_1,
5987 nu_1,
5988 useVF,
5989 vf.data()[eN_k],
5990 phi.data()[eN_k],
5991 u,
5992 v,
5993 w,
5994 q_velocity_sge.data()[eN_k_nSpace+0],
5995 q_velocity_sge.data()[eN_k_nSpace+1],
5996 q_velocity_sge.data()[eN_k_nSpace+2],
5997 eps_porous.data()[elementFlags.data()[eN]],
5998 phi_porous.data()[eN_k],
5999 q_velocity_porous.data()[eN_k_nSpace+0],
6000 q_velocity_porous.data()[eN_k_nSpace+1],
6001 q_velocity_porous.data()[eN_k_nSpace+2],
6002 mom_u_source,
6003 mom_v_source,
6004 mom_w_source,
6005 dmom_u_source,
6006 dmom_v_source,
6007 dmom_w_source);
6008
6009 //Turbulence closure model
6010 if (turbulenceClosureModel >= 3)
6011 {
6012 const double c_mu = 0.09;//mwf hack
6013 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
6014 turbulenceClosureModel,
6015 eps_rho,
6016 eps_mu,
6017 rho_0,
6018 nu_0,
6019 rho_1,
6020 nu_1,
6021 useVF,
6022 vf.data()[eN_k],
6023 phi.data()[eN_k],
6024 porosity,
6025 c_mu, //mwf hack
6026 q_turb_var_0.data()[eN_k],
6027 q_turb_var_1.data()[eN_k],
6028 &q_turb_var_grad_0.data()[eN_k_nSpace],
6029 eddy_viscosity,
6030 mom_uu_diff_ten,
6031 mom_vv_diff_ten,
6032 mom_ww_diff_ten,
6033 mom_uv_diff_ten,
6034 mom_uw_diff_ten,
6035 mom_vu_diff_ten,
6036 mom_vw_diff_ten,
6037 mom_wu_diff_ten,
6038 mom_wv_diff_ten,
6039 mom_u_source,
6040 mom_v_source,
6041 mom_w_source);
6042
6043 }
6044 //
6045 //
6046 //moving mesh
6047 //
6048 if (NONCONSERVATIVE_FORM > 0.0)
6049 {
6050 mom_u_ham -= MOVING_DOMAIN*dmom_u_acc_u*(grad_u[0]*xt + grad_u[1]*yt + grad_u[2]*zt);
6051 dmom_u_ham_grad_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*xt;
6052 dmom_u_ham_grad_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
6053 dmom_u_ham_grad_u[2] -= MOVING_DOMAIN*dmom_u_acc_u*zt;
6054 }
6055 else
6056 {
6057 mom_u_adv[0] -= MOVING_DOMAIN*mom_u_acc*xt;
6058 mom_u_adv[1] -= MOVING_DOMAIN*mom_u_acc*yt;
6059 mom_u_adv[2] -= MOVING_DOMAIN*mom_u_acc*zt;
6060 dmom_u_adv_u[0] -= MOVING_DOMAIN*dmom_u_acc_u*xt;
6061 dmom_u_adv_u[1] -= MOVING_DOMAIN*dmom_u_acc_u*yt;
6062 dmom_u_adv_u[2] -= MOVING_DOMAIN*dmom_u_acc_u*zt;
6063 }
6064
6065 if (NONCONSERVATIVE_FORM > 0.0)
6066 {
6067 mom_v_ham -= MOVING_DOMAIN*dmom_v_acc_v*(grad_v[0]*xt + grad_v[1]*yt + grad_v[2]*zt);
6068 dmom_v_ham_grad_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*xt;
6069 dmom_v_ham_grad_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
6070 dmom_v_ham_grad_v[2] -= MOVING_DOMAIN*dmom_v_acc_v*zt;
6071 }
6072 else
6073 {
6074 mom_v_adv[0] -= MOVING_DOMAIN*mom_v_acc*xt;
6075 mom_v_adv[1] -= MOVING_DOMAIN*mom_v_acc*yt;
6076 mom_v_adv[2] -= MOVING_DOMAIN*mom_v_acc*zt;
6077 dmom_v_adv_v[0] -= MOVING_DOMAIN*dmom_v_acc_v*xt;
6078 dmom_v_adv_v[1] -= MOVING_DOMAIN*dmom_v_acc_v*yt;
6079 dmom_v_adv_v[2] -= MOVING_DOMAIN*dmom_v_acc_v*zt;
6080 }
6081
6082 if (NONCONSERVATIVE_FORM > 0.0)
6083 {
6084 mom_w_ham -= MOVING_DOMAIN*dmom_w_acc_w*(grad_w[0]*xt + grad_w[1]*yt + grad_w[2]*zt);
6085 dmom_w_ham_grad_w[0] -= MOVING_DOMAIN*dmom_w_acc_w*xt;
6086 dmom_w_ham_grad_w[1] -= MOVING_DOMAIN*dmom_w_acc_w*yt;
6087 dmom_w_ham_grad_w[2] -= MOVING_DOMAIN*dmom_w_acc_w*zt;
6088 }
6089 else
6090 {
6091 mom_w_adv[0] -= MOVING_DOMAIN*mom_w_acc*xt;
6092 mom_w_adv[1] -= MOVING_DOMAIN*mom_w_acc*yt;
6093 mom_w_adv[2] -= MOVING_DOMAIN*mom_w_acc*zt;
6094 dmom_w_adv_w[0] -= MOVING_DOMAIN*dmom_w_acc_w*xt;
6095 dmom_w_adv_w[1] -= MOVING_DOMAIN*dmom_w_acc_w*yt;
6096 dmom_w_adv_w[2] -= MOVING_DOMAIN*dmom_w_acc_w*zt;
6097 }
6098 //
6099 //calculate time derivatives
6100 //
6101 ck.bdf(alphaBDF,
6102 q_mom_u_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
6103 mom_u_acc,
6104 dmom_u_acc_u,
6105 mom_u_acc_t,
6106 dmom_u_acc_u_t);
6107 ck.bdf(alphaBDF,
6108 q_mom_v_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
6109 mom_v_acc,
6110 dmom_v_acc_v,
6111 mom_v_acc_t,
6112 dmom_v_acc_v_t);
6113 ck.bdf(alphaBDF,
6114 q_mom_w_acc_beta_bdf.data()[eN_k]*q_dV_last.data()[eN_k]/dV,
6115 mom_w_acc,
6116 dmom_w_acc_w,
6117 mom_w_acc_t,
6118 dmom_w_acc_w_t);
6119 if (NONCONSERVATIVE_FORM > 0.0)
6120 {
6121 mom_u_acc_t *= dmom_u_acc_u;
6122 mom_v_acc_t *= dmom_v_acc_v;
6123 mom_w_acc_t *= dmom_w_acc_w;
6124 }
6125 //
6126 //calculate subgrid error contribution to the Jacobian (strong residual, adjoint, jacobian of strong residual)
6127 //
6128 if (NONCONSERVATIVE_FORM > 0.0)
6129 {
6130 dmom_adv_sge[0] = 0.0;
6131 dmom_adv_sge[1] = 0.0;
6132 dmom_adv_sge[2] = 0.0;
6133 dmom_ham_grad_sge[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt);
6134 dmom_ham_grad_sge[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
6135 dmom_ham_grad_sge[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt);
6136 }
6137 else
6138 {
6139 dmom_adv_sge[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt);
6140 dmom_adv_sge[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt);
6141 dmom_adv_sge[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt);
6142 dmom_ham_grad_sge[0] = 0.0;
6143 dmom_ham_grad_sge[1] = 0.0;
6144 dmom_ham_grad_sge[2] = 0.0;
6145 }
6146 double mv_tau[nSpace]=ZEROVEC;
6147 mv_tau[0] = dmom_adv_sge[0] + dmom_ham_grad_sge[0];
6148 mv_tau[1] = dmom_adv_sge[1] + dmom_ham_grad_sge[1];
6149 mv_tau[2] = dmom_adv_sge[2] + dmom_ham_grad_sge[2];
6150 //
6151 //calculate strong residual
6152 //
6153 pdeResidual_p = ck.Advection_strong(dmass_adv_u,grad_u) +
6154 ck.Advection_strong(dmass_adv_v,grad_v) +
6155 ck.Advection_strong(dmass_adv_w,grad_w) +
6156 DM2*MOVING_DOMAIN*ck.Reaction_strong(alphaBDF*(dV-q_dV_last.data()[eN_k])/dV - div_mesh_velocity) +
6157 ck.Reaction_strong(mass_source);
6158
6159 pdeResidual_u = ck.Mass_strong(mom_u_acc_t) +
6160 ck.Advection_strong(dmom_adv_sge,grad_u) +
6161 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_u) +
6162 ck.Hamiltonian_strong(dmom_u_ham_grad_p,grad_p) +
6163 ck.Reaction_strong(mom_u_source) -
6164 ck.Reaction_strong(dmom_u_acc_u*u*div_mesh_velocity);
6165
6166 pdeResidual_v = ck.Mass_strong(mom_v_acc_t) +
6167 ck.Advection_strong(dmom_adv_sge,grad_v) +
6168 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_v) +
6169 ck.Hamiltonian_strong(dmom_v_ham_grad_p,grad_p) +
6170 ck.Reaction_strong(mom_v_source) -
6171 ck.Reaction_strong(dmom_v_acc_v*v*div_mesh_velocity);
6172
6173 pdeResidual_w = ck.Mass_strong(mom_w_acc_t) +
6174 ck.Advection_strong(dmom_adv_sge,grad_w) +
6175 ck.Hamiltonian_strong(dmom_ham_grad_sge,grad_w) +
6176 ck.Hamiltonian_strong(dmom_w_ham_grad_p,grad_p) +
6177 ck.Reaction_strong(mom_w_source) -
6178 ck.Reaction_strong(dmom_w_acc_w*w*div_mesh_velocity);
6179
6180 //calculate the Jacobian of strong residual
6181 for (int j=0;j<nDOF_v_trial_element;j++)
6182 {
6183 int j_nSpace = j*nSpace;
6184 dpdeResidual_p_u[j]=ck.AdvectionJacobian_strong(dmass_adv_u,&vel_grad_trial_ib[j_nSpace]);
6185 dpdeResidual_p_v[j]=ck.AdvectionJacobian_strong(dmass_adv_v,&vel_grad_trial_ib[j_nSpace]);
6186 dpdeResidual_p_w[j]=ck.AdvectionJacobian_strong(dmass_adv_w,&vel_grad_trial_ib[j_nSpace]);
6187 dpdeResidual_u_u[j]=ck.MassJacobian_strong(dmom_u_acc_u_t,vel_trial[j]) +
6188 ck.HamiltonianJacobian_strong(dmom_ham_grad_sge,&vel_grad_trial_ib[j_nSpace]) +
6189 ck.AdvectionJacobian_strong(dmom_adv_sge,&vel_grad_trial_ib[j_nSpace]) -
6190 ck.ReactionJacobian_strong(dmom_u_acc_u*div_mesh_velocity,vel_trial[j]);
6191 dpdeResidual_v_v[j]=ck.MassJacobian_strong(dmom_v_acc_v_t,vel_trial[j]) +
6192 ck.HamiltonianJacobian_strong(dmom_ham_grad_sge,&vel_grad_trial_ib[j_nSpace]) +
6193 ck.AdvectionJacobian_strong(dmom_adv_sge,&vel_grad_trial_ib[j_nSpace]) -
6194 ck.ReactionJacobian_strong(dmom_v_acc_v*div_mesh_velocity,vel_trial[j]);
6195 dpdeResidual_w_w[j]=ck.MassJacobian_strong(dmom_w_acc_w_t,vel_trial[j]) +
6196 ck.HamiltonianJacobian_strong(dmom_ham_grad_sge,&vel_grad_trial_ib[j_nSpace]) +
6197 ck.AdvectionJacobian_strong(dmom_adv_sge,&vel_grad_trial_ib[j_nSpace]) -
6198 ck.ReactionJacobian_strong(dmom_w_acc_w*div_mesh_velocity,vel_trial[j]);
6199 //VRANS account for drag terms, diagonal only here ... decide if need off diagonal terms too
6200 dpdeResidual_u_u[j]+= ck.ReactionJacobian_strong(dmom_u_source[0],vel_trial[j]);
6201 dpdeResidual_v_v[j]+= ck.ReactionJacobian_strong(dmom_v_source[1],vel_trial[j]);
6202 dpdeResidual_w_w[j]+= ck.ReactionJacobian_strong(dmom_w_source[2],vel_trial[j]);
6203 }
6204 for (int j=0;j<nDOF_trial_element;j++)
6205 {
6206 int j_nSpace = j*nSpace;
6207 dpdeResidual_u_p[j]=ck.HamiltonianJacobian_strong(dmom_u_ham_grad_p,&p_grad_trial_ib[j_nSpace]);
6208 dpdeResidual_v_p[j]=ck.HamiltonianJacobian_strong(dmom_v_ham_grad_p,&p_grad_trial_ib[j_nSpace]);
6209 dpdeResidual_w_p[j]=ck.HamiltonianJacobian_strong(dmom_w_ham_grad_p,&p_grad_trial_ib[j_nSpace]);
6210 }
6211 //calculate tau and tau*Res
6212 //add contributions from mass and sourced terms
6213 double tmpR=dmom_u_acc_u_t + dmom_u_source[0];
6215 elementDiameter.data()[eN],
6216 tmpR,//dmom_u_acc_u_t,
6217 dmom_u_acc_u,
6218 mv_tau,//dmom_adv_sge,
6219 mom_uu_diff_ten[1],
6220 dmom_u_ham_grad_p[0],
6221 tau_v0,
6222 tau_p0,
6223 q_cfl.data()[eN_k]);
6224
6225 calculateSubgridError_tau(Ct_sge,Cd_sge,
6226 G,G_dd_G,tr_G,
6227 tmpR,//dmom_u_acc_u_t,
6228 mv_tau,//dmom_adv_sge,
6229 mom_uu_diff_ten[1],
6230 dmom_u_ham_grad_p[0],
6231 tau_v1,
6232 tau_p1,
6233 q_cfl.data()[eN_k]);
6234
6235 tau_v = useMetrics*tau_v1+(1.0-useMetrics)*tau_v0;
6236 tau_p = useMetrics*tau_p1+(1.0-useMetrics)*tau_p0;
6237
6239 tau_v,
6240 pdeResidual_p,
6241 pdeResidual_u,
6242 pdeResidual_v,
6243 pdeResidual_w,
6244 subgridError_p,
6245 subgridError_u,
6246 subgridError_v,
6247 subgridError_w);
6248
6250 tau_v,
6251 dpdeResidual_p_u,
6252 dpdeResidual_p_v,
6253 dpdeResidual_p_w,
6254 dpdeResidual_u_p,
6255 dpdeResidual_u_u,
6256 dpdeResidual_v_p,
6257 dpdeResidual_v_v,
6258 dpdeResidual_w_p,
6259 dpdeResidual_w_w,
6260 dsubgridError_p_u,
6261 dsubgridError_p_v,
6262 dsubgridError_p_w,
6263 dsubgridError_u_p,
6264 dsubgridError_u_u,
6265 dsubgridError_v_p,
6266 dsubgridError_v_v,
6267 dsubgridError_w_p,
6268 dsubgridError_w_w);
6269 // velocity used in adjoint (VMS or RBLES, with or without lagging the grid scale velocity)
6270 dmom_adv_star[0] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+0] - MOVING_DOMAIN*xt + useRBLES*subgridError_u);
6271 dmom_adv_star[1] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+1] - MOVING_DOMAIN*yt + useRBLES*subgridError_v);
6272 dmom_adv_star[2] = inertial_term*dmom_u_acc_u*(q_velocity_sge.data()[eN_k_nSpace+2] - MOVING_DOMAIN*zt + useRBLES*subgridError_w);
6273
6274 //calculate the adjoint times the test functions
6275 for (int i=0;i<nDOF_test_element;i++)
6276 {
6277 int i_nSpace = i*nSpace;
6278 Lstar_u_p[i]=ck.Advection_adjoint(dmass_adv_u,&p_grad_test_dV[i_nSpace]);
6279 Lstar_v_p[i]=ck.Advection_adjoint(dmass_adv_v,&p_grad_test_dV[i_nSpace]);
6280 Lstar_w_p[i]=ck.Advection_adjoint(dmass_adv_w,&p_grad_test_dV[i_nSpace]);
6281 }
6282 //calculate the adjoint times the test functions
6283 for (int i=0;i<nDOF_v_test_element;i++)
6284 {
6285 int i_nSpace = i*nSpace;
6286 Lstar_u_u[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
6287 Lstar_v_v[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
6288 Lstar_w_w[i]=ck.Advection_adjoint(dmom_adv_star,&vel_grad_test_dV[i_nSpace]);
6289 Lstar_p_u[i]=ck.Hamiltonian_adjoint(dmom_u_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
6290 Lstar_p_v[i]=ck.Hamiltonian_adjoint(dmom_v_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
6291 Lstar_p_w[i]=ck.Hamiltonian_adjoint(dmom_w_ham_grad_p,&vel_grad_test_dV[i_nSpace]);
6292 //VRANS account for drag terms, diagonal only here ... decide if need off diagonal terms too
6293 Lstar_u_u[i]+=ck.Reaction_adjoint(dmom_u_source[0],vel_test_dV[i]);
6294 Lstar_v_v[i]+=ck.Reaction_adjoint(dmom_v_source[1],vel_test_dV[i]);
6295 Lstar_w_w[i]+=ck.Reaction_adjoint(dmom_w_source[2],vel_test_dV[i]);
6296 }
6297
6298 // Assumes non-lagged subgrid velocity
6299 dmom_u_adv_u[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u);
6300 dmom_u_adv_u[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v);
6301 dmom_u_adv_u[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w);
6302
6303 dmom_v_adv_v[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u);
6304 dmom_v_adv_v[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v);
6305 dmom_v_adv_v[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w);
6306
6307 dmom_w_adv_w[0] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_u);
6308 dmom_w_adv_w[1] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_v);
6309 dmom_w_adv_w[2] += inertial_term*dmom_u_acc_u*(useRBLES*subgridError_w);
6310
6311 if(nParticles > 0)
6312 {
6313 //cek todo, this needs to be fixed for not exact
6314 double level_set_normal[nSpace];
6315 double sign=0.0;
6316 if (gf_s.useExact)
6317 {
6318 double norm_exact=0.0,norm_cut=0.0;
6319 if (use_ball_as_particle)
6320 {
6321 for (int I=0;I<nSpace;I++)
6322 {
6323 sign += ball_n[I]*gf_s.get_normal()[I];
6324 level_set_normal[I] = gf_s.get_normal()[I];
6325 norm_cut += level_set_normal[I]*level_set_normal[I];
6326 norm_exact += ball_n[I]*ball_n[I];
6327 }
6328 }
6329 else
6330 {
6331 for (int I=0;I<nSpace;I++)
6332 {
6333 sign += particle_signed_distance_normals.data()[eN_k_3d+I]*gf_s.get_normal()[I];
6334 level_set_normal[I] = gf_s.get_normal()[I];
6335 norm_cut += level_set_normal[I]*level_set_normal[I];
6336 norm_exact += particle_signed_distance_normals.data()[eN_k_3d+I]*particle_signed_distance_normals.data()[eN_k_3d+I];
6337 }
6338 }
6339 assert(std::fabs(1.0-norm_cut) < 1.0e-8);
6340 assert(std::fabs(1.0-norm_exact) < 1.0e-8);
6341 if (sign < 0.0)
6342 for (int I=0;I<nSpace;I++)
6343 level_set_normal[I]*=-1.0;
6344 /* if(icase_s==0)// && (1.0-sign*sign) > 1.0e-3) */
6345 /* { */
6346 /* std::cout<<"phi normal and cut normal divergent "<<eN<<'\t'<<k<<std::endl; */
6347 /* for (int I=0;I<nSpace;I++) */
6348 /* std::cout<<level_set_normal[I]<<'\t'<<particle_signed_distance_normals[eN_k_3d+I]<<std::endl; */
6349 /* } */
6350 }
6351 else
6352 {
6353 if (use_ball_as_particle)
6354 for (int I=0;I<nSpace;I++)
6355 level_set_normal[I] = ball_n[I];
6356 else
6357 for (int I=0;I<nSpace;I++)
6358 level_set_normal[I] = particle_signed_distance_normals.data()[eN_k_3d+I];
6359 }
6360 updateSolidParticleTerms(particle_index,
6361 NONCONSERVATIVE_FORM,
6362 eN < nElements_owned,
6363 particle_nitsche,
6364 dV,
6365 nParticles,
6366 nQuadraturePoints_global,
6367 &particle_signed_distances.data()[eN_k],
6368 level_set_normal,
6369 &particle_velocities.data()[eN_k_3d],
6370 particle_centroids.data(),
6371 use_ball_as_particle,
6372 ball_center.data(),
6373 ball_radius.data(),
6374 ball_velocity.data(),
6375 ball_angular_velocity.data(),
6376 ball_density.data(),
6377 porosity,
6378 particle_penalty_constant/h_phi,//penalty,
6379 particle_alpha,
6380 particle_beta,
6381 eps_rho,
6382 eps_mu,
6383 rho_0,
6384 nu_0,
6385 rho_1,
6386 nu_1,
6387 useVF,
6388 vf.data()[eN_k],
6389 phi.data()[eN_k],
6390 x,
6391 y,
6392 z,
6393 p,
6394 u,
6395 v,
6396 w,
6397 q_velocity_sge.data()[eN_k_nSpace+0],
6398 q_velocity_sge.data()[eN_k_nSpace+1],
6399 q_velocity_sge.data()[eN_k_nSpace+2],
6400 particle_eps,
6401 grad_u,
6402 grad_v,
6403 grad_w,
6404 mass_source_s,
6405 mom_u_source_s,
6406 mom_v_source_s,
6407 mom_w_source_s,
6408 dmom_u_source_s,
6409 dmom_v_source_s,
6410 dmom_w_source_s,
6411 mom_u_adv_s,
6412 mom_v_adv_s,
6413 mom_w_adv_s,
6414 dmom_u_adv_u_s,
6415 dmom_v_adv_v_s,
6416 dmom_w_adv_w_s,
6417 mom_u_ham_s,
6418 dmom_u_ham_grad_u_s,
6419 dmom_u_ham_grad_v_s,
6420 dmom_u_ham_grad_w_s,
6421 dmom_u_ham_u_s,
6422 dmom_u_ham_v_s,
6423 dmom_u_ham_w_s,
6424 mom_v_ham_s,
6425 dmom_v_ham_grad_u_s,
6426 dmom_v_ham_grad_v_s,
6427 dmom_v_ham_grad_w_s,
6428 dmom_v_ham_u_s,
6429 dmom_v_ham_v_s,
6430 dmom_v_ham_w_s,
6431 mom_w_ham_s,
6432 dmom_w_ham_grad_u_s,
6433 dmom_w_ham_grad_v_s,
6434 dmom_w_ham_grad_w_s,
6435 dmom_w_ham_u_s,
6436 dmom_w_ham_v_s,
6437 dmom_w_ham_w_s,
6438 mass_ham_s,
6439 dmass_ham_u_s,
6440 dmass_ham_v_s,
6441 dmass_ham_w_s,
6442 &particle_netForces_tmp[0],
6443 &particle_netMoments_tmp[0],
6444 &particle_surfaceArea_tmp[0],
6445 &particle_surfaceArea_projected_tmp[0],
6446 &projection_direction_tmp[0],
6447 &particle_volume_tmp[0]);
6448 }
6449 //cek todo add RBLES terms consistent to residual modifications or ignore the partials w.r.t the additional RBLES terms
6450 double H_f=1.0;
6451 if (gf.useExact && icase == 0)
6452 {
6453 if (fluid_phase == 0)
6454 H_f = gf.ImH(0.,0.);
6455 else
6456 H_f = gf.H(0.,0.);
6457 }
6458 else
6459 {
6460 assert(fluid_phase == 0);
6461 H_f = 1.0;
6462 }
6463 for(int i=0;i<nDOF_test_element;i++)
6464 {
6465 int i_nSpace = i*nSpace;
6466 for(int j=0;j<nDOF_trial_element;j++)
6467 {
6468 int j_nSpace = j*nSpace;
6469 if (nDOF_test_element == nDOF_v_trial_element)
6470 {
6471 elementJacobian_p_p[i][j] += H_s*H_f*((1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_u_p[j],Lstar_u_p[i]) +
6472 (1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_v_p[j],Lstar_v_p[i]) +
6473 (1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_w_p[j],Lstar_w_p[i]) +
6474 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));
6475 }
6476 }
6477 }
6478 for(int i=0;i<nDOF_test_element;i++)
6479 {
6480 int i_nSpace = i*nSpace;
6481 for(int j=0;j<nDOF_v_trial_element;j++)
6482 {
6483 int j_nSpace = j*nSpace;
6484 elementJacobian_p_u[i][j] += H_s*H_f*(ck.AdvectionJacobian_weak(dmass_adv_u,vel_trial[j],&p_grad_test_dV[i_nSpace]) +
6485 ck.MassJacobian_weak(dmass_ham_u,vel_trial[j],p_test_dV[i]));
6486 elementJacobian_p_v[i][j] += H_s*H_f*(ck.AdvectionJacobian_weak(dmass_adv_v,vel_trial[j],&p_grad_test_dV[i_nSpace]) +
6487 ck.MassJacobian_weak(dmass_ham_v,vel_trial[j],p_test_dV[i]));
6488 elementJacobian_p_w[i][j] += H_s*H_f*(ck.AdvectionJacobian_weak(dmass_adv_w,vel_trial[j],&p_grad_test_dV[i_nSpace]) +
6489 ck.MassJacobian_weak(dmass_ham_w,vel_trial[j],p_test_dV[i]));
6490 if (nDOF_test_element == nDOF_v_trial_element)
6491 {
6492 elementJacobian_p_u[i][j] += H_s*H_f*(1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u_p[i]);
6493 elementJacobian_p_v[i][j] += H_s*H_f*(1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_v_v[j],Lstar_v_p[i]);
6494 elementJacobian_p_w[i][j] += H_s*H_f*(1-PRESSURE_PROJECTION_STABILIZATION)*ck.SubgridErrorJacobian(dsubgridError_w_w[j],Lstar_w_p[i]);
6495 }
6496 }
6497 }
6498 for(int i=0;i<nDOF_v_test_element;i++)
6499 {
6500 int i_nSpace = i*nSpace;
6501 for(int j=0;j<nDOF_trial_element;j++)
6502 {
6503 int j_nSpace = j*nSpace;
6504 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])+
6505 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_u_p[j],Lstar_u_u[i]));
6506 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])+
6507 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_v_p[j],Lstar_v_v[i]));
6508 elementJacobian_w_p[i][j] += H_s*H_f*(ck.HamiltonianJacobian_weak(dmom_w_ham_grad_p,&p_grad_trial_ib[j_nSpace],vel_test_dV[i])+
6509 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_w_p[j],Lstar_w_w[i]));
6510 }
6511 }
6512 for(int i=0;i<nDOF_v_test_element;i++)
6513 {
6514 int i_nSpace = i*nSpace;
6515 for(int j=0;j<nDOF_v_trial_element;j++)
6516 {
6517 int j_nSpace = j*nSpace;
6518 elementJacobian_u_u[i][j] += H_s*H_f*(ck.MassJacobian_weak(dmom_u_acc_u_t,vel_trial[j],vel_test_dV[i]) +
6519 ck.MassJacobian_weak(dmom_u_ham_u,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6520 ck.HamiltonianJacobian_weak(dmom_u_ham_grad_u,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6521 ck.AdvectionJacobian_weak(dmom_u_adv_u,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6522 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]) +
6523 ck.ReactionJacobian_weak(dmom_u_source[0]+NONCONSERVATIVE_FORM*dmom_u_acc_u*div_mesh_velocity,vel_trial[j],vel_test_dV[i]) +
6524 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_u[j],Lstar_p_u[i]) +
6525 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_u_u[j],Lstar_u_u[i]) +
6526 ck.NumericalDiffusionJacobian(q_numDiff_u_last.data()[eN_k],&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]));
6527 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]) +
6528 ck.AdvectionJacobian_weak(dmom_u_adv_v,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6529 ck.MassJacobian_weak(dmom_u_ham_v,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6530 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]) +
6531 ck.ReactionJacobian_weak(dmom_u_source[1],vel_trial[j],vel_test_dV[i]) +
6532 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_v[j],Lstar_p_u[i]));
6533 elementJacobian_u_w[i][j] += H_s*H_f*(ck.HamiltonianJacobian_weak(dmom_u_ham_grad_w,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6534 ck.AdvectionJacobian_weak(dmom_u_adv_w,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6535 ck.MassJacobian_weak(dmom_u_ham_w,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6536 ck.SimpleDiffusionJacobian_weak(sdInfo_u_w_rowptr.data(),sdInfo_u_w_colind.data(),mom_uw_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
6537 ck.ReactionJacobian_weak(dmom_u_source[2],vel_trial[j],vel_test_dV[i]) +
6538 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_w[j],Lstar_p_u[i]));
6539 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]) +
6540 ck.AdvectionJacobian_weak(dmom_v_adv_u,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6541 ck.MassJacobian_weak(dmom_v_ham_u,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6542 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]) +
6543 ck.ReactionJacobian_weak(dmom_v_source[0],vel_trial[j],vel_test_dV[i]) +
6544 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_u[j],Lstar_p_v[i]));
6545 elementJacobian_v_v[i][j] += H_s*H_f*(ck.MassJacobian_weak(dmom_v_acc_v_t,vel_trial[j],vel_test_dV[i]) +
6546 ck.MassJacobian_weak(dmom_v_ham_v,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6547 ck.HamiltonianJacobian_weak(dmom_v_ham_grad_v,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6548 ck.AdvectionJacobian_weak(dmom_v_adv_v,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6549 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]) +
6550 ck.ReactionJacobian_weak(dmom_v_source[1]+NONCONSERVATIVE_FORM*dmom_v_acc_v*div_mesh_velocity,vel_trial[j],vel_test_dV[i]) +
6551 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_v[j],Lstar_p_v[i]) +
6552 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_v_v[j],Lstar_v_v[i]) +
6553 ck.NumericalDiffusionJacobian(q_numDiff_v_last.data()[eN_k],&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]));
6554 elementJacobian_v_w[i][j] += H_s*H_f*(ck.HamiltonianJacobian_weak(dmom_v_ham_grad_w,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6555 ck.AdvectionJacobian_weak(dmom_v_adv_w,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6556 ck.MassJacobian_weak(dmom_v_ham_w,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6557 ck.SimpleDiffusionJacobian_weak(sdInfo_v_w_rowptr.data(),sdInfo_v_w_colind.data(),mom_vw_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
6558 ck.ReactionJacobian_weak(dmom_v_source[2],vel_trial[j],vel_test_dV[i]) +
6559 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_w[j],Lstar_p_v[i]));
6560 elementJacobian_w_u[i][j] += H_s*H_f*(ck.HamiltonianJacobian_weak(dmom_w_ham_grad_u,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6561 ck.AdvectionJacobian_weak(dmom_w_adv_u,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6562 ck.MassJacobian_weak(dmom_w_ham_u,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6563 ck.SimpleDiffusionJacobian_weak(sdInfo_w_u_rowptr.data(),sdInfo_w_u_colind.data(),mom_wu_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
6564 ck.ReactionJacobian_weak(dmom_w_source[0],vel_trial[j],vel_test_dV[i]) +
6565 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_u[j],Lstar_p_w[i]));
6566 elementJacobian_w_v[i][j] += H_s*H_f*(ck.HamiltonianJacobian_weak(dmom_w_ham_grad_v,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6567 ck.AdvectionJacobian_weak(dmom_w_adv_v,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6568 ck.MassJacobian_weak(dmom_w_ham_v,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6569 ck.SimpleDiffusionJacobian_weak(sdInfo_w_v_rowptr.data(),sdInfo_w_v_colind.data(),mom_wv_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
6570 ck.ReactionJacobian_weak(dmom_w_source[1],vel_trial[j],vel_test_dV[i]) +
6571 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_v[j],Lstar_p_w[i]));
6572 elementJacobian_w_w[i][j] += H_s*H_f*(ck.MassJacobian_weak(dmom_w_acc_w_t,vel_trial[j],vel_test_dV[i]) +
6573 ck.MassJacobian_weak(dmom_w_ham_w,vel_trial[j],vel_test_dV[i]) + //cek hack for nonlinear hamiltonian
6574 ck.HamiltonianJacobian_weak(dmom_w_ham_grad_w,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6575 ck.AdvectionJacobian_weak(dmom_w_adv_w,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6576 ck.SimpleDiffusionJacobian_weak(sdInfo_w_w_rowptr.data(),sdInfo_w_w_colind.data(),mom_ww_diff_ten,&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]) +
6577 ck.ReactionJacobian_weak(dmom_w_source[2]+NONCONSERVATIVE_FORM*dmom_w_acc_w*div_mesh_velocity,vel_trial[j],vel_test_dV[i]) +
6578 MOMENTUM_SGE*PRESSURE_SGE*ck.SubgridErrorJacobian(dsubgridError_p_w[j],Lstar_p_w[i]) +
6579 MOMENTUM_SGE*VELOCITY_SGE*ck.SubgridErrorJacobian(dsubgridError_w_w[j],Lstar_w_w[i]) +
6580 ck.NumericalDiffusionJacobian(q_numDiff_w_last.data()[eN_k],&vel_grad_trial_ib[j_nSpace],&vel_grad_test_dV[i_nSpace]));
6581 }//j
6582 }//i
6583 if (nParticles > 0)
6584 {
6585 for(int i=0;i<nDOF_v_test_element;i++)
6586 {
6587 int i_nSpace = i*nSpace;
6588 for(int j=0;j<nDOF_v_trial_element;j++)
6589 {
6590 int j_nSpace = j*nSpace;
6591 elementJacobian_u_u[i][j] += H_f*(ck.MassJacobian_weak(dmom_u_ham_u_s,vel_trial[j],vel_test_dV[i]) +
6592 ck.HamiltonianJacobian_weak(dmom_u_ham_grad_u_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6593 ck.AdvectionJacobian_weak(dmom_u_adv_u_s,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6594 ck.ReactionJacobian_weak(dmom_u_source_s[0],vel_trial[j],vel_test_dV[i]));
6595
6596 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]) +
6597 ck.ReactionJacobian_weak(dmom_u_source_s[1],vel_trial[j],vel_test_dV[i]));
6598
6599 elementJacobian_u_w[i][j] += H_f*(ck.HamiltonianJacobian_weak(dmom_u_ham_grad_w_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6600 ck.ReactionJacobian_weak(dmom_u_source_s[2],vel_trial[j],vel_test_dV[i]));
6601
6602 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]) +
6603 ck.ReactionJacobian_weak(dmom_v_source_s[0],vel_trial[j],vel_test_dV[i]));
6604
6605 elementJacobian_v_v[i][j] += H_f*(ck.MassJacobian_weak(dmom_v_ham_v_s,vel_trial[j],vel_test_dV[i]) +
6606 ck.HamiltonianJacobian_weak(dmom_v_ham_grad_v_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6607 ck.AdvectionJacobian_weak(dmom_v_adv_v_s,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6608 ck.ReactionJacobian_weak(dmom_v_source_s[1],vel_trial[j],vel_test_dV[i]));
6609
6610 elementJacobian_v_w[i][j] += H_f*(ck.HamiltonianJacobian_weak(dmom_v_ham_grad_w_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6611 ck.ReactionJacobian_weak(dmom_v_source_s[2],vel_trial[j],vel_test_dV[i]));
6612
6613 elementJacobian_w_u[i][j] += H_f*(ck.HamiltonianJacobian_weak(dmom_w_ham_grad_u_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6614 ck.ReactionJacobian_weak(dmom_w_source_s[0],vel_trial[j],vel_test_dV[i]));
6615
6616 elementJacobian_w_v[i][j] += H_f*(ck.HamiltonianJacobian_weak(dmom_w_ham_grad_v_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6617 ck.ReactionJacobian_weak(dmom_w_source_s[1],vel_trial[j],vel_test_dV[i]));
6618
6619 elementJacobian_w_w[i][j] += H_f*(ck.MassJacobian_weak(dmom_w_ham_w_s,vel_trial[j],vel_test_dV[i]) +
6620 ck.HamiltonianJacobian_weak(dmom_w_ham_grad_w_s,&vel_grad_trial_ib[j_nSpace],vel_test_dV[i]) +
6621 ck.AdvectionJacobian_weak(dmom_w_adv_w_s,vel_trial[j],&vel_grad_test_dV[i_nSpace]) +
6622 ck.ReactionJacobian_weak(dmom_w_source_s[2],vel_trial[j],vel_test_dV[i]));
6623 }//j
6624 }//i
6625 }
6626 }//k
6627 }//fluid_phase
6628 //
6629 //load into element Jacobian into global Jacobian
6630 //
6631 for (int i=0;i<nDOF_test_element;i++)
6632 {
6633 int eN_i = eN*nDOF_test_element+i;
6634 for (int j=0;j<nDOF_trial_element;j++)
6635 {
6636 int eN_i_j = eN_i*nDOF_trial_element+j;
6637 globalJacobian.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += elementJacobian_p_p[i][j];
6638 }
6639 }
6640 for (int i=0;i<nDOF_test_element;i++)
6641 {
6642 int eN_i = eN*nDOF_test_element+i;
6643 for (int j=0;j<nDOF_v_trial_element;j++)
6644 {
6645 int eN_i_j = eN_i*nDOF_v_trial_element+j;
6646 globalJacobian.data()[csrRowIndeces_p_u.data()[eN_i] + csrColumnOffsets_p_u.data()[eN_i_j]] += elementJacobian_p_u[i][j];
6647 globalJacobian.data()[csrRowIndeces_p_v.data()[eN_i] + csrColumnOffsets_p_v.data()[eN_i_j]] += elementJacobian_p_v[i][j];
6648 globalJacobian.data()[csrRowIndeces_p_w.data()[eN_i] + csrColumnOffsets_p_w.data()[eN_i_j]] += elementJacobian_p_w[i][j];
6649 }
6650 }
6651 for (int i=0;i<nDOF_v_test_element;i++)
6652 {
6653 int eN_i = eN*nDOF_v_test_element+i;
6654 for (int j=0;j<nDOF_trial_element;j++)
6655 {
6656 int eN_i_j = eN_i*nDOF_trial_element+j;
6657 globalJacobian.data()[csrRowIndeces_u_p.data()[eN_i] + csrColumnOffsets_u_p.data()[eN_i_j]] += elementJacobian_u_p[i][j];
6658 globalJacobian.data()[csrRowIndeces_v_p.data()[eN_i] + csrColumnOffsets_v_p.data()[eN_i_j]] += elementJacobian_v_p[i][j];
6659 globalJacobian.data()[csrRowIndeces_w_p.data()[eN_i] + csrColumnOffsets_w_p.data()[eN_i_j]] += elementJacobian_w_p[i][j];
6660 }
6661 }
6662 for (int i=0;i<nDOF_v_test_element;i++)
6663 {
6664 int eN_i = eN*nDOF_v_test_element+i;
6665 for (int j=0;j<nDOF_v_trial_element;j++)
6666 {
6667 int eN_i_j = eN_i*nDOF_v_trial_element+j;
6668 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += elementJacobian_u_u[i][j];
6669 globalJacobian.data()[csrRowIndeces_u_v.data()[eN_i] + csrColumnOffsets_u_v.data()[eN_i_j]] += elementJacobian_u_v[i][j];
6670 globalJacobian.data()[csrRowIndeces_u_w.data()[eN_i] + csrColumnOffsets_u_w.data()[eN_i_j]] += elementJacobian_u_w[i][j];
6671
6672 globalJacobian.data()[csrRowIndeces_v_u.data()[eN_i] + csrColumnOffsets_v_u.data()[eN_i_j]] += elementJacobian_v_u[i][j];
6673 globalJacobian.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += elementJacobian_v_v[i][j];
6674 globalJacobian.data()[csrRowIndeces_v_w.data()[eN_i] + csrColumnOffsets_v_w.data()[eN_i_j]] += elementJacobian_v_w[i][j];
6675
6676 globalJacobian.data()[csrRowIndeces_w_u.data()[eN_i] + csrColumnOffsets_w_u.data()[eN_i_j]] += elementJacobian_w_u[i][j];
6677 globalJacobian.data()[csrRowIndeces_w_v.data()[eN_i] + csrColumnOffsets_w_v.data()[eN_i_j]] += elementJacobian_w_v[i][j];
6678 globalJacobian.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_w_w.data()[eN_i_j]] += elementJacobian_w_w[i][j];
6679 }//j
6680 }//i
6681 }//elements
6682 std::set<int>::iterator it=cutfem_boundaries.begin();
6683 while(it!=cutfem_boundaries.end())
6684 {
6685 std::map<int,double> DWp_Dn_jump,DW_Dn_jump;
6686 std::map<std::pair<int, int>, int> p_p_nz, u_u_nz, v_v_nz, w_w_nz;
6687 double gamma_cutfem=ghost_penalty_constant,gamma_cutfem_p=ghost_penalty_constant,h_cutfem=elementBoundaryDiameter.data()[*it];
6688 int eN_nDOF_v_trial_element = elementBoundaryElementsArray.data()[(*it)*2+0]*nDOF_v_trial_element;
6689 //See Massing Schott Wall 2018
6690 //cek todo modify for two-fluids: rho_0 != rho_1
6691 double norm_v=0.0;
6692 for (int i_offset=1;i_offset<nDOF_v_trial_element;i_offset++)//MSW18 is just on face
6693 {
6694 int i = (cutfem_local_boundaries[*it] + i_offset)%nDOF_v_trial_element;//cek hack only works for P1
6695 double u=u_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
6696 v=v_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]],
6697 w=w_old_dof.data()[vel_l2g.data()[eN_nDOF_v_trial_element+i]];
6698 norm_v=fmax(norm_v,sqrt(u*u+v*v+w*w));
6699 }
6700 double gamma_v_dim = rho_0*(nu_0 + norm_v*h_cutfem + alphaBDF*h_cutfem*h_cutfem);
6701 gamma_cutfem_p *= h_cutfem*h_cutfem/gamma_v_dim;
6702 if (NONCONSERVATIVE_FORM)
6703 gamma_cutfem*=gamma_v_dim;
6704 else
6705 gamma_cutfem*=(gamma_v_dim/rho_0);
6706 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6707 {
6708 double Dp_Dn_jump=0.0, Du_Dn_jump=0.0, Dv_Dn_jump=0.0, Dw_Dn_jump=0.0,dS;
6709 for (int eN_side=0;eN_side < 2; eN_side++)
6710 {
6711 int ebN = *it,
6712 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
6713 for (int i=0;i<nDOF_test_element;i++)
6714 DWp_Dn_jump[p_l2g.data()[eN*nDOF_test_element+i]] = 0.0;
6715 for (int i=0;i<nDOF_v_test_element;i++)
6716 DW_Dn_jump[vel_l2g.data()[eN*nDOF_v_test_element+i]] = 0.0;
6717 }
6718 for (int eN_side=0;eN_side < 2; eN_side++)
6719 {
6720 int ebN = *it,
6721 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side],
6722 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+eN_side],
6723 eN_nDOF_trial_element = eN*nDOF_trial_element,
6724 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
6725 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
6726 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
6727 double p_int=0.0,
6728 u_int=0.0,
6729 v_int=0.0,
6730 w_int=0.0,
6731 grad_p_int[nSpace]=ZEROVEC,
6732 grad_u_int[nSpace]=ZEROVEC,
6733 grad_v_int[nSpace]=ZEROVEC,
6734 grad_w_int[nSpace]=ZEROVEC,
6735 jac_int[nSpace*nSpace],
6736 jacDet_int,
6737 jacInv_int[nSpace*nSpace],
6738 boundaryJac[nSpace*(nSpace-1)],
6739 metricTensor[(nSpace-1)*(nSpace-1)],
6740 metricTensorDetSqrt,
6741 p_test_dS[nDOF_test_element],vel_test_dS[nDOF_v_test_element],
6742 p_grad_trial_trace[nDOF_trial_element*nSpace],vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
6743 p_grad_test_dS[nDOF_trial_element*nSpace],vel_grad_test_dS[nDOF_v_trial_element*nSpace],
6744 normal[nSpace],x_int,y_int,z_int,xt_int,yt_int,zt_int,integralScaling,
6745 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty,
6746 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;
6747 //compute information about mapping from reference element to physical element
6748 ck.calculateMapping_elementBoundary(eN,
6749 ebN_local,
6750 kb,
6751 ebN_local_kb,
6752 mesh_dof.data(),
6753 mesh_l2g.data(),
6754 mesh_trial_trace_ref.data(),
6755 mesh_grad_trial_trace_ref.data(),
6756 boundaryJac_ref.data(),
6757 jac_int,
6758 jacDet_int,
6759 jacInv_int,
6760 boundaryJac,
6761 metricTensor,
6762 metricTensorDetSqrt,
6763 normal_ref.data(),
6764 normal,
6765 x_int,y_int,z_int);
6766 //todo: check that physical coordinates match
6767 ck.calculateMappingVelocity_elementBoundary(eN,
6768 ebN_local,
6769 kb,
6770 ebN_local_kb,
6771 mesh_velocity_dof.data(),
6772 mesh_l2g.data(),
6773 mesh_trial_trace_ref.data(),
6774 xt_int,yt_int,zt_int,
6775 normal,
6776 boundaryJac,
6777 metricTensor,
6778 integralScaling);
6779 dS = metricTensorDetSqrt*dS_ref.data()[kb];
6780 //compute shape and solution information
6781 //shape
6782 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_int,p_grad_trial_trace);
6783 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_int,vel_grad_trial_trace);
6784 for (int i=0;i<nDOF_test_element;i++)
6785 {
6786 int eN_i = eN*nDOF_test_element + i;
6787 for (int I=0;I<nSpace;I++)
6788 DWp_Dn_jump[p_l2g.data()[eN_i]] += p_grad_trial_trace[i*nSpace+I]*normal[I];
6789 }
6790 for (int i=0;i<nDOF_v_test_element;i++)
6791 {
6792 int eN_i = eN*nDOF_v_test_element + i;
6793 for (int I=0;I<nSpace;I++)
6794 DW_Dn_jump[vel_l2g.data()[eN_i]] += vel_grad_trial_trace[i*nSpace+I]*normal[I];
6795 }
6796 }//eN_side
6797 for (int eN_side=0;eN_side < 2; eN_side++)
6798 {
6799 int ebN = *it,
6800 eN = elementBoundaryElementsArray.data()[ebN*2+eN_side];
6801 for (int i=0;i<nDOF_test_element;i++)
6802 {
6803 int eN_i = eN*nDOF_test_element+i;
6804 for (int eN_side2=0;eN_side2 < 2; eN_side2++)
6805 {
6806 int eN2 = elementBoundaryElementsArray.data()[ebN*2+eN_side2];
6807 for (int j=0;j<nDOF_test_element;j++)
6808 {
6809 int eN_i_j = eN_i*nDOF_test_element + j;
6810 int eN2_j = eN2*nDOF_test_element + j;
6811 int ebN_i_j = ebN*4*nDOF_test_X_trial_element +
6812 eN_side*2*nDOF_test_X_trial_element +
6813 eN_side2*nDOF_test_X_trial_element +
6814 i*nDOF_trial_element +
6815 j;
6816 std::pair<int,int> ij = std::make_pair(p_l2g.data()[eN_i], p_l2g.data()[eN2_j]);
6817 if (p_p_nz.count(ij))
6818 {
6819 assert(p_p_nz[ij] == csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_eb_p_p.data()[ebN_i_j]);
6820 }
6821 else
6822 p_p_nz[ij] = csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_eb_p_p.data()[ebN_i_j];
6823 }
6824 }
6825 }
6826 for (int i=0;i<nDOF_v_test_element;i++)
6827 {
6828 int eN_i = eN*nDOF_v_test_element+i;
6829 for (int eN_side2=0;eN_side2 < 2; eN_side2++)
6830 {
6831 int eN2 = elementBoundaryElementsArray.data()[ebN*2+eN_side2];
6832 for (int j=0;j<nDOF_v_test_element;j++)
6833 {
6834 int eN_i_j = eN_i*nDOF_v_test_element + j;
6835 int eN2_j = eN2*nDOF_v_test_element + j;
6836 int ebN_i_j = ebN*4*nDOF_v_test_X_v_trial_element +
6839 i*nDOF_v_trial_element +
6840 j;
6841 std::pair<int,int> ij = std::make_pair(vel_l2g.data()[eN_i], vel_l2g.data()[eN2_j]);
6842 if (u_u_nz.count(ij))
6843 {
6844 assert(u_u_nz[ij] == csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]);
6845 }
6846 else
6847 u_u_nz[ij] = csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j];
6848 if (v_v_nz.count(ij))
6849 {
6850 assert(v_v_nz[ij] == csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j]);
6851 }
6852 else
6853 v_v_nz[ij] = csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j];
6854 if (w_w_nz.count(ij))
6855 {
6856 assert(w_w_nz[ij] == csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_eb_w_w.data()[ebN_i_j]);
6857 }
6858 else
6859 w_w_nz[ij] = csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_eb_w_w.data()[ebN_i_j];
6860 }
6861 }
6862 }
6863 }
6864 for (std::map<int,double>::iterator Wi_it=DWp_Dn_jump.begin(); Wi_it!=DWp_Dn_jump.end(); ++Wi_it)
6865 for (std::map<int,double>::iterator Wj_it=DWp_Dn_jump.begin(); Wj_it!=DWp_Dn_jump.end(); ++Wj_it)
6866 {
6867 int i_global = Wi_it->first,
6868 j_global = Wj_it->first;
6869 double DWp_Dn_jump_i = Wi_it->second,
6870 DWp_Dn_jump_j = Wj_it->second;
6871 std::pair<int,int> ij = std::make_pair(i_global, j_global);
6872 globalJacobian.data()[p_p_nz.at(ij)] += gamma_cutfem_p*h_cutfem*DWp_Dn_jump_j*DWp_Dn_jump_i*dS;
6873 }//i,j
6874 for (std::map<int,double>::iterator Wi_it=DW_Dn_jump.begin(); Wi_it!=DW_Dn_jump.end(); ++Wi_it)
6875 for (std::map<int,double>::iterator Wj_it=DW_Dn_jump.begin(); Wj_it!=DW_Dn_jump.end(); ++Wj_it)
6876 {
6877 int i_global = Wi_it->first,
6878 j_global = Wj_it->first;
6879 double DW_Dn_jump_i = Wi_it->second,
6880 DW_Dn_jump_j = Wj_it->second;
6881 std::pair<int,int> ij = std::make_pair(i_global, j_global);
6882 globalJacobian.data()[u_u_nz.at(ij)] += gamma_cutfem*h_cutfem*DW_Dn_jump_j*DW_Dn_jump_i*dS;
6883 globalJacobian.data()[v_v_nz.at(ij)] += gamma_cutfem*h_cutfem*DW_Dn_jump_j*DW_Dn_jump_i*dS;
6884 globalJacobian.data()[w_w_nz.at(ij)] += gamma_cutfem*h_cutfem*DW_Dn_jump_j*DW_Dn_jump_i*dS;
6885 }//i,j
6886 }//kb
6887 it++;
6888 }//cutfem element boundaries
6889 //
6890 //loop over exterior element boundaries to compute the surface integrals and load them into the global Jacobian
6891 //
6892 for (int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
6893 {
6894 int ebN = exteriorElementBoundariesArray.data()[ebNE],
6895 eN = elementBoundaryElementsArray.data()[ebN*2+0],
6896 eN_nDOF_trial_element = eN*nDOF_trial_element,
6897 eN_nDOF_v_trial_element = eN*nDOF_v_trial_element,
6898 ebN_local = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0];
6899 if (boundaryFlags[ebN] < 1)
6900 continue;
6901 double eps_rho,eps_mu;
6902 double element_phi[nDOF_mesh_trial_element], element_phi_s[nDOF_mesh_trial_element];
6903 for (int j=0;j<nDOF_mesh_trial_element;j++)
6904 {
6905 int eN_j = eN*nDOF_mesh_trial_element+j;
6906 element_phi[j] = phi_nodes.data()[p_l2g.data()[eN_j]];
6907 element_phi_s[j] = phi_solid_nodes.data()[p_l2g.data()[eN_j]];
6908 }
6909 double element_nodes[nDOF_mesh_trial_element*3];
6910 for (int i=0;i<nDOF_mesh_trial_element;i++)
6911 {
6912 int eN_i=eN*nDOF_mesh_trial_element+i;
6913 for(int I=0;I<3;I++)
6914 element_nodes[i*3 + I] = mesh_dof[mesh_l2g.data()[eN_i]*3 + I];
6915 }//i
6916 double mesh_dof_ref[nDOF_mesh_trial_element*3]={0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.};
6917 double xb_ref_calc[nQuadraturePoints_elementBoundary*3];
6918 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6919 {
6920 double x=0.0,y=0.0,z=0.0;
6921 for (int j=0;j<nDOF_mesh_trial_element;j++)
6922 {
6923 int ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb;
6924 int ebN_local_kb_j = ebN_local_kb*nDOF_mesh_trial_element+j;
6925 x += mesh_dof_ref[j*3+0]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
6926 y += mesh_dof_ref[j*3+1]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
6927 z += mesh_dof_ref[j*3+2]*mesh_trial_trace_ref.data()[ebN_local_kb_j];
6928 }
6929 xb_ref_calc[3*kb+0] = x;
6930 xb_ref_calc[3*kb+1] = y;
6931 xb_ref_calc[3*kb+2] = z;
6932 }
6933 int icase_s = gf_s.calculate(element_phi_s, element_nodes, xb_ref_calc,true);
6934#ifdef IFEM
6935 int icase = gf.calculate(element_phi, element_nodes, xb_ref.data(), rho_1*nu_1, rho_0*nu_0,true,false);
6936#else
6937 int icase = gf.calculate(element_phi, element_nodes, xb_ref.data(), 1.0,1.0,true, false);
6938#endif
6939 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
6940 {
6941 int ebNE_kb = ebNE*nQuadraturePoints_elementBoundary+kb,
6942 ebNE_kb_nSpace = ebNE_kb*nSpace,
6943 ebN_local_kb = ebN_local*nQuadraturePoints_elementBoundary+kb,
6944 ebN_local_kb_nSpace = ebN_local_kb*nSpace;
6945
6946 double phi_s_ext=0.0,
6947 p_ext=0.0,
6948 u_ext=0.0,
6949 v_ext=0.0,
6950 w_ext=0.0,
6951 grad_p_ext[nSpace]=ZEROVEC,
6952 grad_u_ext[nSpace]=ZEROVEC,
6953 grad_v_ext[nSpace]=ZEROVEC,
6954 grad_w_ext[nSpace]=ZEROVEC,
6955 p_old=0.0,u_old=0.0,v_old=0.0,w_old=0.0,
6956 grad_p_old[nSpace]=ZEROVEC,grad_u_old[nSpace]=ZEROVEC,grad_v_old[nSpace]=ZEROVEC,grad_w_old[nSpace]=ZEROVEC,
6957 mom_u_acc_ext=0.0,
6958 dmom_u_acc_u_ext=0.0,
6959 mom_v_acc_ext=0.0,
6960 dmom_v_acc_v_ext=0.0,
6961 mom_w_acc_ext=0.0,
6962 dmom_w_acc_w_ext=0.0,
6963 mass_adv_ext[nSpace]=ZEROVEC,
6964 dmass_adv_u_ext[nSpace]=ZEROVEC,
6965 dmass_adv_v_ext[nSpace]=ZEROVEC,
6966 dmass_adv_w_ext[nSpace]=ZEROVEC,
6967 mom_u_adv_ext[nSpace]=ZEROVEC,
6968 dmom_u_adv_u_ext[nSpace]=ZEROVEC,
6969 dmom_u_adv_v_ext[nSpace]=ZEROVEC,
6970 dmom_u_adv_w_ext[nSpace]=ZEROVEC,
6971 mom_v_adv_ext[nSpace]=ZEROVEC,
6972 dmom_v_adv_u_ext[nSpace]=ZEROVEC,
6973 dmom_v_adv_v_ext[nSpace]=ZEROVEC,
6974 dmom_v_adv_w_ext[nSpace]=ZEROVEC,
6975 mom_w_adv_ext[nSpace]=ZEROVEC,
6976 dmom_w_adv_u_ext[nSpace]=ZEROVEC,
6977 dmom_w_adv_v_ext[nSpace]=ZEROVEC,
6978 dmom_w_adv_w_ext[nSpace]=ZEROVEC,
6979 mom_uu_diff_ten_ext[nSpace]=ZEROVEC,
6980 mom_vv_diff_ten_ext[nSpace]=ZEROVEC,
6981 mom_ww_diff_ten_ext[nSpace]=ZEROVEC,
6982 mom_uv_diff_ten_ext[1],
6983 mom_uw_diff_ten_ext[1],
6984 mom_vu_diff_ten_ext[1],
6985 mom_vw_diff_ten_ext[1],
6986 mom_wu_diff_ten_ext[1],
6987 mom_wv_diff_ten_ext[1],
6988 mom_u_source_ext=0.0,
6989 mom_v_source_ext=0.0,
6990 mom_w_source_ext=0.0,
6991 mom_u_ham_ext=0.0,
6992 dmom_u_ham_grad_p_ext[nSpace]=ZEROVEC,
6993 dmom_u_ham_grad_u_ext[nSpace]=ZEROVEC,
6994 dmom_u_ham_u_ext=0.0,
6995 dmom_u_ham_v_ext=0.0,
6996 dmom_u_ham_w_ext=0.0,
6997 mom_v_ham_ext=0.0,
6998 dmom_v_ham_grad_p_ext[nSpace]=ZEROVEC,
6999 dmom_v_ham_grad_v_ext[nSpace]=ZEROVEC,
7000 dmom_v_ham_u_ext=0.0,
7001 dmom_v_ham_v_ext=0.0,
7002 dmom_v_ham_w_ext=0.0,
7003 mom_w_ham_ext=0.0,
7004 dmom_w_ham_grad_p_ext[nSpace]=ZEROVEC,
7005 dmom_w_ham_grad_w_ext[nSpace]=ZEROVEC,
7006 dmom_w_ham_u_ext=0.0,
7007 dmom_w_ham_v_ext=0.0,
7008 dmom_w_ham_w_ext=0.0,
7009 dmom_u_adv_p_ext[nSpace]=ZEROVEC,
7010 dmom_v_adv_p_ext[nSpace]=ZEROVEC,
7011 dmom_w_adv_p_ext[nSpace]=ZEROVEC,
7012 dflux_mass_u_ext=0.0,
7013 dflux_mass_v_ext=0.0,
7014 dflux_mass_w_ext=0.0,
7015 dflux_mom_u_adv_p_ext=0.0,
7016 dflux_mom_u_adv_u_ext=0.0,
7017 dflux_mom_u_adv_v_ext=0.0,
7018 dflux_mom_u_adv_w_ext=0.0,
7019 dflux_mom_v_adv_p_ext=0.0,
7020 dflux_mom_v_adv_u_ext=0.0,
7021 dflux_mom_v_adv_v_ext=0.0,
7022 dflux_mom_v_adv_w_ext=0.0,
7023 dflux_mom_w_adv_p_ext=0.0,
7024 dflux_mom_w_adv_u_ext=0.0,
7025 dflux_mom_w_adv_v_ext=0.0,
7026 dflux_mom_w_adv_w_ext=0.0,
7027 bc_p_ext=0.0,
7028 bc_u_ext=0.0,
7029 bc_v_ext=0.0,
7030 bc_w_ext=0.0,
7031 bc_mom_u_acc_ext=0.0,
7032 bc_dmom_u_acc_u_ext=0.0,
7033 bc_mom_v_acc_ext=0.0,
7034 bc_dmom_v_acc_v_ext=0.0,
7035 bc_mom_w_acc_ext=0.0,
7036 bc_dmom_w_acc_w_ext=0.0,
7037 bc_mass_adv_ext[nSpace]=ZEROVEC,
7038 bc_dmass_adv_u_ext[nSpace]=ZEROVEC,
7039 bc_dmass_adv_v_ext[nSpace]=ZEROVEC,
7040 bc_dmass_adv_w_ext[nSpace]=ZEROVEC,
7041 bc_mom_u_adv_ext[nSpace]=ZEROVEC,
7042 bc_dmom_u_adv_u_ext[nSpace]=ZEROVEC,
7043 bc_dmom_u_adv_v_ext[nSpace]=ZEROVEC,
7044 bc_dmom_u_adv_w_ext[nSpace]=ZEROVEC,
7045 bc_mom_v_adv_ext[nSpace]=ZEROVEC,
7046 bc_dmom_v_adv_u_ext[nSpace]=ZEROVEC,
7047 bc_dmom_v_adv_v_ext[nSpace]=ZEROVEC,
7048 bc_dmom_v_adv_w_ext[nSpace]=ZEROVEC,
7049 bc_mom_w_adv_ext[nSpace]=ZEROVEC,
7050 bc_dmom_w_adv_u_ext[nSpace]=ZEROVEC,
7051 bc_dmom_w_adv_v_ext[nSpace]=ZEROVEC,
7052 bc_dmom_w_adv_w_ext[nSpace]=ZEROVEC,
7053 bc_mom_uu_diff_ten_ext[nSpace]=ZEROVEC,
7054 bc_mom_vv_diff_ten_ext[nSpace]=ZEROVEC,
7055 bc_mom_ww_diff_ten_ext[nSpace]=ZEROVEC,
7056 bc_mom_uv_diff_ten_ext[1],
7057 bc_mom_uw_diff_ten_ext[1],
7058 bc_mom_vu_diff_ten_ext[1],
7059 bc_mom_vw_diff_ten_ext[1],
7060 bc_mom_wu_diff_ten_ext[1],
7061 bc_mom_wv_diff_ten_ext[1],
7062 bc_mom_u_source_ext=0.0,
7063 bc_mom_v_source_ext=0.0,
7064 bc_mom_w_source_ext=0.0,
7065 bc_mom_u_ham_ext=0.0,
7066 bc_dmom_u_ham_grad_p_ext[nSpace]=ZEROVEC,
7067 bc_dmom_u_ham_grad_u_ext[nSpace]=ZEROVEC,
7068 bc_dmom_u_ham_u_ext=0.0,
7069 bc_dmom_u_ham_v_ext=0.0,
7070 bc_dmom_u_ham_w_ext=0.0,
7071 bc_mom_v_ham_ext=0.0,
7072 bc_dmom_v_ham_grad_p_ext[nSpace]=ZEROVEC,
7073 bc_dmom_v_ham_grad_v_ext[nSpace]=ZEROVEC,
7074 bc_dmom_v_ham_u_ext=0.0,
7075 bc_dmom_v_ham_v_ext=0.0,
7076 bc_dmom_v_ham_w_ext=0.0,
7077 bc_mom_w_ham_ext=0.0,
7078 bc_dmom_w_ham_grad_p_ext[nSpace]=ZEROVEC,
7079 bc_dmom_w_ham_grad_w_ext[nSpace]=ZEROVEC,
7080 bc_dmom_w_ham_u_ext=0.0,
7081 bc_dmom_w_ham_v_ext=0.0,
7082 bc_dmom_w_ham_w_ext=0.0,
7083 fluxJacobian_p_p[nDOF_trial_element],
7084 fluxJacobian_p_u[nDOF_v_trial_element],
7085 fluxJacobian_p_v[nDOF_v_trial_element],
7086 fluxJacobian_p_w[nDOF_v_trial_element],
7087 fluxJacobian_u_p[nDOF_trial_element],
7088 fluxJacobian_u_u[nDOF_v_trial_element],
7089 fluxJacobian_u_v[nDOF_v_trial_element],
7090 fluxJacobian_u_w[nDOF_v_trial_element],
7091 fluxJacobian_v_p[nDOF_trial_element],
7092 fluxJacobian_v_u[nDOF_v_trial_element],
7093 fluxJacobian_v_v[nDOF_v_trial_element],
7094 fluxJacobian_v_w[nDOF_v_trial_element],
7095 fluxJacobian_w_p[nDOF_trial_element],
7096 fluxJacobian_w_u[nDOF_v_trial_element],
7097 fluxJacobian_w_v[nDOF_v_trial_element],
7098 fluxJacobian_w_w[nDOF_v_trial_element],
7099 jac_ext[nSpace*nSpace],
7100 jacDet_ext,
7101 jacInv_ext[nSpace*nSpace],
7102 boundaryJac[nSpace*(nSpace-1)],
7103 metricTensor[(nSpace-1)*(nSpace-1)],
7104 metricTensorDetSqrt,
7105 p_grad_trial_trace[nDOF_trial_element*nSpace],
7106 vel_grad_trial_trace[nDOF_v_trial_element*nSpace],
7107 dS,
7108 p_test_dS[nDOF_test_element],
7109 vel_test_dS[nDOF_v_test_element],
7110 normal[nSpace],
7111 x_ext,y_ext,z_ext,xt_ext,yt_ext,zt_ext,integralScaling,
7112 vel_grad_test_dS[nDOF_v_trial_element*nSpace],
7113 //VRANS
7114 porosity_ext,
7115 //
7116 G[nSpace*nSpace],G_dd_G,tr_G,h_phi,h_penalty,penalty;
7119 ck.calculateMapping_elementBoundary(eN,
7120 ebN_local,
7121 kb,
7122 ebN_local_kb,
7123 mesh_dof.data(),
7124 mesh_l2g.data(),
7125 mesh_trial_trace_ref.data(),
7126 mesh_grad_trial_trace_ref.data(),
7127 boundaryJac_ref.data(),
7128 jac_ext,
7129 jacDet_ext,
7130 jacInv_ext,
7131 boundaryJac,
7132 metricTensor,
7133 metricTensorDetSqrt,
7134 normal_ref.data(),
7135 normal,
7136 x_ext,y_ext,z_ext);
7137 ck.calculateMappingVelocity_elementBoundary(eN,
7138 ebN_local,
7139 kb,
7140 ebN_local_kb,
7141 mesh_velocity_dof.data(),
7142 mesh_l2g.data(),
7143 mesh_trial_trace_ref.data(),
7144 xt_ext,yt_ext,zt_ext,
7145 normal,
7146 boundaryJac,
7147 metricTensor,
7148 integralScaling);
7149 //dS = ((1.0-MOVING_DOMAIN)*metricTensorDetSqrt + MOVING_DOMAIN*integralScaling)*dS_ref.data()[kb];
7150 dS = metricTensorDetSqrt*dS_ref.data()[kb];
7151 ck.calculateG(jacInv_ext,G,G_dd_G,tr_G);
7152 ck.calculateGScale(G,&ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],h_phi);
7153
7154 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7155 eps_mu = epsFact_mu *(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7156
7157 //compute shape and solution information
7158 //shape
7159 ck.gradTrialFromRef(&p_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_trial_element],jacInv_ext,p_grad_trial_trace);
7160 ck_v.gradTrialFromRef(&vel_grad_trial_trace_ref.data()[ebN_local_kb_nSpace*nDOF_v_trial_element],jacInv_ext,vel_grad_trial_trace);
7161 //solution and gradients
7162 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);
7163 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);
7164 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);
7165 ck_v.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],w_ext);
7166 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);
7167 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);
7168 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);
7169 ck_v.valFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],&vel_trial_trace_ref.data()[ebN_local_kb*nDOF_v_test_element],w_old);
7170 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_ext);
7171 ck_v.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_ext);
7172 ck_v.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_ext);
7173 ck_v.gradFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_w_ext);
7174 ck.gradFromDOF(p_old_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial_trace,grad_p_old);
7175 ck_v.gradFromDOF(u_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_u_old);
7176 ck_v.gradFromDOF(v_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_v_old);
7177 ck_v.gradFromDOF(w_old_dof.data(),&vel_l2g.data()[eN_nDOF_v_trial_element],vel_grad_trial_trace,grad_w_old);
7178 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);
7179 //precalculate test function products with integration weights
7180 for (int j=0;j<nDOF_test_element;j++)
7181 {
7182 p_test_dS[j] = p_test_trace_ref.data()[ebN_local_kb*nDOF_test_element+j]*dS;
7183 }
7184 //precalculate test function products with integration weights
7185 for (int j=0;j<nDOF_v_test_element;j++)
7186 {
7187 vel_test_dS[j] = vel_test_trace_ref.data()[ebN_local_kb*nDOF_v_test_element+j]*dS;
7188 for (int I=0;I<nSpace;I++)
7189 vel_grad_test_dS[j*nSpace+I] = vel_grad_trial_trace[j*nSpace+I]*dS;//assume test_j == trial_j
7190 }
7191 //
7192 //load the boundary values
7193 //
7194 bc_p_ext = isDOFBoundary_p.data()[ebNE_kb]*ebqe_bc_p_ext.data()[ebNE_kb]+(1-isDOFBoundary_p.data()[ebNE_kb])*p_ext;
7195 //bc values at moving boundaries are specified relative to boundary motion so we need to add it here
7196 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;
7197 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;
7198 bc_w_ext = isDOFBoundary_w.data()[ebNE_kb]*(ebqe_bc_w_ext.data()[ebNE_kb] + MOVING_DOMAIN*zt_ext) + (1-isDOFBoundary_w.data()[ebNE_kb])*w_ext;
7199 //VRANS
7200 porosity_ext = ebqe_porosity_ext.data()[ebNE_kb];
7201 //
7202 //calculate the internal and external trace of the pde coefficients
7203 //
7204 double eddy_viscosity_ext(0.),bc_eddy_viscosity_ext(0.);//not interested in saving boundary eddy viscosity for now
7205 if (use_ball_as_particle == 1 && nParticles > 0)
7206 {
7207 get_distance_to_ball(nParticles, ball_center.data(), ball_radius.data(),x_ext,y_ext,z_ext,ebqe_phi_s.data()[ebNE_kb]);
7208 }
7209 //else distance_to_solids is updated in PreStep
7210 const double particle_eps = particle_epsFact*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
7211 //cek needs to be fixed for two-phase ifem
7212 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]));
7213 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])));
7214 double rho = rho_0*ImH + rho_1*H;
7215 double nu = nu_0*ImH + nu_1*H;
7216 //
7217 evaluateCoefficients(NONCONSERVATIVE_FORM,
7218 sigma,
7219 rho,
7220 nu,
7221 elementDiameter.data()[eN],
7222 smagorinskyConstant,
7223 turbulenceClosureModel,
7224 g.data(),
7225 useVF,
7226 ebqe_vf_ext.data()[ebNE_kb],
7227 ebqe_phi_ext.data()[ebNE_kb],
7228 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
7229 ebqe_kappa_phi_ext.data()[ebNE_kb],
7230 //VRANS
7231 porosity_ext,
7232 //
7233 ebqe_phi_s.data()[ebNE_kb],
7234 p_old,
7235 u_old,
7236 v_old,
7237 w_old,
7238 grad_p_old,
7239 grad_u_old,
7240 grad_v_old,
7241 grad_w_old,
7242 p_ext,
7243 grad_p_ext,
7244 grad_u_ext,
7245 grad_v_ext,
7246 grad_w_ext,
7247 u_ext,
7248 v_ext,
7249 w_ext,
7250 LAG_LES,
7251 eddy_viscosity_ext,
7252 ebqe_eddy_viscosity_last.data()[ebNE_kb],
7253 mom_u_acc_ext,
7254 dmom_u_acc_u_ext,
7255 mom_v_acc_ext,
7256 dmom_v_acc_v_ext,
7257 mom_w_acc_ext,
7258 dmom_w_acc_w_ext,
7259 mass_adv_ext,
7260 dmass_adv_u_ext,
7261 dmass_adv_v_ext,
7262 dmass_adv_w_ext,
7263 mom_u_adv_ext,
7264 dmom_u_adv_u_ext,
7265 dmom_u_adv_v_ext,
7266 dmom_u_adv_w_ext,
7267 mom_v_adv_ext,
7268 dmom_v_adv_u_ext,
7269 dmom_v_adv_v_ext,
7270 dmom_v_adv_w_ext,
7271 mom_w_adv_ext,
7272 dmom_w_adv_u_ext,
7273 dmom_w_adv_v_ext,
7274 dmom_w_adv_w_ext,
7275 mom_uu_diff_ten_ext,
7276 mom_vv_diff_ten_ext,
7277 mom_ww_diff_ten_ext,
7278 mom_uv_diff_ten_ext,
7279 mom_uw_diff_ten_ext,
7280 mom_vu_diff_ten_ext,
7281 mom_vw_diff_ten_ext,
7282 mom_wu_diff_ten_ext,
7283 mom_wv_diff_ten_ext,
7284 mom_u_source_ext,
7285 mom_v_source_ext,
7286 mom_w_source_ext,
7287 mom_u_ham_ext,
7288 dmom_u_ham_grad_p_ext,
7289 dmom_u_ham_grad_u_ext,
7290 dmom_u_ham_u_ext,
7291 dmom_u_ham_v_ext,
7292 dmom_u_ham_w_ext,
7293 mom_v_ham_ext,
7294 dmom_v_ham_grad_p_ext,
7295 dmom_v_ham_grad_v_ext,
7296 dmom_v_ham_u_ext,
7297 dmom_v_ham_v_ext,
7298 dmom_v_ham_w_ext,
7299 mom_w_ham_ext,
7300 dmom_w_ham_grad_p_ext,
7301 dmom_w_ham_grad_w_ext,
7302 dmom_w_ham_u_ext,
7303 dmom_w_ham_v_ext,
7304 dmom_w_ham_w_ext,
7305 0.0,
7306 0.0,
7307 0.0);
7308 //cek needs to be fixed for two-phase ifem
7309 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]));
7310 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])));
7311 rho = rho_0*ImH + rho_1*H;
7312 nu = nu_0*ImH + nu_1*H;
7313 //
7314 evaluateCoefficients(NONCONSERVATIVE_FORM,
7315 sigma,
7316 rho,
7317 nu,
7318 elementDiameter.data()[eN],
7319 smagorinskyConstant,
7320 turbulenceClosureModel,
7321 g.data(),
7322 useVF,
7323 bc_ebqe_vf_ext.data()[ebNE_kb],
7324 bc_ebqe_phi_ext.data()[ebNE_kb],
7325 &ebqe_normal_phi_ext.data()[ebNE_kb_nSpace],
7326 ebqe_kappa_phi_ext.data()[ebNE_kb],
7327 //VRANS
7328 porosity_ext,
7329 //
7330 ebqe_phi_s.data()[ebNE_kb],
7331 p_old,
7332 u_old,
7333 v_old,
7334 w_old,
7335 grad_p_old,
7336 grad_u_old,
7337 grad_v_old,
7338 grad_w_old,
7339 bc_p_ext,
7340 grad_p_ext,
7341 grad_u_ext,
7342 grad_v_ext,
7343 grad_w_ext,
7344 bc_u_ext,
7345 bc_v_ext,
7346 bc_w_ext,
7347 LAG_LES,
7348 bc_eddy_viscosity_ext,
7349 ebqe_eddy_viscosity_last.data()[ebNE_kb],
7350 bc_mom_u_acc_ext,
7351 bc_dmom_u_acc_u_ext,
7352 bc_mom_v_acc_ext,
7353 bc_dmom_v_acc_v_ext,
7354 bc_mom_w_acc_ext,
7355 bc_dmom_w_acc_w_ext,
7356 bc_mass_adv_ext,
7357 bc_dmass_adv_u_ext,
7358 bc_dmass_adv_v_ext,
7359 bc_dmass_adv_w_ext,
7360 bc_mom_u_adv_ext,
7361 bc_dmom_u_adv_u_ext,
7362 bc_dmom_u_adv_v_ext,
7363 bc_dmom_u_adv_w_ext,
7364 bc_mom_v_adv_ext,
7365 bc_dmom_v_adv_u_ext,
7366 bc_dmom_v_adv_v_ext,
7367 bc_dmom_v_adv_w_ext,
7368 bc_mom_w_adv_ext,
7369 bc_dmom_w_adv_u_ext,
7370 bc_dmom_w_adv_v_ext,
7371 bc_dmom_w_adv_w_ext,
7372 bc_mom_uu_diff_ten_ext,
7373 bc_mom_vv_diff_ten_ext,
7374 bc_mom_ww_diff_ten_ext,
7375 bc_mom_uv_diff_ten_ext,
7376 bc_mom_uw_diff_ten_ext,
7377 bc_mom_vu_diff_ten_ext,
7378 bc_mom_vw_diff_ten_ext,
7379 bc_mom_wu_diff_ten_ext,
7380 bc_mom_wv_diff_ten_ext,
7381 bc_mom_u_source_ext,
7382 bc_mom_v_source_ext,
7383 bc_mom_w_source_ext,
7384 bc_mom_u_ham_ext,
7385 bc_dmom_u_ham_grad_p_ext,
7386 bc_dmom_u_ham_grad_u_ext,
7387 bc_dmom_u_ham_u_ext,
7388 bc_dmom_u_ham_v_ext,
7389 bc_dmom_u_ham_w_ext,
7390 bc_mom_v_ham_ext,
7391 bc_dmom_v_ham_grad_p_ext,
7392 bc_dmom_v_ham_grad_v_ext,
7393 bc_dmom_v_ham_u_ext,
7394 bc_dmom_v_ham_v_ext,
7395 bc_dmom_v_ham_w_ext,
7396 bc_mom_w_ham_ext,
7397 bc_dmom_w_ham_grad_p_ext,
7398 bc_dmom_w_ham_grad_w_ext,
7399 bc_dmom_w_ham_u_ext,
7400 bc_dmom_w_ham_v_ext,
7401 bc_dmom_w_ham_w_ext,
7402 0.0,
7403 0.0,
7404 0.0);
7405 //Turbulence closure model
7406 if (turbulenceClosureModel >= 3)
7407 {
7408 const double turb_var_grad_0_dummy[nSpace] = ZEROVEC;
7409 const double c_mu = 0.09;//mwf hack
7410 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
7411 turbulenceClosureModel,
7412 eps_rho,
7413 eps_mu,
7414 rho_0,
7415 nu_0,
7416 rho_1,
7417 nu_1,
7418 useVF,
7419 ebqe_vf_ext.data()[ebNE_kb],
7420 ebqe_phi_ext.data()[ebNE_kb],
7421 porosity_ext,
7422 c_mu, //mwf hack
7423 ebqe_turb_var_0.data()[ebNE_kb],
7424 ebqe_turb_var_1.data()[ebNE_kb],
7425 turb_var_grad_0_dummy, //not needed
7426 eddy_viscosity_ext,
7427 mom_uu_diff_ten_ext,
7428 mom_vv_diff_ten_ext,
7429 mom_ww_diff_ten_ext,
7430 mom_uv_diff_ten_ext,
7431 mom_uw_diff_ten_ext,
7432 mom_vu_diff_ten_ext,
7433 mom_vw_diff_ten_ext,
7434 mom_wu_diff_ten_ext,
7435 mom_wv_diff_ten_ext,
7436 mom_u_source_ext,
7437 mom_v_source_ext,
7438 mom_w_source_ext);
7439
7440 updateTurbulenceClosure(NONCONSERVATIVE_FORM,
7441 turbulenceClosureModel,
7442 eps_rho,
7443 eps_mu,
7444 rho_0,
7445 nu_0,
7446 rho_1,
7447 nu_1,
7448 useVF,
7449 ebqe_vf_ext.data()[ebNE_kb],
7450 ebqe_phi_ext.data()[ebNE_kb],
7451 porosity_ext,
7452 c_mu, //mwf hack
7453 ebqe_turb_var_0.data()[ebNE_kb],
7454 ebqe_turb_var_1.data()[ebNE_kb],
7455 turb_var_grad_0_dummy, //not needed
7456 bc_eddy_viscosity_ext,
7457 bc_mom_uu_diff_ten_ext,
7458 bc_mom_vv_diff_ten_ext,
7459 bc_mom_ww_diff_ten_ext,
7460 bc_mom_uv_diff_ten_ext,
7461 bc_mom_uw_diff_ten_ext,
7462 bc_mom_vu_diff_ten_ext,
7463 bc_mom_vw_diff_ten_ext,
7464 bc_mom_wu_diff_ten_ext,
7465 bc_mom_wv_diff_ten_ext,
7466 bc_mom_u_source_ext,
7467 bc_mom_v_source_ext,
7468 bc_mom_w_source_ext);
7469 }
7470 //
7471 //moving domain
7472 //
7473 if (NONCONSERVATIVE_FORM > 0.0)
7474 {
7475 mom_u_ham_ext -= MOVING_DOMAIN*dmom_u_acc_u_ext*(grad_u_ext[0]*xt_ext +
7476 grad_u_ext[1]*yt_ext +
7477 grad_u_ext[2]*zt_ext);
7478 dmom_u_ham_grad_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
7479 dmom_u_ham_grad_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
7480 dmom_u_ham_grad_u_ext[2] -= MOVING_DOMAIN*dmom_u_acc_u_ext*zt_ext;
7481 }
7482 else
7483 {
7484 mom_u_adv_ext[0] -= MOVING_DOMAIN*mom_u_acc_ext*xt_ext;
7485 mom_u_adv_ext[1] -= MOVING_DOMAIN*mom_u_acc_ext*yt_ext;
7486 mom_u_adv_ext[2] -= MOVING_DOMAIN*mom_u_acc_ext*zt_ext;
7487 dmom_u_adv_u_ext[0] -= MOVING_DOMAIN*dmom_u_acc_u_ext*xt_ext;
7488 dmom_u_adv_u_ext[1] -= MOVING_DOMAIN*dmom_u_acc_u_ext*yt_ext;
7489 dmom_u_adv_u_ext[2] -= MOVING_DOMAIN*dmom_u_acc_u_ext*zt_ext;
7490 }
7491
7492 if (NONCONSERVATIVE_FORM > 0.0)
7493 {
7494 mom_v_ham_ext -= MOVING_DOMAIN*dmom_v_acc_v_ext*(grad_v_ext[0]*xt_ext +
7495 grad_v_ext[1]*yt_ext +
7496 grad_v_ext[2]*zt_ext);
7497 dmom_v_ham_grad_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
7498 dmom_v_ham_grad_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
7499 dmom_v_ham_grad_v_ext[2] -= MOVING_DOMAIN*dmom_v_acc_v_ext*zt_ext;
7500 }
7501 else
7502 {
7503 mom_v_adv_ext[0] -= MOVING_DOMAIN*mom_v_acc_ext*xt_ext;
7504 mom_v_adv_ext[1] -= MOVING_DOMAIN*mom_v_acc_ext*yt_ext;
7505 mom_v_adv_ext[2] -= MOVING_DOMAIN*mom_v_acc_ext*zt_ext;
7506 dmom_v_adv_v_ext[0] -= MOVING_DOMAIN*dmom_v_acc_v_ext*xt_ext;
7507 dmom_v_adv_v_ext[1] -= MOVING_DOMAIN*dmom_v_acc_v_ext*yt_ext;
7508 dmom_v_adv_v_ext[2] -= MOVING_DOMAIN*dmom_v_acc_v_ext*zt_ext;
7509 }
7510
7511 if (NONCONSERVATIVE_FORM > 0.0)
7512 {
7513 mom_w_ham_ext -= MOVING_DOMAIN*dmom_w_acc_w_ext*(grad_w_ext[0]*xt_ext +
7514 grad_w_ext[1]*yt_ext +
7515 grad_w_ext[2]*zt_ext);
7516 dmom_w_ham_grad_w_ext[0] -= MOVING_DOMAIN*dmom_w_acc_w_ext*xt_ext;
7517 dmom_w_ham_grad_w_ext[1] -= MOVING_DOMAIN*dmom_w_acc_w_ext*yt_ext;
7518 dmom_w_ham_grad_w_ext[2] -= MOVING_DOMAIN*dmom_w_acc_w_ext*zt_ext;
7519 }
7520 else
7521 {
7522 mom_w_adv_ext[0] -= MOVING_DOMAIN*mom_w_acc_ext*xt_ext;
7523 mom_w_adv_ext[1] -= MOVING_DOMAIN*mom_w_acc_ext*yt_ext;
7524 mom_w_adv_ext[2] -= MOVING_DOMAIN*mom_w_acc_ext*zt_ext;
7525 dmom_w_adv_w_ext[0] -= MOVING_DOMAIN*dmom_w_acc_w_ext*xt_ext;
7526 dmom_w_adv_w_ext[1] -= MOVING_DOMAIN*dmom_w_acc_w_ext*yt_ext;
7527 dmom_w_adv_w_ext[2] -= MOVING_DOMAIN*dmom_w_acc_w_ext*zt_ext;
7528 }
7529
7530 //moving domain bc's
7531 if (NONCONSERVATIVE_FORM < 1.0)
7532 {
7533 bc_mom_u_adv_ext[0] -= MOVING_DOMAIN*bc_mom_u_acc_ext*xt_ext;
7534 bc_mom_u_adv_ext[1] -= MOVING_DOMAIN*bc_mom_u_acc_ext*yt_ext;
7535 bc_mom_u_adv_ext[2] -= MOVING_DOMAIN*bc_mom_u_acc_ext*zt_ext;
7536
7537 bc_mom_v_adv_ext[0] -= MOVING_DOMAIN*bc_mom_v_acc_ext*xt_ext;
7538 bc_mom_v_adv_ext[1] -= MOVING_DOMAIN*bc_mom_v_acc_ext*yt_ext;
7539 bc_mom_v_adv_ext[2] -= MOVING_DOMAIN*bc_mom_v_acc_ext*zt_ext;
7540
7541 bc_mom_w_adv_ext[0] -= MOVING_DOMAIN*bc_mom_w_acc_ext*xt_ext;
7542 bc_mom_w_adv_ext[1] -= MOVING_DOMAIN*bc_mom_w_acc_ext*yt_ext;
7543 bc_mom_w_adv_ext[2] -= MOVING_DOMAIN*bc_mom_w_acc_ext*zt_ext;
7544 }
7545 //
7546 //calculate the numerical fluxes
7547 //
7548 exteriorNumericalAdvectiveFluxDerivatives(NONCONSERVATIVE_FORM,
7549 isDOFBoundary_p.data()[ebNE_kb],
7550 isDOFBoundary_u.data()[ebNE_kb],
7551 isDOFBoundary_v.data()[ebNE_kb],
7552 isDOFBoundary_w.data()[ebNE_kb],
7553 isAdvectiveFluxBoundary_p.data()[ebNE_kb],
7554 isAdvectiveFluxBoundary_u.data()[ebNE_kb],
7555 isAdvectiveFluxBoundary_v.data()[ebNE_kb],
7556 isAdvectiveFluxBoundary_w.data()[ebNE_kb],
7557 dmom_u_ham_grad_p_ext[0],//=1/rho
7558 normal,
7559 bc_p_ext,
7560 bc_u_ext,
7561 bc_v_ext,
7562 bc_w_ext,
7563 bc_mass_adv_ext,
7564 bc_mom_u_adv_ext,
7565 bc_mom_v_adv_ext,
7566 bc_mom_w_adv_ext,
7567 ebqe_bc_flux_mass_ext.data()[ebNE_kb]+MOVING_DOMAIN*(xt_ext*normal[0]+yt_ext*normal[1]+zt_ext*normal[2]),//bc is relative mass flux
7568 ebqe_bc_flux_mom_u_adv_ext.data()[ebNE_kb],
7569 ebqe_bc_flux_mom_v_adv_ext.data()[ebNE_kb],
7570 ebqe_bc_flux_mom_w_adv_ext.data()[ebNE_kb],
7571 p_ext,
7572 u_ext,
7573 v_ext,
7574 w_ext,
7575 dmom_u_acc_u_ext,
7576 mass_adv_ext,
7577 mom_u_adv_ext,
7578 mom_v_adv_ext,
7579 mom_w_adv_ext,
7580 dmass_adv_u_ext,
7581 dmass_adv_v_ext,
7582 dmass_adv_w_ext,
7583 dmom_u_adv_p_ext,
7584 dmom_u_ham_grad_u_ext,
7585 dmom_u_adv_u_ext,
7586 dmom_u_adv_v_ext,
7587 dmom_u_adv_w_ext,
7588 dmom_v_adv_p_ext,
7589 dmom_v_adv_u_ext,
7590 dmom_v_adv_v_ext,
7591 dmom_v_adv_w_ext,
7592 dmom_w_adv_p_ext,
7593 dmom_w_adv_u_ext,
7594 dmom_w_adv_v_ext,
7595 dmom_w_adv_w_ext,
7596 dflux_mass_u_ext,
7597 dflux_mass_v_ext,
7598 dflux_mass_w_ext,
7599 dflux_mom_u_adv_p_ext,
7600 dflux_mom_u_adv_u_ext,
7601 dflux_mom_u_adv_v_ext,
7602 dflux_mom_u_adv_w_ext,
7603 dflux_mom_v_adv_p_ext,
7604 dflux_mom_v_adv_u_ext,
7605 dflux_mom_v_adv_v_ext,
7606 dflux_mom_v_adv_w_ext,
7607 dflux_mom_w_adv_p_ext,
7608 dflux_mom_w_adv_u_ext,
7609 dflux_mom_w_adv_v_ext,
7610 dflux_mom_w_adv_w_ext);
7611 //
7612 //calculate the flux jacobian
7613 //
7614 ck.calculateGScale(G,normal,h_penalty);
7615 penalty = useMetrics*C_b/h_penalty + (1.0-useMetrics)*ebqe_penalty_ext.data()[ebNE_kb];
7616 if (isActiveElement[eN])
7617 // if(true)//boundaryFlags[ebN] > 0)
7618 { //if boundary flag positive, then include flux contributions on interpart boundaries
7619 for (int j=0;j<nDOF_trial_element;j++)
7620 {
7621 int j_nSpace = j*nSpace,ebN_local_kb_j=ebN_local_kb*nDOF_trial_element+j;
7622 fluxJacobian_p_p[j]=0.0;
7623 fluxJacobian_u_p[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_p_ext,p_trial_trace_ref.data()[ebN_local_kb_j]);
7624 fluxJacobian_v_p[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_p_ext,p_trial_trace_ref.data()[ebN_local_kb_j]);
7625 fluxJacobian_w_p[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_w_adv_p_ext,p_trial_trace_ref.data()[ebN_local_kb_j]);
7626 }
7627 for (int j=0;j<nDOF_v_trial_element;j++)
7628 {
7629 int j_nSpace = j*nSpace,ebN_local_kb_j=ebN_local_kb*nDOF_v_trial_element+j;
7630 fluxJacobian_p_u[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mass_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]);
7631 fluxJacobian_p_v[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mass_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]);
7632 fluxJacobian_p_w[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mass_w_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]);
7633 fluxJacobian_u_u[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7635 ebqe_phi_ext.data()[ebNE_kb],
7636 sdInfo_u_u_rowptr.data(),
7637 sdInfo_u_u_colind.data(),
7638 isDOFBoundary_u.data()[ebNE_kb],
7639 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7640 normal,
7641 mom_uu_diff_ten_ext,
7642 vel_trial_trace_ref.data()[ebN_local_kb_j],
7643 &vel_grad_trial_trace[j_nSpace],
7644 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7645 fluxJacobian_u_v[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7647 ebqe_phi_ext.data()[ebNE_kb],
7648 sdInfo_u_v_rowptr.data(),
7649 sdInfo_u_v_colind.data(),
7650 isDOFBoundary_v.data()[ebNE_kb],
7651 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7652 normal,
7653 mom_uv_diff_ten_ext,
7654 vel_trial_trace_ref.data()[ebN_local_kb_j],
7655 &vel_grad_trial_trace[j_nSpace],
7656 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7657 fluxJacobian_u_w[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_u_adv_w_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7659 ebqe_phi_ext.data()[ebNE_kb],
7660 sdInfo_u_w_rowptr.data(),
7661 sdInfo_u_w_colind.data(),
7662 isDOFBoundary_w.data()[ebNE_kb],
7663 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7664 normal,
7665 mom_uw_diff_ten_ext,
7666 vel_trial_trace_ref.data()[ebN_local_kb_j],
7667 &vel_grad_trial_trace[j_nSpace],
7668 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7669
7670 fluxJacobian_v_u[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7672 ebqe_phi_ext.data()[ebNE_kb],
7673 sdInfo_v_u_rowptr.data(),
7674 sdInfo_v_u_colind.data(),
7675 isDOFBoundary_u.data()[ebNE_kb],
7676 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7677 normal,
7678 mom_vu_diff_ten_ext,
7679 vel_trial_trace_ref.data()[ebN_local_kb_j],
7680 &vel_grad_trial_trace[j_nSpace],
7681 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7682 fluxJacobian_v_v[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7684 ebqe_phi_ext.data()[ebNE_kb],
7685 sdInfo_v_v_rowptr.data(),
7686 sdInfo_v_v_colind.data(),
7687 isDOFBoundary_v.data()[ebNE_kb],
7688 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7689 normal,
7690 mom_vv_diff_ten_ext,
7691 vel_trial_trace_ref.data()[ebN_local_kb_j],
7692 &vel_grad_trial_trace[j_nSpace],
7693 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7694 fluxJacobian_v_w[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_v_adv_w_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7696 ebqe_phi_ext.data()[ebNE_kb],
7697 sdInfo_v_w_rowptr.data(),
7698 sdInfo_v_w_colind.data(),
7699 isDOFBoundary_w.data()[ebNE_kb],
7700 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7701 normal,
7702 mom_vw_diff_ten_ext,
7703 vel_trial_trace_ref.data()[ebN_local_kb_j],
7704 &vel_grad_trial_trace[j_nSpace],
7705 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7706
7707 fluxJacobian_w_u[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_w_adv_u_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7709 ebqe_phi_ext.data()[ebNE_kb],
7710 sdInfo_w_u_rowptr.data(),
7711 sdInfo_w_u_colind.data(),
7712 isDOFBoundary_u.data()[ebNE_kb],
7713 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7714 normal,
7715 mom_wu_diff_ten_ext,
7716 vel_trial_trace_ref.data()[ebN_local_kb_j],
7717 &vel_grad_trial_trace[j_nSpace],
7718 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7719 fluxJacobian_w_v[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_w_adv_v_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7721 ebqe_phi_ext.data()[ebNE_kb],
7722 sdInfo_w_v_rowptr.data(),
7723 sdInfo_w_v_colind.data(),
7724 isDOFBoundary_v.data()[ebNE_kb],
7725 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7726 normal,
7727 mom_wv_diff_ten_ext,
7728 vel_trial_trace_ref.data()[ebN_local_kb_j],
7729 &vel_grad_trial_trace[j_nSpace],
7730 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7731 fluxJacobian_w_w[j]=ck.ExteriorNumericalAdvectiveFluxJacobian(dflux_mom_w_adv_w_ext,vel_trial_trace_ref.data()[ebN_local_kb_j]) +
7733 ebqe_phi_ext.data()[ebNE_kb],
7734 sdInfo_w_w_rowptr.data(),
7735 sdInfo_w_w_colind.data(),
7736 isDOFBoundary_w.data()[ebNE_kb],
7737 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7738 normal,
7739 mom_ww_diff_ten_ext,
7740 vel_trial_trace_ref.data()[ebN_local_kb_j],
7741 &vel_grad_trial_trace[j_nSpace],
7742 penalty);//ebqe_penalty_ext.data()[ebNE_kb]);
7743 }//j
7744 }
7745 //
7746 //update the global Jacobian from the flux Jacobian
7747 //
7748 const double H_s = gf_s.H(particle_eps, ebqe_phi_s[ebNE_kb]);
7749 if (isActiveElement[eN])
7750 {
7751 for (int i=0;i<nDOF_test_element;i++)
7752 {
7753 int eN_i = eN*nDOF_test_element+i;
7754 for (int j=0;j<nDOF_trial_element;j++)
7755 {
7756 int eN_j = eN*nDOF_trial_element+j;
7757 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;
7758
7759 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];
7760 }
7761 }
7762 for (int i=0;i<nDOF_test_element;i++)
7763 {
7764 int eN_i = eN*nDOF_test_element+i;
7765 for (int j=0;j<nDOF_v_trial_element;j++)
7766 {
7767 int eN_j = eN*nDOF_v_trial_element+j;
7768 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;
7769 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];
7770 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];
7771 globalJacobian.data()[csrRowIndeces_p_w.data()[eN_i] + csrColumnOffsets_eb_p_w.data()[ebN_i_j]] += H_s*fluxJacobian_p_w[j]*p_test_dS[i];
7772 }
7773 }
7774 for (int i=0;i<nDOF_v_test_element;i++)
7775 {
7776 int eN_i = eN*nDOF_v_test_element+i;
7777 for (int j=0;j<nDOF_trial_element;j++)
7778 {
7779 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;
7780 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];
7781 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];
7782 globalJacobian.data()[csrRowIndeces_w_p.data()[eN_i] + csrColumnOffsets_eb_w_p.data()[ebN_i_j]] += H_s*fluxJacobian_w_p[j]*vel_test_dS[i];
7783 }
7784 }
7785 for (int i=0;i<nDOF_v_test_element;i++)
7786 {
7787 int eN_i = eN*nDOF_v_test_element+i;
7788 for (int j=0;j<nDOF_v_trial_element;j++)
7789 {
7790 int eN_j = eN*nDOF_v_trial_element+j;
7791 int ebN_i_j = ebN*4*nDOF_v_test_X_v_trial_element + i*nDOF_v_trial_element + j,ebN_local_kb_j=ebN_local_kb*nDOF_v_trial_element+j;
7792 globalJacobian.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_eb_u_u.data()[ebN_i_j]] +=
7793 H_s*(fluxJacobian_u_u[j]*vel_test_dS[i]+
7794 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_u.data()[ebNE_kb],
7795 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7796 eb_adjoint_sigma,
7797 vel_trial_trace_ref.data()[ebN_local_kb_j],
7798 normal,
7799 sdInfo_u_u_rowptr.data(),
7800 sdInfo_u_u_colind.data(),
7801 mom_uu_diff_ten_ext,
7802 &vel_grad_test_dS[i*nSpace]));
7803 globalJacobian.data()[csrRowIndeces_u_v.data()[eN_i] + csrColumnOffsets_eb_u_v.data()[ebN_i_j]] +=
7804 H_s*(fluxJacobian_u_v[j]*vel_test_dS[i]+
7805 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_v.data()[ebNE_kb],
7806 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7807 eb_adjoint_sigma,
7808 vel_trial_trace_ref.data()[ebN_local_kb_j],
7809 normal,
7810 sdInfo_u_v_rowptr.data(),
7811 sdInfo_u_v_colind.data(),
7812 mom_uv_diff_ten_ext,
7813 &vel_grad_test_dS[i*nSpace]));
7814 globalJacobian.data()[csrRowIndeces_u_w.data()[eN_i] + csrColumnOffsets_eb_u_w.data()[ebN_i_j]] +=
7815 H_s*(fluxJacobian_u_w[j]*vel_test_dS[i]+
7816 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_w.data()[ebNE_kb],
7817 isDiffusiveFluxBoundary_u.data()[ebNE_kb],
7818 eb_adjoint_sigma,
7819 vel_trial_trace_ref.data()[ebN_local_kb_j],
7820 normal,
7821 sdInfo_u_w_rowptr.data(),
7822 sdInfo_u_w_colind.data(),
7823 mom_uw_diff_ten_ext,
7824 &vel_grad_test_dS[i*nSpace]));
7825 globalJacobian.data()[csrRowIndeces_v_u.data()[eN_i] + csrColumnOffsets_eb_v_u.data()[ebN_i_j]] +=
7826 H_s*(fluxJacobian_v_u[j]*vel_test_dS[i]+
7827 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_u.data()[ebNE_kb],
7828 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7829 eb_adjoint_sigma,
7830 vel_trial_trace_ref.data()[ebN_local_kb_j],
7831 normal,
7832 sdInfo_v_u_rowptr.data(),
7833 sdInfo_v_u_colind.data(),
7834 mom_vu_diff_ten_ext,
7835 &vel_grad_test_dS[i*nSpace]));
7836 globalJacobian.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_eb_v_v.data()[ebN_i_j]] +=
7837 H_s*(fluxJacobian_v_v[j]*vel_test_dS[i]+
7838 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_v.data()[ebNE_kb],
7839 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7840 eb_adjoint_sigma,
7841 vel_trial_trace_ref.data()[ebN_local_kb_j],
7842 normal,
7843 sdInfo_v_v_rowptr.data(),
7844 sdInfo_v_v_colind.data(),
7845 mom_vv_diff_ten_ext,
7846 &vel_grad_test_dS[i*nSpace]));
7847 globalJacobian.data()[csrRowIndeces_v_w.data()[eN_i] + csrColumnOffsets_eb_v_w.data()[ebN_i_j]] +=
7848 H_s*(fluxJacobian_v_w[j]*vel_test_dS[i]+
7849 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_w.data()[ebNE_kb],
7850 isDiffusiveFluxBoundary_v.data()[ebNE_kb],
7851 eb_adjoint_sigma,
7852 vel_trial_trace_ref.data()[ebN_local_kb_j],
7853 normal,
7854 sdInfo_v_w_rowptr.data(),
7855 sdInfo_v_w_colind.data(),
7856 mom_vw_diff_ten_ext,
7857 &vel_grad_test_dS[i*nSpace]));
7858 globalJacobian.data()[csrRowIndeces_w_u.data()[eN_i] + csrColumnOffsets_eb_w_u.data()[ebN_i_j]] +=
7859 H_s*(fluxJacobian_w_u[j]*vel_test_dS[i]+
7860 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_u.data()[ebNE_kb],
7861 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7862 eb_adjoint_sigma,
7863 vel_trial_trace_ref.data()[ebN_local_kb_j],
7864 normal,
7865 sdInfo_w_u_rowptr.data(),
7866 sdInfo_w_u_colind.data(),
7867 mom_wu_diff_ten_ext,
7868 &vel_grad_test_dS[i*nSpace]));
7869 globalJacobian.data()[csrRowIndeces_w_v.data()[eN_i] + csrColumnOffsets_eb_w_v.data()[ebN_i_j]] +=
7870 H_s*(fluxJacobian_w_v[j]*vel_test_dS[i]+
7871 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_v.data()[ebNE_kb],
7872 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7873 eb_adjoint_sigma,
7874 vel_trial_trace_ref.data()[ebN_local_kb_j],
7875 normal,
7876 sdInfo_w_v_rowptr.data(),
7877 sdInfo_w_v_colind.data(),
7878 mom_wv_diff_ten_ext,
7879 &vel_grad_test_dS[i*nSpace]));
7880 globalJacobian.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_eb_w_w.data()[ebN_i_j]] +=
7881 H_s*(fluxJacobian_w_w[j]*vel_test_dS[i]+
7882 ck.ExteriorElementBoundaryDiffusionAdjointJacobian(isDOFBoundary_w.data()[ebNE_kb],
7883 isDiffusiveFluxBoundary_w.data()[ebNE_kb],
7884 eb_adjoint_sigma,
7885 vel_trial_trace_ref.data()[ebN_local_kb_j],
7886 normal,
7887 sdInfo_w_w_rowptr.data(),
7888 sdInfo_w_w_colind.data(),
7889 mom_ww_diff_ten_ext,
7890 &vel_grad_test_dS[i*nSpace]));
7891 }//j
7892 }//i
7893 }
7894 }//kb
7895 }//ebNE
7896 }//computeJacobian
7897
7899 {
7900 int nExteriorElementBoundaries_global = args.scalar<int>("nExteriorElementBoundaries_global");
7901 xt::pyarray<int>& exteriorElementBoundariesArray = args.array<int>("exteriorElementBoundariesArray");
7902 int nInteriorElementBoundaries_global = args.scalar<int>("nInteriorElementBoundaries_global");
7903 xt::pyarray<int>& interiorElementBoundariesArray = args.array<int>("interiorElementBoundariesArray");
7904 xt::pyarray<int>& elementBoundaryElementsArray = args.array<int>("elementBoundaryElementsArray");
7905 xt::pyarray<int>& elementBoundaryLocalElementBoundariesArray = args.array<int>("elementBoundaryLocalElementBoundariesArray");
7906 xt::pyarray<double>& mesh_dof = args.array<double>("mesh_dof");
7907 xt::pyarray<double>& mesh_velocity_dof = args.array<double>("mesh_velocity_dof");
7908 double MOVING_DOMAIN = args.scalar<double>("MOVING_DOMAIN");
7909 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
7910 xt::pyarray<double>& mesh_trial_trace_ref = args.array<double>("mesh_trial_trace_ref");
7911 xt::pyarray<double>& mesh_grad_trial_trace_ref = args.array<double>("mesh_grad_trial_trace_ref");
7912 xt::pyarray<double>& normal_ref = args.array<double>("normal_ref");
7913 xt::pyarray<double>& boundaryJac_ref = args.array<double>("boundaryJac_ref");
7914 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
7915 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
7916 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
7917 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
7918 xt::pyarray<double>& vel_trial_trace_ref = args.array<double>("vel_trial_trace_ref");
7919 xt::pyarray<double>& ebqe_velocity = args.array<double>("ebqe_velocity");
7920 xt::pyarray<double>& velocityAverage = args.array<double>("velocityAverage");
7921 xt::pyarray<int>& elementMaterialTypes = args.array<int>("elementMaterialTypes");
7922 xt::pyarray<double>& porosityTypes = args.array<double>("porosityTypes");
7923 int permutations[nQuadraturePoints_elementBoundary];
7924 double xArray_left[nQuadraturePoints_elementBoundary*nSpace],
7925 xArray_right[nQuadraturePoints_elementBoundary*nSpace];
7926 for (int i=0;i<nQuadraturePoints_elementBoundary;i++)
7927 permutations[i]=i;//just to initialize
7928 for (int ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
7929 {
7930 int ebN = exteriorElementBoundariesArray.data()[ebNE];
7931 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
7932 {
7933 int ebN_kb_nSpace = ebN*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace,
7934 ebNE_kb_nSpace = ebNE*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace;
7935 velocityAverage.data()[ebN_kb_nSpace+0]=ebqe_velocity.data()[ebNE_kb_nSpace+0];
7936 velocityAverage.data()[ebN_kb_nSpace+1]=ebqe_velocity.data()[ebNE_kb_nSpace+1];
7937 velocityAverage.data()[ebN_kb_nSpace+2]=ebqe_velocity.data()[ebNE_kb_nSpace+2];
7938 }//ebNE
7939 }
7940 for (int ebNI = 0; ebNI < nInteriorElementBoundaries_global; ebNI++)
7941 {
7942 int ebN = interiorElementBoundariesArray.data()[ebNI],
7943 left_eN_global = elementBoundaryElementsArray.data()[ebN*2+0],
7944 left_ebN_element = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+0],
7945 right_eN_global = elementBoundaryElementsArray.data()[ebN*2+1],
7946 right_ebN_element = elementBoundaryLocalElementBoundariesArray.data()[ebN*2+1],
7947 left_eN_nDOF_trial_element = left_eN_global*nDOF_trial_element,
7948 right_eN_nDOF_trial_element = right_eN_global*nDOF_trial_element;
7949 double jac[nSpace*nSpace],
7950 jacDet,
7951 jacInv[nSpace*nSpace],
7952 boundaryJac[nSpace*(nSpace-1)],
7953 metricTensor[(nSpace-1)*(nSpace-1)],
7954 metricTensorDetSqrt,
7955 normal[nSpace],
7956 x,y,z,
7957 xt,yt,zt,integralScaling,
7958 left_porosity = porosityTypes[elementMaterialTypes[left_eN_global]],
7959 right_porosity = porosityTypes[elementMaterialTypes[right_eN_global]];
7960
7961 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
7962 {
7963 ck.calculateMapping_elementBoundary(left_eN_global,
7964 left_ebN_element,
7965 kb,
7966 left_ebN_element*nQuadraturePoints_elementBoundary+kb,
7967 mesh_dof.data(),
7968 mesh_l2g.data(),
7969 mesh_trial_trace_ref.data(),
7970 mesh_grad_trial_trace_ref.data(),
7971 boundaryJac_ref.data(),
7972 jac,
7973 jacDet,
7974 jacInv,
7975 boundaryJac,
7976 metricTensor,
7977 metricTensorDetSqrt,
7978 normal_ref.data(),
7979 normal,
7980 x,y,z);
7981 xArray_left[kb*nSpace+0] = x;
7982 xArray_left[kb*nSpace+1] = y;
7983 xArray_left[kb*nSpace+2] = z;
7984 ck.calculateMapping_elementBoundary(right_eN_global,
7985 right_ebN_element,
7986 kb,
7987 right_ebN_element*nQuadraturePoints_elementBoundary+kb,
7988 mesh_dof.data(),
7989 mesh_l2g.data(),
7990 mesh_trial_trace_ref.data(),
7991 mesh_grad_trial_trace_ref.data(),
7992 boundaryJac_ref.data(),
7993 jac,
7994 jacDet,
7995 jacInv,
7996 boundaryJac,
7997 metricTensor,
7998 metricTensorDetSqrt,
7999 normal_ref.data(),
8000 normal,
8001 x,y,z);
8002 ck.calculateMappingVelocity_elementBoundary(left_eN_global,
8003 left_ebN_element,
8004 kb,
8005 left_ebN_element*nQuadraturePoints_elementBoundary+kb,
8006 mesh_velocity_dof.data(),
8007 mesh_l2g.data(),
8008 mesh_trial_trace_ref.data(),
8009 xt,yt,zt,
8010 normal,
8011 boundaryJac,
8012 metricTensor,
8013 integralScaling);
8014 xArray_right[kb*nSpace+0] = x;
8015 xArray_right[kb*nSpace+1] = y;
8016 xArray_right[kb*nSpace+2] = z;
8017 }
8018 for (int kb_left=0;kb_left<nQuadraturePoints_elementBoundary;kb_left++)
8019 {
8020 double errorNormMin = 1.0;
8021 for (int kb_right=0;kb_right<nQuadraturePoints_elementBoundary;kb_right++)
8022 {
8023 double errorNorm=0.0;
8024 for (int I=0;I<nSpace;I++)
8025 {
8026 errorNorm += fabs(xArray_left[kb_left*nSpace+I]
8027 -
8028 xArray_right[kb_right*nSpace+I]);
8029 }
8030 if (errorNorm < errorNormMin)
8031 {
8032 permutations[kb_right] = kb_left;
8033 errorNormMin = errorNorm;
8034 }
8035 }
8036 }
8037 for (int kb=0;kb<nQuadraturePoints_elementBoundary;kb++)
8038 {
8039 int ebN_kb_nSpace = ebN*nQuadraturePoints_elementBoundary*nSpace+kb*nSpace;
8040 double u_left=0.0,
8041 v_left=0.0,
8042 w_left=0.0,
8043 u_right=0.0,
8044 v_right=0.0,
8045 w_right=0.0;
8046 int left_kb = kb,
8047 right_kb = permutations[kb],
8048 left_ebN_element_kb_nDOF_test_element=(left_ebN_element*nQuadraturePoints_elementBoundary+left_kb)*nDOF_test_element,
8049 right_ebN_element_kb_nDOF_test_element=(right_ebN_element*nQuadraturePoints_elementBoundary+right_kb)*nDOF_test_element;
8050 //
8051 //calculate the velocity solution at quadrature points on left and right
8052 //
8053 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);
8054 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);
8055 ck.valFromDOF(w_dof.data(),&vel_l2g.data()[left_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[left_ebN_element_kb_nDOF_test_element],w_left);
8056 //
8057 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);
8058 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);
8059 ck.valFromDOF(w_dof.data(),&vel_l2g.data()[right_eN_nDOF_trial_element],&vel_trial_trace_ref.data()[right_ebN_element_kb_nDOF_test_element],w_right);
8060 //
8061 velocityAverage.data()[ebN_kb_nSpace+0]=0.5*(left_porosity*u_left + right_porosity*u_right);
8062 velocityAverage.data()[ebN_kb_nSpace+1]=0.5*(left_porosity*v_left + right_porosity*v_right);
8063 velocityAverage.data()[ebN_kb_nSpace+2]=0.5*(left_porosity*w_left + right_porosity*w_right);
8064 }//ebNI
8065 }
8066 }
8067
8068 inline
8069 void evaluateTPAdvectionCoefficients(const double eps_rho,
8070 const double rho_0,
8071 const double rho_1,
8072 const double useVF,
8073 const double& vf,
8074 const double& phi,
8075 const double& u,
8076 const double& v,
8077 const double& w,
8078 double dmass_adv_p[nSpace],
8079 double dmom_u_adv_u[nSpace],
8080 double dmom_v_adv_v[nSpace],
8081 double dmom_w_adv_w[nSpace])
8082 {
8083 double H_rho, ImH_rho, rho;
8084
8085 H_rho = (1.0-useVF)*gf.H(eps_rho,phi) + useVF*fmin(1.0,fmax(0.0,vf));
8086 ImH_rho = (1.0-useVF)*gf.ImH(eps_rho,phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
8087
8088 rho = rho_0*ImH_rho + rho_1*H_rho;
8089
8090 dmass_adv_p[0] = rho*u;
8091 dmass_adv_p[1] = rho*v;
8092 dmass_adv_p[2] = rho*w;
8093
8094 dmom_u_adv_u[0] = rho*u;
8095 dmom_u_adv_u[1] = rho*v;
8096 dmom_u_adv_u[2] = rho*w;
8097
8098 dmom_v_adv_v[0] = rho*u;
8099 dmom_v_adv_v[1] = rho*v;
8100 dmom_v_adv_v[2] = rho*w;
8101
8102 dmom_w_adv_w[0] = rho*u;
8103 dmom_w_adv_w[1] = rho*v;
8104 dmom_w_adv_w[2] = rho*w;
8105 }
8106 inline
8107 void evaluateTPInvViscosityMassCoefficients(const int use_numerical_viscosity,
8108 const double numerical_viscosity,
8109 const double eps_rho,
8110 const double eps_mu,
8111 const double rho_0,
8112 double nu_0,
8113 const double rho_1,
8114 double nu_1,
8115 const double useVF,
8116 const double& vf,
8117 const double& phi,
8118 const double& p,
8119 const double& u,
8120 const double& v,
8121 const double& w,
8122 double& mom_p_acc,
8123 double& dmom_p_acc_p,
8124 double& mom_u_acc,
8125 double& dmom_u_acc_u,
8126 double& mom_v_acc,
8127 double& dmom_v_acc_v,
8128 double& mom_w_acc,
8129 double& dmom_w_acc_w)
8130 {
8131 // This should be split off into a seperate function
8132 double H_rho, ImH_rho, H_mu, ImH_mu, rho, nu, mu;
8133
8134
8135 H_rho = (1.0-useVF)*gf.H(eps_rho,phi) + useVF*fmin(1.0,fmax(0.0,vf));
8136 ImH_rho = (1.0-useVF)*gf.ImH(eps_rho,phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
8137 H_mu = (1.0-useVF)*gf.H(eps_mu,phi) + useVF*fmin(1.0,fmax(0.0,vf));
8138 ImH_mu = (1.0-useVF)*gf.ImH(eps_mu,phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
8139
8140 rho = rho_0*ImH_rho + rho_1*H_rho;
8141 nu = nu_0*ImH_mu + nu_1*H_mu;
8142
8143 mu = rho_0*nu_0*ImH_mu + rho_1*nu_1*H_mu + use_numerical_viscosity*numerical_viscosity;
8144 //mu = rho*nu;
8145
8146 mom_p_acc = p / mu;
8147 dmom_p_acc_p = 1. / mu;
8148
8149 mom_u_acc = u / mu;
8150 dmom_u_acc_u = 1. / mu;
8151
8152 mom_v_acc = v / mu;
8153 dmom_v_acc_v = 1. / mu;
8154
8155 mom_w_acc = w / mu;
8156 dmom_w_acc_w = 1. / mu;
8157 }
8158 inline
8159 void evaluateTPDensityMassCoefficients(const double eps_rho,
8160 const double rho_0,
8161 const double rho_1,
8162 const double useVF,
8163 const double& vf,
8164 const double& phi,
8165 const double& p,
8166 const double& u,
8167 const double& v,
8168 const double& w,
8169 double& mom_p_acc,
8170 double& dmom_p_acc_p,
8171 double& mom_u_acc,
8172 double& dmom_u_acc_u,
8173 double& mom_v_acc,
8174 double& dmom_v_acc_v,
8175 double& mom_w_acc,
8176 double& dmom_w_acc_w)
8177 {
8178 double H_rho, ImH_rho, rho;
8179
8180 H_rho = (1.0-useVF)*gf.H(eps_rho,phi) + useVF*fmin(1.0,fmax(0.0,vf));
8181 ImH_rho = (1.0-useVF)*gf.ImH(eps_rho,phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
8182
8183 rho = rho_0*ImH_rho + rho_1*H_rho;
8184
8185 mom_p_acc = p * rho;
8186 dmom_p_acc_p = rho;
8187
8188 mom_u_acc = u * rho;
8189 dmom_u_acc_u = rho;
8190
8191 mom_v_acc = v * rho;
8192 dmom_v_acc_v = rho;
8193
8194 mom_w_acc = w * rho;
8195 dmom_w_acc_w = rho;
8196 }
8197 inline
8199 const double rho_0,
8200 const double rho_1,
8201 const double useVF,
8202 const double& vf,
8203 const double& phi,
8204 double mom_p_diff_ten[nSpace],
8205 double mom_u_diff_ten[nSpace],
8206 double mom_v_diff_ten[nSpace],
8207 double mom_w_diff_ten[nSpace])
8208 {
8209 double H_rho, ImH_rho, rho;
8210
8211 H_rho = (1.0-useVF)*gf.H(eps_rho,phi) + useVF*fmin(1.0,fmax(0.0,vf));
8212 ImH_rho = (1.0-useVF)*gf.ImH(eps_rho,phi) + useVF*(1.0-fmin(1.0,fmax(0.0,vf)));
8213
8214 rho = rho_0*ImH_rho + rho_1*H_rho;
8215
8216 mom_p_diff_ten[0] = 1.0 / rho ;
8217 mom_p_diff_ten[1] = 1.0 / rho ;
8218 mom_p_diff_ten[2] = 1.0 / rho ;
8219
8220 mom_u_diff_ten[0] = 1.0 / rho ;
8221 mom_u_diff_ten[1] = 1.0 / rho ;
8222 mom_u_diff_ten[2] = 1.0 / rho ;
8223
8224 mom_v_diff_ten[0] = 1.0 / rho ;
8225 mom_v_diff_ten[1] = 1.0 / rho ;
8226 mom_v_diff_ten[2] = 1.0 / rho ;
8227
8228 mom_w_diff_ten[0] = 1.0 / rho ;
8229 mom_w_diff_ten[1] = 1.0 / rho ;
8230 mom_w_diff_ten[2] = 1.0 / rho ;
8231 }
8232
8234 {
8235 xt::pyarray<double>& mesh_trial_ref = args.array<double>("mesh_trial_ref");
8236 xt::pyarray<double>& mesh_grad_trial_ref = args.array<double>("mesh_grad_trial_ref");
8237 xt::pyarray<double>& mesh_dof = args.array<double>("mesh_dof");
8238 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
8239 xt::pyarray<double>& dV_ref = args.array<double>("dV_ref");
8240 xt::pyarray<double>& p_trial_ref = args.array<double>("p_trial_ref");
8241 xt::pyarray<double>& p_grad_trial_ref = args.array<double>("p_grad_trial_ref");
8242 xt::pyarray<double>& vel_trial_ref = args.array<double>("vel_trial_ref");
8243 xt::pyarray<double>& vel_grad_trial_ref = args.array<double>("vel_grad_trial_ref");
8244 xt::pyarray<double>& elementDiameter = args.array<double>("elementDiameter");
8245 xt::pyarray<double>& nodeDiametersArray = args.array<double>("nodeDiametersArray");
8246 int nElements_global = args.scalar<int>("nElements_global");
8247 double useMetrics = args.scalar<double>("useMetrics");
8248 double epsFact_rho = args.scalar<double>("epsFact_rho");
8249 double epsFact_mu = args.scalar<double>("epsFact_mu");
8250 double rho_0 = args.scalar<double>("rho_0");
8251 double nu_0 = args.scalar<double>("nu_0");
8252 double rho_1 = args.scalar<double>("rho_1");
8253 double nu_1 = args.scalar<double>("nu_1");
8254 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
8255 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
8256 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
8257 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
8258 const double useVF = args.scalar<double>("useVF");
8259 xt::pyarray<double> &vf = args.array<double>("&vf");
8260 xt::pyarray<double> &phi = args.array<double>("&phi");
8261 xt::pyarray<int>& csrRowIndeces_p_p = args.array<int>("csrRowIndeces_p_p");
8262 xt::pyarray<int>& csrColumnOffsets_p_p = args.array<int>("csrColumnOffsets_p_p");
8263 xt::pyarray<int>& csrRowIndeces_u_u = args.array<int>("csrRowIndeces_u_u");
8264 xt::pyarray<int>& csrColumnOffsets_u_u = args.array<int>("csrColumnOffsets_u_u");
8265 xt::pyarray<int>& csrRowIndeces_v_v = args.array<int>("csrRowIndeces_v_v");
8266 xt::pyarray<int>& csrColumnOffsets_v_v = args.array<int>("csrColumnOffsets_v_v");
8267 xt::pyarray<int>& csrRowIndeces_w_w = args.array<int>("csrRowIndeces_w_w");
8268 xt::pyarray<int>& csrColumnOffsets_w_w = args.array<int>("csrColumnOffsets_w_w");
8269 xt::pyarray<double>& advection_matrix = args.array<double>("advection_matrix");
8270 gf.useExact = false;
8271 for (int eN=0 ; eN < nElements_global ; ++eN)
8272 {
8273 // local matrix allocations
8274 double eps_rho;
8275
8276 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
8277 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
8278 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
8279 double local_matrix_w_w[nDOF_test_element][nDOF_trial_element];
8280
8281 // clear local matrix entries
8282 for (int i=0 ; i < nDOF_test_element ; ++i)
8283 for (int j=0 ; j < nDOF_trial_element ; ++j){
8284 local_matrix_p_p[i][j] = 0. ;
8285 local_matrix_u_u[i][j] = 0. ;
8286 local_matrix_v_v[i][j] = 0. ;
8287 }
8288
8289 for (int k=0 ; k < nQuadraturePoints_element ; ++k){
8290
8291 int eN_k = eN*nQuadraturePoints_element + k;
8292 int eN_nDOF_trial_element = eN*nDOF_trial_element;
8293
8294 double jac[nSpace*nSpace];
8295 double jacInv[nSpace*nSpace];
8296 double u=0.0, v=0.0, w=0.0;
8297 double dmass_adv_p[nSpace], dmom_u_adv_u[nSpace], dmom_v_adv_v[nSpace], dmom_w_adv_w[nSpace];
8298 double p_grad_trial[nDOF_trial_element*nSpace],
8299 vel_grad_trial[nDOF_trial_element*nSpace];
8300 double p_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element];
8301 double p_grad_test_dV[nDOF_test_element*nSpace],
8302 vel_grad_test_dV[nDOF_test_element*nSpace];
8303 double jacDet, x, y, z, dV, h_phi;
8304
8305 ck.calculateMapping_element(eN,
8306 k,
8307 mesh_dof.data(),
8308 mesh_l2g.data(),
8309 mesh_trial_ref.data(),
8310 mesh_grad_trial_ref.data(),
8311 jac,
8312 jacDet,
8313 jacInv,
8314 x,y,z);
8315
8316 ck.calculateH_element(eN,
8317 k,
8318 nodeDiametersArray.data(),
8319 mesh_l2g.data(),
8320 mesh_trial_ref.data(),
8321 h_phi);
8322
8323 dV = fabs(jacDet)*dV_ref.data()[k];
8324
8325 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
8326
8327 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
8328 ck.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,vel_grad_trial);
8329
8330 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],u);
8331 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],v);
8332 ck.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],w);
8333
8334 for (int j=0; j<nDOF_trial_element;++j)
8335 {
8336 p_test_dV[j] = p_trial_ref.data()[k*nDOF_trial_element+j]*dV;
8337 vel_test_dV[j] = vel_trial_ref.data()[k*nDOF_trial_element+j]*dV;
8338 for (int i=0; i<nSpace; ++i)
8339 {
8340 p_grad_test_dV[j*nSpace+i] = p_grad_trial[j*nSpace+i]*dV;
8341 vel_grad_test_dV[j*nSpace+i] = vel_grad_trial[j*nSpace+i]*dV;
8342 }
8343 }
8344
8345
8347 rho_0,
8348 rho_1,
8349 useVF,
8350 vf.data()[eN_k],
8351 phi.data()[eN_k],
8352 u,
8353 v,
8354 w,
8355 dmass_adv_p,
8356 dmom_u_adv_u,
8357 dmom_v_adv_v,
8358 dmom_w_adv_w);
8359
8360
8361 for(int i=0; i<nDOF_test_element;++i){
8362 int i_nSpace = i*nSpace;
8363
8364 for(int j=0; j<nDOF_trial_element;++j){
8365
8366 int j_nSpace = j*nSpace;
8367
8368 local_matrix_p_p[i][j] -= ck.HamiltonianJacobian_weak(dmass_adv_p,&p_grad_test_dV[i_nSpace],p_trial_ref.data()[j]);
8369 //local_matrix_p_p[i][j] += ck.HamiltonianJacobian_weak(dmass_adv_p ,&p_grad_trial[j_nSpace] ,p_test_dV[i]);
8370 local_matrix_u_u[i][j] += ck.HamiltonianJacobian_weak(dmom_u_adv_u,&vel_grad_trial[j_nSpace],vel_test_dV[i]);
8371 local_matrix_v_v[i][j] += ck.HamiltonianJacobian_weak(dmom_v_adv_v,&vel_grad_trial[j_nSpace],vel_test_dV[i]);
8372 local_matrix_w_w[i][j] += ck.HamiltonianJacobian_weak(dmom_w_adv_w,&vel_grad_trial[j_nSpace],vel_test_dV[i]);
8373 }
8374 }
8375
8376
8377 }//k
8378
8379 // Write local matrix information into global system
8380 for (int i=0 ; i < nDOF_test_element ; ++i)
8381 {
8382 int eN_i = eN*nDOF_test_element + i;
8383 for (int j=0 ; j < nDOF_trial_element ; ++j)
8384 {
8385 int eN_i_j = eN_i*nDOF_trial_element + j;
8386 advection_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
8387 advection_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
8388 advection_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
8389 advection_matrix.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_w_w.data()[eN_i_j]] += local_matrix_w_w[i][j] ;
8390 }
8391 }
8392
8393 }//eN
8394 } // getTwoPhaseAdvectionOperator
8395
8397 {
8398 xt::pyarray<double>& mesh_trial_ref = args.array<double>("mesh_trial_ref");
8399 xt::pyarray<double>& mesh_grad_trial_ref = args.array<double>("mesh_grad_trial_ref");
8400 xt::pyarray<double>& mesh_dof = args.array<double>("mesh_dof");
8401 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
8402 xt::pyarray<double>& dV_ref = args.array<double>("dV_ref");
8403 xt::pyarray<double>& p_grad_trial_ref = args.array<double>("p_grad_trial_ref");
8404 xt::pyarray<double>& vel_grad_trial_ref = args.array<double>("vel_grad_trial_ref");
8405 xt::pyarray<double>& elementDiameter = args.array<double>("elementDiameter");
8406 xt::pyarray<double>& nodeDiametersArray = args.array<double>("nodeDiametersArray");
8407 int nElements_global = args.scalar<int>("nElements_global");
8408 double useMetrics = args.scalar<double>("useMetrics");
8409 double epsFact_rho = args.scalar<double>("epsFact_rho");
8410 double epsFact_mu = args.scalar<double>("epsFact_mu");
8411 double rho_0 = args.scalar<double>("rho_0");
8412 double nu_0 = args.scalar<double>("nu_0");
8413 double rho_1 = args.scalar<double>("rho_1");
8414 double nu_1 = args.scalar<double>("nu_1");
8415 xt::pyarray<int>& p_l2g = args.array<int>("p_l2g");
8416 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
8417 xt::pyarray<double>& p_dof = args.array<double>("p_dof");
8418 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
8419 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
8420 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
8421 const double useVF = args.scalar<double>("useVF");
8422 xt::pyarray<double>& vf = args.array<double>("vf");
8423 xt::pyarray<double>& phi = args.array<double>("phi");
8424 xt::pyarray<int>& sdInfo_p_p_rowptr = args.array<int>("sdInfo_p_p_rowptr");
8425 xt::pyarray<int>& sdInfo_p_p_colind = args.array<int>("sdInfo_p_p_colind");
8426 xt::pyarray<int>& sdInfo_u_u_rowptr = args.array<int>("sdInfo_u_u_rowptr");
8427 xt::pyarray<int>& sdInfo_u_u_colind = args.array<int>("sdInfo_u_u_colind");
8428 xt::pyarray<int>& sdInfo_v_v_rowptr = args.array<int>("sdInfo_v_v_rowptr");
8429 xt::pyarray<int>& sdInfo_v_v_colind = args.array<int>("sdInfo_v_v_colind");
8430 xt::pyarray<int>& sdInfo_w_w_rowptr = args.array<int>("sdInfo_w_w_rowptr");
8431 xt::pyarray<int>& sdInfo_w_w_colind = args.array<int>("sdInfo_w_w_colind");
8432 xt::pyarray<int>& csrRowIndeces_p_p = args.array<int>("csrRowIndeces_p_p");
8433 xt::pyarray<int>& csrColumnOffsets_p_p = args.array<int>("csrColumnOffsets_p_p");
8434 xt::pyarray<int>& csrRowIndeces_u_u = args.array<int>("csrRowIndeces_u_u");
8435 xt::pyarray<int>& csrColumnOffsets_u_u = args.array<int>("csrColumnOffsets_u_u");
8436 xt::pyarray<int>& csrRowIndeces_v_v = args.array<int>("csrRowIndeces_v_v");
8437 xt::pyarray<int>& csrColumnOffsets_v_v = args.array<int>("csrColumnOffsets_v_v");
8438 xt::pyarray<int>& csrRowIndeces_w_w = args.array<int>("csrRowIndeces_w_w");
8439 xt::pyarray<int>& csrColumnOffsets_w_w = args.array<int>("csrColumnOffsets_w_w");
8440 xt::pyarray<double>& laplace_matrix = args.array<double>("laplace_matrix");
8441 gf.useExact = false;
8442 for (int eN=0 ; eN < nElements_global ; ++eN)
8443 {
8444 // local matrix allocations
8445 double eps_rho, eps_mu;
8446
8447 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
8448 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
8449 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
8450 double local_matrix_w_w[nDOF_test_element][nDOF_trial_element];
8451
8452 // reset local matrix entries
8453 for (int i=0 ; i < nDOF_test_element ; ++i)
8454 for (int j=0 ; j < nDOF_trial_element ; ++j){
8455 // set local matrices to 0
8456 local_matrix_p_p[i][j] = 0.;
8457 local_matrix_u_u[i][j] = 0.;
8458 local_matrix_v_v[i][j] = 0.;
8459 local_matrix_w_w[i][j] = 0.;
8460 }
8461
8462 // Loop over quadrature points on element
8463 for (int k=0 ; k < nQuadraturePoints_element; ++k){
8464
8465 int eN_k = eN*nQuadraturePoints_element + k;
8466 int eN_nDOF_trial_element = eN*nDOF_trial_element;
8467
8468 double grad_p[nSpace], grad_u[nSpace], grad_v[nSpace], grad_w[nSpace];
8469 double jac[nSpace*nSpace];
8470 double jacInv[nSpace*nSpace];
8471 double mom_pp_diff_ten[nSpace];
8472 double mom_uu_diff_ten[nSpace];
8473 double mom_vv_diff_ten[nSpace];
8474 double mom_ww_diff_ten[nSpace];
8475 double p_grad_trial[nDOF_trial_element*nSpace],
8476 vel_grad_trial[nDOF_trial_element*nSpace];
8477 double p_grad_test_dV[nDOF_test_element*nSpace],
8478 vel_grad_test_dV[nDOF_test_element*nSpace];
8479 double jacDet, x, y, z, dV, h_phi;
8480
8481 ck.calculateMapping_element(eN,
8482 k,
8483 mesh_dof.data(),
8484 mesh_l2g.data(),
8485 mesh_trial_ref.data(),
8486 mesh_grad_trial_ref.data(),
8487 jac,
8488 jacDet,
8489 jacInv,
8490 x,y,z);
8491
8492 ck.calculateH_element(eN,
8493 k,
8494 nodeDiametersArray.data(),
8495 mesh_l2g.data(),
8496 mesh_trial_ref.data(),
8497 h_phi);
8498
8499 dV = fabs(jacDet)*dV_ref.data()[k];
8500
8501 eps_mu = epsFact_mu * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
8502 eps_rho = epsFact_rho * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
8503
8504 ck.gradTrialFromRef(&p_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,p_grad_trial);
8505 ck.gradTrialFromRef(&vel_grad_trial_ref.data()[k*nDOF_trial_element*nSpace],jacInv,vel_grad_trial);
8506
8507 ck.gradFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],p_grad_trial,grad_p);
8508 ck.gradFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],vel_grad_trial,grad_u);
8509 ck.gradFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],vel_grad_trial,grad_v);
8510 ck.gradFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],vel_grad_trial,grad_w);
8511
8512 for (int j=0; j<nDOF_trial_element;++j)
8513 for (int i=0; i<nSpace; ++i)
8514 {
8515 p_grad_test_dV[j*nSpace+i] = p_grad_trial[j*nSpace+i]*dV;
8516 vel_grad_test_dV[j*nSpace+i] = vel_grad_trial[j*nSpace+i]*dV;
8517 }
8518
8520 rho_0,
8521 rho_1,
8522 useVF,
8523 vf.data()[eN_k],
8524 phi.data()[eN_k],
8525 mom_pp_diff_ten,
8526 mom_uu_diff_ten,
8527 mom_vv_diff_ten,
8528 mom_ww_diff_ten);
8529
8530 // loop over test and weighted trial functions to evaluate local inner products
8531 for (int i=0 ; i < nDOF_test_element ; ++i)
8532 {
8533 int i_nSpace = i*nSpace ;
8534 for (int j=0; j < nDOF_trial_element ; ++j){
8535 int j_nSpace = j*nSpace ;
8536 /* local_matrix_p_p[i][j] += ck.SimpleDiffusionJacobian_weak(sdInfo_p_p_rowptr.data(), */
8537 /* sdInfo_p_p_colind.data(), */
8538 /* mom_pp_diff_ten, */
8539 /* &p_grad_trial[j_nSpace], */
8540 /* &p_grad_test_dV[i_nSpace]); */
8541
8542 /* local_matrix_u_u[i][j] += ck.SimpleDiffusionJacobian_weak(sdInfo_u_u_rowptr.data(), */
8543 /* sdInfo_u_u_colind.data(), */
8544 /* mom_uu_diff_ten, */
8545 /* &vel_grad_trial[j_nSpace], */
8546 /* &vel_grad_test_dV[i_nSpace]); */
8547
8548 /* local_matrix_v_v[i][j] += ck.SimpleDiffusionJacobian_weak(sdInfo_v_v_rowptr.data(), */
8549 /* sdInfo_v_v_colind.data(), */
8550 /* mom_vv_diff_ten, */
8551 /* &vel_grad_trial[j_nSpace], */
8552 /* &vel_grad_test_dV[i_nSpace]); */
8553 local_matrix_p_p[i][j] += ck.NumericalDiffusionJacobian(mom_pp_diff_ten[0],
8554 &p_grad_trial[j_nSpace],
8555 &p_grad_test_dV[i_nSpace]);
8556
8557 local_matrix_u_u[i][j] += ck.NumericalDiffusionJacobian(mom_uu_diff_ten[0],
8558 &vel_grad_trial[j_nSpace],
8559 &vel_grad_test_dV[i_nSpace]);
8560
8561 local_matrix_v_v[i][j] += ck.NumericalDiffusionJacobian(mom_vv_diff_ten[0],
8562 &vel_grad_trial[j_nSpace],
8563 &vel_grad_test_dV[i_nSpace]);
8564
8565 local_matrix_w_w[i][j] += ck.NumericalDiffusionJacobian(mom_ww_diff_ten[0],
8566 &vel_grad_trial[j_nSpace],
8567 &vel_grad_test_dV[i_nSpace]);
8568
8569 } // j
8570 } // i
8571
8572 } // k
8573
8574 // Write local matrix information into global system
8575 for (int i=0 ; i < nDOF_test_element ; ++i)
8576 {
8577 int eN_i = eN*nDOF_test_element + i;
8578 for (int j=0 ; j < nDOF_trial_element ; ++j)
8579 {
8580 int eN_i_j = eN_i*nDOF_trial_element + j;
8581 laplace_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
8582 laplace_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
8583 laplace_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
8584 laplace_matrix.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_w_w.data()[eN_i_j]] += local_matrix_w_w[i][j] ;
8585 }
8586 }
8587
8588 } // eN
8589 }
8590
8592 {
8593 int scale_type = args.scalar<int>("scale_type");
8594 int use_numerical_viscosity = args.scalar<int>("use_numerical_viscosity");
8595 int lumped = args.scalar<int>("lumped");
8596 xt::pyarray<double> &mesh_trial_ref = args.array<double>("&mesh_trial_ref");
8597 xt::pyarray<double> &mesh_grad_trial_ref = args.array<double>("&mesh_grad_trial_ref");
8598 xt::pyarray<double> &mesh_dof = args.array<double>("&mesh_dof");
8599 xt::pyarray<int>& mesh_l2g = args.array<int>("mesh_l2g");
8600 xt::pyarray<double>& dV_ref = args.array<double>("dV_ref");
8601 xt::pyarray<double>& p_trial_ref = args.array<double>("p_trial_ref");
8602 xt::pyarray<double>& p_test_ref = args.array<double>("p_test_ref");
8603 xt::pyarray<double>& vel_trial_ref = args.array<double>("vel_trial_ref");
8604 xt::pyarray<double>& vel_test_ref = args.array<double>("vel_test_ref");
8605 xt::pyarray<double>& elementDiameter = args.array<double>("elementDiameter");
8606 xt::pyarray<double>& nodeDiametersArray = args.array<double>("nodeDiametersArray");
8607 xt::pyarray<double>& numerical_viscosity = args.array<double>("numerical_viscosity");
8608 int nElements_global = args.scalar<int>("nElements_global");
8609 double useMetrics = args.scalar<double>("useMetrics");
8610 double epsFact_rho = args.scalar<double>("epsFact_rho");
8611 double epsFact_mu = args.scalar<double>("epsFact_mu");
8612 double rho_0 = args.scalar<double>("rho_0");
8613 double nu_0 = args.scalar<double>("nu_0");
8614 double rho_1 = args.scalar<double>("rho_1");
8615 double nu_1 = args.scalar<double>("nu_1");
8616 xt::pyarray<int>& p_l2g = args.array<int>("p_l2g");
8617 xt::pyarray<int>& vel_l2g = args.array<int>("vel_l2g");
8618 xt::pyarray<double>& p_dof = args.array<double>("p_dof");
8619 xt::pyarray<double>& u_dof = args.array<double>("u_dof");
8620 xt::pyarray<double>& v_dof = args.array<double>("v_dof");
8621 xt::pyarray<double>& w_dof = args.array<double>("w_dof");
8622 const double useVF = args.scalar<double>("useVF");
8623 xt::pyarray<double>& vf = args.array<double>("vf");
8624 xt::pyarray<double>& phi = args.array<double>("phi");
8625 xt::pyarray<int>& csrRowIndeces_p_p = args.array<int>("csrRowIndeces_p_p");
8626 xt::pyarray<int>& csrColumnOffsets_p_p = args.array<int>("csrColumnOffsets_p_p");
8627 xt::pyarray<int>& csrRowIndeces_u_u = args.array<int>("csrRowIndeces_u_u");
8628 xt::pyarray<int>& csrColumnOffsets_u_u = args.array<int>("csrColumnOffsets_u_u");
8629 xt::pyarray<int>& csrRowIndeces_v_v = args.array<int>("csrRowIndeces_v_v");
8630 xt::pyarray<int>& csrColumnOffsets_v_v = args.array<int>("csrColumnOffsets_v_v");
8631 xt::pyarray<int>& csrRowIndeces_w_w = args.array<int>("csrRowIndeces_w_w");
8632 xt::pyarray<int>& csrColumnOffsets_w_w = args.array<int>("csrColumnOffsets_w_w");
8633 xt::pyarray<double>& mass_matrix = args.array<double>("mass_matrix");
8634 // Step 1.1 - Initialize local matrix
8635
8636 for (int eN=0 ; eN < nElements_global; ++eN){
8637
8638 double local_matrix_p_p[nDOF_test_element][nDOF_trial_element];
8639 double local_matrix_u_u[nDOF_test_element][nDOF_trial_element];
8640 double local_matrix_v_v[nDOF_test_element][nDOF_trial_element];
8641 double local_matrix_w_w[nDOF_test_element][nDOF_trial_element];
8642 double eps_rho, eps_mu;
8643
8644 // reset local matrix entries
8645 for (int i=0; i<nDOF_test_element; ++i)
8646 for (int j=0; j<nDOF_trial_element; ++j){
8647 local_matrix_p_p[i][j] = 0.0 ;
8648 local_matrix_u_u[i][j] = 0.0 ;
8649 local_matrix_v_v[i][j] = 0.0 ;
8650 local_matrix_w_w[i][j] = 0.0 ;
8651 }
8652 // Step 1.2 - Loop over quadrature points on element
8653 for (int k=0 ; k < nQuadraturePoints_element; ++k){
8654
8655 int eN_k = eN*nQuadraturePoints_element+k;
8656 int eN_nDOF_trial_element = eN*nDOF_trial_element;
8657 // *** Local storage arrays ***
8658 double p = 0.0, u = 0.0, v= 0.0 , w= 0.0 ;
8659 double dV;
8660 double mom_p_acc = 0.0, dmom_p_acc_p = 0.0;
8661 double mom_u_acc = 0.0, dmom_u_acc_u = 0.0;
8662 double mom_v_acc = 0.0, dmom_v_acc_v = 0.0;
8663 double mom_w_acc = 0.0, dmom_w_acc_w = 0.0;
8664 double jac[nSpace*nSpace] ;
8665 double jacInv[nSpace*nSpace] ;
8666 double jacDet,x,y,z ;
8667 double p_test_dV[nDOF_test_element], vel_test_dV[nDOF_test_element];
8668 double h_phi;
8669
8670 // Step 1.2.1 Calculate integration weights
8671
8672 ck.calculateMapping_element(eN,
8673 k,
8674 mesh_dof.data(),
8675 mesh_l2g.data(),
8676 mesh_trial_ref.data(),
8677 mesh_grad_trial_ref.data(),
8678 jac,
8679 jacDet,
8680 jacInv,
8681 x,y,z);
8682
8683 ck.calculateH_element(eN,
8684 k,
8685 nodeDiametersArray.data(),
8686 mesh_l2g.data(),
8687 mesh_trial_ref.data(),
8688 h_phi);
8689
8690 dV = fabs(jacDet)*dV_ref.data()[k];
8691
8692 ck.valFromDOF(p_dof.data(),&p_l2g.data()[eN_nDOF_trial_element],&p_trial_ref.data()[k*nDOF_trial_element],p);
8693 ck.valFromDOF(u_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],u);
8694 ck.valFromDOF(v_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],v);
8695 ck.valFromDOF(w_dof.data(),&vel_l2g.data()[eN_nDOF_trial_element],&vel_trial_ref.data()[k*nDOF_trial_element],w);
8696
8697 eps_rho = epsFact_rho*(useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
8698 eps_mu = epsFact_mu * (useMetrics*h_phi+(1.0-useMetrics)*elementDiameter.data()[eN]);
8699 // Step 1.2.2 Scale test functions with integration weights.
8700 for (int j=0 ; j<nDOF_trial_element ; ++j){
8701 p_test_dV[j] = p_test_ref.data()[k*nDOF_trial_element + j]*dV;
8702 vel_test_dV[j] = vel_test_ref.data()[k*nDOF_trial_element + j] * dV;
8703 }
8704
8705 // Step 1.2.2 Evaluate coefficients
8706 if (scale_type==0){
8707 evaluateTPInvViscosityMassCoefficients(use_numerical_viscosity,
8708 numerical_viscosity.data()[eN_k],
8709 eps_rho,
8710 eps_mu,
8711 rho_0,
8712 nu_0,
8713 rho_1,
8714 nu_1,
8715 useVF,
8716 vf.data()[eN_k],
8717 phi.data()[eN_k],
8718 p,
8719 u,
8720 v,
8721 w,
8722 mom_p_acc,
8723 dmom_p_acc_p,
8724 mom_u_acc,
8725 dmom_u_acc_u,
8726 mom_v_acc,
8727 dmom_v_acc_v,
8728 mom_w_acc,
8729 dmom_w_acc_w) ; }
8730 else if(scale_type==1){
8732 rho_0,
8733 rho_1,
8734 useVF,
8735 vf.data()[eN_k],
8736 phi.data()[eN_k],
8737 p,
8738 u,
8739 v,
8740 w,
8741 mom_p_acc,
8742 dmom_p_acc_p,
8743 mom_u_acc,
8744 dmom_u_acc_u,
8745 mom_v_acc,
8746 dmom_v_acc_v,
8747 mom_w_acc,
8748 dmom_w_acc_w) ;
8749 }
8750
8751 // Step 1.2.3 Loop over test and weighted trial functions
8752 // to evaluate local inner product contrubtions
8753 for (int i=0 ; i < nDOF_test_element; ++i)
8754 {
8755 int i_nSpace = i*nSpace;
8756 for (int j=0 ; j < nDOF_trial_element; ++j)
8757 {
8758 int j_nSpace = j*nSpace;
8759 local_matrix_p_p[i][j] += ck.MassJacobian_weak(dmom_p_acc_p,
8760 p_trial_ref.data()[k*nDOF_trial_element+j],
8761 p_test_dV[i]) ;
8762 local_matrix_u_u[i][j] += ck.MassJacobian_weak(dmom_u_acc_u,
8763 vel_trial_ref.data()[k*nDOF_trial_element+j],
8764 vel_test_dV[i]) ;
8765 local_matrix_v_v[i][j] += ck.MassJacobian_weak(dmom_v_acc_v,
8766 vel_trial_ref.data()[k*nDOF_trial_element+j],
8767 vel_test_dV[i]) ;
8768 local_matrix_w_w[i][j] += ck.MassJacobian_weak(dmom_w_acc_w,
8769 vel_trial_ref.data()[k*nDOF_trial_element+j],
8770 vel_test_dV[i]) ;
8771 }//j
8772 }//i
8773
8774
8775 } // k
8776
8777 // Step 1.3 - Write local matrix information into global system
8778 for (int i=0 ; i<nDOF_test_element; ++i)
8779 {
8780 int eN_i = eN*nDOF_test_element+i;
8781 int eN_i_i = eN_i*nDOF_trial_element + i;
8782 for (int j=0 ; j < nDOF_trial_element; ++j)
8783 {
8784 int eN_i_j = eN_i*nDOF_trial_element + j;
8785 if (lumped)
8786 {
8787 mass_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_i]] += local_matrix_p_p[i][j] ;
8788 mass_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_i]] += local_matrix_u_u[i][j] ;
8789 mass_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_i]] += local_matrix_v_v[i][j] ;
8790 mass_matrix.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_w_w.data()[eN_i_i]] += local_matrix_w_w[i][j] ;
8791 }
8792 else
8793 {
8794 mass_matrix.data()[csrRowIndeces_p_p.data()[eN_i] + csrColumnOffsets_p_p.data()[eN_i_j]] += local_matrix_p_p[i][j] ;
8795 mass_matrix.data()[csrRowIndeces_u_u.data()[eN_i] + csrColumnOffsets_u_u.data()[eN_i_j]] += local_matrix_u_u[i][j] ;
8796 mass_matrix.data()[csrRowIndeces_v_v.data()[eN_i] + csrColumnOffsets_v_v.data()[eN_i_j]] += local_matrix_v_v[i][j] ;
8797 mass_matrix.data()[csrRowIndeces_w_w.data()[eN_i] + csrColumnOffsets_w_w.data()[eN_i_j]] += local_matrix_w_w[i][j] ;
8798 }
8799 }
8800 }
8801 } // eN
8802 }
8803 };//RANS2P
8804
8805 inline RANS2P_base* newRANS2P(int nSpaceIn,
8806 int nQuadraturePoints_elementIn,
8807 int nDOF_mesh_trial_elementIn,
8808 int nDOF_trial_elementIn,
8809 int nDOF_test_elementIn,
8810 int nDOF_v_trial_elementIn,
8811 int nDOF_v_test_elementIn,
8812 int nQuadraturePoints_elementBoundaryIn,
8813 int CompKernelFlag)
8814 {
8816 nQuadraturePoints_elementIn,
8817 nDOF_mesh_trial_elementIn,
8818 nDOF_trial_elementIn,
8819 nDOF_test_elementIn,
8820 nDOF_v_trial_elementIn,
8821 nDOF_v_test_elementIn,
8822 nQuadraturePoints_elementBoundaryIn,
8823 CompKernelFlag);
8824 }
8825}//proteus
8826
8827#endif
double nu_0
double rho_1
double nu_1
double rho_0
Int n
Definition Headers.h:28
Double L
Definition Headers.h:72
Double r
Definition Headers.h:83
Double cs
Definition Headers.h:58
Double H
Definition Headers.h:65
Double u
Definition Headers.h:89
Double vy
Definition Headers.h:98
Double * z
Definition Headers.h:49
Double Q
Definition Headers.h:80
Double v
Definition Headers.h:95
Double pe
Definition Headers.h:75
Double vx
Definition Headers.h:97
const double DM3
Definition RANS2P.h:25
const double inertial_term
Definition RANS2P.h:26
const double DM
Definition RANS2P.h:23
const bool UPWIND_DIRICHLET
Definition RANS2P.h:21
#define ZEROVEC
Definition RANS2P.h:20
const double DM2
Definition RANS2P.h:24
int calculate(const double *phi_dof, const double *phi_nodes, const double *xi_r, double ma, double mb, double jf, bool isBoundary, bool scale)
virtual void getTwoPhaseScaledMassOperator(arguments_dict &args)=0
virtual void calculateJacobian(arguments_dict &args)=0
virtual void getTwoPhaseAdvectionOperator(arguments_dict &args)=0
virtual void getTwoPhaseInvScaledLaplaceOperator(arguments_dict &args)=0
virtual void calculateResidual(arguments_dict &args)=0
virtual void calculateVelocityAverage(arguments_dict &args)=0
virtual ~RANS2P_base()
Definition RANS2P.h:133
void step6DOF(arguments_dict &args)
Definition RANS2P.h:140
std::map< int, int > cutfem_local_boundaries
Definition RANS2P.h:320
void getTwoPhaseAdvectionOperator(arguments_dict &args)
Definition RANS2P.h:8233
void exteriorNumericalAdvectiveFluxDerivatives(const double NONCONSERVATIVE_FORM, const int &isDOFBoundary_p, const int &isDOFBoundary_u, const int &isDOFBoundary_v, const int &isDOFBoundary_w, const int &isFluxBoundary_p, const int &isFluxBoundary_u, const int &isFluxBoundary_v, const int &isFluxBoundary_w, const double &oneByRho, const double n[nSpace], const double &bc_p, const double &bc_u, const double &bc_v, const double &bc_w, const double bc_f_mass[nSpace], const double bc_f_umom[nSpace], const double bc_f_vmom[nSpace], const double bc_f_wmom[nSpace], const double &bc_flux_mass, const double &bc_flux_umom, const double &bc_flux_vmom, const double &bc_flux_wmom, const double &p, const double &u, const double &v, const double &w, const double &dmom_u_acc_u, const double f_mass[nSpace], const double f_umom[nSpace], const double f_vmom[nSpace], const double f_wmom[nSpace], const double df_mass_du[nSpace], const double df_mass_dv[nSpace], const double df_mass_dw[nSpace], const double df_umom_dp[nSpace], const double dham_grad[nSpace], const double df_umom_du[nSpace], const double df_umom_dv[nSpace], const double df_umom_dw[nSpace], const double df_vmom_dp[nSpace], const double df_vmom_du[nSpace], const double df_vmom_dv[nSpace], const double df_vmom_dw[nSpace], const double df_wmom_dp[nSpace], const double df_wmom_du[nSpace], const double df_wmom_dv[nSpace], const double df_wmom_dw[nSpace], double &dflux_mass_du, double &dflux_mass_dv, double &dflux_mass_dw, double &dflux_umom_dp, double &dflux_umom_du, double &dflux_umom_dv, double &dflux_umom_dw, double &dflux_vmom_dp, double &dflux_vmom_du, double &dflux_vmom_dv, double &dflux_vmom_dw, double &dflux_wmom_dp, double &dflux_wmom_du, double &dflux_wmom_dv, double &dflux_wmom_dw)
Definition RANS2P.h:1760
GeneralizedFunctions< nSpace, 3, nQuadraturePoints_element, nQuadraturePoints_elementBoundary > gf
Definition RANS2P.h:328
void calculateResidual(arguments_dict &args)
Definition RANS2P.h:2160
void calculateVelocityAverage(arguments_dict &args)
Definition RANS2P.h:7898
void evaluateTPInvDensityLaplaceCoefficients(const double eps_rho, const double rho_0, const double rho_1, const double useVF, const double &vf, const double &phi, double mom_p_diff_ten[nSpace], double mom_u_diff_ten[nSpace], double mom_v_diff_ten[nSpace], double mom_w_diff_ten[nSpace])
Definition RANS2P.h:8198
GeneralizedFunctions< nSpace, 3, nQuadraturePoints_element, nQuadraturePoints_elementBoundary > gf_p
Definition RANS2P.h:329
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)
Definition RANS2P.h:789
void calculateJacobian(arguments_dict &args)
Definition RANS2P.h:5089
void calculateSubgridErrorDerivatives_tauRes(const double &tau_p, const double &tau_v, const double dpdeResidualP_du[nDOF_v_trial_element], const double dpdeResidualP_dv[nDOF_v_trial_element], const double dpdeResidualP_dw[nDOF_v_trial_element], const double dpdeResidualU_dp[nDOF_trial_element], const double dpdeResidualU_du[nDOF_v_trial_element], const double dpdeResidualV_dp[nDOF_trial_element], const double dpdeResidualV_dv[nDOF_v_trial_element], const double dpdeResidualW_dp[nDOF_trial_element], const double dpdeResidualW_dw[nDOF_v_trial_element], double dsubgridErrorP_du[nDOF_v_trial_element], double dsubgridErrorP_dv[nDOF_v_trial_element], double dsubgridErrorP_dw[nDOF_v_trial_element], double dsubgridErrorU_dp[nDOF_trial_element], double dsubgridErrorU_du[nDOF_v_trial_element], double dsubgridErrorV_dp[nDOF_trial_element], double dsubgridErrorV_dv[nDOF_v_trial_element], double dsubgridErrorW_dp[nDOF_trial_element], double dsubgridErrorW_dw[nDOF_v_trial_element])
Definition RANS2P.h:1483
void evaluateCoefficients(const double NONCONSERVATIVE_FORM, const double sigma, const double rho, double nu, const double h_e, const double smagorinskyConstant, const int turbulenceClosureModel, const double g[nSpace], const double useVF, const double &vf, const double &phi, const double n[nSpace], const double &kappa, const double porosity, const double phi_solid, const double p_old, const double u_old, const double v_old, const double w_old, const double grad_p_old[nSpace], const double grad_u_old[nSpace], const double grad_v_old[nSpace], const double grad_w_old[nSpace], const double &p, const double grad_p[nSpace], const double grad_u[nSpace], const double grad_v[nSpace], const double grad_w[nSpace], const double &u, const double &v, const double &w, const double LAG_LES, double &eddy_viscosity, double &eddy_viscosity_last, double &mom_u_acc, double &dmom_u_acc_u, double &mom_v_acc, double &dmom_v_acc_v, double &mom_w_acc, double &dmom_w_acc_w, double mass_adv[nSpace], double dmass_adv_u[nSpace], double dmass_adv_v[nSpace], double dmass_adv_w[nSpace], double mom_u_adv[nSpace], double dmom_u_adv_u[nSpace], double dmom_u_adv_v[nSpace], double dmom_u_adv_w[nSpace], double mom_v_adv[nSpace], double dmom_v_adv_u[nSpace], double dmom_v_adv_v[nSpace], double dmom_v_adv_w[nSpace], double mom_w_adv[nSpace], double dmom_w_adv_u[nSpace], double dmom_w_adv_v[nSpace], double dmom_w_adv_w[nSpace], double mom_uu_diff_ten[nSpace], double mom_vv_diff_ten[nSpace], double mom_ww_diff_ten[nSpace], double mom_uv_diff_ten[1], double mom_uw_diff_ten[1], double mom_vu_diff_ten[1], double mom_vw_diff_ten[1], double mom_wu_diff_ten[1], double mom_wv_diff_ten[1], double &mom_u_source, double &mom_v_source, double &mom_w_source, double &mom_u_ham, double dmom_u_ham_grad_p[nSpace], double dmom_u_ham_grad_u[nSpace], double &dmom_u_ham_u, double &dmom_u_ham_v, double &dmom_u_ham_w, double &mom_v_ham, double dmom_v_ham_grad_p[nSpace], double dmom_v_ham_grad_v[nSpace], double &dmom_v_ham_u, double &dmom_v_ham_v, double &dmom_v_ham_w, double &mom_w_ham, double dmom_w_ham_grad_p[nSpace], double dmom_w_ham_grad_w[nSpace], double &dmom_w_ham_u, double &dmom_w_ham_v, double &dmom_w_ham_w, double forcex, double forcey, double forcez)
Definition RANS2P.h:341
void get_distance_to_ith_ball(int n_balls, const double *ball_center, const double *ball_radius, int I, const double x, const double y, const double z, double &distance)
Definition RANS2P.h:809
const int nDOF_v_test_X_v_trial_element
Definition RANS2P.h:325
const int nDOF_test_X_v_trial_element
Definition RANS2P.h:323
void evaluateTPDensityMassCoefficients(const double eps_rho, const double rho_0, const double rho_1, const double useVF, const double &vf, const double &phi, const double &p, const double &u, const double &v, const double &w, double &mom_p_acc, double &dmom_p_acc_p, double &mom_u_acc, double &dmom_u_acc_u, double &mom_v_acc, double &dmom_v_acc_v, double &mom_w_acc, double &dmom_w_acc_w)
Definition RANS2P.h:8159
const int nDOF_v_test_X_trial_element
Definition RANS2P.h:324
CompKernelType_v ck_v
Definition RANS2P.h:327
const int nDOF_test_X_trial_element
Definition RANS2P.h:322
std::set< int > ifem_boundaries
Definition RANS2P.h:318
void evaluateTPInvViscosityMassCoefficients(const int use_numerical_viscosity, const double numerical_viscosity, const double eps_rho, const double eps_mu, const double rho_0, double nu_0, const double rho_1, double nu_1, const double useVF, const double &vf, const double &phi, const double &p, const double &u, const double &v, const double &w, double &mom_p_acc, double &dmom_p_acc_p, double &mom_u_acc, double &dmom_u_acc_u, double &mom_v_acc, double &dmom_v_acc_v, double &mom_w_acc, double &dmom_w_acc_w)
Definition RANS2P.h:8107
void get_normal_to_ith_ball(int n_balls, const double *ball_center, const double *ball_radius, int I, const double x, const double y, const double z, double &nx, double &ny, double &nz)
Definition RANS2P.h:819
std::set< int > cutfem_boundaries
Definition RANS2P.h:319
void get_velocity_to_ith_ball(int n_balls, const double *ball_center, const double *ball_radius, const double *ball_velocity, const double *ball_angular_velocity, int I, const double x, const double y, const double z, double &vx, double &vy, double &vz)
Definition RANS2P.h:848
void updateSolidParticleTerms(int particle_index, const double NONCONSERVATIVE_FORM, bool element_owned, const double particle_nitsche, const double dV, const int nParticles, const int sd_offset, double *particle_signed_distances, double *particle_signed_distance_normals, double *particle_velocities, double *particle_centroids, const int use_ball_as_particle, const double *ball_center, const double *ball_radius, const double *ball_velocity, const double *ball_angular_velocity, const double *ball_density, const double porosity, const double penalty, const double alpha, const double beta, const double eps_rho, const double eps_mu, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double useVF, const double vf, const double phi, const double x, const double y, const double z, const double p, const double u, const double v, const double w, const double uStar, const double vStar, const double wStar, const double eps_s, const double grad_u[nSpace], const double grad_v[nSpace], const double grad_w[nSpace], double &mass_source, double &mom_u_source, double &mom_v_source, double &mom_w_source, double dmom_u_source[nSpace], double dmom_v_source[nSpace], double dmom_w_source[nSpace], double mom_u_adv[nSpace], double mom_v_adv[nSpace], double mom_w_adv[nSpace], double dmom_u_adv_u[nSpace], double dmom_v_adv_v[nSpace], double dmom_w_adv_w[nSpace], double &mom_u_ham, double dmom_u_ham_grad_u[nSpace], double dmom_u_ham_grad_v[nSpace], double dmom_u_ham_grad_w[nSpace], double &dmom_u_ham_u, double &dmom_u_ham_v, double &dmom_u_ham_w, double &mom_v_ham, double dmom_v_ham_grad_u[nSpace], double dmom_v_ham_grad_v[nSpace], double dmom_v_ham_grad_w[nSpace], double &dmom_v_ham_u, double &dmom_v_ham_v, double &dmom_v_ham_w, double &mom_w_ham, double dmom_w_ham_grad_u[nSpace], double dmom_w_ham_grad_v[nSpace], double dmom_w_ham_grad_w[nSpace], double &dmom_w_ham_u, double &dmom_w_ham_v, double &dmom_w_ham_w, double &mass_ham, double &dmass_ham_u, double &dmass_ham_v, double &dmass_ham_w, double *particle_netForces, double *particle_netMoments, double *particle_surfaceArea, double *particle_surfaceArea_projected, double *projection_direction, double *particle_volume)
Definition RANS2P.h:862
void get_cross_product(const double *u, const double *v, double res[3])
Definition RANS2P.h:842
void getTwoPhaseInvScaledLaplaceOperator(arguments_dict &args)
Definition RANS2P.h:8396
void updateTurbulenceClosure(const double NONCONSERVATIVE_FORM, const int turbulenceClosureModel, const double eps_rho, const double eps_mu, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double useVF, const double vf, const double phi, const double porosity, const double eddy_visc_coef_0, const double turb_var_0, const double turb_var_1, const double turb_grad_0[nSpace], double &eddy_viscosity, double mom_uu_diff_ten[nSpace], double mom_vv_diff_ten[nSpace], double mom_ww_diff_ten[nSpace], double mom_uv_diff_ten[1], double mom_uw_diff_ten[1], double mom_vu_diff_ten[1], double mom_vw_diff_ten[1], double mom_wu_diff_ten[1], double mom_wv_diff_ten[1], double &mom_u_source, double &mom_v_source, double &mom_w_source)
Definition RANS2P.h:1289
void evaluateTPAdvectionCoefficients(const double eps_rho, const double rho_0, const double rho_1, const double useVF, const double &vf, const double &phi, const double &u, const double &v, const double &w, double dmass_adv_p[nSpace], double dmom_u_adv_u[nSpace], double dmom_v_adv_v[nSpace], double dmom_w_adv_w[nSpace])
Definition RANS2P.h:8069
void exteriorNumericalAdvectiveFlux(const double NONCONSERVATIVE_FORM, const int &isDOFBoundary_p, const int &isDOFBoundary_u, const int &isDOFBoundary_v, const int &isDOFBoundary_w, const int &isFluxBoundary_p, const int &isFluxBoundary_u, const int &isFluxBoundary_v, const int &isFluxBoundary_w, const double &oneByRho, const double &bc_oneByRho, const double n[nSpace], const double &bc_p, const double &bc_u, const double &bc_v, const double &bc_w, const double bc_f_mass[nSpace], const double bc_f_umom[nSpace], const double bc_f_vmom[nSpace], const double bc_f_wmom[nSpace], const double &bc_flux_mass, const double &bc_flux_umom, const double &bc_flux_vmom, const double &bc_flux_wmom, const double &p, const double &u, const double &v, const double &w, const double f_mass[nSpace], const double f_umom[nSpace], const double f_vmom[nSpace], const double f_wmom[nSpace], const double df_mass_du[nSpace], const double df_mass_dv[nSpace], const double df_mass_dw[nSpace], const double df_umom_dp[nSpace], const double dham_grad[nSpace], const double df_umom_du[nSpace], const double df_umom_dv[nSpace], const double df_umom_dw[nSpace], const double df_vmom_dp[nSpace], const double df_vmom_du[nSpace], const double df_vmom_dv[nSpace], const double df_vmom_dw[nSpace], const double df_wmom_dp[nSpace], const double df_wmom_du[nSpace], const double df_wmom_dv[nSpace], const double df_wmom_dw[nSpace], double &flux_mass, double &flux_umom, double &flux_vmom, double &flux_wmom, double *velocity)
Definition RANS2P.h:1531
GeneralizedFunctions< nSpace, 3, nQuadraturePoints_element, nQuadraturePoints_elementBoundary > gf_s
Definition RANS2P.h:330
void exteriorNumericalDiffusiveFlux(const double &eps, const double &phi, int *rowptr, int *colind, const int &isDOFBoundary, const int &isFluxBoundary, const double n[nSpace], double *bc_a, const double &bc_u, const double &bc_flux, double *a, const double grad_potential[nSpace], const double &u, const double &penalty, double &flux)
Definition RANS2P.h:2077
CompKernelType ck
Definition RANS2P.h:326
std::set< int > ifem_boundary_elements
Definition RANS2P.h:318
void calculateSubgridError_tauRes(const double &tau_p, const double &tau_v, const double &pdeResidualP, const double &pdeResidualU, const double &pdeResidualV, const double &pdeResidualW, double &subgridErrorP, double &subgridErrorU, double &subgridErrorV, double &subgridErrorW)
Definition RANS2P.h:1463
void updateDarcyForchheimerTerms_Ergun(const double NONCONSERVATIVE_FORM, const double alpha, const double beta, const double eps_rho, const double eps_mu, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double useVF, const double vf, const double phi, const double u, const double v, const double w, const double uStar, const double vStar, const double wStar, const double eps_porous, const double phi_porous, const double u_porous, const double v_porous, const double w_porous, double &mom_u_source, double &mom_v_source, double &mom_w_source, double dmom_u_source[nSpace], double dmom_v_source[nSpace], double dmom_w_source[nSpace])
Definition RANS2P.h:1207
double ExteriorNumericalDiffusiveFluxJacobian(const double &eps, const double &phi, int *rowptr, int *colind, const int &isDOFBoundary, const int &isFluxBoundary, const double n[nSpace], double *a, const double &v, const double grad_v[nSpace], const double &penalty)
Definition RANS2P.h:2127
void calculateSubgridError_tau(const double &hFactor, const double &elementDiameter, const double &dmt, const double &dm, const double df[nSpace], const double &a, const double &pfac, double &tau_v, double &tau_p, double &cfl)
Definition RANS2P.h:1415
void calculateSubgridError_tau(const double &Ct_sge, const double &Cd_sge, const double G[nSpace *nSpace], const double &G_dd_G, const double &tr_G, const double &A0, const double Ai[nSpace], const double &Kij, const double &pfac, double &tau_v, double &tau_p, double &q_cfl)
Definition RANS2P.h:1441
void getTwoPhaseScaledMassOperator(arguments_dict &args)
Definition RANS2P.h:8591
double df(double C, double b, double a, int q, int r)
void vel(double rS, double norm_v, double r, double theta, double *vR, double *vTHETA)
#define sign(x, y)
Definition jf.h:44
#define w(x)
Definition jf.h:22
Definition ADR.h:19
equivalent_polynomials::GeneralizedFunctions_mix< nSpace, nP_ifem, nP, nQ, nEBQ, true > GeneralizedFunctions
Definition ADR.h:21
double phi(const double &g, const double &h, const double &hL, const double &hR, const double &uL, const double &uR)
Definition SW2DCV.h:62
Model_Base * chooseAndAllocateDiscretization(int nSpaceIn, int nQuadraturePoints_elementIn, int nDOF_mesh_trial_elementIn, int nDOF_trial_elementIn, int nDOF_test_elementIn, int nDOF_v_trial_elementIn, int nDOF_v_test_elementIn, int nQuadraturePoints_elementBoundaryIn, int CompKernelFlag)
double rnorm(double *r)
Definition RANS2P.h:33
void F6DOF(double DT, double mass, double *Iref, double *last_u, double *FT, double *last_FT, double *last_mom, double *u, double *mom, double *r, double *J)
Definition RANS2P.h:40
double enorm(double *v)
Definition RANS2P.h:29
RANS2P_base * newRANS2P(int nSpaceIn, int nQuadraturePoints_elementIn, int nDOF_mesh_trial_elementIn, int nDOF_trial_elementIn, int nDOF_test_elementIn, int nDOF_v_trial_elementIn, int nDOF_v_test_elementIn, int nQuadraturePoints_elementBoundaryIn, int CompKernelFlag)
Definition RANS2P.h:8805
double f(const double &g, const double &h, const double &hZ)
Definition SW2DCV.h:58
int dgetrf_(int *m, int *n, double *a, int *lda, int *ipiv, int *info)
int dgetrs_(char *trans, int *n, int *nrhs, double *a, int *lda, int *ipiv, double *b, int *ldb, int *info)
T & scalar(const std::string &key)
xt::pyarray< T > & array(const std::string &key)