20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEKERNEL_IMPL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEKERNEL_IMPL_HPP
27 namespace isothermalCompositionalMultiphaseFVMKernels
30 template<
typename FLUIDWRAPPER,
typename POLICY,
integer NUM_COMP,
integer NUM_DOF >
36 FLUIDWRAPPER
const & fluidWrapper,
37 DofNumberAccessor
const & dofNumberAccessor,
45 BitFlags< KernelFlags > kernelFlags )
53 permeabilityAccessors,
58 m_facePres( faceManager.getField< fields::flow::facePressure >() ),
59 m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ),
60 m_faceCompFrac( faceManager.getField< fields::flow::faceGlobalCompFraction >() ),
61 m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ),
62 m_fluidWrapper( fluidWrapper )
65 template<
typename FLUIDWRAPPER,
typename POLICY,
integer NUM_COMP,
integer NUM_DOF >
69 this->
template launch< POLICY >( numConnections, *
this );
72 template<
typename FLUIDWRAPPER,
typename POLICY,
integer NUM_COMP,
integer NUM_DOF >
81 for(
integer jdof = 0; jdof < numDof; ++jdof )
87 template<
typename FLUIDWRAPPER,
typename POLICY,
integer NUM_COMP,
integer NUM_DOF >
88 template<
typename FUNC >
93 FUNC && compFluxKernelOp )
const
95 using Deriv = constitutive::multifluid::DerivativeOffset;
98 localIndex const er = m_seri( iconn, Order::ELEM );
99 localIndex const esr = m_sesri( iconn, Order::ELEM );
100 localIndex const ei = m_sei( iconn, Order::ELEM );
101 localIndex const kf = m_sei( iconn, Order::FACE );
106 m_stencilWrapper.computeWeights( iconn,
108 stack.transmissibility,
110 real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] );
122 StackArray<
real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES * NUM_COMP,
123 constitutive::multifluid::LAYOUT_PHASE_COMP > facePhaseCompFrac( 1, 1, m_numPhases, NUM_COMP );
124 real64 faceTotalDens = 0.0;
126 constitutive::MultiFluidBase::KernelWrapper::computeValues( m_fluidWrapper,
132 facePhaseMassDens[0][0],
134 facePhaseEnthalpy[0][0],
135 facePhaseInternalEnergy[0][0],
136 facePhaseCompFrac[0][0],
141 for(
integer ip = 0; ip < m_numPhases; ++ip )
145 real64 dDensMean_dC[numComp]{};
147 real64 dProp_dC[numComp]{};
150 real64 dPhaseFlux_dP = 0.0;
151 real64 dPhaseFlux_dC[numComp]{};
156 applyChainRule( numComp,
157 m_dCompFrac_dCompDens[er][esr][ei],
158 m_dPhaseMassDens[er][esr][ei][0][ip],
163 real64 const densMean = 0.5 * ( m_phaseMassDens[er][esr][ei][0][ip] + facePhaseMassDens[0][0][ip] );
164 real64 const dDensMean_dP = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP];
165 for(
integer jc = 0; jc < numComp; ++jc )
167 dDensMean_dC[jc] = 0.5 * dProp_dC[jc];
173 real64 const gravTimesDz = m_gravCoef[er][esr][ei] - m_faceGravCoef[kf];
174 real64 const potDif = m_pres[er][esr][ei] - m_facePres[kf] - densMean * gravTimesDz;
175 real64 const f = stack.transmissibility * potDif;
176 real64 const dF_dP = stack.transmissibility * ( 1.0 - dDensMean_dP * gravTimesDz ) + dTrans_dPres * potDif;
177 for(
integer jc = 0; jc < numComp; ++jc )
179 dF_dC[jc] = -stack.transmissibility * dDensMean_dC[jc] * gravTimesDz;
195 real64 const facePhaseMob = ( facePhaseFrac[0][0][ip] > 0.0 )
196 ? facePhaseFrac[0][0][ip] * faceTotalDens / facePhaseVisc[0][0][ip]
207 phaseFlux = m_phaseMob[er][esr][ei][ip] * f;
208 dPhaseFlux_dP = m_phaseMob[er][esr][ei][ip] * dF_dP + m_dPhaseMob[er][esr][ei][ip][Deriv::dP] * f;
209 for(
integer jc = 0; jc < numComp; ++jc )
212 m_phaseMob[er][esr][ei][ip] * dF_dC[jc] + m_dPhaseMob[er][esr][ei][ip][Deriv::dC+jc] * f;
216 arraySlice1d<
real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub =
217 m_phaseCompFrac[er][esr][ei][0][ip];
218 arraySlice2d<
real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub =
219 m_dPhaseCompFrac[er][esr][ei][0][ip];
222 for(
integer ic = 0; ic < numComp; ++ic )
224 real64 const ycp = phaseCompFracSub[ic];
225 stack.
compFlux[ic] += phaseFlux * ycp;
226 stack.
dCompFlux_dP[ic] += dPhaseFlux_dP * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dP];
228 applyChainRule( numComp,
229 m_dCompFrac_dCompDens[er][esr][ei],
230 dPhaseCompFracSub[ic],
233 for(
integer jc = 0; jc < numComp; ++jc )
235 stack.
dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp + phaseFlux * dProp_dC[jc];
245 phaseFlux = facePhaseMob * f;
246 dPhaseFlux_dP = facePhaseMob * dF_dP;
247 for(
integer jc = 0; jc < numComp; ++jc )
249 dPhaseFlux_dC[jc] = facePhaseMob * dF_dC[jc];
253 for(
integer ic = 0; ic < numComp; ++ic )
255 real64 const ycp = facePhaseCompFrac[0][0][ip][ic];
256 stack.
compFlux[ic] += phaseFlux * ycp;
258 for(
integer jc = 0; jc < numComp; ++jc )
267 compFluxKernelOp( ip, er, esr, ei, kf, f,
268 facePhaseMob, facePhaseEnthalpy[0][0], facePhaseCompFrac[0][0],
269 phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC );
276 for(
integer ic = 0; ic < numComp; ++ic )
280 for(
integer jc = 0; jc < numComp; ++jc )
287 template<
typename FLUIDWRAPPER,
typename POLICY,
integer NUM_COMP,
integer NUM_DOF >
288 template<
typename FUNC >
293 FUNC && assemblyKernelOp )
const
295 using namespace compositionalMultiphaseUtilities;
298 if( AbstractBase::m_kernelFlags.isSet( KernelFlags::TotalMassEquation ) )
302 shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.
localFluxJacobian, work );
303 shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.
localFlux );
309 if( m_ghostRank[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] < 0 )
311 globalIndex const globalRow = m_dofNumber[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )];
312 localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset );
314 GEOS_ASSERT_GT( AbstractBase::m_localMatrix.numRows(), localRow + numComp );
316 for(
integer ic = 0; ic < numComp; ++ic )
318 RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + ic], stack.
localFlux[ic] );
319 AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >
327 assemblyKernelOp( localRow );
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
#define GEOS_ASSERT_GE(lhs, rhs)
Assert that one value compares greater than or equal to the other in debug builds.
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
A struct to automatically construct and store element view accessors.
A struct to automatically construct and store element view accessors.
GEOS_HOST_DEVICE void computeFlux(localIndex const iconn, StackVariables &stack, FUNC &&compFluxKernelOp=NoOpFunc{}) const
Compute the local Dirichlet face flux contributions to the residual and Jacobian.
GEOS_HOST_DEVICE void complete(localIndex const iconn, StackVariables &stack, FUNC &&assemblyKernelOp=NoOpFunc{}) const
Performs the complete phase for the kernel.
DirichletFluxComputeKernel(integer const numPhases, globalIndex const rankOffset, FaceManager const &faceManager, BoundaryStencilWrapper const &stencilWrapper, FLUIDWRAPPER const &fluidWrapper, DofNumberAccessor const &dofNumberAccessor, CompFlowAccessors const &compFlowAccessors, MultiFluidAccessors const &multiFluidAccessors, CapPressureAccessors const &capPressureAccessors, PermeabilityAccessors const &permeabilityAccessors, real64 const dt, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs, BitFlags< KernelFlags > kernelFlags)
Constructor for the kernel interface.
void launchKernel(localIndex const numConnections)
Launch the kernel for a given number of connections.
GEOS_HOST_DEVICE void setup(localIndex const iconn, StackVariables &stack) const
Performs the setup phase for the kernel.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
LvArray::StackArray< T, NDIM, PERMUTATION, localIndex, MAXSIZE > StackArray
Multidimensional stack-based array type. See LvArray:StackArray for details.
ArraySlice< T, 2, USD > arraySlice2d
Alias for 2D array slice.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
int integer
Signed integer type.
Defines the order of element/face in the stencil.
static constexpr localIndex ELEM
Order of element index in stencil.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
real64 dCompFlux_dC[numComp][numComp]
Derivatives of component fluxes wrt component densities.
real64 compFlux[numComp]
Component fluxes.
real64 localFlux[numEqn]
Storage for the face local residual vector.
real64 localFluxJacobian[numEqn][numDof]
Storage for the face local Jacobian matrix.
globalIndex dofColIndices[numDof]
Indices of the matrix rows/columns corresponding to the dofs in this face.
real64 dCompFlux_dP[numComp]
Derivatives of component fluxes wrt pressure.