outflowproblem.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*/
27#ifndef EWOMS_OUTFLOW_PROBLEM_HH
28#define EWOMS_OUTFLOW_PROBLEM_HH
29
31
32#include <opm/material/fluidstates/CompositionalFluidState.hpp>
33#include <opm/material/fluidsystems/H2ON2LiquidPhaseFluidSystem.hpp>
34
35#include <dune/grid/yaspgrid.hh>
36#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
37
38#include <dune/common/version.hh>
39#include <dune/common/fvector.hh>
40#include <dune/common/fmatrix.hh>
41
42namespace Opm {
43template <class TypeTag>
44class OutflowProblem;
45}
46
47namespace Opm::Properties {
48
49namespace TTag {
50
52
53} // namespace TTag
54
55// Set the grid type
56template<class TypeTag>
57struct Grid<TypeTag, TTag::OutflowBaseProblem> { using type = Dune::YaspGrid<2>; };
58
59// Set the problem property
60template<class TypeTag>
61struct Problem<TypeTag, TTag::OutflowBaseProblem> { using type = Opm::OutflowProblem<TypeTag>; };
62
63// Set fluid system
64template<class TypeTag>
65struct FluidSystem<TypeTag, TTag::OutflowBaseProblem>
66{
67private:
69
70public:
71 // Two-component single phase fluid system
72 using type = Opm::H2ON2LiquidPhaseFluidSystem<Scalar>;
73};
74
75} // namespace Opm::Properties
76
77namespace Opm {
95template <class TypeTag>
96class OutflowProblem : public GetPropType<TypeTag, Properties::BaseProblem>
97{
99
109
110 // copy some indices for convenience
111 enum {
112 // Grid and world dimension
113 dim = GridView::dimension,
114 dimWorld = GridView::dimensionworld,
115
116 numPhases = FluidSystem::numPhases,
117
118 // component indices
119 H2OIdx = FluidSystem::H2OIdx,
120 N2Idx = FluidSystem::N2Idx
121 };
122
123 using CoordScalar = typename GridView::ctype;
124 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
125
126 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
127
128public:
132 OutflowProblem(Simulator& simulator)
133 : ParentType(simulator)
134 , eps_(1e-6)
135 { }
136
141 {
142 ParentType::finishInit();
143
144 temperature_ = 273.15 + 20;
145 FluidSystem::init(/*minT=*/temperature_ - 1, /*maxT=*/temperature_ + 2,
146 /*numT=*/3,
147 /*minp=*/0.8e5, /*maxp=*/2.5e5, /*nump=*/500);
148
149 // set parameters of porous medium
150 perm_ = this->toDimMatrix_(1e-10);
151 porosity_ = 0.4;
152 tortuosity_ = 0.28;
153 }
154
158 static void registerParameters()
159 {
160 ParentType::registerParameters();
161
162 Parameters::SetDefault<Parameters::GridFile>("./data/outflow.dgf");
163 Parameters::SetDefault<Parameters::EndTime<Scalar>>(100.0);
164 Parameters::SetDefault<Parameters::InitialTimeStepSize<Scalar>>(1.0);
165
166 Parameters::SetDefault<Parameters::VtkWriteMassFractions>(true);
167 }
168
173
177 std::string name() const
178 { return "outflow"; }
179
184 {
185#ifndef NDEBUG
186 this->model().checkConservativeness();
187
188 // Calculate storage terms
189 EqVector storage;
190 this->model().globalStorage(storage);
191
192 // Write mass balance information for rank 0
193 if (this->gridView().comm().rank() == 0) {
194 std::cout << "Storage: " << storage << std::endl << std::flush;
195 }
196#endif // NDEBUG
197 }
198
204 template <class Context>
205 Scalar temperature(const Context& /*context*/,
206 unsigned /*spaceIdx*/,
207 unsigned /*timeIdx*/) const
208 { return temperature_; } // in [K]
209
215 template <class Context>
216 const DimMatrix& intrinsicPermeability(const Context& /*context*/,
217 unsigned /*spaceIdx*/,
218 unsigned /*timeIdx*/) const
219 { return perm_; }
220
226 template <class Context>
227 Scalar porosity(const Context& /*context*/,
228 unsigned /*spaceIdx*/,
229 unsigned /*timeIdx*/) const
230 { return porosity_; }
231
232#if 0
237 template <class Context>
238 Scalar tortuosity(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
239 { return tortuosity_; }
240
245 template <class Context>
246 Scalar dispersivity(const Context& context,
247 unsigned spaceIdx, unsigned timeIdx) const
248 { return 0; }
249#endif
250
252
257
261 template <class Context>
262 void boundary(BoundaryRateVector& values, const Context& context,
263 unsigned spaceIdx, unsigned timeIdx) const
264 {
265 const GlobalPosition& globalPos = context.pos(spaceIdx, timeIdx);
266
267 if (onLeftBoundary_(globalPos)) {
268 Opm::CompositionalFluidState<Scalar, FluidSystem,
269 /*storeEnthalpy=*/false> fs;
270 initialFluidState_(fs, context, spaceIdx, timeIdx);
271 fs.setPressure(/*phaseIdx=*/0, fs.pressure(/*phaseIdx=*/0) + 1e5);
272
273 Scalar xlN2 = 2e-4;
274 fs.setMoleFraction(/*phaseIdx=*/0, N2Idx, xlN2);
275 fs.setMoleFraction(/*phaseIdx=*/0, H2OIdx, 1 - xlN2);
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 // impose an freeflow boundary condition
285 values.setFreeFlow(context, spaceIdx, timeIdx, fs);
286 }
287 else if (onRightBoundary_(globalPos)) {
288 Opm::CompositionalFluidState<Scalar, FluidSystem,
289 /*storeEnthalpy=*/false> fs;
290 initialFluidState_(fs, context, spaceIdx, timeIdx);
291
292 // impose an outflow boundary condition
293 values.setOutFlow(context, spaceIdx, timeIdx, fs);
294 }
295 else
296 // no flow on top and bottom
297 values.setNoFlow();
298 }
299
301
306
310 template <class Context>
311 void initial(PrimaryVariables& values,
312 const Context& context,
313 unsigned spaceIdx,
314 unsigned timeIdx) const
315 {
316 Opm::CompositionalFluidState<Scalar, FluidSystem, /*storeEnthalpy=*/false> fs;
317 initialFluidState_(fs, context, spaceIdx, timeIdx);
318
319 values.assignNaive(fs);
320 }
321
328 template <class Context>
329 void source(RateVector& rate,
330 const Context& /*context*/,
331 unsigned /*spaceIdx*/,
332 unsigned /*timeIdx*/) const
333 { rate = Scalar(0.0); }
334
336
337private:
338 bool onLeftBoundary_(const GlobalPosition& pos) const
339 { return pos[0] < eps_; }
340
341 bool onRightBoundary_(const GlobalPosition& pos) const
342 { return pos[0] > this->boundingBoxMax()[0] - eps_; }
343
344 template <class FluidState, class Context>
345 void initialFluidState_(FluidState& fs, const Context& context,
346 unsigned spaceIdx, unsigned timeIdx) const
347 {
348 Scalar T = temperature(context, spaceIdx, timeIdx);
349 // Scalar rho = FluidSystem::H2O::liquidDensity(T, /*pressure=*/1.5e5);
350 // Scalar z = context.pos(spaceIdx, timeIdx)[dim - 1] -
351 // this->boundingBoxMax()[dim - 1];
352 // Scalar z = context.pos(spaceIdx, timeIdx)[dim - 1] -
353 // this->boundingBoxMax()[dim - 1];
354
355 fs.setSaturation(/*phaseIdx=*/0, 1.0);
356 fs.setPressure(/*phaseIdx=*/0, 1e5 /* + rho*z */);
357 fs.setMoleFraction(/*phaseIdx=*/0, H2OIdx, 1.0);
358 fs.setMoleFraction(/*phaseIdx=*/0, N2Idx, 0);
359 fs.setTemperature(T);
360
361 typename FluidSystem::template ParameterCache<Scalar> paramCache;
362 paramCache.updateAll(fs);
363 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
364 fs.setDensity(phaseIdx, FluidSystem::density(fs, paramCache, phaseIdx));
365 fs.setViscosity(phaseIdx, FluidSystem::viscosity(fs, paramCache, phaseIdx));
366 }
367 }
368
369 const Scalar eps_;
370
371 MaterialLawParams materialParams_;
372 DimMatrix perm_;
373 Scalar temperature_;
374 Scalar porosity_;
375 Scalar tortuosity_;
376};
377} // namespace Opm
378
379#endif
Problem where dissolved nitrogen is transported with the water phase from the left side to the right.
Definition: outflowproblem.hh:97
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: outflowproblem.hh:311
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: outflowproblem.hh:140
void endTimeStep()
Called by the simulator after each time integration.
Definition: outflowproblem.hh:183
OutflowProblem(Simulator &simulator)
Definition: outflowproblem.hh:132
void source(RateVector &rate, const Context &, unsigned, unsigned) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: outflowproblem.hh:329
Scalar temperature(const Context &, unsigned, unsigned) const
Definition: outflowproblem.hh:205
Scalar porosity(const Context &, unsigned, unsigned) const
Definition: outflowproblem.hh:227
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the boundary conditions for a boundary segment.
Definition: outflowproblem.hh:262
static void registerParameters()
Definition: outflowproblem.hh:158
const DimMatrix & intrinsicPermeability(const Context &, unsigned, unsigned) const
Definition: outflowproblem.hh:216
std::string name() const
The problem name.
Definition: outflowproblem.hh:177
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
Declares the properties required for the compositional multi-phase primary variable switching model.
Opm::H2ON2LiquidPhaseFluidSystem< Scalar > type
Definition: outflowproblem.hh:72
The fluid systems including the information about the phases.
Definition: multiphasebaseproperties.hh:69
Dune::YaspGrid< 2 > type
Definition: outflowproblem.hh:57
The type of the DUNE grid.
Definition: basicproperties.hh:100
The type of the problem.
Definition: fvbaseproperties.hh:81
Definition: outflowproblem.hh:51