dune-vtk 2.12
Loading...
Searching...
No Matches
writer.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <dune/python/pybind11/pybind11.h>
6#include <dune/python/pybind11/stl.h>
9
10namespace Dune::Vtk {
11
12// registerVtkWriter
13// ---------------------
14
15template< class Writer, class... options >
16inline static void registerVtkWriter ( pybind11::handle scope,
17 pybind11::class_< Writer, options... > cls )
18{
19 using GridView = typename Writer::GridView;
20 using DataCollector = typename Writer::DataCollector;
22
23 cls.def( pybind11::init( [] ( const GridView& gv,
24 Vtk::FormatTypes format,
27 pybind11::args args) {
28 return new Writer( Impl::pyMakeDataCollector(MetaType<DataCollector>{}, gv, args), format, datatype, headertype );
29 }),
30 pybind11::arg("grid"),
31 pybind11::arg("format") = Vtk::FormatTypes::BINARY,
32 pybind11::arg("datatype") = Vtk::DataTypes::FLOAT32,
33 pybind11::arg("headertype") = Vtk::DataTypes::UINT32,
34 pybind11::keep_alive< 1, 2 >());
35
36 cls.def( "write",
37 [] ( Writer &writer, const std::string &name ) {
38 writer.write( name );
39 },
40 pybind11::arg("name") );
41 cls.def( "write",
42 [] ( Writer &writer, const std::string &name, int number ) {
43 std::stringstream s; s << name << std::setw(5) << std::setfill('0') << number;
44 writer.write( s.str());
45 },
46 pybind11::arg("name"),
47 pybind11::arg("number") );
48
49 cls.def( "addPointData",
50 [] ( Writer &writer, GridFunction &f,
52 ) {
53 f.setRangeType(range);
54 f.setDataType(data);
55 writer.addPointData(f);
56 },
57 pybind11::keep_alive< 1, 2 >(),
58 pybind11::arg("f"),
59 pybind11::arg("range")=RangeTypes::AUTO,
60 pybind11::arg("data")=DataTypes::FLOAT32
61 );
62 cls.def( "addPointData",
63 [] ( Writer &writer, GridFunction &f,
66 ) {
67 f.setName(name);
68 f.setRangeType(range);
69 f.setDataType(data);
70 writer.addPointData(f);
71 },
72 pybind11::keep_alive< 1, 2 >(),
73 pybind11::arg("f"), pybind11::arg("name"),
74 pybind11::arg("range")=RangeTypes::AUTO,
75 pybind11::arg("data")=DataTypes::FLOAT32
76 );
77 cls.def( "addPointData",
78 [] ( Writer &writer, GridFunction &f,
80 std::vector<int> &components,
82 ) {
83 f.setName(name);
84 f.setRangeType(range);
85 f.setDataType(data);
86 f.setComponents(components);
87 writer.addPointData(f);
88 },
89 pybind11::keep_alive< 1, 2 >(),
90 pybind11::arg("f"), pybind11::arg("name"),
91 pybind11::arg("components"),
92 pybind11::arg("range")=RangeTypes::AUTO,
93 pybind11::arg("data")=DataTypes::FLOAT32
94 );
95 cls.def( "addPointData",
96 [] ( Writer &writer, GridFunction &f,
97 FieldInfo &info) {
98 f.setFieldInfo(info);
99 writer.addPointData(f);
100 },
101 pybind11::keep_alive< 1, 2 >(),
102 pybind11::arg("f"), pybind11::arg("info") );
103 cls.def( "addPointData",
104 [] ( Writer &writer, GridFunction &f,
105 std::vector<int> &components, FieldInfo &info ) {
106 f.setFieldInfo(info);
107 f.setComponents(components);
108 writer.addPointData(f);
109 },
110 pybind11::keep_alive< 1, 2 >(),
111 pybind11::arg("f"), pybind11::arg("components"), pybind11::arg("info") );
112
113 cls.def( "addCellData",
114 [] ( Writer &writer, GridFunction &f,
116 ) {
117 f.setRangeType(range);
118 f.setDataType(data);
119 writer.addCellData(f);
120 },
121 pybind11::keep_alive< 1, 2 >(),
122 pybind11::arg("f"),
123 pybind11::arg("range")=RangeTypes::AUTO,
124 pybind11::arg("data")=DataTypes::FLOAT32
125 );
126 cls.def( "addCellData",
127 [] ( Writer &writer, GridFunction &f,
130 ) {
131 f.setName(name);
132 f.setRangeType(range);
133 f.setDataType(data);
134 writer.addCellData(f);
135 },
136 pybind11::keep_alive< 1, 2 >(),
137 pybind11::arg("f"), pybind11::arg("name"),
138 pybind11::arg("range")=RangeTypes::AUTO,
139 pybind11::arg("data")=DataTypes::FLOAT32
140 );
141 cls.def( "addCellData",
142 [] ( Writer &writer, GridFunction &f,
144 std::vector<int> &components,
146 ) {
147 f.setName(name);
148 f.setRangeType(range);
149 f.setDataType(data);
150 f.setComponents(components);
151 writer.addCellData(f);
152 },
153 pybind11::keep_alive< 1, 2 >(),
154 pybind11::arg("f"), pybind11::arg("name"),
155 pybind11::arg("components"),
156 pybind11::arg("range")=RangeTypes::AUTO,
157 pybind11::arg("data")=DataTypes::FLOAT32
158 );
159 cls.def( "addCellData",
160 [] ( Writer &writer, GridFunction &f,
161 FieldInfo &info) {
162 f.setFieldInfo(info);
163 writer.addCellData(f);
164 },
165 pybind11::keep_alive< 1, 2 >(),
166 pybind11::arg("f"), pybind11::arg("info") );
167 cls.def( "addCellData",
168 [] ( Writer &writer, GridFunction &f,
169 std::vector<int> &components, FieldInfo &info ) {
170 f.setFieldInfo(info);
171 f.setComponents(components);
172 writer.addCellData(f);
173 },
174 pybind11::keep_alive< 1, 2 >(),
175 pybind11::arg("f"), pybind11::arg("components"), pybind11::arg("info") );
176}
177
178} // end namespace Dune::Vtk
Dune::ParameterTree options
Definition datacollector.hh:19
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:36
DataTypes
Definition types.hh:53
static void registerVtkWriter(pybind11::handle scope, pybind11::class_< Writer, options... > cls)
Definition writer.hh:16
const char * name()
static constexpr IntegralRange< T > range(T from, T to) noexcept
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
A Vtk::GridFunction is a function-like object that can be bound to a grid element an that provides an...
Definition gridfunction.hh:89
Definition types.hh:250
T setfill(T... args)
T setw(T... args)
T str(T... args)