3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
component.hh
Go to the documentation of this file.
1#ifndef DUMUX_PYTHON_MATERIAL_COMPONENT_HH
2#define DUMUX_PYTHON_MATERIAL_COMPONENT_HH
3
4#include <dune/python/pybind11/pybind11.h>
5#include <dune/python/pybind11/stl.h>
6
10
11
15
16} // end namespace Dumux::Python::Detail
17
18namespace Dumux {
25template<>
26struct AlwaysFalse<Dumux::Python::Detail::DisableStaticAssert> : public std::true_type {};
27
28} // end namespace Dumux
29
30namespace Dumux::Python::Detail {
31
32struct Name { template<class C> auto operator()(C&& c) -> decltype(C::template name<DisableStaticAssert>()) {} };
33struct MolarMass { template<class C> auto operator()(C&& c) -> decltype(C::template molarMass<DisableStaticAssert>()) {} };
34struct VaporPressure { template<class C> auto operator()(C&& c) -> decltype(C::template vaporPressure<DisableStaticAssert>(0.0)) {} };
35
36struct LiquidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template liquidIsCompressible<DisableStaticAssert>()) {} };
37struct LiquidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidDensity<DisableStaticAssert>(0.0, 0.0)) {} };
38struct LiquidMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
39struct LiquidViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
40struct LiquidEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
41struct LiquidInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
42struct LiquidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
43struct LiquidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
44
45struct GasIsIdeal { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsIdeal<DisableStaticAssert>()) {} };
46struct GasIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsCompressible<DisableStaticAssert>()) {} };
47struct GasDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasDensity<DisableStaticAssert>(0.0, 0.0)) {} };
48struct GasMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
49struct GasViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template gasViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
50struct GasEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template gasEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
51struct GasInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template gasInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
52struct GasHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template gasHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
53struct GasThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template gasThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
54
55struct SolidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template solidIsCompressible<DisableStaticAssert>()) {} };
56struct SolidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template solidDensity<DisableStaticAssert>(0.0)) {} };
57struct SolidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template solidThermalConductivity<DisableStaticAssert>(0.0)) {} };
58struct SolidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template solidHeatCapacity<DisableStaticAssert>(0.0)) {} };
59
60struct Charge { template<class C> auto operator()(C&& c) -> decltype(C::template charge<DisableStaticAssert>()) {} };
61struct CriticalTemperature { template<class C> auto operator()(C&& c) -> decltype(C::template criticalTemperature<DisableStaticAssert>()) {} };
62struct CriticalPressure { template<class C> auto operator()(C&& c) -> decltype(C::template criticalPressure<DisableStaticAssert>()) {} };
63
64} // end namespace Dumux::Python::Detail
65
66
67namespace Dumux::Python {
68
69template <class Comp, class... options>
70void registerComponent(pybind11::handle scope,
71 pybind11::class_<Comp, options...> cls)
72{
73 using pybind11::operator""_a;
74
75 cls.def(pybind11::init());
76
77 // helper lambda to check if the component implements a certain function
78 constexpr auto implements = [](const auto& c)
79 {
80 return !decltype(isValid(c)(std::declval<Comp>()))::value;
81 };
82
83 if constexpr (implements(Detail::Name{}))
84 cls.def_property_readonly_static("name", &Comp::name);
85 if constexpr (implements(Detail::MolarMass{}))
86 cls.def_property_readonly_static("molarMass", &Comp::molarMass);
87
89 {
90 if constexpr (implements(Detail::LiquidIsCompressible{}))
91 cls.def_property_readonly_static("liquidIsCompressible", &Comp::liquidIsCompressible);
92 if constexpr (implements(Detail::LiquidDensity{}))
93 cls.def_static("liquidDensity", &Comp::liquidDensity, "temperature"_a, "pressure"_a);
94 if constexpr (implements(Detail::LiquidMolarDensity{}))
95 cls.def_static("liquidMolarDensity", &Comp::liquidMolarDensity, "temperature"_a, "pressure"_a);
96 if constexpr (implements(Detail::LiquidViscosity{}))
97 cls.def_static("liquidViscosity", &Comp::liquidViscosity, "temperature"_a, "pressure"_a);
98 if constexpr (implements(Detail::LiquidEnthalpy{}))
99 cls.def_static("liquidEnthalpy", &Comp::liquidEnthalpy, "temperature"_a, "pressure"_a);
100 if constexpr (implements(Detail::LiquidInternalEnergy{}))
101 cls.def_static("liquidInternalEnergy", &Comp::liquidInternalEnergy, "temperature"_a, "pressure"_a);
102 if constexpr (implements(Detail::LiquidHeatCapacity{}))
103 cls.def_static("liquidHeatCapacity", &Comp::liquidHeatCapacity, "temperature"_a, "pressure"_a);
104 if constexpr (implements(Detail::LiquidThermalConductivity{}))
105 cls.def_static("liquidThermalConductivity", &Comp::liquidThermalConductivity, "temperature"_a, "pressure"_a);
106 if constexpr(implements(Detail::VaporPressure{}))
107 cls.def_static("vaporPressure", &Comp::vaporPressure, "temperature"_a);
108 }
109
111 {
112 if constexpr(implements(Detail::GasDensity{}))
113 cls.def_static("gasDensity", &Comp::gasDensity, "temperature"_a, "pressure"_a);
114 if constexpr(implements(Detail::GasMolarDensity{}))
115 cls.def_static("gasMolarDensity", &Comp::gasMolarDensity, "temperature"_a, "pressure"_a);
116 if constexpr(implements(Detail::GasIsCompressible{}))
117 cls.def_property_readonly_static("gasIsCompressible", &Comp::gasIsCompressible);
118 if constexpr(implements(Detail::GasIsIdeal{}))
119 cls.def_property_readonly_static("gasIsIdeal", &Comp::gasIsIdeal);
120 if constexpr(implements(Detail::GasViscosity{}))
121 cls.def_static("gasViscosity", &Comp::gasViscosity, "temperature"_a, "pressure"_a);
122 if constexpr(implements(Detail::GasEnthalpy{}))
123 cls.def_static("gasEnthalpy", &Comp::gasEnthalpy, "temperature"_a, "pressure"_a);
124 if constexpr(implements(Detail::GasInternalEnergy{}))
125 cls.def_static("gasInternalEnergy", &Comp::gasInternalEnergy, "temperature"_a, "pressure"_a);
126 if constexpr(implements(Detail::GasHeatCapacity{}))
127 cls.def_static("gasHeatCapacity", &Comp::gasHeatCapacity, "temperature"_a, "pressure"_a);
128 if constexpr(implements(Detail::GasThermalConductivity{}))
129 cls.def_static("gasThermalConductivity", &Comp::gasThermalConductivity, "temperature"_a, "pressure"_a);
130 }
131
133 {
134 if constexpr(implements(Detail::SolidIsCompressible{}))
135 cls.def_property_readonly_static("solidIsCompressible", &Comp::solidIsCompressible);
136 if constexpr(implements(Detail::SolidDensity{}))
137 cls.def_property_readonly_static("solidDensity", &Comp::solidDensity, "temperature_a");
138 if constexpr(implements(Detail::SolidThermalConductivity{}))
139 cls.def_static("solidThermalConductivity", &Comp::solidThermalConductivity, "temperature_a");
140 if constexpr(implements(Detail::SolidHeatCapacity{}))
141 cls.def_static("solidHeatCapacity", &Comp::solidHeatCapacity, "temperature_a");
142 }
143
144 if constexpr (ComponentTraits<Comp>::isIon)
145 {
146 if constexpr(implements(Detail::Charge{}))
147 cls.def_property_readonly_static("charge", &Comp::charge);
148 }
149
151 {
152 if constexpr(implements(Detail::CriticalTemperature{}))
153 cls.def_property_readonly_static("criticalTemperature", &Comp::criticalTemperature);
154 if constexpr(implements(Detail::CriticalPressure{}))
155 cls.def_property_readonly_static("criticalPressure", &Comp::criticalPressure);
156 }
157}
158
159
160} // namespace Dumux::Python
161
162#endif
A helper function for class member function introspection.
Type traits.
Component traits, i.e. information extracted from components.
Definition: adapt.hh:29
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
Definition: python/assembly/fvassembler.hh:30
void registerComponent(pybind11::handle scope, pybind11::class_< Comp, options... > cls)
Definition: component.hh:70
Definition: component.hh:12
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:14
Definition: component.hh:32
auto operator()(C &&c) -> decltype(C::template name< DisableStaticAssert >())
Definition: component.hh:32
Definition: component.hh:33
auto operator()(C &&c) -> decltype(C::template molarMass< DisableStaticAssert >())
Definition: component.hh:33
Definition: component.hh:34
auto operator()(C &&c) -> decltype(C::template vaporPressure< DisableStaticAssert >(0.0))
Definition: component.hh:34
auto operator()(C &&c) -> decltype(C::template liquidIsCompressible< DisableStaticAssert >())
Definition: component.hh:36
Definition: component.hh:37
auto operator()(C &&c) -> decltype(C::template liquidDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:37
auto operator()(C &&c) -> decltype(C::template liquidMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:38
Definition: component.hh:39
auto operator()(C &&c) -> decltype(C::template liquidViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:39
Definition: component.hh:40
auto operator()(C &&c) -> decltype(C::template liquidEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:40
auto operator()(C &&c) -> decltype(C::template liquidInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:41
auto operator()(C &&c) -> decltype(C::template liquidHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:42
auto operator()(C &&c) -> decltype(C::template liquidThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:43
Definition: component.hh:45
auto operator()(C &&c) -> decltype(C::template gasIsIdeal< DisableStaticAssert >())
Definition: component.hh:45
Definition: component.hh:46
auto operator()(C &&c) -> decltype(C::template gasIsCompressible< DisableStaticAssert >())
Definition: component.hh:46
Definition: component.hh:47
auto operator()(C &&c) -> decltype(C::template gasDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:47
Definition: component.hh:48
auto operator()(C &&c) -> decltype(C::template gasMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:48
Definition: component.hh:49
auto operator()(C &&c) -> decltype(C::template gasViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:49
Definition: component.hh:50
auto operator()(C &&c) -> decltype(C::template gasEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:50
Definition: component.hh:51
auto operator()(C &&c) -> decltype(C::template gasInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:51
Definition: component.hh:52
auto operator()(C &&c) -> decltype(C::template gasHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:52
auto operator()(C &&c) -> decltype(C::template gasThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:53
auto operator()(C &&c) -> decltype(C::template solidIsCompressible< DisableStaticAssert >())
Definition: component.hh:55
Definition: component.hh:56
auto operator()(C &&c) -> decltype(C::template solidDensity< DisableStaticAssert >(0.0))
Definition: component.hh:56
auto operator()(C &&c) -> decltype(C::template solidThermalConductivity< DisableStaticAssert >(0.0))
Definition: component.hh:57
Definition: component.hh:58
auto operator()(C &&c) -> decltype(C::template solidHeatCapacity< DisableStaticAssert >(0.0))
Definition: component.hh:58
Definition: component.hh:60
auto operator()(C &&c) -> decltype(C::template charge< DisableStaticAssert >())
Definition: component.hh:60
auto operator()(C &&c) -> decltype(C::template criticalTemperature< DisableStaticAssert >())
Definition: component.hh:61
Definition: component.hh:62
auto operator()(C &&c) -> decltype(C::template criticalPressure< DisableStaticAssert >())
Definition: component.hh:62