20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLCONTROLS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLCONTROLS_HPP
27 #include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
29 #include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
30 #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp"
31 #include "physicsSolvers/fluidFlow/wells/WellConstraintsBase.hpp"
36 namespace dataRepository
40 static constexpr
auto wellControls =
"WellControls";
44 class ElementsReporterBuffer;
151 virtual void validateWellConstraints(
real64 const & time_n,
155 virtual bool isCompositional()
const = 0;
178 virtual void implicitStepSetup(
real64 const & time_n,
181 string const & meshBodyName,
186 implicitStepComplete(
real64 const & time,
189 virtual real64 updateSubRegionState(
real64 const time_n,
212 integer const coupledIterationNumber,
223 integer const coupledIterationNumber,
230 void assembleSystem(
real64 const & time_n,
312 calculateWellResidualNorm(
real64 const & time_n,
320 calculateLocalWellResidualNorm(
real64 const & time_n,
336 real64 const scalingFactor,
345 applyWellSystemSolution(
DofManager const & dofManager,
347 real64 const scalingFactor,
353 virtual void applyWellBoundaryConditions(
real64 const time_n,
379 virtual void initializeWellPostInitialConditionsPreSubGroups(
WellElementSubRegion & subRegion ) = 0;
380 virtual void printRates(
real64 const & time_n,
396 template<
typename CONSTITUTIVE_BASE_TYPE >
407 template<
typename CONSTITUTIVE >
580 setControl( currentConstraint->getControl() );
581 m_currentConstraint = currentConstraint;
623 void setFluidSeparator( std::unique_ptr< constitutive::ConstitutiveBase > fluidSeparatorPtr ) { m_fluidSeparatorPtr = std::move( fluidSeparatorPtr );}
628 constitutive::MultiFluidBase &
getMultiFluidSeparator() {
return dynamicCast< constitutive::MultiFluidBase & >( *m_fluidSeparatorPtr ); }
634 constitutive::SingleFluidBase &
getSingleFluidSeparator() {
return dynamicCast< constitutive::SingleFluidBase & >( *m_fluidSeparatorPtr ); }
676 virtual string wellElementDofName()
const = 0;
678 virtual string resElementDofName()
const = 0;
693 virtual localIndex numFluidComponents()
const = 0;
695 virtual localIndex numFluidPhases()
const = 0;
707 static constexpr
char const * timeStepFromTablesFlagString() {
return "timeStepFromTables"; }
712 static constexpr
char const *
refElevString() {
return "referenceElevation"; }
714 static constexpr
char const *
typeString() {
return "type"; }
743 static constexpr
char const * massDensityString() {
return "massDensity";}
745 static constexpr
char const * currentBHPString() {
return "currentBHP"; }
747 static constexpr
char const * currentPhaseVolRateString() {
return "currentPhaseVolumetricRate"; }
748 static constexpr
char const * currentVolRateString() {
return "currentVolRate"; }
750 static constexpr
char const * currentTotalVolRateString() {
return "currentTotalVolumetricRate"; }
752 static constexpr
char const * currentMassRateString() {
return "currentMassRate"; }
780 template<
typename Constra
intType >
void createConstraint (
string const & constraintName );
832 void selectWellConstraint(
real64 const & time_n,
835 integer const coupledIterationNumber,
836 DomainPartition & domain,
837 string const & meshBodyName,
839 ElementRegionManager & elemManager,
840 WellElementSubRegion & subRegion,
841 DofManager
const & dofManager );
865 bool isLimiting =
false )
const;
932 string const m_ratesOutputDir;
953 std::unique_ptr< constitutive::ConstitutiveBase > m_fluidSeparatorPtr;
998 integer m_enableIsoThermalEstimator;
999 bool m_thermalEffectsEnabled;
1008 bool m_dofManagerInitialized;
1027 template<
typename CONSTITUTIVE >
1035 string & constitutiveName = subRegion.
getReference<
string >( wrapperName );
1036 constitutiveName = getConstitutiveName< CONSTITUTIVE >( subRegion );
1037 GEOS_ERROR_IF( constitutiveName.empty(), GEOS_FMT(
"{}: {} constitutive model not found on subregion {}",
1040 template<
typename CONSTITUTIVE_BASE_TYPE >
1048 GEOS_ERROR_IF( !validName.empty(),
"A valid constitutive model was already found." );
1049 validName = model.getName();
1063 template<
typename BASETYPE = constitutive::ConstitutiveBase,
typename LOOKUP_TYPE >
1067 return constitutiveModels.
getGroup< BASETYPE >( key );
1077 template<
typename BASETYPE = constitutive::ConstitutiveBase,
typename LOOKUP_TYPE >
1081 return constitutiveModels.
getGroup< BASETYPE >( key );
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
#define GEOS_ERROR_IF(COND,...)
Conditionally raise a hard error and terminate the program.
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
dataRepository::Group const & getConstitutiveModels() const
Get the group in which the constitutive models of this subregion are registered.
A buffer to count and store element ids during kernel execution. This facilitates the reporting mecha...
The class is used to manage mesh body.
Class facilitating the representation of a multi-level discretization of a MeshBody.
This class describes the controls used to operate a well.
~WellControls() override
Default destructor.
WellControls & operator=(WellControls &&)=delete
Deleted move operator.
WellControls(WellControls &&)=delete
Deleted move constructor.
WellControls(string const &name, dataRepository::Group *const parent)
Constructor for WellControls Objects.
WellControls(WellControls const &)=delete
Deleted copy constructor.
WellControls & operator=(WellControls const &)=delete
Deleted assignment operator.
virtual void createSeparator(WellElementSubRegion &subRegion)=0
Create well separator.
virtual void expandObjectCatalogs() override
Expand catalog for schema generation.
virtual Group * createChild(string const &childKey, string const &childName) override
Create a new constraint object as a child of this group.
static string coupledSolverAttributePrefix()
String used to form the solverName used to register single-physics solvers in CoupledSolver.
WellControls()=delete
Deleted default constructor.
This class specializes the element region for the case of a well. This class is also in charge of sta...
This class describes a collection of local well elements and perforations.
Base class for all physics solvers.
Wrapper< TBASE > & registerWrapper(string const &name, wrapperMap::KeyIndex::index_type *const rkey=nullptr)
Create and register a Wrapper around a new object.
DataContext const & getDataContext() const
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
string const & getName() const
Get group name.
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Group & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
virtual void initializePreSubGroups() override
Called by Initialize() prior to initializing sub-Groups.
real64 m_refGravCoef
Gravity coefficient of the reference elevation.
void logConstraint(WellConstraintBase const *constraint, WellElementSubRegion const ®ion, real64 time, bool isLimiting=false) const
Logs the state and values of a specific well constraint.
static constexpr char const * initialPressureCoefficientString()
string key for the initial pressure coefficient
ConstraintTypeId getControl() const
Get the control type for the well.
integer m_useSurfaceConditions
Flag to decide whether rates are controlled at rates or surface conditions.
integer estimateSolution() const
getter for esitmator switch
WellConstraintBase const * getBHPConstraint(const ConstraintSourceId source=ConstraintSourceId::USER) const
Gets the defined BHP constraint.
void setWellStatus(real64 const ¤tTime, WellControls::Status status)
Set well status from time and internal action, eg. all perfs closed.
static constexpr char const * fluidNamesString()
String key for the fluid model names.
ConstraintTypeId m_currentControl
Well controls as a Control enum.
stdVector< WellConstraintBase const * > getAllConstraints() const
Gets a list of all constraints constraints.
void setUseMass(integer useMass)
setter to activate mass formulation
virtual void assembleWellConstraintTerms(real64 const &time_n, real64 const &dt, WellElementSubRegion const &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the well constraint terms for an individual well
bool isProducer() const
Is the well a producer?
virtual void postInputInitialization() override
stdVector< WellConstraintBase const * > getRateConstraints() const
Gets a list of rate constraints.
static constexpr char const * targetRegionsString()
String for the targetRegions wrapper.
real64 getRegionAverageTemperature() const
Getter for the reservoir average temperature when m_useSurfaceConditions == 0.
void createConstraint(string const &constraintName)
Create a constraint.
static constexpr char const * useSurfaceConditionsString()
String key for checking the rates at surface conditions.
virtual void assembleWellPressureRelations(real64 const &time_n, real64 const &dt, WellElementSubRegion const &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the well momentum terms for an individual well
real64 m_regionAveragePressure
Region average pressure used in volume rate constraint calculations.
void setNextDtFromTables(real64 const ¤tTime, real64 &nextDt)
set next time step based on tables intervals
bool getWellState() const
Get the well state.
static constexpr char const * perfStatusTableNameString()
string key for perforation status table name
bool m_keepVariablesConstantDuringInitStep
flag to freeze the initial state during initialization in coupled problems
string m_referenceReservoirRegion
Reservoir region associated with reservoir volume constraint.
static constexpr char const * refElevString()
String key for the well reference elevation (for BHP control)
bool isInjector() const
Is the well an injector?
real64 getReferenceElevation() const
Return the reference elvation where pressure constraint is measured.
void enableThermalEffects(bool enable)
Set thermal effects enable.
static constexpr char const * enableCrossflowString()
string key for the crossflow flag
integer m_isCrossflowEnabled
Flag to enable crossflow.
integer m_useMass
flag indicating whether mass or molar formulation should be used
WellControls::Status getWellStatus() const
Is the well open (or shut) based on internal action.
std::string m_discretizationName
Name of the discretization for the region.
bool validateReferenceRegion() const
Validates the reference region.
static constexpr char const * writeCSVFlagString()
String key for the write CSV flag.
real64 getRegionAveragePressure() const
Getter for the reservoir average pressure when m_useSurfaceConditions == 0.
std::string getFlowSolverName() const
Get the control type for the well.
integer m_isThermal
flag indicating whether thermal formulation is used
integer useSurfaceConditions() const
Getter for the flag specifying whether we check rates at surface or reservoir conditions.
integer isThermal() const
getter for iso/thermal switch
bool evaluateConstraints(real64 const &time_n, WellElementSubRegion &subRegion)
Function to evaluate well constraints after applying the solution update.
WellControls::Status m_wellStatus
Well status.
string const & referenceReservoirRegion() const
Getter for the reservoir region associated with reservoir volume constraint.
static constexpr char const * referenceReservoirRegionString()
String key for reference reservoir region.
integer m_writeCSV
rates output
string m_referenceFluidModelName
name of the fluid constitutive model used as a reference for component/phase description on subregion
void setFluidSeparator(std::unique_ptr< constitutive::ConstitutiveBase > fluidSeparatorPtr)
setter for multi fluid separator
integer m_numDofPerResElement
the number of Degrees of Freedom per reservoir element
static constexpr char const * surfaceTemperatureString()
String key for the surface temperature.
virtual real64 updateWellState(MeshBody const &meshBody, ElementRegionManager const &elemManager, WellElementSubRegion &subRegion)=0
Recompute all dependent quantities from primary variables (including constitutive models)
void setRegionAverageTemperature(real64 regionAverageTemperature)
Set the reservoir average temperature when m_useSurfaceConditions == 0.
void setCurrentConstraint(WellConstraintBase *currentConstraint)
Set the current consrtaint.
TableFunction const * m_statusTable
Status table.
real64 m_regionAverageTemperature
Region average temperature used in volume rate constraint calculations.
static constexpr char const * statusTableNameString()
string key for status table name
localIndex numDofPerWellElement() const
getter for the number of degrees of freedom per well element
real64 m_surfaceTemp
Surface temperature.
bool m_wellOpen
Well open flag.
string m_statusTableName
Well status table name.
real64 m_refElevation
Reference elevation.
real64 m_initialPressureCoefficient
Tuning coefficient for the initial well pressure.
constitutive::SingleFluidBase & getSingleFluidSeparator()
Getter for single fluid separator.
localIndex numDofPerResElement() const
getter for the number of degrees of freedom per mesh element
real64 getTargetBHP(real64 const &targetTime, const ConstraintSourceId source=ConstraintSourceId::USER) const
Returns the target bottom hole pressure value.
static constexpr char const * enableIsoThermalEstimatorString()
string key for the enable iso thermal estimator flag
bool isoThermalEstimatorEnabled() const
Is isoThermalEstimator enabled.
bool thermalEffectsEnabled() const
Are thermal effects enabled.
Type m_type
Well type (as Type enum)
void setThermal(bool isThermal)
setter for iso/thermal switch
real64 m_surfacePres
Surface pressure.
string m_perfStatusTableName
Perforation status table name.
WellConstraintBase * getCurrentConstraint()
Get the current consrtaint.
bool isCrossflowEnabled() const
Getter for the flag to enable crossflow.
integer getConstraintPhaseIndex() const
Const accessor for the phase constraint index.
static constexpr char const * surfacePressureString()
String key for the surface pressure.
std::string m_flowSolverName
Name of the flow solver managing this well.
bool isWellOpen() const
Is the well open (or shut) at currentTime, status initalized in WellSolverBase::implicitStepSetup.
const real64 & getSurfaceTemperature() const
Getter for the surface temperature when m_useSurfaceConditions == 1.
static constexpr char const * wellNewtonSolverString()
string key for the well Newton solver
bool evaluateConstraints(real64 const &time_n, real64 const &dt, integer const cycleNumber, integer const coupledIterationNumber, DomainPartition &domain, MeshLevel &mesh, ElementRegionManager &elemManager, WellElementSubRegion &subRegion, DofManager const &dofManager)
Function to evaluate well constraints after applying the solution update.
static constexpr char const * estimateWellSolutionString()
string key for the estimate well solution flag
arrayView1d< real64 const > getInjectionStream() const
Const accessor for the injection stream.
virtual void computeWellPerforationRates(real64 const &time_n, real64 const &GEOS_UNUSED_PARAM(dt), ElementRegionManager &elemManager, WellElementSubRegion &subRegion)=0
Recompute the perforation rates for all the wells.
integer m_numComponents
the number of fluid components
virtual void assembleWellFluxTerms(real64 const &time, real64 const &dt, WellElementSubRegion const &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the flux terms for individual well for all connections between well elements
void setControl(ConstraintTypeId const &newControl)
Set the control type for the well.
integer m_numPhases
the max number of fluid phases
void setConstitutiveName(ElementSubRegionBase &subRegion, string const &wrapperName, string const &constitutiveType) const
Register wrapper with given name and store constitutive model name on the subregion.
static void setNextDtFromTable(TableFunction const *table, real64 const currentTime, real64 &nextDt)
Set next time step based on a table function.
virtual void assembleWellAccumulationTerms(real64 const &time, real64 const &dt, WellElementSubRegion &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the accumulation term for an individual well
static constexpr char const * inputControlString()
String key for the well input control.
virtual void initializeWell(DomainPartition &domain, Group &meshBodies, string const &meshBodyName, MeshLevel &mesh, WellElementSubRegion &subRegion, real64 const &time_n)=0
Initialize well for the beginning of a simulation or restart.
integer useMass()
is useMass option active
real64 getInitialPressureCoefficient() const
Getter for the initial pressure coefficient.
DofManager m_estimatorDoFManager
Well DofManager.
string_array const & getTargetRegionNames() const
return the list of target regions
static string getConstitutiveName(ElementSubRegionBase const &subRegion)
Get the Constitutive Name object.
const real64 & getSurfacePressure() const
Getter for the surface pressure when m_useSurfaceConditions == 1.
integer m_numDofPerWellElement
the number of Degrees of Freedom per well element
ConstraintTypeId m_inputControl
Input well controls as a Control enum.
static constexpr char const * typeString()
String key for the well type.
void setKeepVariablesConstantDuringInitStep(bool const keepVariablesConstantDuringInitStep)
Utility function to keep the well variables during a time step (used in poromechanics simulations)
virtual void resetStateToBeginningOfStep(DomainPartition &domain, string const &meshBodyName, ElementRegionManager const &elemManager, WellElementSubRegion &subRegion)=0
Reset the well state to the beginning of the time step.
void setWellState(bool open)
Set the well state.
std::string getDiscretizationName() const
return the name of the discretization object
virtual void postRestartInitialization() override
Performs initialization required after reading from a restart file.
void setDiscretizationName(const std::string &discretizationName)
set the name of the discretization object
static constexpr char const * currentControlString()
String key for the well current control.
constitutive::MultiFluidBase & getMultiFluidSeparator()
Getter for multi fluid separator.
void setFlowSolverName(const std::string &flowSolverName)
Set the control type for the well.
ConstraintTypeId getInputControl() const
Get the input control type for the well.
real64 getInjectionTemperature() const
Const accessor for the temperature of the injection stream.
void setRegionAveragePressure(real64 regionAveragePressure)
Set the reservoir average pressure when m_useSurfaceConditions == 0.
real64 setNextDt(real64 const ¤tTime, real64 const ¤tDt, WellElementSubRegion &subRegion)
function to set the next time step size
@ NOPLOT
Do not ever write to plot file.
@ NO_WRITE
Do not write into restart.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
std::string string
String type.
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.
static BASETYPE const & getConstitutiveModel(dataRepository::Group const &dataGroup, LOOKUP_TYPE const &key)
Get the Constitutive Model object.
int integer
Signed integer type.
Array< T, 1 > array1d
Alias for 1D array.
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "richardson", "preconditioner")
Declare strings associated with enumeration values.
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
static constexpr auto constitutiveModelsString()
Structure to hold scoped key names.
Struct to serve as a container for variable strings and keys.