3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
component.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 *****************************************************************************/
24#ifndef DUMUX_PYTHON_MATERIAL_COMPONENT_HH
25#define DUMUX_PYTHON_MATERIAL_COMPONENT_HH
26
27#include <dune/python/pybind11/pybind11.h>
28#include <dune/python/pybind11/stl.h>
29
33
34
38
39} // end namespace Dumux::Python::Detail
40
41namespace Dumux {
48template<>
49struct AlwaysFalse<Dumux::Python::Detail::DisableStaticAssert> : public std::true_type {};
50
51} // end namespace Dumux
52
53namespace Dumux::Python::Detail {
54
55struct Name { template<class C> auto operator()(C&& c) -> decltype(C::template name<DisableStaticAssert>()) {} };
56struct MolarMass { template<class C> auto operator()(C&& c) -> decltype(C::template molarMass<DisableStaticAssert>()) {} };
57struct VaporPressure { template<class C> auto operator()(C&& c) -> decltype(C::template vaporPressure<DisableStaticAssert>(0.0)) {} };
58
59struct LiquidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template liquidIsCompressible<DisableStaticAssert>()) {} };
60struct LiquidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidDensity<DisableStaticAssert>(0.0, 0.0)) {} };
61struct LiquidMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
62struct LiquidViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
63struct LiquidEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
64struct LiquidInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
65struct LiquidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
66struct LiquidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
67
68struct GasIsIdeal { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsIdeal<DisableStaticAssert>()) {} };
69struct GasIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsCompressible<DisableStaticAssert>()) {} };
70struct GasDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasDensity<DisableStaticAssert>(0.0, 0.0)) {} };
71struct GasMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
72struct GasViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template gasViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
73struct GasEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template gasEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
74struct GasInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template gasInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
75struct GasHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template gasHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
76struct GasThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template gasThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
77
78struct SolidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template solidIsCompressible<DisableStaticAssert>()) {} };
79struct SolidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template solidDensity<DisableStaticAssert>(0.0)) {} };
80struct SolidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template solidThermalConductivity<DisableStaticAssert>(0.0)) {} };
81struct SolidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template solidHeatCapacity<DisableStaticAssert>(0.0)) {} };
82
83struct Charge { template<class C> auto operator()(C&& c) -> decltype(C::template charge<DisableStaticAssert>()) {} };
84struct CriticalTemperature { template<class C> auto operator()(C&& c) -> decltype(C::template criticalTemperature<DisableStaticAssert>()) {} };
85struct CriticalPressure { template<class C> auto operator()(C&& c) -> decltype(C::template criticalPressure<DisableStaticAssert>()) {} };
86
87} // end namespace Dumux::Python::Detail
88
89
90namespace Dumux::Python {
91
92template <class Comp, class... options>
93void registerComponent(pybind11::handle scope,
94 pybind11::class_<Comp, options...> cls)
95{
96 using pybind11::operator""_a;
97
98 cls.def(pybind11::init());
99
100 // helper lambda to check if the component implements a certain function
101 constexpr auto implements = [](const auto& c)
102 {
103 return !decltype(isValid(c)(std::declval<Comp>()))::value;
104 };
105
106 if constexpr (implements(Detail::Name{}))
107 cls.def_property_readonly_static("name", &Comp::name);
108 if constexpr (implements(Detail::MolarMass{}))
109 cls.def_property_readonly_static("molarMass", &Comp::molarMass);
110
112 {
113 if constexpr (implements(Detail::LiquidIsCompressible{}))
114 cls.def_property_readonly_static("liquidIsCompressible", &Comp::liquidIsCompressible);
115 if constexpr (implements(Detail::LiquidDensity{}))
116 cls.def_static("liquidDensity", &Comp::liquidDensity, "temperature"_a, "pressure"_a);
117 if constexpr (implements(Detail::LiquidMolarDensity{}))
118 cls.def_static("liquidMolarDensity", &Comp::liquidMolarDensity, "temperature"_a, "pressure"_a);
119 if constexpr (implements(Detail::LiquidViscosity{}))
120 cls.def_static("liquidViscosity", &Comp::liquidViscosity, "temperature"_a, "pressure"_a);
121 if constexpr (implements(Detail::LiquidEnthalpy{}))
122 cls.def_static("liquidEnthalpy", &Comp::liquidEnthalpy, "temperature"_a, "pressure"_a);
123 if constexpr (implements(Detail::LiquidInternalEnergy{}))
124 cls.def_static("liquidInternalEnergy", &Comp::liquidInternalEnergy, "temperature"_a, "pressure"_a);
125 if constexpr (implements(Detail::LiquidHeatCapacity{}))
126 cls.def_static("liquidHeatCapacity", &Comp::liquidHeatCapacity, "temperature"_a, "pressure"_a);
127 if constexpr (implements(Detail::LiquidThermalConductivity{}))
128 cls.def_static("liquidThermalConductivity", &Comp::liquidThermalConductivity, "temperature"_a, "pressure"_a);
129 if constexpr(implements(Detail::VaporPressure{}))
130 cls.def_static("vaporPressure", &Comp::vaporPressure, "temperature"_a);
131 }
132
134 {
135 if constexpr(implements(Detail::GasDensity{}))
136 cls.def_static("gasDensity", &Comp::gasDensity, "temperature"_a, "pressure"_a);
137 if constexpr(implements(Detail::GasMolarDensity{}))
138 cls.def_static("gasMolarDensity", &Comp::gasMolarDensity, "temperature"_a, "pressure"_a);
139 if constexpr(implements(Detail::GasIsCompressible{}))
140 cls.def_property_readonly_static("gasIsCompressible", &Comp::gasIsCompressible);
141 if constexpr(implements(Detail::GasIsIdeal{}))
142 cls.def_property_readonly_static("gasIsIdeal", &Comp::gasIsIdeal);
143 if constexpr(implements(Detail::GasViscosity{}))
144 cls.def_static("gasViscosity", &Comp::gasViscosity, "temperature"_a, "pressure"_a);
145 if constexpr(implements(Detail::GasEnthalpy{}))
146 cls.def_static("gasEnthalpy", &Comp::gasEnthalpy, "temperature"_a, "pressure"_a);
147 if constexpr(implements(Detail::GasInternalEnergy{}))
148 cls.def_static("gasInternalEnergy", &Comp::gasInternalEnergy, "temperature"_a, "pressure"_a);
149 if constexpr(implements(Detail::GasHeatCapacity{}))
150 cls.def_static("gasHeatCapacity", &Comp::gasHeatCapacity, "temperature"_a, "pressure"_a);
151 if constexpr(implements(Detail::GasThermalConductivity{}))
152 cls.def_static("gasThermalConductivity", &Comp::gasThermalConductivity, "temperature"_a, "pressure"_a);
153 }
154
156 {
157 if constexpr(implements(Detail::SolidIsCompressible{}))
158 cls.def_property_readonly_static("solidIsCompressible", &Comp::solidIsCompressible);
159 if constexpr(implements(Detail::SolidDensity{}))
160 cls.def_property_readonly_static("solidDensity", &Comp::solidDensity, "temperature_a");
161 if constexpr(implements(Detail::SolidThermalConductivity{}))
162 cls.def_static("solidThermalConductivity", &Comp::solidThermalConductivity, "temperature_a");
163 if constexpr(implements(Detail::SolidHeatCapacity{}))
164 cls.def_static("solidHeatCapacity", &Comp::solidHeatCapacity, "temperature_a");
165 }
166
167 if constexpr (ComponentTraits<Comp>::isIon)
168 {
169 if constexpr(implements(Detail::Charge{}))
170 cls.def_property_readonly_static("charge", &Comp::charge);
171 }
172
174 {
175 if constexpr(implements(Detail::CriticalTemperature{}))
176 cls.def_property_readonly_static("criticalTemperature", &Comp::criticalTemperature);
177 if constexpr(implements(Detail::CriticalPressure{}))
178 cls.def_property_readonly_static("criticalPressure", &Comp::criticalPressure);
179 }
180}
181
182
183} // namespace Dumux::Python
184
185#endif
A helper function for class member function introspection.
Type traits.
Component traits, i.e. information extracted from components.
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:93
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Definition: python/assembly/fvassembler.hh:30
void registerComponent(pybind11::handle scope, pybind11::class_< Comp, options... > cls)
Definition: component.hh:93
Definition: component.hh:35
Template which always yields a false value.
Definition: typetraits.hh:35
Component traits, i.e. information extracted from components.
Definition: componenttraits.hh:43
Helper struct to deactivate static assertions in component's base classes.
Definition: component.hh:37
Definition: component.hh:55
auto operator()(C &&c) -> decltype(C::template name< DisableStaticAssert >())
Definition: component.hh:55
Definition: component.hh:56
auto operator()(C &&c) -> decltype(C::template molarMass< DisableStaticAssert >())
Definition: component.hh:56
Definition: component.hh:57
auto operator()(C &&c) -> decltype(C::template vaporPressure< DisableStaticAssert >(0.0))
Definition: component.hh:57
auto operator()(C &&c) -> decltype(C::template liquidIsCompressible< DisableStaticAssert >())
Definition: component.hh:59
Definition: component.hh:60
auto operator()(C &&c) -> decltype(C::template liquidDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:60
auto operator()(C &&c) -> decltype(C::template liquidMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:61
Definition: component.hh:62
auto operator()(C &&c) -> decltype(C::template liquidViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:62
Definition: component.hh:63
auto operator()(C &&c) -> decltype(C::template liquidEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:63
auto operator()(C &&c) -> decltype(C::template liquidInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:64
auto operator()(C &&c) -> decltype(C::template liquidHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:65
auto operator()(C &&c) -> decltype(C::template liquidThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:66
Definition: component.hh:68
auto operator()(C &&c) -> decltype(C::template gasIsIdeal< DisableStaticAssert >())
Definition: component.hh:68
Definition: component.hh:69
auto operator()(C &&c) -> decltype(C::template gasIsCompressible< DisableStaticAssert >())
Definition: component.hh:69
Definition: component.hh:70
auto operator()(C &&c) -> decltype(C::template gasDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:70
Definition: component.hh:71
auto operator()(C &&c) -> decltype(C::template gasMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:71
Definition: component.hh:72
auto operator()(C &&c) -> decltype(C::template gasViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:72
Definition: component.hh:73
auto operator()(C &&c) -> decltype(C::template gasEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:73
Definition: component.hh:74
auto operator()(C &&c) -> decltype(C::template gasInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:74
Definition: component.hh:75
auto operator()(C &&c) -> decltype(C::template gasHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:75
auto operator()(C &&c) -> decltype(C::template gasThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:76
auto operator()(C &&c) -> decltype(C::template solidIsCompressible< DisableStaticAssert >())
Definition: component.hh:78
Definition: component.hh:79
auto operator()(C &&c) -> decltype(C::template solidDensity< DisableStaticAssert >(0.0))
Definition: component.hh:79
auto operator()(C &&c) -> decltype(C::template solidThermalConductivity< DisableStaticAssert >(0.0))
Definition: component.hh:80
Definition: component.hh:81
auto operator()(C &&c) -> decltype(C::template solidHeatCapacity< DisableStaticAssert >(0.0))
Definition: component.hh:81
Definition: component.hh:83
auto operator()(C &&c) -> decltype(C::template charge< DisableStaticAssert >())
Definition: component.hh:83
auto operator()(C &&c) -> decltype(C::template criticalTemperature< DisableStaticAssert >())
Definition: component.hh:84
Definition: component.hh:85
auto operator()(C &&c) -> decltype(C::template criticalPressure< DisableStaticAssert >())
Definition: component.hh:85