From 4f890ed37915deec521dab04844515d96ea38709 Mon Sep 17 00:00:00 2001 From: Bernd Flemisch Date: Fri, 13 Mar 2020 11:25:43 +0100 Subject: [PATCH] [properties] continue with splice mechanism --- opm/models/common/multiphasebasemodel.hh | 7 +- .../discretization/common/fvbaseproperties.hh | 8 + opm/models/utils/basicproperties.hh | 3 +- opm/models/utils/propertysystem.hh | 147 +++++++----------- 4 files changed, 70 insertions(+), 95 deletions(-) diff --git a/opm/models/common/multiphasebasemodel.hh b/opm/models/common/multiphasebasemodel.hh index 40bd23e3a..b2fd150bb 100644 --- a/opm/models/common/multiphasebasemodel.hh +++ b/opm/models/common/multiphasebasemodel.hh @@ -50,6 +50,11 @@ class MultiPhaseBaseModel; BEGIN_PROPERTIES +namespace TTag { +struct ParallelBiCGStabLinearSolver; +struct FiniteDifferenceLocalLinearizer; +} + //! The generic type tag for problems using the immiscible multi-phase model NEW_TYPE_TAG(MultiPhaseBaseModel, INHERITS_FROM(NumericModel, VtkMultiPhase, VtkTemperature)); @@ -59,7 +64,7 @@ NEW_TYPE_TAG(MultiPhaseBaseModel, INHERITS_FROM(NumericModel, VtkMultiPhase, Vtk template struct Splices { - using tuple = std::tuple>; + using type = std::tuple>; }; //! Set the default spatial discretization diff --git a/opm/models/discretization/common/fvbaseproperties.hh b/opm/models/discretization/common/fvbaseproperties.hh index 1ebc9e96d..54ac34beb 100644 --- a/opm/models/discretization/common/fvbaseproperties.hh +++ b/opm/models/discretization/common/fvbaseproperties.hh @@ -51,6 +51,14 @@ NEW_TYPE_TAG(FvBaseDiscretization, //SET_SPLICES(FvBaseDiscretization, LinearSolverSplice, LocalLinearizerSplice); +template +struct Splices +{ +// using type = std::tuple, +// GetSplicePropType>; + using type = std::tuple; +}; //! use a parallel BiCGStab linear solver by default SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelBiCGStabLinearSolver); diff --git a/opm/models/utils/basicproperties.hh b/opm/models/utils/basicproperties.hh index bb77eb677..27a13982b 100644 --- a/opm/models/utils/basicproperties.hh +++ b/opm/models/utils/basicproperties.hh @@ -100,7 +100,7 @@ NEW_PROP_TAG(ThreadManager); NEW_PROP_TAG(NewtonMethod); NEW_PROP_TAG(SolutionVector); NEW_PROP_TAG(GlobalEqVector); -//NEW_PROP_TAG(VtkOutputFormat); +NEW_PROP_TAG(VtkOutputFormat); //! Specifies the type of a solution for a single degee of freedom NEW_PROP_TAG(PrimaryVariables); @@ -318,6 +318,7 @@ NEW_PROP_TAG(LinearSolverMaxError); NEW_PROP_TAG(LinearSolverSplice); NEW_PROP_TAG(LocalLinearizerSplice); +NEW_PROP_TAG(SpatialDiscretizationSplice); //! The discretization specific part of he implementing the Newton algorithm NEW_PROP_TAG(DiscNewtonMethod); diff --git a/opm/models/utils/propertysystem.hh b/opm/models/utils/propertysystem.hh index ec2a2cfd2..afa9d9567 100644 --- a/opm/models/utils/propertysystem.hh +++ b/opm/models/utils/propertysystem.hh @@ -39,7 +39,7 @@ struct UndefinedProperty {}; template struct Splices { - using tuple = std::tuple<>; + using type = std::tuple<>; }; @@ -133,124 +133,82 @@ struct GetDefined> }; +//! helper struct to get the first property that is defined in the TypeTag hierarchy +template +struct GetDefinedSplice; + +//! helper struct to iterate over the TypeTag hierarchy +template +struct GetNextSpliceTypeTag; + +template +struct GetNextSpliceTypeTag, std::enable_if_t(int{}), void>> +{ using type = typename GetDefinedSplice::type; }; + +template +struct GetNextSpliceTypeTag, std::enable_if_t(int{}), void>> +{ using type = std::tuple<>; }; + +template +struct GetNextSpliceTypeTag, std::enable_if_t(int{}), void>> +{ using type = typename GetDefinedSplice>>::type; }; + +template +struct GetNextSpliceTypeTag, std::enable_if_t(int{}), void>> +{ using type = typename GetDefinedSplice>::type; }; + //! check if a splice S is defined template constexpr auto isDefinedSplice(int) --> decltype(std::integral_constant>::value>{}) +-> decltype(std::integral_constant>::value>{}) { return {}; } //! fall back if a splice is defined template constexpr std::true_type isDefinedSplice(...) { return {}; } -template -struct GetSplicesTypeTags; - -template -struct GetNextSplicesTypeTag; - template -struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> -{ using tuple = typename GetSplicesTypeTags::tuple; }; - -template -struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> -{ using tuple = std::tuple<>; }; - -template -struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> -{ using tuple = typename GetSplicesTypeTags>>::tuple; }; - -template -struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> -{ using tuple = typename GetSplicesTypeTags>::tuple; }; - -template -struct GetSplicesTypeTags> +struct GetDefinedSplice> { - using LastSplices = Splices; - using nexttuple = typename GetNextSplicesTypeTag, void>::tuple; - // originally intended -// using tuple = std::conditional_t(int{}), -// typename ConCatTuples::tuple, -// nexttuple>; - using tuple = std::conditional_t(int{}), - typename LastSplices::tuple, - typename GetNextSplicesTypeTag, void>::tuple>; + using LastSplice = Splices; + using nexttuple = typename GetNextSpliceTypeTag, void>::type; + + using type = std::conditional_t(int{}), + ConCatTuples, + nexttuple>; }; template -struct GetSplicesTypeTags> +struct GetDefinedSplice> { - using FirstSplices = Splices; - using nexttuple = typename GetNextSplicesTypeTag, void>::tuple; - // originally intended -// using tuple = std::conditional_t(int{}), -// typename ConCatTuples::tuple, -// nexttuple>; - using tuple = std::conditional_t(int{}), - typename FirstSplices::tuple, - typename GetNextSplicesTypeTag, void>::tuple>; + using FirstSplice = Splices; + using nexttuple = typename GetNextSpliceTypeTag, void>::type; + + using type = std::conditional_t(int{}), + ConCatTuples, + nexttuple>; }; -} // end namespace Detail - -template -struct SpatialDiscretizationSplice { using type = UndefinedProperty; }; - -namespace TTag { -struct MyTTag {}; -struct MySDTTag {}; -} - -template -struct SpatialDiscretizationSplice -{ using type = TTag::MySDTTag; }; - -template -struct VtkOutputFormat { using type = UndefinedProperty; }; - -template -struct VtkOutputFormat -{ static constexpr auto value = 2; }; - -namespace TTag { -struct FvBaseDiscretization; -struct VcfvDiscretization; -struct MultiPhaseBaseModel; -} - -namespace Detail { - - //! helper struct to extract get the Property specilization given a TypeTag, asserts that the property is defined +//! helper struct to extract get the Property specilization given a TypeTag, asserts that the property is defined template class Property> struct GetPropImpl { - using PType = Properties::SpatialDiscretizationSplice; - using testtype = std::conditional_t(int{}), PType, UndefinedProperty>; - static_assert(!std::is_same::value, "SpatialDiscretizationSplice is undefined in MyTTag!"); - - using QType = Properties::VtkOutputFormat; - using testtype2 = std::conditional_t(int{}), QType, UndefinedProperty>; - static_assert(!std::is_same::value, "VtkOutputFormat is undefined in MySDTTag!"); - - using RType = Properties::VtkOutputFormat; - using testtype3 = std::conditional_t(int{}), RType, UndefinedProperty>; - static_assert(!std::is_same::value, "VtkOutputFormat is undefined in FvBaseDiscretization!"); - - // works: -// using type = typename Detail::GetDefined -// >::type; - using tuple = typename GetSplicesTypeTags>::tuple; + using splice = typename Detail::GetDefinedSplice>::type; + using tuple = std::conditional_t>::value, std::tuple<>, splice>; using type = typename Detail::GetDefined, tuple>::type + ConCatTuples, tuple> >::type; static_assert(!std::is_same::value, "Property is undefined!"); }; +template class Property> +struct GetSplicePropImpl +{ + using type = typename Detail::GetDefined>::type; + static_assert(!std::is_same>::value, "Splice is undefined!"); +}; + } // end namespace Detail } // end namespace Property @@ -267,6 +225,9 @@ using GetProp = typename Properties::Detail::GetPropImpl::typ template class Property> using GetPropType = typename Properties::Detail::GetPropImpl::type::type; +template class Property> +using GetSplicePropType = typename Properties::Detail::GetSplicePropImpl::type::type; + //! get the value data member of a property template class Property> constexpr auto getPropValue() { return Properties::Detail::GetPropImpl::type::value; }