GEOS
ImmiscibleMultiphaseFlow.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_IMMISCIBLEMULTIPHASEFLOW_HPP_
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_IMMISCIBLEMULTIPHASEFLOW_HPP_
22 
26 #include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" // For GravityDensityScheme
27 namespace geos
28 {
29 
30 //START_SPHINX_INCLUDE_00
37 {
38 public:
39 
45  ImmiscibleMultiphaseFlow( const string & name,
46  Group * const parent );
47 
50 
53 
56 
59 
62 
66  virtual ~ImmiscibleMultiphaseFlow() override = default;
71  static string catalogName() { return "ImmiscibleMultiphaseFlow"; }
75  string getCatalogName() const override { return catalogName(); }
76 
77  virtual void registerDataOnMesh( Group & meshBodies ) override final;
78 
79  virtual void
80  implicitStepSetup( real64 const & time_n,
81  real64 const & dt,
82  DomainPartition & domain ) override;
83 
84  virtual void
85  assembleSystem( real64 const time_n,
86  real64 const dt,
87  DomainPartition & domain,
88  DofManager const & dofManager,
90  arrayView1d< real64 > const & localRhs ) override;
91 
92  virtual real64
93  calculateResidualNorm( real64 const & time_n,
94  real64 const & dt,
95  DomainPartition const & domain,
96  DofManager const & dofManager,
97  arrayView1d< real64 const > const & localRhs ) override;
98 
99  virtual void
100  applySystemSolution( DofManager const & dofManager,
101  arrayView1d< real64 const > const & localSolution,
102  real64 const scalingFactor,
103  real64 const dt,
104  DomainPartition & domain ) override;
105 
106  virtual void
107  setupDofs( DomainPartition const & domain,
108  DofManager & dofManager ) const override;
109 
110  virtual void
112  real64 const dt,
113  DomainPartition & domain,
114  DofManager const & dofManager,
115  CRSMatrixView< real64, globalIndex const > const & localMatrix,
116  arrayView1d< real64 > const & localRhs ) override;
117 
118  virtual void
120 
121  virtual void
123  real64 const & dt,
124  DomainPartition & domain ) override;
125 
126  void updateFluidState( ElementSubRegionBase & subRegion ) const;
127 
128  void updateVolumeConstraint( ElementSubRegionBase & subRegion ) const;
129 
130  virtual void saveConvergedState( ElementSubRegionBase & subRegion ) const override final;
131 
132  virtual void updateState( DomainPartition & domain ) override final;
133 
138  integer numFluidPhases() const { return m_numPhases; }
139 
150  DofManager const & dofManager,
151  CRSMatrixView< real64, globalIndex const > const & localMatrix,
152  arrayView1d< real64 > const & localRhs ) const;
153 
163  virtual void
165  DomainPartition const & domain,
166  DofManager const & dofManager,
167  CRSMatrixView< real64, globalIndex const > const & localMatrix,
168  arrayView1d< real64 > const & localRhs ) const;
169 
179  void applyDirichletBC( real64 const time,
180  real64 const dt,
181  DofManager const & dofManager,
182  DomainPartition & domain,
183  CRSMatrixView< real64, globalIndex const > const & localMatrix,
184  arrayView1d< real64 > const & localRhs ) const;
185 
186  void applySourceFluxBC( real64 const time,
187  real64 const dt,
188  DofManager const & dofManager,
189  DomainPartition & domain,
190  CRSMatrixView< real64, globalIndex const > const & localMatrix,
191  arrayView1d< real64 > const & localRhs ) const;
199  virtual real64 setNextDtBasedOnStateChange( real64 const & currentDt,
200  DomainPartition & domain ) override;
201 
202  virtual void initializePreSubGroups() override;
203 
205 
206  virtual void initializeFluidState( MeshLevel & mesh, string_array const & regionNames ) override;
207 
208 
213  void updatePhaseMass( ElementSubRegionBase & subRegion ) const;
214 
216  {
217  // inputs
218 
219  // density averaging scheme
220  static constexpr char const * gravityDensitySchemeString() { return "gravityDensityScheme"; }
221 
222  // time stepping controls
223  static constexpr char const * solutionChangeScalingFactorString() { return "solutionChangeScalingFactor"; }
224  static constexpr char const * targetRelativePresChangeString() { return "targetRelativePressureChangeInTimeStep"; }
225  static constexpr char const * targetPhaseVolFracChangeString() { return "targetPhaseVolFractionChangeInTimeStep"; }
226 
227  // nonlinear solver parameters
228  static constexpr char const * maxRelativePresChangeString() { return "maxRelativePressureChange"; }
229  static constexpr char const * useTotalMassEquationString() { return "useTotalMassEquation"; }
230 
231  static constexpr char const * capPressureNamesString() { return "capillary_pressure"; }
232  static constexpr char const * relPermNamesString() { return "relative_permeability"; }
233  static constexpr char const * elemDofFieldString() { return "elemDofField"; }
234  };
235 
236 
237 private:
238 
239  virtual void postInputInitialization() override;
240 
245  void updateFluidModel( ObjectManagerBase & dataGroup ) const;
246 
251  void updateRelPermModel( ObjectManagerBase & dataGroup ) const;
252 
257  void updateCapPressureModel( ObjectManagerBase & dataGroup ) const;
258 
263  void updatePhaseMobility( ObjectManagerBase & dataGroup ) const;
264 
274  template< typename OBJECT_TYPE >
275  void applyFieldValue( real64 const & time_n,
276  real64 const & dt,
277  MeshLevel & mesh,
278  char const logMessage[],
279  string const fieldKey,
280  string const boundaryFieldKey ) const;
281 
283  integer m_numPhases;
284 
286  bool m_hasCapPressure;
287 
289  integer m_useTotalMassEquation;
290 
292  GravityDensityScheme m_gravityDensityScheme;
293 
295  real64 m_targetRelativePresChange;
296 
298  real64 m_targetPhaseVolFracChange;
299 
301  real64 m_solutionChangeScalingFactor;
302 
303 
304 private:
305 
311  bool validateDirichletBC( DomainPartition & domain,
312  real64 const time ) const;
313 
314  virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override;
315 
316 };
317 
318 template< typename OBJECT_TYPE >
319 void ImmiscibleMultiphaseFlow::applyFieldValue( real64 const & time_n,
320  real64 const & dt,
321  MeshLevel & mesh,
322  char const logMessage[],
323  string const fieldKey,
324  string const boundaryFieldKey ) const
325 {
327 
328  fsManager.apply< OBJECT_TYPE >( time_n + dt,
329  mesh,
330  fieldKey,
331  [&]( FieldSpecificationBase const & fs,
332  string const & setName,
334  OBJECT_TYPE & targetGroup,
335  string const & )
336  {
337  if( fs.getLogLevel() >= 1 && m_nonlinearSolverParameters.m_numNewtonIterations == 0 )
338  {
339  globalIndex const numTargetElems = MpiWrapper::sum< globalIndex >( lset.size() );
340  GEOS_LOG_RANK_0( GEOS_FMT( logMessage,
341  getName(), time_n+dt, fs.getCatalogName(), fs.getName(),
342  setName, targetGroup.getName(), fs.getScale(), numTargetElems ) );
343  }
344 
345  // Specify the bc value of the field
346  fs.applyFieldValue< FieldSpecificationEqual,
347  parallelDevicePolicy<> >( lset,
348  time_n + dt,
349  targetGroup,
350  boundaryFieldKey );
351  } );
352 }
353 
354 
355 } // namespace geos
356 
357 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_IMMISCIBLEMULTIPHASEFLOW_HPP_
#define GEOS_LOG_RANK_0(msg)
Log a message on screen on rank 0.
Definition: Logger.hpp:101
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:44
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
void apply(real64 const time, MeshLevel &mesh, string const &fieldName, LAMBDA &&lambda) const
This function is the main driver for the field applications.
static FieldSpecificationManager & getInstance()
ImmiscibleMultiphaseFlow & operator=(ImmiscibleMultiphaseFlow &&)=delete
deleted move operator
virtual ~ImmiscibleMultiphaseFlow() override=default
default destructor
virtual void implicitStepComplete(real64 const &time, real64 const &dt, DomainPartition &domain) override
perform cleanup for implicit timestep
virtual void updateState(DomainPartition &domain) override final
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void saveConvergedState(ElementSubRegionBase &subRegion) const override final
Utility function to save the converged state.
ImmiscibleMultiphaseFlow(ImmiscibleMultiphaseFlow const &)=delete
deleted copy constructor
virtual void initializePostInitialConditionsPreSubGroups() override
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
virtual void initializePreSubGroups() override
Called by Initialize() prior to initializing sub-Groups.
void updatePhaseMass(ElementSubRegionBase &subRegion) const
Function to update fluid mass.
virtual real64 setNextDtBasedOnStateChange(real64 const &currentDt, DomainPartition &domain) override
function to set the next time step size
virtual void implicitStepSetup(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
function to perform setup for implicit timestep
ImmiscibleMultiphaseFlow(ImmiscibleMultiphaseFlow &&)=default
default move constructor
ImmiscibleMultiphaseFlow(const string &name, Group *const parent)
main constructor for Group Objects
void assembleAccumulationTerm(DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) const
assembles the accumulation and volume balance terms for all cells
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.
integer numFluidPhases() const
Getter for the number of fluid phases.
virtual void assembleFluxTerms(real64 const dt, DomainPartition const &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) const
assembles the flux terms for all cells
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
static string catalogName()
name of the solver in the object catalog
void applyDirichletBC(real64 const time, real64 const dt, DofManager const &dofManager, DomainPartition &domain, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) const
Function to perform the Application of Dirichlet type BC's.
virtual void resetStateToBeginningOfStep(DomainPartition &domain) override
reset state of physics back to the beginning of the step.
virtual void assembleSystem(real64 const time_n, 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
virtual void setupDofs(DomainPartition const &domain, DofManager &dofManager) const override
Populate degree-of-freedom manager with fields relevant to this solver.
ImmiscibleMultiphaseFlow()=delete
deleted default constructor
virtual void registerDataOnMesh(Group &meshBodies) override final
Register wrappers that contain data on the mesh objects.
virtual void applyBoundaryConditions(real64 const time_n, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
apply boundary condition to system
ImmiscibleMultiphaseFlow & operator=(ImmiscibleMultiphaseFlow const &)=delete
deleted assignment operator
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
integer m_numNewtonIterations
The number of nonlinear iterations that have been exectued.
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
NonlinearSolverParameters m_nonlinearSolverParameters
Nonlinear solver parameters.
string const & getName() const
Get group name.
Definition: Group.hpp:1331
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:188
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:401
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:318
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:81
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:279
GravityDensityScheme
Options for density treatment in gravity.