20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP
23 #include "codingUtilities/Utilities.hpp"
26 #include "common/GEOS_RAJA_Interface.hpp"
27 #include "constitutive/diffusion/DiffusionFields.hpp"
28 #include "constitutive/diffusion/DiffusionBase.hpp"
29 #include "constitutive/dispersion/DispersionFields.hpp"
30 #include "constitutive/dispersion/DispersionBase.hpp"
31 #include "constitutive/solid/porosity/PorosityBase.hpp"
32 #include "constitutive/solid/porosity/PorosityFields.hpp"
36 #include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelectors.hpp"
41 namespace isothermalCompositionalMultiphaseFVMKernels
53 template<
integer NUM_COMP,
integer NUM_DOF,
typename STENCILWRAPPER >
80 using AbstractBase::m_dPhaseVolFrac;
81 using AbstractBase::m_kernelFlags;
85 fields::diffusion::diffusivity,
86 fields::diffusion::dDiffusivity_dTemperature,
87 fields::diffusion::phaseDiffusivityMultiplier >;
91 fields::dispersion::dispersivity >;
95 fields::porosity::referencePorosity >;
115 STENCILWRAPPER
const & stencilWrapper,
116 DofNumberAccessor
const & dofNumberAccessor,
125 BitFlags< KernelFlags > kernelFlags )
135 m_phaseVolFrac( compFlowAccessors.get( fields::flow::phaseVolumeFraction {} ) ),
136 m_phaseDens( multiFluidAccessors.get( fields::multifluid::phaseDensity {} ) ),
137 m_dPhaseDens( multiFluidAccessors.get( fields::multifluid::dPhaseDensity {} ) ),
138 m_diffusivity( diffusionAccessors.get( fields::diffusion::diffusivity {} ) ),
139 m_dDiffusivity_dTemp( diffusionAccessors.get( fields::diffusion::dDiffusivity_dTemperature {} ) ),
140 m_phaseDiffusivityMultiplier( diffusionAccessors.get( fields::diffusion::phaseDiffusivityMultiplier {} ) ),
141 m_dispersivity( dispersionAccessors.get( fields::dispersion::dispersivity {} ) ),
144 m_seri( stencilWrapper.getElementRegionIndices() ),
145 m_sesri( stencilWrapper.getElementSubRegionIndices() ),
146 m_sei( stencilWrapper.getElementIndices() )
203 {
return m_sei[iconn].size(); }
245 template<
typename FUNC = NoOpFunc >
250 FUNC && diffusionFluxKernelOp = NoOpFunc{} )
const
252 using Deriv = constitutive::multifluid::DerivativeOffset;
257 m_dDiffusivity_dTemp,
291 real64 compFracGrad = 0.0;
304 localIndex const k_up = (compFracGrad >= 0) ? 0 : 1;
311 real64 const upwindCoefficient =
313 m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
315 diffusionFlux[ic] += upwindCoefficient * compFracGrad;
320 dDiffusionFlux_dP[ke][ic] += upwindCoefficient * dCompFracGrad_dP[ke];
323 dDiffusionFlux_dC[ke][ic][jc] += upwindCoefficient * dCompFracGrad_dC[ke][jc];
328 real64 const dUpwindCoefficient_dP =
330 m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
331 ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] *
m_phaseVolFrac[er_up][esr_up][ei_up][ip]
332 +
m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dP] );
333 dDiffusionFlux_dP[k_up][ic] += dUpwindCoefficient_dP * compFracGrad;
337 m_dPhaseDens[er_up][esr_up][ei_up][0][ip],
342 real64 const dUpwindCoefficient_dC =
344 m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
346 +
m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dC+jc] );
347 dDiffusionFlux_dC[k_up][ic][jc] += dUpwindCoefficient_dC * compFracGrad;
352 diffusionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex,
353 k_up, seri[k_up], sesri[k_up], sei[k_up],
354 compFracGrad, upwindCoefficient );
378 template<
typename FUNC = NoOpFunc >
383 FUNC && dispersionFluxKernelOp = NoOpFunc{} )
const
385 using Deriv = constitutive::multifluid::DerivativeOffset;
425 real64 compFracGrad = 0.0;
438 localIndex const k_up = (compFracGrad >= 0) ? 0 : 1;
445 dispersionFlux[ic] +=
m_phaseDens[er_up][esr_up][ei_up][0][ip] * compFracGrad;
450 dDispersionFlux_dP[ke][ic] +=
m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dP[ke];
453 dDispersionFlux_dC[ke][ic][jc] +=
m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dC[ke][jc];
458 dDispersionFlux_dP[k_up][ic] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * compFracGrad;
462 m_dPhaseDens[er_up][esr_up][ei_up][0][ip],
467 dDispersionFlux_dC[k_up][ic][jc] += dDens_dC[jc] * compFracGrad;
472 dispersionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex,
473 k_up, seri[k_up], sesri[k_up], sei[k_up],
484 dDispersionFlux_dC );
514 using Deriv = constitutive::multifluid::DerivativeOffset;
525 dCompFracGrad_dP[i] += trans[i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dP];
529 m_dPhaseCompFrac[er][esr][ei][0][ip][ic],
534 dCompFracGrad_dC[i][jc] += trans[i] * dCompFrac_dC[jc];
573 localIndex const localDofIndexComp = localDofIndexPres + jc + 1;
587 template<
typename FUNC = NoOpFunc >
592 FUNC && assemblyKernelOp = NoOpFunc{} )
const
594 using namespace compositionalMultiphaseUtilities;
596 if( m_kernelFlags.isSet( KernelFlags::TotalMassEquation ) )
611 if(
m_ghostRank[
m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 )
621 m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >
629 assemblyKernelOp( i, localRow );
641 template<
typename POLICY,
typename KERNEL_TYPE >
646 KERNEL_TYPE
const & kernelComponent )
651 typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ),
652 kernelComponent.numPointsInFlux( iconn ) );
654 kernelComponent.setup( iconn, stack );
657 kernelComponent.computeDiffusionFlux( iconn, stack );
661 kernelComponent.computeDispersionFlux( iconn, stack );
663 kernelComponent.complete( iconn, stack );
693 typename STENCILWRAPPER::IndexContainerViewConstType
const m_seri;
694 typename STENCILWRAPPER::IndexContainerViewConstType
const m_sesri;
695 typename STENCILWRAPPER::IndexContainerViewConstType
const m_sei;
723 template<
typename POLICY,
typename STENCILWRAPPER >
728 string const & dofKey,
731 integer const useTotalMassEquation,
732 string const & solverName,
734 STENCILWRAPPER
const & stencilWrapper,
739 isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&](
auto NC )
741 integer constexpr NUM_COMP = NC();
742 integer constexpr NUM_DOF = NC() + 1;
746 dofNumberAccessor.setName( solverName +
"/accessors/" + dofKey );
748 BitFlags< KernelFlags > kernelFlags;
749 if( useTotalMassEquation )
750 kernelFlags.set( KernelFlags::TotalMassEquation );
753 typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName );
754 typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName );
755 typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName );
756 typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName );
757 typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName );
759 kernelType kernel( numPhases, rankOffset, stencilWrapper,
760 dofNumberAccessor, compFlowAccessors, multiFluidAccessors,
761 diffusionAccessors, dispersionAccessors, porosityAccessors,
762 dt, localMatrix, localRhs, kernelFlags );
763 kernelType::template launch< POLICY >( stencilWrapper.size(),
764 hasDiffusion, hasDispersion,
#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.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
ElementViewAccessor< ArrayView< T const, NDIM, getUSD< PERM > > > constructArrayViewAccessor(string const &name, string const &neighborName=string()) const
This is a function to construct a ElementViewAccessor to access array data registered on the mesh.
array1d< array1d< VIEWTYPE > > ElementViewAccessor
The ElementViewAccessor at the ElementRegionManager level is an array of array of VIEWTYPE.
A struct to automatically construct and store element view accessors.
A struct to automatically construct and store element view accessors.
static void createAndLaunch(integer const numComps, integer const numPhases, globalIndex const rankOffset, string const &dofKey, integer const hasDiffusion, integer const hasDispersion, integer const useTotalMassEquation, string const &solverName, ElementRegionManager const &elemManager, STENCILWRAPPER const &stencilWrapper, real64 const dt, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Create a new kernel and launch.
Define the interface for the assembly kernel in charge of diffusion/dispersion flux terms.
ElementViewConst< arrayView1d< real64 const > > const m_referencePorosity
View on the reference porosity.
ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseDens
Views on phase densities.
STENCILWRAPPER::IndexContainerViewConstType const m_seri
Connection to element maps.
GEOS_HOST_DEVICE void computeCompFractionGradient(integer const ip, integer const ic, localIndex const (&seri)[numFluxSupportPoints], localIndex const (&sesri)[numFluxSupportPoints], localIndex const (&sei)[numFluxSupportPoints], real64 const (&trans)[numFluxSupportPoints], real64 &compFracGrad, real64(&dCompFracGrad_dP)[numFluxSupportPoints], real64(&dCompFracGrad_dC)[numFluxSupportPoints][numComp]) const
Compute the component fraction gradient at this interface.
ElementViewConst< arrayView3d< real64 const > > const m_dispersivity
Views on dispersivity.
DiffusionDispersionFluxComputeKernel(integer const numPhases, globalIndex const rankOffset, STENCILWRAPPER const &stencilWrapper, DofNumberAccessor const &dofNumberAccessor, CompFlowAccessors const &compFlowAccessors, MultiFluidAccessors const &multiFluidAccessors, DiffusionAccessors const &diffusionAccessors, DispersionAccessors const &dispersionAccessors, PorosityAccessors const &porosityAccessors, real64 const dt, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs, BitFlags< KernelFlags > kernelFlags)
Constructor for the kernel interface.
GEOS_HOST_DEVICE void addToLocalFluxAndJacobian(localIndex const (&k)[numFluxSupportPoints], StackVariables &stack, real64 const (&flux)[numComp], real64 const (&dFlux_dP)[numFluxSupportPoints][numComp], real64 const (&dFlux_dC)[numFluxSupportPoints][numComp][numComp]) const
Add the local diffusion/dispersion flux contributions to the residual and Jacobian.
static constexpr localIndex maxNumElems
Maximum number of elements at the face.
GEOS_HOST_DEVICE localIndex stencilSize(localIndex const iconn) const
Getter for the stencil size at this connection.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
GEOS_HOST_DEVICE void computeDiffusionFlux(localIndex const iconn, StackVariables &stack, FUNC &&diffusionFluxKernelOp=NoOpFunc{}) const
Compute the local diffusion flux contributions to the residual and Jacobian.
static void launch(localIndex const numConnections, integer const hasDiffusion, integer const hasDispersion, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
STENCILWRAPPER const m_stencilWrapper
Reference to the stencil wrapper.
static constexpr localIndex maxNumConns
Maximum number of connections at the face.
GEOS_HOST_DEVICE localIndex numPointsInFlux(localIndex const iconn) const
Getter for the number of elements at this connection.
ElementViewConst< arrayView3d< real64 const > > const m_diffusivity
Views on diffusivity.
static constexpr integer numFluxSupportPoints
Number of flux support points (hard-coded for TFPA)
static constexpr integer numComp
Compile time value for the number of components.
GEOS_HOST_DEVICE void computeDispersionFlux(localIndex const iconn, StackVariables &stack, FUNC &&dispersionFluxKernelOp=NoOpFunc{}) const
Compute the local dispersion 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.
GEOS_HOST_DEVICE void setup(localIndex const iconn, StackVariables &stack) const
Performs the setup phase for the kernel.
static constexpr integer numEqn
Compute time value for the number of equations (all of them, except the volume balance equation)
ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseVolFrac
Views on phase volume fraction.
static constexpr localIndex maxStencilSize
Maximum number of points in the stencil.
Base class for FluxComputeKernel that holds all data not dependent on template parameters (like stenc...
real64 const m_dt
Time step size.
ElementViewConst< arrayView1d< globalIndex const > > const m_dofNumber
Views on dof numbers.
ElementViewConst< arrayView1d< integer const > > const m_ghostRank
Views on ghost rank numbers and gravity coefficients.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const m_phaseCompFrac
Views on phase component fractions.
globalIndex const m_rankOffset
Offset for my MPI rank.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
ElementRegionManager::ElementViewConst< VIEWTYPE > ElementViewConst
The type for element-based data. Consists entirely of ArrayView's.
ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const m_dCompFrac_dCompDens
Views on derivatives of comp fractions.
integer const m_numPhases
Number of fluid phases.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
StackArray< T, 2, MAXSIZE > stackArray2d
Alias for 2D stack array.
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
StackArray< T, 1, MAXSIZE > stackArray1d
Alias for 1D stack array.
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.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
stackArray1d< real64, maxNumElems *numEqn > localFlux
Storage for the face local residual vector (all equations except volume balance)
localIndex const stencilSize
Stencil size for a given connection.
stackArray1d< globalIndex, maxNumElems *numDof > dofColIndices
Indices of the matrix rows/columns corresponding to the dofs in this face.
localIndex const numConnectedElems
Number of elements connected at a given connection.
real64 dTrans_dTemp[maxNumConns][numFluxSupportPoints]
Derivatives of transmissibility with respect to pressure.
GEOS_HOST_DEVICE StackVariables(localIndex const size, localIndex numElems)
Constructor for the stack variables.
real64 transmissibility[maxNumConns][numFluxSupportPoints]
Transmissibility.
stackArray2d< real64, maxNumElems *numEqn *maxStencilSize *numDof > localFluxJacobian
Storage for the face local Jacobian matrix.