diffusionproblem.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_POWER_INJECTION_PROBLEM_HH
29#define EWOMS_POWER_INJECTION_PROBLEM_HH
30
32
34
35#include <opm/material/fluidmatrixinteractions/LinearMaterial.hpp>
36#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
37#include <opm/material/fluidsystems/H2ON2FluidSystem.hpp>
38#include <opm/material/fluidstates/CompositionalFluidState.hpp>
39#include <opm/material/constraintsolvers/ComputeFromReferencePhase.hpp>
40
41#include <dune/grid/yaspgrid.hh>
42#include <dune/common/version.hh>
43#include <dune/common/fvector.hh>
44#include <dune/common/fmatrix.hh>
45
46#include <sstream>
47#include <string>
48
49namespace Opm {
50template <class TypeTag>
51class DiffusionProblem;
52}
53
54namespace Opm::Properties {
55
56namespace TTag {
57
59
60} // namespace TTag
61
62// Set the grid implementation to be used
63template<class TypeTag>
64struct Grid<TypeTag, TTag::DiffusionBaseProblem> { using type = Dune::YaspGrid</*dim=*/1>; };
65
66// set the Vanguard property
67template<class TypeTag>
68struct Vanguard<TypeTag, TTag::DiffusionBaseProblem> { using type = Opm::CubeGridVanguard<TypeTag>; };
69
70// Set the problem property
71template<class TypeTag>
72struct Problem<TypeTag, TTag::DiffusionBaseProblem> { using type = Opm::DiffusionProblem<TypeTag>; };
73
74// Set the fluid system
75template<class TypeTag>
76struct FluidSystem<TypeTag, TTag::DiffusionBaseProblem>
77{
78private:
80
81public:
82 using type = Opm::H2ON2FluidSystem<Scalar>;
83};
84
85// Set the material Law
86template<class TypeTag>
87struct MaterialLaw<TypeTag, TTag::DiffusionBaseProblem>
88{
89private:
92
93 static_assert(FluidSystem::numPhases == 2,
94 "A fluid system with two phases is required "
95 "for this problem!");
96
97 using Traits = Opm::TwoPhaseMaterialTraits<Scalar,
98 /*wettingPhaseIdx=*/FluidSystem::liquidPhaseIdx,
99 /*nonWettingPhaseIdx=*/FluidSystem::gasPhaseIdx>;
100
101public:
102 using type = Opm::LinearMaterial<Traits>;
103};
104
105// Enable molecular diffusion for this problem
106template<class TypeTag>
107struct EnableDiffusion<TypeTag, TTag::DiffusionBaseProblem> { static constexpr bool value = true; };
108
109} // namespace Opm::Properties
110
111namespace Opm {
122template <class TypeTag>
123class DiffusionProblem : public GetPropType<TypeTag, Properties::BaseProblem>
124{
126
133
134 enum {
135 // number of phases
136 numPhases = FluidSystem::numPhases,
137
138 // phase indices
139 liquidPhaseIdx = FluidSystem::liquidPhaseIdx,
140 gasPhaseIdx = FluidSystem::gasPhaseIdx,
141
142 // component indices
143 H2OIdx = FluidSystem::H2OIdx,
144 N2Idx = FluidSystem::N2Idx,
145
146 // Grid and world dimension
147 dim = GridView::dimension,
148 dimWorld = GridView::dimensionworld
149 };
150
154
157
158 using CoordScalar = typename GridView::ctype;
159 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
160
161 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
162
163public:
167 DiffusionProblem(Simulator& simulator)
168 : ParentType(simulator)
169 { }
170
175 {
176 ParentType::finishInit();
177
178 FluidSystem::init();
179
180 temperature_ = 273.15 + 20.0;
181
182 materialParams_.finalize();
183
184 K_ = this->toDimMatrix_(1e-12); // [m^2]
185
186 setupInitialFluidStates_();
187 }
188
192 static void registerParameters()
193 {
194 ParentType::registerParameters();
195
196 Parameters::SetDefault<Parameters::CellsX>(250);
197
198 if constexpr (dim > 1) {
199 Parameters::SetDefault<Parameters::CellsY>(1);
200 }
201 if constexpr (dim == 3) {
202 Parameters::SetDefault<Parameters::CellsZ>(1);
203 }
204
205 Parameters::SetDefault<Parameters::EndTime<Scalar>>(1e6);
206 Parameters::SetDefault<Parameters::InitialTimeStepSize<Scalar>>(1000);
207 }
208
213
217 std::string name() const
218 { return std::string("diffusion_") + Model::name(); }
219
224 {
225#ifndef NDEBUG
226 this->model().checkConservativeness();
227
228 // Calculate storage terms
229 EqVector storage;
230 this->model().globalStorage(storage);
231
232 // Write mass balance information for rank 0
233 if (this->gridView().comm().rank() == 0) {
234 std::cout << "Storage: " << storage << std::endl << std::flush;
235 }
236#endif // NDEBUG
237 }
238
240
245
249 template <class Context>
250 const DimMatrix& intrinsicPermeability(const Context& /*context*/,
251 unsigned /*spaceIdx*/,
252 unsigned /*timeIdx*/) const
253 { return K_; }
254
258 template <class Context>
259 Scalar porosity(const Context& /*context*/,
260 unsigned /*spaceIdx*/,
261 unsigned /*timeIdx*/) const
262 { return 0.35; }
263
267 template <class Context>
268 const MaterialLawParams&
269 materialLawParams(const Context& /*context*/,
270 unsigned /*spaceIdx*/,
271 unsigned /*timeIdx*/) const
272 { return materialParams_; }
273
277 template <class Context>
278 Scalar temperature(const Context& /*context*/,
279 unsigned /*spaceIdx*/,
280 unsigned /*timeIdx*/) const
281 { return temperature_; }
282
284
289
295 template <class Context>
296 void boundary(BoundaryRateVector& values,
297 const Context& /*context*/,
298 unsigned /*spaceIdx*/,
299 unsigned /*timeIdx*/) const
300 { values.setNoFlow(); }
301
303
308
312 template <class Context>
313 void initial(PrimaryVariables& values,
314 const Context& context,
315 unsigned spaceIdx,
316 unsigned timeIdx) const
317 {
318 const auto& pos = context.pos(spaceIdx, timeIdx);
319 if (onLeftSide_(pos))
320 values.assignNaive(leftInitialFluidState_);
321 else
322 values.assignNaive(rightInitialFluidState_);
323 }
324
331 template <class Context>
332 void source(RateVector& rate,
333 const Context& /*context*/,
334 unsigned /*spaceIdx*/,
335 unsigned /*timeIdx*/) const
336 { rate = Scalar(0.0); }
337
339
340private:
341 bool onLeftSide_(const GlobalPosition& pos) const
342 { return pos[0] < (this->boundingBoxMin()[0] + this->boundingBoxMax()[0]) / 2; }
343
344 void setupInitialFluidStates_()
345 {
346 // create the initial fluid state for the left half of the domain
347 leftInitialFluidState_.setTemperature(temperature_);
348
349 Scalar Sl = 0.0;
350 leftInitialFluidState_.setSaturation(liquidPhaseIdx, Sl);
351 leftInitialFluidState_.setSaturation(gasPhaseIdx, 1 - Sl);
352
353 Scalar p = 1e5;
354 leftInitialFluidState_.setPressure(liquidPhaseIdx, p);
355 leftInitialFluidState_.setPressure(gasPhaseIdx, p);
356
357 Scalar xH2O = 0.01;
358 leftInitialFluidState_.setMoleFraction(gasPhaseIdx, H2OIdx, xH2O);
359 leftInitialFluidState_.setMoleFraction(gasPhaseIdx, N2Idx, 1 - xH2O);
360
361 using CFRP = Opm::ComputeFromReferencePhase<Scalar, FluidSystem>;
362 typename FluidSystem::template ParameterCache<Scalar> paramCache;
363 CFRP::solve(leftInitialFluidState_, paramCache, gasPhaseIdx,
364 /*setViscosity=*/false, /*setEnthalpy=*/false);
365
366 // create the initial fluid state for the right half of the domain
367 rightInitialFluidState_.assign(leftInitialFluidState_);
368 xH2O = 0.0;
369 rightInitialFluidState_.setMoleFraction(gasPhaseIdx, H2OIdx, xH2O);
370 rightInitialFluidState_.setMoleFraction(gasPhaseIdx, N2Idx, 1 - xH2O);
371 CFRP::solve(rightInitialFluidState_, paramCache, gasPhaseIdx,
372 /*setViscosity=*/false, /*setEnthalpy=*/false);
373 }
374
375 DimMatrix K_;
376 MaterialLawParams materialParams_;
377
378 Opm::CompositionalFluidState<Scalar, FluidSystem> leftInitialFluidState_;
379 Opm::CompositionalFluidState<Scalar, FluidSystem> rightInitialFluidState_;
380 Scalar temperature_;
381};
382
383} // namespace Opm
384
385#endif
Provides a simulator vanguad which creates a regular grid made of quadrilaterals.
Definition: cubegridvanguard.hh:53
1D problem which is driven by molecular diffusion.
Definition: diffusionproblem.hh:124
Scalar temperature(const Context &, unsigned, unsigned) const
Definition: diffusionproblem.hh:278
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: diffusionproblem.hh:313
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: diffusionproblem.hh:174
Scalar porosity(const Context &, unsigned, unsigned) const
Definition: diffusionproblem.hh:259
void boundary(BoundaryRateVector &values, const Context &, unsigned, unsigned) const
Evaluate the boundary conditions for a boundary segment.
Definition: diffusionproblem.hh:296
void source(RateVector &rate, const Context &, unsigned, unsigned) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: diffusionproblem.hh:332
DiffusionProblem(Simulator &simulator)
Definition: diffusionproblem.hh:167
void endTimeStep()
Called by the simulator after each time integration.
Definition: diffusionproblem.hh:223
std::string name() const
The problem name.
Definition: diffusionproblem.hh:217
const MaterialLawParams & materialLawParams(const Context &, unsigned, unsigned) const
Definition: diffusionproblem.hh:269
static void registerParameters()
Definition: diffusionproblem.hh:192
const DimMatrix & intrinsicPermeability(const Context &, unsigned, unsigned) const
Definition: diffusionproblem.hh:250
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 NCP compositional multi-phase model.
Enable diffusive fluxes?
Definition: multiphasebaseproperties.hh:79
Opm::H2ON2FluidSystem< Scalar > type
Definition: diffusionproblem.hh:82
The fluid systems including the information about the phases.
Definition: multiphasebaseproperties.hh:69
Dune::YaspGrid< 1 > type
Definition: diffusionproblem.hh:64
The type of the DUNE grid.
Definition: basicproperties.hh:100
Opm::LinearMaterial< Traits > type
Definition: diffusionproblem.hh:102
The material law which ought to be used (extracted from the spatial parameters)
Definition: multiphasebaseproperties.hh:51
The type of the problem.
Definition: fvbaseproperties.hh:81
Definition: diffusionproblem.hh:58
Property which provides a Vanguard (manages grids)
Definition: basicproperties.hh:96