diff --git a/dune/stuff/function.hh b/dune/stuff/function.hh index 004e220689ad1496328d3b1092f283be79533e47..6357b393105e55533b8fc225e87e49f51e02d46c 100644 --- a/dune/stuff/function.hh +++ b/dune/stuff/function.hh @@ -15,81 +15,80 @@ #include <dune/common/exceptions.hh> #include <dune/stuff/common/color.hh> -#include <dune/stuff/aliases.hh> namespace Dune { namespace Stuff { -namespace Function { - -std::vector<std::string> types() -{ - return { - "function.checkerboard", "function.expression", "function.separable.default", "function.separable.checkerboard"}; -} // std::vector< std::string > types() - // some forwards, includes are below template <class D, int d, class R, int r> -class Interface; +class FunctionInterface; template <class D, int d, class R, int r> -class Checkerboard; +class FunctionCheckerboard; template <class D, int d, class R, int r> -class Expression; +class FunctionExpression; template <class D, int d, class R, int r> -class SeparableDefault; +class FunctionAffineParametricDefault; template <class D, int d, class R, int r> -class SeparableCheckerboard; +class FunctionAffineParametricCheckerboard; + + +std::vector<std::string> availableFunctions() +{ + return {"function.expression", + "function.checkerboard", + "function.affineparametric.default", + "function.affineparametric.checkerboard"}; +} // std::vector< std::string > types() template <class D, int d, class R, int r> -Dune::ParameterTree createSampleDescription(const std::string type) +Dune::ParameterTree createSampleFunctionDescription(const std::string type) { if (type == "function.checkerboard") { - typedef Stuff::Function::Checkerboard<D, d, R, r> FunctionType; + typedef FunctionCheckerboard<D, d, R, r> FunctionType; return FunctionType::createSampleDescription(); } else if (type == "function.expression") { - typedef Stuff::Function::Expression<D, d, R, r> FunctionType; + typedef FunctionExpression<D, d, R, r> FunctionType; return FunctionType::createSampleDescription(); - } else if (type == "function.separable.default") { - typedef Stuff::Function::SeparableDefault<D, d, R, r> FunctionType; + } else if (type == "function.affineparametric.default") { + typedef FunctionAffineParametricDefault<D, d, R, r> FunctionType; return FunctionType::createSampleDescription(); - } else if (type == "function.separable.checkerboard") { - typedef Stuff::Function::SeparableCheckerboard<D, d, R, r> FunctionType; + } else if (type == "function.affineparametric.checkerboard") { + typedef FunctionAffineParametricCheckerboard<D, d, R, r> FunctionType; return FunctionType::createSampleDescription(); } else DUNE_THROW(Dune::RangeError, "\n" << Dune::Stuff::Common::colorStringRed("ERROR:") << " unknown function '" << type << "' requested!"); -} // ... create(...) +} // ... createSampleFunctionDescription(...) template <class D, int d, class R, int r> -Interface<D, d, R, r>* create(const std::string type, const Dune::ParameterTree description = Dune::ParameterTree()) +FunctionInterface<D, d, R, r>* createFunction(const std::string type, + const Dune::ParameterTree description = Dune::ParameterTree()) { - using namespace DSFu; if (type == "function.checkerboard") { - return Checkerboard<D, d, R, r>::createFromDescription(description); + return FunctionCheckerboard<D, d, R, r>::create(description); } else if (type == "function.expression") { - return Expression<D, d, R, r>::createFromDescription(description); - } else if (type == "function.separable.default") { - return SeparableDefault<D, d, R, r>::createFromDescription(description); - } else if (type == "function.separable.checkerboard") { - return SeparableCheckerboard<D, d, R, r>::createFromDescription(description); + return FunctionExpression<D, d, R, r>::create(description); + } else if (type == "function.affineparametric.default") { + return FunctionAffineParametricDefault<D, d, R, r>::create(description); + } else if (type == "function.affineparametric.checkerboard") { + return FunctionAffineParametricCheckerboard<D, d, R, r>::create(description); } else DUNE_THROW(Dune::RangeError, "\n" << Dune::Stuff::Common::colorStringRed("ERROR:") << " unknown function '" << type << "' requested!"); -} // ... create(...) +} // ... createFunction(...) -} // namespace Function } // namespace Stuff } // namespace Dune #include "function/interface.hh" #include "function/checkerboard.hh" #include "function/expression.hh" -#include "function/parametric/separable/default.hh" -#include "function/parametric/separable/checkerboard.hh" +#include "function/affineparametric/default.hh" +#include "function/affineparametric/checkerboard.hh" #endif // DUNE_STUFF_FUNCTION_HH diff --git a/dune/stuff/function/checkerboard.hh b/dune/stuff/function/checkerboard.hh index 4cc754bba1fccd32001145606f007ab13de482bc..52c5d7871c63363d69a8ae0584e51adc03f8497f 100644 --- a/dune/stuff/function/checkerboard.hh +++ b/dune/stuff/function/checkerboard.hh @@ -12,20 +12,20 @@ namespace Dune { namespace Stuff { -namespace Function { +// forward, to allow for specialization template <class DomainFieldImp, int domainDim, class RangeFieldImp, int rangeDim> -class Checkerboard; +class FunctionCheckerboard; template <class DomainFieldImp, int domainDim, class RangeFieldImp> -class Checkerboard<DomainFieldImp, domainDim, RangeFieldImp, 1> - : public Interface<DomainFieldImp, domainDim, RangeFieldImp, 1> +class FunctionCheckerboard<DomainFieldImp, domainDim, RangeFieldImp, 1> + : public FunctionInterface<DomainFieldImp, domainDim, RangeFieldImp, 1> { public: - typedef Checkerboard<DomainFieldImp, domainDim, RangeFieldImp, 1> ThisType; - typedef Interface<DomainFieldImp, domainDim, RangeFieldImp, 1> BaseType; + typedef FunctionCheckerboard<DomainFieldImp, domainDim, RangeFieldImp, 1> ThisType; + typedef FunctionInterface<DomainFieldImp, domainDim, RangeFieldImp, 1> BaseType; typedef typename BaseType::DomainFieldType DomainFieldType; static const int dimDomain = BaseType::dimDomain; @@ -36,11 +36,12 @@ public: static const std::string id() { - return "function.checkerboard"; + return BaseType::id() + ".checkerboard"; } - Checkerboard(const DomainType _lowerLeft, const DomainType _upperRight, const std::vector<size_t> _numElements, - const std::vector<RangeFieldType> _values, const std::string _name = id()) + FunctionCheckerboard(const DomainType _lowerLeft, const DomainType _upperRight, + const std::vector<size_t> _numElements, const std::vector<RangeFieldType> _values, + const std::string _name = id()) : lowerLeft_(_lowerLeft) , upperRight_(_upperRight) , numElements_(_numElements) @@ -60,7 +61,7 @@ public: DUNE_THROW(Dune::InvalidStateException, "\n" << Dune::Stuff::Common::colorStringRed("ERROR:") << " please provide at least as many '_values' as subdomains given by '_numElements'!"); - } + } // FunctionCheckerboard(...) static Dune::ParameterTree createSampleDescription(const std::string subName = "") { @@ -77,9 +78,9 @@ public: extendedDescription.add(description, subName); return extendedDescription; } - } + } // ... createSampleDescription(...) - static ThisType* createFromDescription(const DSC::ExtendedParameterTree description) + static ThisType* create(const DSC::ExtendedParameterTree description) { // get data const std::vector<DomainFieldType> lowerLefts = description.getVector("lowerLeft", DomainFieldType(0), dimDomain); @@ -98,7 +99,7 @@ public: } // create and return return new ThisType(lowerLeft, upperRight, numElements, values); - } // static ThisType createFromParamTree(const Dune::ParameterTree paramTree) + } // ... create(...) const DomainType& lowerLeft() const @@ -157,9 +158,8 @@ private: std::vector<size_t> numElements_; std::vector<RangeFieldType> values_; std::string name_; -}; // class Checkerboard +}; // class FunctionCheckerboard -} // namespace Function } // namespace Stuff } // namespace Dune diff --git a/dune/stuff/function/expression.hh b/dune/stuff/function/expression.hh index c273af533b3520f791e79259ade0d6c1a976f980..46b5e92d22924cb8522845aef5d7e773fc086117 100644 --- a/dune/stuff/function/expression.hh +++ b/dune/stuff/function/expression.hh @@ -29,22 +29,23 @@ namespace Dune { namespace Stuff { -namespace Function { + template <class DomainFieldImp, int domainDim, class RangeFieldImp, int rangeDim> -class Expression : public ExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> +class FunctionExpression + : public FunctionExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> #if HAVE_DUNE_FEM - , - public Dune::Fem::Function<Dune::FunctionSpace<DomainFieldImp, RangeFieldImp, domainDim, rangeDim>, - Expression<DomainFieldImp, domainDim, RangeFieldImp, rangeDim>> + , + public Dune::Fem::Function<Dune::FunctionSpace<DomainFieldImp, RangeFieldImp, domainDim, rangeDim>, + FunctionExpression<DomainFieldImp, domainDim, RangeFieldImp, rangeDim>> #endif - , - public Interface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> + , + public FunctionInterface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> { public: - typedef Expression<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; - typedef ExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> BaseType; - typedef Interface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> InterfaceType; + typedef FunctionExpression<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; + typedef FunctionExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> BaseType; + typedef FunctionInterface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> InterfaceType; using typename InterfaceType::DomainFieldType; using InterfaceType::dimDomain; @@ -58,23 +59,23 @@ public: return InterfaceType::id() + ".expression"; } - Expression(const std::string _variable, const std::string _expression, const int _order = -1, - const std::string _name = "function.expression") + FunctionExpression(const std::string _variable, const std::string _expression, const int _order = -1, + const std::string _name = id()) : BaseType(_variable, _expression) , order_(_order) , name_(_name) { } - Expression(const std::string _variable, const std::vector<std::string> _expressions, const int _order = -1, - const std::string _name = "function.expression") + FunctionExpression(const std::string _variable, const std::vector<std::string> _expressions, const int _order = -1, + const std::string _name = id()) : BaseType(_variable, _expressions) , order_(_order) , name_(_name) { } - Expression(const ThisType& other) + FunctionExpression(const ThisType& other) : BaseType(other) , order_(other.order()) , name_(other.name()) @@ -105,9 +106,9 @@ public: extendedDescription.add(description, subName); return extendedDescription; } - } + } // ... createSampleDescription(...) - static ThisType* createFromDescription(const DSC::ExtendedParameterTree description) + static ThisType* create(const DSC::ExtendedParameterTree description) { // get necessary const std::string _variable = description.get<std::string>("variable", "x"); @@ -130,7 +131,7 @@ public: const std::string _name = description.get<std::string>("name", "function.expression"); // create and return return new ThisType(_variable, _expressions, _order, _name); - } // static ThisType createFromDescription(const Dune::ParameterTree& _description) + } // ... create(...) virtual int order() const { @@ -150,10 +151,9 @@ public: private: int order_; std::string name_; -}; // class Expression +}; // class FunctionExpression -} // namespace Function } // namespace Stuff } // namespace Dune diff --git a/dune/stuff/function/expression/base.hh b/dune/stuff/function/expression/base.hh index 9bd733d7cfcfb270bf61f43869ac18abd346da91..6fdc2b26eb576f2afaf4f74e1cd1827a2fe4a34b 100644 --- a/dune/stuff/function/expression/base.hh +++ b/dune/stuff/function/expression/base.hh @@ -27,12 +27,11 @@ namespace Dune { namespace Stuff { -namespace Function { -// forward +// forward, to be friends template <class RangeFieldImp> -class Coefficient; +class FunctionAffineSeparablCoefficient; ///** @@ -59,10 +58,10 @@ class Coefficient; * \attention Most surely you do not want to use this class directly! */ template <class DomainFieldImp, int domainDim, class RangeFieldImp, int rangeDim> -class ExpressionBase +class FunctionExpressionBase { public: - typedef ExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; + typedef FunctionExpressionBase<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; typedef DomainFieldImp DomainFieldType; static const int dimDomain = domainDim; @@ -70,18 +69,18 @@ public: typedef RangeFieldImp RangeFieldType; static const int dimRange = rangeDim; - ExpressionBase(const std::string _variable, const std::string _expression) + FunctionExpressionBase(const std::string _variable, const std::string _expression) { const std::vector<std::string> expressions(1, _expression); setup(_variable, expressions); } // NonparametricExpression(const std::string variable, const std::string expression) - ExpressionBase(const std::string _variable, const std::vector<std::string> _expressions) + FunctionExpressionBase(const std::string _variable, const std::vector<std::string> _expressions) { setup(_variable, _expressions); } // NonparametricExpression(const std::string variable, const std::vector< std::string >& expressions) - ExpressionBase(const ThisType& _other) + FunctionExpressionBase(const ThisType& _other) { setup(_other.variable(), _other.expression()); } // NonparametricExpression(const ThisType& other) @@ -98,7 +97,7 @@ public: return this; } // ThisType& operator=(const ThisType& other) - ~ExpressionBase() + ~FunctionExpressionBase() { cleanup(); } // ~NonparametricExpression() @@ -203,7 +202,7 @@ public: } // void report(const std::string, std::ostream&, const std::string&) const private: - friend class Coefficient<RangeFieldType>; + friend class FunctionAffineSeparablCoefficient<RangeFieldType>; void evaluate(const Dune::DynamicVector<DomainFieldType>& arg, RangeFieldType& ret) const { @@ -267,9 +266,8 @@ private: RVar* var_arg_[dimDomain]; RVar* vararray_[dimDomain]; ROperation* op_[dimRange]; -}; // class ExpressionBase +}; // class FunctionExpressionBase -} // namespace Function } // namespace Stuff } // namespace Dune diff --git a/dune/stuff/function/interface.hh b/dune/stuff/function/interface.hh index fb9351977bc0fb0259d729047e61de887e99d749..2ec10846849b941f9ab2672cdcef1e40c1c4ea8e 100644 --- a/dune/stuff/function/interface.hh +++ b/dune/stuff/function/interface.hh @@ -19,19 +19,18 @@ namespace Dune { namespace Stuff { -namespace Function { //! forward template <class RangeFieldImp> -class Coefficient; +class FunctionAffineSeparablCoefficient; template <class DomainFieldImp, int domainDim, class RangeFieldImp, int rangeDim> -class Interface +class FunctionInterface { public: - typedef Interface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; + typedef FunctionInterface<DomainFieldImp, domainDim, RangeFieldImp, rangeDim> ThisType; typedef DomainFieldImp DomainFieldType; static const int dimDomain = domainDim; @@ -46,9 +45,9 @@ public: typedef Common::Parameter::Type ParamType; typedef ThisType ComponentType; - typedef Coefficient<RangeFieldType> CoefficientType; + typedef FunctionAffineSeparablCoefficient<RangeFieldType> CoefficientType; - virtual ~Interface() + virtual ~FunctionInterface() { } @@ -160,74 +159,9 @@ public: evaluate(_x, ret); return ret; } +}; // class FunctionInterface - // virtual RangeType evaluate(const DomainType& x, const ParamType& mu) const - // { - // RangeType ret; - // evaluate(x, mu, ret); - // return ret; - // } - - // virtual void evaluate(const ParamType& x, const ParamType& mu, RangeType& ret) const - // { - // // process input - // assert(x.size() == dimDomain); - // DomainType x_fvector; - // for (int i = 0; i < dimDomain; ++i) - // x_fvector[i] = x(i); - // // evaluate - // evaluate(x_fvector, mu, ret); - // } - - // virtual void evaluate(const DomainType& x, const ParamType& mu, ParamType& ret) const - // { - // // evaluate - // RangeType ret_fvector; - // evaluate(x, mu, ret_fvector); - // // process output - // assert(ret.size() == dimRange); - // for (int i = 0; i < dimRange; ++i) - // ret(i) = ret_fvector[i]; - // } - - // virtual void evaluate(const ParamType& x, const ParamType& mu, ParamType& ret) const - // { - // // process input - // assert(x.size() == dimDomain); - // DomainType x_fvector; - // for (int i = 0; i < dimDomain; ++i) - // x_fvector[i] = x(i); - // // evaluate - // RangeType ret_fvector; - // evaluate(x_fvector, mu, ret_fvector); - // // process output - // assert(ret.size() == dimRange); - // for (int i = 0; i < dimRange; ++i) - // ret(i) = ret_fvector[i]; - // } - - // virtual ParamType evaluate(const ParamType& x, const ParamType& mu) const - // { - // ParamType ret; - // evaluate(x, mu, ret); - // return ret; - // } - - // void report(std::ostream& out = std::cout, std::string prefix = "") const - // { - // out << prefix << "parameter explanation:" << std::endl; - // assert(paramExplanation().size() == paramSize()); - // assert(paramRange().size() == 2); - // assert(paramRange()[0].size() == paramSize()); - // assert(paramRange()[1].size() == paramSize()); - // for (unsigned int pp = 0; pp < paramSize(); ++pp) - // out << prefix << " " << paramExplanation()[pp] << ", between " << paramRange()[0](pp) << " and " << - // paramRange()[1](pp) << std::endl; - // } - /* @} */ -}; // class Interface -} // namespace Function } // namespace Stuff } // namespace Dune