vtkfunction.hh 2.45 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
#pragma once

#include <type_traits>

#include <dune/common/std/type_traits.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
6
#include <dune/functions/common/signature.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
7
8

#include "vtklocalfunction.hh"
9
#include "vtktypes.hh"
Praetorius, Simon's avatar
Praetorius, Simon committed
10

11
namespace Dune
Praetorius, Simon's avatar
Praetorius, Simon committed
12
{
13
14
15
  template <class GridView>
  class VtkFunction
  {
16
    template <class F>
17
    using HasLocalFunction = decltype(localFunction(std::declval<F>()));
18

19
    template <class F>
Praetorius, Simon's avatar
Praetorius, Simon committed
20
21
22
23
    using Domain = typename std::decay_t<F>::EntitySet::GlobalCoordinate;

    template <class F>
    using Range = std::decay_t<decltype(std::declval<F>()(std::declval<Domain<F>>()))>;
Praetorius, Simon's avatar
Praetorius, Simon committed
24
25

  public:
Praetorius, Simon's avatar
Praetorius, Simon committed
26
27
28
29
30
31
    /// Constructor VtkFunction from legacy VTKFunction
    VtkFunction (std::shared_ptr<VTKFunction<GridView> const> const& fct)
      : localFct_(fct)
      , name_(fct->name())
      , ncomps_(fct->ncomps())
      , type_(Vtk::FLOAT64)
32
    {}
Praetorius, Simon's avatar
Praetorius, Simon committed
33

Praetorius, Simon's avatar
Praetorius, Simon committed
34
    /// Construct VtkFunction from dune-functions GridFunction with Signature
Praetorius, Simon's avatar
Praetorius, Simon committed
35
    template <class F,
36
      std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0,
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
      std::enable_if_t<Std::is_detected<Range,F>::value,int> = 0>
    VtkFunction (F&& fct, std::string name, int ncomps = 1, Vtk::DataTypes type = Vtk::Map::type<Range<F>>)
      : localFct_(localFunction(std::forward<F>(fct)))
Praetorius, Simon's avatar
Praetorius, Simon committed
40
      , name_(std::move(name))
Praetorius, Simon's avatar
Praetorius, Simon committed
41
      , ncomps_(ncomps)
Praetorius, Simon's avatar
Praetorius, Simon committed
42
      , type_(type)
43
44
    {}

Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
48
49
50
    /// Construct VtkFunction from dune-functions GridFunction without Signature
    template <class F,
      std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0,
      std::enable_if_t<not Std::is_detected<Range,F>::value,int> = 0>
    VtkFunction (F const& fct, std::string name, int ncomps = 1, Vtk::DataTypes type = Vtk::FLOAT32)
      : localFct_(localFunction(std::forward<F>(fct)))
51
      , name_(std::move(name))
Praetorius, Simon's avatar
Praetorius, Simon committed
52
      , ncomps_(ncomps)
53
54
      , type_(type)
    {}
Praetorius, Simon's avatar
Praetorius, Simon committed
55

56
    VtkFunction () = default;
Praetorius, Simon's avatar
Praetorius, Simon committed
57

58
    /// Create a LocalFunction
59
    friend VtkLocalFunction<GridView> localFunction (VtkFunction const& self)
Praetorius, Simon's avatar
Praetorius, Simon committed
60
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
61
      return self.localFct_;
Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
    }

64
    /// Return a name associated with the function
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66
67
68
69
    std::string name () const
    {
      return name_;
    }

70
71
72
73
74
75
    /// Return the number of components of the Range
    int ncomps () const
    {
      return ncomps_;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
76
77
78
79
80
81
    /// Return the VTK Datatype associated with the functions range type
    Vtk::DataTypes type () const
    {
      return type_;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
82
  private:
Praetorius, Simon's avatar
Praetorius, Simon committed
83
    VtkLocalFunction<GridView> localFct_;
Praetorius, Simon's avatar
Praetorius, Simon committed
84
85
    std::string name_;
    int ncomps_ = 1;
Praetorius, Simon's avatar
Praetorius, Simon committed
86
    Vtk::DataTypes type_ = Vtk::FLOAT32;
Praetorius, Simon's avatar
Praetorius, Simon committed
87
88
  };

89
} // end namespace Dune