version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PYTHON_MATERIAL_COMPONENT_HH
13#define DUMUX_PYTHON_MATERIAL_COMPONENT_HH
14
15#include <dune/python/pybind11/pybind11.h>
16#include <dune/python/pybind11/stl.h>
17
21
22
26
27} // end namespace Dumux::Python::Detail
28
29namespace Dumux {
36template<>
37struct AlwaysFalse<Dumux::Python::Detail::DisableStaticAssert> : public std::true_type {};
38
39} // end namespace Dumux
40
41namespace Dumux::Python::Detail {
42
43struct Name { template<class C> auto operator()(C&& c) -> decltype(C::template name<DisableStaticAssert>()) {} };
44struct MolarMass { template<class C> auto operator()(C&& c) -> decltype(C::template molarMass<DisableStaticAssert>()) {} };
45struct VaporPressure { template<class C> auto operator()(C&& c) -> decltype(C::template vaporPressure<DisableStaticAssert>(0.0)) {} };
46
47struct LiquidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template liquidIsCompressible<DisableStaticAssert>()) {} };
48struct LiquidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidDensity<DisableStaticAssert>(0.0, 0.0)) {} };
49struct LiquidMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
50struct LiquidViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
51struct LiquidEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
52struct LiquidInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template liquidInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
53struct LiquidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
54struct LiquidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template liquidThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
55
56struct GasIsIdeal { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsIdeal<DisableStaticAssert>()) {} };
57struct GasIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template gasIsCompressible<DisableStaticAssert>()) {} };
58struct GasDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasDensity<DisableStaticAssert>(0.0, 0.0)) {} };
59struct GasMolarDensity { template<class C> auto operator()(C&& c) -> decltype(C::template gasMolarDensity<DisableStaticAssert>(0.0, 0.0)) {} };
60struct GasViscosity { template<class C> auto operator()(C&& c) -> decltype(C::template gasViscosity<DisableStaticAssert>(0.0, 0.0)) {} };
61struct GasEnthalpy { template<class C> auto operator()(C&& c) -> decltype(C::template gasEnthalpy<DisableStaticAssert>(0.0, 0.0)) {} };
62struct GasInternalEnergy { template<class C> auto operator()(C&& c) -> decltype(C::template gasInternalEnergy<DisableStaticAssert>(0.0, 0.0)) {} };
63struct GasHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template gasHeatCapacity<DisableStaticAssert>(0.0, 0.0)) {} };
64struct GasThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template gasThermalConductivity<DisableStaticAssert>(0.0, 0.0)) {} };
65
66struct SolidIsCompressible { template<class C> auto operator()(C&& c) -> decltype(C::template solidIsCompressible<DisableStaticAssert>()) {} };
67struct SolidDensity { template<class C> auto operator()(C&& c) -> decltype(C::template solidDensity<DisableStaticAssert>(0.0)) {} };
68struct SolidThermalConductivity { template<class C> auto operator()(C&& c) -> decltype(C::template solidThermalConductivity<DisableStaticAssert>(0.0)) {} };
69struct SolidHeatCapacity { template<class C> auto operator()(C&& c) -> decltype(C::template solidHeatCapacity<DisableStaticAssert>(0.0)) {} };
70
71struct Charge { template<class C> auto operator()(C&& c) -> decltype(C::template charge<DisableStaticAssert>()) {} };
72struct CriticalTemperature { template<class C> auto operator()(C&& c) -> decltype(C::template criticalTemperature<DisableStaticAssert>()) {} };
73struct CriticalPressure { template<class C> auto operator()(C&& c) -> decltype(C::template criticalPressure<DisableStaticAssert>()) {} };
74
75} // end namespace Dumux::Python::Detail
76
77
78namespace Dumux::Python {
79
80template <class Comp, class... options>
81void registerComponent(pybind11::handle scope,
82 pybind11::class_<Comp, options...> cls)
83{
84 using pybind11::operator""_a;
85
86 cls.def(pybind11::init());
87
88 // helper lambda to check if the component implements a certain function
89 constexpr auto implements = [](const auto& c)
90 {
91 return !decltype(isValid(c)(std::declval<Comp>()))::value;
92 };
93
94 if constexpr (implements(Detail::Name{}))
95 cls.def_property_readonly_static("name", &Comp::name);
96 if constexpr (implements(Detail::MolarMass{}))
97 cls.def_property_readonly_static("molarMass", &Comp::molarMass);
98
100 {
101 if constexpr (implements(Detail::LiquidIsCompressible{}))
102 cls.def_property_readonly_static("liquidIsCompressible", &Comp::liquidIsCompressible);
103 if constexpr (implements(Detail::LiquidDensity{}))
104 cls.def_static("liquidDensity", &Comp::liquidDensity, "temperature"_a, "pressure"_a);
105 if constexpr (implements(Detail::LiquidMolarDensity{}))
106 cls.def_static("liquidMolarDensity", &Comp::liquidMolarDensity, "temperature"_a, "pressure"_a);
107 if constexpr (implements(Detail::LiquidViscosity{}))
108 cls.def_static("liquidViscosity", &Comp::liquidViscosity, "temperature"_a, "pressure"_a);
109 if constexpr (implements(Detail::LiquidEnthalpy{}))
110 cls.def_static("liquidEnthalpy", &Comp::liquidEnthalpy, "temperature"_a, "pressure"_a);
111 if constexpr (implements(Detail::LiquidInternalEnergy{}))
112 cls.def_static("liquidInternalEnergy", &Comp::liquidInternalEnergy, "temperature"_a, "pressure"_a);
113 if constexpr (implements(Detail::LiquidHeatCapacity{}))
114 cls.def_static("liquidHeatCapacity", &Comp::liquidHeatCapacity, "temperature"_a, "pressure"_a);
115 if constexpr (implements(Detail::LiquidThermalConductivity{}))
116 cls.def_static("liquidThermalConductivity", &Comp::liquidThermalConductivity, "temperature"_a, "pressure"_a);
117 if constexpr(implements(Detail::VaporPressure{}))
118 cls.def_static("vaporPressure", &Comp::vaporPressure, "temperature"_a);
119 }
120
122 {
123 if constexpr(implements(Detail::GasDensity{}))
124 cls.def_static("gasDensity", &Comp::gasDensity, "temperature"_a, "pressure"_a);
125 if constexpr(implements(Detail::GasMolarDensity{}))
126 cls.def_static("gasMolarDensity", &Comp::gasMolarDensity, "temperature"_a, "pressure"_a);
127 if constexpr(implements(Detail::GasIsCompressible{}))
128 cls.def_property_readonly_static("gasIsCompressible", &Comp::gasIsCompressible);
129 if constexpr(implements(Detail::GasIsIdeal{}))
130 cls.def_property_readonly_static("gasIsIdeal", &Comp::gasIsIdeal);
131 if constexpr(implements(Detail::GasViscosity{}))
132 cls.def_static("gasViscosity", &Comp::gasViscosity, "temperature"_a, "pressure"_a);
133 if constexpr(implements(Detail::GasEnthalpy{}))
134 cls.def_static("gasEnthalpy", &Comp::gasEnthalpy, "temperature"_a, "pressure"_a);
135 if constexpr(implements(Detail::GasInternalEnergy{}))
136 cls.def_static("gasInternalEnergy", &Comp::gasInternalEnergy, "temperature"_a, "pressure"_a);
137 if constexpr(implements(Detail::GasHeatCapacity{}))
138 cls.def_static("gasHeatCapacity", &Comp::gasHeatCapacity, "temperature"_a, "pressure"_a);
139 if constexpr(implements(Detail::GasThermalConductivity{}))
140 cls.def_static("gasThermalConductivity", &Comp::gasThermalConductivity, "temperature"_a, "pressure"_a);
141 }
142
144 {
145 if constexpr(implements(Detail::SolidIsCompressible{}))
146 cls.def_property_readonly_static("solidIsCompressible", &Comp::solidIsCompressible);
147 if constexpr(implements(Detail::SolidDensity{}))
148 cls.def_property_readonly_static("solidDensity", &Comp::solidDensity, "temperature_a");
149 if constexpr(implements(Detail::SolidThermalConductivity{}))
150 cls.def_static("solidThermalConductivity", &Comp::solidThermalConductivity, "temperature_a");
151 if constexpr(implements(Detail::SolidHeatCapacity{}))
152 cls.def_static("solidHeatCapacity", &Comp::solidHeatCapacity, "temperature_a");
153 }
154
155 if constexpr (ComponentTraits<Comp>::isIon)
156 {
157 if constexpr(implements(Detail::Charge{}))
158 cls.def_property_readonly_static("charge", &Comp::charge);
159 }
160
162 {
163 if constexpr(implements(Detail::CriticalTemperature{}))
164 cls.def_property_readonly_static("criticalTemperature", &Comp::criticalTemperature);
165 if constexpr(implements(Detail::CriticalPressure{}))
166 cls.def_property_readonly_static("criticalPressure", &Comp::criticalPressure);
167 }
168}
169
170
171} // namespace Dumux::Python
172
173#endif
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:81
A helper function for class member function introspection.
Definition: component.hh:23
Definition: python/assembly/fvassembler.hh:18
void registerComponent(pybind11::handle scope, pybind11::class_< Comp, options... > cls)
Definition: component.hh:81
Definition: adapt.hh:17
Template which always yields a false value.
Definition: common/typetraits/typetraits.hh:24
Component traits, i.e. information extracted from components.
Definition: componenttraits.hh:31
Definition: component.hh:71
auto operator()(C &&c) -> decltype(C::template charge< DisableStaticAssert >())
Definition: component.hh:71
Definition: component.hh:73
auto operator()(C &&c) -> decltype(C::template criticalPressure< DisableStaticAssert >())
Definition: component.hh:73
auto operator()(C &&c) -> decltype(C::template criticalTemperature< DisableStaticAssert >())
Definition: component.hh:72
Helper struct to deactivate static assertions in component's base classes.
Definition: component.hh:25
Definition: component.hh:58
auto operator()(C &&c) -> decltype(C::template gasDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:58
Definition: component.hh:61
auto operator()(C &&c) -> decltype(C::template gasEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:61
Definition: component.hh:63
auto operator()(C &&c) -> decltype(C::template gasHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:63
Definition: component.hh:62
auto operator()(C &&c) -> decltype(C::template gasInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:62
Definition: component.hh:57
auto operator()(C &&c) -> decltype(C::template gasIsCompressible< DisableStaticAssert >())
Definition: component.hh:57
Definition: component.hh:56
auto operator()(C &&c) -> decltype(C::template gasIsIdeal< DisableStaticAssert >())
Definition: component.hh:56
Definition: component.hh:59
auto operator()(C &&c) -> decltype(C::template gasMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:59
auto operator()(C &&c) -> decltype(C::template gasThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:64
Definition: component.hh:60
auto operator()(C &&c) -> decltype(C::template gasViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:60
Definition: component.hh:48
auto operator()(C &&c) -> decltype(C::template liquidDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:48
Definition: component.hh:51
auto operator()(C &&c) -> decltype(C::template liquidEnthalpy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:51
auto operator()(C &&c) -> decltype(C::template liquidHeatCapacity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:53
auto operator()(C &&c) -> decltype(C::template liquidInternalEnergy< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:52
auto operator()(C &&c) -> decltype(C::template liquidIsCompressible< DisableStaticAssert >())
Definition: component.hh:47
auto operator()(C &&c) -> decltype(C::template liquidMolarDensity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:49
auto operator()(C &&c) -> decltype(C::template liquidThermalConductivity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:54
Definition: component.hh:50
auto operator()(C &&c) -> decltype(C::template liquidViscosity< DisableStaticAssert >(0.0, 0.0))
Definition: component.hh:50
Definition: component.hh:44
auto operator()(C &&c) -> decltype(C::template molarMass< DisableStaticAssert >())
Definition: component.hh:44
Definition: component.hh:43
auto operator()(C &&c) -> decltype(C::template name< DisableStaticAssert >())
Definition: component.hh:43
Definition: component.hh:67
auto operator()(C &&c) -> decltype(C::template solidDensity< DisableStaticAssert >(0.0))
Definition: component.hh:67
Definition: component.hh:69
auto operator()(C &&c) -> decltype(C::template solidHeatCapacity< DisableStaticAssert >(0.0))
Definition: component.hh:69
auto operator()(C &&c) -> decltype(C::template solidIsCompressible< DisableStaticAssert >())
Definition: component.hh:66
auto operator()(C &&c) -> decltype(C::template solidThermalConductivity< DisableStaticAssert >(0.0))
Definition: component.hh:68
Definition: component.hh:45
auto operator()(C &&c) -> decltype(C::template vaporPressure< DisableStaticAssert >(0.0))
Definition: component.hh:45