From 81c473c2e5a472f99cd43670fdfa9e7e10f92906 Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Mon, 3 Dec 2018 11:32:53 -0500
Subject: [PATCH] added vtk datatype and fieldInfo to vtkfunction

---
 dune/vtk/vtkfunction.hh | 24 +++++++++++++++++++++---
 dune/vtk/vtktypes.hh    | 26 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/dune/vtk/vtkfunction.hh b/dune/vtk/vtkfunction.hh
index c71d9f4..11ab864 100644
--- a/dune/vtk/vtkfunction.hh
+++ b/dune/vtk/vtkfunction.hh
@@ -48,14 +48,25 @@ namespace Dune
 
   public:
     /// Constructor VtkFunction from legacy VTKFunction
-    VtkFunction (std::shared_ptr<VTKFunction<GridView> const> const& fct)
+    VtkFunction (std::shared_ptr<VTKFunction<GridView> const> const& fct,
+                 Std::optional<Vtk::DataTypes> type = {})
       : localFct_(fct)
       , name_(fct->name())
       , ncomps_(fct->ncomps())
-      , type_(Vtk::FLOAT64)
+      , type_(type ? *type : Vtk::FLOAT64)
     {}
 
     /// Construct VtkFunction from dune-functions GridFunction with Signature
+    // NOTE: Stores the localFunction(fct) by value.
+    /**
+     * \param fct     A Grid(View)-function, providing a `localFunction(fct)`
+     * \param name    The name to use component identification in the VTK file
+     * \param ncomps  Number of components of the pointwise data. Is extracted
+     *                from the range type of the GridFunction if not given.
+     * \param type    The \ref Vtk::DataTypes used in the output. E.g. FLOAT32,
+     *                or FLOAT64. Is extracted from the range type of the
+     *                GridFunction if not given.
+     **/
     template <class F,
       std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0>
     VtkFunction (F&& fct, std::string name,
@@ -70,6 +81,13 @@ namespace Dune
       type_ = type ? *type : Vtk::Map::type<R>();
     }
 
+    template <class F,
+      std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0>
+    VtkFunction (F&& fct, Vtk::FieldInfo fieldInfo,
+                 Std::optional<Vtk::DataTypes> type = {})
+      : VtkFunction(std::forward<F>(fct), fieldInfo.name(), fieldInfo.ncomps(), type)
+    {}
+
     VtkFunction () = default;
 
     /// Create a LocalFunction
@@ -79,7 +97,7 @@ namespace Dune
     }
 
     /// Return a name associated with the function
-    std::string name () const
+    std::string const& name () const
     {
       return name_;
     }
diff --git a/dune/vtk/vtktypes.hh b/dune/vtk/vtktypes.hh
index 435b75f..3d41852 100644
--- a/dune/vtk/vtktypes.hh
+++ b/dune/vtk/vtktypes.hh
@@ -113,5 +113,31 @@ namespace Dune
       bool noPermutation_;
     };
 
+
+    class FieldInfo
+    {
+    public:
+      FieldInfo (std::string name, int ncomps)
+        : name_(std::move(name))
+        , ncomps_(ncomps)
+      {}
+
+      /// The name of the data field
+      std::string const& name () const
+      {
+        return name_;
+      }
+
+      /// The number of components in the data field.
+      int ncomps () const
+      {
+        return ncomps_;
+      }
+
+    private:
+      std::string name_;
+      int ncomps_;
+    };
+
   } // end namespace Vtk
 } // end namespace Dune
-- 
GitLab