GEOS
CompositionalMultiphaseWell.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_COMPOSITIONALMULTIPHASEWELL_HPP_
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_COMPOSITIONALMULTIPHASEWELL_HPP_
22 
23 #include "common/DataTypes.hpp"
24 #include "constitutive/fluid/multifluid/Layouts.hpp"
25 #include "constitutive/relativePermeability/Layouts.hpp"
26 #include "mesh/MeshLevel.hpp"
27 
29 
30 #include "physicsSolvers/fluidFlow/wells/WellConstraintsBase.hpp"
31 #include "physicsSolvers/fluidFlow/wells/WellControls.hpp"
32 namespace geos
33 {
34 
35 namespace constitutive
36 {
37 class ConstitutiveManager;
38 class MultiFluidBase;
39 }
40 
41 namespace compositionalMultiphaseStatistics
42 {
43 class StatsAggregator;
44 }
45 
52 {
53 public:
54 
60  CompositionalMultiphaseWell( const string & name,
61  Group * const parent );
62 
65 
68 
71 
74 
77 
81  virtual ~CompositionalMultiphaseWell() override;
82 
84  void setReservoirStatsAggregator( std::unique_ptr< compositionalMultiphaseStatistics::StatsAggregator > aggregator );
85 
86 
87  virtual void registerWellDataOnMesh( WellElementSubRegion & subRegion ) override;
101  virtual void initializeWell( DomainPartition & domain, Group & meshBodies, string const & meshBodyName, MeshLevel & mesh, WellElementSubRegion & subRegion, real64 const & time_n ) override;
102 
103  virtual void initializeWellPostInitialConditionsPreSubGroups( WellElementSubRegion & subRegion ) override;
104 
105  virtual bool isCompositional() const override { return true; }
106 
107 
111  virtual void assembleWellAccumulationTerms( real64 const & time,
112  real64 const & dt,
113  WellElementSubRegion & subRegion,
114  DofManager const & dofManager,
115  CRSMatrixView< real64, globalIndex const > const & localMatrix,
116  arrayView1d< real64 > const & localRhs ) override;
120  virtual void assembleWellPressureRelations( real64 const & time_n,
121  real64 const & dt,
122  WellElementSubRegion const & subRegion,
123  DofManager const & dofManager,
124  CRSMatrixView< real64, globalIndex const > const & localMatrix,
125  arrayView1d< real64 > const & localRhs ) override;
126 
130  virtual void assembleWellConstraintTerms( real64 const & time_n,
131  real64 const & dt,
132  WellElementSubRegion const & subRegion,
133  DofManager const & dofManager,
134  CRSMatrixView< real64, globalIndex const > const & localMatrix,
135  arrayView1d< real64 > const & localRhs ) override;
139  virtual void computeWellPerforationRates( real64 const & time_n,
140  real64 const & GEOS_UNUSED_PARAM( dt ),
141  ElementRegionManager & elemManager,
142  WellElementSubRegion & subRegion ) override;
143 
147  virtual void assembleWellFluxTerms( real64 const & time,
148  real64 const & dt,
149  WellElementSubRegion const & subRegion,
150  DofManager const & dofManager,
151  CRSMatrixView< real64, globalIndex const > const & localMatrix,
152  arrayView1d< real64 > const & localRhs ) override;
166  virtual array1d< real64 >
168  real64 const & dt,
169  NonlinearSolverParameters const & nonlinearSolverParameters,
170  WellElementSubRegion const & subRegion,
171  DofManager const & dofManager,
172  arrayView1d< real64 const > const & localRhs ) override;
173 
174 
175  virtual real64
176  calculateWellResidualNorm( real64 const & time_n,
177  real64 const & dt,
178  NonlinearSolverParameters const & nonlinearSolverParameters,
179  WellElementSubRegion const & subRegion,
180  DofManager const & dofManager,
181  arrayView1d< real64 const > const & localRhs ) override;
182 
187  DofManager const & dofManager,
188  real64 & maxDeltaPres,
189  real64 & maxDeltaCompDens,
190  real64 & maxDeltaTemp,
191  real64 & minPresScalingFactor,
192  real64 & minCompDensScalingFactor,
193  real64 & minTempScalingFactor,
194  arrayView1d< real64 const > const & localSolution );
195 
196  virtual real64 scalingForWellSystemSolution( WellElementSubRegion & subRegion,
197  DofManager const & dofManager,
198  arrayView1d< real64 const > const & localSolution ) override;
199 
203  virtual bool
205  DofManager const & dofManager,
206  arrayView1d< real64 const > const & localSolution,
207  real64 const scalingFactor,
208  real64 & minPressure,
209  real64 & minDensity,
210  real64 & minTotalDensity,
211  ElementsReporterBuffer & negPressureIds,
212  ElementsReporterBuffer & negDensityIds,
213  ElementsReporterBuffer & negTotalDensityIds ) override;
214 
219  virtual void
220  applyWellSystemSolution( DofManager const & dofManager,
221  arrayView1d< real64 const > const & localSolution,
222  real64 const scalingFactor,
223  real64 const dt,
224  DomainPartition & domain,
225  MeshLevel & mesh,
226  WellElementSubRegion & subRegion ) override;
227 
228  virtual void applyWellBoundaryConditions( real64 const time_n,
229  real64 const dt,
230  ElementRegionManager & elemManager,
231  WellElementSubRegion & subRegion,
232  DofManager const & dofManager,
233  arrayView1d< real64 > const & localRhs,
234  CRSMatrixView< real64, globalIndex const > const & localMatrix ) override;
235 
236 
238  string const & meshBodyName, ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) override;
239 
240  virtual void implicitStepSetup( real64 const & time_n,
241  real64 const & GEOS_UNUSED_PARAM( dt ),
242  DomainPartition & domain,
243  string const & meshBodyName,
244  ElementRegionManager & elemManager,
245  WellElementSubRegion & subRegion ) override;
246 
247  virtual void
248  implicitStepComplete( real64 const & time,
249  real64 const & dt,
250  WellElementSubRegion const & subRegion ) override;
251 
252  virtual void printRates( real64 const & time_n,
253  real64 const & dt,
254  WellElementSubRegion const & subRegion ) override;
255 
263 
269 
276 
283 
290  void updateSeparator( real64 time_n,
291  MeshBody const & meshBody,
292  ElementRegionManager const & elemManager,
293  WellElementSubRegion & subRegion );
294 
302 
309 
314  void updateTotalMassDensity( WellElementSubRegion & subRegion ) const;
315 
320  virtual real64 updateWellState( MeshBody const & meshBody,
321  ElementRegionManager const & elemManager,
322  WellElementSubRegion & subRegion ) override;
323 
324  virtual real64 updateSubRegionState( real64 time_n,
325  MeshBody const & meshBody,
326  ElementRegionManager const & elemManager,
327  WellElementSubRegion & subRegion ) override;
328 
329  virtual string wellElementDofName() const override { return viewKeyStruct::dofFieldString(); }
330 
331  virtual string resElementDofName() const override { return CompositionalMultiphaseBase::viewKeyStruct::elemDofFieldString(); }
332 
333  virtual localIndex numFluidComponents() const override { return m_numComponents; }
334 
335  virtual localIndex numFluidPhases() const override { return m_numPhases; }
336 
337  integer useTotalMassEquation() const { return m_useTotalMassEquation; }
338 
344 
345 
347  {
348  static constexpr char const * dofFieldString() { return "wellVars"; }
349 
350  // inputs
351 
352  static constexpr char const * useMassFlagString() { return CompositionalMultiphaseBase::viewKeyStruct::useMassFlagString(); }
353 
354  static constexpr char const * useTotalMassEquationString() { return CompositionalMultiphaseBase::viewKeyStruct::useTotalMassEquationString(); }
355 
356  static constexpr char const * maxCompFracChangeString() { return CompositionalMultiphaseBase::viewKeyStruct::maxCompFracChangeString(); }
357 
358  static constexpr char const * maxRelativePresChangeString() { return "maxRelativePressureChange"; }
359 
360  static constexpr char const * maxAbsolutePresChangeString() { return "maxAbsolutePressureChange"; }
361 
362  static constexpr char const * maxRelativeCompDensChangeString() { return "maxRelativeCompDensChange"; }
363 
364  static constexpr char const * maxRelativeTempChangeString() { return "maxRelativeTemperatureChange"; }
365 
366  static constexpr char const * allowLocalCompDensChoppingString() { return CompositionalMultiphaseBase::viewKeyStruct::allowLocalCompDensChoppingString(); }
367 
368 
369 
370  } viewKeysCompMultiphaseWell;
371 
381  void validateFluidModel( constitutive::MultiFluidBase const & fluid, constitutive::MultiFluidBase const & referenceFluid )const;
382 
383 protected:
384 
385  virtual void postInputInitialization() override;
386 
387  virtual void initializePostSubGroups() override;
388 
390 
391  void saveState( WellElementSubRegion & subRegion );
392  virtual void postRestartInitialization( ) override;
393 
394 
402  virtual void validateWellConstraints( real64 const & time_n,
403  real64 const & dt,
404  WellElementSubRegion const & subRegion ) override;
405 
409  virtual void createSeparator( WellElementSubRegion & subRegion ) override;
411  std::unique_ptr< compositionalMultiphaseStatistics::StatsAggregator > m_reservoirStatsAggregator;
412 
413 
414 private:
415 
416  struct ReferenceConditions
417  {
418  real64 pressure;
419  real64 temperature;
420  };
421 
422 
423  virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override;
424 
425  void precomputeReferenceConditions( real64 time_n,
426  Group & meshBodies,
427  MeshBody & meshBody,
428  WellElementSubRegion const & subRegion );
429 
430  ReferenceConditions getReferenceConditions( WellElementSubRegion const & subRegion );
431 
432 
434  integer m_useTotalMassEquation;
435 
437  real64 m_maxCompFracChange;
438 
440  real64 m_maxRelativePresChange;
441 
443  real64 m_maxAbsolutePresChange;
444 
446  real64 m_maxRelativeCompDensChange;
447 
449  real64 m_maxRelativeTempChange;
450 
452  real64 m_minScalingFactor;
453 
455  integer m_allowCompDensChopping;
456 
457 
458 
459 };
460 
461 } // namespace geos
462 
463 
464 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_COMPOSITIONALMULTIPHASEWELL_HPP_
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:97
void updateFluidModel(WellElementSubRegion &subRegion)
Update all relevant fluid models using current values of pressure and composition.
void chopNegativeDensities(WellElementSubRegion &subRegion)
Sets all the negative component densities (if any) to zero.
CompositionalMultiphaseWell(CompositionalMultiphaseWell const &)=delete
deleted copy constructor
void updateGlobalComponentFraction(WellElementSubRegion &subRegion) const
Recompute global component fractions from primary variables (component densities)
void updateTotalMassDensity(WellElementSubRegion &subRegion) const
Recompute total mass densities from mass density and phase volume fractions.
void calculateReferenceElementRates(WellElementSubRegion &subRegion)
Calculate well rates at reference element.
virtual void initializePostInitialConditionsPreSubGroups() override
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
void updateSeparator(real64 time_n, MeshBody const &meshBody, ElementRegionManager const &elemManager, WellElementSubRegion &subRegion)
Update well separator using current values of pressure and composition at the reference element.
virtual void createSeparator(WellElementSubRegion &subRegion) override
Create well separator.
void updateVolRatesForConstraint(WellElementSubRegion const &subRegion)
Recompute the volumetric rates that are used in the well constraints.
void validateFluidModel(constitutive::MultiFluidBase const &fluid, constitutive::MultiFluidBase const &referenceFluid) const
Checks fluild model compatibility and validity.
virtual void postRestartInitialization() override
Performs initialization required after reading from a restart file.
CompositionalMultiphaseWell(CompositionalMultiphaseWell &&)=delete
deleted move constructor
virtual void validateWellConstraints(real64 const &time_n, real64 const &dt, WellElementSubRegion const &subRegion) override
Make sure that the well constraints are compatible.
CompositionalMultiphaseWell(const string &name, Group *const parent)
main constructor for Group Objects
std::unique_ptr< compositionalMultiphaseStatistics::StatsAggregator > m_reservoirStatsAggregator
optional statistics aggregator to get the average pressure of simulated region
virtual real64 updateWellState(MeshBody const &meshBody, ElementRegionManager const &elemManager, WellElementSubRegion &subRegion) override
Recompute all dependent quantities from primary variables (including constitutive models)
CompositionalMultiphaseWell & operator=(CompositionalMultiphaseWell &&)=delete
deleted move operator
CompositionalMultiphaseWell & operator=(CompositionalMultiphaseWell const &)=delete
deleted assignment operator
CompositionalMultiphaseWell()=delete
deleted default constructor
virtual void postInputInitialization() override
real64 updatePhaseVolumeFraction(WellElementSubRegion &subRegion) const
Recompute phase volume fractions (saturations) from constitutive and primary variables.
void updateBHPForConstraint(WellElementSubRegion &subRegion)
Recompute the current BHP pressure.
virtual void initializePostSubGroups() override
Called by Initialize() after to initializing sub-Groups.
virtual ~CompositionalMultiphaseWell() override
default destructor
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...
A buffer to count and store element ids during kernel execution. This facilitates the reporting mecha...
The class is used to manage mesh body.
Definition: MeshBody.hpp:36
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
This class describes the controls used to operate a well.
This class describes a collection of local well elements and perforations.
Reponsible of computing physical statistics over the grid, registering the result in the data reposit...
virtual void resetStateToBeginningOfStep(DomainPartition &domain, string const &meshBodyName, ElementRegionManager const &elemManager, WellElementSubRegion &subRegion) override
Reset the well state to the beginning of the time step.
virtual array1d< real64 > calculateLocalWellResidualNorm(real64 const &time_n, real64 const &dt, NonlinearSolverParameters const &nonlinearSolverParameters, WellElementSubRegion const &subRegion, DofManager const &dofManager, arrayView1d< real64 const > const &localRhs) override
real64 scalingForLocalSystemSolution(WellElementSubRegion &subRegion, DofManager const &dofManager, real64 &maxDeltaPres, real64 &maxDeltaCompDens, real64 &maxDeltaTemp, real64 &minPresScalingFactor, real64 &minCompDensScalingFactor, real64 &minTempScalingFactor, arrayView1d< real64 const > const &localSolution)
virtual bool checkWellSystemSolution(WellElementSubRegion &subRegion, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor, real64 &minPressure, real64 &minDensity, real64 &minTotalDensity, ElementsReporterBuffer &negPressureIds, ElementsReporterBuffer &negDensityIds, ElementsReporterBuffer &negTotalDensityIds) override
virtual void applyWellSystemSolution(DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor, real64 const dt, DomainPartition &domain, MeshLevel &mesh, WellElementSubRegion &subRegion) override
virtual void initializeWell(DomainPartition &domain, Group &meshBodies, string const &meshBodyName, MeshLevel &mesh, WellElementSubRegion &subRegion, real64 const &time_n) override
Initialize well for the beginning of a simulation or restart.
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) override
assembles the well momentum terms for an individual well
virtual void assembleWellAccumulationTerms(real64 const &time, real64 const &dt, WellElementSubRegion &subRegion, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
assembles the accumulation term for an individual well
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) override
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) override
assembles the well constraint terms for an individual well
virtual void computeWellPerforationRates(real64 const &time_n, real64 const &GEOS_UNUSED_PARAM(dt), ElementRegionManager &elemManager, WellElementSubRegion &subRegion) override
Recompute the perforation rates for all the wells.
integer m_numComponents
the number of fluid components
integer m_numPhases
the max number of fluid phases
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
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
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
Struct to serve as a container for variable strings and keys.