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