20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRAD_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRAD_HPP
25 #include "constitutive/fluid/multifluid/Layouts.hpp"
26 #include "constitutive/capillaryPressure/layouts.hpp"
33 namespace isothermalCompositionalMultiphaseFVMKernelUtilities
36 template<
typename VIEWTYPE >
37 using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >;
39 using Deriv = constitutive::multifluid::DerivativeOffset;
43 template<
integer numComp,
integer numFluxSupportPo
ints >
49 integer const checkPhasePresenceInGravity,
50 localIndex const ( &seri )[numFluxSupportPoints],
51 localIndex const ( &sesri )[numFluxSupportPoints],
52 localIndex const ( &sei )[numFluxSupportPoints],
53 real64 const ( &trans )[numFluxSupportPoints],
54 real64 const ( &dTrans_dPres )[numFluxSupportPoints],
66 real64 ( & dPresGrad_dP )[numFluxSupportPoints],
67 real64 ( & dPresGrad_dC )[numFluxSupportPoints][numComp],
68 real64 ( & dGravHead_dP )[numFluxSupportPoints],
69 real64 ( & dGravHead_dC )[numFluxSupportPoints][numComp] )
72 for(
integer i = 0; i < numFluxSupportPoints; ++i )
74 dPresGrad_dP[i] = 0.0;
75 dGravHead_dP[i] = 0.0;
76 for(
integer jc = 0; jc < numComp; ++jc )
78 dPresGrad_dC[i][jc] = 0.0;
79 dGravHead_dC[i][jc] = 0.0;
85 real64 dDensMean_dP[numFluxSupportPoints]{};
86 real64 dDensMean_dC[numFluxSupportPoints][numComp]{};
89 real64 dPresGrad_dTrans = 0.0;
91 real64 dGravHead_dTrans = 0.0;
92 real64 dCapPressure_dC[numComp]{};
94 calculateMeanDensity( checkPhasePresenceInGravity, ip,
96 phaseVolFrac, dCompFrac_dCompDens,
97 phaseMassDens, dPhaseMassDens,
98 densMean, dDensMean_dP, dDensMean_dC );
101 for(
integer i = 0; i < numFluxSupportPoints; i++ )
109 real64 dCapPressure_dP = 0.0;
111 for(
integer ic = 0; ic < numComp; ++ic )
113 dCapPressure_dC[ic] = 0.0;
118 capPressure = phaseCapPressure[er][esr][ei][0][ip];
120 for(
integer jp = 0; jp < numPhase; ++jp )
122 real64 const dCapPressure_dS = dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp];
123 dCapPressure_dP += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dP];
125 for(
integer jc = 0; jc < numComp; ++jc )
127 dCapPressure_dC[jc] += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dC+jc];
132 real64 const dP = pres[er][esr][ei] - capPressure;
133 presGrad += trans[i] * dP;
134 dPresGrad_dTrans += dP;
135 dPresGrad_dP[i] += trans[i] * (1 - dCapPressure_dP) + dTrans_dPres[i] * dP;
136 for(
integer jc = 0; jc < numComp; ++jc )
138 dPresGrad_dC[i][jc] += -trans[i] * dCapPressure_dC[jc];
141 real64 const gC = gravCoef[er][esr][ei];
142 real64 const gravD = trans[i] * gC;
143 real64 const dGravD_dTrans = gC;
144 real64 const dGravD_dP = dTrans_dPres[i] * gC;
149 gravHead += densMean * gravD;
150 dGravHead_dTrans += densMean * dGravD_dTrans;
152 for(
integer j = 0; j < numFluxSupportPoints; ++j )
154 dGravHead_dP[j] += dDensMean_dP[j] * gravD + dGravD_dP * densMean;
155 for(
integer jc = 0; jc < numComp; ++jc )
157 dGravHead_dC[j][jc] += dDensMean_dC[j][jc] * gravD;
163 potGrad = presGrad - gravHead;
164 dPotGrad_dTrans = dPresGrad_dTrans - dGravHead_dTrans;
167 template<
integer numComp,
integer numFluxSupportPo
ints >
170 calculateMeanDensity(
integer const checkPhasePresenceInGravity,
172 localIndex const ( &seri )[numFluxSupportPoints],
173 localIndex const ( &sesri )[numFluxSupportPoints],
174 localIndex const ( &sei )[numFluxSupportPoints],
179 real64 & densMean,
real64 ( & dDensMean_dP)[numFluxSupportPoints],
real64 ( & dDensMean_dC )[numFluxSupportPoints][numComp] )
181 real64 dDens_dC[numComp]{};
184 for(
integer i = 0; i < numFluxSupportPoints; ++i )
190 bool const phaseExists = (phaseVolFrac[er][esr][ei][ip] > 0);
191 if( checkPhasePresenceInGravity && !phaseExists )
197 real64 const density = phaseMassDens[er][esr][ei][0][ip];
198 real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP];
200 applyChainRule( numComp,
201 dCompFrac_dCompDens[er][esr][ei],
202 dPhaseMassDens[er][esr][ei][0][ip],
208 dDensMean_dP[i] = dDens_dP;
209 for(
integer jc = 0; jc < numComp; ++jc )
211 dDensMean_dC[i][jc] = dDens_dC[jc];
218 for(
integer i = 0; i < numFluxSupportPoints; ++i )
220 dDensMean_dP[i] /= denom;
221 for(
integer jc = 0; jc < numComp; ++jc )
223 dDensMean_dC[i][jc] /= denom;
#define GEOS_HOST_DEVICE
Marks a host-device function.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
std::int32_t integer
Signed integer type.
ArrayView< T, 4, USD > arrayView4d
Alias for 4D array view.
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
static GEOS_HOST_DEVICE void compute(integer const numPhase, integer const ip, integer const hasCapPressure, integer const checkPhasePresenceInGravity, localIndex const (&seri)[numFluxSupportPoints], localIndex const (&sesri)[numFluxSupportPoints], localIndex const (&sei)[numFluxSupportPoints], real64 const (&trans)[numFluxSupportPoints], real64 const (&dTrans_dPres)[numFluxSupportPoints], ElementViewConst< arrayView1d< real64 const > > const &pres, ElementViewConst< arrayView1d< real64 const > > const &gravCoef, ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const &phaseVolFrac, ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const &dPhaseVolFrac, ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const &dCompFrac_dCompDens, ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const &phaseMassDens, ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const &dPhaseMassDens, ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const &phaseCapPressure, ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const &dPhaseCapPressure_dPhaseVolFrac, real64 &potGrad, real64 &dPotGrad_dTrans, real64(&dPresGrad_dP)[numFluxSupportPoints], real64(&dPresGrad_dC)[numFluxSupportPoints][numComp], real64(&dGravHead_dP)[numFluxSupportPoints], real64(&dGravHead_dC)[numFluxSupportPoints][numComp])