20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_SINGLEPHASEWELLKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_SINGLEPHASEWELLKERNELS_HPP
24 #include "common/GEOS_RAJA_Interface.hpp"
27 #include "constitutive/fluid/singlefluid/SingleFluidFields.hpp"
28 #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp"
29 #include "constitutive/fluid/singlefluid/SingleFluidLayouts.hpp"
30 #include "constitutive/fluid/singlefluid/SingleFluidLayouts.hpp"
35 #include "physicsSolvers/fluidFlow/wells/WellControls.hpp"
43 namespace singlePhaseWellKernels
49 static constexpr
integer RES = 0;
50 static constexpr
integer WELL = 1;
56 static constexpr
integer CURRENT = 0;
57 static constexpr
integer NEXT = 1;
63 static constexpr
integer DPRES = 0;
64 static constexpr
integer DRATE = 1;
67 template<
integer IS_THERMAL >
73 static constexpr
integer dP = 0;
74 static constexpr
integer dQ = dP + 1;
75 static integer constexpr nDer = dQ + 1;
82 static constexpr
integer dP = 0;
83 static constexpr
integer dQ = dP + 1;
84 static constexpr
integer dT = dQ+1;
92 static constexpr
integer CONTROL = 0;
93 static constexpr
integer MASSBAL = 1;
96 template<
integer IS_THERMAL >
102 static constexpr
integer CONTROL = 0;
103 static constexpr
integer MASSBAL = 1;
104 static constexpr
integer nEqn = MASSBAL+1;
109 static constexpr
integer CONTROL = 0;
110 static constexpr
integer MASSBAL = 1;
111 static constexpr
integer ENERGYBAL = MASSBAL+1;
112 static constexpr
integer nEqn = ENERGYBAL+1;
124 static constexpr
real64 EPS = 1e-15;
130 switchControl(
bool const isProducer,
133 real64 const & targetRate,
134 real64 const & currentBHP,
135 real64 const & currentVolRate,
138 template<
integer IS_THERMAL >
146 real64 const & targetRate,
147 real64 const & currentBHP,
149 real64 const & currentVolRate,
167 template<
integer IS_THERMAL >
190 template<
integer IS_THERMAL >
218 fields::singlefluid::density,
219 fields::singlefluid::dDensity,
220 fields::singlefluid::viscosity,
221 fields::singlefluid::dViscosity >;
230 template<
typename VIEWTYPE >
233 template<
integer IS_THERMAL >
238 compute(
real64 const & resPressure,
239 real64 const & resDensity,
241 real64 const & resViscosity,
243 real64 const & wellElemGravCoef,
244 real64 const & wellElemPressure,
245 real64 const & wellElemDensity,
247 real64 const & wellElemViscosity,
249 real64 const & perfGravCoef,
255 template<
integer IS_THERMAL >
309 template<
integer IS_THERMAL >
315 using FLUID_PROP_COFFSET = constitutive::singlefluid::DerivativeOffsetC< IS_THERMAL >;
339 constitutive::SingleFluidBase
const & fluid,
348 m_dWellElemDensity( fluid.dDensity() ),
349 m_wellElemDensity_n( fluid.density_n() ),
373 template<
typename FUNC = NoOpFunc >
376 FUNC && kernelOp = NoOpFunc{} )
const
383 real64 const localAccumDP =
m_wellElemVolume[iwelem] * m_dWellElemDensity[iwelem][0][FLUID_PROP_COFFSET::dP];
386 m_localMatrix.addToRow< serialAtomic >( eqnRowIndex, &presDofColIndex, &localAccumDP, 1 );
389 if constexpr ( IS_THERMAL )
391 real64 const localAccumDT =
m_wellElemVolume[iwelem] * m_dWellElemDensity[iwelem][0][FLUID_PROP_COFFSET::dT];
393 m_localMatrix.addToRow< serialAtomic >( eqnRowIndex, &tempDofColIndex, &localAccumDT, 1 );
394 kernelOp( presDofColIndex, tempDofColIndex );
408 template<
typename POLICY,
typename KERNEL_TYPE >
411 KERNEL_TYPE
const & kernelComponent )
417 if( kernelComponent.elemGhostRank( iwelem ) >= 0 )
421 kernelComponent.computeAccumulation( iwelem );
470 template<
typename POLICY >
475 constitutive::SingleFluidBase
const & fluid,
482 kernel( rankOffset, dofKey, subRegion, fluid, localMatrix, localRhs );
484 launch< POLICY, ElementBasedAssemblyKernel< isThermal > >( subRegion.
size(), kernel );
496 fields::flow::temperature >;
500 fields::singlefluid::density >;
509 template<
typename VIEWTYPE >
513 launch(
integer const isThermal,
518 real64 const & currentTime,
540 template<
integer IS_THERMAL >
549 using FLUID_PROP_COFFSET = constitutive::singlefluid::DerivativeOffsetC< IS_THERMAL >;
553 using CP_Deriv = constitutive::singlefluid::DerivativeOffsetC< IS_THERMAL >;
561 static constexpr
integer maxNumElems = 2;
562 static constexpr
integer maxStencilSize = 2;
575 string const wellDofKey,
585 m_connRate ( subRegion.getField< fields::well::connectionRate >() ),
599 template<
typename FUNC = NoOpFunc >
603 FUNC && compFluxKernelOp = NoOpFunc{} )
const
625 real64 const oneSidedLocalFlux = -flux;
626 real64 const oneSidedLocalFluxJacobian_dRate = -dFlux_dRate;
632 if( oneSidedEqnRowIndex >= 0 && oneSidedEqnRowIndex <
m_localMatrix.numRows() )
634 m_localMatrix.addToRow< parallelDeviceAtomic >( oneSidedEqnRowIndex,
635 &oneSidedDofColIndex_dRate,
636 &oneSidedLocalFluxJacobian_dRate,
638 RAJA::atomicAdd( parallelDeviceAtomic{}, &
m_localRhs[oneSidedEqnRowIndex], oneSidedLocalFlux );
647 real64 localFluxJacobian_dRate[2]{};
650 localFlux[TAG::NEXT] = flux;
651 localFlux[TAG::CURRENT] = -flux;
653 localFluxJacobian_dRate[TAG::NEXT] = dFlux_dRate;
654 localFluxJacobian_dRate[TAG::CURRENT] = -dFlux_dRate;
663 if( eqnRowIndices[i] >= 0 && eqnRowIndices[i] <
m_localMatrix.numRows() )
665 m_localMatrix.addToRow< parallelDeviceAtomic >( eqnRowIndices[i],
667 &localFluxJacobian_dRate[i],
669 RAJA::atomicAdd( parallelDeviceAtomic{}, &
m_localRhs[eqnRowIndices[i]], localFlux[i] );
673 compFluxKernelOp( iwelemNext, currentConnRate );
685 template<
typename POLICY,
typename KERNEL_TYPE >
688 KERNEL_TYPE
const & kernelComponent )
693 kernelComponent.computeFlux( ie );
742 template<
typename POLICY >
753 geos::internal::kernelLaunchSelectorThermalSwitch( isThermal, [&](
auto IS_THERMAL )
756 integer constexpr istherm = IS_THERMAL();
759 kernelType kernel( dt, rankOffset, dofKey, wellControls, subRegion, localMatrix, localRhs );
760 kernelType::template launch< POLICY >( subRegion.
size(), kernel );
772 real64 const & currentTime,
799 constitutive::SingleFluidBase
const & fluid,
803 real64 const minNormalizer )
829 LinfStackVariables & stack )
const override
834 if( idof == singlePhaseWellKernels::RowOffset::CONTROL )
842 normalizer = m_targetBHP;
847 normalizer = LvArray::math::max( LvArray::math::abs( m_constraintValue ),
m_minNormalizer );
852 normalizer = LvArray::math::max( LvArray::math::abs( m_constraintValue ),
m_minNormalizer );
859 normalizer = m_targetBHP;
865 normalizer =
m_dt * LvArray::math::abs( m_constraintValue ) *
m_density_n[iwelem][0];
873 if( val > stack.localValue[0] )
875 stack.localValue[0] = val;
883 L2StackVariables & stack )
const override
886 GEOS_ERROR(
"The L2 norm is not implemented for SinglePhaseWell" );
903 real64 const m_constraintValue;
935 template<
typename POLICY >
938 string const & dofKey,
941 constitutive::SingleFluidBase
const & fluid,
945 real64 const minNormalizer,
946 real64 (& residualNorm)[1] )
951 ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, fluid, wellControls, time, dt, minNormalizer );
952 ResidualNormKernel::launchLinf< POLICY >( subRegion.
size(), kernel, residualNorm );
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
typename ElementViewAccessor< VIEWTYPE >::NestedViewTypeConst ElementViewConst
The ElementViewAccessor at the ElementRegionManager level is the type resulting from ElementViewAcces...
arrayView1d< real64 const > getElementVolume() const
Get the volume of each element in this subregion.
array1d< integer > const & ghostRank()
Get the ghost information of each object.
A struct to automatically construct and store element view accessors.
A struct to automatically construct and store element view accessors.
real64 getConstraintValue(real64 const ¤tTime) const
Get the target bottom hole pressure value.
This class describes the controls used to operate a well.
bool isProducer() const
Is the well a producer?
Control getControl() const
Get the control type for the well.
MinimumBHPConstraint * getMinBHPConstraint()
Getters for constraints.
This class describes a collection of local well elements and perforations.
bool isLocallyOwned() const
Check if well is owned by current rank.
localIndex getTopWellElementIndex() const
Get for the top element index.
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Define the base interface for the residual calculations.
real64 const m_minNormalizer
Value used to make sure that normalizers are never zero.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
GEOS_HOST_DEVICE integer ghostRank(localIndex const i) const
Getter for the ghost rank.
globalIndex const m_rankOffset
Offset for my MPI rank.
arrayView1d< real64 const > const m_localResidual
View on the local residual.
static void createAndLaunch(globalIndex const rankOffset, string const dofKey, WellElementSubRegion const &subRegion, constitutive::SingleFluidBase const &fluid, 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 accumulation.
arrayView1d< real64 const > const m_wellElemVolume
View on the element volumes.
GEOS_HOST_DEVICE integer elemGhostRank(localIndex const ei) const
Getter for the ghost rank of an element.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
ElementBasedAssemblyKernel(globalIndex const rankOffset, string const dofKey, WellElementSubRegion const &subRegion, constitutive::SingleFluidBase const &fluid, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Constructor.
arrayView2d< real64 const, constitutive::singlefluid::USD_FLUID > const m_wellElemDensity
Views on the density.
static constexpr integer numEqn
Compute time value for the number of equations mass bal + momentum + energy bal.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const iwelem, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local accumulation contributions to the residual and Jacobian.
static constexpr integer numDof
Number of Dof's set in this kernal - no dQ in accum.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
globalIndex const m_rankOffset
Offset for my MPI rank.
static void launch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
arrayView1d< integer const > const m_elemGhostRank
View on the ghost ranks.
localIndex const m_iwelemControl
Index of the element where the control is enforced.
static void createAndLaunch(real64 const dt, globalIndex const rankOffset, string const dofKey, WellControls const &wellControls, WellElementSubRegion const &subRegion, 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 flux terms.
GEOS_HOST_DEVICE void computeFlux(localIndex const iwelem, FUNC &&compFluxKernelOp=NoOpFunc{}) const
Compute the local flux contributions to the residual and Jacobian.
arrayView1d< real64 const > const m_connRate
Connection rate.
FaceBasedAssemblyKernel(real64 const dt, globalIndex const rankOffset, string const wellDofKey, WellControls const &wellControls, WellElementSubRegion const &subRegion, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Constructor for the kernel interface.
bool const m_isProducer
Well type.
arrayView2d< real64 const, compflow::USD_COMP > const m_wellElemCompFrac
Element component fraction.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
integer const m_rankOffset
Rank offset for calculating row/col Jacobian indices.
arrayView1d< localIndex const > const m_nextWellElemIndex
Next element index, needed since iterating over element nodes, not edges.
static constexpr integer numDof
Number of Dof's set in this kernal.
real64 const m_dt
Time step size.
static void launch(localIndex const numElements, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
static constexpr integer numEqn
Compile time value for the number of equations except rate, momentum, energy.
arrayView1d< globalIndex const > const m_wellElemDofNumber
Reference to the degree-of-freedom numbers.
static void createAndLaunch(globalIndex const rankOffset, string const &dofKey, arrayView1d< real64 const > const &localResidual, WellElementSubRegion const &subRegion, constitutive::SingleFluidBase const &fluid, WellControls const &wellControls, real64 const time, real64 const dt, real64 const minNormalizer, real64(&residualNorm)[1])
Create a new kernel and launch.
real64 const m_dt
Time step size.
bool const m_isLocallyOwned
Flag indicating whether the well is locally owned or not.
arrayView1d< real64 const > const m_volume
View on the volume.
arrayView2d< real64 const, constitutive::singlefluid::USD_FLUID > const m_density_n
View on total density at the previous converged time step.
virtual GEOS_HOST_DEVICE void computeL2(localIndex const iwelem, L2StackVariables &stack) const override
Compute the local values and normalizer for the L2 norm.
virtual GEOS_HOST_DEVICE void computeLinf(localIndex const iwelem, LinfStackVariables &stack) const override
Compute the local values for the Linf norm.
localIndex const m_iwelemControl
Index of the element where the control is enforced.
WellControls::Control const m_currentControl
Controls.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
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.
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
int integer
Signed integer type.
Array< T, 1 > array1d
Alias for 1D array.
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
ElementRegionManager::ElementViewConst< VIEWTYPE > ElementViewConst
The type for element-based non-constitutive data parameters. Consists entirely of ArrayView's.
ElementRegionManager::ElementViewConst< VIEWTYPE > ElementViewConst
The type for element-based non-constitutive data parameters. Consists entirely of ArrayView's.