My Project
waterairproblem.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_WATER_AIR_PROBLEM_HH
29#define EWOMS_WATER_AIR_PROBLEM_HH
30
31#include <opm/models/pvs/pvsproperties.hh>
32#include <opm/simulators/linalg/parallelistlbackend.hh>
33
34#include <opm/material/fluidsystems/H2OAirFluidSystem.hpp>
35#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
36#include <opm/material/fluidstates/CompositionalFluidState.hpp>
37#include <opm/material/fluidmatrixinteractions/LinearMaterial.hpp>
38#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp>
39#include <opm/material/fluidmatrixinteractions/EffToAbsLaw.hpp>
40#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
41#include <opm/material/thermal/ConstantSolidHeatCapLaw.hpp>
42#include <opm/material/thermal/SomertonThermalConductionLaw.hpp>
43#include <opm/material/constraintsolvers/ComputeFromReferencePhase.hpp>
44
45#include <dune/grid/yaspgrid.hh>
46#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
47
48#include <dune/common/fvector.hh>
49#include <dune/common/fmatrix.hh>
50
51#include <sstream>
52#include <string>
53
54namespace Opm {
55template <class TypeTag>
56class WaterAirProblem;
57}
58
59namespace Opm::Properties {
60
61namespace TTag {
63}
64
65// Set the grid type
66template<class TypeTag>
67struct Grid<TypeTag, TTag::WaterAirBaseProblem> { using type = Dune::YaspGrid<2>; };
68
69// Set the problem property
70template<class TypeTag>
71struct Problem<TypeTag, TTag::WaterAirBaseProblem> { using type = Opm::WaterAirProblem<TypeTag>; };
72
73// Set the material Law
74template<class TypeTag>
75struct MaterialLaw<TypeTag, TTag::WaterAirBaseProblem>
76{
77private:
78 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
79 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
80 using Traits = Opm::TwoPhaseMaterialTraits<Scalar,
81 /*wettingPhaseIdx=*/FluidSystem::liquidPhaseIdx,
82 /*nonWettingPhaseIdx=*/FluidSystem::gasPhaseIdx>;
83
84 // define the material law which is parameterized by effective
85 // saturations
86 using EffMaterialLaw = Opm::RegularizedBrooksCorey<Traits>;
87
88public:
89 // define the material law parameterized by absolute saturations
90 // which uses the two-phase API
91 using type = Opm::EffToAbsLaw<EffMaterialLaw>;
92};
93
94// Set the thermal conduction law
95template<class TypeTag>
96struct ThermalConductionLaw<TypeTag, TTag::WaterAirBaseProblem>
97{
98private:
99 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
100 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
101
102public:
103 // define the material law parameterized by absolute saturations
104 using type = Opm::SomertonThermalConductionLaw<FluidSystem, Scalar>;
105};
106
107// set the energy storage law for the solid phase
108template<class TypeTag>
109struct SolidEnergyLaw<TypeTag, TTag::WaterAirBaseProblem>
110{ using type = Opm::ConstantSolidHeatCapLaw<GetPropType<TypeTag, Properties::Scalar>>; };
111
112// Set the fluid system. in this case, we use the one which describes
113// air and water
114template<class TypeTag>
115struct FluidSystem<TypeTag, TTag::WaterAirBaseProblem>
116{ using type = Opm::H2OAirFluidSystem<GetPropType<TypeTag, Properties::Scalar>>; };
117
118// Enable gravity
119template<class TypeTag>
120struct EnableGravity<TypeTag, TTag::WaterAirBaseProblem> { static constexpr bool value = true; };
121
122// Use forward differences instead of central differences
123template<class TypeTag>
124struct NumericDifferenceMethod<TypeTag, TTag::WaterAirBaseProblem> { static constexpr int value = +1; };
125
126// Write newton convergence
127template<class TypeTag>
128struct NewtonWriteConvergence<TypeTag, TTag::WaterAirBaseProblem> { static constexpr bool value = false; };
129
130// The default for the end time of the simulation (1 year)
131template<class TypeTag>
132struct EndTime<TypeTag, TTag::WaterAirBaseProblem>
133{
134 using type = GetPropType<TypeTag, Scalar>;
135 static constexpr type value = 1.0 * 365 * 24 * 60 * 60;
136};
137
138// The default for the initial time step size of the simulation
139template<class TypeTag>
140struct InitialTimeStepSize<TypeTag, TTag::WaterAirBaseProblem>
141{
142 using type = GetPropType<TypeTag, Scalar>;
143 static constexpr type value = 250;
144};
145
146// The default DGF file to load
147template<class TypeTag>
148struct GridFile<TypeTag, TTag::WaterAirBaseProblem> { static constexpr auto value = "./data/waterair.dgf"; };
149
150// Use the restarted GMRES linear solver with the ILU-2 preconditioner from dune-istl
151template<class TypeTag>
152struct LinearSolverSplice<TypeTag, TTag::WaterAirBaseProblem>
153{ using type = TTag::ParallelIstlLinearSolver; };
154
155template<class TypeTag>
156struct LinearSolverWrapper<TypeTag, TTag::WaterAirBaseProblem>
157{ using type = Opm::Linear::SolverWrapperRestartedGMRes<TypeTag>; };
158
159template<class TypeTag>
160struct PreconditionerWrapper<TypeTag, TTag::WaterAirBaseProblem>
161{ using type = Opm::Linear::PreconditionerWrapperILU<TypeTag>; };
162template<class TypeTag>
163struct PreconditionerOrder<TypeTag, TTag::WaterAirBaseProblem> { static constexpr int value = 2; };
164
165} // namespace Opm::Properties
166
167namespace Opm {
196template <class TypeTag >
197class WaterAirProblem : public GetPropType<TypeTag, Properties::BaseProblem>
198{
199 using ParentType = GetPropType<TypeTag, Properties::BaseProblem>;
200
201 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
202 using GridView = GetPropType<TypeTag, Properties::GridView>;
203
204 // copy some indices for convenience
205 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
206 using Indices = GetPropType<TypeTag, Properties::Indices>;
207 enum {
208 numPhases = FluidSystem::numPhases,
209
210 // energy related indices
211 temperatureIdx = Indices::temperatureIdx,
212 energyEqIdx = Indices::energyEqIdx,
213
214 // component indices
215 H2OIdx = FluidSystem::H2OIdx,
216 AirIdx = FluidSystem::AirIdx,
217
218 // phase indices
219 liquidPhaseIdx = FluidSystem::liquidPhaseIdx,
220 gasPhaseIdx = FluidSystem::gasPhaseIdx,
221
222 // equation indices
223 conti0EqIdx = Indices::conti0EqIdx,
224
225 // Grid and world dimension
226 dim = GridView::dimension,
227 dimWorld = GridView::dimensionworld
228 };
229
230 static const bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>();
231
232 using EqVector = GetPropType<TypeTag, Properties::EqVector>;
233 using RateVector = GetPropType<TypeTag, Properties::RateVector>;
234 using BoundaryRateVector = GetPropType<TypeTag, Properties::BoundaryRateVector>;
235 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
236 using Constraints = GetPropType<TypeTag, Properties::Constraints>;
237 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
238 using Model = GetPropType<TypeTag, Properties::Model>;
239 using MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw>;
240 using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>;
241 using ThermalConductionLawParams = GetPropType<TypeTag, Properties::ThermalConductionLawParams>;
242 using SolidEnergyLawParams = GetPropType<TypeTag, Properties::SolidEnergyLawParams>;
243
244 using CoordScalar = typename GridView::ctype;
245 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
246
247 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
248
249public:
253 WaterAirProblem(Simulator& simulator)
254 : ParentType(simulator)
255 { }
256
261 {
262 ParentType::finishInit();
263
264 maxDepth_ = 1000.0; // [m]
265 eps_ = 1e-6;
266
267 FluidSystem::init(/*Tmin=*/275, /*Tmax=*/600, /*nT=*/100,
268 /*pmin=*/9.5e6, /*pmax=*/10.5e6, /*np=*/200);
269
270 layerBottom_ = 22.0;
271
272 // intrinsic permeabilities
273 fineK_ = this->toDimMatrix_(1e-13);
274 coarseK_ = this->toDimMatrix_(1e-12);
275
276 // porosities
277 finePorosity_ = 0.3;
278 coarsePorosity_ = 0.3;
279
280 // residual saturations
281 fineMaterialParams_.setResidualSaturation(liquidPhaseIdx, 0.2);
282 fineMaterialParams_.setResidualSaturation(gasPhaseIdx, 0.0);
283 coarseMaterialParams_.setResidualSaturation(liquidPhaseIdx, 0.2);
284 coarseMaterialParams_.setResidualSaturation(gasPhaseIdx, 0.0);
285
286 // parameters for the Brooks-Corey law
287 fineMaterialParams_.setEntryPressure(1e4);
288 coarseMaterialParams_.setEntryPressure(1e4);
289 fineMaterialParams_.setLambda(2.0);
290 coarseMaterialParams_.setLambda(2.0);
291
292 fineMaterialParams_.finalize();
293 coarseMaterialParams_.finalize();
294
295 // parameters for the somerton law of thermal conduction
296 computeThermalCondParams_(fineThermalCondParams_, finePorosity_);
297 computeThermalCondParams_(coarseThermalCondParams_, coarsePorosity_);
298
299 // assume constant volumetric heat capacity and granite
300 solidEnergyLawParams_.setSolidHeatCapacity(790.0 // specific heat capacity of granite [J / (kg K)]
301 * 2700.0); // density of granite [kg/m^3]
302 solidEnergyLawParams_.finalize();
303 }
304
309
313 std::string name() const
314 {
315 std::ostringstream oss;
316 oss << "waterair_" << Model::name();
317 if (getPropValue<TypeTag, Properties::EnableEnergy>())
318 oss << "_ni";
319
320 return oss.str();
321 }
322
327 {
328#ifndef NDEBUG
329 // checkConservativeness() does not include the effect of constraints, so we
330 // disable it for this problem...
331 //this->model().checkConservativeness();
332
333 // Calculate storage terms
334 EqVector storage;
335 this->model().globalStorage(storage);
336
337 // Write mass balance information for rank 0
338 if (this->gridView().comm().rank() == 0) {
339 std::cout << "Storage: " << storage << std::endl << std::flush;
340 }
341#endif // NDEBUG
342 }
343
350 template <class Context>
351 const DimMatrix& intrinsicPermeability(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
352 {
353 const GlobalPosition& pos = context.pos(spaceIdx, timeIdx);
354 if (isFineMaterial_(pos))
355 return fineK_;
356 return coarseK_;
357 }
358
362 template <class Context>
363 Scalar porosity(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
364 {
365 const GlobalPosition& pos = context.pos(spaceIdx, timeIdx);
366 if (isFineMaterial_(pos))
367 return finePorosity_;
368 else
369 return coarsePorosity_;
370 }
371
375 template <class Context>
376 const MaterialLawParams& materialLawParams(const Context& context,
377 unsigned spaceIdx,
378 unsigned timeIdx) const
379 {
380 const GlobalPosition& pos = context.pos(spaceIdx, timeIdx);
381 if (isFineMaterial_(pos))
382 return fineMaterialParams_;
383 else
384 return coarseMaterialParams_;
385 }
386
392 template <class Context>
393 const SolidEnergyLawParams&
394 solidEnergyLawParams(const Context& /*context*/,
395 unsigned /*spaceIdx*/,
396 unsigned /*timeIdx*/) const
397 { return solidEnergyLawParams_; }
398
402 template <class Context>
403 const ThermalConductionLawParams&
404 thermalConductionLawParams(const Context& context,
405 unsigned spaceIdx,
406 unsigned timeIdx) const
407 {
408 const GlobalPosition& pos = context.pos(spaceIdx, timeIdx);
409 if (isFineMaterial_(pos))
410 return fineThermalCondParams_;
411 return coarseThermalCondParams_;
412 }
413
415
420
429 template <class Context>
430 void boundary(BoundaryRateVector& values,
431 const Context& context,
432 unsigned spaceIdx, unsigned timeIdx) const
433 {
434 const auto& pos = context.cvCenter(spaceIdx, timeIdx);
435 assert(onLeftBoundary_(pos) ||
436 onLowerBoundary_(pos) ||
437 onRightBoundary_(pos) ||
438 onUpperBoundary_(pos));
439
440 if (onInlet_(pos)) {
441 RateVector massRate(0.0);
442 massRate[conti0EqIdx + AirIdx] = -1e-3; // [kg/(m^2 s)]
443
444 // impose an forced inflow boundary condition on the inlet
445 values.setMassRate(massRate);
446
447 if (enableEnergy) {
448 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
449 initialFluidState_(fs, context, spaceIdx, timeIdx);
450
451 Scalar hl = fs.enthalpy(liquidPhaseIdx);
452 Scalar hg = fs.enthalpy(gasPhaseIdx);
453 values.setEnthalpyRate(values[conti0EqIdx + AirIdx] * hg +
454 values[conti0EqIdx + H2OIdx] * hl);
455 }
456 }
457 else if (onLeftBoundary_(pos) || onRightBoundary_(pos)) {
458 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
459 initialFluidState_(fs, context, spaceIdx, timeIdx);
460
461 // impose an freeflow boundary condition
462 values.setFreeFlow(context, spaceIdx, timeIdx, fs);
463 }
464 else
465 // no flow on top and bottom
466 values.setNoFlow();
467 }
468
470
475
482 template <class Context>
483 void initial(PrimaryVariables& values,
484 const Context& context,
485 unsigned spaceIdx,
486 unsigned timeIdx) const
487 {
488 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
489 initialFluidState_(fs, context, spaceIdx, timeIdx);
490
491 const auto& matParams = materialLawParams(context, spaceIdx, timeIdx);
492 values.assignMassConservative(fs, matParams, /*inEquilibrium=*/true);
493 }
494
501 template <class Context>
502 void source(RateVector& rate,
503 const Context& /*context*/,
504 unsigned /*spaceIdx*/,
505 unsigned /*timeIdx*/) const
506 { rate = 0; }
507
509
510private:
511 bool onLeftBoundary_(const GlobalPosition& pos) const
512 { return pos[0] < eps_; }
513
514 bool onRightBoundary_(const GlobalPosition& pos) const
515 { return pos[0] > this->boundingBoxMax()[0] - eps_; }
516
517 bool onLowerBoundary_(const GlobalPosition& pos) const
518 { return pos[1] < eps_; }
519
520 bool onUpperBoundary_(const GlobalPosition& pos) const
521 { return pos[1] > this->boundingBoxMax()[1] - eps_; }
522
523 bool onInlet_(const GlobalPosition& pos) const
524 { return onLowerBoundary_(pos) && (15.0 < pos[0]) && (pos[0] < 25.0); }
525
526 bool inHighTemperatureRegion_(const GlobalPosition& pos) const
527 { return (20 < pos[0]) && (pos[0] < 30) && (pos[1] < 30); }
528
529 template <class Context, class FluidState>
530 void initialFluidState_(FluidState& fs,
531 const Context& context,
532 unsigned spaceIdx,
533 unsigned timeIdx) const
534 {
535 const GlobalPosition& pos = context.pos(spaceIdx, timeIdx);
536
537 Scalar densityW = 1000.0;
538 fs.setPressure(liquidPhaseIdx, 1e5 + (maxDepth_ - pos[1])*densityW*9.81);
539 fs.setSaturation(liquidPhaseIdx, 1.0);
540 fs.setMoleFraction(liquidPhaseIdx, H2OIdx, 1.0);
541 fs.setMoleFraction(liquidPhaseIdx, AirIdx, 0.0);
542
543 if (inHighTemperatureRegion_(pos))
544 fs.setTemperature(380);
545 else
546 fs.setTemperature(283.0 + (maxDepth_ - pos[1])*0.03);
547
548 // set the gas saturation and pressure
549 fs.setSaturation(gasPhaseIdx, 0);
550 Scalar pc[numPhases];
551 const auto& matParams = materialLawParams(context, spaceIdx, timeIdx);
552 MaterialLaw::capillaryPressures(pc, matParams, fs);
553 fs.setPressure(gasPhaseIdx, fs.pressure(liquidPhaseIdx) + (pc[gasPhaseIdx] - pc[liquidPhaseIdx]));
554
555 typename FluidSystem::template ParameterCache<Scalar> paramCache;
556 using CFRP = Opm::ComputeFromReferencePhase<Scalar, FluidSystem>;
557 CFRP::solve(fs, paramCache, liquidPhaseIdx, /*setViscosity=*/true, /*setEnthalpy=*/true);
558 }
559
560 void computeThermalCondParams_(ThermalConductionLawParams& params, Scalar poro)
561 {
562 Scalar lambdaGranite = 2.8; // [W / (K m)]
563
564 // create a Fluid state which has all phases present
565 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
566 fs.setTemperature(293.15);
567 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
568 fs.setPressure(phaseIdx, 1.0135e5);
569 }
570
571 typename FluidSystem::template ParameterCache<Scalar> paramCache;
572 paramCache.updateAll(fs);
573 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
574 Scalar rho = FluidSystem::density(fs, paramCache, phaseIdx);
575 fs.setDensity(phaseIdx, rho);
576 }
577
578 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
579 Scalar lambdaSaturated;
580 if (FluidSystem::isLiquid(phaseIdx)) {
581 Scalar lambdaFluid =
582 FluidSystem::thermalConductivity(fs, paramCache, phaseIdx);
583 lambdaSaturated = std::pow(lambdaGranite, (1-poro)) + std::pow(lambdaFluid, poro);
584 }
585 else
586 lambdaSaturated = std::pow(lambdaGranite, (1-poro));
587
588 params.setFullySaturatedLambda(phaseIdx, lambdaSaturated);
589 if (!FluidSystem::isLiquid(phaseIdx))
590 params.setVacuumLambda(lambdaSaturated);
591 }
592 }
593
594 bool isFineMaterial_(const GlobalPosition& pos) const
595 { return pos[dim-1] > layerBottom_; }
596
597 DimMatrix fineK_;
598 DimMatrix coarseK_;
599 Scalar layerBottom_;
600
601 Scalar finePorosity_;
602 Scalar coarsePorosity_;
603
604 MaterialLawParams fineMaterialParams_;
605 MaterialLawParams coarseMaterialParams_;
606
607 ThermalConductionLawParams fineThermalCondParams_;
608 ThermalConductionLawParams coarseThermalCondParams_;
609 SolidEnergyLawParams solidEnergyLawParams_;
610
611 Scalar maxDepth_;
612 Scalar eps_;
613};
614} // namespace Opm
615
616#endif
Non-isothermal gas injection problem where a air is injected into a fully water saturated medium.
Definition: waterairproblem.hh:198
const DimMatrix & intrinsicPermeability(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:351
void finishInit()
Definition: waterairproblem.hh:260
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:483
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:430
std::string name() const
Definition: waterairproblem.hh:313
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:363
void source(RateVector &rate, const Context &, unsigned, unsigned) const
Definition: waterairproblem.hh:502
const ThermalConductionLawParams & thermalConductionLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:404
void endTimeStep()
Definition: waterairproblem.hh:326
WaterAirProblem(Simulator &simulator)
Definition: waterairproblem.hh:253
const MaterialLawParams & materialLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: waterairproblem.hh:376
const SolidEnergyLawParams & solidEnergyLawParams(const Context &, unsigned, unsigned) const
Return the parameters for the energy storage law of the rock.
Definition: waterairproblem.hh:394
Definition: waterairproblem.hh:62