8 #include <paraviewo/VTMWriter.hpp>
9 #include <paraviewo/VTUWriter.hpp>
24 const std::filesystem::path& filename,
25 const std::string& vertices_name,
26 const Eigen::MatrixXi& elements,
43 const std::string& name,
45 const std::vector<double>& val,
46 const bool is_cell_field)
49 Eigen::Map<const Eigen::MatrixXd>(&val[0], stride, val.size() / stride).transpose();
51 if (stride == 1 || stride == 2 || stride == 3) {
57 }
else if (stride % 3 == 0) {
58 for (int64_t i = 0; i < stride; i += 3) {
61 name +
"_" + std::to_string(i / 3),
62 tmp.block(0, i, tmp.rows(), 3));
65 name +
"_" + std::to_string(i / 3),
66 tmp.block(0, i, tmp.rows(), 3));
69 }
else if (stride % 2 == 0) {
70 for (int64_t i = 0; i < stride; i += 2) {
73 name +
"_" + std::to_string(i / 2),
74 tmp.block(0, i, tmp.rows(), 2));
77 name +
"_" + std::to_string(i / 2),
78 tmp.block(0, i, tmp.rows(), 2));
82 for (int64_t i = 0; i < stride; ++i) {
84 m_paraview_file->add_cell_field(name +
"_" + std::to_string(i), tmp.col(i));
93 const std::filesystem::path& filename,
94 const std::string& vertices_name,
99 bool write_tetrahedra)
107 std::array<Eigen::MatrixXi, 4> cells;
109 for (
size_t i = 0; i < 4; ++i) {
113 const auto tuples = mesh.
get_all(pt,
true);
114 cells[i].resize(tuples.size(), i + 1);
116 for (
size_t j = 0; j < tuples.size(); ++j) {
117 const auto& t = tuples[j];
119 for (
size_t d = 0; d < cells[i].cols(); ++d) {
124 cells[i](j, 0) = vid;
148 m_writers[0].init(filename.string() +
"_verts.vtu", vertices_name, cells[0],
m_enabled[0]);
149 m_writers[1].init(filename.string() +
"_edges.vtu", vertices_name, cells[1],
m_enabled[1]);
150 m_writers[2].init(filename.string() +
"_faces.vtu", vertices_name, cells[2],
m_enabled[2]);
151 m_writers[3].init(filename.string() +
"_tets.vtu", vertices_name, cells[3],
m_enabled[3]);
153 paraviewo::VTMWriter vtm;
154 if (
m_enabled[0]) vtm.add_dataset(
"verts",
"mesh", filename.string() +
"_verts.vtu");
155 if (
m_enabled[1]) vtm.add_dataset(
"edges",
"mesh", filename.string() +
"_edges.vtu");
156 if (
m_enabled[2]) vtm.add_dataset(
"faces",
"mesh", filename.string() +
"_faces.vtu");
157 if (
m_enabled[3]) vtm.add_dataset(
"tets",
"mesh", filename.string() +
"_tets.vtu");
159 vtm.save(filename.string() +
".vtm");
163 const std::string& name,
165 const int64_t stride,
166 const std::vector<int64_t>& val,
167 const int64_t default_val)
169 std::vector<double> tmp;
170 tmp.reserve(val.size());
171 for (
const auto& v : val) tmp.push_back(v);
177 const std::string& name,
179 const int64_t stride,
180 const std::vector<double>& val,
181 const double default_val)
187 const std::string& name,
189 const int64_t stride,
190 const std::vector<char>& val,
191 const char default_val)
193 std::vector<double> tmp;
194 tmp.reserve(val.size());
195 for (
const auto& v : val) tmp.push_back(v);
202 const std::string& name,
204 const int64_t stride,
205 const std::vector<Rational>& val,
208 std::vector<double> tmp;
209 tmp.reserve(val.size());
210 for (
const auto& v : val) tmp.push_back(
double(v));
216 const std::string& name,
218 const int64_t stride,
219 const std::vector<double>& val)
224 assert(stride == 2 || stride == 3);
227 Eigen::Map<const Eigen::MatrixXd>(&val[0], stride, val.size() / stride).transpose();
229 for (
int i = 0; i <
m_writers.size(); ++i) {
232 }
else if (type == 0) {
233 for (
size_t i = 0; i <
m_writers.size(); ++i) {
237 m_writers[type].write(name, stride, val,
true);
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
std::string m_vertices_name
std::filesystem::path m_filename
std::shared_ptr< paraviewo::ParaviewWriter > m_paraview_file
void write(const std::string &name, const int64_t stride, const std::vector< double > &val, const bool is_cell_field)
Eigen::MatrixXd m_vertices
Eigen::MatrixXi m_elements
void init(const std::filesystem::path &filename, const std::string &vertices_name, const Eigen::MatrixXi &elements, const bool enabled)
~ParaviewInternalWriter()
ParaviewWriter(const std::filesystem::path &filename, const std::string &vertices_name, const Mesh &mesh, bool write_points=true, bool write_edges=true, bool write_faces=true, bool write_tetrahedra=true)
std::array< ParaviewInternalWriter, 4 > m_writers
bool write(const int dim) override
std::array< bool, 4 > m_enabled
void write_internal(const std::string &name, const int64_t type, const int64_t stride, const std::vector< double > &val)
std::string m_vertices_name