dune-vtk  0.2
writer.hh
Go to the documentation of this file.
1 // -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_PYTHON_VTK_WRITER_HH
5 #define DUNE_PYTHON_VTK_WRITER_HH
6 
7 #include <dune/vtk/vtkwriter.hh>
8 
9 #include <dune/python/pybind11/pybind11.h>
10 #include <dune/python/pybind11/stl.h>
11 
12 namespace Dune
13 {
14 
15  namespace Vtk
16  {
17 
18  // registerVTKWriter
19  // -----------------
20 
21  template< class Writer, class... options >
22  inline static void registerVtkWriter ( pybind11::handle scope,
23  pybind11::class_< Writer, options... > cls )
24  {
25  using GridView = typename Writer::GridView;
26  using VirtualizedGF = Dune::Vtk::Function<GridView>;
27 
28  cls.def( pybind11::init( [] ( GridView &grid,
29  Vtk::FormatTypes format,
30  Vtk::DataTypes datatype,
31  Vtk::DataTypes headertype,
32  pybind11::kwargs kwargs) {
33  return new Writer( grid, format, datatype, headertype );
34  }), pybind11::arg("grid"),
35  pybind11::arg("format") = Vtk::FormatTypes::BINARY,
36  pybind11::arg("datatype") = Vtk::DataTypes::FLOAT32,
37  pybind11::arg("headertype") = Vtk::DataTypes::UINT32,
38  pybind11::keep_alive< 1, 2 >());
39 
40  cls.def( "write",
41  [] ( Writer &writer, const std::string &name ) {
42  writer.write( name );
43  },
44  pybind11::arg("name") );
45  cls.def( "write",
46  [] ( Writer &writer, const std::string &name, int number ) {
47  std::stringstream s; s << name << std::setw(5) << std::setfill('0') << number;
48  writer.write( s.str());
49  },
50  pybind11::arg("name"),
51  pybind11::arg("number") );
52 
53  cls.def( "addPointData",
54  [] ( Writer &writer, VirtualizedGF &f,
55  RangeTypes range, DataTypes data
56  ) {
57  f.setRangeType(range);
58  f.setDataType(data);
59  writer.addPointData(f);
60  },
61  pybind11::keep_alive< 1, 2 >(),
62  pybind11::arg("f"),
63  pybind11::arg("range")=RangeTypes::AUTO,
64  pybind11::arg("data")=DataTypes::FLOAT32
65  );
66  cls.def( "addPointData",
67  [] ( Writer &writer, VirtualizedGF &f,
68  std::string &name,
69  RangeTypes range, DataTypes data
70  ) {
71  f.setName(name);
72  f.setRangeType(range);
73  f.setDataType(data);
74  writer.addPointData(f);
75  },
76  pybind11::keep_alive< 1, 2 >(),
77  pybind11::arg("f"), pybind11::arg("name"),
78  pybind11::arg("range")=RangeTypes::AUTO,
79  pybind11::arg("data")=DataTypes::FLOAT32
80  );
81  cls.def( "addPointData",
82  [] ( Writer &writer, VirtualizedGF &f,
83  std::string &name,
84  std::vector<int> &components,
85  RangeTypes range, DataTypes data
86  ) {
87  f.setName(name);
88  f.setRangeType(range);
89  f.setDataType(data);
90  f.setComponents(components);
91  writer.addPointData(f);
92  },
93  pybind11::keep_alive< 1, 2 >(),
94  pybind11::arg("f"), pybind11::arg("name"),
95  pybind11::arg("components"),
96  pybind11::arg("range")=RangeTypes::AUTO,
97  pybind11::arg("data")=DataTypes::FLOAT32
98  );
99  cls.def( "addPointData",
100  [] ( Writer &writer, VirtualizedGF &f,
101  FieldInfo &info) {
102  f.setFieldInfo(info);
103  writer.addPointData(f);
104  },
105  pybind11::keep_alive< 1, 2 >(),
106  pybind11::arg("f"), pybind11::arg("info") );
107  cls.def( "addPointData",
108  [] ( Writer &writer, VirtualizedGF &f,
109  std::vector<int> &components, FieldInfo &info ) {
110  f.setFieldInfo(info);
111  f.setComponents(components);
112  writer.addPointData(f);
113  },
114  pybind11::keep_alive< 1, 2 >(),
115  pybind11::arg("f"), pybind11::arg("components"), pybind11::arg("info") );
116 
117  cls.def( "addCellData",
118  [] ( Writer &writer, VirtualizedGF &f,
119  RangeTypes range, DataTypes data
120  ) {
121  f.setRangeType(range);
122  f.setDataType(data);
123  writer.addCellData(f);
124  },
125  pybind11::keep_alive< 1, 2 >(),
126  pybind11::arg("f"),
127  pybind11::arg("range")=RangeTypes::AUTO,
128  pybind11::arg("data")=DataTypes::FLOAT32
129  );
130  cls.def( "addCellData",
131  [] ( Writer &writer, VirtualizedGF &f,
132  std::string &name,
133  RangeTypes range, DataTypes data
134  ) {
135  f.setName(name);
136  f.setRangeType(range);
137  f.setDataType(data);
138  writer.addCellData(f);
139  },
140  pybind11::keep_alive< 1, 2 >(),
141  pybind11::arg("f"), pybind11::arg("name"),
142  pybind11::arg("range")=RangeTypes::AUTO,
143  pybind11::arg("data")=DataTypes::FLOAT32
144  );
145  cls.def( "addCellData",
146  [] ( Writer &writer, VirtualizedGF &f,
147  std::string &name,
148  std::vector<int> &components,
149  RangeTypes range, DataTypes data
150  ) {
151  f.setName(name);
152  f.setRangeType(range);
153  f.setDataType(data);
154  f.setComponents(components);
155  writer.addCellData(f);
156  },
157  pybind11::keep_alive< 1, 2 >(),
158  pybind11::arg("f"), pybind11::arg("name"),
159  pybind11::arg("components"),
160  pybind11::arg("range")=RangeTypes::AUTO,
161  pybind11::arg("data")=DataTypes::FLOAT32
162  );
163  cls.def( "addCellData",
164  [] ( Writer &writer, VirtualizedGF &f,
165  FieldInfo &info) {
166  f.setFieldInfo(info);
167  writer.addCellData(f);
168  },
169  pybind11::keep_alive< 1, 2 >(),
170  pybind11::arg("f"), pybind11::arg("info") );
171  cls.def( "addCellData",
172  [] ( Writer &writer, VirtualizedGF &f,
173  std::vector<int> &components, FieldInfo &info ) {
174  f.setFieldInfo(info);
175  f.setComponents(components);
176  writer.addCellData(f);
177  },
178  pybind11::keep_alive< 1, 2 >(),
179  pybind11::arg("f"), pybind11::arg("components"), pybind11::arg("info") );
180  }
181 
182  } // namespace Vtk
183 
184 } // namespace Dune
185 
186 #endif // DUNE_PYTHON_VTK_WRITER_HH
Definition: writer.hh:13
FormatTypes
Type used for representing the output format.
Definition: types.hh:21
RangeTypes
Type used to determine whether to limit output components to e.g. 3 (vector), or 9 (tensor)
Definition: types.hh:35
DataTypes
Definition: types.hh:52
static void registerVtkWriter(pybind11::handle scope, pybind11::class_< Writer, options... > cls)
Definition: writer.hh:22
Wrapper class for functions allowing local evaluations.
Definition: function.hh:28
Definition: types.hh:228