20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_SINGLEPHASEWELLCONSTRAINTKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_SINGLEPHASEWELLCONSTRAINTKERNELS_HPP
23 #include "codingUtilities/Utilities.hpp"
24 #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp"
25 #include "constitutive/fluid/singlefluid/SingleFluidFields.hpp"
28 #include "physicsSolvers/fluidFlow/wells/WellControls.hpp"
29 #include "physicsSolvers/fluidFlow/wells/WellBHPConstraints.hpp"
30 #include "physicsSolvers/fluidFlow/wells/WellVolumeRateConstraint.hpp"
36 namespace singlePhaseWellConstraintKernels
42 template<
integer IS_THERMAL >
46 static void setTemperatureDerivative(
real64 *
const dControlEqn,
49 if constexpr ( IS_THERMAL )
55 template< BHPConstra
intTypeId I >
56 static void assembleConstraintEquation(
real64 const & time_n,
60 string const & wellDofKey,
77 using Deriv = constitutive::singlefluid::DerivativeOffsetC< IS_THERMAL >;
85 wellControls.
getReference<
real64 >( SinglePhaseWell::viewKeyStruct::currentBHPString() );
89 real64 const dDensity_dP = dDensity[iwelemRef][0][Deriv::dP];
91 if constexpr ( IS_THERMAL )
93 dDensity_dT = dDensity[iwelemRef][0][Deriv::dT];
98 globalIndex const dofNumber = wellElemDofNumber[iwelemRef];
99 localIndex const eqnRowIndex = LvArray::integerConversion< localIndex >( dofNumber + ROFFSET_WJ::CONTROL - rankOffset );
101 for(
integer i = 0; i < COFFSET_WJ::nDer; ++i )
103 dofColIndices[ i ] = dofNumber + i;
106 real64 const diffGravCoef = refGravCoef - wellElemGravCoef[iwelemRef];
107 real64 dControlEqn[2+IS_THERMAL]{};
108 dControlEqn[COFFSET_WJ::dP] = 1.0 + dDensity_dP * diffGravCoef;
109 setTemperatureDerivative( dControlEqn, dDensity_dT * diffGravCoef );
111 RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[eqnRowIndex], currentBHP - targetBHP );
112 localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( eqnRowIndex,
119 static void assembleConstraintEquation(
real64 const & time_n,
121 T< VolumeRateConstraint > & constraint,
123 string const & wellDofKey,
136 using Deriv = constitutive::singlefluid::DerivativeOffsetC< IS_THERMAL >;
147 real64 const currentVolRate =
148 wellControls.
getReference<
real64 >( WellControls::viewKeyStruct::currentVolRateString() );
154 real64 const densityRef = density[iwelemRef][0];
155 real64 const dDensity_dP = dDensity[iwelemRef][0][Deriv::dP];
157 if constexpr ( IS_THERMAL )
159 dDensity_dT = dDensity[iwelemRef][0][Deriv::dT];
164 globalIndex const dofNumber = wellElemDofNumber[iwelemRef];
165 localIndex const eqnRowIndex = LvArray::integerConversion< localIndex >( dofNumber + ROFFSET_WJ::CONTROL - rankOffset );
167 for(
integer i = 0; i < COFFSET_WJ::nDer; ++i )
169 dofColIndices[ i ] = dofNumber + i;
172 real64 const densInv = 1.0 / densityRef;
173 real64 dControlEqn[2+IS_THERMAL]{};
174 dControlEqn[COFFSET_WJ::dP] = -( useSurfaceConditions == 0 ) * dDensity_dP * currentVolRate * densInv;
175 dControlEqn[COFFSET_WJ::dQ] = densInv;
176 setTemperatureDerivative( dControlEqn,
177 -( useSurfaceConditions == 0 ) * dDensity_dT * currentVolRate * densInv );
179 RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[eqnRowIndex], currentVolRate - targetVolRate );
180 localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( eqnRowIndex,
#define GEOS_HOST_DEVICE
Marks a host-device function.
This class describes a minimum pressure constraint used to control a injection well.
real64 getReferenceGravityCoef() const
Getter for the reference gravity coefficient.
GEOS_DECLTYPE_AUTO_RETURN getField() const
Get a view to the field associated with a trait from this ObjectManagerBase.
This class describes a volume rate constraint used to control a well.
real64 getConstraintValue(real64 const ¤tTime) const
Get the target bottom hole pressure value.
This class describes the controls used to operate a well.
This class describes a collection of local well elements and perforations.
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.
integer useSurfaceConditions() const
Getter for the flag specifying whether we check rates at surface or reservoir conditions.
constitutive::SingleFluidBase & getSingleFluidSeparator()
Getter for single fluid separator.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
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.
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.