Compile-time configuration and setup of DuMux models and simulations. More...
The DuMux property system is based on the concept of type traits with added inheritance. It is implemented using template metaprogramming.
In the context of the DuMux property system, a property is an arbitrary class which may contain type definitions, values and methods. Just like normal classes, properties can be arranged in hierarchies. In the context of the DuMux property system, nodes of the inheritance hierarchy are called type tags.
It also supports property nesting. Property nesting means that the definition of a property can depend on the value of other properties which may be defined for arbitrary levels of the inheritance hierarchy.
This section gives a high level overview over the property system's design and principle ideas illustrated by self-contained examples.
All source files which use the property system should include the header file dumux/common/properties.hh. Declaration of type tags and property tags as well as defining properties must be done inside the namespace Dumux::Properties.
New nodes in the type tag hierarchy can be defined in the Dumux::Properties::TTag namespace using
where the InheritsFrom alias is optional. To avoid inconsistencies in the hierarchy, each type tag may be defined only once for a program. If you call Dumux::GetProp the property system will first look for the properties defined in BaseTagName1 in the InheritsFrom list. If a defined property is found this property is returned. If no defined property is found the search will continue in the ancestors of BaseTagName1. If again no defined property is found the search will continue in the second BaseTagName2 in the list, and so on. If no defined property is found at all, a compiler error is triggered.
Example:
New property tags are defined using the macro DUMUX_DEFINE_PROPERTY, e.g.
Essentially this corresponds to the following code
If you need to forward declare a property you can use
The value of a property on a given node of the type tag hierarchy is defined by means of partial template specialization
where here the property PropertyTagName is specialized for the tag TTag::TypeTagName. The body typically contains either the type alias type, or a static constexpr data member value. However, you can of course write in the body whatever you like.
Here is an example including a type tag, property definitions and specializations:
The type of a property can be retrieved using
There is a helper struct and a helper function to retrieve the type and value members of a property
Example:
Inside property definitions there is access to all other properties which are defined somewhere on the type tag hierarchy. The node for which the current property is requested is available via the template argument TypeTag. Inside property class bodies GetPropType can be used to retrieve other properties and create aliases.
Example:
As a concrete example, let us consider some kinds of cars: Compact cars, sedans, trucks, pickups, military tanks and the Hummer-H1 sports utility vehicle. Since all these cars share some characteristics, it makes sense to inherit those from the closest matching car type and only specify the properties which are different. Thus, an inheritance diagram for the car types above might look like outlined in the figure.
Using the DuMux property system, this type hierarchy with inheritance is defined by:
The Figure lists a few property names which make sense for at least one of the nodes. These property names can be defined as follows:
So far, the inheritance hierarchy and the property names are completely separate. What is missing is setting some values for the property names on specific nodes of the inheritance hierarchy. Let us assume the following:
Using the DuMux property system, these assumptions are formulated using
The above hierarchy can also be written in a more terse notation using property type aliases. For this to work, the properties must be defined with the DUMUX_DEFINE_PROPERTY macro.
The property values can be retrieved with Dumux::getPropValue and some diagnostic messages can be generated. For example
will yield the following output:
Classes | |
| struct | Dumux::Properties::UndefinedProperty |
| a tag to mark properties as undefined More... | |
| struct | Dumux::Properties::PropertyAlias< P > |
| a tag to specify a direct alias for property extraction More... | |
Macros | |
| #define | DUMUX_DEFINE_PROPERTY(Prop) |
| A preprocessor macro to define properties. | |
Typedefs | |
| template<class TypeTag, template< class, class > class Property> | |
| using | Dumux::GetProp = typename Properties::Detail::GetPropImpl<TypeTag, Property>::type |
| get the type of a property | |
| template<class TypeTag, template< class, class > class Property, class T> | |
| using | Dumux::GetPropOr = typename Properties::Detail::GetPropOrImpl<TypeTag, Property, T>::type |
| get the type of a property or the type T if the property is undefined | |
| template<class TypeTag, template< class, class > class Property> | |
| using | Dumux::GetPropType = typename GetProp<TypeTag, Property>::type |
| get the type alias defined in the property | |
| template<class TypeTag, template< class, class > class Property, class T> | |
| using | Dumux::GetPropTypeOr = typename GetPropOr<TypeTag, Property, T>::type |
| get the type alias defined in the property or the type T if the property is undefined | |
Functions | |
| template<class TypeTag, template< class, class > class Property> | |
| constexpr bool | Dumux::Properties::hasDefinedType () |
| whether the property is defined/specialized for TypeTag | |
| template<class ParentTypeTag, class TypeTag> | |
| constexpr bool | Dumux::Properties::inheritsFrom () |
| Return true if the given type tag inherits from the given parent type tag. | |
| template<class TypeTag, template< class, class > class Property> | |
| constexpr auto | Dumux::getPropValue () |
| get the value data member of a property | |
Files | |
| file | properties.hh |
| Defines all properties used in Dumux. | |
| file | grid.hh |
| Defines a type tags and some fundamental grid-related properties. | |
| file | model.hh |
| Defines a type tags and some fundamental properties for all models. | |
| file | propertysystem.hh |
| The Dumux property system, traits with inheritance. | |
| #define DUMUX_DEFINE_PROPERTY | ( | Prop | ) |
The macro defines two components for each property. The first is the definition of the property. For example for a property Scalar we get
The second is the specialization of the PropertyAlias template for the newly defined property. For a property Scalar, we get
The specialization contains the template alias "Alias" that can be used to check if a given type tag "MyTypeTag" has an alias member "Scalar", and a template alias "TemplateAlias" that can be used to check if a given type tag "MyTypeTag" has a template alias Scalar and can be instantiated with a given type tag "TypeTag" (this will be the user- end type tag).
| using Dumux::GetProp = typename Properties::Detail::GetPropImpl<TypeTag, Property>::type |
| using Dumux::GetPropOr = typename Properties::Detail::GetPropOrImpl<TypeTag, Property, T>::type |
| using Dumux::GetPropType = typename GetProp<TypeTag, Property>::type |
| using Dumux::GetPropTypeOr = typename GetPropOr<TypeTag, Property, T>::type |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |