diff --git a/CHANGELOG.md b/CHANGELOG.md index f813ea9a23fe70a9d80beb97d06f2c7e93659f55..f4f59475a3657dfea408536efee1dca2654d6521 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,11 @@ `dune-common` 2.7. - The following implementations of the deprecated `Dune::VirtualFunction` interface - have been removed: `ConstantFunction`. + have been removed: `ConstantFunction`, `SumFunction`, `SumGridFunction`, + `ComposedFunction`, `ComposedGridFunction`, `Polynomial`. + +- The class `NamedFunctionMap` based on `Dune::VirtualFunction` has been removed. + Use `std::map<:std::string, std::function<Range(Domain)>>` as a replacement. # 2.9 Release diff --git a/dune/fufem/functions/CMakeLists.txt b/dune/fufem/functions/CMakeLists.txt index afdac60d98574bb8b173000a37540e1ba6f12be8..1a36f24cb9e8531f5c5378b993234bf6fa11821b 100644 --- a/dune/fufem/functions/CMakeLists.txt +++ b/dune/fufem/functions/CMakeLists.txt @@ -4,16 +4,11 @@ install(FILES basisgridfunction.hh cachedcomponentwrapper.hh coarsegridfunctionwrapper.hh - composedfunction.hh - composedgridfunction.hh deformationfunction.hh localbasisderivativefunction.hh localbasisjacobianfunction.hh - polynomial.hh portablegreymap.hh portablepixelmap.hh - sumfunction.hh - sumgridfunction.hh vintagebasisgridfunction.hh virtualdifferentiablefunction.hh virtualgridfunction.hh diff --git a/dune/fufem/functions/composedfunction.hh b/dune/fufem/functions/composedfunction.hh deleted file mode 100644 index d7a670c1320c72b959f91be0077694a912b51178..0000000000000000000000000000000000000000 --- a/dune/fufem/functions/composedfunction.hh +++ /dev/null @@ -1,70 +0,0 @@ -// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set ts=8 sw=4 et sts=4: -#ifndef COMPOSED_FUNCTION_HH -#define COMPOSED_FUNCTION_HH - -// Borrow internal helper from dune-localfunctions -// for transition of function interface -#include <dune/localfunctions/common/localinterpolation.hh> - -/** \brief A class implementing the composition of two functions. - * - * The composed function \f$ f\circ g:A\rightarrow C \f$ where \f$ g:A\rightarrow B \f$ and \f$ f:B\rightarrow C \f$ - * is implemented. - * \tparam AT type of \f$ domain(g)\f$ - * \tparam BT type of \f$ range(g)\f$ and \f$ domain(f)\f$ - * \tparam CT type of \f$ range(f)\f$ - */ -template <typename AT, typename BT, typename CT> -class ComposedFunction -{ -public: - using DomainType = AT; - using RangeType = CT; - - using InnerFunctionType = std::function<BT(AT)>; - using OuterFunctionType = std::function<CT(BT)>; - - /** \brief Constructor - * - * \param f outer function for composition - * \param g inner function for composition - */ - template<class F, class G> - ComposedFunction(const F& f, const G& g) : - f_(Dune::Impl::makeFunctionWithCallOperator<BT>(f)), - g_(Dune::Impl::makeFunctionWithCallOperator<AT>(g)) - {} - - /** \brief composed evaluation of one component using eval of the composed functions - * - * \param x point in \f$ A \f$ at which to evaluate - * \param y vector in \f$ C \f$ to store the function value in - */ - RangeType operator()(const DomainType& x) - { - return f_(g_(x)); - } - - /** \brief composed evaluation of one component using eval of the composed functions - * - * \deprecated Use operator() instead - * - * \param x point in \f$ A \f$ at which to evaluate - * \param y vector in \f$ C \f$ to store the function value in - */ - void evaluate(const DomainType& x, RangeType& y) const - { - y = f_(g_(x)); - } - - ~ComposedFunction(){} - -private: - OuterFunctionType f_; - InnerFunctionType g_; - -}; - -#endif - diff --git a/dune/fufem/functions/composedgridfunction.hh b/dune/fufem/functions/composedgridfunction.hh deleted file mode 100644 index 21a783cba53519ae8bfafd97af8a5d305e9e0891..0000000000000000000000000000000000000000 --- a/dune/fufem/functions/composedgridfunction.hh +++ /dev/null @@ -1,109 +0,0 @@ -// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set ts=8 sw=4 et sts=4: -#ifndef COMPOSED_GRID_FUNCTION_HH -#define COMPOSED_GRID_FUNCTION_HH - -#include <dune/fufem/functions/virtualgridfunction.hh> - -/** \brief A class implementing the composition of a GridFunction and another Function. The resulting Function therefore is again a GridFunction. - * - * The composed function \f$ f\circ g:A\rightarrow C \f$ is implemented where \f$ g:A\rightarrow B \f$ is a - * GridFunction and \f$ f:B\rightarrow C \f$ a general function derived from VirtualFunction. - * \tparam GridType type of the Grid - * \tparam BT type of \f$ range(f)\f$ and \f$ domain(g)\f$ - * \tparam CT type of \f$ range(g)\f$ - */ -template <typename GridType, typename BT, typename CT> -class ComposedGridFunction : - public VirtualGridFunction<GridType, CT> -{ - - typedef VirtualGridFunction<GridType, CT> BaseType; - -public: - typedef typename BaseType::LocalDomainType LocalDomainType; - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - typedef typename BaseType::DerivativeType DerivativeType; - typedef typename BaseType::Grid Grid; - - typedef VirtualGridFunction<GridType,BT> InnerFunctionType; - typedef Dune::VirtualFunction<BT,RangeType> OuterFunctionType; - - typedef typename BaseType::Element Element; - - /** \brief Constructor - * - * \param f outer function for composition - * \param g inner (grid-)function for composition - */ - ComposedGridFunction(const OuterFunctionType& f, const InnerFunctionType& g): - BaseType(g.grid()), - f_(f), - g_(g) - {} - - /** \brief composed evaluation of all components using evalall/evalalllocal of the composed functions - * - * \param e Grid Element on which to evaluate locally - * \param x point in \f$ A \f$ at which to evaluate - * \param y vector in \f$ C \f$ to store the function value in - */ - virtual void evaluateLocal(const Element& e, const DomainType& x, RangeType& y) const - { - BT ytemp; - - g_.evaluateLocal(e,x,ytemp); - f_.evaluate(ytemp,y); - - return; - } - - - /** \brief evaluation of derivative in local coordinates - * - * \param e Evaluate in local coordinates with respect to this element. - * \param x point in local coordinates at which to evaluate the derivative - * \param d will contain the derivative at x after return - */ - virtual void evaluateDerivativeLocal(const Element& e, const LocalDomainType& x, DerivativeType& d) const - { - using VDFunc = VirtualDifferentiableFunction<BT,RangeType>; - const VDFunc* vdf = dynamic_cast<const VDFunc*>(&f_); - if (vdf) - { - BT ytemp; - g_.evaluateLocal(e,x,ytemp); // g(x) - - typename VDFunc::DerivativeType dfgx; // f'(g(x)) - typename InnerFunctionType::DerivativeType dgx; // g'(x) - - vdf->evaluateDerivative(ytemp,dfgx); - - g_.evaluateDerivativeLocal(e,x,dgx); - - // d = dfgx*dgx; - d = dfgx.rightmultiplyany(dgx); - - return; - } - else - DUNE_THROW(Dune::Exception,"This composed function is not piecewise differentiable on elements because its outer function isn't."); - - return; - } - - virtual bool isDefinedOn(const Element& e) const - { - return g_.isDefinedOn(e); - } - - ~ComposedGridFunction(){} - -private: - const OuterFunctionType& f_; - const InnerFunctionType& g_; -}; - -#endif - diff --git a/dune/fufem/functions/polynomial.hh b/dune/fufem/functions/polynomial.hh deleted file mode 100644 index 1990ff341a343cd5f0af4b67bc067d691844c6f6..0000000000000000000000000000000000000000 --- a/dune/fufem/functions/polynomial.hh +++ /dev/null @@ -1,146 +0,0 @@ -// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- -// vi: set ts=8 sw=2 et sts=2: -#ifndef POLYNOMIAL_HH -#define POLYNOMIAL_HH - -#include <map> -#include <memory> - -#include <dune/fufem/functions/virtualdifferentiablefunction.hh> - -/** \brief A class implementing polynomials \f$ P:\mathbb{R}\rightarrow\mathbb{R} \f$ of arbitrary degree. - * - * The polynomial expects the coefficients of the monomial representation and implements its evaluation and - * its derivatives of arbitrary order. - * \tparam DT Domain Field type - * \tparam RT Range Field type - */ -template < class DT, class RT > -class Polynomial: - public VirtualDifferentiableFunction<DT,RT> -{ - private: - typedef VirtualDifferentiableFunction<DT,RT> BaseType; - - - public: - typedef std::vector<RT> CoeffType; - - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - typedef typename BaseType::DerivativeType DerivativeType; - - /** \brief Constructor - * - * \param coeffs vector containing the coefficients of the monomial representation - */ - Polynomial(const CoeffType coeffs): - coeffs_(coeffs), - degree_(coeffs.size()-1) - {} - - /** \brief polynomial degree - */ - int degree() const - { - return degree_; - } - - /** \brief evaluation of the polynomial at point x - * - * The polynomial is evaluated efficiently using Horner's scheme - * \param x the point at which to evaluate - */ - RangeType evaluate(const DomainType& x) const - { - RangeType p = 0.0; - - for (int k=degree_; k>=0; --k) - p = x*p + coeffs_[k]; - - return p; - } - - /** \brief evaluation of the polynomial at point x - * - * The polynomial is evaluated efficiently using Horner's scheme - * \param x the point at which to evaluate - * \param y the object to store the function value in - */ - virtual void evaluate(const DomainType& x, RangeType& y) const - { - y = evaluate(x); - return; - } - - - /** \brief evaluation of derivative - * - * \param x point at which to evaluate - * \param d object to store the derivative - */ - virtual void evaluateDerivative(const DomainType& x, DerivativeType& d) const - { - // Compute result as field, because FM<K,1,1> and FV<k,1,1> - // d not interact nicely and we're having univariate polynomials - // anyway. - using Field = typename Dune::FieldTraits<DerivativeType>::field_type; - Field y = 0.0; - for (int k=degree_; k>=1; --k) - y = x*y + dCoeff(1,k)*coeffs_[k]; - d = y; - return; - } - - /** \brief Returns the derivative function as a Polynomial object - * - * \param d order of the derivative - */ - Polynomial<DomainType, RangeType>& D(const std::size_t d) - { - if (d==0) - return *this; - - typename DerivativeContainer::iterator ret=dP.find(d); - if (ret==dP.end()) - { - CoeffType newCoeffs = coeffs_; - - for (std::size_t k = degree_; k>=d; --k) - newCoeffs[k] *= dCoeff(d,k); - - for (std::size_t k=0; k<d; ++k) - { - typename CoeffType::iterator firstEntry=newCoeffs.begin(); - newCoeffs.erase(firstEntry); - } - - ret = dP.insert(std::make_pair(d,std::make_shared<Polynomial<DT,RT> >(newCoeffs))).first; - } - - return *(ret->second); - } - - ~Polynomial() - {} - - private: - const CoeffType coeffs_; - const unsigned int degree_; - - typedef std::map<std::size_t, std::shared_ptr<Polynomial<DT,RT> > > DerivativeContainer; - DerivativeContainer dP; - - unsigned int dCoeff(const int& d, const int& k) const - { - unsigned int r=1; - for (int i=0; i<d; ++i) - r *= k-i; - - return r; - } - -}; - - -#endif diff --git a/dune/fufem/functions/sumfunction.hh b/dune/fufem/functions/sumfunction.hh deleted file mode 100644 index 983e1e5ecd574c3460c2df10b8208310fa7dcd74..0000000000000000000000000000000000000000 --- a/dune/fufem/functions/sumfunction.hh +++ /dev/null @@ -1,88 +0,0 @@ -// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set ts=8 sw=4 et sts=4: -#ifndef SUM_FUNCTION_HH -#define SUM_FUNCTION_HH - -#include <vector> - -#include <dune/common/exceptions.hh> -#include <dune/common/function.hh> - -/** \brief A class implementing linear combinations of several functions. - * - * The function \f$ \sum a_if_i:A\rightarrow B \f$ where \f$ (\sum a_if_i)(x) = \sum a_i\cdot f_i(x) \f$ - * is implemented. - * \tparam DT type of \f$ domain(f_i)\f$ - * \tparam RT type of \f$ range(f_i)\f$ - */ -template <typename DT, typename RT> -class SumFunction : - virtual public Dune::VirtualFunction<DT, RT> -{ - typedef Dune::VirtualFunction<DT,RT> BaseType; -public: - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - - /** \brief Default Constructor - * - */ - SumFunction() - {} - - /** \brief Constructor - * - */ - SumFunction(std::vector<const BaseType*>& functions, std::vector<double>& coefficients): - functions_(functions), - coefficients_(coefficients) - { - if (functions_.size() != coefficients.size()) - DUNE_THROW(Dune::Exception,"You have not supplied the correct number of coefficients in SumFunction::SumFunction(std::vector<BaseType*>&, std::vector<double>&) (sumfunction.hh)"); - } - - /** \brief evaluation using evaluate of the respective functions - * - * \param x point in \f$ A \f$ at which to evaluate - * \param y variable to store the function value in - */ - virtual void evaluate(const DomainType& x, RangeType& y) const - { - y = 0.0; - - if (functions_.size()==0) - DUNE_THROW(Dune::Exception,"No function has been registered for summed evaluation in SumFunction::evaluate (sumfunction.hh)"); - - RangeType ytemp; - - for (size_t i=0; i<functions_.size(); ++i) - { - functions_[i]->evaluate(x,ytemp); - ytemp *= coefficients_[i]; - y += ytemp; - } - - return; - } - - /** \brief register functions to be summed up - * - * \param coefficient for summand function - * \param function summand function to register - */ - virtual void registerFunction(double coefficient, const BaseType& function) - { - functions_.push_back(&function); - coefficients_.push_back(coefficient); - } - - ~SumFunction(){} - -private: - std::vector<const BaseType*> functions_; - std::vector<double> coefficients_; - -}; - -#endif - diff --git a/dune/fufem/functions/sumgridfunction.hh b/dune/fufem/functions/sumgridfunction.hh deleted file mode 100644 index 78cf475e52ae4517aea595fb3f196fce82ff9959..0000000000000000000000000000000000000000 --- a/dune/fufem/functions/sumgridfunction.hh +++ /dev/null @@ -1,130 +0,0 @@ -// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set ts=8 sw=4 et sts=4: -#ifndef SUM_GRID_FUNCTION_HH -#define SUM_GRID_FUNCTION_HH - -#include <vector> - -#include <dune/fufem/functions/virtualgridfunction.hh> - -/** \brief A class implementing linear combinations of several GridFunctions. - * - * The function \f$ \sum a_if_i:GridType:[...]:GlobalCoordinate\rightarrow B \f$ where \f$ (\sum a_if_i)(x) = \sum a_i\cdot f_i(x) \f$ - * is implemented. - * \tparam GridType the GridType of the grid on which the GridFunctions are given - * \tparam RT type of \f$ range(f_i)\f$ - */ -template <typename GridType, typename RT> -class SumGridFunction: - public VirtualGridFunction<GridType, RT> -{ - - typedef VirtualGridFunction<GridType, RT> BaseType; - typedef typename GridType::Traits::template Codim<0>::Entity Element; - -public: - - typedef typename BaseType::LocalDomainType LocalDomainType; - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - typedef typename BaseType::DerivativeType DerivativeType; - - - /** \brief Default Constructor - * - */ - SumGridFunction(const GridType& grid): - BaseType(grid) - {} - - /** \brief summed up local evaluation using evaluateLocal of the registered functions - * - * \param e Grid Element on which to evaluate locally - * \param x point at which to evaluate - * \param y object to store the function value in - */ - virtual void evaluateLocal(const Element& e, const LocalDomainType& x, RangeType& y) const - { - if (not(isDefinedOn(e))) - DUNE_THROW(Dune::Exception, "SumGridFunction not defined on given element."); - - y = 0.0; - - if (functions_.size()==0) - DUNE_THROW(Dune::Exception,"No function has been registered for summed evaluation"); - - RangeType ytemp; - - for (size_t i=0; i<functions_.size(); ++i) - { - functions_[i]->evaluateLocal(e,x,ytemp); - ytemp *= coefficients_[i]; - y += ytemp; - } - - return; - } - - /** \brief evaluation of derivative in local coordinates - * - * \param e Evaluate in local coordinates with respect to this element. - * \param x point in local coordinates at which to evaluate the derivative - * \param d will contain the derivative at x after return - */ - virtual void evaluateDerivativeLocal(const Element& e, const LocalDomainType& x, DerivativeType& d) const - { - if (not(isDefinedOn(e))) - DUNE_THROW(Dune::Exception, "SumGridFunction not defined on given element."); - - d = 0.0; - - if (functions_.size()==0) - DUNE_THROW(Dune::Exception,"No function has been registered for summed evaluation"); - - DerivativeType dtemp; - - for (size_t i=0; i<functions_.size(); ++i) - { - functions_[i]->evaluateDerivativeLocal(e,x,dtemp); - dtemp *= coefficients_[i]; - d += dtemp; - } - - return; - } - - /** - * \brief Check whether local evaluation is possible - * - * \param e Return true if local evaluation is possible on this element. - */ - virtual bool isDefinedOn(const Element& e) const - { - bool r=true; - for (size_t i=0; i<functions_.size(); ++i) - r = r and functions_[i]->isDefinedOn(e); - - return r; - } - - /** \brief register functions to be summed up - * - * \param coefficient of summand function - * \param function summand (grid-)function to register - */ - virtual void registerFunction(double coefficient, const BaseType& function) - { - functions_.push_back(&function); - coefficients_.push_back(coefficient); - } - - ~SumGridFunction(){} - -private: - std::vector<const BaseType*> functions_; - std::vector<double> coefficients_; - -}; - -#endif - diff --git a/dune/fufem/functiontools/CMakeLists.txt b/dune/fufem/functiontools/CMakeLists.txt index 033d7189573788548659f546f7f6bb32ea8225fc..62ce2874a489b9a2e45927fa2eb9159e6d0b7e1b 100644 --- a/dune/fufem/functiontools/CMakeLists.txt +++ b/dune/fufem/functiontools/CMakeLists.txt @@ -5,6 +5,5 @@ install(FILES functionintegrator.hh gradientbasis.hh gridfunctionadaptor.hh - namedfunctionmap.hh p0p1interpolation.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/fufem/functiontools) diff --git a/dune/fufem/functiontools/namedfunctionmap.hh b/dune/fufem/functiontools/namedfunctionmap.hh deleted file mode 100644 index ab7d30489d0a5feb9b03e1e0db85c72826eacc12..0000000000000000000000000000000000000000 --- a/dune/fufem/functiontools/namedfunctionmap.hh +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef NAMED_FUNCTION_MAP_HH -#define NAMED_FUNCTION_MAP_HH - -#include <map> -#include <string> - -#include <dune/common/exceptions.hh> -#include <dune/common/function.hh> -#include <dune/fufem/functions/virtualdifferentiablefunction.hh> - -template <class DomainType, class RangeType> -class NamedFunctionMap : - public std::map<std::string, typename Dune::VirtualFunction<DomainType,RangeType>* > -{ - public: - typedef typename Dune::VirtualFunction<DomainType,RangeType> Function; - typedef VirtualDifferentiableFunction<DomainType,RangeType> DifferentiableFunction; - - NamedFunctionMap() - { - } - - const Function* getFunction(const std::string& name) const - { - typename Base::const_iterator it = this->find(name); - if (it!=this->end()) - return it->second; - DUNE_THROW(Dune::RangeError, "Function named '" << name << "' not found in NamedFunctionMap!"); - return 0; - } - - Function* getFunction(const std::string& name) - { - typename Base::const_iterator it = this->find(name); - if (it!=this->end()) - return it->second; - DUNE_THROW(Dune::RangeError, "Function named '" << name << "' not found in NamedFunctionMap!"); - return 0; - } - - const DifferentiableFunction* getDifferentiableFunction(const std::string& name) const - { - const Function* p = getFunction(name); - return dynamic_cast<const DifferentiableFunction*>(getFunction(name)); - } - - DifferentiableFunction* getDifferentiableFunction(const std::string& name) - { - Function* p = getFunction(name); - return dynamic_cast<DifferentiableFunction*>(getFunction(name)); - } - - - private: - typedef std::map<std::string, Function* > Base; -}; - - -#endif diff --git a/dune/fufem/test/CMakeLists.txt b/dune/fufem/test/CMakeLists.txt index 3c04b849d492f2148703f7fd165b46040eb1f67a..1078f422ff4047c01ea3b4d9b4513ce17df38b9b 100644 --- a/dune/fufem/test/CMakeLists.txt +++ b/dune/fufem/test/CMakeLists.txt @@ -6,7 +6,6 @@ set(GRID_BASED_TESTS boundarypatchtest boundarypatchprolongatortest coarsegridfunctionwrappertest - composedfunctiontest constructboundarydofstest dunefunctionsipdgassemblertest functionintegratortest @@ -21,10 +20,8 @@ set(GRID_BASED_TESTS istlbackendtest laplaceassemblertest localassemblertest - polynomialtest secondorderassemblertest subgridxyfunctionalassemblertest - sumfunctiontest tensortest transferoperatorassemblertest vintagebasisgridfunctiontest diff --git a/dune/fufem/test/composedfunctiontest.cc b/dune/fufem/test/composedfunctiontest.cc deleted file mode 100644 index 46c075a327310a8835986c8e396f0c88b1a5d20d..0000000000000000000000000000000000000000 --- a/dune/fufem/test/composedfunctiontest.cc +++ /dev/null @@ -1,276 +0,0 @@ -#include <config.h> - -#include <cmath> -#include <cstdio> - -#include <dune/common/parallel/mpihelper.hh> -#include <dune/common/exceptions.hh> -#include <dune/common/fvector.hh> -#include <dune/common/function.hh> - - -#include <dune/fufem/functions/composedfunction.hh> -#include <dune/fufem/functions/composedgridfunction.hh> -#include <dune/fufem/functions/basisgridfunction.hh> -#include <dune/fufem/functions/virtualgridfunction.hh> -#include <dune/fufem/functions/virtualdifferentiablefunction.hh> - -#include <dune/fufem/functiontools/basisinterpolator.hh> - -#include <dune/fufem/functionspacebases/p1nodalbasis.hh> - -#include "common.hh" - -/** \brief inflates by zeros or cuts off trailing components according to Domain and Range dimensions. for domaindim==rangedim it's simply the identity - * - */ -template <class DT, class RT> -class InflateOrCut_Base : - public Dune::VirtualFunction<DT,RT> -{ - public: - using DomainType = DT; - using RangeType = RT; - - enum {DomainDim = DomainType::dimension, - RangeDim = RangeType::dimension}; - - InflateOrCut_Base() - {} - - void evaluate(const DomainType& x, RangeType& y) const - { - y = 0.0; - for (int i=0; i<DomainDim and i<RangeDim; ++i) - y[i]=x[i]; - } - - RangeType operator()(const DomainType& x) const - { - RangeType y; - evaluate(x,y); - return y; - } -}; - -/** \brief inflates by zeros or cuts off trailing components according to Domain and Range dimensions. for domaindim==rangedim it's simply the identity - * - */ -template <class GridType, class RT> -class InflateOrCut_GridF: - public VirtualGridFunction<GridType,RT> -{ - typedef VirtualGridFunction<GridType,RT> BaseType; - - public: - typedef typename BaseType::LocalDomainType LocalDomainType; - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - - typedef typename BaseType::Element Element; - - enum {DomainDim = DomainType::dimension, - RangeDim = RangeType::dimension}; - - InflateOrCut_GridF(GridType& grid): - BaseType(grid) - {} - - virtual void evaluateLocal(const Element& e, const LocalDomainType& x, RangeType& y) const - { - y = 0.0; - - DomainType xglobal = e.geometry().global(x); - - for (int i=0; i<DomainDim and i<RangeDim; ++i) - { - y[i]=xglobal[i]; - } - - return; - } - - virtual bool isDefinedOn(const Element&) const - { - return true; - } - -}; -/** \brief inflates by zeros or cuts off trailing components according to Domain and Range dimensions. for domaindim==rangedim it's simply the identity - * - */ -template <class GridViewType, class RT> -class InflateOrCut_GridVF: - public VirtualGridViewFunction<GridViewType,RT> -{ - typedef VirtualGridViewFunction<GridViewType,RT> BaseType; - - public: - typedef typename BaseType::LocalDomainType LocalDomainType; - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - - typedef typename BaseType::Element Element; - - enum {DomainDim = DomainType::dimension, - RangeDim = RangeType::dimension}; - - InflateOrCut_GridVF(const GridViewType& gridview): - BaseType(gridview) - {} - - virtual void evaluateLocal(const Element& e, const LocalDomainType& x, RangeType& y) const - { - y = 0.0; - - DomainType xglobal = e.geometry().global(x); - - for (int i=0; i<DomainDim and i<RangeDim; ++i) - { - y[i]=xglobal[i]; - } - - return; - } -}; - -/** \brief TestSuite for ComposedFunction - * - * Takes InflateOrCut_Base functions f,g such that \f$f\circ g:\mathbb R^n\longrightarrow\mathbb R^m\longrightarrow \mathbb R^d\f$ with \f$m > n \geq d\f$. So on the first d components - * the composition should be the identity. - */ -struct ComposedFunctionTestSuite -{ - bool check() - { - const std::size_t n=3, - m=5, - d=2; - - std::size_t n_testpoints=100; - - typedef Dune::FieldVector<double,n> DomainType; - typedef Dune::FieldVector<double,m> IntermediateRangeType; - typedef Dune::FieldVector<double,d> RangeType; - - typedef InflateOrCut_Base<DomainType,IntermediateRangeType> InnerFunctionType; - typedef InflateOrCut_Base<IntermediateRangeType,RangeType> OuterFunctionType; - - InnerFunctionType g; - OuterFunctionType f; - - ComposedFunction<DomainType,IntermediateRangeType,RangeType> f_after_g(f,g); - - DomainType x(0.0); - RangeType y(0.0); - - for (std::size_t run=0; run<n_testpoints; ++run) - { - for (std::size_t dcomp=0; dcomp<n; ++dcomp) - x[dcomp] = (5.0*rand())/RAND_MAX - 2.5; - - f_after_g.evaluate(x,y); - - for (std::size_t rcomp=0; rcomp<d; ++rcomp) - if (std::abs(y[rcomp]-x[rcomp])>1e-15) - { - std::cout << "y[" << rcomp << "] = " << y[rcomp] << ", x[" << rcomp << "] = " << x[rcomp] << std::endl; - - return false; - } - } - - return true; - } -}; -/** \brief TestSuite for ComposedFunction - * - * Takes InflateOrCut functions f,g such that \f$f\circ g:\mathbb R^n\longrightarrow\mathbb R^m\longrightarrow \mathbb R^d\f$ with \f$m > n,\ m > d\f$. So on the first min(n,d) components - * the composition should be the identity. - */ -struct ComposedGridFunctionTestSuite -{ - template <class GridType> - bool check(GridType& grid) - { - const unsigned int n=GridType::dimension, - m=5, - d=4; - - const std::size_t n_testpoints=100; - - typedef Dune::FieldVector<typename GridType::ctype,n> DomainType; - typedef Dune::FieldVector<double,m> IntermediateRangeType; - typedef Dune::FieldVector<double,d> RangeType; - - typedef InflateOrCut_GridF<GridType,IntermediateRangeType> InnerFunctionType; - typedef InflateOrCut_GridVF<typename GridType::LeafGridView,IntermediateRangeType> InnerFunctionType2; - typedef InflateOrCut_Base<IntermediateRangeType,RangeType> OuterFunctionType; - - InnerFunctionType g(grid); - InnerFunctionType2 gg(grid.leafGridView()); - OuterFunctionType f; - - ComposedGridFunction<GridType,IntermediateRangeType,RangeType> f_after_g(f,g); - ComposedGridFunction<GridType,IntermediateRangeType,RangeType> f_after_gg(f,gg); - - DomainType x(0.0); - RangeType y(0.0),yy(0.0); - - for (std::size_t run=0; run<n_testpoints; ++run) - { - double sum=0; - for (std::size_t dcomp=0; dcomp<n; ++dcomp) - { - x[dcomp] = std::min((1.0*rand())/(n-1)/RAND_MAX, 1-sum); - sum += x[dcomp]; - } - - f_after_g.evaluate(x,y); // let's just use evaluate. It's the default implementation using evaluateLocal internally so the GridFunction aspect should be checked well enough - f_after_gg.evaluate(x,yy); - - std::size_t kmin = std::min(d,n); - - for (std::size_t rcomp=0; rcomp<kmin; ++rcomp) - if (std::abs(y[rcomp]-x[rcomp])>1e-15 or std::abs(yy[rcomp]-x[rcomp])>1e-15) - { - std::cout << "y[" << rcomp << "] = " << y[rcomp] << ", x[" << rcomp << "] = " << x[rcomp] << std::endl; - - return false; - } - - for (std::size_t rcomp=kmin; rcomp<d; ++rcomp) - if (y[rcomp]!=0.0 or yy[rcomp]!=0.0) - return false; - } - - return true; - } -}; - -int main(int argc, char** argv) -{ - Dune::MPIHelper::instance(argc, argv); - - std::cout << "This is the ComposedFunctionTest" << std::endl; - - bool passed = true; - - { - ComposedFunctionTestSuite cftests; - - passed = cftests.check(); - if (passed) - std::cout << "ComposedFunction test passed" << std::endl; - else - std::cout << "ComposedFunction test failed" << std::endl; - } - - { - ComposedGridFunctionTestSuite cftests; - passed = checkWithStandardAdaptiveGrids(cftests); - } - - return passed ? 0 : 1; - -} diff --git a/dune/fufem/test/polynomialtest.cc b/dune/fufem/test/polynomialtest.cc deleted file mode 100644 index 35457b2e2e286c9d61e55506af5cf3ad4d2b1456..0000000000000000000000000000000000000000 --- a/dune/fufem/test/polynomialtest.cc +++ /dev/null @@ -1,119 +0,0 @@ -#include <config.h> - -#include <cmath> -#include <cstdio> - -#include <dune/common/parallel/mpihelper.hh> -#include <dune/common/exceptions.hh> -#include <dune/common/fvector.hh> -#include <dune/common/function.hh> - -#include <dune/fufem/functions/polynomial.hh> - -#include "common.hh" - -/** \brief TestSuite for Polynomial - * - * + compares Polynomial::evaluate to manual evaluation of polynomial (hm, well...) - * + compares Polynomial::evaluateDerivative to manual evaluateDerivative of derivative of polynomial (hm, well) - * + checks consistency of Polynomial::evaluateDerivative() and Polynomial::D().evaluate() - * - */ -struct PolynomialTestSuite -{ - bool check() - { - - const int n_testpoints=10, - n_testpolynomials = 5, - maxdegree = 10, - maxcoeff = 100; - - typedef Dune::FieldVector<double,1> DomainType; - typedef Dune::FieldVector<double,1> RangeType; - - typedef Polynomial<DomainType,RangeType> PType; - typedef PType::CoeffType CoeffType; - typedef PType::DerivativeType DerivativeType; - - for (int p=0; p<n_testpolynomials; ++p) - { - CoeffType coeffs((rand() % maxdegree) + 2); - std::cout << p << ": coeffs= "; - for (size_t c=0; c<coeffs.size(); ++c) - { - coeffs[c] = (2.0*maxcoeff*rand())/RAND_MAX - maxcoeff; - std::cout << coeffs[c] << " " ; - } - std::cout << std::endl; - - PType polynomial(coeffs); - - DomainType x(0.0); - RangeType y(0.0), - ycheck(0.0), - Dcheck(0.0); - DerivativeType d(0.0), - dcheck(0.0); - - for (int run=0; run<n_testpoints; ++run) - { - x = (4.0*rand())/RAND_MAX - 2.0; - - ycheck = 0.0; - for (size_t j=0; j<coeffs.size(); ++j) - ycheck += coeffs[j]*std::pow(x,j); - - polynomial.evaluate(x,y); - - if (std::abs((y-ycheck)/y)>1e-12) - { - std::cout << "Polynomial::evaluate(" << x << ") = " << y << std::endl; - std::cout << "manual evaluation: " << ycheck << std::endl; - return false; - } - - dcheck = 0.0; - for (size_t j=1; j<coeffs.size(); ++j) - dcheck += coeffs[j]*j*std::pow(x,j-1); - - polynomial.evaluateDerivative(x,d); - polynomial.D(1).evaluate(x,Dcheck); - - if (std::abs((d-dcheck)/d)>1e-12) - { - std::cout << "Polynomial::evaluateDerivative(" << x << ") = " << d << std::endl; - std::cout << "manual derivative evaluation: " << dcheck << std::endl; - return false; - } - if (std::abs((d-Dcheck)/d)>1e-12) - { - std::cout << "Polynomial::evaluateDerivative(" << x << ") = " << d << std::endl; - std::cout << "Polynomial::D().evaluate(" << x << ") = " << Dcheck << std::endl; - return false; - } - - } - } - return true; - } -}; - - -int main(int argc, char** argv) -{ - Dune::MPIHelper::instance(argc, argv); - - std::cout << "This is the PolynomialTest" << std::endl; - - PolynomialTestSuite tests; - - bool passed = tests.check(); - if (passed) - std::cout << "Polynomial test passed" << std::endl; - else - std::cout << "Polynomial test failed" << std::endl; - - return passed ? 0 : 1; - -} diff --git a/dune/fufem/test/sumfunctiontest.cc b/dune/fufem/test/sumfunctiontest.cc deleted file mode 100644 index bd2962b1696aae22dbff79aecf89793d27222e29..0000000000000000000000000000000000000000 --- a/dune/fufem/test/sumfunctiontest.cc +++ /dev/null @@ -1,243 +0,0 @@ -#include <config.h> - -#include <cmath> -#include <cstdio> - -#include <dune/common/parallel/mpihelper.hh> -#include <dune/common/exceptions.hh> -#include <dune/common/fvector.hh> -#include <dune/common/function.hh> - -#include <dune/fufem/functions/sumfunction.hh> -#include <dune/fufem/functions/sumgridfunction.hh> -#include <dune/fufem/functions/basisgridfunction.hh> -#include <dune/fufem/functions/virtualgridfunction.hh> - -#include <dune/fufem/functiontools/basisinterpolator.hh> - -#include <dune/fufem/functionspacebases/dunefunctionsbasis.hh> -#include <dune/functions/functionspacebases/lagrangebasis.hh> - -#include "common.hh" - -/** \brief sin^2(comp) or cos^2(comp) as specified in constructor - * - */ -template <class DT, class RT> -class TrigFunctionSquared: - public Dune::VirtualFunction<DT,RT> -{ - typedef Dune::VirtualFunction<DT,RT> BaseType; - - public: - enum Trig { - SIN, - COS - }; - - typedef typename BaseType::DomainType DomainType; - typedef typename BaseType::RangeType RangeType; - - TrigFunctionSquared(int comp, Trig basic_trig): - trig_(basic_trig), - comp_(comp) - {} - - virtual void evaluate(const DomainType& x, RangeType& y) const - { - double temp{0}; - switch (trig_) { - case SIN: - temp=sin(x[comp_]); - break; - case COS: - temp=cos(x[comp_]); - break; - } - y = temp*temp; - } - private: - Trig trig_; - int comp_; -}; - -/** \brief TestSuite for SumFunction - * - * Takes a '2D partition of 1', here 1 = (0.5*sin^2(x)+0.5*sin^2(y)) + (0.5*cos^2(x)+0.5*cos^2(y)), and implement it as nested SumFunction. - * Validation against 1. - */ -struct SumFunctionTestSuite -{ - bool check() - { - const int DDIM=2; - const int RDIM=2; - - const int n_testpoints=100; - - typedef Dune::FieldVector<double,DDIM> DomainType; - typedef Dune::FieldVector<double,RDIM> RangeType; - - typedef TrigFunctionSquared<DomainType,RangeType> TFType; - - TFType sin2x(0,TFType::SIN); - TFType sin2y(1,TFType::SIN); - TFType cos2x(0,TFType::COS); - TFType cos2y(1,TFType::COS); - - SumFunction<DomainType,RangeType> sumfunction1; - sumfunction1.registerFunction(0.5, sin2x); - sumfunction1.registerFunction(0.5, sin2y); - SumFunction<DomainType,RangeType> sumfunction2; - sumfunction2.registerFunction(0.5, cos2x); - sumfunction2.registerFunction(0.5, cos2y); - SumFunction<DomainType,RangeType> sumfunction; - sumfunction.registerFunction(1.0,sumfunction1); - sumfunction.registerFunction(1.0,sumfunction2); - - SumFunction<DomainType,RangeType> checkfunction; - checkfunction.registerFunction(1.0,sin2x); - checkfunction.registerFunction(1.0,cos2x); - - DomainType x(0.0); - RangeType y(0.0), - ycheck(0.0); - for (int run=0; run<n_testpoints; ++run) - { - for (int dcomp=0; dcomp<DDIM; ++dcomp) - x[dcomp] = (6.3*rand())/RAND_MAX - 3.15; - - sumfunction.evaluate(x,y); - checkfunction.evaluate(x,ycheck); - - for (int rcomp=0; rcomp<RDIM; ++rcomp) - if (y[rcomp]-1.0>1e-12) - { - std::cout << "(0.5*sin^2(x)+0.5*sin^2(y)) + (0.5*cos^2(x)+0.5*cos^2(y)) = " << y[rcomp] << std::endl; - std::cout << "check: sin^2(x)+cos^2(x) = " << ycheck[rcomp] << std::endl; - - return false; - } - } - - return true; - } -}; - -/** \brief TestSuite for SumGridFunction - * - * Use partition of 1 as above for P1 GridFunctions. They still should add up to 1 everywhere. - * - */ -struct SumGridFunctionTestSuite -{ - template <class GridType> - bool check(GridType& grid) - { - const int RDIM=2; - - typedef typename GridType::template Codim<0>::Geometry::GlobalCoordinate DomainType; - typedef Dune::FieldVector<double,RDIM> RangeType; - - typedef TrigFunctionSquared<DomainType,RangeType> TFType; - - TFType sin2x(0,TFType::SIN); - TFType sin2y(1,TFType::SIN); - TFType cos2x(0,TFType::COS); - TFType cos2y(1,TFType::COS); - - typedef DuneFunctionsBasis<Dune::Functions::LagrangeBasis<typename GridType::LeafGridView,1 > > Basis; - Basis basis(grid.leafGridView()); - - typedef Dune::BlockVector<RangeType> CoeffType; - CoeffType coeffs1(basis.size()), - coeffs2(basis.size()), - coeffs3(basis.size()), - coeffs4(basis.size()); - - typedef BasisGridFunction<Basis,CoeffType> GridFunctionType; - - CoeffType sumVector; - - Functions::interpolate(basis,coeffs1,sin2x); - GridFunctionType summand1(basis,coeffs1); - sumVector = coeffs1; - Functions::interpolate(basis,coeffs2,sin2y); - GridFunctionType summand2(basis,coeffs2); - sumVector += coeffs2; - Functions::interpolate(basis,coeffs3,cos2x); - GridFunctionType summand3(basis,coeffs3); - sumVector += coeffs3; - Functions::interpolate(basis,coeffs4,cos2y); - GridFunctionType summand4(basis,coeffs4); - sumVector += coeffs4; - - for (size_t i=0; i<basis.size();++i) - for (int j=0; j<RDIM; ++j) - if (std::abs(sumVector[i][j]-2.0) > 1e-12 ) - { - std::cout << i << ", " << j << ": " << sumVector[i][j] << std::endl; - return false; - } - - SumGridFunction<GridType,RangeType> sumfunction1(grid); - sumfunction1.registerFunction(0.5, summand1); - sumfunction1.registerFunction(0.5, summand2); - SumGridFunction<GridType,RangeType> sumfunction2(grid); - sumfunction2.registerFunction(0.5, summand3); - sumfunction2.registerFunction(0.5, summand4); - SumGridFunction<GridType,RangeType> sumfunction(grid); - sumfunction.registerFunction(1.0,sumfunction1); - sumfunction.registerFunction(1.0,sumfunction2); - - SumGridFunction<GridType,RangeType> checkfunction(grid); - checkfunction.registerFunction(1.0, summand1); - checkfunction.registerFunction(1.0, summand3); - - std::function<RangeType(DomainType)> one = [](DomainType x) -> RangeType { return RangeType(1.0); }; - - return compareEvaluateByGridViewQuadrature(sumfunction, one, grid.leafGridView(), 3); - } -}; - -int main(int argc, char** argv) -{ - Dune::MPIHelper::instance(argc, argv); - - std::cout << "This is the SumFunctionTest" << std::endl; - - SumFunctionTestSuite sftests; - SumGridFunctionTestSuite sgftests; - - bool passed = sftests.check(); - if (passed) - std::cout << "SumFunction test passed" << std::endl; - else - std::cout << "SumFunction test failed" << std::endl; - -#if HAVE_DUNE_UGGRID - passed = passed and checkWithAdaptiveGrid<Dune::UGGrid<2> >(sgftests, 3, 3); - if (not passed) - std::cout << "SumGridFunction test failed on locally refined UGGrid<2>." << std::endl; -#if HAVE_DUNE_SUBGRID - passed = passed and checkWithSubGrid<Dune::UGGrid<2> >(sgftests, 3, 3, "SubGrid< 2,UGGrid<2> >"); - if (not passed) - std::cout << "SumGridFunction test failed on locally refined SubGrid< 2,UGGrid<2> >." << std::endl; -#endif -#endif - -#if HAVE_DUNE_ALUGRID - passed = passed and checkWithAdaptiveGrid<Dune::ALUGrid<2,2, Dune::simplex, Dune::nonconforming> >(sgftests, 3, 3); - if (not passed) - std::cout << "SumGridFunction test failed on locally refined ALUGrid<2,2,simplex,nonconforming>." << std::endl; -#if HAVE_DUNE_SUBGRID - passed = passed and checkWithSubGrid<Dune::ALUGrid<2,2, Dune::simplex, Dune::nonconforming> >(sgftests, 3, 3, "SubGrid< 3,ALUGrid<...> >"); - if (not passed) - std::cout << "SumGridFunction test failed on locally refined SubGrid< 2,ALUGrid<2,2,simplex,nonconforming> >." << std::endl; -#endif -#endif - - - return passed ? 0 : 1; - -}