dune-vtk  0.2
defaultvtkfunction.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <dune/common/fmatrix.hh>
6 #include <dune/common/fvector.hh>
7 #include <dune/common/typetraits.hh>
8 
10 
11 namespace Dune
12 {
13  namespace Vtk
14  {
16  template <class GridView, class LocalFunction>
18  : public LocalFunctionInterface<GridView>
19  {
20  using Self = LocalFunctionWrapper;
22  using Entity = typename Interface::Entity;
23  using LocalCoordinate = typename Interface::LocalCoordinate;
24 
25  public:
27  template <class LocalFct,
28  disableCopyMove<Self, LocalFct> = 0>
29  explicit LocalFunctionWrapper (LocalFct&& localFct)
30  : localFct_(std::forward<LocalFct>(localFct))
31  {}
32 
34  virtual void bind (Entity const& entity) override
35  {
36  localFct_.bind(entity);
37  }
38 
40  virtual void unbind () override
41  {
42  localFct_.unbind();
43  }
44 
46  virtual double evaluate (int comp, LocalCoordinate const& xi) const override
47  {
48  return evaluateImpl(comp, localFct_(xi));
49  }
50 
51  private:
52  // Evaluate a component of a vector valued data
53  template <class T, int N, int M>
54  double evaluateImpl (int comp, FieldMatrix<T,N,M> const& mat) const
55  {
56  int r = comp / 3;
57  int c = comp % 3;
58  return r < N && c < M ? mat[r][c] : 0.0;
59  }
60 
61  // Evaluate a component of a vector valued data
62  template <class T, int N>
63  double evaluateImpl (int comp, FieldVector<T,N> const& vec) const
64  {
65  return comp < N ? vec[comp] : 0.0;
66  }
67 
68  // Evaluate a component of a vector valued data
69  template <class T,
70  std::enable_if_t<IsIndexable<T,int>::value, int> = 0>
71  double evaluateImpl (int comp, T const& value) const
72  {
73  return value[comp];
74  }
75 
76  // Return the scalar values
77  template <class T,
78  std::enable_if_t<not IsIndexable<T,int>::value, int> = 0>
79  double evaluateImpl (int comp, T const& value) const
80  {
81  assert(comp == 0);
82  return value;
83  }
84 
85  private:
86  LocalFunction localFct_;
87  };
88 
89  } // end namespace Vtk
90 } // end namespace Dune
Definition: writer.hh:13
Type erasure for dune-functions LocalFunction interface.
Definition: defaultvtkfunction.hh:19
virtual double evaluate(int comp, LocalCoordinate const &xi) const override
Evaluate the LocalFunction in LocalCoordinates.
Definition: defaultvtkfunction.hh:46
virtual void bind(Entity const &entity) override
Bind the LocalFunction to the Entity.
Definition: defaultvtkfunction.hh:34
LocalFunctionWrapper(LocalFct &&localFct)
Constructor. Stores a copy of the passed localFct in a local variable.
Definition: defaultvtkfunction.hh:29
virtual void unbind() override
Unbind the LocalFunction from the Entity.
Definition: defaultvtkfunction.hh:40
Definition: function.hh:18
Definition: function.hh:21
void unbind()
Unbind from the currently bound entity.
Definition: localfunction.hh:87
void bind(Entity const &entity)
Bind the function to the grid entity.
Definition: localfunction.hh:80
An abstract base class for LocalFunctions that can be bound to an element and evaluated in local coor...
Definition: localfunctioninterface.hh:11
typename Entity::Geometry::LocalCoordinate LocalCoordinate
Definition: localfunctioninterface.hh:14
typename GridView::template Codim< 0 >::Entity Entity
Definition: localfunctioninterface.hh:13