opm-simulators
flashmodel.hh
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
28 #ifndef OPM_PTFLASH_MODEL_HH
29 #define OPM_PTFLASH_MODEL_HH
30 
31 #include <opm/material/constraintsolvers/PTFlash.hpp>
32 
33 #include <opm/material/densead/Math.hpp>
34 
35 #include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
36 #include <opm/material/fluidmatrixinteractions/NullMaterial.hpp>
37 
40 
45 
50 
57 
58 #include <cassert>
59 #include <memory>
60 #include <sstream>
61 #include <string>
62 #include <tuple>
63 
64 namespace Opm {
65 
66 template <class TypeTag>
67 class FlashModel;
68 
69 }
70 
71 namespace Opm::Properties {
72 
73 namespace TTag {
75 struct FlashModel { using InheritsFrom = std::tuple<MultiPhaseBaseModel>; };
76 } // namespace TTag
77 
79 template<class TypeTag>
80 struct LocalResidual<TypeTag, TTag::FlashModel>
81 { using type = FlashLocalResidual<TypeTag>; };
82 
84 template<class TypeTag>
85 struct NewtonMethod<TypeTag, TTag::FlashModel>
86 { using type = FlashNewtonMethod<TypeTag>; };
87 
89 template<class TypeTag>
90 struct FlashSolver<TypeTag, TTag::FlashModel>
91 {
92  using type = PTFlash<GetPropType<TypeTag, Properties::Scalar>,
94 };
95 
97 template<class TypeTag>
98 struct Model<TypeTag, TTag::FlashModel>
99 { using type = FlashModel<TypeTag>; };
100 
102 template<class TypeTag>
103 struct PrimaryVariables<TypeTag, TTag::FlashModel>
104 { using type = FlashPrimaryVariables<TypeTag>; };
105 
107 template<class TypeTag>
108 struct RateVector<TypeTag, TTag::FlashModel>
109 { using type = FlashRateVector<TypeTag>; };
110 
112 template<class TypeTag>
113 struct BoundaryRateVector<TypeTag, TTag::FlashModel>
114 { using type = FlashBoundaryRateVector<TypeTag>; };
115 
117 template<class TypeTag>
118 struct IntensiveQuantities<TypeTag, TTag::FlashModel>
119 { using type = FlashIntensiveQuantities<TypeTag>; };
120 
122 template<class TypeTag>
123 struct ExtensiveQuantities<TypeTag, TTag::FlashModel>
124 { using type = FlashExtensiveQuantities<TypeTag>; };
125 
127 template<class TypeTag>
128 struct Indices<TypeTag, TTag::FlashModel>
129 { using type = FlashIndices<TypeTag, /*PVIdx=*/0>; };
130 
131 // disable molecular diffusion by default
132 template<class TypeTag>
133 struct EnableDiffusion<TypeTag, TTag::FlashModel>
134 { static constexpr bool value = false; };
135 
137 template<class TypeTag>
138 struct EnableEnergy<TypeTag, TTag::FlashModel>
139 { static constexpr bool value = false; };
140 
141 template<class TypeTag>
142 struct EnableWater<TypeTag, TTag::MultiPhaseBaseModel>
143 { static constexpr int value = GetPropType<TypeTag, Properties::FluidSystem>::waterEnabled; };
144 
145 } // namespace Opm::Properties
146 
147 namespace Opm {
148 
191 template <class TypeTag>
192 class FlashModel
193  : public MultiPhaseBaseModel<TypeTag>
194 {
195  using ParentType = MultiPhaseBaseModel<TypeTag>;
196 
200 
202 
203  enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
204  static constexpr bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
205  static constexpr bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>();
206 
207  using EnergyModule = ::Opm::EnergyModule<TypeTag, enableEnergy>;
208 
209 public:
210  explicit FlashModel(Simulator& simulator)
211  : ParentType(simulator)
212  {}
213 
217  static void registerParameters()
218  {
220 
221  // register runtime parameters of the VTK output modules
224 
225  if constexpr (enableDiffusion) {
227  }
228 
229  if constexpr (enableEnergy) {
231  }
232 
233  Parameters::Register<Parameters::FlashTolerance<Scalar>>
234  ("The maximum tolerance for the flash solver to "
235  "consider the solution converged");
236  Parameters::Register<Parameters::FlashVerbosity>
237  ("Flash solver verbosity level");
238  Parameters::Register<Parameters::FlashTwoPhaseMethod>
239  ("Method for solving vapor-liquid composition. Available options include: "
240  "ssi, newton, ssi+newton");
241 
242  Parameters::SetDefault<Parameters::FlashTolerance<Scalar>>(1.e-8);
243  Parameters::SetDefault<Parameters::EnableIntensiveQuantityCache>(true);
244 
245  // since thermodynamic hints are basically free if the cache for intensive quantities is
246  // enabled, and this model usually shows quite a performance improvment if they are
247  // enabled, let's enable them by default.
248  Parameters::SetDefault<Parameters::EnableThermodynamicHints>(true);
249  }
250 
254  std::string primaryVarName(unsigned pvIdx) const
255  {
256  const std::string& tmp = EnergyModule::primaryVarName(pvIdx);
257  if (!tmp.empty()) {
258  return tmp;
259  }
260 
261  std::ostringstream oss;
262  if (Indices::z0Idx <= pvIdx && pvIdx < Indices::z0Idx + numComponents - 1) {
263  oss << "z_," << FluidSystem::componentName(/*compIdx=*/pvIdx - Indices::z0Idx);
264  }
265  else if (pvIdx == Indices::pressure0Idx) {
266  oss << "pressure_" << FluidSystem::phaseName(0);
267  }
268  else {
269  assert(false);
270  }
271 
272  return oss.str();
273  }
274 
278  std::string eqName(unsigned eqIdx) const
279  {
280  const std::string& tmp = EnergyModule::eqName(eqIdx);
281  if (!tmp.empty()) {
282  return tmp;
283  }
284 
285  std::ostringstream oss;
286  if (Indices::conti0EqIdx <= eqIdx &&
287  eqIdx < Indices::conti0EqIdx + numComponents)
288  {
289  const unsigned compIdx = eqIdx - Indices::conti0EqIdx;
290  oss << "continuity^" << FluidSystem::componentName(compIdx);
291  }
292  else {
293  assert(false);
294  }
295 
296  return oss.str();
297  }
298 
299  void registerOutputModules_()
300  {
301  ParentType::registerOutputModules_();
302 
303  // add the VTK output modules which are meaningful for the model
304  this->addOutputModule(std::make_unique<VtkCompositionModule<TypeTag>>(this->simulator_));
305  this->addOutputModule(std::make_unique<VtkPTFlashModule<TypeTag>>(this->simulator_));
306  if constexpr (enableDiffusion) {
307  this->addOutputModule(std::make_unique<VtkDiffusionModule<TypeTag>>(this->simulator_));
308  }
309  if constexpr (enableEnergy) {
310  this->addOutputModule(std::make_unique<VtkEnergyModule<TypeTag>>(this->simulator_));
311  }
312  }
313 };
314 
315 } // namespace Opm
316 
317 #endif
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
std::string primaryVarName(unsigned pvIdx) const
Given an primary variable index, return a human readable name.
Definition: flashmodel.hh:254
Specifies the type of the actual Newton method.
Definition: fvbaseproblem.hh:54
VTK output module for quantities which make sense for models which assume thermal equilibrium...
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: flashmodel.hh:217
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkcompositionmodule.hpp:87
Defines the primary variable and equation indices for the compositional multi-phase model based on fl...
This template class contains the data which is required to calculate all fluxes of components over a ...
Enable water?
Definition: multiphasebaseproperties.hh:103
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...
VTK output module for the PT Flash calculation This module deals with the following quantities: K...
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
VTK output module for the PT Flash calculation This module deals with the following quantities: K...
Definition: vtkptflashmodule.hpp:52
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkdiffusionmodule.hpp:88
Declares the properties required by the compositional multi-phase model based on flash calculations...
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: multiphasebasemodel.hh:197
std::string eqName(unsigned eqIdx) const
Given an equation index, return a human readable name.
Definition: flashmodel.hh:278
Represents the primary variables used by the compositional flow model based on flash calculations...
A Newton solver specific to the PTFlash model.
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkenergymodule.hpp:87
VTK output module for the fluid composition.
Definition: vtkcompositionmodule.hpp:56
Contains the intensive quantities of the flash-based compositional multi-phase model.
Implements a boundary vector for the fully implicit compositional multi-phase model which is based on...
Calculates the local residual of the compositional multi-phase model based on flash calculations...
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:55
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
Definition: blackoilmodel.hh:75
Declares the parameters for the compositional multi-phase model based on flash calculations.
VTK output module for quantities which make sense for models which incorperate molecular diffusion...
The type of the flash constraint solver.
Definition: flashproperties.hh:39
Implements a vector representing rates of conserved quantities.
A Newton solver specific to the PTFlash model.
Definition: flashnewtonmethod.hh:54
A compositional multi-phase model based on flash-calculations
Definition: flashmodel.hh:64
VTK output module for quantities which make sense for models which incorperate molecular diffusion...
Definition: vtkdiffusionmodule.hpp:57
VTK output module for the fluid composition.
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkptflashmodule.hpp:83
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Definition: multiphasebasemodel.hh:57