opm-simulators
EquilInitializer.hpp
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_EQUIL_INITIALIZER_HPP
29 #define OPM_EQUIL_INITIALIZER_HPP
30 
31 #include <opm/grid/common/CartesianIndexMapper.hpp>
32 
33 #include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
34 #include <opm/material/fluidstates/BlackOilFluidState.hpp>
35 
39 
41 
42 #include <limits>
43 #include <vector>
44 
45 namespace Opm {
46 
57 template <class TypeTag>
59 {
66 
67  enum { numPhases = FluidSystem::numPhases };
68  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
69  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
70  enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
71 
72  enum { numComponents = FluidSystem::numComponents };
73  enum { oilCompIdx = FluidSystem::oilCompIdx };
74  enum { gasCompIdx = FluidSystem::gasCompIdx };
75  enum { waterCompIdx = FluidSystem::waterCompIdx };
76 
77  enum { dimWorld = GridView::dimensionworld };
78  static constexpr bool enableDissolution =
79  Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
80  static constexpr bool enableBrine = getPropValue<TypeTag, Properties::EnableBrine>();
81  enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
82  enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
83  enum { enableDisgasInWater = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
84  static constexpr bool enableDissolvedGas =
85  Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
86  static constexpr bool enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>();
87  static constexpr EnergyModules energyModuleType = getPropValue<TypeTag, Properties::EnergyModuleType>();
88 
89 public:
90  // NB: setting the enableEnergy argument to true enables storage of enthalpy and
91  // internal energy!
92  using ScalarFluidState = BlackOilFluidState<Scalar,
93  FluidSystem,
94  energyModuleType != EnergyModules::NoTemperature,
95  energyModuleType == EnergyModules::FullyImplicitThermal,
96  enableDissolution,
97  enableVapwat,
98  enableBrine,
99  enableSaltPrecipitation,
100  enableDisgasInWater,
101  enableSolvent,
102  Indices::numPhases>;
103 
104 
105  template <class EclMaterialLawManager>
106  EquilInitializer(const Simulator& simulator,
107  EclMaterialLawManager& materialLawManager)
108  : simulator_(simulator)
109  {
110  const auto& vanguard = simulator.vanguard();
111  const auto& eclState = vanguard.eclState();
112 
113  unsigned numElems = vanguard.grid().size(0);
116  using CartesianIndexMapper = Dune::CartesianIndexMapper<Grid>;
117  using Initializer = EQUIL::DeckDependent::InitialStateComputer<FluidSystem,
118  Grid,
119  GridView,
120  ElementMapper,
121  CartesianIndexMapper>;
122 
123  Initializer initialState(materialLawManager,
124  eclState,
125  vanguard.grid(),
126  vanguard.gridView(),
127  vanguard.cartesianMapper(),
128  simulator.problem().gravity()[dimWorld - 1],
129  simulator.problem().numPressurePointsEquil());
130 
131  // copy the result into the array of initial fluid states
132  initialFluidStates_.resize(numElems);
133  for (unsigned int elemIdx = 0; elemIdx < numElems; ++elemIdx) {
134  auto& fluidState = initialFluidStates_[elemIdx];
135 
136  // get the PVT region index of the current element
137  unsigned regionIdx = simulator_.problem().pvtRegionIndex(elemIdx);
138  fluidState.setPvtRegionIndex(regionIdx);
139 
140  // set the phase saturations
141  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
142  if (FluidSystem::phaseIsActive(phaseIdx))
143  fluidState.setSaturation(phaseIdx, initialState.saturation()[phaseIdx][elemIdx]);
144  else if (Indices::numPhases == 3)
145  fluidState.setSaturation(phaseIdx, 0.0);
146  }
147 
148  if constexpr (enableDissolvedGas) {
149  if (FluidSystem::enableDissolvedGas())
150  fluidState.setRs(initialState.rs()[elemIdx]);
151  else if (Indices::gasEnabled && Indices::oilEnabled)
152  fluidState.setRs(0.0);
153  if (FluidSystem::enableVaporizedOil())
154  fluidState.setRv(initialState.rv()[elemIdx]);
155  else if (Indices::gasEnabled && Indices::oilEnabled)
156  fluidState.setRv(0.0);
157  }
158 
159  if constexpr (enableVapwat) {
160  if (FluidSystem::enableVaporizedWater())
161  fluidState.setRvw(initialState.rvw()[elemIdx]);
162  }
163 
164  // set the temperature.
165  if constexpr (energyModuleType != EnergyModules::NoTemperature)
166  fluidState.setTemperature(initialState.temperature()[elemIdx]);
167 
168  // set the phase pressures, invB factor and density
169  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
170  if (!FluidSystem::phaseIsActive(phaseIdx))
171  continue;
172  fluidState.setPressure(phaseIdx, initialState.press()[phaseIdx][elemIdx]);
173 
174  const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx);
175  fluidState.setInvB(phaseIdx, b);
176 
177  const auto& rho = FluidSystem::density(fluidState, phaseIdx, regionIdx);
178  fluidState.setDensity(phaseIdx, rho);
179 
180  if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
181  const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, regionIdx);
182  fluidState.setEnthalpy(phaseIdx, h);
183  }
184  }
185 
186  // set the salt concentration
187  if constexpr (enableBrine)
188  fluidState.setSaltConcentration(initialState.saltConcentration()[elemIdx]);
189 
190  //set the (solid) salt saturation
191  if constexpr (enableSaltPrecipitation)
192  fluidState.setSaltSaturation(initialState.saltSaturation()[elemIdx]);
193  }
194  }
195 
202  const ScalarFluidState& initialFluidState(unsigned elemIdx) const
203  {
204  return initialFluidStates_[elemIdx];
205  }
206 
207 protected:
208  const Simulator& simulator_;
209 
210  std::vector<ScalarFluidState> initialFluidStates_;
211 };
212 } // namespace Opm
213 
214 #endif // OPM_EQUIL_INITIALIZER_HPP
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
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
const ScalarFluidState & initialFluidState(unsigned elemIdx) const
Return the initial thermodynamic state which should be used as the initial condition.
Definition: EquilInitializer.hpp:202
Definition: InitStateEquil.hpp:703
Declares the properties required by the black oil model.
Declare the properties used by the infrastructure code of the finite volume discretizations.
Computes the initial condition based on the EQUIL keyword from ECL.
Definition: EquilInitializer.hpp:58
The Opm property system, traits with inheritance.
Routines that actually solve the ODEs that emerge from the hydrostatic equilibrium problem...
Definition: CollectDataOnIORank.hpp:50
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83