version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_COMMON_FV_SPATIAL_PARAMS_HH
14#define DUMUX_COMMON_FV_SPATIAL_PARAMS_HH
15
16#include <memory>
17
18#include <dune/common/fvector.hh>
19#include <dune/common/exceptions.hh>
20
22
23namespace Dumux {
24
30template<class GridGeometry,
31 class Scalar,
32 class Implementation>
34{
35 using GridView = typename GridGeometry::GridView;
36 using Element = typename GridView::template Codim<0>::Entity;
37 using SubControlVolume = typename GridGeometry::SubControlVolume;
38
39 static constexpr int dimWorld = GridView::dimensionworld;
40
41 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
42 using GravityVector = Dune::FieldVector<Scalar, dimWorld>;
43
44public:
45 FVSpatialParams(std::shared_ptr<const GridGeometry> gridGeometry)
46 : gridGeometry_(gridGeometry)
47 , gravity_(0.0)
48 {
49 if (getParam<bool>("Problem.EnableGravity"))
50 gravity_[dimWorld-1] = -9.81;
51 }
52
62 template<class ElementSolution>
63 Scalar extrusionFactor(const Element& element,
64 const SubControlVolume& scv,
65 const ElementSolution& elemSol) const
66 {
67 // forward to generic interface
68 return asImp_().extrusionFactorAtPos(scv.center());
69 }
70
74 Scalar extrusionFactorAtPos(const GlobalPosition& globalPos) const
75 {
76 // As a default, i.e. if the user's spatial parameters do not overload
77 // any extrusion factor method, return 1.0
78 return 1.0;
79 }
80
84 template<class ElementSolution>
85 Scalar temperature(const Element& element,
86 const SubControlVolume& scv,
87 const ElementSolution& elemSol) const
88 {
89 // forward to generic interface
90 return asImp_().temperatureAtPos(scv.center());
91 }
92
97 Scalar temperatureAtPos(const GlobalPosition& globalPos) const
98 {
99 static const Scalar defaultTemperature = [] ()
100 {
101 Scalar defaultTemp = 293.15; // 20°C
102 if (!hasParam("SpatialParams.Temperature"))
103 {
104 std::cout << " -- Using the default temperature of " << defaultTemp << " in the entire domain. "
105 << "Overload temperatureAtPos() in your spatial params class to define a custom temperature field."
106 << "Or provide the preferred domain temperature via the SpatialParams.Temperature parameter."
107 << std::endl;
108 }
109 const Scalar temperature = getParam<Scalar>("SpatialParams.Temperature", defaultTemp);
110 return temperature;
111 } ();
112
113 return defaultTemperature;
114 }
115
126 const GravityVector& gravity(const GlobalPosition& pos) const
127 { return gravity_; }
128
130 const GridGeometry& gridGeometry() const
131 { return *gridGeometry_; }
132
133protected:
135 Implementation &asImp_()
136 { return *static_cast<Implementation *>(this); }
137
139 const Implementation &asImp_() const
140 { return *static_cast<const Implementation *>(this); }
141
142private:
143 std::shared_ptr<const GridGeometry> gridGeometry_;
144 GravityVector gravity_;
145};
146
147} // namespace Dumux
148
149#endif
The base class for spatial parameters used with finite-volume schemes.
Definition: common/fvspatialparams.hh:34
Scalar temperatureAtPos(const GlobalPosition &globalPos) const
Return the temperature in the domain at the given position.
Definition: common/fvspatialparams.hh:97
Implementation & asImp_()
Returns the implementation of the spatial parameters (static polymorphism)
Definition: common/fvspatialparams.hh:135
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:85
Scalar extrusionFactorAtPos(const GlobalPosition &globalPos) const
Return how much the domain is extruded at a given position.
Definition: common/fvspatialparams.hh:74
const Implementation & asImp_() const
Returns the implementation of the spatial parameters (static polymorphism)
Definition: common/fvspatialparams.hh:139
FVSpatialParams(std::shared_ptr< const GridGeometry > gridGeometry)
Definition: common/fvspatialparams.hh:45
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvspatialparams.hh:130
const GravityVector & gravity(const GlobalPosition &pos) const
Returns the acceleration due to gravity .
Definition: common/fvspatialparams.hh:126
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:63
bool hasParam(const std::string &param)
Check whether a key exists in the parameter tree.
Definition: parameters.hh:157
Definition: adapt.hh:17
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.