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/fvector.hh> 12 #include <dune/common/fmatrix.hh> 14 #include <dune/grid/utility/hierarchicsearch.hh> 16 #include <dune/typetree/typetree.hh> 36 template<
class DF,
int n,
class D,
class RF,
int m,
class R>
67 template<
class T,
class Imp>
79 inline void evaluate (
const typename Traits::DomainType& x,
80 typename Traits::RangeType& y)
const 82 asImp().evaluate(x,y);
86 Imp& asImp () {
return static_cast<Imp &
> (*this);}
87 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
105 template<
typename Time>
111 template<
typename GV>
118 typedef typename GV::Traits::template Codim<0>::Entity
ElementType;
149 : _dataSetType(dataSetType)
161 _dataSetType = dataSetType;
175 template<
class GV,
class RF,
int m,
class R>
178 Dune::FieldVector<typename GV::Grid::ctype,
186 template<
class T,
class Imp>
211 asImp().evaluate(e,x,y);
217 return asImp().getGridView();
221 Imp& asImp () {
return static_cast<Imp &
> (*this);}
222 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
230 template<
class GV,
class RF,
int m,
class R>
232 :
public FunctionTraits<typename GV::Grid::ctype, GV::dimension-1,
233 Dune::FieldVector<typename GV::Grid::ctype,
245 template<
class T,
class Imp>
266 asImp().evaluate(ig,x,y);
272 return asImp().getGridView();
276 Imp& asImp () {
return static_cast<Imp &
> (*this);}
277 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
297 template<
class T,
class Imp>
300 ,
public TypeTree::LeafNode
324 template<
class T,
class Imp>
327 ,
public TypeTree::LeafNode
342 template<
typename TT>
344 :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
349 template<
typename LeafNode,
typename TreePath>
350 void leaf(LeafNode& node, TreePath treePath)
const 365 template<
class T, std::
size_t k>
367 :
public TypeTree::PowerNode<T,k>
370 typedef TypeTree::PowerNode<T,k> BaseT;
382 template <
typename TT>
385 TypeTree::applyToTree(*
this,visitor);
449 : BaseT(c0,c1,c2,c3,c4)
459 : BaseT(c0,c1,c2,c3,c4,c5)
470 : BaseT(c0,c1,c2,c3,c4,c5,c6)
482 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7)
495 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8)
509 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
527 template<
typename... Children>
529 :
public TypeTree::CompositeNode<Children...>
532 typedef TypeTree::CompositeNode<Children...> BaseT;
541 typedef typename BaseT::template Child<0>::Type::GridViewType
GridViewType;
547 : BaseT(TypeTree::assertGridViewType<typename BaseT::template Child<0>::Type>(children)...)
552 template <
typename TT>
555 TypeTree::applyToTree(*
this,visitor);
583 GridFunctionBaseAdapter<Imp> >
607 inline void evaluate (
const typename Imp::Traits::ElementType&
e,
608 const typename Imp::Traits::DomainType& x,
609 typename Imp::Traits::RangeType& y)
const 615 inline const typename Imp::Traits::GridViewType&
getGridView ()
const 617 return imp.getGridView();
626 template<
typename GV,
typename RF,
int m>
644 template<
typename T,
typename Imp>
659 asImp().evaluateGlobal(e.geometry().global(x),y);
669 Imp& asImp () {
return static_cast<Imp &
> (*this);}
670 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
679 typename T::Traits::RangeFieldType,
681 Dune::FieldVector<typename T::Traits::RangeFieldType,1>
683 NormalFluxGridFunctionAdapter<T> >
697 static_assert((static_cast<int>(T::Traits::GridViewType::dimension)==static_cast<int>(T::Traits::dimRange)),
"number of components must equal dimension");
700 typename T::Traits::RangeType v;
704 if (!e.geometry().type().isTriangle())
705 DUNE_THROW(Dune::NotImplemented,
"only implemented for triangles");
713 if (std::abs(x[0])<1E-10)
719 nu = e.geometry().corner(n1);
720 nu -= e.geometry().corner(n0);
725 y = v[0]*nu[0]+v[1]*nu[1];
729 if (std::abs(x[1])<1E-10)
735 nu = e.geometry().corner(n1);
736 nu -= e.geometry().corner(n0);
741 y = v[0]*nu[0]+v[1]*nu[1];
745 if (std::abs(x[0]+x[1]-1.0)<1E-10)
751 nu = e.geometry().corner(n1);
752 nu -= e.geometry().corner(n0);
757 y = v[0]*nu[0]+v[1]*nu[1];
761 DUNE_THROW(Dune::Exception,
"x needs to be on an edge");
767 return t->getGridView();
771 shared_ptr<T const> t;
789 inline void evaluate (
const typename Traits::ElementType&
e,
790 const typename Traits::DomainType& x,
791 typename Traits::RangeType& y)
const 794 typename T::Traits::RangeType v;
798 typename Traits::ElementType::Geometry::JacobianInverseTransposed
799 J = e.geometry().jacobianInverseTransposed(x);
802 y *= e.geometry().integrationElement(x);
808 return t->getGridView();
812 shared_ptr<T const> t;
823 template<
typename VTKWriter>
824 struct AddGridFunctionsToVTKWriter
825 :
public TypeTree::TreeVisitor
826 ,
public TypeTree::DynamicTraversal
832 AddGridFunctionsToVTKWriter(VTKWriter& w_,
const std::string & s_) :
835 template<
typename T,
typename TreePath>
836 void leaf(
const T& t, TreePath treePath) {
837 std::stringstream name;
839 for (std::size_t i=0; i < treePath.size(); ++i)
840 name <<
"_" << treePath.element(i);
841 w.addVertexData(make_shared< VTKGridFunctionAdapter<T> >(t,name.str()));
852 template<
typename GV,
typename T>
855 AddGridFunctionsToVTKWriter<Dune::VTKWriter<GV> > visitor(w,
s);
856 TypeTree::applyToTree(t,visitor);
869 template<
typename G,
typename T>
873 typename T::Traits::RangeFieldType,
875 typename T::Traits::RangeType>,
876 FunctionToGridFunctionAdapter<G,T> >
880 typename T::Traits::RangeFieldType,
884 (std::is_same<
typename T::Traits::DomainFieldType,
886 "GridView's and wrapped Functions DomainFieldType don't match");
888 T::Traits::dimDomain==Traits::dimDomain,
889 "GridView's and wrapped Functions dimDomain don't match");
891 (std::is_same<
typename T::Traits::DomainType,
893 "GridView's and wrapped Functions DomainType don't match");
906 t.evaluate(e.geometry().global(x),y);
923 template<
typename GF>
925 :
public FunctionInterface<FunctionTraits<typename GF::Traits::GridViewType::ctype,
926 GF::Traits::GridViewType::dimensionworld,
927 Dune::FieldVector<typename GF::Traits::GridViewType::ctype,
928 GF::Traits::GridViewType::dimensionworld
930 typename GF::Traits::RangeFieldType,
931 GF::Traits::dimRange,
932 Dune::FieldVector<typename GF::Traits::RangeFieldType,
933 GF::Traits::dimRange>
935 GridFunctionToFunctionAdapter<GF> >
940 GF::Traits::GridViewType::dimensionworld,
941 Dune::FieldVector<
typename GF::Traits::GridViewType::ctype,
942 GF::Traits::GridViewType::dimensionworld
944 typename GF::Traits::RangeFieldType,
945 GF::Traits::dimRange,
946 Dune::FieldVector<
typename GF::Traits::RangeFieldType,
947 GF::Traits::dimRange>
953 , hsearch(gf.getGridView().grid(), gf.getGridView().indexSet())
964 typename GF::Traits::GridViewType::Grid::Traits::template Codim<0>::EntityPointer
965 ep = hsearch.findEntity(x);
966 gf.evaluate(*ep, ep->geometry().local(x), y);
971 const Dune::HierarchicSearch<
typename GF::Traits::GridViewType::Grid,
972 typename GF::Traits::GridViewType::IndexSet> hsearch;
981 template<
typename T,
typename E>
984 GlobalFunctionToLocalFunctionAdapter<T,E> >
1001 inline void evaluate (
const typename Traits::DomainType& x,
1002 typename Traits::RangeType& y)
const 1004 t.evaluate(
e.geometry().global(x),y);
1017 template<
typename T>
1020 GridFunctionToLocalFunctionAdapter<T> >
1031 const typename Traits::ElementType& e_)
1039 inline void evaluate (
const typename Traits::DomainType& x,
1040 typename Traits::RangeType& y)
const 1047 const typename Traits::ElementType&
e;
1053 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> >
1067 inline void evaluate (
const typename Traits::DomainType& x,
1068 typename Traits::RangeType& y)
const 1070 typename T::Traits::RangeType Y;
1090 typename T::Traits::RangeFieldType,1,
1091 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
1092 BoundaryGridFunctionSelectComponentAdapter<T> >
1095 typename T::Traits::RangeFieldType,1,
1096 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
1109 template<
typename I>
1111 const typename Traits::DomainType& x,
1112 typename Traits::RangeType& y)
const 1114 typename T::Traits::RangeType Y;
1122 return t.getGridView();
VTKWriter & w
Definition: function.hh:829
R RangeType
range type
Definition: function.hh:61
Namespace for output-related data types and enums.
Definition: function.hh:130
Definition: function.hh:356
make a LocalFunction from a GridFunction using local coordinates
Definition: function.hh:1018
DataSetType
The type of the data set.
Definition: function.hh:137
Default class for additional methods in instationary functions.
Definition: function.hh:91
const Entity & e
Definition: localfunctionspace.hh:120
Wrap intersection.
Definition: geometrywrapper.hh:56
leaf of a function tree
Definition: function.hh:298
T::Traits Traits
Definition: function.hh:987
traits class holding function signature, same as in local function
Definition: function.hh:231
function signature for analytic functions on a grid
Definition: function.hh:627
Definition: function.hh:516
BaseT::Traits Traits
Export type traits.
Definition: function.hh:1058
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:853
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:343
NormalFluxGridFunctionAdapter(const T &t_)
Definition: function.hh:689
Dune::PDELab::GridFunctionTraits< typename T::Traits::GridViewType, typename T::Traits::RangeFieldType, 1, Dune::FieldVector< typename T::Traits::RangeFieldType, 1 > > Traits
Definition: function.hh:686
PowerGridFunction(T &t)
Construct a PowerGridFunction with k clones of the function t.
Definition: function.hh:392
PowerGridFunction(T &t0, T &t1,...)
Initialize all children with different function objects.
Definition: function.hh:417
void select(int k_)
set component to be selected
Definition: function.hh:1076
BoundaryGridFunctionSelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:1102
GV GridViewType
Export grid view type in addition.
Definition: function.hh:238
CompositeGridFunction(T0 &t0, T1 &t1,...)
Initialize all children.
Definition: function.hh:568
make a GridFunction from a Function
Definition: function.hh:870
GridFunctionToLocalFunctionAdapter(const T &t_, const typename Traits::ElementType &e_)
Create a GridFunctionToLocalFunctionAdapter.
Definition: function.hh:1030
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:948
GridFunctionBaseAdapter(const Imp &imp_)
construct a GridFunctionBaseAdapter
Definition: function.hh:594
T Traits
Export type traits.
Definition: function.hh:72
Definition: function.hh:677
Turn an ordinary GridFunction into a GridFunctionTree leaf.
Definition: function.hh:581
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:1110
const Traits::GridViewType & getGridView() const
Definition: function.hh:662
dimension of the range
Definition: function.hh:57
TT time
Definition: function.hh:346
SelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:1060
GridFunctionBase(typename Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:310
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:383
Takes a BoundaryGridFunction and acts as a single component.
Definition: function.hh:1088
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:124
CompositeGridFunctionTag ImplementationTag
Definition: function.hh:536
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
FunctionToGridFunctionAdapter(const G &g_, const T &t_)
Create a FunctionToGridFunctionAdapter.
Definition: function.hh:900
make a Function in local coordinates from a Function in global coordinates
Definition: function.hh:982
a Function that maps x in DomainType to y in RangeType
Definition: function.hh:68
BaseT::template Child< 0 >::Type::GridViewType GridViewType
record the GridView
Definition: function.hh:541
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:1001
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:262
A data set with vertex values.
Definition: function.hh:139
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:655
D DomainType
domain type in dim-size coordinates
Definition: function.hh:49
PowerCompositeGridFunctionTraits< typename BaseT::template Child< 0 >::Type::GridViewType > Traits
Definition: function.hh:538
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:118
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:806
PowerGridFunctionTag ImplementationTag
Definition: function.hh:376
traits class holding the function signature, same as in local function
Definition: function.hh:176
GridFunctionTag ImplementationTag
Definition: function.hh:304
a Function maps x in DomainType to y in RangeType
Definition: function.hh:1053
GV The type of the grid view the function lives on.
Definition: function.hh:112
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:1039
Dune::PDELab::GridFunctionBase< Traits, PiolaBackwardAdapter< T > > BaseT
Definition: function.hh:783
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:961
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
CompositeGridFunction(Children &... children)
Definition: function.hh:546
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:270
GridFunctionToFunctionAdapter(const GF &gf_)
make a GridFunctionToFunctionAdapter
Definition: function.hh:951
RF RangeFieldType
Export type for range field.
Definition: function.hh:52
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:692
T::Traits Traits
Definition: function.hh:782
T::Traits::GridViewType GridViewType
Definition: function.hh:781
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:1067
void leaf(LeafNode &node, TreePath treePath) const
Definition: function.hh:350
void setDataSetType(Output::DataSetType dataSetType)
Set the data set type of this function.
Definition: function.hh:159
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:332
PowerCompositeSetTimeVisitor(const TT time_)
Definition: function.hh:347
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:765
const IG & ig
Definition: constraints.hh:148
GridFunctionInterface(Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:194
Definition: function.hh:287
const Imp::Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:615
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:187
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:553
GridFunctionOutputParameters(Output::DataSetType dataSetType=Output::vertexData)
Standard constructor.
Definition: function.hh:148
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:207
PowerGridFunction()
Definition: function.hh:388
product of identical functions
Definition: function.hh:366
dimension of the domain
Definition: function.hh:45
DF DomainFieldType
Export type for domain field.
Definition: function.hh:40
leaf of a function tree
Definition: function.hh:325
CompositeGridFunction()
Definition: function.hh:543
T Traits
Definition: function.hh:649
GridFunctionTag ImplementationTag
Definition: function.hh:330
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1120
Dune::PDELab::GridFunctionInterface< Traits, NormalFluxGridFunctionAdapter< T > > BaseT
Definition: function.hh:687
BaseT::Traits Traits
Export type traits.
Definition: function.hh:1100
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:789
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:607
void select(int k_)
set component to be selected
Definition: function.hh:1127
T Traits
Export type traits of the boundary grid function.
Definition: function.hh:250
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:115
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:79
an analytic grid function
Definition: function.hh:645
GlobalFunctionToLocalFunctionAdapter(const T &t_, const E &e_)
Create a GlobalFunctionToLocalFunctionAdapter.
Definition: function.hh:994
GridFunctionTraits< G, typename T::Traits::RangeFieldType, T::Traits::dimRange, typename T::Traits::RangeType > Traits
Definition: function.hh:882
composite functions
Definition: function.hh:528
PiolaBackwardAdapter(const T &t_)
Definition: function.hh:786
AnalyticGridFunctionBase(const typename Traits::GridViewType &g_)
Construct an Analytic GridFunctionBase given a GridView g_.
Definition: function.hh:652
void setTime(Time t)
set time for subsequent evaluation
Definition: function.hh:106
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:902
typename Base::Output Output
Definition: function.hh:308
T::Traits Traits
Definition: function.hh:1023
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:153
make a Function from a GridFunction
Definition: function.hh:924
Definition: function.hh:37
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:306
A BoundaryGridFunction allows evaluation on boundary intersections.
Definition: function.hh:246
const std::string s
Definition: function.hh:830
Definition: function.hh:777
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:215
T Traits
Export type traits.
Definition: function.hh:192
const Traits::GridViewType & getGridView() const
Definition: function.hh:909
T::GridViewType GridViewType
record the GridView
Definition: function.hh:379
PowerCompositeGridFunctionTraits< typename T::GridViewType > Traits
Definition: function.hh:374