2#ifndef DUNE_PDELAB_FUNCTION_HH
3#define DUNE_PDELAB_FUNCTION_HH
8#include <dune/common/deprecated.hh>
9#include <dune/common/exceptions.hh>
10#include <dune/common/typetraits.hh>
11#include <dune/common/shared_ptr.hh>
12#include <dune/common/fvector.hh>
13#include <dune/common/fmatrix.hh>
15#include <dune/grid/utility/hierarchicsearch.hh>
17#include <dune/typetree/typetree.hh>
37 template<
class DF,
int n,
class D,
class RF,
int m,
class R>
68 template<
class T,
class Imp>
80 inline void evaluate (
const typename Traits::DomainType& x,
81 typename Traits::RangeType& y)
const
83 asImp().evaluate(x,y);
87 Imp& asImp () {
return static_cast<Imp &
> (*this);}
88 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
106 template<
typename Time>
112 template<
typename GV>
119 typedef typename GV::Traits::template Codim<0>::Entity
ElementType;
176 template<
class GV,
class RF,
int m,
class R>
179 Dune::FieldVector<typename GV::Grid::ctype,
187 template<
class T,
class Imp>
208 inline void evaluate (
const typename Traits::ElementType& e,
209 const typename Traits::DomainType& x,
210 typename Traits::RangeType& y)
const
212 asImp().evaluate(e,x,y);
218 return asImp().getGridView();
222 Imp& asImp () {
return static_cast<Imp &
> (*this);}
223 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
231 template<
class GV,
class RF,
int m,
class R>
233 :
public FunctionTraits<typename GV::Grid::ctype, GV::dimension-1,
234 Dune::FieldVector<typename GV::Grid::ctype,
246 template<
class T,
class Imp>
264 const typename Traits::DomainType& x,
265 typename Traits::RangeType& y)
const
267 asImp().evaluate(
ig,x,y);
273 return asImp().getGridView();
277 Imp& asImp () {
return static_cast<Imp &
> (*this);}
278 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
298 template<
class T,
class Imp>
301 ,
public TypeTree::LeafNode
325 template<
class T,
class Imp>
328 ,
public TypeTree::LeafNode
343 template<
typename TT>
345 :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
350 template<
typename LeafNode,
typename TreePath>
351 void leaf(LeafNode& node, TreePath treePath)
const
366 template<
class T, std::
size_t k>
368 :
public TypeTree::PowerNode<T,k>
371 typedef TypeTree::PowerNode<T,k> BaseT;
383 template <
typename TT>
386 TypeTree::applyToTree(*
this,visitor);
398 : BaseT(container) {}
458 : BaseT(c0,c1,c2,c3,c4)
468 : BaseT(c0,c1,c2,c3,c4,c5)
479 : BaseT(c0,c1,c2,c3,c4,c5,c6)
491 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7)
504 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8)
518 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
536 template<
typename... Children>
538 :
public TypeTree::CompositeNode<Children...>
541 typedef TypeTree::CompositeNode<Children...> BaseT;
550 typedef typename BaseT::template Child<0>::Type::GridViewType
GridViewType;
556 : BaseT(TypeTree::assertGridViewType<typename BaseT::template Child<0>::Type>(children)...)
565 template <
typename TT>
568 TypeTree::applyToTree(*
this,visitor);
596 GridFunctionBaseAdapter<Imp> >
620 inline void evaluate (
const typename Imp::Traits::ElementType& e,
621 const typename Imp::Traits::DomainType& x,
622 typename Imp::Traits::RangeType& y)
const
628 inline const typename Imp::Traits::GridViewType&
getGridView ()
const
630 return imp.getGridView();
639 template<
typename GV,
typename RF,
int m>
657 template<
typename T,
typename Imp>
668 inline void evaluate (
const typename Traits::ElementType& e,
669 const typename Traits::DomainType& x,
670 typename Traits::RangeType& y)
const
672 asImp().evaluateGlobal(e.geometry().global(x),y);
681 typename Traits::GridViewType g;
682 Imp& asImp () {
return static_cast<Imp &
> (*this);}
683 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
692 typename T::Traits::RangeFieldType,
694 Dune::FieldVector<typename T::Traits::RangeFieldType,1>
696 NormalFluxGridFunctionAdapter<T> >
710 static_assert((
static_cast<int>(T::Traits::GridViewType::dimension)==
static_cast<int>(T::Traits::dimRange)),
"number of components must equal dimension");
713 typename T::Traits::RangeType v;
717 if (!e.geometry().type().isTriangle())
718 DUNE_THROW(Dune::NotImplemented,
"only implemented for triangles");
726 if (std::abs(x[0])<1E-10)
732 nu = e.geometry().corner(n1);
733 nu -= e.geometry().corner(n0);
738 y = v[0]*nu[0]+v[1]*nu[1];
742 if (std::abs(x[1])<1E-10)
748 nu = e.geometry().corner(n1);
749 nu -= e.geometry().corner(n0);
754 y = v[0]*nu[0]+v[1]*nu[1];
758 if (std::abs(x[0]+x[1]-1.0)<1E-10)
764 nu = e.geometry().corner(n1);
765 nu -= e.geometry().corner(n0);
770 y = v[0]*nu[0]+v[1]*nu[1];
774 DUNE_THROW(Dune::Exception,
"x needs to be on an edge");
780 return t->getGridView();
784 std::shared_ptr<T const> t;
802 inline void evaluate (
const typename Traits::ElementType& e,
803 const typename Traits::DomainType& x,
804 typename Traits::RangeType& y)
const
807 typename T::Traits::RangeType v;
811 typename Traits::ElementType::Geometry::JacobianInverseTransposed
812 J = e.geometry().jacobianInverseTransposed(x);
815 y *= e.geometry().integrationElement(x);
821 return t->getGridView();
825 std::shared_ptr<T const> t;
836 template<
typename VTKWriter>
837 struct AddGridFunctionsToVTKWriter
838 :
public TypeTree::TreeVisitor
839 ,
public TypeTree::DynamicTraversal
845 AddGridFunctionsToVTKWriter(VTKWriter& w_,
const std::string & s_) :
848 template<
typename T,
typename TreePath>
849 void leaf(
const T& t, TreePath treePath) {
850 std::stringstream name;
852 for (std::size_t i=0; i < treePath.size(); ++i)
853 name <<
"_" << treePath.element(i);
854 w.addVertexData(std::make_shared< VTKGridFunctionAdapter<T> >(t,name.str()));
865 template<
typename GV,
typename T>
868 AddGridFunctionsToVTKWriter<Dune::VTKWriter<GV> > visitor(
w,
s);
869 TypeTree::applyToTree(t,visitor);
882 template<
typename G,
typename T>
886 typename T::Traits::RangeFieldType,
888 typename T::Traits::RangeType>,
889 FunctionToGridFunctionAdapter<G,T> >
893 typename T::Traits::RangeFieldType,
897 (std::is_same<
typename T::Traits::DomainFieldType,
899 "GridView's and wrapped Functions DomainFieldType don't match");
902 "GridView's and wrapped Functions dimDomain don't match");
904 (std::is_same<
typename T::Traits::DomainType,
906 "GridView's and wrapped Functions DomainType don't match");
919 t.evaluate(e.geometry().global(x),y);
936 template<
typename GF>
938 :
public FunctionInterface<FunctionTraits<typename GF::Traits::GridViewType::ctype,
939 GF::Traits::GridViewType::dimensionworld,
940 Dune::FieldVector<typename GF::Traits::GridViewType::ctype,
941 GF::Traits::GridViewType::dimensionworld
943 typename GF::Traits::RangeFieldType,
944 GF::Traits::dimRange,
945 Dune::FieldVector<typename GF::Traits::RangeFieldType,
946 GF::Traits::dimRange>
948 GridFunctionToFunctionAdapter<GF> >
953 GF::Traits::GridViewType::dimensionworld,
954 Dune::FieldVector<
typename GF::Traits::GridViewType::ctype,
955 GF::Traits::GridViewType::dimensionworld
957 typename GF::Traits::RangeFieldType,
958 GF::Traits::dimRange,
959 Dune::FieldVector<
typename GF::Traits::RangeFieldType,
960 GF::Traits::dimRange>
966 , hsearch(gf.getGridView().grid(), gf.getGridView().indexSet())
977 typename GF::Traits::GridViewType::Grid::Traits::template Codim<0>::Entity
978 e = hsearch.findEntity(x);
979 gf.evaluate(e, e.geometry().local(x), y);
984 const Dune::HierarchicSearch<
typename GF::Traits::GridViewType::Grid,
985 typename GF::Traits::GridViewType::IndexSet> hsearch;
994 template<
typename T,
typename E>
997 GlobalFunctionToLocalFunctionAdapter<T,E> >
1014 inline void evaluate (
const typename Traits::DomainType& x,
1015 typename Traits::RangeType& y)
const
1017 t.evaluate(e.geometry().global(x),y);
1030 template<
typename T>
1033 GridFunctionToLocalFunctionAdapter<T> >
1044 const typename Traits::ElementType& e_)
1052 inline void evaluate (
const typename Traits::DomainType& x,
1053 typename Traits::RangeType& y)
const
1060 const typename Traits::ElementType& e;
1066 class SelectComponentAdapter :
public FunctionInterface<FunctionTraits<typename T::Traits::DomainFieldType,T::Traits::dimDomain,typename T::Traits::DomainType,typename T::Traits::RangeFieldType,1,Dune::FieldVector<typename T::Traits::RangeFieldType,1> > , SelectComponentAdapter<T> >
1080 inline void evaluate (
const typename Traits::DomainType& x,
1081 typename Traits::RangeType& y)
const
1083 typename T::Traits::RangeType Y;
1103 typename T::Traits::RangeFieldType,1,
1104 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
1105 BoundaryGridFunctionSelectComponentAdapter<T> >
1108 typename T::Traits::RangeFieldType,1,
1109 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
1122 template<
typename I>
1124 const typename Traits::DomainType& x,
1125 typename Traits::RangeType& y)
const
1127 typename T::Traits::RangeType Y;
1135 return t.getGridView();
VTKWriter & w
Definition: function.hh:842
const std::string s
Definition: function.hh:843
const IG & ig
Definition: constraints.hh:149
void vtkwriter_tree_addvertexdata(Dune::VTKWriter< GV > &w, const T &t, std::string s="data")
add vertex data from a GridFunctionTree to a VTKWriter
Definition: function.hh:866
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Definition: function.hh:39
@ dimRange
dimension of the range
Definition: function.hh:58
D DomainType
domain type in dim-size coordinates
Definition: function.hh:50
R RangeType
range type
Definition: function.hh:62
DF DomainFieldType
Export type for domain field.
Definition: function.hh:41
RF RangeFieldType
Export type for range field.
Definition: function.hh:53
@ dimDomain
dimension of the domain
Definition: function.hh:46
a Function that maps x in DomainType to y in RangeType
Definition: function.hh:70
T Traits
Export type traits.
Definition: function.hh:73
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:80
Default class for additional methods in instationary functions.
Definition: function.hh:93
void setTime(Time t)
set time for subsequent evaluation
Definition: function.hh:107
GV The type of the grid view the function lives on.
Definition: function.hh:114
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:119
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:116
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:126
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:154
void setDataSetType(Output::DataSetType dataSetType)
Set the data set type of this function.
Definition: function.hh:160
GridFunctionOutputParameters(Output::DataSetType dataSetType=Output::vertexData)
Standard constructor.
Definition: function.hh:149
Namespace for output-related data types and enums.
Definition: function.hh:132
DataSetType
The type of the data set.
Definition: function.hh:139
@ cellData
A data set with cell values.
Definition: function.hh:141
@ vertexData
A data set with vertex values.
Definition: function.hh:140
traits class holding the function signature, same as in local function
Definition: function.hh:183
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:190
T Traits
Export type traits.
Definition: function.hh:193
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the GridFunction at given position.
Definition: function.hh:208
GridFunctionInterface(Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:195
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:216
traits class holding function signature, same as in local function
Definition: function.hh:237
GV GridViewType
Export grid view type in addition.
Definition: function.hh:239
A BoundaryGridFunction allows evaluation on boundary intersections.
Definition: function.hh:248
T Traits
Export type traits of the boundary grid function.
Definition: function.hh:251
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:271
void evaluate(const IntersectionGeometry< I > &ig, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the GridFunction at given position.
Definition: function.hh:263
Definition: function.hh:288
leaf of a function tree
Definition: function.hh:302
typename Base::Output Output
Definition: function.hh:309
GridFunctionTag ImplementationTag
Definition: function.hh:305
GridFunctionBase(typename Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:311
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:307
leaf of a function tree
Definition: function.hh:329
GridFunctionTag ImplementationTag
Definition: function.hh:331
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:333
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:346
TT time
Definition: function.hh:347
void leaf(LeafNode &node, TreePath treePath) const
Definition: function.hh:351
PowerCompositeSetTimeVisitor(const TT time_)
Definition: function.hh:348
Definition: function.hh:357
product of identical functions
Definition: function.hh:369
PowerGridFunction(T &t)
Construct a PowerGridFunction with k clones of the function t.
Definition: function.hh:401
PowerCompositeGridFunctionTraits< typename T::GridViewType > Traits
Definition: function.hh:375
PowerGridFunction()
Definition: function.hh:389
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:384
T::GridViewType GridViewType
record the GridView
Definition: function.hh:380
PowerGridFunction(T &t0, T &t1,...)
Initialize all children with different function objects.
Definition: function.hh:426
PowerGridFunction(const std::array< std::shared_ptr< T >, k > &container)
Construct a new Power Grid Function object.
Definition: function.hh:397
PowerGridFunctionTag ImplementationTag
Definition: function.hh:377
Definition: function.hh:525
composite functions
Definition: function.hh:539
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:566
CompositeGridFunctionTag ImplementationTag
Definition: function.hh:545
CompositeGridFunction(std::shared_ptr< Children >... children)
Definition: function.hh:560
PowerCompositeGridFunctionTraits< typename BaseT::template Child< 0 >::Type::GridViewType > Traits
Definition: function.hh:547
CompositeGridFunction(Children &... children)
Definition: function.hh:555
CompositeGridFunction(T0 &t0, T1 &t1,...)
Initialize all children.
Definition: function.hh:581
BaseT::template Child< 0 >::Type::GridViewType GridViewType
record the GridView
Definition: function.hh:550
CompositeGridFunction()
Definition: function.hh:552
Turn an ordinary GridFunction into a GridFunctionTree leaf.
Definition: function.hh:597
void evaluate(const typename Imp::Traits::ElementType &e, const typename Imp::Traits::DomainType &x, typename Imp::Traits::RangeType &y) const
Evaluate the GridFunction at given position.
Definition: function.hh:620
const Imp::Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:628
GridFunctionBaseAdapter(const Imp &imp_)
construct a GridFunctionBaseAdapter
Definition: function.hh:607
function signature for analytic functions on a grid
Definition: function.hh:642
an analytic grid function
Definition: function.hh:660
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the GridFunction at given position.
Definition: function.hh:668
const Traits::GridViewType & getGridView() const
Definition: function.hh:675
T Traits
Definition: function.hh:662
AnalyticGridFunctionBase(const typename Traits::GridViewType &g_)
Construct an Analytic GridFunctionBase given a GridView g_.
Definition: function.hh:665
Definition: function.hh:697
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:705
NormalFluxGridFunctionAdapter(const T &t_)
Definition: function.hh:702
Dune::PDELab::GridFunctionTraits< typename T::Traits::GridViewType, typename T::Traits::RangeFieldType, 1, Dune::FieldVector< typename T::Traits::RangeFieldType, 1 > > Traits
Definition: function.hh:699
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:778
Dune::PDELab::GridFunctionInterface< Traits, NormalFluxGridFunctionAdapter< T > > BaseT
Definition: function.hh:700
Definition: function.hh:792
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:802
Dune::PDELab::GridFunctionBase< Traits, PiolaBackwardAdapter< T > > BaseT
Definition: function.hh:796
T::Traits::GridViewType GridViewType
Definition: function.hh:794
T::Traits Traits
Definition: function.hh:795
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:819
PiolaBackwardAdapter(const T &t_)
Definition: function.hh:799
make a GridFunction from a Function
Definition: function.hh:890
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:915
const Traits::GridViewType & getGridView() const
Definition: function.hh:922
FunctionToGridFunctionAdapter(const G &g_, const T &t_)
Create a FunctionToGridFunctionAdapter.
Definition: function.hh:913
GridFunctionTraits< G, typename T::Traits::RangeFieldType, T::Traits::dimRange, typename T::Traits::RangeType > Traits
Definition: function.hh:895
make a Function from a GridFunction
Definition: function.hh:949
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:974
FunctionTraits< typename GF::Traits::GridViewType::ctype, GF::Traits::GridViewType::dimensionworld, Dune::FieldVector< typename GF::Traits::GridViewType::ctype, GF::Traits::GridViewType::dimensionworld >, typename GF::Traits::RangeFieldType, GF::Traits::dimRange, Dune::FieldVector< typename GF::Traits::RangeFieldType, GF::Traits::dimRange > > Traits
Export type traits.
Definition: function.hh:961
GridFunctionToFunctionAdapter(const GF &gf_)
make a GridFunctionToFunctionAdapter
Definition: function.hh:964
make a Function in local coordinates from a Function in global coordinates
Definition: function.hh:998
GlobalFunctionToLocalFunctionAdapter(const T &t_, const E &e_)
Create a GlobalFunctionToLocalFunctionAdapter.
Definition: function.hh:1007
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:1014
T::Traits Traits
Definition: function.hh:1000
make a LocalFunction from a GridFunction using local coordinates
Definition: function.hh:1034
T::Traits Traits
Definition: function.hh:1036
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:1052
GridFunctionToLocalFunctionAdapter(const T &t_, const typename Traits::ElementType &e_)
Create a GridFunctionToLocalFunctionAdapter.
Definition: function.hh:1043
a Function maps x in DomainType to y in RangeType
Definition: function.hh:1067
void select(int k_)
set component to be selected
Definition: function.hh:1089
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:1080
BaseT::Traits Traits
Export type traits.
Definition: function.hh:1071
SelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:1073
Takes a BoundaryGridFunction and acts as a single component.
Definition: function.hh:1106
BoundaryGridFunctionSelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:1115
void select(int k_)
set component to be selected
Definition: function.hh:1140
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1133
BaseT::Traits Traits
Export type traits.
Definition: function.hh:1113
void evaluate(const IntersectionGeometry< I > &ig, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:1123
Wrap intersection.
Definition: geometrywrapper.hh:57
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139