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" 
   40 namespace isothermalCompositionalMultiphaseFVMKernels
 
   52 template< 
integer NUM_COMP, 
integer NUM_DOF, 
typename STENCILWRAPPER >
 
   79   using AbstractBase::m_dPhaseVolFrac;
 
   80   using AbstractBase::m_kernelFlags;
 
   84                               fields::diffusion::diffusivity,
 
   85                               fields::diffusion::dDiffusivity_dTemperature,
 
   86                               fields::diffusion::phaseDiffusivityMultiplier >;
 
   90                               fields::dispersion::dispersivity >;
 
   94                               fields::porosity::referencePorosity >;
 
  114                                         STENCILWRAPPER 
const & stencilWrapper,
 
  115                                         DofNumberAccessor 
const & dofNumberAccessor,
 
  124                                         BitFlags< KernelFlags > kernelFlags )
 
  134     m_phaseVolFrac( compFlowAccessors.get( fields::flow::phaseVolumeFraction {} ) ),
 
  135     m_phaseDens( multiFluidAccessors.get( fields::multifluid::phaseDensity {} ) ),
 
  136     m_dPhaseDens( multiFluidAccessors.get( fields::multifluid::dPhaseDensity {} ) ),
 
  137     m_diffusivity( diffusionAccessors.get( fields::diffusion::diffusivity {} ) ),
 
  138     m_dDiffusivity_dTemp( diffusionAccessors.get( fields::diffusion::dDiffusivity_dTemperature {} ) ),
 
  139     m_phaseDiffusivityMultiplier( diffusionAccessors.get( fields::diffusion::phaseDiffusivityMultiplier {} ) ),
 
  140     m_dispersivity( dispersionAccessors.get( fields::dispersion::dispersivity {} ) ),
 
  143     m_seri( stencilWrapper.getElementRegionIndices() ),
 
  144     m_sesri( stencilWrapper.getElementSubRegionIndices() ),
 
  145     m_sei( stencilWrapper.getElementIndices() )
 
  202   { 
return m_sei[iconn].size(); }
 
  244   template< 
typename FUNC = NoOpFunc >
 
  249                              FUNC && diffusionFluxKernelOp = NoOpFunc{} ) 
const 
  251     using Deriv = constitutive::multifluid::DerivativeOffset;
 
  256                                      m_dDiffusivity_dTemp,
 
  290             real64 compFracGrad = 0.0;
 
  303             localIndex const k_up = (compFracGrad >= 0) ? 0 : 1;
 
  310             real64 const upwindCoefficient =
 
  312               m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
 
  314             diffusionFlux[ic] += upwindCoefficient * compFracGrad;
 
  319               dDiffusionFlux_dP[ke][ic] += upwindCoefficient * dCompFracGrad_dP[ke];
 
  322                 dDiffusionFlux_dC[ke][ic][jc] += upwindCoefficient * dCompFracGrad_dC[ke][jc];
 
  327             real64 const dUpwindCoefficient_dP =
 
  329               m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
 
  330               ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * 
m_phaseVolFrac[er_up][esr_up][ei_up][ip]
 
  331                 + 
m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dP] );
 
  332             dDiffusionFlux_dP[k_up][ic] += dUpwindCoefficient_dP * compFracGrad;
 
  336                             m_dPhaseDens[er_up][esr_up][ei_up][0][ip],
 
  341               real64 const dUpwindCoefficient_dC =
 
  343                 m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] *
 
  345                   + 
m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dC+jc] );
 
  346               dDiffusionFlux_dC[k_up][ic][jc] += dUpwindCoefficient_dC * compFracGrad;
 
  351             diffusionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex,
 
  352                                    k_up, seri[k_up], sesri[k_up], sei[k_up],
 
  353                                    compFracGrad, upwindCoefficient );
 
  377   template< 
typename FUNC = NoOpFunc >
 
  382                               FUNC && dispersionFluxKernelOp = NoOpFunc{} ) 
const 
  384     using Deriv = constitutive::multifluid::DerivativeOffset;
 
  424             real64 compFracGrad = 0.0;
 
  437             localIndex const k_up = (compFracGrad >= 0) ? 0 : 1;
 
  444             dispersionFlux[ic] += 
m_phaseDens[er_up][esr_up][ei_up][0][ip] * compFracGrad;
 
  449               dDispersionFlux_dP[ke][ic] += 
m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dP[ke];
 
  452                 dDispersionFlux_dC[ke][ic][jc] += 
m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dC[ke][jc];
 
  457             dDispersionFlux_dP[k_up][ic] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * compFracGrad;
 
  461                             m_dPhaseDens[er_up][esr_up][ei_up][0][ip],
 
  466               dDispersionFlux_dC[k_up][ic][jc] += dDens_dC[jc] * compFracGrad;
 
  471             dispersionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex,
 
  472                                     k_up, seri[k_up], sesri[k_up], sei[k_up],
 
  483                                    dDispersionFlux_dC );
 
  513     using Deriv = constitutive::multifluid::DerivativeOffset;
 
  524       dCompFracGrad_dP[i] += trans[i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dP];
 
  528                       m_dPhaseCompFrac[er][esr][ei][0][ip][ic],
 
  533         dCompFracGrad_dC[i][jc] += trans[i] * dCompFrac_dC[jc];
 
  572           localIndex const localDofIndexComp = localDofIndexPres + jc + 1;
 
  586   template< 
typename FUNC = NoOpFunc >
 
  591                  FUNC && assemblyKernelOp = NoOpFunc{} ) 
const 
  593     using namespace compositionalMultiphaseUtilities;
 
  595     if( m_kernelFlags.isSet( KernelFlags::TotalMassEquation ) )
 
  610       if( 
m_ghostRank[
m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 )
 
  620           m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >
 
  628         assemblyKernelOp( i, localRow );
 
  640   template< 
typename POLICY, 
typename KERNEL_TYPE >
 
  645           KERNEL_TYPE 
const & kernelComponent )
 
  650       typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ),
 
  651                                                   kernelComponent.numPointsInFlux( iconn ) );
 
  653       kernelComponent.setup( iconn, stack );
 
  656         kernelComponent.computeDiffusionFlux( iconn, stack );
 
  660         kernelComponent.computeDispersionFlux( iconn, stack );
 
  662       kernelComponent.complete( iconn, stack );
 
  692   typename STENCILWRAPPER::IndexContainerViewConstType 
const m_seri;
 
  693   typename STENCILWRAPPER::IndexContainerViewConstType 
const m_sesri;
 
  694   typename STENCILWRAPPER::IndexContainerViewConstType 
const m_sei;
 
  722   template< 
typename POLICY, 
typename STENCILWRAPPER >
 
  727                    string const & dofKey,
 
  728                    BitFlags< KernelFlags > kernelFlags,
 
  729                    string const & solverName,
 
  731                    STENCILWRAPPER 
const & stencilWrapper,
 
  736     isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( 
auto NC )
 
  738       integer constexpr NUM_COMP = NC();
 
  739       integer constexpr NUM_DOF = NC() + 1;
 
  743       dofNumberAccessor.setName( solverName + 
"/accessors/" + dofKey );
 
  746       typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName );
 
  747       typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName );
 
  748       typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName );
 
  749       typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName );
 
  750       typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName );
 
  752       kernelType kernel( numPhases, rankOffset, stencilWrapper,
 
  753                          dofNumberAccessor, compFlowAccessors, multiFluidAccessors,
 
  754                          diffusionAccessors, dispersionAccessors, porosityAccessors,
 
  755                          dt, localMatrix, localRhs, kernelFlags );
 
  756       kernelType::template launch< POLICY >( stencilWrapper.size(),
 
  757                                              kernelFlags.isSet( KernelFlags::Diffusion ),
 
  758                                              kernelFlags.isSet( KernelFlags::Dispersion ),
 
#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, BitFlags< KernelFlags > kernelFlags, 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.
 
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).
 
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
 
int 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.