2 #ifndef DUNE_PDELAB_COMMON_FUNCTION_HH 3 #define DUNE_PDELAB_COMMON_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> 35 template<
class DF,
int n,
class D,
class RF,
int m,
class R>
66 template<
class T,
class Imp>
78 inline void evaluate (
const typename Traits::DomainType& x,
79 typename Traits::RangeType& y)
const 81 asImp().evaluate(x,y);
85 Imp& asImp () {
return static_cast<Imp &
> (*this);}
86 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
104 template<
typename Time>
110 template<
typename GV>
117 typedef typename GV::Traits::template Codim<0>::Entity
ElementType;
148 : _dataSetType(dataSetType)
160 _dataSetType = dataSetType;
174 template<
class GV,
class RF,
int m,
class R>
177 Dune::FieldVector<typename GV::Grid::ctype,
185 template<
class T,
class Imp>
210 asImp().evaluate(e,x,y);
216 return asImp().getGridView();
220 Imp& asImp () {
return static_cast<Imp &
> (*this);}
221 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
229 template<
class GV,
class RF,
int m,
class R>
231 :
public FunctionTraits<typename GV::Grid::ctype, GV::dimension-1,
232 Dune::FieldVector<typename GV::Grid::ctype,
244 template<
class T,
class Imp>
265 asImp().evaluate(ig,x,y);
271 return asImp().getGridView();
275 Imp& asImp () {
return static_cast<Imp &
> (*this);}
276 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
287 template<
typename G,
typename T>
289 public TypeTree::LeafNode,
292 typename T::Traits::RangeFieldType,
294 typename T::Traits::RangeType>,
295 FunctionToGridFunctionAdapter<G,T> >
299 typename T::Traits::RangeFieldType,
303 (std::is_same<
typename T::Traits::DomainFieldType,
305 "GridView's and wrapped Functions DomainFieldType don't match");
307 T::Traits::dimDomain==Traits::dimDomain,
308 "GridView's and wrapped Functions dimDomain don't match");
310 (std::is_same<
typename T::Traits::DomainType,
312 "GridView's and wrapped Functions DomainType don't match");
325 t.evaluate(e.geometry().global(x),y);
342 template<
typename GF>
344 :
public FunctionInterface<FunctionTraits<typename GF::Traits::GridViewType::ctype,
345 GF::Traits::GridViewType::dimensionworld,
346 Dune::FieldVector<typename GF::Traits::GridViewType::ctype,
347 GF::Traits::GridViewType::dimensionworld
349 typename GF::Traits::RangeFieldType,
350 GF::Traits::dimRange,
351 Dune::FieldVector<typename GF::Traits::RangeFieldType,
352 GF::Traits::dimRange>
354 GridFunctionToFunctionAdapter<GF> >
359 GF::Traits::GridViewType::dimensionworld,
360 Dune::FieldVector<
typename GF::Traits::GridViewType::ctype,
361 GF::Traits::GridViewType::dimensionworld
363 typename GF::Traits::RangeFieldType,
364 GF::Traits::dimRange,
365 Dune::FieldVector<
typename GF::Traits::RangeFieldType,
366 GF::Traits::dimRange>
372 , hsearch(gf.getGridView().grid(), gf.getGridView().indexSet())
383 auto e = hsearch.findEntity(x);
384 gf.evaluate(
e,
e.geometry().local(x),y);
389 const Dune::HierarchicSearch<
typename GF::Traits::GridViewType::Grid,
390 typename GF::Traits::GridViewType::IndexSet> hsearch;
399 template<
typename T,
typename E>
402 GlobalFunctionToLocalFunctionAdapter<T,E> >
419 inline void evaluate (
const typename Traits::DomainType& x,
420 typename Traits::RangeType& y)
const 422 t.evaluate(
e.geometry().global(x),y);
438 GridFunctionToLocalFunctionAdapter<T> >
449 const typename Traits::ElementType& e_)
457 inline void evaluate (
const typename Traits::DomainType& x,
458 typename Traits::RangeType& y)
const 465 const typename Traits::ElementType&
e;
471 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> >
485 inline void evaluate (
const typename Traits::DomainType& x,
486 typename Traits::RangeType& y)
const 488 typename T::Traits::RangeType Y;
508 typename T::Traits::RangeFieldType,1,
509 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
510 BoundaryGridFunctionSelectComponentAdapter<T> >
513 typename T::Traits::RangeFieldType,1,
514 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
529 const typename Traits::DomainType& x,
530 typename Traits::RangeType& y)
const 532 typename T::Traits::RangeType Y;
540 return t.getGridView();
574 template<
class T,
class Imp>
577 ,
public TypeTree::LeafNode
594 template<
class T,
class Imp>
597 ,
public TypeTree::LeafNode
612 template<
typename TT>
614 :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
619 template<
typename LeafNode,
typename TreePath>
620 void leaf(LeafNode& node, TreePath treePath)
const 635 template<
class T, std::
size_t k>
637 :
public TypeTree::PowerNode<T,k>
640 typedef TypeTree::PowerNode<T,k> BaseT;
652 template <
typename TT>
655 TypeTree::applyToTree(*
this,visitor);
719 : BaseT(c0,c1,c2,c3,c4)
729 : BaseT(c0,c1,c2,c3,c4,c5)
740 : BaseT(c0,c1,c2,c3,c4,c5,c6)
752 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7)
765 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8)
779 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
797 template<
typename... Children>
799 :
public TypeTree::CompositeNode<Children...>
802 typedef TypeTree::CompositeNode<Children...> BaseT;
811 typedef typename BaseT::template Child<0>::Type::GridViewType
GridViewType;
817 : BaseT(TypeTree::assertGridViewType<typename BaseT::template Child<0>::Type>(children)...)
822 template <
typename TT>
825 TypeTree::applyToTree(*
this,visitor);
853 GridFunctionBaseAdapter<Imp> >
877 inline void evaluate (
const typename Imp::Traits::ElementType&
e,
878 const typename Imp::Traits::DomainType& x,
879 typename Imp::Traits::RangeType& y)
const 885 inline const typename Imp::Traits::GridViewType&
getGridView ()
const 887 return imp.getGridView();
896 template<
typename GV,
typename RF,
int m>
914 template<
typename T,
typename Imp>
929 asImp().evaluateGlobal(e.geometry().global(x),y);
939 Imp& asImp () {
return static_cast<Imp &
> (*this);}
940 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
949 typename T::Traits::RangeFieldType,
951 Dune::FieldVector<typename T::Traits::RangeFieldType,1>
953 NormalFluxGridFunctionAdapter<T> >
954 ,
public TypeTree::LeafNode
968 static_assert((static_cast<int>(T::Traits::GridViewType::dimension)==static_cast<int>(T::Traits::dimRange)),
"number of components must equal dimension");
971 typename T::Traits::RangeType v;
975 if (!e.geometry().type().isTriangle())
976 DUNE_THROW(Dune::NotImplemented,
"only implemented for triangles");
984 if (std::abs(x[0])<1E-10)
990 nu = e.geometry().corner(n1);
991 nu -= e.geometry().corner(n0);
996 y = v[0]*nu[0]+v[1]*nu[1];
1000 if (std::abs(x[1])<1E-10)
1006 nu = e.geometry().corner(n1);
1007 nu -= e.geometry().corner(n0);
1011 nu /= nu.two_norm();
1012 y = v[0]*nu[0]+v[1]*nu[1];
1016 if (std::abs(x[0]+x[1]-1.0)<1E-10)
1022 nu = e.geometry().corner(n1);
1023 nu -= e.geometry().corner(n0);
1027 nu /= nu.two_norm();
1028 y = v[0]*nu[0]+v[1]*nu[1];
1032 DUNE_THROW(Dune::Exception,
"x needs to be on an edge");
1038 return t->getGridView();
1042 shared_ptr<T const> t;
1047 template<
typename T>
1050 ,
public TypeTree::LeafNode
1060 inline void evaluate (
const typename Traits::ElementType&
e,
1061 const typename Traits::DomainType& x,
1062 typename Traits::RangeType& y)
const 1065 typename T::Traits::RangeType v;
1069 typename Traits::ElementType::Geometry::JacobianInverseTransposed
1070 J = e.geometry().jacobianInverseTransposed(x);
1073 y *= e.geometry().integrationElement(x);
1079 return t->getGridView();
1083 shared_ptr<T const> t;
1094 template<
typename VTKWriter>
1095 struct AddGridFunctionsToVTKWriter
1096 :
public TypeTree::TreeVisitor
1097 ,
public TypeTree::DynamicTraversal
1101 const std::string
s;
1103 AddGridFunctionsToVTKWriter(VTKWriter& w_,
const std::string & s_) :
1106 template<
typename T,
typename TreePath>
1107 void leaf(
const T& t, TreePath treePath) {
1108 std::stringstream name;
1110 for (std::size_t i=0; i < treePath.size(); ++i)
1111 name <<
"_" << treePath.element(i);
1112 w.addVertexData(make_shared< VTKGridFunctionAdapter<T> >(t,name.str()));
1123 template<
typename GV,
typename T>
1126 AddGridFunctionsToVTKWriter<Dune::VTKWriter<GV> > visitor(w,
s);
1127 TypeTree::applyToTree(t,visitor);
1137 #endif // DUNE_PDELAB_COMMON_FUNCTION_HH PowerCompositeGridFunctionTraits< typename BaseT::template Child< 0 >::Type::GridViewType > Traits
Definition: function.hh:808
void setDataSetType(Output::DataSetType dataSetType)
Set the data set type of this function.
Definition: function.hh:158
const IG & ig
Definition: constraints.hh:148
a Function maps x in DomainType to y in RangeType
Definition: function.hh:471
composite functions
Definition: function.hh:798
Wrap intersection.
Definition: geometrywrapper.hh:56
make a Function from a GridFunction
Definition: function.hh:343
Definition: function.hh:626
void leaf(LeafNode &node, TreePath treePath) const
Definition: function.hh:620
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:269
leaf of a function tree
Definition: function.hh:575
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:877
PowerCompositeSetTimeVisitor(const TT time_)
Definition: function.hh:617
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:653
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:419
Definition: function.hh:1048
GV The type of the grid view the function lives on.
Definition: function.hh:111
CompositeGridFunction()
Definition: function.hh:813
T Traits
Export type traits.
Definition: function.hh:191
const std::string s
Definition: function.hh:1101
function signature for analytic functions on a grid
Definition: function.hh:897
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:261
Definition: function.hh:36
AnalyticGridFunctionBase(const typename Traits::GridViewType &g_)
Construct an Analytic GridFunctionBase given a GridView g_.
Definition: function.hh:922
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:214
CompositeGridFunction(Children &... children)
Definition: function.hh:816
TT time
Definition: function.hh:616
GridFunctionTraits< G, typename T::Traits::RangeFieldType, T::Traits::dimRange, typename T::Traits::RangeType > Traits
Definition: function.hh:301
BaseT::template Child< 0 >::Type::GridViewType GridViewType
record the GridView
Definition: function.hh:811
Definition: function.hh:786
PowerCompositeGridFunctionTraits< typename T::GridViewType > Traits
Definition: function.hh:644
BaseT::Traits Traits
Export type traits.
Definition: function.hh:476
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:117
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:582
traits class holding function signature, same as in local function
Definition: function.hh:230
Namespace for output-related data types and enums.
Definition: function.hh:129
NormalFluxGridFunctionAdapter(const T &t_)
Definition: function.hh:960
Dune::PDELab::GridFunctionTraits< typename T::Traits::GridViewType, typename T::Traits::RangeFieldType, 1, Dune::FieldVector< typename T::Traits::RangeFieldType, 1 > > Traits
Definition: function.hh:957
Definition: function.hh:947
Default class for additional methods in instationary functions.
Definition: function.hh:90
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:152
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:367
make a LocalFunction from a GridFunction using local coordinates
Definition: function.hh:436
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:528
GV GridViewType
Export grid view type in addition.
Definition: function.hh:237
make a GridFunction from a Function
Definition: function.hh:288
GridFunctionTag ImplementationTag
Definition: function.hh:580
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:186
T Traits
Definition: function.hh:919
T Traits
Export type traits.
Definition: function.hh:71
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:114
T::Traits Traits
Definition: function.hh:441
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:457
Dune::PDELab::GridFunctionInterface< Traits, PiolaBackwardAdapter< T > > BaseT
Definition: function.hh:1055
PiolaBackwardAdapter(const T &t_)
Definition: function.hh:1057
RF RangeFieldType
Export type for range field.
Definition: function.hh:51
Takes a BoundaryGridFunction and acts as a single component.
Definition: function.hh:506
T Traits
Export type traits of the boundary grid function.
Definition: function.hh:249
make a Function in local coordinates from a Function in global coordinates
Definition: function.hh:400
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:78
dimension of the range
Definition: function.hh:56
FunctionToGridFunctionAdapter(const G &g_, const T &t_)
Create a FunctionToGridFunctionAdapter.
Definition: function.hh:319
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:538
PowerGridFunctionTag ImplementationTag
Definition: function.hh:646
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:321
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:823
CompositeGridFunctionTag ImplementationTag
Definition: function.hh:806
BaseT::Traits Traits
Export type traits.
Definition: function.hh:518
T::Traits Traits
Definition: function.hh:1054
GridFunctionInterface(Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:193
A data set with vertex values.
Definition: function.hh:138
DF DomainFieldType
Export type for domain field.
Definition: function.hh:39
const Traits::GridViewType & getGridView() const
Definition: function.hh:328
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1077
PowerGridFunction()
Definition: function.hh:658
const Traits::GridViewType & getGridView() const
Definition: function.hh:932
GridFunctionTag ImplementationTag
Definition: function.hh:600
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:206
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:1124
PowerGridFunction(T &t0, T &t1,...)
Initialize all children with different function objects.
Definition: function.hh:687
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:613
T::GridViewType GridViewType
record the GridView
Definition: function.hh:649
Definition: function.hh:564
D DomainType
domain type in dim-size coordinates
Definition: function.hh:48
GridFunctionToFunctionAdapter(const GF &gf_)
make a GridFunctionToFunctionAdapter
Definition: function.hh:370
Dune::PDELab::GridFunctionInterface< Traits, NormalFluxGridFunctionAdapter< T > > BaseT
Definition: function.hh:958
SelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:478
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
const Entity & e
Definition: localfunctionspace.hh:111
GridFunctionToLocalFunctionAdapter(const T &t_, const typename Traits::ElementType &e_)
Create a GridFunctionToLocalFunctionAdapter.
Definition: function.hh:448
Turn an ordinary GridFunction into a GridFunctionTree leaf.
Definition: function.hh:851
const Imp::Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:885
product of identical functions
Definition: function.hh:636
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:1060
DataSetType
The type of the data set.
Definition: function.hh:136
void setTime(Time t)
set time for subsequent evaluation
Definition: function.hh:105
void select(int k_)
set component to be selected
Definition: function.hh:494
T::Traits::GridViewType GridViewType
Definition: function.hh:1053
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1036
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:963
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:123
VTKWriter & w
Definition: function.hh:1100
void select(int k_)
set component to be selected
Definition: function.hh:545
CompositeGridFunction(T0 &t0, T1 &t1,...)
Initialize all children.
Definition: function.hh:838
an analytic grid function
Definition: function.hh:915
T::Traits Traits
Definition: function.hh:405
a Function that maps x in DomainType to y in RangeType
Definition: function.hh:67
GlobalFunctionToLocalFunctionAdapter(const T &t_, const E &e_)
Create a GlobalFunctionToLocalFunctionAdapter.
Definition: function.hh:412
R RangeType
range type
Definition: function.hh:60
A BoundaryGridFunction allows evaluation on boundary intersections.
Definition: function.hh:245
leaf of a function tree
Definition: function.hh:595
traits class holding the function signature, same as in local function
Definition: function.hh:175
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:602
GridFunctionBaseAdapter(const Imp &imp_)
construct a GridFunctionBaseAdapter
Definition: function.hh:864
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:925
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:485
PowerGridFunction(T &t)
Construct a PowerGridFunction with k clones of the function t.
Definition: function.hh:662
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:380
BoundaryGridFunctionSelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:520
GridFunctionOutputParameters(Output::DataSetType dataSetType=Output::vertexData)
Standard constructor.
Definition: function.hh:147
dimension of the domain
Definition: function.hh:44