1 #ifndef TWOPHASEDARCYCOEFFICIENTS_H
2 #define TWOPHASEDARCYCOEFFICIENTS_H
11 template<
class PSK,
class DENSITY_W,
class DENSITY_N>
13 int nPointsPerSimplex,
18 const int* materialTypes,
24 const double* rwork_psk,
const int* iwork_psk,
25 const double* rwork_psk_tol,
26 const double* rwork_density_w,
27 const double* rwork_density_n,
42 double* dphi_psiw_dpsiw,
44 double* dphi_psin_dpsiw,
45 double* dphi_psin_dsw,
54 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
55 DENSITY_W density_w(rwork_density_w);
56 DENSITY_N density_n(rwork_density_n);
57 double drhow_dsw,drhon_dsw,drhow_dpsiw,drhon_dpsiw;
59 const int nnz = rowptr[nSpace];
60 for (
int eN=0;eN<nSimplex;eN++)
62 matID = materialTypes[eN];
63 psk.setParams(&rwork_psk[matID*nParams]);
64 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
66 i = eN*nPointsPerSimplex+pN;
69 psin[i] = psiw[i] + psk.psic;
70 dpsin_dsw[i] = psk.dpsic;
74 density_w.calc(psiw[i]);
75 density_n.calc(psin[i]);
77 drhow_dpsiw = density_w.drho;
80 drhon_dpsiw = density_n.drho;
81 drhon_dsw = density_n.drho*psk.dpsic;
84 mw[i] = omega[matID]*density_w.rho*sw[i];
85 dmw_dsw[i] = omega[matID]*(density_w.rho + sw[i]*drhow_dsw);
86 dmw_dpsiw[i]= omega[matID]*sw[i]*drhow_dpsiw;
89 mn[i] = omega[matID]*density_n.rho*(1.0-sw[i]);
90 dmn_dsw[i] = omega[matID]*((1.0-sw[i])*drhon_dsw -density_n.rho);
91 dmn_dpsiw[i]= omega[matID]*(1.0-sw[i])*drhon_dpsiw;
94 phi_psiw[i] = psiw[i];
95 dphi_psiw_dpsiw[i] = 1.0;
98 phi_psin[i] = psiw[i] + psk.psic;
99 dphi_psin_dpsiw[i]= 1.0;
100 dphi_psin_dsw[i]= psk.dpsic;
102 for (
int I=0;I<nSpace;I++)
106 phi_psiw[i] -= g[I]*x[i*3+I];
108 phi_psin[i] -= b*g[I]*x[i*3+I];
110 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
114 aw[i*
nnz+m] = density_w.rho*Kbar[matID*
nnz+m]*psk.krw/muw;
115 daw_dsw[i*
nnz+m] = density_w.rho*Kbar[matID*
nnz+m]*psk.dkrw/muw + drhow_dsw*Kbar[matID*
nnz+m]*psk.krw/muw;
116 daw_dpsiw[i*
nnz+m]= drhow_dpsiw*Kbar[matID*
nnz+m]*psk.krw/muw;
119 an[i*
nnz+m] = density_n.rho*Kbar[matID*
nnz+m]*psk.krn/mun;
120 dan_dsw[i*
nnz+m] = density_n.rho*Kbar[matID*
nnz+m]*psk.dkrn/mun + drhon_dsw*Kbar[matID*
nnz+m]*psk.krn/mun;
121 dan_dpsiw[i*
nnz+m] = drhon_dpsiw*Kbar[matID*
nnz+m]*psk.krn/mun;
128 template<
class PSK,
class DENSITY_W,
class DENSITY_N>
131 int nPointsPerSimplex,
136 const int* materialTypes,
142 const double* rwork_psk,
const int* iwork_psk,
143 const double* rwork_psk_tol,
144 const double* rwork_density_w,
145 const double* rwork_density_n,
160 double* dphi_psiw_dpsiw,
162 double* dphi_psin_dpsiw,
163 double* dphi_psin_dsw,
178 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
179 DENSITY_W density_w(rwork_density_w);
180 DENSITY_N density_n(rwork_density_n);
181 double drhow_dsw,drhon_dsw,drhow_dpsiw,drhon_dpsiw;
182 double rhow_x,drhow_x_dsw,drhow_x_dpsiw,rhon_x,drhon_x_dsw,drhon_x_dpsiw;
184 const int nnz = rowptr[nSpace];
185 for (
int eN=0;eN<nSimplex;eN++)
187 matID = materialTypes[eN];
188 psk.setParams(&rwork_psk[matID*nParams]);
189 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
191 i = eN*nPointsPerSimplex+pN;
194 psin[i] = psiw[i] + psk.psic;
195 dpsin_dsw[i] = psk.dpsic;
199 density_w.calc(psiw[i]);
200 density_n.calc(psin[i]);
202 drhow_dpsiw = density_w.drho;
205 drhon_dpsiw = density_n.drho;
206 drhon_dsw = density_n.drho*psk.dpsic;
209 mw[i] = omega[matID]*density_w.rho*sw[i];
210 dmw_dsw[i] = omega[matID]*(density_w.rho + sw[i]*drhow_dsw);
211 dmw_dpsiw[i]= omega[matID]*sw[i]*drhow_dpsiw;
214 mn[i] = omega[matID]*density_n.rho*(1.0-sw[i]);
215 dmn_dsw[i] = omega[matID]*((1.0-sw[i])*drhon_dsw -density_n.rho);
216 dmn_dpsiw[i]= omega[matID]*(1.0-sw[i])*drhon_dpsiw;
219 phi_psiw[i] = psiw[i];
220 dphi_psiw_dpsiw[i] = 1.0;
223 phi_psin[i] = psiw[i] + psk.psic;
224 dphi_psin_dpsiw[i]= 1.0;
225 dphi_psin_dsw[i]= psk.dpsic;
227 rhow_x = density_w.rho;
228 drhow_x_dsw = drhow_dsw;
229 drhow_x_dpsiw= drhow_dpsiw;
230 rhon_x = density_n.rho;
231 drhon_x_dsw = drhon_dsw;
232 drhon_x_dpsiw= drhon_dpsiw;
233 if (compressibilityFlag == 0)
243 for (
int I=0;I<nSpace;I++)
245 fw[i*nSpace+I] = 0.0;
246 dfw_dsw[i*nSpace+I] = 0.0;
247 dfw_dpsiw[i*nSpace+I]= 0.0;
249 fn[i*nSpace+I] = 0.0;
250 dfn_dsw[i*nSpace+I] = 0.0;
251 dfn_dpsiw[i*nSpace+I]= 0.0;
253 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
257 fw[i*nSpace+I] += rhow_x*rhow_x*Kbar[matID*
nnz+m]*psk.krw/muw*g[colind[m]];
258 dfw_dsw[i*nSpace+I] += rhow_x*rhow_x*Kbar[matID*
nnz+m]*psk.dkrw/muw*g[colind[m]] + 2.0*rhow_x*drhow_x_dsw*Kbar[matID*
nnz+m]*psk.krw/muw*g[colind[m]];
259 dfw_dpsiw[i*nSpace+I] += 2.0*rhow_x*drhow_x_dpsiw*Kbar[matID*
nnz+m]*psk.krw/muw*g[colind[m]];
261 fn[i*nSpace+I] += rhon_x*rhon_x*Kbar[matID*
nnz+m]*psk.krn/mun*b*g[colind[m]];
262 dfn_dsw[i*nSpace+I] += rhon_x*rhon_x*Kbar[matID*
nnz+m]*psk.dkrn/mun*b*g[colind[m]] + 2.0*rhon_x*drhon_x_dsw*Kbar[matID*
nnz+m]*psk.krn/mun*b*g[colind[m]];
263 dfn_dpsiw[i*nSpace+I] += 2.0*rhon_x*drhon_x_dpsiw*Kbar[matID*
nnz+m]*psk.krn/mun*b*g[colind[m]];
266 aw[i*
nnz+m] = rhow_x*Kbar[matID*
nnz+m]*psk.krw/muw;
267 daw_dsw[i*
nnz+m] = rhow_x*Kbar[matID*
nnz+m]*psk.dkrw/muw + drhow_x_dsw*Kbar[matID*
nnz+m]*psk.krw/muw;
268 daw_dpsiw[i*
nnz+m]= drhow_x_dpsiw*Kbar[matID*
nnz+m]*psk.krw/muw;
271 an[i*
nnz+m] = rhon_x*Kbar[matID*
nnz+m]*psk.krn/mun;
272 dan_dsw[i*
nnz+m] = rhon_x*Kbar[matID*
nnz+m]*psk.dkrn/mun + drhon_x_dsw*Kbar[matID*
nnz+m]*psk.krn/mun;
273 dan_dpsiw[i*
nnz+m] = drhon_x_dpsiw*Kbar[matID*
nnz+m]*psk.krn/mun;
294 int nPointsPerSimplex,
295 const int* materialTypes,
302 for (
int eN=0; eN < nSimplex; eN++)
304 matID = materialTypes[eN];
305 for (
int pN=0,i;pN<nPointsPerSimplex;pN++)
307 i = eN*nPointsPerSimplex+pN;
308 vol_frac_w[i] = omega[matID]*sw[i];
309 vol_frac_n[i] = omega[matID]*(1.0-sw[i]);
322 template<
class PSK,
class DENSITY_W,
class DENSITY_N>
324 int nPointsPerSimplex,
329 const int* materialTypes,
335 const double* rwork_psk,
const int* iwork_psk,
336 const double* rwork_psk_tol,
337 const double* rwork_density_w,
338 const double* rwork_density_n,
351 double* dphi_psiw_dpsiw,
353 double* dphi_psin_dpsiw,
354 double* dphi_psin_dpsic,
363 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
364 DENSITY_W density_w(rwork_density_w);
365 DENSITY_N density_n(rwork_density_n);
366 double drhow_dpsiw,drhow_dpsic,drhon_dpsiw,drhon_dpsic,
367 swi,psin,dsw_dpsic,dpsin_dpsic;
368 const int nnz = rowptr[nSpace];
369 for (
int eN=0;eN<nSimplex;eN++)
371 matID = materialTypes[eN];
372 psk.setParams(&rwork_psk[matID*nParams]);
373 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
375 i = eN*nPointsPerSimplex+pN;
376 psk.calc_from_psic(psic[i]);
379 psin = psiw[i] + psic[i];
387 swi = psk.Se*(psk.Sw_max-psk.Sw_min) + psk.Sw_min;
389 dsw_dpsic = psk.dSe_dpsic/psk.dSe_dSw;
392 density_w.calc(psiw[i]);
393 density_n.calc(psin);
395 drhow_dpsiw = density_w.drho;
398 drhon_dpsiw = density_n.drho;
399 drhon_dpsic = density_n.drho;
403 mw[i] = omega[matID]*density_w.rho*swi;
404 dmw_dpsic[i]= omega[matID]*(density_w.rho*dsw_dpsic + swi*drhow_dpsic);
405 dmw_dpsiw[i]= omega[matID]*swi*drhow_dpsiw;
408 mn[i] = omega[matID]*density_n.rho*(1.0-swi);
409 dmn_dpsic[i]= omega[matID]*((1.0-swi)*drhon_dpsic -density_n.rho*dsw_dpsic);
410 dmn_dpsiw[i]= omega[matID]*(1.0-swi)*drhon_dpsiw;
413 phi_psiw[i] = psiw[i];
414 dphi_psiw_dpsiw[i] = 1.0;
418 dphi_psin_dpsiw[i]= 1.0;
419 dphi_psin_dpsic[i]= dpsin_dpsic;
421 for (
int I=0;I<nSpace;I++)
425 phi_psiw[i] -= g[I]*x[i*3+I];
427 phi_psin[i] -= b*g[I]*x[i*3+I];
429 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
433 aw[i*
nnz+m] = density_w.rho*Kbar[matID*
nnz+m]*psk.krw/muw;
434 daw_dpsic[i*
nnz+m]= density_w.rho*Kbar[matID*
nnz+m]*psk.dkrw/muw + drhow_dpsic*Kbar[matID*
nnz+m]*psk.krw/muw;
435 daw_dpsiw[i*
nnz+m]= drhow_dpsiw*Kbar[matID*
nnz+m]*psk.krw/muw;
438 an[i*
nnz+m] = density_n.rho*Kbar[matID*
nnz+m]*psk.krn/mun;
439 dan_dpsic[i*
nnz+m] = density_n.rho*Kbar[matID*
nnz+m]*psk.dkrn/mun + drhon_dpsic*Kbar[matID*
nnz+m]*psk.krn/mun;
440 dan_dpsiw[i*
nnz+m] = drhon_dpsiw*Kbar[matID*
nnz+m]*psk.krn/mun;
451 dmn_dpsic[i] = omega[matID]*density_n.rho;
452 dmw_dpsic[i] =-omega[matID]*density_n.rho;
455 dphi_psin_dpsiw[i]= 0.0;
456 dphi_psin_dpsic[i]= 0.0;
457 for (
int I=0;I<nSpace;I++)
459 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
462 dan_dpsic[i*
nnz+m] = 0.0;
463 dan_dpsiw[i*
nnz+m] = 0.0;
464 daw_dpsic[i*
nnz+m] = 0.0;
478 static inline int twophaseDarcy_incompressible_split_sd_saturation_het_matType(
int nSimplex,
479 int nPointsPerSimplex,
484 const int* materialTypes,
490 double capillaryDiffusionScaling,
491 double advectionScaling,
492 const double* rwork_psk,
const int* iwork_psk,
493 const double* rwork_psk_tol,
494 const double* rwork_density_w,
495 const double* rwork_density_n,
509 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
512 const int nnz = rowptr[nSpace];
519 for (
int eN=0;eN<nSimplex;eN++)
521 matID = materialTypes[eN];
522 psk.setParams(&rwork_psk[matID*nParams]);
523 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
525 i = eN*nPointsPerSimplex+pN;
527 fracFlow.calc(psk,density_w,density_n);
530 m[i] = omega[matID]*density_w.rho*sw[i];
531 dm[i] = omega[matID]*density_w.rho;
537 for (
int I=0;I<nSpace;I++)
541 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
543 const int J = colind[m];
546 f[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.fw
547 - Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn*(b*density_n.rho-density_w.rho)*g[I]) ;
548 df[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.dfw
549 - (Kbar[matID*
nnz+m]*g[I]*(b*density_n.rho-density_w.rho))*(fracFlow.lambdaw*fracFlow.dfn + fracFlow.fn*fracFlow.dlambdaw));
553 a[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn;
554 da[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*(fracFlow.dlambdaw*fracFlow.fn + fracFlow.lambdaw*fracFlow.dfn);
565 template<
class PSK,
class DENSITY_W>
566 static inline int twophaseDarcy_slightCompressible_split_sd_saturation_het_matType(
int nSimplex,
567 int nPointsPerSimplex,
572 const int* materialTypes,
578 double capillaryDiffusionScaling,
579 double advectionScaling,
580 const double* rwork_psk,
const int* iwork_psk,
581 const double* rwork_psk_tol,
582 const double* rwork_density_w,
583 const double* rwork_density_n,
598 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
603 const double rwork_density_w_x[1] = {1.0};
const double rwork_density_n_x[1] = {1.0};
604 ConstantDensity density_w_x(rwork_density_w_x),density_n_x(rwork_density_n_x);
606 DENSITY_W density_w(rwork_density_w);
607 const int nnz = rowptr[nSpace];
614 for (
int eN=0;eN<nSimplex;eN++)
616 matID = materialTypes[eN];
617 psk.setParams(&rwork_psk[matID*nParams]);
618 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
620 i = eN*nPointsPerSimplex+pN;
622 density_w.calc(psiw[i]);
623 fracFlow.calc(psk,density_w_x,density_n_x);
627 m[i] = omega[matID]*density_w.rho*sw[i];
629 dm[i] = omega[matID]*density_w.rho;
635 for (
int I=0;I<nSpace;I++)
639 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
641 const int J = colind[m];
644 f[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.fw
645 - Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn*(b*density_n_x.rho-density_w_x.rho)*g[I]) ;
646 df[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.dfw
647 - (Kbar[matID*
nnz+m]*g[I]*(b*density_n_x.rho-density_w_x.rho))*(fracFlow.lambdaw*fracFlow.dfn + fracFlow.fn*fracFlow.dlambdaw));
651 a[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn;
652 da[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*(fracFlow.dlambdaw*fracFlow.fn + fracFlow.lambdaw*fracFlow.dfn);
664 static inline int twophaseDarcy_incompressible_split_sd_pressure_het_matType(
int nSimplex,
665 int nPointsPerSimplex,
670 const int* materialTypes,
676 double capillaryDiffusionScaling,
677 const double* rwork_psk,
const int* iwork_psk,
678 const double* rwork_psk_tol,
679 const double* rwork_density_w,
680 const double* rwork_density_n,
683 const double* grad_psic,
688 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
691 const int nnz = rowptr[nSpace];
692 for (
int eN=0;eN<nSimplex;eN++)
694 matID = materialTypes[eN];
695 psk.setParams(&rwork_psk[matID*nParams]);
696 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
698 i = eN*nPointsPerSimplex+pN;
700 fracFlow.calc(psk,density_w,density_n);
702 for (
int I=0;I<nSpace;I++)
705 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
707 const int J = colind[m];
711 f[i*nSpace+I] = - capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdat*(fracFlow.fn*grad_psic[i*nSpace+I]) +
712 Kbar[matID*
nnz+m]*fracFlow.lambdat*(density_w.rho + fracFlow.fn*(b*density_n.rho-density_w.rho))*g[I];
716 a[i*
nnz+m] = Kbar[matID*
nnz+m]*fracFlow.lambdat;
727 template<
class PSK,
class DENSITY_W,
class DENSITY_N>
728 static inline int twophaseDarcy_slightCompressible_split_sd_pressure_het_matType(
int nSimplex,
729 int nPointsPerSimplex,
734 const int* materialTypes,
740 double capillaryDiffusionScaling,
741 const double* rwork_psk,
const int* iwork_psk,
742 const double* rwork_psk_tol,
743 const double* rwork_density_w,
744 const double* rwork_density_n,
749 const double* grad_psic,
756 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
761 const double rwork_density_w_x[1] = {1.0};
const double rwork_density_n_x[1] = {1.0};
762 ConstantDensity density_w_x(rwork_density_w_x),density_n_x(rwork_density_n_x);
763 DENSITY_W density_w(rwork_density_w);
764 DENSITY_N density_n(rwork_density_n);
765 const int nnz = rowptr[nSpace];
766 double drhow_dpsiw,drhon_dpsiw;
767 for (
int eN=0;eN<nSimplex;eN++)
769 matID = materialTypes[eN];
770 psk.setParams(&rwork_psk[matID*nParams]);
771 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
773 i = eN*nPointsPerSimplex+pN;
775 density_w.calc(psiw[i]);
776 density_n.calc(psin[i]);
778 fracFlow.calc(psk,density_w_x,density_n_x);
781 drhow_dpsiw = density_w.drho;
783 drhon_dpsiw = density_n.drho;
787 m[i] = omega[matID]*density_w.rho*sw[i] + omega[matID]*density_n.rho*(1.0-sw[i]);
788 dm[i]= omega[matID]*drhow_dpsiw*sw[i] + omega[matID]*drhon_dpsiw*(1.0-sw[i]);
790 for (
int I=0;I<nSpace;I++)
793 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
795 const int J = colind[m];
798 f[i*nSpace+I] = - capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdat*(fracFlow.fn*grad_psic[i*nSpace+I]) +
799 Kbar[matID*
nnz+m]*fracFlow.lambdat*(density_w_x.rho + fracFlow.fn*(b*density_n_x.rho-density_w_x.rho))*g[I];
801 a[i*
nnz+m] = Kbar[matID*
nnz+m]*fracFlow.lambdat;
812 template<
class PSK,
class DENSITY_N>
813 static inline int twophaseDarcy_compressibleN_split_sd_saturation_het_matType(
int nSimplex,
814 int nPointsPerSimplex,
819 const int* materialTypes,
825 double capillaryDiffusionScaling,
826 double advectionScaling,
827 const double* rwork_psk,
const int* iwork_psk,
828 const double* rwork_psk_tol,
829 const double* rwork_density_w,
830 const double* rwork_density_n,
845 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
848 DENSITY_N density_n(rwork_density_n);
849 const int nnz = rowptr[nSpace];
857 for (
int eN=0;eN<nSimplex;eN++)
859 matID = materialTypes[eN];
860 psk.setParams(&rwork_psk[matID*nParams]);
861 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
863 i = eN*nPointsPerSimplex+pN;
866 psin = psiw[i] + psk.psic;
868 density_w.calc(psiw[i]);
869 density_n.calc(psin);
871 fracFlow.calc(psk,density_w,density_n);
875 m[i] = omega[matID]*density_w.rho*sw[i];
876 dm[i] = omega[matID]*density_w.rho;
882 for (
int I=0;I<nSpace;I++)
885 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
887 const int J = colind[m];
890 f[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.fw
891 - Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn*(b*density_n.rho-density_w.rho)*g[I]) ;
892 df[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.dfw
893 - (Kbar[matID*
nnz+m]*g[I]*(b*density_n.rho-density_w.rho))*(fracFlow.lambdaw*fracFlow.dfn + fracFlow.fn*fracFlow.dlambdaw));
897 a[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn;
898 da[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*(fracFlow.dlambdaw*fracFlow.fn + fracFlow.lambdaw*fracFlow.dfn);
909 template<
class PSK,
class DENSITY_N>
910 static inline int twophaseDarcy_compressibleN_split_sd_pressure_het_matType(
int nSimplex,
911 int nPointsPerSimplex,
916 const int* materialTypes,
922 double capillaryDiffusionScaling,
923 const double* rwork_psk,
const int* iwork_psk,
924 const double* rwork_psk_tol,
925 const double* rwork_density_w,
926 const double* rwork_density_n,
931 const double* grad_psic,
938 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
941 DENSITY_N density_n(rwork_density_n);
942 const int nnz = rowptr[nSpace];
944 for (
int eN=0;eN<nSimplex;eN++)
946 matID = materialTypes[eN];
947 psk.setParams(&rwork_psk[matID*nParams]);
948 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
950 i = eN*nPointsPerSimplex+pN;
952 density_w.calc(psiw[i]);
953 density_n.calc(psin[i]);
955 fracFlow.calc(psk,density_w,density_n);
958 drhon_dpsiw = density_n.drho;
962 m[i] = omega[matID]*density_w.rho*sw[i] + omega[matID]*density_n.rho*(1.0-sw[i]);
963 dm[i]= omega[matID]*drhon_dpsiw*(1.0-sw[i]);
965 for (
int I=0;I<nSpace;I++)
968 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
970 const int J = colind[m];
973 f[i*nSpace+I] = - capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdat*(fracFlow.fn*grad_psic[i*nSpace+I]) +
974 Kbar[matID*
nnz+m]*fracFlow.lambdat*(density_w.rho + fracFlow.fn*(b*density_n.rho-density_w.rho))*g[I];
976 a[i*
nnz+m] = Kbar[matID*
nnz+m]*fracFlow.lambdat;
985 static inline int twophaseDarcy_incompressible_split_pp_sd_saturation_het_matType(
int nSimplex,
986 int nPointsPerSimplex,
991 const int* materialTypes,
997 double capillaryDiffusionScaling,
998 double advectionScaling,
999 const double* rwork_psk,
const int* iwork_psk,
1000 const double* rwork_psk_tol,
1001 const double* rwork_density_w,
1002 const double* rwork_density_n,
1017 PSK psk(rwork_psk,iwork_psk); psk.setTolerances(rwork_psk_tol);
1019 ConstantDensity density_w(rwork_density_w),density_n(rwork_density_n);
1020 const int nnz = rowptr[nSpace];
1021 double psic_eval(0.),dpsic_eval(0.),dsw_du(0.);
1028 for (
int eN=0;eN<nSimplex;eN++)
1030 matID = materialTypes[eN];
1031 psk.setParams(&rwork_psk[matID*nParams]);
1032 for(
int pN=0,i;pN<nPointsPerSimplex;pN++)
1034 i = eN*nPointsPerSimplex+pN;
1041 dpsic_eval=psk.dpsic;
1045 psic_eval =
u[i]; dpsic_eval=1.0;
1046 psk.calc_from_psic(psic_eval);
1047 sw[i] = psk.Se*(psk.Sw_max-psk.Sw_min) + psk.Sw_min;
1048 dsw_du = psk.dSe_dpsic/psk.dSe_dSw;
1050 fracFlow.calc(psk,density_w,density_n);
1053 m[i] = omega[matID]*density_w.rho*sw[i];
1054 dm[i] = omega[matID]*density_w.rho*dsw_du;
1058 dphi[i]= dpsic_eval;
1060 for (
int I=0;I<nSpace;I++)
1064 for (
int m=rowptr[I]; m < rowptr[I+1]; m++)
1066 const int J = colind[m];
1069 f[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.fw
1070 - Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn*(b*density_n.rho-density_w.rho)*g[I]) ;
1071 df[i*nSpace+I] = advectionScaling*(qt[i*nSpace+I]*fracFlow.dfw
1072 - (Kbar[matID*
nnz+m]*g[I]*(b*density_n.rho-density_w.rho))*(fracFlow.lambdaw*fracFlow.dfn + fracFlow.fn*fracFlow.dlambdaw));
1076 a[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*fracFlow.lambdaw*fracFlow.fn;
1077 da[i*
nnz+m] = -capillaryDiffusionScaling*Kbar[matID*
nnz+m]*(fracFlow.dlambdaw*fracFlow.fn + fracFlow.lambdaw*fracFlow.dfn);
1090 template <
class PSK>
1094 const double* domain,
1095 const double* rwork_psk,
1096 const int* iwork_psk,
1097 const double* rwork_psk_tol,
1098 double* splineTable)
1100 PSK psk(rwork_psk,iwork_psk);
1101 psk.setTolerances(rwork_psk_tol);
1105 for (
int i=0; i < nknots; i++)
1107 double sw = domain[i];
1110 std::cout<<
"generate splineTable calcFlag=0 startIndex= "<<startIndex<<
" nknots= "<<nknots<<
" sw["<<i<<
"]= "<<sw<<
" psic= "<<psk.psic<<
" krw= "<<psk.krw<<
" krn= "<<psk.krn<<std::endl;
1111 splineTable[startIndex+i] =sw;
1112 splineTable[startIndex + nknots +i]=psk.psic;
1113 splineTable[startIndex + nknots*2+i]=psk.krw;
1114 splineTable[startIndex + nknots*3+i]=psk.krn;
1118 splineTable[startIndex + nknots] = splineTable[startIndex + nknots+1]+1.0;
1122 for (
int i=0; i < nknots; i++)
1124 double psic = domain[i];
1125 psk.calc_from_psic(psic);
1126 splineTable[startIndex+i] =psic;
1127 splineTable[startIndex + nknots +i]=psk.Se*(psk.Sw_max-psk.Sw_min) + psk.Sw_min;
1128 splineTable[startIndex + nknots*2+i]=psk.krw;
1129 splineTable[startIndex + nknots*3+i]=psk.krn;
1132 splineTable[startIndex + nknots] = splineTable[startIndex + nknots+1]*(1.0+1.e-8);
1134 splineTable[startIndex + nknots*2] = splineTable[startIndex + nknots*2+1];
1136 splineTable[startIndex + nknots*3] = splineTable[startIndex + nknots*3+1];