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> 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 (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 (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 typename GF::Traits::GridViewType::Grid::Traits::template Codim<0>::EntityPointer
384 ep = hsearch.findEntity(x);
385 gf.evaluate(*ep, ep->geometry().local(x), y);
390 const Dune::HierarchicSearch<
typename GF::Traits::GridViewType::Grid,
391 typename GF::Traits::GridViewType::IndexSet> hsearch;
400 template<
typename T,
typename E>
403 GlobalFunctionToLocalFunctionAdapter<T,E> >
420 inline void evaluate (
const typename Traits::DomainType& x,
421 typename Traits::RangeType& y)
const 423 t.evaluate(
e.geometry().global(x),y);
439 GridFunctionToLocalFunctionAdapter<T> >
450 const typename Traits::ElementType& e_)
458 inline void evaluate (
const typename Traits::DomainType& x,
459 typename Traits::RangeType& y)
const 466 const typename Traits::ElementType&
e;
472 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> >
486 inline void evaluate (
const typename Traits::DomainType& x,
487 typename Traits::RangeType& y)
const 489 typename T::Traits::RangeType Y;
509 typename T::Traits::RangeFieldType,1,
510 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
511 BoundaryGridFunctionSelectComponentAdapter<T> >
514 typename T::Traits::RangeFieldType,1,
515 Dune::FieldVector<typename T::Traits::RangeFieldType,1> > ,
530 const typename Traits::DomainType& x,
531 typename Traits::RangeType& y)
const 533 typename T::Traits::RangeType Y;
541 return t.getGridView();
575 template<
class T,
class Imp>
578 ,
public TypeTree::LeafNode
595 template<
class T,
class Imp>
598 ,
public TypeTree::LeafNode
613 template<
typename TT>
615 :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
620 template<
typename LeafNode,
typename TreePath>
621 void leaf(LeafNode& node, TreePath treePath)
const 636 template<
class T, std::
size_t k>
638 :
public TypeTree::PowerNode<T,k>
641 typedef TypeTree::PowerNode<T,k> BaseT;
653 template <
typename TT>
656 TypeTree::applyToTree(*
this,visitor);
720 : BaseT(c0,c1,c2,c3,c4)
730 : BaseT(c0,c1,c2,c3,c4,c5)
741 : BaseT(c0,c1,c2,c3,c4,c5,c6)
753 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7)
766 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8)
780 : BaseT(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
798 template<
typename... Children>
800 :
public TypeTree::CompositeNode<Children...>
803 typedef TypeTree::CompositeNode<Children...> BaseT;
812 typedef typename BaseT::template Child<0>::Type::GridViewType
GridViewType;
818 : BaseT(TypeTree::assertGridViewType<typename BaseT::template Child<0>::Type>(children)...)
823 template <
typename TT>
826 TypeTree::applyToTree(*
this,visitor);
854 GridFunctionBaseAdapter<Imp> >
878 inline void evaluate (
const typename Imp::Traits::ElementType&
e,
879 const typename Imp::Traits::DomainType& x,
880 typename Imp::Traits::RangeType& y)
const 886 inline const typename Imp::Traits::GridViewType&
getGridView ()
const 888 return imp.getGridView();
897 template<
typename GV,
typename RF,
int m>
915 template<
typename T,
typename Imp>
930 asImp().evaluateGlobal(e.geometry().global(x),y);
940 Imp& asImp () {
return static_cast<Imp &
> (*this);}
941 const Imp& asImp ()
const {
return static_cast<const Imp &
>(*this);}
950 typename T::Traits::RangeFieldType,
952 Dune::FieldVector<typename T::Traits::RangeFieldType,1>
954 NormalFluxGridFunctionAdapter<T> >
955 ,
public TypeTree::LeafNode
969 static_assert((static_cast<int>(T::Traits::GridViewType::dimension)==static_cast<int>(T::Traits::dimRange)),
"number of components must equal dimension");
972 typename T::Traits::RangeType v;
976 if (!e.geometry().type().isTriangle())
977 DUNE_THROW(Dune::NotImplemented,
"only implemented for triangles");
985 if (std::abs(x[0])<1E-10)
991 nu = e.geometry().corner(n1);
992 nu -= e.geometry().corner(n0);
997 y = v[0]*nu[0]+v[1]*nu[1];
1001 if (std::abs(x[1])<1E-10)
1007 nu = e.geometry().corner(n1);
1008 nu -= e.geometry().corner(n0);
1012 nu /= nu.two_norm();
1013 y = v[0]*nu[0]+v[1]*nu[1];
1017 if (std::abs(x[0]+x[1]-1.0)<1E-10)
1023 nu = e.geometry().corner(n1);
1024 nu -= e.geometry().corner(n0);
1028 nu /= nu.two_norm();
1029 y = v[0]*nu[0]+v[1]*nu[1];
1033 DUNE_THROW(Dune::Exception,
"x needs to be on an edge");
1039 return t->getGridView();
1043 shared_ptr<T const> t;
1048 template<
typename T>
1051 ,
public TypeTree::LeafNode
1061 inline void evaluate (
const typename Traits::ElementType&
e,
1062 const typename Traits::DomainType& x,
1063 typename Traits::RangeType& y)
const 1066 typename T::Traits::RangeType v;
1070 typename Traits::ElementType::Geometry::JacobianInverseTransposed
1071 J = e.geometry().jacobianInverseTransposed(x);
1074 y *= e.geometry().integrationElement(x);
1080 return t->getGridView();
1084 shared_ptr<T const> t;
1095 template<
typename VTKWriter>
1096 struct AddGridFunctionsToVTKWriter
1097 :
public TypeTree::TreeVisitor
1098 ,
public TypeTree::DynamicTraversal
1102 const std::string
s;
1104 AddGridFunctionsToVTKWriter(VTKWriter& w_,
const std::string & s_) :
1107 template<
typename T,
typename TreePath>
1108 void leaf(
const T& t, TreePath treePath) {
1109 std::stringstream name;
1111 for (std::size_t i=0; i < treePath.size(); ++i)
1112 name <<
"_" << treePath.element(i);
1113 w.addVertexData(make_shared< VTKGridFunctionAdapter<T> >(t,name.str()));
1124 template<
typename GV,
typename T>
1127 AddGridFunctionsToVTKWriter<Dune::VTKWriter<GV> > visitor(w,
s);
1128 TypeTree::applyToTree(t,visitor);
SelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:479
AnalyticGridFunctionBase(const typename Traits::GridViewType &g_)
Construct an Analytic GridFunctionBase given a GridView g_.
Definition: function.hh:923
dimension of the range
Definition: function.hh:56
void setDataSetType(Output::DataSetType dataSetType)
Set the data set type of this function.
Definition: function.hh:158
TT time
Definition: function.hh:617
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:964
traits class holding function signature, same as in local function
Definition: function.hh:230
function signature for analytic functions on a grid
Definition: function.hh:898
T::Traits::GridViewType GridViewType
Definition: function.hh:1054
static const unsigned int value
Definition: gridfunctionspace/tags.hh:177
Turn an ordinary GridFunction into a GridFunctionTree leaf.
Definition: function.hh:852
composite functions
Definition: function.hh:799
T::Traits Traits
Definition: function.hh:442
CompositeGridFunction(Children &...children)
Definition: function.hh:817
PowerCompositeSetTimeVisitor(const TT time_)
Definition: function.hh:618
Definition: function.hh:627
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
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:583
T Traits
Export type traits of the boundary grid function.
Definition: function.hh:249
const IG & ig
Definition: constraints.hh:148
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:529
CompositeGridFunction(T0 &t0, T1 &t1,...)
Initialize all children.
Definition: function.hh:839
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:1125
PowerGridFunction()
Definition: function.hh:659
GridFunctionToFunctionAdapter(const GF &gf_)
make a GridFunctionToFunctionAdapter
Definition: function.hh:370
make a GridFunction from a Function
Definition: function.hh:288
RF RangeFieldType
Export type for range field.
Definition: function.hh:51
PowerCompositeGridFunctionTraits< typename BaseT::template Child< 0 >::Type::GridViewType > Traits
Definition: function.hh:809
GV The type of the grid view the function lives on.
Definition: function.hh:111
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:114
Dune::PDELab::GridFunctionInterface< Traits, PiolaBackwardAdapter< T > > BaseT
Definition: function.hh:1056
DF DomainFieldType
Export type for domain field.
Definition: function.hh:39
Takes a BoundaryGridFunction and acts as a single component.
Definition: function.hh:507
void leaf(LeafNode &node, TreePath treePath) const
Definition: function.hh:621
Definition: adaptivity.hh:27
PiolaBackwardAdapter(const T &t_)
Definition: function.hh:1058
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:321
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:117
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
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:437
Definition: function.hh:1049
GridFunctionInterface(Output::DataSetType dataSetType=Output::vertexData)
Definition: function.hh:193
BaseT::template Child< 0 >::Type::GridViewType GridViewType
record the GridView
Definition: function.hh:812
GridFunctionTag ImplementationTag
Definition: function.hh:581
A data set with vertex values.
Definition: function.hh:138
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:269
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1078
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:214
NormalFluxGridFunctionAdapter(const T &t_)
Definition: function.hh:961
GridFunctionToLocalFunctionAdapter(const T &t_, const typename Traits::ElementType &e_)
Create a GridFunctionToLocalFunctionAdapter.
Definition: function.hh:449
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:539
GridFunctionOutputParameters(Output::DataSetType dataSetType=Output::vertexData)
Standard constructor.
Definition: function.hh:147
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: function.hh:1061
GridFunctionBaseAdapter(const Imp &imp_)
construct a GridFunctionBaseAdapter
Definition: function.hh:865
a Function maps x in DomainType to y in RangeType
Definition: function.hh:472
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:78
an analytic grid function
Definition: function.hh:916
const Entity & e
Definition: localfunctionspace.hh:111
Dune::PDELab::GridFunctionInterface< Traits, NormalFluxGridFunctionAdapter< T > > BaseT
Definition: function.hh:959
D DomainType
domain type in dim-size coordinates
Definition: function.hh:48
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:654
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:486
make a Function in local coordinates from a Function in global coordinates
Definition: function.hh:401
PowerGridFunctionTag ImplementationTag
Definition: function.hh:647
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:878
T Traits
Export type traits.
Definition: function.hh:71
T::Traits Traits
Definition: function.hh:1055
BaseT::Traits Traits
Export type traits.
Definition: function.hh:519
make a Function from a GridFunction
Definition: function.hh:343
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:614
GridFunctionTag ImplementationTag
Definition: function.hh:601
T Traits
Export type traits.
Definition: function.hh:191
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:123
CompositeGridFunctionTag ImplementationTag
Definition: function.hh:807
T::Traits Traits
Definition: function.hh:406
Dune::PDELab::GridFunctionTraits< typename T::Traits::GridViewType, typename T::Traits::RangeFieldType, 1, Dune::FieldVector< typename T::Traits::RangeFieldType, 1 > > Traits
Definition: function.hh:958
GlobalFunctionToLocalFunctionAdapter(const T &t_, const E &e_)
Create a GlobalFunctionToLocalFunctionAdapter.
Definition: function.hh:413
FunctionToGridFunctionAdapter(const G &g_, const T &t_)
Create a FunctionToGridFunctionAdapter.
Definition: function.hh:319
R RangeType
range type
Definition: function.hh:60
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:926
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:458
BoundaryGridFunctionSelectComponentAdapter(const T &t_, int k_)
Definition: function.hh:521
GridFunctionTraits< G, typename T::Traits::RangeFieldType, T::Traits::dimRange, typename T::Traits::RangeType > Traits
Definition: function.hh:301
DataSetType
The type of the data set.
Definition: function.hh:136
A BoundaryGridFunction allows evaluation on boundary intersections.
Definition: function.hh:245
VTKWriter & w
Definition: function.hh:1101
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: function.hh:824
Namespace for output-related data types and enums.
Definition: function.hh:129
BaseT::Traits Traits
Export type traits.
Definition: function.hh:477
Wrap intersection.
Definition: geometrywrapper.hh:56
const Imp::Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:886
T::GridViewType GridViewType
record the GridView
Definition: function.hh:650
const Traits::GridViewType & getGridView() const
Definition: function.hh:328
Definition: function.hh:948
PowerGridFunction(T &t)
Construct a PowerGridFunction with k clones of the function t.
Definition: function.hh:663
Default class for additional methods in instationary functions.
Definition: function.hh:90
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the local function at the given position.
Definition: function.hh:420
const std::string s
Definition: function.hh:1102
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:152
void select(int k_)
set component to be selected
Definition: function.hh:546
a Function that maps x in DomainType to y in RangeType
Definition: function.hh:67
T::GridViewType GridViewType
Type of the GridView.
Definition: function.hh:603
PowerCompositeGridFunctionTraits< typename T::GridViewType > Traits
Definition: function.hh:645
PowerGridFunction(T &t0, T &t1,...)
Initialize all children with different function objects.
Definition: function.hh:688
GV GridViewType
Export grid view type in addition.
Definition: function.hh:237
void setTime(Time t)
set time for subsequent evaluation
Definition: function.hh:105
leaf of a function tree
Definition: function.hh:596
void select(int k_)
set component to be selected
Definition: function.hh:495
Definition: function.hh:36
Definition: function.hh:565
const Traits::GridViewType & getGridView() const
Definition: function.hh:933
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate all basis function at given position.
Definition: function.hh:380
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:186
T Traits
Definition: function.hh:920
leaf of a function tree
Definition: function.hh:576
dimension of the domain
Definition: function.hh:44
product of identical functions
Definition: function.hh:637
traits class holding the function signature, same as in local function
Definition: function.hh:175
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: function.hh:1037
CompositeGridFunction()
Definition: function.hh:814
Definition: function.hh:787