3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
test/porousmediumflow/1pnc/implicit/1p3c/problem.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_1P3C_TEST_PROBLEM_HH
27#define DUMUX_1P3C_TEST_PROBLEM_HH
28
29#if HAVE_UG
30#include <dune/grid/uggrid.hh>
31#endif
32#include <dune/grid/yaspgrid.hh>
33
40
43
44#include "../1p2c/spatialparams.hh"
45
48
49namespace Dumux {
50
51template <class TypeTag>
52class MaxwellStefanOnePThreeCTestProblem;
53
54namespace Properties {
55
56// Create new type tags
57namespace TTag {
58struct MaxwellStefanOnePThreeCTest { using InheritsFrom = std::tuple<OnePNC>; };
59struct MaxwellStefanOnePThreeCTestBox { using InheritsFrom = std::tuple<MaxwellStefanOnePThreeCTest, BoxModel>; };
60struct MaxwellStefanOnePThreeCTestCCTpfa { using InheritsFrom = std::tuple<MaxwellStefanOnePThreeCTest, CCTpfaModel>; };
61} // end namespace TTag
62
63// Set the grid type
64#if HAVE_UG
65template<class TypeTag>
66struct Grid<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = Dune::UGGrid<2>; };
67#else
68template<class TypeTag>
69struct Grid<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = Dune::YaspGrid<2>; };
70#endif
71
72// Set the problem property
73template<class TypeTag>
74struct Problem<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = MaxwellStefanOnePThreeCTestProblem<TypeTag>; };
75
80template<class TypeTag>
82: public FluidSystems::Base<GetPropType<TypeTag, Properties::Scalar>, H2N2CO2FluidSystem<TypeTag>>
83
84{
89
90public:
92 static constexpr int numPhases = 1;
93 static constexpr int numComponents = 3;
94
95 static constexpr int H2Idx = 0; //first major component
96 static constexpr int N2Idx = 1; //second major component
97 static constexpr int CO2Idx = 2; //secondary component
98
100 static std::string componentName(int compIdx)
101 { return "MaxwellStefan_" + std::to_string(compIdx); }
102
104 static std::string phaseName(int phaseIdx = 0)
105 { return "Gas"; }
106
108 static Scalar molarMass(unsigned int compIdx)
109 {
110 switch (compIdx)
111 {
112 case H2Idx: return 0.002;
113 case N2Idx: return 0.028;
114 case CO2Idx:return 0.044;
115 }
116 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);;
117 }
118
130 template <class FluidState>
131 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
132 int phaseIdx,
133 int compIIdx,
134 int compJIdx)
135 {
136 if (compIIdx > compJIdx)
137 {
138 using std::swap;
139 swap(compIIdx, compJIdx);
140 }
141
142 if (compIIdx == H2Idx && compJIdx == N2Idx)
143 return 83.3e-6;
144 if (compIIdx == H2Idx && compJIdx == CO2Idx)
145 return 68.0e-6;
146 if (compIIdx == N2Idx && compJIdx == CO2Idx)
147 return 16.8e-6;
148 DUNE_THROW(Dune::InvalidStateException,
149 "Binary diffusion coefficient of components "
150 << compIIdx << " and " << compJIdx << " is undefined!\n");
151 }
152 using Base::density;
161 template <class FluidState>
162 static Scalar density(const FluidState &fluidState,
163 const int phaseIdx)
164 {
165 Scalar T = fluidState.temperature(phaseIdx);
166 Scalar p = fluidState.pressure(phaseIdx);
167 return IdealGas::molarDensity(T, p) * fluidState.averageMolarMass(0);
168 }
169
170 using Base::viscosity;
177 template <class FluidState>
178 static Scalar viscosity(const FluidState &fluidState,
179 int phaseIdx)
180 {
181 return 1e-6;
182 }
183
184 using Base::molarDensity;
194 template <class FluidState>
195 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
196 {
197 Scalar T = fluidState.temperature(phaseIdx);
198 Scalar p = fluidState.pressure(phaseIdx);
199 return IdealGas::molarDensity(T,p);
200 }
201};
202
203// Set fluid configuration
204template<class TypeTag>
205struct FluidSystem<TypeTag, TTag::MaxwellStefanOnePThreeCTest>
207
208// Set the spatial parameters
209template<class TypeTag>
210struct SpatialParams<TypeTag, TTag::MaxwellStefanOnePThreeCTest>
211{
215};
216
217// Define whether mole(true) or mass (false) fractions are used
218template<class TypeTag>
219struct UseMoles<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { static constexpr bool value = true; };
220
222template<class TypeTag>
223struct MolecularDiffusionType<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = MaxwellStefansLaw<TypeTag>; };
224}
225
239template <class TypeTag>
241{
243
254
256 static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
257
258 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
259 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
260
261public:
262 MaxwellStefanOnePThreeCTestProblem(std::shared_ptr<const GridGeometry> gridGeometry)
264 {
265 name_ = getParam<std::string>("Problem.Name");
266
267 // stating in the terminal whether mole or mass fractions are used
268 if (useMoles)
269 std::cout<<"problem uses mole fractions" << '\n';
270 else
271 std::cout<<"problem uses mass fractions" << '\n';
272
273 plotOutput_ = false;
274 }
275
279 // \{
280
285 const std::string& name() const
286 { return name_; }
287
288
294 Scalar temperature() const
295 { return 273.15 + 20; } // in [K]
296
298 void plotComponentsOverTime(const SolutionVector& curSol, Scalar time)
299 {
300 if (plotOutput_)
301 {
302 Scalar x_co2_left = 0.0;
303 Scalar x_n2_left = 0.0;
304 Scalar x_co2_right = 0.0;
305 Scalar x_n2_right = 0.0;
306 Scalar x_h2_left = 0.0;
307 Scalar x_h2_right = 0.0;
308 Scalar i = 0.0;
309 Scalar j = 0.0;
310 if (!(time < 0.0))
311 {
312 for (const auto& element : elements(this->gridGeometry().gridView()))
313 {
314 auto fvGeometry = localView(this->gridGeometry());
315 fvGeometry.bindElement(element);
316
317 const auto elemSol = elementSolution(element, curSol, this->gridGeometry());
318 for (auto&& scv : scvs(fvGeometry))
319 {
320 const auto& globalPos = scv.dofPosition();
321 VolumeVariables volVars;
322 volVars.update(elemSol, *this, element, scv);
323
324 if (globalPos[0] < 0.5)
325 {
326 x_co2_left += volVars.moleFraction(0,2);
327
328 x_n2_left += volVars.moleFraction(0,1);
329 x_h2_left += volVars.moleFraction(0,0);
330 i +=1;
331 }
332 else
333 {
334 x_co2_right += volVars.moleFraction(0,2);
335 x_n2_right += volVars.moleFraction(0,1);
336 x_h2_right += volVars.moleFraction(0,0);
337 j +=1;
338 }
339 }
340 }
341 x_co2_left /= i;
342 x_n2_left /= i;
343 x_h2_left /= i;
344 x_co2_right /= j;
345 x_n2_right /= j;
346 x_h2_right /= j;
347
348 // do a gnuplot
349 x_.push_back(time); // in seconds
350 y_.push_back(x_n2_left);
351 y2_.push_back(x_n2_right);
352 y3_.push_back(x_co2_left);
353 y4_.push_back(x_co2_right);
354 y5_.push_back(x_h2_left);
355 y6_.push_back(x_h2_right);
356
357 gnuplot_.resetPlot();
358 gnuplot_.setXRange(0, std::min(time, 72000.0));
359 gnuplot_.setYRange(0.4, 0.6);
360 gnuplot_.setXlabel("time [s]");
361 gnuplot_.setYlabel("mole fraction mol/mol");
362 gnuplot_.addDataSetToPlot(x_, y_, "N2_left.dat", "w l t 'N_2 left'");
363 gnuplot_.addDataSetToPlot(x_, y2_, "N2_right.dat", "w l t 'N_2 right'");
364 gnuplot_.plot("mole_fraction_N2");
365
366 gnuplot2_.resetPlot();
367 gnuplot2_.setXRange(0, std::min(time, 72000.0));
368 gnuplot2_.setYRange(0.0, 0.6);
369 gnuplot2_.setXlabel("time [s]");
370 gnuplot2_.setYlabel("mole fraction mol/mol");
371 gnuplot2_.addDataSetToPlot(x_, y3_, "CO2_left.dat", "w l t 'CO_2 left'");
372 gnuplot2_.addDataSetToPlot(x_, y4_, "CO2_right.dat", "w l t 'CO_2 right");
373 gnuplot2_.plot("mole_fraction_CO2");
374
375 gnuplot3_.resetPlot();
376 gnuplot3_.setXRange(0, std::min(time, 72000.0));
377 gnuplot3_.setYRange(0.0, 0.6);
378 gnuplot3_.setXlabel("time [s]");
379 gnuplot3_.setYlabel("mole fraction mol/mol");
380 gnuplot3_.addDataSetToPlot(x_, y5_, "H2_left.dat", "w l t 'H_2 left'");
381 gnuplot3_.addDataSetToPlot(x_, y6_, "H2_right.dat", "w l t 'H_2 right'");
382 gnuplot3_.plot("mole_fraction_H2");
383 }
384 }
385 }
386
387 // \}
388
392 // \{
393
400 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
401 {
402 BoundaryTypes values;
403 values.setAllNeumann();
404 return values;
405 }
406
412 NumEqVector neumannAtPos(const GlobalPosition& globalPos) const
413 { return NumEqVector(0.0); }
414
415 // \}
416
420 // \{
421
427 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
428 {
429 PrimaryVariables initialValues(0.0);
430 if (globalPos[0] < 0.5)
431 {
432 initialValues[Indices::pressureIdx] = 1e5;
433 initialValues[FluidSystem::N2Idx] = 0.50086;
434 initialValues[FluidSystem::CO2Idx] = 0.49914;
435 }
436 else
437 {
438 initialValues[Indices::pressureIdx] = 1e5;
439 initialValues[FluidSystem::N2Idx] = 0.49879;
440 initialValues[FluidSystem::CO2Idx] = 0.0;
441 }
442 return initialValues;
443 }
444
445 // \}
446
447private:
448 std::string name_;
449
453
454 std::vector<Scalar> x_;
455 std::vector<Scalar> y_;
456 std::vector<Scalar> y2_;
457 std::vector<Scalar> y3_;
458 std::vector<Scalar> y4_;
459 std::vector<Scalar> y5_;
460 std::vector<Scalar> y6_;
461
462 bool plotOutput_;
463};
464
465} // end namespace Dumux
466
467#endif
Defines a type tag and some properties for models using the box scheme.
Properties for all models using cell-centered finite volume scheme with TPFA.
free functions for the evaluation of primary variable gradients inside elements.
free functions for the evaluation of primary variables inside elements.
This file contains the data which is required to calculate diffusive mass fluxes due to molecular dif...
Interface for passing data sets to a file and plotting them, if gnuplot is installed.
Relations valid for an ideal gas.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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:149
Base class for all finite-volume problems.
Definition: common/fvproblem.hh:50
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:588
The DUNE grid type.
Definition: common/properties.hh:57
UndefinedProperty type
Definition: common/properties.hh:57
Property to specify the type of a problem which has to be solved.
Definition: common/properties.hh:69
Property whether to use moles or kg as amount unit for balance equations.
Definition: common/properties.hh:102
The type for the calculation of the molecular diffusion fluxes.
Definition: common/properties.hh:212
The type of the spatial parameters object.
Definition: common/properties.hh:221
The type of the fluid system to use.
Definition: common/properties.hh:223
The type of the fluid state to use.
Definition: common/properties.hh:225
Definition: maxwellstefanslaw.hh:37
Interface for passing data sets to a file and plotting them, if gnuplot is installed.
Definition: gnuplotinterface.hh:57
Fluid system base class.
Definition: fluidsystems/base.hh:45
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: fluidsystems/base.hh:134
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Given a phase's composition, temperature and pressure, return the binary diffusion coefficient for c...
Definition: fluidsystems/base.hh:326
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: fluidsystems/base.hh:160
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: fluidsystems/base.hh:236
Relations valid for an ideal gas.
Definition: idealgas.hh:37
static constexpr Scalar molarDensity(Scalar temperature, Scalar pressure)
The molar density of the gas , depending on pressure and temperature.
Definition: idealgas.hh:70
Base class for all fully implicit porous media problems.
Definition: dumux/porousmediumflow/problem.hh:39
Definition of the spatial parameters for the 1pnc test problems.
Definition: porousmediumflow/1pnc/implicit/1p2c/spatialparams.hh:41
Definition of a problem for a 1p3c problem: Component transport of N2, CO2 and H2.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:241
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluates the boundary conditions for a Neumann boundary segment.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:412
MaxwellStefanOnePThreeCTestProblem(std::shared_ptr< const GridGeometry > gridGeometry)
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:262
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluates the initial value for a control volume.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:427
const std::string & name() const
The problem name. This is used as a prefix for files generated by the simulation.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:285
BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
Specifies which kind of boundary condition should be used for which equation on a given boundary segm...
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:400
void plotComponentsOverTime(const SolutionVector &curSol, Scalar time)
Called after every time step.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:298
Scalar temperature() const
Returns the temperature within the domain [K].
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:294
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:58
std::tuple< OnePNC > InheritsFrom
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:58
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:59
std::tuple< MaxwellStefanOnePThreeCTest, BoxModel > InheritsFrom
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:59
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:60
std::tuple< MaxwellStefanOnePThreeCTest, CCTpfaModel > InheritsFrom
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:60
Dune::YaspGrid< 2 > type
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:69
A simple fluid system with three components for testing the multi-component diffusion with the Maxwel...
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:84
static constexpr int CO2Idx
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:97
static Scalar density(const FluidState &fluidState, const int phaseIdx)
Given a phase's composition, temperature, pressure, and the partial pressures of all components,...
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:162
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculates the dynamic viscosity of a fluid phase .
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:178
static constexpr int N2Idx
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:96
static constexpr int numComponents
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:93
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:195
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Given a phase's composition, temperature and pressure, returns the binary diffusion coefficient for ...
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:131
static std::string componentName(int compIdx)
Human readable component name (index compIdx) (for vtk output)
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:100
static constexpr int H2Idx
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:95
static constexpr int numPhases
The number of phases.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:92
static std::string phaseName(int phaseIdx=0)
Human readable phase name (index phaseIdx) (for velocity vtk output)
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:104
static Scalar molarMass(unsigned int compIdx)
Molar mass in kg/mol of the component with index compIdx.
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:108
GetPropType< TypeTag, Properties::GridGeometry > GridGeometry
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:212
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: test/porousmediumflow/1pnc/implicit/1p3c/problem.hh:213
Adaption of the fully implicit model to the one-phase n-component flow model.
Base class for all porous media problems.
Fluid system base class.