Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • bugfix/any_hh-use_std_remove_const
  • bugfix/matrix-size-in-dune-functions-assembler
  • bugfix/test-memory-leak
  • debug/functionspacebasistest
  • experimental/test-core-ci
  • face_hierarchy
  • feature/DG-Transferoperator-Assembler
  • feature/dune-functions-assembler-with-skeleton
  • feature/dune-functions-assemblers
  • feature/elastictensor-interface
  • feature/exploit-tensor-quadrature
  • feature/handout-wrapped-functionsbasis
  • feature/matrix-free-wip
  • feature/no-auto-ptr-via-boost
  • feature/powerBasis
  • feature/thread-parallel-assembler
  • feature/update-ci
  • improve_grid
  • introduce-periodic-basis
  • master
  • maxka/conformingbasis
  • missing-include
  • move-makefunction-to-namespace-dune-fufem
  • pipping/dune-fufem-feature/heterogeneous-second-order
  • releases/2.0-1
  • releases/2.1-1
  • releases/2.2-1
  • releases/2.3-1
  • releases/2.3-2
  • releases/2.4-1
  • releases/2.4-2
  • releases/2.5-1
  • releases/2.6-1
  • releases/2.7
  • releases/2.8
  • releases/2.9
  • subgridassembler-rework
  • temp/test-CI-with-subgrid-enabled
  • test/use-default-ci-setup
  • tobias-patches
  • tobias-patches-membrane
  • work-matrixindexset
  • subversion->git
43 results

Target

Select target project
  • lisa_julia.nebel_at_tu-dresden.de/dune-fufem
  • akbib/dune-fufem
  • patrick.jaap_at_tu-dresden.de/dune-fufem
  • burchardt_at_igpm.rwth-aachen.de/dune-fufem
4 results
Select Git revision
  • bugfix/matrix-size-in-dune-functions-assembler
  • debug/functionspacebasistest
  • experimental/test-core-ci
  • feature/DG-Transferoperator-Assembler
  • feature/assemble-transfer-operator-with-powerbasis
  • feature/dune-functions-assembler-with-skeleton
  • feature/dune-functions-assemblers
  • feature/elastictensor-interface
  • feature/matrix-free-wip
  • feature/no-auto-ptr-via-boost
  • feature/powerBasis
  • improve_grid
  • lisa-master
  • master
  • maxka/conformingbasis
  • missing-include
  • move-makefunction-to-namespace-dune-fufem
  • releases/2.0-1
  • releases/2.1-1
  • releases/2.2-1
  • releases/2.3-1
  • releases/2.3-2
  • releases/2.4-1
  • releases/2.4-2
  • releases/2.5-1
  • releases/2.6-1
  • releases/2.7
  • subgridassembler-rework
  • temp/test-CI-with-subgrid-enabled
  • subversion->git
30 results
Show changes
Showing
with 304 additions and 861 deletions
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <dune/fufem/python/module.hh> #include <dune/fufem/python/module.hh>
#include <dune/fufem/python/common.hh> #include <dune/fufem/python/common.hh>
#include <dune/fufem/python/conversion.hh> #include <dune/fufem/python/conversion.hh>
#include <dune/fufem/python/function.hh>
#else #else
#warning dunepython.hh was included but python was not found or enabled! #warning dunepython.hh was included but python was not found or enabled!
......
...@@ -35,7 +35,7 @@ class ErrorFractionMarkingStrategy ...@@ -35,7 +35,7 @@ class ErrorFractionMarkingStrategy
//! Layout class for a all codim all geometry type mapper //! Layout class for a all codim all geometry type mapper
struct AllCodimLayout { struct AllCodimLayout {
bool operator() (Dune::GeometryType gt DUNE_UNUSED, int) const { bool operator() ([[maybe_unused]] Dune::GeometryType gt, int) const {
return true; return true;
} }
}; };
...@@ -81,7 +81,7 @@ mark(const std::vector<RefinementIndicator<GridType>*>& refinementIndicators, ...@@ -81,7 +81,7 @@ mark(const std::vector<RefinementIndicator<GridType>*>& refinementIndicators,
const std::vector<GridType*>& grids, const std::vector<GridType*>& grids,
double fraction) double fraction)
{ {
typedef typename Dune::LeafMultipleCodimMultipleGeomTypeMapper<GridType> AllCodimMapper; typedef typename Dune::MultipleCodimMultipleGeomTypeMapper<typename GridType::LeafGridView> AllCodimMapper;
typedef typename std::multimap<double, std::pair<int,int>, std::greater<double> > ErrorMap; typedef typename std::multimap<double, std::pair<int,int>, std::greater<double> > ErrorMap;
if (grids.size() != refinementIndicators.size()) if (grids.size() != refinementIndicators.size())
......
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
GridType& grid, GridType& grid,
field_type fraction); field_type fraction);
DUNE_DEPRECATED_MSG("Please use a std::shared_ptr for the refinementIndicator") [[deprecated("Please use a std::shared_ptr for the refinementIndicator")]]
static void mark(const std::vector<RefinementIndicator<GridType>* >& refinementIndicator, static void mark(const std::vector<RefinementIndicator<GridType>* >& refinementIndicator,
const std::vector<GridType*>& grids, const std::vector<GridType*>& grids,
field_type fraction); field_type fraction);
...@@ -109,7 +109,7 @@ mark(const std::vector<std::shared_ptr<RefinementIndicator<GridType> > >& refine ...@@ -109,7 +109,7 @@ mark(const std::vector<std::shared_ptr<RefinementIndicator<GridType> > >& refine
minGridError[i] = std::numeric_limits<field_type>::max(); minGridError[i] = std::numeric_limits<field_type>::max();
maxGridError[i] = -std::numeric_limits<field_type>::max(); maxGridError[i] = -std::numeric_limits<field_type>::max();
Dune::LeafMultipleCodimMultipleGeomTypeMapper<GridType> p0Mapper(*grids[i], Dune::mcmgElementLayout()); Dune::MultipleCodimMultipleGeomTypeMapper<typename GridType::LeafGridView> p0Mapper(grids[i]->leafGridView(), Dune::mcmgElementLayout());
const auto& leafView = grids[i]->leafGridView(); const auto& leafView = grids[i]->leafGridView();
...@@ -169,7 +169,7 @@ mark(const std::vector<std::shared_ptr<RefinementIndicator<GridType> > >& refine ...@@ -169,7 +169,7 @@ mark(const std::vector<std::shared_ptr<RefinementIndicator<GridType> > >& refine
for (size_t i=0; i<grids.size(); i++) { for (size_t i=0; i<grids.size(); i++) {
Dune::LeafMultipleCodimMultipleGeomTypeMapper<GridType> p0Mapper(*grids[i], Dune::mcmgElementLayout()); Dune::MultipleCodimMultipleGeomTypeMapper<typename GridType::LeafGridView> p0Mapper(grids[i]->leafGridView(), Dune::mcmgElementLayout());
for (const auto& e : elements(grids[i]->leafGridView())) for (const auto& e : elements(grids[i]->leafGridView()))
if (refinedElements[i][p0Mapper.index(e)][0]) if (refinedElements[i][p0Mapper.index(e)][0])
......
#ifndef DUNE_FUFEM_FORMATSTRING_HH #ifndef DUNE_FUFEM_FORMATSTRING_HH
#define DUNE_FUFEM_FORMATSTRING_HH #define DUNE_FUFEM_FORMATSTRING_HH
#include <cstdio> #warning This file is deprecated! Please use Dune::formatString from the file dune/common/stringutility.hh!
#include <dune/common/exceptions.hh> #include <string>
#include <dune/common/stringutility.hh>
namespace Dune { namespace Dune {
namespace Fufem { namespace Fufem {
...@@ -16,39 +18,10 @@ namespace Fufem { ...@@ -16,39 +18,10 @@ namespace Fufem {
* \returns Result of conversion as string * \returns Result of conversion as string
*/ */
template<class... T> template<class... T>
[[deprecated("Please use Dune::formatString() from dune/dommon/stringutility.hh a replacement.")]]
std::string formatString(const std::string& s, const T&... args) std::string formatString(const std::string& s, const T&... args)
{ {
static const int bufferSize=1000; return Dune::formatString(s, args...);
char buffer[bufferSize];
int r = std::snprintf(buffer, bufferSize, s.c_str(), args...);
// negative return values correspond to errors
if (r<0)
DUNE_THROW(Dune::Exception,"Could not convert format string using given arguments.");
// if buffer was large enough return result as string
if (r<bufferSize)
return std::string(buffer);
// if buffer was to small allocate a larger buffer using
// the returned size hint +1 for the terminating 0-byte.
int dynamicBufferSize = r+1;
char* dynamicBuffer = new char[dynamicBufferSize];
// convert and check for errors again
r = std::snprintf(dynamicBuffer, dynamicBufferSize, s.c_str(), args...);
if (r<0)
DUNE_THROW(Dune::Exception,"Could not convert format string using given arguments.");
// the new buffer should always be large enough
assert(r<dynamicBufferSize);
// convert result to string, release buffer, return result
std::string result(dynamicBuffer);
delete[] dynamicBuffer;
return result;
} }
} }
......
...@@ -4,20 +4,12 @@ install(FILES ...@@ -4,20 +4,12 @@ install(FILES
basisgridfunction.hh basisgridfunction.hh
cachedcomponentwrapper.hh cachedcomponentwrapper.hh
coarsegridfunctionwrapper.hh coarsegridfunctionwrapper.hh
composedfunction.hh
composedgridfunction.hh
constantfunction.hh
deformationfunction.hh deformationfunction.hh
localbasisderivativefunction.hh localbasisderivativefunction.hh
localbasisjacobianfunction.hh localbasisjacobianfunction.hh
polynomial.hh
portablegreymap.hh portablegreymap.hh
portablepixelmap.hh portablepixelmap.hh
sumfunction.hh vintagebasisgridfunction.hh
sumgridfunction.hh
virtualdifferentiablefunction.hh virtualdifferentiablefunction.hh
virtualfunctiontoboundarysegmentadapter.hh
virtualgridfunction.hh virtualgridfunction.hh
vtkbasisgridfunction.hh
vtkvirtualfunction.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/fufem/functions) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/fufem/functions)
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <dune/common/function.hh>
#include <dune/geometry/referenceelements.hh> #include <dune/geometry/referenceelements.hh>
#include <dune/fufem/functions/cachedcomponentwrapper.hh> #include <dune/fufem/functions/cachedcomponentwrapper.hh>
...@@ -29,9 +27,7 @@ ...@@ -29,9 +27,7 @@
* \tparam LocalBasis The local basis type * \tparam LocalBasis The local basis type
*/ */
template <class Entity, class FE, class Base template <class Entity, class FE, class Base
=typename Dune::Function< = typename FE::Traits::LocalBasisType::Traits>
const typename FE::Traits::LocalBasisType::Traits::DomainType&,
typename FE::Traits::LocalBasisType::Traits::RangeType&> >
class AlienElementLocalBasisFunction : class AlienElementLocalBasisFunction :
public CachedComponentWrapper<AlienElementLocalBasisFunction<Entity, FE, Base>, public CachedComponentWrapper<AlienElementLocalBasisFunction<Entity, FE, Base>,
typename std::vector<typename FE::Traits::LocalBasisType::Traits::RangeType>, typename std::vector<typename FE::Traits::LocalBasisType::Traits::RangeType>,
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <dune/common/function.hh>
#include <dune/common/fvector.hh> #include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
...@@ -114,11 +113,10 @@ struct Components<typename std::vector<T> > ...@@ -114,11 +113,10 @@ struct Components<typename std::vector<T> >
* by providing a cache for the evaluation of all functions. * by providing a cache for the evaluation of all functions.
* *
* \tparam Imp Implementation providing the evaluateAll method * \tparam Imp Implementation providing the evaluateAll method
* \tparam FunctionBaseClass The base class for this wrapper * \tparam FunctionBaseClass This once was used as a base class. Now it just provides DomainType and RangeType
*/ */
template <class Imp, class AllRangeType, class FunctionBaseClass> template <class Imp, class AllRangeType, class FunctionBaseClass>
class CachedComponentWrapper : class CachedComponentWrapper
public FunctionBaseClass
{ {
public: public:
typedef typename FunctionBaseClass::DomainType DomainType; typedef typename FunctionBaseClass::DomainType DomainType;
...@@ -175,6 +173,13 @@ class CachedComponentWrapper : ...@@ -175,6 +173,13 @@ class CachedComponentWrapper :
} }
} }
RangeType operator()(const DomainType& x) const
{
RangeType y;
evaluate(x,y);
return y;
}
protected: protected:
const Imp& asImp () const const Imp& asImp () const
......
// -*- 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
#include <dune/common/function.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 Dune::VirtualFunction<AT, CT>
{
typedef Dune::VirtualFunction<AT, CT> BaseType;
public:
typedef typename BaseType::DomainType DomainType;
typedef typename BaseType::RangeType RangeType;
typedef Dune::VirtualFunction<AT,BT> InnerFunctionType;
typedef Dune::VirtualFunction<BT,CT> OuterFunctionType;
/** \brief Constructor
*
* \param f_ outer function for composition
* \param g_ inner function for composition
*/
ComposedFunction(const OuterFunctionType& f_, const InnerFunctionType& g_) :
f(f_),
g(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
*/
virtual void evaluate(const DomainType& x, RangeType& y) const
{
BT ytemp;
g.evaluate(x,ytemp);
f.evaluate(ytemp,y);
}
~ComposedFunction(){}
private:
const OuterFunctionType& f;
const InnerFunctionType& g;
};
#endif
// -*- 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
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set ts=8 sw=4 et sts=4:
#ifndef CONSTANT_FUNCTION_HH
#define CONSTANT_FUNCTION_HH
#include <type_traits>
#include <dune/fufem/functions/virtualdifferentiablefunction.hh>
/** \brief A class wrapping a constant function
*
* \tparam DT DomainType
* \tparam RT RangeType
*/
template < class DT, class RT >
class ConstantFunction:
public VirtualDifferentiableFunction<DT,RT>
{
typedef VirtualDifferentiableFunction<DT,RT> BaseType;
// The following two methods provide the actual
// implementation of evaluateDerivative().
// In general there is only a special method for
// the dummy type DerivativeTypeNotImplemented
// that does not change the DerivativeType object
// handed to it. This is necessary if there is
// no proper type available for the implementation
// of the derivative.
//
// Only if the DerivativeType is not equal to
// DerivativeTypeNotImplemented (i.e. if there
// is an implementation of the derivative)
// we enable a method that sets the DerivativeType
// object to zero.
//
// We could also change the base class in the
// former case using enable_if with template
// specialization in the following way:
//
// template < class DT, class RT , class SFINAE_DUMMY=void>
// class ConstantFunction:
// public VirtualDifferentiableFunction<DT,RT>
// {
// [...]
// };
//
//
// template < class DT, class RT >
// class ConstantFunction <DT, RT,
// typename std::enable_if<
// std::is_same< typename DerivativeTypefier<DT, RT>::DerivativeType, DerivativeTypeNotImplemented>::value
// >::type >:
// public Dune::VirtualFunction<DT,RT>
// {
// [...]
// };
static void setDerivativeZero(DerivativeTypeNotImplemented& d)
{}
template<class T, typename std::enable_if<not(std::is_same<T, DerivativeTypeNotImplemented>::value),int >::type=0>
static void setDerivativeZero(T& d)
{
d=0;
}
public:
typedef typename BaseType::DomainType DomainType;
typedef typename BaseType::RangeType RangeType;
typedef typename BaseType::DerivativeType DerivativeType;
/** \brief Constructor
*
* \param constant Value of the constant function
*/
ConstantFunction(const RangeType constant):
constant_(constant)
{}
/** \brief evaluate function
*
* \param x the point at which to evaluate
* \param y variable to store result in
*/
virtual void evaluate(const DomainType& x, RangeType& y) const
{
y = constant_;
return;
}
/** \brief evaluate derivative
*
* \param x the point at which to evaluate
* \param d object to store result in
*/
virtual void evaluateDerivative(const DomainType& x, DerivativeType& d) const
{
setDerivativeZero(d);
return;
}
private:
const RangeType constant_;
};
#endif
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
@author graeser@math.fu-berlin.de @author graeser@math.fu-berlin.de
*/ */
#include <dune/common/function.hh>
#include <dune/fufem/functions/localbasisjacobianfunction.hh> #include <dune/fufem/functions/localbasisjacobianfunction.hh>
...@@ -18,9 +16,7 @@ ...@@ -18,9 +16,7 @@
* \tparam LocalBasis The local basis type * \tparam LocalBasis The local basis type
*/ */
template <class FE, class Base template <class FE, class Base
=typename Dune::Function< = typename FE::Traits::LocalBasisType::Traits>
const typename FE::Traits::LocalBasisType::Traits::DomainType&,
typename FE::Traits::LocalBasisType::Traits::RangeType&> >
class LocalBasisDerivativeFunction : class LocalBasisDerivativeFunction :
public Base public Base
{ {
...@@ -76,6 +72,11 @@ class LocalBasisDerivativeFunction : ...@@ -76,6 +72,11 @@ class LocalBasisDerivativeFunction :
y = D[0][j_]; y = D[0][j_];
} }
RangeType operator()(const DomainType& x) const
{
return jacobianFunction_(x)[0][j_];
}
private: private:
JacobianFunction jacobianFunction_; JacobianFunction jacobianFunction_;
int j_; int j_;
......
...@@ -10,19 +10,22 @@ ...@@ -10,19 +10,22 @@
#include <vector> #include <vector>
#include <dune/common/function.hh>
#include <dune/fufem/functions/cachedcomponentwrapper.hh> #include <dune/fufem/functions/cachedcomponentwrapper.hh>
namespace Impl {
template<class FE>
struct LFEJacobianFunctionTraits {
using DomainType = typename FE::Traits::LocalBasisType::Traits::DomainType;
using RangeType = typename FE::Traits::LocalBasisType::Traits::JacobianType;
};
}
/** \brief Wrap partial derivative of local basis functions /** \brief Wrap partial derivative of local basis functions
* *
* \tparam FE The local finite element type * \tparam FE The local finite element type
*/ */
template <class FE, class Base template <class FE, class Base
=typename Dune::Function< = Impl::LFEJacobianFunctionTraits<FE>>
const typename FE::Traits::LocalBasisType::Traits::DomainType&,
typename FE::Traits::LocalBasisType::Traits::JacobianType&> >
class LocalBasisJacobianFunction : class LocalBasisJacobianFunction :
public CachedComponentWrapper< public CachedComponentWrapper<
LocalBasisJacobianFunction<FE, Base>, LocalBasisJacobianFunction<FE, Base>,
......
// -*- 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
{
d = 0.0;
for (int k=degree_; k>=1; --k)
d = x*d + dCoeff(1,k)*coeffs_[k];
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
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
#include <dune/grid/yaspgrid.hh> #include <dune/grid/yaspgrid.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
#include <dune/fufem/functions/virtualgridfunction.hh> #include <dune/fufem/functions/virtualgridfunction.hh>
#include <dune/fufem/functions/basisgridfunction.hh>
#include <dune/fufem/functionspacebases/q1nodalbasis.hh>
/** \brief Class wrapping a greymap (acquired from PGM ASCII (P2)-files) providing it as a piecewise bi-linear GridFunction /** \brief Class wrapping a greymap (acquired from PGM ASCII (P2)-files) providing it as a piecewise bi-linear GridFunction
* *
...@@ -37,10 +38,10 @@ class PortableGreyMap: ...@@ -37,10 +38,10 @@ class PortableGreyMap:
typedef BaseType::RangeType RangeType; typedef BaseType::RangeType RangeType;
typedef BaseType::DerivativeType DerivativeType; typedef BaseType::DerivativeType DerivativeType;
typedef Q1NodalBasis<GridType::LeafGridView> Basis; typedef Dune::Functions::LagrangeBasis<GridType::LeafGridView, 1> Basis;
typedef Dune::BlockVector<RangeType> CoeffType; typedef Dune::BlockVector<RangeType> CoeffType;
typedef BasisGridFunction<Basis, CoeffType> FunctionType; using FunctionType = Dune::Functions::DiscreteGlobalBasisFunction<Basis,CoeffType,Dune::Functions::HierarchicNodeToRangeMap,RangeType>;
/** An enum identifying the employed color scheme. /** An enum identifying the employed color scheme.
*/ */
...@@ -205,7 +206,7 @@ class PortableGreyMap: ...@@ -205,7 +206,7 @@ class PortableGreyMap:
basis_ = new Basis(grid_->leafGridView()); basis_ = new Basis(grid_->leafGridView());
coeffs_.resize(basis_->size()); coeffs_.resize(basis_->size());
coeffs_ = 0.0; coeffs_ = 0.0;
greyMapFunction_ = new FunctionType(*basis_, coeffs_); greyMapFunction_ = new FunctionType(Dune::Functions::makeDiscreteGlobalBasisFunction<RangeType>(*basis_, coeffs_));
if (pgmID == "P2") if (pgmID == "P2")
{ {
...@@ -335,8 +336,7 @@ class PortableGreyMap: ...@@ -335,8 +336,7 @@ class PortableGreyMap:
xx[0] = (x[0]-xDomainMin_)/(xDomainMax_-xDomainMin_)*(width_-1); xx[0] = (x[0]-xDomainMin_)/(xDomainMax_-xDomainMin_)*(width_-1);
xx[1] = (x[1]-yDomainMin_)/(yDomainMax_-yDomainMin_)*(height_-1); xx[1] = (x[1]-yDomainMin_)/(yDomainMax_-yDomainMin_)*(height_-1);
RangeType r = 0.0; RangeType r = (*greyMapFunction_)(xx);
greyMapFunction_->evaluate(xx,r);
y = fRangeMin_ + (colorscheme_==DEFAULT ? r/imgParams_[2] : (1-r/imgParams_[2]))*(fRangeMax_-fRangeMin_); y = fRangeMin_ + (colorscheme_==DEFAULT ? r/imgParams_[2] : (1-r/imgParams_[2]))*(fRangeMax_-fRangeMin_);
return; return;
...@@ -355,8 +355,9 @@ class PortableGreyMap: ...@@ -355,8 +355,9 @@ class PortableGreyMap:
if (greyMapFunction_==0) if (greyMapFunction_==0)
DUNE_THROW(Dune::Exception,"No greymap has been loaded. Use readGreyMap() first."); DUNE_THROW(Dune::Exception,"No greymap has been loaded. Use readGreyMap() first.");
RangeType r = 0.0; auto localGreyMapFunction = localFunction(*greyMapFunction_);
greyMapFunction_->evaluateLocal(ntt,x,r); localGreyMapFunction.bind(ntt);
RangeType r = localGreyMapFunction(x);
y = fRangeMin_ + (colorscheme_==DEFAULT ? r/imgParams_[2] : (1-r/imgParams_[2]))*(fRangeMax_-fRangeMin_); y = fRangeMin_ + (colorscheme_==DEFAULT ? r/imgParams_[2] : (1-r/imgParams_[2]))*(fRangeMax_-fRangeMin_);
return; return;
...@@ -371,7 +372,7 @@ class PortableGreyMap: ...@@ -371,7 +372,7 @@ class PortableGreyMap:
* \param x point (global coordinates) at which to evaluate the derivative * \param x point (global coordinates) at which to evaluate the derivative
* \param d will contain the derivative at x after return * \param d will contain the derivative at x after return
*/ */
virtual void evaluateDerivative(const DomainType& x DUNE_UNUSED, DerivativeType& d DUNE_UNUSED) const virtual void evaluateDerivative([[maybe_unused]] const DomainType& x, [[maybe_unused]] DerivativeType& d) const
{ {
DUNE_THROW(Dune::NotImplemented, "Derivative not implemented"); DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
} }
...@@ -382,7 +383,7 @@ class PortableGreyMap: ...@@ -382,7 +383,7 @@ class PortableGreyMap:
* \param x point in local coordinates at which to evaluate the derivative * \param x point in local coordinates at which to evaluate the derivative
* \param d will contain the derivative at x after return * \param d will contain the derivative at x after return
*/ */
virtual void evaluateDerivativeLocal(const Element& e DUNE_UNUSED, const LocalDomainType& x DUNE_UNUSED, DerivativeType& d DUNE_UNUSED) const virtual void evaluateDerivativeLocal([[maybe_unused]] const Element& e, [[maybe_unused]] const LocalDomainType& x, [[maybe_unused]] DerivativeType& d) const
{ {
DUNE_THROW(Dune::NotImplemented, "Derivative not implemented"); DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
} }
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <dune/grid/yaspgrid.hh> #include <dune/grid/yaspgrid.hh>
#include <dune/fufem/functions/basisgridfunction.hh> #include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/fufem/functionspacebases/q1nodalbasis.hh> #include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
/** \brief Class to represent a color map /** \brief Class to represent a color map
* *
...@@ -514,10 +514,10 @@ class PortablePixelMap: ...@@ -514,10 +514,10 @@ class PortablePixelMap:
typedef BaseType::RangeType RangeType; typedef BaseType::RangeType RangeType;
typedef BaseType::DerivativeType DerivativeType; typedef BaseType::DerivativeType DerivativeType;
typedef Q1NodalBasis<GridType::LeafGridView> Basis; typedef Dune::Functions::LagrangeBasis<GridType::LeafGridView, 1> Basis;
typedef Dune::BlockVector<RangeType> CoeffType; typedef Dune::BlockVector<RangeType> CoeffType;
typedef BasisGridFunction<Basis, CoeffType> FunctionType; using FunctionType = Dune::Functions::DiscreteGlobalBasisFunction<Basis,CoeffType,Dune::Functions::HierarchicNodeToRangeMap,RangeType>;
/** An enum for the data format of exported grafix files /** An enum for the data format of exported grafix files
...@@ -688,7 +688,7 @@ class PortablePixelMap: ...@@ -688,7 +688,7 @@ class PortablePixelMap:
basis_ = new Basis(grid_->leafGridView()); basis_ = new Basis(grid_->leafGridView());
coeffs_.resize(basis_->size()); coeffs_.resize(basis_->size());
coeffs_ = 0.0; coeffs_ = 0.0;
pixMapFunction_ = new FunctionType(*basis_,coeffs_); pixMapFunction_ = new FunctionType(Dune::Functions::makeDiscreteGlobalBasisFunction<RangeType>(*basis_, coeffs_));
/* if it's the binary format we need to open in binary mode */ /* if it's the binary format we need to open in binary mode */
if (ppmID == "P6") if (ppmID == "P6")
...@@ -850,7 +850,7 @@ class PortablePixelMap: ...@@ -850,7 +850,7 @@ class PortablePixelMap:
xx[0] = (x[0]-xDomainMin_)/(xDomainMax_-xDomainMin_)*(width_-1); xx[0] = (x[0]-xDomainMin_)/(xDomainMax_-xDomainMin_)*(width_-1);
xx[1] = (x[1]-yDomainMin_)/(yDomainMax_-yDomainMin_)*(height_-1); xx[1] = (x[1]-yDomainMin_)/(yDomainMax_-yDomainMin_)*(height_-1);
pixMapFunction_->evaluate(xx,y); y = (*pixMapFunction_)(xx);
return; return;
} }
...@@ -868,7 +868,9 @@ class PortablePixelMap: ...@@ -868,7 +868,9 @@ class PortablePixelMap:
if (pixMapFunction_==0) if (pixMapFunction_==0)
DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first."); DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
pixMapFunction_->evaluateLocal(ntt,x,y); auto localPixMapFunction = localFunction(*pixMapFunction_);
localPixMapFunction.bind(ntt);
y = localPixMapFunction(x);
return; return;
} }
......
// -*- 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
// -*- 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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_FUFEM_FUNCTIONS_VINTAGEBASISGRIDFUNCTION_HH
#define DUNE_FUFEM_FUNCTIONS_VINTAGEBASISGRIDFUNCTION_HH
#include <type_traits>
#include <optional>
#include <memory>
#include <dune/common/shared_ptr.hh>
#include <dune/common/exceptions.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/functions/gridfunctions/gridfunction.hh>
#include <dune/fufem/functions/basisgridfunction.hh>
namespace Dune::Fufem {
namespace Impl {
/**
* \brief A dune-functions grid function implemented using a dune-fufem basis
*
* This allows to use a dune-fufem basis as dune-functions
* grid function. Moreover you can customize the local function
* evaluation.
*/
template<typename B, typename V, typename LEV, typename R = typename V::value_type>
class VintageBasisGridFunction
{
public:
using Basis = B;
using Vector = V;
using LocalEvaluator = LEV;
using Coefficient = std::decay_t<decltype(std::declval<Vector>()[0])>;
using GridView = typename Basis::GridView;
using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
using Domain = typename EntitySet::GlobalCoordinate;
using Range = R;
using LocalDomain = typename EntitySet::LocalCoordinate;
using Element = typename EntitySet::Element;
using Traits = Dune::Functions::Imp::GridFunctionTraits<Range(Domain), EntitySet, Dune::Functions::DefaultDerivativeTraits, 16>;
class LocalFunction
{
public:
using GlobalFunction = VintageBasisGridFunction;
using Domain = GlobalFunction::LocalDomain;
using Range = GlobalFunction::Range;
using Element = GlobalFunction::Element;
LocalFunction(const VintageBasisGridFunction& globalFunction)
: globalFunction_(&globalFunction)
{}
LocalFunction(const LocalFunction& other) = default;
LocalFunction(LocalFunction&& other) = default;
LocalFunction& operator=(const LocalFunction& other) = default;
LocalFunction& operator=(LocalFunction&& other) = default;
/**
* \brief Bind LocalFunction to grid element.
*
* You must call this method before operator()
* and after changes to the coefficient vector.
*/
void bind(const Element& element) {
element_ = element;
}
void unbind() {
element_.reset();
}
bool bound() const {
return static_cast<bool>(element_);
}
Range operator()(const Domain& x) const {
auto y = Range(0);
globalFunction_->localEvaluator()(
globalFunction_->basis(),
globalFunction_->dofs(),
*element_,
x,
y);
return y;
}
const Element& localContext() const {
return *element_;
}
friend typename Traits::LocalFunctionTraits::DerivativeInterface derivative(const LocalFunction& t) {
DUNE_THROW(NotImplemented,"not implemented");
}
private:
const VintageBasisGridFunction* globalFunction_;
std::optional<Element> element_;
};
template<class B_T, class V_T, class LEV_T>
VintageBasisGridFunction(B_T&& basis, V_T&& v, LEV_T&& localEvaluator)
: entitySet_(basis.getGridView())
, basis_(wrap_or_move(std::forward<B_T>(basis)))
, coefficients_(wrap_or_move(std::forward<V_T>(v)))
, localEvaluator_(std::forward<LEV_T>(localEvaluator))
{}
template<class B_T, class V_T>
VintageBasisGridFunction(B_T&& basis, V_T&& v)
: entitySet_(basis.getGridView())
, basis_(wrap_or_move(std::forward<B_T>(basis)))
, coefficients_(wrap_or_move(std::forward<V_T>(v)))
, localEvaluator_()
{}
const Basis& basis() const {
return *basis_;
}
const V& dofs() const {
return *coefficients_;
}
const LEV& localEvaluator() const {
return localEvaluator_;
}
Range operator() (const Domain& x) const {
DUNE_THROW(NotImplemented,"not implemented");
}
friend typename Traits::DerivativeInterface derivative(const VintageBasisGridFunction& t) {
DUNE_THROW(NotImplemented,"not implemented");
}
friend LocalFunction localFunction(const VintageBasisGridFunction& t) {
return LocalFunction(t);
}
const EntitySet& entitySet() const {
return entitySet_;
}
private:
EntitySet entitySet_;
std::shared_ptr<const Basis> basis_;
std::shared_ptr<const V> coefficients_;
LocalEvaluator localEvaluator_;
};
/**
* \brief Construction of local functions from a temporary VintageBasisGridFunction (forbidden)
*
* Since a VintageBasisGridFunction::LocalFunction stores a reference
* to the global VintageBasisGridFunction its life time is bound to
* the latter. Hence construction from a temporary VintageBasisGridFunction
* would lead to a dangling reference and is thus forbidden/deleted.
*/
template<typename... TT>
void localFunction(VintageBasisGridFunction<TT...>&& t) = delete;
} // end namespace Impl
/**
* \brief Create a VintageBasisGridFunction
*
* This allows to use a dune-fufem basis as dune-functions
* grid function. Moreover you can customize the local function
* evaluation.
*
* \tparam R Range type of function
* \tparam B Type of dune-fufem basis
* \tparam V Type of coefficient vector
* \tparam LEV Type of local evaluator
*
* \param basis Dune-fufem basis to interpret the coefficient vector
* \param v Coefficient vector of FE function wrt the given basis
* \param localEvaluator A function doing the local evaluation.
*
* The actual local function implementation is forwarded to the
* callback localEvaluator whose signature
* localEvaluator(basis, coefficients, element, localX, y)
* mimics the LocalEvaluator::evaluateLocal() function.
* By implementing a custom callback you can e.g.
* represent partial derivatives.
*/
template<typename R, typename B, typename V, typename LEV>
auto makeVintageBasisGridFunction(B&& basis, V&& v, LEV&& localEvaluator)
{
using Basis = std::decay_t<B>;
using Vector = std::decay_t<V>;
using LocalEvaluator = std::decay_t<LEV>;
return Impl::VintageBasisGridFunction<Basis, Vector, LocalEvaluator, R>(std::forward<B>(basis), std::forward<V>(v), std::forward<LEV>(localEvaluator));
}
/**
* \brief Create a VintageBasisGridFunction
*
* This allows to use a dune-fufem basis as dune-functions
* grid function.
*
* \tparam R Range type of function
* \tparam B Type of dune-fufem basis
* \tparam V Type of coefficient vector
*
* \param basis Dune-fufem basis to interpret the coefficient vector
* \param v Coefficient vector of FE function wrt the given basis
*/
template<typename R, typename B, typename V>
auto makeVintageBasisGridFunction(B&& basis, V&& v)
{
using Basis = std::decay_t<B>;
using Vector = std::decay_t<V>;
auto localEvaluator = [](const auto& b, const auto& v, const auto&e, const auto& x, auto& y) {
LocalEvaluator<Basis, Vector, R>::evaluateLocal(b, v, e, x, y);
};
using LocalEvaluator = decltype(localEvaluator);
return Impl::VintageBasisGridFunction<Basis, Vector, LocalEvaluator, R>(std::forward<B>(basis), std::forward<V>(v), std::move(localEvaluator));
}
} // end namespace Dune::Fufem
#endif // DUNE_FUFEM_FUNCTIONS_VINTAGEBASISGRIDFUNCTION_HH
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set ts=8 sw=4 et sts=4:
#ifndef VIRTUALFUNCTION_TO_BOUNDARYSEGMENT_ADAPTOR_HH
#define VIRTUALFUNCTION_TO_BOUNDARYSEGMENT_ADAPTOR_HH
#include <memory>
#include <dune/common/fvector.hh>
#include <dune/common/function.hh>
#include <dune/grid/common/boundarysegment.hh>
/**
* \brief Adapter from VirtualFunction to BoundarySegment
*
* \tparam dim Dimension of the grid
* \tparam dimworld World dimension of the grid
*/
template<int dim, int dimworld>
class VirtualFunctionToBoundarySegmentAdapter :
public Dune::BoundarySegment<dim, dimworld>
{
public:
typedef Dune::FieldVector<double,dim-1> DomainType;
typedef Dune::FieldVector<double,dimworld> RangeType;
typedef Dune::VirtualFunction<DomainType, RangeType> FunctionType;
typedef std::shared_ptr<const FunctionType> FunctionSharedPtr;
/**
* \brief Construct an adaptor from VirtualFunction
*
* Since BoundarySegments are in general handed over as shared_ptr
* it needs to control the lifetime of the wrapped function.
* Thus we pass it as shared_ptr.
*
* \param f A VirtualFunction implementation of the boundary parametrization
*/
VirtualFunctionToBoundarySegmentAdapter(const FunctionSharedPtr& f):
f_(f)
{}
virtual RangeType operator() (const DomainType &local) const
{
RangeType global;
f_->evaluate(local, global);
return global;
}
protected:
const FunctionSharedPtr f_;
};
#endif
// -*- c-basic-offset:4 tab-width:4 -*-
#ifndef VTK_BASIS_GRID_FUNCTION_HH
#define VTK_BASIS_GRID_FUNCTION_HH
#include <dune/grid/io/file/vtk/function.hh>
#include <dune/fufem/functions/basisgridfunction.hh>
/** \brief A VTK basis grid function.
*
* This function "evaluates" by evaluating the global basis and interpolating the function values.
* \tparam Basis The global basis.
* \tparam CoefficientType The vector type for the coefficients.
*/
template<class Basis, class CoefficientType>
class VTKBasisGridFunction : public Dune::VTKFunction<typename Basis::GridView>
{
typedef Dune::VTKFunction<typename Basis::GridView> Base;
typedef typename CoefficientType::value_type RangeType;
public:
typedef typename Base::Entity Entity;
typedef typename Base::ctype ctype;
using Base::dim;
/** \brief Construct from given global basis, coefficient vector and name.
*
* \param basis The global basis.
* \param v A corresponding vector of coefficients.
* \param s A name of the function.
*/
VTKBasisGridFunction(const Basis &basis, const CoefficientType &v, const std::string &s) :
basis_(basis),
coeffs_(v),
s_( s )
{
/* Nothing. */
}
/** \brief Get the number of components the function has. */
virtual int ncomps () const
{
return CoefficientType::value_type::dimension;
}
/** \brief Locally evaluate a component of the function.
*
* \param comp The component to evaluate.
* \param e The element the local coordinates are taken from.
* \param xi The local coordinates where to evaluate the function.
*/
virtual double evaluate (int comp, const Entity &e,
const Dune::FieldVector<ctype,dim> &xi) const
{
RangeType y;
// use LocalEvaluator to make function also work for nonconforming bases
LocalEvaluator<Basis, CoefficientType, RangeType>::evaluateLocal(basis_, coeffs_, e, xi, y);
return y[comp];
}
/** \brief Get the name of that function. */
virtual std::string name () const
{
return s_;
}
/** \brief Destructor. */
virtual ~VTKBasisGridFunction() {}
private:
const Basis &basis_;
const CoefficientType &coeffs_;
std::string s_;
};
#endif