Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always export vertex attributes in paraview #841

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions src/wmtk/io/ParaviewWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,49 @@
void ParaviewWriter::ParaviewInternalWriter::write(
const std::string& name,
const int64_t stride,
const std::vector<double>& val)
const std::vector<double>& val,
const bool is_cell_field)
{
Eigen::MatrixXd tmp =
Eigen::Map<const Eigen::MatrixXd>(&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));

Check warning on line 64 in src/wmtk/io/ParaviewWriter.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/io/ParaviewWriter.cpp#L62-L64

Added lines #L62 - L64 were not covered by tests
}
}
} 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));

Check warning on line 76 in src/wmtk/io/ParaviewWriter.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/io/ParaviewWriter.cpp#L74-L76

Added lines #L74 - L76 were not covered by tests
}
}
} 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));

Check warning on line 82 in src/wmtk/io/ParaviewWriter.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/io/ParaviewWriter.cpp#L82

Added line #L82 was not covered by tests
} else {
m_paraview_file->add_field(name + "_" + std::to_string(i), tmp.col(i));

Check warning on line 84 in src/wmtk/io/ParaviewWriter.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/io/ParaviewWriter.cpp#L84

Added line #L84 was not covered by tests
}
}
}
}
Expand Down Expand Up @@ -198,9 +219,13 @@
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);
}
}
}


Expand Down
6 changes: 5 additions & 1 deletion src/wmtk/io/ParaviewWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>& val);
void write(
const std::string& name,
const int64_t stride,
const std::vector<double>& val,
const bool is_cell_field);


Eigen::MatrixXd& vertices() { return m_vertices; }
Expand Down
10 changes: 10 additions & 0 deletions tests/io/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}

TEST_CASE("hdf5_3d", "[io]")
{
Eigen::Matrix<int64_t, 2, 4> T;
Expand Down
Loading