3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
deprecated.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_DEPRECATED_HH
26#define DUMUX_COMMON_DEPRECATED_HH
27
28#include <dune/common/version.hh>
29#include <dune/common/exceptions.hh>
30#include <dune/common/std/type_traits.hh>
31
32namespace Dumux {
33
34#ifndef DOXYGEN // hide from doxygen
35// Helper classes/functions for deprecation
36// Each implementation has to state after which release
37// it will be removed. Implementations in the Deprecated
38// namespace will be removed without
39// deprecation after their usage in the code expired,
40// so most likely you don't want to use this in your code
41namespace Deprecated {
42
43#ifdef __clang__
44#pragma clang diagnostic push
45#pragma clang diagnostic ignored "-Wdeprecated-declarations"
46#endif // __clang__
47template <class Mapper, class GridView>
48using GridViewDetector = decltype(std::declval<Mapper>().update(std::declval<GridView>()));
49
50template<class Mapper, class GridView>
51static constexpr bool hasUpdateGridView()
52{ return Dune::Std::is_detected<GridViewDetector, Mapper, GridView>::value; }
53
54template <typename Problem, typename GlobalPosition>
55using HasIsOnWallDetector = decltype(std::declval<Problem>().isOnWallAtPos(std::declval<GlobalPosition>()));
56
57template<class Problem, typename GlobalPosition>
58static constexpr bool hasIsOnWall()
59{ return Dune::Std::is_detected<HasIsOnWallDetector, Problem, GlobalPosition>::value; }
60
61template <typename ModelTraits>
62using HasEnableCompositionalDispersionDetector = decltype(ModelTraits::enableCompositionalDispersion());
63
64template<class ModelTraits>
65static constexpr bool hasEnableCompositionalDispersion()
66{ return Dune::Std::is_detected<HasEnableCompositionalDispersionDetector, ModelTraits>::value; }
67
68template <typename ModelTraits>
69using HasEnableThermalDispersionDetector = decltype(ModelTraits::enableThermalDispersion());
70
71template<class ModelTraits>
72static constexpr bool hasEnableThermalDispersion()
73{ return Dune::Std::is_detected<HasEnableThermalDispersionDetector, ModelTraits>::value; }
74
75template<class SpatialParams, class Element, class Scv, class ElemSol>
76using HasNewTemperatureDetector = decltype(std::declval<SpatialParams>().temperature(
77 std::declval<Element>(),
78 std::declval<Scv>(),
79 std::declval<ElemSol>()
80));
81
82template<class Problem, class GlobalPosition>
83using HasBaseProblemTemperatureAtPosDetector = decltype(std::declval<Problem>().temperatureAtPos(
84 std::declval<GlobalPosition>(), int{}
85));
86
87template<class Problem>
88using HasBaseProblemTemperatureDetector = decltype(std::declval<Problem>().temperature(int{}));
89
90template<class SpatialParams, class Element, class SubControlVolume, class ElementSolution>
91using HasExtrusionFactorDetector = decltype(std::declval<SpatialParams>().extrusionFactor(
92 std::declval<Element>(),
93 std::declval<SubControlVolume>(),
94 std::declval<ElementSolution>()
95 ));
96
97template<class Problem, class Element, class SubControlVolume, class ElementSolution>
98using HasBaseProblemExtrusionFactorDetector = decltype(std::declval<Problem>().extrusionFactor(
99 std::declval<Element>(),
100 std::declval<SubControlVolume>(),
101 std::declval<ElementSolution>(),
102 double{}
103 ));
104
105template<class Problem, class GlobalPosition>
106using HasBaseProblemExtrusionFactorAtPosDetector = decltype(std::declval<Problem>().extrusionFactorAtPos(
107 std::declval<GlobalPosition>(),
108 double{}
109 ));
110
111
112template<class Problem, class Element, class SubControlVolume>
113using HasBaseProblemEffectiveFluidDensity = decltype(std::declval<Problem>().effectiveFluidDensity(
114 std::declval<Element>(),
115 std::declval<SubControlVolume>(),
116 double{}
117 ));
118
119template<class Problem, class GlobalPosition>
120using HasEffectiveFluidDensityAtPos = decltype(std::declval<Problem>().effectiveFluidDensityAtPos(
121 std::declval<GlobalPosition>()
122 ));
123
124template<class Problem,
125 class Element,
126 class FVElementGeometry,
127 class ElemVolVars,
128 class FluxVarsCache>
129using HasBaseProblemEffectivePorePressure = decltype(std::declval<Problem>().effectivePorePressure(
130 std::declval<Element>(),
131 std::declval<FVElementGeometry>(),
132 std::declval<ElemVolVars>(),
133 std::declval<FluxVarsCache>(),
134 double{}
135 ));
136
137template<class Problem, class GlobalPosition>
138using HasEffectivePorePressureAtPos = decltype(std::declval<Problem>().effectivePorePressureAtPos(
139 std::declval<GlobalPosition>()
140 ));
141
142
143#ifdef __clang__
144#pragma clang diagnostic pop
145#endif // __clang__
146
147// helper class to print deprecated message
148template <class Mapper>
149#if DUNE_VERSION_GTE(DUNE_GRID,2,8)
150[[deprecated("The interface mapper.update() is deprecated. All mappers now have to implement `update(gridView)` instead (with a gridView as argument). Only mappers with the new interface will be support for dune-grid 2.7 is dropped.")]]
151#endif
152void update(Mapper& mapper)
153{ mapper.update(); };
154
155template<class Problem, class Element, class SubControlVolume, class ElementSolution>
156decltype(auto) extrusionFactor(const Problem& problem,
157 const Element& element,
158 const SubControlVolume& scv,
159 const ElementSolution& elemSol)
160{
161 using SpatialParams = std::decay_t<decltype(problem.spatialParams())>;
162 using GlobalPosition = std::decay_t<decltype(scv.center())>;
163
164 static constexpr bool hasNewSpatialParamsInterface = Dune::Std::is_detected<
165 HasExtrusionFactorDetector, SpatialParams, Element, SubControlVolume, ElementSolution
166 >::value;
167
168 static constexpr bool hasBaseProblemInterface = Dune::Std::is_detected<
169 HasBaseProblemExtrusionFactorDetector, Problem, Element, SubControlVolume, ElementSolution
170 >::value;
171
172 static constexpr bool hasBaseProblemAtPosInterface = Dune::Std::is_detected<
173 HasBaseProblemExtrusionFactorAtPosDetector, Problem, GlobalPosition
174 >::value;
175
176 static constexpr bool hasUserDefinedProblemExtrusionFactor = !hasBaseProblemInterface || !hasBaseProblemAtPosInterface;
177
178 if constexpr (hasNewSpatialParamsInterface && hasUserDefinedProblemExtrusionFactor)
179 DUNE_THROW(Dune::InvalidStateException,
180 "Extrusion factor defined both in problem implementation (deprecated interface) and spatial params (new interface). "
181 "Please move the overload in your problem implementation to your spatial parameters.");
182
183 if constexpr (hasNewSpatialParamsInterface)
184 return problem.spatialParams().extrusionFactor(element, scv, elemSol);
185 else
186 return problem.extrusionFactor(element, scv, elemSol);
187}
188
189template<typename Problem, typename Element, typename Scv, typename ElemSol>
190decltype(auto) temperature(const Problem& problem, const Element& element, const Scv& scv, const ElemSol& elemSol)
191{
192 using SpatialParams = std::decay_t<decltype(problem.spatialParams())>;
193 using GlobalPosition = std::decay_t<decltype(scv.dofPosition())>;
194
195 static constexpr bool hasBaseProbTempAtPosInterface = Dune::Std::is_detected<
196 HasBaseProblemTemperatureAtPosDetector, Problem, GlobalPosition
197 >::value;
198 static constexpr bool hasBaseProbTempInterface = Dune::Std::is_detected<
199 HasBaseProblemTemperatureDetector, Problem
200 >::value;
201 static constexpr bool spatialParamsHaveNewInterface = Dune::Std::is_detected<
202 HasNewTemperatureDetector, SpatialParams, Element, Scv, ElemSol
203 >::value;
204
205 static constexpr bool problemHasUserDefinedTemperature = !hasBaseProbTempAtPosInterface || !hasBaseProbTempInterface;
206
207 if constexpr (problemHasUserDefinedTemperature && spatialParamsHaveNewInterface)
208 DUNE_THROW(Dune::InvalidStateException,
209 "Temperature defined both in problem implementation (deprecated interface) and spatial params (new interface). "
210 "Please move the temperature definition in your problem implementation to your spatial parameters.");
211
212 if constexpr (spatialParamsHaveNewInterface)
213 return problem.spatialParams().temperature(element, scv, elemSol);
214 else
215 return problem.temperatureAtPos(scv.dofPosition());
216}
217
218template<class Problem, class Element, class SubControlVolume>
219decltype(auto) effectiveFluidDensity(const Problem& problem,
220 const Element& element,
221 const SubControlVolume& scv)
222{
223 using GlobalPosition = typename SubControlVolume::Traits::GlobalPosition;
224
225 static constexpr bool hasBaseProblemDensity = Dune::Std::is_detected<
226 HasBaseProblemEffectiveFluidDensity, Problem, Element, SubControlVolume
227 >::value;
228
229 static constexpr bool hasProblemDensityAtPos = Dune::Std::is_detected<
230 HasEffectiveFluidDensityAtPos, Problem, GlobalPosition
231 >::value;
232
233 static constexpr bool problemDefinesUserDensity =
234 hasProblemDensityAtPos || !hasBaseProblemDensity;
235
236 if constexpr (problemDefinesUserDensity)
237 return problem.effectiveFluidDensity(element, scv);
238 else
239 return problem.spatialParams().effectiveFluidDensity(element, scv);
240}
241
242template<class Problem, class Element, class FVElementGeometry, class ElemVolVars, class FluxVarsCache>
243decltype(auto) effectivePorePressure(const Problem& problem,
244 const Element& element,
245 const FVElementGeometry& fvGeometry,
246 const ElemVolVars& elemVolVars,
247 const FluxVarsCache& fluxVarsCache)
248{
249 using GlobalPosition = typename FVElementGeometry::GridGeometry::SubControlVolume::Traits::GlobalPosition;
250
251 static constexpr bool hasBaseProblemPressure = Dune::Std::is_detected<
252 HasBaseProblemEffectivePorePressure,
253 Problem,
254 Element,
255 FVElementGeometry,
256 ElemVolVars,
257 FluxVarsCache
258 >::value;
259
260 static constexpr bool hasProblemPressureAtPos = Dune::Std::is_detected<
261 HasEffectivePorePressureAtPos, Problem, GlobalPosition
262 >::value;
263
264 static constexpr bool problemDefinesUserPressure =
265 hasProblemPressureAtPos || !hasBaseProblemPressure;
266
267 if constexpr (problemDefinesUserPressure)
268 return problem.effectivePorePressure(
269 element, fvGeometry, elemVolVars, fluxVarsCache
270 );
271 else
272 return problem.spatialParams().effectivePorePressure(
273 element, fvGeometry, elemVolVars, fluxVarsCache
274 );
275}
276
277} // end namespace Deprecated
278#endif
279
280} // end namespace Dumux
281#endif
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51