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 
40 
42 
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  enum { enableDissolution = Indices::compositionSwitchIdx >= 0 };
79  enum { enableBrine = getPropValue<TypeTag, Properties::EnableBrine>() };
80  enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
81  enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
82  enum { enableDisgasInWater = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
83  enum { enableDissolvedGas = Indices::compositionSwitchIdx >= 0 };
84  enum { enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>() };
85  static constexpr EnergyModules energyModuleType = getPropValue<TypeTag, Properties::EnergyModuleType>();
86 
87 public:
88  // NB: setting the enableEnergy argument to true enables storage of enthalpy and
89  // internal energy!
90  using ScalarFluidState = BlackOilFluidState<Scalar,
91  FluidSystem,
92  energyModuleType != EnergyModules::NoTemperature,
93  energyModuleType == EnergyModules::FullyImplicitThermal,
94  enableDissolution,
95  enableVapwat,
96  enableBrine,
97  enableSaltPrecipitation,
98  enableDisgasInWater,
99  enableSolvent,
100  Indices::numPhases>;
101 
102 
103  template <class EclMaterialLawManager>
104  EquilInitializer(const Simulator& simulator,
105  EclMaterialLawManager& materialLawManager)
106  : simulator_(simulator)
107  {
108  const auto& vanguard = simulator.vanguard();
109  const auto& eclState = vanguard.eclState();
110 
111  unsigned numElems = vanguard.grid().size(0);
114  using CartesianIndexMapper = Dune::CartesianIndexMapper<Grid>;
115  using Initializer = EQUIL::DeckDependent::InitialStateComputer<FluidSystem,
116  Grid,
117  GridView,
118  ElementMapper,
119  CartesianIndexMapper>;
120 
121  Initializer initialState(materialLawManager,
122  eclState,
123  vanguard.grid(),
124  vanguard.gridView(),
125  vanguard.cartesianMapper(),
126  simulator.problem().gravity()[dimWorld - 1],
127  simulator.problem().numPressurePointsEquil());
128 
129  // copy the result into the array of initial fluid states
130  initialFluidStates_.resize(numElems);
131  for (unsigned int elemIdx = 0; elemIdx < numElems; ++elemIdx) {
132  auto& fluidState = initialFluidStates_[elemIdx];
133 
134  // get the PVT region index of the current element
135  unsigned regionIdx = simulator_.problem().pvtRegionIndex(elemIdx);
136  fluidState.setPvtRegionIndex(regionIdx);
137 
138  // set the phase saturations
139  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
140  if (FluidSystem::phaseIsActive(phaseIdx))
141  fluidState.setSaturation(phaseIdx, initialState.saturation()[phaseIdx][elemIdx]);
142  else if (Indices::numPhases == 3)
143  fluidState.setSaturation(phaseIdx, 0.0);
144  }
145 
146  if constexpr (enableDissolvedGas) {
147  if (FluidSystem::enableDissolvedGas())
148  fluidState.setRs(initialState.rs()[elemIdx]);
149  else if (Indices::gasEnabled && Indices::oilEnabled)
150  fluidState.setRs(0.0);
151  if (FluidSystem::enableVaporizedOil())
152  fluidState.setRv(initialState.rv()[elemIdx]);
153  else if (Indices::gasEnabled && Indices::oilEnabled)
154  fluidState.setRv(0.0);
155  }
156 
157  if constexpr (enableVapwat) {
158  if (FluidSystem::enableVaporizedWater())
159  fluidState.setRvw(initialState.rvw()[elemIdx]);
160  }
161 
162  // set the temperature.
163  if constexpr (energyModuleType != EnergyModules::NoTemperature)
164  fluidState.setTemperature(initialState.temperature()[elemIdx]);
165 
166  // set the phase pressures, invB factor and density
167  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
168  if (!FluidSystem::phaseIsActive(phaseIdx))
169  continue;
170  fluidState.setPressure(phaseIdx, initialState.press()[phaseIdx][elemIdx]);
171 
172  const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx);
173  fluidState.setInvB(phaseIdx, b);
174 
175  const auto& rho = FluidSystem::density(fluidState, phaseIdx, regionIdx);
176  fluidState.setDensity(phaseIdx, rho);
177 
178  if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
179  const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, regionIdx);
180  fluidState.setEnthalpy(phaseIdx, h);
181  }
182  }
183 
184  // set the salt concentration
185  if constexpr (enableBrine)
186  fluidState.setSaltConcentration(initialState.saltConcentration()[elemIdx]);
187 
188  //set the (solid) salt saturation
189  if constexpr (enableSaltPrecipitation)
190  fluidState.setSaltSaturation(initialState.saltSaturation()[elemIdx]);
191  }
192  }
193 
200  const ScalarFluidState& initialFluidState(unsigned elemIdx) const
201  {
202  return initialFluidStates_[elemIdx];
203  }
204 
205 protected:
206  const Simulator& simulator_;
207 
208  std::vector<ScalarFluidState> initialFluidStates_;
209 };
210 } // namespace Opm
211 
212 #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
This file contains a set of helper functions used by VFPProd / VFPInj.
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:200
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...
Contains the classes required to extend the black-oil model by energy.
Definition: CollectDataOnIORank.hpp:49
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83