GEOS
WellSolverBase.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLSOLVERBASE_HPP_
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLSOLVERBASE_HPP_
22 
24 
25 namespace geos
26 {
27 
28 class DomainPartition;
29 class WellControls;
30 class WellElementSubRegion;
31 
39 {
40 public:
41 
43  static string coupledSolverAttributePrefix() { return "well"; }
44 
50  WellSolverBase( const string & name,
51  Group * const parent );
52 
54  virtual ~WellSolverBase() override;
55 
57  WellSolverBase() = delete;
58 
60  WellSolverBase( WellSolverBase const & ) = delete;
61 
63  WellSolverBase( WellSolverBase && ) = default;
64 
66  WellSolverBase & operator=( WellSolverBase const & ) = delete;
67 
70 
71  virtual Group * createChild( string const & childKey, string const & childName ) override;
72 
74  virtual void expandObjectCatalogs() override;
75 
76 
81  void setFlowSolverName( string const & name ) { m_flowSolverName = name; }
82 
87  string const & getFlowSolverName() const { return m_flowSolverName; }
88 
94 
100 
105  integer isThermal() const { return m_isThermal; }
106 
111  virtual string wellElementDofName() const = 0;
112 
117  virtual string resElementDofName() const = 0;
118 
123  virtual localIndex numFluidComponents() const = 0;
124 
129  virtual localIndex numFluidPhases() const = 0;
130 
137 
143  WellControls const & getWellControls( WellElementSubRegion const & subRegion ) const;
144 
145 
151  void setPerforationStatus( real64 const & time_n, DomainPartition & domain );
152 
160  virtual void registerDataOnMesh( Group & meshBodies ) override;
161 
162  void selectWellConstraint( real64 const & time_n,
163  real64 const & dt,
164  integer const coupledIterationNumber,
165  DomainPartition & domain );
166 
167 
168  void setupWellDofs( DomainPartition & domain );
169 
170  void setupWellSystem ( DomainPartition & domain,
171  DofManager & dofManager,
172  CRSMatrix< real64, globalIndex > & localMatrix,
173  ParallelVector & rhs,
174  ParallelVector & solution,
175  bool const setSparsity = true );
176 
177  virtual void setupDofs( DomainPartition const & domain,
178  DofManager & dofManager ) const override;
179 
180  virtual void implicitStepSetup( real64 const & time_n,
181  real64 const & dt,
182  DomainPartition & domain ) override;
183 
184  virtual void implicitStepComplete( real64 const & GEOS_UNUSED_PARAM( time_n ),
185  real64 const & GEOS_UNUSED_PARAM( dt ),
186  DomainPartition & GEOS_UNUSED_PARAM( domain ) ) override {}
187 
188  virtual void applyBoundaryConditions( real64 const GEOS_UNUSED_PARAM( time_n ),
189  real64 const GEOS_UNUSED_PARAM( dt ),
191  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
193  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ) ) override {}
194 
195  virtual void applyWellBoundaryConditions( real64 const GEOS_UNUSED_PARAM( time_n ),
196  real64 const GEOS_UNUSED_PARAM( dt ),
197  ElementRegionManager & GEOS_UNUSED_PARAM( elemManager ),
198  WellElementSubRegion & GEOS_UNUSED_PARAM( subRegion ),
199  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
200  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ),
201  CRSMatrixView< real64, globalIndex const > const & GEOS_UNUSED_PARAM( localMatrix ) ) {}
202 
215  void assembleWellSystem( real64 const time,
216  real64 const dt,
217  ElementRegionManager const & elementRegionManager,
218  WellElementSubRegion & subRegion,
219  DofManager const & dofManager,
220  CRSMatrixView< real64, globalIndex const > const & localMatrix,
221  arrayView1d< real64 > const & localRhs );
222 
223  virtual void assembleSystem( real64 const time,
224  real64 const dt,
225  DomainPartition & domain,
226  DofManager const & dofManager,
227  CRSMatrixView< real64, globalIndex const > const & localMatrix,
228  arrayView1d< real64 > const & localRhs ) override;
229 
230  virtual void assembleWellFluxTerms( real64 const & GEOS_UNUSED_PARAM( time ),
231  real64 const & GEOS_UNUSED_PARAM( dt ),
232  WellElementSubRegion const & GEOS_UNUSED_PARAM( subRegion ),
233  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
235  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ) ) = 0;
236 
237 
247  virtual void assembleFluxTerms( real64 const & time_n,
248  real64 const & dt,
249  DomainPartition & domain,
250  DofManager const & dofManager,
251  CRSMatrixView< real64, globalIndex const > const & localMatrix,
252  arrayView1d< real64 > const & localRhs ) = 0;
253 
254 
255 
256  virtual void assembleWellAccumulationTerms( real64 const & time,
257  real64 const & dt,
258  WellElementSubRegion & subRegion,
259  DofManager const & dofManager,
260  CRSMatrixView< real64, globalIndex const > const & localMatrix,
261  arrayView1d< real64 > const & localRhs ) = 0;
262 
263 
271  virtual void assembleAccumulationTerms( real64 const & time_n,
272  real64 const & dt,
273  DomainPartition & domain,
274  DofManager const & dofManager,
275  CRSMatrixView< real64, globalIndex const > const & localMatrix,
276  arrayView1d< real64 > const & localRhs ) = 0;
277 
278  virtual void assembleWellConstraintTerms( real64 const & GEOS_UNUSED_PARAM( time ),
279  real64 const & GEOS_UNUSED_PARAM( dt ),
280  WellElementSubRegion const & GEOS_UNUSED_PARAM( subRegion ),
281  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
283  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ) ) = 0;
284 
285  virtual void assembleWellPressureRelations ( real64 const & GEOS_UNUSED_PARAM( time ),
286  real64 const & GEOS_UNUSED_PARAM( dt ),
287  WellElementSubRegion const & GEOS_UNUSED_PARAM( subRegion ),
288  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
290  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ) ) = 0;
301  virtual void assemblePressureRelations( real64 const & time_n,
302  real64 const & dt,
303  DomainPartition const & domain,
304  DofManager const & dofManager,
305  CRSMatrixView< real64, globalIndex const > const & localMatrix,
306  arrayView1d< real64 > const & localRhs ) = 0;
307 
313  virtual real64 updateWellState( WellElementSubRegion & subRegion ) = 0;
314  virtual void updateState( DomainPartition & domain ) override;
315 
323 
324 
325  virtual void computeWellPerforationRates( real64 const & GEOS_UNUSED_PARAM( time_n ),
326  real64 const & GEOS_UNUSED_PARAM( dt ),
327  ElementRegionManager const & GEOS_UNUSED_PARAM( elemManager ),
328  WellElementSubRegion & GEOS_UNUSED_PARAM( subRegion ) ){}
329 
334  virtual void computePerforationRates( real64 const & time_n,
335  real64 const & dt,
336  DomainPartition & domain ) = 0;
337 
338  virtual real64
339  calculateWellResidualNorm( real64 const & GEOS_UNUSED_PARAM( time_n ),
340  real64 const & GEOS_UNUSED_PARAM( dt ),
341  WellElementSubRegion const & GEOS_UNUSED_PARAM( subRegion ),
342  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
343  arrayView1d< real64 const > const & GEOS_UNUSED_PARAM( localRhs ) ) = 0;
344 
345  virtual real64
346  scalingForWellSystemSolution( ElementSubRegionBase & GEOS_UNUSED_PARAM( subRegion ),
347  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
348  arrayView1d< real64 const > const & GEOS_UNUSED_PARAM( localSolution ) ) = 0;
349 
350  virtual bool
351  checkWellSystemSolution( ElementSubRegionBase & GEOS_UNUSED_PARAM( subRegion ),
352  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
353  arrayView1d< real64 const > const & GEOS_UNUSED_PARAM( localSolution ),
354  real64 const GEOS_UNUSED_PARAM( scalingFactor ) ) = 0;
355  virtual void
356  applyWellSystemSolution( DofManager const & GEOS_UNUSED_PARAM( dofManager ),
357  arrayView1d< real64 const > const & GEOS_UNUSED_PARAM( localSolution ),
358  real64 const GEOS_UNUSED_PARAM( scalingFactor ),
359  real64 const GEOS_UNUSED_PARAM( dt ),
361  MeshLevel & GEOS_UNUSED_PARAM( mesh ),
362  WellElementSubRegion & GEOS_UNUSED_PARAM( subRegion ) ) = 0;
363 
364  bool solveNonlinearSystem( real64 const & time_n,
365  real64 const & stepDt,
366  integer const cycleNumber,
367  DomainPartition & domain,
368  MeshLevel & mesh,
369  ElementRegionManager & elementRegionManager,
370  WellElementSubRegion & subregion,
371  DofManager const & dofManager );
393  bool
394  lineSearch1( real64 const & time_n,
395  real64 const & dt,
396  integer const cycleNumber,
397  DomainPartition & domain,
398  ElementRegionManager & elemManager,
399  WellElementSubRegion & subRegion,
400  MeshLevel & mesh,
401  DofManager const & dofManager,
402  CRSMatrixView< real64, globalIndex const > const & localMatrix,
403  ParallelVector & rhs,
404  ParallelVector & solution,
405  real64 const scaleFactor,
406  real64 & lastResidual );
414  virtual real64 setNextDt( real64 const & currentTime,
415  real64 const & currentDt,
416  DomainPartition & domain ) override;
417 
426  void setKeepVariablesConstantDuringInitStep( bool const keepVariablesConstantDuringInitStep )
427  { m_keepVariablesConstantDuringInitStep = keepVariablesConstantDuringInitStep; }
428 
430  {
431  static constexpr char const * isThermalString() { return "isThermal"; }
432  static constexpr char const * writeCSVFlagString() { return "writeCSV"; }
433  static constexpr char const * timeStepFromTablesFlagString() { return "timeStepFromTables"; }
434  static constexpr char const * useNewCodeString() { return "useNewCode"; }
435 
436  static constexpr char const * fluidNamesString() { return "fluidNames"; }
437  };
438 
439 private:
440 
445  void precomputeData( DomainPartition & domain );
446 
447 protected:
448 
449  virtual void postInputInitialization() override;
450 
452 
453  virtual void initializePostSubGroups() override;
454 
459  virtual void initializeWells( DomainPartition & domain, real64 const & time_n ) = 0;
460  virtual void initializeWell( DomainPartition & domain, MeshLevel & mesh, WellElementSubRegion & subRegion, real64 const & time_n ) = 0;
467  virtual void validateWellConstraints( real64 const & time_n,
468  real64 const & dt,
469  WellElementSubRegion const & subRegion,
470  ElementRegionManager const & elemManager ) = 0;
471 
472  virtual void printRates( real64 const & time_n,
473  real64 const & dt,
474  DomainPartition & domain ) = 0;
475 
476  virtual bool evaluateConstraints( real64 const & GEOS_UNUSED_PARAM( time_n ) ,
477  real64 const & GEOS_UNUSED_PARAM( stepDt ),
478  integer const GEOS_UNUSED_PARAM( cycleNumber ),
479  integer const GEOS_UNUSED_PARAM( coupledIterationNumber ),
481  MeshLevel & GEOS_UNUSED_PARAM( mesh ),
482  ElementRegionManager & GEOS_UNUSED_PARAM( elemManager ),
483  WellElementSubRegion & GEOS_UNUSED_PARAM( subRegion ) ,
484  DofManager const & GEOS_UNUSED_PARAM( dofManager ) ) { return false;};
485 
486 
487 
490 
493 
496 
499 
502 
505 
508  string const m_ratesOutputDir;
509 
510  // flag to enable time step selection base on rates/bhp tables coordinates
511  integer m_timeStepFromTables;
512 
515 
518 
521 
522 
526  std::map< std::string, DofManager > m_estimatorDoFManager;
527 
528 
529 
530  integer m_useNewCode;
531  integer my_ctime; //tjb
532 };
533 
534 }
535 
536 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLSOLVERBASE_HPP_
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:45
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...
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
Base class for all physics solvers.
This class describes the controls used to operate a well.
This class describes a collection of local well elements and perforations.
virtual string wellElementDofName() const =0
get the name of DOF defined on well elements
bool lineSearch1(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain, ElementRegionManager &elemManager, WellElementSubRegion &subRegion, MeshLevel &mesh, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, ParallelVector &rhs, ParallelVector &solution, real64 const scaleFactor, real64 &lastResidual)
Function to perform line search.
bool m_keepVariablesConstantDuringInitStep
flag to freeze the initial state during initialization in coupled problems
virtual real64 updateSubRegionState(WellElementSubRegion &subRegion)=0
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void computePerforationRates(real64 const &time_n, real64 const &dt, DomainPartition &domain)=0
Recompute the perforation rates for all the wells.
void setPerforationStatus(real64 const &time_n, DomainPartition &domain)
Open and close perfs based on user defined perf status table.
string m_flowSolverName
name of the flow solver
virtual void expandObjectCatalogs() override
Expand catalog for schema generation.
integer m_isThermal
flag indicating whether thermal formulation is used
virtual void updateState(DomainPartition &domain) override
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void initializePostInitialConditionsPreSubGroups() override
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
std::map< std::string, DofManager > m_estimatorDoFManager
DofManagers for each wells estimator.
virtual localIndex numFluidPhases() const =0
Get the number of fluid phases.
integer m_numComponents
the number of fluid components
virtual Group * createChild(string const &childKey, string const &childName) override
creates a child group of of this PhysicsSolverBase instantiation
virtual real64 updateWellState(WellElementSubRegion &subRegion)=0
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void assembleAccumulationTerms(real64 const &time_n, real64 const &dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the accumulation term for all the well elements
virtual void initializePostSubGroups() override
Called by Initialize() after to initializing sub-Groups.
string m_referenceFluidModelName
name of the fluid constitutive model used as a reference for component/phase description
integer m_numDofPerWellElement
the number of Degrees of Freedom per well element
static string coupledSolverAttributePrefix()
String used to form the solverName used to register single-physics solvers in CoupledSolver.
string const & getFlowSolverName() const
getter for the name of the flow solver (used in UpdateState)
virtual void assembleFluxTerms(real64 const &time_n, real64 const &dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the flux terms for all connections between well elements
WellControls & getWellControls(WellElementSubRegion const &subRegion)
getter for the well controls associated to this well subRegion
localIndex numDofPerResElement() const
getter for the number of degrees of freedom per mesh element
virtual localIndex numFluidComponents() const =0
const getter for the number of fluid components
integer isThermal() const
getter for iso/thermal switch
virtual void postInputInitialization() override
integer m_writeCSV
rates output
WellControls const & getWellControls(WellElementSubRegion const &subRegion) const
const getter for the well controls associated to this well subRegion
virtual void validateWellConstraints(real64 const &time_n, real64 const &dt, WellElementSubRegion const &subRegion, ElementRegionManager const &elemManager)=0
Make sure that the well constraints are compatible.
integer m_numDofPerResElement
the number of Degrees of Freedom per reservoir element
WellSolverBase(WellSolverBase &&)=default
default move constructor
virtual void initializeWells(DomainPartition &domain, real64 const &time_n)=0
Initialize all the primary and secondary variables in all the wells.
integer m_estimateSolution
flag to use the estimator
virtual string resElementDofName() const =0
get the name of DOF defined on well elements
virtual real64 setNextDt(real64 const &currentTime, real64 const &currentDt, DomainPartition &domain) override
function to set the next time step size
localIndex numDofPerWellElement() const
getter for the number of degrees of freedom per well element
WellSolverBase()=delete
deleted default constructor
WellSolverBase & operator=(WellSolverBase const &)=delete
deleted assignment operator
WellSolverBase(WellSolverBase const &)=delete
deleted copy constructor
void assembleWellSystem(real64 const time, real64 const dt, ElementRegionManager const &elementRegionManager, WellElementSubRegion &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
function to assemble the linear system matrix and rhs
virtual void assemblePressureRelations(real64 const &time_n, real64 const &dt, DomainPartition const &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)=0
assembles the pressure relations at all connections between well elements except at the well head
integer m_numPhases
the max number of fluid phases
void setFlowSolverName(string const &name)
setter for the name of the flow solver (needed to use the flow kernels like UpdateFluid)
virtual ~WellSolverBase() override
default destructor
WellSolverBase & operator=(WellSolverBase &&)=delete
deleted move operator
void setKeepVariablesConstantDuringInitStep(bool const keepVariablesConstantDuringInitStep)
Utility function to keep the well variables during a time step (used in poromechanics simulations)
virtual void assembleSystem(real64 const time, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
function to assemble the linear system matrix and rhs
WellSolverBase(const string &name, Group *const parent)
main constructor for Group Objects
virtual void registerDataOnMesh(Group &meshBodies) override
Register wrappers that contain data on the mesh objects.
virtual void implicitStepSetup(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
function to perform setup for implicit timestep
virtual void setupDofs(DomainPartition const &domain, DofManager &dofManager) const override
Populate degree-of-freedom manager with fields relevant to this solver.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
Definition: DataTypes.hpp:305
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
int integer
Signed integer type.
Definition: DataTypes.hpp:81
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.
Structure to hold scoped key names.