3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
common/fvspatialparams.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 *****************************************************************************/
25#ifndef DUMUX_COMMON_FV_SPATIAL_PARAMS_HH
26#define DUMUX_COMMON_FV_SPATIAL_PARAMS_HH
27
28#include <memory>
29
30#include <dune/common/fvector.hh>
31#include <dune/common/exceptions.hh>
32
34
35namespace Dumux {
36
42template<class GridGeometry,
43 class Scalar,
44 class Implementation>
46{
47 using GridView = typename GridGeometry::GridView;
48 using Element = typename GridView::template Codim<0>::Entity;
49 using SubControlVolume = typename GridGeometry::SubControlVolume;
50
51 static constexpr int dimWorld = GridView::dimensionworld;
52
53 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
54 using GravityVector = Dune::FieldVector<Scalar, dimWorld>;
55
56public:
57 FVSpatialParams(std::shared_ptr<const GridGeometry> gridGeometry)
58 : gridGeometry_(gridGeometry)
59 , gravity_(0.0)
60 {
61 if (getParam<bool>("Problem.EnableGravity"))
62 gravity_[dimWorld-1] = -9.81;
63 }
64
74 template<class ElementSolution>
75 Scalar extrusionFactor(const Element& element,
76 const SubControlVolume& scv,
77 const ElementSolution& elemSol) const
78 {
79 // forward to generic interface
80 return asImp_().extrusionFactorAtPos(scv.center());
81 }
82
86 Scalar extrusionFactorAtPos(const GlobalPosition& globalPos) const
87 {
88 // As a default, i.e. if the user's spatial parameters do not overload
89 // any extrusion factor method, return 1.0
90 return 1.0;
91 }
92
96 template<class ElementSolution>
97 Scalar temperature(const Element& element,
98 const SubControlVolume& scv,
99 const ElementSolution& elemSol) const
100 {
101 // forward to generic interface
102 return asImp_().temperatureAtPos(scv.center());
103 }
104
109 Scalar temperatureAtPos(const GlobalPosition& globalPos) const
110 {
111 static const Scalar defaultTemperature = [] ()
112 {
113 Scalar defaultTemp = 293.15; // 20°C
114 if (!hasParam("SpatialParams.Temperature"))
115 {
116 std::cout << " -- Using the default temperature of " << defaultTemp << " in the entire domain. "
117 << "Overload temperatureAtPos() in your spatial params class to define a custom temperature field."
118 << "Or provide the preferred domain temperature via the SpatialParams.Temperature parameter."
119 << std::endl;
120 }
121 const Scalar temperature = getParam<Scalar>("SpatialParams.Temperature", defaultTemp);
122 return temperature;
123 } ();
124
125 return defaultTemperature;
126 }
127
138 const GravityVector& gravity(const GlobalPosition& pos) const
139 { return gravity_; }
140
142 const GridGeometry& gridGeometry() const
143 { return *gridGeometry_; }
144
145protected:
147 Implementation &asImp_()
148 { return *static_cast<Implementation *>(this); }
149
151 const Implementation &asImp_() const
152 { return *static_cast<const Implementation *>(this); }
153
154private:
155 std::shared_ptr<const GridGeometry> gridGeometry_;
156 GravityVector gravity_;
157};
158
159} // namespace Dumux
160
161#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
bool hasParam(const std::string &param)
Check whether a key exists in the parameter tree.
Definition: parameters.hh:169
Definition: adapt.hh:29
The base class for spatial parameters used with finite-volume schemes.
Definition: common/fvspatialparams.hh:46
Scalar temperatureAtPos(const GlobalPosition &globalPos) const
Return the temperature in the domain at the given position.
Definition: common/fvspatialparams.hh:109
Implementation & asImp_()
Returns the implementation of the spatial parameters (static polymorphism)
Definition: common/fvspatialparams.hh:147
Scalar temperature(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Return the temperature in the given sub-control volume.
Definition: common/fvspatialparams.hh:97
Scalar extrusionFactorAtPos(const GlobalPosition &globalPos) const
Return how much the domain is extruded at a given position.
Definition: common/fvspatialparams.hh:86
const Implementation & asImp_() const
Returns the implementation of the spatial parameters (static polymorphism)
Definition: common/fvspatialparams.hh:151
FVSpatialParams(std::shared_ptr< const GridGeometry > gridGeometry)
Definition: common/fvspatialparams.hh:57
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvspatialparams.hh:142
const GravityVector & gravity(const GlobalPosition &pos) const
Returns the acceleration due to gravity .
Definition: common/fvspatialparams.hh:138
Scalar extrusionFactor(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Return how much the domain is extruded at a given sub-control volume.
Definition: common/fvspatialparams.hh:75