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 "constitutive/fluid/multifluid/Layouts.hpp"
24 #include "constitutive/relativePermeability/Layouts.hpp"
27 
28 #include "physicsSolvers/fluidFlow/wells/WellConstraintsBase.hpp"
29 
30 namespace geos
31 {
32 
33 namespace constitutive
34 {
35 class ConstitutiveManager;
36 class MultiFluidBase;
37 }
38 
45 {
46 public:
47 
53  CompositionalMultiphaseWell( const string & name,
54  Group * const parent );
55 
58 
61 
64 
67 
70 
74  virtual ~CompositionalMultiphaseWell() override = default;
75 
80  static string catalogName() { return "CompositionalMultiphaseWell"; }
84  string getCatalogName() const override { return catalogName(); }
85 
86  virtual void registerDataOnMesh( Group & meshBodies ) override;
87 
88 
97  virtual real64
98  calculateWellResidualNorm( real64 const & time_n,
99  real64 const & dt,
100  WellElementSubRegion const & subRegion,
101  DofManager const & dofManager,
102  arrayView1d< real64 const > const & localRhs ) override;
103 
104  virtual real64
105  calculateResidualNorm( real64 const & time_n,
106  real64 const & dt,
107  DomainPartition const & domain,
108  DofManager const & dofManager,
109  arrayView1d< real64 const > const & localRhs ) override;
110 
111  virtual real64
112  scalingForWellSystemSolution( ElementSubRegionBase & subRegion,
113  DofManager const & dofManager,
114  arrayView1d< real64 const > const & localSolution ) override;
115 
116  virtual real64
118  DofManager const & dofManager,
119  arrayView1d< real64 const > const & localSolution ) override;
120 
121  virtual bool
122  checkWellSystemSolution( ElementSubRegionBase & subRegion,
123  DofManager const & dofManager,
124  arrayView1d< real64 const > const & localSolution,
125  real64 const scalingFactor ) override;
126 
127  virtual bool
129  DofManager const & dofManager,
130  arrayView1d< real64 const > const & localSolution,
131  real64 const scalingFactor ) override;
132 
133  virtual void
134  applyWellSystemSolution( DofManager const & dofManager,
135  arrayView1d< real64 const > const & localSolution,
136  real64 const scalingFactor,
137  real64 const dt,
138  DomainPartition & domain,
139  MeshLevel & mesh,
140  WellElementSubRegion & subRegion ) override;
141 
142  virtual void
143  applySystemSolution( DofManager const & dofManager,
144  arrayView1d< real64 const > const & localSolution,
145  real64 const scalingFactor,
146  real64 const dt,
147  DomainPartition & domain ) override;
148 
149  virtual void
151 
152  virtual void
153  implicitStepSetup( real64 const & time,
154  real64 const & dt,
155  DomainPartition & domain ) override;
156 
157  virtual void
159  real64 const & dt,
160  DomainPartition & domain ) override;
161 
169 
176 
183 
190 
197 
205 
212 
217  void updateTotalMassDensity( WellElementSubRegion & subRegion ) const;
218 
223  virtual void computeWellPerforationRates( real64 const & time_n,
224  real64 const & GEOS_UNUSED_PARAM( dt ),
225  ElementRegionManager const & elemManager,
226  WellElementSubRegion & subRegion )override;
227 
228 
233  virtual void computePerforationRates( real64 const & time_n,
234  real64 const & dt, DomainPartition & domain ) override;
235 
240  virtual real64 updateWellState( WellElementSubRegion & subRegion ) override;
241  virtual void updateState( DomainPartition & domain ) override;
242 
243  virtual real64 updateSubRegionState( WellElementSubRegion & subRegion ) override;
244 
245  virtual string wellElementDofName() const override { return viewKeyStruct::dofFieldString(); }
246 
247  virtual string resElementDofName() const override { return CompositionalMultiphaseBase::viewKeyStruct::elemDofFieldString(); }
248 
249  virtual localIndex numFluidComponents() const override { return m_numComponents; }
250 
251  virtual localIndex numFluidPhases() const override { return m_numPhases; }
252 
253  integer useTotalMassEquation() const { return m_useTotalMassEquation; }
254 
255  virtual void assembleWellFluxTerms( real64 const & time,
256  real64 const & dt,
257  WellElementSubRegion const & subRegion,
258  DofManager const & dofManager,
259  CRSMatrixView< real64, globalIndex const > const & localMatrix,
260  arrayView1d< real64 > const & localRhs ) override;
261 
272  virtual void assembleFluxTerms( real64 const & time_n,
273  real64 const & dt,
274  DomainPartition & domain,
275  DofManager const & dofManager,
276  CRSMatrixView< real64, globalIndex const > const & localMatrix,
277  arrayView1d< real64 > const & localRhs )override;
278 
279  virtual void assembleWellAccumulationTerms( real64 const & time,
280  real64 const & dt,
281  WellElementSubRegion & subRegion,
282  DofManager const & dofManager,
283  CRSMatrixView< real64, globalIndex const > const & localMatrix,
284  arrayView1d< real64 > const & localRhs ) override;
285 
293  virtual void assembleAccumulationTerms( real64 const & time_n,
294  real64 const & dt,
295  DomainPartition & domain,
296  DofManager const & dofManager,
297  CRSMatrixView< real64, globalIndex const > const & localMatrix,
298  arrayView1d< real64 > const & localRhs ) override;
299 
300  virtual void assembleWellConstraintTerms( real64 const & time_n,
301  real64 const & dt,
302  WellElementSubRegion const & subRegion,
303  DofManager const & dofManager,
304  CRSMatrixView< real64, globalIndex const > const & localMatrix,
305  arrayView1d< real64 > const & localRhs ) override;
306 
307  virtual void applyWellBoundaryConditions( real64 const time_n,
308  real64 const dt,
309  ElementRegionManager & elemManager,
310  WellElementSubRegion & subRegion,
311  DofManager const & dofManager,
312  arrayView1d< real64 > const & localRhs,
313  CRSMatrixView< real64, globalIndex const > const & localMatrix ) override;
314 
315  virtual void applyBoundaryConditions( real64 const GEOS_UNUSED_PARAM( time_n ),
316  real64 const GEOS_UNUSED_PARAM( dt ),
318  DofManager const & GEOS_UNUSED_PARAM( dofManager ),
320  arrayView1d< real64 > const & GEOS_UNUSED_PARAM( localRhs ) ) override;
321 
322 
332  virtual void assembleWellPressureRelations( real64 const & time_n,
333  real64 const & dt,
334  WellElementSubRegion const & subRegion,
335  DofManager const & dofManager,
336  CRSMatrixView< real64, globalIndex const > const & localMatrix,
337  arrayView1d< real64 > const & localRhs ) override;
338 
339  virtual void assemblePressureRelations( real64 const & time_n,
340  real64 const & dt,
341  DomainPartition const & domain,
342  DofManager const & dofManager,
343  CRSMatrixView< real64, globalIndex const > const & localMatrix,
344  arrayView1d< real64 > const & localRhs ) override;
345 
346 
352 
353  void chopNegativeDensities( WellElementSubRegion & subRegion );
354 
356  {
357  static constexpr char const * dofFieldString() { return "compositionalWellVars"; }
358 
359  // inputs
360 
361  static constexpr char const * useMassFlagString() { return CompositionalMultiphaseBase::viewKeyStruct::useMassFlagString(); }
362 
363  static constexpr char const * useTotalMassEquationString() { return CompositionalMultiphaseBase::viewKeyStruct::useTotalMassEquationString(); }
364 
365  static constexpr char const * maxCompFracChangeString() { return CompositionalMultiphaseBase::viewKeyStruct::maxCompFracChangeString(); }
366 
367  static constexpr char const * maxRelativePresChangeString() { return "maxRelativePressureChange"; }
368 
369  static constexpr char const * maxAbsolutePresChangeString() { return "maxAbsolutePressureChange"; }
370 
371  static constexpr char const * maxRelativeCompDensChangeString() { return "maxRelativeCompDensChange"; }
372 
373  static constexpr char const * maxRelativeTempChangeString() { return "maxRelativeTemperatureChange"; }
374 
375  static constexpr char const * allowLocalCompDensChoppingString() { return CompositionalMultiphaseBase::viewKeyStruct::allowLocalCompDensChoppingString(); }
376 
377  // control data (not registered on the mesh)
378 
379  static constexpr char const * massDensityString() { return "massDensity";}
380 
381  static constexpr char const * currentBHPString() { return "currentBHP"; }
382  static constexpr char const * dCurrentBHPString() { return "dCurrentBHP"; }
383 
384  static constexpr char const * dCurrentBHP_dPresString() { return "dCurrentBHP_dPres"; }
385  static constexpr char const * dCurrentBHP_dCompDensString() { return "dCurrentBHP_dCompDens"; }
386 
387  static constexpr char const * currentPhaseVolRateString() { return "currentPhaseVolumetricRate"; }
388  static constexpr char const * dCurrentPhaseVolRateString() { return "dCurrentPhaseVolumetricRate"; }
389 
390 
391  static constexpr char const * dCurrentPhaseVolRate_dPresString() { return "dCurrentPhaseVolumetricRate_dPres"; }
392 
393  static constexpr char const * dCurrentPhaseVolRate_dCompDensString() { return "dCurrentPhaseVolumetricRate_dCompDens"; }
394 
395  static constexpr char const * dCurrentPhaseVolRate_dRateString() { return "dCurrentPhaseVolumetricRate_dRate"; }
396 
397  static constexpr char const * currentTotalVolRateString() { return "currentTotalVolumetricRate"; }
398  static constexpr char const * dCurrentTotalVolRateString() { return "dCurrentTotalVolumetricRate"; }
399 
400  static constexpr char const * currentMassRateString() { return "currentMassRate"; }
401 
402  static constexpr char const * dCurrentTotalVolRate_dPresString() { return "dCurrentTotalVolumetricRate_dPres"; }
403 
404  static constexpr char const * dCurrentTotalVolRate_dCompDensString() { return "dCurrentTotalVolumetricRate_dCompDens"; }
405 
406  static constexpr char const * dCurrentTotalVolRate_dRateString() { return "dCurrentTotalVolumetricRate_dRate"; }
407 
408  } viewKeysCompMultiphaseWell;
409 
410 protected:
411 
412  virtual void postInputInitialization() override;
413 
414  virtual void initializePostSubGroups() override;
415 
417 
418  void saveState( WellElementSubRegion & subRegion );
419  virtual void postRestartInitialization() override final;
420  /*
421  * @brief Utility function that checks the consistency of the constitutive models
422  * @param[in] domain the domain partition
423  * @detail
424  * This function will produce an error if one of the well constitutive models
425  * is incompatible with the corresponding models in reservoir
426  * regions connected to that particular well.
427  */
428  void validateConstitutiveModels( DomainPartition const & domain ) const;
429 
434  void validateWellControlsForFluid( WellControls const & wellControls,
435  constitutive::MultiFluidBase const & fluid ) const;
436 
437 
445  virtual void validateWellConstraints( real64 const & time_n,
446  real64 const & dt,
447  WellElementSubRegion const & subRegion,
448  ElementRegionManager const & elemManager ) override;
449 
454 
455  void printRates( real64 const & time_n,
456  real64 const & dt,
457  DomainPartition & domain ) override;
458 
459  virtual bool evaluateConstraints( real64 const & time_n,
460  real64 const & stepDt,
461  integer const cycleNumber,
462  integer const coupledIterationNumber,
463  DomainPartition & domain,
464  MeshLevel & mesh,
465  ElementRegionManager & elemManager,
466  WellElementSubRegion & subRegion,
467  DofManager const & dofManager ) override;
468 
469 private:
470 
475  void initializeWells( DomainPartition & domain, real64 const & time_n ) override;
476 
477  void initializeWell( DomainPartition & domain, MeshLevel & mesh, WellElementSubRegion & subRegion, real64 const & time_n ) override;
478 
479  virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override;
480 
481  template< typename ... GROUPTYPES >
482  void selectLimitingConstraint( real64 const & time_n, integer const coupledIterationNumber, WellElementSubRegion & subRegion );
483 
484  void solveConstraint( WellConstraintBase * constraint,
485  real64 const & time_n,
486  real64 const & dt,
487  integer const cycleNumber,
488  integer const coupledIterationNumber,
489  DomainPartition & domain,
490  MeshLevel & mesh,
491  ElementRegionManager & elemManager,
492  WellElementSubRegion & subRegion,
493  DofManager const & dofManager );
494 
495 
497  integer m_useMass;
498 
500  integer m_useTotalMassEquation;
501 
503  real64 m_maxCompFracChange;
504 
506  real64 m_maxRelativePresChange;
507 
509  real64 m_maxAbsolutePresChange;
510 
512  real64 m_maxRelativeCompDensChange;
513 
515  real64 m_maxRelativeTempChange;
516 
518  real64 m_minScalingFactor;
519 
521  integer m_allowCompDensChopping;
522 
524  localIndex m_targetPhaseIndex;
525 
526 
527 
528 };
529 
530 } // namespace geos
531 
532 
533 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_COMPOSITIONALMULTIPHASEWELL_HPP_
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
void updateFluidModel(WellElementSubRegion &subRegion)
Update all relevant fluid models using current values of pressure and composition.
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) override
assembles the flux terms for all connections between well elements
virtual void updateState(DomainPartition &domain) override
Recompute all dependent quantities from primary variables (including constitutive models)
void chopNegativeDensities(DomainPartition &domain)
Sets all the negative component densities (if any) to zero.
virtual string wellElementDofName() const override
get the name of DOF defined on well elements
CompositionalMultiphaseWell(CompositionalMultiphaseWell const &)=delete
deleted copy constructor
void validateWellControlsForFluid(WellControls const &wellControls, constitutive::MultiFluidBase const &fluid) const
Checks if the WellControls parameters are within the fluid tables ranges.
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 pressure relations at all connections between well elements except at the well head
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.
CompositionalMultiphaseWell(CompositionalMultiphaseWell &&)=default
default move constructor
void calculateReferenceElementRates(WellElementSubRegion &subRegion)
Calculate well rates at reference element.
virtual void initializePostInitialConditionsPreSubGroups() override
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
virtual real64 updateWellState(WellElementSubRegion &subRegion) override
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void computePerforationRates(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
Recompute the perforation rates for all the wells.
void updateSeparator(WellElementSubRegion &subRegion)
Update well separator using current values of pressure and composition at the reference element.
virtual real64 updateSubRegionState(WellElementSubRegion &subRegion) override
Recompute all dependent quantities from primary variables (including constitutive models)
virtual ~CompositionalMultiphaseWell() override=default
default destructor
virtual localIndex numFluidComponents() const override
const getter for the number of fluid components
virtual void validateWellConstraints(real64 const &time_n, real64 const &dt, WellElementSubRegion const &subRegion, ElementRegionManager const &elemManager) override
Make sure that the well constraints are compatible.
CompositionalMultiphaseWell(const string &name, Group *const parent)
main constructor for Group Objects
static string catalogName()
name of the node manager in the object catalog
virtual void registerDataOnMesh(Group &meshBodies) override
Register wrappers that contain data on the mesh objects.
void createSeparator()
Create well separator.
CompositionalMultiphaseWell & operator=(CompositionalMultiphaseWell &&)=delete
deleted move operator
virtual void postRestartInitialization() override final
Performs initialization required after reading from a restart file.
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) override
assembles the accumulation term for all the well elements
virtual void computeWellPerforationRates(real64 const &time_n, real64 const &GEOS_UNUSED_PARAM(dt), ElementRegionManager const &elemManager, WellElementSubRegion &subRegion) override
Recompute the perforation rates for all the wells.
void updateVolRatesForConstraint(WellElementSubRegion &subRegion)
Recompute the volumetric rates that are used in the well constraints.
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) override
assembles the pressure relations at all connections between well elements except at the well head
virtual localIndex numFluidPhases() const override
Get the number of fluid phases.
CompositionalMultiphaseWell & operator=(CompositionalMultiphaseWell const &)=delete
deleted assignment operator
virtual string resElementDofName() const override
get the name of DOF defined on well elements
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.
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
This class describes the controls used to operate a well.
This class describes a collection of local well elements and perforations.
integer m_numComponents
the number of fluid components
integer m_numPhases
the max number of fluid phases
virtual real64 scalingForSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution) override
Function to determine if the solution vector should be scaled back in order to maintain a known const...
virtual void implicitStepSetup(real64 const &time, real64 const &dt, DomainPartition &domain) override
function to perform setup for implicit timestep
virtual void resetStateToBeginningOfStep(DomainPartition &domain) override
reset state of physics back to the beginning of the step.
virtual void implicitStepComplete(real64 const &time, real64 const &dt, DomainPartition &domain) override
perform cleanup for implicit timestep
virtual real64 calculateResidualNorm(real64 const &time_n, real64 const &dt, DomainPartition const &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localRhs) override
calculate the norm of the global system residual
virtual void applySystemSolution(DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor, real64 const dt, DomainPartition &domain) override
Function to apply the solution vector to the state.
virtual bool checkSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor) override
Function to check system solution for physical consistency and constraint violation.
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