PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
writer.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include "writer.h"
12#include "vtkWriter.h"
13#include "legacyVtkWriter.h"
14#include "mshWriter.h"
15
17 : d_vtkWriter_p(nullptr), d_legacyVtkWriter_p(nullptr),
18 d_mshWriter_p(nullptr), d_format("vtu") {}
19
20rw::writer::Writer::Writer(const std::string &filename,
21 const std::string &format,
22 const std::string &compress_type)
23 : d_vtkWriter_p(nullptr), d_legacyVtkWriter_p(nullptr),
24 d_mshWriter_p(nullptr), d_format("vtu") {
25 open(filename, format, compress_type);
26}
27
28void rw::writer::Writer::open(const std::string &filename,
29 const std::string &format,
30 const std::string &compress_type) {
31 d_format = format;
32 if (d_format == "vtu")
33 d_vtkWriter_p = new rw::writer::VtkWriter(filename, compress_type);
34 else if (d_format == "msh")
35 d_mshWriter_p = new rw::writer::MshWriter(filename, compress_type);
36 else if (d_format == "legacy_vtk")
37 d_legacyVtkWriter_p =
38 new rw::writer::LegacyVtkWriter(filename, compress_type);
39 else {
40 std::cerr << "File format " << d_format << " is not supported.\n";
41 exit(1);
42 }
43}
44
46 delete (d_vtkWriter_p);
47}
48
50 const std::vector<util::Point> *nodes,
51 const std::vector<util::Point> *u) {
52
53 if (d_format == "vtu")
54 d_vtkWriter_p->appendNodes(nodes, u);
55 else if (d_format == "msh")
56 d_mshWriter_p->appendNodes(nodes, u);
57 else if (d_format == "legacy_vtk")
58 d_legacyVtkWriter_p->appendNodes(nodes, u);
59}
60
62 const std::vector<util::Point> *nodes, const size_t &element_type,
63 const std::vector<size_t> *en_con, const std::vector<util::Point> *u) {
64
65 if (d_format == "vtu")
66 d_vtkWriter_p->appendMesh(nodes, element_type, en_con, u);
67 else if (d_format == "msh")
68 d_mshWriter_p->appendMesh(nodes, element_type, en_con, u);
69 else if (d_format == "legacy_vtk")
70 d_legacyVtkWriter_p->appendMesh(nodes, element_type, en_con, u);
71}
72
74 const std::string &name, const std::vector<uint8_t> *data) {
75
76 if (d_format == "vtu")
77 d_vtkWriter_p->appendPointData(name, data);
78 else if (d_format == "msh")
79 d_mshWriter_p->appendPointData(name, data);
80 else if (d_format == "legacy_vtk")
81 d_legacyVtkWriter_p->appendPointData(name, data);
82}
83
85 const std::string &name, const std::vector<size_t> *data) {
86
87 if (d_format == "vtu")
88 d_vtkWriter_p->appendPointData(name, data);
89 else if (d_format == "msh")
90 d_mshWriter_p->appendPointData(name, data);
91 else if (d_format == "legacy_vtk")
92 d_legacyVtkWriter_p->appendPointData(name, data);
93}
94
96 const std::string &name, const std::vector<int> *data) {
97
98 if (d_format == "vtu")
99 d_vtkWriter_p->appendPointData(name, data);
100 else if (d_format == "msh")
101 d_mshWriter_p->appendPointData(name, data);
102 else if (d_format == "legacy_vtk")
103 d_legacyVtkWriter_p->appendPointData(name, data);
104}
105
107 const std::string &name, const std::vector<float> *data) {
108
109 if (d_format == "vtu")
110 d_vtkWriter_p->appendPointData(name, data);
111 else if (d_format == "msh")
112 d_mshWriter_p->appendPointData(name, data);
113 else if (d_format == "legacy_vtk")
114 d_legacyVtkWriter_p->appendPointData(name, data);
115}
116
118 const std::string &name, const std::vector<double> *data) {
119
120 if (d_format == "vtu")
121 d_vtkWriter_p->appendPointData(name, data);
122 else if (d_format == "msh")
123 d_mshWriter_p->appendPointData(name, data);
124 else if (d_format == "legacy_vtk")
125 d_legacyVtkWriter_p->appendPointData(name, data);
126}
127
129 const std::string &name, const std::vector<util::Point> *data) {
130
131 if (d_format == "vtu")
132 d_vtkWriter_p->appendPointData(name, data);
133 else if (d_format == "msh")
134 d_mshWriter_p->appendPointData(name, data);
135 else if (d_format == "legacy_vtk")
136 d_legacyVtkWriter_p->appendPointData(name, data);
137}
138
140 const std::string &name, const std::vector<util::SymMatrix3> *data) {
141
142 if (d_format == "vtu")
143 d_vtkWriter_p->appendPointData(name, data);
144 else if (d_format == "msh")
145 d_mshWriter_p->appendPointData(name, data);
146 else if (d_format == "legacy_vtk")
147 d_legacyVtkWriter_p->appendPointData(name, data);
148}
149
151 const std::string &name, const std::vector<float> *data) {
152
153 if (d_format == "vtu")
154 d_vtkWriter_p->appendCellData(name, data);
155 else if (d_format == "msh")
156 d_mshWriter_p->appendCellData(name, data);
157 else if (d_format == "legacy_vtk")
158 d_legacyVtkWriter_p->appendCellData(name, data);
159}
160
162 const std::string &name, const std::vector<util::SymMatrix3> *data) {
163
164 if (d_format == "vtu")
165 d_vtkWriter_p->appendCellData(name, data);
166 else if (d_format == "msh")
167 d_mshWriter_p->appendCellData(name, data);
168 else if (d_format == "legacy_vtk")
169 d_legacyVtkWriter_p->appendCellData(name, data);
170}
171
172void rw::writer::Writer::addTimeStep(const double &timestep) {
173
174 if (d_format == "vtu")
175 d_vtkWriter_p->addTimeStep(timestep);
176 else if (d_format == "msh")
177 d_mshWriter_p->addTimeStep(timestep);
178 else if (d_format == "legacy_vtk")
179 d_legacyVtkWriter_p->addTimeStep(timestep);
180}
181
182void rw::writer::Writer::appendFieldData(const std::string &name,
183 const double &data) {
184
185 if (d_format == "vtu")
186 d_vtkWriter_p->appendFieldData(name, data);
187 else if (d_format == "msh")
188 d_mshWriter_p->appendFieldData(name, data);
189 else if (d_format == "legacy_vtk")
190 d_legacyVtkWriter_p->appendFieldData(name, data);
191}
192
193void rw::writer::Writer::appendFieldData(const std::string &name,
194 const float &data) {
195
196 if (d_format == "vtu")
197 d_vtkWriter_p->appendFieldData(name, data);
198 else if (d_format == "msh")
199 d_mshWriter_p->appendFieldData(name, data);
200 else if (d_format == "legacy_vtk")
201 d_legacyVtkWriter_p->appendFieldData(name, data);
202}
203
205
206 if (d_format == "vtu")
207 d_vtkWriter_p->close();
208 else if (d_format == "msh")
209 d_mshWriter_p->close();
210 else if (d_format == "legacy_vtk")
211 d_legacyVtkWriter_p->close();
212}
A vtk writer for simple point data and complex fem mesh data.
A .msh writer for simple point data and complex fem mesh data.
Definition mshWriter.h:24
A vtk writer for simple point data and complex fem mesh data.
Definition vtkWriter.h:28
void appendCellData(const std::string &name, const std::vector< float > *data)
Writes the float data associated to cells to the file.
Definition writer.cpp:150
void appendFieldData(const std::string &name, const double &data)
Writes the scalar field data to the file.
Definition writer.cpp:182
void appendNodes(const std::vector< util::Point > *nodes, const std::vector< util::Point > *u=nullptr)
Writes the nodes to the file.
Definition writer.cpp:49
void addTimeStep(const double &timestep)
Writes the time step to the file.
Definition writer.cpp:172
void appendPointData(const std::string &name, const std::vector< uint8_t > *data)
Writes the scalar point data to the file.
Definition writer.cpp:73
~Writer()
Destructor.
Definition writer.cpp:45
void open(const std::string &filename, const std::string &format="vtu", const std::string &compress_type="")
Open a .vtu file.
Definition writer.cpp:28
Writer()
Constructor.
Definition writer.cpp:16
void close()
Closes the file and store it to the hard disk.
Definition writer.cpp:204
void appendMesh(const std::vector< util::Point > *nodes, const size_t &element_type, const std::vector< size_t > *en_con, const std::vector< util::Point > *u=nullptr)
Writes the mesh data to file.
Definition writer.cpp:61