3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
propertysystem.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_PROPERTY_SYSTEM_HH
27#define DUMUX_PROPERTY_SYSTEM_HH
28
29#include <tuple>
30#include <type_traits>
31
32namespace Dumux::Properties {
33
36
37} // end namespace Dumux::Properties
38
39
40// hide from doxygen
41#ifndef DOXYGEN
42
44namespace Dumux::Properties::Detail {
45
47template<class P>
48constexpr auto isDefinedProperty(int)
49-> decltype(std::integral_constant<bool, !std::is_same_v<typename P::type, UndefinedProperty>>{})
50{ return {}; }
51
53template<class P>
54constexpr std::true_type isDefinedProperty(...) { return {}; }
55
57template<class T>
58constexpr auto hasParentTypeTag(int)
59-> decltype(std::declval<typename T::InheritsFrom>(), std::true_type{})
60{ return {}; }
61
63template<class T>
64constexpr std::false_type hasParentTypeTag(...)
65{ return {}; }
66
68template<class ...Tuples>
69using ConCatTuples = decltype(std::tuple_cat(std::declval<Tuples>()...));
70
72template<class TypeTag, template<class,class> class Property, class TTagList>
73struct GetDefined;
74
76template<class TypeTag, template<class,class> class Property, class TTagList, class Enable>
77struct GetNextTypeTag;
78
79template<class TypeTag, template<class,class> class Property, class LastTypeTag>
80struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<hasParentTypeTag<LastTypeTag>(int{}), void>>
81{ using type = typename GetDefined<TypeTag, Property, typename LastTypeTag::InheritsFrom>::type; };
82
83template<class TypeTag, template<class,class> class Property, class LastTypeTag>
84struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<!hasParentTypeTag<LastTypeTag>(int{}), void>>
85{ using type = UndefinedProperty; };
86
87template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
88struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<hasParentTypeTag<FirstTypeTag>(int{}), void>>
89{ using type = typename GetDefined<TypeTag, Property, ConCatTuples<typename FirstTypeTag::InheritsFrom, std::tuple<Args...>>>::type; };
90
91template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
92struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<!hasParentTypeTag<FirstTypeTag>(int{}), void>>
93{ using type = typename GetDefined<TypeTag, Property, std::tuple<Args...>>::type; };
94
95template<class TypeTag, template<class,class> class Property, class LastTypeTag>
96struct GetDefined<TypeTag, Property, std::tuple<LastTypeTag>>
97{
98// For clang, the following alias triggers compiler warnings if instantiated
99// from something like `GetPropType<..., DeprecatedProperty>`, even if that is
100// contained in a diagnostic pragma construct that should prevent these warnings.
101// As a workaround, also add the pragmas around this line.
102// See the discussion in MR 1647 for more details.
103#ifdef __clang__
104#pragma clang diagnostic push
105#pragma clang diagnostic ignored "-Wdeprecated-declarations"
106#endif
107 using LastType = Property<TypeTag, LastTypeTag>;
108#ifdef __clang__
109#pragma clang diagnostic pop
110#endif
111 using type = std::conditional_t<isDefinedProperty<LastType>(int{}), LastType,
112 typename GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, void>::type>;
113};
114
115template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
116struct GetDefined<TypeTag, Property, std::tuple<FirstTypeTag, Args...>>
117{
118// See the comment above.
119#ifdef __clang__
120#pragma clang diagnostic push
121#pragma clang diagnostic ignored "-Wdeprecated-declarations"
122#endif
123 using FirstType = Property<TypeTag, FirstTypeTag>;
124#ifdef __clang__
125#pragma clang diagnostic pop
126#endif
127 using type = std::conditional_t<isDefinedProperty<FirstType>(int{}), FirstType,
128 typename GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, void>::type>;
129};
130
132template<class TypeTag, template<class,class> class Property>
133struct GetPropImpl
134{
135 using type = typename Detail::GetDefined<TypeTag, Property, std::tuple<TypeTag>>::type;
136 static_assert(!std::is_same_v<type, UndefinedProperty>, "Property is undefined!");
137};
138
139template<class TypeTag, template<class,class> class Property, class T>
140struct GetPropOrImpl
141{
142 using PT = typename Detail::GetDefined<TypeTag, Property, std::tuple<TypeTag>>::type;
143 struct WrapperT { using type = T; }; // fake property wrapper
144 using type = std::conditional_t<std::is_same_v<PT, UndefinedProperty>, WrapperT, PT>;
145};
146
147} // end namespace Dumux::Properties::Detail
148
149#endif // DOXYGEN
150
151namespace Dumux::Properties {
152
154template<class TypeTag, template<class,class> class Property>
155inline constexpr bool hasDefinedType()
156{
157 using type = typename Detail::GetDefined<TypeTag, Property, std::tuple<TypeTag>>::type;
158 return !std::is_same_v<type, UndefinedProperty>;
159}
160
161} // end namespace Dumux::Properties
162
163namespace Dumux {
164
166template<class TypeTag, template<class,class> class Property>
167using GetProp = typename Properties::Detail::GetPropImpl<TypeTag, Property>::type;
168
170template<class TypeTag, template<class,class> class Property, class T>
171using GetPropOr = typename Properties::Detail::GetPropOrImpl<TypeTag, Property, T>::type;
172
173// See the comment above.
174#ifdef __clang__
175#pragma clang diagnostic push
176#pragma clang diagnostic ignored "-Wdeprecated-declarations"
177#endif
179template<class TypeTag, template<class,class> class Property>
181
183template<class TypeTag, template<class,class> class Property, class T>
185
187template<class TypeTag, template<class,class> class Property>
188inline constexpr auto getPropValue() { return GetProp<TypeTag, Property>::value; }
189#ifdef __clang__
190#pragma clang diagnostic pop
191#endif
192
193} // end namespace Dumux
194
195#endif
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
constexpr auto getPropValue()
get the value data member of a property
Definition: propertysystem.hh:188
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property
Definition: propertysystem.hh:167
typename Properties::Detail::GetPropOrImpl< TypeTag, Property, T >::type GetPropOr
get the type of a property or the type T if the property is undefined
Definition: propertysystem.hh:171
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
typename GetPropOr< TypeTag, Property, T >::type GetPropTypeOr
get the type alias defined in the property or the type T if the property is undefined
Definition: propertysystem.hh:184
Definition: common/properties.hh:37
constexpr bool hasDefinedType()
whether the property is defined/specialized for TypeTag
Definition: propertysystem.hh:155
a tag to mark properties as undefined
Definition: propertysystem.hh:35