3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
test/porousmediumflow/tracer/multicomp/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_MAXWELL_STEFAN_TEST_PROBLEM_HH
27#define DUMUX_MAXWELL_STEFAN_TEST_PROBLEM_HH
28
29#include <dune/grid/yaspgrid.hh>
30
34
37
38#include "spatialparams.hh"
40
43
44namespace Dumux {
45template <class TypeTag>
46class MaxwellStefanTestProblem;
47
48namespace Properties {
49// Create new type tags
50namespace TTag {
51struct MaxwellStefanTest { using InheritsFrom = std::tuple<Tracer>; };
52struct MaxwellStefanTestCC { using InheritsFrom = std::tuple<MaxwellStefanTest, CCTpfaModel>; };
53struct MaxwellStefanTestBox { using InheritsFrom = std::tuple<MaxwellStefanTest, BoxModel>; };
54} // end namespace TTag
55
56// Set the grid type
57template<class TypeTag>
58struct Grid<TypeTag, TTag::MaxwellStefanTest> { using type = Dune::YaspGrid<2>; };
59
60// Set the problem property
61template<class TypeTag>
62struct Problem<TypeTag, TTag::MaxwellStefanTest> { using type = MaxwellStefanTestProblem<TypeTag>; };
63
64// Set the spatial parameters
65template<class TypeTag>
66struct SpatialParams<TypeTag, TTag::MaxwellStefanTest>
67{
71};
72
73// Define whether mole(true) or mass (false) fractions are used
74template<class TypeTag>
75struct UseMoles<TypeTag, TTag::MaxwellStefanTest> { static constexpr bool value = true; };
76
78template<class TypeTag>
79struct MolecularDiffusionType<TypeTag, TTag::MaxwellStefanTest> { using type = MaxwellStefansLaw<TypeTag>; };
80
82template<class TypeTag>
84: public FluidSystems::Base<GetPropType<TypeTag, Properties::Scalar>, MaxwellStefanTracerFluidSystem<TypeTag>>
85
86{
90 using Element = typename GridView::template Codim<0>::Entity;
91 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
92 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
93
94public:
95 static constexpr bool isTracerFluidSystem()
96 { return true; }
98 static constexpr int numComponents = 3;
99
100 static constexpr int compOneIdx = 0;//first major component
101 static constexpr int compTwoIdx = 1;//second major component
102 static constexpr int compThreeIdx = 2;//secondary component
103
105 static std::string componentName(int compIdx)
106 {
107 switch (compIdx)
108 {
109 case compOneIdx: return "CompOne";
110 case compTwoIdx: return "CompTwo";
111 case compThreeIdx:return "CompThree";
112 }
113 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
114 }
115
117 static std::string phaseName(int phaseIdx = 0)
118 { return "Gas"; }
119
121 static Scalar molarMass(unsigned int compIdx)
122 { return 0.02896; /*air*/ }
123
126 static Scalar binaryDiffusionCoefficient(unsigned int compIdx,
127 const Problem& problem,
128 const Element& element,
129 const SubControlVolume& scv)
130 {
131 if (compIdx == compOneIdx)
132 return 0;
133 if (compIdx == compTwoIdx)
134 return 83.3e-6;
135 if (compIdx == compThreeIdx)
136 return 68.0e-6;
137 DUNE_THROW(Dune::InvalidStateException,
138 "Binary diffusion coefficient of component "
139 << compIdx <<" is undefined!\n");
140 }
141
144 static Scalar binaryDiffusionCoefficient(unsigned int compIIdx,
145 unsigned int compJIdx,
146 const Problem& problem,
147 const Element& element,
148 const SubControlVolume& scv)
149 {
150 if (compIIdx > compJIdx)
151 {
152 using std::swap;
153 swap(compIIdx, compJIdx);
154 }
155
156 if (compIIdx == compOneIdx && compJIdx == compTwoIdx)
157 return 83.3e-6;
158 if (compIIdx == compOneIdx && compJIdx == compThreeIdx)
159 return 68.0e-6;
160 if (compIIdx == compTwoIdx && compJIdx == compThreeIdx)
161 return 16.8e-6;
162 DUNE_THROW(Dune::InvalidStateException,
163 "Binary diffusion coefficient of components "
164 << compIIdx << " and " << compJIdx << " is undefined!\n");
165 }
166
176 template <class FluidState>
177 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
178 {
179 return density(fluidState, phaseIdx)/molarMass(0);
180 }
181};
182
183template<class TypeTag>
184struct FluidSystem<TypeTag, TTag::MaxwellStefanTest> { using type = MaxwellStefanTracerFluidSystem<TypeTag>; };
185
186} // end namespace Properties
187
198template <class TypeTag>
200{
202
214
216 static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
217
218 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
219 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
220
221public:
222 MaxwellStefanTestProblem(std::shared_ptr<const GridGeometry> gridGeometry)
224 {
225 name_ = getParam<std::string>("Problem.Name");
226
227 // stating in the console whether mole or mass fractions are used
228 if(useMoles)
229 std::cout<<"problem uses mole fractions" << '\n';
230 else
231 std::cout<<"problem uses mass fractions" << '\n';
232
233 plotOutput_ = false;
234 }
235
239 // \{
240
245 const std::string& name() const
246 { return name_; }
247
249 void plotComponentsOverTime(const SolutionVector& curSol, Scalar time)
250 {
251 if (plotOutput_)
252 {
253 Scalar x_CompThree_left = 0.0;
254 Scalar x_CompTwo_left = 0.0;
255 Scalar x_CompThree_right = 0.0;
256 Scalar x_CompTwo_right = 0.0;
257 Scalar x_CompOne_left = 0.0;
258 Scalar x_CompOne_right = 0.0;
259 Scalar i = 0.0;
260 Scalar j = 0.0;
261 if (!(time < 0.0))
262 {
263 for (const auto& element : elements(this->gridGeometry().gridView()))
264 {
265 auto fvGeometry = localView(this->gridGeometry());
266 fvGeometry.bindElement(element);
267
268 const auto elemSol = elementSolution(element, curSol, this->gridGeometry());
269 for (auto&& scv : scvs(fvGeometry))
270 {
271 const auto& globalPos = scv.dofPosition();
272 VolumeVariables volVars;
273 volVars.update(elemSol, *this, element, scv);
274
275 if (globalPos[0] < 0.5)
276 {
277 x_CompThree_left += volVars.moleFraction(0,2);
278
279 x_CompTwo_left += volVars.moleFraction(0,1);
280 x_CompOne_left += volVars.moleFraction(0,0);
281 i +=1;
282 }
283 else
284 {
285 x_CompThree_right += volVars.moleFraction(0,2);
286 x_CompTwo_right += volVars.moleFraction(0,1);
287 x_CompOne_right += volVars.moleFraction(0,0);
288 j +=1;
289 }
290
291 }
292 }
293 x_CompThree_left /= i;
294 x_CompTwo_left /= i;
295 x_CompOne_left /= i;
296 x_CompThree_right /= j;
297 x_CompTwo_right /= j;
298 x_CompOne_right /= j;
299
300 //do a gnuplot
301 x_.push_back(time); // in seconds
302 y_.push_back(x_CompTwo_left);
303 y2_.push_back(x_CompTwo_right);
304 y3_.push_back(x_CompThree_left);
305 y4_.push_back(x_CompThree_right);
306 y5_.push_back(x_CompOne_left);
307 y6_.push_back(x_CompOne_right);
308
309 gnuplot_.resetPlot();
310 gnuplot_.setXRange(0, std::min(time, 72000.0));
311 gnuplot_.setYRange(0.4, 0.6);
312 gnuplot_.setXlabel("time [s]");
313 gnuplot_.setYlabel("mole fraction mol/mol");
314 gnuplot_.addDataSetToPlot(x_, y_, "CompTwo_left.dat", "w l t 'CompTwo left'");
315 gnuplot_.addDataSetToPlot(x_, y2_, "CompTwo_right.dat", "w l t 'CompTwo right'");
316 gnuplot_.plot("mole_fraction_CompTwo");
317
318 gnuplot2_.resetPlot();
319 gnuplot2_.setXRange(0, std::min(time, 72000.0));
320 gnuplot2_.setYRange(0.0, 0.6);
321 gnuplot2_.setXlabel("time [s]");
322 gnuplot2_.setYlabel("mole fraction mol/mol");
323 gnuplot2_.addDataSetToPlot(x_, y3_, "CompThree_left.dat", "w l t 'CompThree left'");
324 gnuplot2_.addDataSetToPlot(x_, y4_, "CompThree_right.dat", "w l t 'CompThree right");
325 gnuplot2_.plot("mole_fraction_CompThree");
326
327 gnuplot3_.resetPlot();
328 gnuplot3_.setXRange(0, std::min(time, 72000.0));
329 gnuplot3_.setYRange(0.0, 0.6);
330 gnuplot3_.setXlabel("time [s]");
331 gnuplot3_.setYlabel("mole fraction mol/mol");
332 gnuplot3_.addDataSetToPlot(x_, y5_, "CompOne_left.dat", "w l t 'CompOne left'");
333 gnuplot3_.addDataSetToPlot(x_, y6_, "CompOne_right.dat", "w l t 'CompOne right'");
334 gnuplot3_.plot("mole_fraction_CompOne");
335 }
336 }
337 }
338
339 // \}
340
344 // \{
345
352 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
353 {
354 BoundaryTypes values;
355 values.setAllNeumann();
356 return values;
357 }
358
365 NumEqVector neumannAtPos(const GlobalPosition& globalPos) const
366 { return NumEqVector(0.0); }
367
368 // \}
369
373 // \{
374
383 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
384 {
385 PrimaryVariables initialValues(0.0);
386 if (globalPos[0] < 0.5)
387 {
388 initialValues[FluidSystem::compOneIdx] = 0.0;
389 initialValues[FluidSystem::compTwoIdx] = 0.50086;
390 initialValues[FluidSystem::compThreeIdx] = 0.49914;
391 }
392 else
393 {
394 initialValues[FluidSystem::compOneIdx] = 0.50121;
395 initialValues[FluidSystem::compTwoIdx] = 0.49879;
396 initialValues[FluidSystem::compThreeIdx] = 0.0;
397 }
398 return initialValues;
399 }
400
401 // \}
402
403private:
404 static constexpr Scalar eps_ = 1e-6;
405 std::string name_;
406
410
411 std::vector<double> x_;
412 std::vector<double> y_;
413 std::vector<double> y2_;
414 std::vector<double> y3_;
415 std::vector<double> y4_;
416 std::vector<double> y5_;
417 std::vector<double> y6_;
418
419 bool plotOutput_;
420};
421
422} // end namespace Dumux
423
424#endif
Element solution classes and factory functions.
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.
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.
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
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
void setXlabel(const std::string &label)
Sets the label for the x-axis.
Definition: gnuplotinterface.hh:279
void resetPlot()
Deletes all plots from a plotting window and resets user-defined options.
Definition: gnuplotinterface.hh:174
void addDataSetToPlot(const std::vector< Scalar > &x, const std::vector< Scalar > &y, const std::string &fileName, const std::string &options="with lines")
Adds a data set and writes a data file.
Definition: gnuplotinterface.hh:242
void plot(const std::string &filename="")
Plots the files for a specific window number, writes a gnuplot and png file.
Definition: gnuplotinterface.hh:89
void setXRange(Scalar min, Scalar max)
Sets the range for the x-axis.
Definition: gnuplotinterface.hh:300
void setYRange(Scalar min, Scalar max)
Sets the range for the y-axis.
Definition: gnuplotinterface.hh:313
void setYlabel(const std::string &label)
Sets the label for the y-axis.
Definition: gnuplotinterface.hh:289
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
Base class for all fully implicit porous media problems.
Definition: dumux/porousmediumflow/problem.hh:39
GetPropType< TypeTag, Properties::SpatialParams > SpatialParams
Export spatial parameter type.
Definition: dumux/porousmediumflow/problem.hh:58
Definition of a problem for the MaxwellStefan problem.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:200
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluates the boundary conditions for a Neumann boundary segment.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:365
const std::string & name() const
The problem name. This is used as a prefix for files generated by the simulation.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:245
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluates the initial value for a control volume.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:383
MaxwellStefanTestProblem(std::shared_ptr< const GridGeometry > gridGeometry)
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:222
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/tracer/multicomp/problem.hh:352
void plotComponentsOverTime(const SolutionVector &curSol, Scalar time)
Called after every time step.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:249
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:51
std::tuple< Tracer > InheritsFrom
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:51
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:52
std::tuple< MaxwellStefanTest, CCTpfaModel > InheritsFrom
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:52
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:53
std::tuple< MaxwellStefanTest, BoxModel > InheritsFrom
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:53
Dune::YaspGrid< 2 > type
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:58
GetPropType< TypeTag, Properties::GridGeometry > GridGeometry
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:68
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:69
A simple fluid system with one MaxwellStefan component.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:86
static Scalar binaryDiffusionCoefficient(unsigned int compIIdx, unsigned int compJIdx, const Problem &problem, const Element &element, const SubControlVolume &scv)
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:144
static Scalar molarMass(unsigned int compIdx)
Molar mass in kg/mol of the component with index compIdx.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:121
static constexpr int compThreeIdx
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:102
static constexpr int compTwoIdx
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:101
static std::string phaseName(int phaseIdx=0)
Human readable phase name (index phaseIdx) (for velocity vtk output)
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:117
static constexpr bool isTracerFluidSystem()
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:95
static std::string componentName(int compIdx)
Human readable component name (index compIdx) (for vtk output)
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:105
static constexpr int numComponents
The number of components.
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:98
static constexpr int compOneIdx
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:100
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:177
static Scalar binaryDiffusionCoefficient(unsigned int compIdx, const Problem &problem, const Element &element, const SubControlVolume &scv)
Definition: test/porousmediumflow/tracer/multicomp/problem.hh:126
Definition of the spatial parameters for the MaxwellStefan problem.
Definition: porousmediumflow/tracer/multicomp/spatialparams.hh:41
Adaption of the fully implicit scheme to the tracer transport model.
Base class for all porous media problems.
Fluid system base class.
Definition of the spatial parameters for the MaxwellStefan problem.