[properties] replace propertysystem

This commit is contained in:
Bernd Flemisch
2020-02-07 15:44:22 +01:00
parent 344f6587fa
commit 6d6ba6909c
65 changed files with 865 additions and 1668 deletions

View File

@@ -30,9 +30,23 @@
#include <dune/common/parametertree.hh>
// explicitly guard the include so that the property system
// header doesn't need to be opened and checked all the time
#ifndef OPM_PROPERTY_SYSTEM_HH
#include <opm/models/utils/propertysystem.hh>
// remove this after release 3.1 to disable macros per default
#ifndef OPM_ENABLE_OLD_PROPERTY_MACROS
#define OPM_ENABLE_OLD_PROPERTY_MACROS 1
#endif
// remove this after release 3.2 to remove macros completely
#if OPM_ENABLE_OLD_PROPERTY_MACROS
#include <opm/models/utils/propertysystemmacros.hh>
#endif // OPM_ENABLE_OLD_PROPERTY_MACROS
#endif // OPM_PROPERTY_SYSTEM_HH
#include <opm/models/utils/parametersystem.hh>
#include <opm/models/io/dgfvanguard.hh>
#if HAVE_DUNE_FEM
#include <dune/fem/gridpart/adaptiveleafgridpart.hh>
@@ -50,6 +64,7 @@ BEGIN_PROPERTIES
// +-> ImplicitModel
///////////////////////////////////
NEW_TYPE_TAG(ParameterSystem);
//! Type tag for all models.
NEW_TYPE_TAG(NumericModel, INHERITS_FROM(ParameterSystem));
@@ -76,10 +91,238 @@ NEW_PROP_TAG(Vanguard);
NEW_PROP_TAG(GridView);
NEW_PROP_TAG(Simulator);
NEW_PROP_TAG(Grid);
NEW_PROP_TAG(GridFile);
NEW_PROP_TAG(Model);
NEW_PROP_TAG(Problem);
NEW_PROP_TAG(ThreadManager);
NEW_PROP_TAG(NewtonMethod);
NEW_PROP_TAG(SolutionVector);
NEW_PROP_TAG(GlobalEqVector);
NEW_PROP_TAG(VtkOutputFormat);
//! Specifies the type of a solution for a single degee of freedom
NEW_PROP_TAG(PrimaryVariables);
//! Specifies whether the problem to be simulated exhibits contraint degrees of freedom
NEW_PROP_TAG(EnableConstraints);
//! Specifies the type of objects which specify constraints for a single degee of freedom
NEW_PROP_TAG(Constraints);
//! Vector containing a quantity of for equation for a single degee of freedom
NEW_PROP_TAG(EqVector);
//! The class which linearizes the non-linear system of equations
NEW_PROP_TAG(Linearizer);
//! Specifies the type of a global Jacobian matrix
NEW_PROP_TAG(SparseMatrixAdapter);
//! Specifies the type of the linear solver to be used
NEW_PROP_TAG(LinearSolverBackend);
//! Specifies whether the Newton method should print messages or not
NEW_PROP_TAG(NewtonVerbose);
//! Specifies the type of the class which writes out the Newton convergence
NEW_PROP_TAG(NewtonConvergenceWriter);
//! Specifies whether the convergence rate and the global residual
//! gets written out to disk for every Newton iteration
NEW_PROP_TAG(NewtonWriteConvergence);
//! Specifies whether the convergence rate and the global residual
//! gets written out to disk for every Newton iteration
NEW_PROP_TAG(ConvergenceWriter);
/*!
* \brief The value for the error below which convergence is declared
*
* This value can (and for the porous media models will) be changed to account for grid
* scaling and other effects.
*/
NEW_PROP_TAG(NewtonTolerance);
//! The maximum error which may occur in a simulation before the
//! Newton method for the time step is aborted
NEW_PROP_TAG(NewtonMaxError);
/*!
* \brief The number of iterations at which the Newton method
* should aim at.
*
* This is used to control the time-step size. The heuristic used
* is to scale the last time-step size by the deviation of the
* number of iterations used from the target steps.
*/
NEW_PROP_TAG(NewtonTargetIterations);
//! Number of maximum iterations for the Newton method.
NEW_PROP_TAG(NewtonMaxIterations);
#if HAVE_DUNE_FEM
NEW_PROP_TAG(GridPart);
#endif
NEW_PROP_TAG(LocalLinearizer);
NEW_PROP_TAG(Evaluation);
NEW_PROP_TAG(NumericDifferenceMethod);
NEW_PROP_TAG(BaseEpsilon);
NEW_PROP_TAG(LocalResidual);
NEW_PROP_TAG(ElementContext);
NEW_PROP_TAG(NumPhases);
NEW_PROP_TAG(NumComponents);
NEW_PROP_TAG(NumEq);
NEW_PROP_TAG(FluidSystem);
NEW_PROP_TAG(DiscBaseOutputModule);
// create new type tag for the VTK primary variables output
NEW_PROP_TAG(EnableVtkOutput);
// create the property tags needed for the primary variables module
NEW_PROP_TAG(VtkWritePrimaryVars);
NEW_PROP_TAG(VtkWriteProcessRank);
NEW_PROP_TAG(VtkWriteDofIndex);
NEW_PROP_TAG(VtkWriteExtrusionFactor);
NEW_PROP_TAG(VtkWritePressures);
NEW_PROP_TAG(VtkWriteDensities);
NEW_PROP_TAG(VtkWriteSaturations);
NEW_PROP_TAG(VtkWriteMobilities);
NEW_PROP_TAG(VtkWriteRelativePermeabilities);
NEW_PROP_TAG(VtkWriteViscosities);
NEW_PROP_TAG(VtkWriteAverageMolarMasses);
NEW_PROP_TAG(VtkWritePorosity);
NEW_PROP_TAG(VtkWriteIntrinsicPermeabilities);
NEW_PROP_TAG(VtkWritePotentialGradients);
NEW_PROP_TAG(VtkWriteFilterVelocities);
NEW_PROP_TAG(VtkWriteTemperature);
NEW_PROP_TAG(VtkWriteSolidInternalEnergy);
NEW_PROP_TAG(VtkWriteThermalConductivity);
NEW_PROP_TAG(VtkWriteInternalEnergies);
NEW_PROP_TAG(VtkWriteEnthalpies);
NEW_PROP_TAG(IntensiveQuantities);
NEW_PROP_TAG(BoundaryContext);
NEW_PROP_TAG(BoundaryRateVector);
NEW_PROP_TAG(CellsX);
NEW_PROP_TAG(CellsY);
NEW_PROP_TAG(CellsZ);
NEW_PROP_TAG(ContinueOnConvergenceError);
NEW_PROP_TAG(DiscExtensiveQuantities);
NEW_PROP_TAG(DiscIntensiveQuantities);
NEW_PROP_TAG(DiscLocalResidual);
NEW_PROP_TAG(Discretization);
NEW_PROP_TAG(DofMapper);
NEW_PROP_TAG(DomainSizeX);
NEW_PROP_TAG(DomainSizeY);
NEW_PROP_TAG(DomainSizeZ);
NEW_PROP_TAG(ElementMapper);
NEW_PROP_TAG(EnableAsyncVtkOutput);
NEW_PROP_TAG(EnableEnergy);
NEW_PROP_TAG(EnableGravity);
NEW_PROP_TAG(EnableGridAdaptation);
NEW_PROP_TAG(EnableStorageCache);
NEW_PROP_TAG(ExtensiveQuantities);
NEW_PROP_TAG(ExtensiveStorageTerm);
NEW_PROP_TAG(Fluid);
NEW_PROP_TAG(FluxModule);
NEW_PROP_TAG(GradientCalculator);
NEW_PROP_TAG(GridCommHandleFactory);
NEW_PROP_TAG(Indices);
NEW_PROP_TAG(LinearizeNonLocalElements);
NEW_PROP_TAG(MaterialLaw);
NEW_PROP_TAG(MaterialLawParams);
NEW_PROP_TAG(MaxTimeStepDivisions);
NEW_PROP_TAG(MaxTimeStepSize);
NEW_PROP_TAG(MinTimeStepSize);
NEW_PROP_TAG(OutputDir);
NEW_PROP_TAG(RateVector);
NEW_PROP_TAG(SolidEnergyLaw);
NEW_PROP_TAG(Stencil);
NEW_PROP_TAG(ThermalConductionLaw);
NEW_PROP_TAG(ThreadsPerProcess);
NEW_PROP_TAG(TimeDiscHistorySize);
NEW_PROP_TAG(UseLinearizationLock);
NEW_PROP_TAG(UseP1FiniteElementGradients);
NEW_PROP_TAG(UseVolumetricResidual);
NEW_PROP_TAG(VertexMapper);
NEW_PROP_TAG(SolidEnergyLawParams);
NEW_PROP_TAG(ThermalConductionLawParams);
NEW_PROP_TAG(BaseProblem);
NEW_PROP_TAG(ConstraintsContext);
NEW_PROP_TAG(ElementEqVector);
NEW_PROP_TAG(EnableExperiments);
NEW_PROP_TAG(EnableIntensiveQuantityCache);
NEW_PROP_TAG(EnableThermodynamicHints);
NEW_PROP_TAG(NonwettingPhase);
NEW_PROP_TAG(SpatialDiscretizationSplice);
NEW_PROP_TAG(WettingPhase);
NEW_PROP_TAG(OverlappingMatrix);
NEW_PROP_TAG(OverlappingVector);
NEW_PROP_TAG(PreconditionerOrder);
NEW_PROP_TAG(PreconditionerRelaxation);
NEW_PROP_TAG(AmgCoarsenTarget);
NEW_PROP_TAG(BorderListCreator);
NEW_PROP_TAG(Overlap);
NEW_PROP_TAG(OverlappingScalarProduct);
NEW_PROP_TAG(OverlappingLinearOperator);
//! the preconditioner used by the linear solver
NEW_PROP_TAG(PreconditionerWrapper);
//! The floating point type used internally by the linear solver
NEW_PROP_TAG(LinearSolverScalar);
/*!
* \brief The size of the algebraic overlap of the linear solver.
*
* Algebraic overlaps can be thought as being the same as the overlap
* of a grid, but it is only existant for the linear system of
* equations.
*/
NEW_PROP_TAG(LinearSolverOverlapSize);
/*!
* \brief Maximum accepted error of the solution of the linear solver.
*/
NEW_PROP_TAG(LinearSolverTolerance);
/*!
* \brief Maximum accepted error of the norm of the residual.
*/
NEW_PROP_TAG(LinearSolverAbsTolerance);
/*!
* \brief Specifies the verbosity of the linear solver
*
* By default it is 0, i.e. it doesn't print anything. Setting this
* property to 1 prints aggregated convergence rates, 2 prints the
* convergence rate of every iteration of the scheme.
*/
NEW_PROP_TAG(LinearSolverVerbosity);
//! Maximum number of iterations eyecuted by the linear solver
NEW_PROP_TAG(LinearSolverMaxIterations);
NEW_PROP_TAG(LinearSolverMaxError);
NEW_PROP_TAG(LinearSolverSplice);
NEW_PROP_TAG(LocalLinearizerSplice);
//! The discretization specific part of he implementing the Newton algorithm
NEW_PROP_TAG(DiscNewtonMethod);
//! Property which tells the Vanguard how often the grid should be refined
//! after creation.
NEW_PROP_TAG(GridGlobalRefinements);
@@ -116,6 +359,8 @@ NEW_PROP_TAG(RestartTime);
//! The name of the file with a number of forced time step lengths
NEW_PROP_TAG(PredeterminedTimeStepsFile);
NEW_PROP_TAG(ParameterMetaData);
///////////////////////////////////
// Values for the properties
///////////////////////////////////
@@ -138,8 +383,6 @@ SET_PROP(NumericModel, ParameterTree)
//! use the global group as default for the model's parameter group
SET_STRING_PROP(NumericModel, ModelParameterGroup, "");
//! Use the DgfVanguard by default
SET_TYPE_PROP(NumericModel, Vanguard, Opm::DgfVanguard<TypeTag>);
//! Set a value for the GridFile property
SET_STRING_PROP(NumericModel, GridFile, "");

View File

@@ -32,7 +32,7 @@
#ifndef EWOMS_PARAMETER_SYSTEM_HH
#define EWOMS_PARAMETER_SYSTEM_HH
#include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/basicproperties.hh>
#include <opm/material/common/Exceptions.hpp>
#include <opm/material/common/Unused.hpp>
@@ -74,8 +74,8 @@
* \endcode
*/
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description) \
::Opm::Parameters::registerParam<TypeTag, ParamType, PTAG(ParamName)>( \
#ParamName, #ParamName, Description)
::Opm::Parameters::registerParam<TypeTag, ParamType>( \
#ParamName, #ParamName, GET_PROP_VALUE(TypeTag, ParamName), Description)
/*!
* \ingroup Parameter
@@ -85,7 +85,7 @@
* This allows to deal with unused parameters
*/
#define EWOMS_HIDE_PARAM(TypeTag, ParamName) \
::Opm::Parameters::hideParam<TypeTag, PTAG(ParamName)>(#ParamName)
::Opm::Parameters::hideParam<TypeTag, PTAG_(ParamName)>(#ParamName)
/*!
* \ingroup Parameter
@@ -115,14 +115,14 @@
* \endcode
*/
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName) \
(::Opm::Parameters::get<TypeTag, ParamType, PTAG(ParamName)>(#ParamName, \
#ParamName))
(::Opm::Parameters::get<TypeTag, ParamType>(#ParamName, \
GET_PROP_VALUE(TypeTag, ParamName)))
//!\cond SKIP_THIS
#define EWOMS_GET_PARAM_(TypeTag, ParamType, ParamName) \
(::Opm::Parameters::get<TypeTag, ParamType, PTAG(ParamName)>( \
#ParamName, #ParamName, \
/*errorIfNotRegistered=*/false))
(::Opm::Parameters::get<TypeTag, ParamType>(#ParamName, \
GET_PROP_VALUE(TypeTag, ParamName), \
/*errorIfNotRegistered=*/false))
/*!
* \ingroup Parameter
@@ -148,7 +148,7 @@
* If the parameter in question has not been registered, this throws an exception.
*/
#define EWOMS_PARAM_IS_SET(TypeTag, ParamType, ParamName) \
(::Opm::Parameters::isSet<TypeTag, ParamType, PTAG(ParamName)>(#ParamName, \
(::Opm::Parameters::isSet<TypeTag, ParamType, PTAG_(ParamName)>(#ParamName, \
#ParamName))
namespace Opm {
@@ -180,6 +180,10 @@ template <class TypeTag, class ParamType, class PropTag>
const ParamType get(const char *propTagName,
const char *paramName,
bool errorIfNotRegistered = true);
template <class TypeTag, class ParamType>
const ParamType get(const char *paramName,
const ParamType& defaultValue,
bool errorIfNotRegistered = true);
class ParamRegFinalizerBase_
{
@@ -189,12 +193,13 @@ public:
virtual void retrieve() = 0;
};
template <class TypeTag, class ParamType, class PropTag>
template <class TypeTag, class ParamType>
class ParamRegFinalizer_ : public ParamRegFinalizerBase_
{
public:
ParamRegFinalizer_(const std::string& paramName)
ParamRegFinalizer_(const std::string& paramName, const ParamType& defaultValue)
: paramName_(paramName)
, defaultValue_(defaultValue)
{}
virtual void retrieve() override
@@ -202,13 +207,14 @@ public:
// retrieve the parameter once to make sure that its value does
// not contain a syntax error.
ParamType __attribute__((unused)) dummy =
get<TypeTag, ParamType, PropTag>(/*propTagName=*/paramName_.data(),
paramName_.data(),
/*errorIfNotRegistered=*/true);
get<TypeTag, ParamType>(paramName_.data(),
defaultValue_,
/*errorIfNotRegistered=*/true);
}
private:
std::string paramName_;
ParamType defaultValue_;
};
} // namespace Parameters
@@ -218,9 +224,8 @@ BEGIN_PROPERTIES
// type tag which is supposed to spliced in or inherited from if the
// parameter system is to be used
NEW_TYPE_TAG(ParameterSystem);
//NEW_TYPE_TAG(ParameterSystem);
NEW_PROP_TAG(ParameterMetaData);
//! Set the ParameterMetaData property
@@ -943,15 +948,21 @@ class Param
public:
template <class ParamType, class PropTag>
static const ParamType get(const char *propTagName,
const char *paramName,
bool errorIfNotRegistered = true)
static ParamType get(const char *propTagName,
const char *paramName,
bool errorIfNotRegistered = true)
{
return retrieve_<ParamType, PropTag>(propTagName,
paramName,
errorIfNotRegistered);
return retrieve_<ParamType>(paramName, getPropValue<TypeTag, PropTag>(), errorIfNotRegistered);
}
template <class ParamType>
static ParamType get(const char *paramName,
const ParamType& defaultValue,
bool errorIfNotRegistered = true)
{
return retrieve_<ParamType>(paramName, defaultValue, errorIfNotRegistered);
}
static void clear()
{
ParamsMeta::clear();
@@ -1035,10 +1046,10 @@ private:
}
}
template <class ParamType, class PropTag>
static const ParamType retrieve_(const char OPM_OPTIM_UNUSED *propTagName,
const char *paramName,
bool errorIfNotRegistered = true)
template <class ParamType>
static ParamType retrieve_(const char *paramName,
const ParamType& defaultValue,
bool errorIfNotRegistered = true)
{
#ifndef NDEBUG
// make sure that the parameter is used consistently. since
@@ -1066,8 +1077,7 @@ private:
std::string canonicalName(paramName);
// retrieve actual parameter from the parameter tree
const ParamType defaultValue = GET_PROP_VALUE_(TypeTag, PropTag);
return ParamsMeta::tree().template get<ParamType>(canonicalName, defaultValue );
return ParamsMeta::tree().template get<ParamType>(canonicalName, defaultValue);
}
};
@@ -1079,6 +1089,12 @@ const ParamType get(const char *propTagName, const char *paramName, bool errorIf
errorIfNotRegistered);
}
template <class TypeTag, class ParamType>
const ParamType get(const char *paramName, const ParamType& defaultValue, bool errorIfNotRegistered)
{
return Param<TypeTag>::template get<ParamType>(paramName, defaultValue, errorIfNotRegistered);
}
template <class TypeTag, class Container>
void getLists(Container& usedParams, Container& unusedParams)
{
@@ -1121,8 +1137,8 @@ bool isSet(const char *propTagName, const char *paramName, bool errorIfNotRegist
errorIfNotRegistered);
}
template <class TypeTag, class ParamType, class PropTag>
void registerParam(const char *paramName, const char *propertyName, const char *usageString)
template <class TypeTag, class ParamType>
void registerParam(const char *paramName, const char *propertyName, const ParamType& defaultValue, const char *usageString)
{
typedef typename GET_PROP(TypeTag, ParameterMetaData) ParamsMeta;
if (!ParamsMeta::registrationOpen())
@@ -1130,7 +1146,7 @@ void registerParam(const char *paramName, const char *propertyName, const char *
"the parameter '"+std::string(paramName)+"' was registered.");
ParamsMeta::registrationFinalizers().emplace_back(
new ParamRegFinalizer_<TypeTag, ParamType, PropTag>(paramName));
new ParamRegFinalizer_<TypeTag, ParamType>(paramName, defaultValue));
ParamInfo paramInfo;
paramInfo.paramName = paramName;
@@ -1140,7 +1156,7 @@ void registerParam(const char *paramName, const char *propertyName, const char *
paramInfo.propertyName = propertyName;
paramInfo.usageString = usageString;
std::ostringstream oss;
oss << GET_PROP_VALUE_(TypeTag, PropTag);
oss << defaultValue;
paramInfo.compileTimeValue = oss.str();
paramInfo.isHidden = false;
if (ParamsMeta::registry().find(paramName) != ParamsMeta::registry().end()) {
@@ -1160,7 +1176,7 @@ void hideParam(const char *paramName)
{
// make sure that a property with the parameter name exists. we cannot check if a
// parameter exists at compile time, so this will only be caught at runtime
static const auto defaultValue OPM_UNUSED = GET_PROP_VALUE_(TypeTag, PropTag);
static const auto defaultValue OPM_UNUSED = getPropValue<TypeTag, PropTag>;
typedef typename GET_PROP(TypeTag, ParameterMetaData) ParamsMeta;
if (!ParamsMeta::registrationOpen())

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,392 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \ingroup Properties
* \brief Provides the magic behind the DuMuX property system.
*
* Properties allow to associate arbitrary data types to
* identifiers. A property is always defined on a pair (TypeTag,
* PropertyTag) where TypeTag is the identifier for the object the
* property is defined for and PropertyTag is an unique identifier of
* the property.
*
* Type tags are hierarchic and inherit properties defined on their
* ancesters. At each level, properties defined on lower levels can be
* overwritten or even made undefined. It is also possible to define
* defaults for properties if it makes sense.
*
* Properties may make use other properties for the respective type
* tag and these properties can also be defined on an arbitrary level
* of the hierarchy.
*/
#ifndef OPM_PROPERTY_SYSTEM_MACROS_HH
#define OPM_PROPERTY_SYSTEM_MACROS_HH
#warning "Property macros are deprecated and will be removed after release 3.2. \
If you are not using property macros you can disable this warning by \
setting OPM_ENABLE_OLD_PROPERTY_MACROS to 0 (false) when configuring DuMux. \
OPM_ENABLE_OLD_PROPERTY_MACROS defaults to 1 (true) until release 3.1. \
After release 3.1 it will default to 0 (false) so you will have to manually \
enable property macros in order to use them."
#include <opm/models/utils/propertysystem.hh>
namespace Opm {
namespace Properties {
namespace TTag {}
/*!
* \brief Makes a type out of a type tag name
*/
#define TTAG(TypeTagName) ::Opm::Properties::TTag::TypeTagName
/*!
* \brief Makes a type out of a property tag name
*/
//#define PTAG(PropTagName) PropTagName
/*!
* \brief Makes a type out of a property tag name
*/
#define PTAG_(PropTagName) ::Opm::Properties::PropTagName
// in the old property system the order in inherit_from was the other way around
// this flips the order of a tuple to restore old behaviour when using the macro.
// when you are using non-macro version make sure to flip the order.
template<class Tuple, class IndexSequence>
struct ReverseTupleImpl;
template<class Tuple, size_t... I>
struct ReverseTupleImpl<Tuple, std::index_sequence<I...>>
{
using type = std::tuple<std::tuple_element_t<sizeof...(I) - 1 - I, Tuple>...>;
};
// revert tuple argument order
template<class Tuple>
using ReverseTuple = typename ReverseTupleImpl<Tuple, std::make_index_sequence<std::tuple_size<Tuple>::value>>::type;
// a temporary hack to make the macro still work, we set using InheritsFrom = void,
// which gets picked up by the new property as non inheritance, this can be removed
// once all macros are gone
namespace Detail {
template<class TypeTagTuple>
struct GetTypeTagInheritance;
template<class OneTypeTag>
struct GetTypeTagInheritance<std::tuple<OneTypeTag>>
{
using type = void;
};
template<class FirstTypeTag, class ...OtherTypeTags>
struct GetTypeTagInheritance<std::tuple<FirstTypeTag, OtherTypeTags...>>
{
// reverse order to restore old behaviour
using type = ReverseTuple<std::tuple<OtherTypeTags...>>;
};
} // end namespace Detail
/*!
* \ingroup Properties
* \brief Define a new type tag.
*
* A type tag can inherit the properties defined on up to five parent
* type tags. Examples:
*
* \code
* // The type tag doesn't inherit any properties from other type tags
* NEW_TYPE_TAG(FooTypeTag);
*
* // BarTypeTag inherits all properties from FooTypeTag
* NEW_TYPE_TAG(BarTypeTag, INHERITS_FROM(FooTypeTag));
*
* // FooBarTypeTag inherits the properties of FooTypeTag as well as
* // those of BarTypeTag. Properties defined on BarTypeTag have
* // preceedence over those defined for FooTypeTag:
* NEW_TYPE_TAG(FooBarTypeTag, INHERITS_FROM(FooTypeTag, BarTypeTag));
* \endcode
*/
#define OPM_GET_HEAD_(Arg1, ...) Arg1
#define NEW_TYPE_TAG(...) \
namespace TTag { \
struct OPM_GET_HEAD_(__VA_ARGS__) \
{ using InheritsFrom = Detail::GetTypeTagInheritance<std::tuple<__VA_ARGS__>>::type; }; \
} extern int semicolonHack_
/*!
* \ingroup Properties
* \brief Syntactic sugar for NEW_TYPE_TAG.
*
* See the documentation for NEW_TYPE_TAG.
*/
#define INHERITS_FROM(...) __VA_ARGS__
/*!
* \ingroup Properties
* \brief Define a property tag.
*
* A property tag is the unique identifier for a property. It may only
* be declared once in your program. There is also no hierarchy of
* property tags as for type tags.
*
* Examples:
*
* \code
* NEW_PROP_TAG(blubbPropTag);
* NEW_PROP_TAG(blabbPropTag);
* \endcode
*/
#define NEW_PROP_TAG(PTagName) \
template<class TypeTag, class MyTypeTag> \
struct PTagName { using type = UndefinedProperty; }; \
extern int semicolonHack_
/*!
* \ingroup Properties
* \brief Set a property for a specific type tag.
*
* After this macro, you must to specify a complete body of a class
* template, including the trailing semicolon. If you need to retrieve
* another property within the class body, you can use TypeTag as the
* argument for the type tag for the GET_PROP macro.
*
* Example:
*
* \code
* SET_PROP(FooTypeTag, blubbPropTag)
* {
* static int value = 10;
* static int calculate(int arg)
* { calculateInternal_(arg); }
*
* private:
* // retrieve the blabbProp property for the real TypeTag the
* // property is defined on. Note that blabbProb does not need to
* // be defined on FooTypeTag, but can also be defined for some
* // derived type tag.
* using blabb = typename GET_PROP(TypeTag, blabbProp);
*
* static int calculateInternal_(int arg)
* { return arg * blabb::value; };
* \endcode
* };
*/
#define SET_PROP(EffTypeTagName, PropTagName) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)>
/*!
* \ingroup Properties
* \brief Set a property to a simple constant integer value.
*
* The constant can be accessed by the 'value' attribute.
*/
#define SET_INT_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
{ \
using type = int; \
static constexpr int value = __VA_ARGS__; \
}
/*!
* \ingroup Properties
* \brief Set a property to a simple constant boolean value.
*
* The constant can be accessed by the 'value' attribute.
*/
#define SET_BOOL_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
{ \
using type = bool; \
static constexpr bool value = __VA_ARGS__; \
}
/*!
* \ingroup Properties
* \brief Set a property which defines a type.
*
* The type can be accessed by the 'type' attribute.
*/
#define SET_TYPE_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
{ \
using type = __VA_ARGS__; \
}
/*!
* \ingroup Properties
* \brief Set a property to a simple constant scalar value.
*
* The constant can be accessed by the 'value' attribute. In order to
* use this macro, the property tag "Scalar" needs to be defined for
* the real type tag.
*/
#define SET_SCALAR_PROP(EffTypeTagName, PropTagName, ...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
{ \
using Scalar = Opm::GetPropType<TypeTag, Scalar>; \
public: \
using type = Scalar; \
static const Scalar value; \
}; \
template <class TypeTag> \
const typename PropTagName<TypeTag, TTAG(EffTypeTagName)>::type \
PropTagName<TypeTag, TTAG(EffTypeTagName)>::value(__VA_ARGS__)
/*!
* \ingroup Properties
* \brief Set a property to a simple constant string value.
*
* The constant can be accessed by the 'value' attribute and is of
* type std::string.
*/
#define SET_STRING_PROP(EffTypeTagName, PropTagName, ...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
{ \
public: \
using type = std::string; \
static const std::string value; \
}; \
template <class TypeTag> \
const typename PropTagName<TypeTag, TTAG(EffTypeTagName)>::type \
PropTagName<TypeTag, TTAG(EffTypeTagName)>::value(__VA_ARGS__)
// getters
#define GET_PROP(TypeTag, PropTagName) ::Opm::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type
#define GET_PROP_VALUE(TypeTag, PropTagName) ::Opm::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type::value
#define GET_PROP_TYPE(TypeTag, PropTagName) ::Opm::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type::type
/*!
* \ingroup Properties
* \brief Define splices for a given type tag.
*
* Splices can be seen as children which can be overridden lower in
* the hierarchy. It can thus be seen as a "deferred inheritance"
* mechanism. Example:
*
* \code
* // First, define type tags for two different linear solvers:
* // BiCGStab and SuperLU. The first needs the "MaxIterations"
* // property, the second defines the "UsePivoting" property.
* NEW_TYPE_TAG(BiCGStabSolver);
* NEW_PROP_TAG(MaxIterations);
* SET_INT_PROP(BiCGStabSolver, MaxIterations, 100);
*
* NEW_TYPE_TAG(SuperLUSolver);
* NEW_PROP_TAG(UsePivoting);
* SET_BOOL_PROP(SuperLUSolver, UsePivoting, true);
*
* // The model type tag defines the splice 'LinearSolver' and sets it
* // to the 'BiCGStabSolver' type tag.
* NEW_TYPE_TAG(ModelTypeTag);
* NEW_PROP_TAG(LinearSolver);
* SET_SPLICES(ModelTypeTag, LinearSolver);
* SET_TAG_PROP(ModelTypeTag, LinearSolver, BiCGStabSolver);
*
* // The problem type tag is derived from the model type tag, but uses
* // the SuperLU solver. Since this is done using a splice, all properties
* // defined for the "SuperLUSolver" are inherited and the ones for the
* // BiCGStabSolver type tag are undefined
* NEW_TYPE_TAG(ProblemTypeTag, INHERITS_FROM(ModelTypeTag));
* SET_TAG_PROP(ProblemTypeTag, LinearSolver, SuperLUSolver);
* \endcode
*/
// template class to revert the order or a std::tuple's arguments. This is required to
// make the properties of children defined on the right overwrite the properties of the
// children on the left. See https://sydius.me/2011/07/reverse-tuple-in-c/
template<typename... Args>
class RevertedTuple
{
private:
template<unsigned int N, typename... All>
struct RevertedTupleOuter
{
template<typename Head, typename... Tail>
struct RevertedTupleInner: RevertedTupleOuter<N-1, Head, All...>::template RevertedTupleInner<Tail...> { };
};
template<typename... All>
struct RevertedTupleOuter<0, All...>
{
template<typename... Tail>
struct RevertedTupleInner {
typedef std::tuple<All...> type;
};
};
public:
typedef typename RevertedTupleOuter<sizeof...(Args)>::template RevertedTupleInner<Args...>::type type;
};
namespace PTag {
// this class needs to be located in the PTag namespace for reasons
// you don't really want to know...
template <class TypeTag>
struct Splices
{
typedef typename std::tuple<> tuple;
};
} // namespace PTag
#define SET_SPLICES(TypeTagName, ...) \
namespace PTag { \
template<> \
struct Splices<TTAG(TypeTagName)> \
{ \
typedef RevertedTuple<__VA_ARGS__>::type tuple; \
}; \
SPLICE_INFO_(TypeTagName, __VA_ARGS__) \
} \
extern int semicolonHack_
#define SET_PROP_(EffTypeTagName, PropKind, PropTagName, ...) \
template <class TypeTag> \
struct PropTagName<TypeTag, TTAG(EffTypeTagName)>
/*!
* \ingroup Properties
* \brief Define a property containing a type tag.
*
* This is convenient for splices.
*/
#define SET_TAG_PROP(EffTypeTagName, PropTagName, ValueTypeTagName) \
SET_PROP_(EffTypeTagName, \
/*kind=*/"tag ", \
PropTagName, \
/*value=*/TTAG(ValueTypeTagName)) \
{ \
typedef TTAG(ValueTypeTagName) type; \
}
} // namespace Properties
} // namespace Opm
#endif // OPM_PROPERTY_SYSTEM_HH

View File

@@ -48,15 +48,6 @@
BEGIN_PROPERTIES
NEW_PROP_TAG(Scalar);
NEW_PROP_TAG(Vanguard);
NEW_PROP_TAG(GridView);
NEW_PROP_TAG(Model);
NEW_PROP_TAG(Problem);
NEW_PROP_TAG(EndTime);
NEW_PROP_TAG(RestartTime);
NEW_PROP_TAG(InitialTimeStepSize);
NEW_PROP_TAG(PredeterminedTimeStepsFile);
END_PROPERTIES
@@ -984,6 +975,11 @@ private:
bool finished_;
bool verbose_;
};
namespace Properties {
SET_TYPE_PROP(NumericModel, Simulator, Opm::Simulator<TypeTag>);
}
} // namespace Opm
#endif

View File

@@ -71,13 +71,6 @@
BEGIN_PROPERTIES
// forward declaration of property tags
NEW_PROP_TAG(Scalar);
NEW_PROP_TAG(Simulator);
NEW_PROP_TAG(ThreadManager);
NEW_PROP_TAG(PrintProperties);
NEW_PROP_TAG(PrintParameters);
NEW_PROP_TAG(ParameterFile);
NEW_PROP_TAG(Problem);
END_PROPERTIES