diff --git a/slides/properties.md b/slides/properties.md index fc7d6e4511750c2e539aa2994d0c7e9d889ed801..d49b4246c1ad111e038c36824696fff69599db73 100644 --- a/slides/properties.md +++ b/slides/properties.md @@ -76,7 +76,6 @@ using GOF0 = Dune::GridOperator< CF, CF >; -DGGO2 dggo2(gfs, cd, gfs, cf, lop, mbe); ``` ## Traits classes @@ -84,7 +83,7 @@ DGGO2 dggo2(gfs, cd, gfs, cf, lop, mbe); A usual way to group template parameters ```cpp -template<class PV, class FSY, class FST, class SSY, class SST, class PT, class MT, class SR> +template<class PV, class FSY, class FST, class SSY,...> struct TwoPVolumeVariablesTraits { using PrimaryVariables = PV; @@ -97,31 +96,42 @@ struct TwoPVolumeVariablesTraits using SaturationReconstruction = SR; }; ``` -## Traits classes -Making it usable using a single template parameter -```c++ -template<class TypeTag> -struct VolumeVariables<TypeTag, TTag::TwoP> +## Type traits + +Why do we need the type? + +```cpp +// Type trait template declaration +template<typename T> struct ValueType; + +// Specialization for vectors of T +template<typename T, typename Allocator> +struct ValueType<std::vector<T, Allocator>> { using type = T; }; + +// Specialization for Dune::FieldVector +template<typename T, int size> +struct ValueType<Dune::FieldVector<T, size>> { using type = T; }; +``` + +## Type traits + +```cpp + +template <class Traits> +class TwoPVolumeVariables + { -private: - using PV = GetPropType<TypeTag, Properties::PrimaryVariables>; - using FSY = GetPropType<TypeTag, Properties::FluidSystem>; - using FST = GetPropType<TypeTag, Properties::FluidState>; - using SSY = GetPropType<TypeTag, Properties::SolidSystem>; - using SST = GetPropType<TypeTag, Properties::SolidState>; - using MT = GetPropType<TypeTag, Properties::ModelTraits>; - using PT = typename GetPropType<TypeTag, Properties::SpatialParams>::PermeabilityType; - using DM = typename GetPropType<TypeTag, Properties::GridGeometry>::DiscretizationMethod; - static constexpr bool enableIS = getPropValue<TypeTag, Properties::EnableBoxInterfaceSolver>(); - // class used for scv-wise reconstruction of nonwetting phase saturations - using SR = TwoPScvSaturationReconstruction<DM, enableIS>; - - using Traits = TwoPVolumeVariablesTraits<PV, FSY, FST, SSY, SST, PT, MT, SR>; -public: - using type = TwoPVolumeVariables<Traits>; -}; + ... +using FluidSystem = typename Traits::FluidSystem + ... + +``` +Usage: these VolumeVariables will work for various FluidSystems: + +```cpp +Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx); ``` ## Inheriting from traits classes @@ -143,24 +153,6 @@ struct MyDoubleTraits : public MyBaseTraits // this is a vector of ints! typename MyDoubleTraits::Vector v{1.14142, 1.73205}; ``` - -## Type traits - -Based on template specialization - -```cpp -// Type trait template declaration -template<typename T> struct ValueType; - -// Specialization for vectors of T -template<typename T, typename Allocator> -struct ValueType<std::vector<T, Allocator>> { using type = T; }; - -// Specialization for Dune::FieldVector -template<typename T, int size> -struct ValueType<Dune::FieldVector<T, size>> { using type = T; }; -``` - # The DuMuX Property System ## Property System Design