Skip to content

Commit

Permalink
Merge pull request #846 from wildmeshing/teseo/iofix
Browse files Browse the repository at this point in the history
paraview fixes
teseoch authored Dec 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents bd2e000 + f710d78 commit 5b5fffb
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/wmtk/io/ParaviewWriter.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,9 @@
#include <wmtk/utils/Logger.hpp>
#include <wmtk/utils/Rational.hpp>

#include <paraviewo/VTMWriter.hpp>
#include <paraviewo/VTUWriter.hpp>

// #include <paraviewo/HDF5VTUWriter.hpp>

#include <sstream>
@@ -147,6 +149,14 @@ ParaviewWriter::ParaviewWriter(
m_writers[1].init(filename.string() + "_edges.vtu", vertices_name, cells[1], m_enabled[1]);
m_writers[2].init(filename.string() + "_faces.vtu", vertices_name, cells[2], m_enabled[2]);
m_writers[3].init(filename.string() + "_tets.vtu", vertices_name, cells[3], m_enabled[3]);

paraviewo::VTMWriter vtm;
if (m_enabled[0]) vtm.add_dataset("verts", "mesh", filename.string() + "_verts.vtu");
if (m_enabled[1]) vtm.add_dataset("edges", "mesh", filename.string() + "_edges.vtu");
if (m_enabled[2]) vtm.add_dataset("faces", "mesh", filename.string() + "_faces.vtu");
if (m_enabled[3]) vtm.add_dataset("tets", "mesh", filename.string() + "_tets.vtu");

vtm.save(filename.string() + ".vtm");
}

void ParaviewWriter::write(
@@ -219,12 +229,12 @@ 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, 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);
}
} else if (m_enabled[type]) {
m_writers[type].write(name, stride, val, true);
}
}

14 changes: 7 additions & 7 deletions tests/io/test_io.cpp
Original file line number Diff line number Diff line change
@@ -89,17 +89,17 @@ TEST_CASE("paraview_2d", "[io]")
auto mesh = read_mesh(WMTK_DATA_DIR "/fan.msh");

ParaviewWriter writer("paraview_2d", "vertices", *mesh, true, true, true, false);
mesh->serialize(writer);
CHECK_NOTHROW(mesh->serialize(writer));
}

TEST_CASE("paraview_2d_vtag", "[io.]")
TEST_CASE("paraview_2d_vtag", "[io]")
{
auto mesh = read_mesh(WMTK_DATA_DIR "/fan.msh");
mesh->register_attribute<int64_t>("tag", PrimitiveType::Triangle, 1);
mesh->register_attribute<int64_t>("tag1", PrimitiveType::Vertex, 1);

ParaviewWriter writer("paraview_2d_vtag", "vertices", *mesh, false, false, true, false);
mesh->serialize(writer);
ParaviewWriter writer("paraview_2d_vtag", "vertices", *mesh, true, true, true, false);
CHECK_NOTHROW(mesh->serialize(writer));
}

TEST_CASE("hdf5_3d", "[io]")
@@ -110,7 +110,7 @@ TEST_CASE("hdf5_3d", "[io]")
mesh.initialize(T);

HDF5Writer writer("hdf5_3d.hdf5");
mesh.serialize(writer);
CHECK_NOTHROW(mesh.serialize(writer));
}

TEST_CASE("hdf5_multimesh", "[io]")
@@ -157,7 +157,7 @@ TEST_CASE("paraview_3d", "[io]")
mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, mesh);

ParaviewWriter writer("paraview_3d", "vertices", mesh, true, true, true, true);
mesh.serialize(writer);
CHECK_NOTHROW(mesh.serialize(writer));
}

TEST_CASE("msh_3d", "[io]")
@@ -303,5 +303,5 @@ TEST_CASE("attribute_after_split", "[io][.]")

// attribute_after_split_edges.hdf contains a 1 in the "test_attribute"
ParaviewWriter writer("attribute_after_split", "vertices", m, true, true, true, false);
m.serialize(writer);
CHECK_NOTHROW(m.serialize(writer));
}

0 comments on commit 5b5fffb

Please sign in to comment.