tutorial1problem.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 EWOMS_TUTORIAL1_PROBLEM_HH /*@\label{tutorial1:guardian1}@*/
29#define EWOMS_TUTORIAL1_PROBLEM_HH /*@\label{tutorial1:guardian2}@*/
30
31// The numerical model
33
34// The spatial discretization (VCFV == Vertex-Centered Finite Volumes)
35#include <opm/models/discretization/vcfv/vcfvdiscretization.hh> /*@\label{tutorial1:include-discretization}@*/
36
37// The chemical species that are used
38#include <opm/material/components/SimpleH2O.hpp>
39#include <opm/material/components/Lnapl.hpp>
40
41// Headers required for the capillary pressure law
42#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp> /*@\label{tutorial1:rawLawInclude}@*/
43#include <opm/material/fluidmatrixinteractions/EffToAbsLaw.hpp>
44#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
45
46// For the DUNE grid
47#include <dune/grid/yaspgrid.hh> /*@\label{tutorial1:include-grid-manager}@*/
48#include <opm/models/io/cubegridvanguard.hh> /*@\label{tutorial1:include-grid-manager}@*/
49
50// For Dune::FieldMatrix
51#include <dune/common/fmatrix.hh>
52#include <dune/common/version.hh>
53
54namespace Opm {
55// forward declaration of the problem class
56template <class TypeTag>
57class Tutorial1Problem;
58}
59
60namespace Opm::Properties {
61
62// Create a new type tag for the problem
63// Create new type tags
64namespace TTag {
65struct Tutorial1Problem { using InheritsFrom = std::tuple<ImmiscibleTwoPhaseModel>; };
66} // end namespace TTag
67
68// Select the vertex centered finite volume method as spatial discretization
69template<class TypeTag>
71{ using type = TTag::VcfvDiscretization; }; /*@\label{tutorial1:set-spatial-discretization}@*/
72
73// Set the "Problem" property
74template<class TypeTag>
75struct Problem<TypeTag, TTag::Tutorial1Problem>
76{ using type = Opm::Tutorial1Problem<TypeTag>; }; /*@\label{tutorial1:set-problem}@*/
77
78// Set grid and the grid manager to be used
79template<class TypeTag>
80struct Grid<TypeTag, TTag::Tutorial1Problem> { using type = Dune::YaspGrid</*dim=*/2>; }; /*@\label{tutorial1:set-grid}@*/
81template<class TypeTag>
82struct Vanguard<TypeTag, TTag::Tutorial1Problem> { using type = Opm::CubeGridVanguard<TypeTag>; }; /*@\label{tutorial1:set-grid-manager}@*/
83
84// Set the wetting phase /*@\label{tutorial1:2p-system-start}@*/
85template<class TypeTag>
86struct WettingPhase<TypeTag, TTag::Tutorial1Problem> /*@\label{tutorial1:wettingPhase}@*/
87{
89 using type = Opm::LiquidPhase<Scalar, Opm::SimpleH2O<Scalar> >;
90};
91
92// Set the non-wetting phase
93template<class TypeTag>
94struct NonwettingPhase<TypeTag, TTag::Tutorial1Problem> /*@\label{tutorial1:nonwettingPhase}@*/
95{
97 using type = Opm::LiquidPhase<Scalar, Opm::LNAPL<Scalar> >;
98}; /*@\label{tutorial1:2p-system-end}@*/
99
100// Set the material law
101template<class TypeTag>
102struct MaterialLaw<TypeTag, TTag::Tutorial1Problem>
103{
104private:
105 // create a class holding the necessary information for a
106 // two-phase capillary pressure law
109 enum { wettingPhaseIdx = FluidSystem::wettingPhaseIdx };
110 enum { nonWettingPhaseIdx = FluidSystem::nonWettingPhaseIdx };
111 using Traits = Opm::TwoPhaseMaterialTraits<Scalar, wettingPhaseIdx, nonWettingPhaseIdx>;
112
113 // define the material law which is parameterized by effective
114 // saturations
115 using RawMaterialLaw = Opm::RegularizedBrooksCorey<Traits>; /*@\label{tutorial1:rawlaw}@*/
116
117public:
118 // Convert absolute saturations into effective ones before passing
119 // it to the base capillary pressure law
120 using type = Opm::EffToAbsLaw<RawMaterialLaw>; /*@\label{tutorial1:eff2abs}@*/
121};
122
123} // namespace Opm::Properties
124
125namespace Opm {
126
128template <class TypeTag>
130 : public GetPropType<TypeTag, Properties::BaseProblem> /*@\label{tutorial1:def-problem}@*/
131{
135
136 // Grid dimension
137 enum {
138 dim = GridView::dimension,
139 dimWorld = GridView::dimensionworld
140 };
141
142 // The type of the intrinsic permeability tensor
143 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
144
145 // eWoms specific types are specified via the property system
153 using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>; /*@\label{tutorial1:matLawObjectType}@*/
154
155 // phase indices
156 enum { numPhases = FluidSystem::numPhases };
157 enum { wettingPhaseIdx = FluidSystem::wettingPhaseIdx };
158 enum { nonWettingPhaseIdx = FluidSystem::nonWettingPhaseIdx };
159
160 // Indices of the conservation equations
161 enum { contiWettingEqIdx = Indices::conti0EqIdx + wettingPhaseIdx };
162 enum { contiNonWettingEqIdx = Indices::conti0EqIdx + nonWettingPhaseIdx };
163
164public:
167 Tutorial1Problem(Simulator& simulator)
168 : ParentType(simulator)
169 , eps_(3e-6)
170 { }
171
176 {
177 ParentType::finishInit();
178
179 // Use an isotropic and homogeneous intrinsic permeability
180 K_ = this->toDimMatrix_(1e-7);
181
182 // Parameters of the Brooks-Corey law
183 materialParams_.setEntryPressure(500.0 /*Pa*/); /*@\label{tutorial1:setLawParams}@*/
184 materialParams_.setLambda(2); // shape parameter
185
186 // Set the residual saturations
187 materialParams_.setResidualSaturation(wettingPhaseIdx, 0.0);
188 materialParams_.setResidualSaturation(nonWettingPhaseIdx, 0.0);
189
190 // wrap up the initialization of the material law's parameters
191 materialParams_.finalize();
192 }
193
197 static void registerParameters()
198 {
199 ParentType::registerParameters();
200
201 Parameters::SetDefault<Parameters::CellsX>(100);
202 Parameters::SetDefault<Parameters::CellsY>(1);
203 Parameters::SetDefault<Parameters::DomainSizeX<Scalar>>(300.0);
204 Parameters::SetDefault<Parameters::DomainSizeY<Scalar>>(60.0);
205
206 if constexpr (dim == 3) {
207 Parameters::SetDefault<Parameters::CellsZ>(1);
208 Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(0.0);
209 }
210
211 Parameters::SetDefault<Parameters::EndTime<Scalar>>(100e3);
212 Parameters::SetDefault<Parameters::InitialTimeStepSize<Scalar>>(125.0);
213 }
214
216 std::string name() const
217 { return "tutorial1"; }
218
220 template <class Context>
221 Scalar temperature(const Context& /*context*/,
222 unsigned /*spaceIdx*/, unsigned /*timeIdx*/) const
223 { return 283.15; }
224
226 template <class Context>
227 const DimMatrix& intrinsicPermeability(const Context& /*context*/, /*@\label{tutorial1:permeability}@*/
228 unsigned /*spaceIdx*/, unsigned /*timeIdx*/) const
229 { return K_; }
230
232 template <class Context>
233 Scalar porosity(const Context& /*context*/,
234 unsigned /*spaceIdx*/, unsigned /*timeIdx*/) const /*@\label{tutorial1:porosity}@*/
235 { return 0.2; }
236
238 template <class Context>
239 const MaterialLawParams& materialLawParams(const Context& /*context*/, /*@\label{tutorial1:matLawParams}@*/
240 unsigned /*spaceIdx*/, unsigned /*timeIdx*/) const
241 { return materialParams_; }
242
244 template <class Context>
245 void boundary(BoundaryRateVector& values, const Context& context,
246 unsigned spaceIdx, unsigned timeIdx) const
247 {
248 const auto& pos = context.pos(spaceIdx, timeIdx);
249 if (pos[0] < eps_) {
250 // Free-flow conditions on left boundary
251 const auto& materialParams = this->materialLawParams(context, spaceIdx, timeIdx);
252
253 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
254 Scalar Sw = 1.0;
255 fs.setSaturation(wettingPhaseIdx, Sw);
256 fs.setSaturation(nonWettingPhaseIdx, 1.0 - Sw);
257 fs.setTemperature(temperature(context, spaceIdx, timeIdx));
258
259 Scalar pC[numPhases];
260 MaterialLaw::capillaryPressures(pC, materialParams, fs);
261 fs.setPressure(wettingPhaseIdx, 200e3);
262 fs.setPressure(nonWettingPhaseIdx, 200e3 + pC[nonWettingPhaseIdx] - pC[nonWettingPhaseIdx]);
263
264 typename FluidSystem::template ParameterCache<Scalar> paramCache;
265 paramCache.updateAll(fs);
266 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
267 fs.setDensity(phaseIdx, FluidSystem::density(fs, paramCache, phaseIdx));
268 fs.setViscosity(phaseIdx, FluidSystem::viscosity(fs, paramCache, phaseIdx));
269 }
270
271 values.setFreeFlow(context, spaceIdx, timeIdx, fs);
272 }
273 else if (pos[0] > this->boundingBoxMax()[0] - eps_) {
274 // forced outflow at the right boundary
275 RateVector massRate(0.0);
276
277 massRate[contiWettingEqIdx] = 0.0; // [kg / (s m^2)]
278 massRate[contiNonWettingEqIdx] = 3e-2; // [kg / (s m^2)]
279
280 values.setMassRate(massRate);
281 }
282 else // no flow at the remaining boundaries
283 values.setNoFlow();
284 }
285
289 template <class Context>
290 void source(RateVector& sourceRate, const Context& /*context*/,
291 unsigned /*spaceIdx*/, unsigned /*timeIdx*/) const
292 {
293 sourceRate[contiWettingEqIdx] = 0.0;
294 sourceRate[contiNonWettingEqIdx] = 0.0;
295 }
296
298 template <class Context>
299 void initial(PrimaryVariables& values, const Context& context,
300 unsigned spaceIdx, unsigned timeIdx) const
301 {
302 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
303
304 // the domain is initially fully saturated by LNAPL
305 Scalar Sw = 0.0;
306 fs.setSaturation(wettingPhaseIdx, Sw);
307 fs.setSaturation(nonWettingPhaseIdx, 1.0 - Sw);
308
309 // the temperature is given by the temperature() method
310 fs.setTemperature(temperature(context, spaceIdx, timeIdx));
311
312 // set pressure of the wetting phase to 200 kPa = 2 bar
313 Scalar pC[numPhases];
314 MaterialLaw::capillaryPressures(pC, materialLawParams(context, spaceIdx, timeIdx),
315 fs);
316 fs.setPressure(wettingPhaseIdx, 200e3);
317 fs.setPressure(nonWettingPhaseIdx, 200e3 + pC[nonWettingPhaseIdx] - pC[nonWettingPhaseIdx]);
318
319 values.assignNaive(fs);
320 }
321
322private:
323 DimMatrix K_;
324 // Object that holds the parameters of required by the capillary pressure law.
325 MaterialLawParams materialParams_; /*@\label{tutorial1:matParamsObject}@*/
326
327 // small epsilon value
328 Scalar eps_;
329};
330} // namespace Opm
331
332#endif
333
Provides a simulator vanguad which creates a regular grid made of quadrilaterals.
Definition: cubegridvanguard.hh:53
Tutorial problem using the "immiscible" model.
Definition: tutorial1problem.hh:131
const DimMatrix & intrinsicPermeability(const Context &, unsigned, unsigned) const
Returns the intrinsic permeability tensor [m^2] at a position.
Definition: tutorial1problem.hh:227
Scalar porosity(const Context &, unsigned, unsigned) const
Defines the porosity [-] of the medium at a given position.
Definition: tutorial1problem.hh:233
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluates the initial value at a given position in the domain.
Definition: tutorial1problem.hh:299
void finishInit()
Definition: tutorial1problem.hh:175
Tutorial1Problem(Simulator &simulator)
Definition: tutorial1problem.hh:167
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluates the boundary conditions.
Definition: tutorial1problem.hh:245
void source(RateVector &sourceRate, const Context &, unsigned, unsigned) const
Definition: tutorial1problem.hh:290
std::string name() const
Specifies the problem name. This is used for files generated by the simulation.
Definition: tutorial1problem.hh:216
const MaterialLawParams & materialLawParams(const Context &, unsigned, unsigned) const
Returns the parameter object for the material law at a given position.
Definition: tutorial1problem.hh:239
Scalar temperature(const Context &, unsigned, unsigned) const
Returns the temperature at a given position.
Definition: tutorial1problem.hh:221
static void registerParameters()
Definition: tutorial1problem.hh:197
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
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:235
Dune::YaspGrid< 2 > type
Definition: tutorial1problem.hh:80
The type of the DUNE grid.
Definition: basicproperties.hh:100
Opm::EffToAbsLaw< RawMaterialLaw > type
Definition: tutorial1problem.hh:120
The material law which ought to be used (extracted from the spatial parameters)
Definition: multiphasebaseproperties.hh:51
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: tutorial1problem.hh:96
Opm::LiquidPhase< Scalar, Opm::LNAPL< Scalar > > type
Definition: tutorial1problem.hh:97
The non-wetting phase for two-phase models.
Definition: immiscibleproperties.hh:44
The type of the problem.
Definition: fvbaseproperties.hh:81
The splice to be used for the spatial discretization.
Definition: multiphasebaseproperties.hh:39
Definition: tutorial1problem.hh:65
std::tuple< ImmiscibleTwoPhaseModel > InheritsFrom
Definition: tutorial1problem.hh:65
Definition: vcfvproperties.hh:41
Property which provides a Vanguard (manages grids)
Definition: basicproperties.hh:96
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: tutorial1problem.hh:88
Opm::LiquidPhase< Scalar, Opm::SimpleH2O< Scalar > > type
Definition: tutorial1problem.hh:89
The wetting phase for two-phase models.
Definition: immiscibleproperties.hh:41