legacyvtkfunction.hh 1.24 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
#pragma once

#include <memory>

#include <dune/grid/io/file/vtk/function.hh>

#include "vtklocalfunctioninterface.hh"

9
namespace Dune
Praetorius, Simon's avatar
Praetorius, Simon committed
10
11
12
13
14
15
16
17
18
19
20
{
  /// Type erasure for Legacy VTKFunction
  template <class GridView>
  class VTKLocalFunctionWrapper final
      : public VtkLocalFunctionInterface<GridView>
  {
    using Interface = VtkLocalFunctionInterface<GridView>;
    using Entity = typename Interface::Entity;
    using LocalCoordinate = typename Interface::LocalCoordinate;

  public:
21
    /// Constructor. Stores a shared pointer to the passed Dune::VTKFunction
Praetorius, Simon's avatar
Praetorius, Simon committed
22
23
24
25
    VTKLocalFunctionWrapper (std::shared_ptr<VTKFunction<GridView> const> const& fct)
      : fct_(fct)
    {}

26
    /// Stores a pointer to the passed entity
Praetorius, Simon's avatar
Praetorius, Simon committed
27
28
29
30
31
    virtual void bind (Entity const& entity) override
    {
      entity_ = &entity;
    }

32
    /// Unsets the stored entity pointer
Praetorius, Simon's avatar
Praetorius, Simon committed
33
34
35
36
37
    virtual void unbind () override
    {
      entity_ = nullptr;
    }

38
    /// Evaluate the Dune::VTKFunction in LocalCoordinates on the stored Entity
Praetorius, Simon's avatar
Praetorius, Simon committed
39
40
41
42
43
44
45
46
47
48
    virtual double evaluate (int comp, LocalCoordinate const& xi) const override
    {
      return fct_->evaluate(comp, *entity_, xi);
    }

  private:
    std::shared_ptr<VTKFunction<GridView> const> fct_;
    Entity const* entity_;
  };

49
} // end namespace Dune