structuredgridwriter.hh 2.57 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <array>
#include <iosfwd>
#include <map>

7
#include <dune/vtk/filewriter.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
8
#include <dune/vtk/forward.hh>
Stenger, Florian's avatar
Stenger, Florian committed
9
10
#include <dune/vtk/function.hh>
#include <dune/vtk/types.hh>
11
12
#include <dune/vtk/datacollectors/structureddatacollector.hh>

Stenger, Florian's avatar
Stenger, Florian committed
13
#include <dune/vtk/writerinterface.hh>
14

15
namespace Dune
16
{
17
18
19
20
21
  /// File-Writer for StructuredGrid VTK .vts files
  /**
   * Requirement:
   * - DataCollector must be a model of \ref StructuredDataCollector
   **/
Praetorius, Simon's avatar
Praetorius, Simon committed
22
  template <class GridView, class DataCollector>
23
  class VtkStructuredGridWriter
24
      : public VtkWriterInterface<GridView, DataCollector>
25
26
27
  {
    static constexpr int dimension = GridView::dimension;

28
    using Super = VtkWriterInterface<GridView, DataCollector>;
29
30
31
    using pos_type = typename Super::pos_type;

  public:
32
33
    /// forwarding constructor to \ref VtkWriterInterface
    using Super::Super;
34
35
36

  private:
    /// Write a serial VTK file in Unstructured format
37
    virtual void writeSerialFile (std::ofstream& out) const override;
38
39
40
41

    /// Write a parallel VTK file `pfilename.pvtu` in Unstructured format,
    /// with `size` the number of pieces and serial files given by `pfilename_p[i].vtu`
    /// for [i] in [0,...,size).
42
    virtual void writeParallelFile (std::ofstream& out, std::string const& pfilename, int size) const override;
43
44
45
46
47
48

    virtual std::string fileExtension () const override
    {
      return "vts";
    }

49
50
    virtual void writeGridAppended (std::ofstream& out, std::vector<std::uint64_t>& blocks) const override;

51
52
53
54
55
56
57
58
59
60
  private:
    using Super::dataCollector_;
    using Super::format_;
    using Super::datatype_;

    // attached data
    using Super::pointData_;
    using Super::cellData_;
  };

61
62
63
64
  // deduction guides
  template <class GridView,
    class = std::void_t<typename GridView::IndexSet>>
  VtkStructuredGridWriter(GridView const&, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
Stenger, Florian's avatar
Stenger, Florian committed
65
    -> VtkStructuredGridWriter<GridView, Vtk::StructuredDataCollector<GridView>>;
66
67
68
69
70
71
72
73
74
75
76

  template <class DataCollector,
    class = std::void_t<typename DataCollector::GridView>>
  VtkStructuredGridWriter(DataCollector&, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
    -> VtkStructuredGridWriter<typename DataCollector::GridView, DataCollector>;

  template <class DataCollector,
    class = std::void_t<typename DataCollector::GridView>>
  VtkStructuredGridWriter(std::shared_ptr<DataCollector>, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
    -> VtkStructuredGridWriter<typename DataCollector::GridView, DataCollector>;

77
} // end namespace Dune
78

Stenger, Florian's avatar
Stenger, Florian committed
79
#include "structuredgridwriter.impl.hh"