diff --git a/src/wmtk/io/ParaviewWriter.cpp b/src/wmtk/io/ParaviewWriter.cpp index 7831e0548c..074ffe0930 100644 --- a/src/wmtk/io/ParaviewWriter.cpp +++ b/src/wmtk/io/ParaviewWriter.cpp @@ -40,28 +40,49 @@ ParaviewWriter::ParaviewInternalWriter::~ParaviewInternalWriter() void ParaviewWriter::ParaviewInternalWriter::write( const std::string& name, const int64_t stride, - const std::vector& val) + const std::vector& val, + const bool is_cell_field) { Eigen::MatrixXd tmp = Eigen::Map(&val[0], stride, val.size() / stride).transpose(); if (stride == 1 || stride == 2 || stride == 3) { - m_paraview_file->add_cell_field(name, tmp); + if (is_cell_field) { + m_paraview_file->add_cell_field(name, tmp); + } else { + m_paraview_file->add_field(name, tmp); + } } else if (stride % 3 == 0) { for (int64_t i = 0; i < stride; i += 3) { - m_paraview_file->add_cell_field( - name + "_" + std::to_string(i / 3), - tmp.block(0, i, tmp.rows(), 3)); + if (is_cell_field) { + m_paraview_file->add_cell_field( + name + "_" + std::to_string(i / 3), + tmp.block(0, i, tmp.rows(), 3)); + } else { + m_paraview_file->add_field( + name + "_" + std::to_string(i / 3), + tmp.block(0, i, tmp.rows(), 3)); + } } } else if (stride % 2 == 0) { for (int64_t i = 0; i < stride; i += 2) { - m_paraview_file->add_cell_field( - name + "_" + std::to_string(i / 2), - tmp.block(0, i, tmp.rows(), 2)); + if (is_cell_field) { + m_paraview_file->add_cell_field( + name + "_" + std::to_string(i / 2), + tmp.block(0, i, tmp.rows(), 2)); + } else { + m_paraview_file->add_field( + name + "_" + std::to_string(i / 2), + tmp.block(0, i, tmp.rows(), 2)); + } } } else { for (int64_t i = 0; i < stride; ++i) { - m_paraview_file->add_cell_field(name + "_" + std::to_string(i), tmp.col(i)); + if (is_cell_field) { + m_paraview_file->add_cell_field(name + "_" + std::to_string(i), tmp.col(i)); + } else { + m_paraview_file->add_field(name + "_" + std::to_string(i), tmp.col(i)); + } } } } @@ -198,9 +219,13 @@ void ParaviewWriter::write_internal( for (int i = 0; i < m_writers.size(); ++i) { if (m_enabled[i]) m_writers[i].vertices() = V; } - - } else if (m_enabled[type]) - m_writers[type].write(name, stride, val); + } else if (m_enabled[type]) { + m_writers[type].write(name, stride, val, true); + } else if (type == 0) { // vertex attrs are always written + for (size_t i = 0; i < m_writers.size(); ++i) { + if (m_enabled[i]) m_writers[i].write(name, stride, val, false); + } + } } diff --git a/src/wmtk/io/ParaviewWriter.hpp b/src/wmtk/io/ParaviewWriter.hpp index 9cdefbfb58..925bc2868d 100644 --- a/src/wmtk/io/ParaviewWriter.hpp +++ b/src/wmtk/io/ParaviewWriter.hpp @@ -28,7 +28,11 @@ class ParaviewWriter : public MeshWriter const Eigen::MatrixXi& elements, const bool enabled); - void write(const std::string& name, const int64_t stride, const std::vector& val); + void write( + const std::string& name, + const int64_t stride, + const std::vector& val, + const bool is_cell_field); Eigen::MatrixXd& vertices() { return m_vertices; } diff --git a/tests/io/test_io.cpp b/tests/io/test_io.cpp index 5a22b332b5..ea87a5cabe 100644 --- a/tests/io/test_io.cpp +++ b/tests/io/test_io.cpp @@ -92,6 +92,16 @@ TEST_CASE("paraview_2d", "[io]") mesh->serialize(writer); } +TEST_CASE("paraview_2d_vtag", "[io.]") +{ + auto mesh = read_mesh(WMTK_DATA_DIR "/fan.msh"); + mesh->register_attribute("tag", PrimitiveType::Triangle, 1); + mesh->register_attribute("tag1", PrimitiveType::Vertex, 1); + + ParaviewWriter writer("paraview_2d_vtag", "vertices", *mesh, false, false, true, false); + mesh->serialize(writer); +} + TEST_CASE("hdf5_3d", "[io]") { Eigen::Matrix T;