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