2 #ifndef DUNE_PDELAB_FUNCTION_HH
3 #define DUNE_PDELAB_FUNCTION_HH
8 #include <dune/common/deprecated.hh>
9 #include <dune/common/static_assert.hh>
10 #include <dune/common/exceptions.hh>
11 #include <dune/common/typetraits.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>
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;
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);}
288 template<
typename G,
typename T>
290 public TypeTree::LeafNode,
293 typename T::Traits::RangeFieldType,
295 typename T::Traits::RangeType>,
296 FunctionToGridFunctionAdapter<G,T> >
300 typename T::Traits::RangeFieldType,
304 (is_same<
typename T::Traits::DomainFieldType,
306 "GridView's and wrapped Functions DomainFieldType don't match");
309 "GridView's and wrapped Functions dimDomain don't match");
311 (is_same<
typename T::Traits::DomainType,
313 "GridView's and wrapped Functions DomainType don't match");
326 t.evaluate(e.geometry().global(x),y);
343 template<
typename GF>
345 :
public FunctionInterface<FunctionTraits<typename GF::Traits::GridViewType::ctype,
346 GF::Traits::GridViewType::dimensionworld,
347 Dune::FieldVector<typename GF::Traits::GridViewType::ctype,
348 GF::Traits::GridViewType::dimensionworld
350 typename GF::Traits::RangeFieldType,
351 GF::Traits::dimRange,
352 Dune::FieldVector<typename GF::Traits::RangeFieldType,
353 GF::Traits::dimRange>
355 GridFunctionToFunctionAdapter<GF> >
360 GF::Traits::GridViewType::dimensionworld,
361 Dune::FieldVector<
typename GF::Traits::GridViewType::ctype,
362 GF::Traits::GridViewType::dimensionworld
364 typename GF::Traits::RangeFieldType,
365 GF::Traits::dimRange,
366 Dune::FieldVector<
typename GF::Traits::RangeFieldType,
367 GF::Traits::dimRange>
373 , hsearch(gf.getGridView().grid(), gf.getGridView().indexSet())
384 typename GF::Traits::GridViewType::Grid::Traits::template Codim<0>::EntityPointer
385 ep = hsearch.findEntity(x);
386 gf.evaluate(*ep, ep->geometry().local(x), y);
391 const Dune::HierarchicSearch<
typename GF::Traits::GridViewType::Grid,
392 typename GF::Traits::GridViewType::IndexSet> hsearch;
401 template<
typename T,
typename E>
404 GlobalFunctionToLocalFunctionAdapter<T,E> >
421 inline void evaluate (
const typename Traits::DomainType& x,
422 typename Traits::RangeType& y)
const
424 t.evaluate(e.geometry().global(x),y);
440 GridFunctionToLocalFunctionAdapter<T> >
451 const typename Traits::ElementType& e_)
459 inline void evaluate (
const typename Traits::DomainType& x,
460 typename Traits::RangeType& y)
const
467 const typename Traits::ElementType& e;
473 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> >
487 inline void evaluate (
const typename Traits::DomainType& x,
488 typename Traits::RangeType& y)
const
490 typename T::Traits::RangeType Y;
510 typename T::Traits::RangeFieldType,1,
511 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
512 BoundaryGridFunctionSelectComponentAdapter<T> >
515 typename T::Traits::RangeFieldType,1,
516 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
531 const typename Traits::DomainType& x,
532 typename Traits::RangeType& y)
const
534 typename T::Traits::RangeType Y;
542 return t.getGridView();
576 template<
class T,
class Imp>
579 ,
public TypeTree::LeafNode
596 template<
class T,
class Imp>
599 ,
public TypeTree::LeafNode
614 template<
typename TT>
616 :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
621 template<
typename LeafNode,
typename TreePath>
622 void leaf(LeafNode& node, TreePath treePath)
const
637 template<
class T, std::
size_t k>
639 :
public TypeTree::PowerNode<T,k>
642 typedef TypeTree::PowerNode<T,k> BaseT;
654 template <
typename TT>
657 Dune::TypeTree::applyToTree(*
this,visitor);
721 : BaseT(c0,c1,c2,c3,c4)
731 : BaseT(c0,c1,c2,c3,c4,c5)
742 : BaseT(c0,c1,c2,c3,c4,c5,c6)
754 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7)
767 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8)
781 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
799 template<DUNE_TYPETREE_COMPOSITENODE_TEMPLATE_CHILDREN>
801 :
public DUNE_TYPETREE_COMPOSITENODE_BASETYPE
804 typedef DUNE_TYPETREE_COMPOSITENODE_BASETYPE BaseT;
813 typedef typename BaseT::template Child<0>::Type::GridViewType
GridViewType;
819 : BaseT(DUNE_TYPETREE_COMPOSITENODE_CHILDVARIABLES_THROUGH_FUNCTION(TypeTree::assertGridViewType<typename BaseT::template Child<0>::Type>))
824 template <
typename TT>
827 Dune::TypeTree::applyToTree(*
this,visitor);
855 GridFunctionBaseAdapter<Imp> >
879 inline void evaluate (
const typename Imp::Traits::ElementType&
e,
880 const typename Imp::Traits::DomainType& x,
881 typename Imp::Traits::RangeType& y)
const
887 inline const typename Imp::Traits::GridViewType&
getGridView ()
const
889 return imp.getGridView();
898 template<
typename GV,
typename RF,
int m>
916 template<
typename T,
typename Imp>
931 asImp().evaluateGlobal(e.geometry().global(x),y);
940 typename Traits::GridViewType g;
941 Imp& asImp () {
return static_cast<Imp &
> (*this);}
942 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
951 typename T::Traits::RangeFieldType,
953 Dune::FieldVector<typename T::Traits::RangeFieldType,1>
955 NormalFluxGridFunctionAdapter<T> >
956 ,
public TypeTree::LeafNode
970 dune_static_assert((static_cast<int>(T::Traits::GridViewType::dimension)==static_cast<int>(T::Traits::dimRange)),
"number of components must equal dimension");
973 typename T::Traits::RangeType v;
977 if (!e.geometry().type().isTriangle())
978 DUNE_THROW(Dune::NotImplemented,
"only implemented for triangles");
986 if (std::abs(x[0])<1E-10)
992 nu = e.geometry().corner(n1);
993 nu -= e.geometry().corner(n0);
998 y = v[0]*nu[0]+v[1]*nu[1];
1002 if (std::abs(x[1])<1E-10)
1008 nu = e.geometry().corner(n1);
1009 nu -= e.geometry().corner(n0);
1013 nu /= nu.two_norm();
1014 y = v[0]*nu[0]+v[1]*nu[1];
1018 if (std::abs(x[0]+x[1]-1.0)<1E-10)
1024 nu = e.geometry().corner(n1);
1025 nu -= e.geometry().corner(n0);
1029 nu /= nu.two_norm();
1030 y = v[0]*nu[0]+v[1]*nu[1];
1034 DUNE_THROW(Dune::Exception,
"x needs to be on an edge");
1040 return t->getGridView();
1044 shared_ptr<T const> t;
1049 template<
typename T>
1052 ,
public TypeTree::LeafNode
1062 inline void evaluate (
const typename Traits::ElementType&
e,
1063 const typename Traits::DomainType& x,
1064 typename Traits::RangeType& y)
const
1067 typename T::Traits::RangeType v;
1071 typename Traits::ElementType::Geometry::JacobianInverseTransposed
1072 J = e.geometry().jacobianInverseTransposed(x);
1075 y *= e.geometry().integrationElement(x);
1081 return t->getGridView();
1085 shared_ptr<T const> t;
1096 template<
typename VTKWriter>
1097 struct AddGridFunctionsToVTKWriter
1098 :
public TypeTree::TreeVisitor
1099 ,
public TypeTree::DynamicTraversal
1103 const std::string
s;
1105 AddGridFunctionsToVTKWriter(VTKWriter& w_,
const std::string & s_) :
1108 template<
typename T,
typename TreePath>
1109 void leaf(
const T& t, TreePath treePath) {
1110 std::stringstream name;
1112 for (std::size_t i=0; i < treePath.size(); ++i)
1113 name <<
"_" << treePath.element(i);
1114 w.addVertexData(
new VTKGridFunctionAdapter<T>(t,name.str()));
1125 template<
typename GV,
typename T>
1128 AddGridFunctionsToVTKWriter<Dune::VTKWriter<GV> > visitor(w,s);
1129 TypeTree::applyToTree(t,visitor);
AnalyticGridFunctionBase(const typename Traits::GridViewType &g_)
Construct an Analytic GridFunctionBase given a GridView g_.
Definition: function.hh:924
dimension of the range
Definition: function.hh:57
GridFunctionInterface(Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:194
const Traits::GridViewType & getGridView() const
Definition: function.hh:329
T::Traits::GridViewType GridViewType
Definition: function.hh:1055
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:459
dune_static_assert((is_same< typename T::Traits::DomainFieldType, typename Traits::DomainFieldType >::value),"GridView's and wrapped Functions DomainFieldType don't match")
PowerCompositeGridFunctionTraits< typename T::GridViewType > Traits
Definition: function.hh:646
T Traits
Export type traits of the boundary grid function.
Definition: function.hh:250
Takes a BoundaryGridFunction and acts as a single component.
Definition: function.hh:508
function signature for analytic functions on a grid
Definition: function.hh:899
BaseT::Traits Traits
Export type traits.
Definition: function.hh:478
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:615
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:215
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:825
Dune::PDELab::GridFunctionInterface< Traits, PiolaBackwardAdapter< T > > BaseT
Definition: function.hh:1057
a Function maps x in DomainType to y in RangeType
Definition: function.hh:473
void select(int k_)
set component to be selected
Definition: function.hh:496
T::Traits Traits
Definition: function.hh:407
PowerCompositeGridFunctionTraits< typename BaseT::template Child< 0 >::Type::GridViewType > Traits
Definition: function.hh:810
CompositeGridFunctionTag ImplementationTag
Definition: function.hh:808
make a GridFunction from a Function
Definition: function.hh:289
DF DomainFieldType
Export type for domain field.
Definition: function.hh:40
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:118
GridFunctionTag ImplementationTag
Definition: function.hh:582
SelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:480
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1038
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1079
VTKWriter & w
Definition: function.hh:1102
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:655
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:153
make a Function in local coordinates from a Function in global coordinates
Definition: function.hh:402
composite functions
Definition: function.hh:800
make a Function from a GridFunction
Definition: function.hh:344
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:965
void setDataSetType(Output::DataSetType dataSetType)
Set the data set type of this function.
Definition: function.hh:159
A BoundaryGridFunction allows evaluation on boundary intersections.
Definition: function.hh:246
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:124
BaseT::Traits Traits
Export type traits.
Definition: function.hh:520
GridFunctionOutputParameters(Output::DataSetType dataSetType=Output::vertexData)
Standard constructor.
Definition: function.hh:148
Turn an ordinary GridFunction into a GridFunctionTree leaf.
Definition: function.hh:853
NormalFluxGridFunctionAdapter(const T &t_)
Definition: function.hh:962
PiolaBackwardAdapter(const T &t_)
Definition: function.hh:1059
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:381
RF RangeFieldType
Export type for range field.
Definition: function.hh:52
D DomainType
domain type in dim-size coordinates
Definition: function.hh:49
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:879
PowerCompositeSetTimeVisitor(const TT time_)
Definition: function.hh:619
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:322
Definition: function.hh:628
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:604
an analytic grid function
Definition: function.hh:917
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:1062
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:79
CompositeGridFunction(T0 &t0, T1 &t1,...)
Initialize all children.
Definition: function.hh:840
T Traits
Export type traits.
Definition: function.hh:72
PowerGridFunction()
Definition: function.hh:660
Default class for additional methods in instationary functions.
Definition: function.hh:91
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:487
Definition: function.hh:566
Definition: function.hh:788
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:187
a Function that maps x in DomainType to y in RangeType
Definition: function.hh:68
FunctionToGridFunctionAdapter(const G &g_, const T &t_)
Create a FunctionToGridFunctionAdapter.
Definition: function.hh:320
R RangeType
range type
Definition: function.hh:61
A data set with vertex values.
Definition: function.hh:139
const IG & ig
Definition: common/constraints.hh:146
CompositeGridFunction()
Definition: function.hh:815
PowerGridFunction(T &t)
Construct a PowerGridFunction with k clones of the function t.
Definition: function.hh:664
leaf of a function tree
Definition: function.hh:577
DataSetType
The type of the data set.
Definition: function.hh:137
void select(int k_)
set component to be selected
Definition: function.hh:547
T::Traits Traits
Definition: function.hh:443
GV GridViewType
Export grid view type in addition.
Definition: function.hh:238
Dune::PDELab::GridFunctionTraits< typename T::Traits::GridViewType, typename T::Traits::RangeFieldType, 1, Dune::FieldVector< typename T::Traits::RangeFieldType, 1 > > Traits
Definition: function.hh:959
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:927
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:540
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
leaf of a function tree
Definition: function.hh:597
CompositeGridFunction(DUNE_TYPETREE_COMPOSITENODE_CONSTRUCTOR_SIGNATURE)
Definition: function.hh:818
GV The type of the grid view the function lives on.
Definition: function.hh:112
T::Traits Traits
Definition: function.hh:1056
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:270
A data set with cell values.
Definition: function.hh:140
BaseT::template Child< 0 >::Type::GridViewType GridViewType
record the GridView
Definition: function.hh:813
Dune::PDELab::GridFunctionInterface< Traits, NormalFluxGridFunctionAdapter< T > > BaseT
Definition: function.hh:960
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
traits class holding the function signature, same as in local function
Definition: function.hh:176
traits class holding function signature, same as in local function
Definition: function.hh:231
PowerGridFunctionTag ImplementationTag
Definition: function.hh:648
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:421
T Traits
Export type traits.
Definition: function.hh:192
T::GridViewType GridViewType
record the GridView
Definition: function.hh:651
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:368
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:115
GridFunctionBaseAdapter(const Imp &imp_)
construct a GridFunctionBaseAdapter
Definition: function.hh:866
const Imp::Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:887
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
Definition: function.hh:37
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:1126
product of identical functions
Definition: function.hh:638
Namespace for output-related data types and enums.
Definition: function.hh:130
GridFunctionToLocalFunctionAdapter(const T &t_, const typename Traits::ElementType &e_)
Create a GridFunctionToLocalFunctionAdapter.
Definition: function.hh:450
GridFunctionToFunctionAdapter(const GF &gf_)
make a GridFunctionToFunctionAdapter
Definition: function.hh:371
BoundaryGridFunctionSelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:522
GridFunctionTag ImplementationTag
Definition: function.hh:602
Definition: function.hh:949
PowerGridFunction(T &t0, T &t1,...)
Initialize all children with different function objects.
Definition: function.hh:689
const E & e
Definition: interpolate.hh:172
Definition: function.hh:1050
const Traits::GridViewType & getGridView() const
Definition: function.hh:934
TT time
Definition: function.hh:618
T Traits
Definition: function.hh:921
make a LocalFunction from a GridFunction using local coordinates
Definition: function.hh:438
GlobalFunctionToLocalFunctionAdapter(const T &t_, const E &e_)
Create a GlobalFunctionToLocalFunctionAdapter.
Definition: function.hh:414
dimension of the domain
Definition: function.hh:45
GridFunctionTraits< G, typename T::Traits::RangeFieldType, T::Traits::dimRange, typename T::Traits::RangeType > Traits
Definition: function.hh:302
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:584
Wrap intersection.
Definition: geometrywrapper.hh:56
void leaf(LeafNode &node, TreePath treePath) const
Definition: function.hh:622
const std::string s
Definition: function.hh:1103
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:530