proteus  1.8.1
C/C++/Fortran libraries
transportCoefficients.c
Go to the documentation of this file.
2 
8 /*define relaxation function according to Jacobsen et al 2012, INJNMF*/
9 double relaxationFunction(double phi, double phiStart, double phiEnd)
10 {
11  double H;
12  double x;
13  double Length;
14 
15  if(phiStart < phiEnd)
16  {
17  Length = phiEnd - phiStart;
18  x = (phi - phiStart)/Length;
19  H = 1 - (exp(pow(x,3.5)) - 1.)/ (exp(1) - 1.);
20  }
21  else
22  {
23  Length = -(phiEnd - phiStart);
24  x = 1 - (phi - phiStart)/Length;
25  H = 1 - (exp(pow(x,3.5)) - 1.)/ (exp(1) - 1.);
26  }
27  return H;
28 
29 
30 
31 }
32 /*#define SCALAR_DIFFUSION*/
33 double smoothedHeaviside(double eps, double phi)
34 {
35  double H;
36  if (phi > eps)
37  H=1.0;
38  else if (phi < -eps)
39  H=0.0;
40  else if (phi==0.0)
41  H=0.5;
42  else
43  H = 0.5*(1.0 + phi/eps + sin(M_PI*phi/eps)/M_PI);
44  return H;
45 }
46 
47 double smoothedHeaviside_integral(double eps, double phi)
48 {
49  double HI;
50  if (phi > eps)
51  {
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));
53  }
54  else if (phi < -eps)
55  {
56  HI=0.0;
57  }
58  else
59  {
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));
61  }
62  return HI;
63 }
64 
65 double smoothedDirac(double eps, double phi)
66 {
67  double d;
68  if (phi > eps)
69  d=0.0;
70  else if (phi < -eps)
71  d=0.0;
72  else
73  d = 0.5*(1.0 + cos(M_PI*phi/eps))/eps;
74  return d;
75 }
76 
77 double linearHeaviside(double eps, double phi)
78 {
79  double H;
80  if (phi > eps)
81  H=1.0;
82  else if (phi < -eps)
83  H=0.0;
84  else
85  H = 0.5*((phi+eps)/eps);
86  return H;
87 }
88 
89 double linearDirac(double eps, double phi)
90 {
91  double d;
92  if (phi > eps)
93  d=0.0;
94  else if (phi < -eps)
95  d=0.0;
96  else
97  d = 0.5/eps;
98  return d;
99 }
100 
102  const int nSpace,
103  const double M,
104  const double *A,
105  const double *B,
106  const double C,
107  const double t,
108  const double *x,
109  const double *u,
110  double *m,
111  double *dm,
112  double *f,
113  double *df,
114  double *a,
115  double *r,
116  double *dr)
117 {
118  int k,I,J;
119  const int nSpace2=nSpace*nSpace;
120  for (k=0;k<nPoints;k++)
121  {
122  m[k]=M*u[k];
123  dm[k]=M;
124 
125  for (I=0;I<nSpace;I++)
126  {
127  f[k*nSpace+I]=B[I]*u[k];
128  df[k*nSpace+I]=B[I];
129  for (J=0;J<nSpace;J++)
130  {
131  a[k*nSpace2+I*nSpace+J]=A[I*nSpace+J];
132  }
133  }
134 
135  r[k]=C*u[k];
136  dr[k]=C;
137  }
138 }
139 
141  const int nSpace,
142  const double omega,
143  const double d,
144  const double alpha_L,
145  const double alpha_T,
146  const double *v,
147  const double *u,
148  double *m,
149  double *dm,
150  double *f,
151  double *df,
152  double *a)
153 {
154  int k,I,J;
155  const int nSpace2=nSpace*nSpace;
156  double norm_v;
157 
158  for (k=0;k<nPoints;k++)
159  {
160  m[k]=omega*u[k];
161  dm[k]=omega;
162  norm_v = 0.0;
163  for (I=0;I<nSpace;I++)
164  {
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];
168  }
169  norm_v = sqrt(norm_v);
170  if (norm_v > 0.0)
171  {
172  for (I=0;I<nSpace;I++)
173  {
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++)
176  {
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];
179  }
180  }
181  }
182  else
183  for (I=0;I<nSpace;I++)
184  a[k*nSpace2+I*nSpace+I]=omega*d;
185  }
186 }
188  const int nSpace,
189  const double omega,
190  const double d_c,
191  const double d_e,
192  const double alpha_L,
193  const double alpha_T,
194  const double Kox_max,
195  const double Kox_C,
196  const double Kox_E,
197  const double Kox_X,
198  const double Yield,
199  const double k_d,
200  const double *v,
201  const double *c_c,
202  const double *c_e,
203  const double *c_x,
204  double *m_c,
205  double *dm_c,
206  double *m_e,
207  double *dm_e,
208  double *m_x,
209  double *dm_x,
210  double *f_c,
211  double *df_c,
212  double *f_e,
213  double *df_e,
214  double *a_c,
215  double *a_e,
216  double *r_c,
217  double *dr_c_dc,
218  double *dr_c_de,
219  double *dr_c_dx,
220  double *r_e,
221  double *dr_e_dc,
222  double *dr_e_de,
223  double *dr_e_dx,
224  double *r_x,
225  double *dr_x_dc,
226  double *dr_x_de,
227  double *dr_x_dx)
228 {
229  int k,I,J;
230  const int nSpace2=nSpace*nSpace;
231  double norm_v;
232  double C,E,X,denomC,denomE,denomX,rox,drox_dC,drox_dE,drox_dX;
233  for (k=0;k<nPoints;k++)
234  {
235  C = c_c[k]; E = c_e[k]; X = c_x[k];
236  m_c[k]=omega*C;
237  dm_c[k]=omega;
238  m_e[k]=omega*E;
239  dm_e[k]=omega;
240  m_x[k]=omega*X;
241  dm_x[k]=omega;
242 
243  norm_v = 0.0;
244  for (I=0;I<nSpace;I++)
245  {
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];
250 
251  norm_v += v[k*nSpace+I]*v[k*nSpace+I];
252  }
253  norm_v = sqrt(norm_v);
254  if (norm_v > 0.0)
255  {
256  for (I=0;I<nSpace;I++)
257  {
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++)
260  {
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];
263  }
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++)
266  {
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];
269  }
270  }
271  }
272  else
273  {
274  for (I=0;I<nSpace;I++)
275  {
276  a_c[k*nSpace2+I*nSpace+I]=omega*d_c;
277  a_e[k*nSpace2+I*nSpace+I]=omega*d_e;
278  }
279  }/*dispersion calc*/
280  /*reactions*/
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));
286 
287  r_c[k] = omega*rox;
288  r_e[k] = 3.0*omega*rox;
289  r_x[k] = -Yield*omega*rox + X*omega*k_d;
290 
291  dr_c_dc[k] = omega*drox_dC; dr_c_de[k] = omega*drox_dE; dr_c_dx[k] = omega*drox_dX;
292 
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;
294 
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;
298 /* /\*mwf debug*\/ */
299 /* printf("bio01eval k=%d C=%g E=%g X=%g rox=%g \n",k,C,E,X,rox); */
300  }
301 }
302 
304  const int nSpace,
305  const double omega,
306  const double d_m,
307  const double d_h,
308  const double alpha_L,
309  const double alpha_T,
310  const double K_m,
311  const double K_h,
312  const double K_w,
313  const double Z_tot,
314  const double *v,
315  const double *c_m,
316  const double *c_h,
317  double *m_m,
318  double *dm_m_m,
319  double *dm_m_h,
320  double *m_h,
321  double *dm_h_m,
322  double *dm_h_h,
323  double *f_m,
324  double *df_m,
325  double *f_h,
326  double *df_h,
327  double *a_m,
328  double *a_h,
329  double *phi_h,
330  double *dphi_h,
331  double *r_m,
332  double *dr_m_dm,
333  double *dr_m_dh,
334  double *r_h,
335  double *dr_h_dm,
336  double *dr_h_dh)
337 
338 {
339  int k,I,J;
340  const int nSpace2=nSpace*nSpace;
341  double norm_v;
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++)
345  {
346  /*metal, proton, hydroxyl*/
347  C_m = c_m[k]; C_h= c_h[k]; C_oh = K_w/(C_h+eps);
348  /*acidity*/
349  C_a = C_h - C_oh; dC_a_dC_h = 1.0 + K_w/(C_h*C_h+eps);
350  /*sorbed concentrations*/
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;
354 
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);
361 
362  /*nonlinear potential for C_h*/
363  phi_h[k] = C_a;
364  dphi_h[k] = dC_a_dC_h;
365  norm_v = 0.0;
366  for (I=0;I<nSpace;I++)
367  {
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;
372 
373  norm_v += v[k*nSpace+I]*v[k*nSpace+I];
374  }
375  norm_v = sqrt(norm_v);
376  if (norm_v > 0.0)
377  {
378  for (I=0;I<nSpace;I++)
379  {
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++)
382  {
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];
385  }
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++)
388  {
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];
391  }
392  }
393  }
394  else
395  {
396  for (I=0;I<nSpace;I++)
397  {
398  a_m[k*nSpace2+I*nSpace+I]=omega*d_m;
399  a_h[k*nSpace2+I*nSpace+I]=omega*d_h;
400  }
401  }/*dispersion calc*/
402  r_m[k] = 0.0;
403  r_h[k] = 0.0;
404  dr_m_dm[k] = 0.0;
405  dr_m_dh[k] = 0.0;
406  dr_h_dm[k] = 0.0;
407  dr_h_dh[k] = 0.0;
408 
409 /* /\*mwf debug*\/ */
410 /* printf("ionExeval k=%d C_m=%g C_h=%g \n",k,C_m,C_h); */
411  }
412 }
414  const int nPointsPerSimplex,
415  const int nSpace,
416  const double d,
417  const int* materialTypes,
418  const double *omega_types,
419  const double *alpha_L_types,
420  const double *alpha_T_types,
421  const double *v,
422  const double *u,
423  double *m,
424  double *dm,
425  double *f,
426  double *df,
427  double *a)
428 {
429  int i,j,k,I,J,matID;
430  const int nSpace2=nSpace*nSpace;
431  double norm_v;
432 
433  for (i=0;i<nSimplex;i++)
434  {
435  matID = materialTypes[i];
436  for (j=0; j < nPointsPerSimplex; j++)
437  {
438  k = i*nPointsPerSimplex+j;
439 
440  m[k]=omega_types[matID]*u[k];
441  dm[k]=omega_types[matID];
442  norm_v = 0.0;
443  for (I=0;I<nSpace;I++)
444  {
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];
448  }
449  norm_v = sqrt(norm_v);
450  if (norm_v > 0.0)
451  {
452  for (I=0;I<nSpace;I++)
453  {
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++)
456  {
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];
459  }
460  }
461  }
462  else
463  for (I=0;I<nSpace;I++)
464  a[k*nSpace2+I*nSpace+I]=omega_types[matID]*d;
465  }
466  }
467 }
469  const int nPointsPerSimplex,
470  const int nSpace,
471  const double d,
472  const int* materialTypes,
473  const double *theta, /*phase volume fraction*/
474  const double *alpha_L_types,
475  const double *alpha_T_types,
476  const double *v,/*phase darcy velocity*/
477  const double *u,
478  double *m,
479  double *dm,
480  double *f,
481  double *df,
482  double *a)
483 {
484  int i,j,k,I,J,matID;
485  const int nSpace2=nSpace*nSpace;
486  double norm_v;
487 
488  for (i=0;i<nSimplex;i++)
489  {
490  matID = materialTypes[i];
491  for (j=0; j < nPointsPerSimplex; j++)
492  {
493  k = i*nPointsPerSimplex+j;
494 
495  m[k]=theta[k]*u[k];
496  dm[k]=theta[k];
497  norm_v = 0.0;
498  for (I=0;I<nSpace;I++)
499  {
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];
503  }
504  norm_v = sqrt(norm_v);
505  if (norm_v > 0.0)
506  {
507  for (I=0;I<nSpace;I++)
508  {
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++)
511  {
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];
514  }
515  }
516  }
517  else
518  for (I=0;I<nSpace;I++)
519  a[k*nSpace2+I*nSpace+I]=theta[k]*d;
520  }
521  }
522 }
524  const int nPointsPerSimplex,
525  const int nSpace,
526  const double rho_w,
527  const double rho_n,
528  const double specificHeat_w,
529  const double specificHeat_n,
530  const int* materialTypes,
531  const double *theta, /*phase volume fraction*/
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,
540  const double *v,/*phase darcy velocity*/
541  const double *u,
542  double *m,
543  double *dm,
544  double *f,
545  double *df,
546  double *a)
547 {
548  int i,j,k,I,J,matID;
549  const int nSpace2=nSpace*nSpace;
550  double norm_v,tmp,sw,Ke,lambda;
551 
552  for (i=0;i<nSimplex;i++)
553  {
554  matID = materialTypes[i];
555  for (j=0; j < nPointsPerSimplex; j++)
556  {
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];
560  m[k]=tmp*u[k];
561  dm[k]=tmp;
562  norm_v = 0.0;
563  for (I=0;I<nSpace;I++)
564  {
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];
568  }
569  norm_v = sqrt(norm_v);
570  sw = theta[k]/thetaS_types[matID];
571  if (norm_v > 0.0)
572  {
573  for (I=0;I<nSpace;I++)
574  {
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++)
577  {
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];
580  }
581  }
582  }
583 
584  /*todo check with Stacy for right form*/
585  if (sw > 0.05)
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++)
589  {
590  a[k*nSpace2+I*nSpace+I] += lambda*lambda_aniso_types[matID*nSpace+I];
591  }
592 
593  }
594  }
595 }
596 
597 void nonlinearADR_pqrstEvaluate(const int nPoints,
598  const int nSpace,
599  const double M,
600  const double* A,
601  const double* B,
602  const double C,
603  const double p_pow,
604  const double q_pow,
605  const double r_pow,
606  const double s_pow,
607  const double t_pow,
608  const double t,
609  const double *x,
610  const double *u,
611  double *m,
612  double *dm,
613  double *f,
614  double *df,
615  double *a,
616  double *da,
617  double *phi,
618  double *dphi,
619  double *r,
620  double *dr)
621 {
622  int k,I,J;
623  const int nSpace2=nSpace*nSpace;
624  double uPlus,
625  tmp_f,
626  tmp_df,
627  tmp_a,
628  tmp_da;
629  const double pM1_pow=p_pow-1.0,
630  qM1_pow=q_pow-1.0,
631  rM1_pow=r_pow-1.0,
632  sM1_pow=s_pow-1.0,
633  tM1_pow=t_pow-1.0;
634  for (k=0;k<nPoints;k++)
635  {
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;
639 
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;
642 
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;
645 
646  for (I=0;I<nSpace;I++)
647  {
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++)
651  {
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;
654  }
655  }
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;
658 
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;
661  }
662 }
663 
664 void nonlinearADR_pqrstDualEvaluate(const int nPoints,
665  const int nSpace,
666  const double M,
667  const double* A,
668  const double* B,
669  const double C,
670  const double p1,
671  const double q1,
672  const double r1,
673  const double s1,
674  const double t1,
675  const double p2,
676  const double q2,
677  const double r2,
678  const double s2,
679  const double t2,
680  const double t,
681  const double *x,
682  const double *u,
683  double *m,
684  double *dm,
685  double *f,
686  double *df,
687  double *a,
688  double *da,
689  double *phi,
690  double *dphi,
691  double *r,
692  double *dr)
693 {
694  int k,I,J;
695  const int nSpace2=nSpace*nSpace;
696  double max_1mu_0,atmp,datmp;
697  const double p2M1=p2-1.0,
698  q2M1=q2-1.0,
699  r2M1=r2-1.0,
700  s2M1=s2-1.0,
701  t2M1=t2-1.0;
702 
704  nSpace,
705  M,
706  A,
707  B,
708  C,
709  p1,q1,r1,s1,t1,
710  t,
711  x,
712  u,
713  m,dm,
714  f,df,
715  a,da,
716  phi,dphi,
717  r,
718  dr);
719 
720  for (k=0; k < nPoints; k++)
721  {
722  max_1mu_0 = 1.0-u[k] > 0.0 ? 1.0-u[k] : 0.0;
723 
724  if (p2 > 1.0)
725  {
726  m[k] *= pow(max_1mu_0,p2);
727  dm[k] *= pow(max_1mu_0,p2M1)*p2;
728  }
729 
730  if (q2 > 1.0)
731  {
732  for (I=0; I < nSpace; I++)
733  {
734  f[k*nSpace+I] *= pow(max_1mu_0,q2);
735  df[k*nSpace+I] *= pow(max_1mu_0,q2M1)*q2;
736  }
737  }
738 
739  if (t2 > 0.0)
740  {
741  atmp = pow(max_1mu_0,t2);
742  datmp = pow(max_1mu_0,t2M1);
743  for (I=0; I < nSpace; I++)
744  {
745  for (J=0; J < nSpace; J++)
746  {
747  a[k*nSpace2+I*nSpace+J] *= atmp;
748  da[k*nSpace2+I*nSpace+J] *= datmp*t2;
749  }
750  }
751  }
752 
753  if (r2 > 1.0)
754  {
755  phi[k] *= pow(max_1mu_0,r2);
756  dphi[k] *= pow(max_1mu_0,r2M1)*r2;
757  }
758 
759  if (s2 > 1.0)
760  {
761  r[k] *= pow(max_1mu_0,s2*r[k]);
762  dr[k] *= pow(max_1mu_0,s2M1)*s2;
763  }
764  }
765 }
766 
767 void unitSquareRotationEvaluate(const int nPoints,
768  const int nSpace,
769  const double *x,
770  const double *u,
771  double *m,
772  double *dm,
773  double *f,
774  double *df)
775 {
776  double vx, vy;
777  int k;
778  for (k=0; k < nPoints; k++)
779  {
780  m[k] = u[k];
781  dm[k] = 1.0;
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];
786  df[k*nSpace] = vx;
787  df[k*nSpace+1] = vy;
788  }
789 }
790 
791 void unitCubeRotationEvaluate(const int nPoints,
792  const int nSpace,
793  const double *x,
794  const double *u,
795  double *m,
796  double *dm,
797  double *f,
798  double *df)
799 {
800  double vx, vy, vz;
801  int k;
802  for (k=0; k < nPoints; k++)
803  {
804  m[k] = u[k];
805  dm[k] = 1.0;
806  vx = 2.0*M_PI*(x[k*3+1] - 0.5);
807  vy = 2.0*M_PI*(0.5 - x[k*3]);
808  vz = 0.0;
809  f[k*nSpace] = vx*u[k];
810  f[k*nSpace+1] = vy*u[k];
811  f[k*nSpace+2] = vz*u[k];
812  df[k*nSpace] = vx;
813  df[k*nSpace+1] = vy;
814  df[k*nSpace+2] = vz;
815  }
816 }
817 
818 void rotatingPulseVelEvaluate(const int nPoints,
819  const int nSpace,
820  const double self_a,
821  const double *x,
822  const double *u,
823  double *m,
824  double *dm,
825  double *f,
826  double *df,
827  double *a,
828  double *da,
829  double *phi,
830  double *dphi)
831 {
832  /*mwf add variable declarations*/
833  double vx,vy;
834  int k,I;
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));
839 
840 
841  for (k=0; k < nPoints; k++)
842  {
843  dm[k] = dphi[k] = 1.0;
844 
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];
849  df[k*nSpace] = vx;
850  df[k*nSpace+1] = vy;
851 
852  for (I=0; I < nSpace; I++)
853  {
854  a[k*nSpace2 + I*nSpace + I] = self_a;
855  }
856  }
857 }
858 
859 void disRotatingPulseVelEvaluate(const int nPoints,
860  const int nSpace,
861  const double self_a,
862  const double *x,
863  const double *u,
864  double *m,
865  double *dm,
866  double *f,
867  double *df,
868  double *a,
869  double *da,
870  double *phi,
871  double *dphi)
872 {
873  double X,Y,vx,vy;
874  int k,I;
875  const int nSpace2 = nSpace*nSpace;
876 
877  memcpy(m, u, nPoints * sizeof(double));
878  memcpy(phi, u, nPoints * sizeof(double));
879  memset(da, 0, nPoints * nSpace2 * sizeof(double));
880 
881  for (k=0; k < nPoints; k++)
882  {
883  dm[k] = dphi[k] = 1.0;
884 
885  X = x[k*3+1] - 0.5;
886  Y = x[k*3] - 0.5;
887  vx = -4.0*X;
888  vy = 4.0*Y;
889  f[k*nSpace] = vx*u[k];
890  f[k*nSpace+1] = vy*u[k];
891  df[k*nSpace] = vx;
892  df[k*nSpace+1] = vy;
893  if (sqrt(X*X+Y*Y) < 0.25)
894  {
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;
899  }
900 
901  for (I=0; I < nSpace; I++)
902  {
903  a[k*nSpace2 + I*nSpace + I] = self_a;
904  }
905  }
906 }
907 
908 void disVelEvaluate(const int nPoints,
909  const int nSpace,
910  const double self_a,
911  const double *x,
912  const double *u,
913  double *m,
914  double *dm,
915  double *f,
916  double *df,
917  double *a,
918  double *da,
919  double *phi,
920  double *dphi)
921 {
922  int k,I,J;
923  const int nSpace2 = nSpace*nSpace;
924 
925  for (k=0; k < nPoints; k++)
926  {
927  m[k] = u[k];
928  phi[k] = 0.0;
929  dm[k] = dphi[k] = 1.0;
930 
931  f[k*nSpace] = u[k];
932  f[k*nSpace+1] = 0.0;
933  df[k*nSpace] = 1.0;
934  df[k*nSpace+1] = 0.0;
935  if (x[k*3+1] > 0.5)
936  {
937  f[k*nSpace] *= 0.25;
938  df[k*nSpace] *= 0.25;
939  }
940 
941  for (I=0; I < nSpace; I++)
942  {
943  a[k*nSpace2 + I*nSpace + I] = self_a;
944 
945  for (J=0; J < nSpace; J++)
946  {
947  da[k*nSpace2 + I*nSpace + J] = 0.0;
948  }
949  }
950  }
951 }
952 
953 void burgersDiagonalVelEvaluate(const int nPoints,
954  const int nSpace,
955  const double self_a,
956  const double *self_v,
957  const double *u,
958  double *m,
959  double *dm,
960  double *f,
961  double *df,
962  double *a,
963  double *phi,
964  double *dphi)
965 {
966  double u2;
967  int k,I;
968  const int nSpace2 = nSpace*nSpace;
969  /*mwf changed to remove maxu0*/
970  for (k=0; k < nPoints; k++)
971  {
972  m[k] = phi[k] = u[k];
973  dm[k] = dphi[k] = 1.0;
974  u2 = u[k]*u[k];
975  for (I=0; I < nSpace; I++)
976  {
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];
980 
981 /* for (J=0; J < nSpace; J++) */
982 /* { */
983 /* da[k*nSpace2 + I*nSpace + J] = 0.0; */
984 /* } */
985  }
986  }
987 }
988 
989 void burgersDiagonalVelHJEvaluate(const int nPoints,
990  const int nSpace,
991  const double self_a,
992  const double *self_v,
993  const double *u,
994  const double *grad_u,
995  double *m,
996  double *dm,
997  double *H,
998  double *dH,
999  double *a,
1000  double *phi,
1001  double *dphi)
1002 {
1003  double u2;
1004  int k,I;
1005  const int nSpace2 = nSpace*nSpace;
1006  /*mwf changed to remove maxu0*/
1007  for (k=0; k < nPoints; k++)
1008  {
1009  m[k] = phi[k] = u[k];
1010  dm[k] = dphi[k] = 1.0;
1011  u2 = u[k]*u[k];
1012  H[k] = 0.0;
1013  for (I=0; I < nSpace; I++)
1014  {
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];
1018 
1019 /* for (J=0; J < nSpace; J++) */
1020 /* { */
1021 /* da[k*nSpace2 + I*nSpace + J] = 0.0; */
1022 /* } */
1023  }
1024  }
1025 }
1026 
1028  int nSpace,
1029  double *M,
1030  double *A,
1031  double *B,
1032  double *Bcon,
1033  double *C,
1034  double t,
1035  double *x,
1036  double *u,
1037  double *m,
1038  double *dm,
1039  double *f,
1040  double *df,
1041  double *a,
1042  double *da,
1043  double *phi,
1044  double *dphi,
1045  double *r,
1046  double *dr)
1047 {
1048  int k,I,J;
1049  const int nSpace2=nSpace*nSpace;
1050  for (k=0;k<nPoints;k++)
1051  {
1052  m[k]=M[k]*u[k];
1053  dm[k]=M[k];
1054  for (I=0;I<nSpace;I++)
1055  {
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++)
1059  {
1060  a[k*nSpace2+I*nSpace+J]=A[k*nSpace2 + I*nSpace+J];
1061  da[k*nSpace2+I*nSpace+J]=0.0;
1062  }
1063  }
1064 
1065  phi[k]=u[k];
1066  dphi[k]=1.0;
1067 
1068  r[k]=C[k]*u[k];
1069  dr[k]=C[k];
1070  }
1071 }
1072 
1074  int nSpace,
1075  double eps,
1076  double* u_levelSet,
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)
1082 {
1083  int k,I,J;
1084  const int nSpace2=nSpace*nSpace;
1085  double H,oneMinusH;
1086  for (k=0;k<nPoints;k++)
1087  {
1088  if (u_levelSet[k] > eps)
1089  {
1090  M[k] = M1;
1091  for (I=0;I<nSpace;I++)
1092  {
1093  B[k*nSpace+I]=B1[I];
1094  Bcon[k*nSpace+I]=Bcon1[I];
1095  for (J=0;J<nSpace;J++)
1096  {
1097  A[k*nSpace2+I*nSpace+J]=A1[I*nSpace+J];
1098  }
1099  }
1100  C[k] = C1;
1101  }
1102  else if (u_levelSet[k] < -eps)
1103  {
1104  M[k] = M2;
1105  for (I=0;I<nSpace;I++)
1106  {
1107  B[k*nSpace+I]=B2[I];
1108  Bcon[k*nSpace+I]=Bcon2[I];
1109  for (J=0;J<nSpace;J++)
1110  {
1111  A[k*nSpace2+I*nSpace+J]=A2[I*nSpace+J];
1112  }
1113  }
1114  C[k] = C2;
1115  }
1116  else
1117  {
1118  H = 0.5*(1.0 + u_levelSet[k]/eps + sin((M_PI*u_levelSet[k])/eps)/M_PI);
1119  oneMinusH=1.0-H;
1120  M[k] = oneMinusH*M2 + H*M1;
1121  for (I=0;I<nSpace;I++)
1122  {
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++)
1126  {
1127  A[k*nSpace2+I*nSpace+J]=oneMinusH*A2[I*nSpace+J] + H*A1[I*nSpace+J];
1128  }
1129  }
1130  C[k]=oneMinusH*C2+H*C1;
1131  }
1132  }
1133 }
1134 
1136  int nSpace,
1137  double v_scale,
1138  double* vIn,
1139  double* vOut)
1140 {
1141  int i,I;
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];
1145 }
1146 
1148  int nSpace,
1149  double* B,
1150  double t,
1151  double* x,
1152  double* u,
1153  double* grad_u,
1154  double* m, double* dm,
1155  double* h, double* dh,
1156  double* rh)
1157 {
1158  int i,I;
1159  for (i=0;i<nPoints;i++)
1160  {
1161  rh[i]=0.0;
1162  h[i]=0.0;
1163  m[i]=u[i];
1164  dm[i]=1.0;
1165  for (I=0;I<nSpace;I++)
1166  {
1167  h[i] += B[i*nSpace+I]*grad_u[i*nSpace+I];
1168  dh[i*nSpace+I]=B[i*nSpace+I];
1169  }
1170  }
1171 }
1172 
1174  int nSpace,
1175  double* B,
1176  double t,
1177  double* x,
1178  double* u,
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)
1184 {
1185  int i,I;
1186  for (i=0;i<nPoints;i++)
1187  {
1188  m[i]=u[i];
1189  dm[i]=1.0;
1190  for (I=0;I<nSpace;I++)
1191  {
1192  f[i*nSpace+I] = B[i*nSpace+I]*u[i];
1193  df[i*nSpace+I]=B[i*nSpace+I];
1194  }
1195  }
1196 }
1197 
1199  int nSpace,
1200  double* v,
1201  double* u,
1202  double* grad_u,
1203  double* m,
1204  double* dm,
1205  double* H,
1206  double* dH)
1207 {
1208  int i,I;
1209  for (i=0;i<nPoints;i++)
1210  {
1211  m[i]=u[i];
1212  dm[i]=1.0;
1213  H[i] = 0.0;
1214  for (I=0;I<nSpace;I++)
1215  {
1216  H[i] += v[i*nSpace+I]*grad_u[i*nSpace+I];
1217  dH[i*nSpace+I] = v[i*nSpace+I];
1218  }
1219  }
1220 }
1221 
1223  int nSpace,
1224  double* v,
1225  double* u,
1226  double* m,
1227  double* dm,
1228  double* f,
1229  double* df)
1230 {
1231  int i,I;
1232  for (i=0;i<nPoints;i++)
1233  {
1234  m[i]=u[i];
1235  dm[i]=1.0;
1236  for (I=0;I<nSpace;I++)
1237  {
1238  f[i*nSpace+I] = v[i*nSpace+I]*u[i];
1239  df[i*nSpace+I] = v[i*nSpace+I];
1240  }
1241  }
1242 }
1243 
1244 void VOFCoefficientsEvaluate(int nPoints,
1245  int nSpace,
1246  double eps,
1247  double* v,
1248  double* phi,
1249  double* u,
1250  double* m,
1251  double* dm,
1252  double* f,
1253  double* df)
1254 {
1255  int i,I;
1256  for (i=0;i<nPoints;i++)
1257  {
1258  m[i]=u[i];
1259  dm[i]=1.0;
1260  for (I=0;I<nSpace;I++)
1261  {
1262 /* f[i*nSpace+I] = v[i*nSpace+I]*smoothedHeaviside(eps,phi[i]); */
1263 /* df[i*nSpace+I] = 0.0; */
1264  f[i*nSpace+I] = v[i*nSpace+I]*u[i];
1265  df[i*nSpace+I] = v[i*nSpace+I];
1266  }
1267  }
1268 }
1269 
1271  int nSpace,
1272  double *grad_phi,
1273  double *u,
1274  double *f,
1275  double *r,
1276  double *dr)
1277 {
1278  int i,I;
1279  double norm_grad_phi;
1280  for (i=0;i<nPoints;i++)
1281  {
1282  r[i] = u[i];
1283  dr[i] = 1.0;
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)
1289  {
1290  for (I=0;I<nSpace;I++)
1291  f[i*nSpace+I] = grad_phi[i*nSpace+I]/norm_grad_phi;
1292  }
1293  else
1294  f[i*nSpace+I] = 0.0;
1295  }
1296 }
1297 
1299  double eps,
1300  double* u_levelSet,
1301  double* S)
1302 {
1303  int k;
1304  double H;
1305  for (k=0;k<nPoints;k++)
1306  {
1307  if (u_levelSet[k] > eps)
1308  S[k]= 1.0;
1309  else if (u_levelSet[k] < -eps)
1310  S[k] = -1.0;
1311  else
1312  {
1313  H = 0.5*(1.0 + u_levelSet[k]/eps + sin((M_PI*u_levelSet[k])/eps)/M_PI);
1314  S[k]=2.0*H - 1.0;
1315  }
1316  }
1317 /* for (k=0;k<nPoints;k++) */
1318 /* S[k] = u_levelSet[k]/sqrt(u_levelSet[k]*u_levelSet[k] + eps*eps); */
1319 /* if(u_levelSet[k] > 0.0) */
1320 /* S[k] = 1.0; */
1321 /* else */
1322 /* S[k] = -1.0; */
1323 }
1324 
1326  int nSpace,
1327  double* S,
1328  double* u,
1329  double* grad_u,
1330  double* m, double* dm,
1331  double* h, double* dh,
1332  double* rh)
1333 {
1334  int i,I;
1335  for (i=0;i<nPoints;i++)
1336  {
1337  m[i]=u[i];
1338  dm[i]=1.0;
1339  rh[i]=-1.0;
1340  h[i]=0.0;
1341  for (I=0;I<nSpace;I++)
1342  h[i] += grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1343  h[i] = sqrt(h[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];
1347  else
1348  dh[i*nSpace+I] = (S[i]*grad_u[i*nSpace+I])/1.0e-8;
1349  h[i]+=rh[i];
1350  h[i]*=S[i];
1351  rh[i]*=S[i];
1352  }
1353 }
1354 void eikonalEquationEvaluate(int nPoints,
1355  int nSpace,
1356  double rhs,
1357  double* u,
1358  double* grad_u,
1359  double* m,
1360  double* dm,
1361  double* H,
1362  double* dH,
1363  double* r)
1364 {
1365  int i,I;
1366  double normGradU;
1367  for (i=0;i<nPoints;i++)
1368  {
1369  m[i]=u[i];
1370  dm[i]=1.0;
1371  H[i] = 0.0;
1372  r[i]=-rhs;
1373  normGradU=0.0;
1374  for (I=0;I<nSpace;I++)
1375  normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1376  normGradU = sqrt(normGradU);
1377  H[i] = normGradU;
1378  for (I=0;I<nSpace;I++)
1379  {
1380  dH[i*nSpace+I] = grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1381  }/*I*/
1382  }/*i*/
1383 }
1385  int nSpace,
1386  double eps,
1387  double* u_levelSet,
1388  double* u,
1389  double* grad_u,
1390  double* m,
1391  double* dm,
1392  double* H,
1393  double* dH,
1394  double* r)
1395 {
1396  int i,I;
1397  double Si,normGradU;/* He */
1398  /*mwf debug
1399  printf("redistanceLS nPoints= %d nSpace= %d eps= %g \n",nPoints,nSpace,eps);
1400  */
1401  for (i=0;i<nPoints;i++)
1402  {
1403  m[i]=u[i];
1404  dm[i]=1.0;
1405  H[i] = 0.0;
1406  Si = -1.0+2.0*smoothedHeaviside(eps,u_levelSet[i]);
1407 /* if (u_levelSet[i] > eps) */
1408 /* Si=1.0; */
1409 /* else if (u_levelSet[i] < -eps) */
1410 /* Si=-1.0; */
1411 /* else */
1412 /* { */
1413 /* He=0.5*(1.0 + u_levelSet[i]/eps + sin(M_PI*u_levelSet[i]/eps)/M_PI); */
1414 /* Si= 2.0*He-1.0; */
1415 /* } */
1416  /*mwf now try just straight sign with small eps*/
1417  /*Si = u_levelSet[i]/sqrt(u_levelSet[i]*u_levelSet[i]+1.0e-12)*/;
1418  /*
1419  r =-S
1420  H =S*|\grad d|
1421  dH=S*\grad d/|\grad d|
1422  */
1423  r[i]=-Si;
1424  normGradU=0.0;
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;
1429  /*
1430  mwf debug what about solving with r= 0 and H=S*(|\grad d|-1)?
1431  no longer homogeneous of order 1, gets Hamiltonian wrong in stabilization
1432  */
1433  /*
1434  r[i] = 0.0;
1435  H[i] = Si*(normGradU-1.0);
1436  */
1437  for (I=0;I<nSpace;I++)
1438  {
1439  dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1440  }/*I*/
1441  }/*i*/
1442 }
1444  int nSpace,
1445  double eps,
1446  double lambda_penalty,
1447  double* u_levelSet,
1448  double* u,
1449  double* grad_u,
1450  double* m,
1451  double* dm,
1452  double* H,
1453  double* dH,
1454  double* r,
1455  double* dr)
1456 {
1457  int i,I;
1458  double Si,normGradU;/* He */
1459  /*mwf debug
1460  printf("redistanceLS nPoints= %d nSpace= %d eps= %g \n",nPoints,nSpace,eps);
1461  */
1462  for (i=0;i<nPoints;i++)
1463  {
1464  m[i]=u[i];
1465  dm[i]=1.0;
1466  H[i] = 0.0;
1467  Si = -1.0+2.0*smoothedHeaviside(eps,u_levelSet[i]);
1468 /* if (u_levelSet[i] > eps) */
1469 /* Si=1.0; */
1470 /* else if (u_levelSet[i] < -eps) */
1471 /* Si=-1.0; */
1472 /* else */
1473 /* { */
1474 /* He=0.5*(1.0 + u_levelSet[i]/eps + sin(M_PI*u_levelSet[i]/eps)/M_PI); */
1475 /* Si= 2.0*He-1.0; */
1476 /* } */
1477  /*mwf now try just straight sign with small eps*/
1478  /*Si = u_levelSet[i]/sqrt(u_levelSet[i]*u_levelSet[i]+1.0e-12)*/;
1479  /*
1480  r =-S
1481  H =S*|\grad d|
1482  dH=S*\grad d/|\grad d|
1483  */
1484  r[i]=-Si;
1485  normGradU=0.0;
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;
1490  /*
1491  mwf debug what about solving with r= 0 and H=S*(|\grad d|-1)?
1492  no longer homogeneous of order 1, gets Hamiltonian wrong in stabilization
1493  */
1494  /*
1495  r[i] = 0.0;
1496  H[i] = Si*(normGradU-1.0);
1497  */
1498  for (I=0;I<nSpace;I++)
1499  {
1500  dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1501  }/*I*/
1502  /*add in weak penalty*/
1503  r[i] += (u[i]-u_levelSet[i])*lambda_penalty*smoothedDirac(eps,u_levelSet[i]);
1504  dr[i] = lambda_penalty*smoothedDirac(eps,u_levelSet[i]);
1505  }/*i*/
1506 }
1507 
1508 /*
1509  redistance as before, but include lagrange multiplier source term to improve volume
1510  conservation following Sussman and Fatemi 99
1511 */
1513  int nPointsPerSimplex,
1514  int nSpace,
1515  double eps,
1516  double* u_levelSet,
1517  double* dV,
1518  double* u,
1519  double* grad_u,
1520  double* m,
1521  double* dm,
1522  double* H,
1523  double* dH,
1524  double* r)
1525 {
1526  int ie,iq,i,I;
1527  double He,Si,normGradU,
1528  dHe,Li,lambda;
1529  /*mwf debug
1530  printf("redistanceLSSandF nSimplex=%d nPointsPerSimplex= %d nSpace= %d eps= %g \n",nSimplex,
1531  nPointsPerSimplex,nSpace,eps);
1532  */
1533  for (ie=0; ie < nSimplex; ie++)
1534  {
1535  /*first loop through simplex and compute normal coefficients,
1536  then loop back through and include lagrange multiplier term
1537  */
1538  for (iq=0;iq<nPointsPerSimplex;iq++)
1539  {
1540  i = ie*nPointsPerSimplex + iq;
1541  m[i]=u[i];
1542  dm[i]=1.0;
1543  H[i] = 0.0;
1544  dHe = 0.0;
1545  if (u_levelSet[i] > eps)
1546  {
1547  Si=1.0; He = 1.0;
1548  }
1549  else if (u_levelSet[i] < -eps)
1550  {
1551  Si=-1.0; He = 0.0;
1552  }
1553  else
1554  {
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);
1557  Si= 2.0*He-1.0;
1558  }
1559  normGradU=0.0;
1560  for (I=0;I<nSpace;I++)
1561  normGradU+= grad_u[i*nSpace+I]*grad_u[i*nSpace+I];
1562  normGradU = sqrt(normGradU);
1563  /*now loop through simplex and compute averages*/
1564  r[i]=-Si;
1565  H[i] = Si*normGradU;
1566  for (I=0;I<nSpace;I++)
1567  {
1568  dH[i*nSpace+I] = Si*grad_u[i*nSpace+I]/(normGradU+1.0e-12);
1569  }/*I*/
1570  }/*iq loop 1*/
1571  /*the following is wasteful*/
1572  lambda = 0.0;
1573  for (iq = 0; iq < nPointsPerSimplex; iq++)
1574  {
1575  i = ie*nPointsPerSimplex + iq;
1576  Li= -r[i] - H[i];/* Si(1-|gradU|) */
1577  dHe = 0.0;
1578  if (u_levelSet[i] > eps)
1579  {
1580  Si=1.0; He = 1.0;
1581  }
1582  else if (u_levelSet[i] < -eps)
1583  {
1584  Si=-1.0; He = 0.0;
1585  }
1586  else
1587  {
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);
1590  Si= 2.0*He-1.0;
1591  }
1592  normGradU = H[i]/Si;
1593  lambda -= dHe*Li*dV[i]/(dHe*dHe*normGradU+1.0e-8);
1594  }/*iq*/
1595  /*go back through and update source term*/
1596  for (iq = 0; iq < nPointsPerSimplex; iq++)
1597  {
1598  i = ie*nPointsPerSimplex + iq;
1599  dHe = 0.0; He=1.0;
1600  if (u_levelSet[i] > eps)
1601  {Si=1.0; He = 1.0;}
1602  else if (u_levelSet[i] < -eps)
1603  {Si=-1.0; He = 0.0;}
1604  else
1605  {
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);
1608  Si= 2.0*He-1.0;
1609  }
1610  normGradU = H[i]/Si;
1611  r[i] -= lambda*dHe*normGradU;/*recall r is minus right hand side*/
1612  /*mwf debug
1613  printf("redistSandF ie=%d iq=%d u=%g He=%g dHe=%g Si=%g |gradu|=%g lam=%g r=%g\n",
1614  ie,iq,u_levelSet[i],He,dHe,Si,normGradU,lambda,r[i]);
1615  */
1616  }/*iq*/
1617  }/*ie*/
1618 }/*func*/
1619 
1620 void setWeakDirichletConditionsForLevelSet(int nElements_global,
1621  int nDOF_trial_element,
1622  double epsilon_freeze_factor,
1623  const double *elementDiameter,
1624  const int * u_l2g,
1625  const double *u_dof,
1626  int * freeze_nodes_tmp,
1627  int * weakDirichletConditionFlags)
1628 {
1629  int eN,j,jj,signU,j0,J0,J;
1630  double eps;
1631  for (eN = 0; eN < nElements_global; eN++)
1632  {
1633  for (j = 0; j < nDOF_trial_element; j++)
1634  freeze_nodes_tmp[j] = 0;
1635  eps = epsilon_freeze_factor*elementDiameter[eN];
1636  signU = 0; j0 = 0;
1637  while (signU == 0 && j0 < nDOF_trial_element)
1638  {
1639  J0 = u_l2g[eN*nDOF_trial_element + j0];
1640  if (u_dof[J0] < -eps)
1641  signU = -1;
1642  else if (u_dof[J0] > eps)
1643  signU = 1;
1644  else
1645  freeze_nodes_tmp[j0] = 1;
1646  j0++;
1647  }
1648  for (j = j0; j < nDOF_trial_element; j++)
1649  {
1650  J = u_l2g[eN*nDOF_trial_element + j];
1651  if ((u_dof[J] < -eps && signU == 1) ||
1652  (u_dof[J] > eps && signU == -1))
1653  {
1654  for (jj = 0; jj < nDOF_trial_element; jj++)
1655  freeze_nodes_tmp[jj] = 1;
1656  break;
1657  }
1658  else if (fabs(u_dof[J]) < eps)
1659  freeze_nodes_tmp[j] = 1;
1660  }
1661  for (j = 0; j < nDOF_trial_element; j++)
1662  {
1663  if (freeze_nodes_tmp[j] == 1)
1664  {
1665  J = u_l2g[eN*nDOF_trial_element + j];
1666  weakDirichletConditionFlags[J] = 1;
1667  }
1668  }
1669  }//eN
1670 }
1671 
1673  int nDOF_trial_element,
1674  double epsilon_freeze_factor,
1675  const double *elementDiameter,
1676  const int * u_l2g,
1677  const double *u_dof,
1678  int * freeze_nodes_tmp,
1679  int * weakDirichletConditionFlags)
1680 {
1681  int eN,j,J;
1682  double eps;
1683  for (eN = 0; eN < nElements_global; eN++)
1684  {
1685  eps = epsilon_freeze_factor*elementDiameter[eN];
1686  for (j = 0; j < nDOF_trial_element; j++)
1687  {
1688  J = u_l2g[eN*nDOF_trial_element + j];
1689  if (fabs(u_dof[J]) < eps)
1690  weakDirichletConditionFlags[J] = 1;
1691  }
1692  }
1693 }
1694 
1695 /***********************************************************************
1696  begin two phase potential flow duplication efforts by mwf
1697  ***********************************************************************/
1699  int nSpace,
1700  double Km, double rhoM,
1701  double Kp, double rhoP,
1702  double eps,
1703  double * gravity_u,
1704  double * u,
1705  double * gradu,
1706  double * u_levelSet,
1707  double * phi_pot,
1708  double * a,
1709  double * f,
1710  double * r,
1711  double * m,
1712  double * dphi_pot,
1713  double * da,
1714  double * df,
1715  double * dr,
1716  double * dm)
1717 {
1718  int k,I,J,nSpace2;
1719  double He;
1720 
1721  nSpace2 = nSpace*nSpace;
1722  for (k = 0; k < nPoints; k++)
1723  {
1724  m[k] = 0.0; dm[k] = 1.0;
1725  r[k] = 0.0; dr[k] = 0.0;
1726  phi_pot[k] =u[k];
1727  dphi_pot[k]=1.0;
1728 
1729  He = smoothedHeaviside(eps,u_levelSet[k]);
1730  /*mwf debug
1731  printf("u_ls[%d]= %g He=%g \n",k,u_levelSet[k],He);
1732  */
1733  for (I = 0; I < nSpace; I++)
1734  {
1735  for (J = 0; J < nSpace; J++)
1736  {
1737  if (I==J)
1738  a[k*nSpace2 + I*nSpace+J] = Km + He*(Kp-Km);
1739  else
1740  a[k*nSpace2 + I*nSpace+J] = 0.0;
1741  da[k*nSpace2 + I*nSpace+J] = 0.0;
1742  }
1743  f[k*nSpace + I] = (Km*rhoM + He*(Kp*rhoP-Km*rhoM))*gravity_u[I];
1744  df[k*nSpace + I]= 0.0;
1745  }/*I*/
1746  }/*k*/
1747 
1748 }
1749 
1751  int nSpace,
1752  double Km, double rhoM,
1753  double Kp, double rhoP,
1754  double eps,
1755  double * gravity_u,
1756  double * u,
1757  double * gradu,
1758  double * u_levelSet,
1759  double * phi_pot,
1760  double * a,
1761  double * f,
1762  double * r,
1763  double * m,
1764  double * dphi_pot,
1765  double * da,
1766  double * df,
1767  double * dr,
1768  double * dm)
1769 {
1770  int k,I,J,nSpace2;
1771  double He,rhoHe;
1772  double rhoEps = 0.0; /*do not smear density*/
1773  nSpace2 = nSpace*nSpace;
1774  for (k = 0; k < nPoints; k++)
1775  {
1776  m[k] = 0.0; dm[k] = 1.0;
1777  r[k] = 0.0; dr[k] = 0.0;
1778  phi_pot[k] =u[k];
1779  dphi_pot[k]=1.0;
1780 
1781  He = smoothedHeaviside(eps,u_levelSet[k]);
1782  rhoHe = smoothedHeaviside(rhoEps,u_levelSet[k]);
1783  /*mwf debug
1784  printf("u_ls[%d]= %g He=%g \n",k,u_levelSet[k],He);
1785  */
1786  for (I = 0; I < nSpace; I++)
1787  {
1788  for (J = 0; J < nSpace; J++)
1789  {
1790  if (I==J)
1791  a[k*nSpace2 + I*nSpace+J] = Km + He*(Kp-Km);
1792  else
1793  a[k*nSpace2 + I*nSpace+J] = 0.0;
1794  da[k*nSpace2 + I*nSpace+J] = 0.0;
1795  }
1796  f[k*nSpace + I] = (Km*rhoM + He*(Kp*rhoP-Km*rhoM))*gravity_u[I];
1797  df[k*nSpace + I]= 0.0;
1798  }/*I*/
1799  }/*k*/
1800 
1801 }
1802 
1803 void Laplace_Evaluate2D(const int nPoints,
1804  double *mom_p_diff_ten,
1805  double *mom_u_diff_ten,
1806  double *mom_v_diff_ten)
1807 {
1808  int k;
1809  for (k=0; k<nPoints; k++)
1810  {
1811  mom_p_diff_ten[k*2+0] = 1.0;
1812  mom_p_diff_ten[k*2+1] = 1.0;
1813 
1814  mom_u_diff_ten[k*2+0] = 1.0;
1815  mom_u_diff_ten[k*2+1] = 1.0;
1816 
1817  mom_v_diff_ten[k*2+0] = 1.0;
1818  mom_v_diff_ten[k*2+1] = 1.0;
1819  }
1820 }
1821 
1822 void Laplace_Evaluate3D(const int nPoints,
1823  double *mom_p_diff_ten,
1824  double *mom_u_diff_ten,
1825  double *mom_v_diff_ten,
1826  double *mom_w_diff_ten)
1827 {
1828  int k;
1829  for (k=0; k<nPoints; k++)
1830  {
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;
1834 
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;
1838 
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;
1842 
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;
1846  }
1847 }
1848 
1849 
1850 void NavierStokes_2D_Evaluate(const int nPoints,
1851  const double rho,
1852  const double nu,
1853  const double *g,
1854  const double *p,
1855  const double *grad_p,
1856  const double *u,
1857  const double *v,
1858  double *mom_u_acc,
1859  double *dmom_u_acc_u,
1860  double *mom_v_acc,
1861  double *dmom_v_acc_v,
1862  double *mass_adv,
1863  double *dmass_adv_u,
1864  double *dmass_adv_v,
1865  double *mom_u_adv,
1866  double *dmom_u_adv_u,
1867  double *dmom_u_adv_v,
1868  double *mom_v_adv,
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,
1875  double *mom_u_ham,
1876  double *dmom_u_ham_grad_p,
1877  double *mom_v_ham,
1878  double *dmom_v_ham_grad_p)
1879 {
1880  int k;
1881  for (k=0;k<nPoints;k++)
1882  {
1884  //momentum accumulation
1885  mom_u_acc[k]=u[k];
1886  dmom_u_acc_u[k]=1.0;
1887 
1888  mom_v_acc[k]=v[k];
1889  dmom_v_acc_v[k]=1.0;
1890 
1891  //mass advective flux
1892  mass_adv[k*2+0]=u[k];
1893  mass_adv[k*2+1]=v[k];
1894 
1895  dmass_adv_u[k*2+0]=1.0;
1896  dmass_adv_v[k*2+1]=1.0;
1897 
1898  //u momentum advective flux
1899  mom_u_adv[k*2+0]=u[k]*u[k];
1900  mom_u_adv[k*2+1]=u[k]*v[k];
1901 
1902  dmom_u_adv_u[k*2+0]=2.0*u[k];
1903  dmom_u_adv_u[k*2+1]=v[k];
1904 
1905  dmom_u_adv_v[k*2+1]=u[k];
1906 
1907  //v momentum advective_flux
1908  mom_v_adv[k*2+0]=v[k]*u[k];
1909  mom_v_adv[k*2+1]=v[k]*v[k];
1910 
1911  dmom_v_adv_u[k*2+0]=v[k];
1912 
1913  dmom_v_adv_v[k*2+0]=u[k];
1914  dmom_v_adv_v[k*2+1]=2.0*v[k];
1915 
1916  //u momentum diffusion tensor
1917  mom_u_diff_ten[k*4+0] = nu;
1918  mom_u_diff_ten[k*4+3] = nu;
1919 
1920  //v momentum diffusion tensor
1921  mom_v_diff_ten[k*4+0] = nu;
1922  mom_v_diff_ten[k*4+3] = nu;
1923 
1924  //momentum sources
1925  mom_u_source[k] = -g[0];
1926  mom_v_source[k] = -g[1];
1927 
1928  //u momentum Hamiltonian (pressure)
1929  mom_u_ham[k] = grad_p[k*2+0]/rho;
1930  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
1931 
1932  //v momentum Hamiltonian (pressure)
1933  mom_v_ham[k] = grad_p[k*2+1]/rho;
1934  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
1935  }
1936 }
1937 
1938 void NavierStokes_3D_Evaluate(const int nPoints,
1939  const double rho,
1940  const double nu,
1941  const double *g,
1942  const double *p,
1943  const double *grad_p,
1944  const double *u,
1945  const double *v,
1946  const double *w,
1947  double *mom_u_acc,
1948  double *dmom_u_acc_u,
1949  double *mom_v_acc,
1950  double *dmom_v_acc_v,
1951  double *mom_w_acc,
1952  double *dmom_w_acc_w,
1953  double *mass_adv,
1954  double *dmass_adv_u,
1955  double *dmass_adv_v,
1956  double *dmass_adv_w,
1957  double *mom_u_adv,
1958  double *dmom_u_adv_u,
1959  double *dmom_u_adv_v,
1960  double *dmom_u_adv_w,
1961  double *mom_v_adv,
1962  double *dmom_v_adv_u,
1963  double *dmom_v_adv_v,
1964  double *dmom_v_adv_w,
1965  double *mom_w_adv,
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,
1975  double *mom_u_ham,
1976  double *dmom_u_ham_grad_p,
1977  double *mom_v_ham,
1978  double *dmom_v_ham_grad_p,
1979  double *mom_w_ham,
1980  double *dmom_w_ham_grad_p)
1981 {
1982  int k;
1983  for (k=0;k<nPoints;k++)
1984  {
1986  //momentum accumulation
1987 
1988  mom_u_acc[k]=u[k];
1989  dmom_u_acc_u[k]=1.0;
1990 
1991  mom_v_acc[k]=v[k];
1992  dmom_v_acc_v[k]=1.0;
1993 
1994  mom_w_acc[k]=w[k];
1995  dmom_w_acc_w[k]=1.0;
1996 
1997  //mass advective flux
1998  mass_adv[k*3+0]=u[k];
1999  mass_adv[k*3+1]=v[k];
2000  mass_adv[k*3+2]=w[k];
2001 
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;
2005 
2006  //u momentum advective flux
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];
2010 
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];
2014 
2015  dmom_u_adv_v[k*3+1]=u[k];
2016 
2017  dmom_u_adv_w[k*3+2]=u[k];
2018 
2019  //v momentum advective_flux
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];
2023 
2024  dmom_v_adv_u[k*3+0]=v[k];
2025 
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];
2029 
2030  dmom_v_adv_w[k*3+2]=v[k];
2031 
2032  //w momentum advective_flux
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];
2036 
2037  dmom_w_adv_u[k*3+0]=w[k];
2038 
2039  dmom_w_adv_v[k*3+0]=w[k];
2040 
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];
2044 
2045  //u momentum diffusion tensor
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;
2049 
2050  //v momentum diffusion tensor
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;
2054 
2055  //w momentum diffusion tensor
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;
2059 
2060  //momentum sources
2061  mom_u_source[k] = -g[0];
2062  mom_v_source[k] = -g[1];
2063  mom_w_source[k] = -g[2];
2064 
2065  //u momentum Hamiltonian (pressure)
2066  mom_u_ham[k] = grad_p[k*3+0]/rho;
2067  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
2068 
2069  //v momentum Hamiltonian (pressure)
2070  mom_v_ham[k] = grad_p[k*3+1]/rho;
2071  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
2072 
2073  //w momentum Hamiltonian (pressure)
2074  mom_w_ham[k] = grad_p[k*3+2]/rho;
2075  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
2076  }
2077 }
2078 
2079 void Stokes_2D_Evaluate(const int nPoints,
2080  const double rho,
2081  const double nu,
2082  const double *g,
2083  const double *p,
2084  const double *grad_p,
2085  const double *u,
2086  const double *v,
2087  double *mom_u_acc,
2088  double *dmom_u_acc_u,
2089  double *mom_v_acc,
2090  double *dmom_v_acc_v,
2091  double *mass_adv,
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,
2098  double *mom_u_ham,
2099  double *dmom_u_ham_grad_p,
2100  double *mom_v_ham,
2101  double *dmom_v_ham_grad_p)
2102 {
2103  int k;
2104  for (k=0;k<nPoints;k++)
2105  {
2107  //momentum accumulation
2108  mom_u_acc[k]=u[k];
2109  dmom_u_acc_u[k]=1.0;
2110 
2111  mom_v_acc[k]=v[k];
2112  dmom_v_acc_v[k]=1.0;
2113 
2114  //mass advective flux
2115  mass_adv[k*2+0]=u[k];
2116  mass_adv[k*2+1]=v[k];
2117 
2118  dmass_adv_u[k*2+0]=1.0;
2119  dmass_adv_v[k*2+1]=1.0;
2120 
2121  //u momentum diffusion tensor
2122  mom_u_diff_ten[k*4+0] = nu;
2123  mom_u_diff_ten[k*4+3] = nu;
2124 
2125  //v momentum diffusion tensor
2126  mom_v_diff_ten[k*4+0] = nu;
2127  mom_v_diff_ten[k*4+3] = nu;
2128 
2129  //momentum sources
2130  mom_u_source[k] = -g[0];
2131  mom_v_source[k] = -g[1];
2132 
2133  //u momentum Hamiltonian (pressure)
2134  mom_u_ham[k] = grad_p[k*2+0]/rho;
2135  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2136 
2137  //v momentum Hamiltonian (pressure)
2138  mom_v_ham[k] = grad_p[k*2+1]/rho;
2139  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2140  }
2141 }
2142 
2143 void StokesP_2D_Evaluate(const int nPoints,
2144  const double rho,
2145  const double nu,
2146  const double *g,
2147  const double *p,
2148  const double *u,
2149  const double *v,
2150  double *mom_u_acc,
2151  double *dmom_u_acc_u,
2152  double *mom_v_acc,
2153  double *dmom_v_acc_v,
2154  double *mass_adv,
2155  double *dmass_adv_u,
2156  double *dmass_adv_v,
2157  double *mom_u_adv,
2158  double *dmom_u_adv_p,
2159  double *mom_v_adv,
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)
2165 {
2166  int k;
2167  for (k=0;k<nPoints;k++)
2168  {
2170  //momentum accumulation
2171  mom_u_acc[k]=u[k];
2172  dmom_u_acc_u[k]=1.0;
2173 
2174  mom_v_acc[k]=v[k];
2175  dmom_v_acc_v[k]=1.0;
2176 
2177  //mass advective flux
2178  mass_adv[k*2+0]=u[k];
2179  mass_adv[k*2+1]=v[k];
2180 
2181  dmass_adv_u[k*2+0]=1.0;
2182  dmass_adv_v[k*2+1]=1.0;
2183 
2184  //u momentum advective flux
2185  mom_u_adv[k*2+0]=p[k]/rho;
2186  dmom_u_adv_p[k*2+0]=1.0/rho;
2187 
2188  //v momentum advective flux
2189  mom_v_adv[k*2+1]=p[k]/rho;
2190  dmom_v_adv_p[k*2+1]=1.0/rho;
2191 
2192  //u momentum diffusion tensor
2193  mom_u_diff_ten[k*4+0] = nu;
2194  mom_u_diff_ten[k*4+3] = nu;
2195 
2196  //v momentum diffusion tensor
2197  mom_v_diff_ten[k*4+0] = nu;
2198  mom_v_diff_ten[k*4+3] = nu;
2199 
2200  //momentum sources
2201  mom_u_source[k] = -g[0];
2202  mom_v_source[k] = -g[1];
2203  }
2204 }
2205 
2206 void Stokes_3D_Evaluate(const int nPoints,
2207  const double rho,
2208  const double nu,
2209  const double *g,
2210  const double *p,
2211  const double *grad_p,
2212  const double *u,
2213  const double *v,
2214  const double *w,
2215  double *mom_u_acc,
2216  double *dmom_u_acc_u,
2217  double *mom_v_acc,
2218  double *dmom_v_acc_v,
2219  double *mom_w_acc,
2220  double *dmom_w_acc_w,
2221  double *mass_adv,
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,
2231  double *mom_u_ham,
2232  double *dmom_u_ham_grad_p,
2233  double *mom_v_ham,
2234  double *dmom_v_ham_grad_p,
2235  double *mom_w_ham,
2236  double *dmom_w_ham_grad_p)
2237 {
2238  int k;
2239  for (k=0;k<nPoints;k++)
2240  {
2242  //momentum accumulation
2243  mom_u_acc[k]=u[k];
2244  dmom_u_acc_u[k]=1.0;
2245 
2246  mom_v_acc[k]=v[k];
2247  dmom_v_acc_v[k]=1.0;
2248 
2249  mom_w_acc[k]=w[k];
2250  dmom_w_acc_w[k]=1.0;
2251 
2252  //mass advective flux
2253  mass_adv[k*3+0]=u[k];
2254  mass_adv[k*3+1]=v[k];
2255  mass_adv[k*3+2]=w[k];
2256 
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;
2260 
2261  //u momentum diffusion tensor
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;
2265 
2266  //v momentum diffusion tensor
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;
2270 
2271  //w momentum diffusion tensor
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;
2275 
2276  //momentum sources
2277  mom_u_source[k] = -g[0];
2278  mom_v_source[k] = -g[1];
2279  mom_w_source[k] = -g[2];
2280 
2281  //u momentum Hamiltonian (pressure)
2282  mom_u_ham[k] = grad_p[k*3+0]/rho;
2283  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
2284 
2285  //v momentum Hamiltonian (pressure)
2286  mom_v_ham[k] = grad_p[k*3+1]/rho;
2287  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
2288 
2289  //w momentum Hamiltonian (pressure)
2290  mom_w_ham[k] = grad_p[k*3+2]/rho;
2291  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
2292  }
2293 }
2294 
2295 void StokesP_3D_Evaluate(const int nPoints,
2296  const double rho,
2297  const double nu,
2298  const double *g,
2299  const double *p,
2300  const double *u,
2301  const double *v,
2302  const double *w,
2303  double *mom_u_acc,
2304  double *dmom_u_acc_u,
2305  double *mom_v_acc,
2306  double *dmom_v_acc_v,
2307  double *mom_w_acc,
2308  double *dmom_w_acc_w,
2309  double *mass_adv,
2310  double *dmass_adv_u,
2311  double *dmass_adv_v,
2312  double *dmass_adv_w,
2313  double *mom_u_adv,
2314  double *dmom_u_adv_p,
2315  double *mom_v_adv,
2316  double *dmom_v_adv_p,
2317  double *mom_w_adv,
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)
2325 {
2326  int k;
2327  for (k=0;k<nPoints;k++)
2328  {
2330  //momentum accumulation
2331  mom_u_acc[k]=u[k];
2332  dmom_u_acc_u[k]=1.0;
2333 
2334  mom_v_acc[k]=v[k];
2335  dmom_v_acc_v[k]=1.0;
2336 
2337  mom_w_acc[k]=w[k];
2338  dmom_w_acc_w[k]=1.0;
2339 
2340  //mass advective flux
2341  mass_adv[k*3+0]=u[k];
2342  mass_adv[k*3+1]=v[k];
2343  mass_adv[k*3+2]=w[k];
2344 
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;
2348 
2349  //u momentum advective flux
2350  mom_u_adv[k*3+0]=p[k]/rho;
2351  dmom_u_adv_p[k*3+0]=1.0/rho;
2352 
2353  //v momentum advective flux
2354  mom_v_adv[k*3+1]=p[k]/rho;
2355  dmom_v_adv_p[k*3+1]=1.0/rho;
2356 
2357  //w momentum advective flux
2358  mom_w_adv[k*3+2]=p[k]/rho;
2359  dmom_w_adv_p[k*3+2]=1.0/rho;
2360 
2361  //u momentum diffusion tensor
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;
2365 
2366  //v momentum diffusion tensor
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;
2370 
2371  //w momentum diffusion tensor
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;
2375 
2376  //momentum sources
2377  mom_u_source[k] = -g[0];
2378  mom_v_source[k] = -g[1];
2379  mom_w_source[k] = -g[2];
2380  }
2381 }
2382 
2384  const double eps,
2385  const double rho_0,
2386  const double nu_0,
2387  const double rho_1,
2388  const double nu_1,
2389  const double* g,
2390  const double* phi,
2391  const double *p,
2392  const double *grad_p,
2393  const double *u,
2394  const double *v,
2395  double *mom_u_acc,
2396  double *dmom_u_acc_u,
2397  double *mom_v_acc,
2398  double *dmom_v_acc_v,
2399  double *mass_adv,
2400  double *dmass_adv_u,
2401  double *dmass_adv_v,
2402  double *mom_u_adv,
2403  double *dmom_u_adv_u,
2404  double *dmom_u_adv_v,
2405  double *mom_v_adv,
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,
2412  double *mom_u_ham,
2413  double *dmom_u_ham_grad_p,
2414  double *mom_v_ham,
2415  double *dmom_v_ham_grad_p)
2416 {
2417  int k;
2418  double rho,nu,H;
2419  for (k=0;k<nPoints;k++)
2420  {
2422  H = smoothedHeaviside(eps,phi[k]);
2423  rho = rho_0*(1.0-H)+rho_1*H;
2424  nu = nu_0*(1.0-H)+nu_1*H;
2425 
2426  //u momentum accumulation
2427  mom_u_acc[k]=u[k];
2428  dmom_u_acc_u[k]=1.0;
2429 
2430  //v momentum accumulation
2431  mom_v_acc[k]=v[k];
2432  dmom_v_acc_v[k]=1.0;
2433 
2434  //mass advective flux
2435  mass_adv[k*2+0]=u[k];
2436  mass_adv[k*2+1]=v[k];
2437 
2438  dmass_adv_u[k*2+0]=1.0;
2439  dmass_adv_v[k*2+1]=1.0;
2440 
2441  //u momentum advective flux
2442  mom_u_adv[k*2+0]=u[k]*u[k];
2443  mom_u_adv[k*2+1]=u[k]*v[k];
2444 
2445  dmom_u_adv_u[k*2+0]=2.0*u[k];
2446  dmom_u_adv_u[k*2+1]=v[k];
2447 
2448  dmom_u_adv_v[k*2+1]=u[k];
2449 
2450  //v momentum advective_flux
2451  mom_v_adv[k*2+0]=v[k]*u[k];
2452  mom_v_adv[k*2+1]=v[k]*v[k];
2453 
2454  dmom_v_adv_u[k*2+0]=v[k];
2455 
2456  dmom_v_adv_v[k*2+0]=u[k];
2457  dmom_v_adv_v[k*2+1]=2.0*v[k];
2458 
2459  //u momentum diffusion tensor
2460  mom_u_diff_ten[k*4+0] = nu;
2461  mom_u_diff_ten[k*4+3] = nu;
2462 
2463  //v momentum diffusion tensor
2464  mom_v_diff_ten[k*4+0] = nu;
2465  mom_v_diff_ten[k*4+3] = nu;
2466 
2467  //momentum sources
2468  mom_u_source[k] = -g[0];
2469  mom_v_source[k] = -g[1];
2470 
2471  //u momentum Hamiltonian (pressure)
2472  mom_u_ham[k] = grad_p[k*2+0]/rho;
2473  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2474 
2475  //v momentum Hamiltonian (pressure)
2476  mom_v_ham[k] = grad_p[k*2+1]/rho;
2477  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2478  }
2479 }
2480 
2482  const double eps_rho,
2483  const double eps_mu,
2484  const double sigma,
2485  const double rho_0,
2486  const double nu_0,
2487  const double rho_1,
2488  const double nu_1,
2489  const double* g,
2490  const double* phi,
2491  const double* n,
2492  const double* kappa,
2493  const double *p,
2494  const double *grad_p,
2495  const double *u,
2496  const double *v,
2497  double *mom_u_acc,
2498  double *dmom_u_acc_u,
2499  double *mom_v_acc,
2500  double *dmom_v_acc_v,
2501  double *mass_adv,
2502  double *dmass_adv_u,
2503  double *dmass_adv_v,
2504  double *mom_u_adv,
2505  double *dmom_u_adv_u,
2506  double *dmom_u_adv_v,
2507  double *mom_v_adv,
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,
2516  double *mom_u_ham,
2517  double *dmom_u_ham_grad_p,
2518  double *mom_v_ham,
2519  double *dmom_v_ham_grad_p)
2520 {
2521  int k;
2522  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
2523  for (k=0;k<nPoints;k++)
2524  {
2526  H_rho = smoothedHeaviside(eps_rho,phi[k]);
2527  d_rho = smoothedDirac(eps_rho,phi[k]);
2528  H_mu = smoothedHeaviside(eps_mu,phi[k]);
2529  d_mu = smoothedDirac(eps_mu,phi[k]);
2530 
2531  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
2532  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
2533  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
2534 
2535 /* //u momentum accumulation */
2536 /* mom_u_acc[k]=rho*u[k]; */
2537 /* dmom_u_acc_u[k]=rho; */
2538 
2539 /* //v momentum accumulation */
2540 /* mom_v_acc[k]=rho*v[k]; */
2541 /* dmom_v_acc_v[k]=rho; */
2542 
2543 /* //mass advective flux */
2544 /* mass_adv[k*2+0]=u[k]; */
2545 /* mass_adv[k*2+1]=v[k]; */
2546 
2547 /* dmass_adv_u[k*2+0]=1.0; */
2548 /* dmass_adv_v[k*2+1]=1.0; */
2549 
2550 /* //u momentum advective flux */
2551 /* mom_u_adv[k*2+0]=rho*u[k]*u[k]; */
2552 /* mom_u_adv[k*2+1]=rho*u[k]*v[k]; */
2553 
2554 /* dmom_u_adv_u[k*2+0]=2.0*rho*u[k]; */
2555 /* dmom_u_adv_u[k*2+1]=rho*v[k]; */
2556 
2557 /* dmom_u_adv_v[k*2+1]=rho*u[k]; */
2558 
2559 /* //v momentum advective_flux */
2560 /* mom_v_adv[k*2+0]=rho*v[k]*u[k]; */
2561 /* mom_v_adv[k*2+1]=rho*v[k]*v[k]; */
2562 
2563 /* dmom_v_adv_u[k*2+0]=rho*v[k]; */
2564 
2565 /* dmom_v_adv_v[k*2+0]=rho*u[k]; */
2566 /* dmom_v_adv_v[k*2+1]=2.0*rho*v[k]; */
2567 
2568 /* #ifdef SCALAR_DIFFUSION */
2569 /* //u momentum diffusion tensor */
2570 /* mom_u_diff_ten[k*4+0] = mu; */
2571 /* mom_u_diff_ten[k*4+3] = mu; */
2572 
2573 /* //v momentum diffusion tensor */
2574 /* mom_v_diff_ten[k*4+0] = mu; */
2575 /* mom_v_diff_ten[k*4+3] = mu; */
2576 /* #else */
2577 /* //u momentum diffusion tensor */
2578 /* mom_u_diff_ten[k*4+0] = 2.0*mu; */
2579 /* mom_u_diff_ten[k*4+3] = mu; */
2580 /* mom_uv_diff_ten[k*4+2]=mu; */
2581 
2582 /* //v momentum diffusion tensor */
2583 /* mom_v_diff_ten[k*4+0] = mu; */
2584 /* mom_v_diff_ten[k*4+3] = 2.0*mu; */
2585 /* mom_vu_diff_ten[k*4+1] = mu; */
2586 /* #endif */
2587 
2588 /* //momentum sources */
2589 /* norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]); */
2590 /* if (norm_n < 1.0e-8) */
2591 /* norm_n = 1.0e-8; */
2592 /* mom_u_source[k] = -rho*g[0] - d_mu*sigma*kappa[k]*n[k*2+0]/(norm_n); */
2593 /* mom_v_source[k] = -rho*g[1] - d_mu*sigma*kappa[k]*n[k*2+1]/(norm_n); */
2594 
2595 /* //u momentum Hamiltonian (pressure) */
2596 
2597 /* mom_u_ham[k] = grad_p[k*2+0]; */
2598 /* dmom_u_ham_grad_p[k*2+0]=1.0; */
2599 
2600 /* //v momentum Hamiltonian (pressure) */
2601 /* mom_v_ham[k] = grad_p[k*2+1]; */
2602 /* dmom_v_ham_grad_p[k*21]=1.0; */
2603 
2604  //cek incomp form
2605  //u momentum accumulation
2606  mom_u_acc[k]=u[k];
2607  dmom_u_acc_u[k]=1.0;
2608 
2609  //v momentum accumulation
2610  mom_v_acc[k]=v[k];
2611  dmom_v_acc_v[k]=1.0;
2612 
2613  //mass advective flux
2614  mass_adv[k*2+0]=u[k];
2615  mass_adv[k*2+1]=v[k];
2616 
2617  dmass_adv_u[k*2+0]=1.0;
2618  dmass_adv_v[k*2+1]=1.0;
2619 
2620  //u momentum advective flux
2621  mom_u_adv[k*2+0]=u[k]*u[k];
2622  mom_u_adv[k*2+1]=u[k]*v[k];
2623 
2624  dmom_u_adv_u[k*2+0]=2.0*u[k];
2625  dmom_u_adv_u[k*2+1]=v[k];
2626 
2627  dmom_u_adv_v[k*2+1]=u[k];
2628 
2629  //v momentum advective_flux
2630  mom_v_adv[k*2+0]=v[k]*u[k];
2631  mom_v_adv[k*2+1]=v[k]*v[k];
2632 
2633  dmom_v_adv_u[k*2+0]=v[k];
2634 
2635  dmom_v_adv_v[k*2+0]=u[k];
2636  dmom_v_adv_v[k*2+1]=2.0*v[k];
2637 
2638 #ifdef SCALAR_DIFFUSION
2639  //u momentum diffusion tensor
2640  mom_u_diff_ten[k*4+0] = nu;
2641  mom_u_diff_ten[k*4+3] = nu;
2642 
2643  //v momentum diffusion tensor
2644  mom_v_diff_ten[k*4+0] = nu;
2645  mom_v_diff_ten[k*4+3] = nu;
2646 #else
2647  //u momentum diffusion tensor
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;
2651 
2652  //v momentum diffusion tensor
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;
2656 #endif
2657 
2658  //momentum sources
2659 /* mom_u_source[k] = -g[0]; */
2660 /* mom_v_source[k] = -g[1]; */
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));
2664 
2665  //u momentum Hamiltonian (pressure)
2666 
2667  mom_u_ham[k] = grad_p[k*2+0]/rho;
2668  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2669 
2670  //v momentum Hamiltonian (pressure)
2671  mom_v_ham[k] = grad_p[k*2+1]/rho;
2672  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2673  }
2674 }
2675 
2676 
2678  const double eps_rho,
2679  const double eps_mu,
2680  const double sigma,
2681  const double rho_0,
2682  const double nu_0,
2683  const double rho_1,
2684  const double nu_1,
2685  const double* g,
2686  const double* phi,
2687  const double* n,
2688  const double* kappa,
2689  const double *p,
2690  const double *grad_p,
2691  const double *u,
2692  const double *v,
2693  double *mom_u_acc,
2694  double *dmom_u_acc_u,
2695  double *mom_v_acc,
2696  double *dmom_v_acc_v,
2697  double *mass_adv,
2698  double *dmass_adv_u,
2699  double *dmass_adv_v,
2700  double *mom_u_adv,
2701  double *dmom_u_adv_u,
2702  double *dmom_u_adv_v,
2703  double *mom_v_adv,
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,
2712  double *mom_u_ham,
2713  double *dmom_u_ham_grad_p,
2714  double *mom_v_ham,
2715  double *dmom_v_ham_grad_p)
2716 {
2717  int k;
2718  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
2719  for (k=0;k<nPoints;k++)
2720  {
2722  H_rho = smoothedHeaviside(eps_rho,phi[k]);
2723  d_rho = smoothedDirac(eps_rho,phi[k]);
2724  H_mu = smoothedHeaviside(eps_mu,phi[k]);
2725  d_mu = smoothedDirac(eps_mu,phi[k]);
2726 
2727  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
2728  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
2729  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
2730 
2731  //u momentum accumulation
2732  mom_u_acc[k]=u[k];
2733  dmom_u_acc_u[k]=1.0;
2734 
2735  //v momentum accumulation
2736  mom_v_acc[k]=v[k];
2737  dmom_v_acc_v[k]=1.0;
2738 
2739  //mass advective flux
2740  mass_adv[k*2+0]=u[k];
2741  mass_adv[k*2+1]=v[k];
2742 
2743  dmass_adv_u[k*2+0]=1.0;
2744  dmass_adv_v[k*2+1]=1.0;
2745 
2746  //u momentum advective flux
2747  mom_u_adv[k*2+0]=u[k]*u[k];
2748  mom_u_adv[k*2+1]=u[k]*v[k];
2749 
2750  dmom_u_adv_u[k*2+0]=2.0*u[k];
2751  dmom_u_adv_u[k*2+1]=v[k];
2752 
2753  dmom_u_adv_v[k*2+1]=u[k];
2754 
2755  //v momentum advective_flux
2756  mom_v_adv[k*2+0]=v[k]*u[k];
2757  mom_v_adv[k*2+1]=v[k]*v[k];
2758 
2759  dmom_v_adv_u[k*2+0]=v[k];
2760 
2761  dmom_v_adv_v[k*2+0]=u[k];
2762  dmom_v_adv_v[k*2+1]=2.0*v[k];
2763 
2764  //u momentum diffusion tensor
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;
2768 
2769  //v momentum diffusion tensor
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;
2773 
2774  //momentum sources
2775  /* printf("rho = %.2f\n",rho); */
2776  /* printf("mom_u_source = %f\n",mom_u_source[k]); */
2777  /* printf("mom_v_source = %f\n",mom_u_source[k]); */
2778  /* printf("d_mu = %f\n" , d_mu); */
2779  /* printf("sigma = %f\n " , sigma); */
2780 
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));
2784  //u momentum Hamiltonian (pressure)
2785 
2786  mom_u_ham[k] = grad_p[k*2+0]/rho;
2787  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
2788 
2789  //v momentum Hamiltonian (pressure)
2790  mom_v_ham[k] = grad_p[k*2+1]/rho;
2791  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
2792 
2793  /* //compressible form */
2794  /* //u momentum accumulation */
2795  /* mom_u_acc[k]=rho*u[k]; */
2796  /* dmom_u_acc_u[k]=rho; */
2797 
2798  /* //v momentum accumulation */
2799  /* mom_v_acc[k]=rho*v[k]; */
2800  /* dmom_v_acc_v[k]=rho; */
2801 
2802  /* //mass advective flux */
2803  /* mass_adv[k*2+0]=u[k]; */
2804  /* mass_adv[k*2+1]=v[k]; */
2805 
2806  /* dmass_adv_u[k*2+0]=1.0; */
2807  /* dmass_adv_v[k*2+1]=1.0; */
2808 
2809  /* //u momentum advective flux */
2810  /* mom_u_adv[k*2+0]=rho*u[k]*u[k]; */
2811  /* mom_u_adv[k*2+1]=rho*u[k]*v[k]; */
2812 
2813  /* dmom_u_adv_u[k*2+0]=rho*2.0*u[k]; */
2814  /* dmom_u_adv_u[k*2+1]=rho*v[k]; */
2815 
2816  /* dmom_u_adv_v[k*2+1]=rho*u[k]; */
2817 
2818  /* //v momentum advective_flux */
2819  /* mom_v_adv[k*2+0]=rho*v[k]*u[k]; */
2820  /* mom_v_adv[k*2+1]=rho*v[k]*v[k]; */
2821 
2822  /* dmom_v_adv_u[k*2+0]=rho*v[k]; */
2823 
2824  /* dmom_v_adv_v[k*2+0]=rho*u[k]; */
2825  /* dmom_v_adv_v[k*2+1]=rho*2.0*v[k]; */
2826 
2827  /* //u momentum diffusion tensor */
2828  /* mom_u_diff_ten[k*2+0] = 2.0*mu; */
2829  /* mom_u_diff_ten[k*2+1] = mu; */
2830  /* mom_uv_diff_ten[k]=mu; */
2831 
2832  /* //v momentum diffusion tensor */
2833  /* mom_v_diff_ten[k*2+0] = mu; */
2834  /* mom_v_diff_ten[k*2+1] = 2.0*mu; */
2835  /* mom_vu_diff_ten[k] = mu; */
2836 
2837  /* //momentum sources */
2838  /* norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]); */
2839  /* mom_u_source[k] = -rho*g[0] - d_mu*sigma*kappa[k]*n[k*2+0]/(norm_n+1.0e-8); */
2840  /* mom_v_source[k] = -rho*g[1] - d_mu*sigma*kappa[k]*n[k*2+1]/(norm_n+1.0e-8); */
2841 
2842  /* //u momentum Hamiltonian (pressure) */
2843 
2844  /* mom_u_ham[k] = grad_p[k*2+0]; */
2845  /* dmom_u_ham_grad_p[k*2+0]=1.0; */
2846 
2847  /* //v momentum Hamiltonian (pressure) */
2848  /* mom_v_ham[k] = grad_p[k*2+1]; */
2849  /* dmom_v_ham_grad_p[k*2+1]=1.0; */
2850  }
2851 }
2852 
2854  const double eps_rho,
2855  const double eps_mu,
2856  const double sigma,
2857  const double rho_0,
2858  const double nu_0,
2859  const double rho_1,
2860  const double nu_1,
2861  const double rho_s,
2862  const double nu_s,
2863  const double* g,
2864  const double* phi,
2865  const double* n,
2866  const double* kappa,
2867  const double* phi_s,
2868  const double* n_s,
2869  const double *p,
2870  const double *grad_p,
2871  const double *u,
2872  const double *v,
2873  double *mom_u_acc,
2874  double *dmom_u_acc_u,
2875  double *mom_v_acc,
2876  double *dmom_v_acc_v,
2877  double *mass_adv,
2878  double *dmass_adv_u,
2879  double *dmass_adv_v,
2880  double *mom_u_adv,
2881  double *dmom_u_adv_u,
2882  double *dmom_u_adv_v,
2883  double *mom_v_adv,
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,
2896  double *mom_u_ham,
2897  double *dmom_u_ham_grad_p,
2898  double *mom_v_ham,
2899  double *dmom_v_ham_grad_p)
2900 {
2901  int k;
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++)
2905  {
2907  H_rho = smoothedHeaviside(eps_rho,phi[k]);
2908  d_rho = smoothedDirac(eps_rho,phi[k]);
2909  H_mu = smoothedHeaviside(eps_mu,phi[k]);
2910  d_mu = smoothedDirac(eps_mu,phi[k]);
2911 
2912  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
2913  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
2914  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
2915  rho = rho_0;
2916  nu = nu_0;
2917  mu = rho_0*nu_0;
2918 
2919 /* H_rho_s = smoothedHeaviside(eps_rho,phi_s[k]); */
2920 /* d_rho_s = smoothedDirac(eps_rho,phi_s[k]); */
2921 /* H_mu_s = smoothedHeaviside(eps_mu,phi_s[k]); */
2922 /* d_mu_s = smoothedDirac(eps_mu,phi_s[k]); */
2923 
2924 /* rho = rho_s*(1.0-H_rho_s)+rho*H_rho_s; */
2925 /* nu = nu_s*(1.0-H_mu_s)+nu*H_mu_s; */
2926 /* mu = rho_s*nu_s*(1.0-H_mu_s)+rho*nu*H_mu_s; */
2927 
2928  //u momentum accumulation
2929  mom_u_acc[k]=rho*u[k];
2930  dmom_u_acc_u[k]=rho;
2931 
2932  //v momentum accumulation
2933  mom_v_acc[k]=rho*v[k];
2934  dmom_v_acc_v[k]=rho;
2935 
2936  //mass advective flux
2937  mass_adv[k*2+0]=u[k];
2938  mass_adv[k*2+1]=v[k];
2939 
2940  dmass_adv_u[k*2+0]=1.0;
2941  dmass_adv_v[k*2+1]=1.0;
2942 
2943  //u momentum advective flux
2944  mom_u_adv[k*2+0]=rho*u[k]*u[k];
2945  mom_u_adv[k*2+1]=rho*u[k]*v[k];
2946 
2947  dmom_u_adv_u[k*2+0]=2.0*rho*u[k];
2948  dmom_u_adv_u[k*2+1]=rho*v[k];
2949 
2950  dmom_u_adv_v[k*2+1]=rho*u[k];
2951 
2952  //v momentum advective_flux
2953  mom_v_adv[k*2+0]=rho*v[k]*u[k];
2954  mom_v_adv[k*2+1]=rho*v[k]*v[k];
2955 
2956  dmom_v_adv_u[k*2+0]=rho*v[k];
2957 
2958  dmom_v_adv_v[k*2+0]=rho*u[k];
2959  dmom_v_adv_v[k*2+1]=2.0*rho*v[k];
2960 
2961  //u momentum diffusion tensor
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;
2965 
2966  //v momentum diffusion tensor
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;
2970 
2971  //momentum sources
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]);
2974 
2975 /* mom_u_source[k] = -rho*g[0] */
2976 /* - d_mu*sigma*kappa[k]*n[k*2+0]/norm_n */
2977 /* +rho*d_mu_s*(u[k]*u[k]*n_s[k*2+0] + u[k]*v[k]*n_s[k*2+1])/norm_n_s */
2978 /* +rho*(1.0-H_mu_s)*u[k]; */
2979 /* dmom_u_source_u[k] = rho*d_mu_s*(2.0*u[k]*n_s[k*2+0] */
2980 /* + v[k]*n_s[k*2+1])/norm_n_s */
2981 /* +rho*(1.0-H_mu_s); */
2982 /* dmom_u_source_v[k] = rho*d_mu_s*u[k]*n_s[k*2+1]/norm_n_s; */
2983 
2984 /* mom_v_source[k] = -rho*g[1] */
2985 /* - d_mu*sigma*kappa[k]*n[k*2+1]/norm_n */
2986 /* +rho*d_mu_s*(v[k]*u[k]*n_s[k*2+0] */
2987 /* + v[k]*v[k]*n_s[k*2+1])/norm_n_s */
2988 /* +rho*(1.0-H_mu_s)*v[k]; */
2989 /* dmom_v_source_u[k] = rho*d_mu_s*v[k]*n_s[k*2+0]/norm_n_s; */
2990 /* dmom_v_source_v[k] = rho*d_mu_s*(u[k]*n_s[k*2+0] */
2991 /* + 2.0*v[k]*n_s[k*2+1])/norm_n_s */
2992 /* +rho*(1.0-H_mu_s); */
2993 
2994  /* mom_u_source[k] = -rho*g[0] */
2995  /* - d_mu*sigma*kappa[k]*n[k*2+0]/norm_n */
2996  /* +rho*2.0*(1.0-H_mu_s)*u[k]; */
2997  /* dmom_u_source_u[k] = rho*2.0*(1.0-H_mu_s); */
2998  /* dmom_u_source_v[k] = 0.0; */
2999 
3000  /* mom_v_source[k] = -rho*g[1] */
3001  /* - d_mu*sigma*kappa[k]*n[k*2+1]/norm_n */
3002  /* +rho*2.0*(1.0-H_mu_s)*v[k]; */
3003  /* dmom_v_source_u[k] = 0.0; */
3004  /* dmom_v_source_v[k] = rho*2.0*(1.0-H_mu_s); */
3005 
3006  /* mom_u_source[k] = -rho*g[0] */
3007  /* - d_mu*sigma*kappa[k]*n[k*2+0]/norm_n */
3008  /* - rho*d_mu_s*(u[k]*u[k]*n_s[k*2+0] + u[k]*v[k]*n_s[k*2+1])/norm_n_s; */
3009 
3010  /* dmom_u_source_u[k] = -rho*d_mu_s*(2.0*u[k]*n_s[k*2+0] */
3011  /* + v[k]*n_s[k*2+1])/norm_n_s; */
3012 
3013  /* dmom_u_source_v[k] = -rho*d_mu_s*u[k]*n_s[k*2+1]/norm_n_s; */
3014 
3015  /* mom_v_source[k] = -rho*g[1] */
3016  /* - d_mu*sigma*kappa[k]*n[k*2+1]/norm_n */
3017  /* - rho*d_mu_s*(v[k]*u[k]*n_s[k*2+0] */
3018  /* + v[k]*v[k]*n_s[k*2+1])/norm_n_s; */
3019 
3020  /* dmom_v_source_u[k] = -rho*d_mu_s*v[k]*n_s[k*2+0]/norm_n_s; */
3021  /* dmom_v_source_v[k] = -rho*d_mu_s*(u[k]*n_s[k*2+0] */
3022  /* + 2.0*v[k]*n_s[k*2+1])/norm_n_s; */
3023 
3024  /* mom_u_source[k] = -rho*g[0] +(1.0-H_mu_s)*u[k]; */
3025  /* dmom_u_source_u[k] = (1.0-H_mu_s); */
3026  /* dmom_u_source_v[k] = 0.0; */
3027 
3028  /* mom_v_source[k] = -rho*g[1] +(1.0-H_mu_s)*v[k]; */
3029  /* dmom_v_source_u[k] = 0.0; */
3030  /* dmom_v_source_v[k] = (1.0-H_mu_s); */
3031  mom_u_source[k] = -rho*g[0];
3032  dmom_u_source_u[k] = 0.0;
3033  dmom_u_source_v[k] = 0.0;
3034 
3035  mom_v_source[k] = -rho*g[1];
3036  dmom_v_source_u[k] = 0.0;
3037  dmom_v_source_v[k] = 0.0;
3038 
3039  //u momentum Hamiltonian (pressure)
3040 
3041  mom_u_ham[k] = grad_p[k*2+0];
3042  dmom_u_ham_grad_p[k*2+0]=1.0;
3043 
3044  //v momentum Hamiltonian (pressure)
3045  mom_v_ham[k] = grad_p[k*2+1];
3046  dmom_v_ham_grad_p[k*2+1]=1.0;
3047  }
3048 }
3049 
3051  const double boundaryPenaltyCoef,
3052  const double volumePenaltyCoef,
3053  const double eps_rho,
3054  const double eps_mu,
3055  const double sigma,
3056  const double rho_0,
3057  const double nu_0,
3058  const double rho_1,
3059  const double nu_1,
3060  const double rho_s,
3061  const double nu_s,
3062  const double* g,
3063  const double* phi,
3064  const double* n,
3065  const double* kappa,
3066  const double* phi_s,
3067  const double* n_s,
3068  const double *p,
3069  const double *grad_p,
3070  const double *u,
3071  const double *v,
3072  double *mom_u_acc,
3073  double *dmom_u_acc_u,
3074  double *mom_v_acc,
3075  double *dmom_v_acc_v,
3076  double *mass_adv,
3077  double *dmass_adv_u,
3078  double *dmass_adv_v,
3079  double *mom_u_adv,
3080  double *dmom_u_adv_u,
3081  double *dmom_u_adv_v,
3082  double *mom_v_adv,
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,
3095  double *mom_u_ham,
3096  double *dmom_u_ham_grad_p,
3097  double *mom_v_ham,
3098  double *dmom_v_ham_grad_p)
3099 {
3100  int k;
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);
3105  //sp=0.0;
3106  for (k=0;k<nPoints;k++)
3107  {
3109  H_rho = smoothedHeaviside(eps_rho,phi[k]);
3110  d_rho = smoothedDirac(eps_rho,phi[k]);
3111  H_mu = smoothedHeaviside(eps_mu,phi[k]);
3112  d_mu = smoothedDirac(eps_mu,phi[k]);
3113 
3114  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
3115  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
3116  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
3117 
3118  H_rho_s = smoothedHeaviside(eps_rho,phi_s[k]);
3119  d_rho_s = smoothedDirac(eps_rho,phi_s[k]);
3120  H_mu_s = smoothedHeaviside(eps_mu,phi_s[k]);
3121  d_mu_s = smoothedDirac(eps_mu,phi_s[k]);
3122 
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]);
3125 
3126  //mwf start hacking here ...
3127  //make coefficients just be fluid values first?
3128  /* rho = rho_s*(1.0-H_rho_s)+rho*H_rho_s; */
3129  /* nu = nu_s*(1.0-H_mu_s)+nu*H_mu_s; */
3130  /* mu = rho_s*nu_s*(1.0-H_mu_s)+rho*nu*H_mu_s; */
3131 
3132  //u momentum accumulation
3133  mom_u_acc[k]=H_mu_s*rho*u[k];
3134  dmom_u_acc_u[k]=H_mu_s*rho;
3135 
3136  //v momentum accumulation
3137  mom_v_acc[k]=H_mu_s*rho*v[k];
3138  dmom_v_acc_v[k]=H_mu_s*rho;
3139 
3140  //mwf volume conservation holds in both solid and fluid
3141  //mass advective flux
3142  mass_adv[k*2+0]=u[k];
3143  mass_adv[k*2+1]=v[k];
3144 
3145  dmass_adv_u[k*2+0]=1.0;
3146  dmass_adv_v[k*2+1]=1.0;
3147 
3148  //mwf continue killing acceleration in solid phase
3149  //u momentum advective flux
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;
3152 
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;
3155 
3156  dmom_u_adv_v[k*2+1]=H_mu_s*rho*u[k];
3157 
3158  //v momentum advective_flux
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;
3161 
3162  dmom_v_adv_u[k*2+0]=H_mu_s*rho*v[k];
3163 
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;
3166 
3167  //mwf no diffusion of momentum in solid phase either,
3168  //mwf also need to switch to Laplace form temporarily because of bc's?
3169  //u momentum diffusion tensor
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;
3173 
3174  //v momentum diffusion tensor
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;
3178 /* //u momentum diffusion tensor */
3179 /* mom_u_diff_ten[k*4+0] = H_mu_s*mu; */
3180 /* mom_u_diff_ten[k*4+3] = H_mu_s*mu; */
3181 /* mom_uv_diff_ten[k*4+2]= 0.0; */
3182 
3183 /* //v momentum diffusion tensor */
3184 /* mom_v_diff_ten[k*4+0] = H_mu_s*mu; */
3185 /* mom_v_diff_ten[k*4+3] = H_mu_s*mu; */
3186 /* mom_vu_diff_ten[k*4+1] = 0.0; */
3187 
3188  //momentum sources
3189 
3190  //mwf momentum in solid phase is just \grad p = 0 (i.e. pressure is constant) with penalties to enforce
3191  //mwf velocity is equal to input (v^s = 0 for now) on boundary and in solid region
3192  if (quadraticPenalty)
3193  {
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);
3198 
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;
3202 
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);
3207 
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);
3211  }
3212  else if (sipgPenalty)
3213  {
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);
3217 
3218  dmom_u_source_u[k] = volumePenaltyCoef*rho*(1.0-H_mu_s);
3219  dmom_u_source_v[k] = 0.0;
3220 
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);
3224 
3225  dmom_v_source_u[k] = 0.0;
3226  dmom_v_source_v[k] = volumePenaltyCoef*rho*(1.0-H_mu_s);
3227 
3228  volumeFlux = u[k]*n_s[k*2+0] + v[k]*n_s[k*2+1];
3229  if (volumeFlux < 0.0)
3230  {
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;
3232 
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;
3235 
3236  dmom_u_source_v[k] = rho*d_mu_s*u[k]*n_s[k*2+1]/norm_n_s;
3237 
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;
3240 
3241  dmom_v_source_u[k] += rho*d_mu_s*v[k]*n_s[k*2+0]/norm_n_s;
3242 
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;
3245  }
3246  }
3247  else
3248  {
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);
3253 
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;
3257 
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);
3262 
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);
3266 
3267  }
3268  //mwf include grad_p term in solid phase to enforce p = constant (or integral around boundary is zero?)
3269  //u momentum Hamiltonian (pressure)
3270  mom_u_ham[k] = grad_p[k*2+0];
3271  dmom_u_ham_grad_p[k*2+0]=1.0;
3272 
3273  //v momentum Hamiltonian (pressure)
3274  mom_v_ham[k] = grad_p[k*2+1];
3275  dmom_v_ham_grad_p[k*2+1]=1.0;
3276  }
3277 }
3278 
3280  const double eps_rho,
3281  const double eps_mu,
3282  const double sigma,
3283  const double rho_0,
3284  const double nu_0,
3285  const double rho_1,
3286  const double nu_1,
3287  const double* g,
3288  const double* phi,
3289  const double* n,
3290  const double* kappa,
3291  const double *p,
3292  const double *grad_p,
3293  const double *u,
3294  const double *v,
3295  const double *w,
3296  double *mom_u_acc,
3297  double *dmom_u_acc_u,
3298  double *mom_v_acc,
3299  double *dmom_v_acc_v,
3300  double *mom_w_acc,
3301  double *dmom_w_acc_w,
3302  double *mass_adv,
3303  double *dmass_adv_u,
3304  double *dmass_adv_v,
3305  double *dmass_adv_w,
3306  double *mom_u_adv,
3307  double *dmom_u_adv_u,
3308  double *dmom_u_adv_v,
3309  double *dmom_u_adv_w,
3310  double *mom_v_adv,
3311  double *dmom_v_adv_u,
3312  double *dmom_v_adv_v,
3313  double *dmom_v_adv_w,
3314  double *mom_w_adv,
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,
3330  double *mom_u_ham,
3331  double *dmom_u_ham_grad_p,
3332  double *mom_v_ham,
3333  double *dmom_v_ham_grad_p,
3334  double *mom_w_ham,
3335  double *dmom_w_ham_grad_p)
3336 {
3337  int k;
3338  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
3339  for (k=0;k<nPoints;k++)
3340  {
3342  /*H = smoothedHeaviside(eps,phi[k]);*/
3343  H_rho = smoothedHeaviside(eps_rho,phi[k]);
3344  d_rho = smoothedDirac(eps_rho,phi[k]);
3345  H_mu = smoothedHeaviside(eps_mu,phi[k]);
3346  d_mu = smoothedDirac(eps_mu,phi[k]);
3347 
3348  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
3349  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
3350  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
3351 
3352 /* //u momentum accumulation */
3353 /* mom_u_acc[k]=rho*u[k]; */
3354 /* dmom_u_acc_u[k]=rho; */
3355 
3356 /* //v momentum accumulation */
3357 /* mom_v_acc[k]=rho*v[k]; */
3358 /* dmom_v_acc_v[k]=rho; */
3359 
3360 /* //w momentum accumulation */
3361 /* mom_w_acc[k]=rho*w[k]; */
3362 /* dmom_w_acc_w[k]=rho; */
3363 
3364 
3365 /* //mass advective flux */
3366 /* mass_adv[k*3+0]=u[k]; */
3367 /* mass_adv[k*3+1]=v[k]; */
3368 /* mass_adv[k*3+2]=w[k]; */
3369 
3370 /* dmass_adv_u[k*3+0]=1.0; */
3371 /* dmass_adv_v[k*3+1]=1.0; */
3372 /* dmass_adv_w[k*3+2]=1.0; */
3373 
3374 /* //u momentum advective flux */
3375 /* mom_u_adv[k*3+0]=rho*u[k]*u[k]; */
3376 /* mom_u_adv[k*3+1]=rho*u[k]*v[k]; */
3377 /* mom_u_adv[k*3+2]=rho*u[k]*w[k]; */
3378 
3379 /* dmom_u_adv_u[k*3+0]=2.0*rho*u[k]; */
3380 /* dmom_u_adv_u[k*3+1]=rho*v[k]; */
3381 /* dmom_u_adv_u[k*3+2]=rho*w[k]; */
3382 
3383 /* dmom_u_adv_v[k*3+1]=rho*u[k]; */
3384 
3385 /* dmom_u_adv_w[k*3+2]=rho*u[k]; */
3386 
3387 /* //v momentum advective_flux */
3388 /* mom_v_adv[k*3+0]=rho*v[k]*u[k]; */
3389 /* mom_v_adv[k*3+1]=rho*v[k]*v[k]; */
3390 /* mom_v_adv[k*3+2]=rho*v[k]*w[k]; */
3391 
3392 /* dmom_v_adv_u[k*3+0]=rho*v[k]; */
3393 
3394 /* dmom_v_adv_w[k*3+2]=rho*v[k]; */
3395 
3396 /* dmom_v_adv_v[k*3+0]=rho*u[k]; */
3397 /* dmom_v_adv_v[k*3+1]=2.0*rho*v[k]; */
3398 /* dmom_v_adv_v[k*3+2]=rho*w[k]; */
3399 
3400 /* //w momentum advective_flux */
3401 /* mom_w_adv[k*3+0]=rho*w[k]*u[k]; */
3402 /* mom_w_adv[k*3+1]=rho*w[k]*v[k]; */
3403 /* mom_w_adv[k*3+2]=rho*w[k]*w[k]; */
3404 
3405 /* dmom_w_adv_u[k*3+0]=rho*w[k]; */
3406 
3407 /* dmom_w_adv_v[k*3+1]=rho*w[k]; */
3408 
3409 /* dmom_w_adv_w[k*3+0]=rho*u[k]; */
3410 /* dmom_w_adv_w[k*3+1]=rho*v[k]; */
3411 /* dmom_w_adv_w[k*3+2]=2.0*rho*w[k]; */
3412 
3413 /* //u momentum diffusion tensor */
3414 /* mom_u_diff_ten[k*9+0] = 2.0*mu; */
3415 /* mom_u_diff_ten[k*9+4] = mu; */
3416 /* mom_u_diff_ten[k*9+8] = mu; */
3417 
3418 /* mom_uv_diff_ten[k*9+3]=mu; */
3419 
3420 /* mom_uw_diff_ten[k*9+6]=mu; */
3421 
3422 /* //v momentum diffusion tensor */
3423 /* mom_v_diff_ten[k*9+0] = mu; */
3424 /* mom_v_diff_ten[k*9+4] = 2.0*mu; */
3425 /* mom_v_diff_ten[k*9+8] = mu; */
3426 
3427 /* mom_vu_diff_ten[k*9+1]=mu; */
3428 
3429 /* mom_vw_diff_ten[k*9+7]=mu; */
3430 
3431 /* //w momentum diffusion tensor */
3432 /* mom_w_diff_ten[k*9+0] = mu; */
3433 /* mom_w_diff_ten[k*9+4] = mu; */
3434 /* mom_w_diff_ten[k*9+8] = 2.0*mu; */
3435 
3436 /* mom_wu_diff_ten[k*9+2]=mu; */
3437 
3438 /* mom_wv_diff_ten[k*9+5]=mu; */
3439 
3440 /* //momentum sources */
3441 /* 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]); */
3442 /* mom_u_source[k] = -rho*g[0] - d_mu*sigma*kappa[k]*n[k*3+0]/(norm_n); */
3443 /* mom_v_source[k] = -rho*g[1] - d_mu*sigma*kappa[k]*n[k*3+1]/(norm_n); */
3444 /* mom_w_source[k] = -rho*g[2] - d_mu*sigma*kappa[k]*n[k*3+2]/(norm_n); */
3445 
3446 
3447 /* //u momentum Hamiltonian (pressure) */
3448 /* mom_u_ham[k] = grad_p[k*3+0]; */
3449 /* dmom_u_ham_grad_p[k*3+0]=1.0; */
3450 
3451 /* //v momentum Hamiltonian (pressure) */
3452 /* mom_v_ham[k] = grad_p[k*3+1]; */
3453 /* dmom_v_ham_grad_p[k*3+1]=1.0; */
3454 
3455 /* //w momentum Hamiltonian (pressure) */
3456 /* mom_w_ham[k] = grad_p[k*3+2]; */
3457 /* dmom_w_ham_grad_p[k*3+2]=1.0; */
3458 
3459  //cek "incompressible" form
3460  //u momentum accumulation
3461  mom_u_acc[k]=u[k];
3462  dmom_u_acc_u[k]=1.0;
3463 
3464  //v momentum accumulation
3465  mom_v_acc[k]=v[k];
3466  dmom_v_acc_v[k]=1.0;
3467 
3468  //w momentum accumulation
3469  mom_w_acc[k]=w[k];
3470  dmom_w_acc_w[k]=1.0;
3471 
3472 
3473  //mass advective flux
3474  mass_adv[k*3+0]=u[k];
3475  mass_adv[k*3+1]=v[k];
3476  mass_adv[k*3+2]=w[k];
3477 
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;
3481 
3482  //u momentum advective flux
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];
3486 
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];
3490 
3491  dmom_u_adv_v[k*3+1]=u[k];
3492 
3493  dmom_u_adv_w[k*3+2]=u[k];
3494 
3495  //v momentum advective_flux
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];
3499 
3500  dmom_v_adv_u[k*3+0]=v[k];
3501 
3502  dmom_v_adv_w[k*3+2]=v[k];
3503 
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];
3507 
3508  //w momentum advective_flux
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];
3512 
3513  dmom_w_adv_u[k*3+0]=w[k];
3514 
3515  dmom_w_adv_v[k*3+1]=w[k];
3516 
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];
3520 
3521  //u momentum diffusion tensor
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;
3525 
3526  mom_uv_diff_ten[k*9+3]=nu;
3527 
3528  mom_uw_diff_ten[k*9+6]=nu;
3529 
3530  //v momentum diffusion tensor
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;
3534 
3535  mom_vu_diff_ten[k*9+1]=nu;
3536 
3537  mom_vw_diff_ten[k*9+7]=nu;
3538 
3539  //w momentum diffusion tensor
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;
3543 
3544  mom_wu_diff_ten[k*9+2]=nu;
3545 
3546  mom_wv_diff_ten[k*9+5]=nu;
3547 
3548  //momentum sources
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));
3553 
3554 
3555  //u momentum Hamiltonian (pressure)
3556  mom_u_ham[k] = grad_p[k*3+0]/rho;
3557  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
3558 
3559  //v momentum Hamiltonian (pressure)
3560  mom_v_ham[k] = grad_p[k*3+1]/rho;
3561  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
3562 
3563  //w momentum Hamiltonian (pressure)
3564  mom_w_ham[k] = grad_p[k*3+2]/rho;
3565  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
3566  }
3567 }
3569  const double eps_rho,
3570  const double eps_mu,
3571  const double sigma,
3572  const double rho_0,
3573  const double nu_0,
3574  const double rho_1,
3575  const double nu_1,
3576  const double* g,
3577  const double* phi,
3578  const double* n,
3579  const double* kappa,
3580  const double *p,
3581  const double *grad_p,
3582  const double *u,
3583  const double *v,
3584  const double *w,
3585  double *mom_u_acc,
3586  double *dmom_u_acc_u,
3587  double *mom_v_acc,
3588  double *dmom_v_acc_v,
3589  double *mom_w_acc,
3590  double *dmom_w_acc_w,
3591  double *mass_adv,
3592  double *dmass_adv_u,
3593  double *dmass_adv_v,
3594  double *dmass_adv_w,
3595  double *mom_u_adv,
3596  double *dmom_u_adv_u,
3597  double *dmom_u_adv_v,
3598  double *dmom_u_adv_w,
3599  double *mom_v_adv,
3600  double *dmom_v_adv_u,
3601  double *dmom_v_adv_v,
3602  double *dmom_v_adv_w,
3603  double *mom_w_adv,
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,
3619  double *mom_u_ham,
3620  double *dmom_u_ham_grad_p,
3621  double *mom_v_ham,
3622  double *dmom_v_ham_grad_p,
3623  double *mom_w_ham,
3624  double *dmom_w_ham_grad_p)
3625 {
3626  int k;
3627  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n;
3628  for (k=0;k<nPoints;k++)
3629  {
3631  /*H = smoothedHeaviside(eps,phi[k]);*/
3632  H_rho = smoothedHeaviside(eps_rho,phi[k]);
3633  d_rho = smoothedDirac(eps_rho,phi[k]);
3634  H_mu = smoothedHeaviside(eps_mu,phi[k]);
3635  d_mu = smoothedDirac(eps_mu,phi[k]);
3636 
3637  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
3638  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
3639  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
3640 
3641  //u momentum accumulation
3642  mom_u_acc[k]=u[k];
3643  dmom_u_acc_u[k]=1.0;
3644 
3645  //v momentum accumulation
3646  mom_v_acc[k]=v[k];
3647  dmom_v_acc_v[k]=1.0;
3648 
3649  //w momentum accumulation
3650  mom_w_acc[k]=w[k];
3651  dmom_w_acc_w[k]=1.0;
3652 
3653 
3654  //mass advective flux
3655  mass_adv[k*3+0]=u[k];
3656  mass_adv[k*3+1]=v[k];
3657  mass_adv[k*3+2]=w[k];
3658 
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;
3662 
3663  //u momentum advective flux
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];
3667 
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];
3671 
3672  dmom_u_adv_v[k*3+1]=u[k];
3673 
3674  dmom_u_adv_w[k*3+2]=u[k];
3675 
3676  //v momentum advective_flux
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];
3680 
3681  dmom_v_adv_u[k*3+0]=v[k];
3682 
3683  dmom_v_adv_w[k*3+2]=v[k];
3684 
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];
3688 
3689  //w momentum advective_flux
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];
3693 
3694  dmom_w_adv_u[k*3+0]=w[k];
3695 
3696  dmom_w_adv_v[k*3+1]=w[k];
3697 
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];
3701 
3702  //u momentum diffusion tensor
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;
3706 
3707  mom_uv_diff_ten[k]=nu;
3708 
3709  mom_uw_diff_ten[k]=nu;
3710 
3711  //v momentum diffusion tensor
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;
3715 
3716  mom_vu_diff_ten[k]=nu;
3717 
3718  mom_vw_diff_ten[k]=nu;
3719 
3720  //w momentum diffusion tensor
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;
3724 
3725  mom_wu_diff_ten[k]=nu;
3726 
3727  mom_wv_diff_ten[k]=nu;
3728 
3729  //momentum sources
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));
3734 
3735 
3736  //u momentum Hamiltonian (pressure)
3737  mom_u_ham[k] = grad_p[k*3+0]/rho;
3738  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
3739 
3740  //v momentum Hamiltonian (pressure)
3741  mom_v_ham[k] = grad_p[k*3+1]/rho;
3742  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
3743 
3744  //w momentum Hamiltonian (pressure)
3745  mom_w_ham[k] = grad_p[k*3+2]/rho;
3746  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
3747  }
3748 }
3750  const double boundaryPenaltyCoef,
3751  const double volumePenaltyCoef,
3752  const double eps_rho,
3753  const double eps_mu,
3754  const double sigma,
3755  const double rho_0,
3756  const double nu_0,
3757  const double rho_1,
3758  const double nu_1,
3759  const double rho_s,
3760  const double nu_s,
3761  const double* g,
3762  const double* phi,
3763  const double* n,
3764  const double* kappa,
3765  const double* phi_s,
3766  const double* n_s,
3767  const double *p,
3768  const double *grad_p,
3769  const double *u,
3770  const double *v,
3771  const double *w,
3772  double *mom_u_acc,
3773  double *dmom_u_acc_u,
3774  double *mom_v_acc,
3775  double *dmom_v_acc_v,
3776  double *mom_w_acc,
3777  double *dmom_w_acc_w,
3778  double *mass_adv,
3779  double *dmass_adv_u,
3780  double *dmass_adv_v,
3781  double *dmass_adv_w,
3782  double *mom_u_adv,
3783  double *dmom_u_adv_u,
3784  double *dmom_u_adv_v,
3785  double *dmom_u_adv_w,
3786  double *mom_v_adv,
3787  double *dmom_v_adv_u,
3788  double *dmom_v_adv_v,
3789  double *dmom_v_adv_w,
3790  double *mom_w_adv,
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,
3815  double *mom_u_ham,
3816  double *dmom_u_ham_grad_p,
3817  double *mom_v_ham,
3818  double *dmom_v_ham_grad_p,
3819  double *mom_w_ham,
3820  double *dmom_w_ham_grad_p)
3821 {
3822  int k;
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;
3825 
3826  for (k=0;k<nPoints;k++)
3827  {
3829  /*H = smoothedHeaviside(eps,phi[k]);*/
3830  H_rho = smoothedHeaviside(eps_rho,phi[k]);
3831  d_rho = smoothedDirac(eps_rho,phi[k]);
3832  H_mu = smoothedHeaviside(eps_mu,phi[k]);
3833  d_mu = smoothedDirac(eps_mu,phi[k]);
3834 
3835  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
3836  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
3837  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
3838 
3839  H_rho_s = smoothedHeaviside(eps_rho,phi_s[k]);
3840  d_rho_s = smoothedDirac(eps_rho,phi_s[k]);
3841  H_mu_s = smoothedHeaviside(eps_mu,phi_s[k]);
3842  d_mu_s = smoothedDirac(eps_mu,phi_s[k]);
3843 
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;
3847 
3848  //u momentum accumulation
3849  mom_u_acc[k]=H_mu_s*rho*u[k];
3850  dmom_u_acc_u[k]=H_mu_s*rho;
3851 
3852  //v momentum accumulation
3853  mom_v_acc[k]=H_mu_s*rho*v[k];
3854  dmom_v_acc_v[k]=H_mu_s*rho;
3855 
3856  //w momentum accumulation
3857  mom_w_acc[k]=H_mu_s*rho*w[k];
3858  dmom_w_acc_w[k]=H_mu_s*rho;
3859 
3860 
3861  //mass advective flux
3862  mass_adv[k*3+0]=u[k];
3863  mass_adv[k*3+1]=v[k];
3864  mass_adv[k*3+2]=w[k];
3865 
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;
3869 
3870  //u momentum advective flux
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];
3874 
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];
3878 
3879  dmom_u_adv_v[k*3+1]=H_mu_s*rho*u[k];
3880 
3881  dmom_u_adv_w[k*3+2]=H_mu_s*rho*u[k];
3882 
3883  //v momentum advective_flux
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];
3887 
3888  dmom_v_adv_u[k*3+0]=H_mu_s*rho*v[k];
3889 
3890  dmom_v_adv_w[k*3+2]=H_mu_s*rho*v[k];
3891 
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];
3895 
3896  //w momentum advective_flux
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];
3900 
3901  dmom_w_adv_u[k*3+0]=H_mu_s*rho*w[k];
3902 
3903  dmom_w_adv_v[k*3+1]=H_mu_s*rho*w[k];
3904 
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];
3908 
3909  //u momentum diffusion tensor
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;
3913 
3914  mom_uv_diff_ten[k*9+3]=H_mu_s*mu;
3915 
3916  mom_uw_diff_ten[k*9+6]=H_mu_s*mu;
3917 
3918  //v momentum diffusion tensor
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;
3922 
3923  mom_vu_diff_ten[k*9+1]=H_mu_s*mu;
3924 
3925  mom_vw_diff_ten[k*9+7]=H_mu_s*mu;
3926 
3927  //w momentum diffusion tensor
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;
3931 
3932  mom_wu_diff_ten[k*9+2]=H_mu_s*mu;
3933 
3934  mom_wv_diff_ten[k*9+5]=H_mu_s*mu;
3935 
3936  //momentum sources
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);
3941 
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;
3946 
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);
3950 
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;
3955 
3956 
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);
3964 
3965 
3966 
3967  //u momentum Hamiltonian (pressure)
3968  mom_u_ham[k] = grad_p[k*3+0];
3969  dmom_u_ham_grad_p[k*3+0]=1.0;
3970 
3971  //v momentum Hamiltonian (pressure)
3972  mom_v_ham[k] = grad_p[k*3+1];
3973  dmom_v_ham_grad_p[k*3+1]=1.0;
3974 
3975  //w momentum Hamiltonian (pressure)
3976  mom_w_ham[k] = grad_p[k*3+2];
3977  dmom_w_ham_grad_p[k*3+2]=1.0;
3978  }
3979 }
3980 
3982  const double eps,
3983  const double rho_0,
3984  const double nu_0,
3985  const double rho_1,
3986  const double nu_1,
3987  const double* g,
3988  const double* phi,
3989  const double *p,
3990  const double *grad_p,
3991  const double *u,
3992  const double *v,
3993  const double *w,
3994  double *mom_u_acc,
3995  double *dmom_u_acc_u,
3996  double *mom_v_acc,
3997  double *dmom_v_acc_v,
3998  double *mom_w_acc,
3999  double *dmom_w_acc_w,
4000  double *mass_adv,
4001  double *dmass_adv_u,
4002  double *dmass_adv_v,
4003  double *dmass_adv_w,
4004  double *mom_u_adv,
4005  double *dmom_u_adv_u,
4006  double *dmom_u_adv_v,
4007  double *dmom_u_adv_w,
4008  double *mom_v_adv,
4009  double *dmom_v_adv_u,
4010  double *dmom_v_adv_v,
4011  double *dmom_v_adv_w,
4012  double *mom_w_adv,
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,
4022  double *mom_u_ham,
4023  double *dmom_u_ham_grad_p,
4024  double *mom_v_ham,
4025  double *dmom_v_ham_grad_p,
4026  double *mom_w_ham,
4027  double *dmom_w_ham_grad_p)
4028 {
4029  int k;
4030  double rho,nu,H;
4031  for (k=0;k<nPoints;k++)
4032  {
4033  H = smoothedHeaviside(eps,phi[k]);
4034  rho = rho_0*(1.0-H)+rho_1*H;
4035  nu = nu_0*(1.0-H)+nu_1*H;
4036 
4037  //momentum accumulation
4038  mom_u_acc[k]=u[k];
4039  dmom_u_acc_u[k]=1.0;
4040 
4041  mom_v_acc[k]=v[k];
4042  dmom_v_acc_v[k]=1.0;
4043 
4044  mom_w_acc[k]=w[k];
4045  dmom_w_acc_w[k]=1.0;
4046 
4047  //mass advective flux
4048  mass_adv[k*3+0]=u[k];
4049  mass_adv[k*3+1]=v[k];
4050  mass_adv[k*3+2]=w[k];
4051 
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;
4055 
4056  //u momentum advective flux
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];
4060 
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];
4064 
4065  dmom_u_adv_v[k*3+1]=u[k];
4066 
4067  dmom_u_adv_w[k*3+2]=u[k];
4068 
4069  //v momentum advective_flux
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];
4073 
4074  dmom_v_adv_u[k*3+0]=v[k];
4075 
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];
4079 
4080  dmom_v_adv_w[k*3+2]=v[k];
4081 
4082  //w momentum advective_flux
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];
4086 
4087  dmom_w_adv_u[k*3+0]=w[k];
4088 
4089  dmom_w_adv_v[k*3+0]=w[k];
4090 
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];
4094 
4095  //u momentum diffusion tensor
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;
4099 
4100  //v momentum diffusion tensor
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;
4104 
4105  //w momentum diffusion tensor
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;
4109 
4110  //momentum sources
4111  mom_u_source[k] = -g[0];
4112  mom_v_source[k] = -g[1];
4113  mom_w_source[k] = -g[2];
4114 
4115  //u momentum Hamiltonian (pressure)
4116  mom_u_ham[k] = grad_p[k*3+0]/rho;
4117  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4118 
4119  //v momentum Hamiltonian (pressure)
4120  mom_v_ham[k] = grad_p[k*3+1]/rho;
4121  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4122 
4123  //w momentum Hamiltonian (pressure)
4124  mom_w_ham[k] = grad_p[k*3+2]/rho;
4125  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4126  }
4127 }
4128 
4129 void TwophaseStokes_LS_SO_2D_Evaluate(const int nPoints,
4130  const double eps,
4131  const double rho_0,
4132  const double nu_0,
4133  const double rho_1,
4134  const double nu_1,
4135  const double* g,
4136  const double* phi,
4137  const double *p,
4138  const double *grad_p,
4139  const double *u,
4140  const double *v,
4141  double *mom_u_acc,
4142  double *dmom_u_acc_u,
4143  double *mom_v_acc,
4144  double *dmom_v_acc_v,
4145  double *mass_adv,
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,
4152  double *mom_u_ham,
4153  double *dmom_u_ham_grad_p,
4154  double *mom_v_ham,
4155  double *dmom_v_ham_grad_p)
4156 {
4157  int k;
4158  double rho,nu,H;
4159  for (k=0;k<nPoints;k++)
4160  {
4162  H = smoothedHeaviside(eps,phi[k]);
4163  rho = rho_0*(1.0-H)+rho_1*H;
4164  nu = nu_0*(1.0-H)+nu_1*H;
4165 
4166  //u momentum accumulation
4167  mom_u_acc[k]=u[k];
4168  dmom_u_acc_u[k]=1.0;
4169 
4170  //v momentum accumulation
4171  mom_v_acc[k]=v[k];
4172  dmom_v_acc_v[k]=1.0;
4173 
4174  //mass advective flux
4175  mass_adv[k*2+0]=u[k];
4176  mass_adv[k*2+1]=v[k];
4177 
4178  dmass_adv_u[k*2+0]=1.0;
4179  dmass_adv_v[k*2+1]=1.0;
4180 
4181  //u momentum diffusion tensor
4182  mom_u_diff_ten[k*4+0] = nu;
4183  mom_u_diff_ten[k*4+3] = nu;
4184 
4185  //v momentum diffusion tensor
4186  mom_v_diff_ten[k*4+0] = nu;
4187  mom_v_diff_ten[k*4+3] = nu;
4188 
4189  //momentum sources
4190  mom_u_source[k] = -g[0];
4191  mom_v_source[k] = -g[1];
4192 
4193  //u momentum Hamiltonian (pressure)
4194  mom_u_ham[k] = grad_p[k*2+0]/rho;
4195  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4196 
4197  //v momentum Hamiltonian (pressure)
4198  mom_v_ham[k] = grad_p[k*2+1]/rho;
4199  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4200  }
4201 }
4202 
4203 void TwophaseStokes_LS_SO_3D_Evaluate(const int nPoints,
4204  const double eps,
4205  const double rho_0,
4206  const double nu_0,
4207  const double rho_1,
4208  const double nu_1,
4209  const double* g,
4210  const double* phi,
4211  const double *p,
4212  const double *grad_p,
4213  const double *u,
4214  const double *v,
4215  const double *w,
4216  double *mom_u_acc,
4217  double *dmom_u_acc_u,
4218  double *mom_v_acc,
4219  double *dmom_v_acc_v,
4220  double *mom_w_acc,
4221  double *dmom_w_acc_w,
4222  double *mass_adv,
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,
4232  double *mom_u_ham,
4233  double *dmom_u_ham_grad_p,
4234  double *mom_v_ham,
4235  double *dmom_v_ham_grad_p,
4236  double *mom_w_ham,
4237  double *dmom_w_ham_grad_p)
4238 {
4239  int k;
4240  double rho,nu,H;
4241  for (k=0;k<nPoints;k++)
4242  {
4243  H = smoothedHeaviside(eps,phi[k]);
4244  rho = rho_0*(1.0-H)+rho_1*H;
4245  nu = nu_0*(1.0-H)+nu_1*H;
4246 
4247  //momentum accumulation
4248  mom_u_acc[k]=u[k];
4249  dmom_u_acc_u[k]=1.0;
4250 
4251  mom_v_acc[k]=v[k];
4252  dmom_v_acc_v[k]=1.0;
4253 
4254  mom_w_acc[k]=w[k];
4255  dmom_w_acc_w[k]=1.0;
4256 
4257  //mass advective flux
4258  mass_adv[k*3+0]=u[k];
4259  mass_adv[k*3+1]=v[k];
4260  mass_adv[k*3+2]=w[k];
4261 
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;
4265 
4266  //u momentum diffusion tensor
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;
4270 
4271  //v momentum diffusion tensor
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;
4275 
4276  //w momentum diffusion tensor
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;
4280 
4281  //momentum sources
4282  mom_u_source[k] = -g[0];
4283  mom_v_source[k] = -g[1];
4284  mom_w_source[k] = -g[2];
4285 
4286  //u momentum Hamiltonian (pressure)
4287  mom_u_ham[k] = grad_p[k*3+0]/rho;
4288  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4289 
4290  //v momentum Hamiltonian (pressure)
4291  mom_v_ham[k] = grad_p[k*3+1]/rho;
4292  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4293 
4294  //w momentum Hamiltonian (pressure)
4295  mom_w_ham[k] = grad_p[k*3+2]/rho;
4296  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4297  }
4298 }
4299 
4301  const double eps,
4302  const double rho_0,
4303  const double nu_0,
4304  const double rho_1,
4305  const double nu_1,
4306  const double* g,
4307  const double* vof,
4308  const double *p,
4309  const double *grad_p,
4310  const double *u,
4311  const double *v,
4312  double *mom_u_acc,
4313  double *dmom_u_acc_u,
4314  double *mom_v_acc,
4315  double *dmom_v_acc_v,
4316  double *mass_adv,
4317  double *dmass_adv_u,
4318  double *dmass_adv_v,
4319  double *mom_u_adv,
4320  double *dmom_u_adv_u,
4321  double *dmom_u_adv_v,
4322  double *mom_v_adv,
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,
4329  double *mom_u_ham,
4330  double *dmom_u_ham_grad_p,
4331  double *mom_v_ham,
4332  double *dmom_v_ham_grad_p)
4333 {
4334  int k;
4335  double rho,nu,H;
4336  for (k=0;k<nPoints;k++)
4337  {
4339  H = fmax(0.0,fmin(1.0,vof[k]));
4340  rho = rho_0*(1.0-H)+rho_1*H;
4341  nu = nu_0*(1.0-H)+nu_1*H;
4342 
4343  //u momentum accumulation
4344  mom_u_acc[k]=u[k];
4345  dmom_u_acc_u[k]=1.0;
4346 
4347  //v momentum accumulation
4348  mom_v_acc[k]=v[k];
4349  dmom_v_acc_v[k]=1.0;
4350 
4351  //mass advective flux
4352  mass_adv[k*2+0]=u[k];
4353  mass_adv[k*2+1]=v[k];
4354 
4355  dmass_adv_u[k*2+0]=1.0;
4356  dmass_adv_v[k*2+1]=1.0;
4357 
4358  //u momentum advective flux
4359  mom_u_adv[k*2+0]=u[k]*u[k];
4360  mom_u_adv[k*2+1]=u[k]*v[k];
4361 
4362  dmom_u_adv_u[k*2+0]=2.0*u[k];
4363  dmom_u_adv_u[k*2+1]=v[k];
4364 
4365  dmom_u_adv_v[k*2+1]=u[k];
4366 
4367  //v momentum advective_flux
4368  mom_v_adv[k*2+0]=v[k]*u[k];
4369  mom_v_adv[k*2+1]=v[k]*v[k];
4370 
4371  dmom_v_adv_u[k*2+0]=v[k];
4372 
4373  dmom_v_adv_v[k*2+0]=u[k];
4374  dmom_v_adv_v[k*2+1]=2.0*v[k];
4375 
4376  //u momentum diffusion tensor
4377  mom_u_diff_ten[k*4+0] = nu;
4378  mom_u_diff_ten[k*4+3] = nu;
4379 
4380  //v momentum diffusion tensor
4381  mom_v_diff_ten[k*4+0] = nu;
4382  mom_v_diff_ten[k*4+3] = nu;
4383 
4384  //momentum sources
4385  mom_u_source[k] = -g[0];
4386  mom_v_source[k] = -g[1];
4387 
4388  //u momentum Hamiltonian (pressure)
4389  mom_u_ham[k] = grad_p[k*2+0]/rho;
4390  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4391 
4392  //v momentum Hamiltonian (pressure)
4393  mom_v_ham[k] = grad_p[k*2+1]/rho;
4394  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4395  }
4396 }
4397 
4399  const double eps,
4400  const double rho_0,
4401  const double nu_0,
4402  const double rho_1,
4403  const double nu_1,
4404  const double* g,
4405  const double* vof,
4406  const double *p,
4407  const double *grad_p,
4408  const double *u,
4409  const double *v,
4410  const double *w,
4411  double *mom_u_acc,
4412  double *dmom_u_acc_u,
4413  double *mom_v_acc,
4414  double *dmom_v_acc_v,
4415  double *mom_w_acc,
4416  double *dmom_w_acc_w,
4417  double *mass_adv,
4418  double *dmass_adv_u,
4419  double *dmass_adv_v,
4420  double *dmass_adv_w,
4421  double *mom_u_adv,
4422  double *dmom_u_adv_u,
4423  double *dmom_u_adv_v,
4424  double *dmom_u_adv_w,
4425  double *mom_v_adv,
4426  double *dmom_v_adv_u,
4427  double *dmom_v_adv_v,
4428  double *dmom_v_adv_w,
4429  double *mom_w_adv,
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,
4439  double *mom_u_ham,
4440  double *dmom_u_ham_grad_p,
4441  double *mom_v_ham,
4442  double *dmom_v_ham_grad_p,
4443  double *mom_w_ham,
4444  double *dmom_w_ham_grad_p)
4445 {
4446  int k;
4447  double rho,nu,H;
4448  for (k=0;k<nPoints;k++)
4449  {
4450  H = fmax(0.0,fmin(1.0,vof[k]));
4451  rho = rho_0*(1.0-H)+rho_1*H;
4452  nu = nu_0*(1.0-H)+nu_1*H;
4453 
4454  //momentum accumulation
4455  mom_u_acc[k]=u[k];
4456  dmom_u_acc_u[k]=1.0;
4457 
4458  mom_v_acc[k]=v[k];
4459  dmom_v_acc_v[k]=1.0;
4460 
4461  mom_w_acc[k]=w[k];
4462  dmom_w_acc_w[k]=1.0;
4463 
4464  //mass advective flux
4465  mass_adv[k*3+0]=u[k];
4466  mass_adv[k*3+1]=v[k];
4467  mass_adv[k*3+2]=w[k];
4468 
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;
4472 
4473  //u momentum advective flux
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];
4477 
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];
4481 
4482  dmom_u_adv_v[k*3+1]=u[k];
4483 
4484  dmom_u_adv_w[k*3+2]=u[k];
4485 
4486  //v momentum advective_flux
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];
4490 
4491  dmom_v_adv_u[k*3+0]=v[k];
4492 
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];
4496 
4497  dmom_v_adv_w[k*3+2]=v[k];
4498 
4499  //w momentum advective_flux
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];
4503 
4504  dmom_w_adv_u[k*3+0]=w[k];
4505 
4506  dmom_w_adv_v[k*3+0]=w[k];
4507 
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];
4511 
4512  //u momentum diffusion tensor
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;
4516 
4517  //v momentum diffusion tensor
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;
4521 
4522  //w momentum diffusion tensor
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;
4526 
4527  //momentum sources
4528  mom_u_source[k] = -g[0];
4529  mom_v_source[k] = -g[1];
4530  mom_w_source[k] = -g[2];
4531 
4532  //u momentum Hamiltonian (pressure)
4533  mom_u_ham[k] = grad_p[k*3+0]/rho;
4534  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4535 
4536  //v momentum Hamiltonian (pressure)
4537  mom_v_ham[k] = grad_p[k*3+1]/rho;
4538  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4539 
4540  //w momentum Hamiltonian (pressure)
4541  mom_w_ham[k] = grad_p[k*3+2]/rho;
4542  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4543  }
4544 }
4545 
4546 void TwophaseStokes_VOF_SO_2D_Evaluate(const int nPoints,
4547  const double eps,
4548  const double rho_0,
4549  const double nu_0,
4550  const double rho_1,
4551  const double nu_1,
4552  const double* g,
4553  const double* vof,
4554  const double *p,
4555  const double *grad_p,
4556  const double *u,
4557  const double *v,
4558  double *mom_u_acc,
4559  double *dmom_u_acc_u,
4560  double *mom_v_acc,
4561  double *dmom_v_acc_v,
4562  double *mass_adv,
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,
4569  double *mom_u_ham,
4570  double *dmom_u_ham_grad_p,
4571  double *mom_v_ham,
4572  double *dmom_v_ham_grad_p)
4573 {
4574  int k;
4575  double rho,nu,H;
4576  for (k=0;k<nPoints;k++)
4577  {
4579  H = fmax(0.0,fmin(1.0,vof[k]));
4580  rho = rho_0*(1.0-H)+rho_1*H;
4581  nu = nu_0*(1.0-H)+nu_1*H;
4582 
4583  //u momentum accumulation
4584  mom_u_acc[k]=u[k];
4585  dmom_u_acc_u[k]=1.0;
4586 
4587  //v momentum accumulation
4588  mom_v_acc[k]=v[k];
4589  dmom_v_acc_v[k]=1.0;
4590 
4591  //mass advective flux
4592  mass_adv[k*2+0]=u[k];
4593  mass_adv[k*2+1]=v[k];
4594 
4595  dmass_adv_u[k*2+0]=1.0;
4596  dmass_adv_v[k*2+1]=1.0;
4597 
4598  //u momentum diffusion tensor
4599  mom_u_diff_ten[k*4+0] = nu;
4600  mom_u_diff_ten[k*4+3] = nu;
4601 
4602  //v momentum diffusion tensor
4603  mom_v_diff_ten[k*4+0] = nu;
4604  mom_v_diff_ten[k*4+3] = nu;
4605 
4606  //momentum sources
4607  mom_u_source[k] = -g[0];
4608  mom_v_source[k] = -g[1];
4609 
4610  //u momentum Hamiltonian (pressure)
4611  mom_u_ham[k] = grad_p[k*2+0]/rho;
4612  dmom_u_ham_grad_p[k*2+0]=1.0/rho;
4613 
4614  //v momentum Hamiltonian (pressure)
4615  mom_v_ham[k] = grad_p[k*2+1]/rho;
4616  dmom_v_ham_grad_p[k*2+1]=1.0/rho;
4617  }
4618 }
4619 
4620 void TwophaseStokes_VOF_SO_3D_Evaluate(const int nPoints,
4621  const double eps,
4622  const double rho_0,
4623  const double nu_0,
4624  const double rho_1,
4625  const double nu_1,
4626  const double* g,
4627  const double* vof,
4628  const double *p,
4629  const double *grad_p,
4630  const double *u,
4631  const double *v,
4632  const double *w,
4633  double *mom_u_acc,
4634  double *dmom_u_acc_u,
4635  double *mom_v_acc,
4636  double *dmom_v_acc_v,
4637  double *mom_w_acc,
4638  double *dmom_w_acc_w,
4639  double *mass_adv,
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,
4649  double *mom_u_ham,
4650  double *dmom_u_ham_grad_p,
4651  double *mom_v_ham,
4652  double *dmom_v_ham_grad_p,
4653  double *mom_w_ham,
4654  double *dmom_w_ham_grad_p)
4655 {
4656  int k;
4657  double rho,nu,H;
4658  for (k=0;k<nPoints;k++)
4659  {
4660  H = fmax(0.0,fmin(1.0,vof[k]));
4661  rho = rho_0*(1.0-H)+rho_1*H;
4662  nu = nu_0*(1.0-H)+nu_1*H;
4663 
4664  //momentum accumulation
4665  mom_u_acc[k]=u[k];
4666  dmom_u_acc_u[k]=1.0;
4667 
4668  mom_v_acc[k]=v[k];
4669  dmom_v_acc_v[k]=1.0;
4670 
4671  mom_w_acc[k]=w[k];
4672  dmom_w_acc_w[k]=1.0;
4673 
4674  //mass advective flux
4675  mass_adv[k*3+0]=u[k];
4676  mass_adv[k*3+1]=v[k];
4677  mass_adv[k*3+2]=w[k];
4678 
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;
4682 
4683  //u momentum diffusion tensor
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;
4687 
4688  //v momentum diffusion tensor
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;
4692 
4693  //w momentum diffusion tensor
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;
4697 
4698  //momentum sources
4699  mom_u_source[k] = -g[0];
4700  mom_v_source[k] = -g[1];
4701  mom_w_source[k] = -g[2];
4702 
4703  //u momentum Hamiltonian (pressure)
4704  mom_u_ham[k] = grad_p[k*3+0]/rho;
4705  dmom_u_ham_grad_p[k*3+0]=1.0/rho;
4706 
4707  //v momentum Hamiltonian (pressure)
4708  mom_v_ham[k] = grad_p[k*3+1]/rho;
4709  dmom_v_ham_grad_p[k*3+1]=1.0/rho;
4710 
4711  //w momentum Hamiltonian (pressure)
4712  mom_w_ham[k] = grad_p[k*3+2]/rho;
4713  dmom_w_ham_grad_p[k*3+2]=1.0/rho;
4714  }
4715 }
4716 
4717 void unitSquareVortexEvaluate(const int nPoints,
4718  const int nSpace,
4719  double t,
4720  const double *x,
4721  const double *u,
4722  double *m,
4723  double *dm,
4724  double *f,
4725  double *df)
4726 {
4727  double vx, vy, xk, yk;
4728  int k;
4729  double one8 = 1.0/8.0;
4730  for (k=0; k < nPoints; k++)
4731  {
4732  m[k] = u[k];
4733  dm[k] = 1.0;
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];
4739  df[k*nSpace] = vx;
4740  df[k*nSpace+1] = vy;
4741  }
4742 }
4743 
4744 /*for HJ testing*/
4745 void constantVelocityLevelSetEvaluate(const int nPoints,
4746  const int nSpace,
4747  const double *b,
4748  const double *x,
4749  const double *u,
4750  const double *gradu,
4751  double *m,
4752  double *dm,
4753  double *f,
4754  double *df,
4755  double *H,
4756  double *dH)
4757 {
4758  double bdotgrad;
4759  int k,id;
4760  for (k=0; k < nPoints; k++)
4761  {
4762  m[k] = u[k];
4763  dm[k] = 1.0;
4764  bdotgrad=0.0;
4765  for (id=0; id < nSpace; id++)
4766  {
4767  f[k*nSpace+id] = 0.0; /*just for now since helps get all the right quad terms*/
4768  df[k*nSpace+id]= 0.0; /*just for now since helps get all the right quad terms*/
4769 
4770  bdotgrad+= gradu[k*nSpace+id]*b[id];
4771  dH[k*nSpace+id]=b[id];
4772  }
4773  H[k] = bdotgrad;
4774  }
4775 }
4777  const int nSpace,
4778  double b,
4779  const double *x,
4780  const double *u,
4781  const double *gradu,
4782  double *m,
4783  double *dm,
4784  double *f,
4785  double *df,
4786  double *H,
4787  double *dH)
4788 {
4789  double normgradu;
4790  int k,id;
4791  for (k=0; k < nPoints; k++)
4792  {
4793  m[k] = u[k];
4794  dm[k] = 1.0;
4795  normgradu=0.0;
4796  for (id=0; id < nSpace; id++)
4797  {
4798  f[k*nSpace+id] = 0.0; /*just for now since helps get all the right quad terms*/
4799  df[k*nSpace+id]= 0.0; /*just for now since helps get all the right quad terms*/
4800 
4801  normgradu+= gradu[k*nSpace+id]*gradu[k*nSpace+id];
4802 
4803  }
4804  normgradu = sqrt(normgradu);
4805  H[k] = b*normgradu;
4806  for (id=0; id < nSpace; id++)
4807  {
4808  dH[k*nSpace+id]=gradu[k*nSpace+id]/(normgradu+1.0e-8);
4809  }
4810  }
4811 }
4812 void unitSquareVortexLevelSetEvaluate(const int nPoints,
4813  const int nSpace,
4814  double t,
4815  const double *x,
4816  const double *u,
4817  const double *gradu,
4818  double *m,
4819  double *dm,
4820  double *f,
4821  double *df,
4822  double *H,
4823  double *dH)
4824 {
4825  double v[3], xk, yk, vdotgrad, one8;
4826  int k,id;
4827  v[2] = 0.0;
4828  one8 = 1.0/8.0;
4829  for (k=0; k < nPoints; k++)
4830  {
4831  m[k] = u[k];
4832  dm[k] = 1.0;
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);
4836  vdotgrad=0.0;
4837  for (id=0; id < nSpace; id++)
4838  {
4839  f[k*nSpace+id] = 0.0; /*just for now since helps get all the right quad terms*/
4840  df[k*nSpace+id]= 0.0; /*just for now since helps get all the right quad terms*/
4841 
4842  vdotgrad+= gradu[k*nSpace+id]*v[id];
4843  dH[k*nSpace+id]=v[id];
4844  }
4845  H[k] = vdotgrad;
4846  }
4847 }
4848 void unitSquareRotationLevelSetEvaluate(const int nPoints,
4849  const int nSpace,
4850  double t,
4851  const double *x,
4852  const double *u,
4853  const double *gradu,
4854  double *m,
4855  double *dm,
4856  double *f,
4857  double *df,
4858  double *H,
4859  double *dH)
4860 {
4861  double v[3], xk, yk, vdotgrad, one8;
4862  int k,id;
4863  v[2] = 0.0;
4864  one8 = 1.0/8.0;
4865  for (k=0; k < nPoints; k++)
4866  {
4867  m[k] = u[k];
4868  dm[k] = 1.0;
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]);
4872  vdotgrad=0.0;
4873  for (id=0; id < nSpace; id++)
4874  {
4875  f[k*nSpace+id] = 0.0; /*just for now since helps get all the right quad terms*/
4876  df[k*nSpace+id]= 0.0; /*just for now since helps get all the right quad terms*/
4877 
4878  vdotgrad+= gradu[k*nSpace+id]*v[id];
4879  dH[k*nSpace+id]=v[id];
4880  }
4881  H[k] = vdotgrad;
4882  }
4883 }
4884 
4885 void HJBurgersEvaluate(const int nPoints,
4886  const int nSpace,
4887  const double offset,
4888  const double *u,
4889  const double *gradu,
4890  double *m,
4891  double *dm,
4892  double *H,
4893  double *dH)
4894 {
4895  int k,id,jd;
4896  double tmp;
4897  for (k=0; k < nPoints; k++)
4898  {
4899  m[k] = u[k];
4900  dm[k] = 1.0;
4901  tmp = offset;
4902  for (id=0; id < nSpace; id++)
4903  {
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];
4908  }
4909  H[k] = tmp*tmp*0.5;
4910  }
4911 }
4912 
4913 /* /\** Coefficients for the mass conservative head-based Richards' equation using Mualem-Van Genuchten. */
4914 /* *\/ */
4915 /* void conservativeHeadRichardsMualemVanGenuchtenEvaluate(const int nPoints, */
4916 /* const int nSpace, */
4917 /* const double rho, */
4918 /* const double* gravity, */
4919 /* const double* alpha, */
4920 /* const double* n, */
4921 /* const double* m, */
4922 /* const double* thetaS, */
4923 /* const double* thetaR, */
4924 /* const double* thetaSR, */
4925 /* const double* KWs, */
4926 /* double *u, */
4927 /* double *mass, */
4928 /* double *dmass, */
4929 /* double *f, */
4930 /* double *df, */
4931 /* double *a, */
4932 /* double *da, */
4933 /* double *phi, */
4934 /* double *dphi) */
4935 /* { */
4936 /* int k,I,J; */
4937 /* const int nSpace2=nSpace*nSpace; */
4938 /* register double psiC,alphaPsiC,alphaPsiC_n,alphaPsiC_nM1,onePlus_alphaPsiC_n,sBar,sBarByOnePlus_alphaPsiC_n,sqrt_sBar,sqrt_1minusSbar,thetaW,DsBar_DpC,DthetaW_DpC,vBar,uBar,krW,krN, */
4939 /* alphaPsiC_nM2,sBarBy_onePlus_alphaPsiC_n_2,DDsBar_DDpC,DDthetaW_DDpC,DkrW_DpC,rho2=rho*rho; */
4940 /* double KW[9],KN[9],DKW_DpC[9]; */
4941 /* for (k=0;k<nPoints;k++) */
4942 /* { */
4943 /* psiC = -u[k]; */
4944 /* if (psiC > 0.0) */
4945 /* { */
4946 /* alphaPsiC = alpha[k]*psiC; */
4947 /* alphaPsiC_n = pow(alphaPsiC,n[k]); */
4948 /* alphaPsiC_nM1 = alphaPsiC_n/alphaPsiC; */
4949 /* alphaPsiC_nM2 = alphaPsiC_nM1/alphaPsiC; */
4950 /* onePlus_alphaPsiC_n = 1.0 + alphaPsiC_n; */
4951 /* sBar = pow(onePlus_alphaPsiC_n,-m[k]); */
4952 /* sBarByOnePlus_alphaPsiC_n = sBar/onePlus_alphaPsiC_n; */
4953 /* sqrt_sBar = sqrt(sBar); */
4954 /* sqrt_1minusSbar = sqrt(1.0 - sBar); */
4955 /* thetaW = thetaSR[k]*sBar + thetaR[k]; */
4956 /* DsBar_DpC = -alpha[k]*(n[k]-1.0)*alphaPsiC_nM1 */
4957 /* *sBarByOnePlus_alphaPsiC_n; */
4958 /* DthetaW_DpC = thetaSR[k] * DsBar_DpC; */
4959 /* vBar = 1.0-alphaPsiC_nM1*sBar; */
4960 /* uBar = alphaPsiC_nM1*sBar; */
4961 /* krW = sqrt_sBar*vBar*vBar; */
4962 /* DkrW_DpC = (0.5/sqrt_sBar)*DsBar_DpC*vBar*vBar */
4963 /* - */
4964 /* 2.0*sqrt_sBar*vBar* */
4965 /* (alpha[k]*(n[k]-1.0)*alphaPsiC_nM2*sBar */
4966 /* + alphaPsiC_nM1 * DsBar_DpC); */
4967 /* for (I=0;I<nSpace;I++) */
4968 /* for(J=0;J<nSpace;J++) */
4969 /* { */
4970 /* KW[I*nSpace + J] = KWs[k*nSpace2 + I*nSpace + J]*krW; */
4971 /* DKW_DpC[I*nSpace + J] = KWs[k*nSpace2 + I*nSpace + J]*DkrW_DpC; */
4972 /* } */
4973 /* } */
4974 /* else */
4975 /* { */
4976 /* sBar = 1.0; */
4977 /* thetaW = thetaS[k]; */
4978 /* DsBar_DpC = 0.0; */
4979 /* DthetaW_DpC = 0.0; */
4980 /* krW = 1.0; */
4981 /* for (I=0;I<nSpace;I++) */
4982 /* for(J=0;J<nSpace;J++) */
4983 /* { */
4984 /* KW[I*nSpace + J] = KWs[k*nSpace2 + I*nSpace + J]; */
4985 /* DKW_DpC[I*nSpace + J] = 0.0; */
4986 /* } */
4987 /* } */
4988 /* mass[k] = rho*thetaW; */
4989 /* dmass[k] = -rho*DthetaW_DpC; */
4990 /* for (I=0;I<nSpace;I++) */
4991 /* { */
4992 /* f[k*nSpace+I] = 0.0; */
4993 /* df[k*nSpace+I] = 0.0; */
4994 /* for (J=0;J<nSpace;J++) */
4995 /* { */
4996 /* f[k*nSpace+I] += rho2*KW[I*nSpace + J]*gravity[J]; */
4997 /* df[k*nSpace+I] -= rho2*DKW_DpC[I*nSpace + J]*gravity[J]; */
4998 /* a[k*nSpace2+I*nSpace+J] = rho*KW[I*nSpace + J]; */
4999 /* da[k*nSpace2+I*nSpace+J] = -rho*DKW_DpC[I*nSpace + J]; */
5000 /* } */
5001 /* } */
5002 /* } */
5003 /* } */
5004 
5008  const int nSpace,
5009  const double rho,
5010  const double beta,
5011  const double* gravity,
5012  const double* x,
5013  const double alpha,
5014  const double n,
5015  const double m,
5016  const double thetaR,
5017  const double thetaSR,
5018  const double KWs,
5019  double *u,
5020  double *mass,
5021  double *dmass,
5022  double *f,
5023  double *df,
5024  double *a,
5025  double *da,
5026  double *phi,
5027  double *dphi)
5028 {
5029  int k,I;
5030  const int nSpace2=nSpace*nSpace;
5031  register double psiC,
5032  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5033  onePlus_pcBar_n,
5034  sBar,sqrt_sBar,DsBar_DpsiC,
5035  thetaW,DthetaW_DpsiC,
5036  vBar,vBar2,DvBar_DpsiC,
5037  KW,DKW_DpsiC,
5038  rho2=rho*rho,
5039  thetaS=thetaR+thetaSR,
5040  rhom,drhom;
5041  for (k=0;k<nPoints;k++)
5042  {
5043  psiC = -u[k];
5044  if (psiC > 0.0)
5045  {
5046  pcBar = alpha*psiC;
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;
5051 
5052  sBar = pow(onePlus_pcBar_n,-m);
5053  /* using -mn = 1-n */
5054  DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5055 
5056  vBar = 1.0-pcBar_nM1*sBar;
5057  vBar2 = vBar*vBar;
5058  DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5059 
5060  thetaW = thetaSR*sBar + thetaR;
5061  DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5062 
5063  sqrt_sBar = sqrt(sBar);
5064  KW= KWs*sqrt_sBar*vBar2;
5065  DKW_DpsiC= KWs*
5066  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5067  +
5068  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5069  }
5070  else
5071  {
5072  thetaW = thetaS;
5073  DthetaW_DpsiC = 0.0;
5074  KW = KWs;
5075  DKW_DpsiC = 0.0;
5076  }
5077  //slight compressibility
5078  rhom = rho*exp(beta*u[k]);
5079  drhom = beta*rhom;
5080 
5081  mass[k] = rhom*thetaW;
5082  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5083  for (I=0;I<nSpace;I++)
5084  {
5085  f[k*nSpace+I] = rho2*KW*gravity[I];
5086  df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I];
5087 
5088  a[k*nSpace2+I*nSpace+I] = rho*KW;
5089  da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
5090  }
5091  }
5092 }
5093 /* mwf begin unnecessary RE additions */
5094 /* TODO: figure out how to handle dmass term to get right jacobian*/
5096  const int nPointsPerSimplex,
5097  const int nSpace,
5098  const double rho,
5099  const double* gravity,
5100  const double alpha,
5101  const double n,
5102  const double m,
5103  const double thetaR,
5104  const double thetaSR,
5105  const double KWs,
5106  double *dV,
5107  double *u,
5108  double *mass,
5109  double *dmass,
5110  double *f,
5111  double *df,
5112  double *a,
5113  double *da)
5114 {
5115  int k,I,J,eN;
5116  const int nSpace2=nSpace*nSpace;
5117  register double psiC,
5118  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5119  onePlus_pcBar_n,
5120  sBar,sqrt_sBar,DsBar_DpsiC,
5121  thetaW,DthetaW_DpsiC,
5122  vBar,vBar2,DvBar_DpsiC,
5123  KW,DKW_DpsiC,
5124  rho2=rho*rho,
5125  thetaS=thetaR+thetaSR;
5126 
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},
5131  {0.0,0.0,0.0},
5132  {0.0,0.0,0.0}};
5133  double daavg[3][3]= {{0.0,0.0,0.0},
5134  {0.0,0.0,0.0},
5135  {0.0,0.0,0.0}};
5136  /*mwf debug
5137  printf("revgL2proj nSimplices=%d nPerSimp=%d nSpace=%d\n",nSimplices,nPointsPerSimplex,
5138  nSpace);
5139  */
5140  for (eN = 0; eN < nSimplices; eN++)
5141  {
5142  mavg = 0.0; dmavg = 0.0; vol = 0.0;
5143  for (I=0; I < nSpace; I++)
5144  {
5145  favg[I] =0.0; dfavg[I] = 0.0;
5146  for (J=0; J < nSpace;J++)
5147  {
5148  aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5149  }
5150  }
5151  for (k=0;k<nPointsPerSimplex;k++)
5152  {
5153  psiC = -u[eN*nPointsPerSimplex + k];
5154  if (psiC > 0.0)
5155  {
5156  pcBar = alpha*psiC;
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;
5161 
5162  sBar = pow(onePlus_pcBar_n,-m);
5163  /* using -mn = 1-n */
5164  DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5165 
5166  vBar = 1.0-pcBar_nM1*sBar;
5167  vBar2 = vBar*vBar;
5168  DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5169 
5170  thetaW = thetaSR*sBar + thetaR;
5171  DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5172 
5173  sqrt_sBar = sqrt(sBar);
5174  KW= KWs*sqrt_sBar*vBar2;
5175  DKW_DpsiC= KWs*
5176  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5177  +
5178  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5179  }
5180  else
5181  {
5182  thetaW = thetaS;
5183  DthetaW_DpsiC = 0.0;
5184  KW = KWs;
5185  DKW_DpsiC = 0.0;
5186  }
5187  /*mwf debug
5188  printf("revgmL2 eN=%d k=%d psiC=%g thetaW=%g KW=%g rho=%g DKW_DpsiC=%g\n",
5189  eN,k,psiC,thetaW,KW,rho,DKW_DpsiC);
5190  */
5191  vol += dV[eN*nPointsPerSimplex + k];
5192  mavg += rho*thetaW*dV[eN*nPointsPerSimplex + k];
5193  dmavg +=-rho*DthetaW_DpsiC*dV[eN*nPointsPerSimplex + k];
5194  /*go ahead and assign point values for derivs since this is what's actually
5195  appropriate at least for stiffness and advection terms,
5196  but it's not correct for mass term*/
5197  dmass[eN*nPointsPerSimplex+ k] =-rho*DthetaW_DpsiC;
5198 
5199  for (I=0; I < nSpace; I++)
5200  {
5201  favg[I] += rho2*KW*gravity[I]*dV[eN*nPointsPerSimplex + k];
5202  dfavg[I]+=-rho2*DKW_DpsiC*gravity[I]*dV[eN*nPointsPerSimplex + k];
5203  J=I;/*assume isotropic for now*/
5204  aavg[I][J] += rho*KW*dV[eN*nPointsPerSimplex + k];
5205  daavg[I][J] +=-rho*DKW_DpsiC*dV[eN*nPointsPerSimplex + k];
5206 
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;
5209  }
5210  }/*end k 1*/
5211  assert(vol > 0.0);
5212  /*mwf debug
5213  printf("eN=%d vol=%g mavg=%g dmavg=%g favg=[%g,%g,%g] aavg=[%g,%g,%g] \n",
5214  eN,vol,mavg,dmavg,favg[0],favg[1],favg[2],aavg[0][0],aavg[1][1],aavg[2][2]);
5215  */
5216  for (k=0; k < nPointsPerSimplex; k++)
5217  {
5218  mass[eN*nPointsPerSimplex + k] = mavg/vol;
5219  /*dmass[eN*nPointsPerSimplex+ k] = dmavg/vol;*/
5220  for (I=0; I < nSpace; I++)
5221  {
5222  f[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = favg[I]/vol;
5223  /*df[eN*nPointsPerSimplex*nSpace+ k*nSpace + I] = dfavg[I]/vol;*/
5224  for (J=0; J < nSpace; J++)
5225  {
5226  if (J == I)
5227  {
5228  a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = aavg[I][J]/vol;
5229  /*da[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J]= daavg[I][J]/vol;*/
5230  }
5231  else
5232  {
5233  a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J] = 0.0;
5234  /*da[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + J]= 0.0;*/
5235  }
5236  }
5237 
5238  }/*I*/
5239  }/*k*/
5240  }
5241 }
5242 /* TODO: figure out how to handle dmass term to get right jacobian*/
5244  const int nElementBoundaries_element,
5245  const int nPointsPerElementBoundary,
5246  const int nSpace,
5247  const double rho,
5248  const double* gravity,
5249  const double alpha,
5250  const double n,
5251  const double m,
5252  const double thetaR,
5253  const double thetaSR,
5254  const double KWs,
5255  double *dV,
5256  double *u,
5257  double *mass,
5258  double *dmass,
5259  double *f,
5260  double *df,
5261  double *a,
5262  double *da)
5263 {
5264  int k,I,J,eN,ebN;
5265  const int nSpace2=nSpace*nSpace;
5266  register double psiC,
5267  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5268  onePlus_pcBar_n,
5269  sBar,sqrt_sBar,DsBar_DpsiC,
5270  thetaW,DthetaW_DpsiC,
5271  vBar,vBar2,DvBar_DpsiC,
5272  KW,DKW_DpsiC,
5273  rho2=rho*rho,
5274  thetaS=thetaR+thetaSR;
5275 
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},
5280  {0.0,0.0,0.0},
5281  {0.0,0.0,0.0}};
5282  double daavg[3][3]= {{0.0,0.0,0.0},
5283  {0.0,0.0,0.0},
5284  {0.0,0.0,0.0}};
5285  /*mwf debug
5286  printf("revgL2projBnd nElements=%d nElemBndp=%d nPtsPerBnd=%d nSpace=%d\n",nElements,nElementBoundaries_element,
5287  nPointsPerElementBoundary,
5288  nSpace);
5289  */
5290  for (eN = 0; eN < nElements; eN++)
5291  {
5292  for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
5293  {
5294  mavg = 0.0; dmavg = 0.0; vol = 0.0;
5295  for (I=0; I < nSpace; I++)
5296  {
5297  favg[I] =0.0; dfavg[I] = 0.0;
5298  for (J=0; J < nSpace;J++)
5299  {
5300  aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5301  }
5302  }
5303  for (k=0;k<nPointsPerElementBoundary;k++)
5304  {
5305  psiC = -u[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k];
5306  if (psiC > 0.0)
5307  {
5308  pcBar = alpha*psiC;
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;
5313 
5314  sBar = pow(onePlus_pcBar_n,-m);
5315  /* using -mn = 1-n */
5316  DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5317 
5318  vBar = 1.0-pcBar_nM1*sBar;
5319  vBar2 = vBar*vBar;
5320  DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5321 
5322  thetaW = thetaSR*sBar + thetaR;
5323  DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5324 
5325  sqrt_sBar = sqrt(sBar);
5326  KW= KWs*sqrt_sBar*vBar2;
5327  DKW_DpsiC= KWs*
5328  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5329  +
5330  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5331  }
5332  else
5333  {
5334  thetaW = thetaS;
5335  DthetaW_DpsiC = 0.0;
5336  KW = KWs;
5337  DKW_DpsiC = 0.0;
5338  }
5339  /*mwf debug
5340  printf("revgmL2 eN=%d ebN=%d k=%d psiC=%g thetaW=%g KW=%g rho=%g DKW_DpsiC=%g\n",
5341  eN,ebN,k,psiC,thetaW,KW,rho,DKW_DpsiC);
5342  */
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];
5346  /*mwf go ahead and assign point values for derivs since this is what's needed for stiffness terms but
5347  even though it's not the right thing to do for mass term*/
5348  dmass[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k] =
5349  -rho*DthetaW_DpsiC;
5350  for (I=0; I < nSpace; I++)
5351  {
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];
5356  J = I; /*assume isotropic*/
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];
5361 
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;
5366 
5367  }
5368  }/*end k 1*/
5369  assert(vol > 0.0);
5370  /*mwf debug
5371  printf("eN=%d vol=%g mavg=%g dmavg=%g favg=[%g,%g,%g] aavg=[%g,%g,%g] \n",
5372  eN,vol,mavg,dmavg,favg[0],favg[1],favg[2],aavg[0][0],aavg[1][1],aavg[2][2]);
5373  */
5374  for (k=0; k < nPointsPerElementBoundary; k++)
5375  {
5376  mass[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k] = mavg/vol;
5377  /*dmass[eN*nElementBoundaries_element*nPointsPerElementBoundary + ebN*nPointsPerElementBoundary + k] =
5378  dmavg/vol;*/
5379  for (I=0; I < nSpace; I++)
5380  {
5381  f[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace + ebN*nPointsPerElementBoundary*nSpace +
5382  k*nSpace + I] = favg[I]/vol;
5383  /*df[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace + ebN*nPointsPerElementBoundary*nSpace +
5384  k*nSpace + I] = dfavg[I]/vol;*/
5385  for (J=0; J < nSpace; J++)
5386  {
5387  /*assume diagonal for now*/
5388  if (J == I)
5389  {
5390  a[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2 + ebN*nPointsPerElementBoundary*nSpace2 +
5391  k*nSpace2 + I*nSpace + J] = aavg[I][J]/vol;
5392  /*da[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2+
5393  ebN*nPointsPerElementBoundary*nSpace2 +
5394  k*nSpace2 + I*nSpace + J]= daavg[I][J]/vol;*/
5395 
5396  }
5397  else
5398  {
5399  a[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2 + ebN*nPointsPerElementBoundary*nSpace2 +
5400  k*nSpace2 + I*nSpace + J] = 0.0;
5401  /*da[eN*nElementBoundaries_element*nPointsPerElementBoundary*nSpace2+
5402  ebN*nPointsPerElementBoundary*nSpace2 +
5403  k*nSpace2 + I*nSpace + J]= 0.0;*/
5404 
5405  }
5406  }
5407  }/*I*/
5408  }/*k*/
5409  }/*ebN*/
5410  }/*eN*/
5411 }
5413  const int nPointsPerSimplex,
5414  const int nSpace,
5415  const double rho,
5416  const double *gravity,
5417  const double *alpha,
5418  const double *n,
5419  const double *thetaR,
5420  const double *thetaSR,
5421  const double *KWs,
5422  double *dV,
5423  double *u,
5424  double *mass,
5425  double *dmass,
5426  double *f,
5427  double *df,
5428  double *a,
5429  double *da)
5430 {
5431  int k,I,J,eN;
5432  const int nSpace2=nSpace*nSpace;
5433  register double psiC,
5434  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5435  onePlus_pcBar_n,
5436  sBar,sqrt_sBar,DsBar_DpsiC,
5437  thetaW,DthetaW_DpsiC,
5438  vBar,vBar2,DvBar_DpsiC,
5439  KW,DKW_DpsiC,
5440  rho2=rho*rho;
5441  register double thetaS,m;
5442 
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},
5447  {0.0,0.0,0.0},
5448  {0.0,0.0,0.0}};
5449  double daavg[3][3]= {{0.0,0.0,0.0},
5450  {0.0,0.0,0.0},
5451  {0.0,0.0,0.0}};
5452  /*mwf debug
5453  printf("revgL2proj nSimplices=%d nPerSimp=%d nSpace=%d\n",nSimplices,nPointsPerSimplex,
5454  nSpace);
5455  */
5456  for (eN = 0; eN < nSimplices; eN++)
5457  {
5458  mavg = 0.0; dmavg = 0.0; vol = 0.0;
5459  for (I=0; I < nSpace; I++)
5460  {
5461  favg[I] =0.0; dfavg[I] = 0.0;
5462  for (J=0; J < nSpace;J++)
5463  {
5464  aavg[I][J] = 0.0; daavg[I][J] = 0.0;
5465  }
5466  }
5467  for (k=0;k<nPointsPerSimplex;k++)
5468  {
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];
5472  if (psiC > 0.0)
5473  {
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;
5479 
5480  sBar = pow(onePlus_pcBar_n,-m);
5481  /* using -mn = 1-n */
5482  DsBar_DpsiC = alpha[eN*nPointsPerSimplex + k]*(1.0-n[eN*nPointsPerSimplex + k])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5483 
5484  vBar = 1.0-pcBar_nM1*sBar;
5485  vBar2 = vBar*vBar;
5486  DvBar_DpsiC = -alpha[eN*nPointsPerSimplex + k]*(n[eN*nPointsPerSimplex + k]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5487 
5488  thetaW = thetaSR[eN*nPointsPerSimplex + k]*sBar + thetaR[eN*nPointsPerSimplex + k];
5489  DthetaW_DpsiC = thetaSR[eN*nPointsPerSimplex + k] * DsBar_DpsiC;
5490 
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
5495  +
5496  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5497  }
5498  else
5499  {
5500  thetaW = thetaS;
5501  DthetaW_DpsiC = 0.0;
5502  KW = KWs[eN*nPointsPerSimplex + k];
5503  DKW_DpsiC = 0.0;
5504  }
5505  /*mwf debug
5506  printf("revgmL2 eN=%d k=%d psiC=%g thetaW=%g KW=%g rho=%g DKW_DpsiC=%g\n",
5507  eN,k,psiC,thetaW,KW,rho,DKW_DpsiC);
5508  */
5509  vol += dV[eN*nPointsPerSimplex + k];
5510  mavg += rho*thetaW*dV[eN*nPointsPerSimplex + k];
5511  dmavg +=-rho*DthetaW_DpsiC*dV[eN*nPointsPerSimplex + k];
5512  /*go ahead and assign point values for deriv terms since this is right thing to do
5513  for stiffness terms even though it's not right for mass terms*/
5514  dmass[eN*nPointsPerSimplex+ k] = -rho*DthetaW_DpsiC;
5515  for (I=0; I < nSpace; I++)
5516  {
5517  favg[I] += rho2*KW*gravity[I]*dV[eN*nPointsPerSimplex + k];
5518  dfavg[I]+=-rho2*DKW_DpsiC*gravity[I]*dV[eN*nPointsPerSimplex + k];
5519 
5520  df[eN*nPointsPerSimplex*nSpace+ k*nSpace + I] = -rho2*DKW_DpsiC*gravity[I];
5521  J=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;
5525  }
5526  }/*end k 1*/
5527  assert(vol > 0.0);
5528  /*mwf debug
5529  printf("eN=%d vol=%g mavg=%g dmavg=%g favg=[%g,%g,%g] aavg=[%g,%g,%g] \n",
5530  eN,vol,mavg,dmavg,favg[0],favg[1],favg[2],aavg[0][0],aavg[1][1],aavg[2][2]);
5531  */
5532  for (k=0; k < nPointsPerSimplex; k++)
5533  {
5534  mass[eN*nPointsPerSimplex + k] = mavg/vol;
5535  /*dmass[eN*nPointsPerSimplex+ k] = dmavg/vol;*/
5536  for (I=0; I < nSpace; I++)
5537  {
5538  /*assume diagonal*/
5539  f[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = favg[I]/vol;
5540  /*df[eN*nPointsPerSimplex*nSpace+ k*nSpace + I] = dfavg[I]/vol;*/
5541  a[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + I] = aavg[I][I]/vol;
5542  /*da[eN*nPointsPerSimplex*nSpace2 + k*nSpace2 + I*nSpace + I]= daavg[I][I]/vol;*/
5543  }/*I*/
5544  }/*k*/
5545  }
5546 }
5547 
5551  const int nSpace,
5552  const double rho,
5553  const double* gravity,
5554  const double* x,
5555  const double alpha,
5556  const double n,
5557  const double m,
5558  const double thetaR,
5559  const double thetaSR,
5560  const double KWs,
5561  double *u,
5562  double *mass,
5563  double *dmass,
5564  double *f,
5565  double *df,
5566  double *a,
5567  double *da,
5568  double *phi,
5569  double *dphi)
5570 {
5571  int k,I;
5572  const int nSpace2=nSpace*nSpace;
5573  register double psiC,
5574  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
5575  onePlus_pcBar_n,
5576  sBar,sqrt_sBar,DsBar_DpsiC,
5577  thetaW,DthetaW_DpsiC,
5578  vBar,vBar2,DvBar_DpsiC,
5579  KW,DKW_DpsiC,
5580  thetaS=thetaR+thetaSR;
5581  /*mwf elevation */
5582  register double elev;
5583  for (k=0;k<nPoints;k++)
5584  {
5585  elev = 0.0;
5586  for (I=0; I < nSpace; I++)
5587  elev += gravity[I]*x[k*3+I];
5588  /*mwf if unknown is h
5589  psiC = -u[k]-elev;
5590  */
5591  /*mwf if unknown is psi*/
5592  psiC = -u[k];
5593 
5594  if (psiC > 0.0)
5595  {
5596  pcBar = alpha*psiC;
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;
5601 
5602  sBar = pow(onePlus_pcBar_n,-m);
5603  /* using -mn = 1-n */
5604  DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5605 
5606  vBar = 1.0-pcBar_nM1*sBar;
5607  vBar2 = vBar*vBar;
5608  DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5609 
5610  thetaW = thetaSR*sBar + thetaR;
5611  DthetaW_DpsiC = thetaSR * DsBar_DpsiC;
5612 
5613  sqrt_sBar = sqrt(sBar);
5614  KW= KWs*sqrt_sBar*vBar2;
5615  DKW_DpsiC= KWs*
5616  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5617  +
5618  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5619  }
5620  else
5621  {
5622  thetaW = thetaS;
5623  DthetaW_DpsiC = 0.0;
5624  KW = KWs;
5625  DKW_DpsiC = 0.0;
5626  }
5627  mass[k] = rho*thetaW;
5628  dmass[k] = -rho*DthetaW_DpsiC;
5629  /* remember to turn on nonlinear potential if you want to use total head */
5630  /*mwf unknown is psi*/
5631  phi[k] = -psiC;
5632  dphi[k] = 1.0;
5633 
5634  /*mwf unknown is h
5635  phi[k] = u[k];
5636  dphi[k] = 1.0;
5637  */
5638  for (I=0;I<nSpace;I++)
5639  {
5640  f[k*nSpace+I] = 0.0;
5641  df[k*nSpace+I] = 0.0;
5642  /*mwf unknown is psi*/
5643  phi[k] -= rho*gravity[I]*x[k*3+I];
5644 
5645  a[k*nSpace2+I*nSpace+I] = rho*KW;
5646  da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC;
5647  }
5648  }
5649 }
5650 
5651 void l2projectScalar(const int nSimplices,
5652  const int nPointsPerSimplex,
5653  double * dV,
5654  double * r)
5655 {
5656  int eN,k;
5657  double ravg,vol;
5658 
5659  for (eN = 0; eN < nSimplices; eN++)
5660  {
5661  ravg = 0.0; vol = 0.0;
5662  for (k=0; k < nPointsPerSimplex; k++)
5663  {
5664  vol += dV[eN*nPointsPerSimplex+k];
5665  ravg += r[eN*nPointsPerSimplex + k]*dV[eN*nPointsPerSimplex+k];
5666  }
5667 
5668  assert(vol > 0.0);
5669  ravg = ravg / vol;
5670  for (k=0; k < nPointsPerSimplex; k++)
5671  {
5672  r[eN*nPointsPerSimplex + k] = ravg;
5673  }
5674  }
5675 }
5676 void l2projectVector(const int nSimplices,
5677  const int nPointsPerSimplex,
5678  const int nSpace,
5679  double * dV,
5680  double * r)
5681 {
5682  int eN,k,I;
5683  double vol;
5684  /*need different max size, take a chance on variable length array?*/
5685  double ravg[nSpace];
5686  for (eN = 0; eN < nSimplices; eN++)
5687  {
5688  vol = 0.0;
5689  for (I=0; I < nSpace; I++)
5690  ravg[I] = 0.0;
5691  for (k=0; k < nPointsPerSimplex; k++)
5692  {
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];
5696  }
5697  assert(vol > 0.0);
5698  for (k=0; k < nPointsPerSimplex; k++)
5699  {
5700  for (I=0; I < nSpace; I++)
5701  r[eN*nPointsPerSimplex*nSpace + k*nSpace + I] = ravg[I]/vol;
5702  }
5703  }
5704 }
5705 void l2project2Tensor(const int nSimplices,
5706  const int nPointsPerSimplex,
5707  const int nSpace,
5708  double * dV,
5709  double * r)
5710 {
5711  int eN,k,I,J,nSpace2;
5712  double vol;
5713  /*need different max size, take a chance on variable length array?*/
5714  double ravg[nSpace*nSpace];
5715  nSpace2 = nSpace*nSpace;
5716  for (eN = 0; eN < nSimplices; eN++)
5717  {
5718  vol = 0.0;
5719  for (I=0; I < nSpace2; I++)
5720  ravg[I] = 0.0;
5721  for (k=0; k < nPointsPerSimplex; k++)
5722  {
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]
5727  *
5728  dV[eN*nPointsPerSimplex+k];
5729  }
5730  assert(vol > 0.0);
5731  for (k=0; k < nPointsPerSimplex; k++)
5732  {
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;
5736  }
5737  }
5738 }
5739 
5741  const int nPointsPerSimplex,
5742  const int nSpace,
5743  double pc_eps,
5744  const int * rowptr,
5745  const int * colind,
5746  const int* materialTypes,
5747  const double rho,
5748  const double beta,
5749  const double* gravity,
5750  const double* alpha,
5751  const double* n,
5752  const double* thetaR,
5753  const double* thetaSR,
5754  const double* KWs,
5755  double *u,
5756  double *mass,
5757  double *dmass,
5758  double *f,
5759  double *df,
5760  double *a,
5761  double *da,
5762  double* vol_frac)
5763 {
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,
5768  onePlus_pcBar_n,
5769  sBar,sqrt_sBar,DsBar_DpsiC,
5770  thetaW,DthetaW_DpsiC,
5771  vBar,vBar2,DvBar_DpsiC,
5772  KWr,DKWr_DpsiC,
5773  rho2=rho*rho,
5774  thetaS,
5775  rhom,drhom,m,
5776  betauStar;
5777  const int nnz = rowptr[nSpace];
5778  for (i=0; i < nSimplex; i++)
5779  {
5780  matID= materialTypes[i];
5781  for (j=0;j<nPointsPerSimplex;j++)
5782  {
5783  k = i*nPointsPerSimplex + j;
5784  psiC = -u[k];
5785  m = 1.0 - 1.0/n[matID];
5786  thetaS = thetaR[matID] + thetaSR[matID];
5787  if (psiC > 0.0)
5788  {
5789  pcBar = alpha[matID]*psiC;
5790  pcBarStar = fmax(pcBar,pc_eps);
5791 
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;
5796 
5797  sBar = pow(onePlus_pcBar_n,-m);
5798  /* using -mn = 1-n */
5799  DsBar_DpsiC = alpha[matID]*(1.0-n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5800 
5801  vBar = 1.0-pcBar_nM1*sBar;
5802  vBar2 = vBar*vBar;
5803  DvBar_DpsiC = -alpha[matID]*(n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5804 
5805  thetaW = thetaSR[matID]*sBar + thetaR[matID];
5806  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
5807 
5808  sqrt_sBar = sqrt(sBar);
5809  KWr= sqrt_sBar*vBar2;
5810  DKWr_DpsiC= ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5811  +
5812  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5813  }
5814  else
5815  {
5816  thetaW = thetaS;
5817  DthetaW_DpsiC = 0.0;
5818  KWr = 1.0;
5819  DKWr_DpsiC = 0.0;
5820  }
5821  //slight compressibility
5822  betauStar = fmin(beta*u[k],1000.0);
5823  rhom = rho*exp(betauStar);
5824  drhom = beta*rhom;
5825  mass[k] = rhom*thetaW;
5826  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5827  vol_frac[k] = thetaW;
5828  //mass[k] = rho*thetaW;
5829  //dmass[k] = -rho*DthetaW_DpsiC;
5830  for (I=0;I<nSpace;I++)
5831  {
5832  f[k*nSpace+I] = 0.0;
5833  df[k*nSpace+I] = 0.0;
5834  for (ii=rowptr[I]; ii < rowptr[I+1]; ii++)
5835  {
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];
5840  }/*m*/
5841  }/*I*/
5842  }/*k*/
5843  }/*j*/
5844 
5845 }
5846 
5848  const int nPointsPerSimplex,
5849  const int nSpace,
5850  double linear_break,
5851  const int * rowptr,
5852  const int * colind,
5853  const int* materialTypes,
5854  const double rho,
5855  const double beta,
5856  const double* gravity,
5857  const double* alpha,
5858  const double* n,
5859  const double* thetaR,
5860  const double* thetaSR,
5861  const double* KWs,
5862  double *u,
5863  double *mass,
5864  double *dmass,
5865  double *f,
5866  double *df,
5867  double *a,
5868  double *da,
5869  double* vol_frac)
5870 {
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,
5875  onePlus_pcBar_n,
5876  sBar,sqrt_sBar,DsBar_DpsiC,
5877  thetaW,DthetaW_DpsiC,
5878  vBar,vBar2,DvBar_DpsiC,
5879  KWr,DKWr_DpsiC,
5880  rho2=rho*rho,
5881  thetaS,
5882  rhom,drhom,m,
5883  betauStar;
5884  const int nnz = rowptr[nSpace];
5885  pcBarStar = linear_break;
5886 
5887  for (i=0; i < nSimplex; i++)
5888  {
5889  matID= materialTypes[i];
5890  for (j=0;j<nPointsPerSimplex;j++)
5891  {
5892  k = i*nPointsPerSimplex + j;
5893  psiC = -u[k];
5894  m = 1.0 - 1.0/n[matID];
5895  thetaS = thetaR[matID] + thetaSR[matID];
5896  if (psiC > 0.0)
5897  {
5898  pcBar = alpha[matID]*psiC;
5899  if (psiC <= pcBarStar)
5900  {
5901  /*calculate regularization parameters again because n varies*/
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;
5906 
5907  sBar = pow(onePlus_pcBar_n,-m);
5908  /* using -mn = 1-n */
5909  DsBar_DpsiC = alpha[matID]*(1.0-n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5910 
5911  vBar = 1.0-pcBar_nM1*sBar;
5912  vBar2 = vBar*vBar;
5913  DvBar_DpsiC = -alpha[matID]*(n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5914 
5915  sBarStar = sBar;
5916  sqrt_sBar = sqrt(sBar);
5917  KWrStar= sqrt_sBar*vBar2;
5918 
5919  /*now compute linearized solution*/
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;
5924 
5925  DKWr_DpsiC= (KWrStar - 1.0)/(pcBarStar-0.0);
5926  KWr = DKWr_DpsiC*(psiC-0.0) + 1.0;
5927  }
5928  else
5929  {
5930  pcBar = alpha[matID]*psiC;
5931  pcBarStar = fmax(pcBar,1.0e-8);
5932 
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;
5937 
5938  sBar = pow(onePlus_pcBar_n,-m);
5939  /* using -mn = 1-n */
5940  DsBar_DpsiC = alpha[matID]*(1.0-n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
5941 
5942  vBar = 1.0-pcBar_nM1*sBar;
5943  vBar2 = vBar*vBar;
5944  DvBar_DpsiC = -alpha[matID]*(n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
5945 
5946  thetaW = thetaSR[matID]*sBar + thetaR[matID];
5947  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
5948 
5949  sqrt_sBar = sqrt(sBar);
5950  KWr= sqrt_sBar*vBar2;
5951  DKWr_DpsiC= ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
5952  +
5953  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
5954 
5955  }
5956  }
5957  else
5958  {
5959  thetaW = thetaS;
5960  DthetaW_DpsiC = 0.0;
5961  KWr = 1.0;
5962  DKWr_DpsiC = 0.0;
5963  }
5964  //slight compressibility
5965  betauStar = fmin(beta*u[k],1000.0);
5966  rhom = rho*exp(betauStar);
5967  drhom = beta*rhom;
5968  mass[k] = rhom*thetaW;
5969  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
5970  vol_frac[k] = thetaW;
5971  //mass[k] = rho*thetaW;
5972  //dmass[k] = -rho*DthetaW_DpsiC;
5973  for (I=0;I<nSpace;I++)
5974  {
5975  f[k*nSpace+I] = 0.0;
5976  df[k*nSpace+I] = 0.0;
5977  for (ii=rowptr[I]; ii < rowptr[I+1]; ii++)
5978  {
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];
5983  }/*m*/
5984  }/*I*/
5985  }/*k*/
5986  }/*j*/
5987 
5988 }
5989 
5991  const int nPointsPerSimplex,
5992  const int nSpace,
5993  const int* materialTypes,
5994  const double rho,
5995  const double beta,
5996  const double* gravity,
5997  const double* alpha,
5998  const double* n,
5999  const double* thetaR,
6000  const double* thetaSR,
6001  const double* KWs,
6002  double *u,
6003  double *mass,
6004  double *dmass,
6005  double *f,
6006  double *df,
6007  double *a,
6008  double *da)
6009 {
6010  int i,j,k,I,matID;
6011  const int nSpace2=nSpace*nSpace;
6012  register double psiC,
6013  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6014  onePlus_pcBar_n,
6015  sBar,sqrt_sBar,DsBar_DpsiC,
6016  thetaW,DthetaW_DpsiC,
6017  vBar,vBar2,DvBar_DpsiC,
6018  KW,DKW_DpsiC,
6019  rho2=rho*rho,
6020  thetaS,
6021  rhom,drhom,m;
6022  for (i=0; i < nSimplex; i++)
6023  {
6024  matID= materialTypes[i];
6025  for (j=0;j<nPointsPerSimplex;j++)
6026  {
6027  k = i*nPointsPerSimplex + j;
6028  psiC = -u[k];
6029  m = 1.0 - 1.0/n[matID];
6030  thetaS = thetaR[matID] + thetaSR[matID];
6031  if (psiC > 0.0)
6032  {
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;
6038 
6039  sBar = pow(onePlus_pcBar_n,-m);
6040  /* using -mn = 1-n */
6041  DsBar_DpsiC = alpha[matID]*(1.0-n[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6042 
6043  vBar = 1.0-pcBar_nM1*sBar;
6044  vBar2 = vBar*vBar;
6045  DvBar_DpsiC = -alpha[matID]*(n[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6046 
6047  thetaW = thetaSR[matID]*sBar + thetaR[matID];
6048  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
6049 
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
6054  +
6055  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6056  }
6057  else
6058  {
6059  thetaW = thetaS;
6060  DthetaW_DpsiC = 0.0;
6061  KW = KWs[matID];
6062  DKW_DpsiC = 0.0;
6063  }
6064  //slight compressibility
6065  rhom = rho*exp(beta*u[k]);
6066  drhom = beta*rhom;
6067  mass[k] = rhom*thetaW;
6068  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
6069  //mass[k] = rho*thetaW;
6070  //dmass[k] = -rho*DthetaW_DpsiC;
6071  for (I=0;I<nSpace;I++)
6072  {
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;
6077  }/*I*/
6078  }/*k*/
6079  }/*j*/
6080 
6081 }
6082 
6083 void seepageBrezis(const int nSimplex,
6084  const int nPointsPerSimplex,
6085  const int nSpace,
6086  const int* materialTypes,
6087  const double epsFact,
6088  const double rho,
6089  const double beta,
6090  const double* elementDiameter,
6091  const double* gravity,
6092  const double* alpha,
6093  const double* n,
6094  const double* thetaR,
6095  const double* thetaSR,
6096  const double* KWs,
6097  double *u,
6098  double *mass,
6099  double *dmass,
6100  double *f,
6101  double *df,
6102  double *a,
6103  double *da)
6104 {
6105  int i,j,k,I,matID;
6106  const int nSpace2=nSpace*nSpace;
6107  register double psiC,
6108  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6109  onePlus_pcBar_n,
6110  sBar,sqrt_sBar,DsBar_DpsiC,
6111  thetaW,DthetaW_DpsiC,
6112  vBar,vBar2,DvBar_DpsiC,
6113  KW,DKW_DpsiC,
6114  rho2=rho*rho,
6115  thetaS,
6116  rhom,drhom,m,eps,hStar,dhStar;
6117  for (i=0; i < nSimplex; i++)
6118  {
6119  matID= materialTypes[i];
6120  eps = epsFact*elementDiameter[i];
6121  for (j=0;j<nPointsPerSimplex;j++)
6122  {
6123  k = i*nPointsPerSimplex + j;
6124  thetaS = thetaR[matID] + thetaSR[matID];
6125  /* hStar = linearHeaviside(eps,u[k]+eps)*(1.0-1.0e-5)+1.0e-5; */
6126  /* dhStar = linearDirac(eps,u[k]+eps)*(1.0-1.0e-5); */
6127  hStar = smoothedHeaviside(eps,u[k]+eps)*(1.0-1.0e-5)+1.0e-5;
6128  dhStar = smoothedDirac(eps,u[k]+eps)*(1.0-1.0e-5);
6129  mass[k] = thetaS*hStar;
6130  dmass[k] = thetaS*dhStar;
6131  for (I=0;I<nSpace;I++)
6132  {
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;
6137  }/*I*/
6138  }/*k*/
6139  }/*j*/
6140 
6141 }
6142 
6143 void conservativeHeadRichardsJLeverett(const int nSimplex,
6144  const int nPointsPerSimplex,
6145  const int nSpace,
6146  const int* materialTypes,
6147  const double rho,
6148  const double beta,
6149  const double* gravity,
6150  const double* phi,
6151  const double* psiD,
6152  const double* ns,
6153  const double* nk,
6154  const double* S_wirr,
6155  const double* S_nwr,
6156  const double* kr0,
6157  double *u,
6158  double *mass,
6159  double *dmass,
6160  double *f,
6161  double *df,
6162  double *a,
6163  double *da)
6164 {
6165  int i,j,k,I,matID;
6166  const int nSpace2=nSpace*nSpace;
6167  register double psiC,
6168  Se,Sw,dSw,
6169  kr,dkr,
6170  rho2=rho*rho,
6171  rhom,drhom;
6172  const double reg_diff=1.0e-2;
6173  for (i=0; i < nSimplex; i++)
6174  {
6175  matID= materialTypes[i];
6176  for (j=0;j<nPointsPerSimplex;j++)
6177  {
6178  k = i*nPointsPerSimplex + j;
6179  psiC = -u[k];
6180  if (psiC > 0.0 && psiC < psiD[matID])
6181  {
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];
6187  }
6188  else if (psiC <= 0.0)
6189  {
6190  Se = 1.0;
6191  Sw = 1.0 - S_nwr[matID];
6192  dSw = 0.0;
6193  kr = kr0[matID]+reg_diff;
6194  dkr = 0.0;
6195  }
6196  else
6197  {
6198  Se = 0.0;
6199  Sw = S_wirr[matID];
6200  dSw = 0.0;
6201  kr = reg_diff;
6202  dkr = 0.0;
6203  }
6204  //slight compressibility
6205  rhom = rho*exp(beta*u[k]);
6206  drhom = beta*rhom;
6207 
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++)
6211  {
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;
6216  }/*I*/
6217  }/*k*/
6218  }/*j*/
6219 }
6221  const int nPointsPerSimplex,
6222  const int nSpace,
6223  const int* materialTypes,
6224  const double rho,
6225  const double beta,
6226  const double* gravity,
6227  const double* phi,
6228  const double* psiD,
6229  const double* ns,
6230  const double* nk,
6231  const double* S_wirr,
6232  const double* S_nwr,
6233  const double* kr0x,
6234  const double* kr0y,
6235  const double* kr0z,
6236  double *u,
6237  double *mass,
6238  double *dmass,
6239  double *f,
6240  double *df,
6241  double *a,
6242  double *da)
6243 {
6244  int i,j,k,I,matID;
6245  const int nSpace2=nSpace*nSpace;
6246  register double psiC,pcBar,
6247  Se,dSe,Sw,dSw,
6248  kr,dkr,
6249  rho2=rho*rho,
6250  rhom,drhom;
6251  const double reg_diff=1.0e-2;
6252  for (i=0; i < nSimplex; i++)
6253  {
6254  matID= materialTypes[i];
6255  for (j=0;j<nPointsPerSimplex;j++)
6256  {
6257  k = i*nPointsPerSimplex + j;
6258  psiC = -u[k];
6259  if (psiC >= psiD[matID])
6260  {
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;
6270  }
6271  else
6272  {
6273  Se = 1.0;
6274  Sw = 1.0 - S_nwr[matID];
6275  dSw = 0.0;
6276  kr = 1.0;
6277  dkr = 0.0;
6278  }
6279 /* if (psiC > 0.0 && psiC < psiD[matID]) */
6280 /* { */
6281 /* Se = 1.0 - pow(psiC/psiD[matID],ns[matID]); */
6282 /* Sw = Se*(1.0 - S_wirr[matID] - S_nwr[matID]) + S_wirr[matID]; */
6283 /* dSw = (1.0 - S_wirr[matID] - S_nwr[matID])*pow(psiC/psiD[matID],ns[matID]-1.0)*ns[matID]/psiD[matID]; */
6284 /* kr = pow(Se,nk[matID])+reg_diff; */
6285 /* dkr = pow(Se,nk[matID]-1.0)*nk[matID]*pow(psiC/psiD[matID],ns[matID]-1.0)*ns[matID]/psiD[matID]; */
6286 /* } */
6287 /* else if (psiC <= 0.0) */
6288 /* { */
6289 /* Se = 1.0; */
6290 /* Sw = 1.0 - S_nwr[matID]; */
6291 /* dSw = 0.0; */
6292 /* kr = 1.0+reg_diff; */
6293 /* dkr = 0.0; */
6294 /* } */
6295 /* else */
6296 /* { */
6297 /* Se = 0.0; */
6298 /* Sw = S_wirr[matID]; */
6299 /* dSw = 0.0; */
6300 /* kr = reg_diff; */
6301 /* dkr = 0.0; */
6302 /* } */
6303  //slight compressibility
6304  rhom = rho*exp(beta*u[k]);
6305  drhom = beta*rhom;
6306 
6307  mass[k] = rhom*Sw*phi[matID];
6308  dmass[k] = rhom*dSw*phi[matID]+drhom*Sw*phi[matID];
6309  I=0;
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;
6314  if (nSpace > 1)
6315  {
6316  I=1;
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;
6321  if (nSpace > 2)
6322  {
6323  I=2;
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;
6328  }
6329  }
6330  }/*k*/
6331  }/*j*/
6332 }
6333 
6334 
6335 /* mwf end unnecessary additions */
6336 
6338  const int nSpace,
6339  const double rho,
6340  const double* gravity,
6341  const double* alpha,
6342  const double* n,
6343  const double* thetaR,
6344  const double* thetaSR,
6345  const double* KWs,
6346  double *u,
6347  double *mass,
6348  double *dmass,
6349  double *f,
6350  double *df,
6351  double *a,
6352  double *da)
6353 {
6354  int k,I;
6355  const int nSpace2=nSpace*nSpace;
6356  register double psiC,
6357  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
6358  onePlus_pcBar_n,
6359  sBar,sqrt_sBar,DsBar_DpsiC,
6360  thetaW,DthetaW_DpsiC,
6361  vBar,vBar2,DvBar_DpsiC,
6362  KW,DKW_DpsiC,
6363  rho2=rho*rho,
6364  thetaS,
6365  m;
6366  for (k=0;k<nPoints;k++)
6367  {
6368  psiC = -u[k];
6369  m = 1.0 - 1.0/n[k];
6370  thetaS = thetaR[k] + thetaSR[k];
6371  if (psiC > 0.0)
6372  {
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;
6378 
6379  sBar = pow(onePlus_pcBar_n,-m);
6380  /* using -mn = 1-n */
6381  DsBar_DpsiC = alpha[k]*(1.0-n[k])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6382 
6383  vBar = 1.0-pcBar_nM1*sBar;
6384  vBar2 = vBar*vBar;
6385  DvBar_DpsiC = -alpha[k]*(n[k]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6386 
6387  thetaW = thetaSR[k]*sBar + thetaR[k];
6388  DthetaW_DpsiC = thetaSR[k] * DsBar_DpsiC;
6389 
6390  sqrt_sBar = sqrt(sBar);
6391  KW= KWs[k]*sqrt_sBar*vBar2;
6392  DKW_DpsiC= KWs[k]*
6393  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
6394  +
6395  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6396  }
6397  else
6398  {
6399  thetaW = thetaS;
6400  DthetaW_DpsiC = 0.0;
6401  KW = KWs[k];
6402  DKW_DpsiC = 0.0;
6403  }
6404  mass[k] = rho*thetaW;
6405  dmass[k] = -rho*DthetaW_DpsiC;
6406  for (I=0;I<nSpace;I++)
6407  {
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;
6412  }
6413  }
6414 }
6415 
6419  const int nSpace,
6420  const double rho,
6421  const double* gravity,
6422  const double* x,
6423  const double alpha,
6424  const double n,
6425  const double m,
6426  const double thetaR,
6427  const double thetaSR,
6428  const double KWs,
6429  double *u,
6430  double *mass,
6431  double *dmass,
6432  double *f,
6433  double *df,
6434  double *a,
6435  double *da,
6436  double *phi,
6437  double *dphi)
6438 {
6439  int k,I;
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,
6444  onePlus_pcBar_n,
6445  sBar,sqrt_sBar,DsBar_DpsiC,
6446  thetaW,
6447  vBar,vBar2,DvBar_DpsiC,
6448  KW,DKW_DpsiC,
6449  rho2=rho*rho,
6450  thetaS=thetaR+thetaSR;
6451  for (k=0;k<nPoints;k++)
6452  {
6453  sBar = u[k];
6454  thetaW = thetaS*u[k];
6455  if (u[k] < 1.0-eps &&
6456  u[k] > 0.0+eps)
6457  {
6458  /* piggy back on head based formulas */
6459  psiC = pow(pow(sBar,-1.0/m)-1.0,1.0/n)/alpha;
6460 
6461  pcBar = alpha*psiC;
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;
6466 
6467  /* using -mn = 1-n */
6468  DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1;
6469 
6470  vBar = 1.0-pcBar_nM1*sBar;
6471  vBar2 = vBar*vBar;
6472  DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
6473 
6474  sqrt_sBar = sqrt(sBar);
6475  KW= KWs*sqrt_sBar*vBar2;
6476  DKW_DpsiC= KWs*
6477  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
6478  +
6479  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
6480  }
6481  else if (u[k] >= 1.0-eps)
6482  {
6483  psiC = 0.0;
6484  DsBar_DpsiC = -1.0;
6485  KW = KWs;
6486  DKW_DpsiC = 0.0;
6487  }
6488  else
6489  {
6490  psiC = pow(pow(eps,-1.0/m)-1.0,1.0/n)/alpha;
6491  DsBar_DpsiC = -1.0;
6492  KW = 0.0;
6493  DKW_DpsiC = 0.0;
6494  }
6495  mass[k] = rho*thetaW;
6496  dmass[k] = rho*thetaS;
6497  phi[k] = -psiC;
6498  dphi[k] = -1.0/DsBar_DpsiC;
6499  for (I=0;I<nSpace;I++)
6500  {
6501  f[k*nSpace+I] = rho2*KW*gravity[I];
6502  df[k*nSpace+I] = rho2*DKW_DpsiC*gravity[I]/DsBar_DpsiC;
6503  /* calculate the total head the slow way for now */
6504 /* f[k*nSpace+I] = 0.0; */
6505 /* df[k*nSpace+I] = 0.0; */
6506 /* phi[k] -= rho*gravity[I]*x[k*3+I]; */
6507  a[k*nSpace2+I*nSpace+I] = rho*KW;
6508  da[k*nSpace2+I*nSpace+I] = rho*DKW_DpsiC/DsBar_DpsiC;
6509  }
6510 /* /\* regularized diffusion *\/ */
6511 /* phi[k] = -psiC+9.0e-1*u[k];; */
6512 /* dphi[k] = -1.0/DsBar_DpsiC+9.0e-1; */
6513 /* for (I=0;I<nSpace;I++) */
6514 /* { */
6515 /* f[k*nSpace+I] = rho2*KW*gravity[I]; */
6516 /* df[k*nSpace+I] = rho2*DKW_DpsiC*gravity[I]/DsBar_DpsiC; */
6517 /* /\* calculate the total head the slow way for now *\/ */
6518 /* f[k*nSpace+I] = 0.0; */
6519 /* df[k*nSpace+I] = 0.0; */
6520 /* phi[k] -= rho*gravity[I]*x[k*3+I]; */
6521 /* a[k*nSpace2+I*nSpace+I] = rho*KW+9.0e-1; */
6522 /* da[k*nSpace2+I*nSpace+I] = rho*DKW_DpsiC/DsBar_DpsiC; */
6523 /* } */
6524  }
6525 }
6526 
6527 /* /\** Coefficients for the mass conservative Saturation equation for the fractional flow form of two-phase flow equations using Mualem-Van Genuchten. */
6528 /* *\/ */
6529 /* void conservativeTwophaseSaturationMualemVanGenuchtenHomEvaluate(const int nPoints, */
6530 /* const int nSpace, */
6531 /* const double rho, */
6532 /* const double* gravity, */
6533 /* const double alpha, */
6534 /* const double n, */
6535 /* const double m, */
6536 /* const double thetaR, */
6537 /* const double thetaSR, */
6538 /* const double KWs, */
6539 /* const double viscosityRatio, */
6540 /* const double densityRatio, */
6541 /* const double* v, */
6542 /* double *u, */
6543 /* double *mass, */
6544 /* double *dmass, */
6545 /* double *f, */
6546 /* double *df, */
6547 /* double *a, */
6548 /* double *da) */
6549 /* { */
6550 /* int k,I; */
6551 /* const int nSpace2=nSpace*nSpace; */
6552 /* register double psiC, */
6553 /* pcBar,pcBar_n,pcBar_nM1,pcBar_nM2, */
6554 /* onePlus_pcBar_n, */
6555 /* sBar,sqrt_sBar,DsBar_DpsiC, */
6556 /* thetaW,DthetaW_DpsiC, */
6557 /* vBar,vBar2,DvBar_DpsiC, */
6558 /* KW,DKW_DpsiC, */
6559 /* rho2=rho*rho, */
6560 /* thetaS=thetaR+thetaSR; */
6561 /* for (k=0;k<nPoints;k++) */
6562 /* { */
6563 /* sBar = fmin(fmax((u[k] - sIR)/sMir,0.0),1.0); */
6564 /* DsBar_Du = 1.0/sMIR; */
6565 
6566 /* onePlus_alphaPsiC_n = pow(sBar,1.0/-m); */
6567 /* alphaPsiC_n = onePlus_alphaPsiC_n - 1.0; */
6568 /* alphaPsiC = pow(alphaPsiC_n,1.0/n); */
6569 
6570 /* psiC = alphaPsiC/alpha; */
6571 
6572 /* alphaPsiC_nM1 = alphaPsiC_n/alphaPsiC; */
6573 /* sBarByOnePlus_alphaPsiC_n = sBar/onePlus_alphaPsiC_n; */
6574 /* DsBar_DpC = -alpha[i]*(n[i]-1.0)*alphaPsiC_nM1 */
6575 /* *sBarByOnePlus_alphaPsiC_n; */
6576 
6577 /* if(psiC<=0.0) */
6578 /* { */
6579 /* DsBar_DpC = 0.0; */
6580 /* } */
6581 /* } */
6582 
6583 
6584 /* inline void VanGenuchten2p::calculateDerivatives() */
6585 /* { */
6586 /* alphaPsiC_nM2 = alphaPsiC_nM1/alphaPsiC; */
6587 
6588 /* sBarBy_onePlus_alphaPsiC_n_2 = sBarByOnePlus_alphaPsiC_n */
6589 /* /onePlus_alphaPsiC_n; */
6590 /* DDsBar_DDpC = alpha[i]*alpha[i]*(n[i]-1) */
6591 /* *((2*n[i]-1)*alphaPsiC_nM1*alphaPsiC_nM1 */
6592 /* *sBarBy_onePlus_alphaPsiC_n_2 */
6593 /* - */
6594 /* (n[i]-1)*alphaPsiC_nM2 */
6595 /* *sBarByOnePlus_alphaPsiC_n); */
6596 
6597 /* if (psiC <= 0.0) */
6598 /* { */
6599 /* DDsBar_DDpC = 0.0; */
6600 /* } */
6601 /* } */
6602 /* psiC = -u[k]; */
6603 /* if (psiC > 0.0) */
6604 /* { */
6605 /* pcBar = alpha*psiC; */
6606 /* pcBar_nM2 = pow(pcBar,n-2); */
6607 /* pcBar_nM1 = pcBar_nM2*pcBar; */
6608 /* pcBar_n = pcBar_nM1*pcBar; */
6609 /* onePlus_pcBar_n = 1.0 + pcBar_n; */
6610 
6611 /* sBar = pow(onePlus_pcBar_n,-m); */
6612 /* /\* using -mn = 1-n *\/ */
6613 /* DsBar_DpsiC = alpha*(1.0-n)*(sBar/onePlus_pcBar_n)*pcBar_nM1; */
6614 
6615 /* vBar = 1.0-pcBar_nM1*sBar; */
6616 /* vBar2 = vBar*vBar; */
6617 /* DvBar_DpsiC = -alpha*(n-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC; */
6618 
6619 /* thetaW = thetaSR*sBar + thetaR; */
6620 /* DthetaW_DpsiC = thetaSR * DsBar_DpsiC; */
6621 
6622 /* sqrt_sBar = sqrt(sBar); */
6623 /* krw = sqrt_sBar*vBar2; */
6624 /* Dkrw_DpsiC= KWs* */
6625 /* ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2 */
6626 /* + */
6627 /* 2.0*sqrt_sBar*vBar*DvBar_DpsiC); */
6628 /* } */
6629 /* else */
6630 /* { */
6631 /* thetaW = thetaS; */
6632 /* DthetaW_DpsiC = 0.0; */
6633 /* KW = KWs; */
6634 /* DKW_DpsiC = 0.0; */
6635 /* } */
6636 /* mass[k] = rho*thetaW; */
6637 /* dmass[k] = -rho*DthetaW_DpsiC; */
6638 /* for (I=0;I<nSpace;I++) */
6639 /* { */
6640 /* f[k*nSpace+I] = rho2*KW*gravity[I]; */
6641 /* df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I]; */
6642 /* a[k*nSpace2+I*nSpace+I] = rho*KW; */
6643 /* da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC; */
6644 /* } */
6645 /* } */
6646 /* } */
6647 
6649  const int nSpace,
6650  const double rho,
6651  const double* gravity,
6652  const double* lambda,
6653  const double* pd,
6654  const double* thetaR,
6655  const double* thetaS,
6656  const double* KWs,
6657  double *u,
6658  double *mass,
6659  double *dmass,
6660  double *f,
6661  double *df,
6662  double *a,
6663  double *da)
6664 {
6665  int k,I;
6666  const int nSpace2=nSpace*nSpace;
6667  register double psiC,
6668  pcBar,
6669  sBar,DsBar_DpsiC,
6670  thetaW,DthetaW_DpsiC,
6671  KW,DKW_DpsiC,
6672  rho2=rho*rho,thetaSR;
6673  for (k=0;k<nPoints;k++)
6674  {
6675  psiC = -u[k];
6676  if (psiC >= pd[k])
6677  {
6678  pcBar = psiC/pd[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;
6686  }
6687  else
6688  {
6689  thetaW = thetaS[k];
6690  DthetaW_DpsiC = 0.0;
6691  KW = KWs[k];
6692  DKW_DpsiC = 0.0;
6693  }
6694  mass[k] = rho*thetaW;
6695  dmass[k] = -rho*DthetaW_DpsiC;
6696  for (I=0;I<nSpace;I++)
6697  {
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;
6702  }
6703  }
6704 }
6705 
6707  const int nSpace,
6708  const double rho,
6709  const double beta,
6710  const double* gravity,
6711  const double lambda,
6712  const double pd,
6713  const double thetaR,
6714  const double thetaSR,
6715  const double KWs,
6716  double *u,
6717  double *mass,
6718  double *dmass,
6719  double *f,
6720  double *df,
6721  double *a,
6722  double *da)
6723 {
6724  int k,I;
6725  const int nSpace2=nSpace*nSpace;
6726  register double psiC,
6727  pcBar,
6728  sBar,DsBar_DpsiC,
6729  thetaW,DthetaW_DpsiC,
6730  KW,DKW_DpsiC,
6731  rho2=rho*rho,
6732  thetaS=thetaR+thetaSR,
6733  rhom,drhom;
6734 
6735 /* /\* see what the Lipschitz constants are like *\/ */
6736 /* pcBar = 1.0; */
6737 /* sBar = pow(pcBar, -lambda); */
6738 /* DsBar_DpsiC = -lambda*sBar/(pcBar*pd); */
6739 /* /\* DsBar_DpsiC = -lambda*sBar/psiC; *\/ */
6740 /* KW = KWs*pow(sBar, (2+3*lambda)/lambda); */
6741 /* DKW_DpsiC = KWs*((2+3*lambda)/lambda*pow(sBar, 2/lambda*(1+lambda))*DsBar_DpsiC); */
6742 /* thetaW = thetaSR*sBar + thetaR; */
6743 /* DthetaW_DpsiC = thetaSR*DsBar_DpsiC; */
6744 /* k=0; */
6745 /* mass[k] = rho*thetaW; */
6746 /* dmass[k] = -rho*DthetaW_DpsiC; */
6747 /* for (I=0;I<nSpace;I++) */
6748 /* { */
6749 /* f[k*nSpace+I] = rho2*KW*gravity[I]; */
6750 /* df[k*nSpace+I] = -rho2*DKW_DpsiC*gravity[I]; */
6751 /* a[k*nSpace2+I*nSpace+I] = rho*KW; */
6752 /* da[k*nSpace2+I*nSpace+I] = -rho*DKW_DpsiC; */
6753 /* } */
6754 /* printf("m = %12.5e \ndm=%12.5e \nf=%12.5e \ndf=%12.5e \na=%12.5e \nda=%12.5e\n",mass[k],dmass[k],f[k],df[k],a[k],da[k]); */
6755  for (k=0;k<nPoints;k++)
6756  {
6757  psiC = -u[k];
6758  if (psiC >= pd)
6759  {
6760  pcBar = psiC/pd;
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;
6767 /* /\*cek stupid version *\/ */
6768 /* sBar = pow(psiC/pd,-lambda); */
6769 /* DsBar_DpsiC = -lambda*pow(psiC/pd,-lambda-1.0)/pd; */
6770 /* KW = KWs*pow(sBar,(2.0+3.0*lambda)/lambda); */
6771 /* DKW_DpsiC = KWs*((2.0+3.0*lambda)/lambda)*pow(sBar,(2.0+3.0*lambda)/lambda - 1.0)*DsBar_DpsiC; */
6772 /* thetaW = thetaSR*sBar + thetaR; */
6773 /* DthetaW_DpsiC = thetaSR*DsBar_DpsiC; */
6774  }
6775  else
6776  {
6777  thetaW = thetaS;
6778  DthetaW_DpsiC = 0.0;
6779  KW = KWs;
6780  DKW_DpsiC = 0.0;
6781  }
6782  //slight compressibility
6783  rhom = rho*exp(beta*u[k]);
6784  drhom = beta*rhom;
6785 
6786  mass[k] = rhom*thetaW;
6787  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
6788  for (I=0;I<nSpace;I++)
6789  {
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;
6794  }
6795  }
6796 }
6797 
6799  const int nSpace,
6800  const double rho,
6801  const double* gravity,
6802  const double lambda,
6803  const double pd,
6804  const double thetaR,
6805  const double thetaSR,
6806  const double KWs,
6807  double *u,
6808  double *mass,
6809  double *dmass,
6810  double *f,
6811  double *df,
6812  double *a,
6813  double *da,
6814  double *phi,
6815  double *dphi)
6816 {
6817  int k,I;
6818  const int nSpace2=nSpace*nSpace;
6819  register double psiC=0.0,
6820  pcBar,
6821  sBar,DsBar_DpsiC=0.0,
6822  thetaW,DthetaW_DpsiC=0.0,
6823  KW,DKW_DpsiC,
6824  rho2=rho*rho,
6825  thetaS=thetaR+thetaSR;
6826  for (k=0;k<nPoints;k++)
6827  {
6828  sBar = u[k];
6829  thetaW = thetaS*sBar;
6830  if (u[k] < 1.0)
6831  {
6832  psiC = pow(sBar, -1/lambda)*pd;
6833  /* pcBar = pow(sBar, -1/lambda); */
6834 
6835  /* same as before */
6836  pcBar = psiC/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;
6843  }
6844  else
6845  {
6846  KW = KWs;
6847  DKW_DpsiC = 0.0;
6848  }
6849  mass[k] = rho*thetaW;
6850  dmass[k] = -rho*DthetaW_DpsiC;
6851  phi[k] = -psiC;
6852  dphi[k] = -1.0/DsBar_DpsiC;
6853  for (I=0;I<nSpace;I++)
6854  {
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;
6859  }
6860  }
6861 }
6862 
6863 
6865  const int nSpace,
6866  const double rho,
6867  const double* gravity,
6868  const double alpha,
6869  const double n,
6870  const double m,
6871  const double thetaR,
6872  const double thetaSR,
6873  const double KWs,
6874  double *u,
6875  double *mass,
6876  double *dmass,
6877  double *f,
6878  double *df,
6879  double *a,
6880  double *da)
6881 {
6882  int k,I;
6883  const int nSpace2=nSpace*nSpace;
6884  register double psiC,
6885  pcBar,pd,lambda,
6886  sBar,DsBar_DpsiC,
6887  thetaW,DthetaW_DpsiC,
6888  KW,DKW_DpsiC,
6889  rho2=rho*rho,
6890  thetaS=thetaR+thetaSR;
6891  for (k=0;k<nPoints;k++)
6892  {
6893  psiC = -u[k];
6894  /* alternative representations given in Johns paper */
6895  pd = 1/alpha;
6896  lambda = n-1;
6897  /* printf("pd = %10.6e\t lambda = %10.6e\n", pd, lambda); */
6898  /* I do not know if this will work; cite Russell Johns paper */
6899  /* lambda = m/(1-m)*(1-pow(0.5,1/m));
6900  thetaStar=0.72-0.35*exp(-pow(n,4));
6901  pd = pow(thetaStar,1/lambda)/alpha*pow(pow(thetaStar,-1/m)-1, 1-m); */
6902  if (psiC > pd)
6903  {
6904  pcBar = psiC/pd;
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;
6911  }
6912  else
6913  {
6914  thetaW = thetaS;
6915  DthetaW_DpsiC = 0.0;
6916  KW = KWs;
6917  DKW_DpsiC = 0.0;
6918  }
6919  mass[k] = rho*thetaW;
6920  dmass[k] = -rho*DthetaW_DpsiC;
6921  for (I=0;I<nSpace;I++)
6922  {
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;
6927  }
6928  }
6929 }
6930 
6931 /* jcc for two phase flow in porous media, modified by cek and mwf*/
6932 
6933 /* int psk_set(int pskModelFlag, */
6934 /* double* rwork, */
6935 /* double mvg_m, */
6936 /* double alpha, */
6937 /* double bc_lambda, */
6938 /* double bc_pd, */
6939 /* int (**psk_eval)(double Se, */
6940 /* double *rwork, */
6941 /* double *krw, */
6942 /* double *dkrw, */
6943 /* double *krn, */
6944 /* double *dkrn, */
6945 /* double *psic, */
6946 /* double *dpsic)) */
6947 /* { */
6948 /* if(pskModelFlag == 0) */
6949 /* { */
6950 /* *psk_eval = psk_eval_simp; */
6951 /* } */
6952 /* else if(pskModelFlag == 1) */
6953 /* { */
6954 /* *psk_eval = psk_eval_VGM; */
6955 /* rwork[0] = mvg_m; */
6956 /* rwork[1] = alpha; */
6957 /* } */
6958 /* else if(pskModelFlag == 2) */
6959 /* { */
6960 /* *psk_eval = psk_eval_VGB; */
6961 /* rwork[0] = mvg_m; */
6962 /* rwork[1] = alpha; */
6963 /* } */
6964 /* else if(pskModelFlag == 3) */
6965 /* { */
6966 /* *psk_eval = psk_eval_BCM; */
6967 /* rwork[0] = bc_lambda; */
6968 /* rwork[1] = bc_pd; */
6969 /* } */
6970 /* else if(pskModelFlag == 4) */
6971 /* { */
6972 /* *psk_eval = psk_eval_BCB; */
6973 /* rwork[0] = bc_lambda; */
6974 /* rwork[1] = bc_pd; */
6975 /* } */
6976 /* else */
6977 /* { */
6978 /* printf("Error with pskModelFlag, using simple quadratic model \n"); */
6979 /* *psk_eval = psk_eval_simp; */
6980 /* return 1; */
6981 /* } */
6982 /* return 0; */
6983 /* } */
6984 
6985 /* void FractionalFlowPhaseForm_saturationEvaluate( */
6986 /* const int nPoints, */
6987 /* const int nSpace, */
6988 /* const int nc, */
6989 /* const int pskModelFlag, */
6990 /* const double Kbar, */
6991 /* const double rhon, */
6992 /* const double rhow, */
6993 /* const double *g, */
6994 /* const double g_norm, */
6995 /* const double alpha, */
6996 /* const double bc_lambda, */
6997 /* const double bc_pd, */
6998 /* const double mvg_n, */
6999 /* const double mvg_m, */
7000 /* const double omega, */
7001 /* const double mun, */
7002 /* const double muw, */
7003 /* const double sw_min, */
7004 /* const double sw_max, */
7005 /* const double M, */
7006 /* const double R, */
7007 /* const double Temp, */
7008 /* const double p_o, */
7009 /* const double b, */
7010 /* double *u, */
7011 /* double *m, */
7012 /* double *dm, */
7013 /* double *phi, */
7014 /* double *dphi, */
7015 /* double *f, */
7016 /* double *df, */
7017 /* double *a, */
7018 /* double *da, */
7019 /* double *q_t, */
7020 /* double *psiw) */
7021 /* { */
7022 /* int (*psk_eval)(double Se, */
7023 /* double *rwork, */
7024 /* double *krw, */
7025 /* double *dkrw, */
7026 /* double *krn, */
7027 /* double *dkrn, */
7028 /* double *psic, */
7029 /* double *dpsic); */
7030 /* double rwork[2]; */
7031 /* psk_set(pskModelFlag,rwork,mvg_m,alpha,bc_lambda,bc_pd,&psk_eval); */
7032 /* int i, pi,I; */
7033 /* const int nSpace2=nSpace*nSpace; */
7034 /* double Se,dSe_dSw,krw,krn,dkrw,dkrn,psi,dpsi; */
7035 /* double lambdaw,dlambdaw; */
7036 /* double lambdan,dlambdan; */
7037 /* double lambdat,dlambdat; */
7038 /* /\* double dlambdaw_psiw,dlambdan_psiw,dlambdat_psiw; *\/ */
7039 /* double fw,dfw,fn,dfn; */
7040 /* /\* double dfw_psiw,dfn_psiw; *\/ */
7041 /* double RHON,dRHON,dRHON_psiw; */
7042 
7043 /* double omega_rhow = omega*rhow; */
7044 
7045 /* for(i=0;i<nc;i++) */
7046 /* { */
7047 /* for (pi=0;pi<nPoints;pi++) */
7048 /* { */
7049 /* effectiveSaturation(u[pi],sw_min,sw_max,&Se,&dSe_dSw); */
7050 /* psk_eval(Se,rwork,&krw,&dkrw,&krn,&dkrn,&psi,&dpsi); */
7051 /* dkrw*=dSe_dSw; */
7052 /* dkrn*=dSe_dSw; */
7053 /* dpsi*=dSe_dSw; */
7054 /* /\* Get the auxiliary variables for a compressable wetting phase. *\/ */
7055 /* /\* psk_auxVarCom_n_phase(krw,dkrw,krn,dkrn,psi,dpsi, *\/ */
7056 /* /\* rhow,rhon,muw,mun,g_norm,u[pi],M,R,Temp,p_o, *\/ */
7057 /* /\* &lambdaw,&dlambdaw,&dlambdaw_psiw,&RHON,&dRHON,&dRHON_psiw, *\/ */
7058 /* /\* &lambdan,&dlambdan,&dlambdan_psiw,&lambdat,&dlambdat,&dlambdat_psiw, *\/ */
7059 /* /\* &fw,&dfw,&dfw_psiw,&fn,&dfn,&dfn_psiw); *\/ */
7060 
7061 /* psk_auxVar(krw, */
7062 /* dkrw, */
7063 /* krn, */
7064 /* dkrn, */
7065 /* psi, */
7066 /* dpsi, */
7067 /* rhow, */
7068 /* rhon, */
7069 /* muw, */
7070 /* mun, */
7071 /* &lambdaw, */
7072 /* &dlambdaw, */
7073 /* &lambdan, */
7074 /* &dlambdan, */
7075 /* &lambdat, */
7076 /* &dlambdat, */
7077 /* &fw, */
7078 /* &dfw, */
7079 /* &fn, */
7080 /* &dfn); */
7081 /* RHON=rhon; */
7082 /* dRHON_psiw=0.0; */
7083 /* dRHON=0.0; */
7084 /* /\* dlambdan_psiw=0.0; *\/ */
7085 /* /\* dlambdat_psiw=0.0; *\/ */
7086 /* /\* dfn_psiw=0.0; *\/ */
7087 
7088 /* m[pi] = omega_rhow*(u[pi]*(sw_max-sw_min)+sw_min); */
7089 /* dm[pi] = omega_rhow*(sw_max-sw_min); */
7090 
7091 /* phi[pi] = psi; */
7092 /* dphi[pi]= dpsi; */
7093 
7094 /* for (I=0;I<nSpace;I++) */
7095 /* { */
7096 /* f[pi*nSpace+I] = q_t[pi*nSpace+I]*fw - Kbar*lambdaw*fn*(b*RHON-rhow)*g[I]; */
7097 /* df[pi*nSpace+I] = q_t[pi*nSpace+I]*dfw */
7098 /* - (Kbar*dlambdaw*fn*(b*RHON-rhow)*g[I]+ */
7099 /* Kbar*lambdaw*dfn*(b*RHON-rhow)*g[I]+ */
7100 /* Kbar*lambdaw*fn*(b*dRHON-rhow)*g[I]); */
7101 
7102 /* a[pi*nSpace2+I*nSpace+I] = -Kbar*lambdaw*fn; */
7103 /* da[pi*nSpace2+I*nSpace+I] = -Kbar*(dlambdaw*fn + lambdaw*dfn); */
7104 /* } */
7105 /* } */
7106 /* } */
7107 /* } */
7108 
7109 
7110 /* void FractionalFlowPhaseForm_potentialEvaluate( */
7111 /* const int nPoints, */
7112 /* const int nSpace, */
7113 /* const int nc, */
7114 /* const int pskModelFlag, */
7115 /* const double Kbar, */
7116 /* const double rhon, */
7117 /* const double rhow, */
7118 /* const double *g, */
7119 /* const double g_norm, */
7120 /* const double alpha, */
7121 /* const double bc_lambda, */
7122 /* const double bc_pd, */
7123 /* const double mvg_n, */
7124 /* const double mvg_m, */
7125 /* const double omega, */
7126 /* const double mun, */
7127 /* const double muw, */
7128 /* const double sw_min, */
7129 /* const double sw_max, */
7130 /* const double M, */
7131 /* const double R, */
7132 /* const double Temp, */
7133 /* const double p_o, */
7134 /* const double b, */
7135 /* double *u, */
7136 /* double *m, */
7137 /* double *dm, */
7138 /* double *phi, */
7139 /* double *dphi, */
7140 /* double *f, */
7141 /* double *df, */
7142 /* double *a, */
7143 /* double *da, */
7144 /* double *s_w, */
7145 /* double *grad_psic) */
7146 /* { */
7147 /* int (*psk_eval)(double Se, */
7148 /* double *rwork, */
7149 /* double *krw, */
7150 /* double *dkrw, */
7151 /* double *krn, */
7152 /* double *dkrn, */
7153 /* double *psic, */
7154 /* double *dpsic); */
7155 /* double rwork[2]; */
7156 /* psk_set(pskModelFlag,rwork,mvg_m,alpha,bc_lambda,bc_pd,&psk_eval); */
7157 /* int i, pi,I; */
7158 /* const int nSpace2=nSpace*nSpace; */
7159 /* double sw; */
7160 /* double dSe_dSw,Se,krw,krn,dkrw,dkrn,psi,dpsi; */
7161 /* double lambdaw,dlambdaw;/\* ,dlambdaw_psiw; *\/ */
7162 /* double lambdan,dlambdan,dlambdan_psiw; */
7163 /* double lambdat,dlambdat,dlambdat_psiw; */
7164 /* double fw,dfw,fn,dfn; */
7165 /* double dfn_psiw;/\* dfw_psiw *\/ */
7166 /* double RHON,dRHON,dRHON_psiw; */
7167 
7168 /* for(i=0;i<nc;i++) */
7169 /* { */
7170 /* for (pi=0;pi<nPoints;pi++) */
7171 /* { */
7172 /* if (s_w[pi] < sw_min) */
7173 /* { */
7174 /* Se = 0.0; */
7175 /* dSe_dSw = 0.0; */
7176 /* } */
7177 /* else if (s_w[pi] > sw_max) */
7178 /* { */
7179 /* Se = 1.0; */
7180 /* dSe_dSw =0.0; */
7181 /* } */
7182 /* else */
7183 /* { */
7184 /* Se = (s_w[pi] - sw_min)/(sw_max-sw_min); */
7185 /* dSe_dSw = 1.0/(sw_max - sw_min); */
7186 /* } */
7187 /* /\* Get the psk relation values *\/ */
7188 /* psk_eval(s_w[pi],rwork,&krw,&dkrw,&krn,&dkrn,&psi,&dpsi); */
7189 /* dkrw*=dSe_dSw; */
7190 /* dkrn*=dSe_dSw; */
7191 /* dpsi*=dSe_dSw; */
7192 
7193 /* /\* Get the auxiliary variables *\/ */
7194 
7195 /* /\* psk_auxVarCom_n_phase(krw,dkrw,krn,dkrn,psi,dpsi, *\/ */
7196 /* /\* rhow,rhon,muw,mun,g_norm,u[pi],M,R,Temp,p_o, *\/ */
7197 /* /\* &lambdaw,&dlambdaw,&dlambdaw_psiw,&RHON,&dRHON,&dRHON_psiw, *\/ */
7198 /* /\* &lambdan,&dlambdan,&dlambdan_psiw,&lambdat,&dlambdat,&dlambdat_psiw, *\/ */
7199 /* /\* &fw,&dfw,&dfw_psiw,&fn,&dfn,&dfn_psiw); *\/ */
7200 
7201 /* psk_auxVar(krw, */
7202 /* dkrw, */
7203 /* krn, */
7204 /* dkrn, */
7205 /* psi, */
7206 /* dpsi, */
7207 /* rhow, */
7208 /* rhon, */
7209 /* muw, */
7210 /* mun, */
7211 /* &lambdaw, */
7212 /* &dlambdaw, */
7213 /* &lambdan, */
7214 /* &dlambdan, */
7215 /* &lambdat, */
7216 /* &dlambdat, */
7217 /* &fw, */
7218 /* &dfw, */
7219 /* &fn, */
7220 /* &dfn); */
7221 /* RHON=rhon; */
7222 /* dRHON_psiw=0.0; */
7223 /* dRHON=0.0; */
7224 /* dlambdan_psiw=0.0; */
7225 /* dlambdat_psiw=0.0; */
7226 /* dfn_psiw=0.0; */
7227 
7228 /* m[pi] = omega*((sw*(sw_max-sw_min)+sw_min)*(rhow-RHON) + RHON); */
7229 /* dm[pi] = -omega*(sw*(sw_max-sw_min)+sw_min)*dRHON_psiw + omega*dRHON_psiw; */
7230 
7231 /* phi[pi] = u[pi]; */
7232 /* dphi[pi] = 1.0; */
7233 /* for (I=0;I<nSpace;I++) */
7234 /* { */
7235 /* f[pi*nSpace+I] = - Kbar*lambdat*(fn*grad_psic[pi*nSpace+I]) + Kbar*lambdat*(rhow + fn*(b*RHON-rhow))*g[I]; */
7236 /* df[pi*nSpace+I] = ( -Kbar*grad_psic[pi*nSpace+I]*( lambdat*dfn_psiw + fn*dlambdat_psiw ) */
7237 /* +Kbar*g[I]*( dlambdat_psiw*(rhow + fn*(b*RHON-rhow) ) */
7238 /* + lambdat*( dfn_psiw*(b*RHON - rhow) */
7239 /* + fn*(b*dRHON_psiw) ) ) ); */
7240 
7241 /* a[pi*nSpace2+I*nSpace+I] = Kbar*lambdat; */
7242 /* da[pi*nSpace2+I*nSpace+I] = Kbar*dlambdat_psiw; */
7243 /* } */
7244 /* } */
7245 /* } */
7246 /* } */
7247 
7248 /* void FractionalFlowPhaseForm_saturationHetEvaluate( */
7249 /* const int nPoints, */
7250 /* const int nSpace, */
7251 /* const int nc, */
7252 /* const int pskModelFlag, */
7253 /* const double *Kbar, */
7254 /* const double rhon, */
7255 /* const double rhow, */
7256 /* const double *g, */
7257 /* const double *alpha, */
7258 /* const double *bc_lambda, */
7259 /* const double *bc_pd, */
7260 /* const double *mvg_m, */
7261 /* const double *thetaS, */
7262 /* const double *thetaR, */
7263 /* const double mun, */
7264 /* const double muw, */
7265 /* const double b, */
7266 /* double *u, */
7267 /* double *m, */
7268 /* double *dm, */
7269 /* double *phi, */
7270 /* double *dphi, */
7271 /* double *f, */
7272 /* double *df, */
7273 /* double *a, */
7274 /* double *da, */
7275 /* double *q_t) */
7276 /* { */
7277 /* int (*psk_eval)(double Se, */
7278 /* double *rwork, */
7279 /* double *krw, */
7280 /* double *dkrw, */
7281 /* double *krn, */
7282 /* double *dkrn, */
7283 /* double *psic, */
7284 /* double *dpsic); */
7285 /* double rwork[2]; */
7286 /* psk_set(pskModelFlag,rwork,mvg_m[0],alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
7287 /* int i, pi,I; */
7288 /* const int nSpace2=nSpace*nSpace; */
7289 /* double krw,krn,dkrw,dkrn,psic,dpsic; */
7290 /* double lambdaw,dlambdaw,lambdan,dlambdan,lambdat,dlambdat,fw,dfw,fn,dfn; */
7291 
7292 /* for(i=0;i<nc;i++){ */
7293 /* for (pi=0;pi<nPoints;pi++) */
7294 /* { */
7295 /* if((pskModelFlag==1)||(pskModelFlag==2)) */
7296 /* { */
7297 /* rwork[0] = mvg_m[pi]; */
7298 /* rwork[1] = alpha[pi]; */
7299 /* } */
7300 /* else if ((pskModelFlag==3)||(pskModelFlag==4)) */
7301 /* { */
7302 /* rwork[0] = bc_lambda[pi]; */
7303 /* rwork[1] = bc_pd[pi]; */
7304 /* } */
7305 /* psk_eval(u[pi],rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7306 
7307 /* /\* Get the auxiliary variables *\/ */
7308 /* psk_auxVar(krw,dkrw,krn,dkrn,psic,dpsic, */
7309 /* rhow,rhon,muw,mun, */
7310 /* &lambdaw,&dlambdaw,&lambdan,&dlambdan,&lambdat, */
7311 /* &dlambdat,&fw,&dfw,&fn,&dfn); */
7312 
7313 /* m[pi] = rhow*( (thetaS[pi]-thetaR[pi])*u[pi] + thetaR[pi] ); */
7314 /* dm[pi] = rhow*(thetaS[pi]-thetaR[pi]); */
7315 
7316 /* phi[pi] = psic; */
7317 /* dphi[pi]= dpsic; */
7318 
7319 /* for (I=0;I<nSpace;I++) */
7320 /* { */
7321 /* f[pi*nSpace+I] = (q_t[pi*nSpace+I]*fw */
7322 /* - Kbar[pi]*lambdaw*fn*(b*rhon-rhow)*g[I]) ; */
7323 /* df[pi*nSpace+I] = (q_t[pi*nSpace+I]*dfw */
7324 /* - (Kbar[pi]*g[I]*(b*rhon-rhow))*(lambdaw*dfn + fn*dlambdaw)); */
7325 
7326 /* a[pi*nSpace2+I*nSpace+I] = -Kbar[pi]*lambdaw*fn; */
7327 /* da[pi*nSpace2+I*nSpace+I] = -Kbar[pi]*(dlambdaw*fn + lambdaw*dfn); */
7328 /* } */
7329 /* } */
7330 /* } */
7331 /* } */
7332 
7333 /* void FractionalFlowPhaseForm_potentialHetEvaluate( */
7334 /* const int nPoints, */
7335 /* const int nSpace, */
7336 /* const int nc, */
7337 /* const int pskModelFlag, */
7338 /* const double *Kbar, */
7339 /* const double rhon, */
7340 /* const double rhow, */
7341 /* const double *g, */
7342 /* const double *alpha, */
7343 /* const double *bc_lambda, */
7344 /* const double *bc_pd, */
7345 /* const double *mvg_m, */
7346 /* const double *thetaS, */
7347 /* const double *thetaR, */
7348 /* const double mun, */
7349 /* const double muw, */
7350 /* const double b, */
7351 /* double *u, */
7352 /* double *m, */
7353 /* double *dm, */
7354 /* double *phi, */
7355 /* double *dphi, */
7356 /* double *f, */
7357 /* double *df, */
7358 /* double *a, */
7359 /* double *da, */
7360 /* double *s_w, */
7361 /* double *grad_psic) */
7362 /* { */
7363 /* int (*psk_eval)(double Se, */
7364 /* double *rwork, */
7365 /* double *krw, */
7366 /* double *dkrw, */
7367 /* double *krn, */
7368 /* double *dkrn, */
7369 /* double *psic, */
7370 /* double *dpsic); */
7371 /* double rwork[2]; */
7372 /* psk_set(pskModelFlag,rwork,mvg_m[0],alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
7373 /* int i, pi,I; */
7374 /* const int nSpace2=nSpace*nSpace; */
7375 /* double krw,krn,dkrw,dkrn,psi,dpsi; */
7376 /* double lambdaw,dlambdaw,lambdan,dlambdan,lambdat,dlambdat,fw,dfw,fn,dfn; */
7377 
7378 /* for(i=0;i<nc;i++) */
7379 /* { */
7380 /* for (pi=0;pi<nPoints;pi++) */
7381 /* { */
7382 /* if((pskModelFlag==1)||(pskModelFlag==2)) */
7383 /* { */
7384 /* rwork[0] = mvg_m[pi]; */
7385 /* rwork[1] = alpha[pi]; */
7386 /* } */
7387 /* else if ((pskModelFlag==3)||(pskModelFlag==4)) */
7388 /* { */
7389 /* rwork[0] = bc_lambda[pi]; */
7390 /* rwork[1] = bc_pd[pi]; */
7391 /* } */
7392 /* /\* Get the psk relation values *\/ */
7393 /* psk_eval(s_w[pi],rwork,&krw,&dkrw,&krn,&dkrn,&psi,&dpsi); */
7394 
7395 /* /\* Get the auxiliary variables *\/ */
7396 /* psk_auxVar(krw,dkrw,krn,dkrn,psi,dpsi, */
7397 /* rhow,rhon,muw,mun, */
7398 /* &lambdaw,&dlambdaw,&lambdan,&dlambdan,&lambdat, */
7399 /* &dlambdat,&fw,&dfw,&fn,&dfn); */
7400 
7401 /* m[pi] = ((thetaS[pi]-thetaR[pi])*s_w[pi] + thetaR[pi])*(rhow-rhon) + thetaS[pi]*rhon; */
7402 /* dm[pi] = 0.0; */
7403 
7404 /* phi[pi] = u[pi]; */
7405 /* dphi[pi]= 1.0; */
7406 
7407 /* for (I=0;I<nSpace;I++) */
7408 /* { */
7409 /* f[pi*nSpace+I] = -Kbar[pi]*lambdat*( fn*grad_psic[pi*nSpace+I] - (rhow + fn*(b*rhon-rhow))*g[I] ); */
7410 /* df[pi*nSpace+I] = 0.0; */
7411 
7412 /* a[pi*nSpace2+I*nSpace+I] = Kbar[pi]*lambdat; */
7413 /* da[pi*nSpace2+I*nSpace+I] = 0.0; */
7414 /* } */
7415 /* } */
7416 /* } */
7417 /* } */
7418 
7419 /* /\* end jcc additions for two phase flow *\/ */
7420 
7421 /* void TwophaseDarcyFC_Evaluate(const int nPoints, */
7422 /* const int nSpace, */
7423 /* const int pskModelFlag, */
7424 /* const double Kbar, */
7425 /* const double rhon, */
7426 /* const double rhow, */
7427 /* const double *g, */
7428 /* const double *x, */
7429 /* const double alpha, */
7430 /* const double bc_lambda, */
7431 /* const double bc_pd, */
7432 /* const double mvg_n, */
7433 /* const double mvg_m, */
7434 /* const double omega, */
7435 /* const double omega_r, */
7436 /* const double mun, */
7437 /* const double muw, */
7438 /* const double b, */
7439 /* double *sw, */
7440 /* double *psiw, */
7441 /* double *mw, */
7442 /* double *dmw, */
7443 /* double *mn, */
7444 /* double *dmn, */
7445 /* double *phi_psiw, */
7446 /* double *dphi_psiw_dpsiw, */
7447 /* double *phi_psin, */
7448 /* double *dphi_psin_dpsiw, */
7449 /* double *dphi_psin_dsw, */
7450 /* double *fw, */
7451 /* double *dfw, */
7452 /* double *fn, */
7453 /* double *dfn, */
7454 /* double *aw, */
7455 /* double *daw, */
7456 /* double *an, */
7457 /* double *dan) */
7458 /* { */
7459 /* int (*psk_eval)(double Sw, */
7460 /* double *rwork, */
7461 /* double *krw, */
7462 /* double *dkrw, */
7463 /* double *krn, */
7464 /* double *dkrn, */
7465 /* double *psic, */
7466 /* double *dpsic); */
7467 /* double rwork[4]; */
7468 /* psk_set(pskModelFlag,rwork,mvg_m,alpha,bc_lambda,bc_pd,&psk_eval); */
7469 /* int pi,I; */
7470 /* const int nSpace2=nSpace*nSpace; */
7471 /* double se; */
7472 /* double krw,krn,dkrw,dkrn,psic,dpsic,KN,DKN,KW,DKW; */
7473 /* double omega_rhow = omega*rhow,omega_rhon = omega*rhon; */
7474 /* const double omega_sr_inv = 1.0/(omega - omega_r); */
7475 /* for (pi=0;pi<nPoints;pi++) */
7476 /* { */
7477 /* /\*effective saturation*\/ */
7478 /* se = (omega*sw[pi] - omega_r)*omega_sr_inv; */
7479 
7480 /* /\* Get the psk relation values *\/ */
7481 /* psk_eval(se,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7482 
7483 /* /\* phase mass terms *\/ */
7484 /* mw[pi] = omega_rhow*sw[pi]; */
7485 /* dmw[pi] = omega_rhow; */
7486 
7487 /* mn[pi] = omega_rhon*(1.0-sw[pi]); */
7488 /* dmn[pi] =-omega_rhon; */
7489 
7490 /* /\* potentials *\/ */
7491 /* phi_psiw[pi] = psiw[pi]; */
7492 /* dphi_psiw_dpsiw[pi]= 1.0; */
7493 
7494 /* phi_psin[pi] = psiw[pi] + psic; */
7495 /* dphi_psin_dpsiw[pi]= 1.0; */
7496 /* dphi_psin_dsw[pi]= dpsic; */
7497 
7498 /* KW = rhow*Kbar*krw/muw; */
7499 /* DKW = rhow*Kbar*dkrw/muw; */
7500 
7501 /* KN = rhon*Kbar*krn/mun; */
7502 /* DKN = rhon*Kbar*dkrn/mun; */
7503 
7504 /* for (I=0;I<nSpace;I++) */
7505 /* { */
7506 /* phi_psiw[pi] -= rhow*g[I]*x[pi*3+I]; */
7507 /* phi_psin[pi] -= b*rhon*g[I]*x[pi*3+I]; */
7508 
7509 /* aw[pi*nSpace2+I*nSpace+I] = KW; */
7510 /* daw[pi*nSpace2+I*nSpace+I] = DKW; */
7511 
7512 /* an[pi*nSpace2+I*nSpace+I] = KN; */
7513 /* dan[pi*nSpace2+I*nSpace+I] = DKN; */
7514 /* } */
7515 /* } */
7516 /* } */
7517 
7518 /* void TwophaseFFDarcyFC_Evaluate(const int nPoints, */
7519 /* const int nSpace, */
7520 /* const int pskModelFlag, */
7521 /* const double Kbar, */
7522 /* const double rhon, */
7523 /* const double rhow, */
7524 /* const double *g, */
7525 /* const double *x, */
7526 /* const double alpha, */
7527 /* const double bc_lambda, */
7528 /* const double bc_pd, */
7529 /* const double mvg_n, */
7530 /* const double mvg_m, */
7531 /* const double omega, */
7532 /* const double omega_r, */
7533 /* const double mun, */
7534 /* const double muw, */
7535 /* const double b, */
7536 /* double *sw, */
7537 /* double *psiw, */
7538 /* double *mw, */
7539 /* double *dmw_dsw, */
7540 /* double *mm, */
7541 /* double *dmm_dsw, */
7542 /* double *phi_psic, */
7543 /* double *dphi_psic_dsw, */
7544 /* double *phi_psiw, */
7545 /* double *dphi_psiw_dpsiw, */
7546 /* double *fm, */
7547 /* double *dfm_dsw, */
7548 /* double *aw_psiw, */
7549 /* double *daw_psiw_dsw, */
7550 /* double *am_psiw, */
7551 /* double *dam_psiw_dsw, */
7552 /* double *am_psic, */
7553 /* double *dam_psic_dsw) */
7554 /* { */
7555 /* int (*psk_eval)(double Se, */
7556 /* double *rwork, */
7557 /* double *krw, */
7558 /* double *dkrw, */
7559 /* double *krn, */
7560 /* double *dkrn, */
7561 /* double *psic, */
7562 /* double *dpsic); */
7563 /* double rwork[2]; */
7564 /* psk_set(pskModelFlag,rwork,mvg_m,alpha,bc_lambda,bc_pd,&psk_eval); */
7565 /* int pi,I; */
7566 /* const int nSpace2=nSpace*nSpace; */
7567 /* double se,sw_max=1.0,sw_min=0.0; */
7568 /* double krw,krn,dkrw,dkrn,psic,dpsic,KW,DKW; */
7569 /* double lambdaw,dlambdaw,lambdan,dlambdan,lambdat,dlambdat,fw,dfw,fn,dfn; */
7570 /* double omega_rhow = omega*rhow; */
7571 /* /\* double max_krw=0.0,max_krn=0.0; *\/ */
7572 /* double RHON; */
7573 /* const double omega_sr_inv = 1.0/(omega - omega_r); */
7574 
7575 /* for (pi=0;pi<nPoints;pi++) */
7576 /* { */
7577 /* se = (omega*sw[pi] - omega_r)*omega_sr_inv; */
7578 
7579 /* /\* Get the psk relation values *\/ */
7580 /* psk_eval(se,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7581 
7582 /* /\* Get the auxiliary variables *\/ */
7583 /* psk_auxVar(krw,dkrw,krn,dkrn,psic,dpsic, */
7584 /* rhow,rhon,muw,mun, */
7585 /* &lambdaw,&dlambdaw,&lambdan,&dlambdan,&lambdat, */
7586 /* &dlambdat,&fw,&dfw,&fn,&dfn); */
7587 
7588 /* /\* w-phase mass term *\/ */
7589 /* mw[pi] = omega_rhow*(sw[pi]*(sw_max-sw_min)+sw_min); */
7590 /* dmw_dsw[pi] = omega_rhow*(sw_max-sw_min); */
7591 
7592 /* /\* mixture mass term *\/ */
7593 /* mm[pi] = omega*((sw[pi]*(sw_max-sw_min)+sw_min)*(rhow-RHON) + RHON); */
7594 /* dmm_dsw[pi] = omega*(((sw_max-sw_min)+sw_min)*(rhow-RHON)); */
7595 
7596 /* /\* capillary potential*\/ */
7597 /* phi_psic[pi] = psic; */
7598 /* dphi_psic_dsw[pi]= dpsic; */
7599 
7600 /* /\* w-phase potential *\/ */
7601 /* phi_psiw[pi] = psiw[pi]; */
7602 /* dphi_psiw_dpsiw[pi]= 1.0; */
7603 
7604 /* KW = rhow*Kbar*krw/muw; */
7605 /* DKW = rhow*Kbar*dkrw/muw; */
7606 /* for (I=0;I<nSpace;I++) */
7607 /* { */
7608 /* /\* w phase *\/ */
7609 /* phi_psiw[pi] -= rhow*g[I]*x[pi*3+I]; */
7610 
7611 /* aw_psiw[pi*nSpace2+I*nSpace+I] = KW; */
7612 /* daw_psiw_dsw[pi*nSpace2+I*nSpace+I] = DKW; */
7613 
7614 /* /\* mixture *\/ */
7615 /* fm[pi*nSpace+I] = Kbar*lambdat*fn*(b*rhon-rhow)*g[I]; */
7616 /* dfm_dsw[pi*nSpace+I] = Kbar*(dlambdat*fn + lambdat*dfn)*(b*rhon-rhow)*g[I]; */
7617 
7618 /* am_psiw[pi*nSpace2+I*nSpace+I] = Kbar*lambdat; */
7619 /* dam_psiw_dsw[pi*nSpace2+I*nSpace+I] = Kbar*dlambdat; */
7620 
7621 /* am_psic[pi*nSpace2+I*nSpace+I] = Kbar*lambdat*fn; */
7622 /* dam_psic_dsw[pi*nSpace2+I*nSpace+I] = Kbar*(dlambdat*fn+lambdat*dfn); */
7623 /* } */
7624 /* } */
7625 /* } */
7626 
7627 /* void TwophaseDarcyFCHet_Evaluate(const int nPoints, */
7628 /* const int nSpace, */
7629 /* const int pskModelFlag, */
7630 /* const double *Kbar, */
7631 /* const double rhon, */
7632 /* const double rhow, */
7633 /* const double *g, */
7634 /* const double *x, */
7635 /* const double *alpha, */
7636 /* const double *bc_lambda, */
7637 /* const double *bc_pd, */
7638 /* const double *mvg_m, */
7639 /* const double *omega, */
7640 /* const double *omega_r, */
7641 /* const double mun, */
7642 /* const double muw, */
7643 /* const double b, */
7644 /* double *sw, */
7645 /* double *psiw, */
7646 /* double *mw, */
7647 /* double *dmw, */
7648 /* double *mn, */
7649 /* double *dmn, */
7650 /* double *phi_psiw, */
7651 /* double *dphi_psiw_dpsiw, */
7652 /* double *phi_psin, */
7653 /* double *dphi_psin_dpsiw, */
7654 /* double *dphi_psin_dsw, */
7655 /* double *fw, */
7656 /* double *dfw, */
7657 /* double *fn, */
7658 /* double *dfn, */
7659 /* double *aw, */
7660 /* double *daw, */
7661 /* double *an, */
7662 /* double *dan) */
7663 /* { */
7664 /* int (*psk_eval)(double Se, */
7665 /* double *rwork, */
7666 /* double *krw, */
7667 /* double *dkrw, */
7668 /* double *krn, */
7669 /* double *dkrn, */
7670 /* double *psic, */
7671 /* double *dpsic); */
7672 /* double rwork[2]; */
7673 /* psk_set(pskModelFlag,rwork,mvg_m[0],alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
7674 
7675 /* int pi,I; */
7676 /* const int nSpace2=nSpace*nSpace; */
7677 /* double se; */
7678 /* double krw,krn,dkrw,dkrn,psic,dpsic,KN,DKN,KW,DKW; */
7679 
7680 /* for (pi=0;pi<nPoints;pi++) */
7681 /* { */
7682 /* if((pskModelFlag==1)||(pskModelFlag==2)) */
7683 /* { */
7684 /* rwork[0] = mvg_m[pi]; */
7685 /* rwork[1] = alpha[pi]; */
7686 /* } */
7687 /* else if ((pskModelFlag==3)||(pskModelFlag==4)) */
7688 /* { */
7689 /* rwork[0] = bc_lambda[pi]; */
7690 /* rwork[1] = bc_pd[pi]; */
7691 /* } */
7692 /* /\*effective saturation*\/ */
7693 /* se = (omega[pi]*sw[pi] - omega_r[pi])/(omega[pi]-omega_r[pi]); */
7694 
7695 /* /\* Get the psk relation values *\/ */
7696 /* psk_eval(se,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7697 
7698 /* /\* phase mass terms *\/ */
7699 /* mw[pi] = omega[pi]*rhow*sw[pi]; */
7700 /* dmw[pi] = omega[pi]*rhow; */
7701 
7702 /* mn[pi] = omega[pi]*rhon*(1.0-sw[pi]); */
7703 /* dmn[pi] = -omega[pi]*rhon; */
7704 
7705 /* /\* potentials *\/ */
7706 /* phi_psiw[pi] = psiw[pi]; */
7707 /* dphi_psiw_dpsiw[pi]= 1.0; */
7708 
7709 /* phi_psin[pi] = psiw[pi] + psic; */
7710 /* dphi_psin_dpsiw[pi]= 1.0; */
7711 /* dphi_psin_dsw[pi]= dpsic; */
7712 
7713 /* KW = rhow*Kbar[pi]*krw/muw; */
7714 /* DKW = rhow*Kbar[pi]*dkrw/muw; */
7715 
7716 /* KN = rhon*Kbar[pi]*krn/mun; */
7717 /* DKN = rhon*Kbar[pi]*dkrn/mun; */
7718 
7719 /* for (I=0;I<nSpace;I++) */
7720 /* { */
7721 /* phi_psiw[pi] -= rhow*g[I]*x[pi*3+I]; */
7722 /* phi_psin[pi] -= b*rhon*g[I]*x[pi*3+I]; */
7723 
7724 /* aw[pi*nSpace2+I*nSpace+I] = KW; */
7725 /* daw[pi*nSpace2+I*nSpace+I] = DKW; */
7726 
7727 /* an[pi*nSpace2+I*nSpace+I] = KN; */
7728 /* dan[pi*nSpace2+I*nSpace+I] = DKN; */
7729 /* } */
7730 /* } */
7731 /* } */
7732 
7733 /* void TwophaseDarcyFCHet_EvaluateV2(const int nSimplex, */
7734 /* const int nPointsPerSimplex, */
7735 /* const int nSpace, */
7736 /* const int nTypes, */
7737 /* const int pskModelFlag, */
7738 /* const int* materialTypes, */
7739 /* const double *Kbar, */
7740 /* const double rhon, */
7741 /* const double rhow, */
7742 /* const double b, */
7743 /* const double *g, */
7744 /* const double *x, */
7745 /* const double *mvg_alpha, */
7746 /* const double *mvg_n, */
7747 /* const double *mvg_m, */
7748 /* const double *bc_pd, */
7749 /* const double *bc_lambda, */
7750 /* const double *thetaS, */
7751 /* const double *thetaR, */
7752 /* const double mun, */
7753 /* const double muw, */
7754 /* double *sw, */
7755 /* double *psiw, */
7756 /* double *mw, */
7757 /* double *dmw, */
7758 /* double *mn, */
7759 /* double *dmn, */
7760 /* double *phi_psiw, */
7761 /* double *dphi_psiw_dpsiw, */
7762 /* double *phi_psin, */
7763 /* double *dphi_psin_dpsiw, */
7764 /* double *dphi_psin_dsw, */
7765 /* double *fw, */
7766 /* double *dfw, */
7767 /* double *fn, */
7768 /* double *dfn, */
7769 /* double *aw, */
7770 /* double *daw, */
7771 /* double *an, */
7772 /* double *dan) */
7773 /* { */
7774 /* int (*psk_eval)(double Se, */
7775 /* double *rwork, */
7776 /* double *krw, */
7777 /* double *dkrw, */
7778 /* double *krn, */
7779 /* double *dkrn, */
7780 /* double *psic, */
7781 /* double *dpsic); */
7782 /* double rwork[2]; */
7783 /* psk_set(pskModelFlag,rwork,mvg_m[0],mvg_alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
7784 
7785 /* int i,j,k,I,matID; */
7786 /* const int nSpace2=nSpace*nSpace; */
7787 /* double se,thw,thn,ths,thr; */
7788 /* double krw,krn,dkrw,dkrn,psic,dpsic,KN,DKN,KW,DKW; */
7789 
7790 /* for (i=0; i < nSimplex; i++) */
7791 /* { */
7792 /* matID=materialTypes[i]; */
7793 /* if (matID < 0) */
7794 /* matID = 0; */
7795 /* if (matID > nTypes-1) */
7796 /* matID = nTypes-1; */
7797 /* for (j=0; j < nPointsPerSimplex; j++) */
7798 /* { */
7799 /* k = i*nPointsPerSimplex + j; */
7800 /* if(pskModelFlag==1 || pskModelFlag==2) */
7801 /* { */
7802 /* rwork[0] = mvg_m[matID]; */
7803 /* rwork[1] = mvg_alpha[matID]; */
7804 /* } */
7805 /* else if (pskModelFlag==3 ||pskModelFlag==4) */
7806 /* { */
7807 /* rwork[0] = bc_lambda[matID]; */
7808 /* rwork[1] = bc_pd[matID]; */
7809 /* } */
7810 /* /\*volume fractions*\/ */
7811 /* ths = thetaS[matID]; thr = thetaR[matID]; */
7812 /* thw = ths*sw[k]; /\*wetting*\/ */
7813 /* thn = ths*(1.0-sw[k]);/\*non wetting*\/ */
7814 
7815 /* /\*effective saturation*\/ */
7816 /* se = (thw-thr)/(ths-thr); */
7817 
7818 /* /\* Get the psk relation values *\/ */
7819 /* psk_eval(se,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7820 /* /\* /\\* if using BC have to enforce displacement pressure here?*\\/ *\/ */
7821 /* /\* if((pskModelFlag == 3 || pskModelFlag == 4) && *\/ */
7822 /* /\* se >= 1.0-pd_eps) *\/ */
7823 /* /\* { *\/ */
7824 /* /\* psic = 0.0; dpsic = 0.0; krn = 0.0; dkrn = 0.0; krw = 1.0; *\/ */
7825 /* /\* } *\/ */
7826 
7827 /* /\* phase mass terms *\/ */
7828 /* mw[k] = thw*rhow; */
7829 /* dmw[k] = ths*rhow; */
7830 
7831 /* mn[k] = thn*rhon; */
7832 /* dmn[k] =-ths*rhon; */
7833 
7834 /* /\* potentials *\/ */
7835 /* phi_psiw[k] = psiw[k]; */
7836 /* dphi_psiw_dpsiw[k]= 1.0; */
7837 
7838 /* phi_psin[k] = psiw[k] + psic; */
7839 /* dphi_psin_dpsiw[k]= 1.0; */
7840 /* dphi_psin_dsw[k]= dpsic; */
7841 
7842 /* /\*conductivities*\/ */
7843 /* KW = rhow*Kbar[matID]*krw/muw; /\*mu's are normalized by muw*\/ */
7844 /* DKW = rhow*Kbar[matID]*dkrw/muw; */
7845 
7846 /* KN = rhon*Kbar[matID]*krn/mun; */
7847 /* DKN = rhon*Kbar[matID]*dkrn/mun; */
7848 
7849 /* for (I=0;I<nSpace;I++) */
7850 /* { */
7851 /* phi_psiw[k] -= rhow*g[I]*x[k*3+I]; */
7852 /* phi_psin[k] -= rhon*g[I]*x[k*3+I]; */
7853 
7854 /* aw[k*nSpace2+I*nSpace+I] = KW;/\*have rho's in them*\/ */
7855 /* daw[k*nSpace2+I*nSpace+I] = DKW; */
7856 
7857 /* an[k*nSpace2+I*nSpace+I] = KN; */
7858 /* dan[k*nSpace2+I*nSpace+I] = DKN; */
7859 /* }/\*I*\/ */
7860 /* }/\*j*\/ */
7861 /* }/\*i*\/ */
7862 /* } */
7863 
7864 /* void TwophaseFFDarcyFCHet_EvaluateV2(const int nSimplex, */
7865 /* const int nPointsPerSimplex, */
7866 /* const int nSpace, */
7867 /* const int nTypes, */
7868 /* const int pskModelFlag, */
7869 /* const int* materialTypes, */
7870 /* const double *Kbar, */
7871 /* const double rhon, */
7872 /* const double rhow, */
7873 /* const double b, */
7874 /* const double *g, */
7875 /* const double *x, */
7876 /* const double *mvg_alpha, */
7877 /* const double *mvg_n, */
7878 /* const double *mvg_m, */
7879 /* const double *bc_pd, */
7880 /* const double *bc_lambda, */
7881 /* const double *thetaS, */
7882 /* const double *thetaR, */
7883 /* const double mun, */
7884 /* const double muw, */
7885 /* double *sw, */
7886 /* double *psiw, */
7887 /* double *mw, */
7888 /* double *dmw_dsw, */
7889 /* double *mm, */
7890 /* double *dmm_dsw, */
7891 /* double *phi_psic, */
7892 /* double *dphi_psic_dsw, */
7893 /* double *phi_psiw, */
7894 /* double *dphi_psiw_dpsiw, */
7895 /* double *fm, */
7896 /* double *dfm_dsw, */
7897 /* double *fw, */
7898 /* double *dfw_dsw, */
7899 /* double *aw_psiw, */
7900 /* double *daw_psiw_dsw, */
7901 /* double *am_psiw, */
7902 /* double *dam_psiw_dsw, */
7903 /* double *am_psic, */
7904 /* double *dam_psic_dsw) */
7905 /* { */
7906 /* int (*psk_eval)(double Se, */
7907 /* double *rwork, */
7908 /* double *krw, */
7909 /* double *dkrw, */
7910 /* double *krn, */
7911 /* double *dkrn, */
7912 /* double *psic, */
7913 /* double *dpsic); */
7914 /* double rwork[2]; */
7915 /* psk_set(pskModelFlag,rwork,mvg_m[0],mvg_alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
7916 
7917 /* int i,j,k,I,matID; */
7918 /* const int nSpace2=nSpace*nSpace; */
7919 /* const double pd_eps = 9.0e-6; */
7920 /* double se,thw,thn,ths,thr; */
7921 /* double krw,krn,dkrw,dkrn,psic,dpsic,KN,DKN,KW,DKW; */
7922 
7923 /* for (i=0; i < nSimplex; i++) */
7924 /* { */
7925 /* matID=materialTypes[i]; */
7926 /* if (matID < 0) */
7927 /* matID = 0; */
7928 /* if (matID > nTypes-1) */
7929 /* matID = nTypes-1; */
7930 /* for (j=0; j < nPointsPerSimplex; j++) */
7931 /* { */
7932 /* k = i*nPointsPerSimplex + j; */
7933 /* if(pskModelFlag==1 || pskModelFlag==2) */
7934 /* { */
7935 /* rwork[0] = mvg_m[matID]; */
7936 /* rwork[1] = mvg_alpha[matID]; */
7937 /* } */
7938 /* else if (pskModelFlag==3 ||pskModelFlag==4) */
7939 /* { */
7940 /* rwork[0] = bc_lambda[matID]; */
7941 /* rwork[1] = bc_pd[matID]; */
7942 /* } */
7943 /* /\*volume fractions*\/ */
7944 /* ths = thetaS[matID]; thr = thetaR[matID]; */
7945 /* thw = ths*sw[k]; /\*wetting*\/ */
7946 /* thn = ths*(1.0-sw[k]);/\*non wetting*\/ */
7947 /* /\*effective saturation*\/ */
7948 /* se = (thw-thr)/(ths-thr); */
7949 
7950 /* /\* Get the psk relation values *\/ */
7951 /* psk_eval(se,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
7952 /* /\* if using BC have to enforce displacement pressure here?*\/ */
7953 /* if((pskModelFlag == 3 || pskModelFlag == 4) && */
7954 /* se >= 1.0-pd_eps) */
7955 /* { */
7956 /* psic = 0.0; dpsic = 0.0; krn = 0.0; dkrn = 0.0; krw = 1.0; */
7957 /* } */
7958 
7959 /* /\* w-phase mass term *\/ */
7960 /* mw[k] = thw*rhow; */
7961 /* dmw_dsw[k]= ths*rhow; */
7962 
7963 /* /\* mixture mass term *\/ */
7964 /* mm[k] = thw*rhow + thn*rhon; */
7965 /* dmm_dsw[k]= ths*(rhow - rhon); */
7966 
7967 /* /\* capillary potential*\/ */
7968 /* phi_psic[k] = psic; */
7969 /* dphi_psic_dsw[k]= dpsic; */
7970 
7971 /* /\* w-phase potential *\/ */
7972 /* phi_psiw[k] = psiw[k]; */
7973 /* dphi_psiw_dpsiw[k]= 1.0; */
7974 
7975 /* KW = rhow*Kbar[matID]*krw/muw; */
7976 /* DKW = rhow*Kbar[matID]*dkrw/muw; */
7977 
7978 /* KN = rhon*Kbar[matID]*krn/mun; */
7979 /* DKN = rhon*Kbar[matID]*dkrn/mun; */
7980 /* for (I=0;I<nSpace;I++) */
7981 /* { */
7982 /* /\* w phase *\/ */
7983 /* /\*don't include gravity in potential?*\/ */
7984 /* /\*phi_psiw[k] -= rhow*g[I]*x[pi*3+I]*\/; */
7985 /* /\* w [hase *\/ */
7986 /* fw[k*nSpace+I] = rhow*KW*g[I]; */
7987 /* dfw_dsw[k*nSpace+I]= rhow*DKW*g[I]; */
7988 
7989 /* aw_psiw[k*nSpace2+I*nSpace+I] = KW; */
7990 /* daw_psiw_dsw[k*nSpace2+I*nSpace+I] = DKW; */
7991 
7992 /* /\* mixture *\/ */
7993 /* fm[k*nSpace+I] = rhow*KW*g[I] + rhon*KN*b*g[I]; */
7994 /* dfm_dsw[k*nSpace+I]= rhow*DKW*g[I]+ rhon*DKN*b*g[I]; */
7995 
7996 /* am_psiw[k*nSpace2+I*nSpace+I] = KW + KN; */
7997 /* dam_psiw_dsw[k*nSpace2+I*nSpace+I] = DKW + DKN; */
7998 
7999 /* am_psic[k*nSpace2+I*nSpace+I] = KN; */
8000 /* dam_psic_dsw[k*nSpace2+I*nSpace+I] = DKN; */
8001 /* }/\*I*\/ */
8002 /* }/\*j*\/ */
8003 /* }/\*i*\/ */
8004 /* } */
8005 
8006 /* void TwophaseFFDarcyFCHet_Evaluate(const int nPoints, */
8007 /* const int nSpace, */
8008 /* const int pskModelFlag, */
8009 /* const double *Kbar, */
8010 /* const double rhon, */
8011 /* const double rhow, */
8012 /* const double *g, */
8013 /* const double *x, */
8014 /* const double *alpha, */
8015 /* const double *bc_lambda, */
8016 /* const double *bc_pd, */
8017 /* const double *mvg_m, */
8018 /* const double *omega, */
8019 /* const double *omega_r, */
8020 /* const double mun, */
8021 /* const double muw, */
8022 /* const double b, */
8023 /* double *sw, */
8024 /* double *psiw, */
8025 /* double *mw, */
8026 /* double *dmw_dsw, */
8027 /* double *mm, */
8028 /* double *dmm_dsw, */
8029 /* double *phi_psic, */
8030 /* double *dphi_psic_dsw, */
8031 /* double *phi_psiw, */
8032 /* double *dphi_psiw_dpsiw, */
8033 /* double *fm, */
8034 /* double *dfm_dsw, */
8035 /* double *aw_psiw, */
8036 /* double *daw_psiw_dsw, */
8037 /* double *am_psiw, */
8038 /* double *dam_psiw_dsw, */
8039 /* double *am_psic, */
8040 /* double *dam_psic_dsw) */
8041 /* { */
8042 /* int (*psk_eval)(double Se, */
8043 /* double *rwork, */
8044 /* double *krw, */
8045 /* double *dkrw, */
8046 /* double *krn, */
8047 /* double *dkrn, */
8048 /* double *psic, */
8049 /* double *dpsic); */
8050 /* double rwork[2]; */
8051 /* psk_set(pskModelFlag,rwork,mvg_m[0],alpha[0],bc_lambda[0],bc_pd[0],&psk_eval); */
8052 /* int pi,I; */
8053 /* const int nSpace2=nSpace*nSpace; */
8054 /* double se,seeval; */
8055 /* double krw,krn,dkrw,dkrn,psic,dpsic,KW,DKW; */
8056 /* double lambdaw,dlambdaw,lambdan,dlambdan,lambdat,dlambdat,fw,dfw,fn,dfn; */
8057 
8058 /* for (pi=0;pi<nPoints;pi++){ */
8059 
8060 /* if((pskModelFlag==1)||(pskModelFlag==2)) */
8061 /* { */
8062 /* rwork[0] = mvg_m[pi]; */
8063 /* rwork[1] = alpha[pi]; */
8064 /* } */
8065 /* else if ((pskModelFlag==3)||(pskModelFlag==4)) */
8066 /* { */
8067 /* rwork[0] = bc_lambda[pi]; */
8068 /* rwork[1] = bc_pd[pi]; */
8069 /* } */
8070 /* /\*effective saturation*\/ */
8071 /* se = (omega[pi]*sw[pi] - omega_r[pi])/(omega[pi]-omega_r[pi]); */
8072 
8073 /* /\* Get the psk relation values *\/ */
8074 /* psk_eval(seeval,rwork,&krw,&dkrw,&krn,&dkrn,&psic,&dpsic); */
8075 
8076 /* /\* Get the auxiliary variables *\/ */
8077 /* psk_auxVar(krw,dkrw,krn,dkrn,psic,dpsic, */
8078 /* rhow,rhon,muw,mun, */
8079 /* &lambdaw,&dlambdaw,&lambdan,&dlambdan,&lambdat, */
8080 /* &dlambdat,&fw,&dfw,&fn,&dfn); */
8081 
8082 /* /\* w-phase mass term *\/ */
8083 /* mw[pi] = omega[pi]*rhow*sw[pi]; */
8084 /* dmw_dsw[pi] = omega[pi]*rhow; */
8085 
8086 /* /\* mixture mass term *\/ */
8087 /* mm[pi] = omega[pi]*(sw[pi]*(rhow-rhon) + rhon); */
8088 /* dmm_dsw[pi] = omega[pi]*(rhow-rhon); */
8089 
8090 /* /\* capillary potential*\/ */
8091 /* phi_psic[pi] = psic; */
8092 /* dphi_psic_dsw[pi]= dpsic; */
8093 
8094 /* /\* w-phase potential *\/ */
8095 /* phi_psiw[pi] = psiw[pi]; */
8096 /* dphi_psiw_dpsiw[pi]= 1.0; */
8097 
8098 /* KW = rhow*Kbar[pi]*krw/muw; */
8099 /* DKW = rhow*Kbar[pi]*dkrw/muw; */
8100 
8101 /* for (I=0;I<nSpace;I++) */
8102 /* { */
8103 /* /\* w phase *\/ */
8104 /* phi_psiw[pi] -= rhow*g[I]*x[pi*3+I]; */
8105 
8106 /* aw_psiw[pi*nSpace2+I*nSpace+I] = KW; */
8107 /* daw_psiw_dsw[pi*nSpace2+I*nSpace+I] = DKW; */
8108 
8109 /* /\* mixture *\/ */
8110 /* fm[pi*nSpace+I] = Kbar[pi]*lambdat*fn*(b*rhon-rhow)*g[I]; */
8111 /* dfm_dsw[pi*nSpace+I] = Kbar[pi]*(dlambdat*fn + lambdat*dfn)*(b*rhon-rhow)*g[I]; */
8112 
8113 /* am_psiw[pi*nSpace2+I*nSpace+I] = Kbar[pi]*lambdat; */
8114 /* dam_psiw_dsw[pi*nSpace2+I*nSpace+I] = Kbar[pi]*dlambdat; */
8115 
8116 /* am_psic[pi*nSpace2+I*nSpace+I] = Kbar[pi]*lambdat*fn; */
8117 /* dam_psic_dsw[pi*nSpace2+I*nSpace+I] = Kbar[pi]*(dlambdat*fn+lambdat*dfn); */
8118 /* } */
8119 /* } */
8120 /* } */
8121 
8122 /* end two-phase flow in porous media coefficients */
8123 
8124 void LinearElasticity_1D_Evaluate(const int nPoints,
8125  const double E,
8126  const double nu,
8127  const double *g,
8128  const double *u,
8129  double *uu_diff_ten,
8130  double *u_force)
8131 {
8132  int k;
8133  for (k=0;k<nPoints;k++)
8134  {
8135  /* \sigma^x */
8136 
8137  /* a^{xx} */
8138 
8139  uu_diff_ten[k*1+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8140  }
8141 }
8142 
8143 void LinearElasticity_2D_Evaluate(const int nPoints,
8144  const double E,
8145  const double nu,
8146  const double *g,
8147  const double *u,
8148  const double *v,
8149  double *uu_diff_ten,double *uv_diff_ten,
8150  double *vu_diff_ten,double *vv_diff_ten,
8151  double *u_force,
8152  double *v_force)
8153 {
8154  int k;
8155  for (k=0;k<nPoints;k++)
8156  {
8157  /* \sigma^x */
8158 
8159  /* a^{xx} */
8160 
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;
8163 
8164  /* a^{xy} */
8165 
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;
8168 
8169  /* \sigma^y */
8170 
8171  /* a^{yx} */
8172 
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));
8175 
8176  /* a^{yy} */
8177 
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));
8180 
8181  u_force[k] = -g[0];
8182  v_force[k] = -g[1];
8183  }
8184 }
8185 
8186 void LinearElasticity_3D_Evaluate(const int nPoints,
8187  const double E,
8188  const double nu,
8189  const double *g,
8190  const double *u,
8191  const double *v,
8192  const double *w,
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,
8196  double *u_force,
8197  double *v_force,
8198  double *w_force)
8199 {
8200  int k;
8201  for (k=0;k<nPoints;k++)
8202  {
8203  /* \sigma^x */
8204 
8205  /* a^{xx} */
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;
8209 
8210  /* a^{xy} */
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;
8213 
8214  /* a^{xz} */
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;
8217 
8218  /* \sigma^y */
8219 
8220  /* a^{yx} */
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));
8223 
8224  /* a^{yy} */
8225 
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;
8229 
8230  /* a^{yz} */
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;
8233 
8234  /* \sigma^z */
8235 
8236  /* a^{zx} */
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));
8239 
8240  /* a^{zy} */
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));
8243 
8244  /* a^{zz} */
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));
8248 
8249  u_force[k] = -g[0];
8250  v_force[k] = -g[1];
8251  w_force[k] = -g[2];
8252  }
8253 }
8254 
8255 void MovingMesh_1D_Evaluate(const int nPoints,
8256  const double E0,
8257  const double nu,
8258  const double *g,
8259  const double *det_J,
8260  const double *u,
8261  double *uu_diff_ten,
8262  double *u_force)
8263 {
8264  double E;
8265  int k;
8266  for (k=0;k<nPoints;k++)
8267  {
8268  E = E0/det_J[k];
8269  /* \sigma^x */
8270 
8271  /* a^{xx} */
8272  uu_diff_ten[k*1+0] = (E/(1.0+nu))*(1.0+nu/(1.0-2.0*nu));
8273  }
8274 }
8275 
8276 void MovingMesh_2D_Evaluate(const int nPoints,
8277  const double E0,
8278  const double nu,
8279  const double *g,
8280  const double *det_J,
8281  const double *u,
8282  const double *v,
8283  double *uu_diff_ten,double *uv_diff_ten,
8284  double *vu_diff_ten,double *vv_diff_ten,
8285  double *u_force,
8286  double *v_force)
8287 {
8288  double E;
8289  int k;
8290  for (k=0;k<nPoints;k++)
8291  {
8292  E = E0/det_J[k];
8293  /* \sigma^x */
8294 
8295  /* a^{xx} */
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;
8298 
8299  /* a^{xy} */
8300 
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;
8303 
8304  /* \sigma^y */
8305 
8306  /* a^{yx} */
8307 
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));
8310 
8311  /* a^{yy} */
8312 
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));
8315 
8316  u_force[k] = -g[0];
8317  v_force[k] = -g[1];
8318  }
8319 }
8320 
8321 void MovingMesh_3D_Evaluate(const int nPoints,
8322  const double E0,
8323  const double nu,
8324  const double *g,
8325  const double *det_J,
8326  const double *u,
8327  const double *v,
8328  const double *w,
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,
8332  double *u_force,
8333  double *v_force,
8334  double *w_force)
8335 {
8336  double E;
8337  int k;
8338  for (k=0;k<nPoints;k++)
8339  {
8340  E = E0/det_J[k];
8341  /* \sigma^x */
8342 
8343  /* a^{xx} */
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;
8347 
8348  /* a^{xy} */
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;
8351 
8352  /* a^{xz} */
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;
8355 
8356  /* \sigma^y */
8357 
8358  /* a^{yx} */
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));
8361 
8362  /* a^{yy} */
8363 
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;
8367 
8368  /* a^{yz} */
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;
8371 
8372  /* \sigma^z */
8373 
8374  /* a^{zx} */
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));
8377 
8378  /* a^{zy} */
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));
8381 
8382  /* a^{zz} */
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));
8386 
8387  u_force[k] = -g[0];
8388  v_force[k] = -g[1];
8389  w_force[k] = -g[2];
8390  }
8391 }
8392 
8394  int nSpace,
8395  double epsHeaviside,
8396  double epsDirac,
8397  double epsDiffusion,
8398  double* u_ls,
8399  double* H_vof,
8400  double* u,
8401  double* r,
8402  double* dr,
8403  double* a)
8404 {
8405  int i,I,nSpace2=nSpace*nSpace;
8406 /* double eps=1.0e-1; */
8407 
8408  for (i=0;i<nPoints;i++)
8409  {
8410  // r[i] = (1.0-smoothedHeaviside(epsHeaviside,u[i] + u_ls[i])) - H_vof[i];
8411  // dr[i] = -smoothedDirac(epsDirac,u[i] + u_ls[i]);
8412  r[i] = smoothedHeaviside(epsHeaviside,u[i] + u_ls[i]) - H_vof[i];
8413  dr[i] = smoothedDirac(epsDirac,u[i] + u_ls[i]);
8414  for (I=0;I<nSpace;I++)
8415  a[nSpace2*i+I*nSpace+I] = epsDiffusion;
8416  }
8417 
8418 
8419 /* for (i=0;i<nPoints;i++) */
8420 /* { */
8421 /* if ((H_vof[i] > eps) && (H_vof[i] < (1.0-eps)) ) */
8422 /* { */
8423 /* r[i] = smoothedHeaviside(epsHeaviside,u[i] + u_ls[i]) - H_vof[i]; */
8424 /* dr[i] = smoothedDirac(epsDirac,u[i] + u_ls[i]); */
8425 /* for (I=0;I<nSpace;I++) */
8426 /* a[nSpace2*i+I*nSpace+I] = epsDiffusion; */
8427 /* } */
8428 /* else */
8429 /* { */
8430 /* r[i] = u[i]; */
8431 /* dr[i] = 1.0; */
8432 /* for (I=0;I<nSpace;I++) */
8433 /* a[nSpace2*i+I*nSpace+I] = 0.0; */
8434 /* } */
8435 /* } */
8436 }
8437 
8439  double epsHeaviside,
8440  double epsDirac,
8441  double* u_ls,
8442  double* H_vof,
8443  double* u,
8444  double* r,
8445  double* dr)
8446 {
8447  int i;
8448  for (i=0;i<nPoints;i++)
8449  {
8450  r[i] = smoothedHeaviside(epsHeaviside,u[i] + u_ls[i]) - H_vof[i];
8451  dr[i] = smoothedDirac(epsDirac,u[i] + u_ls[i]);
8452  }
8453 }
8454 
8456  int nSpace,
8457  const double * x,
8458  const double * u,
8459  double * m,
8460  double * dm,
8461  double * f,
8462  double * df,
8463  double * a)
8464 {
8465  /***********************************************************************
8466  Buckley Leverett 5 spot example from Liu SIAM Num 93
8467 
8468  velocity described by potential phi = -0.01 log((x^2 + y^2)^{1/2})
8469 
8470  flux function is f = u^2/(0.2 - 0.4u + 1.2 u^2)
8471 
8472  u is water saturation
8473  ***********************************************************************/
8474  double vx,vy,r,drdx,drdy,frac,dfrac,denom,ddenom;
8475  int k;
8476  const int nSpace2 = nSpace*nSpace;
8477  const double eps = 1.0e-3;
8478  memset(a, 0, nPoints * nSpace2 * sizeof(double));
8479  /*memset(da, 0, nPoints * nSpace2 * sizeof(double));*/
8480 
8481  for (k = 0; k < nPoints; k++)
8482  {
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);
8490  m[k] = u[k];
8491  dm[k]= 1.0;
8492 
8493  f[k*nSpace+0]=vx*frac;
8494  f[k*nSpace+1]=vy*frac;
8495 
8496  df[k*nSpace+0]=vx*dfrac;
8497  df[k*nSpace+1]=vy*dfrac;
8498  }
8499 }
8500 
8501 /*Simplified NS in a porous region with spatially variable porosity
8502  but uniform mean grain size and other empirical fitting parameters for now
8503  taken from Breugem etal Journal of Fluid Mechanics 06
8504  full tensor version needs to be verified may not be correct combination
8505  with Darcy-Forcheimer drag terms */
8507  const double rho,
8508  const double mu,
8509  const double *meanGrainSize,
8510  const double *g,
8511  const double *p,
8512  const double *grad_p,
8513  const double *u,
8514  const double *v,
8515  const double *porosity,
8516  double *mom_u_acc,
8517  double *dmom_u_acc_u,
8518  double *mom_v_acc,
8519  double *dmom_v_acc_v,
8520  double *mass_adv,
8521  double *dmass_adv_u,
8522  double *dmass_adv_v,
8523  double *mom_u_adv,
8524  double *dmom_u_adv_u,
8525  double *dmom_u_adv_v,
8526  double *mom_v_adv,
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,
8539  double *mom_u_ham,
8540  double *dmom_u_ham_grad_p,
8541  double *mom_v_ham,
8542  double *dmom_v_ham_grad_p)
8543 {
8544  int k;
8545  double Ftilde,Kinv,uc;
8546  for (k=0;k<nPoints;k++)
8547  {
8549  //u momentum accumulation
8550  mom_u_acc[k]=porosity[k]*rho*u[k];
8551  dmom_u_acc_u[k]=porosity[k]*rho;
8552 
8553  //v momentum accumulation
8554  mom_v_acc[k]=porosity[k]*rho*v[k];
8555  dmom_v_acc_v[k]=porosity[k]*rho;
8556 
8557  //mass advective flux
8558  mass_adv[k*2+0]=porosity[k]*u[k];
8559  mass_adv[k*2+1]=porosity[k]*v[k];
8560 
8561  dmass_adv_u[k*2+0]=porosity[k];
8562  dmass_adv_v[k*2+1]=porosity[k];
8563 
8564  //u momentum advective flux
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];
8567 
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];
8570 
8571  dmom_u_adv_v[k*2+1]=porosity[k]*rho*u[k];
8572 
8573  //v momentum advective_flux
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];
8576 
8577  dmom_v_adv_u[k*2+0]=porosity[k]*rho*v[k];
8578 
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];
8581 
8582  //u momentum diffusion tensor
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;
8586 
8587  //v momentum diffusion tensor
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;
8591 
8592 
8593  //momentum sources
8594  //porous medium contribution
8595  //end up with extra porosity term in final expression because multiply whole momentum
8596  //equation through by porosity
8597  uc = sqrt(u[k]*u[k]+v[k]*v[k]);
8598  if (fabs(1.0-porosity[k]) < 1.0e-7)
8599  Ftilde = 0.0;
8600  else
8601  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu;
8602  /*mwf hack
8603  Ftilde =0.0;
8604  */
8605  //trap divide by zero here
8606  if (fabs(porosity[k]) < 1.0e-7)
8607  Kinv = 0.0;
8608  else
8609  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8610 
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];
8613 
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)));
8616 
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)));
8619 
8620  //u momentum Hamiltonian (pressure)
8621 
8622  mom_u_ham[k] = porosity[k]*grad_p[k*2+0];
8623  dmom_u_ham_grad_p[k*2+0]=porosity[k];
8624 
8625  //v momentum Hamiltonian (pressure)
8626  mom_v_ham[k] = porosity[k]*grad_p[k*2+1];
8627  dmom_v_ham_grad_p[k*2+1]=porosity[k];
8628  }
8629 }
8631  const double rho,
8632  const double mu,
8633  const double* meanGrainSize,
8634  const double* g,
8635  const double *p,
8636  const double *grad_p,
8637  const double *u,
8638  const double *v,
8639  const double *w,
8640  const double *porosity,
8641  double *mom_u_acc,
8642  double *dmom_u_acc_u,
8643  double *mom_v_acc,
8644  double *dmom_v_acc_v,
8645  double *mom_w_acc,
8646  double *dmom_w_acc_w,
8647  double *mass_adv,
8648  double *dmass_adv_u,
8649  double *dmass_adv_v,
8650  double *dmass_adv_w,
8651  double *mom_u_adv,
8652  double *dmom_u_adv_u,
8653  double *dmom_u_adv_v,
8654  double *dmom_u_adv_w,
8655  double *mom_v_adv,
8656  double *dmom_v_adv_u,
8657  double *dmom_v_adv_v,
8658  double *dmom_v_adv_w,
8659  double *mom_w_adv,
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,
8684  double *mom_u_ham,
8685  double *dmom_u_ham_grad_p,
8686  double *mom_v_ham,
8687  double *dmom_v_ham_grad_p,
8688  double *mom_w_ham,
8689  double *dmom_w_ham_grad_p)
8690 {
8691  int k;
8692  double Ftilde,Kinv,uc;
8693  for (k=0;k<nPoints;k++)
8694  {
8696  //u momentum accumulation
8697  mom_u_acc[k]=porosity[k]*rho*u[k];
8698  dmom_u_acc_u[k]=porosity[k]*rho;
8699 
8700  //v momentum accumulation
8701  mom_v_acc[k]=porosity[k]*rho*v[k];
8702  dmom_v_acc_v[k]=porosity[k]*rho;
8703 
8704  //w momentum accumulation
8705  mom_w_acc[k]=porosity[k]*rho*w[k];
8706  dmom_w_acc_w[k]=porosity[k]*rho;
8707 
8708 
8709  //mass advective flux
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];
8713 
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];
8717 
8718  //u momentum advective flux
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];
8722 
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];
8726 
8727  dmom_u_adv_v[k*3+1]=porosity[k]*rho*u[k];
8728 
8729  dmom_u_adv_w[k*3+2]=porosity[k]*rho*u[k];
8730 
8731  //v momentum advective_flux
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];
8735 
8736  dmom_v_adv_u[k*3+0]=porosity[k]*rho*v[k];
8737 
8738  dmom_v_adv_w[k*3+2]=porosity[k]*rho*v[k];
8739 
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];
8743 
8744  //w momentum advective_flux
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];
8748 
8749  dmom_w_adv_u[k*3+0]=porosity[k]*rho*w[k];
8750 
8751  dmom_w_adv_v[k*3+1]=porosity[k]*rho*w[k];
8752 
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];
8756 
8757  //u momentum diffusion tensor
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;
8761 
8762  mom_uv_diff_ten[k*9+3]=porosity[k]*mu;
8763 
8764  mom_uw_diff_ten[k*9+6]=porosity[k]*mu;
8765 
8766  //v momentum diffusion tensor
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;
8770 
8771  mom_vu_diff_ten[k*9+1]=porosity[k]*mu;
8772 
8773  mom_vw_diff_ten[k*9+7]=porosity[k]*mu;
8774 
8775  //w momentum diffusion tensor
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;
8779 
8780  mom_wu_diff_ten[k*9+2]=porosity[k]*mu;
8781 
8782  mom_wv_diff_ten[k*9+5]=porosity[k]*mu;
8783 
8784  //momentum sources
8785  //porous medium contribution
8786  //end up with extra porosity term in final expression because multiply whole momentum
8787  //equation through by porosity
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)
8790  Ftilde = 0.0;
8791  else
8792  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu;
8793  /*mwf hack
8794  Ftilde =0.0;
8795  */
8796  //trap divide by zero here
8797  if (fabs(porosity[k]) < 1.0e-7)
8798  Kinv = 0.0;
8799  else
8800  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8801 
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];
8805 
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)));
8809 
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)));
8813 
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)));
8817 
8818  //u momentum Hamiltonian (pressure)
8819  mom_u_ham[k] = porosity[k]*grad_p[k*3+0];
8820  dmom_u_ham_grad_p[k*3+0]=porosity[k];
8821 
8822  //v momentum Hamiltonian (pressure)
8823  mom_v_ham[k] = porosity[k]*grad_p[k*3+1];
8824  dmom_v_ham_grad_p[k*3+1]=porosity[k];
8825 
8826  //w momentum Hamiltonian (pressure)
8827  mom_w_ham[k] = porosity[k]*grad_p[k*3+2];
8828  dmom_w_ham_grad_p[k*3+2]=porosity[k];
8829  }
8830 }
8831 
8833  const int killNonlinearDrag,
8834  const double eps_rho,
8835  const double eps_mu,
8836  const double sigma,
8837  const double rho_0,
8838  const double nu_0,
8839  const double rho_1,
8840  const double nu_1,
8841  const double* meanGrainSize,
8842  const double* g,
8843  const double* phi,
8844  const double* n,
8845  const double* kappa,
8846  const double *p,
8847  const double *grad_p,
8848  const double *u,
8849  const double *v,
8850  const double *porosity,
8851  double *mom_u_acc,
8852  double *dmom_u_acc_u,
8853  double *mom_v_acc,
8854  double *dmom_v_acc_v,
8855  double *mass_adv,
8856  double *dmass_adv_u,
8857  double *dmass_adv_v,
8858  double *mom_u_adv,
8859  double *dmom_u_adv_u,
8860  double *dmom_u_adv_v,
8861  double *mom_v_adv,
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,
8874  double *mom_u_ham,
8875  double *dmom_u_ham_grad_p,
8876  double *mom_v_ham,
8877  double *dmom_v_ham_grad_p)
8878 {
8879  int k;
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++)
8886  {
8888  H_rho = smoothedHeaviside(eps_rho,phi[k]);
8889  d_rho = smoothedDirac(eps_rho,phi[k]);
8890  H_mu = smoothedHeaviside(eps_mu,phi[k]);
8891  d_mu = smoothedDirac(eps_mu,phi[k]);
8892 
8893  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
8894  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
8895  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
8896 
8897  //u momentum accumulation
8898  mom_u_acc[k]=porosity[k]*u[k];
8899  dmom_u_acc_u[k]=porosity[k];
8900 
8901  //v momentum accumulation
8902  mom_v_acc[k]=porosity[k]*v[k];
8903  dmom_v_acc_v[k]=porosity[k];
8904 
8905 
8906  //mass advective flux
8907  mass_adv[k*2+0]=porosity[k]*u[k];
8908  mass_adv[k*2+1]=porosity[k]*v[k];
8909 
8910  dmass_adv_u[k*2+0]=porosity[k];
8911  dmass_adv_v[k*2+1]=porosity[k];
8912 
8913  //u momentum advective flux
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];
8916 
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];
8919 
8920  dmom_u_adv_v[k*2+1]=porosity[k]*u[k];
8921 
8922  //v momentum advective_flux
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];
8925 
8926  dmom_v_adv_u[k*2+0]=porosity[k]*v[k];
8927 
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];
8930 
8931 #ifdef SCALAR_DIFFUSION
8932  //u momentum diffusion tensor
8933  mom_u_diff_ten[k*4+0] = nu*porosity[k];
8934  mom_u_diff_ten[k*4+3] = nu*porosity[k];
8935 
8936  //v momentum diffusion tensor
8937  mom_v_diff_ten[k*4+0] = nu*porosity[k];
8938  mom_v_diff_ten[k*4+3] = nu*porosity[k];
8939 #else
8940  //u momentum diffusion tensor
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;
8944 
8945  //v momentum diffusion tensor
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;
8949 #endif
8950 
8951  //momentum sources
8952  //two-phase flow contribution
8953  norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]);
8954  //porous medium contribution
8955  //end up with extra porosity term in final expression because multiply whole momentum
8956  //equation through by porosity
8957  uc = sqrt(u[k]*u[k]+v[k]*v[k]);
8958  if (fabs(1.0-porosity[k]) < 1.0e-7)
8959  Ftilde = 0.0;
8960  else
8961  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
8962  /*mwf hack
8963  Ftilde =0.0;
8964  */
8965  //allow only linear resistance for sponge layers etc
8966  Ftilde *= nonlinearDragFactor;
8967  //trap divide by zero here
8968  if (fabs(porosity[k]) < 1.0e-7)
8969  Kinv = 0.0;
8970  else
8971  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
8972 
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];
8977 
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)));
8980 
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)));
8983 
8984  //u momentum Hamiltonian (pressure)
8985 
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;
8988 
8989  //v momentum Hamiltonian (pressure)
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;
8992  //compressible form
8993 /* //u momentum accumulation */
8994 /* mom_u_acc[k]=porosity[k]*rho*u[k]; */
8995 /* dmom_u_acc_u[k]=porosity[k]*rho; */
8996 
8997 /* //v momentum accumulation */
8998 /* mom_v_acc[k]=porosity[k]*rho*v[k]; */
8999 /* dmom_v_acc_v[k]=porosity[k]*rho; */
9000 
9001 
9002 /* //mass advective flux */
9003 /* mass_adv[k*2+0]=porosity[k]*u[k]; */
9004 /* mass_adv[k*2+1]=porosity[k]*v[k]; */
9005 
9006 /* dmass_adv_u[k*2+0]=porosity[k]; */
9007 /* dmass_adv_v[k*2+1]=porosity[k]; */
9008 
9009 /* //u momentum advective flux */
9010 /* mom_u_adv[k*2+0]=porosity[k]*rho*u[k]*u[k]; */
9011 /* mom_u_adv[k*2+1]=porosity[k]*rho*u[k]*v[k]; */
9012 
9013 /* dmom_u_adv_u[k*2+0]=2.0*porosity[k]*rho*u[k]; */
9014 /* dmom_u_adv_u[k*2+1]=porosity[k]*rho*v[k]; */
9015 
9016 /* dmom_u_adv_v[k*2+1]=porosity[k]*rho*u[k]; */
9017 
9018 /* //v momentum advective_flux */
9019 /* mom_v_adv[k*2+0]=porosity[k]*rho*v[k]*u[k]; */
9020 /* mom_v_adv[k*2+1]=porosity[k]*rho*v[k]*v[k]; */
9021 
9022 /* dmom_v_adv_u[k*2+0]=porosity[k]*rho*v[k]; */
9023 
9024 /* dmom_v_adv_v[k*2+0]=porosity[k]*rho*u[k]; */
9025 /* dmom_v_adv_v[k*2+1]=2.0*porosity[k]*rho*v[k]; */
9026 
9027 /* //u momentum diffusion tensor */
9028 /* mom_u_diff_ten[k*4+0] = 2.0*porosity[k]*mu; */
9029 /* mom_u_diff_ten[k*4+3] = porosity[k]*mu; */
9030 /* mom_uv_diff_ten[k*4+2]=porosity[k]*mu; */
9031 
9032 /* //v momentum diffusion tensor */
9033 /* mom_v_diff_ten[k*4+0] = porosity[k]*mu; */
9034 /* mom_v_diff_ten[k*4+3] = 2.0*porosity[k]*mu; */
9035 /* mom_vu_diff_ten[k*4+1] = porosity[k]*mu; */
9036 
9037 
9038 /* //momentum sources */
9039 /* //two-phase flow contribution */
9040 /* norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]); */
9041 /* //porous medium contribution */
9042 /* //end up with extra porosity term in final expression because multiply whole momentum */
9043 /* //equation through by porosity */
9044 /* uc = sqrt(u[k]*u[k]+v[k]*v[k]); */
9045 /* if (fabs(1.0-porosity[k]) < 1.0e-7) */
9046 /* Ftilde = 0.0; */
9047 /* else */
9048 /* Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu; */
9049 /* /\*mwf hack */
9050 /* Ftilde =0.0; */
9051 /* *\/ */
9052 /* //trap divide by zero here */
9053 /* if (fabs(porosity[k]) < 1.0e-7) */
9054 /* Kinv = 0.0; */
9055 /* else */
9056 /* Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]); */
9057 
9058 /* mom_u_source[k] = -porosity[k]*rho*g[0] - d_mu*sigma*kappa[k]*n[k*2+0]/(norm_n) */
9059 /* + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*u[k]; */
9060 /* mom_v_source[k] = -porosity[k]*rho*g[1] - d_mu*sigma*kappa[k]*n[k*2+1]/(norm_n) */
9061 /* + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*v[k]; */
9062 
9063 /* dmom_u_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc + u[k]*u[k]/(uc+1.0e-12))); */
9064 /* dmom_u_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+1.0e-12))); */
9065 
9066 /* dmom_v_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc + v[k]*v[k]/(uc+1.0e-12))); */
9067 /* dmom_v_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+1.0e-12))); */
9068 
9069 /* //u momentum Hamiltonian (pressure) */
9070 
9071 /* mom_u_ham[k] = porosity[k]*grad_p[k*2+0]; */
9072 /* dmom_u_ham_grad_p[k*2+0]=porosity[k]; */
9073 
9074 /* //v momentum Hamiltonian (pressure) */
9075 /* mom_v_ham[k] = porosity[k]*grad_p[k*2+1]; */
9076 /* dmom_v_ham_grad_p[k*2+1]=porosity[k]; */
9077  }
9078 }
9080  const int killNonlinearDrag,
9081  const double eps_rho,
9082  const double eps_mu,
9083  const double sigma,
9084  const double rho_0,
9085  const double nu_0,
9086  const double rho_1,
9087  const double nu_1,
9088  const double* meanGrainSize,
9089  const double* g,
9090  const double* phi,
9091  const double* n,
9092  const double* kappa,
9093  const double *p,
9094  const double *grad_p,
9095  const double *u,
9096  const double *v,
9097  const double *porosity,
9098  double *mom_u_acc,
9099  double *dmom_u_acc_u,
9100  double *mom_v_acc,
9101  double *dmom_v_acc_v,
9102  double *mass_adv,
9103  double *dmass_adv_u,
9104  double *dmass_adv_v,
9105  double *mom_u_adv,
9106  double *dmom_u_adv_u,
9107  double *dmom_u_adv_v,
9108  double *mom_v_adv,
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,
9121  double *mom_u_ham,
9122  double *dmom_u_ham_grad_p,
9123  double *mom_v_ham,
9124  double *dmom_v_ham_grad_p)
9125 {
9126  int k;
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++)
9133  {
9135  H_rho = smoothedHeaviside(eps_rho,phi[k]);
9136  d_rho = smoothedDirac(eps_rho,phi[k]);
9137  H_mu = smoothedHeaviside(eps_mu,phi[k]);
9138  d_mu = smoothedDirac(eps_mu,phi[k]);
9139 
9140  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
9141  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
9142  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
9143  //u momentum accumulation
9144  mom_u_acc[k]=porosity[k]*u[k];
9145  dmom_u_acc_u[k]=porosity[k];
9146 
9147  //v momentum accumulation
9148  mom_v_acc[k]=porosity[k]*v[k];
9149  dmom_v_acc_v[k]=porosity[k];
9150 
9151  //mass advective flux
9152  mass_adv[k*2+0]=porosity[k]*u[k];
9153  mass_adv[k*2+1]=porosity[k]*v[k];
9154 
9155  dmass_adv_u[k*2+0]=porosity[k];
9156  dmass_adv_v[k*2+1]=porosity[k];
9157 
9158  //u momentum advective flux
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];
9161 
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];
9164 
9165  dmom_u_adv_v[k*2+1]=porosity[k]*u[k];
9166 
9167  //v momentum advective_flux
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];
9170 
9171  dmom_v_adv_u[k*2+0]=porosity[k]*v[k];
9172 
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];
9175 
9176  //u momentum diffusion tensor
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;
9180 
9181  //v momentum diffusion tensor
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];
9185 
9186  //momentum sources
9187  norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]);
9188  //porous medium contribution
9189  //end up with extra porosity term in final expression because multiply whole momentum
9190  //equation through by porosity
9191  uc = sqrt(u[k]*u[k]+v[k]*v[k]);
9192  if (fabs(1.0-porosity[k]) < 1.0e-7)
9193  Ftilde = 0.0;
9194  else
9195  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9196  /*mwf hack
9197  Ftilde =0.0;
9198  */
9199  //allow only linear resistance for sponge layers etc
9200  Ftilde *= nonlinearDragFactor;
9201  //trap divide by zero here
9202  if (fabs(porosity[k]) < 1.0e-7)
9203  Kinv = 0.0;
9204  else
9205  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9206 
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];
9211 
9212  /*mwf orig*/
9213 /* dmom_u_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc + u[k]*u[k]/(uc+div_eps))); */
9214 /* dmom_u_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+div_eps))); */
9215 
9216 /* dmom_v_source_u[k] = porosity[k]*porosity[k]*nu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+div_eps))); */
9217 /* dmom_v_source_v[k] = porosity[k]*porosity[k]*nu*Kinv*(1.0 + Ftilde*(uc + v[k]*v[k]/(uc+div_eps))); */
9218 
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);
9222 
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);
9226 
9227  //mwf debug
9228  //printf("k=%d uc=%g norm_n=%g porosity=%g meanGrain= %g Ftilde=%g Kinv=%g \n",k,uc,norm_n,porosity[k],meanGrainSize[k],Ftilde,Kinv);
9229  //u momentum Hamiltonian (pressure)
9230 
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;
9233 
9234  //v momentum Hamiltonian (pressure)
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;
9237 
9238  /* //compressible form */
9239  /* //u momentum accumulation */
9240  /* mom_u_acc[k]=porosity[k]*rho*u[k]; */
9241  /* dmom_u_acc_u[k]=porosity[k]*rho; */
9242 
9243  /* //v momentum accumulation */
9244  /* mom_v_acc[k]=porosity[k]*rho*v[k]; */
9245  /* dmom_v_acc_v[k]=porosity[k]*rho; */
9246 
9247  /* //mass advective flux */
9248  /* mass_adv[k*2+0]=porosity[k]*u[k]; */
9249  /* mass_adv[k*2+1]=porosity[k]*v[k]; */
9250 
9251  /* dmass_adv_u[k*2+0]=porosity[k]; */
9252  /* dmass_adv_v[k*2+1]=porosity[k]; */
9253 
9254  /* //u momentum advective flux */
9255  /* mom_u_adv[k*2+0]=porosity[k]*rho*u[k]*u[k]; */
9256  /* mom_u_adv[k*2+1]=porosity[k]*rho*u[k]*v[k]; */
9257 
9258  /* dmom_u_adv_u[k*2+0]=porosity[k]*rho*2.0*u[k]; */
9259  /* dmom_u_adv_u[k*2+1]=porosity[k]*rho*v[k]; */
9260 
9261  /* dmom_u_adv_v[k*2+1]=porosity[k]*rho*u[k]; */
9262 
9263  /* //v momentum advective_flux */
9264  /* mom_v_adv[k*2+0]=porosity[k]*rho*v[k]*u[k]; */
9265  /* mom_v_adv[k*2+1]=porosity[k]*rho*v[k]*v[k]; */
9266 
9267  /* dmom_v_adv_u[k*2+0]=porosity[k]*rho*v[k]; */
9268 
9269  /* dmom_v_adv_v[k*2+0]=porosity[k]*rho*u[k]; */
9270  /* dmom_v_adv_v[k*2+1]=porosity[k]*rho*2.0*v[k]; */
9271 
9272  /* //u momentum diffusion tensor */
9273  /* mom_u_diff_ten[k*2+0] = 2.0*porosity[k]*mu; */
9274  /* mom_u_diff_ten[k*2+1] = porosity[k]*mu; */
9275  /* mom_uv_diff_ten[k]=porosity[k]*mu; */
9276 
9277  /* //v momentum diffusion tensor */
9278  /* mom_v_diff_ten[k*2+0] = porosity[k]*mu; */
9279  /* mom_v_diff_ten[k*2+1] = 2.0*porosity[k]*mu; */
9280  /* mom_vu_diff_ten[k] = porosity[k]*mu; */
9281 
9282  /* //momentum sources */
9283  /* norm_n = sqrt(n[k*2+0]*n[k*2+0]+n[k*2+1]*n[k*2+1]); */
9284  //porous medium contribution
9285  //end up with extra porosity term in final expression because multiply whole momentum
9286  //equation through by porosity
9287 /* uc = sqrt(u[k]*u[k]+v[k]*v[k]); */
9288 /* if (fabs(1.0-porosity[k]) < 1.0e-7) */
9289 /* Ftilde = 0.0; */
9290 /* else */
9291 /* Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/mu; */
9292 /* /\*mwf hack */
9293 /* Ftilde =0.0; */
9294 /* *\/ */
9295 /* //trap divide by zero here */
9296 /* if (fabs(porosity[k]) < 1.0e-7) */
9297 /* Kinv = 0.0; */
9298 /* else */
9299 /* Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]); */
9300 
9301 /* mom_u_source[k] = -porosity[k]*rho*g[0] - porosity[k]*d_mu*sigma*kappa[k]*n[k*2+0]/(norm_n) */
9302 /* + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*u[k]; */
9303 /* mom_v_source[k] = -porosity[k]*rho*g[1] - porosity[k]*d_mu*sigma*kappa[k]*n[k*2+1]/(norm_n) */
9304 /* + porosity[k]*porosity[k]*mu*Kinv*(1.0+Ftilde*uc)*v[k]; */
9305 
9306 /* dmom_u_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc + u[k]*u[k]/(uc+div_eps))); */
9307 /* dmom_u_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+div_eps))); */
9308 
9309 /* dmom_v_source_v[k] = porosity[k]*porosity[k]*mu*Kinv*(1.0 + Ftilde*(uc + v[k]*v[k]/(uc+div_eps))); */
9310 /* dmom_v_source_u[k] = porosity[k]*porosity[k]*mu*Kinv*(0.0 + Ftilde*(u[k]*v[k]/(uc+div_eps))); */
9311 
9312  /* //u momentum Hamiltonian (pressure) */
9313 
9314  /* mom_u_ham[k] = grad_p[k*2+0]*porosity[k]; */
9315  /* dmom_u_ham_grad_p[k*2+0]=porosity[k]; */
9316 
9317  /* //v momentum Hamiltonian (pressure) */
9318  /* mom_v_ham[k] = grad_p[k*2+1]*porosity[k]; */
9319  /* dmom_v_ham_grad_p[k*2+1]=porosity[k]; */
9320  }
9321 }
9323  const int killNonlinearDrag,
9324  const double eps_rho,
9325  const double eps_mu,
9326  const double sigma,
9327  const double rho_0,
9328  const double nu_0,
9329  const double rho_1,
9330  const double nu_1,
9331  const double* meanGrainSize,
9332  const double* g,
9333  const double* phi,
9334  const double* n,
9335  const double* kappa,
9336  const double *p,
9337  const double *grad_p,
9338  const double *u,
9339  const double *v,
9340  const double *w,
9341  const double *porosity,
9342  double *mom_u_acc,
9343  double *dmom_u_acc_u,
9344  double *mom_v_acc,
9345  double *dmom_v_acc_v,
9346  double *mom_w_acc,
9347  double *dmom_w_acc_w,
9348  double *mass_adv,
9349  double *dmass_adv_u,
9350  double *dmass_adv_v,
9351  double *dmass_adv_w,
9352  double *mom_u_adv,
9353  double *dmom_u_adv_u,
9354  double *dmom_u_adv_v,
9355  double *dmom_u_adv_w,
9356  double *mom_v_adv,
9357  double *dmom_v_adv_u,
9358  double *dmom_v_adv_v,
9359  double *dmom_v_adv_w,
9360  double *mom_w_adv,
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,
9385  double *mom_u_ham,
9386  double *dmom_u_ham_grad_p,
9387  double *mom_v_ham,
9388  double *dmom_v_ham_grad_p,
9389  double *mom_w_ham,
9390  double *dmom_w_ham_grad_p)
9391 {
9392  int k;
9393  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n,
9394  uc,Ftilde,Kinv;
9395  double nonlinearDragFactor = 1.0;
9396  if (killNonlinearDrag)
9397  nonlinearDragFactor = 0.0;
9398  for (k=0;k<nPoints;k++)
9399  {
9401  /*H = smoothedHeaviside(eps,phi[k]);*/
9402  H_rho = smoothedHeaviside(eps_rho,phi[k]);
9403  d_rho = smoothedDirac(eps_rho,phi[k]);
9404  H_mu = smoothedHeaviside(eps_mu,phi[k]);
9405  d_mu = smoothedDirac(eps_mu,phi[k]);
9406 
9407  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
9408  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
9409  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
9410 
9411 /* //u momentum accumulation */
9412 /* mom_u_acc[k]=rho*porosity[k]*u[k]; */
9413 /* dmom_u_acc_u[k]=rho*porosity[k]; */
9414 
9415 /* //v momentum accumulation */
9416 /* mom_v_acc[k]=rho*porosity[k]*v[k]; */
9417 /* dmom_v_acc_v[k]=rho*porosity[k]; */
9418 
9419 /* //w momentum accumulation */
9420 /* mom_w_acc[k]=rho*porosity[k]*w[k]; */
9421 /* dmom_w_acc_w[k]=rho*porosity[k]; */
9422 
9423 
9424 /* //mass advective flux */
9425 /* mass_adv[k*3+0]=porosity[k]*u[k]; */
9426 /* mass_adv[k*3+1]=porosity[k]*v[k]; */
9427 /* mass_adv[k*3+2]=porosity[k]*w[k]; */
9428 
9429 /* dmass_adv_u[k*3+0]=porosity[k]; */
9430 /* dmass_adv_v[k*3+1]=porosity[k]; */
9431 /* dmass_adv_w[k*3+2]=porosity[k]; */
9432 
9433 /* //u momentum advective flux */
9434 /* mom_u_adv[k*3+0]=rho*porosity[k]*u[k]*u[k]; */
9435 /* mom_u_adv[k*3+1]=rho*porosity[k]*u[k]*v[k]; */
9436 /* mom_u_adv[k*3+2]=rho*porosity[k]*u[k]*w[k]; */
9437 
9438 /* dmom_u_adv_u[k*3+0]=2.0*rho*porosity[k]*u[k]; */
9439 /* dmom_u_adv_u[k*3+1]=rho*porosity[k]*v[k]; */
9440 /* dmom_u_adv_u[k*3+2]=rho*porosity[k]*w[k]; */
9441 
9442 /* dmom_u_adv_v[k*3+1]=rho*porosity[k]*u[k]; */
9443 
9444 /* dmom_u_adv_w[k*3+2]=rho*porosity[k]*u[k]; */
9445 
9446 /* //v momentum advective_flux */
9447 /* mom_v_adv[k*3+0]=rho*porosity[k]*v[k]*u[k]; */
9448 /* mom_v_adv[k*3+1]=rho*porosity[k]*v[k]*v[k]; */
9449 /* mom_v_adv[k*3+2]=rho*porosity[k]*v[k]*w[k]; */
9450 
9451 /* dmom_v_adv_u[k*3+0]=rho*porosity[k]*v[k]; */
9452 
9453 /* dmom_v_adv_w[k*3+2]=rho*porosity[k]*v[k]; */
9454 
9455 /* dmom_v_adv_v[k*3+0]=rho*porosity[k]*u[k]; */
9456 /* dmom_v_adv_v[k*3+1]=2.0*rho*porosity[k]*v[k]; */
9457 /* dmom_v_adv_v[k*3+2]=rho*porosity[k]*w[k]; */
9458 
9459 /* //w momentum advective_flux */
9460 /* mom_w_adv[k*3+0]=rho*porosity[k]*w[k]*u[k]; */
9461 /* mom_w_adv[k*3+1]=rho*porosity[k]*w[k]*v[k]; */
9462 /* mom_w_adv[k*3+2]=rho*porosity[k]*w[k]*w[k]; */
9463 
9464 /* dmom_w_adv_u[k*3+0]=rho*porosity[k]*w[k]; */
9465 
9466 /* dmom_w_adv_v[k*3+1]=rho*porosity[k]*w[k]; */
9467 
9468 /* dmom_w_adv_w[k*3+0]=rho*porosity[k]*u[k]; */
9469 /* dmom_w_adv_w[k*3+1]=rho*porosity[k]*v[k]; */
9470 /* dmom_w_adv_w[k*3+2]=2.0*rho*porosity[k]*w[k]; */
9471 
9472 /* //u momentum diffusion tensor */
9473 /* mom_u_diff_ten[k*9+0] = 2.0*porosity[k]*mu; */
9474 /* mom_u_diff_ten[k*9+4] = porosity[k]*mu; */
9475 /* mom_u_diff_ten[k*9+8] = porosity[k]*mu; */
9476 
9477 /* mom_uv_diff_ten[k*9+3]=porosity[k]*mu; */
9478 
9479 /* mom_uw_diff_ten[k*9+6]=porosity[k]*mu; */
9480 
9481 /* //v momentum diffusion tensor */
9482 /* mom_v_diff_ten[k*9+0] = porosity[k]*mu; */
9483 /* mom_v_diff_ten[k*9+4] = 2.0*porosity[k]*mu; */
9484 /* mom_v_diff_ten[k*9+8] = porosity[k]*mu; */
9485 
9486 /* mom_vu_diff_ten[k*9+1]=porosity[k]*mu; */
9487 
9488 /* mom_vw_diff_ten[k*9+7]=porosity[k]*mu; */
9489 
9490 /* //w momentum diffusion tensor */
9491 /* mom_w_diff_ten[k*9+0] = porosity[k]*mu; */
9492 /* mom_w_diff_ten[k*9+4] = porosity[k]*mu; */
9493 /* mom_w_diff_ten[k*9+8] = 2.0*porosity[k]*mu; */
9494 
9495 /* mom_wu_diff_ten[k*9+2]=porosity[k]*mu; */
9496 
9497 /* mom_wv_diff_ten[k*9+5]=porosity[k]*mu; */
9498 
9499 /* //momentum sources */
9500 /* 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]); */
9501 /* mom_u_source[k] = -rho*porosity[k]*g[0] - *porosity[k]*d_mu*sigma*kappa[k]*n[k*3+0]/(norm_n); */
9502 /* mom_v_source[k] = -rho*porosity[k]*g[1] - *porosity[k]*d_mu*sigma*kappa[k]*n[k*3+1]/(norm_n); */
9503 /* mom_w_source[k] = -rho*porosity[k]*g[2] - *porosity[k]*d_mu*sigma*kappa[k]*n[k*3+2]/(norm_n); */
9504 
9505 
9506 /* //u momentum Hamiltonian (pressure) */
9507 /* mom_u_ham[k] = grad_p[k*3+0]; */
9508 /* dmom_u_ham_grad_p[k*3+0]=1.0; */
9509 
9510 /* //v momentum Hamiltonian (pressure) */
9511 /* mom_v_ham[k] = grad_p[k*3+1]; */
9512 /* dmom_v_ham_grad_p[k*3+1]=1.0; */
9513 
9514 /* //w momentum Hamiltonian (pressure) */
9515 /* mom_w_ham[k] = grad_p[k*3+2]; */
9516 /* dmom_w_ham_grad_p[k*3+2]=1.0; */
9517 
9518  //cek "incompressible" form
9519  //u momentum accumulation
9520  mom_u_acc[k]=porosity[k]*u[k];
9521  dmom_u_acc_u[k]=porosity[k];
9522 
9523  //v momentum accumulation
9524  mom_v_acc[k]=porosity[k]*v[k];
9525  dmom_v_acc_v[k]=porosity[k];
9526 
9527  //w momentum accumulation
9528  mom_w_acc[k]=porosity[k]*w[k];
9529  dmom_w_acc_w[k]=porosity[k];
9530 
9531 
9532  //mass advective flux
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];
9536 
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];
9540 
9541  //u momentum advective flux
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];
9545 
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];
9549 
9550  dmom_u_adv_v[k*3+1]=porosity[k]*u[k];
9551 
9552  dmom_u_adv_w[k*3+2]=porosity[k]*u[k];
9553 
9554  //v momentum advective_flux
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];
9558 
9559  dmom_v_adv_u[k*3+0]=porosity[k]*v[k];
9560 
9561  dmom_v_adv_w[k*3+2]=porosity[k]*v[k];
9562 
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];
9566 
9567  //w momentum advective_flux
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];
9571 
9572  dmom_w_adv_u[k*3+0]=porosity[k]*w[k];
9573 
9574  dmom_w_adv_v[k*3+1]=porosity[k]*w[k];
9575 
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];
9579 
9580  //u momentum diffusion tensor
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;
9584 
9585  mom_uv_diff_ten[k*9+3]=porosity[k]*nu;
9586 
9587  mom_uw_diff_ten[k*9+6]=porosity[k]*nu;
9588 
9589  //v momentum diffusion tensor
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;
9593 
9594  mom_vu_diff_ten[k*9+1]=porosity[k]*nu;
9595 
9596  mom_vw_diff_ten[k*9+7]=porosity[k]*nu;
9597 
9598  //w momentum diffusion tensor
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;
9602 
9603  mom_wu_diff_ten[k*9+2]=porosity[k]*nu;
9604 
9605  mom_wv_diff_ten[k*9+5]=porosity[k]*nu;
9606 
9607  //momentum sources
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]);
9609  //porous medium contribution
9610  //end up with extra porosity term in final expression because multiply whole momentum
9611  //equation through by porosity
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)
9614  Ftilde = 0.0;
9615  else
9616  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9617  /*mwf hack
9618  Ftilde =0.0;
9619  */
9620  //allow only linear resistance for sponge layers etc
9621  Ftilde *= nonlinearDragFactor;
9622  //trap divide by zero here
9623  if (fabs(porosity[k]) < 1.0e-7)
9624  Kinv = 0.0;
9625  else
9626  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9627 
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];
9634 
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)));
9638 
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)));
9642 
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)));
9646 
9647  //u momentum Hamiltonian (pressure)
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;
9650 
9651  //v momentum Hamiltonian (pressure)
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;
9654 
9655  //w momentum Hamiltonian (pressure)
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;
9658  }
9659 }
9661  const int killNonlinearDrag,
9662  const double eps_rho,
9663  const double eps_mu,
9664  const double sigma,
9665  const double rho_0,
9666  const double nu_0,
9667  const double rho_1,
9668  const double nu_1,
9669  const double* meanGrainSize,
9670  const double* g,
9671  const double* phi,
9672  const double* n,
9673  const double* kappa,
9674  const double *p,
9675  const double *grad_p,
9676  const double *u,
9677  const double *v,
9678  const double *w,
9679  const double *porosity,
9680  double *mom_u_acc,
9681  double *dmom_u_acc_u,
9682  double *mom_v_acc,
9683  double *dmom_v_acc_v,
9684  double *mom_w_acc,
9685  double *dmom_w_acc_w,
9686  double *mass_adv,
9687  double *dmass_adv_u,
9688  double *dmass_adv_v,
9689  double *dmass_adv_w,
9690  double *mom_u_adv,
9691  double *dmom_u_adv_u,
9692  double *dmom_u_adv_v,
9693  double *dmom_u_adv_w,
9694  double *mom_v_adv,
9695  double *dmom_v_adv_u,
9696  double *dmom_v_adv_v,
9697  double *dmom_v_adv_w,
9698  double *mom_w_adv,
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,
9723  double *mom_u_ham,
9724  double *dmom_u_ham_grad_p,
9725  double *mom_v_ham,
9726  double *dmom_v_ham_grad_p,
9727  double *mom_w_ham,
9728  double *dmom_w_ham_grad_p)
9729 {
9730  int k;
9731  double rho,nu,mu,H_rho,d_rho,H_mu,d_mu,norm_n,
9732  uc,Ftilde,Kinv;
9733  double nonlinearDragFactor = 1.0;
9734  if (killNonlinearDrag)
9735  nonlinearDragFactor = 0.0;
9736  for (k=0;k<nPoints;k++)
9737  {
9739  /*H = smoothedHeaviside(eps,phi[k]);*/
9740  H_rho = smoothedHeaviside(eps_rho,phi[k]);
9741  d_rho = smoothedDirac(eps_rho,phi[k]);
9742  H_mu = smoothedHeaviside(eps_mu,phi[k]);
9743  d_mu = smoothedDirac(eps_mu,phi[k]);
9744 
9745  rho = rho_0*(1.0-H_rho)+rho_1*H_rho;
9746  nu = nu_0*(1.0-H_mu)+nu_1*H_mu;
9747  mu = rho_0*nu_0*(1.0-H_mu)+rho_1*nu_1*H_mu;
9748 
9749  //u momentum accumulation
9750  mom_u_acc[k]=porosity[k]*u[k];
9751  dmom_u_acc_u[k]=porosity[k];
9752 
9753  //v momentum accumulation
9754  mom_v_acc[k]=porosity[k]*v[k];
9755  dmom_v_acc_v[k]=porosity[k];
9756 
9757  //w momentum accumulation
9758  mom_w_acc[k]=porosity[k]*w[k];
9759  dmom_w_acc_w[k]=porosity[k];
9760 
9761 
9762  //mass advective flux
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];
9766 
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];
9770 
9771  //u momentum advective flux
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];
9775 
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];
9779 
9780  dmom_u_adv_v[k*3+1]=porosity[k]*u[k];
9781 
9782  dmom_u_adv_w[k*3+2]=porosity[k]*u[k];
9783 
9784  //v momentum advective_flux
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];
9788 
9789  dmom_v_adv_u[k*3+0]=porosity[k]*v[k];
9790 
9791  dmom_v_adv_w[k*3+2]=porosity[k]*v[k];
9792 
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];
9796 
9797  //w momentum advective_flux
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];
9801 
9802  dmom_w_adv_u[k*3+0]=porosity[k]*w[k];
9803 
9804  dmom_w_adv_v[k*3+1]=porosity[k]*w[k];
9805 
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];
9809 
9810  //u momentum diffusion tensor
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;
9814 
9815  mom_uv_diff_ten[k]=porosity[k]*nu;
9816 
9817  mom_uw_diff_ten[k]=porosity[k]*nu;
9818 
9819  //v momentum diffusion tensor
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;
9823 
9824  mom_vu_diff_ten[k]=porosity[k]*nu;
9825 
9826  mom_vw_diff_ten[k]=porosity[k]*nu;
9827 
9828  //w momentum diffusion tensor
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;
9832 
9833  mom_wu_diff_ten[k]=porosity[k]*nu;
9834 
9835  mom_wv_diff_ten[k]=porosity[k]*nu;
9836 
9837  //momentum sources
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]);
9839  //end up with extra porosity term in final expression because multiply whole momentum
9840  //equation through by porosity
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)
9843  Ftilde = 0.0;
9844  else
9845  Ftilde = porosity[k]*meanGrainSize[k]*1.0e-2/(1.0-porosity[k])/nu;
9846  /*mwf hack
9847  Ftilde =0.0;
9848  */
9849  //allow only linear resistance for sponge layers etc
9850  Ftilde *= nonlinearDragFactor;
9851  //trap divide by zero here
9852  if (fabs(porosity[k]) < 1.0e-7)
9853  Kinv = 0.0;
9854  else
9855  Kinv = 180.0*(1.0-porosity[k])*(1.0-porosity[k])/(meanGrainSize[k]*meanGrainSize[k]*porosity[k]*porosity[k]*porosity[k]);
9856 
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];
9863 
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)));
9867 
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)));
9871 
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)));
9875 
9876 
9877  //u momentum Hamiltonian (pressure)
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;
9880 
9881  //v momentum Hamiltonian (pressure)
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;
9884 
9885  //w momentum Hamiltonian (pressure)
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;
9888  }
9889 }
9891  int nSpace,
9892  double eps,
9893  double* v,
9894  double* phi,
9895  double* porosity,
9896  double* u,
9897  double* m,
9898  double* dm,
9899  double* f,
9900  double* df)
9901 {
9902 /* printf("eps in vof %12.5e\n",eps); */
9903  int i,I;
9904  for (i=0;i<nPoints;i++)
9905  {
9906  m[i]=u[i]*porosity[i];
9907  dm[i]=porosity[i];
9908  for (I=0;I<nSpace;I++)
9909  {
9910 /* f[i*nSpace+I] = porosity[i]*v[i*nSpace+I]*smoothedHeaviside(eps,phi[i]); */
9911 /* df[i*nSpace+I] = 0.0; */
9912  f[i*nSpace+I] = porosity[i]*v[i*nSpace+I]*u[i];
9913  df[i*nSpace+I] = porosity[i]*v[i*nSpace+I];
9914  }
9915  }
9916 }
9917 
9918 /***********************************************************************
9919  Basic k-epsilon model for incompressible flow from Hutter etal Chaper 11
9920 
9921 \bar{\vec v} = <\vec v> Reynolds-averaged (mean) velocity
9922 \vec v^{'} = turbulent fluctuation
9923 assume \vec v = <\vec v> + \vec v^{'}, with <\vec v^{'}> = 0
9924 
9925 Reynolds averaged NS equations
9926 
9927 \deld \bar{\vec v} = 0
9928 
9929 \pd{\bar{\vec v}}{t} + \deld \left(\bar{\vec v} \outer \bar{\vec v}\right)
9930  -\nu \deld \ten \bar{D} + \frac{1}{\rho}\grad \bar p
9931  - \frac{1}{rho}\deld \ten{R} = 0
9932 
9933 Reynolds stress term
9934 
9935 \ten R = -\rho <\vec v^{'}\outer \vec v^{'}>
9936 \frac{1}{\rho}\ten{R} = 2 \nu_t \bar{D} - \frac{2}{3}k\ten{I}
9937 
9938 D_{ij}(\vec v) = \frac{1}{2} \left( \pd{v_i}{x_j} + \pd{v_j}{x_i})
9939 \ten D \bar{\ten D} = D(<\vec v>), \ten D^{'} = \ten D(\vec v^{'})
9940 
9941 
9942 
9943 k-epsilon tranport equations
9944 
9945 \pd{k}{t} + \deld (k\bar{\vec v})
9946  - \deld\left[\left(\frac{\nu_t}{\sigma_k} + \nu\right)\grad k \right]
9947  - 4\nu_t \Pi_{D} + \epsilon = 0
9948 
9949 \pd{\varepsilon}{t} + \deld (\varepsilon \bar{\vec v})
9950  - \deld\left[\left(\frac{\nu_t}{\sigma_\varepsilon} + \nu\right)\grad \varepsilon \right]
9951  - 4c_1 k \Pi_{D} + c_2 \frac{\epsilon^2}{k} = 0
9952 
9953 
9954 k -- turbulent kinetic energy = <\vec v^{'}\dot \vec v^{'}>
9955 \varepsilon -- turbulent dissipation rate = 4 \nu <\Pi_{D^{'}}>
9956 
9957 \nu -- kinematic viscosity (\mu/\rho)
9958 \nu_t -- turbulent viscosity = c_mu \frac{k^2}{\varepsilon}
9959 
9960 
9961 \Pi_{\ten A} = \frac{1}{2}tr(\ten A^2) = 1/2 \ten A\cdot \ten A
9962 \ten D \cdot \ten D = \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
9963  1/2 (u_y + v_x)^2 \right]
9964 
9965 4 \Pi_{D} = 2 \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
9966  1/2 (u_y + v_x)^2 \right]
9967  = \left[ (2 u_x^2 + 2 v_y^2 + (u_y + v_x)^2 \right]
9968 
9969 \sigma_k -- Prandtl number \approx 1
9970 \sigma_e -- c_{\mu}/c_e
9971 
9972 c_{\mu} = 0.09, c_1 = 0.126, c_2 = 1.92, c_{\varepsilon} = 0.07
9973 
9974  ***********************************************************************/
9975 void kEpsilon_2D_Evaluate(int nPoints,
9976  int nSpace,
9977  double sigma_k,
9978  double sigma_e,
9979  double c_1,
9980  double c_2,
9981  double c_mu,
9982  double c_e,
9983  double nu,
9984  double *velocity,
9985  double *gradu,
9986  double *gradv,
9987  double *k,
9988  double *epsilon,
9989  double *m_k,
9990  double *dm_k,
9991  double *m_e,
9992  double *dm_e,
9993  double *phi_k,
9994  double *dphi_k,
9995  double *phi_e,
9996  double *dphi_e,
9997  double *f_k,
9998  double *df_k,
9999  double *f_e,
10000  double *df_e,
10001  double *a_k,
10002  double *da_k_dk,
10003  double *da_k_de,
10004  double *a_e,
10005  double *da_e_dk,
10006  double *da_e_de,
10007  double *r_k,
10008  double *dr_k_dk,
10009  double *dr_k_de,
10010  double *r_e,
10011  double *dr_e_dk,
10012  double *dr_e_de)
10013 
10014 {
10015  int i,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++)
10019  {
10020  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10021  kval = k[i] >= 0.0 ? k[i] : 0.0;
10022  /*eddy viscosity*/
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);
10026  if (nu_t < 0.0)
10027  {
10028  nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10029  }
10030  /*mwf debug
10031  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10032  nu_t,dnu_t_dk,dnu_t_de);
10033  */
10034  /*linear mass terms for k-e*/
10035  m_k[i] = k[i];
10036  dm_k[i]= 1.0;
10037 
10038  m_e[i] = epsilon[i];
10039  dm_e[i]= 1.0;
10040 
10041  /*linear advection*/
10042  for (I=0; I < nSpace; I++)
10043  {
10044  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10045  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10046 
10047  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10048  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10049  }
10050  /*linear potentials*/
10051  phi_k[i] = k[i];
10052  dphi_k[i]= 1.0;
10053  phi_e[i] = epsilon[i];
10054  dphi_e[i]= 1.0;
10055 
10056  /*nonlinear diffusion*/
10057  for (I=0; I < nSpace; I++)
10058  {
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;
10062 
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;
10066  }
10067 
10068  /*production term*/
10069  /*4*Pi_D*/
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]);
10072 
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;
10076 
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);
10080  if (disp < 0.0)
10081  {
10082  disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10083  }
10084  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10085  dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;/* -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps); */
10086  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10087 
10088  }
10089 }
10090 void kEpsilon_2D_Evaluate_sd(int nPoints,
10091  int nSpace,
10092  double sigma_k,
10093  double sigma_e,
10094  double c_1,
10095  double c_2,
10096  double c_mu,
10097  double c_e,
10098  double nu,
10099  double *velocity,
10100  double *gradu,
10101  double *gradv,
10102  double *k,
10103  double *epsilon,
10104  double *m_k,
10105  double *dm_k,
10106  double *m_e,
10107  double *dm_e,
10108  double *phi_k,
10109  double *dphi_k,
10110  double *phi_e,
10111  double *dphi_e,
10112  double *f_k,
10113  double *df_k,
10114  double *f_e,
10115  double *df_e,
10116  double *a_k,
10117  double *da_k_dk,
10118  double *da_k_de,
10119  double *a_e,
10120  double *da_e_dk,
10121  double *da_e_de,
10122  double *r_k,
10123  double *dr_k_dk,
10124  double *dr_k_de,
10125  double *r_e,
10126  double *dr_e_dk,
10127  double *dr_e_de)
10128 
10129 {
10130  int i,I;
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++)
10134  {
10135  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10136  kval = k[i] >= 0.0 ? k[i] : 0.0;
10137  /*eddy viscosity*/
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);
10141  if (nu_t < 0.0)
10142  {
10143  nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10144  }
10145  /*mwf debug
10146  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10147  nu_t,dnu_t_dk,dnu_t_de);
10148  */
10149  /*linear mass terms for k-e*/
10150  m_k[i] = k[i];
10151  dm_k[i]= 1.0;
10152 
10153  m_e[i] = epsilon[i];
10154  dm_e[i]= 1.0;
10155 
10156  /*linear advection*/
10157  for (I=0; I < nSpace; I++)
10158  {
10159  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10160  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10161 
10162  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10163  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10164  }
10165  /*linear potentials*/
10166  phi_k[i] = k[i];
10167  dphi_k[i]= 1.0;
10168  phi_e[i] = epsilon[i];
10169  dphi_e[i]= 1.0;
10170 
10171  /*nonlinear diffusion*/
10172  for (I=0; I < nSpace; I++)
10173  {
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;
10177 
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;
10181  }
10182 
10183  /*production term*/
10184  /*4*Pi_D*/
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]);
10187 
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;
10191 
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);
10195  if (disp < 0.0)
10196  {
10197  disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10198  }
10199  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10200  dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;/* -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps); */
10201  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10202 
10203  }
10204 }
10205 void kEpsilon_3D_Evaluate_sd(int nPoints,
10206  int nSpace,
10207  double sigma_k,
10208  double sigma_e,
10209  double c_1,
10210  double c_2,
10211  double c_mu,
10212  double c_e,
10213  double nu,
10214  double *velocity,
10215  double *gradu,
10216  double *gradv,
10217  double *gradw,
10218  double *k,
10219  double *epsilon,
10220  double *m_k,
10221  double *dm_k,
10222  double *m_e,
10223  double *dm_e,
10224  double *phi_k,
10225  double *dphi_k,
10226  double *phi_e,
10227  double *dphi_e,
10228  double *f_k,
10229  double *df_k,
10230  double *f_e,
10231  double *df_e,
10232  double *a_k,
10233  double *da_k_dk,
10234  double *da_k_de,
10235  double *a_e,
10236  double *da_e_dk,
10237  double *da_e_de,
10238  double *r_k,
10239  double *dr_k_dk,
10240  double *dr_k_de,
10241  double *r_e,
10242  double *dr_e_dk,
10243  double *dr_e_de)
10244 
10245 {
10246  int i,I;
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++)
10250  {
10251  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10252  kval = k[i] >= 0.0 ? k[i] : 0.0;
10253  /*eddy viscosity*/
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);
10257  if (nu_t < 0.0)
10258  {
10259  nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10260  }
10261  /*mwf debug
10262  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10263  nu_t,dnu_t_dk,dnu_t_de);
10264  */
10265  /*linear mass terms for k-e*/
10266  m_k[i] = k[i];
10267  dm_k[i]= 1.0;
10268 
10269  m_e[i] = epsilon[i];
10270  dm_e[i]= 1.0;
10271 
10272  /*linear advection*/
10273  for (I=0; I < nSpace; I++)
10274  {
10275  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10276  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10277 
10278  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10279  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10280  }
10281  /*linear potentials*/
10282  phi_k[i] = k[i];
10283  dphi_k[i]= 1.0;
10284  phi_e[i] = epsilon[i];
10285  dphi_e[i]= 1.0;
10286 
10287  /*nonlinear diffusion*/
10288  for (I=0; I < nSpace; I++)
10289  {
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;
10293 
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;
10297  }
10298 
10299  /*production term*/
10300  /*4*Pi_D*/
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])
10304  +
10305  (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10306  +
10307  (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10308  +
10309  (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10310 
10311 
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;
10315 
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);
10319  if (disp < 0.0)
10320  {
10321  disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10322  }
10323  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10324  dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;/* -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps); */
10325  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10326 
10327  }
10328 }
10329 void kEpsilon_3D_Evaluate(int nPoints,
10330  int nSpace,
10331  double sigma_k,
10332  double sigma_e,
10333  double c_1,
10334  double c_2,
10335  double c_mu,
10336  double c_e,
10337  double nu,
10338  double *velocity,
10339  double *gradu,
10340  double *gradv,
10341  double *gradw,
10342  double *k,
10343  double *epsilon,
10344  double *m_k,
10345  double *dm_k,
10346  double *m_e,
10347  double *dm_e,
10348  double *phi_k,
10349  double *dphi_k,
10350  double *phi_e,
10351  double *dphi_e,
10352  double *f_k,
10353  double *df_k,
10354  double *f_e,
10355  double *df_e,
10356  double *a_k,
10357  double *da_k_dk,
10358  double *da_k_de,
10359  double *a_e,
10360  double *da_e_dk,
10361  double *da_e_de,
10362  double *r_k,
10363  double *dr_k_dk,
10364  double *dr_k_de,
10365  double *r_e,
10366  double *dr_e_dk,
10367  double *dr_e_de)
10368 
10369 {
10370  int i,I;
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++)
10374  {
10375  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10376  kval = k[i] >= 0.0 ? k[i] : 0.0;
10377  /*eddy viscosity*/
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);
10381  if (nu_t < 0.0)
10382  {
10383  nu_t = 0.0; dnu_t_dk = 0.0; dnu_t_de = 0.0;
10384  }
10385  /*mwf debug
10386  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10387  nu_t,dnu_t_dk,dnu_t_de);
10388  */
10389  /*linear mass terms for k-e*/
10390  m_k[i] = k[i];
10391  dm_k[i]= 1.0;
10392 
10393  m_e[i] = epsilon[i];
10394  dm_e[i]= 1.0;
10395 
10396  /*linear advection*/
10397  for (I=0; I < nSpace; I++)
10398  {
10399  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10400  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10401 
10402  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10403  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10404  }
10405  /*linear potentials*/
10406  phi_k[i] = k[i];
10407  dphi_k[i]= 1.0;
10408  phi_e[i] = epsilon[i];
10409  dphi_e[i]= 1.0;
10410 
10411  /*nonlinear diffusion*/
10412  for (I=0; I < nSpace; I++)
10413  {
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;
10417 
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;
10421  }
10422 
10423  /*production term*/
10424  /*4*Pi_D*/
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])
10428  +
10429  (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10430  +
10431  (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10432  +
10433  (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10434 
10435 
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;
10439 
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);
10443  if (disp < 0.0)
10444  {
10445  disp = 0.0; ddisp_dk = 0.0; ddisp_de = 0.0;
10446  }
10447  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10448  dr_e_dk[i] = -c_1*PiD4 + ddisp_dk;/* -c_2*epsilon[i]*epsilon[i]/(k[i]*k[i]+div_eps); */
10449  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10450 
10451  }
10452 }
10453 
10454 
10455 /*version of kEpsilon where k and epsilon are solved independently */
10456 void kEpsilon_k_2D_Evaluate_sd(int nPoints,
10457  int nSpace,
10458  double sigma_k,
10459  double c_mu,
10460  double nu,
10461  double *velocity,
10462  double *gradu,
10463  double *gradv,
10464  double *k,
10465  double *epsilon,
10466  double *m_k,
10467  double *dm_k,
10468  double *phi_k,
10469  double *dphi_k,
10470  double *f_k,
10471  double *df_k,
10472  double *a_k,
10473  double *da_k_dk,
10474  double *r_k,
10475  double *dr_k_dk)
10476 
10477 {
10478  int i,I;
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++)
10482  {
10483  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10484  kval = k[i] >= 0.0 ? k[i] : 0.0;
10485  /*eddy viscosity*/
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);
10488  if (nu_t < 0.0)
10489  {
10490  nu_t = 0.0; dnu_t_dk = 0.0;
10491  }
10492  /*mwf debug
10493  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g\n",i,k[i],i,epsilon[i],
10494  nu_t,dnu_t_dk);
10495  */
10496  /*linear mass terms for k-e*/
10497  m_k[i] = k[i];
10498  dm_k[i]= 1.0;
10499  /*linear advection*/
10500  for (I=0; I < nSpace; I++)
10501  {
10502  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10503  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10504  }
10505  /*linear potentials*/
10506  phi_k[i] = k[i];
10507  dphi_k[i]= 1.0;
10508  /*nonlinear diffusion*/
10509  for (I=0; I < nSpace; I++)
10510  {
10511  a_k[i*2+I] = nu_t/sigma_k + nu;
10512  da_k_dk[i*2 + I] = dnu_t_dk/sigma_k;
10513 
10514  }
10515 
10516  /*production term*/
10517  /*4*Pi_D*/
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]);
10520 
10521  r_k[i] = -nu_t*PiD4 + epsilon[i];
10522  dr_k_dk[i] = -dnu_t_dk*PiD4;
10523 
10524  }
10525 }
10527  int nSpace,
10528  double sigma_e,
10529  double c_1,
10530  double c_2,
10531  double c_mu,
10532  double c_e,
10533  double nu,
10534  double *velocity,
10535  double *gradu,
10536  double *gradv,
10537  double *k,
10538  double *epsilon,
10539  double *m_e,
10540  double *dm_e,
10541  double *phi_e,
10542  double *dphi_e,
10543  double *f_e,
10544  double *df_e,
10545  double *a_e,
10546  double *da_e_de,
10547  double *r_e,
10548  double *dr_e_de)
10549 
10550 {
10551  int i,I;
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++)
10555  {
10556  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10557  kval = k[i] >= 0.0 ? k[i] : 0.0;
10558  /*eddy viscosity*/
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);
10561  if (nu_t < 0.0)
10562  {
10563  nu_t = 0.0; dnu_t_de = 0.0;
10564  }
10565  /*mwf debug
10566  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10567  nu_t,dnu_t_de);
10568  */
10569  /*linear mass terms for e*/
10570  m_e[i] = epsilon[i];
10571  dm_e[i]= 1.0;
10572 
10573  /*linear advection*/
10574  for (I=0; I < nSpace; I++)
10575  {
10576  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10577  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10578  }
10579  /*linear potential*/
10580  phi_e[i] = epsilon[i];
10581  dphi_e[i]= 1.0;
10582 
10583  /*nonlinear diffusion*/
10584  for (I=0; I < nSpace; I++)
10585  {
10586  a_e[i*2 + I] = nu_t/sigma_e + nu;
10587  da_e_de[i*2 + I] = dnu_t_de/sigma_e;
10588  }
10589 
10590  /*production term*/
10591  /*4*Pi_D*/
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]);
10594 
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);
10597  if (disp < 0.0)
10598  {
10599  disp = 0.0; ddisp_de = 0.0;
10600  }
10601  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10602  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10603 
10604  }
10605 }
10606 void kEpsilon_k_3D_Evaluate_sd(int nPoints,
10607  int nSpace,
10608  double sigma_k,
10609  double c_mu,
10610  double nu,
10611  double *velocity,
10612  double *gradu,
10613  double *gradv,
10614  double *gradw,
10615  double *k,
10616  double *epsilon,
10617  double *m_k,
10618  double *dm_k,
10619  double *phi_k,
10620  double *dphi_k,
10621  double *f_k,
10622  double *df_k,
10623  double *a_k,
10624  double *da_k_dk,
10625  double *r_k,
10626  double *dr_k_dk)
10627 {
10628  int i,I;
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++)
10632  {
10633  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10634  kval = k[i] >= 0.0 ? k[i] : 0.0;
10635  /*eddy viscosity*/
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);
10638  if (nu_t < 0.0)
10639  {
10640  nu_t = 0.0; dnu_t_dk = 0.0;
10641  }
10642  /*mwf debug
10643  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_dk=%g \n",i,k[i],i,epsilon[i],
10644  nu_t,dnu_t_dk);
10645  */
10646  /*linear mass terms for k-e*/
10647  m_k[i] = k[i];
10648  dm_k[i]= 1.0;
10649 
10650  /*linear advection*/
10651  for (I=0; I < nSpace; I++)
10652  {
10653  f_k[i*nSpace+I] = k[i]*velocity[i*nSpace+I];
10654  df_k[i*nSpace+I]= velocity[i*nSpace+I];
10655 
10656  }
10657  /*linear potentials*/
10658  phi_k[i] = k[i];
10659  dphi_k[i]= 1.0;
10660 
10661  /*nonlinear diffusion*/
10662  for (I=0; I < nSpace; I++)
10663  {
10664  a_k[i*nSpace+I] = nu_t/sigma_k + nu;
10665  da_k_dk[i*nSpace + I] = dnu_t_dk/sigma_k;
10666  }
10667 
10668  /*production term*/
10669  /*4*Pi_D*/
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])
10673  +
10674  (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10675  +
10676  (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10677  +
10678  (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10679 
10680 
10681  r_k[i] = -nu_t*PiD4 + epsilon[i];
10682  dr_k_dk[i] = -dnu_t_dk*PiD4;
10683 
10684  }
10685 }
10687  int nSpace,
10688  double sigma_e,
10689  double c_1,
10690  double c_2,
10691  double c_mu,
10692  double c_e,
10693  double nu,
10694  double *velocity,
10695  double *gradu,
10696  double *gradv,
10697  double *gradw,
10698  double *k,
10699  double *epsilon,
10700  double *m_e,
10701  double *dm_e,
10702  double *phi_e,
10703  double *dphi_e,
10704  double *f_e,
10705  double *df_e,
10706  double *a_e,
10707  double *da_e_de,
10708  double *r_e,
10709  double *dr_e_de)
10710 
10711 {
10712  int i,I;
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++)
10716  {
10717  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10718  kval = k[i] >= 0.0 ? k[i] : 0.0;
10719  /*eddy viscosity*/
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);
10722  if (nu_t < 0.0)
10723  {
10724  nu_t = 0.0; dnu_t_de = 0.0;
10725  }
10726  /*mwf debug
10727  printf("keps eval k[%d]=%g e[%d]=%g nu_t=%g dnu_t_de=%g\n",i,k[i],i,epsilon[i],
10728  nu_t,dnu_t_de);
10729  */
10730  /*linear mass terms for e*/
10731  m_e[i] = epsilon[i];
10732  dm_e[i]= 1.0;
10733 
10734  /*linear advection*/
10735  for (I=0; I < nSpace; I++)
10736  {
10737  f_e[i*nSpace+I] = epsilon[i]*velocity[i*nSpace+I];
10738  df_e[i*nSpace+I]= velocity[i*nSpace+I];
10739  }
10740  /*linear potentials*/
10741  phi_e[i] = epsilon[i];
10742  dphi_e[i]= 1.0;
10743 
10744  /*nonlinear diffusion*/
10745  for (I=0; I < nSpace; I++)
10746  {
10747  a_e[i*nSpace + I] = nu_t/sigma_e + nu;
10748  da_e_de[i*nSpace + I] = dnu_t_de/sigma_e;
10749  }
10750 
10751  /*production term*/
10752  /*4*Pi_D*/
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])
10756  +
10757  (gradu[i*nSpace+1] + gradv[i*nSpace+0])*(gradu[i*nSpace+1] + gradv[i*nSpace+0])
10758  +
10759  (gradu[i*nSpace+2] + gradw[i*nSpace+0])*(gradu[i*nSpace+2] + gradw[i*nSpace+0])
10760  +
10761  (gradv[i*nSpace+2] + gradw[i*nSpace+1])*(gradv[i*nSpace+2] + gradw[i*nSpace+1]);
10762 
10763 
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);
10766  if (disp < 0.0)
10767  {
10768  disp = 0.0; ddisp_de = 0.0;
10769  }
10770  r_e[i] = -c_1*k[i]*PiD4 + disp;/*c_2*epsilon[i]*epsilon[i]/(k[i]+div_eps);*/
10771  dr_e_de[i] = ddisp_de; /*2.0*c_2*epsilon[i]/(k[i]+div_eps); */
10772 
10773  }
10774 }
10775 
10776 /***********************************************************************
10777  Evolution equations (mass and momentum conservation)
10778  for Reynolds Averaged Navier Stokes formulation with k-epsilon turbulence
10779  model
10780 
10781 
10782 Reynolds averaged NS equations
10783 
10784 \deld \bar{\vec v} = 0
10785 
10786 \pd{\bar{\vec v}}{t} + \deld \left(\bar{\vec v} \outer \bar{\vec v}\right)
10787  -\nu \deld \ten \bar{D} + \frac{1}{\rho}\grad \bar p
10788  - \frac{1}{rho}\deld \ten{R} = 0
10789 
10790 Reynolds stress term
10791 
10792 \ten R = -\rho <\vec v^{'}\outer \vec v^{'}>
10793 \frac{1}{\rho}\ten{R} = 2 \nu_t \bar{D} - \frac{2}{3}k\ten{I}
10794 
10795 D_{ij}(\vec v) = \frac{1}{2} \left( \pd{v_i}{x_j} + \pd{v_j}{x_i})
10796 \ten D \bar{\ten D} = D(<\vec v>), \ten D^{'} = \ten D(\vec v^{'})
10797 
10798 
10799 For simplicity, the 2/3 k\ten{I} part of the Reynolds stress will be incorporated into
10800  the momentum source term
10801 
10802 The eddy viscosity will simply appear as an additional, spatially varying
10803  term in the momentum diffusion tensor
10804 
10805 This version assumes standard NS terms have been evaluated and only
10806  updates diffusion tensor and source term
10807  ***********************************************************************/
10809  const double nu,
10810  const double c_mu,
10811  const double* k,
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)
10820 {
10821  int i;
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++)
10826  {
10827  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10828  kval = k[i] >= 0.0 ? k[i] : 0.0;
10829 
10830  nu_t= c_mu*kval*kval/(eval+div_zero);
10831 #ifdef SCALAR_DIFFUSION
10832  //u momentum diffusion tensor
10833  mom_u_diff_ten[i*4+0] += nu_t;
10834  mom_u_diff_ten[i*4+3] += nu_t;
10835 
10836  //v momentum diffusion tensor
10837  mom_v_diff_ten[i*4+0] += nu_t;
10838  mom_v_diff_ten[i*4+3] += nu_t;
10839 #else
10840  //u momentum diffusion tensor
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;
10844 
10845  //v momentum diffusion tensor
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;
10849 #endif
10850 
10851 
10852  //momentum sources
10853  mom_u_source[i] += twoThirds*grad_k[i*2+0];
10854  mom_v_source[i] += twoThirds*grad_k[i*2+1];
10855 
10856  }
10857 }
10858 /***********************************************************************
10859  Evolution equations (mass and momentum conservation)
10860  for Reynolds Averaged Navier Stokes formulation with k-epsilon turbulence
10861  model
10862 
10863 
10864 Reynolds averaged NS equations
10865 
10866 \deld \bar{\vec v} = 0
10867 
10868 \pd{\bar{\vec v}}{t} + \deld \left(\bar{\vec v} \outer \bar{\vec v}\right)
10869  -\nu \deld \ten \bar{D} + \frac{1}{\rho}\grad \bar p
10870  - \frac{1}{rho}\deld \ten{R} = 0
10871 
10872 Reynolds stress term
10873 
10874 \ten R = -\rho <\vec v^{'}\outer \vec v^{'}>
10875 \frac{1}{\rho}\ten{R} = 2 \nu_t \bar{D} - \frac{2}{3}k\ten{I}
10876 
10877 D_{ij}(\vec v) = \frac{1}{2} \left( \pd{v_i}{x_j} + \pd{v_j}{x_i})
10878 \ten D \bar{\ten D} = D(<\vec v>), \ten D^{'} = \ten D(\vec v^{'})
10879 
10880 
10881 For simplicity, the 2/3 k\ten{I} part of the Reynolds stress will be incorporated into
10882  the momentum source term
10883 
10884 The eddy viscosity will simply appear as an additional, spatially varying
10885  term in the momentum diffusion tensor
10886 
10887 This version assumes standard NS terms have been evaluated and only
10888  updates diffusion tensor and source term
10889  ***********************************************************************/
10891  const double rho,
10892  const double nu,
10893  const double c_mu,
10894  const double* k,
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)
10903 {
10904  int i;
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++)
10909  {
10910  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10911  kval = k[i] >= 0.0 ? k[i] : 0.0;
10912 
10913  nu_t= c_mu*kval*kval/(eval+div_zero);
10914 
10915  //u momentum diffusion tensor
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;
10919 
10920  //v momentum diffusion tensor
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;
10924 
10925 
10926  //momentum sources
10927  mom_u_source[i] += twoThirds*grad_k[i*2+0];
10928  mom_v_source[i] += twoThirds*grad_k[i*2+1];
10929 
10930  }
10931 }
10933  const double nu,
10934  const double c_mu,
10935  const double* k,
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)
10950 {
10951  int i;
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++)
10956  {
10957  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
10958  kval = k[i] >= 0.0 ? k[i] : 0.0;
10959 
10960  nu_t= c_mu*kval*kval/(eval+div_zero);
10961  //u momentum diffusion tensor
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;
10965 
10966  mom_uv_diff_ten[i*9+3]+=nu_t;
10967 
10968  mom_uw_diff_ten[i*9+6]+=nu_t;
10969 
10970  //v momentum diffusion tensor
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;
10974 
10975  mom_vu_diff_ten[i*9+1]+=nu_t;
10976 
10977  mom_vw_diff_ten[i*9+7]+=nu_t;
10978 
10979  //w momentum diffusion tensor
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;
10983 
10984  mom_wu_diff_ten[i*9+2]+=nu_t;
10985 
10986  mom_wv_diff_ten[i*9+5]+=nu_t;
10987 
10988 
10989  //momentum sources
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];
10993 
10994  }
10995 }
10997  const double nu,
10998  const double c_mu,
10999  const double* k,
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)
11014 {
11015  int i;
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++)
11020  {
11021  eval = epsilon[i] >= 0.0 ? epsilon[i] : 0.0;
11022  kval = k[i] >= 0.0 ? k[i] : 0.0;
11023 
11024  nu_t= c_mu*kval*kval/(eval+div_zero);
11025  //u momentum diffusion tensor
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;
11029 
11030  mom_uv_diff_ten[i]+=nu_t;
11031 
11032  mom_uw_diff_ten[i]+=nu_t;
11033 
11034  //v momentum diffusion tensor
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;
11038 
11039  mom_vu_diff_ten[i]+=nu_t;
11040 
11041  mom_vw_diff_ten[i]+=nu_t;
11042 
11043  //w momentum diffusion tensor
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;
11047 
11048  mom_wu_diff_ten[i]+=nu_t;
11049 
11050  mom_wv_diff_ten[i]+=nu_t;
11051  //momentum sources
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];
11055 
11056  }
11057 }
11058 
11059 void scriptedSphereMotionSignedDistance(const int nPoints,
11060  const double t,
11061  const int nSpace,
11062  const int nSpheres,
11063  const double * radii,
11064  const double * centers,
11065  const double * x,
11066  double * phi,
11067  double * n)
11068 {
11069  /*brute force calculation of signed distance from nSphere moving spheres*/
11070  int i,j,k;
11071  double minDistance,distance,tmp;
11072 
11073  for (k=0; k < nPoints; k++)
11074  {
11075  for (j=0; j < nSpheres; j++)
11076  {
11077  tmp = 0.0;
11078  for (i=0; i < nSpace; i++)
11079  {
11080  tmp += (x[3*k+i]-centers[3*j+i])*(x[3*k+i]-centers[3*j+i]);
11081  }
11082  distance = sqrt(tmp) - radii[j];
11083  if (j == 0)
11084  {
11085  minDistance = distance;
11086  for (i=0; i < nSpace; i++)
11087  {
11088  n[k*nSpace + i]= (x[3*k+i]-centers[3*j+i])/(distance+1.0e-12);
11089  }
11090  }
11091  else if (fabs(distance) < fabs(minDistance))
11092  {
11093  minDistance=distance;
11094  for (i=0; i < nSpace; i++)
11095  {
11096  n[k*nSpace + i]= (x[3*k+i]-centers[3*j+i])/(distance+1.0e-12);
11097  }
11098  }
11099  }/*sphere loop*/
11100  phi[k] = minDistance;
11101 
11102  }/*point loop*/
11103 
11104 
11105 }
11106 
11107 void shallowWater_1D_Evaluate(const int nPoints,
11108  const double h_eps,
11109  const double g,
11110  const double bedFrictionCoefficient,
11111  const double bedFrictionPower,
11112  const double eddyViscosity,
11113  const double* x, /*bathymetry elevation in index 1 (y)*/
11114  const double* db_dx,/*db/dx (bed slope) */
11115  const double* h,
11116  const double* hu,
11117  double *H,
11118  double *mass_acc,
11119  double *dmass_acc_dh,
11120  double *mom_acc,
11121  double *dmom_acc_dhu,
11122  double *mass_adv,
11123  double *dmass_adv_dhu,
11124  double *mom_adv,
11125  double *dmom_adv_dh,
11126  double *dmom_adv_dhu,
11127  double *mom_source,
11128  double *dmom_source_dh,
11129  double *dmom_source_dhu,
11130  double *mom_diff)
11131 {
11132  int k;
11133  double u,du_dh,du_dhu,heval,hpow,hunorm;
11134  for (k=0;k<nPoints;k++)
11135  {
11136  if (h[k] < h_eps)
11137  {
11138  u = 0.0;
11139  du_dh = 0.0;
11140  du_dhu = 0.0;
11141  }
11142  else
11143  {
11144  u = hu[k]/h[k];
11145  du_dh = -hu[k]/(h[k]*h[k]);
11146  du_dhu = 1.0/h[k];
11147  }
11148  /*elevation above reference point*/
11149  H[k] = h[k] + x[k*3+1];
11150 
11151  mass_acc[k] = h[k];
11152  dmass_acc_dh[k] = 1.0;
11153 
11154  mom_acc[k] = hu[k];
11155  dmom_acc_dhu[k] = 1.0;
11156 
11157  mass_adv[k] = hu[k];
11158  dmass_adv_dhu[k] = 1.0;
11159 
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;
11163 
11164  /*constant eddy viscosity for now*/
11165  mom_diff[k] = eddyViscosity;
11166  /*bathymetry contributions, go on left hand side*/
11167  mom_source[k] = g*h[k]*db_dx[k];
11168  dmom_source_dh[k]= g*db_dx[k];
11169  /*bed Friction contributions, go on left hand side*/
11170  heval=fmax(1.0e-3,h[k]);
11171  hpow =pow(heval,-bedFrictionPower-2.0);/*have extra powers of h because formula numerator has hu*/
11172  hunorm = fabs(hu[k]);
11173  mom_source[k] += g*hu[k]*bedFrictionCoefficient*hunorm*hpow; /*recall g is magnitude of gravity here*/
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);
11177  }
11178 }
11179 
11180 void shallowWater_2D_Evaluate(const int nPoints,
11181  const double h_eps,
11182  const double g,
11183  const double bedFrictionCoefficient,
11184  const double bedFrictionPower,
11185  const double eddyViscosity,
11186  const double* x, /*bathymetry elevation in index 2 (z)*/
11187  const double* grad_b,/*\nabla b (bed slope) */
11188  const double* h,
11189  const double* hu,
11190  const double* hv,
11191  double *H,
11192  double *mass_acc,
11193  double *dmass_acc_dh,
11194  double *mom_u_acc,
11195  double *dmom_u_acc_dhu,
11196  double *mom_v_acc,
11197  double *dmom_v_acc_dhv,
11198  double *mass_adv,
11199  double *dmass_adv_dhu,
11200  double *dmass_adv_dhv,
11201  double *mom_u_adv,
11202  double *dmom_u_adv_dh,
11203  double *dmom_u_adv_dhu,
11204  double *dmom_u_adv_dhv,
11205  double *mom_v_adv,
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)
11219 {
11220  int k;
11221  double u,du_dh,du_dhu,v,dv_dh,dv_dhv,heval,unorm,hpow;
11222  for (k=0;k<nPoints;k++)
11223  {
11224  if (h[k] < h_eps)
11225  {
11226  u =0.0;
11227  du_dh = 0.0;
11228  du_dhu = 0.0;
11229 
11230  v =0.0;
11231  dv_dh = 0.0;
11232  dv_dhv = 0.0;
11233  }
11234  else
11235  {
11236  u = hu[k]/h[k];
11237  du_dh = -hu[k]/(h[k]*h[k]);
11238  du_dhu = 1.0/h[k];
11239 
11240  v = hv[k]/h[k];
11241  dv_dh = -hv[k]/(h[k]*h[k]);
11242  dv_dhv = 1.0/h[k];
11243  }
11244  //height above reference point
11245  H[k] = h[k] + x[k*3+2];
11246  //mass
11247  mass_acc[k] = h[k];
11248  dmass_acc_dh[k] = 1.0;
11249 
11250  mass_adv[2*k+0] = hu[k];
11251  dmass_adv_dhu[2*k+0] = 1.0;
11252 
11253  mass_adv[2*k+1] = hv[k];
11254  dmass_adv_dhv[2*k+1] = 1.0;
11255 
11256  //mom u
11257  mom_u_acc[k] = hu[k];
11258  dmom_u_acc_dhu[k] = 1.0;
11259 
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;
11263 
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;
11268 
11269  //constant eddy viscosity for now,
11270  //temporarily assume full tensor storage even though diagonal
11271  //mom_u_diff[4*k+0] = eddyViscosity;
11272  //mom_u_diff[4*k+3] = eddyViscosity;
11273  mom_u_diff[2*k+0] = eddyViscosity;
11274  mom_u_diff[2*k+1] = eddyViscosity;
11275 
11276  //mom v
11277  mom_v_acc[k] = hv[k];
11278  dmom_v_acc_dhv[k] = 1.0;
11279 
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;
11284 
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;
11288 
11289  //constant eddy viscosity for now,
11290  //temporarily assume full tensor storage even though diagonal
11291  //mom_v_diff[4*k+0] = eddyViscosity;
11292  //mom_v_diff[4*k+3] = eddyViscosity;
11293  mom_v_diff[2*k+0] = eddyViscosity;
11294  mom_v_diff[2*k+1] = eddyViscosity;
11295  /*bathymetry contributions, goes on left hand side*/
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];
11298 
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];
11301  /*bed Friction contributions, go on left hand side*/
11302  heval=fmax(1.0e-3,h[k]);
11303  hpow =pow(heval,-bedFrictionPower-2.0);/*have extra powers of h because formula numerator has hu*/
11304  unorm = sqrt(hu[k]*hu[k] + hv[k]*hv[k]);
11305 
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);
11312 
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);
11319 
11320  }
11321 }
11322 
11324  const int computeAverages,
11325  const int nSimplex,
11326  const int nPointsPerSimplex,
11327  const int nSpace,
11328  const int nQuadraturePoints_elementBoundary,
11329  const int* elementBoundaryElementsArray,
11330  const int* quadraturePointToElementBoundary,
11331  const int* materialTypes,
11332  const double rho,
11333  const double beta,
11334  const double* gravity,
11335  const double* alpha,
11336  const double* n_vg,
11337  const double* thetaR,
11338  const double* thetaSR,
11339  const double* KWs,
11340  const double *u,
11341  const double *gradu,
11342  const double *n_global,
11343  const double *dV,
11344  double *mass,
11345  double *dmass,
11346  double *f_avg,
11347  double *df_avg,
11348  double *a_avg,
11349  double *da_avg,
11350  double *f,
11351  double *df,
11352  double *a,
11353  double *da)
11354 {
11355  int i,j,k,I,matID;
11356  const int nSpace2=nSpace*nSpace;
11357  register double psiC,
11358  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
11359  onePlus_pcBar_n,
11360  sBar,sqrt_sBar,DsBar_DpsiC,
11361  thetaW,DthetaW_DpsiC,
11362  vBar,vBar2,DvBar_DpsiC,
11363  KW,DKW_DpsiC,
11364  rho2=rho*rho,
11365  thetaS,
11366  rhom,drhom,m;
11367  int eN_upwind,ebN_global;
11368  register double drive,avgfI,avgdfI,avgaII,avgdaII,vol;
11369  /*
11370  loop through and compute point values as normal
11371  could add harmonic average for point values at faces here
11372 
11373  if upwinding,
11374  loop through and compute average for each simplex
11375  loop through each point,
11376  find face for that point
11377  find upwind direction for that face
11378  set point value and derivative to average from upwind neighbor
11379 
11380  */
11381  for (i=0; i < nSimplex; i++)
11382  {
11383  matID= materialTypes[i];
11384  for (j=0;j<nPointsPerSimplex;j++)
11385  {
11386  k = i*nPointsPerSimplex + j;
11387  psiC = -u[k];
11388  m = 1.0 - 1.0/n_vg[matID];
11389  thetaS = thetaR[matID] + thetaSR[matID];
11390  if (psiC > 0.0)
11391  {
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;
11397 
11398  sBar = pow(onePlus_pcBar_n,-m);
11399  /* using -mn = 1-n */
11400  DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11401 
11402  vBar = 1.0-pcBar_nM1*sBar;
11403  vBar2 = vBar*vBar;
11404  DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11405 
11406  thetaW = thetaSR[matID]*sBar + thetaR[matID];
11407  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11408 
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
11413  +
11414  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11415  }
11416  else
11417  {
11418  thetaW = thetaS;
11419  DthetaW_DpsiC = 0.0;
11420  KW = KWs[matID];
11421  DKW_DpsiC = 0.0;
11422  }
11423  //slight compressibility
11424  rhom = rho*exp(beta*u[k]);
11425  drhom = beta*rhom;
11426 
11427  mass[k] = rhom*thetaW;
11428  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11429  //mass[k] = rho*thetaW;
11430  //dmass[k] = -rho*DthetaW_DpsiC;
11431  for (I=0;I<nSpace;I++)
11432  {
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;
11437  }/*I*/
11438  }/*k*/
11439  }/*j*/
11440  if (upwindFlag == 1 || upwindFlag == 2)
11441  {
11442  if (computeAverages == 1) /*compute averages for element quadrature call only*/
11443  {
11444  for (i=0; i < nSimplex; i++)
11445  {
11446  matID= materialTypes[i];
11447  vol = 0.0;
11448  for (j=0; j < nPointsPerSimplex; j++)
11449  vol += dV[i*nPointsPerSimplex + j];
11450  /*put dimensions on outside of loop to make averaging accumulation easier*/
11451  for (I=0; I < nSpace; I++)
11452  {
11453  avgaII = 0.0; avgfI = 0.0;
11454  avgdaII= 0.0; avgdfI= 0.0;
11455  for (j=0;j<nPointsPerSimplex;j++)
11456  {
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];
11462  }
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;
11468  /*mwf debug
11469  printf("RE V2 upwind nSimplex= %d nPerSimplex= %d i=%d j=%d I=%d k=%d \n",nSimplex,nPointsPerSimplex,i,j,I,k);
11470  */
11471  }/*space dim loop*/
11472  }/*simplex loop for averages*/
11473  }
11474  for (i=0; i < nSimplex; i++)
11475  {
11476  matID= materialTypes[i];
11477  for (j=0;j<nPointsPerSimplex;j++)
11478  {
11479  k = i*nPointsPerSimplex + j;
11480  ebN_global = quadraturePointToElementBoundary[k];
11481  drive = 0.0;
11482  for (I=0; I < nSpace; I++)
11483  {
11484  drive += (rho2*KWs[matID]*gravity[I]-rho*KWs[matID]*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11485  0*nSpace + I];
11486  }
11487  if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11488  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11489  else
11490  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11491  /*mwf debug
11492  printf("RE V2 upwind nSimplex= %d nPerSimplex= %d i=%d j=%d k=%d ebN_global= %d eN_upwind= %d\n",nSimplex,nPointsPerSimplex,i,j,k,ebN_global,
11493  eN_upwind);
11494  */
11495  for (I = 0; I < nSpace; I++)
11496  {
11497  f[k*nSpace + I] = f_avg[eN_upwind*nSpace+I];
11498  /*mwf don't update derivative?*/
11499  /*df[k*nSpace+ I] = df_avg[eN_upwind*nSpace+I];*/
11500  a[i*nPointsPerSimplex*nSpace2 + j*nSpace2+ I*nSpace+I] = a_avg[eN_upwind*nSpace2+I*nSpace+I];
11501  /*da[k*nSpace2+ I*nSpace+I] = da_avg[eN_upwind*nSpace2+I*nSpace+I];*/
11502  }
11503  if (upwindFlag == 2)
11504  {
11505  for (I = 0; I < nSpace; I++)
11506  {
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];
11509  }
11510  }
11511  }/*point loop for simplex*/
11512  }/*simplex loop for upwinding*/
11513  }/*if upwind*/
11514 }
11516  const int computeAverages,
11517  const int nSimplex,
11518  const int nPointsPerSimplex,
11519  const int nSpace,
11520  const int nQuadraturePoints_elementBoundary,
11521  const int* elementBoundaryElementsArray,
11522  const int* quadraturePointToElementBoundary,
11523  const int* materialTypes,
11524  const double rho,
11525  const double beta,
11526  const double* gravity,
11527  const double* alpha,
11528  const double* n_vg,
11529  const double* thetaR,
11530  const double* thetaSR,
11531  const double* KWs,
11532  const double *u,
11533  const double *gradu,
11534  const double *n_global,
11535  const double *dV,
11536  double *mass,
11537  double *dmass,
11538  double *f_avg,
11539  double *df_avg,
11540  double *a_avg,
11541  double *da_avg,
11542  double *f,
11543  double *df,
11544  double *a,
11545  double *da)
11546 {
11547  int i,j,k,I,matID;
11548  const int nSpace2=nSpace*nSpace;
11549  register double psiC,
11550  pcBar,pcBar_n,pcBar_nM1,pcBar_nM2,
11551  onePlus_pcBar_n,
11552  sBar,sqrt_sBar,DsBar_DpsiC,
11553  thetaW,DthetaW_DpsiC,
11554  vBar,vBar2,DvBar_DpsiC,
11555  KWr,DKWr_DpsiC,
11556  rho2=rho*rho,
11557  thetaS,
11558  rhom,drhom,m;
11559  int eN_upwind,ebN_global;
11560  register double drive,KWs_harm,KWs_left,KWs_right,krw_val,dkrw_val,vol;
11561  /*
11562  loop through and compute point values for m as usual
11563  store point values for kr, dkr and
11564  calculate average value for kr, dkr
11565 
11566  loop again through each point
11567  find face for that point
11568  compute harmonic average of (rho*Ks)
11569 
11570  if upwinding,
11571  find upwind direction for that face
11572  set point value to
11573  a_{ij,f} = (rho*Ks)_{ij,h,f}k_r^{up}
11574  f_{i} = (rho*rho*Ks)_{h,f}k_r^{up}\vec g
11575  else
11576  set point value to
11577  a_{ij,f} = (rho*Ks)_{ij,h,f}k_r(\psi_f)
11578  f_{i} = (rho*rho*Ks)_{h,f}k_r(\psi_f)\vec g
11579 
11580  */
11581 
11582  if (upwindFlag > 0)
11583  assert(computeAverages);
11584  for (i=0; i < nSimplex; i++)
11585  {
11586  matID= materialTypes[i];
11587  /*for computing averages*/
11588  vol = 0.0;
11589  for (j=0; j < nPointsPerSimplex; j++)
11590  vol += dV[i*nPointsPerSimplex + j];
11591  /*store average information with a_avg first entry for now*/
11592  if (computeAverages)
11593  {
11594  a_avg[i*nSpace2+0*nSpace+0] = 0.0;
11595  da_avg[i*nSpace2+0*nSpace+0] = 0.0;
11596  }
11597  for (j=0;j<nPointsPerSimplex;j++)
11598  {
11599  k = i*nPointsPerSimplex + j;
11600  psiC = -u[k];
11601  m = 1.0 - 1.0/n_vg[matID];
11602  thetaS = thetaR[matID] + thetaSR[matID];
11603  if (psiC > 0.0)
11604  {
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;
11610 
11611  sBar = pow(onePlus_pcBar_n,-m);
11612  /* using -mn = 1-n */
11613  DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11614 
11615  vBar = 1.0-pcBar_nM1*sBar;
11616  vBar2 = vBar*vBar;
11617  DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11618 
11619  thetaW = thetaSR[matID]*sBar + thetaR[matID];
11620  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11621 
11622  sqrt_sBar = sqrt(sBar);
11623  KWr= sqrt_sBar*vBar2;
11624  DKWr_DpsiC=
11625  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
11626  +
11627  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11628  }
11629  else
11630  {
11631  thetaW = thetaS;
11632  DthetaW_DpsiC = 0.0;
11633  KWr = 1.0;
11634  DKWr_DpsiC = 0.0;
11635  }
11636  /*slight compressibility*/
11637  rhom = rho*exp(beta*u[k]);
11638  drhom = beta*rhom;
11639 
11640  mass[k] = rhom*thetaW;
11641  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11642  /*store point values of kr in a and da*/
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)/*accumulate averages*/
11646  {
11647  a_avg[i*nSpace2 + 0*nSpace + 0] += KWr*dV[k];
11648  da_avg[i*nSpace2+ 0*nSpace + 0] += -DKWr_DpsiC*dV[k];
11649  }
11650  }/*j*/
11651  /*finish average calculations*/
11652  if (computeAverages)/*accumulate averages*/
11653  {
11654  a_avg[i*nSpace2 + 0*nSpace + 0] /= vol;
11655  da_avg[i*nSpace2 + 0*nSpace + 0] /= vol;
11656  }
11657  }/*i*/
11658 
11659 
11660  for (i=0; i < nSimplex; i++)
11661  {
11662  matID= materialTypes[i];
11663  for (j=0;j<nPointsPerSimplex;j++)
11664  {
11665  k = i*nPointsPerSimplex + j;
11666  ebN_global = quadraturePointToElementBoundary[k];
11667  /*first grab harmonic average for conductivity*/
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);
11672 
11673  drive = 0.0;
11674  for (I=0; I < nSpace; I++)
11675  {
11676  drive += (rho2*KWs_harm*gravity[I]-rho*KWs_harm*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11677  0*nSpace + I];
11678  }
11679  if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11680  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11681  else
11682  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11683  /*mwf debug
11684  printf("RE V2 upwind nSimplex= %d nPerSimplex= %d i=%d j=%d k=%d ebN_global= %d eN_upwind= %d\n",nSimplex,nPointsPerSimplex,i,j,k,ebN_global,
11685  eN_upwind);
11686  */
11687  /*start with point val for kr*/
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) /*don't have a choice for point upwinding*/
11691  {
11692  krw_val = a_avg[eN_upwind*nSpace2 + 0*nSpace + 0];
11693  /*use point value in jacobian regardless*/
11694  }
11695 
11696 
11697  for (I = 0; I < nSpace; I++)
11698  {
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;
11703  }
11704 
11705  }/*point loop for simplex*/
11706  }/*simplex loop for upwinding*/
11707 
11708 }
11709 
11711  const int computeAverages,
11712  const int nSimplex,
11713  const int nPointsPerSimplex,
11714  const int nSpace,
11715  const int nQuadraturePoints_elementBoundary,
11716  const int *rowptr,
11717  const int *colind,
11718  const int* elementBoundaryElementsArray,
11719  const int* quadraturePointToElementBoundary,
11720  const int* materialTypes,
11721  const double rho,
11722  const double beta,
11723  const double* gravity,
11724  const double* alpha,
11725  const double* n_vg,
11726  const double* thetaR,
11727  const double* thetaSR,
11728  const double* KWs,
11729  const double *u,
11730  const double *gradu,
11731  const double *n_global,
11732  const double *dV,
11733  double *mass,
11734  double *dmass,
11735  double *f_avg,
11736  double *df_avg,
11737  double *a_avg,
11738  double *da_avg,
11739  double *f,
11740  double *df,
11741  double *a,
11742  double *da)
11743 {
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,
11748  onePlus_pcBar_n,
11749  sBar,sqrt_sBar,DsBar_DpsiC,
11750  thetaW,DthetaW_DpsiC,
11751  vBar,vBar2,DvBar_DpsiC,
11752  KWr,DKWr_DpsiC,
11753  rho2=rho*rho,
11754  thetaS,
11755  rhom,drhom,m;
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]; /*sparse mat rep for diffusion*/
11759  /*
11760  loop through and compute point values for m as usual
11761  store point values for kr, dkr and
11762  calculate average value for kr, dkr
11763 
11764  loop again through each point
11765  find face for that point
11766  compute harmonic average of (rho*Ks)
11767 
11768  if upwinding,
11769  find upwind direction for that face
11770  set point value to
11771  a_{ij,f} = (rho*Ks)_{ij,h,f}k_r^{up}
11772  f_{i} = (rho*rho*Ks)_{h,f}k_r^{up}\vec g
11773  else
11774  set point value to
11775  a_{ij,f} = (rho*Ks)_{ij,h,f}k_r(\psi_f)
11776  f_{i} = (rho*rho*Ks)_{h,f}k_r(\psi_f)\vec g
11777 
11778  */
11779 
11780  if (upwindFlag > 0)
11781  assert(computeAverages);
11782  for (i=0; i < nSimplex; i++)
11783  {
11784  matID= materialTypes[i];
11785  /*for computing averages*/
11786  vol = 0.0;
11787  for (j=0; j < nPointsPerSimplex; j++)
11788  vol += dV[i*nPointsPerSimplex + j];
11789  /*store average information with a_avg first entry for now*/
11790  if (computeAverages)
11791  {
11792  a_avg[i*nSpace2+0*nSpace+0] = 0.0;
11793  da_avg[i*nSpace2+0*nSpace+0] = 0.0;
11794  }
11795  for (j=0;j<nPointsPerSimplex;j++)
11796  {
11797  k = i*nPointsPerSimplex + j;
11798  psiC = -u[k];
11799  m = 1.0 - 1.0/n_vg[matID];
11800  thetaS = thetaR[matID] + thetaSR[matID];
11801  if (psiC > 0.0)
11802  {
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;
11808 
11809  sBar = pow(onePlus_pcBar_n,-m);
11810  /* using -mn = 1-n */
11811  DsBar_DpsiC = alpha[matID]*(1.0-n_vg[matID])*(sBar/onePlus_pcBar_n)*pcBar_nM1;
11812 
11813  vBar = 1.0-pcBar_nM1*sBar;
11814  vBar2 = vBar*vBar;
11815  DvBar_DpsiC = -alpha[matID]*(n_vg[matID]-1.0)*pcBar_nM2*sBar - pcBar_nM1*DsBar_DpsiC;
11816 
11817  thetaW = thetaSR[matID]*sBar + thetaR[matID];
11818  DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
11819 
11820  sqrt_sBar = sqrt(sBar);
11821  KWr= sqrt_sBar*vBar2;
11822  DKWr_DpsiC=
11823  ((0.5/sqrt_sBar)*DsBar_DpsiC*vBar2
11824  +
11825  2.0*sqrt_sBar*vBar*DvBar_DpsiC);
11826  }
11827  else
11828  {
11829  thetaW = thetaS;
11830  DthetaW_DpsiC = 0.0;
11831  KWr = 1.0;
11832  DKWr_DpsiC = 0.0;
11833  }
11834  /*slight compressibility*/
11835  rhom = rho*exp(beta*u[k]);
11836  drhom = beta*rhom;
11837 
11838  mass[k] = rhom*thetaW;
11839  dmass[k] = -rhom*DthetaW_DpsiC+drhom*thetaW;
11840  /*store point values of kr in a and da using first entry*/
11841  J = rowptr[0];
11842  a[i*nPointsPerSimplex*nnz + j*nnz + J] = KWr;
11843  da[i*nPointsPerSimplex*nnz + j*nnz + J]= -DKWr_DpsiC;
11844  if (computeAverages)/*accumulate averages*/
11845  {
11846  a_avg[i*nnz + J] += KWr*dV[k];
11847  da_avg[i*nnz+ J] += -DKWr_DpsiC*dV[k];
11848  }
11849  }/*j*/
11850  /*finish average calculations*/
11851  if (computeAverages)/*accumulate averages*/
11852  {
11853  a_avg[i*nnz + J] /= vol;
11854  da_avg[i*nnz + J] /= vol;
11855  }
11856  }/*i*/
11857 
11858 
11859  for (i=0; i < nSimplex; i++)
11860  {
11861  matID= materialTypes[i];
11862  for (j=0;j<nPointsPerSimplex;j++)
11863  {
11864  k = i*nPointsPerSimplex + j;
11865  ebN_global = quadraturePointToElementBoundary[k];
11866  /*first grab harmonic average for conductivity*/
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);
11871 
11872  drive = 0.0;
11873  for (I=0; I < nSpace; I++)
11874  {
11875  drive += (rho2*KWs_harm*gravity[I]-rho*KWs_harm*gradu[k*nSpace+I])*n_global[ebN_global*nQuadraturePoints_elementBoundary*nSpace +
11876  0*nSpace + I];
11877  }
11878  if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global*2 + 1] < 0)
11879  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 0];
11880  else
11881  eN_upwind = elementBoundaryElementsArray[ebN_global*2 + 1];
11882  /*mwf debug
11883  printf("RE V2 upwind nSimplex= %d nPerSimplex= %d i=%d j=%d k=%d ebN_global= %d eN_upwind= %d\n",nSimplex,nPointsPerSimplex,i,j,k,ebN_global,
11884  eN_upwind);
11885  */
11886  /*start with point val for kr*/
11887  J = rowptr[0]; /*just grab first entry because assuming diagonal for now*/
11888  krw_val = a[i*nPointsPerSimplex*nnz + j*nnz + J];
11889  dkrw_val= da[i*nPointsPerSimplex*nnz + j*nnz + J];
11890  if (upwindFlag > 0) /*don't have a choice for point upwinding*/
11891  {
11892  krw_val = a_avg[eN_upwind*nnz + J];
11893 /* if (i != eN_upwind) */
11894 /* dkrw_val = 0.0; */
11895 /* else */
11896 /* dkrw_val = da_avg[eN_upwind*nnz + J]; */
11897  }
11898 
11899 
11900  for (I = 0; I < nSpace; I++)
11901  {
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++)
11905  {
11906  if (colind[J] == I)
11907  {
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;
11910  }
11911  else
11912  {
11913  a[i*nPointsPerSimplex*nnz + j*nnz + J] = 0.0;
11914  da[i*nPointsPerSimplex*nnz + j*nnz + J]= 0.0;
11915  }
11916  }
11917  }
11918 
11919  }/*point loop for simplex*/
11920  }/*simplex loop for upwinding*/
11921 
11922 }
11923 
11924 void applyContactLineSlip(int nExteriorElementBoundaries_global,
11925  int nQuadraturePoints_elementBoundary,
11926  double eps,
11927  int* isDOFBoundary,
11928  double* phi,
11929  double* advectiveFlux,
11930  double* diffusiveFlux)
11931 {
11932  int ebNE,k;
11933  double weight;
11934  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
11935  {
11936  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
11937  {
11938  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11939  {
11940  weight = (smoothedDirac(eps,0) - smoothedDirac(eps,phi[ebNE*nQuadraturePoints_elementBoundary+k]))/smoothedDirac(eps,0);
11941  advectiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] *= weight;
11942  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] *= weight;
11943  }
11944  }
11945  }
11946 }
11947 
11948 void applyContactLineSlipJacobian(int nExteriorElementBoundaries_global,
11949  int nQuadraturePoints_elementBoundary,
11950  int nDOF_trial_element,
11951  double eps,
11952  int* isDOFBoundary,
11953  double* phi,
11954  double* fluxJacobian)
11955 {
11956  int ebNE,k,j;
11957  double weight;
11958  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
11959  {
11960  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
11961  {
11962  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11963  {
11964  weight = (smoothedDirac(eps,0) - smoothedDirac(eps,phi[ebNE*nQuadraturePoints_elementBoundary+k]))/smoothedDirac(eps,0);
11965  for(j=0;j<nDOF_trial_element;j++)
11966  {
11967  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11968  k*nDOF_trial_element+
11969  j] *= weight;
11970  }
11971  }
11972  }
11973  }
11974 }
11978 void diffusiveWave1DEvaluate(const int nPoints,
11979  const double alpha,
11980  const double gamma,
11981  const double epsilon,
11982  const double* x,
11983  const double* u,
11984  const double* grad_u,
11985  double* m,
11986  double* dm,
11987  double* a,
11988  double* da)
11989 {
11990  int i;
11991  double depth=0.0;
11992  double hold=0.0;
11993 
11994  for (i=0; i<nPoints; i++)
11995  {
11996  m[i]=u[i];
11997  dm[i]=1.0;
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);
12003 
12004  }
12005 }
12006 
12007 void diffusiveWave2DEvaluate(const int nd,
12008  const int nPoints,
12009  const double alpha,
12010  const double gamma,
12011  const double epsilon,
12012  const double* x,
12013  const double* u,
12014  const double* grad_u,
12015  double* m,
12016  double* dm,
12017  double* a,
12018  double* da)
12019 {
12020  int i;
12021  double depth=0.0;
12022  double hold=0.0;
12023 
12024  for (i=0; i<nPoints; i++)
12025  {
12026  m[i]=u[i];
12027  dm[i]=1.0;
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);
12032 
12033  }
12034 }
12035 
12036 void calculateEddyViscosity_Smagorinsky_2D(const int nElements_global,
12037  const int nQuadraturePoints_element,
12038  const double smagorinskyConstant,
12039  const double * h_e,
12040  const double * grad_u,
12041  const double * grad_v,
12042  double * nu_t)
12043 {
12044  int eN,k;
12045  const int nSpace = 2;
12046  double norm_S2,norm_S;
12047  for (eN = 0; eN < nElements_global; eN++)
12048  {
12049  for (k = 0; k < nQuadraturePoints_element; k++)
12050  {
12051  norm_S2 =
12052  grad_u[eN*nQuadraturePoints_element*nSpace +
12053  k*nSpace + 0]
12054  *
12055  grad_u[eN*nQuadraturePoints_element*nSpace +
12056  k*nSpace + 0]
12057  +
12058  grad_v[eN*nQuadraturePoints_element*nSpace +
12059  k*nSpace + 1]
12060  *
12061  grad_v[eN*nQuadraturePoints_element*nSpace +
12062  k*nSpace + 1]
12063  +
12064  0.5*
12065  (grad_u[eN*nQuadraturePoints_element*nSpace +
12066  k*nSpace + 1]
12067  +
12068  grad_v[eN*nQuadraturePoints_element*nSpace +
12069  k*nSpace + 0])
12070  *
12071  (grad_u[eN*nQuadraturePoints_element*nSpace +
12072  k*nSpace + 1]
12073  +
12074  grad_v[eN*nQuadraturePoints_element*nSpace +
12075  k*nSpace + 0]);
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;
12079 
12080  }
12081  }
12082 
12083 }
12084 void calculateEddyViscosity_Smagorinsky_3D(const int nElements_global,
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,
12091  double * nu_t)
12092 {
12093  int eN,k;
12094  const int nSpace = 3;
12095  double norm_S2,norm_S;
12096  for (eN = 0; eN < nElements_global; eN++)
12097  {
12098  for (k = 0; k < nQuadraturePoints_element; k++)
12099  {
12100  norm_S2 =
12101  grad_u[eN*nQuadraturePoints_element*nSpace +
12102  k*nSpace + 0]
12103  *
12104  grad_u[eN*nQuadraturePoints_element*nSpace +
12105  k*nSpace + 0]
12106  +
12107  grad_v[eN*nQuadraturePoints_element*nSpace +
12108  k*nSpace + 1]
12109  *
12110  grad_v[eN*nQuadraturePoints_element*nSpace +
12111  k*nSpace + 1]
12112  +
12113  grad_w[eN*nQuadraturePoints_element*nSpace +
12114  k*nSpace + 2]
12115  *
12116  grad_w[eN*nQuadraturePoints_element*nSpace +
12117  k*nSpace + 2]
12118  +
12119  0.5*
12120  (grad_u[eN*nQuadraturePoints_element*nSpace +
12121  k*nSpace + 1]
12122  +
12123  grad_v[eN*nQuadraturePoints_element*nSpace +
12124  k*nSpace + 0])
12125  *
12126  (grad_u[eN*nQuadraturePoints_element*nSpace +
12127  k*nSpace + 1]
12128  +
12129  grad_v[eN*nQuadraturePoints_element*nSpace +
12130  k*nSpace + 0])
12131  +
12132  0.5*
12133  (grad_u[eN*nQuadraturePoints_element*nSpace +
12134  k*nSpace + 2]
12135  +
12136  grad_w[eN*nQuadraturePoints_element*nSpace +
12137  k*nSpace + 0])
12138  *
12139  (grad_u[eN*nQuadraturePoints_element*nSpace +
12140  k*nSpace + 2]
12141  +
12142  grad_w[eN*nQuadraturePoints_element*nSpace +
12143  k*nSpace + 0])
12144  +
12145  0.5*
12146  (grad_v[eN*nQuadraturePoints_element*nSpace +
12147  k*nSpace + 2]
12148  +
12149  grad_w[eN*nQuadraturePoints_element*nSpace +
12150  k*nSpace + 1])
12151  *
12152  (grad_v[eN*nQuadraturePoints_element*nSpace +
12153  k*nSpace + 2]
12154  +
12155  grad_w[eN*nQuadraturePoints_element*nSpace +
12156  k*nSpace + 1]);
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;
12160 
12161  }
12162  }
12163 
12164 }
12165 void calculateEddyViscosity_Smagorinsky2P_2D(const int nElements_global,
12166  const int nQuadraturePoints_element,
12167  const double smagorinskyConstant_0,
12168  const double smagorinskyConstant_1,
12169  const double eps,
12170  const double * phi_ls,
12171  const double * h_e,
12172  const double * grad_u,
12173  const double * grad_v,
12174  double * nu_t)
12175 {
12176  int eN,k;
12177  const int nSpace = 2;
12178  double norm_S2,norm_S,H_smc,smc;
12179  for (eN = 0; eN < nElements_global; eN++)
12180  {
12181  for (k = 0; k < nQuadraturePoints_element; k++)
12182  {
12183  H_smc = smoothedHeaviside(eps,phi_ls[k]);
12184  smc = smagorinskyConstant_0*(1.0-H_smc) + smagorinskyConstant_1*H_smc;
12185 
12186  norm_S2 =
12187  grad_u[eN*nQuadraturePoints_element*nSpace +
12188  k*nSpace + 0]
12189  *
12190  grad_u[eN*nQuadraturePoints_element*nSpace +
12191  k*nSpace + 0]
12192  +
12193  grad_v[eN*nQuadraturePoints_element*nSpace +
12194  k*nSpace + 1]
12195  *
12196  grad_v[eN*nQuadraturePoints_element*nSpace +
12197  k*nSpace + 1]
12198  +
12199  0.5*
12200  (grad_u[eN*nQuadraturePoints_element*nSpace +
12201  k*nSpace + 1]
12202  +
12203  grad_v[eN*nQuadraturePoints_element*nSpace +
12204  k*nSpace + 0])
12205  *
12206  (grad_u[eN*nQuadraturePoints_element*nSpace +
12207  k*nSpace + 1]
12208  +
12209  grad_v[eN*nQuadraturePoints_element*nSpace +
12210  k*nSpace + 0]);
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;
12214 
12215  }
12216  }
12217 
12218 }
12219 void calculateEddyViscosity_Smagorinsky2P_3D(const int nElements_global,
12220  const int nQuadraturePoints_element,
12221  const double smagorinskyConstant_0,
12222  const double smagorinskyConstant_1,
12223  const double eps,
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,
12229  double * nu_t)
12230 {
12231  int eN,k;
12232  const int nSpace = 3;
12233  double norm_S2,norm_S,H_smc,smc;
12234  for (eN = 0; eN < nElements_global; eN++)
12235  {
12236  for (k = 0; k < nQuadraturePoints_element; k++)
12237  {
12238  H_smc = smoothedHeaviside(eps,phi_ls[k]);
12239  smc = smagorinskyConstant_0*(1.0-H_smc) + smagorinskyConstant_1*H_smc;
12240 
12241  norm_S2 =
12242  grad_u[eN*nQuadraturePoints_element*nSpace +
12243  k*nSpace + 0]
12244  *
12245  grad_u[eN*nQuadraturePoints_element*nSpace +
12246  k*nSpace + 0]
12247  +
12248  grad_v[eN*nQuadraturePoints_element*nSpace +
12249  k*nSpace + 1]
12250  *
12251  grad_v[eN*nQuadraturePoints_element*nSpace +
12252  k*nSpace + 1]
12253  +
12254  grad_w[eN*nQuadraturePoints_element*nSpace +
12255  k*nSpace + 2]
12256  *
12257  grad_w[eN*nQuadraturePoints_element*nSpace +
12258  k*nSpace + 2]
12259  +
12260  0.5*
12261  (grad_u[eN*nQuadraturePoints_element*nSpace +
12262  k*nSpace + 1]
12263  +
12264  grad_v[eN*nQuadraturePoints_element*nSpace +
12265  k*nSpace + 0])
12266  *
12267  (grad_u[eN*nQuadraturePoints_element*nSpace +
12268  k*nSpace + 1]
12269  +
12270  grad_v[eN*nQuadraturePoints_element*nSpace +
12271  k*nSpace + 0])
12272  +
12273  0.5*
12274  (grad_u[eN*nQuadraturePoints_element*nSpace +
12275  k*nSpace + 2]
12276  +
12277  grad_w[eN*nQuadraturePoints_element*nSpace +
12278  k*nSpace + 0])
12279  *
12280  (grad_u[eN*nQuadraturePoints_element*nSpace +
12281  k*nSpace + 2]
12282  +
12283  grad_w[eN*nQuadraturePoints_element*nSpace +
12284  k*nSpace + 0])
12285  +
12286  0.5*
12287  (grad_v[eN*nQuadraturePoints_element*nSpace +
12288  k*nSpace + 2]
12289  +
12290  grad_w[eN*nQuadraturePoints_element*nSpace +
12291  k*nSpace + 1])
12292  *
12293  (grad_v[eN*nQuadraturePoints_element*nSpace +
12294  k*nSpace + 2]
12295  +
12296  grad_w[eN*nQuadraturePoints_element*nSpace +
12297  k*nSpace + 1]);
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;
12301 
12302  }
12303  }
12304 
12305 }
12306 
12307 void eddyViscosity_2D_Update(const int nPoints,
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)
12313 {
12314  int i;
12315  for (i=0;i<nPoints;i++)
12316  {
12317 #ifdef SCALAR_DIFFUSION
12318  //u momentum diffusion tensor
12319  mom_u_diff_ten[i*4+0] += nu_t[i];
12320  mom_u_diff_ten[i*4+3] += nu_t[i];
12321 
12322  //v momentum diffusion tensor
12323  mom_v_diff_ten[i*4+0] += nu_t[i];
12324  mom_v_diff_ten[i*4+3] += nu_t[i];
12325 #else
12326  //u momentum diffusion tensor
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];
12330 
12331  //v momentum diffusion tensor
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];
12335 #endif
12336 
12337 
12338  }
12339 }
12340 void eddyViscosity_2D_Update_sd(const int nPoints,
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)
12346 {
12347  int i;
12348  for (i=0;i<nPoints;i++)
12349  {
12350  //u momentum diffusion tensor
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];
12354 
12355  //v momentum diffusion tensor
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];
12359 
12360  }
12361 }
12362 void eddyViscosity_3D_Update(const int nPoints,
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)
12373 {
12374  int k;
12375  for (k=0;k<nPoints;k++)
12376  {
12377  //u momentum diffusion tensor
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];
12381 
12382  mom_uv_diff_ten[k*9+3]=nu_t[k];
12383 
12384  mom_uw_diff_ten[k*9+6]=nu_t[k];
12385 
12386  //v momentum diffusion tensor
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];
12390 
12391  mom_vu_diff_ten[k*9+1]=nu_t[k];
12392 
12393  mom_vw_diff_ten[k*9+7]=nu_t[k];
12394 
12395  //w momentum diffusion tensor
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];
12399 
12400  mom_wu_diff_ten[k*9+2]=nu_t[k];
12401 
12402  mom_wv_diff_ten[k*9+5]=nu_t[k];
12403 
12404 
12405  }
12406 }
12407 void eddyViscosity_3D_Update_sd(const int nPoints,
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)
12418 {
12419  int k;
12420  for (k=0;k<nPoints;k++)
12421  {
12422  //u momentum diffusion tensor
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];
12426 
12427  mom_uv_diff_ten[k]+=nu_t[k];
12428 
12429  mom_uw_diff_ten[k]+=nu_t[k];
12430 
12431  //v momentum diffusion tensor
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];
12435 
12436  mom_vu_diff_ten[k]+=nu_t[k];
12437 
12438  mom_vw_diff_ten[k]+=nu_t[k];
12439 
12440  //w momentum diffusion tensor
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];
12444 
12445  mom_wu_diff_ten[k]+=nu_t[k];
12446 
12447  mom_wv_diff_ten[k]+=nu_t[k];
12448 
12449  }
12450 }
12451 
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,
12460  //
12461  const double* omega_s_x, //source region (rectangular)
12462  const double* omega_s_y,
12463  const double* omega_s_z,
12464  double t,
12465  int waveFlag, //1 secondOrderStokes
12466  //2 solitaryWave
12467  //0 monochromaticWave
12468  double epsFact,
12469  double waveHeight,
12470  double waveCelerity,
12471  double waveFrequency,
12472  double waveNumber,
12473  double waterDepth,
12474  double* source)
12475 {
12476  int eN,k,j,eN_j;
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;
12479  /*stokes wave parameters*/
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;
12483  if (waveFlag == 1)
12484  {
12485  kd = waveNumber*waterDepth;
12486  a_s = waveHeight*0.5;
12487  sinhkd = sinh(kd);
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);
12490  p_s = asin(term1);
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;
12495 
12496  }
12497  else if (waveFlag == 2)
12498  {
12499  term1 = 4.0*waveHeight/sqrt(waveHeight/waterDepth);/*x_s*/
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;
12505  }
12506  else
12507  {
12508  factor = waveHeight/source_volume*waveCelerity*sin(waveFrequency*t);
12509  }
12510  for (eN = 0; eN < nElements_global; eN++)
12511  {
12512  eps = epsFact*elementDiametersArray[eN];
12513  for (k = 0; k < nQuadraturePoints_element; k++)
12514  {
12515  x=0.; y=0.; z=0.;
12516  for (j=0; j < nDOF_element_mesh; j++)
12517  {
12518  eN_j= eN*nDOF_element_mesh+j;
12519  N_j = mesh_trial_ref[k*nDOF_element_mesh+j];
12520 
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;
12524 
12525  }
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;
12529  delta = (1.0-smoothedHeaviside(eps,distance_x))*(1.0-smoothedHeaviside(eps,distance_y))*(1.0-smoothedHeaviside(eps,distance_z));
12530  source[eN*nQuadraturePoints_element+k] = -factor*delta;
12531 
12532  }
12533  }
12534 
12535 }
12536 /* /\*simple piecewise linear interpolation from a table */
12537 /* assumes xv are increasing */
12538 /* *\/ */
12539 /* int findInterval(const double* vertices, int nv, double x, int* ival, double tol) */
12540 /* { */
12541 /* int leftInt=0,rightInt=nv-2,failed=1,mid=0; */
12542 /* assert(rightInt >= leftInt); */
12543 /* /\*take care of easy cases first*\/ */
12544 /* if (fabs(x-vertices[leftInt]) < tol) */
12545 /* { */
12546 /* *ival=leftInt; */
12547 /* failed=0; */
12548 /* return failed; */
12549 /* } */
12550 /* if (x <= vertices[leftInt]-tol) */
12551 /* { */
12552 /* *ival=-1; */
12553 /* failed=1; */
12554 /* return failed; */
12555 /* } */
12556 /* if (fabs(x-vertices[rightInt+1]) < tol) */
12557 /* { */
12558 /* *ival=rightInt; */
12559 /* failed=0; */
12560 /* return failed; */
12561 /* } */
12562 /* if (x >= vertices[rightInt+1]+tol) */
12563 /* { */
12564 /* *ival = nv; */
12565 /* failed=1; */
12566 /* return failed; */
12567 /* } */
12568 /* /\*otherwise, should have x in (left,right)*\/ */
12569 /* while (leftInt <= rightInt) */
12570 /* { */
12571 /* mid = (int)(floor(0.5*(leftInt+rightInt))); */
12572 /* if (vertices[mid] <= x && x < vertices[mid+1])/\*x in interval mid*\/ */
12573 /* { */
12574 /* *ival = mid; */
12575 /* failed = 0; */
12576 /* return failed; */
12577 /* } */
12578 /* else if (x < vertices[mid])/\*x to the left of mid*\/ */
12579 /* rightInt = mid-1; */
12580 /* else if (x >= vertices[mid+1]) /\*x to the right of mid*\/ */
12581 /* leftInt = mid+1; */
12582 /* else */
12583 /* { */
12584 /* printf("findInterval shouldn't be here leftInt=%d rightInt=%d \n",leftInt,rightInt); */
12585 /* assert(0); */
12586 /* failed = 1; */
12587 /* return failed; */
12588 /* } */
12589 /* } */
12590 /* failed = 1; */
12591 /* return failed; */
12592 /* } */
12593 /* void piecewiseLinearTableLookup(double x, */
12594 /* int nv, */
12595 /* int* start, */
12596 /* double* y, */
12597 /* double* dy, */
12598 /* const double* xv, */
12599 /* const double* yv) */
12600 /* { */
12601 /* int index=*start,findFailed=0; */
12602 /* double val,tol=1.0e-8; */
12603 /* findFailed = findInterval(xv,nv,x,&index,tol); */
12604 /* if (findFailed && index == -1) */
12605 /* { */
12606 /* /\*extrapolate off left, could use endpoint instead*\/ */
12607 /* index=0; */
12608 /* } */
12609 /* else if (findFailed && index == nv) */
12610 /* { */
12611 /* /\*extrapolate off right, could use endpoint instead*\/ */
12612 /* index = nv-2; */
12613 /* } */
12614 /* else */
12615 /* { */
12616 /* assert(0 <= index && index < nv-1); */
12617 /* assert(xv[index]-tol <= x && x<= xv[index+1]+tol); */
12618 /* } */
12619 /* assert(0 <= index && index < nv-1); */
12620 /* val = yv[index] + (yv[index+1]-yv[index])/(xv[index+1]-xv[index])*(x-xv[index]); */
12621 /* *y = val; */
12622 /* *dy = (yv[index+1]-yv[index])/(xv[index+1]-xv[index]); */
12623 /* *start = index; */
12624 /* } */
12625 
12626 void Mass_2D_Evaluate(const int nPoints,
12627  double rho,
12628  double *p,
12629  double *u,
12630  double *v,
12631  double *mom_p_acc,
12632  double *mom_u_acc,
12633  double *mom_v_acc,
12634  double *dmom_p_acc_p,
12635  double *dmom_u_acc_u,
12636  double *dmom_v_acc_v)
12637 {
12638  int k;
12639  for (k=0; k<nPoints; k++){
12640  mom_p_acc[k] = p[k];
12641  dmom_p_acc_p[k] = 1.0;
12642 
12643  mom_u_acc[k] = u[k];
12644  dmom_u_acc_u[k] = 1.0;
12645 
12646  mom_v_acc[k] = v[k];
12647  dmom_v_acc_v[k] = 1.0;
12648  }
12649 }
12650 
12651 void Mass_3D_Evaluate(const int nPoints,
12652  double rho,
12653  double *p,
12654  double *u,
12655  double *v,
12656  double *w,
12657  double *mom_p_acc,
12658  double *mom_u_acc,
12659  double *mom_v_acc,
12660  double *mom_w_acc,
12661  double *dmom_p_acc_p,
12662  double *dmom_u_acc_u,
12663  double *dmom_v_acc_v,
12664  double *dmom_w_acc_w)
12665 {
12666  int k;
12667  for (k=0; k<nPoints; k++){
12668  mom_p_acc[k] = p[k];
12669  dmom_p_acc_p[k] = 1.0;
12670 
12671  mom_u_acc[k] = u[k];
12672  dmom_u_acc_u[k] = 1.0;
12673 
12674  mom_v_acc[k] = v[k];
12675  dmom_v_acc_v[k] = 1.0;
12676 
12677  mom_w_acc[k] = w[k];
12678  dmom_w_acc_w[k] = 1.0;
12679  }
12680 }
12681 
12683  const double eps,
12684  const double rho_0,
12685  const double nu_0,
12686  const double rho_1,
12687  const double nu_1,
12688  const double* phi,
12689  double *mom_p_diff_ten,
12690  double *mom_u_diff_ten,
12691  double *mom_v_diff_ten)
12692 {
12693  int k;
12694  double rho,nu,mu,H;
12695 
12696  for (k=0; k<nPoints; k++)
12697  {
12698  H = smoothedHeaviside(eps,phi[k]);
12699  rho = rho_0*(1.0-H) + rho_1*H;
12700  nu = nu_0*(1.0-H) + nu_1*H;
12701  mu = rho_0*nu_0*(1.0-H) + rho_1*nu_1*H;
12702 
12703  mom_p_diff_ten[k*2+0] = 1.0 / rho;
12704  mom_p_diff_ten[k*2+1] = 1.0 / rho;
12705 
12706  mom_u_diff_ten[k*2+0] = 1.0 / rho;
12707  mom_u_diff_ten[k*2+1] = 1.0 / rho;
12708 
12709  mom_v_diff_ten[k*2+0] = 1.0 / rho;
12710  mom_v_diff_ten[k*2+1] = 1.0 / rho;
12711  }
12712 }
12713 
12714 void TwoPhaseAdvection_2D_Evaluate(const int nPoints,
12715  const double eps,
12716  const double rho_0,
12717  const double nu_0,
12718  const double rho_1,
12719  const double nu_1,
12720  const double *phi,
12721  const double *p,
12722  const double *u,
12723  const double *v,
12724  double *mass_adv,
12725  double *dmass_adv_p,
12726  double *dmass_adv_u,
12727  double *dmass_adv_v,
12728  double *mom_u_adv,
12729  double *dmom_u_adv_u,
12730  double *dmom_u_adv_v,
12731  double *mom_v_adv,
12732  double *dmom_v_adv_u,
12733  double *dmom_v_adv_v)
12734 {
12735  int k;
12736  double rho, nu, mu, H;
12737 
12738  for (k=0;k<nPoints;k++)
12739  {
12740  H = smoothedHeaviside(eps,phi[k]);
12741  rho = rho_0*(1.0-H) + rho_1*H;
12742  nu = nu_0*(1.0-H) + nu_1*H;
12743  mu = rho_0*nu_0*(1.0-H) + rho_1*nu_1*H;
12744 
12745  //mass advective flux
12746  mass_adv[k*2+0]=rho*u[k]*p[k];
12747  mass_adv[k*2+1]=rho*v[k]*p[k];
12748 
12749  dmass_adv_p[k*2+0] = rho*u[k];
12750  dmass_adv_p[k*2+1] = rho*v[k];
12751  // ARB - NOTE TO SELF...Why arent these derivatives p[k]?
12752  // Possible error to investigate.
12753  dmass_adv_u[k*2+0]= 0.0;
12754  dmass_adv_v[k*2+1]= 0.0;
12755 
12756  mom_u_adv[k*2+0] = rho*u[k]*u[k];
12757  mom_u_adv[k*2+1] = rho*u[k]*v[k];
12758 
12759  dmom_u_adv_u[k*2+0] = rho*2.0*u[k];
12760  dmom_u_adv_u[k*2+1] = rho*v[k];
12761 
12762  dmom_u_adv_v[k*2+1] = rho*u[k];
12763 
12764  mom_v_adv[k*2+0] = rho*v[k]*u[k];
12765  mom_v_adv[k*2+1] = rho*v[k]*v[k];
12766 
12767  dmom_v_adv_u[k*2+0] = rho*v[k];
12768 
12769  dmom_v_adv_v[k*2+0] = rho*u[k];
12770  dmom_v_adv_v[k*2+1] = rho*2.0*v[k];
12771  }
12772 }
VolumeAveragedTwophaseNavierStokes_ST_LS_SO_3D_Evaluate_sd
void VolumeAveragedTwophaseNavierStokes_ST_LS_SO_3D_Evaluate_sd(const int nPoints, const int killNonlinearDrag, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *meanGrainSize, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *w, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_u_source_w, double *dmom_v_source_u, double *dmom_v_source_v, double *dmom_v_source_w, double *dmom_w_source_u, double *dmom_w_source_v, double *dmom_w_source_w, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:9660
Laplace_Evaluate2D
void Laplace_Evaluate2D(const int nPoints, double *mom_p_diff_ten, double *mom_u_diff_ten, double *mom_v_diff_ten)
Definition: transportCoefficients.c:1803
Y
Double * Y
Definition: Headers.h:48
Stokes_3D_Evaluate
void Stokes_3D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:2206
smoothedHeaviside
double smoothedHeaviside(double eps, double phi)
Definition: transportCoefficients.c:33
TwophaseNavierStokes_LS_SO_2D_Evaluate
void TwophaseNavierStokes_LS_SO_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:2383
redistanceLevelSetCoefficientsWithWeakPenaltyEvaluate
void redistanceLevelSetCoefficientsWithWeakPenaltyEvaluate(int nPoints, int nSpace, double eps, double lambda_penalty, double *u_levelSet, double *u, double *grad_u, double *m, double *dm, double *H, double *dH, double *r, double *dr)
Definition: transportCoefficients.c:1443
conservativeHeadRichardsMualemVanGenuchtenHetEvaluate
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6337
redistanceLevelSetSandFCoefficientsEvaluate
void redistanceLevelSetSandFCoefficientsEvaluate(int nSimplex, int nPointsPerSimplex, int nSpace, double eps, double *u_levelSet, double *dV, double *u, double *grad_u, double *m, double *dm, double *H, double *dH, double *r)
Definition: transportCoefficients.c:1512
shallowWater_2D_Evaluate
void shallowWater_2D_Evaluate(const int nPoints, const double h_eps, const double g, const double bedFrictionCoefficient, const double bedFrictionPower, const double eddyViscosity, const double *x, const double *grad_b, const double *h, const double *hu, const double *hv, double *H, double *mass_acc, double *dmass_acc_dh, double *mom_u_acc, double *dmom_u_acc_dhu, double *mom_v_acc, double *dmom_v_acc_dhv, double *mass_adv, double *dmass_adv_dhu, double *dmass_adv_dhv, double *mom_u_adv, double *dmom_u_adv_dh, double *dmom_u_adv_dhu, double *dmom_u_adv_dhv, double *mom_v_adv, double *dmom_v_adv_dh, double *dmom_v_adv_dhu, double *dmom_v_adv_dhv, double *mom_u_diff, double *mom_v_diff, double *mom_u_source, double *dmom_u_source_dh, double *dmom_u_source_dhu, double *dmom_u_source_dhv, double *mom_v_source, double *dmom_v_source_dh, double *dmom_v_source_dhu, double *dmom_v_source_dhv)
Definition: transportCoefficients.c:11180
kEpsilon_2D_Evaluate
void kEpsilon_2D_Evaluate(int nPoints, int nSpace, double sigma_k, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *k, double *epsilon, double *m_k, double *dm_k, double *m_e, double *dm_e, double *phi_k, double *dphi_k, double *phi_e, double *dphi_e, double *f_k, double *df_k, double *f_e, double *df_e, double *a_k, double *da_k_dk, double *da_k_de, double *a_e, double *da_e_dk, double *da_e_de, double *r_k, double *dr_k_dk, double *dr_k_de, double *r_e, double *dr_e_dk, double *dr_e_de)
Definition: transportCoefficients.c:9975
diffusiveWave1DEvaluate
void diffusiveWave1DEvaluate(const int nPoints, const double alpha, const double gamma, const double epsilon, const double *x, const double *u, const double *grad_u, double *m, double *dm, double *a, double *da)
Definition: transportCoefficients.c:11978
w
#define w(x)
Definition: jf.h:22
VolumeAveragedTwophaseNavierStokes_ST_LS_SO_3D_Evaluate
void VolumeAveragedTwophaseNavierStokes_ST_LS_SO_3D_Evaluate(const int nPoints, const int killNonlinearDrag, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *meanGrainSize, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *w, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_u_source_w, double *dmom_v_source_u, double *dmom_v_source_v, double *dmom_v_source_w, double *dmom_w_source_u, double *dmom_w_source_v, double *dmom_w_source_w, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:9322
rotatingPulseVelEvaluate
void rotatingPulseVelEvaluate(const int nPoints, const int nSpace, const double self_a, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:818
B
Double * B
Definition: Headers.h:41
l2project2Tensor
void l2project2Tensor(const int nSimplices, const int nPointsPerSimplex, const int nSpace, double *dV, double *r)
Definition: transportCoefficients.c:5705
TwophaseNavierStokes_ST_LS_SO_2D_Evaluate_sd
void TwophaseNavierStokes_ST_LS_SO_2D_Evaluate_sd(const int nPoints, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:2677
conservativeHeadRichardsJLeverett
void conservativeHeadRichardsJLeverett(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *phi, const double *psiD, const double *ns, const double *nk, const double *S_wirr, const double *S_nwr, const double *kr0, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6143
twophaseLevelSetCoefficientsEvaluate
void twophaseLevelSetCoefficientsEvaluate(int nPoints, int nSpace, double *B, double t, double *x, double *u, double *grad_u, double *m, double *dm, double *h, double *dh, double *rh)
Definition: transportCoefficients.c:1147
HI
#define HI
Definition: Headers.h:4
l2projectVector
void l2projectVector(const int nSimplices, const int nPointsPerSimplex, const int nSpace, double *dV, double *r)
Definition: transportCoefficients.c:5676
VolumeAveragedTwophaseNavierStokes_ST_LS_SO_2D_Evaluate_sd
void VolumeAveragedTwophaseNavierStokes_ST_LS_SO_2D_Evaluate_sd(const int nPoints, const int killNonlinearDrag, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *meanGrainSize, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_v_source_u, double *dmom_v_source_v, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:9079
conservativeSatRichardsMualemVanGenuchtenHomEvaluate
void conservativeSatRichardsMualemVanGenuchtenHomEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double *x, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:6418
kEpsilon_epsilon_2D_Evaluate_sd
void kEpsilon_epsilon_2D_Evaluate_sd(int nPoints, int nSpace, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *k, double *epsilon, double *m_e, double *dm_e, double *phi_e, double *dphi_e, double *f_e, double *df_e, double *a_e, double *da_e_de, double *r_e, double *dr_e_de)
Definition: transportCoefficients.c:10526
TwophaseStokes_LS_SO_3D_Evaluate
void TwophaseStokes_LS_SO_3D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:4203
NavierStokes_2D_Evaluate
void NavierStokes_2D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:1850
ThreephaseNavierStokes_ST_LS_SO_2D_EvaluateOrig
void ThreephaseNavierStokes_ST_LS_SO_2D_EvaluateOrig(const int nPoints, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double rho_s, const double nu_s, const double *g, const double *phi, const double *n, const double *kappa, const double *phi_s, const double *n_s, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *dmom_u_source_u, double *dmom_u_source_v, double *mom_v_source, double *dmom_v_source_u, double *dmom_v_source_v, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:2853
conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm_sd
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm_sd(const int upwindFlag, const int computeAverages, const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int nQuadraturePoints_elementBoundary, const int *rowptr, const int *colind, const int *elementBoundaryElementsArray, const int *quadraturePointToElementBoundary, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n_vg, const double *thetaR, const double *thetaSR, const double *KWs, const double *u, const double *gradu, const double *n_global, const double *dV, double *mass, double *dmass, double *f_avg, double *df_avg, double *a_avg, double *da_avg, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:11710
linearHeaviside
double linearHeaviside(double eps, double phi)
Definition: transportCoefficients.c:77
TwoPhaseInvScaledLaplace_2D_Evaluate
void TwoPhaseInvScaledLaplace_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *phi, double *mom_p_diff_ten, double *mom_u_diff_ten, double *mom_v_diff_ten)
Definition: transportCoefficients.c:12682
TwophaseNavierStokes_LS_SO_3D_Evaluate
void TwophaseNavierStokes_LS_SO_3D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:3981
calculateEddyViscosity_Smagorinsky2P_3D
void calculateEddyViscosity_Smagorinsky2P_3D(const int nElements_global, const int nQuadraturePoints_element, const double smagorinskyConstant_0, const double smagorinskyConstant_1, const double eps, const double *phi_ls, const double *h_e, const double *grad_u, const double *grad_v, const double *grad_w, double *nu_t)
Definition: transportCoefficients.c:12219
kd
Double kd
Definition: Headers.h:70
StokesP_2D_Evaluate
void StokesP_2D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_p, double *mom_v_adv, double *dmom_v_adv_p, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source)
Definition: transportCoefficients.c:2143
TwophaseNavierStokes_ST_LS_SO_3D_Evaluate
void TwophaseNavierStokes_ST_LS_SO_3D_Evaluate(const int nPoints, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:3279
f
Double f
Definition: Headers.h:64
unitSquareVortexEvaluate
void unitSquareVortexEvaluate(const int nPoints, const int nSpace, double t, const double *x, const double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:4717
darcySharpInterfaceFlowImEvaluate
void darcySharpInterfaceFlowImEvaluate(int nPoints, int nSpace, double Km, double rhoM, double Kp, double rhoP, double eps, double *gravity_u, double *u, double *gradu, double *u_levelSet, double *phi_pot, double *a, double *f, double *r, double *m, double *dphi_pot, double *da, double *df, double *dr, double *dm)
Definition: transportCoefficients.c:1750
ThreephaseNavierStokes_ST_LS_SO_2D_Evaluate
void ThreephaseNavierStokes_ST_LS_SO_2D_Evaluate(const int nPoints, const double boundaryPenaltyCoef, const double volumePenaltyCoef, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double rho_s, const double nu_s, const double *g, const double *phi, const double *n, const double *kappa, const double *phi_s, const double *n_s, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *dmom_u_source_u, double *dmom_u_source_v, double *mom_v_source, double *dmom_v_source_u, double *dmom_v_source_v, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:3050
linearADR_ConstantCoefficientsEvaluate
void linearADR_ConstantCoefficientsEvaluate(const int nPoints, const int nSpace, const double M, const double *A, const double *B, const double C, const double t, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *r, double *dr)
Definition: transportCoefficients.c:101
scriptedSphereMotionSignedDistance
void scriptedSphereMotionSignedDistance(const int nPoints, const double t, const int nSpace, const int nSpheres, const double *radii, const double *centers, const double *x, double *phi, double *n)
Definition: transportCoefficients.c:11059
applyContactLineSlip
void applyContactLineSlip(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, double eps, int *isDOFBoundary, double *phi, double *advectiveFlux, double *diffusiveFlux)
Definition: transportCoefficients.c:11924
nonlinearADR_pqrstEvaluate
void nonlinearADR_pqrstEvaluate(const int nPoints, const int nSpace, const double M, const double *A, const double *B, const double C, const double p_pow, const double q_pow, const double r_pow, const double s_pow, const double t_pow, const double t, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi, double *r, double *dr)
Definition: transportCoefficients.c:597
kEpsilon_k_3D_Evaluate_sd
void kEpsilon_k_3D_Evaluate_sd(int nPoints, int nSpace, double sigma_k, double c_mu, double nu, double *velocity, double *gradu, double *gradv, double *gradw, double *k, double *epsilon, double *m_k, double *dm_k, double *phi_k, double *dphi_k, double *f_k, double *df_k, double *a_k, double *da_k_dk, double *r_k, double *dr_k_dk)
Definition: transportCoefficients.c:10606
applyContactLineSlipJacobian
void applyContactLineSlipJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, double eps, int *isDOFBoundary, double *phi, double *fluxJacobian)
Definition: transportCoefficients.c:11948
Stokes_2D_Evaluate
void Stokes_2D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:2079
conservativeHeadRichardsL2projMualemVanGenuchtenHomEvaluate
void conservativeHeadRichardsL2projMualemVanGenuchtenHomEvaluate(const int nSimplices, const int nPointsPerSimplex, const int nSpace, const double rho, const double *gravity, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *dV, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:5095
n
Int n
Definition: Headers.h:28
NavierStokes_3D_Evaluate
void NavierStokes_3D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:1938
redistanceLevelSetCoefficientsEvaluate
void redistanceLevelSetCoefficientsEvaluate(int nPoints, int nSpace, double eps, double *u_levelSet, double *u, double *grad_u, double *m, double *dm, double *H, double *dH, double *r)
Definition: transportCoefficients.c:1384
df
double df(double C, double b, double a, int q, int r)
Definition: analyticalSolutions.c:2209
phi
Double phi
Definition: Headers.h:76
calculateEddyViscosity_Smagorinsky_3D
void calculateEddyViscosity_Smagorinsky_3D(const int nElements_global, const int nQuadraturePoints_element, const double smagorinskyConstant, const double *h_e, const double *grad_u, const double *grad_v, const double *grad_w, double *nu_t)
Definition: transportCoefficients.c:12084
conservativeHeadRichardsJLeverettAni
void conservativeHeadRichardsJLeverettAni(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *phi, const double *psiD, const double *ns, const double *nk, const double *S_wirr, const double *S_nwr, const double *kr0x, const double *kr0y, const double *kr0z, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6220
kEpsilon_3D_Evaluate
void kEpsilon_3D_Evaluate(int nPoints, int nSpace, double sigma_k, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *gradw, double *k, double *epsilon, double *m_k, double *dm_k, double *m_e, double *dm_e, double *phi_k, double *dphi_k, double *phi_e, double *dphi_e, double *f_k, double *df_k, double *f_e, double *df_e, double *a_k, double *da_k_dk, double *da_k_de, double *a_e, double *da_e_dk, double *da_e_de, double *r_k, double *dr_k_dk, double *dr_k_de, double *r_e, double *dr_e_dk, double *dr_e_de)
Definition: transportCoefficients.c:10329
kEpsilon_k_2D_Evaluate_sd
void kEpsilon_k_2D_Evaluate_sd(int nPoints, int nSpace, double sigma_k, double c_mu, double nu, double *velocity, double *gradu, double *gradv, double *k, double *epsilon, double *m_k, double *dm_k, double *phi_k, double *dphi_k, double *f_k, double *df_k, double *a_k, double *da_k_dk, double *r_k, double *dr_k_dk)
Definition: transportCoefficients.c:10456
constantVelocityLevelSetEvaluate
void constantVelocityLevelSetEvaluate(const int nPoints, const int nSpace, const double *b, const double *x, const double *u, const double *gradu, double *m, double *dm, double *f, double *df, double *H, double *dH)
Definition: transportCoefficients.c:4745
variablySaturatedGroundwaterEnergyTransportCoefficientsEvaluate_hetMat
void variablySaturatedGroundwaterEnergyTransportCoefficientsEvaluate_hetMat(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const double rho_w, const double rho_n, const double specificHeat_w, const double specificHeat_n, const int *materialTypes, const double *theta, const double *thetaS_types, const double *alpha_L_types, const double *alpha_T_types, const double *rho_s_types, const double *specificHeat_s_types, const double *lambda_sat_types, const double *lambda_dry_types, const double *lambda_aniso_types, const double *v, const double *u, double *m, double *dm, double *f, double *df, double *a)
Definition: transportCoefficients.c:523
LinearElasticity_3D_Evaluate
void LinearElasticity_3D_Evaluate(const int nPoints, const double E, const double nu, const double *g, const double *u, const double *v, const double *w, double *uu_diff_ten, double *uv_diff_ten, double *uw_diff_ten, double *vu_diff_ten, double *vv_diff_ten, double *vw_diff_ten, double *wu_diff_ten, double *wv_diff_ten, double *ww_diff_ten, double *u_force, double *v_force, double *w_force)
Definition: transportCoefficients.c:8186
cLevelSetCoefficientsEvaluate
void cLevelSetCoefficientsEvaluate(int nPoints, int nSpace, double *v, double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:1222
twophasePotentialFlowEvaluate
void twophasePotentialFlowEvaluate(int nPoints, int nSpace, double *M, double *A, double *B, double *Bcon, double *C, double t, double *x, double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi, double *r, double *dr)
Definition: transportCoefficients.c:1027
shallowWater_1D_Evaluate
void shallowWater_1D_Evaluate(const int nPoints, const double h_eps, const double g, const double bedFrictionCoefficient, const double bedFrictionPower, const double eddyViscosity, const double *x, const double *db_dx, const double *h, const double *hu, double *H, double *mass_acc, double *dmass_acc_dh, double *mom_acc, double *dmom_acc_dhu, double *mass_adv, double *dmass_adv_dhu, double *mom_adv, double *dmom_adv_dh, double *dmom_adv_dhu, double *mom_source, double *dmom_source_dh, double *dmom_source_dhu, double *mom_diff)
Definition: transportCoefficients.c:11107
VolumeAveragedTwophaseNavierStokes_ST_LS_SO_2D_Evaluate
void VolumeAveragedTwophaseNavierStokes_ST_LS_SO_2D_Evaluate(const int nPoints, const int killNonlinearDrag, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *meanGrainSize, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_v_source_u, double *dmom_v_source_v, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:8832
Laplace_Evaluate3D
void Laplace_Evaluate3D(const int nPoints, double *mom_p_diff_ten, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten)
Definition: transportCoefficients.c:1822
eddyViscosity_3D_Update
void eddyViscosity_3D_Update(const int nPoints, const double *nu_t, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten)
Definition: transportCoefficients.c:12362
darcySharpInterfaceFlowEvaluate
void darcySharpInterfaceFlowEvaluate(int nPoints, int nSpace, double Km, double rhoM, double Kp, double rhoP, double eps, double *gravity_u, double *u, double *gradu, double *u_levelSet, double *phi_pot, double *a, double *f, double *r, double *m, double *dphi_pot, double *da, double *df, double *dr, double *dm)
Definition: transportCoefficients.c:1698
H
Double H
Definition: Headers.h:65
vx
Double vx
Definition: Headers.h:97
conservativeTotalHeadRichardsMualemVanGenuchtenHomEvaluate
void conservativeTotalHeadRichardsMualemVanGenuchtenHomEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double *x, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:5550
HJBurgersEvaluate
void HJBurgersEvaluate(const int nPoints, const int nSpace, const double offset, const double *u, const double *gradu, double *m, double *dm, double *H, double *dH)
Definition: transportCoefficients.c:4885
nu_0
double nu_0
Definition: ErrorResidualMethod.cpp:22
levelSetConservationCoefficientsEvaluate
void levelSetConservationCoefficientsEvaluate(int nPoints, int nSpace, double epsHeaviside, double epsDirac, double epsDiffusion, double *u_ls, double *H_vof, double *u, double *r, double *dr, double *a)
Definition: transportCoefficients.c:8393
conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:5990
v
Double v
Definition: Headers.h:95
StokesP_3D_Evaluate
void StokesP_3D_Evaluate(const int nPoints, const double rho, const double nu, const double *g, const double *p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_p, double *mom_v_adv, double *dmom_v_adv_p, double *mom_w_adv, double *dmom_w_adv_p, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source)
Definition: transportCoefficients.c:2295
conservativeHeadRichardsBrooksCoreyBurdineHetEvaluate
void conservativeHeadRichardsBrooksCoreyBurdineHetEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double *lambda, const double *pd, const double *thetaR, const double *thetaS, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6648
ReynoldsAveragedNavierStokes_kEpsilon_2D_Update
void ReynoldsAveragedNavierStokes_kEpsilon_2D_Update(const int nPoints, const double nu, const double c_mu, const double *k, const double *grad_k, const double *epsilon, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source)
Definition: transportCoefficients.c:10808
nu_1
double nu_1
Definition: ErrorResidualMethod.cpp:22
transportCoefficients.h
calculateWaveFunction3d_ref
void calculateWaveFunction3d_ref(int nElements_global, int nDOF_element_mesh, int nQuadraturePoints_element, const double *mesh_trial_ref, const double *mesh_dof, const int *mesh_l2g, const double *elementDiametersArray, const double *omega_s_x, const double *omega_s_y, const double *omega_s_z, double t, int waveFlag, double epsFact, double waveHeight, double waveCelerity, double waveFrequency, double waveNumber, double waterDepth, double *source)
Definition: transportCoefficients.c:12452
eddyViscosity_3D_Update_sd
void eddyViscosity_3D_Update_sd(const int nPoints, const double *nu_t, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten)
Definition: transportCoefficients.c:12407
Mass_3D_Evaluate
void Mass_3D_Evaluate(const int nPoints, double rho, double *p, double *u, double *v, double *w, double *mom_p_acc, double *mom_u_acc, double *mom_v_acc, double *mom_w_acc, double *dmom_p_acc_p, double *dmom_u_acc_u, double *dmom_v_acc_v, double *dmom_w_acc_w)
Definition: transportCoefficients.c:12651
TwophaseStokes_VOF_SO_3D_Evaluate
void TwophaseStokes_VOF_SO_3D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *vof, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:4620
diffusiveWave2DEvaluate
void diffusiveWave2DEvaluate(const int nd, const int nPoints, const double alpha, const double gamma, const double epsilon, const double *x, const double *u, const double *grad_u, double *m, double *dm, double *a, double *da)
Definition: transportCoefficients.c:12007
twophaseLevelSetCoefficientsUpdateVelocity
void twophaseLevelSetCoefficientsUpdateVelocity(int nPoints, int nSpace, double v_scale, double *vIn, double *vOut)
Definition: transportCoefficients.c:1135
conservativeHeadRichardsL2projMualemVanGenuchtenHetEvaluate
void conservativeHeadRichardsL2projMualemVanGenuchtenHetEvaluate(const int nSimplices, const int nPointsPerSimplex, const int nSpace, const double rho, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *dV, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:5412
unitSquareRotationEvaluate
void unitSquareRotationEvaluate(const int nPoints, const int nSpace, const double *x, const double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:767
twophaseSignedDistanceCoefficientsUpdateSignFunction
void twophaseSignedDistanceCoefficientsUpdateSignFunction(int nPoints, double eps, double *u_levelSet, double *S)
Definition: transportCoefficients.c:1298
conservativeHeadRichardsBCBfromMVGHomEvaluate
void conservativeHeadRichardsBCBfromMVGHomEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6864
ReynoldsAveragedNavierStokes_kEpsilon_3D_Update
void ReynoldsAveragedNavierStokes_kEpsilon_3D_Update(const int nPoints, const double nu, const double c_mu, const double *k, const double *grad_k, const double *epsilon, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source)
Definition: transportCoefficients.c:10932
vy
Double vy
Definition: Headers.h:98
z
Double * z
Definition: Headers.h:49
TwophaseNavierStokes_VOF_SO_2D_Evaluate
void TwophaseNavierStokes_VOF_SO_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *vof, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:4300
burgersDiagonalVelEvaluate
void burgersDiagonalVelEvaluate(const int nPoints, const int nSpace, const double self_a, const double *self_v, const double *u, double *m, double *dm, double *f, double *df, double *a, double *phi, double *dphi)
Definition: transportCoefficients.c:953
u
Double u
Definition: Headers.h:89
relaxationFunction
double relaxationFunction(double phi, double phiStart, double phiEnd)
Definition: transportCoefficients.c:9
ns
Int ns
Definition: Headers.h:30
eddyViscosity_2D_Update
void eddyViscosity_2D_Update(const int nPoints, const double *nu_t, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten)
Definition: transportCoefficients.c:12307
seepageBrezis
void seepageBrezis(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int *materialTypes, const double epsFact, const double rho, const double beta, const double *elementDiameter, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6083
smoothedDirac
double smoothedDirac(double eps, double phi)
Definition: transportCoefficients.c:65
LinearElasticity_1D_Evaluate
void LinearElasticity_1D_Evaluate(const int nPoints, const double E, const double nu, const double *g, const double *u, double *uu_diff_ten, double *u_force)
Definition: transportCoefficients.c:8124
ThreephaseNavierStokes_ST_LS_SO_3D_Evaluate
void ThreephaseNavierStokes_ST_LS_SO_3D_Evaluate(const int nPoints, const double boundaryPenaltyCoef, const double volumePenaltyCoef, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double rho_s, const double nu_s, const double *g, const double *phi, const double *n, const double *kappa, const double *phi_s, const double *n_s, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_u_source_w, double *mom_v_source, double *dmom_v_source_u, double *dmom_v_source_v, double *dmom_v_source_w, double *mom_w_source, double *dmom_w_source_u, double *dmom_w_source_v, double *dmom_w_source_w, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:3749
conservativeHeadRichardsMualemVanGenuchten_sd_het
void conservativeHeadRichardsMualemVanGenuchten_sd_het(const int nSimplex, const int nPointsPerSimplex, const int nSpace, double pc_eps, const int *rowptr, const int *colind, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *vol_frac)
Definition: transportCoefficients.c:5740
conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm(const int upwindFlag, const int computeAverages, const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int nQuadraturePoints_elementBoundary, const int *elementBoundaryElementsArray, const int *quadraturePointToElementBoundary, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n_vg, const double *thetaR, const double *thetaSR, const double *KWs, const double *u, const double *gradu, const double *n_global, const double *dV, double *mass, double *dmass, double *f_avg, double *df_avg, double *a_avg, double *da_avg, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:11515
TwoPhaseAdvection_2D_Evaluate
void TwoPhaseAdvection_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *phi, const double *p, const double *u, const double *v, double *mass_adv, double *dmass_adv_p, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v)
Definition: transportCoefficients.c:12714
ncLevelSetCoefficientsEvaluate
void ncLevelSetCoefficientsEvaluate(int nPoints, int nSpace, double *v, double *u, double *grad_u, double *m, double *dm, double *H, double *dH)
Definition: transportCoefficients.c:1198
conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwind
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwind(const int upwindFlag, const int computeAverages, const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int nQuadraturePoints_elementBoundary, const int *elementBoundaryElementsArray, const int *quadraturePointToElementBoundary, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n_vg, const double *thetaR, const double *thetaSR, const double *KWs, const double *u, const double *gradu, const double *n_global, const double *dV, double *mass, double *dmass, double *f_avg, double *df_avg, double *a_avg, double *da_avg, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:11323
MovingMesh_3D_Evaluate
void MovingMesh_3D_Evaluate(const int nPoints, const double E0, const double nu, const double *g, const double *det_J, const double *u, const double *v, const double *w, double *uu_diff_ten, double *uv_diff_ten, double *uw_diff_ten, double *vu_diff_ten, double *vv_diff_ten, double *vw_diff_ten, double *wu_diff_ten, double *wv_diff_ten, double *ww_diff_ten, double *u_force, double *v_force, double *w_force)
Definition: transportCoefficients.c:8321
TwophaseNavierStokes_ST_LS_SO_3D_Evaluate_sd
void TwophaseNavierStokes_ST_LS_SO_3D_Evaluate_sd(const int nPoints, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:3568
TwophaseStokes_LS_SO_2D_Evaluate
void TwophaseStokes_LS_SO_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:4129
rho_1
double rho_1
Definition: ErrorResidualMethod.cpp:22
TwophaseNavierStokes_ST_LS_SO_2D_Evaluate
void TwophaseNavierStokes_ST_LS_SO_2D_Evaluate(const int nPoints, const double eps_rho, const double eps_mu, const double sigma, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *phi, const double *n, const double *kappa, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:2481
MovingMesh_1D_Evaluate
void MovingMesh_1D_Evaluate(const int nPoints, const double E0, const double nu, const double *g, const double *det_J, const double *u, double *uu_diff_ten, double *u_force)
Definition: transportCoefficients.c:8255
levelSetConservationCoefficientsEvaluate_sd
void levelSetConservationCoefficientsEvaluate_sd(int nPoints, double epsHeaviside, double epsDirac, double *u_ls, double *H_vof, double *u, double *r, double *dr)
Definition: transportCoefficients.c:8438
VolumeAveragedNavierStokesFullDevStress_3D_Evaluate
void VolumeAveragedNavierStokesFullDevStress_3D_Evaluate(const int nPoints, const double rho, const double mu, const double *meanGrainSize, const double *g, const double *p, const double *grad_p, const double *u, const double *v, const double *w, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_u_source_w, double *dmom_v_source_u, double *dmom_v_source_v, double *dmom_v_source_w, double *dmom_w_source_u, double *dmom_w_source_v, double *dmom_w_source_w, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:8630
LinearElasticity_2D_Evaluate
void LinearElasticity_2D_Evaluate(const int nPoints, const double E, const double nu, const double *g, const double *u, const double *v, double *uu_diff_ten, double *uv_diff_ten, double *vu_diff_ten, double *vv_diff_ten, double *u_force, double *v_force)
Definition: transportCoefficients.c:8143
conservativeHeadRichardsMualemVanGenuchtenHomEvaluate
void conservativeHeadRichardsMualemVanGenuchtenHomEvaluate(const int nPoints, const int nSpace, const double rho, const double beta, const double *gravity, const double *x, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:5007
unitCubeRotationEvaluate
void unitCubeRotationEvaluate(const int nPoints, const int nSpace, const double *x, const double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:791
groundwaterBryantDawsonIonExEvaluateFC
void groundwaterBryantDawsonIonExEvaluateFC(const int nPoints, const int nSpace, const double omega, const double d_m, const double d_h, const double alpha_L, const double alpha_T, const double K_m, const double K_h, const double K_w, const double Z_tot, const double *v, const double *c_m, const double *c_h, double *m_m, double *dm_m_m, double *dm_m_h, double *m_h, double *dm_h_m, double *dm_h_h, double *f_m, double *df_m, double *f_h, double *df_h, double *a_m, double *a_h, double *phi_h, double *dphi_h, double *r_m, double *dr_m_dm, double *dr_m_dh, double *r_h, double *dr_h_dm, double *dr_h_dh)
Definition: transportCoefficients.c:303
evaluateBuckleyLeverettLiuExample
void evaluateBuckleyLeverettLiuExample(int nPoints, int nSpace, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a)
Definition: transportCoefficients.c:8455
VolumeAveragedNavierStokesFullDevStress_2D_Evaluate
void VolumeAveragedNavierStokesFullDevStress_2D_Evaluate(const int nPoints, const double rho, const double mu, const double *meanGrainSize, const double *g, const double *p, const double *grad_p, const double *u, const double *v, const double *porosity, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source, double *dmom_u_source_u, double *dmom_u_source_v, double *dmom_v_source_u, double *dmom_v_source_v, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:8506
VOFCoefficientsEvaluate
void VOFCoefficientsEvaluate(int nPoints, int nSpace, double eps, double *v, double *phi, double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:1244
variablySaturatedGroundwaterTransportCoefficientsEvaluate_hetMat
void variablySaturatedGroundwaterTransportCoefficientsEvaluate_hetMat(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const double d, const int *materialTypes, const double *theta, const double *alpha_L_types, const double *alpha_T_types, const double *v, const double *u, double *m, double *dm, double *f, double *df, double *a)
Definition: transportCoefficients.c:468
conservativeHeadRichardsL2projBndMualemVanGenuchtenHomEvaluate
void conservativeHeadRichardsL2projBndMualemVanGenuchtenHomEvaluate(const int nElements, const int nElementBoundaries_element, const int nPointsPerElementBoundary, const int nSpace, const double rho, const double *gravity, const double alpha, const double n, const double m, const double thetaR, const double thetaSR, const double KWs, double *dV, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:5243
kEpsilon_2D_Evaluate_sd
void kEpsilon_2D_Evaluate_sd(int nPoints, int nSpace, double sigma_k, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *k, double *epsilon, double *m_k, double *dm_k, double *m_e, double *dm_e, double *phi_k, double *dphi_k, double *phi_e, double *dphi_e, double *f_k, double *df_k, double *f_e, double *df_e, double *a_k, double *da_k_dk, double *da_k_de, double *a_e, double *da_e_dk, double *da_e_de, double *r_k, double *dr_k_dk, double *dr_k_de, double *r_e, double *dr_e_dk, double *dr_e_de)
Definition: transportCoefficients.c:10090
VolumeAveragedVOFCoefficientsEvaluate
void VolumeAveragedVOFCoefficientsEvaluate(int nPoints, int nSpace, double eps, double *v, double *phi, double *porosity, double *u, double *m, double *dm, double *f, double *df)
Definition: transportCoefficients.c:9890
ReynoldsAveragedNavierStokes_kEpsilon_3D_Update_sd
void ReynoldsAveragedNavierStokes_kEpsilon_3D_Update_sd(const int nPoints, const double nu, const double c_mu, const double *k, const double *grad_k, const double *epsilon, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_uv_diff_ten, double *mom_uw_diff_ten, double *mom_vu_diff_ten, double *mom_vw_diff_ten, double *mom_wu_diff_ten, double *mom_wv_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source)
Definition: transportCoefficients.c:10996
kEpsilon_epsilon_3D_Evaluate_sd
void kEpsilon_epsilon_3D_Evaluate_sd(int nPoints, int nSpace, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *gradw, double *k, double *epsilon, double *m_e, double *dm_e, double *phi_e, double *dphi_e, double *f_e, double *df_e, double *a_e, double *da_e_de, double *r_e, double *dr_e_de)
Definition: transportCoefficients.c:10686
pd
#define pd(x)
Definition: jf.h:24
linearDirac
double linearDirac(double eps, double phi)
Definition: transportCoefficients.c:89
eikonalEquationEvaluate
void eikonalEquationEvaluate(int nPoints, int nSpace, double rhs, double *u, double *grad_u, double *m, double *dm, double *H, double *dH, double *r)
Definition: transportCoefficients.c:1354
groundwaterTransportCoefficientsEvaluate_hetMat
void groundwaterTransportCoefficientsEvaluate_hetMat(const int nSimplex, const int nPointsPerSimplex, const int nSpace, const double d, const int *materialTypes, const double *omega_types, const double *alpha_L_types, const double *alpha_T_types, const double *v, const double *u, double *m, double *dm, double *f, double *df, double *a)
Definition: transportCoefficients.c:413
conservativeSatRichardsBrooksCoreyBurdineHomEvaluate
void conservativeSatRichardsBrooksCoreyBurdineHomEvaluate(const int nPoints, const int nSpace, const double rho, const double *gravity, const double lambda, const double pd, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:6798
conservativeHeadRichardsBrooksCoreyBurdineHomEvaluate
void conservativeHeadRichardsBrooksCoreyBurdineHomEvaluate(const int nPoints, const int nSpace, const double rho, const double beta, const double *gravity, const double lambda, const double pd, const double thetaR, const double thetaSR, const double KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da)
Definition: transportCoefficients.c:6706
twophasePotentialFlowUpdateFreeSurface
void twophasePotentialFlowUpdateFreeSurface(int nPoints, int nSpace, double eps, double *u_levelSet, double M1, double M2, double *M, double *A1, double *A2, double *A, double *B1, double *B2, double *B, double *Bcon1, double *Bcon2, double *Bcon, double C1, double C2, double *C)
Definition: transportCoefficients.c:1073
MovingMesh_2D_Evaluate
void MovingMesh_2D_Evaluate(const int nPoints, const double E0, const double nu, const double *g, const double *det_J, const double *u, const double *v, double *uu_diff_ten, double *uv_diff_ten, double *vu_diff_ten, double *vv_diff_ten, double *u_force, double *v_force)
Definition: transportCoefficients.c:8276
r
Double r
Definition: Headers.h:83
groundwaterTransportCoefficientsEvaluate
void groundwaterTransportCoefficientsEvaluate(const int nPoints, const int nSpace, const double omega, const double d, const double alpha_L, const double alpha_T, const double *v, const double *u, double *m, double *dm, double *f, double *df, double *a)
Definition: transportCoefficients.c:140
burgersDiagonalVelHJEvaluate
void burgersDiagonalVelHJEvaluate(const int nPoints, const int nSpace, const double self_a, const double *self_v, const double *u, const double *grad_u, double *m, double *dm, double *H, double *dH, double *a, double *phi, double *dphi)
Definition: transportCoefficients.c:989
calculateEddyViscosity_Smagorinsky2P_2D
void calculateEddyViscosity_Smagorinsky2P_2D(const int nElements_global, const int nQuadraturePoints_element, const double smagorinskyConstant_0, const double smagorinskyConstant_1, const double eps, const double *phi_ls, const double *h_e, const double *grad_u, const double *grad_v, double *nu_t)
Definition: transportCoefficients.c:12165
ReynoldsAveragedNavierStokes_kEpsilon_2D_Update_sd
void ReynoldsAveragedNavierStokes_kEpsilon_2D_Update_sd(const int nPoints, const double rho, const double nu, const double c_mu, const double *k, const double *grad_k, const double *epsilon, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten, double *mom_u_source, double *mom_v_source)
Definition: transportCoefficients.c:10890
nonlinearADR_pqrstDualEvaluate
void nonlinearADR_pqrstDualEvaluate(const int nPoints, const int nSpace, const double M, const double *A, const double *B, const double C, const double p1, const double q1, const double r1, const double s1, const double t1, const double p2, const double q2, const double r2, const double s2, const double t2, const double t, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi, double *r, double *dr)
Definition: transportCoefficients.c:664
l2projectScalar
void l2projectScalar(const int nSimplices, const int nPointsPerSimplex, double *dV, double *r)
Definition: transportCoefficients.c:5651
smoothedHeaviside_integral
double smoothedHeaviside_integral(double eps, double phi)
Definition: transportCoefficients.c:47
eddyViscosity_2D_Update_sd
void eddyViscosity_2D_Update_sd(const int nPoints, const double *nu_t, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_uv_diff_ten, double *mom_vu_diff_ten)
Definition: transportCoefficients.c:12340
disVelEvaluate
void disVelEvaluate(const int nPoints, const int nSpace, const double self_a, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:908
setWeakDirichletConditionsForLevelSet
void setWeakDirichletConditionsForLevelSet(int nElements_global, int nDOF_trial_element, double epsilon_freeze_factor, const double *elementDiameter, const int *u_l2g, const double *u_dof, int *freeze_nodes_tmp, int *weakDirichletConditionFlags)
Definition: transportCoefficients.c:1620
TwophaseStokes_VOF_SO_2D_Evaluate
void TwophaseStokes_VOF_SO_2D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *vof, const double *p, const double *grad_p, const double *u, const double *v, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p)
Definition: transportCoefficients.c:4546
rho_0
double rho_0
Definition: ErrorResidualMethod.cpp:22
disRotatingPulseVelEvaluate
void disRotatingPulseVelEvaluate(const int nPoints, const int nSpace, const double self_a, const double *x, const double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi)
Definition: transportCoefficients.c:859
groundwaterBiodegradation01EvaluateFC
void groundwaterBiodegradation01EvaluateFC(const int nPoints, const int nSpace, const double omega, const double d_c, const double d_e, const double alpha_L, const double alpha_T, const double Kox_max, const double Kox_C, const double Kox_E, const double Kox_X, const double Yield, const double k_d, const double *v, const double *c_c, const double *c_e, const double *c_x, double *m_c, double *dm_c, double *m_e, double *dm_e, double *m_x, double *dm_x, double *f_c, double *df_c, double *f_e, double *df_e, double *a_c, double *a_e, double *r_c, double *dr_c_dc, double *dr_c_de, double *dr_c_dx, double *r_e, double *dr_e_dc, double *dr_e_de, double *dr_e_dx, double *r_x, double *dr_x_dc, double *dr_x_de, double *dr_x_dx)
Definition: transportCoefficients.c:187
constantNormalVelocityLevelSetEvaluate
void constantNormalVelocityLevelSetEvaluate(const int nPoints, const int nSpace, double b, const double *x, const double *u, const double *gradu, double *m, double *dm, double *f, double *df, double *H, double *dH)
Definition: transportCoefficients.c:4776
TwophaseNavierStokes_VOF_SO_3D_Evaluate
void TwophaseNavierStokes_VOF_SO_3D_Evaluate(const int nPoints, const double eps, const double rho_0, const double nu_0, const double rho_1, const double nu_1, const double *g, const double *vof, const double *p, const double *grad_p, const double *u, const double *v, const double *w, double *mom_u_acc, double *dmom_u_acc_u, double *mom_v_acc, double *dmom_v_acc_v, double *mom_w_acc, double *dmom_w_acc_w, double *mass_adv, double *dmass_adv_u, double *dmass_adv_v, double *dmass_adv_w, double *mom_u_adv, double *dmom_u_adv_u, double *dmom_u_adv_v, double *dmom_u_adv_w, double *mom_v_adv, double *dmom_v_adv_u, double *dmom_v_adv_v, double *dmom_v_adv_w, double *mom_w_adv, double *dmom_w_adv_u, double *dmom_w_adv_v, double *dmom_w_adv_w, double *mom_u_diff_ten, double *mom_v_diff_ten, double *mom_w_diff_ten, double *mom_u_source, double *mom_v_source, double *mom_w_source, double *mom_u_ham, double *dmom_u_ham_grad_p, double *mom_v_ham, double *dmom_v_ham_grad_p, double *mom_w_ham, double *dmom_w_ham_grad_p)
Definition: transportCoefficients.c:4398
unitSquareRotationLevelSetEvaluate
void unitSquareRotationLevelSetEvaluate(const int nPoints, const int nSpace, double t, const double *x, const double *u, const double *gradu, double *m, double *dm, double *f, double *df, double *H, double *dH)
Definition: transportCoefficients.c:4848
calculateEddyViscosity_Smagorinsky_2D
void calculateEddyViscosity_Smagorinsky_2D(const int nElements_global, const int nQuadraturePoints_element, const double smagorinskyConstant, const double *h_e, const double *grad_u, const double *grad_v, double *nu_t)
Definition: transportCoefficients.c:12036
setSimpleWeakDirichletConditionsForLevelSet
void setSimpleWeakDirichletConditionsForLevelSet(int nElements_global, int nDOF_trial_element, double epsilon_freeze_factor, const double *elementDiameter, const int *u_l2g, const double *u_dof, int *freeze_nodes_tmp, int *weakDirichletConditionFlags)
Definition: transportCoefficients.c:1672
twophaseSignedDistanceCoefficientsEvaluate
void twophaseSignedDistanceCoefficientsEvaluate(int nPoints, int nSpace, double *S, double *u, double *grad_u, double *m, double *dm, double *h, double *dh, double *rh)
Definition: transportCoefficients.c:1325
conservativeHeadRichardsMualemVanGenuchten_sd_het_linearized_at_saturation
void conservativeHeadRichardsMualemVanGenuchten_sd_het_linearized_at_saturation(const int nSimplex, const int nPointsPerSimplex, const int nSpace, double linear_break, const int *rowptr, const int *colind, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n, const double *thetaR, const double *thetaSR, const double *KWs, double *u, double *mass, double *dmass, double *f, double *df, double *a, double *da, double *vol_frac)
Definition: transportCoefficients.c:5847
nnz
#define nnz
Definition: Richards.h:9
levelSetCurvatureCoefficientsEvaluate
void levelSetCurvatureCoefficientsEvaluate(int nPoints, int nSpace, double *grad_phi, double *u, double *f, double *r, double *dr)
Definition: transportCoefficients.c:1270
twophaseLevelSetCoefficientsEvaluateCI
void twophaseLevelSetCoefficientsEvaluateCI(int nPoints, int nSpace, double *B, double t, double *x, double *u, double *m, double *dm, double *f, double *df, double *a, double *da, double *phi, double *dphi, double *r, double *dr)
Definition: transportCoefficients.c:1173
unitSquareVortexLevelSetEvaluate
void unitSquareVortexLevelSetEvaluate(const int nPoints, const int nSpace, double t, const double *x, const double *u, const double *gradu, double *m, double *dm, double *f, double *df, double *H, double *dH)
Definition: transportCoefficients.c:4812
kEpsilon_3D_Evaluate_sd
void kEpsilon_3D_Evaluate_sd(int nPoints, int nSpace, double sigma_k, double sigma_e, double c_1, double c_2, double c_mu, double c_e, double nu, double *velocity, double *gradu, double *gradv, double *gradw, double *k, double *epsilon, double *m_k, double *dm_k, double *m_e, double *dm_e, double *phi_k, double *dphi_k, double *phi_e, double *dphi_e, double *f_k, double *df_k, double *f_e, double *df_e, double *a_k, double *da_k_dk, double *da_k_de, double *a_e, double *da_e_dk, double *da_e_de, double *r_k, double *dr_k_dk, double *dr_k_de, double *r_e, double *dr_e_dk, double *dr_e_de)
Definition: transportCoefficients.c:10205
Mass_2D_Evaluate
void Mass_2D_Evaluate(const int nPoints, double rho, double *p, double *u, double *v, double *mom_p_acc, double *mom_u_acc, double *mom_v_acc, double *dmom_p_acc_p, double *dmom_u_acc_u, double *dmom_v_acc_v)
Definition: transportCoefficients.c:12626