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
36#include <opm/models/blackoil/blackoilproperties.hh>
37#include <opm/models/discretization/common/fvbaseproperties.hh>
38#include <opm/models/utils/propertysystem.hh>
39
41
42#include <vector>
43
44namespace Opm {
45
56template <class TypeTag>
58{
59 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
60 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
61 using GridView = GetPropType<TypeTag, Properties::GridView>;
62 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
63 using MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw>;
64 using Indices = GetPropType<TypeTag, Properties::Indices>;
65
66 enum { numPhases = FluidSystem::numPhases };
67 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
68 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
69 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
70
71 enum { numComponents = FluidSystem::numComponents };
72 enum { oilCompIdx = FluidSystem::oilCompIdx };
73 enum { gasCompIdx = FluidSystem::gasCompIdx };
74 enum { waterCompIdx = FluidSystem::waterCompIdx };
75
76 enum { dimWorld = GridView::dimensionworld };
77 enum { enableTemperature = getPropValue<TypeTag, Properties::EnableTemperature>() };
78 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
79 enum { enableDissolution = Indices::compositionSwitchIdx >= 0 };
80 enum { enableBrine = getPropValue<TypeTag, Properties::EnableBrine>() };
81 enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
82 enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
83 enum { has_disgas_in_water = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
84
85
86public:
87 // NB: setting the enableEnergy argument to true enables storage of enthalpy and
88 // internal energy!
89 using ScalarFluidState = BlackOilFluidState<Scalar,
90 FluidSystem,
91 enableTemperature,
92 enableEnergy,
93 enableDissolution,
94 enableVapwat,
95 enableBrine,
96 enableSaltPrecipitation,
97 has_disgas_in_water,
98 Indices::numPhases>;
99
100
101 template <class EclMaterialLawManager>
102 EquilInitializer(const Simulator& simulator,
103 EclMaterialLawManager& materialLawManager)
104 : simulator_(simulator)
105 {
106 const auto& vanguard = simulator.vanguard();
107 const auto& eclState = vanguard.eclState();
108
109 unsigned numElems = vanguard.grid().size(0);
110 using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
111 using Grid = GetPropType<TypeTag, Properties::Grid>;
112 using CartesianIndexMapper = Dune::CartesianIndexMapper<Grid>;
113 using Initializer = EQUIL::DeckDependent::InitialStateComputer<FluidSystem,
114 Grid,
115 GridView,
116 ElementMapper,
117 CartesianIndexMapper>;
118
119 Initializer initialState(materialLawManager,
120 eclState,
121 vanguard.grid(),
122 vanguard.gridView(),
123 vanguard.cartesianMapper(),
124 simulator.problem().gravity()[dimWorld - 1],
125 simulator.problem().numPressurePointsEquil());
126
127 // copy the result into the array of initial fluid states
128 initialFluidStates_.resize(numElems);
129 for (unsigned int elemIdx = 0; elemIdx < numElems; ++elemIdx) {
130 auto& fluidState = initialFluidStates_[elemIdx];
131
132 // get the PVT region index of the current element
133 unsigned regionIdx = simulator_.problem().pvtRegionIndex(elemIdx);
134 fluidState.setPvtRegionIndex(regionIdx);
135
136 // set the phase saturations
137 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
138 if (FluidSystem::phaseIsActive(phaseIdx))
139 fluidState.setSaturation(phaseIdx, initialState.saturation()[phaseIdx][elemIdx]);
140 else if (Indices::numPhases == 3)
141 fluidState.setSaturation(phaseIdx, 0.0);
142 }
143
144 if (FluidSystem::enableDissolvedGas())
145 fluidState.setRs(initialState.rs()[elemIdx]);
146 else if (Indices::gasEnabled && Indices::oilEnabled)
147 fluidState.setRs(0.0);
148
149 if (FluidSystem::enableVaporizedOil())
150 fluidState.setRv(initialState.rv()[elemIdx]);
151 else if (Indices::gasEnabled && Indices::oilEnabled)
152 fluidState.setRv(0.0);
153
154 if (FluidSystem::enableVaporizedWater())
155 fluidState.setRvw(initialState.rvw()[elemIdx]);
156
157 // set the temperature.
158 if (enableTemperature || enableEnergy)
159 fluidState.setTemperature(initialState.temperature()[elemIdx]);
160
161 // set the phase pressures, invB factor and density
162 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
163 if (!FluidSystem::phaseIsActive(phaseIdx))
164 continue;
165 fluidState.setPressure(phaseIdx, initialState.press()[phaseIdx][elemIdx]);
166
167 const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx);
168 fluidState.setInvB(phaseIdx, b);
169
170 const auto& rho = FluidSystem::density(fluidState, phaseIdx, regionIdx);
171 fluidState.setDensity(phaseIdx, rho);
172
173 if (enableEnergy) {
174 const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, regionIdx);
175 fluidState.setEnthalpy(phaseIdx, h);
176 }
177 }
178
179 // set the salt concentration
180 if constexpr (enableBrine)
181 fluidState.setSaltConcentration(initialState.saltConcentration()[elemIdx]);
182
183 //set the (solid) salt saturation
184 if constexpr (enableSaltPrecipitation)
185 fluidState.setSaltSaturation(initialState.saltSaturation()[elemIdx]);
186 }
187 }
188
195 const ScalarFluidState& initialFluidState(unsigned elemIdx) const
196 {
197 return initialFluidStates_[elemIdx];
198 }
199
200protected:
201 const Simulator& simulator_;
202
203 std::vector<ScalarFluidState> initialFluidStates_;
204};
205} // namespace Opm
206
207#endif // OPM_EQUIL_INITIALIZER_HPP
Routines that actually solve the ODEs that emerge from the hydrostatic equilibrium problem.
Definition: CollectDataOnIORank.hpp:49
Definition: InitStateEquil.hpp:680
Computes the initial condition based on the EQUIL keyword from ECL.
Definition: EquilInitializer.hpp:58
EquilInitializer(const Simulator &simulator, EclMaterialLawManager &materialLawManager)
Definition: EquilInitializer.hpp:102
const Simulator & simulator_
Definition: EquilInitializer.hpp:201
std::vector< ScalarFluidState > initialFluidStates_
Definition: EquilInitializer.hpp:203
const ScalarFluidState & initialFluidState(unsigned elemIdx) const
Return the initial thermodynamic state which should be used as the initial condition.
Definition: EquilInitializer.hpp:195
BlackOilFluidState< Scalar, FluidSystem, enableTemperature, enableEnergy, enableDissolution, enableVapwat, enableBrine, enableSaltPrecipitation, has_disgas_in_water, Indices::numPhases > ScalarFluidState
Definition: EquilInitializer.hpp:98
Definition: BlackoilPhases.hpp:27