8 #include <paraviewo/VTUWriter.hpp>
22 const std::filesystem::path& filename,
23 const std::string& vertices_name,
24 const Eigen::MatrixXi& elements,
41 const std::string& name,
43 const std::vector<double>& val)
46 Eigen::Map<const Eigen::MatrixXd>(&val[0], stride, val.size() / stride).transpose();
48 if (stride == 1 || stride == 2 || stride == 3) {
50 }
else if (stride % 3 == 0) {
51 for (int64_t i = 0; i < stride; i += 3) {
53 name +
"_" + std::to_string(i / 3),
54 tmp.block(0, i, tmp.rows(), 3));
56 }
else if (stride % 2 == 0) {
57 for (int64_t i = 0; i < stride; i += 2) {
59 name +
"_" + std::to_string(i / 2),
60 tmp.block(0, i, tmp.rows(), 2));
63 for (int64_t i = 0; i < stride; ++i) {
64 m_paraview_file->add_cell_field(name +
"_" + std::to_string(i), tmp.col(i));
70 const std::filesystem::path& filename,
71 const std::string& vertices_name,
76 bool write_tetrahedra)
84 std::array<Eigen::MatrixXi, 4> cells;
86 for (
size_t i = 0; i < 4; ++i) {
90 const auto tuples = mesh.
get_all(pt,
true);
91 cells[i].resize(tuples.size(), i + 1);
93 for (
size_t j = 0; j < tuples.size(); ++j) {
94 const auto& t = tuples[j];
96 for (
size_t d = 0; d < cells[i].cols(); ++d) {
101 cells[i](j, 0) = vid;
125 m_writers[0].init(filename.string() +
"_verts.vtu", vertices_name, cells[0],
m_enabled[0]);
126 m_writers[1].init(filename.string() +
"_edges.vtu", vertices_name, cells[1],
m_enabled[1]);
127 m_writers[2].init(filename.string() +
"_faces.vtu", vertices_name, cells[2],
m_enabled[2]);
128 m_writers[3].init(filename.string() +
"_tets.vtu", vertices_name, cells[3],
m_enabled[3]);
132 const std::string& name,
134 const int64_t stride,
135 const std::vector<int64_t>& val,
136 const int64_t default_val)
138 std::vector<double> tmp;
139 tmp.reserve(val.size());
140 for (
const auto& v : val) tmp.push_back(v);
146 const std::string& name,
148 const int64_t stride,
149 const std::vector<double>& val,
150 const double default_val)
156 const std::string& name,
158 const int64_t stride,
159 const std::vector<char>& val,
160 const char default_val)
162 std::vector<double> tmp;
163 tmp.reserve(val.size());
164 for (
const auto& v : val) tmp.push_back(v);
171 const std::string& name,
173 const int64_t stride,
174 const std::vector<Rational>& val,
177 std::vector<double> tmp;
178 tmp.reserve(val.size());
179 for (
const auto& v : val) tmp.push_back(
double(v));
185 const std::string& name,
187 const int64_t stride,
188 const std::vector<double>& val)
193 assert(stride == 2 || stride == 3);
196 Eigen::Map<const Eigen::MatrixXd>(&val[0], stride, val.size() / stride).transpose();
198 for (
int i = 0; i <
m_writers.size(); ++i) {
203 m_writers[type].write(name, stride, val);
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
void write(const std::string &name, const int64_t stride, const std::vector< double > &val)
std::shared_ptr< paraviewo::ParaviewWriter > m_paraview_file
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