17 Length = phiEnd - phiStart;
18 x = (
phi - phiStart)/Length;
19 H = 1 - (exp(pow(x,3.5)) - 1.)/ (exp(1) - 1.);
23 Length = -(phiEnd - phiStart);
24 x = 1 - (
phi - phiStart)/Length;
25 H = 1 - (exp(pow(x,3.5)) - 1.)/ (exp(1) - 1.);
43 H = 0.5*(1.0 +
phi/eps + sin(M_PI*
phi/eps)/M_PI);
52 HI=
phi - eps + 0.5*(eps + 0.5*eps*eps/eps - eps*cos(M_PI*eps/eps)/(M_PI*M_PI)) - 0.5*((-eps) + 0.5*(-eps)*(-eps)/eps - eps*cos(M_PI*(-eps)/eps)/(M_PI*M_PI));
60 HI = 0.5*(
phi + 0.5*
phi*
phi/eps - eps*cos(M_PI*
phi/eps)/(M_PI*M_PI)) - 0.5*((-eps) + 0.5*(-eps)*(-eps)/eps - eps*cos(M_PI*(-eps)/eps)/(M_PI*M_PI));
73 d = 0.5*(1.0 + cos(M_PI*
phi/eps))/eps;
85 H = 0.5*((
phi+eps)/eps);
119 const int nSpace2=nSpace*nSpace;
120 for (k=0;k<nPoints;k++)
125 for (I=0;I<nSpace;I++)
127 f[k*nSpace+I]=
B[I]*
u[k];
129 for (J=0;J<nSpace;J++)
131 a[k*nSpace2+I*nSpace+J]=A[I*nSpace+J];
144 const double alpha_L,
145 const double alpha_T,
155 const int nSpace2=nSpace*nSpace;
158 for (k=0;k<nPoints;k++)
163 for (I=0;I<nSpace;I++)
165 f[k*nSpace+I]=
v[k*nSpace+I]*
u[k];
166 df[k*nSpace+I]=
v[k*nSpace+I];
167 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
169 norm_v = sqrt(norm_v);
172 for (I=0;I<nSpace;I++)
174 a[k*nSpace2+I*nSpace+I]=omega*d + alpha_T*norm_v + (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
175 for (J=I+1;J<nSpace;J++)
177 a[k*nSpace2+I*nSpace+J]=(alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
178 a[k*nSpace2+J*nSpace+I]=a[k*nSpace2+I*nSpace+J];
183 for (I=0;I<nSpace;I++)
184 a[k*nSpace2+I*nSpace+I]=omega*d;
192 const double alpha_L,
193 const double alpha_T,
194 const double Kox_max,
230 const int nSpace2=nSpace*nSpace;
232 double C,E,X,denomC,denomE,denomX,rox,drox_dC,drox_dE,drox_dX;
233 for (k=0;k<nPoints;k++)
235 C = c_c[k]; E = c_e[k]; X = c_x[k];
244 for (I=0;I<nSpace;I++)
246 f_c[k*nSpace+I]=
v[k*nSpace+I]*C;
247 df_c[k*nSpace+I]=
v[k*nSpace+I];
248 f_e[k*nSpace+I]=
v[k*nSpace+I]*E;
249 df_e[k*nSpace+I]=
v[k*nSpace+I];
251 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
253 norm_v = sqrt(norm_v);
256 for (I=0;I<nSpace;I++)
258 a_c[k*nSpace2+I*nSpace+I]=omega*d_c + alpha_T*norm_v + (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
259 for (J=I+1;J<nSpace;J++)
261 a_c[k*nSpace2+I*nSpace+J]= (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
262 a_c[k*nSpace2+J*nSpace+I]=a_c[k*nSpace2+I*nSpace+J];
264 a_e[k*nSpace2+I*nSpace+I]=omega*d_e + alpha_T*norm_v + (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
265 for (J=I+1;J<nSpace;J++)
267 a_e[k*nSpace2+I*nSpace+J]= (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
268 a_e[k*nSpace2+J*nSpace+I]=a_e[k*nSpace2+I*nSpace+J];
274 for (I=0;I<nSpace;I++)
276 a_c[k*nSpace2+I*nSpace+I]=omega*d_c;
277 a_e[k*nSpace2+I*nSpace+I]=omega*d_e;
281 denomC = C + Kox_C; denomE = E + Kox_E; denomX = X + Kox_X;
282 rox = Kox_max*X*(C/denomC)*(E/denomE)*(Kox_X/denomX);
283 drox_dC = Kox_max*X*(E/denomE)*(Kox_X/denomX)*(1.0/denomC -C/(denomC*denomC));
284 drox_dE = Kox_max*X*(C/denomC)*(Kox_X/denomX)*(1.0/denomE -E/(denomE*denomE));
285 drox_dX = Kox_max*(C/denomC)*(E/denomE)*(Kox_X/denomX -Kox_X*X/(denomX*denomX));
288 r_e[k] = 3.0*omega*rox;
289 r_x[k] = -Yield*omega*rox + X*omega*k_d;
291 dr_c_dc[k] = omega*drox_dC; dr_c_de[k] = omega*drox_dE; dr_c_dx[k] = omega*drox_dX;
293 dr_e_dc[k] = 3.0*omega*drox_dC; dr_e_de[k] = 3.0*omega*drox_dE; dr_e_dx[k] = 3.0*omega*drox_dX;
295 dr_x_dc[k] = -Yield*omega*drox_dC;
296 dr_x_de[k] = -Yield*omega*drox_dE;
297 dr_x_dx[k] = -Yield*omega*drox_dX + omega*k_d;
308 const double alpha_L,
309 const double alpha_T,
340 const int nSpace2=nSpace*nSpace;
342 double C_m,C_h,C_oh,C_a,Z_m,Z_h,dC_a_dC_h,denomZ;
343 const double eps = 1.0e-12;
344 for (k=0;k<nPoints;k++)
347 C_m = c_m[k]; C_h= c_h[k]; C_oh = K_w/(C_h+eps);
349 C_a = C_h - C_oh; dC_a_dC_h = 1.0 + K_w/(C_h*C_h+eps);
351 denomZ = 1.0 + K_m*C_m + K_h*C_h;
352 Z_m = K_m*C_m*Z_tot/denomZ;
353 Z_h = K_h*C_h*Z_tot/denomZ;
355 m_m[k] =omega*(C_m + Z_m);
356 dm_m_m[k]=omega*(1.0 + K_m*Z_tot/denomZ - K_m*C_m*Z_tot/(denomZ*denomZ)*K_m*C_m);
357 dm_m_h[k]=omega*( - K_m*C_m*Z_tot/(denomZ*denomZ)*K_h*C_h);
358 m_h[k] =omega*(C_a + Z_h);
359 dm_h_m[k]=omega*( - K_h*C_h*Z_tot/(denomZ*denomZ)*K_m*C_m);
360 dm_h_h[k]=omega*(dC_a_dC_h + K_h*Z_tot/denomZ - K_h*C_h*Z_tot/(denomZ*denomZ)*K_h*C_h);
364 dphi_h[k] = dC_a_dC_h;
366 for (I=0;I<nSpace;I++)
368 f_m[k*nSpace+I]=
v[k*nSpace+I]*C_m;
369 df_m[k*nSpace+I]=
v[k*nSpace+I];
370 f_h[k*nSpace+I]=
v[k*nSpace+I]*C_a;
371 df_h[k*nSpace+I]=
v[k*nSpace+I]*dC_a_dC_h;
373 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
375 norm_v = sqrt(norm_v);
378 for (I=0;I<nSpace;I++)
380 a_m[k*nSpace2+I*nSpace+I]=omega*d_m + alpha_T*norm_v + (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
381 for (J=I+1;J<nSpace;J++)
383 a_m[k*nSpace2+I*nSpace+J]= (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
384 a_m[k*nSpace2+J*nSpace+I]=a_m[k*nSpace2+I*nSpace+J];
386 a_h[k*nSpace2+I*nSpace+I]=omega*d_h + alpha_T*norm_v + (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
387 for (J=I+1;J<nSpace;J++)
389 a_h[k*nSpace2+I*nSpace+J]= (alpha_L - alpha_T)*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
390 a_h[k*nSpace2+J*nSpace+I]=a_h[k*nSpace2+I*nSpace+J];
396 for (I=0;I<nSpace;I++)
398 a_m[k*nSpace2+I*nSpace+I]=omega*d_m;
399 a_h[k*nSpace2+I*nSpace+I]=omega*d_h;
414 const int nPointsPerSimplex,
417 const int* materialTypes,
418 const double *omega_types,
419 const double *alpha_L_types,
420 const double *alpha_T_types,
430 const int nSpace2=nSpace*nSpace;
433 for (i=0;i<nSimplex;i++)
435 matID = materialTypes[i];
436 for (j=0; j < nPointsPerSimplex; j++)
438 k = i*nPointsPerSimplex+j;
440 m[k]=omega_types[matID]*
u[k];
441 dm[k]=omega_types[matID];
443 for (I=0;I<nSpace;I++)
445 f[k*nSpace+I]=
v[k*nSpace+I]*
u[k];
446 df[k*nSpace+I]=
v[k*nSpace+I];
447 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
449 norm_v = sqrt(norm_v);
452 for (I=0;I<nSpace;I++)
454 a[k*nSpace2+I*nSpace+I]=omega_types[matID]*d + alpha_T_types[matID]*norm_v + (alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
455 for (J=I+1;J<nSpace;J++)
457 a[k*nSpace2+I*nSpace+J]=(alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
458 a[k*nSpace2+J*nSpace+I]=a[k*nSpace2+I*nSpace+J];
463 for (I=0;I<nSpace;I++)
464 a[k*nSpace2+I*nSpace+I]=omega_types[matID]*d;
469 const int nPointsPerSimplex,
472 const int* materialTypes,
474 const double *alpha_L_types,
475 const double *alpha_T_types,
485 const int nSpace2=nSpace*nSpace;
488 for (i=0;i<nSimplex;i++)
490 matID = materialTypes[i];
491 for (j=0; j < nPointsPerSimplex; j++)
493 k = i*nPointsPerSimplex+j;
498 for (I=0;I<nSpace;I++)
500 f[k*nSpace+I]=
v[k*nSpace+I]*
u[k];
501 df[k*nSpace+I]=
v[k*nSpace+I];
502 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
504 norm_v = sqrt(norm_v);
507 for (I=0;I<nSpace;I++)
509 a[k*nSpace2+I*nSpace+I]=theta[k]*d + alpha_T_types[matID]*norm_v + (alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
510 for (J=I+1;J<nSpace;J++)
512 a[k*nSpace2+I*nSpace+J]=(alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
513 a[k*nSpace2+J*nSpace+I]=a[k*nSpace2+I*nSpace+J];
518 for (I=0;I<nSpace;I++)
519 a[k*nSpace2+I*nSpace+I]=theta[k]*d;
524 const int nPointsPerSimplex,
528 const double specificHeat_w,
529 const double specificHeat_n,
530 const int* materialTypes,
532 const double *thetaS_types,
533 const double *alpha_L_types,
534 const double *alpha_T_types,
535 const double *rho_s_types,
536 const double *specificHeat_s_types,
537 const double *lambda_sat_types,
538 const double *lambda_dry_types,
539 const double *lambda_aniso_types,
549 const int nSpace2=nSpace*nSpace;
550 double norm_v,tmp,sw,Ke,lambda;
552 for (i=0;i<nSimplex;i++)
554 matID = materialTypes[i];
555 for (j=0; j < nPointsPerSimplex; j++)
557 k = i*nPointsPerSimplex+j;
558 tmp = theta[k]*rho_w*specificHeat_w + (thetaS_types[matID]-theta[k])*rho_n*specificHeat_n +
559 (1.0-thetaS_types[matID])*rho_s_types[matID]*specificHeat_s_types[matID];
563 for (I=0;I<nSpace;I++)
565 f[k*nSpace+I]=
v[k*nSpace+I]*rho_w*specificHeat_w*
u[k];
566 df[k*nSpace+I]=
v[k*nSpace+I]*rho_w*specificHeat_w;
567 norm_v +=
v[k*nSpace+I]*
v[k*nSpace+I];
569 norm_v = sqrt(norm_v);
570 sw = theta[k]/thetaS_types[matID];
573 for (I=0;I<nSpace;I++)
575 a[k*nSpace2+I*nSpace+I]= rho_w*specificHeat_w*alpha_T_types[matID]*norm_v + rho_w*specificHeat_w*(alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+I]/norm_v;
576 for (J=I+1;J<nSpace;J++)
578 a[k*nSpace2+I*nSpace+J]=rho_w*specificHeat_w*(alpha_L_types[matID] - alpha_T_types[matID])*
v[k*nSpace+I]*
v[k*nSpace+J]/norm_v;
579 a[k*nSpace2+J*nSpace+I]=a[k*nSpace2+I*nSpace+J];
586 Ke = 0.7*log(sw) + 1.0;
587 lambda = (lambda_sat_types[matID]-lambda_dry_types[matID])*Ke + lambda_dry_types[matID];
588 for (I=0;I<nSpace;I++)
590 a[k*nSpace2+I*nSpace+I] += lambda*lambda_aniso_types[matID*nSpace+I];
623 const int nSpace2=nSpace*nSpace;
629 const double pM1_pow=p_pow-1.0,
634 for (k=0;k<nPoints;k++)
636 uPlus =
u[k] > 0.0 ?
u[k] : 0.0;
637 m[k] = p_pow > 1.0 ? M*pow(uPlus,p_pow) : M*
u[k];
638 dm[k] = p_pow > 1.0 ? p_pow*M*pow(uPlus,pM1_pow) : M;
640 tmp_f = q_pow > 1.0 ? pow(uPlus,q_pow) :
u[k];
641 tmp_df = q_pow > 1.0 ? q_pow*pow(uPlus,qM1_pow) : 1.0;
643 tmp_a = t_pow > 0.0 ? pow(uPlus,t_pow) : 1.0;
644 tmp_da = t_pow > 0.0 ? t_pow*pow(uPlus,tM1_pow) : 0.0;
646 for (I=0;I<nSpace;I++)
648 f[k*nSpace+I] =
B[I]*tmp_f;
649 df[k*nSpace+I] =
B[I]*tmp_df;
650 for (J=0;J<nSpace;J++)
652 a[k*nSpace2+I*nSpace+J] = A[I*nSpace + J]*tmp_a;
653 da[k*nSpace2+I*nSpace+J] = A[I*nSpace + J]*tmp_da;
656 phi[k] = r_pow > 1.0 ? pow(uPlus,r_pow) :
u[k];
657 dphi[k] = r_pow > 1.0 ? r_pow*pow(uPlus,rM1_pow) : 1.0;
659 r[k] = s_pow > 1.0 ? C*pow(uPlus,s_pow) : C*
u[k];
660 dr[k] = s_pow > 1.0 ? s_pow*C*pow(uPlus,sM1_pow) : C;
695 const int nSpace2=nSpace*nSpace;
696 double max_1mu_0,atmp,datmp;
697 const double p2M1=p2-1.0,
720 for (k=0; k < nPoints; k++)
722 max_1mu_0 = 1.0-
u[k] > 0.0 ? 1.0-
u[k] : 0.0;
726 m[k] *= pow(max_1mu_0,p2);
727 dm[k] *= pow(max_1mu_0,p2M1)*p2;
732 for (I=0; I < nSpace; I++)
734 f[k*nSpace+I] *= pow(max_1mu_0,q2);
735 df[k*nSpace+I] *= pow(max_1mu_0,q2M1)*q2;
741 atmp = pow(max_1mu_0,t2);
742 datmp = pow(max_1mu_0,t2M1);
743 for (I=0; I < nSpace; I++)
745 for (J=0; J < nSpace; J++)
747 a[k*nSpace2+I*nSpace+J] *= atmp;
748 da[k*nSpace2+I*nSpace+J] *= datmp*t2;
755 phi[k] *= pow(max_1mu_0,r2);
756 dphi[k] *= pow(max_1mu_0,r2M1)*r2;
761 r[k] *= pow(max_1mu_0,s2*
r[k]);
762 dr[k] *= pow(max_1mu_0,s2M1)*s2;
778 for (k=0; k < nPoints; k++)
782 vx = 2.0*M_PI*(x[k*3+1] - 0.5);
783 vy = 2.0*M_PI*(0.5 - x[k*3]);
784 f[k*nSpace] =
vx*
u[k];
785 f[k*nSpace+1] =
vy*
u[k];
802 for (k=0; k < nPoints; k++)
806 vx = 2.0*M_PI*(x[k*3+1] - 0.5);
807 vy = 2.0*M_PI*(0.5 - x[k*3]);
809 f[k*nSpace] =
vx*
u[k];
810 f[k*nSpace+1] =
vy*
u[k];
811 f[k*nSpace+2] = vz*
u[k];
835 const int nSpace2 = nSpace*nSpace;
836 memset(da, 0, nPoints * nSpace2 *
sizeof(
double));
837 memcpy(m,
u, nPoints *
sizeof(
double));
838 memcpy(
phi,
u, nPoints *
sizeof(
double));
841 for (k=0; k < nPoints; k++)
843 dm[k] = dphi[k] = 1.0;
845 vx = -4.0*(x[k*3+1] - 0.5);
846 vy = 4.0*(x[k*3] - 0.5);
847 f[k*nSpace] =
vx*
u[k];
848 f[k*nSpace+1] =
vy*
u[k];
852 for (I=0; I < nSpace; I++)
854 a[k*nSpace2 + I*nSpace + I] = self_a;
875 const int nSpace2 = nSpace*nSpace;
877 memcpy(m,
u, nPoints *
sizeof(
double));
878 memcpy(
phi,
u, nPoints *
sizeof(
double));
879 memset(da, 0, nPoints * nSpace2 *
sizeof(
double));
881 for (k=0; k < nPoints; k++)
883 dm[k] = dphi[k] = 1.0;
889 f[k*nSpace] =
vx*
u[k];
890 f[k*nSpace+1] =
vy*
u[k];
893 if (sqrt(X*X+
Y*
Y) < 0.25)
895 f[k*nSpace] *= 0.001;
896 f[k*nSpace+1] *= 0.001;
897 df[k*nSpace] *= 0.001;
898 df[k*nSpace+1] *= 0.001;
901 for (I=0; I < nSpace; I++)
903 a[k*nSpace2 + I*nSpace + I] = self_a;
923 const int nSpace2 = nSpace*nSpace;
925 for (k=0; k < nPoints; k++)
929 dm[k] = dphi[k] = 1.0;
934 df[k*nSpace+1] = 0.0;
938 df[k*nSpace] *= 0.25;
941 for (I=0; I < nSpace; I++)
943 a[k*nSpace2 + I*nSpace + I] = self_a;
945 for (J=0; J < nSpace; J++)
947 da[k*nSpace2 + I*nSpace + J] = 0.0;
956 const double *self_v,
968 const int nSpace2 = nSpace*nSpace;
970 for (k=0; k < nPoints; k++)
972 m[k] =
phi[k] =
u[k];
973 dm[k] = dphi[k] = 1.0;
975 for (I=0; I < nSpace; I++)
977 a[k*nSpace2 + I*nSpace + I] = self_a;
978 f[k*nSpace+I] = self_v[I] *
u[k] *
u[k] * 0.5;
979 df[k*nSpace+I]= self_v[I] *
u[k];
992 const double *self_v,
994 const double *grad_u,
1005 const int nSpace2 = nSpace*nSpace;
1007 for (k=0; k < nPoints; k++)
1009 m[k] =
phi[k] =
u[k];
1010 dm[k] = dphi[k] = 1.0;
1013 for (I=0; I < nSpace; I++)
1015 a[k*nSpace2 + I*nSpace + I] = self_a;
1016 H[k] += self_v[I] * grad_u[k*nSpace+I] *
u[k];
1017 dH[k*nSpace+I]= self_v[I] *
u[k];
1049 const int nSpace2=nSpace*nSpace;
1050 for (k=0;k<nPoints;k++)
1054 for (I=0;I<nSpace;I++)
1056 f[k*nSpace+I]=
B[k*nSpace+I]*
u[k] + Bcon[k*nSpace+I];
1057 df[k*nSpace+I]=
B[k*nSpace+I];
1058 for (J=0;J<nSpace;J++)
1060 a[k*nSpace2+I*nSpace+J]=A[k*nSpace2 + I*nSpace+J];
1061 da[k*nSpace2+I*nSpace+J]=0.0;
1077 double M1,
double M2,
double *M,
1078 double* A1,
double* A2,
double *A,
1079 double* B1,
double* B2,
double *
B,
1080 double* Bcon1,
double* Bcon2,
double *Bcon,
1081 double C1,
double C2,
double *C)
1084 const int nSpace2=nSpace*nSpace;
1086 for (k=0;k<nPoints;k++)
1088 if (u_levelSet[k] > eps)
1091 for (I=0;I<nSpace;I++)
1093 B[k*nSpace+I]=B1[I];
1094 Bcon[k*nSpace+I]=Bcon1[I];
1095 for (J=0;J<nSpace;J++)
1097 A[k*nSpace2+I*nSpace+J]=A1[I*nSpace+J];
1102 else if (u_levelSet[k] < -eps)
1105 for (I=0;I<nSpace;I++)
1107 B[k*nSpace+I]=B2[I];
1108 Bcon[k*nSpace+I]=Bcon2[I];
1109 for (J=0;J<nSpace;J++)
1111 A[k*nSpace2+I*nSpace+J]=A2[I*nSpace+J];
1118 H = 0.5*(1.0 + u_levelSet[k]/eps + sin((M_PI*u_levelSet[k])/eps)/M_PI);
1120 M[k] = oneMinusH*M2 +
H*M1;
1121 for (I=0;I<nSpace;I++)
1123 B[k*nSpace+I]=oneMinusH*B2[I] +
H*B1[I];
1124 Bcon[k*nSpace+I]=oneMinusH*Bcon2[I] +
H*Bcon1[I];
1125 for (J=0;J<nSpace;J++)
1127 A[k*nSpace2+I*nSpace+J]=oneMinusH*A2[I*nSpace+J] +
H*A1[I*nSpace+J];
1130 C[k]=oneMinusH*C2+
H*C1;
1142 for (i=0;i<nPoints;i++)
1143 for (I=0;I<nSpace;I++)
1144 vOut[i*nSpace+I]=v_scale*vIn[i*nSpace+I];
1154 double* m,
double* dm,
1155 double* h,
double* dh,
1159 for (i=0;i<nPoints;i++)
1165 for (I=0;I<nSpace;I++)
1167 h[i] +=
B[i*nSpace+I]*grad_u[i*nSpace+I];
1168 dh[i*nSpace+I]=
B[i*nSpace+I];
1179 double* m,
double* dm,
1180 double*
f,
double*
df,
1181 double* a,
double* da,
1182 double*
phi,
double* dphi,
1183 double*
r,
double* dr)
1186 for (i=0;i<nPoints;i++)
1190 for (I=0;I<nSpace;I++)
1192 f[i*nSpace+I] =
B[i*nSpace+I]*
u[i];
1193 df[i*nSpace+I]=
B[i*nSpace+I];
1209 for (i=0;i<nPoints;i++)
1214 for (I=0;I<nSpace;I++)
1216 H[i] +=
v[i*nSpace+I]*grad_u[i*nSpace+I];
1217 dH[i*nSpace+I] =
v[i*nSpace+I];
1232 for (i=0;i<nPoints;i++)
1236 for (I=0;I<nSpace;I++)
1238 f[i*nSpace+I] =
v[i*nSpace+I]*
u[i];
1239 df[i*nSpace+I] =
v[i*nSpace+I];
1256 for (i=0;i<nPoints;i++)
1260 for (I=0;I<nSpace;I++)
1264 f[i*nSpace+I] =
v[i*nSpace+I]*
u[i];
1265 df[i*nSpace+I] =
v[i*nSpace+I];
1279 double norm_grad_phi;
1280 for (i=0;i<nPoints;i++)
1284 norm_grad_phi = 0.0;
1285 for (I=0;I<nSpace;I++)
1286 norm_grad_phi += grad_phi[i*nSpace+I]*grad_phi[i*nSpace+I];
1287 norm_grad_phi = sqrt(norm_grad_phi);
1288 if (norm_grad_phi > 0.0)
1290 for (I=0;I<nSpace;I++)
1291 f[i*nSpace+I] = grad_phi[i*nSpace+I]/norm_grad_phi;
1294 f[i*nSpace+I] = 0.0;
1305 for (k=0;k<nPoints;k++)
1307 if (u_levelSet[k] > eps)
1309 else if (u_levelSet[k] < -eps)
1313 H = 0.5*(1.0 + u_levelSet[k]/eps + sin((M_PI*u_levelSet[k])/eps)/M_PI);
1330 double* m,
double* dm,
1331 double* h,
double* dh,
1335 for (i=0;i<nPoints;i++)
1341 for (I=0;I<nSpace;I++)
1342 h[i] += grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1344 for (I=0;I<nSpace;I++)
1345 if(h[i]>= fabs(S[i]*grad_u[i*nSpace+I])*1.0e-8)
1346 dh[i*nSpace+I] = (S[i]*grad_u[i*nSpace+I])/h[i];
1348 dh[i*nSpace+I] = (S[i]*grad_u[i*nSpace+I])/1.0e-8;
1367 for (i=0;i<nPoints;i++)
1374 for (I=0;I<nSpace;I++)
1375 normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1376 normGradU = sqrt(normGradU);
1378 for (I=0;I<nSpace;I++)
1380 dH[i*nSpace+I] = grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1397 double Si,normGradU;
1401 for (i=0;i<nPoints;i++)
1425 for (I=0;I<nSpace;I++)
1426 normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1427 normGradU = sqrt(normGradU);
1428 H[i] = Si*normGradU;
1437 for (I=0;I<nSpace;I++)
1439 dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1446 double lambda_penalty,
1458 double Si,normGradU;
1462 for (i=0;i<nPoints;i++)
1486 for (I=0;I<nSpace;I++)
1487 normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1488 normGradU = sqrt(normGradU);
1489 H[i] = Si*normGradU;
1498 for (I=0;I<nSpace;I++)
1500 dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1503 r[i] += (
u[i]-u_levelSet[i])*lambda_penalty*
smoothedDirac(eps,u_levelSet[i]);
1513 int nPointsPerSimplex,
1527 double He,Si,normGradU,
1533 for (ie=0; ie < nSimplex; ie++)
1538 for (iq=0;iq<nPointsPerSimplex;iq++)
1540 i = ie*nPointsPerSimplex + iq;
1545 if (u_levelSet[i] > eps)
1549 else if (u_levelSet[i] < -eps)
1555 He =0.5*(1.0 + u_levelSet[i]/eps + sin(M_PI*u_levelSet[i]/eps)/M_PI);
1556 dHe=0.5*(0.0 + 1.0/eps + cos(M_PI*u_levelSet[i]/eps)/eps);
1560 for (I=0;I<nSpace;I++)
1561 normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1562 normGradU = sqrt(normGradU);
1565 H[i] = Si*normGradU;
1566 for (I=0;I<nSpace;I++)
1568 dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1573 for (iq = 0; iq < nPointsPerSimplex; iq++)
1575 i = ie*nPointsPerSimplex + iq;
1578 if (u_levelSet[i] > eps)
1582 else if (u_levelSet[i] < -eps)
1588 He =0.5*(1.0 + u_levelSet[i]/eps + sin(M_PI*u_levelSet[i]/eps)/M_PI);
1589 dHe=0.5*(0.0 + 1.0/eps + cos(M_PI*u_levelSet[i]/eps)/eps);
1592 normGradU =
H[i]/Si;
1593 lambda -= dHe*Li*dV[i]/(dHe*dHe*normGradU+1.0e-8);
1596 for (iq = 0; iq < nPointsPerSimplex; iq++)
1598 i = ie*nPointsPerSimplex + iq;
1600 if (u_levelSet[i] > eps)
1602 else if (u_levelSet[i] < -eps)
1603 {Si=-1.0; He = 0.0;}
1606 He =0.5*(1.0 + u_levelSet[i]/eps + sin(M_PI*u_levelSet[i]/eps)/M_PI);
1607 dHe=0.5*(0.0 + 1.0/eps + cos(M_PI*u_levelSet[i]/eps)/eps);
1610 normGradU =
H[i]/Si;
1611 r[i] -= lambda*dHe*normGradU;
1621 int nDOF_trial_element,
1622 double epsilon_freeze_factor,
1623 const double *elementDiameter,
1625 const double *u_dof,
1626 int * freeze_nodes_tmp,
1627 int * weakDirichletConditionFlags)
1629 int eN,j,jj,signU,j0,J0,J;
1631 for (eN = 0; eN < nElements_global; eN++)
1633 for (j = 0; j < nDOF_trial_element; j++)
1634 freeze_nodes_tmp[j] = 0;
1635 eps = epsilon_freeze_factor*elementDiameter[eN];
1637 while (signU == 0 && j0 < nDOF_trial_element)
1639 J0 = u_l2g[eN*nDOF_trial_element + j0];
1640 if (u_dof[J0] < -eps)
1642 else if (u_dof[J0] > eps)
1645 freeze_nodes_tmp[j0] = 1;
1648 for (j = j0; j < nDOF_trial_element; j++)
1650 J = u_l2g[eN*nDOF_trial_element + j];
1651 if ((u_dof[J] < -eps && signU == 1) ||
1652 (u_dof[J] > eps && signU == -1))
1654 for (jj = 0; jj < nDOF_trial_element; jj++)
1655 freeze_nodes_tmp[jj] = 1;
1658 else if (fabs(u_dof[J]) < eps)
1659 freeze_nodes_tmp[j] = 1;
1661 for (j = 0; j < nDOF_trial_element; j++)
1663 if (freeze_nodes_tmp[j] == 1)
1665 J = u_l2g[eN*nDOF_trial_element + j];
1666 weakDirichletConditionFlags[J] = 1;
1673 int nDOF_trial_element,
1674 double epsilon_freeze_factor,
1675 const double *elementDiameter,
1677 const double *u_dof,
1678 int * freeze_nodes_tmp,
1679 int * weakDirichletConditionFlags)
1683 for (eN = 0; eN < nElements_global; eN++)
1685 eps = epsilon_freeze_factor*elementDiameter[eN];
1686 for (j = 0; j < nDOF_trial_element; j++)
1688 J = u_l2g[eN*nDOF_trial_element + j];
1689 if (fabs(u_dof[J]) < eps)
1690 weakDirichletConditionFlags[J] = 1;
1700 double Km,
double rhoM,
1701 double Kp,
double rhoP,
1706 double * u_levelSet,
1721 nSpace2 = nSpace*nSpace;
1722 for (k = 0; k < nPoints; k++)
1724 m[k] = 0.0; dm[k] = 1.0;
1725 r[k] = 0.0; dr[k] = 0.0;
1733 for (I = 0; I < nSpace; I++)
1735 for (J = 0; J < nSpace; J++)
1738 a[k*nSpace2 + I*nSpace+J] = Km + He*(Kp-Km);
1740 a[k*nSpace2 + I*nSpace+J] = 0.0;
1741 da[k*nSpace2 + I*nSpace+J] = 0.0;
1743 f[k*nSpace + I] = (Km*rhoM + He*(Kp*rhoP-Km*rhoM))*gravity_u[I];
1744 df[k*nSpace + I]= 0.0;
1752 double Km,
double rhoM,
1753 double Kp,
double rhoP,
1758 double * u_levelSet,
1772 double rhoEps = 0.0;
1773 nSpace2 = nSpace*nSpace;
1774 for (k = 0; k < nPoints; k++)
1776 m[k] = 0.0; dm[k] = 1.0;
1777 r[k] = 0.0; dr[k] = 0.0;
1786 for (I = 0; I < nSpace; I++)
1788 for (J = 0; J < nSpace; J++)
1791 a[k*nSpace2 + I*nSpace+J] = Km + He*(Kp-Km);
1793 a[k*nSpace2 + I*nSpace+J] = 0.0;
1794 da[k*nSpace2 + I*nSpace+J] = 0.0;
1796 f[k*nSpace + I] = (Km*rhoM + He*(Kp*rhoP-Km*rhoM))*gravity_u[I];
1797 df[k*nSpace + I]= 0.0;
1804 double *mom_p_diff_ten,
1805 double *mom_u_diff_ten,
1806 double *mom_v_diff_ten)
1809 for (k=0; k<nPoints; k++)
1811 mom_p_diff_ten[k*2+0] = 1.0;
1812 mom_p_diff_ten[k*2+1] = 1.0;
1814 mom_u_diff_ten[k*2+0] = 1.0;
1815 mom_u_diff_ten[k*2+1] = 1.0;
1817 mom_v_diff_ten[k*2+0] = 1.0;
1818 mom_v_diff_ten[k*2+1] = 1.0;
1823 double *mom_p_diff_ten,
1824 double *mom_u_diff_ten,
1825 double *mom_v_diff_ten,
1826 double *mom_w_diff_ten)
1829 for (k=0; k<nPoints; k++)
1831 mom_p_diff_ten[k*3+0] = 1.0;
1832 mom_p_diff_ten[k*3+1] = 1.0;
1833 mom_p_diff_ten[k*3+2] = 1.0;
1835 mom_u_diff_ten[k*3+0] = 1.0;
1836 mom_u_diff_ten[k*3+1] = 1.0;
1837 mom_u_diff_ten[k*3+2] = 1.0;
1839 mom_v_diff_ten[k*3+0] = 1.0;
1840 mom_v_diff_ten[k*3+1] = 1.0;
1841 mom_v_diff_ten[k*3+2] = 1.0;
1843 mom_w_diff_ten[k*3+0] = 1.0;
1844 mom_w_diff_ten[k*3+1] = 1.0;
1845 mom_w_diff_ten[k*3+2] = 1.0;
1855 const double *grad_p,
1859 double *dmom_u_acc_u,
1861 double *dmom_v_acc_v,
1863 double *dmass_adv_u,
1864 double *dmass_adv_v,
1866 double *dmom_u_adv_u,
1867 double *dmom_u_adv_v,
1869 double *dmom_v_adv_u,
1870 double *dmom_v_adv_v,
1871 double *mom_u_diff_ten,
1872 double *mom_v_diff_ten,
1873 double *mom_u_source,
1874 double *mom_v_source,
1876 double *dmom_u_ham_grad_p,
1878 double *dmom_v_ham_grad_p)
1881 for (k=0;k<nPoints;k++)
1886 dmom_u_acc_u[k]=1.0;
1889 dmom_v_acc_v[k]=1.0;
1892 mass_adv[k*2+0]=
u[k];
1893 mass_adv[k*2+1]=
v[k];
1895 dmass_adv_u[k*2+0]=1.0;
1896 dmass_adv_v[k*2+1]=1.0;
1899 mom_u_adv[k*2+0]=
u[k]*
u[k];
1900 mom_u_adv[k*2+1]=
u[k]*
v[k];
1902 dmom_u_adv_u[k*2+0]=2.0*
u[k];
1903 dmom_u_adv_u[k*2+1]=
v[k];
1905 dmom_u_adv_v[k*2+1]=
u[k];
1908 mom_v_adv[k*2+0]=
v[k]*
u[k];
1909 mom_v_adv[k*2+1]=
v[k]*
v[k];
1911 dmom_v_adv_u[k*2+0]=
v[k];
1913 dmom_v_adv_v[k*2+0]=
u[k];
1914 dmom_v_adv_v[k*2+1]=2.0*
v[k];
1917 mom_u_diff_ten[k*4+0] = nu;
1918 mom_u_diff_ten[k*4+3] = nu;
1921 mom_v_diff_ten[k*4+0] = nu;
1922 mom_v_diff_ten[k*4+3] = nu;
1925 mom_u_source[k] = -g[0];
1926 mom_v_source[k] = -g[1];
1929 mom_u_ham[k] = grad_p[k*2+0]/rho;
1930 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
1933 mom_v_ham[k] = grad_p[k*2+1]/rho;
1934 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
1943 const double *grad_p,
1948 double *dmom_u_acc_u,
1950 double *dmom_v_acc_v,
1952 double *dmom_w_acc_w,
1954 double *dmass_adv_u,
1955 double *dmass_adv_v,
1956 double *dmass_adv_w,
1958 double *dmom_u_adv_u,
1959 double *dmom_u_adv_v,
1960 double *dmom_u_adv_w,
1962 double *dmom_v_adv_u,
1963 double *dmom_v_adv_v,
1964 double *dmom_v_adv_w,
1966 double *dmom_w_adv_u,
1967 double *dmom_w_adv_v,
1968 double *dmom_w_adv_w,
1969 double *mom_u_diff_ten,
1970 double *mom_v_diff_ten,
1971 double *mom_w_diff_ten,
1972 double *mom_u_source,
1973 double *mom_v_source,
1974 double *mom_w_source,
1976 double *dmom_u_ham_grad_p,
1978 double *dmom_v_ham_grad_p,
1980 double *dmom_w_ham_grad_p)
1983 for (k=0;k<nPoints;k++)
1989 dmom_u_acc_u[k]=1.0;
1992 dmom_v_acc_v[k]=1.0;
1995 dmom_w_acc_w[k]=1.0;
1998 mass_adv[k*3+0]=
u[k];
1999 mass_adv[k*3+1]=
v[k];
2000 mass_adv[k*3+2]=
w[k];
2002 dmass_adv_u[k*3+0]=1.0;
2003 dmass_adv_v[k*3+1]=1.0;
2004 dmass_adv_w[k*3+2]=1.0;
2007 mom_u_adv[k*3+0]=
u[k]*
u[k];
2008 mom_u_adv[k*3+1]=
u[k]*
v[k];
2009 mom_u_adv[k*3+2]=
u[k]*
w[k];
2011 dmom_u_adv_u[k*3+0]=2.0*
u[k];
2012 dmom_u_adv_u[k*3+1]=
v[k];
2013 dmom_u_adv_u[k*3+2]=
w[k];
2015 dmom_u_adv_v[k*3+1]=
u[k];
2017 dmom_u_adv_w[k*3+2]=
u[k];
2020 mom_v_adv[k*3+0]=
v[k]*
u[k];
2021 mom_v_adv[k*3+1]=
v[k]*
v[k];
2022 mom_v_adv[k*3+2]=
v[k]*
w[k];
2024 dmom_v_adv_u[k*3+0]=
v[k];
2026 dmom_v_adv_v[k*3+0]=
u[k];
2027 dmom_v_adv_v[k*3+1]=2.0*
v[k];
2028 dmom_v_adv_v[k*3+2]=
w[k];
2030 dmom_v_adv_w[k*3+2]=
v[k];
2033 mom_w_adv[k*3+0]=
w[k]*
u[k];
2034 mom_w_adv[k*3+1]=
w[k]*
v[k];
2035 mom_w_adv[k*3+2]=
w[k]*
w[k];
2037 dmom_w_adv_u[k*3+0]=
w[k];
2039 dmom_w_adv_v[k*3+0]=
w[k];
2041 dmom_w_adv_w[k*3+0]=
u[k];
2042 dmom_w_adv_w[k*3+1]=
v[k];
2043 dmom_w_adv_w[k*3+2]=2.0*
w[k];
2046 mom_u_diff_ten[k*9+0] = nu;
2047 mom_u_diff_ten[k*9+4] = nu;
2048 mom_u_diff_ten[k*9+8] = nu;
2051 mom_v_diff_ten[k*9+0] = nu;
2052 mom_v_diff_ten[k*9+4] = nu;
2053 mom_v_diff_ten[k*9+8] = nu;
2056 mom_w_diff_ten[k*9+0] = nu;
2057 mom_w_diff_ten[k*9+4] = nu;
2058 mom_w_diff_ten[k*9+8] = nu;
2061 mom_u_source[k] = -g[0];
2062 mom_v_source[k] = -g[1];
2063 mom_w_source[k] = -g[2];
2066 mom_u_ham[k] = grad_p[k*3+0]/rho;
2067 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
2070 mom_v_ham[k] = grad_p[k*3+1]/rho;
2071 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
2074 mom_w_ham[k] = grad_p[k*3+2]/rho;
2075 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
2084 const double *grad_p,
2088 double *dmom_u_acc_u,
2090 double *dmom_v_acc_v,
2092 double *dmass_adv_u,
2093 double *dmass_adv_v,
2094 double *mom_u_diff_ten,
2095 double *mom_v_diff_ten,
2096 double *mom_u_source,
2097 double *mom_v_source,
2099 double *dmom_u_ham_grad_p,
2101 double *dmom_v_ham_grad_p)
2104 for (k=0;k<nPoints;k++)
2109 dmom_u_acc_u[k]=1.0;
2112 dmom_v_acc_v[k]=1.0;
2115 mass_adv[k*2+0]=
u[k];
2116 mass_adv[k*2+1]=
v[k];
2118 dmass_adv_u[k*2+0]=1.0;
2119 dmass_adv_v[k*2+1]=1.0;
2122 mom_u_diff_ten[k*4+0] = nu;
2123 mom_u_diff_ten[k*4+3] = nu;
2126 mom_v_diff_ten[k*4+0] = nu;
2127 mom_v_diff_ten[k*4+3] = nu;
2130 mom_u_source[k] = -g[0];
2131 mom_v_source[k] = -g[1];
2134 mom_u_ham[k] = grad_p[k*2+0]/rho;
2135 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2138 mom_v_ham[k] = grad_p[k*2+1]/rho;
2139 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2151 double *dmom_u_acc_u,
2153 double *dmom_v_acc_v,
2155 double *dmass_adv_u,
2156 double *dmass_adv_v,
2158 double *dmom_u_adv_p,
2160 double *dmom_v_adv_p,
2161 double *mom_u_diff_ten,
2162 double *mom_v_diff_ten,
2163 double *mom_u_source,
2164 double *mom_v_source)
2167 for (k=0;k<nPoints;k++)
2172 dmom_u_acc_u[k]=1.0;
2175 dmom_v_acc_v[k]=1.0;
2178 mass_adv[k*2+0]=
u[k];
2179 mass_adv[k*2+1]=
v[k];
2181 dmass_adv_u[k*2+0]=1.0;
2182 dmass_adv_v[k*2+1]=1.0;
2185 mom_u_adv[k*2+0]=p[k]/rho;
2186 dmom_u_adv_p[k*2+0]=1.0/rho;
2189 mom_v_adv[k*2+1]=p[k]/rho;
2190 dmom_v_adv_p[k*2+1]=1.0/rho;
2193 mom_u_diff_ten[k*4+0] = nu;
2194 mom_u_diff_ten[k*4+3] = nu;
2197 mom_v_diff_ten[k*4+0] = nu;
2198 mom_v_diff_ten[k*4+3] = nu;
2201 mom_u_source[k] = -g[0];
2202 mom_v_source[k] = -g[1];
2211 const double *grad_p,
2216 double *dmom_u_acc_u,
2218 double *dmom_v_acc_v,
2220 double *dmom_w_acc_w,
2222 double *dmass_adv_u,
2223 double *dmass_adv_v,
2224 double *dmass_adv_w,
2225 double *mom_u_diff_ten,
2226 double *mom_v_diff_ten,
2227 double *mom_w_diff_ten,
2228 double *mom_u_source,
2229 double *mom_v_source,
2230 double *mom_w_source,
2232 double *dmom_u_ham_grad_p,
2234 double *dmom_v_ham_grad_p,
2236 double *dmom_w_ham_grad_p)
2239 for (k=0;k<nPoints;k++)
2244 dmom_u_acc_u[k]=1.0;
2247 dmom_v_acc_v[k]=1.0;
2250 dmom_w_acc_w[k]=1.0;
2253 mass_adv[k*3+0]=
u[k];
2254 mass_adv[k*3+1]=
v[k];
2255 mass_adv[k*3+2]=
w[k];
2257 dmass_adv_u[k*3+0]=1.0;
2258 dmass_adv_v[k*3+1]=1.0;
2259 dmass_adv_w[k*3+2]=1.0;
2262 mom_u_diff_ten[k*9+0] = nu;
2263 mom_u_diff_ten[k*9+4] = nu;
2264 mom_u_diff_ten[k*9+8] = nu;
2267 mom_v_diff_ten[k*9+0] = nu;
2268 mom_v_diff_ten[k*9+4] = nu;
2269 mom_v_diff_ten[k*9+8] = nu;
2272 mom_w_diff_ten[k*9+0] = nu;
2273 mom_w_diff_ten[k*9+4] = nu;
2274 mom_w_diff_ten[k*9+8] = nu;
2277 mom_u_source[k] = -g[0];
2278 mom_v_source[k] = -g[1];
2279 mom_w_source[k] = -g[2];
2282 mom_u_ham[k] = grad_p[k*3+0]/rho;
2283 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
2286 mom_v_ham[k] = grad_p[k*3+1]/rho;
2287 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
2290 mom_w_ham[k] = grad_p[k*3+2]/rho;
2291 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
2304 double *dmom_u_acc_u,
2306 double *dmom_v_acc_v,
2308 double *dmom_w_acc_w,
2310 double *dmass_adv_u,
2311 double *dmass_adv_v,
2312 double *dmass_adv_w,
2314 double *dmom_u_adv_p,
2316 double *dmom_v_adv_p,
2318 double *dmom_w_adv_p,
2319 double *mom_u_diff_ten,
2320 double *mom_v_diff_ten,
2321 double *mom_w_diff_ten,
2322 double *mom_u_source,
2323 double *mom_v_source,
2324 double *mom_w_source)
2327 for (k=0;k<nPoints;k++)
2332 dmom_u_acc_u[k]=1.0;
2335 dmom_v_acc_v[k]=1.0;
2338 dmom_w_acc_w[k]=1.0;
2341 mass_adv[k*3+0]=
u[k];
2342 mass_adv[k*3+1]=
v[k];
2343 mass_adv[k*3+2]=
w[k];
2345 dmass_adv_u[k*3+0]=1.0;
2346 dmass_adv_v[k*3+1]=1.0;
2347 dmass_adv_w[k*3+2]=1.0;
2350 mom_u_adv[k*3+0]=p[k]/rho;
2351 dmom_u_adv_p[k*3+0]=1.0/rho;
2354 mom_v_adv[k*3+1]=p[k]/rho;
2355 dmom_v_adv_p[k*3+1]=1.0/rho;
2358 mom_w_adv[k*3+2]=p[k]/rho;
2359 dmom_w_adv_p[k*3+2]=1.0/rho;
2362 mom_u_diff_ten[k*9+0] = nu;
2363 mom_u_diff_ten[k*9+4] = nu;
2364 mom_u_diff_ten[k*9+8] = nu;
2367 mom_v_diff_ten[k*9+0] = nu;
2368 mom_v_diff_ten[k*9+4] = nu;
2369 mom_v_diff_ten[k*9+8] = nu;
2372 mom_w_diff_ten[k*9+0] = nu;
2373 mom_w_diff_ten[k*9+4] = nu;
2374 mom_w_diff_ten[k*9+8] = nu;
2377 mom_u_source[k] = -g[0];
2378 mom_v_source[k] = -g[1];
2379 mom_w_source[k] = -g[2];
2392 const double *grad_p,
2396 double *dmom_u_acc_u,
2398 double *dmom_v_acc_v,
2400 double *dmass_adv_u,
2401 double *dmass_adv_v,
2403 double *dmom_u_adv_u,
2404 double *dmom_u_adv_v,
2406 double *dmom_v_adv_u,
2407 double *dmom_v_adv_v,
2408 double *mom_u_diff_ten,
2409 double *mom_v_diff_ten,
2410 double *mom_u_source,
2411 double *mom_v_source,
2413 double *dmom_u_ham_grad_p,
2415 double *dmom_v_ham_grad_p)
2419 for (k=0;k<nPoints;k++)
2428 dmom_u_acc_u[k]=1.0;
2432 dmom_v_acc_v[k]=1.0;
2435 mass_adv[k*2+0]=
u[k];
2436 mass_adv[k*2+1]=
v[k];
2438 dmass_adv_u[k*2+0]=1.0;
2439 dmass_adv_v[k*2+1]=1.0;
2442 mom_u_adv[k*2+0]=
u[k]*
u[k];
2443 mom_u_adv[k*2+1]=
u[k]*
v[k];
2445 dmom_u_adv_u[k*2+0]=2.0*
u[k];
2446 dmom_u_adv_u[k*2+1]=
v[k];
2448 dmom_u_adv_v[k*2+1]=
u[k];
2451 mom_v_adv[k*2+0]=
v[k]*
u[k];
2452 mom_v_adv[k*2+1]=
v[k]*
v[k];
2454 dmom_v_adv_u[k*2+0]=
v[k];
2456 dmom_v_adv_v[k*2+0]=
u[k];
2457 dmom_v_adv_v[k*2+1]=2.0*
v[k];
2460 mom_u_diff_ten[k*4+0] = nu;
2461 mom_u_diff_ten[k*4+3] = nu;
2464 mom_v_diff_ten[k*4+0] = nu;
2465 mom_v_diff_ten[k*4+3] = nu;
2468 mom_u_source[k] = -g[0];
2469 mom_v_source[k] = -g[1];
2472 mom_u_ham[k] = grad_p[k*2+0]/rho;
2473 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2476 mom_v_ham[k] = grad_p[k*2+1]/rho;
2477 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2482 const double eps_rho,
2483 const double eps_mu,
2492 const double* kappa,
2494 const double *grad_p,
2498 double *dmom_u_acc_u,
2500 double *dmom_v_acc_v,
2502 double *dmass_adv_u,
2503 double *dmass_adv_v,
2505 double *dmom_u_adv_u,
2506 double *dmom_u_adv_v,
2508 double *dmom_v_adv_u,
2509 double *dmom_v_adv_v,
2510 double *mom_u_diff_ten,
2511 double *mom_v_diff_ten,
2512 double *mom_uv_diff_ten,
2513 double *mom_vu_diff_ten,
2514 double *mom_u_source,
2515 double *mom_v_source,
2517 double *dmom_u_ham_grad_p,
2519 double *dmom_v_ham_grad_p)
2522 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
2523 for (k=0;k<nPoints;k++)
2607 dmom_u_acc_u[k]=1.0;
2611 dmom_v_acc_v[k]=1.0;
2614 mass_adv[k*2+0]=
u[k];
2615 mass_adv[k*2+1]=
v[k];
2617 dmass_adv_u[k*2+0]=1.0;
2618 dmass_adv_v[k*2+1]=1.0;
2621 mom_u_adv[k*2+0]=
u[k]*
u[k];
2622 mom_u_adv[k*2+1]=
u[k]*
v[k];
2624 dmom_u_adv_u[k*2+0]=2.0*
u[k];
2625 dmom_u_adv_u[k*2+1]=
v[k];
2627 dmom_u_adv_v[k*2+1]=
u[k];
2630 mom_v_adv[k*2+0]=
v[k]*
u[k];
2631 mom_v_adv[k*2+1]=
v[k]*
v[k];
2633 dmom_v_adv_u[k*2+0]=
v[k];
2635 dmom_v_adv_v[k*2+0]=
u[k];
2636 dmom_v_adv_v[k*2+1]=2.0*
v[k];
2638 #ifdef SCALAR_DIFFUSION
2640 mom_u_diff_ten[k*4+0] = nu;
2641 mom_u_diff_ten[k*4+3] = nu;
2644 mom_v_diff_ten[k*4+0] = nu;
2645 mom_v_diff_ten[k*4+3] = nu;
2648 mom_u_diff_ten[k*4+0] = 2.0*nu;
2649 mom_u_diff_ten[k*4+3] = nu;
2650 mom_uv_diff_ten[k*4+2]=nu;
2653 mom_v_diff_ten[k*4+0] = nu;
2654 mom_v_diff_ten[k*4+3] = 2.0*nu;
2655 mom_vu_diff_ten[k*4+1] = nu;
2661 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
2662 mom_u_source[k] = -g[0] - d_mu*sigma*kappa[k]*
n[k*2+0]/(rho*(norm_n+1.0e-8));
2663 mom_v_source[k] = -g[1] - d_mu*sigma*kappa[k]*
n[k*2+1]/(rho*(norm_n+1.0e-8));
2667 mom_u_ham[k] = grad_p[k*2+0]/rho;
2668 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2671 mom_v_ham[k] = grad_p[k*2+1]/rho;
2672 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2678 const double eps_rho,
2679 const double eps_mu,
2688 const double* kappa,
2690 const double *grad_p,
2694 double *dmom_u_acc_u,
2696 double *dmom_v_acc_v,
2698 double *dmass_adv_u,
2699 double *dmass_adv_v,
2701 double *dmom_u_adv_u,
2702 double *dmom_u_adv_v,
2704 double *dmom_v_adv_u,
2705 double *dmom_v_adv_v,
2706 double *mom_u_diff_ten,
2707 double *mom_v_diff_ten,
2708 double *mom_uv_diff_ten,
2709 double *mom_vu_diff_ten,
2710 double *mom_u_source,
2711 double *mom_v_source,
2713 double *dmom_u_ham_grad_p,
2715 double *dmom_v_ham_grad_p)
2718 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
2719 for (k=0;k<nPoints;k++)
2733 dmom_u_acc_u[k]=1.0;
2737 dmom_v_acc_v[k]=1.0;
2740 mass_adv[k*2+0]=
u[k];
2741 mass_adv[k*2+1]=
v[k];
2743 dmass_adv_u[k*2+0]=1.0;
2744 dmass_adv_v[k*2+1]=1.0;
2747 mom_u_adv[k*2+0]=
u[k]*
u[k];
2748 mom_u_adv[k*2+1]=
u[k]*
v[k];
2750 dmom_u_adv_u[k*2+0]=2.0*
u[k];
2751 dmom_u_adv_u[k*2+1]=
v[k];
2753 dmom_u_adv_v[k*2+1]=
u[k];
2756 mom_v_adv[k*2+0]=
v[k]*
u[k];
2757 mom_v_adv[k*2+1]=
v[k]*
v[k];
2759 dmom_v_adv_u[k*2+0]=
v[k];
2761 dmom_v_adv_v[k*2+0]=
u[k];
2762 dmom_v_adv_v[k*2+1]=2.0*
v[k];
2765 mom_u_diff_ten[k*2+0] = 2.0*nu;
2766 mom_u_diff_ten[k*2+1] = nu;
2767 mom_uv_diff_ten[k]=nu;
2770 mom_v_diff_ten[k*2+0] = nu;
2771 mom_v_diff_ten[k*2+1] = 2.0*nu;
2772 mom_vu_diff_ten[k] = nu;
2781 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
2782 mom_u_source[k] = -g[0] - d_mu*sigma*kappa[k]*
n[k*2+0]/(rho*(norm_n+1.0e-8));
2783 mom_v_source[k] = -g[1] - d_mu*sigma*kappa[k]*
n[k*2+1]/(rho*(norm_n+1.0e-8));
2786 mom_u_ham[k] = grad_p[k*2+0]/rho;
2787 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2790 mom_v_ham[k] = grad_p[k*2+1]/rho;
2791 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2854 const double eps_rho,
2855 const double eps_mu,
2866 const double* kappa,
2867 const double* phi_s,
2870 const double *grad_p,
2874 double *dmom_u_acc_u,
2876 double *dmom_v_acc_v,
2878 double *dmass_adv_u,
2879 double *dmass_adv_v,
2881 double *dmom_u_adv_u,
2882 double *dmom_u_adv_v,
2884 double *dmom_v_adv_u,
2885 double *dmom_v_adv_v,
2886 double *mom_u_diff_ten,
2887 double *mom_v_diff_ten,
2888 double *mom_uv_diff_ten,
2889 double *mom_vu_diff_ten,
2890 double *mom_u_source,
2891 double *dmom_u_source_u,
2892 double *dmom_u_source_v,
2893 double *mom_v_source,
2894 double *dmom_v_source_u,
2895 double *dmom_v_source_v,
2897 double *dmom_u_ham_grad_p,
2899 double *dmom_v_ham_grad_p)
2902 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,
2903 H_rho_s,d_rho_s,H_mu_s,d_mu_s,norm_n,norm_n_s;
2904 for (k=0;k<nPoints;k++)
2929 mom_u_acc[k]=rho*
u[k];
2930 dmom_u_acc_u[k]=rho;
2933 mom_v_acc[k]=rho*
v[k];
2934 dmom_v_acc_v[k]=rho;
2937 mass_adv[k*2+0]=
u[k];
2938 mass_adv[k*2+1]=
v[k];
2940 dmass_adv_u[k*2+0]=1.0;
2941 dmass_adv_v[k*2+1]=1.0;
2944 mom_u_adv[k*2+0]=rho*
u[k]*
u[k];
2945 mom_u_adv[k*2+1]=rho*
u[k]*
v[k];
2947 dmom_u_adv_u[k*2+0]=2.0*rho*
u[k];
2948 dmom_u_adv_u[k*2+1]=rho*
v[k];
2950 dmom_u_adv_v[k*2+1]=rho*
u[k];
2953 mom_v_adv[k*2+0]=rho*
v[k]*
u[k];
2954 mom_v_adv[k*2+1]=rho*
v[k]*
v[k];
2956 dmom_v_adv_u[k*2+0]=rho*
v[k];
2958 dmom_v_adv_v[k*2+0]=rho*
u[k];
2959 dmom_v_adv_v[k*2+1]=2.0*rho*
v[k];
2962 mom_u_diff_ten[k*4+0] = 2.0*mu;
2963 mom_u_diff_ten[k*4+3] = mu;
2964 mom_uv_diff_ten[k*4+2]=mu;
2967 mom_v_diff_ten[k*4+0] = mu;
2968 mom_v_diff_ten[k*4+3] = 2.0*mu;
2969 mom_vu_diff_ten[k*4+1] = mu;
2972 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
2973 norm_n_s = sqrt(n_s[k*2+0]*n_s[k*2+0]+n_s[k*2+1]*n_s[k*2+1]);
3031 mom_u_source[k] = -rho*g[0];
3032 dmom_u_source_u[k] = 0.0;
3033 dmom_u_source_v[k] = 0.0;
3035 mom_v_source[k] = -rho*g[1];
3036 dmom_v_source_u[k] = 0.0;
3037 dmom_v_source_v[k] = 0.0;
3041 mom_u_ham[k] = grad_p[k*2+0];
3042 dmom_u_ham_grad_p[k*2+0]=1.0;
3045 mom_v_ham[k] = grad_p[k*2+1];
3046 dmom_v_ham_grad_p[k*2+1]=1.0;
3051 const double boundaryPenaltyCoef,
3052 const double volumePenaltyCoef,
3053 const double eps_rho,
3054 const double eps_mu,
3065 const double* kappa,
3066 const double* phi_s,
3069 const double *grad_p,
3073 double *dmom_u_acc_u,
3075 double *dmom_v_acc_v,
3077 double *dmass_adv_u,
3078 double *dmass_adv_v,
3080 double *dmom_u_adv_u,
3081 double *dmom_u_adv_v,
3083 double *dmom_v_adv_u,
3084 double *dmom_v_adv_v,
3085 double *mom_u_diff_ten,
3086 double *mom_v_diff_ten,
3087 double *mom_uv_diff_ten,
3088 double *mom_vu_diff_ten,
3089 double *mom_u_source,
3090 double *dmom_u_source_u,
3091 double *dmom_u_source_v,
3092 double *mom_v_source,
3093 double *dmom_v_source_u,
3094 double *dmom_v_source_v,
3096 double *dmom_u_ham_grad_p,
3098 double *dmom_v_ham_grad_p)
3101 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,
3102 H_rho_s,d_rho_s,H_mu_s,d_mu_s,norm_n,norm_n_s,volumeFlux,sp;
3103 int quadraticPenalty = 0,sipgPenalty=1.0;
3104 sp=(double)(sipgPenalty);
3106 for (k=0;k<nPoints;k++)
3123 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
3124 norm_n_s = sqrt(n_s[k*2+0]*n_s[k*2+0]+n_s[k*2+1]*n_s[k*2+1]);
3133 mom_u_acc[k]=H_mu_s*rho*
u[k];
3134 dmom_u_acc_u[k]=H_mu_s*rho;
3137 mom_v_acc[k]=H_mu_s*rho*
v[k];
3138 dmom_v_acc_v[k]=H_mu_s*rho;
3142 mass_adv[k*2+0]=
u[k];
3143 mass_adv[k*2+1]=
v[k];
3145 dmass_adv_u[k*2+0]=1.0;
3146 dmass_adv_v[k*2+1]=1.0;
3150 mom_u_adv[k*2+0]=H_mu_s*rho*
u[k]*
u[k] - sp*(
u[k]-0.0)*d_mu_s*n_s[k*2+0]/norm_n_s;
3151 mom_u_adv[k*2+1]=H_mu_s*rho*
u[k]*
v[k] - sp*(
u[k]-0.0)*d_mu_s*n_s[k*2+1]/norm_n_s;
3153 dmom_u_adv_u[k*2+0]=2.0*H_mu_s*rho*
u[k] - sp*d_mu_s*n_s[k*2+0]/norm_n_s;
3154 dmom_u_adv_u[k*2+1]=H_mu_s*rho*
v[k] - sp*d_mu_s*n_s[k*2+1]/norm_n_s;
3156 dmom_u_adv_v[k*2+1]=H_mu_s*rho*
u[k];
3159 mom_v_adv[k*2+0]=H_mu_s*rho*
v[k]*
u[k] - sp*(
v[k]-0.0)*d_mu_s*n_s[k*2+0]/norm_n_s;
3160 mom_v_adv[k*2+1]=H_mu_s*rho*
v[k]*
v[k] - sp*(
v[k]-0.0)*d_mu_s*n_s[k*2+1]/norm_n_s;
3162 dmom_v_adv_u[k*2+0]=H_mu_s*rho*
v[k];
3164 dmom_v_adv_v[k*2+0]=H_mu_s*rho*
u[k] - sp*d_mu_s*n_s[k*2+0]/norm_n_s;
3165 dmom_v_adv_v[k*2+1]=2.0*H_mu_s*rho*
v[k] - sp*d_mu_s*n_s[k*2+1]/norm_n_s;
3170 mom_u_diff_ten[k*4+0] = 2.0*H_mu_s*mu;
3171 mom_u_diff_ten[k*4+3] = H_mu_s*mu;
3172 mom_uv_diff_ten[k*4+2]=H_mu_s*mu;
3175 mom_v_diff_ten[k*4+0] = H_mu_s*mu;
3176 mom_v_diff_ten[k*4+3] = 2.0*H_mu_s*mu;
3177 mom_vu_diff_ten[k*4+1] = H_mu_s*mu;
3192 if (quadraticPenalty)
3194 mom_u_source[k] = -H_mu_s*rho*g[0]
3195 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+0]/norm_n
3196 +boundaryPenaltyCoef*rho*d_mu_s*(
u[k] - 0.0)
3197 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
u[k] - 0.0)*(
u[k] - 0.0);
3199 dmom_u_source_u[k] = boundaryPenaltyCoef*rho*d_mu_s
3200 +volumePenaltyCoef*rho*(1.0-H_mu_s)*2.0*(
u[k]-0.0);
3201 dmom_u_source_v[k] = 0.0;
3203 mom_v_source[k] = -H_mu_s*rho*g[1]
3204 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+1]/norm_n
3205 +boundaryPenaltyCoef*rho*d_mu_s*(
v[k] - 0.0)
3206 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
v[k] - 0.0)*(
v[k] - 0.0);
3208 dmom_v_source_u[k] = 0.0;
3209 dmom_v_source_v[k] = boundaryPenaltyCoef*rho*d_mu_s
3210 +volumePenaltyCoef*rho*(1.0-H_mu_s)*2.0*(
v[k] - 0.0);
3212 else if (sipgPenalty)
3214 mom_u_source[k] = -H_mu_s*rho*g[0]
3215 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+0]/norm_n
3216 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
u[k] - 0.0);
3218 dmom_u_source_u[k] = volumePenaltyCoef*rho*(1.0-H_mu_s);
3219 dmom_u_source_v[k] = 0.0;
3221 mom_v_source[k] = -H_mu_s*rho*g[1]
3222 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+1]/norm_n
3223 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
v[k] - 0.0);
3225 dmom_v_source_u[k] = 0.0;
3226 dmom_v_source_v[k] = volumePenaltyCoef*rho*(1.0-H_mu_s);
3228 volumeFlux =
u[k]*n_s[k*2+0] +
v[k]*n_s[k*2+1];
3229 if (volumeFlux < 0.0)
3231 mom_u_source[k] += rho*d_mu_s*
u[k]*(
u[k]*n_s[k*2+0] +
v[k]*n_s[k*2+1])/norm_n_s;
3233 dmom_u_source_u[k] += rho*d_mu_s*(2.0*
u[k]*n_s[k*2+0]
3234 +
v[k]*n_s[k*2+1])/norm_n_s;
3236 dmom_u_source_v[k] = rho*d_mu_s*
u[k]*n_s[k*2+1]/norm_n_s;
3238 mom_v_source[k] += rho*d_mu_s*(
v[k]*
u[k]*n_s[k*2+0]
3239 +
v[k]*
v[k]*n_s[k*2+1])/norm_n_s;
3241 dmom_v_source_u[k] += rho*d_mu_s*
v[k]*n_s[k*2+0]/norm_n_s;
3243 dmom_v_source_v[k] += rho*d_mu_s*(
u[k]*n_s[k*2+0]
3244 + 2.0*
v[k]*n_s[k*2+1])/norm_n_s;
3249 mom_u_source[k] = -H_mu_s*rho*g[0]
3250 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+0]/norm_n
3251 +boundaryPenaltyCoef*rho*d_mu_s*(
u[k] - 0.0)
3252 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
u[k] - 0.0);
3254 dmom_u_source_u[k] = boundaryPenaltyCoef*rho*d_mu_s
3255 +volumePenaltyCoef*rho*(1.0-H_mu_s);
3256 dmom_u_source_v[k] = 0.0;
3258 mom_v_source[k] = -H_mu_s*rho*g[1]
3259 - H_mu_s*d_mu*sigma*kappa[k]*
n[k*2+1]/norm_n
3260 +boundaryPenaltyCoef*rho*d_mu_s*(
v[k] - 0.0)
3261 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
v[k] - 0.0);
3263 dmom_v_source_u[k] = 0.0;
3264 dmom_v_source_v[k] = boundaryPenaltyCoef*rho*d_mu_s
3265 +volumePenaltyCoef*rho*(1.0-H_mu_s);
3270 mom_u_ham[k] = grad_p[k*2+0];
3271 dmom_u_ham_grad_p[k*2+0]=1.0;
3274 mom_v_ham[k] = grad_p[k*2+1];
3275 dmom_v_ham_grad_p[k*2+1]=1.0;
3280 const double eps_rho,
3281 const double eps_mu,
3290 const double* kappa,
3292 const double *grad_p,
3297 double *dmom_u_acc_u,
3299 double *dmom_v_acc_v,
3301 double *dmom_w_acc_w,
3303 double *dmass_adv_u,
3304 double *dmass_adv_v,
3305 double *dmass_adv_w,
3307 double *dmom_u_adv_u,
3308 double *dmom_u_adv_v,
3309 double *dmom_u_adv_w,
3311 double *dmom_v_adv_u,
3312 double *dmom_v_adv_v,
3313 double *dmom_v_adv_w,
3315 double *dmom_w_adv_u,
3316 double *dmom_w_adv_v,
3317 double *dmom_w_adv_w,
3318 double *mom_u_diff_ten,
3319 double *mom_v_diff_ten,
3320 double *mom_w_diff_ten,
3321 double *mom_uv_diff_ten,
3322 double *mom_uw_diff_ten,
3323 double *mom_vu_diff_ten,
3324 double *mom_vw_diff_ten,
3325 double *mom_wu_diff_ten,
3326 double *mom_wv_diff_ten,
3327 double *mom_u_source,
3328 double *mom_v_source,
3329 double *mom_w_source,
3331 double *dmom_u_ham_grad_p,
3333 double *dmom_v_ham_grad_p,
3335 double *dmom_w_ham_grad_p)
3338 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
3339 for (k=0;k<nPoints;k++)
3462 dmom_u_acc_u[k]=1.0;
3466 dmom_v_acc_v[k]=1.0;
3470 dmom_w_acc_w[k]=1.0;
3474 mass_adv[k*3+0]=
u[k];
3475 mass_adv[k*3+1]=
v[k];
3476 mass_adv[k*3+2]=
w[k];
3478 dmass_adv_u[k*3+0]=1.0;
3479 dmass_adv_v[k*3+1]=1.0;
3480 dmass_adv_w[k*3+2]=1.0;
3483 mom_u_adv[k*3+0]=
u[k]*
u[k];
3484 mom_u_adv[k*3+1]=
u[k]*
v[k];
3485 mom_u_adv[k*3+2]=
u[k]*
w[k];
3487 dmom_u_adv_u[k*3+0]=2.0*
u[k];
3488 dmom_u_adv_u[k*3+1]=
v[k];
3489 dmom_u_adv_u[k*3+2]=
w[k];
3491 dmom_u_adv_v[k*3+1]=
u[k];
3493 dmom_u_adv_w[k*3+2]=
u[k];
3496 mom_v_adv[k*3+0]=
v[k]*
u[k];
3497 mom_v_adv[k*3+1]=
v[k]*
v[k];
3498 mom_v_adv[k*3+2]=
v[k]*
w[k];
3500 dmom_v_adv_u[k*3+0]=
v[k];
3502 dmom_v_adv_w[k*3+2]=
v[k];
3504 dmom_v_adv_v[k*3+0]=
u[k];
3505 dmom_v_adv_v[k*3+1]=2.0*
v[k];
3506 dmom_v_adv_v[k*3+2]=
w[k];
3509 mom_w_adv[k*3+0]=
w[k]*
u[k];
3510 mom_w_adv[k*3+1]=
w[k]*
v[k];
3511 mom_w_adv[k*3+2]=
w[k]*
w[k];
3513 dmom_w_adv_u[k*3+0]=
w[k];
3515 dmom_w_adv_v[k*3+1]=
w[k];
3517 dmom_w_adv_w[k*3+0]=
u[k];
3518 dmom_w_adv_w[k*3+1]=
v[k];
3519 dmom_w_adv_w[k*3+2]=2.0*
w[k];
3522 mom_u_diff_ten[k*9+0] = 2.0*nu;
3523 mom_u_diff_ten[k*9+4] = nu;
3524 mom_u_diff_ten[k*9+8] = nu;
3526 mom_uv_diff_ten[k*9+3]=nu;
3528 mom_uw_diff_ten[k*9+6]=nu;
3531 mom_v_diff_ten[k*9+0] = nu;
3532 mom_v_diff_ten[k*9+4] = 2.0*nu;
3533 mom_v_diff_ten[k*9+8] = nu;
3535 mom_vu_diff_ten[k*9+1]=nu;
3537 mom_vw_diff_ten[k*9+7]=nu;
3540 mom_w_diff_ten[k*9+0] = nu;
3541 mom_w_diff_ten[k*9+4] = nu;
3542 mom_w_diff_ten[k*9+8] = 2.0*nu;
3544 mom_wu_diff_ten[k*9+2]=nu;
3546 mom_wv_diff_ten[k*9+5]=nu;
3549 norm_n = sqrt(
n[k*3+0]*
n[k*3+0]+
n[k*3+1]*
n[k*3+1]+
n[k*3+2]*
n[k*3+2]);
3550 mom_u_source[k] = -g[0] - d_mu*sigma*kappa[k]*
n[k*3+0]/(rho*(norm_n+1.0e-8));
3551 mom_v_source[k] = -g[1] - d_mu*sigma*kappa[k]*
n[k*3+1]/(rho*(norm_n+1.0e-8));
3552 mom_w_source[k] = -g[2] - d_mu*sigma*kappa[k]*
n[k*3+2]/(rho*(norm_n+1.0e-8));
3556 mom_u_ham[k] = grad_p[k*3+0]/rho;
3557 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
3560 mom_v_ham[k] = grad_p[k*3+1]/rho;
3561 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
3564 mom_w_ham[k] = grad_p[k*3+2]/rho;
3565 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
3569 const double eps_rho,
3570 const double eps_mu,
3579 const double* kappa,
3581 const double *grad_p,
3586 double *dmom_u_acc_u,
3588 double *dmom_v_acc_v,
3590 double *dmom_w_acc_w,
3592 double *dmass_adv_u,
3593 double *dmass_adv_v,
3594 double *dmass_adv_w,
3596 double *dmom_u_adv_u,
3597 double *dmom_u_adv_v,
3598 double *dmom_u_adv_w,
3600 double *dmom_v_adv_u,
3601 double *dmom_v_adv_v,
3602 double *dmom_v_adv_w,
3604 double *dmom_w_adv_u,
3605 double *dmom_w_adv_v,
3606 double *dmom_w_adv_w,
3607 double *mom_u_diff_ten,
3608 double *mom_v_diff_ten,
3609 double *mom_w_diff_ten,
3610 double *mom_uv_diff_ten,
3611 double *mom_uw_diff_ten,
3612 double *mom_vu_diff_ten,
3613 double *mom_vw_diff_ten,
3614 double *mom_wu_diff_ten,
3615 double *mom_wv_diff_ten,
3616 double *mom_u_source,
3617 double *mom_v_source,
3618 double *mom_w_source,
3620 double *dmom_u_ham_grad_p,
3622 double *dmom_v_ham_grad_p,
3624 double *dmom_w_ham_grad_p)
3627 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
3628 for (k=0;k<nPoints;k++)
3643 dmom_u_acc_u[k]=1.0;
3647 dmom_v_acc_v[k]=1.0;
3651 dmom_w_acc_w[k]=1.0;
3655 mass_adv[k*3+0]=
u[k];
3656 mass_adv[k*3+1]=
v[k];
3657 mass_adv[k*3+2]=
w[k];
3659 dmass_adv_u[k*3+0]=1.0;
3660 dmass_adv_v[k*3+1]=1.0;
3661 dmass_adv_w[k*3+2]=1.0;
3664 mom_u_adv[k*3+0]=
u[k]*
u[k];
3665 mom_u_adv[k*3+1]=
u[k]*
v[k];
3666 mom_u_adv[k*3+2]=
u[k]*
w[k];
3668 dmom_u_adv_u[k*3+0]=2.0*
u[k];
3669 dmom_u_adv_u[k*3+1]=
v[k];
3670 dmom_u_adv_u[k*3+2]=
w[k];
3672 dmom_u_adv_v[k*3+1]=
u[k];
3674 dmom_u_adv_w[k*3+2]=
u[k];
3677 mom_v_adv[k*3+0]=
v[k]*
u[k];
3678 mom_v_adv[k*3+1]=
v[k]*
v[k];
3679 mom_v_adv[k*3+2]=
v[k]*
w[k];
3681 dmom_v_adv_u[k*3+0]=
v[k];
3683 dmom_v_adv_w[k*3+2]=
v[k];
3685 dmom_v_adv_v[k*3+0]=
u[k];
3686 dmom_v_adv_v[k*3+1]=2.0*
v[k];
3687 dmom_v_adv_v[k*3+2]=
w[k];
3690 mom_w_adv[k*3+0]=
w[k]*
u[k];
3691 mom_w_adv[k*3+1]=
w[k]*
v[k];
3692 mom_w_adv[k*3+2]=
w[k]*
w[k];
3694 dmom_w_adv_u[k*3+0]=
w[k];
3696 dmom_w_adv_v[k*3+1]=
w[k];
3698 dmom_w_adv_w[k*3+0]=
u[k];
3699 dmom_w_adv_w[k*3+1]=
v[k];
3700 dmom_w_adv_w[k*3+2]=2.0*
w[k];
3703 mom_u_diff_ten[k*3+0] = 2.0*nu;
3704 mom_u_diff_ten[k*3+1] = nu;
3705 mom_u_diff_ten[k*3+2] = nu;
3707 mom_uv_diff_ten[k]=nu;
3709 mom_uw_diff_ten[k]=nu;
3712 mom_v_diff_ten[k*3+0] = nu;
3713 mom_v_diff_ten[k*3+1] = 2.0*nu;
3714 mom_v_diff_ten[k*3+2] = nu;
3716 mom_vu_diff_ten[k]=nu;
3718 mom_vw_diff_ten[k]=nu;
3721 mom_w_diff_ten[k*3+0] = nu;
3722 mom_w_diff_ten[k*3+1] = nu;
3723 mom_w_diff_ten[k*3+2] = 2.0*nu;
3725 mom_wu_diff_ten[k]=nu;
3727 mom_wv_diff_ten[k]=nu;
3730 norm_n = sqrt(
n[k*3+0]*
n[k*3+0]+
n[k*3+1]*
n[k*3+1]+
n[k*3+2]*
n[k*3+2]);
3731 mom_u_source[k] = -g[0] - d_mu*sigma*kappa[k]*
n[k*3+0]/(rho*(norm_n+1.0e-8));
3732 mom_v_source[k] = -g[1] - d_mu*sigma*kappa[k]*
n[k*3+1]/(rho*(norm_n+1.0e-8));
3733 mom_w_source[k] = -g[2] - d_mu*sigma*kappa[k]*
n[k*3+2]/(rho*(norm_n+1.0e-8));
3737 mom_u_ham[k] = grad_p[k*3+0]/rho;
3738 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
3741 mom_v_ham[k] = grad_p[k*3+1]/rho;
3742 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
3745 mom_w_ham[k] = grad_p[k*3+2]/rho;
3746 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
3750 const double boundaryPenaltyCoef,
3751 const double volumePenaltyCoef,
3752 const double eps_rho,
3753 const double eps_mu,
3764 const double* kappa,
3765 const double* phi_s,
3768 const double *grad_p,
3773 double *dmom_u_acc_u,
3775 double *dmom_v_acc_v,
3777 double *dmom_w_acc_w,
3779 double *dmass_adv_u,
3780 double *dmass_adv_v,
3781 double *dmass_adv_w,
3783 double *dmom_u_adv_u,
3784 double *dmom_u_adv_v,
3785 double *dmom_u_adv_w,
3787 double *dmom_v_adv_u,
3788 double *dmom_v_adv_v,
3789 double *dmom_v_adv_w,
3791 double *dmom_w_adv_u,
3792 double *dmom_w_adv_v,
3793 double *dmom_w_adv_w,
3794 double *mom_u_diff_ten,
3795 double *mom_v_diff_ten,
3796 double *mom_w_diff_ten,
3797 double *mom_uv_diff_ten,
3798 double *mom_uw_diff_ten,
3799 double *mom_vu_diff_ten,
3800 double *mom_vw_diff_ten,
3801 double *mom_wu_diff_ten,
3802 double *mom_wv_diff_ten,
3803 double *mom_u_source,
3804 double *dmom_u_source_u,
3805 double *dmom_u_source_v,
3806 double *dmom_u_source_w,
3807 double *mom_v_source,
3808 double *dmom_v_source_u,
3809 double *dmom_v_source_v,
3810 double *dmom_v_source_w,
3811 double *mom_w_source,
3812 double *dmom_w_source_u,
3813 double *dmom_w_source_v,
3814 double *dmom_w_source_w,
3816 double *dmom_u_ham_grad_p,
3818 double *dmom_v_ham_grad_p,
3820 double *dmom_w_ham_grad_p)
3823 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,
3824 H_rho_s,d_rho_s,H_mu_s,d_mu_s,norm_n,norm_n_s;
3826 for (k=0;k<nPoints;k++)
3844 rho = rho_s*(1.0-H_rho_s)+rho*H_rho_s;
3845 nu = nu_s*(1.0-H_mu_s)+nu*H_mu_s;
3846 mu = rho_s*nu_s*(1.0-H_mu_s)+rho*nu*H_mu_s;
3849 mom_u_acc[k]=H_mu_s*rho*
u[k];
3850 dmom_u_acc_u[k]=H_mu_s*rho;
3853 mom_v_acc[k]=H_mu_s*rho*
v[k];
3854 dmom_v_acc_v[k]=H_mu_s*rho;
3857 mom_w_acc[k]=H_mu_s*rho*
w[k];
3858 dmom_w_acc_w[k]=H_mu_s*rho;
3862 mass_adv[k*3+0]=
u[k];
3863 mass_adv[k*3+1]=
v[k];
3864 mass_adv[k*3+2]=
w[k];
3866 dmass_adv_u[k*3+0]=1.0;
3867 dmass_adv_v[k*3+1]=1.0;
3868 dmass_adv_w[k*3+2]=1.0;
3871 mom_u_adv[k*3+0]=H_mu_s*rho*
u[k]*
u[k];
3872 mom_u_adv[k*3+1]=H_mu_s*rho*
u[k]*
v[k];
3873 mom_u_adv[k*3+2]=H_mu_s*rho*
u[k]*
w[k];
3875 dmom_u_adv_u[k*3+0]=2.0*H_mu_s*rho*
u[k];
3876 dmom_u_adv_u[k*3+1]=H_mu_s*rho*
v[k];
3877 dmom_u_adv_u[k*3+2]=H_mu_s*rho*
w[k];
3879 dmom_u_adv_v[k*3+1]=H_mu_s*rho*
u[k];
3881 dmom_u_adv_w[k*3+2]=H_mu_s*rho*
u[k];
3884 mom_v_adv[k*3+0]=H_mu_s*rho*
v[k]*
u[k];
3885 mom_v_adv[k*3+1]=H_mu_s*rho*
v[k]*
v[k];
3886 mom_v_adv[k*3+2]=H_mu_s*rho*
v[k]*
w[k];
3888 dmom_v_adv_u[k*3+0]=H_mu_s*rho*
v[k];
3890 dmom_v_adv_w[k*3+2]=H_mu_s*rho*
v[k];
3892 dmom_v_adv_v[k*3+0]=H_mu_s*rho*
u[k];
3893 dmom_v_adv_v[k*3+1]=2.0*H_mu_s*rho*
v[k];
3894 dmom_v_adv_v[k*3+2]=H_mu_s*rho*
w[k];
3897 mom_w_adv[k*3+0]=H_mu_s*rho*
w[k]*
u[k];
3898 mom_w_adv[k*3+1]=H_mu_s*rho*
w[k]*
v[k];
3899 mom_w_adv[k*3+2]=H_mu_s*rho*
w[k]*
w[k];
3901 dmom_w_adv_u[k*3+0]=H_mu_s*rho*
w[k];
3903 dmom_w_adv_v[k*3+1]=H_mu_s*rho*
w[k];
3905 dmom_w_adv_w[k*3+0]=H_mu_s*rho*
u[k];
3906 dmom_w_adv_w[k*3+1]=H_mu_s*rho*
v[k];
3907 dmom_w_adv_w[k*3+2]=2.0*H_mu_s*rho*
w[k];
3910 mom_u_diff_ten[k*9+0] = 2.0*H_mu_s*mu;
3911 mom_u_diff_ten[k*9+4] = H_mu_s*mu;
3912 mom_u_diff_ten[k*9+8] = H_mu_s*mu;
3914 mom_uv_diff_ten[k*9+3]=H_mu_s*mu;
3916 mom_uw_diff_ten[k*9+6]=H_mu_s*mu;
3919 mom_v_diff_ten[k*9+0] = H_mu_s*mu;
3920 mom_v_diff_ten[k*9+4] = 2.0*H_mu_s*mu;
3921 mom_v_diff_ten[k*9+8] = H_mu_s*mu;
3923 mom_vu_diff_ten[k*9+1]=H_mu_s*mu;
3925 mom_vw_diff_ten[k*9+7]=H_mu_s*mu;
3928 mom_w_diff_ten[k*9+0] = H_mu_s*mu;
3929 mom_w_diff_ten[k*9+4] = H_mu_s*mu;
3930 mom_w_diff_ten[k*9+8] = 2.0*H_mu_s*mu;
3932 mom_wu_diff_ten[k*9+2]=H_mu_s*mu;
3934 mom_wv_diff_ten[k*9+5]=H_mu_s*mu;
3937 norm_n = sqrt(
n[k*3+0]*
n[k*3+0]+
n[k*3+1]*
n[k*3+1]+
n[k*3+2]*
n[k*3+2]);
3938 mom_u_source[k] = -H_mu_s*rho*g[0] - H_mu_s*d_mu*sigma*kappa[k]*
n[k*3+0]/(norm_n)
3939 +boundaryPenaltyCoef*rho*d_mu_s*(
u[k] - 0.0)
3940 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
u[k] - 0.0);
3942 dmom_u_source_u[k] = boundaryPenaltyCoef*rho*d_mu_s
3943 +volumePenaltyCoef*rho*(1.0-H_mu_s);
3944 dmom_u_source_v[k] = 0.0;
3945 dmom_u_source_w[k] = 0.0;
3947 mom_v_source[k] = -H_mu_s*rho*g[1] - H_mu_s*d_mu*sigma*kappa[k]*
n[k*3+1]/(norm_n)
3948 +boundaryPenaltyCoef*rho*d_mu_s*(
v[k] - 0.0)
3949 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
v[k] - 0.0);
3951 dmom_v_source_u[k] = 0.0;
3952 dmom_v_source_v[k] = boundaryPenaltyCoef*rho*d_mu_s
3953 +volumePenaltyCoef*rho*(1.0-H_mu_s);
3954 dmom_v_source_w[k] = 0.0;
3957 mom_w_source[k] = -H_mu_s*rho*g[2] - H_mu_s*d_mu*sigma*kappa[k]*
n[k*3+2]/(norm_n)
3958 +boundaryPenaltyCoef*rho*d_mu_s*(
w[k] - 0.0)
3959 +volumePenaltyCoef*rho*(1.0-H_mu_s)*(
w[k] - 0.0);
3960 dmom_w_source_u[k] = 0.0;
3961 dmom_w_source_v[k] = 0.0;
3962 dmom_w_source_w[k] = boundaryPenaltyCoef*rho*d_mu_s
3963 +volumePenaltyCoef*rho*(1.0-H_mu_s);
3968 mom_u_ham[k] = grad_p[k*3+0];
3969 dmom_u_ham_grad_p[k*3+0]=1.0;
3972 mom_v_ham[k] = grad_p[k*3+1];
3973 dmom_v_ham_grad_p[k*3+1]=1.0;
3976 mom_w_ham[k] = grad_p[k*3+2];
3977 dmom_w_ham_grad_p[k*3+2]=1.0;
3990 const double *grad_p,
3995 double *dmom_u_acc_u,
3997 double *dmom_v_acc_v,
3999 double *dmom_w_acc_w,
4001 double *dmass_adv_u,
4002 double *dmass_adv_v,
4003 double *dmass_adv_w,
4005 double *dmom_u_adv_u,
4006 double *dmom_u_adv_v,
4007 double *dmom_u_adv_w,
4009 double *dmom_v_adv_u,
4010 double *dmom_v_adv_v,
4011 double *dmom_v_adv_w,
4013 double *dmom_w_adv_u,
4014 double *dmom_w_adv_v,
4015 double *dmom_w_adv_w,
4016 double *mom_u_diff_ten,
4017 double *mom_v_diff_ten,
4018 double *mom_w_diff_ten,
4019 double *mom_u_source,
4020 double *mom_v_source,
4021 double *mom_w_source,
4023 double *dmom_u_ham_grad_p,
4025 double *dmom_v_ham_grad_p,
4027 double *dmom_w_ham_grad_p)
4031 for (k=0;k<nPoints;k++)
4039 dmom_u_acc_u[k]=1.0;
4042 dmom_v_acc_v[k]=1.0;
4045 dmom_w_acc_w[k]=1.0;
4048 mass_adv[k*3+0]=
u[k];
4049 mass_adv[k*3+1]=
v[k];
4050 mass_adv[k*3+2]=
w[k];
4052 dmass_adv_u[k*3+0]=1.0;
4053 dmass_adv_v[k*3+1]=1.0;
4054 dmass_adv_w[k*3+2]=1.0;
4057 mom_u_adv[k*3+0]=
u[k]*
u[k];
4058 mom_u_adv[k*3+1]=
u[k]*
v[k];
4059 mom_u_adv[k*3+2]=
u[k]*
w[k];
4061 dmom_u_adv_u[k*3+0]=2.0*
u[k];
4062 dmom_u_adv_u[k*3+1]=
v[k];
4063 dmom_u_adv_u[k*3+2]=
w[k];
4065 dmom_u_adv_v[k*3+1]=
u[k];
4067 dmom_u_adv_w[k*3+2]=
u[k];
4070 mom_v_adv[k*3+0]=
v[k]*
u[k];
4071 mom_v_adv[k*3+1]=
v[k]*
v[k];
4072 mom_v_adv[k*3+2]=
v[k]*
w[k];
4074 dmom_v_adv_u[k*3+0]=
v[k];
4076 dmom_v_adv_v[k*3+0]=
u[k];
4077 dmom_v_adv_v[k*3+1]=2.0*
v[k];
4078 dmom_v_adv_v[k*3+2]=
w[k];
4080 dmom_v_adv_w[k*3+2]=
v[k];
4083 mom_w_adv[k*3+0]=
w[k]*
u[k];
4084 mom_w_adv[k*3+1]=
w[k]*
v[k];
4085 mom_w_adv[k*3+2]=
w[k]*
w[k];
4087 dmom_w_adv_u[k*3+0]=
w[k];
4089 dmom_w_adv_v[k*3+0]=
w[k];
4091 dmom_w_adv_w[k*3+0]=
u[k];
4092 dmom_w_adv_w[k*3+1]=
v[k];
4093 dmom_w_adv_w[k*3+2]=2.0*
w[k];
4096 mom_u_diff_ten[k*9+0] = nu;
4097 mom_u_diff_ten[k*9+4] = nu;
4098 mom_u_diff_ten[k*9+8] = nu;
4101 mom_v_diff_ten[k*9+0] = nu;
4102 mom_v_diff_ten[k*9+4] = nu;
4103 mom_v_diff_ten[k*9+8] = nu;
4106 mom_w_diff_ten[k*9+0] = nu;
4107 mom_w_diff_ten[k*9+4] = nu;
4108 mom_w_diff_ten[k*9+8] = nu;
4111 mom_u_source[k] = -g[0];
4112 mom_v_source[k] = -g[1];
4113 mom_w_source[k] = -g[2];
4116 mom_u_ham[k] = grad_p[k*3+0]/rho;
4117 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4120 mom_v_ham[k] = grad_p[k*3+1]/rho;
4121 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4124 mom_w_ham[k] = grad_p[k*3+2]/rho;
4125 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4138 const double *grad_p,
4142 double *dmom_u_acc_u,
4144 double *dmom_v_acc_v,
4146 double *dmass_adv_u,
4147 double *dmass_adv_v,
4148 double *mom_u_diff_ten,
4149 double *mom_v_diff_ten,
4150 double *mom_u_source,
4151 double *mom_v_source,
4153 double *dmom_u_ham_grad_p,
4155 double *dmom_v_ham_grad_p)
4159 for (k=0;k<nPoints;k++)
4168 dmom_u_acc_u[k]=1.0;
4172 dmom_v_acc_v[k]=1.0;
4175 mass_adv[k*2+0]=
u[k];
4176 mass_adv[k*2+1]=
v[k];
4178 dmass_adv_u[k*2+0]=1.0;
4179 dmass_adv_v[k*2+1]=1.0;
4182 mom_u_diff_ten[k*4+0] = nu;
4183 mom_u_diff_ten[k*4+3] = nu;
4186 mom_v_diff_ten[k*4+0] = nu;
4187 mom_v_diff_ten[k*4+3] = nu;
4190 mom_u_source[k] = -g[0];
4191 mom_v_source[k] = -g[1];
4194 mom_u_ham[k] = grad_p[k*2+0]/rho;
4195 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4198 mom_v_ham[k] = grad_p[k*2+1]/rho;
4199 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4212 const double *grad_p,
4217 double *dmom_u_acc_u,
4219 double *dmom_v_acc_v,
4221 double *dmom_w_acc_w,
4223 double *dmass_adv_u,
4224 double *dmass_adv_v,
4225 double *dmass_adv_w,
4226 double *mom_u_diff_ten,
4227 double *mom_v_diff_ten,
4228 double *mom_w_diff_ten,
4229 double *mom_u_source,
4230 double *mom_v_source,
4231 double *mom_w_source,
4233 double *dmom_u_ham_grad_p,
4235 double *dmom_v_ham_grad_p,
4237 double *dmom_w_ham_grad_p)
4241 for (k=0;k<nPoints;k++)
4249 dmom_u_acc_u[k]=1.0;
4252 dmom_v_acc_v[k]=1.0;
4255 dmom_w_acc_w[k]=1.0;
4258 mass_adv[k*3+0]=
u[k];
4259 mass_adv[k*3+1]=
v[k];
4260 mass_adv[k*3+2]=
w[k];
4262 dmass_adv_u[k*3+0]=1.0;
4263 dmass_adv_v[k*3+1]=1.0;
4264 dmass_adv_w[k*3+2]=1.0;
4267 mom_u_diff_ten[k*9+0] = nu;
4268 mom_u_diff_ten[k*9+4] = nu;
4269 mom_u_diff_ten[k*9+8] = nu;
4272 mom_v_diff_ten[k*9+0] = nu;
4273 mom_v_diff_ten[k*9+4] = nu;
4274 mom_v_diff_ten[k*9+8] = nu;
4277 mom_w_diff_ten[k*9+0] = nu;
4278 mom_w_diff_ten[k*9+4] = nu;
4279 mom_w_diff_ten[k*9+8] = nu;
4282 mom_u_source[k] = -g[0];
4283 mom_v_source[k] = -g[1];
4284 mom_w_source[k] = -g[2];
4287 mom_u_ham[k] = grad_p[k*3+0]/rho;
4288 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4291 mom_v_ham[k] = grad_p[k*3+1]/rho;
4292 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4295 mom_w_ham[k] = grad_p[k*3+2]/rho;
4296 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4309 const double *grad_p,
4313 double *dmom_u_acc_u,
4315 double *dmom_v_acc_v,
4317 double *dmass_adv_u,
4318 double *dmass_adv_v,
4320 double *dmom_u_adv_u,
4321 double *dmom_u_adv_v,
4323 double *dmom_v_adv_u,
4324 double *dmom_v_adv_v,
4325 double *mom_u_diff_ten,
4326 double *mom_v_diff_ten,
4327 double *mom_u_source,
4328 double *mom_v_source,
4330 double *dmom_u_ham_grad_p,
4332 double *dmom_v_ham_grad_p)
4336 for (k=0;k<nPoints;k++)
4339 H = fmax(0.0,fmin(1.0,vof[k]));
4345 dmom_u_acc_u[k]=1.0;
4349 dmom_v_acc_v[k]=1.0;
4352 mass_adv[k*2+0]=
u[k];
4353 mass_adv[k*2+1]=
v[k];
4355 dmass_adv_u[k*2+0]=1.0;
4356 dmass_adv_v[k*2+1]=1.0;
4359 mom_u_adv[k*2+0]=
u[k]*
u[k];
4360 mom_u_adv[k*2+1]=
u[k]*
v[k];
4362 dmom_u_adv_u[k*2+0]=2.0*
u[k];
4363 dmom_u_adv_u[k*2+1]=
v[k];
4365 dmom_u_adv_v[k*2+1]=
u[k];
4368 mom_v_adv[k*2+0]=
v[k]*
u[k];
4369 mom_v_adv[k*2+1]=
v[k]*
v[k];
4371 dmom_v_adv_u[k*2+0]=
v[k];
4373 dmom_v_adv_v[k*2+0]=
u[k];
4374 dmom_v_adv_v[k*2+1]=2.0*
v[k];
4377 mom_u_diff_ten[k*4+0] = nu;
4378 mom_u_diff_ten[k*4+3] = nu;
4381 mom_v_diff_ten[k*4+0] = nu;
4382 mom_v_diff_ten[k*4+3] = nu;
4385 mom_u_source[k] = -g[0];
4386 mom_v_source[k] = -g[1];
4389 mom_u_ham[k] = grad_p[k*2+0]/rho;
4390 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4393 mom_v_ham[k] = grad_p[k*2+1]/rho;
4394 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4407 const double *grad_p,
4412 double *dmom_u_acc_u,
4414 double *dmom_v_acc_v,
4416 double *dmom_w_acc_w,
4418 double *dmass_adv_u,
4419 double *dmass_adv_v,
4420 double *dmass_adv_w,
4422 double *dmom_u_adv_u,
4423 double *dmom_u_adv_v,
4424 double *dmom_u_adv_w,
4426 double *dmom_v_adv_u,
4427 double *dmom_v_adv_v,
4428 double *dmom_v_adv_w,
4430 double *dmom_w_adv_u,
4431 double *dmom_w_adv_v,
4432 double *dmom_w_adv_w,
4433 double *mom_u_diff_ten,
4434 double *mom_v_diff_ten,
4435 double *mom_w_diff_ten,
4436 double *mom_u_source,
4437 double *mom_v_source,
4438 double *mom_w_source,
4440 double *dmom_u_ham_grad_p,
4442 double *dmom_v_ham_grad_p,
4444 double *dmom_w_ham_grad_p)
4448 for (k=0;k<nPoints;k++)
4450 H = fmax(0.0,fmin(1.0,vof[k]));
4456 dmom_u_acc_u[k]=1.0;
4459 dmom_v_acc_v[k]=1.0;
4462 dmom_w_acc_w[k]=1.0;
4465 mass_adv[k*3+0]=
u[k];
4466 mass_adv[k*3+1]=
v[k];
4467 mass_adv[k*3+2]=
w[k];
4469 dmass_adv_u[k*3+0]=1.0;
4470 dmass_adv_v[k*3+1]=1.0;
4471 dmass_adv_w[k*3+2]=1.0;
4474 mom_u_adv[k*3+0]=
u[k]*
u[k];
4475 mom_u_adv[k*3+1]=
u[k]*
v[k];
4476 mom_u_adv[k*3+2]=
u[k]*
w[k];
4478 dmom_u_adv_u[k*3+0]=2.0*
u[k];
4479 dmom_u_adv_u[k*3+1]=
v[k];
4480 dmom_u_adv_u[k*3+2]=
w[k];
4482 dmom_u_adv_v[k*3+1]=
u[k];
4484 dmom_u_adv_w[k*3+2]=
u[k];
4487 mom_v_adv[k*3+0]=
v[k]*
u[k];
4488 mom_v_adv[k*3+1]=
v[k]*
v[k];
4489 mom_v_adv[k*3+2]=
v[k]*
w[k];
4491 dmom_v_adv_u[k*3+0]=
v[k];
4493 dmom_v_adv_v[k*3+0]=
u[k];
4494 dmom_v_adv_v[k*3+1]=2.0*
v[k];
4495 dmom_v_adv_v[k*3+2]=
w[k];
4497 dmom_v_adv_w[k*3+2]=
v[k];
4500 mom_w_adv[k*3+0]=
w[k]*
u[k];
4501 mom_w_adv[k*3+1]=
w[k]*
v[k];
4502 mom_w_adv[k*3+2]=
w[k]*
w[k];
4504 dmom_w_adv_u[k*3+0]=
w[k];
4506 dmom_w_adv_v[k*3+0]=
w[k];
4508 dmom_w_adv_w[k*3+0]=
u[k];
4509 dmom_w_adv_w[k*3+1]=
v[k];
4510 dmom_w_adv_w[k*3+2]=2.0*
w[k];
4513 mom_u_diff_ten[k*9+0] = nu;
4514 mom_u_diff_ten[k*9+4] = nu;
4515 mom_u_diff_ten[k*9+8] = nu;
4518 mom_v_diff_ten[k*9+0] = nu;
4519 mom_v_diff_ten[k*9+4] = nu;
4520 mom_v_diff_ten[k*9+8] = nu;
4523 mom_w_diff_ten[k*9+0] = nu;
4524 mom_w_diff_ten[k*9+4] = nu;
4525 mom_w_diff_ten[k*9+8] = nu;
4528 mom_u_source[k] = -g[0];
4529 mom_v_source[k] = -g[1];
4530 mom_w_source[k] = -g[2];
4533 mom_u_ham[k] = grad_p[k*3+0]/rho;
4534 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4537 mom_v_ham[k] = grad_p[k*3+1]/rho;
4538 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4541 mom_w_ham[k] = grad_p[k*3+2]/rho;
4542 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4555 const double *grad_p,
4559 double *dmom_u_acc_u,
4561 double *dmom_v_acc_v,
4563 double *dmass_adv_u,
4564 double *dmass_adv_v,
4565 double *mom_u_diff_ten,
4566 double *mom_v_diff_ten,
4567 double *mom_u_source,
4568 double *mom_v_source,
4570 double *dmom_u_ham_grad_p,
4572 double *dmom_v_ham_grad_p)
4576 for (k=0;k<nPoints;k++)
4579 H = fmax(0.0,fmin(1.0,vof[k]));
4585 dmom_u_acc_u[k]=1.0;
4589 dmom_v_acc_v[k]=1.0;
4592 mass_adv[k*2+0]=
u[k];
4593 mass_adv[k*2+1]=
v[k];
4595 dmass_adv_u[k*2+0]=1.0;
4596 dmass_adv_v[k*2+1]=1.0;
4599 mom_u_diff_ten[k*4+0] = nu;
4600 mom_u_diff_ten[k*4+3] = nu;
4603 mom_v_diff_ten[k*4+0] = nu;
4604 mom_v_diff_ten[k*4+3] = nu;
4607 mom_u_source[k] = -g[0];
4608 mom_v_source[k] = -g[1];
4611 mom_u_ham[k] = grad_p[k*2+0]/rho;
4612 dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4615 mom_v_ham[k] = grad_p[k*2+1]/rho;
4616 dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4629 const double *grad_p,
4634 double *dmom_u_acc_u,
4636 double *dmom_v_acc_v,
4638 double *dmom_w_acc_w,
4640 double *dmass_adv_u,
4641 double *dmass_adv_v,
4642 double *dmass_adv_w,
4643 double *mom_u_diff_ten,
4644 double *mom_v_diff_ten,
4645 double *mom_w_diff_ten,
4646 double *mom_u_source,
4647 double *mom_v_source,
4648 double *mom_w_source,
4650 double *dmom_u_ham_grad_p,
4652 double *dmom_v_ham_grad_p,
4654 double *dmom_w_ham_grad_p)
4658 for (k=0;k<nPoints;k++)
4660 H = fmax(0.0,fmin(1.0,vof[k]));
4666 dmom_u_acc_u[k]=1.0;
4669 dmom_v_acc_v[k]=1.0;
4672 dmom_w_acc_w[k]=1.0;
4675 mass_adv[k*3+0]=
u[k];
4676 mass_adv[k*3+1]=
v[k];
4677 mass_adv[k*3+2]=
w[k];
4679 dmass_adv_u[k*3+0]=1.0;
4680 dmass_adv_v[k*3+1]=1.0;
4681 dmass_adv_w[k*3+2]=1.0;
4684 mom_u_diff_ten[k*9+0] = nu;
4685 mom_u_diff_ten[k*9+4] = nu;
4686 mom_u_diff_ten[k*9+8] = nu;
4689 mom_v_diff_ten[k*9+0] = nu;
4690 mom_v_diff_ten[k*9+4] = nu;
4691 mom_v_diff_ten[k*9+8] = nu;
4694 mom_w_diff_ten[k*9+0] = nu;
4695 mom_w_diff_ten[k*9+4] = nu;
4696 mom_w_diff_ten[k*9+8] = nu;
4699 mom_u_source[k] = -g[0];
4700 mom_v_source[k] = -g[1];
4701 mom_w_source[k] = -g[2];
4704 mom_u_ham[k] = grad_p[k*3+0]/rho;
4705 dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4708 mom_v_ham[k] = grad_p[k*3+1]/rho;
4709 dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4712 mom_w_ham[k] = grad_p[k*3+2]/rho;
4713 dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4727 double vx,
vy, xk, yk;
4729 double one8 = 1.0/8.0;
4730 for (k=0; k < nPoints; k++)
4734 xk = x[k*3]; yk = x[k*3+1];
4735 vx = cos(M_PI*one8*t)*sin(2.0*M_PI*yk)*sin(M_PI*xk)*sin(M_PI*xk);
4736 vy =-cos(M_PI*one8*t)*sin(2.0*M_PI*xk)*sin(M_PI*yk)*sin(M_PI*yk);
4737 f[k*nSpace] =
vx*
u[k];
4738 f[k*nSpace+1] =
vy*
u[k];
4740 df[k*nSpace+1] =
vy;
4750 const double *gradu,
4760 for (k=0; k < nPoints; k++)
4765 for (
id=0;
id < nSpace;
id++)
4767 f[k*nSpace+id] = 0.0;
4768 df[k*nSpace+id]= 0.0;
4770 bdotgrad+= gradu[k*nSpace+id]*b[id];
4771 dH[k*nSpace+id]=b[id];
4781 const double *gradu,
4791 for (k=0; k < nPoints; k++)
4796 for (
id=0;
id < nSpace;
id++)
4798 f[k*nSpace+id] = 0.0;
4799 df[k*nSpace+id]= 0.0;
4801 normgradu+= gradu[k*nSpace+id]*gradu[k*nSpace+id];
4804 normgradu = sqrt(normgradu);
4806 for (
id=0;
id < nSpace;
id++)
4808 dH[k*nSpace+id]=gradu[k*nSpace+id]/(normgradu+1.0e-8);
4817 const double *gradu,
4825 double v[3], xk, yk, vdotgrad, one8;
4829 for (k=0; k < nPoints; k++)
4833 xk = x[k*3]; yk = x[k*3+1];
4834 v[0] = cos(M_PI*one8*t)*sin(2.0*M_PI*yk)*sin(M_PI*xk)*sin(M_PI*xk);
4835 v[1] =-cos(M_PI*one8*t)*sin(2.0*M_PI*xk)*sin(M_PI*yk)*sin(M_PI*yk);
4837 for (
id=0;
id < nSpace;
id++)
4839 f[k*nSpace+id] = 0.0;
4840 df[k*nSpace+id]= 0.0;
4842 vdotgrad+= gradu[k*nSpace+id]*
v[id];
4843 dH[k*nSpace+id]=
v[id];
4853 const double *gradu,
4861 double v[3], xk, yk, vdotgrad, one8;
4865 for (k=0; k < nPoints; k++)
4869 xk = x[k*3]; yk = x[k*3+1];
4870 v[0] = 2.0*M_PI*(x[k*3+1] - 0.5);
4871 v[1] =2.0*M_PI*(0.5 - x[k*3]);
4873 for (
id=0;
id < nSpace;
id++)
4875 f[k*nSpace+id] = 0.0;
4876 df[k*nSpace+id]= 0.0;
4878 vdotgrad+= gradu[k*nSpace+id]*
v[id];
4879 dH[k*nSpace+id]=
v[id];
4887 const double offset,
4889 const double *gradu,
4897 for (k=0; k < nPoints; k++)
4902 for (
id=0;
id < nSpace;
id++)
4904 tmp += gradu[k*nSpace+id];
4905 dH[k*nSpace+id]= offset;
4906 for (jd=0; jd < nSpace; jd++)
4907 dH[k*nSpace+
id] += gradu[k*nSpace+jd];
5011 const double* gravity,
5016 const double thetaR,
5017 const double thetaSR,
5030 const int nSpace2=nSpace*nSpace;
5031 register double psiC,
5032 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5034 sBar,sqrt_sBar,DsBar_DpsiC,
5035 thetaW,DthetaW_DpsiC,
5036 vBar,vBar2,DvBar_DpsiC,
5039 thetaS=thetaR+thetaSR,
5041 for (k=0;k<nPoints;k++)
5047 pcBar_nM2 = pow(pcBar,
n-2);
5048 pcBar_nM1 = pcBar_nM2*pcBar;
5049 pcBar_n = pcBar_nM1*pcBar;
5050 onePlus_pcBar_n = 1.0 + pcBar_n;
5052 sBar = pow(onePlus_pcBar_n,-m);
5054 DsBar_DpsiC = alpha*(1.0-
n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5056 vBar = 1.0-pcBar_nM1*sBar;
5058 DvBar_DpsiC = -alpha*(
n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5060 thetaW = thetaSR*sBar + thetaR;
5061 DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5063 sqrt_sBar = sqrt(sBar);
5064 KW= KWs*sqrt_sBar*vBar2;
5066 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5068 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5073 DthetaW_DpsiC = 0.0;
5078 rhom = rho*exp(beta*
u[k]);
5081 mass[k] = rhom*thetaW;
5082 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5083 for (I=0;I<nSpace;I++)
5085 f[k*nSpace+I] = rho2*KW*gravity[I];
5086 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
5088 a[k*nSpace2+I*nSpace+I] = rho*KW;
5089 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
5096 const int nPointsPerSimplex,
5099 const double* gravity,
5103 const double thetaR,
5104 const double thetaSR,
5116 const int nSpace2=nSpace*nSpace;
5117 register double psiC,
5118 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5120 sBar,sqrt_sBar,DsBar_DpsiC,
5121 thetaW,DthetaW_DpsiC,
5122 vBar,vBar2,DvBar_DpsiC,
5125 thetaS=thetaR+thetaSR;
5127 double mavg,dmavg,vol;
5128 double favg[3] = {0.0,0.0,0.0};
5129 double dfavg[3] = {0.0,0.0,0.0};
5130 double aavg[3][3]= {{0.0,0.0,0.0},
5133 double daavg[3][3]= {{0.0,0.0,0.0},
5140 for (eN = 0; eN < nSimplices; eN++)
5142 mavg = 0.0; dmavg = 0.0; vol = 0.0;
5143 for (I=0; I < nSpace; I++)
5145 favg[I] =0.0; dfavg[I] = 0.0;
5146 for (J=0; J < nSpace;J++)
5148 aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5151 for (k=0;k<nPointsPerSimplex;k++)
5153 psiC = -
u[eN*nPointsPerSimplex + k];
5157 pcBar_nM2 = pow(pcBar,
n-2);
5158 pcBar_nM1 = pcBar_nM2*pcBar;
5159 pcBar_n = pcBar_nM1*pcBar;
5160 onePlus_pcBar_n = 1.0 + pcBar_n;
5162 sBar = pow(onePlus_pcBar_n,-m);
5164 DsBar_DpsiC = alpha*(1.0-
n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5166 vBar = 1.0-pcBar_nM1*sBar;
5168 DvBar_DpsiC = -alpha*(
n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5170 thetaW = thetaSR*sBar + thetaR;
5171 DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5173 sqrt_sBar = sqrt(sBar);
5174 KW= KWs*sqrt_sBar*vBar2;
5176 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5178 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5183 DthetaW_DpsiC = 0.0;
5191 vol += dV[eN*nPointsPerSimplex + k];
5192 mavg += rho*thetaW*dV[eN*nPointsPerSimplex + k];
5193 dmavg +=-rho*DthetaW_DpsiC*dV[eN*nPointsPerSimplex + k];
5197 dmass[eN*nPointsPerSimplex+ k] =-rho*DthetaW_DpsiC;
5199 for (I=0; I < nSpace; I++)
5201 favg[I] += rho2*KW*gravity[I]*dV[eN*nPointsPerSimplex + k];
5202 dfavg[I]+=-rho2*DKW_DpsiC*gravity[I]*dV[eN*nPointsPerSimplex + k];
5204 aavg[I][J] += rho*KW*dV[eN*nPointsPerSimplex + k];
5205 daavg[I][J] +=-rho*DKW_DpsiC*dV[eN*nPointsPerSimplex + k];
5207 df[eN*nPointsPerSimplex*nSpace+ k*nSpace + I] = -rho2*DKW_DpsiC*gravity[I];
5208 da[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = -rho*DKW_DpsiC;
5216 for (k=0; k < nPointsPerSimplex; k++)
5218 mass[eN*nPointsPerSimplex + k] = mavg/vol;
5220 for (I=0; I < nSpace; I++)
5222 f[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = favg[I]/vol;
5224 for (J=0; J < nSpace; J++)
5228 a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = aavg[I][J]/vol;
5233 a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = 0.0;
5244 const int nElementBoundaries_element,
5245 const int nPointsPerElementBoundary,
5248 const double* gravity,
5252 const double thetaR,
5253 const double thetaSR,
5265 const int nSpace2=nSpace*nSpace;
5266 register double psiC,
5267 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5269 sBar,sqrt_sBar,DsBar_DpsiC,
5270 thetaW,DthetaW_DpsiC,
5271 vBar,vBar2,DvBar_DpsiC,
5274 thetaS=thetaR+thetaSR;
5276 double mavg,dmavg,vol;
5277 double favg[3] = {0.0,0.0,0.0};
5278 double dfavg[3] = {0.0,0.0,0.0};
5279 double aavg[3][3]= {{0.0,0.0,0.0},
5282 double daavg[3][3]= {{0.0,0.0,0.0},
5290 for (eN = 0; eN < nElements; eN++)
5292 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
5294 mavg = 0.0; dmavg = 0.0; vol = 0.0;
5295 for (I=0; I < nSpace; I++)
5297 favg[I] =0.0; dfavg[I] = 0.0;
5298 for (J=0; J < nSpace;J++)
5300 aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5303 for (k=0;k<nPointsPerElementBoundary;k++)
5305 psiC = -
u[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k];
5309 pcBar_nM2 = pow(pcBar,
n-2);
5310 pcBar_nM1 = pcBar_nM2*pcBar;
5311 pcBar_n = pcBar_nM1*pcBar;
5312 onePlus_pcBar_n = 1.0 + pcBar_n;
5314 sBar = pow(onePlus_pcBar_n,-m);
5316 DsBar_DpsiC = alpha*(1.0-
n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5318 vBar = 1.0-pcBar_nM1*sBar;
5320 DvBar_DpsiC = -alpha*(
n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5322 thetaW = thetaSR*sBar + thetaR;
5323 DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5325 sqrt_sBar = sqrt(sBar);
5326 KW= KWs*sqrt_sBar*vBar2;
5328 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5330 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5335 DthetaW_DpsiC = 0.0;
5343 vol += dV[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k];
5344 mavg += rho*thetaW*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k];
5345 dmavg +=-rho*DthetaW_DpsiC*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k];
5348 dmass[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k] =
5350 for (I=0; I < nSpace; I++)
5352 favg[I] += rho2*KW*gravity[I]*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary +
5353 ebN*nPointsPerElementBoundary + k];
5354 dfavg[I]+=-rho2*DKW_DpsiC*gravity[I]*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary +
5355 ebN*nPointsPerElementBoundary + k];
5357 aavg[I][J] += rho*KW*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary +
5358 ebN*nPointsPerElementBoundary + k];
5359 daavg[I][J] +=-rho*DKW_DpsiC*dV[eN*nElementBoundaries_element*nPointsPerElementBoundary +
5360 ebN*nPointsPerElementBoundary + k];
5362 df[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace + ebN*nPointsPerElementBoundary*nSpace +
5363 k*nSpace + I] = -rho2*DKW_DpsiC*gravity[I];
5364 da[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2+ ebN*nPointsPerElementBoundary*nSpace2 +
5365 k*nSpace2 + I*nSpace + J]= -rho*DKW_DpsiC;
5374 for (k=0; k < nPointsPerElementBoundary; k++)
5376 mass[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k] = mavg/vol;
5379 for (I=0; I < nSpace; I++)
5381 f[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace + ebN*nPointsPerElementBoundary*nSpace +
5382 k*nSpace + I] = favg[I]/vol;
5385 for (J=0; J < nSpace; J++)
5390 a[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2 + ebN*nPointsPerElementBoundary*nSpace2 +
5391 k*nSpace2 + I*nSpace + J] = aavg[I][J]/vol;
5399 a[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2 + ebN*nPointsPerElementBoundary*nSpace2 +
5400 k*nSpace2 + I*nSpace + J] = 0.0;
5413 const int nPointsPerSimplex,
5416 const double *gravity,
5417 const double *alpha,
5419 const double *thetaR,
5420 const double *thetaSR,
5432 const int nSpace2=nSpace*nSpace;
5433 register double psiC,
5434 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5436 sBar,sqrt_sBar,DsBar_DpsiC,
5437 thetaW,DthetaW_DpsiC,
5438 vBar,vBar2,DvBar_DpsiC,
5441 register double thetaS,m;
5443 double mavg,dmavg,vol;
5444 double favg[3] = {0.0,0.0,0.0};
5445 double dfavg[3] = {0.0,0.0,0.0};
5446 double aavg[3][3]= {{0.0,0.0,0.0},
5449 double daavg[3][3]= {{0.0,0.0,0.0},
5456 for (eN = 0; eN < nSimplices; eN++)
5458 mavg = 0.0; dmavg = 0.0; vol = 0.0;
5459 for (I=0; I < nSpace; I++)
5461 favg[I] =0.0; dfavg[I] = 0.0;
5462 for (J=0; J < nSpace;J++)
5464 aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5467 for (k=0;k<nPointsPerSimplex;k++)
5469 psiC = -
u[eN*nPointsPerSimplex + k];
5470 m = 1.0 - 1.0/
n[eN*nPointsPerSimplex + k];
5471 thetaS = thetaR[eN*nPointsPerSimplex + k] + thetaSR[eN*nPointsPerSimplex + k];
5474 pcBar = alpha[eN*nPointsPerSimplex + k]*psiC;
5475 pcBar_nM2 = pow(pcBar,
n[eN*nPointsPerSimplex + k]-2);
5476 pcBar_nM1 = pcBar_nM2*pcBar;
5477 pcBar_n = pcBar_nM1*pcBar;
5478 onePlus_pcBar_n = 1.0 + pcBar_n;
5480 sBar = pow(onePlus_pcBar_n,-m);
5482 DsBar_DpsiC = alpha[eN*nPointsPerSimplex + k]*(1.0-
n[eN*nPointsPerSimplex + k])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5484 vBar = 1.0-pcBar_nM1*sBar;
5486 DvBar_DpsiC = -alpha[eN*nPointsPerSimplex + k]*(
n[eN*nPointsPerSimplex + k]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5488 thetaW = thetaSR[eN*nPointsPerSimplex + k]*sBar + thetaR[eN*nPointsPerSimplex + k];
5489 DthetaW_DpsiC = thetaSR[eN*nPointsPerSimplex + k] * DsBar_DpsiC;
5491 sqrt_sBar = sqrt(sBar);
5492 KW= KWs[eN*nPointsPerSimplex + k]*sqrt_sBar*vBar2;
5493 DKW_DpsiC= KWs[eN*nPointsPerSimplex + k]*
5494 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5496 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5501 DthetaW_DpsiC = 0.0;
5502 KW = KWs[eN*nPointsPerSimplex + k];
5509 vol += dV[eN*nPointsPerSimplex + k];
5510 mavg += rho*thetaW*dV[eN*nPointsPerSimplex + k];
5511 dmavg +=-rho*DthetaW_DpsiC*dV[eN*nPointsPerSimplex + k];
5514 dmass[eN*nPointsPerSimplex+ k] = -rho*DthetaW_DpsiC;
5515 for (I=0; I < nSpace; I++)
5517 favg[I] += rho2*KW*gravity[I]*dV[eN*nPointsPerSimplex + k];
5518 dfavg[I]+=-rho2*DKW_DpsiC*gravity[I]*dV[eN*nPointsPerSimplex + k];
5520 df[eN*nPointsPerSimplex*nSpace+ k*nSpace + I] = -rho2*DKW_DpsiC*gravity[I];
5522 aavg[I][J] += rho*KW*dV[eN*nPointsPerSimplex + k];
5523 daavg[I][J] +=-rho*DKW_DpsiC*dV[eN*nPointsPerSimplex + k];
5524 da[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + I] = -rho*DKW_DpsiC;
5532 for (k=0; k < nPointsPerSimplex; k++)
5534 mass[eN*nPointsPerSimplex + k] = mavg/vol;
5536 for (I=0; I < nSpace; I++)
5539 f[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = favg[I]/vol;
5541 a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + I] = aavg[I][I]/vol;
5553 const double* gravity,
5558 const double thetaR,
5559 const double thetaSR,
5572 const int nSpace2=nSpace*nSpace;
5573 register double psiC,
5574 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5576 sBar,sqrt_sBar,DsBar_DpsiC,
5577 thetaW,DthetaW_DpsiC,
5578 vBar,vBar2,DvBar_DpsiC,
5580 thetaS=thetaR+thetaSR;
5582 register double elev;
5583 for (k=0;k<nPoints;k++)
5586 for (I=0; I < nSpace; I++)
5587 elev += gravity[I]*x[k*3+I];
5597 pcBar_nM2 = pow(pcBar,
n-2);
5598 pcBar_nM1 = pcBar_nM2*pcBar;
5599 pcBar_n = pcBar_nM1*pcBar;
5600 onePlus_pcBar_n = 1.0 + pcBar_n;
5602 sBar = pow(onePlus_pcBar_n,-m);
5604 DsBar_DpsiC = alpha*(1.0-
n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5606 vBar = 1.0-pcBar_nM1*sBar;
5608 DvBar_DpsiC = -alpha*(
n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5610 thetaW = thetaSR*sBar + thetaR;
5611 DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5613 sqrt_sBar = sqrt(sBar);
5614 KW= KWs*sqrt_sBar*vBar2;
5616 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5618 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5623 DthetaW_DpsiC = 0.0;
5627 mass[k] = rho*thetaW;
5628 dmass[k] = -rho*DthetaW_DpsiC;
5638 for (I=0;I<nSpace;I++)
5640 f[k*nSpace+I] = 0.0;
5641 df[k*nSpace+I] = 0.0;
5643 phi[k] -= rho*gravity[I]*x[k*3+I];
5645 a[k*nSpace2+I*nSpace+I] = rho*KW;
5646 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
5652 const int nPointsPerSimplex,
5659 for (eN = 0; eN < nSimplices; eN++)
5661 ravg = 0.0; vol = 0.0;
5662 for (k=0; k < nPointsPerSimplex; k++)
5664 vol += dV[eN*nPointsPerSimplex+k];
5665 ravg +=
r[eN*nPointsPerSimplex + k]*dV[eN*nPointsPerSimplex+k];
5670 for (k=0; k < nPointsPerSimplex; k++)
5672 r[eN*nPointsPerSimplex + k] = ravg;
5677 const int nPointsPerSimplex,
5685 double ravg[nSpace];
5686 for (eN = 0; eN < nSimplices; eN++)
5689 for (I=0; I < nSpace; I++)
5691 for (k=0; k < nPointsPerSimplex; k++)
5693 vol += dV[eN*nPointsPerSimplex+k];
5694 for (I=0; I < nSpace; I++)
5695 ravg[I] +=
r[eN*nPointsPerSimplex*nSpace + k*nSpace + I]*dV[eN*nPointsPerSimplex+k];
5698 for (k=0; k < nPointsPerSimplex; k++)
5700 for (I=0; I < nSpace; I++)
5701 r[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = ravg[I]/vol;
5706 const int nPointsPerSimplex,
5711 int eN,k,I,J,nSpace2;
5714 double ravg[nSpace*nSpace];
5715 nSpace2 = nSpace*nSpace;
5716 for (eN = 0; eN < nSimplices; eN++)
5719 for (I=0; I < nSpace2; I++)
5721 for (k=0; k < nPointsPerSimplex; k++)
5723 vol += dV[eN*nPointsPerSimplex+k];
5724 for (I=0; I < nSpace; I++)
5725 for (J=0; J < nSpace; J++)
5726 ravg[I*nSpace+J] +=
r[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J]
5728 dV[eN*nPointsPerSimplex+k];
5731 for (k=0; k < nPointsPerSimplex; k++)
5733 for (I=0; I < nSpace; I++)
5734 for (J=0; J < nSpace; J++)
5735 r[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = ravg[I*nSpace+J]/vol;
5741 const int nPointsPerSimplex,
5746 const int* materialTypes,
5749 const double* gravity,
5750 const double* alpha,
5752 const double* thetaR,
5753 const double* thetaSR,
5764 int i,j,k,I,matID,ii;
5765 const int nSpace2=nSpace*nSpace;
5766 register double psiC,pcBarStar,
5767 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5769 sBar,sqrt_sBar,DsBar_DpsiC,
5770 thetaW,DthetaW_DpsiC,
5771 vBar,vBar2,DvBar_DpsiC,
5777 const int nnz = rowptr[nSpace];
5778 for (i=0; i < nSimplex; i++)
5780 matID= materialTypes[i];
5781 for (j=0;j<nPointsPerSimplex;j++)
5783 k = i*nPointsPerSimplex + j;
5785 m = 1.0 - 1.0/
n[matID];
5786 thetaS = thetaR[matID] + thetaSR[matID];
5789 pcBar = alpha[matID]*psiC;
5790 pcBarStar = fmax(pcBar,pc_eps);
5792 pcBar_nM2 = pow(pcBarStar,
n[matID]-2);
5793 pcBar_nM1 = pcBar_nM2*pcBar;
5794 pcBar_n = pcBar_nM1*pcBar;
5795 onePlus_pcBar_n = 1.0 + pcBar_n;
5797 sBar = pow(onePlus_pcBar_n,-m);
5799 DsBar_DpsiC = alpha[matID]*(1.0-
n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5801 vBar = 1.0-pcBar_nM1*sBar;
5803 DvBar_DpsiC = -alpha[matID]*(
n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5805 thetaW = thetaSR[matID]*sBar + thetaR[matID];
5806 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
5808 sqrt_sBar = sqrt(sBar);
5809 KWr= sqrt_sBar*vBar2;
5810 DKWr_DpsiC= ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5812 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5817 DthetaW_DpsiC = 0.0;
5822 betauStar = fmin(beta*
u[k],1000.0);
5823 rhom = rho*exp(betauStar);
5825 mass[k] = rhom*thetaW;
5826 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5827 vol_frac[k] = thetaW;
5830 for (I=0;I<nSpace;I++)
5832 f[k*nSpace+I] = 0.0;
5833 df[k*nSpace+I] = 0.0;
5834 for (ii=rowptr[I]; ii < rowptr[I+1]; ii++)
5836 f[k*nSpace+I] += rho2*KWr*KWs[matID*
nnz+ii]*gravity[colind[ii]];
5837 df[k*nSpace+I] += -rho2*DKWr_DpsiC*KWs[matID*
nnz+ii]*gravity[colind[ii]];
5838 a[k*
nnz+ii] = rho*KWr*KWs[matID*
nnz+ii];
5839 da[k*
nnz+ii] = -rho*DKWr_DpsiC*KWs[matID*
nnz+ii];
5848 const int nPointsPerSimplex,
5850 double linear_break,
5853 const int* materialTypes,
5856 const double* gravity,
5857 const double* alpha,
5859 const double* thetaR,
5860 const double* thetaSR,
5871 int i,j,k,I,matID,ii;
5872 const int nSpace2=nSpace*nSpace;
5873 register double psiC,pcBarStar,sBarStar,KWrStar,
5874 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5876 sBar,sqrt_sBar,DsBar_DpsiC,
5877 thetaW,DthetaW_DpsiC,
5878 vBar,vBar2,DvBar_DpsiC,
5884 const int nnz = rowptr[nSpace];
5885 pcBarStar = linear_break;
5887 for (i=0; i < nSimplex; i++)
5889 matID= materialTypes[i];
5890 for (j=0;j<nPointsPerSimplex;j++)
5892 k = i*nPointsPerSimplex + j;
5894 m = 1.0 - 1.0/
n[matID];
5895 thetaS = thetaR[matID] + thetaSR[matID];
5898 pcBar = alpha[matID]*psiC;
5899 if (psiC <= pcBarStar)
5902 pcBar_nM2 = pow(pcBarStar,
n[matID]-2.);
5903 pcBar_nM1 = pcBar_nM2*pcBar;
5904 pcBar_n = pcBar_nM1*pcBar;
5905 onePlus_pcBar_n = 1.0 + pcBar_n;
5907 sBar = pow(onePlus_pcBar_n,-m);
5909 DsBar_DpsiC = alpha[matID]*(1.0-
n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5911 vBar = 1.0-pcBar_nM1*sBar;
5913 DvBar_DpsiC = -alpha[matID]*(
n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5916 sqrt_sBar = sqrt(sBar);
5917 KWrStar= sqrt_sBar*vBar2;
5920 DsBar_DpsiC = (sBarStar-1.0)/(pcBarStar-0.0);
5921 sBar = DsBar_DpsiC*(psiC-0.0) + 1.0;
5922 thetaW = thetaSR[matID]*sBar + thetaR[matID];
5923 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
5925 DKWr_DpsiC= (KWrStar - 1.0)/(pcBarStar-0.0);
5926 KWr = DKWr_DpsiC*(psiC-0.0) + 1.0;
5930 pcBar = alpha[matID]*psiC;
5931 pcBarStar = fmax(pcBar,1.0e-8);
5933 pcBar_nM2 = pow(pcBarStar,
n[matID]-2);
5934 pcBar_nM1 = pcBar_nM2*pcBar;
5935 pcBar_n = pcBar_nM1*pcBar;
5936 onePlus_pcBar_n = 1.0 + pcBar_n;
5938 sBar = pow(onePlus_pcBar_n,-m);
5940 DsBar_DpsiC = alpha[matID]*(1.0-
n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5942 vBar = 1.0-pcBar_nM1*sBar;
5944 DvBar_DpsiC = -alpha[matID]*(
n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5946 thetaW = thetaSR[matID]*sBar + thetaR[matID];
5947 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
5949 sqrt_sBar = sqrt(sBar);
5950 KWr= sqrt_sBar*vBar2;
5951 DKWr_DpsiC= ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5953 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5960 DthetaW_DpsiC = 0.0;
5965 betauStar = fmin(beta*
u[k],1000.0);
5966 rhom = rho*exp(betauStar);
5968 mass[k] = rhom*thetaW;
5969 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5970 vol_frac[k] = thetaW;
5973 for (I=0;I<nSpace;I++)
5975 f[k*nSpace+I] = 0.0;
5976 df[k*nSpace+I] = 0.0;
5977 for (ii=rowptr[I]; ii < rowptr[I+1]; ii++)
5979 f[k*nSpace+I] += rho2*KWr*KWs[matID*
nnz+ii]*gravity[colind[ii]];
5980 df[k*nSpace+I] += -rho2*DKWr_DpsiC*KWs[matID*
nnz+ii]*gravity[colind[ii]];
5981 a[k*
nnz+ii] = rho*KWr*KWs[matID*
nnz+ii];
5982 da[k*
nnz+ii] = -rho*DKWr_DpsiC*KWs[matID*
nnz+ii];
5991 const int nPointsPerSimplex,
5993 const int* materialTypes,
5996 const double* gravity,
5997 const double* alpha,
5999 const double* thetaR,
6000 const double* thetaSR,
6011 const int nSpace2=nSpace*nSpace;
6012 register double psiC,
6013 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6015 sBar,sqrt_sBar,DsBar_DpsiC,
6016 thetaW,DthetaW_DpsiC,
6017 vBar,vBar2,DvBar_DpsiC,
6022 for (i=0; i < nSimplex; i++)
6024 matID= materialTypes[i];
6025 for (j=0;j<nPointsPerSimplex;j++)
6027 k = i*nPointsPerSimplex + j;
6029 m = 1.0 - 1.0/
n[matID];
6030 thetaS = thetaR[matID] + thetaSR[matID];
6033 pcBar = alpha[matID]*psiC;
6034 pcBar_nM2 = pow(pcBar,
n[matID]-2);
6035 pcBar_nM1 = pcBar_nM2*pcBar;
6036 pcBar_n = pcBar_nM1*pcBar;
6037 onePlus_pcBar_n = 1.0 + pcBar_n;
6039 sBar = pow(onePlus_pcBar_n,-m);
6041 DsBar_DpsiC = alpha[matID]*(1.0-
n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6043 vBar = 1.0-pcBar_nM1*sBar;
6045 DvBar_DpsiC = -alpha[matID]*(
n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6047 thetaW = thetaSR[matID]*sBar + thetaR[matID];
6048 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
6050 sqrt_sBar = sqrt(sBar);
6051 KW= KWs[matID]*sqrt_sBar*vBar2;
6052 DKW_DpsiC= KWs[matID]*
6053 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
6055 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6060 DthetaW_DpsiC = 0.0;
6065 rhom = rho*exp(beta*
u[k]);
6067 mass[k] = rhom*thetaW;
6068 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
6071 for (I=0;I<nSpace;I++)
6073 f[k*nSpace+I] = rho2*KW*gravity[I];
6074 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
6075 a[k*nSpace2+I*nSpace+I] = rho*KW;
6076 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
6084 const int nPointsPerSimplex,
6086 const int* materialTypes,
6087 const double epsFact,
6090 const double* elementDiameter,
6091 const double* gravity,
6092 const double* alpha,
6094 const double* thetaR,
6095 const double* thetaSR,
6106 const int nSpace2=nSpace*nSpace;
6107 register double psiC,
6108 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6110 sBar,sqrt_sBar,DsBar_DpsiC,
6111 thetaW,DthetaW_DpsiC,
6112 vBar,vBar2,DvBar_DpsiC,
6116 rhom,drhom,m,eps,hStar,dhStar;
6117 for (i=0; i < nSimplex; i++)
6119 matID= materialTypes[i];
6120 eps = epsFact*elementDiameter[i];
6121 for (j=0;j<nPointsPerSimplex;j++)
6123 k = i*nPointsPerSimplex + j;
6124 thetaS = thetaR[matID] + thetaSR[matID];
6129 mass[k] = thetaS*hStar;
6130 dmass[k] = thetaS*dhStar;
6131 for (I=0;I<nSpace;I++)
6133 f[k*nSpace+I] = KWs[matID]*gravity[I]*hStar;
6134 df[k*nSpace+I] = KWs[matID]*gravity[I]*dhStar;
6135 a[k*nSpace2+I*nSpace+I] = KWs[matID]*hStar;
6136 da[k*nSpace2+I*nSpace+I] = KWs[matID]*dhStar;
6144 const int nPointsPerSimplex,
6146 const int* materialTypes,
6149 const double* gravity,
6154 const double* S_wirr,
6155 const double* S_nwr,
6166 const int nSpace2=nSpace*nSpace;
6167 register double psiC,
6172 const double reg_diff=1.0e-2;
6173 for (i=0; i < nSimplex; i++)
6175 matID= materialTypes[i];
6176 for (j=0;j<nPointsPerSimplex;j++)
6178 k = i*nPointsPerSimplex + j;
6180 if (psiC > 0.0 && psiC < psiD[matID])
6182 Se = 1.0 - pow(psiC/psiD[matID],
ns[matID]);
6183 Sw = Se*(1.0 - S_wirr[matID] - S_nwr[matID]) + S_wirr[matID];
6184 dSw = (1.0 - S_wirr[matID] - S_nwr[matID])*pow(psiC/psiD[matID],
ns[matID]-1.0)*
ns[matID]/psiD[matID];
6185 kr = kr0[matID]*pow(Se,nk[matID])+reg_diff;
6186 dkr = kr0[matID]*pow(Se,nk[matID]-1.0)*nk[matID]*pow(psiC/psiD[matID],
ns[matID]-1.0)*
ns[matID]/psiD[matID];
6188 else if (psiC <= 0.0)
6191 Sw = 1.0 - S_nwr[matID];
6193 kr = kr0[matID]+reg_diff;
6205 rhom = rho*exp(beta*
u[k]);
6208 mass[k] = rhom*Sw*
phi[matID];
6209 dmass[k] = rhom*dSw*
phi[matID]+drhom*Sw*
phi[matID];
6210 for (I=0;I<nSpace;I++)
6212 f[k*nSpace+I] = rho2*kr*gravity[I];
6213 df[k*nSpace+I] = rho2*dkr*gravity[I];
6214 a[k*nSpace2+I*nSpace+I] = rho*kr;
6215 da[k*nSpace2+I*nSpace+I] = rho*dkr;
6221 const int nPointsPerSimplex,
6223 const int* materialTypes,
6226 const double* gravity,
6231 const double* S_wirr,
6232 const double* S_nwr,
6245 const int nSpace2=nSpace*nSpace;
6246 register double psiC,pcBar,
6251 const double reg_diff=1.0e-2;
6252 for (i=0; i < nSimplex; i++)
6254 matID= materialTypes[i];
6255 for (j=0;j<nPointsPerSimplex;j++)
6257 k = i*nPointsPerSimplex + j;
6259 if (psiC >= psiD[matID])
6261 pcBar = psiC/psiD[matID];
6262 Se = pow(pcBar, -
ns[matID]);
6263 Sw = Se*(1.0 - S_wirr[matID] - S_nwr[matID]) + S_wirr[matID];
6264 dSe =
ns[matID]*Se/(pcBar*psiD[matID]);
6265 dSw = (1.0 - S_wirr[matID] - S_nwr[matID])*dSe;
6266 kr = pow(Se, (2.0+3.0*
ns[matID])/
ns[matID]);
6267 dkr = ((2.0+3.0*
ns[matID])/
ns[matID]*pow(Se, 2.0/
ns[matID]*(1.0+
ns[matID]))*dSe);
6268 kr = pow(Se,nk[matID]);
6269 dkr = nk[matID]*pow(Se,nk[matID]-1)*dSe;
6274 Sw = 1.0 - S_nwr[matID];
6304 rhom = rho*exp(beta*
u[k]);
6307 mass[k] = rhom*Sw*
phi[matID];
6308 dmass[k] = rhom*dSw*
phi[matID]+drhom*Sw*
phi[matID];
6310 f[k*nSpace+I] = rho2*kr0x[matID]*kr*gravity[I];
6311 df[k*nSpace+I] = rho2*kr0x[matID]*dkr*gravity[I];
6312 a[k*nSpace2+I*nSpace+I] = rho*kr0x[matID]*kr;
6313 da[k*nSpace2+I*nSpace+I] = rho*kr0x[matID]*dkr;
6317 f[k*nSpace+I] = rho2*kr0y[matID]*kr*gravity[I];
6318 df[k*nSpace+I] = rho2*kr0y[matID]*dkr*gravity[I];
6319 a[k*nSpace2+I*nSpace+I] = rho*kr0y[matID]*kr;
6320 da[k*nSpace2+I*nSpace+I] = rho*kr0y[matID]*dkr;
6324 f[k*nSpace+I] = rho2*kr0z[matID]*kr*gravity[I];
6325 df[k*nSpace+I] = rho2*kr0z[matID]*dkr*gravity[I];
6326 a[k*nSpace2+I*nSpace+I] = rho*kr0z[matID]*kr;
6327 da[k*nSpace2+I*nSpace+I] = rho*kr0z[matID]*dkr;
6340 const double* gravity,
6341 const double* alpha,
6343 const double* thetaR,
6344 const double* thetaSR,
6355 const int nSpace2=nSpace*nSpace;
6356 register double psiC,
6357 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6359 sBar,sqrt_sBar,DsBar_DpsiC,
6360 thetaW,DthetaW_DpsiC,
6361 vBar,vBar2,DvBar_DpsiC,
6366 for (k=0;k<nPoints;k++)
6370 thetaS = thetaR[k] + thetaSR[k];
6373 pcBar = alpha[k]*psiC;
6374 pcBar_nM2 = pow(pcBar,
n[k]-2);
6375 pcBar_nM1 = pcBar_nM2*pcBar;
6376 pcBar_n = pcBar_nM1*pcBar;
6377 onePlus_pcBar_n = 1.0 + pcBar_n;
6379 sBar = pow(onePlus_pcBar_n,-m);
6381 DsBar_DpsiC = alpha[k]*(1.0-
n[k])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6383 vBar = 1.0-pcBar_nM1*sBar;
6385 DvBar_DpsiC = -alpha[k]*(
n[k]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6387 thetaW = thetaSR[k]*sBar + thetaR[k];
6388 DthetaW_DpsiC = thetaSR[k] * DsBar_DpsiC;
6390 sqrt_sBar = sqrt(sBar);
6391 KW= KWs[k]*sqrt_sBar*vBar2;
6393 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
6395 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6400 DthetaW_DpsiC = 0.0;
6404 mass[k] = rho*thetaW;
6405 dmass[k] = -rho*DthetaW_DpsiC;
6406 for (I=0;I<nSpace;I++)
6408 f[k*nSpace+I] = rho2*KW*gravity[I];
6409 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
6410 a[k*nSpace2+I*nSpace+I] = rho*KW;
6411 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
6421 const double* gravity,
6426 const double thetaR,
6427 const double thetaSR,
6440 const int nSpace2=nSpace*nSpace;
6441 const double eps=1.0e-8;
6442 register double psiC,
6443 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6445 sBar,sqrt_sBar,DsBar_DpsiC,
6447 vBar,vBar2,DvBar_DpsiC,
6450 thetaS=thetaR+thetaSR;
6451 for (k=0;k<nPoints;k++)
6454 thetaW = thetaS*
u[k];
6455 if (
u[k] < 1.0-eps &&
6459 psiC = pow(pow(sBar,-1.0/m)-1.0,1.0/
n)/alpha;
6462 pcBar_nM2 = pow(pcBar,
n-2);
6463 pcBar_nM1 = pcBar_nM2*pcBar;
6464 pcBar_n = pcBar_nM1*pcBar;
6465 onePlus_pcBar_n = 1.0 + pcBar_n;
6468 DsBar_DpsiC = alpha*(1.0-
n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6470 vBar = 1.0-pcBar_nM1*sBar;
6472 DvBar_DpsiC = -alpha*(
n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6474 sqrt_sBar = sqrt(sBar);
6475 KW= KWs*sqrt_sBar*vBar2;
6477 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
6479 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6481 else if (
u[k] >= 1.0-eps)
6490 psiC = pow(pow(eps,-1.0/m)-1.0,1.0/
n)/alpha;
6495 mass[k] = rho*thetaW;
6496 dmass[k] = rho*thetaS;
6498 dphi[k] = -1.0/DsBar_DpsiC;
6499 for (I=0;I<nSpace;I++)
6501 f[k*nSpace+I] = rho2*KW*gravity[I];
6502 df[k*nSpace+I] = rho2*DKW_DpsiC*gravity[I]/DsBar_DpsiC;
6507 a[k*nSpace2+I*nSpace+I] = rho*KW;
6508 da[k*nSpace2+I*nSpace+I] = rho*DKW_DpsiC/DsBar_DpsiC;
6651 const double* gravity,
6652 const double* lambda,
6654 const double* thetaR,
6655 const double* thetaS,
6666 const int nSpace2=nSpace*nSpace;
6667 register double psiC,
6670 thetaW,DthetaW_DpsiC,
6672 rho2=rho*rho,thetaSR;
6673 for (k=0;k<nPoints;k++)
6679 sBar = pow(pcBar, -lambda[k]);
6680 DsBar_DpsiC = -lambda[k]*sBar/(pcBar*
pd[k]);
6681 KW = KWs[k]*pow(sBar, (2.0+3.0*lambda[k])/lambda[k]);
6682 DKW_DpsiC = KWs[k]*((2.0+3.0*lambda[k])/lambda[k]*pow(sBar, 2.0/lambda[k]*(1.0+lambda[k]))*DsBar_DpsiC);
6683 thetaSR = thetaS[k]-thetaR[k];
6684 thetaW = thetaSR*sBar + thetaR[k];
6685 DthetaW_DpsiC = thetaSR*DsBar_DpsiC;
6690 DthetaW_DpsiC = 0.0;
6694 mass[k] = rho*thetaW;
6695 dmass[k] = -rho*DthetaW_DpsiC;
6696 for (I=0;I<nSpace;I++)
6698 f[k*nSpace+I] = rho2*KW*gravity[I];
6699 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
6700 a[k*nSpace2+I*nSpace+I] = rho*KW;
6701 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
6710 const double* gravity,
6711 const double lambda,
6713 const double thetaR,
6714 const double thetaSR,
6725 const int nSpace2=nSpace*nSpace;
6726 register double psiC,
6729 thetaW,DthetaW_DpsiC,
6732 thetaS=thetaR+thetaSR,
6755 for (k=0;k<nPoints;k++)
6761 sBar = pow(pcBar, -lambda);
6762 DsBar_DpsiC = -lambda*sBar/psiC;
6763 KW = KWs*pow(sBar, (2.0+3.0*lambda)/lambda);
6764 DKW_DpsiC = KWs*((2.0+3.0*lambda)/lambda*pow(sBar, 2.0/lambda*(1.0+lambda))*DsBar_DpsiC);
6765 thetaW = thetaSR*sBar + thetaR;
6766 DthetaW_DpsiC = thetaSR*DsBar_DpsiC;
6778 DthetaW_DpsiC = 0.0;
6783 rhom = rho*exp(beta*
u[k]);
6786 mass[k] = rhom*thetaW;
6787 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
6788 for (I=0;I<nSpace;I++)
6790 f[k*nSpace+I] = rho2*KW*gravity[I];
6791 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
6792 a[k*nSpace2+I*nSpace+I] = rho*KW;
6793 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
6801 const double* gravity,
6802 const double lambda,
6804 const double thetaR,
6805 const double thetaSR,
6818 const int nSpace2=nSpace*nSpace;
6819 register double psiC=0.0,
6821 sBar,DsBar_DpsiC=0.0,
6822 thetaW,DthetaW_DpsiC=0.0,
6825 thetaS=thetaR+thetaSR;
6826 for (k=0;k<nPoints;k++)
6829 thetaW = thetaS*sBar;
6832 psiC = pow(sBar, -1/lambda)*
pd;
6837 sBar = pow(pcBar, -lambda);
6838 DsBar_DpsiC = -lambda*sBar/(pcBar*
pd);
6839 KW = KWs*pow(sBar, (2+3*lambda)/lambda);
6840 DKW_DpsiC = KWs*((2+3*lambda)/lambda*pow(sBar, 2/lambda*(1+lambda))*DsBar_DpsiC);
6841 thetaW = thetaSR*sBar + thetaR;
6842 DthetaW_DpsiC = thetaSR*DsBar_DpsiC;
6849 mass[k] = rho*thetaW;
6850 dmass[k] = -rho*DthetaW_DpsiC;
6852 dphi[k] = -1.0/DsBar_DpsiC;
6853 for (I=0;I<nSpace;I++)
6855 f[k*nSpace+I] = rho2*KW*gravity[I];
6856 df[k*nSpace+I] = rho2*DKW_DpsiC*gravity[I]/DsBar_DpsiC;
6857 a[k*nSpace2+I*nSpace+I] = rho*KW;
6858 da[k*nSpace2+I*nSpace+I] = rho*DKW_DpsiC/DsBar_DpsiC;
6867 const double* gravity,
6871 const double thetaR,
6872 const double thetaSR,
6883 const int nSpace2=nSpace*nSpace;
6884 register double psiC,
6887 thetaW,DthetaW_DpsiC,
6890 thetaS=thetaR+thetaSR;
6891 for (k=0;k<nPoints;k++)
6905 sBar = pow(pcBar, -lambda);
6906 DsBar_DpsiC = -lambda*sBar/(pcBar*
pd);
6907 KW = KWs*pow(sBar, (2+3*lambda)/lambda);
6908 DKW_DpsiC = KWs*((2+3*lambda)/lambda*pow(sBar, 2/lambda*(1+lambda))*DsBar_DpsiC);
6909 thetaW = thetaSR*sBar + thetaR;
6910 DthetaW_DpsiC = thetaSR*DsBar_DpsiC;
6915 DthetaW_DpsiC = 0.0;
6919 mass[k] = rho*thetaW;
6920 dmass[k] = -rho*DthetaW_DpsiC;
6921 for (I=0;I<nSpace;I++)
6923 f[k*nSpace+I] = rho2*KW*gravity[I];
6924 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
6925 a[k*nSpace2+I*nSpace+I] = rho*KW;
6926 da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
8129 double *uu_diff_ten,
8133 for (k=0;k<nPoints;k++)
8139 uu_diff_ten[k*1+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8149 double *uu_diff_ten,
double *uv_diff_ten,
8150 double *vu_diff_ten,
double *vv_diff_ten,
8155 for (k=0;k<nPoints;k++)
8161 uu_diff_ten[k*4+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8162 uu_diff_ten[k*4+3] = (E/(1.0+nu))*0.5;
8166 uv_diff_ten[k*4+1] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8167 uv_diff_ten[k*4+2] = (E/(1.0+nu))*0.5;
8173 vu_diff_ten[k*4+1] = (E/(1.0+nu))*0.5;
8174 vu_diff_ten[k*4+2] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8178 vv_diff_ten[k*4+0] = (E/(1.0+nu))*0.5;
8179 vv_diff_ten[k*4+3] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8193 double *uu_diff_ten,
double *uv_diff_ten,
double *uw_diff_ten,
8194 double *vu_diff_ten,
double *vv_diff_ten,
double *vw_diff_ten,
8195 double *wu_diff_ten,
double *wv_diff_ten,
double *ww_diff_ten,
8201 for (k=0;k<nPoints;k++)
8206 uu_diff_ten[k*9+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8207 uu_diff_ten[k*9+4] = (E/(1.0+nu))*0.5;
8208 uu_diff_ten[k*9+8] = (E/(1.0+nu))*0.5;
8211 uv_diff_ten[k*9+1] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8212 uv_diff_ten[k*9+3] = (E/(1.0+nu))*0.5;
8215 uw_diff_ten[k*9+2] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8216 uw_diff_ten[k*9+6] = (E/(1.0+nu))*0.5;
8221 vu_diff_ten[k*9+1] = (E/(1.0+nu))*0.5;
8222 vu_diff_ten[k*9+3] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8226 vv_diff_ten[k*9+0] = (E/(1.0+nu))*0.5;
8227 vv_diff_ten[k*9+4] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8228 vv_diff_ten[k*9+8] = (E/(1.0+nu))*0.5;
8231 vw_diff_ten[k*9+5] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8232 vw_diff_ten[k*9+7] = (E/(1.0+nu))*0.5;
8237 wu_diff_ten[k*9+2] = (E/(1.0+nu))*0.5;
8238 wu_diff_ten[k*9+6] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8241 wv_diff_ten[k*9+5] = (E/(1.0+nu))*0.5;
8242 wv_diff_ten[k*9+7] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8245 ww_diff_ten[k*9+0] = (E/(1.0+nu))*0.5;
8246 ww_diff_ten[k*9+4] = (E/(1.0+nu))*0.5;
8247 ww_diff_ten[k*9+8] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8259 const double *det_J,
8261 double *uu_diff_ten,
8266 for (k=0;k<nPoints;k++)
8272 uu_diff_ten[k*1+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8280 const double *det_J,
8283 double *uu_diff_ten,
double *uv_diff_ten,
8284 double *vu_diff_ten,
double *vv_diff_ten,
8290 for (k=0;k<nPoints;k++)
8296 uu_diff_ten[k*4+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8297 uu_diff_ten[k*4+3] = (E/(1.0+nu))*0.5;
8301 uv_diff_ten[k*4+1] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8302 uv_diff_ten[k*4+2] = (E/(1.0+nu))*0.5;
8308 vu_diff_ten[k*4+1] = (E/(1.0+nu))*0.5;
8309 vu_diff_ten[k*4+2] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8313 vv_diff_ten[k*4+0] = (E/(1.0+nu))*0.5;
8314 vv_diff_ten[k*4+3] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8325 const double *det_J,
8329 double *uu_diff_ten,
double *uv_diff_ten,
double *uw_diff_ten,
8330 double *vu_diff_ten,
double *vv_diff_ten,
double *vw_diff_ten,
8331 double *wu_diff_ten,
double *wv_diff_ten,
double *ww_diff_ten,
8338 for (k=0;k<nPoints;k++)
8344 uu_diff_ten[k*9+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8345 uu_diff_ten[k*9+4] = (E/(1.0+nu))*0.5;
8346 uu_diff_ten[k*9+8] = (E/(1.0+nu))*0.5;
8349 uv_diff_ten[k*9+1] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8350 uv_diff_ten[k*9+3] = (E/(1.0+nu))*0.5;
8353 uw_diff_ten[k*9+2] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8354 uw_diff_ten[k*9+6] = (E/(1.0+nu))*0.5;
8359 vu_diff_ten[k*9+1] = (E/(1.0+nu))*0.5;
8360 vu_diff_ten[k*9+3] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8364 vv_diff_ten[k*9+0] = (E/(1.0+nu))*0.5;
8365 vv_diff_ten[k*9+4] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8366 vv_diff_ten[k*9+8] = (E/(1.0+nu))*0.5;
8369 vw_diff_ten[k*9+5] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8370 vw_diff_ten[k*9+7] = (E/(1.0+nu))*0.5;
8375 wu_diff_ten[k*9+2] = (E/(1.0+nu))*0.5;
8376 wu_diff_ten[k*9+6] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8379 wv_diff_ten[k*9+5] = (E/(1.0+nu))*0.5;
8380 wv_diff_ten[k*9+7] = (E/(1.0+nu))*(nu/(1.0-2.0*nu));
8383 ww_diff_ten[k*9+0] = (E/(1.0+nu))*0.5;
8384 ww_diff_ten[k*9+4] = (E/(1.0+nu))*0.5;
8385 ww_diff_ten[k*9+8] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8395 double epsHeaviside,
8397 double epsDiffusion,
8405 int i,I,nSpace2=nSpace*nSpace;
8408 for (i=0;i<nPoints;i++)
8414 for (I=0;I<nSpace;I++)
8415 a[nSpace2*i+I*nSpace+I] = epsDiffusion;
8439 double epsHeaviside,
8448 for (i=0;i<nPoints;i++)
8474 double vx,
vy,
r,drdx,drdy,frac,dfrac,denom,ddenom;
8476 const int nSpace2 = nSpace*nSpace;
8477 const double eps = 1.0e-3;
8478 memset(a, 0, nPoints * nSpace2 *
sizeof(
double));
8481 for (k = 0; k < nPoints; k++)
8483 r = sqrt(x[k*3+0]*x[k*3+0] + x[k*3+1]*x[k*3+1] + eps);
8484 drdx = x[k*3+0]/
r; drdy = x[k*3+1]/
r;
8485 vx = 0.01*drdx/
r;
vy = 0.01*drdy/
r;
8486 denom = (0.2 - 0.4*
u[k] + 1.2*
u[k]*
u[k]);
8487 ddenom= 2.4*
u[k] - 0.4;
8488 frac=
u[k]*
u[k]/denom;
8489 dfrac = 2.0*
u[k]/denom -
u[k]*
u[k]*ddenom/(denom*denom);
8493 f[k*nSpace+0]=
vx*frac;
8494 f[k*nSpace+1]=
vy*frac;
8496 df[k*nSpace+0]=
vx*dfrac;
8497 df[k*nSpace+1]=
vy*dfrac;
8509 const double *meanGrainSize,
8512 const double *grad_p,
8515 const double *porosity,
8517 double *dmom_u_acc_u,
8519 double *dmom_v_acc_v,
8521 double *dmass_adv_u,
8522 double *dmass_adv_v,
8524 double *dmom_u_adv_u,
8525 double *dmom_u_adv_v,
8527 double *dmom_v_adv_u,
8528 double *dmom_v_adv_v,
8529 double *mom_u_diff_ten,
8530 double *mom_v_diff_ten,
8531 double *mom_uv_diff_ten,
8532 double *mom_vu_diff_ten,
8533 double *mom_u_source,
8534 double *mom_v_source,
8535 double *dmom_u_source_u,
8536 double *dmom_u_source_v,
8537 double *dmom_v_source_u,
8538 double *dmom_v_source_v,
8540 double *dmom_u_ham_grad_p,
8542 double *dmom_v_ham_grad_p)
8545 double Ftilde,Kinv,uc;
8546 for (k=0;k<nPoints;k++)
8550 mom_u_acc[k]=porosity[k]*rho*
u[k];
8551 dmom_u_acc_u[k]=porosity[k]*rho;
8554 mom_v_acc[k]=porosity[k]*rho*
v[k];
8555 dmom_v_acc_v[k]=porosity[k]*rho;
8558 mass_adv[k*2+0]=porosity[k]*
u[k];
8559 mass_adv[k*2+1]=porosity[k]*
v[k];
8561 dmass_adv_u[k*2+0]=porosity[k];
8562 dmass_adv_v[k*2+1]=porosity[k];
8565 mom_u_adv[k*2+0]=porosity[k]*rho*
u[k]*
u[k];
8566 mom_u_adv[k*2+1]=porosity[k]*rho*
u[k]*
v[k];
8568 dmom_u_adv_u[k*2+0]=2.0*porosity[k]*rho*
u[k];
8569 dmom_u_adv_u[k*2+1]=porosity[k]*rho*
v[k];
8571 dmom_u_adv_v[k*2+1]=porosity[k]*rho*
u[k];
8574 mom_v_adv[k*2+0]=porosity[k]*rho*
v[k]*
u[k];
8575 mom_v_adv[k*2+1]=porosity[k]*rho*
v[k]*
v[k];
8577 dmom_v_adv_u[k*2+0]=porosity[k]*rho*
v[k];
8579 dmom_v_adv_v[k*2+0]=porosity[k]*rho*
u[k];
8580 dmom_v_adv_v[k*2+1]=2.0*porosity[k]*rho*
v[k];
8583 mom_u_diff_ten[k*4+0] = 2.0*porosity[k]*mu;
8584 mom_u_diff_ten[k*4+3] = porosity[k]*mu;
8585 mom_uv_diff_ten[k*4+2]= porosity[k]*mu;
8588 mom_v_diff_ten[k*4+0] = porosity[k]*mu;
8589 mom_v_diff_ten[k*4+3] = 2.0*porosity[k]*mu;
8590 mom_vu_diff_ten[k*4+1] = porosity[k]*mu;
8597 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]);
8598 if (fabs(1.0-porosity[k]) < 1.0e-7)
8601 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu;
8606 if (fabs(porosity[k]) < 1.0e-7)
8609 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8611 mom_u_source[k] = -porosity[k]*rho*g[0] + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*
u[k];
8612 mom_v_source[k] = -porosity[k]*rho*g[1] + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*
v[k];
8614 dmom_u_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc +
u[k]*
u[k]/(uc+1.0e-12)));
8615 dmom_u_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
8617 dmom_v_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc +
v[k]*
v[k]/(uc+1.0e-12)));
8618 dmom_v_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
8622 mom_u_ham[k] = porosity[k]*grad_p[k*2+0];
8623 dmom_u_ham_grad_p[k*2+0]=porosity[k];
8626 mom_v_ham[k] = porosity[k]*grad_p[k*2+1];
8627 dmom_v_ham_grad_p[k*2+1]=porosity[k];
8633 const double* meanGrainSize,
8636 const double *grad_p,
8640 const double *porosity,
8642 double *dmom_u_acc_u,
8644 double *dmom_v_acc_v,
8646 double *dmom_w_acc_w,
8648 double *dmass_adv_u,
8649 double *dmass_adv_v,
8650 double *dmass_adv_w,
8652 double *dmom_u_adv_u,
8653 double *dmom_u_adv_v,
8654 double *dmom_u_adv_w,
8656 double *dmom_v_adv_u,
8657 double *dmom_v_adv_v,
8658 double *dmom_v_adv_w,
8660 double *dmom_w_adv_u,
8661 double *dmom_w_adv_v,
8662 double *dmom_w_adv_w,
8663 double *mom_u_diff_ten,
8664 double *mom_v_diff_ten,
8665 double *mom_w_diff_ten,
8666 double *mom_uv_diff_ten,
8667 double *mom_uw_diff_ten,
8668 double *mom_vu_diff_ten,
8669 double *mom_vw_diff_ten,
8670 double *mom_wu_diff_ten,
8671 double *mom_wv_diff_ten,
8672 double *mom_u_source,
8673 double *mom_v_source,
8674 double *mom_w_source,
8675 double *dmom_u_source_u,
8676 double *dmom_u_source_v,
8677 double *dmom_u_source_w,
8678 double *dmom_v_source_u,
8679 double *dmom_v_source_v,
8680 double *dmom_v_source_w,
8681 double *dmom_w_source_u,
8682 double *dmom_w_source_v,
8683 double *dmom_w_source_w,
8685 double *dmom_u_ham_grad_p,
8687 double *dmom_v_ham_grad_p,
8689 double *dmom_w_ham_grad_p)
8692 double Ftilde,Kinv,uc;
8693 for (k=0;k<nPoints;k++)
8697 mom_u_acc[k]=porosity[k]*rho*
u[k];
8698 dmom_u_acc_u[k]=porosity[k]*rho;
8701 mom_v_acc[k]=porosity[k]*rho*
v[k];
8702 dmom_v_acc_v[k]=porosity[k]*rho;
8705 mom_w_acc[k]=porosity[k]*rho*
w[k];
8706 dmom_w_acc_w[k]=porosity[k]*rho;
8710 mass_adv[k*3+0]=porosity[k]*
u[k];
8711 mass_adv[k*3+1]=porosity[k]*
v[k];
8712 mass_adv[k*3+2]=porosity[k]*
w[k];
8714 dmass_adv_u[k*3+0]=porosity[k];
8715 dmass_adv_v[k*3+1]=porosity[k];
8716 dmass_adv_w[k*3+2]=porosity[k];
8719 mom_u_adv[k*3+0]=porosity[k]*rho*
u[k]*
u[k];
8720 mom_u_adv[k*3+1]=porosity[k]*rho*
u[k]*
v[k];
8721 mom_u_adv[k*3+2]=porosity[k]*rho*
u[k]*
w[k];
8723 dmom_u_adv_u[k*3+0]=2.0*porosity[k]*rho*
u[k];
8724 dmom_u_adv_u[k*3+1]=porosity[k]*rho*
v[k];
8725 dmom_u_adv_u[k*3+2]=porosity[k]*rho*
w[k];
8727 dmom_u_adv_v[k*3+1]=porosity[k]*rho*
u[k];
8729 dmom_u_adv_w[k*3+2]=porosity[k]*rho*
u[k];
8732 mom_v_adv[k*3+0]=porosity[k]*rho*
v[k]*
u[k];
8733 mom_v_adv[k*3+1]=porosity[k]*rho*
v[k]*
v[k];
8734 mom_v_adv[k*3+2]=porosity[k]*rho*
v[k]*
w[k];
8736 dmom_v_adv_u[k*3+0]=porosity[k]*rho*
v[k];
8738 dmom_v_adv_w[k*3+2]=porosity[k]*rho*
v[k];
8740 dmom_v_adv_v[k*3+0]=porosity[k]*rho*
u[k];
8741 dmom_v_adv_v[k*3+1]=2.0*porosity[k]*rho*
v[k];
8742 dmom_v_adv_v[k*3+2]=porosity[k]*rho*
w[k];
8745 mom_w_adv[k*3+0]=porosity[k]*rho*
w[k]*
u[k];
8746 mom_w_adv[k*3+1]=porosity[k]*rho*
w[k]*
v[k];
8747 mom_w_adv[k*3+2]=porosity[k]*rho*
w[k]*
w[k];
8749 dmom_w_adv_u[k*3+0]=porosity[k]*rho*
w[k];
8751 dmom_w_adv_v[k*3+1]=porosity[k]*rho*
w[k];
8753 dmom_w_adv_w[k*3+0]=porosity[k]*rho*
u[k];
8754 dmom_w_adv_w[k*3+1]=porosity[k]*rho*
v[k];
8755 dmom_w_adv_w[k*3+2]=2.0*porosity[k]*rho*
w[k];
8758 mom_u_diff_ten[k*9+0] = 2.0*porosity[k]*mu;
8759 mom_u_diff_ten[k*9+4] = porosity[k]*mu;
8760 mom_u_diff_ten[k*9+8] = porosity[k]*mu;
8762 mom_uv_diff_ten[k*9+3]=porosity[k]*mu;
8764 mom_uw_diff_ten[k*9+6]=porosity[k]*mu;
8767 mom_v_diff_ten[k*9+0] = porosity[k]*mu;
8768 mom_v_diff_ten[k*9+4] = 2.0*porosity[k]*mu;
8769 mom_v_diff_ten[k*9+8] = porosity[k]*mu;
8771 mom_vu_diff_ten[k*9+1]=porosity[k]*mu;
8773 mom_vw_diff_ten[k*9+7]=porosity[k]*mu;
8776 mom_w_diff_ten[k*9+0] = porosity[k]*mu;
8777 mom_w_diff_ten[k*9+4] = porosity[k]*mu;
8778 mom_w_diff_ten[k*9+8] = 2.0*porosity[k]*mu;
8780 mom_wu_diff_ten[k*9+2]=porosity[k]*mu;
8782 mom_wv_diff_ten[k*9+5]=porosity[k]*mu;
8788 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]+
w[k]*
w[k]);
8789 if (fabs(1.0-porosity[k]) < 1.0e-7)
8792 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu;
8797 if (fabs(porosity[k]) < 1.0e-7)
8800 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8802 mom_u_source[k] = -porosity[k]*rho*g[0] + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*
u[k];
8803 mom_v_source[k] = -porosity[k]*rho*g[1] + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*
v[k];
8804 mom_w_source[k] = -porosity[k]*rho*g[2] + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*
w[k];
8806 dmom_u_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc +
u[k]*
u[k]/(uc+1.0e-12)));
8807 dmom_u_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
v[k]*
u[k]/(uc+1.0e-12)));
8808 dmom_u_source_w[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
w[k]*
u[k]/(uc+1.0e-12)));
8810 dmom_v_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc +
v[k]*
v[k]/(uc+1.0e-12)));
8811 dmom_v_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
8812 dmom_v_source_w[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
w[k]*
v[k]/(uc+1.0e-12)));
8814 dmom_w_source_w[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc +
w[k]*
w[k]/(uc+1.0e-12)));
8815 dmom_w_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
u[k]*
w[k]/(uc+1.0e-12)));
8816 dmom_w_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(
v[k]*
w[k]/(uc+1.0e-12)));
8819 mom_u_ham[k] = porosity[k]*grad_p[k*3+0];
8820 dmom_u_ham_grad_p[k*3+0]=porosity[k];
8823 mom_v_ham[k] = porosity[k]*grad_p[k*3+1];
8824 dmom_v_ham_grad_p[k*3+1]=porosity[k];
8827 mom_w_ham[k] = porosity[k]*grad_p[k*3+2];
8828 dmom_w_ham_grad_p[k*3+2]=porosity[k];
8833 const int killNonlinearDrag,
8834 const double eps_rho,
8835 const double eps_mu,
8841 const double* meanGrainSize,
8845 const double* kappa,
8847 const double *grad_p,
8850 const double *porosity,
8852 double *dmom_u_acc_u,
8854 double *dmom_v_acc_v,
8856 double *dmass_adv_u,
8857 double *dmass_adv_v,
8859 double *dmom_u_adv_u,
8860 double *dmom_u_adv_v,
8862 double *dmom_v_adv_u,
8863 double *dmom_v_adv_v,
8864 double *mom_u_diff_ten,
8865 double *mom_v_diff_ten,
8866 double *mom_uv_diff_ten,
8867 double *mom_vu_diff_ten,
8868 double *mom_u_source,
8869 double *mom_v_source,
8870 double *dmom_u_source_u,
8871 double *dmom_u_source_v,
8872 double *dmom_v_source_u,
8873 double *dmom_v_source_v,
8875 double *dmom_u_ham_grad_p,
8877 double *dmom_v_ham_grad_p)
8880 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
8881 double Ftilde,Kinv,uc;
8882 double nonlinearDragFactor = 1.0;
8883 if (killNonlinearDrag)
8884 nonlinearDragFactor = 0.0;
8885 for (k=0;k<nPoints;k++)
8898 mom_u_acc[k]=porosity[k]*
u[k];
8899 dmom_u_acc_u[k]=porosity[k];
8902 mom_v_acc[k]=porosity[k]*
v[k];
8903 dmom_v_acc_v[k]=porosity[k];
8907 mass_adv[k*2+0]=porosity[k]*
u[k];
8908 mass_adv[k*2+1]=porosity[k]*
v[k];
8910 dmass_adv_u[k*2+0]=porosity[k];
8911 dmass_adv_v[k*2+1]=porosity[k];
8914 mom_u_adv[k*2+0]=porosity[k]*
u[k]*
u[k];
8915 mom_u_adv[k*2+1]=porosity[k]*
u[k]*
v[k];
8917 dmom_u_adv_u[k*2+0]=2.0*porosity[k]*
u[k];
8918 dmom_u_adv_u[k*2+1]=porosity[k]*
v[k];
8920 dmom_u_adv_v[k*2+1]=porosity[k]*
u[k];
8923 mom_v_adv[k*2+0]=porosity[k]*
v[k]*
u[k];
8924 mom_v_adv[k*2+1]=porosity[k]*
v[k]*
v[k];
8926 dmom_v_adv_u[k*2+0]=porosity[k]*
v[k];
8928 dmom_v_adv_v[k*2+0]=porosity[k]*
u[k];
8929 dmom_v_adv_v[k*2+1]=2.0*porosity[k]*
v[k];
8931 #ifdef SCALAR_DIFFUSION
8933 mom_u_diff_ten[k*4+0] = nu*porosity[k];
8934 mom_u_diff_ten[k*4+3] = nu*porosity[k];
8937 mom_v_diff_ten[k*4+0] = nu*porosity[k];
8938 mom_v_diff_ten[k*4+3] = nu*porosity[k];
8941 mom_u_diff_ten[k*4+0] = 2.0*porosity[k]*nu;
8942 mom_u_diff_ten[k*4+3] = porosity[k]*nu;
8943 mom_uv_diff_ten[k*4+2]=porosity[k]*nu;
8946 mom_v_diff_ten[k*4+0] = porosity[k]*nu;
8947 mom_v_diff_ten[k*4+3] = 2.0*porosity[k]*nu;
8948 mom_vu_diff_ten[k*4+1] = porosity[k]*nu;
8953 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
8957 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]);
8958 if (fabs(1.0-porosity[k]) < 1.0e-7)
8961 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
8966 Ftilde *= nonlinearDragFactor;
8968 if (fabs(porosity[k]) < 1.0e-7)
8971 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8973 mom_u_source[k] = -porosity[k]*g[0] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*2+0]/(norm_n)
8974 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
u[k];
8975 mom_v_source[k] = -porosity[k]*rho*g[1] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*2+1]/(norm_n)
8976 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
v[k];
8978 dmom_u_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
u[k]*
u[k]/(uc+1.0e-12)));
8979 dmom_u_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
8981 dmom_v_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
v[k]*
v[k]/(uc+1.0e-12)));
8982 dmom_v_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
8986 mom_u_ham[k] = porosity[k]*grad_p[k*2+0]/rho;
8987 dmom_u_ham_grad_p[k*2+0]=porosity[k]/rho;
8990 mom_v_ham[k] = porosity[k]*grad_p[k*2+1]/rho;
8991 dmom_v_ham_grad_p[k*2+1]=porosity[k]/rho;
9080 const int killNonlinearDrag,
9081 const double eps_rho,
9082 const double eps_mu,
9088 const double* meanGrainSize,
9092 const double* kappa,
9094 const double *grad_p,
9097 const double *porosity,
9099 double *dmom_u_acc_u,
9101 double *dmom_v_acc_v,
9103 double *dmass_adv_u,
9104 double *dmass_adv_v,
9106 double *dmom_u_adv_u,
9107 double *dmom_u_adv_v,
9109 double *dmom_v_adv_u,
9110 double *dmom_v_adv_v,
9111 double *mom_u_diff_ten,
9112 double *mom_v_diff_ten,
9113 double *mom_uv_diff_ten,
9114 double *mom_vu_diff_ten,
9115 double *mom_u_source,
9116 double *mom_v_source,
9117 double *dmom_u_source_u,
9118 double *dmom_u_source_v,
9119 double *dmom_v_source_u,
9120 double *dmom_v_source_v,
9122 double *dmom_u_ham_grad_p,
9124 double *dmom_v_ham_grad_p)
9127 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n,uc,Ftilde,Kinv;
9128 const double div_eps = 1.0e-6;
9129 double nonlinearDragFactor = 1.0;
9130 if (killNonlinearDrag)
9131 nonlinearDragFactor = 0.0;
9132 for (k=0;k<nPoints;k++)
9144 mom_u_acc[k]=porosity[k]*
u[k];
9145 dmom_u_acc_u[k]=porosity[k];
9148 mom_v_acc[k]=porosity[k]*
v[k];
9149 dmom_v_acc_v[k]=porosity[k];
9152 mass_adv[k*2+0]=porosity[k]*
u[k];
9153 mass_adv[k*2+1]=porosity[k]*
v[k];
9155 dmass_adv_u[k*2+0]=porosity[k];
9156 dmass_adv_v[k*2+1]=porosity[k];
9159 mom_u_adv[k*2+0]=porosity[k]*
u[k]*
u[k];
9160 mom_u_adv[k*2+1]=porosity[k]*
u[k]*
v[k];
9162 dmom_u_adv_u[k*2+0]=2.0*porosity[k]*
u[k];
9163 dmom_u_adv_u[k*2+1]=porosity[k]*
v[k];
9165 dmom_u_adv_v[k*2+1]=porosity[k]*
u[k];
9168 mom_v_adv[k*2+0]=porosity[k]*
v[k]*
u[k];
9169 mom_v_adv[k*2+1]=porosity[k]*
v[k]*
v[k];
9171 dmom_v_adv_u[k*2+0]=porosity[k]*
v[k];
9173 dmom_v_adv_v[k*2+0]=porosity[k]*
u[k];
9174 dmom_v_adv_v[k*2+1]=2.0*porosity[k]*
v[k];
9177 mom_u_diff_ten[k*2+0] = 2.0*porosity[k]*nu;
9178 mom_u_diff_ten[k*2+1] = porosity[k]*nu;
9179 mom_uv_diff_ten[k]=porosity[k]*nu;
9182 mom_v_diff_ten[k*2+0] = porosity[k]*nu;
9183 mom_v_diff_ten[k*2+1] = 2.0*nu*porosity[k];
9184 mom_vu_diff_ten[k] = nu*porosity[k];
9187 norm_n = sqrt(
n[k*2+0]*
n[k*2+0]+
n[k*2+1]*
n[k*2+1]);
9191 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]);
9192 if (fabs(1.0-porosity[k]) < 1.0e-7)
9195 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9200 Ftilde *= nonlinearDragFactor;
9202 if (fabs(porosity[k]) < 1.0e-7)
9205 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9207 mom_u_source[k] = -porosity[k]*g[0] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*2+0]/(norm_n)
9208 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
u[k];
9209 mom_v_source[k] = -porosity[k]*g[1] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*2+1]/(norm_n)
9210 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
v[k];
9219 dmom_u_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*uc) +
9220 porosity[k]*porosity[k]*nu*Kinv*Ftilde*
u[k]*
u[k]/(uc+div_eps);
9221 dmom_u_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*Ftilde*
u[k]*
v[k]/(uc+div_eps);
9223 dmom_v_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*uc) +
9224 porosity[k]*porosity[k]*nu*Kinv*Ftilde*
v[k]*
v[k]/(uc+div_eps);
9225 dmom_v_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*Ftilde*
u[k]*
v[k]/(uc+div_eps);
9231 mom_u_ham[k] = porosity[k]*grad_p[k*2+0]/rho;
9232 dmom_u_ham_grad_p[k*2+0]=porosity[k]/rho;
9235 mom_v_ham[k] = porosity[k]*grad_p[k*2+1]/rho;
9236 dmom_v_ham_grad_p[k*2+1]=porosity[k]/rho;
9323 const int killNonlinearDrag,
9324 const double eps_rho,
9325 const double eps_mu,
9331 const double* meanGrainSize,
9335 const double* kappa,
9337 const double *grad_p,
9341 const double *porosity,
9343 double *dmom_u_acc_u,
9345 double *dmom_v_acc_v,
9347 double *dmom_w_acc_w,
9349 double *dmass_adv_u,
9350 double *dmass_adv_v,
9351 double *dmass_adv_w,
9353 double *dmom_u_adv_u,
9354 double *dmom_u_adv_v,
9355 double *dmom_u_adv_w,
9357 double *dmom_v_adv_u,
9358 double *dmom_v_adv_v,
9359 double *dmom_v_adv_w,
9361 double *dmom_w_adv_u,
9362 double *dmom_w_adv_v,
9363 double *dmom_w_adv_w,
9364 double *mom_u_diff_ten,
9365 double *mom_v_diff_ten,
9366 double *mom_w_diff_ten,
9367 double *mom_uv_diff_ten,
9368 double *mom_uw_diff_ten,
9369 double *mom_vu_diff_ten,
9370 double *mom_vw_diff_ten,
9371 double *mom_wu_diff_ten,
9372 double *mom_wv_diff_ten,
9373 double *mom_u_source,
9374 double *mom_v_source,
9375 double *mom_w_source,
9376 double *dmom_u_source_u,
9377 double *dmom_u_source_v,
9378 double *dmom_u_source_w,
9379 double *dmom_v_source_u,
9380 double *dmom_v_source_v,
9381 double *dmom_v_source_w,
9382 double *dmom_w_source_u,
9383 double *dmom_w_source_v,
9384 double *dmom_w_source_w,
9386 double *dmom_u_ham_grad_p,
9388 double *dmom_v_ham_grad_p,
9390 double *dmom_w_ham_grad_p)
9393 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n,
9395 double nonlinearDragFactor = 1.0;
9396 if (killNonlinearDrag)
9397 nonlinearDragFactor = 0.0;
9398 for (k=0;k<nPoints;k++)
9520 mom_u_acc[k]=porosity[k]*
u[k];
9521 dmom_u_acc_u[k]=porosity[k];
9524 mom_v_acc[k]=porosity[k]*
v[k];
9525 dmom_v_acc_v[k]=porosity[k];
9528 mom_w_acc[k]=porosity[k]*
w[k];
9529 dmom_w_acc_w[k]=porosity[k];
9533 mass_adv[k*3+0]=porosity[k]*
u[k];
9534 mass_adv[k*3+1]=porosity[k]*
v[k];
9535 mass_adv[k*3+2]=porosity[k]*
w[k];
9537 dmass_adv_u[k*3+0]=porosity[k];
9538 dmass_adv_v[k*3+1]=porosity[k];
9539 dmass_adv_w[k*3+2]=porosity[k];
9542 mom_u_adv[k*3+0]=porosity[k]*
u[k]*
u[k];
9543 mom_u_adv[k*3+1]=porosity[k]*
u[k]*
v[k];
9544 mom_u_adv[k*3+2]=porosity[k]*
u[k]*
w[k];
9546 dmom_u_adv_u[k*3+0]=2.0*porosity[k]*
u[k];
9547 dmom_u_adv_u[k*3+1]=porosity[k]*
v[k];
9548 dmom_u_adv_u[k*3+2]=porosity[k]*
w[k];
9550 dmom_u_adv_v[k*3+1]=porosity[k]*
u[k];
9552 dmom_u_adv_w[k*3+2]=porosity[k]*
u[k];
9555 mom_v_adv[k*3+0]=porosity[k]*
v[k]*
u[k];
9556 mom_v_adv[k*3+1]=porosity[k]*
v[k]*
v[k];
9557 mom_v_adv[k*3+2]=porosity[k]*
v[k]*
w[k];
9559 dmom_v_adv_u[k*3+0]=porosity[k]*
v[k];
9561 dmom_v_adv_w[k*3+2]=porosity[k]*
v[k];
9563 dmom_v_adv_v[k*3+0]=porosity[k]*
u[k];
9564 dmom_v_adv_v[k*3+1]=2.0*porosity[k]*
v[k];
9565 dmom_v_adv_v[k*3+2]=porosity[k]*
w[k];
9568 mom_w_adv[k*3+0]=porosity[k]*
w[k]*
u[k];
9569 mom_w_adv[k*3+1]=porosity[k]*
w[k]*
v[k];
9570 mom_w_adv[k*3+2]=porosity[k]*
w[k]*
w[k];
9572 dmom_w_adv_u[k*3+0]=porosity[k]*
w[k];
9574 dmom_w_adv_v[k*3+1]=porosity[k]*
w[k];
9576 dmom_w_adv_w[k*3+0]=porosity[k]*
u[k];
9577 dmom_w_adv_w[k*3+1]=porosity[k]*
v[k];
9578 dmom_w_adv_w[k*3+2]=2.0*porosity[k]*
w[k];
9581 mom_u_diff_ten[k*9+0] = 2.0*porosity[k]*nu;
9582 mom_u_diff_ten[k*9+4] = porosity[k]*nu;
9583 mom_u_diff_ten[k*9+8] = porosity[k]*nu;
9585 mom_uv_diff_ten[k*9+3]=porosity[k]*nu;
9587 mom_uw_diff_ten[k*9+6]=porosity[k]*nu;
9590 mom_v_diff_ten[k*9+0] = porosity[k]*nu;
9591 mom_v_diff_ten[k*9+4] = 2.0*porosity[k]*nu;
9592 mom_v_diff_ten[k*9+8] = porosity[k]*nu;
9594 mom_vu_diff_ten[k*9+1]=porosity[k]*nu;
9596 mom_vw_diff_ten[k*9+7]=porosity[k]*nu;
9599 mom_w_diff_ten[k*9+0] = porosity[k]*nu;
9600 mom_w_diff_ten[k*9+4] = porosity[k]*nu;
9601 mom_w_diff_ten[k*9+8] = 2.0*porosity[k]*nu;
9603 mom_wu_diff_ten[k*9+2]=porosity[k]*nu;
9605 mom_wv_diff_ten[k*9+5]=porosity[k]*nu;
9608 norm_n = sqrt(
n[k*3+0]*
n[k*3+0]+
n[k*3+1]*
n[k*3+1]+
n[k*3+2]*
n[k*3+2]);
9612 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]+
w[k]*
w[k]);
9613 if (fabs(1.0-porosity[k]) < 1.0e-7)
9616 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9621 Ftilde *= nonlinearDragFactor;
9623 if (fabs(porosity[k]) < 1.0e-7)
9626 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9628 mom_u_source[k] = -porosity[k]*g[0] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+0]/(rho*(norm_n+1.0e-8))
9629 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
u[k];
9630 mom_v_source[k] = -porosity[k]*g[1] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+1]/(rho*(norm_n+1.0e-8))
9631 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
v[k];
9632 mom_w_source[k] = -porosity[k]*g[2] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+2]/(rho*(norm_n+1.0e-8))
9633 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
w[k];
9635 dmom_u_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
u[k]*
u[k]/(uc+1.0e-12)));
9636 dmom_u_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
9637 dmom_u_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
w[k]/(uc+1.0e-12)));
9639 dmom_v_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
9640 dmom_v_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
v[k]*
v[k]/(uc+1.0e-12)));
9641 dmom_v_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
v[k]/(uc+1.0e-12)));
9643 dmom_w_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
u[k]/(uc+1.0e-12)));
9644 dmom_w_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
v[k]/(uc+1.0e-12)));
9645 dmom_w_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
w[k]*
w[k]/(uc+1.0e-12)));
9648 mom_u_ham[k] = porosity[k]*grad_p[k*3+0]/rho;
9649 dmom_u_ham_grad_p[k*3+0]=porosity[k]/rho;
9652 mom_v_ham[k] = porosity[k]*grad_p[k*3+1]/rho;
9653 dmom_v_ham_grad_p[k*3+1]=porosity[k]/rho;
9656 mom_w_ham[k] = porosity[k]*grad_p[k*3+2]/rho;
9657 dmom_w_ham_grad_p[k*3+2]=porosity[k]/rho;
9661 const int killNonlinearDrag,
9662 const double eps_rho,
9663 const double eps_mu,
9669 const double* meanGrainSize,
9673 const double* kappa,
9675 const double *grad_p,
9679 const double *porosity,
9681 double *dmom_u_acc_u,
9683 double *dmom_v_acc_v,
9685 double *dmom_w_acc_w,
9687 double *dmass_adv_u,
9688 double *dmass_adv_v,
9689 double *dmass_adv_w,
9691 double *dmom_u_adv_u,
9692 double *dmom_u_adv_v,
9693 double *dmom_u_adv_w,
9695 double *dmom_v_adv_u,
9696 double *dmom_v_adv_v,
9697 double *dmom_v_adv_w,
9699 double *dmom_w_adv_u,
9700 double *dmom_w_adv_v,
9701 double *dmom_w_adv_w,
9702 double *mom_u_diff_ten,
9703 double *mom_v_diff_ten,
9704 double *mom_w_diff_ten,
9705 double *mom_uv_diff_ten,
9706 double *mom_uw_diff_ten,
9707 double *mom_vu_diff_ten,
9708 double *mom_vw_diff_ten,
9709 double *mom_wu_diff_ten,
9710 double *mom_wv_diff_ten,
9711 double *mom_u_source,
9712 double *mom_v_source,
9713 double *mom_w_source,
9714 double *dmom_u_source_u,
9715 double *dmom_u_source_v,
9716 double *dmom_u_source_w,
9717 double *dmom_v_source_u,
9718 double *dmom_v_source_v,
9719 double *dmom_v_source_w,
9720 double *dmom_w_source_u,
9721 double *dmom_w_source_v,
9722 double *dmom_w_source_w,
9724 double *dmom_u_ham_grad_p,
9726 double *dmom_v_ham_grad_p,
9728 double *dmom_w_ham_grad_p)
9731 double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n,
9733 double nonlinearDragFactor = 1.0;
9734 if (killNonlinearDrag)
9735 nonlinearDragFactor = 0.0;
9736 for (k=0;k<nPoints;k++)
9750 mom_u_acc[k]=porosity[k]*
u[k];
9751 dmom_u_acc_u[k]=porosity[k];
9754 mom_v_acc[k]=porosity[k]*
v[k];
9755 dmom_v_acc_v[k]=porosity[k];
9758 mom_w_acc[k]=porosity[k]*
w[k];
9759 dmom_w_acc_w[k]=porosity[k];
9763 mass_adv[k*3+0]=porosity[k]*
u[k];
9764 mass_adv[k*3+1]=porosity[k]*
v[k];
9765 mass_adv[k*3+2]=porosity[k]*
w[k];
9767 dmass_adv_u[k*3+0]=porosity[k];
9768 dmass_adv_v[k*3+1]=porosity[k];
9769 dmass_adv_w[k*3+2]=porosity[k];
9772 mom_u_adv[k*3+0]=porosity[k]*
u[k]*
u[k];
9773 mom_u_adv[k*3+1]=porosity[k]*
u[k]*
v[k];
9774 mom_u_adv[k*3+2]=porosity[k]*
u[k]*
w[k];
9776 dmom_u_adv_u[k*3+0]=2.0*porosity[k]*
u[k];
9777 dmom_u_adv_u[k*3+1]=porosity[k]*
v[k];
9778 dmom_u_adv_u[k*3+2]=porosity[k]*
w[k];
9780 dmom_u_adv_v[k*3+1]=porosity[k]*
u[k];
9782 dmom_u_adv_w[k*3+2]=porosity[k]*
u[k];
9785 mom_v_adv[k*3+0]=porosity[k]*
v[k]*
u[k];
9786 mom_v_adv[k*3+1]=porosity[k]*
v[k]*
v[k];
9787 mom_v_adv[k*3+2]=porosity[k]*
v[k]*
w[k];
9789 dmom_v_adv_u[k*3+0]=porosity[k]*
v[k];
9791 dmom_v_adv_w[k*3+2]=porosity[k]*
v[k];
9793 dmom_v_adv_v[k*3+0]=porosity[k]*
u[k];
9794 dmom_v_adv_v[k*3+1]=2.0*porosity[k]*
v[k];
9795 dmom_v_adv_v[k*3+2]=porosity[k]*
w[k];
9798 mom_w_adv[k*3+0]=porosity[k]*
w[k]*
u[k];
9799 mom_w_adv[k*3+1]=porosity[k]*
w[k]*
v[k];
9800 mom_w_adv[k*3+2]=porosity[k]*
w[k]*
w[k];
9802 dmom_w_adv_u[k*3+0]=porosity[k]*
w[k];
9804 dmom_w_adv_v[k*3+1]=porosity[k]*
w[k];
9806 dmom_w_adv_w[k*3+0]=porosity[k]*
u[k];
9807 dmom_w_adv_w[k*3+1]=porosity[k]*
v[k];
9808 dmom_w_adv_w[k*3+2]=2.0*porosity[k]*
w[k];
9811 mom_u_diff_ten[k*3+0] = 2.0*porosity[k]*nu;
9812 mom_u_diff_ten[k*3+1] = porosity[k]*nu;
9813 mom_u_diff_ten[k*3+2] = porosity[k]*nu;
9815 mom_uv_diff_ten[k]=porosity[k]*nu;
9817 mom_uw_diff_ten[k]=porosity[k]*nu;
9820 mom_v_diff_ten[k*3+0] = porosity[k]*nu;
9821 mom_v_diff_ten[k*3+1] = 2.0*porosity[k]*nu;
9822 mom_v_diff_ten[k*3+2] = porosity[k]*nu;
9824 mom_vu_diff_ten[k]=porosity[k]*nu;
9826 mom_vw_diff_ten[k]=porosity[k]*nu;
9829 mom_w_diff_ten[k*3+0] = porosity[k]*nu;
9830 mom_w_diff_ten[k*3+1] = porosity[k]*nu;
9831 mom_w_diff_ten[k*3+2] = 2.0*porosity[k]*nu;
9833 mom_wu_diff_ten[k]=porosity[k]*nu;
9835 mom_wv_diff_ten[k]=porosity[k]*nu;
9838 norm_n = sqrt(
n[k*3+0]*
n[k*3+0]+
n[k*3+1]*
n[k*3+1]+
n[k*3+2]*
n[k*3+2]);
9841 uc = sqrt(
u[k]*
u[k]+
v[k]*
v[k]+
w[k]*
w[k]);
9842 if (fabs(1.0-porosity[k]) < 1.0e-7)
9845 Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9850 Ftilde *= nonlinearDragFactor;
9852 if (fabs(porosity[k]) < 1.0e-7)
9855 Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9857 mom_u_source[k] = -porosity[k]*g[0] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+0]/(rho*(norm_n+1.0e-8))
9858 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
u[k];
9859 mom_v_source[k] = -porosity[k]*g[1] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+1]/(rho*(norm_n+1.0e-8))
9860 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
v[k];
9861 mom_w_source[k] = -porosity[k]*g[2] - porosity[k]*d_mu*sigma*kappa[k]*
n[k*3+2]/(rho*(norm_n+1.0e-8))
9862 + porosity[k]*porosity[k]*nu*Kinv*(1.0+Ftilde*uc)*
w[k];
9864 dmom_u_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
u[k]*
u[k]/(uc+1.0e-12)));
9865 dmom_u_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
9866 dmom_u_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
w[k]/(uc+1.0e-12)));
9868 dmom_v_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
u[k]*
v[k]/(uc+1.0e-12)));
9869 dmom_v_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
v[k]*
v[k]/(uc+1.0e-12)));
9870 dmom_v_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
v[k]/(uc+1.0e-12)));
9872 dmom_w_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
u[k]/(uc+1.0e-12)));
9873 dmom_w_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(
w[k]*
v[k]/(uc+1.0e-12)));
9874 dmom_w_source_w[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc +
w[k]*
w[k]/(uc+1.0e-12)));
9878 mom_u_ham[k] = porosity[k]*grad_p[k*3+0]/rho;
9879 dmom_u_ham_grad_p[k*3+0]=porosity[k]/rho;
9882 mom_v_ham[k] = porosity[k]*grad_p[k*3+1]/rho;
9883 dmom_v_ham_grad_p[k*3+1]=porosity[k]/rho;
9886 mom_w_ham[k] = porosity[k]*grad_p[k*3+2]/rho;
9887 dmom_w_ham_grad_p[k*3+2]=porosity[k]/rho;
9904 for (i=0;i<nPoints;i++)
9906 m[i]=
u[i]*porosity[i];
9908 for (I=0;I<nSpace;I++)
9912 f[i*nSpace+I] = porosity[i]*
v[i*nSpace+I]*
u[i];
9913 df[i*nSpace+I] = porosity[i]*
v[i*nSpace+I];
10016 double nu_t,dnu_t_dk,dnu_t_de,PiD4,eval,kval,disp,ddisp_dk,ddisp_de;
10017 const double div_eps = 1.0e-6;
10018 for (i = 0; i < nPoints; i++)
10020 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10021 kval = k[i] >= 0.0 ? k[i] : 0.0;
10023 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10024 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10025 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10028 nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10038 m_e[i] = epsilon[i];
10042 for (I=0; I < nSpace; I++)
10044 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10045 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10047 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10048 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10053 phi_e[i] = epsilon[i];
10057 for (I=0; I < nSpace; I++)
10059 a_k[i*nSpace*nSpace + I*nSpace + I] = nu_t/sigma_k + nu;
10060 da_k_dk[i*nSpace*nSpace + I*nSpace + I] = dnu_t_dk/sigma_k;
10061 da_k_de[i*nSpace*nSpace + I*nSpace + I] = dnu_t_de/sigma_k;
10063 a_e[i*nSpace*nSpace + I*nSpace + I] = nu_t/sigma_e + nu;
10064 da_e_dk[i*nSpace*nSpace + I*nSpace + I] = dnu_t_dk/sigma_e;
10065 da_e_de[i*nSpace*nSpace + I*nSpace + I] = dnu_t_de/sigma_e;
10070 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] + gradv[i*nSpace+1]*gradv[i*nSpace+1]) +
10071 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0]);
10073 r_k[i] = -nu_t*PiD4 + epsilon[i];
10074 dr_k_dk[i] = -dnu_t_dk*PiD4;
10075 dr_k_de[i] = -dnu_t_de*PiD4 + 1.0;
10077 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10078 ddisp_dk = -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps);
10079 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10082 disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10084 r_e[i] = -c_1*k[i]*PiD4 + disp;
10085 dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;
10086 dr_e_de[i] = ddisp_de;
10131 double nu_t,dnu_t_dk,dnu_t_de,PiD4,eval,kval,disp,ddisp_dk,ddisp_de;
10132 const double div_eps = 1.0e-6;
10133 for (i = 0; i < nPoints; i++)
10135 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10136 kval = k[i] >= 0.0 ? k[i] : 0.0;
10138 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10139 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10140 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10143 nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10153 m_e[i] = epsilon[i];
10157 for (I=0; I < nSpace; I++)
10159 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10160 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10162 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10163 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10168 phi_e[i] = epsilon[i];
10172 for (I=0; I < nSpace; I++)
10174 a_k[i*2+I] = nu_t/sigma_k + nu;
10175 da_k_dk[i*2 + I] = dnu_t_dk/sigma_k;
10176 da_k_de[i*2 + I] = dnu_t_de/sigma_k;
10178 a_e[i*2 + I] = nu_t/sigma_e + nu;
10179 da_e_dk[i*2 + I] = dnu_t_dk/sigma_e;
10180 da_e_de[i*2 + I] = dnu_t_de/sigma_e;
10185 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] + gradv[i*nSpace+1]*gradv[i*nSpace+1]) +
10186 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0]);
10188 r_k[i] = -nu_t*PiD4 + epsilon[i];
10189 dr_k_dk[i] = -dnu_t_dk*PiD4;
10190 dr_k_de[i] = -dnu_t_de*PiD4 + 1.0;
10192 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10193 ddisp_dk = -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps);
10194 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10197 disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10199 r_e[i] = -c_1*k[i]*PiD4 + disp;
10200 dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;
10201 dr_e_de[i] = ddisp_de;
10247 double nu_t,dnu_t_dk,dnu_t_de,PiD4,eval,kval,disp,ddisp_dk,ddisp_de;
10248 const double div_eps = 1.0e-6;
10249 for (i = 0; i < nPoints; i++)
10251 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10252 kval = k[i] >= 0.0 ? k[i] : 0.0;
10254 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10255 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10256 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10259 nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10269 m_e[i] = epsilon[i];
10273 for (I=0; I < nSpace; I++)
10275 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10276 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10278 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10279 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10284 phi_e[i] = epsilon[i];
10288 for (I=0; I < nSpace; I++)
10290 a_k[i*nSpace+I] = nu_t/sigma_k + nu;
10291 da_k_dk[i*nSpace + I] = dnu_t_dk/sigma_k;
10292 da_k_de[i*nSpace + I] = dnu_t_de/sigma_k;
10294 a_e[i*nSpace + I] = nu_t/sigma_e + nu;
10295 da_e_dk[i*nSpace + I] = dnu_t_dk/sigma_e;
10296 da_e_de[i*nSpace + I] = dnu_t_de/sigma_e;
10301 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] +
10302 gradv[i*nSpace+1]*gradv[i*nSpace+1] +
10303 gradw[i*nSpace+2]*gradw[i*nSpace+2])
10305 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10307 (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10309 (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10312 r_k[i] = -nu_t*PiD4 + epsilon[i];
10313 dr_k_dk[i] = -dnu_t_dk*PiD4;
10314 dr_k_de[i] = -dnu_t_de*PiD4 + 1.0;
10316 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10317 ddisp_dk = -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps);
10318 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10321 disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10323 r_e[i] = -c_1*k[i]*PiD4 + disp;
10324 dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;
10325 dr_e_de[i] = ddisp_de;
10371 double nu_t,dnu_t_dk,dnu_t_de,PiD4,eval,kval,disp,ddisp_dk,ddisp_de;
10372 const double div_eps = 1.0e-6;
10373 for (i = 0; i < nPoints; i++)
10375 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10376 kval = k[i] >= 0.0 ? k[i] : 0.0;
10378 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10379 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10380 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10383 nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10393 m_e[i] = epsilon[i];
10397 for (I=0; I < nSpace; I++)
10399 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10400 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10402 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10403 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10408 phi_e[i] = epsilon[i];
10412 for (I=0; I < nSpace; I++)
10414 a_k[i*nSpace*nSpace + I*nSpace + I] = nu_t/sigma_k + nu;
10415 da_k_dk[i*nSpace*nSpace + I*nSpace + I] = dnu_t_dk/sigma_k;
10416 da_k_de[i*nSpace*nSpace + I*nSpace + I] = dnu_t_de/sigma_k;
10418 a_e[i*nSpace*nSpace + I*nSpace + I] = nu_t/sigma_e + nu;
10419 da_e_dk[i*nSpace*nSpace + I*nSpace + I] = dnu_t_dk/sigma_e;
10420 da_e_de[i*nSpace*nSpace + I*nSpace + I] = dnu_t_de/sigma_e;
10425 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] +
10426 gradv[i*nSpace+1]*gradv[i*nSpace+1] +
10427 gradw[i*nSpace+2]*gradw[i*nSpace+2])
10429 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10431 (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10433 (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10436 r_k[i] = -nu_t*PiD4 + epsilon[i];
10437 dr_k_dk[i] = -dnu_t_dk*PiD4;
10438 dr_k_de[i] = -dnu_t_de*PiD4 + 1.0;
10440 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10441 ddisp_dk = -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps);
10442 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10445 disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10447 r_e[i] = -c_1*k[i]*PiD4 + disp;
10448 dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;
10449 dr_e_de[i] = ddisp_de;
10479 double nu_t,dnu_t_dk,PiD4,eval,kval,disp,ddisp_dk,ddisp_de;
10480 const double div_eps = 1.0e-3;
10481 for (i = 0; i < nPoints; i++)
10483 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10484 kval = k[i] >= 0.0 ? k[i] : 0.0;
10486 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10487 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10490 nu_t = 0.0; dnu_t_dk = 0.0;
10500 for (I=0; I < nSpace; I++)
10502 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10503 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10509 for (I=0; I < nSpace; I++)
10511 a_k[i*2+I] = nu_t/sigma_k + nu;
10512 da_k_dk[i*2 + I] = dnu_t_dk/sigma_k;
10518 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] + gradv[i*nSpace+1]*gradv[i*nSpace+1]) +
10519 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0]);
10521 r_k[i] = -nu_t*PiD4 + epsilon[i];
10522 dr_k_dk[i] = -dnu_t_dk*PiD4;
10552 double nu_t,dnu_t_de,PiD4,eval,kval,disp,ddisp_de;
10553 const double div_eps = 1.0e-3;
10554 for (i = 0; i < nPoints; i++)
10556 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10557 kval = k[i] >= 0.0 ? k[i] : 0.0;
10559 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10560 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10563 nu_t = 0.0; dnu_t_de = 0.0;
10570 m_e[i] = epsilon[i];
10574 for (I=0; I < nSpace; I++)
10576 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10577 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10580 phi_e[i] = epsilon[i];
10584 for (I=0; I < nSpace; I++)
10586 a_e[i*2 + I] = nu_t/sigma_e + nu;
10587 da_e_de[i*2 + I] = dnu_t_de/sigma_e;
10592 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] + gradv[i*nSpace+1]*gradv[i*nSpace+1]) +
10593 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0]);
10595 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10596 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10599 disp = 0.0; ddisp_de = 0.0;
10601 r_e[i] = -c_1*k[i]*PiD4 + disp;
10602 dr_e_de[i] = ddisp_de;
10629 double nu_t,dnu_t_dk,PiD4,eval,kval;
10630 const double div_eps = 1.0e-6;
10631 for (i = 0; i < nPoints; i++)
10633 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10634 kval = k[i] >= 0.0 ? k[i] : 0.0;
10636 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10637 dnu_t_dk = 2.0*c_mu*k[i]/(epsilon[i]+div_eps);
10640 nu_t = 0.0; dnu_t_dk = 0.0;
10651 for (I=0; I < nSpace; I++)
10653 f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10654 df_k[i*nSpace+I]= velocity[i*nSpace+I];
10662 for (I=0; I < nSpace; I++)
10664 a_k[i*nSpace+I] = nu_t/sigma_k + nu;
10665 da_k_dk[i*nSpace + I] = dnu_t_dk/sigma_k;
10670 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] +
10671 gradv[i*nSpace+1]*gradv[i*nSpace+1] +
10672 gradw[i*nSpace+2]*gradw[i*nSpace+2])
10674 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10676 (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10678 (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10681 r_k[i] = -nu_t*PiD4 + epsilon[i];
10682 dr_k_dk[i] = -dnu_t_dk*PiD4;
10713 double nu_t,dnu_t_de,PiD4,eval,kval,disp,ddisp_de;
10714 const double div_eps = 1.0e-6;
10715 for (i = 0; i < nPoints; i++)
10717 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10718 kval = k[i] >= 0.0 ? k[i] : 0.0;
10720 nu_t = c_mu*k[i]*k[i]/(epsilon[i]+div_eps);
10721 dnu_t_de =-c_mu*k[i]*k[i]/(epsilon[i]*epsilon[i]+div_eps);
10724 nu_t = 0.0; dnu_t_de = 0.0;
10731 m_e[i] = epsilon[i];
10735 for (I=0; I < nSpace; I++)
10737 f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10738 df_e[i*nSpace+I]= velocity[i*nSpace+I];
10741 phi_e[i] = epsilon[i];
10745 for (I=0; I < nSpace; I++)
10747 a_e[i*nSpace + I] = nu_t/sigma_e + nu;
10748 da_e_de[i*nSpace + I] = dnu_t_de/sigma_e;
10753 PiD4 = 2.0*(gradu[i*nSpace+0]*gradu[i*nSpace+0] +
10754 gradv[i*nSpace+1]*gradv[i*nSpace+1] +
10755 gradw[i*nSpace+2]*gradw[i*nSpace+2])
10757 (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10759 (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10761 (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10764 disp = c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);
10765 ddisp_de = 2.0*c_2*epsilon[i]/(k[i]+div_eps);
10768 disp = 0.0; ddisp_de = 0.0;
10770 r_e[i] = -c_1*k[i]*PiD4 + disp;
10771 dr_e_de[i] = ddisp_de;
10812 const double* grad_k,
10813 const double* epsilon,
10814 double *mom_u_diff_ten,
10815 double *mom_v_diff_ten,
10816 double *mom_uv_diff_ten,
10817 double *mom_vu_diff_ten,
10818 double *mom_u_source,
10819 double *mom_v_source)
10822 double nu_t,eval,kval;
10823 const double twoThirds = 2.0/3.0;
10824 const double div_zero = 1.0e-6;
10825 for (i=0;i<nPoints;i++)
10827 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10828 kval = k[i] >= 0.0 ? k[i] : 0.0;
10830 nu_t= c_mu*kval*kval/(eval+div_zero);
10831 #ifdef SCALAR_DIFFUSION
10833 mom_u_diff_ten[i*4+0] += nu_t;
10834 mom_u_diff_ten[i*4+3] += nu_t;
10837 mom_v_diff_ten[i*4+0] += nu_t;
10838 mom_v_diff_ten[i*4+3] += nu_t;
10841 mom_u_diff_ten[i*4+0] += 2.0*nu_t;
10842 mom_u_diff_ten[i*4+3] += nu_t;
10843 mom_uv_diff_ten[i*4+2]+= nu_t;
10846 mom_v_diff_ten[i*4+0] += nu_t;
10847 mom_v_diff_ten[i*4+3] += 2.0*nu_t;
10848 mom_vu_diff_ten[i*4+1] += nu_t;
10853 mom_u_source[i] += twoThirds*grad_k[i*2+0];
10854 mom_v_source[i] += twoThirds*grad_k[i*2+1];
10895 const double* grad_k,
10896 const double* epsilon,
10897 double *mom_u_diff_ten,
10898 double *mom_v_diff_ten,
10899 double *mom_uv_diff_ten,
10900 double *mom_vu_diff_ten,
10901 double *mom_u_source,
10902 double *mom_v_source)
10905 double nu_t,eval,kval;
10906 const double twoThirds = 2.0/3.0;
10907 const double div_zero = 1.0e-6;
10908 for (i=0;i<nPoints;i++)
10910 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10911 kval = k[i] >= 0.0 ? k[i] : 0.0;
10913 nu_t= c_mu*kval*kval/(eval+div_zero);
10916 mom_u_diff_ten[i*2+0] += 2.0*nu_t;
10917 mom_u_diff_ten[i*2+1] += nu_t;
10918 mom_uv_diff_ten[i]+= nu_t;
10921 mom_v_diff_ten[i*2+0] += nu_t;
10922 mom_v_diff_ten[i*2+1] += 2.0*nu_t;
10923 mom_vu_diff_ten[i] += nu_t;
10927 mom_u_source[i] += twoThirds*grad_k[i*2+0];
10928 mom_v_source[i] += twoThirds*grad_k[i*2+1];
10936 const double* grad_k,
10937 const double* epsilon,
10938 double *mom_u_diff_ten,
10939 double *mom_v_diff_ten,
10940 double *mom_w_diff_ten,
10941 double *mom_uv_diff_ten,
10942 double *mom_uw_diff_ten,
10943 double *mom_vu_diff_ten,
10944 double *mom_vw_diff_ten,
10945 double *mom_wu_diff_ten,
10946 double *mom_wv_diff_ten,
10947 double *mom_u_source,
10948 double *mom_v_source,
10949 double *mom_w_source)
10952 double nu_t,eval,kval;
10953 const double twoThirds = 2.0/3.0;
10954 const double div_zero = 1.0e-6;
10955 for (i=0;i<nPoints;i++)
10957 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10958 kval = k[i] >= 0.0 ? k[i] : 0.0;
10960 nu_t= c_mu*kval*kval/(eval+div_zero);
10962 mom_u_diff_ten[i*9+0] += 2.0*nu_t;
10963 mom_u_diff_ten[i*9+4] += nu_t;
10964 mom_u_diff_ten[i*9+8] += nu_t;
10966 mom_uv_diff_ten[i*9+3]+=nu_t;
10968 mom_uw_diff_ten[i*9+6]+=nu_t;
10971 mom_v_diff_ten[i*9+0] += nu_t;
10972 mom_v_diff_ten[i*9+4] += 2.0*nu_t;
10973 mom_v_diff_ten[i*9+8] += nu_t;
10975 mom_vu_diff_ten[i*9+1]+=nu_t;
10977 mom_vw_diff_ten[i*9+7]+=nu_t;
10980 mom_w_diff_ten[i*9+0] += nu_t;
10981 mom_w_diff_ten[i*9+4] += nu_t;
10982 mom_w_diff_ten[i*9+8] += 2.0*nu_t;
10984 mom_wu_diff_ten[i*9+2]+=nu_t;
10986 mom_wv_diff_ten[i*9+5]+=nu_t;
10990 mom_u_source[i] += twoThirds*grad_k[i*3+0];
10991 mom_v_source[i] += twoThirds*grad_k[i*3+1];
10992 mom_w_source[i] += twoThirds*grad_k[i*3+2];
11000 const double* grad_k,
11001 const double* epsilon,
11002 double *mom_u_diff_ten,
11003 double *mom_v_diff_ten,
11004 double *mom_w_diff_ten,
11005 double *mom_uv_diff_ten,
11006 double *mom_uw_diff_ten,
11007 double *mom_vu_diff_ten,
11008 double *mom_vw_diff_ten,
11009 double *mom_wu_diff_ten,
11010 double *mom_wv_diff_ten,
11011 double *mom_u_source,
11012 double *mom_v_source,
11013 double *mom_w_source)
11016 double nu_t,eval,kval;
11017 const double twoThirds = 2.0/3.0;
11018 const double div_zero = 1.0e-6;
11019 for (i=0;i<nPoints;i++)
11021 eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
11022 kval = k[i] >= 0.0 ? k[i] : 0.0;
11024 nu_t= c_mu*kval*kval/(eval+div_zero);
11026 mom_u_diff_ten[i*3+0] += 2.0*nu_t;
11027 mom_u_diff_ten[i*3+1] += nu_t;
11028 mom_u_diff_ten[i*3+2] += nu_t;
11030 mom_uv_diff_ten[i]+=nu_t;
11032 mom_uw_diff_ten[i]+=nu_t;
11035 mom_v_diff_ten[i*3+0] += nu_t;
11036 mom_v_diff_ten[i*3+1] += 2.0*nu_t;
11037 mom_v_diff_ten[i*3+2] += nu_t;
11039 mom_vu_diff_ten[i]+=nu_t;
11041 mom_vw_diff_ten[i]+=nu_t;
11044 mom_w_diff_ten[i*3+0] += nu_t;
11045 mom_w_diff_ten[i*3+1] += nu_t;
11046 mom_w_diff_ten[i*3+2] += 2.0*nu_t;
11048 mom_wu_diff_ten[i]+=nu_t;
11050 mom_wv_diff_ten[i]+=nu_t;
11052 mom_u_source[i] += twoThirds*grad_k[i*3+0];
11053 mom_v_source[i] += twoThirds*grad_k[i*3+1];
11054 mom_w_source[i] += twoThirds*grad_k[i*3+2];
11062 const int nSpheres,
11063 const double * radii,
11064 const double * centers,
11071 double minDistance,distance,tmp;
11073 for (k=0; k < nPoints; k++)
11075 for (j=0; j < nSpheres; j++)
11078 for (i=0; i < nSpace; i++)
11080 tmp += (x[3*k+i]-centers[3*j+i])*(x[3*k+i]-centers[3*j+i]);
11082 distance = sqrt(tmp) - radii[j];
11085 minDistance = distance;
11086 for (i=0; i < nSpace; i++)
11088 n[k*nSpace + i]= (x[3*k+i]-centers[3*j+i])/(distance+1.0e-12);
11091 else if (fabs(distance) < fabs(minDistance))
11093 minDistance=distance;
11094 for (i=0; i < nSpace; i++)
11096 n[k*nSpace + i]= (x[3*k+i]-centers[3*j+i])/(distance+1.0e-12);
11100 phi[k] = minDistance;
11108 const double h_eps,
11110 const double bedFrictionCoefficient,
11111 const double bedFrictionPower,
11112 const double eddyViscosity,
11114 const double* db_dx,
11119 double *dmass_acc_dh,
11121 double *dmom_acc_dhu,
11123 double *dmass_adv_dhu,
11125 double *dmom_adv_dh,
11126 double *dmom_adv_dhu,
11127 double *mom_source,
11128 double *dmom_source_dh,
11129 double *dmom_source_dhu,
11133 double u,du_dh,du_dhu,heval,hpow,hunorm;
11134 for (k=0;k<nPoints;k++)
11145 du_dh = -hu[k]/(h[k]*h[k]);
11149 H[k] = h[k] + x[k*3+1];
11151 mass_acc[k] = h[k];
11152 dmass_acc_dh[k] = 1.0;
11154 mom_acc[k] = hu[k];
11155 dmom_acc_dhu[k] = 1.0;
11157 mass_adv[k] = hu[k];
11158 dmass_adv_dhu[k] = 1.0;
11160 mom_adv[k] = hu[k]*
u+0.5*g*h[k]*h[k];
11161 dmom_adv_dh[k] = hu[k]*du_dh+g*h[k];
11162 dmom_adv_dhu[k] =
u + hu[k]*du_dhu;
11165 mom_diff[k] = eddyViscosity;
11167 mom_source[k] = g*h[k]*db_dx[k];
11168 dmom_source_dh[k]= g*db_dx[k];
11170 heval=fmax(1.0e-3,h[k]);
11171 hpow =pow(heval,-bedFrictionPower-2.0);
11172 hunorm = fabs(hu[k]);
11173 mom_source[k] += g*hu[k]*bedFrictionCoefficient*hunorm*hpow;
11174 dmom_source_dh[k] += -(bedFrictionPower+2.0)*g*hu[k]*bedFrictionCoefficient*hunorm*pow(heval,-bedFrictionPower-3.0);
11175 dmom_source_dhu[k] = g*bedFrictionCoefficient*hunorm*hpow
11176 +g*bedFrictionCoefficient*hu[k]*hu[k]*hpow/(hunorm+h_eps);
11181 const double h_eps,
11183 const double bedFrictionCoefficient,
11184 const double bedFrictionPower,
11185 const double eddyViscosity,
11187 const double* grad_b,
11193 double *dmass_acc_dh,
11195 double *dmom_u_acc_dhu,
11197 double *dmom_v_acc_dhv,
11199 double *dmass_adv_dhu,
11200 double *dmass_adv_dhv,
11202 double *dmom_u_adv_dh,
11203 double *dmom_u_adv_dhu,
11204 double *dmom_u_adv_dhv,
11206 double *dmom_v_adv_dh,
11207 double *dmom_v_adv_dhu,
11208 double *dmom_v_adv_dhv,
11209 double *mom_u_diff,
11210 double *mom_v_diff,
11211 double *mom_u_source,
11212 double *dmom_u_source_dh,
11213 double *dmom_u_source_dhu,
11214 double *dmom_u_source_dhv,
11215 double *mom_v_source,
11216 double *dmom_v_source_dh,
11217 double *dmom_v_source_dhu,
11218 double *dmom_v_source_dhv)
11221 double u,du_dh,du_dhu,
v,dv_dh,dv_dhv,heval,unorm,hpow;
11222 for (k=0;k<nPoints;k++)
11237 du_dh = -hu[k]/(h[k]*h[k]);
11241 dv_dh = -hv[k]/(h[k]*h[k]);
11245 H[k] = h[k] + x[k*3+2];
11247 mass_acc[k] = h[k];
11248 dmass_acc_dh[k] = 1.0;
11250 mass_adv[2*k+0] = hu[k];
11251 dmass_adv_dhu[2*k+0] = 1.0;
11253 mass_adv[2*k+1] = hv[k];
11254 dmass_adv_dhv[2*k+1] = 1.0;
11257 mom_u_acc[k] = hu[k];
11258 dmom_u_acc_dhu[k] = 1.0;
11260 mom_u_adv[2*k+0] = hu[k]*
u+0.5*g*h[k]*h[k];
11261 dmom_u_adv_dh[2*k+0] = hu[k]*du_dh+g*h[k];
11262 dmom_u_adv_dhu[2*k+0] =
u+hu[k]*du_dhu;
11264 mom_u_adv[2*k+1] = hu[k]*
v;
11265 dmom_u_adv_dh[2*k+1] = hu[k]*dv_dh;
11266 dmom_u_adv_dhu[2*k+1] =
v;
11267 dmom_u_adv_dhv[2*k+1] = hu[k]*dv_dhv;
11273 mom_u_diff[2*k+0] = eddyViscosity;
11274 mom_u_diff[2*k+1] = eddyViscosity;
11277 mom_v_acc[k] = hv[k];
11278 dmom_v_acc_dhv[k] = 1.0;
11280 mom_v_adv[2*k+0] = hv[k]*
u;
11281 dmom_v_adv_dh[2*k+0] = hv[k]*du_dh;
11282 dmom_v_adv_dhu[2*k+0] = hv[k]*du_dhu;
11283 dmom_v_adv_dhv[2*k+0] =
u;
11285 mom_v_adv[2*k+1] = hv[k]*
v+0.5*g*h[k]*h[k];
11286 dmom_v_adv_dh[2*k+1] = hv[k]*dv_dh+g*h[k];
11287 dmom_v_adv_dhv[2*k+1] =
v + hv[k]*dv_dhv;
11293 mom_v_diff[2*k+0] = eddyViscosity;
11294 mom_v_diff[2*k+1] = eddyViscosity;
11296 mom_u_source[k] = g*h[k]*grad_b[k*2+0];
11297 dmom_u_source_dh[k]= g*grad_b[k*2+0];
11299 mom_v_source[k] = g*h[k]*grad_b[k*2+1];
11300 dmom_v_source_dh[k]= g*grad_b[k*2+1];
11302 heval=fmax(1.0e-3,h[k]);
11303 hpow =pow(heval,-bedFrictionPower-2.0);
11304 unorm = sqrt(hu[k]*hu[k] + hv[k]*hv[k]);
11306 mom_u_source[k] += g*hu[k]*bedFrictionCoefficient*unorm*hpow;
11307 dmom_u_source_dh[k] += -(bedFrictionPower+2.0)*g*hu[k]*bedFrictionCoefficient*unorm*pow(heval,-bedFrictionPower-3.0);
11308 dmom_u_source_dhu[k] = g*bedFrictionCoefficient*unorm*hpow
11309 +g*bedFrictionCoefficient*hu[k]*hu[k]*hpow/(unorm+h_eps);
11310 dmom_u_source_dhv[k] = g*bedFrictionCoefficient*unorm*hpow
11311 +g*bedFrictionCoefficient*hu[k]*hv[k]*hpow/(unorm+h_eps);
11313 mom_v_source[k] += g*hv[k]*bedFrictionCoefficient*unorm*hpow;
11314 dmom_v_source_dh[k] += -(bedFrictionPower+2.0)*g*hv[k]*bedFrictionCoefficient*unorm*pow(heval,-bedFrictionPower-3.0);
11315 dmom_v_source_dhu[k] = g*bedFrictionCoefficient*unorm*hpow
11316 +g*bedFrictionCoefficient*hu[k]*hv[k]*hpow/(unorm+h_eps);
11317 dmom_v_source_dhv[k] = g*bedFrictionCoefficient*unorm*hpow
11318 +g*bedFrictionCoefficient*hv[k]*hv[k]*hpow/(unorm+h_eps);
11324 const int computeAverages,
11325 const int nSimplex,
11326 const int nPointsPerSimplex,
11328 const int nQuadraturePoints_elementBoundary,
11329 const int* elementBoundaryElementsArray,
11330 const int* quadraturePointToElementBoundary,
11331 const int* materialTypes,
11334 const double* gravity,
11335 const double* alpha,
11336 const double* n_vg,
11337 const double* thetaR,
11338 const double* thetaSR,
11341 const double *gradu,
11342 const double *n_global,
11356 const int nSpace2=nSpace*nSpace;
11357 register double psiC,
11358 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
11360 sBar,sqrt_sBar,DsBar_DpsiC,
11361 thetaW,DthetaW_DpsiC,
11362 vBar,vBar2,DvBar_DpsiC,
11367 int eN_upwind,ebN_global;
11368 register double drive,avgfI,avgdfI,avgaII,avgdaII,vol;
11381 for (i=0; i < nSimplex; i++)
11383 matID= materialTypes[i];
11384 for (j=0;j<nPointsPerSimplex;j++)
11386 k = i*nPointsPerSimplex + j;
11388 m = 1.0 - 1.0/n_vg[matID];
11389 thetaS = thetaR[matID] + thetaSR[matID];
11392 pcBar = alpha[matID]*psiC;
11393 pcBar_nM2 = pow(pcBar,n_vg[matID]-2);
11394 pcBar_nM1 = pcBar_nM2*pcBar;
11395 pcBar_n = pcBar_nM1*pcBar;
11396 onePlus_pcBar_n = 1.0 + pcBar_n;
11398 sBar = pow(onePlus_pcBar_n,-m);
11400 DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11402 vBar = 1.0-pcBar_nM1*sBar;
11404 DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11406 thetaW = thetaSR[matID]*sBar + thetaR[matID];
11407 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11409 sqrt_sBar = sqrt(sBar);
11410 KW= KWs[matID]*sqrt_sBar*vBar2;
11411 DKW_DpsiC= KWs[matID]*
11412 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
11414 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11419 DthetaW_DpsiC = 0.0;
11424 rhom = rho*exp(beta*
u[k]);
11427 mass[k] = rhom*thetaW;
11428 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11431 for (I=0;I<nSpace;I++)
11433 f[k*nSpace+I] = rho2*KW*gravity[I];
11434 df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
11435 a[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I] = rho*KW;
11436 da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
11440 if (upwindFlag == 1 || upwindFlag == 2)
11442 if (computeAverages == 1)
11444 for (i=0; i < nSimplex; i++)
11446 matID= materialTypes[i];
11448 for (j=0; j < nPointsPerSimplex; j++)
11449 vol += dV[i*nPointsPerSimplex + j];
11451 for (I=0; I < nSpace; I++)
11453 avgaII = 0.0; avgfI = 0.0;
11454 avgdaII= 0.0; avgdfI= 0.0;
11455 for (j=0;j<nPointsPerSimplex;j++)
11457 k = i*nPointsPerSimplex + j;
11458 avgfI +=
f[k*nSpace + I]*dV[k];
11459 avgdfI +=
df[k*nSpace+ I]*dV[k];
11460 avgaII += a[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I]*dV[k];
11461 avgdaII += da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I]*dV[k];
11463 avgfI /= vol; avgdfI /= vol; avgaII /= vol; avgdaII /= vol;
11464 f_avg[i*nSpace + I] = avgfI;
11465 df_avg[i*nSpace +I] = avgdfI;
11466 a_avg[i*nSpace2+I*nSpace+I] = avgaII;
11467 da_avg[i*nSpace2+I*nSpace+I]= avgdaII;
11474 for (i=0; i < nSimplex; i++)
11476 matID= materialTypes[i];
11477 for (j=0;j<nPointsPerSimplex;j++)
11479 k = i*nPointsPerSimplex + j;
11480 ebN_global = quadraturePointToElementBoundary[k];
11482 for (I=0; I < nSpace; I++)
11484 drive += (rho2*KWs[matID]*gravity[I]-rho*KWs[matID]*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11487 if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11488 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11490 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11495 for (I = 0; I < nSpace; I++)
11497 f[k*nSpace + I] = f_avg[eN_upwind*nSpace+I];
11500 a[i*nPointsPerSimplex*nSpace2 + j*nSpace2+ I*nSpace+I] = a_avg[eN_upwind*nSpace2+I*nSpace+I];
11503 if (upwindFlag == 2)
11505 for (I = 0; I < nSpace; I++)
11507 df[k*nSpace+ I] = df_avg[eN_upwind*nSpace + I];
11508 da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+ I*nSpace+I] = da_avg[eN_upwind*nSpace2+I*nSpace+I];
11516 const int computeAverages,
11517 const int nSimplex,
11518 const int nPointsPerSimplex,
11520 const int nQuadraturePoints_elementBoundary,
11521 const int* elementBoundaryElementsArray,
11522 const int* quadraturePointToElementBoundary,
11523 const int* materialTypes,
11526 const double* gravity,
11527 const double* alpha,
11528 const double* n_vg,
11529 const double* thetaR,
11530 const double* thetaSR,
11533 const double *gradu,
11534 const double *n_global,
11548 const int nSpace2=nSpace*nSpace;
11549 register double psiC,
11550 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
11552 sBar,sqrt_sBar,DsBar_DpsiC,
11553 thetaW,DthetaW_DpsiC,
11554 vBar,vBar2,DvBar_DpsiC,
11559 int eN_upwind,ebN_global;
11560 register double drive,KWs_harm,KWs_left,KWs_right,krw_val,dkrw_val,vol;
11582 if (upwindFlag > 0)
11583 assert(computeAverages);
11584 for (i=0; i < nSimplex; i++)
11586 matID= materialTypes[i];
11589 for (j=0; j < nPointsPerSimplex; j++)
11590 vol += dV[i*nPointsPerSimplex + j];
11592 if (computeAverages)
11594 a_avg[i*nSpace2+0*nSpace+0] = 0.0;
11595 da_avg[i*nSpace2+0*nSpace+0] = 0.0;
11597 for (j=0;j<nPointsPerSimplex;j++)
11599 k = i*nPointsPerSimplex + j;
11601 m = 1.0 - 1.0/n_vg[matID];
11602 thetaS = thetaR[matID] + thetaSR[matID];
11605 pcBar = alpha[matID]*psiC;
11606 pcBar_nM2 = pow(pcBar,n_vg[matID]-2);
11607 pcBar_nM1 = pcBar_nM2*pcBar;
11608 pcBar_n = pcBar_nM1*pcBar;
11609 onePlus_pcBar_n = 1.0 + pcBar_n;
11611 sBar = pow(onePlus_pcBar_n,-m);
11613 DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11615 vBar = 1.0-pcBar_nM1*sBar;
11617 DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11619 thetaW = thetaSR[matID]*sBar + thetaR[matID];
11620 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11622 sqrt_sBar = sqrt(sBar);
11623 KWr= sqrt_sBar*vBar2;
11625 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
11627 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11632 DthetaW_DpsiC = 0.0;
11637 rhom = rho*exp(beta*
u[k]);
11640 mass[k] = rhom*thetaW;
11641 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11643 a[i*nPointsPerSimplex*nSpace2 + j*nSpace2 + 0*nSpace + 0] = KWr;
11644 da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+ 0*nSpace + 0]= -DKWr_DpsiC;
11645 if (computeAverages)
11647 a_avg[i*nSpace2 + 0*nSpace + 0] += KWr*dV[k];
11648 da_avg[i*nSpace2+ 0*nSpace + 0] += -DKWr_DpsiC*dV[k];
11652 if (computeAverages)
11654 a_avg[i*nSpace2 + 0*nSpace + 0] /= vol;
11655 da_avg[i*nSpace2 + 0*nSpace + 0] /= vol;
11660 for (i=0; i < nSimplex; i++)
11662 matID= materialTypes[i];
11663 for (j=0;j<nPointsPerSimplex;j++)
11665 k = i*nPointsPerSimplex + j;
11666 ebN_global = quadraturePointToElementBoundary[k];
11668 KWs_left = KWs[matID]; KWs_right = KWs_left;
11669 if (elementBoundaryElementsArray[ebN_global*2 + 1] >= 0)
11670 KWs_right = KWs[materialTypes[elementBoundaryElementsArray[ebN_global*2 + 1]]];
11671 KWs_harm = 2.0*KWs_left*KWs_right/(KWs_left + KWs_right + 1.0e-24);
11674 for (I=0; I < nSpace; I++)
11676 drive += (rho2*KWs_harm*gravity[I]-rho*KWs_harm*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11679 if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11680 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11682 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11688 krw_val = a[i*nPointsPerSimplex*nSpace2 + j*nSpace2 + 0*nSpace +0];
11689 dkrw_val= da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+ 0*nSpace +0];
11690 if (upwindFlag > 0)
11692 krw_val = a_avg[eN_upwind*nSpace2 + 0*nSpace + 0];
11697 for (I = 0; I < nSpace; I++)
11699 f[k*nSpace + I] = rho2*krw_val*KWs_harm*gravity[I];
11700 df[k*nSpace+ I] = rho2*dkrw_val*KWs_harm*gravity[I];
11701 a[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I] = rho*krw_val*KWs_harm;
11702 da[i*nPointsPerSimplex*nSpace2 + j*nSpace2+I*nSpace+I]= rho*dkrw_val*KWs_harm;
11711 const int computeAverages,
11712 const int nSimplex,
11713 const int nPointsPerSimplex,
11715 const int nQuadraturePoints_elementBoundary,
11718 const int* elementBoundaryElementsArray,
11719 const int* quadraturePointToElementBoundary,
11720 const int* materialTypes,
11723 const double* gravity,
11724 const double* alpha,
11725 const double* n_vg,
11726 const double* thetaR,
11727 const double* thetaSR,
11730 const double *gradu,
11731 const double *n_global,
11744 int i,j,k,I,matID,J,
nnz;
11745 const int nSpace2=nSpace*nSpace;
11746 register double psiC,
11747 pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
11749 sBar,sqrt_sBar,DsBar_DpsiC,
11750 thetaW,DthetaW_DpsiC,
11751 vBar,vBar2,DvBar_DpsiC,
11756 int eN_upwind,ebN_global;
11757 register double drive,KWs_harm,KWs_left,KWs_right,krw_val,dkrw_val,vol;
11758 nnz = rowptr[nSpace];
11780 if (upwindFlag > 0)
11781 assert(computeAverages);
11782 for (i=0; i < nSimplex; i++)
11784 matID= materialTypes[i];
11787 for (j=0; j < nPointsPerSimplex; j++)
11788 vol += dV[i*nPointsPerSimplex + j];
11790 if (computeAverages)
11792 a_avg[i*nSpace2+0*nSpace+0] = 0.0;
11793 da_avg[i*nSpace2+0*nSpace+0] = 0.0;
11795 for (j=0;j<nPointsPerSimplex;j++)
11797 k = i*nPointsPerSimplex + j;
11799 m = 1.0 - 1.0/n_vg[matID];
11800 thetaS = thetaR[matID] + thetaSR[matID];
11803 pcBar = alpha[matID]*psiC;
11804 pcBar_nM2 = pow(pcBar,n_vg[matID]-2);
11805 pcBar_nM1 = pcBar_nM2*pcBar;
11806 pcBar_n = pcBar_nM1*pcBar;
11807 onePlus_pcBar_n = 1.0 + pcBar_n;
11809 sBar = pow(onePlus_pcBar_n,-m);
11811 DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11813 vBar = 1.0-pcBar_nM1*sBar;
11815 DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11817 thetaW = thetaSR[matID]*sBar + thetaR[matID];
11818 DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11820 sqrt_sBar = sqrt(sBar);
11821 KWr= sqrt_sBar*vBar2;
11823 ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
11825 2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11830 DthetaW_DpsiC = 0.0;
11835 rhom = rho*exp(beta*
u[k]);
11838 mass[k] = rhom*thetaW;
11839 dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11842 a[i*nPointsPerSimplex*
nnz + j*
nnz + J] = KWr;
11843 da[i*nPointsPerSimplex*
nnz + j*
nnz + J]= -DKWr_DpsiC;
11844 if (computeAverages)
11846 a_avg[i*
nnz + J] += KWr*dV[k];
11847 da_avg[i*
nnz+ J] += -DKWr_DpsiC*dV[k];
11851 if (computeAverages)
11853 a_avg[i*
nnz + J] /= vol;
11854 da_avg[i*
nnz + J] /= vol;
11859 for (i=0; i < nSimplex; i++)
11861 matID= materialTypes[i];
11862 for (j=0;j<nPointsPerSimplex;j++)
11864 k = i*nPointsPerSimplex + j;
11865 ebN_global = quadraturePointToElementBoundary[k];
11867 KWs_left = KWs[matID]; KWs_right = KWs_left;
11868 if (elementBoundaryElementsArray[ebN_global*2 + 1] >= 0)
11869 KWs_right = KWs[materialTypes[elementBoundaryElementsArray[ebN_global*2 + 1]]];
11870 KWs_harm = 2.0*KWs_left*KWs_right/(KWs_left + KWs_right + 1.0e-24);
11873 for (I=0; I < nSpace; I++)
11875 drive += (rho2*KWs_harm*gravity[I]-rho*KWs_harm*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11878 if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11879 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11881 eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11888 krw_val = a[i*nPointsPerSimplex*
nnz + j*
nnz + J];
11889 dkrw_val= da[i*nPointsPerSimplex*
nnz + j*
nnz + J];
11890 if (upwindFlag > 0)
11892 krw_val = a_avg[eN_upwind*
nnz + J];
11900 for (I = 0; I < nSpace; I++)
11902 f[k*nSpace + I] = rho2*krw_val*KWs_harm*gravity[I];
11903 df[k*nSpace+ I] = rho2*dkrw_val*KWs_harm*gravity[I];
11904 for (J=rowptr[I]; J < rowptr[I+1]; J++)
11906 if (colind[J] == I)
11908 a[i*nPointsPerSimplex*
nnz + j*
nnz + J] = rho*krw_val*KWs_harm;
11909 da[i*nPointsPerSimplex*
nnz + j*
nnz + J]= rho*dkrw_val*KWs_harm;
11913 a[i*nPointsPerSimplex*
nnz + j*
nnz + J] = 0.0;
11914 da[i*nPointsPerSimplex*
nnz + j*
nnz + J]= 0.0;
11925 int nQuadraturePoints_elementBoundary,
11927 int* isDOFBoundary,
11929 double* advectiveFlux,
11930 double* diffusiveFlux)
11934 for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
11936 for(k=0;k<nQuadraturePoints_elementBoundary;k++)
11938 if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11941 advectiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] *= weight;
11942 diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] *= weight;
11949 int nQuadraturePoints_elementBoundary,
11950 int nDOF_trial_element,
11952 int* isDOFBoundary,
11954 double* fluxJacobian)
11958 for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
11960 for(k=0;k<nQuadraturePoints_elementBoundary;k++)
11962 if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11965 for(j=0;j<nDOF_trial_element;j++)
11967 fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11968 k*nDOF_trial_element+
11979 const double alpha,
11980 const double gamma,
11981 const double epsilon,
11984 const double* grad_u,
11994 for (i=0; i<nPoints; i++)
11998 hold=
u[i]-x[i*3+2];
11999 depth=fmax(hold, 0.0);
12000 hold=fabs(grad_u[i]);
12001 a[i]= (pow(depth,alpha))/(pow(hold, 1.0-gamma)+epsilon);
12002 da[i]=(alpha*pow(depth,alpha-1.0))/(pow(hold, 1.0-gamma)+epsilon);
12009 const double alpha,
12010 const double gamma,
12011 const double epsilon,
12014 const double* grad_u,
12024 for (i=0; i<nPoints; i++)
12028 depth=fmax(
u[i]-x[i*3+2],0.0);
12029 hold=sqrt(grad_u[2*i]*grad_u[2*i]+grad_u[2*i+1]*grad_u[2*i+1]);
12030 a[i*4]=a[i*4+3]= (pow(depth,alpha))/(pow(hold, 1.0-gamma)+epsilon);
12031 da[i*4]=da[i*4+3]=(alpha*pow(depth,alpha-1.0))/(pow(hold, 1.0-gamma)+epsilon);
12037 const int nQuadraturePoints_element,
12038 const double smagorinskyConstant,
12039 const double * h_e,
12040 const double * grad_u,
12041 const double * grad_v,
12045 const int nSpace = 2;
12046 double norm_S2,norm_S;
12047 for (eN = 0; eN < nElements_global; eN++)
12049 for (k = 0; k < nQuadraturePoints_element; k++)
12052 grad_u[eN*nQuadraturePoints_element*nSpace +
12055 grad_u[eN*nQuadraturePoints_element*nSpace +
12058 grad_v[eN*nQuadraturePoints_element*nSpace +
12061 grad_v[eN*nQuadraturePoints_element*nSpace +
12065 (grad_u[eN*nQuadraturePoints_element*nSpace +
12068 grad_v[eN*nQuadraturePoints_element*nSpace +
12071 (grad_u[eN*nQuadraturePoints_element*nSpace +
12074 grad_v[eN*nQuadraturePoints_element*nSpace +
12076 norm_S = sqrt(2.0*norm_S2);
12077 nu_t[eN*nQuadraturePoints_element + k] =
12078 smagorinskyConstant*smagorinskyConstant*h_e[eN]*h_e[eN]*norm_S;
12085 const int nQuadraturePoints_element,
12086 const double smagorinskyConstant,
12087 const double * h_e,
12088 const double * grad_u,
12089 const double * grad_v,
12090 const double * grad_w,
12094 const int nSpace = 3;
12095 double norm_S2,norm_S;
12096 for (eN = 0; eN < nElements_global; eN++)
12098 for (k = 0; k < nQuadraturePoints_element; k++)
12101 grad_u[eN*nQuadraturePoints_element*nSpace +
12104 grad_u[eN*nQuadraturePoints_element*nSpace +
12107 grad_v[eN*nQuadraturePoints_element*nSpace +
12110 grad_v[eN*nQuadraturePoints_element*nSpace +
12113 grad_w[eN*nQuadraturePoints_element*nSpace +
12116 grad_w[eN*nQuadraturePoints_element*nSpace +
12120 (grad_u[eN*nQuadraturePoints_element*nSpace +
12123 grad_v[eN*nQuadraturePoints_element*nSpace +
12126 (grad_u[eN*nQuadraturePoints_element*nSpace +
12129 grad_v[eN*nQuadraturePoints_element*nSpace +
12133 (grad_u[eN*nQuadraturePoints_element*nSpace +
12136 grad_w[eN*nQuadraturePoints_element*nSpace +
12139 (grad_u[eN*nQuadraturePoints_element*nSpace +
12142 grad_w[eN*nQuadraturePoints_element*nSpace +
12146 (grad_v[eN*nQuadraturePoints_element*nSpace +
12149 grad_w[eN*nQuadraturePoints_element*nSpace +
12152 (grad_v[eN*nQuadraturePoints_element*nSpace +
12155 grad_w[eN*nQuadraturePoints_element*nSpace +
12157 norm_S = sqrt(2.0*norm_S2);
12158 nu_t[eN*nQuadraturePoints_element + k] =
12159 smagorinskyConstant*smagorinskyConstant*h_e[eN]*h_e[eN]*norm_S;
12166 const int nQuadraturePoints_element,
12167 const double smagorinskyConstant_0,
12168 const double smagorinskyConstant_1,
12170 const double * phi_ls,
12171 const double * h_e,
12172 const double * grad_u,
12173 const double * grad_v,
12177 const int nSpace = 2;
12178 double norm_S2,norm_S,H_smc,smc;
12179 for (eN = 0; eN < nElements_global; eN++)
12181 for (k = 0; k < nQuadraturePoints_element; k++)
12184 smc = smagorinskyConstant_0*(1.0-H_smc) + smagorinskyConstant_1*H_smc;
12187 grad_u[eN*nQuadraturePoints_element*nSpace +
12190 grad_u[eN*nQuadraturePoints_element*nSpace +
12193 grad_v[eN*nQuadraturePoints_element*nSpace +
12196 grad_v[eN*nQuadraturePoints_element*nSpace +
12200 (grad_u[eN*nQuadraturePoints_element*nSpace +
12203 grad_v[eN*nQuadraturePoints_element*nSpace +
12206 (grad_u[eN*nQuadraturePoints_element*nSpace +
12209 grad_v[eN*nQuadraturePoints_element*nSpace +
12211 norm_S = sqrt(2.0*norm_S2);
12212 nu_t[eN*nQuadraturePoints_element + k] =
12213 smc*smc*h_e[eN]*h_e[eN]*norm_S;
12220 const int nQuadraturePoints_element,
12221 const double smagorinskyConstant_0,
12222 const double smagorinskyConstant_1,
12224 const double * phi_ls,
12225 const double * h_e,
12226 const double * grad_u,
12227 const double * grad_v,
12228 const double * grad_w,
12232 const int nSpace = 3;
12233 double norm_S2,norm_S,H_smc,smc;
12234 for (eN = 0; eN < nElements_global; eN++)
12236 for (k = 0; k < nQuadraturePoints_element; k++)
12239 smc = smagorinskyConstant_0*(1.0-H_smc) + smagorinskyConstant_1*H_smc;
12242 grad_u[eN*nQuadraturePoints_element*nSpace +
12245 grad_u[eN*nQuadraturePoints_element*nSpace +
12248 grad_v[eN*nQuadraturePoints_element*nSpace +
12251 grad_v[eN*nQuadraturePoints_element*nSpace +
12254 grad_w[eN*nQuadraturePoints_element*nSpace +
12257 grad_w[eN*nQuadraturePoints_element*nSpace +
12261 (grad_u[eN*nQuadraturePoints_element*nSpace +
12264 grad_v[eN*nQuadraturePoints_element*nSpace +
12267 (grad_u[eN*nQuadraturePoints_element*nSpace +
12270 grad_v[eN*nQuadraturePoints_element*nSpace +
12274 (grad_u[eN*nQuadraturePoints_element*nSpace +
12277 grad_w[eN*nQuadraturePoints_element*nSpace +
12280 (grad_u[eN*nQuadraturePoints_element*nSpace +
12283 grad_w[eN*nQuadraturePoints_element*nSpace +
12287 (grad_v[eN*nQuadraturePoints_element*nSpace +
12290 grad_w[eN*nQuadraturePoints_element*nSpace +
12293 (grad_v[eN*nQuadraturePoints_element*nSpace +
12296 grad_w[eN*nQuadraturePoints_element*nSpace +
12298 norm_S = sqrt(2.0*norm_S2);
12299 nu_t[eN*nQuadraturePoints_element + k] =
12300 smc*smc*h_e[eN]*h_e[eN]*norm_S;
12308 const double* nu_t,
12309 double *mom_u_diff_ten,
12310 double *mom_v_diff_ten,
12311 double *mom_uv_diff_ten,
12312 double *mom_vu_diff_ten)
12315 for (i=0;i<nPoints;i++)
12317 #ifdef SCALAR_DIFFUSION
12319 mom_u_diff_ten[i*4+0] += nu_t[i];
12320 mom_u_diff_ten[i*4+3] += nu_t[i];
12323 mom_v_diff_ten[i*4+0] += nu_t[i];
12324 mom_v_diff_ten[i*4+3] += nu_t[i];
12327 mom_u_diff_ten[i*4+0] += 2.0*nu_t[i];
12328 mom_u_diff_ten[i*4+3] += nu_t[i];
12329 mom_uv_diff_ten[i*4+2]+= nu_t[i];
12332 mom_v_diff_ten[i*4+0] += nu_t[i];
12333 mom_v_diff_ten[i*4+3] += 2.0*nu_t[i];
12334 mom_vu_diff_ten[i*4+1] += nu_t[i];
12341 const double* nu_t,
12342 double *mom_u_diff_ten,
12343 double *mom_v_diff_ten,
12344 double *mom_uv_diff_ten,
12345 double *mom_vu_diff_ten)
12348 for (i=0;i<nPoints;i++)
12351 mom_u_diff_ten[i*2+0] += 2.0*nu_t[i];
12352 mom_u_diff_ten[i*2+1] += nu_t[i];
12353 mom_uv_diff_ten[i]+= nu_t[i];
12356 mom_v_diff_ten[i*2+0] += nu_t[i];
12357 mom_v_diff_ten[i*2+1] += 2.0*nu_t[i];
12358 mom_vu_diff_ten[i] += nu_t[i];
12363 const double* nu_t,
12364 double *mom_u_diff_ten,
12365 double *mom_v_diff_ten,
12366 double *mom_w_diff_ten,
12367 double *mom_uv_diff_ten,
12368 double *mom_uw_diff_ten,
12369 double *mom_vu_diff_ten,
12370 double *mom_vw_diff_ten,
12371 double *mom_wu_diff_ten,
12372 double *mom_wv_diff_ten)
12375 for (k=0;k<nPoints;k++)
12378 mom_u_diff_ten[k*9+0] = 2.0*nu_t[k];
12379 mom_u_diff_ten[k*9+4] = nu_t[k];
12380 mom_u_diff_ten[k*9+8] = nu_t[k];
12382 mom_uv_diff_ten[k*9+3]=nu_t[k];
12384 mom_uw_diff_ten[k*9+6]=nu_t[k];
12387 mom_v_diff_ten[k*9+0] = nu_t[k];
12388 mom_v_diff_ten[k*9+4] = 2.0*nu_t[k];
12389 mom_v_diff_ten[k*9+8] = nu_t[k];
12391 mom_vu_diff_ten[k*9+1]=nu_t[k];
12393 mom_vw_diff_ten[k*9+7]=nu_t[k];
12396 mom_w_diff_ten[k*9+0] = nu_t[k];
12397 mom_w_diff_ten[k*9+4] = nu_t[k];
12398 mom_w_diff_ten[k*9+8] = 2.0*nu_t[k];
12400 mom_wu_diff_ten[k*9+2]=nu_t[k];
12402 mom_wv_diff_ten[k*9+5]=nu_t[k];
12408 const double* nu_t,
12409 double *mom_u_diff_ten,
12410 double *mom_v_diff_ten,
12411 double *mom_w_diff_ten,
12412 double *mom_uv_diff_ten,
12413 double *mom_uw_diff_ten,
12414 double *mom_vu_diff_ten,
12415 double *mom_vw_diff_ten,
12416 double *mom_wu_diff_ten,
12417 double *mom_wv_diff_ten)
12420 for (k=0;k<nPoints;k++)
12423 mom_u_diff_ten[k*3+0] += 2.0*nu_t[k];
12424 mom_u_diff_ten[k*3+1] += nu_t[k];
12425 mom_u_diff_ten[k*3+2] += nu_t[k];
12427 mom_uv_diff_ten[k]+=nu_t[k];
12429 mom_uw_diff_ten[k]+=nu_t[k];
12432 mom_v_diff_ten[k*3+0] += nu_t[k];
12433 mom_v_diff_ten[k*3+1] += 2.0*nu_t[k];
12434 mom_v_diff_ten[k*3+2] += nu_t[k];
12436 mom_vu_diff_ten[k]+=nu_t[k];
12438 mom_vw_diff_ten[k]+=nu_t[k];
12441 mom_w_diff_ten[k*3+0] += nu_t[k];
12442 mom_w_diff_ten[k*3+1] += nu_t[k];
12443 mom_w_diff_ten[k*3+2] += 2.0*nu_t[k];
12445 mom_wu_diff_ten[k]+=nu_t[k];
12447 mom_wv_diff_ten[k]+=nu_t[k];
12453 int nElements_global,
12454 int nDOF_element_mesh,
12455 int nQuadraturePoints_element,
12456 const double* mesh_trial_ref,
12457 const double* mesh_dof,
12458 const int* mesh_l2g,
12459 const double* elementDiametersArray,
12461 const double* omega_s_x,
12462 const double* omega_s_y,
12463 const double* omega_s_z,
12470 double waveCelerity,
12471 double waveFrequency,
12477 double x,y,
z,factor,dx_source,dy_source,dz_source,source_volume,N_j,
12478 distance_x,distance_y,distance_z,delta,eps;
12480 double p_s,a_s,b_s,
kd,term1,term2,term3,sinhkd;
12481 dx_source=omega_s_x[1]-omega_s_x[0]; dy_source=omega_s_y[1]-omega_s_y[0]; dz_source=omega_s_z[1]-omega_s_z[0];
12482 source_volume = dx_source*dy_source*dz_source;
12485 kd = waveNumber*waterDepth;
12486 a_s = waveHeight*0.5;
12488 b_s = waveHeight*waveHeight*waveNumber*cosh(
kd)*(2.0 + cosh(2.*
kd)/(16.0+sinhkd*sinhkd*sinhkd));
12489 term1 = -a_s + sqrt(a_s*a_s + 8.0*b_s*b_s)/(4.0*b_s);
12491 term1 = waveCelerity*waveHeight*cos(M_PI*0.5 - waveFrequency*t - p_s);
12492 term2 = waveCelerity*waveHeight*waveHeight*cosh(
kd)/(8.0*sinhkd*sinhkd*sinhkd);
12493 term3 = 2.0 + cosh(2.0*
kd)*cos(2.0*(M_PI*0.5 - waveFrequency*t - p_s));
12494 factor = (term1 + term2*term3)/source_volume;
12497 else if (waveFlag == 2)
12499 term1 = 4.0*waveHeight/sqrt(waveHeight/waterDepth);
12500 term2= sqrt(3.0*waveHeight/(4.0*waterDepth*waterDepth*waterDepth))*(term1 - waveCelerity*t);
12501 term2= fmax(term2,-80.0);
12502 term2= fmin(term2, 80.0);
12503 term3= 1.0/(cosh(term2)+1.0e-12);
12504 factor = waveHeight*waveCelerity*term3*term3/source_volume;
12508 factor = waveHeight/source_volume*waveCelerity*sin(waveFrequency*t);
12510 for (eN = 0; eN < nElements_global; eN++)
12512 eps = epsFact*elementDiametersArray[eN];
12513 for (k = 0; k < nQuadraturePoints_element; k++)
12516 for (j=0; j < nDOF_element_mesh; j++)
12518 eN_j= eN*nDOF_element_mesh+j;
12519 N_j = mesh_trial_ref[k*nDOF_element_mesh+j];
12521 x += mesh_dof[mesh_l2g[eN_j]*3+0]*N_j;
12522 y += mesh_dof[mesh_l2g[eN_j]*3+1]*N_j;
12523 z += mesh_dof[mesh_l2g[eN_j]*3+2]*N_j;
12526 distance_x = fabs(x-0.5*(omega_s_x[1]+omega_s_x[0])) - 0.5*dx_source;
12527 distance_y = fabs(y-0.5*(omega_s_y[1]+omega_s_y[0])) - 0.5*dy_source;
12528 distance_z = fabs(
z-0.5*(omega_s_z[1]+omega_s_z[0])) - 0.5*dz_source;
12530 source[eN*nQuadraturePoints_element+k] = -factor*delta;
12634 double *dmom_p_acc_p,
12635 double *dmom_u_acc_u,
12636 double *dmom_v_acc_v)
12639 for (k=0; k<nPoints; k++){
12640 mom_p_acc[k] = p[k];
12641 dmom_p_acc_p[k] = 1.0;
12643 mom_u_acc[k] =
u[k];
12644 dmom_u_acc_u[k] = 1.0;
12646 mom_v_acc[k] =
v[k];
12647 dmom_v_acc_v[k] = 1.0;
12661 double *dmom_p_acc_p,
12662 double *dmom_u_acc_u,
12663 double *dmom_v_acc_v,
12664 double *dmom_w_acc_w)
12667 for (k=0; k<nPoints; k++){
12668 mom_p_acc[k] = p[k];
12669 dmom_p_acc_p[k] = 1.0;
12671 mom_u_acc[k] =
u[k];
12672 dmom_u_acc_u[k] = 1.0;
12674 mom_v_acc[k] =
v[k];
12675 dmom_v_acc_v[k] = 1.0;
12677 mom_w_acc[k] =
w[k];
12678 dmom_w_acc_w[k] = 1.0;
12684 const double rho_0,
12686 const double rho_1,
12689 double *mom_p_diff_ten,
12690 double *mom_u_diff_ten,
12691 double *mom_v_diff_ten)
12694 double rho,nu,mu,
H;
12696 for (k=0; k<nPoints; k++)
12703 mom_p_diff_ten[k*2+0] = 1.0 / rho;
12704 mom_p_diff_ten[k*2+1] = 1.0 / rho;
12706 mom_u_diff_ten[k*2+0] = 1.0 / rho;
12707 mom_u_diff_ten[k*2+1] = 1.0 / rho;
12709 mom_v_diff_ten[k*2+0] = 1.0 / rho;
12710 mom_v_diff_ten[k*2+1] = 1.0 / rho;
12716 const double rho_0,
12718 const double rho_1,
12725 double *dmass_adv_p,
12726 double *dmass_adv_u,
12727 double *dmass_adv_v,
12729 double *dmom_u_adv_u,
12730 double *dmom_u_adv_v,
12732 double *dmom_v_adv_u,
12733 double *dmom_v_adv_v)
12736 double rho, nu, mu,
H;
12738 for (k=0;k<nPoints;k++)
12746 mass_adv[k*2+0]=rho*
u[k]*p[k];
12747 mass_adv[k*2+1]=rho*
v[k]*p[k];
12749 dmass_adv_p[k*2+0] = rho*
u[k];
12750 dmass_adv_p[k*2+1] = rho*
v[k];
12753 dmass_adv_u[k*2+0]= 0.0;
12754 dmass_adv_v[k*2+1]= 0.0;
12756 mom_u_adv[k*2+0] = rho*
u[k]*
u[k];
12757 mom_u_adv[k*2+1] = rho*
u[k]*
v[k];
12759 dmom_u_adv_u[k*2+0] = rho*2.0*
u[k];
12760 dmom_u_adv_u[k*2+1] = rho*
v[k];
12762 dmom_u_adv_v[k*2+1] = rho*
u[k];
12764 mom_v_adv[k*2+0] = rho*
v[k]*
u[k];
12765 mom_v_adv[k*2+1] = rho*
v[k]*
v[k];
12767 dmom_v_adv_u[k*2+0] = rho*
v[k];
12769 dmom_v_adv_v[k*2+0] = rho*
u[k];
12770 dmom_v_adv_v[k*2+1] = rho*2.0*
v[k];