26#ifndef VULPES_GEOMETRY_MESH_EXPORTER_HPP_
27#define VULPES_GEOMETRY_MESH_EXPORTER_HPP_
39#include <unordered_map>
45#include <vtkAppendFilter.h>
47#include <vtkCellArray.h>
48#include <vtkCellData.h>
49#include <vtkDoubleArray.h>
50#include <vtkFieldData.h>
51#include <vtkFloatArray.h>
53#include <vtkIntArray.h>
54#include <vtkLongLongArray.h>
55#include <vtkMPIController.h>
57#include <vtkPointData.h>
59#include <vtkPolyData.h>
60#include <vtkPolyDataReader.h>
61#include <vtkPolygon.h>
62#include <vtkPolyhedron.h>
63#include <vtkSmartPointer.h>
65#include <vtkTriangle.h>
67#include <vtkUnstructuredGrid.h>
68#include <vtkUnstructuredGridWriter.h>
69#include <vtkXMLPUnstructuredGridWriter.h>
70#include <vtkXMLUnstructuredGridReader.h>
93 Ascii = vtkXMLWriterBase::Ascii,
140 vtkXMLWriterBase::CompressorType::ZLIB;
166template <
typename MeshDerived>
180 const MeshDerived& mesh,
const VtuOptions& options = {})
197 const std::string& filename,
198 const std::optional<VtuOptions>& options = std::nullopt)
const;
230 const std::string& filename,
const VtuOptions& write_options)
const;
241 if constexpr (MeshDerived::self_dim == 2 && !MeshDerived::parallel()) {
262template <
typename MeshDerived>
264 const std::string& filename,
265 const std::optional<VtuOptions>& options)
const {
269 if (filename.ends_with(
".pvtu")) {
270 if constexpr (MeshDerived::parallel()) {
273 throw std::invalid_argument(
274 ".pvtu output is only implemented for ParallelMesh");
279 vtkNew<vtkAppendFilter> merged_grids;
281 merged_grids->AddInputData(grid);
283 merged_grids->MergePointsOff();
284 merged_grids->Update();
285 if (filename.ends_with(
".vtu")) {
286 vtkNew<vtkXMLUnstructuredGridWriter> writer;
287 writer->SetFileName(filename.c_str());
288 writer->SetInputConnection(merged_grids->GetOutputPort());
290 writer->SetDataMode(write_options.
data_mode);
292 }
else if (filename.ends_with(
".vtk")) {
293 vtkNew<vtkUnstructuredGridWriter> writer;
294 writer->SetFileName(filename.c_str());
295 writer->SetInputConnection(merged_grids->GetOutputPort());
296 writer->SetFileTypeToASCII();
299 throw std::invalid_argument(
"Unhandled output format: " + filename);
303template <
typename MeshDerived>
305 const std::string& filename,
const VtuOptions& write_options)
const {
307 MeshDerived::parallel(),
308 "savePvtu is only implemented for ParallelMesh exporters.");
310 vtkNew<vtkAppendFilter> merged_grids;
312 merged_grids->AddInputData(grid);
314 merged_grids->MergePointsOff();
315 merged_grids->Update();
320 static vtkNew<vtkMPIController> vtk_controller;
321 static const bool controller_initialized = []() {
322 vtk_controller->Initialize(
nullptr,
nullptr, 1);
325 (void)controller_initialized;
327 vtkNew<vtkXMLPUnstructuredGridWriter> writer;
331 writer->SetController(vtk_controller);
332 writer->SetFileName(filename.c_str());
333 writer->SetInputConnection(merged_grids->GetOutputPort());
338 writer->SetDataMode(write_options.
data_mode);
354template <
typename MeshDerived>
385 if constexpr (MeshDerived::self_dim == 2 && MeshDerived::parallel()) {
388 ".pvtu/.vtu export of a periodic ParallelMesh is not supported");
390 std::cerr <<
"MeshExporter: periodic ParallelMesh export is not "
391 "supported; output geometry will be wrong at "
392 "periodic boundaries."
398 if constexpr (MeshDerived::self_dim == 2) {
400 }
else if constexpr (MeshDerived::self_dim == 3) {
404 MeshDerived::self_dim == 2 || MeshDerived::self_dim == 3,
405 "Only 2D and 3D meshes are supported.");
409 const auto& vtxs = mesh_ref.getVertexes();
412 for (
const auto& [tag_name, tag] : mesh_ref.getMeshTags().tags[0]) {
413 if constexpr (MeshDerived::parallel()) {
414 const auto num_exported_vtx =
415 static_cast<std::size_t
>(mesh_ref.nLocEntity(0));
416 if (tag.size() == num_exported_vtx || tag.size() == vtxs.size()) {
420 if (tag.size() == vtxs.size()) {
426 std::vector<index_t> cell_id;
427 if constexpr (MeshDerived::parallel()) {
428 cell_id.resize(mesh_ref.nOwnedCells());
429 const auto& local_to_global =
430 mesh_ref.localToGlobal(MeshDerived::self_dim);
431 assert(local_to_global.size() >= cell_id.size());
432 std::copy_n(local_to_global.begin(), cell_id.size(), cell_id.begin());
434 cell_id.resize(mesh_ref.numCells());
435 std::iota(cell_id.begin(), cell_id.end(),
index_t{0});
439 if constexpr (MeshDerived::parallel()) {
440 std::vector<int> owner_rank(mesh_ref.nOwnedCells(),
mpi::rank());
444 const auto& cell_tags = mesh_ref.getMeshTags().tags[MeshDerived::self_dim];
445 for (
const auto& [tag_name, tag] : cell_tags) {
446 const auto num_cells =
static_cast<std::size_t
>(mesh_ref.numCells());
447 if constexpr (MeshDerived::parallel()) {
448 const auto num_exported_cells =
449 static_cast<std::size_t
>(mesh_ref.nOwnedCells());
451 if (tag.size() == num_exported_cells || tag.size() == num_cells) {
455 if (tag.size() == num_cells) {
475 const std::string& label,
476 const Eigen::Map<
const Eigen::Matrix<float_t, -1, -1>> data_view)
const;
489 const std::string& label,
490 const Eigen::Matrix<float_t, -1, -1>& data)
const {
492 label, Eigen::Map<
const Eigen::Matrix<float_t, -1, -1>>{
493 data.data(), data.rows(), data.cols()});
508 const std::string& label,
const std::vector<float_t>& data)
const {
510 label, Eigen::Map<
const Eigen::Matrix<float_t, -1, -1>>{
511 data.data(), 1,
static_cast<Eigen::Index
>(data.size())});
523 const std::string& label,
const std::vector<index_t>& data)
const;
532 template <
typename DataType>
534 const std::string& label,
535 const Eigen::Map<
const Eigen::Vector<DataType, -1>> data_view)
const;
544 template <
typename DataType>
546 const std::string& label,
const std::vector<DataType>& data)
const {
548 label, Eigen::Map<
const Eigen::Vector<DataType, -1>>{
549 data.data(),
static_cast<Eigen::Index
>(data.size())});
583template <
typename MeshDerived>
585 const std::string& label,
586 const Eigen::Map<
const Eigen::Matrix<float_t, -1, -1>> data_view)
const {
589 Eigen::Index num_values_to_write = data_view.cols();
590 if constexpr (MeshDerived::parallel()) {
591 const auto num_exported_vtx =
592 static_cast<Eigen::Index
>(this->
getMeshRef().nLocEntity(0));
594 data_view.cols() == num_exported_vtx ||
596 static_cast<Eigen::Index
>(this->getMeshRef().getVertexes().size()));
597 num_values_to_write = num_exported_vtx;
601 static_cast<Eigen::Index
>(this->getMeshRef().getVertexes().size()));
603 for (Eigen::Index c = 0; c < data_view.rows(); ++c) {
604 vtkNew<vtkFloatArray> scalar;
605 const std::string curr_label =
606 (data_view.rows() == 1) ? label : (label +
"_" + std::to_string(c));
607 scalar->SetName(curr_label.c_str());
609 for (Eigen::Index i = 0; i < num_values_to_write; ++i) {
610 scalar->InsertNextValue(data_view(c, i));
612 vtk_unstructured_grid->GetPointData()->AddArray(scalar);
617template <
typename MeshDerived>
619 const std::string& label,
const std::vector<index_t>& data)
const {
622 std::size_t num_values_to_write = data.size();
623 if constexpr (MeshDerived::parallel()) {
624 const auto num_exported_vtx =
625 static_cast<std::size_t
>(this->
getMeshRef().nLocEntity(0));
627 data.size() == num_exported_vtx ||
628 data.size() == this->getMeshRef().getVertexes().size());
629 num_values_to_write = num_exported_vtx;
631 assert(data.size() == this->getMeshRef().getVertexes().size());
634 auto add = [&](
auto& scalar) {
635 scalar->SetName(label.c_str());
636 for (std::size_t i = 0; i < num_values_to_write; ++i) {
637 scalar->InsertNextValue(data[i]);
639 vtk_unstructured_grid->GetPointData()->AddArray(scalar);
642 if constexpr (std::is_integral_v<index_t> &&
sizeof(
index_t) <= 4) {
643 vtkNew<vtkIntArray> scalar;
645 }
else if constexpr (std::is_integral_v<index_t> &&
sizeof(
index_t) == 8) {
646 vtkNew<vtkLongLongArray> scalar;
650 std::is_integral_v<index_t>,
651 "MeshExporter vertex integer data requires integral index_t");
655template <
typename MeshDerived>
656template <
typename DataType>
658 const std::string& label,
659 const Eigen::Map<
const Eigen::Vector<DataType, -1>> data_view)
const {
662 Eigen::Index num_values_to_write = data_view.size();
663 if constexpr (MeshDerived::parallel()) {
664 const auto num_exported_cells =
665 static_cast<Eigen::Index
>(this->
getMeshRef().nOwnedCells());
667 data_view.size() == num_exported_cells ||
669 static_cast<Eigen::Index
>(this->getMeshRef().numCells()));
670 num_values_to_write = num_exported_cells;
674 static_cast<Eigen::Index
>(this->getMeshRef().numCells()));
676 auto add = [&](
auto& arr) {
677 arr->SetName(label.c_str());
678 for (Eigen::Index i = 0; i < num_values_to_write; ++i) {
679 arr->InsertNextValue(data_view[i]);
681 vtk_unstructured_grid->GetCellData()->AddArray(arr);
683 if constexpr (std::is_same_v<DataType, double>) {
684 vtkNew<vtkDoubleArray> arr;
686 }
else if constexpr (std::is_integral_v<DataType> &&
sizeof(
DataType) <= 4) {
687 vtkNew<vtkIntArray> arr;
689 }
else if constexpr (std::is_integral_v<DataType> &&
sizeof(
DataType) == 8) {
690 vtkNew<vtkLongLongArray> arr;
693 vtkNew<vtkFloatArray> arr;
701template <
typename MeshDerived>
705 const auto& metadata = mesh.getMetadata();
708 for (
const auto& [name, values] : metadata.doubles) {
709 vtkNew<vtkDoubleArray> array;
710 array->SetName(name.c_str());
711 array->SetNumberOfComponents(1);
712 array->SetNumberOfTuples(values.size());
713 for (std::size_t i = 0; i < values.size(); ++i) {
714 array->SetValue(i, values[i]);
716 vtk_unstructured_grid->GetFieldData()->AddArray(array);
720 for (
const auto& [name, values] : metadata.ints) {
721 vtkNew<vtkLongLongArray> array;
722 array->SetName(name.c_str());
723 array->SetNumberOfComponents(1);
724 array->SetNumberOfTuples(values.size());
725 for (std::size_t i = 0; i < values.size(); ++i) {
726 array->SetValue(i,
static_cast<int64_t
>(values[i]));
728 vtk_unstructured_grid->GetFieldData()->AddArray(array);
732template <
typename MeshDerived>
735 this->
m_vtk_grids[0] = vtkSmartPointer<vtkUnstructuredGrid>::New();
738 vtkNew<vtkPoints> points;
741 const auto& vtxs = mesh_ref.getVertexes();
742 if constexpr (MeshDerived::parallel()) {
745 for (
index_t vtx_id = 0; vtx_id < mesh_ref.nLocEntity(0); ++vtx_id) {
746 const auto& point = vtxs[vtx_id];
747 points->InsertNextPoint(point[0], point[1], 0.0);
750 for (
const auto& point : vtxs) {
751 points->InsertNextPoint(point[0], point[1], 0.0);
754 vtk_unstructured_grid->SetPoints(points);
756 vtkNew<vtkCellArray> cells;
760 if constexpr (MeshDerived::parallel()) {
761 return mesh_ref.nOwnedCells();
763 return mesh_ref.numCells();
766 for (
index_t cell_id = 0; cell_id < num_cells; ++cell_id) {
767 const auto cell = mesh_ref.getCellToVtxMap().getRow(cell_id);
768 vtkNew<vtkPolygon> vtk_cell;
769 vtk_cell->GetPointIds()->SetNumberOfIds(cell.size());
770 for (
index_t i = 0; i < cell.size(); ++i) {
771 vtk_cell->GetPointIds()->SetId(i, cell[i]);
773 cells->InsertNextCell(vtk_cell);
775 vtk_unstructured_grid->SetCells(VTK_POLYGON, cells);
778template <
typename MeshDerived>
781 this->
m_vtk_grids[0] = vtkSmartPointer<vtkUnstructuredGrid>::New();
784 const auto& vtxs = mesh_ref.getVertexes();
786 vtkNew<vtkPoints> points;
788 if constexpr (MeshDerived::parallel()) {
791 for (
index_t vtx_id = 0; vtx_id < mesh_ref.nLocEntity(0); ++vtx_id) {
792 const auto& point = vtxs[vtx_id];
793 points->InsertNextPoint(point.data());
796 for (
const auto& point : vtxs) {
797 points->InsertNextPoint(point.data());
800 vtk_unstructured_grid->SetPoints(points);
805 if constexpr (MeshDerived::parallel()) {
806 return mesh_ref.nOwnedCells();
808 return mesh_ref.numCells();
811 for (
index_t cell_id = 0; cell_id < num_cells; ++cell_id) {
812 const auto cell = mesh_ref.getCellToVtxMap().getRow(cell_id);
813 std::vector<vtkIdType> vtk_vtx_ids;
814 for (
index_t i = 0; i < cell.size(); ++i) {
815 vtk_vtx_ids.push_back(cell[i]);
817 vtkNew<vtkIdList> faces;
818 const auto& facet_map = mesh_ref.getCellToFacetMap();
819 const index_t n_faces = facet_map[cell_id].size();
820 for (
index_t i = 0; i < n_faces; ++i) {
821 const index_t face_id = facet_map[cell_id][i];
822 const auto face_vtxs = mesh_ref.getFacetToVtxMap()[face_id];
823 const index_t face_size = face_vtxs.size();
824 faces->InsertNextId(face_size);
826 const auto fw_order =
827 (mesh_ref.getFacetToCellMap()[face_id][0] == cell_id);
829 for (
auto vid : face_vtxs) {
830 faces->InsertNextId(vid);
833 for (
auto it = face_vtxs.end(); it != face_vtxs.begin();) {
834 faces->InsertNextId(*(--it));
838 vtk_unstructured_grid->InsertNextCell(
839 VTK_POLYHEDRON, cell.size(), vtk_vtx_ids.data(), n_faces,
840 faces->GetPointer(0));
856template <
typename MeshDerived>
881 const MeshDerived& mesh,
882 std::size_t min_n_submesh_elem,
889 if constexpr (MeshDerived::self_dim == 2) {
891 }
else if constexpr (MeshDerived::self_dim == 3) {
895 MeshDerived::self_dim == 2 || MeshDerived::self_dim == 3,
896 "Only 2D and 3D meshes are supported.");
900 std::vector<index_t> cell_id(this->
m_vtk_grids.size());
901 if constexpr (MeshDerived::parallel()) {
902 const auto& local_to_global =
903 this->
getMeshRef().localToGlobal(MeshDerived::self_dim);
904 assert(local_to_global.size() >= this->m_vtk_grids.size());
905 std::copy_n(local_to_global.begin(), cell_id.size(), cell_id.begin());
907 std::iota(cell_id.begin(), cell_id.end(),
index_t{0});
911 if constexpr (MeshDerived::parallel()) {
916 for (
const auto& [tag_name, tag] :
917 this->
getMeshRef().getMeshTags().tags[MeshDerived::self_dim]) {
919 const auto num_cells =
static_cast<std::size_t
>(mesh_ref.numCells());
920 if constexpr (MeshDerived::parallel()) {
921 const auto num_exported_cells =
922 static_cast<std::size_t
>(mesh_ref.nOwnedCells());
923 if (tag.size() == num_exported_cells || tag.size() == num_cells) {
927 if (tag.size() == num_cells) {
945 const std::string& label,
946 const datastructure::CrsMap<float_t, index_t>& data)
const;
959 template <
typename DataType>
961 const std::string& label,
962 const Eigen::Map<
const Eigen::Vector<DataType, -1>> data_view)
const;
971 template <
typename DataType>
973 const std::string& label,
const std::vector<DataType>& data)
const {
975 label, Eigen::Map<
const Eigen::Vector<DataType, -1>>{
976 data.data(),
static_cast<Eigen::Index
>(data.size())});
1003template <
typename MeshDerived>
1005 const std::string& label,
1008 if constexpr (MeshDerived::parallel()) {
1010 data.
size() ==
static_cast<index_t>(grids.size()) ||
1011 data.
size() == this->getMeshRef().numCells());
1013 assert(data.
size() ==
static_cast<index_t>(grids.size()));
1015 for (std::size_t grid_id = 0; grid_id < grids.size(); ++grid_id) {
1016 auto grid = grids[grid_id];
1017 const auto cell_data = data[grid_id];
1018 assert(cell_data.size() % grid->GetNumberOfPoints() == 0);
1019 const auto block_size = cell_data.size() / grid->GetNumberOfPoints();
1021 for (Eigen::Index b = 0; b < block_size; ++b) {
1022 vtkNew<vtkFloatArray> scalar;
1023 const std::string curr_label =
1024 (block_size == 1) ? label : (label +
"_" + std::to_string(b));
1025 scalar->SetName(curr_label.c_str());
1026 for (
index_t i = b; i < cell_data.size(); i += block_size) {
1027 scalar->InsertNextValue(cell_data[i]);
1029 grid->GetPointData()->AddArray(scalar);
1034template <
typename MeshDerived>
1035template <
typename DataType>
1037 const std::string& label,
1038 const Eigen::Map<
const Eigen::Vector<DataType, -1>> data_view)
const {
1040 if constexpr (MeshDerived::parallel()) {
1042 data_view.size() ==
static_cast<Eigen::Index
>(grids.size()) ||
1044 static_cast<Eigen::Index
>(this->getMeshRef().numCells()));
1046 assert(data_view.size() ==
static_cast<Eigen::Index
>(grids.size()));
1048 for (std::size_t grid_id = 0; grid_id < grids.size(); ++grid_id) {
1049 auto grid = grids[grid_id];
1050 auto add = [&](
auto& arr) {
1051 arr->SetName(label.c_str());
1052 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
1053 arr->InsertNextValue(data_view[grid_id]);
1055 grid->GetCellData()->AddArray(arr);
1057 if constexpr (std::is_same_v<DataType, double>) {
1058 vtkNew<vtkDoubleArray> arr;
1060 }
else if constexpr (
1061 std::is_integral_v<DataType> &&
sizeof(
DataType) <= 4) {
1062 vtkNew<vtkIntArray> arr;
1064 }
else if constexpr (
1065 std::is_integral_v<DataType> &&
sizeof(
DataType) == 8) {
1066 vtkNew<vtkLongLongArray> arr;
1069 vtkNew<vtkFloatArray> arr;
1075template <
typename MeshDerived>
1077 std::size_t min_n_submesh_elem) {
1082 if constexpr (MeshDerived::parallel()) {
1083 return mesh_ref.nOwnedCells();
1085 return mesh_ref.numCells();
1088 for (
index_t cell_id = 0; cell_id < num_cells; ++cell_id) {
1089 this->
m_vtk_grids.push_back(vtkSmartPointer<vtkUnstructuredGrid>::New());
1090 auto vtk_unstructured_grid = this->
m_vtk_grids.back();
1093 const auto max_area =
1094 cell.
measure() /
static_cast<double>(min_n_submesh_elem);
1096 options.maxarea = max_area;
1097 options.fixedarea = 1;
1104 vtkNew<vtkPoints> points;
1107 points->SetDataType(VTK_DOUBLE);
1109 for (Eigen::Index i = 0; i < pts.cols(); ++i) {
1110 points->InsertNextPoint(pts(0, i), pts(1, i), 0.0);
1112 vtk_unstructured_grid->SetPoints(points);
1115 vtkNew<vtkCellArray> cells;
1116 for (
index_t tri_id = 0; tri_id < tria.cols(); ++tri_id) {
1117 vtkNew<vtkTriangle> vtk_cell;
1118 for (int32_t d = 0; d < 3; ++d) {
1119 vtk_cell->GetPointIds()->SetId(d, tria(d, tri_id));
1121 cells->InsertNextCell(vtk_cell);
1123 vtk_unstructured_grid->SetCells(VTK_TRIANGLE, cells);
1127template <
typename MeshDerived>
1129 std::size_t min_n_submesh_elem) {
1134 if constexpr (MeshDerived::parallel()) {
1135 return mesh_ref.nOwnedCells();
1137 return mesh_ref.numCells();
1140 for (
index_t cell_id = 0; cell_id < num_cells; ++cell_id) {
1141 this->
m_vtk_grids.push_back(vtkSmartPointer<vtkUnstructuredGrid>::New());
1142 auto vtk_unstructured_grid = this->
m_vtk_grids.back();
1145 const auto max_volume =
1146 cell.
measure() /
static_cast<double>(min_n_submesh_elem);
1147 assert(max_volume > 0);
1149 options.maxvolume = max_volume;
1150 options.fixedvolume = 1;
1151 options.maxvolume_length = std::pow(max_volume, 1. / 3.) / 3.;
1158 vtkNew<vtkPoints> points;
1161 points->SetDataType(VTK_DOUBLE);
1163 for (Eigen::Index i = 0; i < pts.cols(); ++i) {
1164 points->InsertNextPoint(pts(0, i), pts(1, i), pts(2, i));
1166 vtk_unstructured_grid->SetPoints(points);
1169 for (
index_t tet_id = 0; tet_id < tets.cols(); ++tet_id) {
1170 vtkNew<vtkTetra> tetra;
1171 for (int32_t d = 0; d < 4; ++d) {
1172 tetra->GetPointIds()->SetId(d, tets(d, tet_id));
1174 vtk_unstructured_grid->InsertNextCell(
1175 tetra->GetCellType(), tetra->GetPointIds());
1180template <
typename MeshType>
1181void exportMesh(
const MeshType& mesh,
const std::string& filename) {
1183 exporter.
save(filename);
1201template <
typename MeshDerived>
1204 if (MeshDerived::self_dim != 2) {
1208 const auto& md = mesh.getMetadata();
1211 if (!md.ints.contains(
"MeshPeriodicTopologyClosed")) {
1215 const auto closed_status = md.ints.at(
"MeshPeriodicTopologyClosed").front();
1217 return closed_status == 1;
1232template <
typename ScalarType,
typename IndexType>
1236 const auto& md = mesh.getMetadata();
1237 assert(md.ints.contains(
"MeshPeriodicTopologyClosed"));
1238 assert(md.ints.at(
"MeshPeriodicTopologyClosed").front() == 1);
1245 return reopened_mesh;
Definition crs_map.hpp:72
IndexType size() const
Get the number of rows in the CRS map.
Definition crs_map.hpp:331
auto measure() const
Definition cell.hpp:128
auto measure() const
Definition cell.hpp:213
A class for a 2D mesh, inheriting from MeshBase.
Definition mesh_2d.hpp:94
Base class for exporting a mesh to VTK file formats.
Definition mesh_exporter.hpp:167
void initializeMeshForExport() const
Initializes the mesh for export, modifying if necessary.
Definition mesh_exporter.hpp:239
const MeshDerived & getMeshRef() const
Gets a reference to the mesh for export (original/modified).
Definition mesh_exporter.hpp:254
std::optional< MeshDerived > m_modified_mesh
Definition mesh_exporter.hpp:218
void save(const std::string &filename, const std::optional< VtuOptions > &options=std::nullopt) const
Saves the mesh data to a file.
Definition mesh_exporter.hpp:263
const MeshDerived & m_mesh
Definition mesh_exporter.hpp:213
VtuOptions m_export_options
Definition mesh_exporter.hpp:214
const auto & getVtkGrids() const
Gets a constant reference to the generated VTK grids.
Definition mesh_exporter.hpp:210
const auto & getMesh() const
Gets a constant reference to the mesh.
Definition mesh_exporter.hpp:204
std::vector< vtkSmartPointer< vtkUnstructuredGrid > > m_vtk_grids
Definition mesh_exporter.hpp:216
void savePvtu(const std::string &filename, const VtuOptions &write_options) const
Saves the mesh data to a parallel VTU file.
Definition mesh_exporter.hpp:304
MeshExporterBase(const MeshDerived &mesh, const VtuOptions &options={})
Constructs a MeshExporterBase for a given mesh.
Definition mesh_exporter.hpp:179
MeshDerived::index_t index_t
The index type used by the mesh.
Definition mesh_exporter.hpp:172
void attachCellData(const std::string &label, const std::vector< DataType > &data) const
Attaches cell data to the sub-meshes.
Definition mesh_exporter.hpp:972
MeshDerived::index_t index_t
The index type used by the mesh.
Definition mesh_exporter.hpp:866
void attachVertexData(const std::string &label, const datastructure::CrsMap< float_t, index_t > &data) const
Attaches vertex data to the sub-meshes.
Definition mesh_exporter.hpp:1004
void buildVtkMesh3D(std::size_t min_n_submesh_elem)
Builds 3D sub-meshes from each cell.
Definition mesh_exporter.hpp:1128
MeshDerived::float_t float_t
The float type used by the mesh.
Definition mesh_exporter.hpp:862
void attachCellData(const std::string &label, const Eigen::Map< const Eigen::Vector< DataType, -1 > > data_view) const
Attaches cell data to the sub-meshes.
Definition mesh_exporter.hpp:1036
MeshExporterSubmesh(const MeshDerived &mesh, std::size_t min_n_submesh_elem, const VtuOptions &options={})
Constructs a MeshExporterSubmesh for a given mesh.
Definition mesh_exporter.hpp:880
void buildVtkMesh2D(std::size_t min_n_submesh_elem)
Builds 2D sub-meshes from each cell.
Definition mesh_exporter.hpp:1076
Exports a single mesh as a single VTK grid.
Definition mesh_exporter.hpp:355
void attachVertexData(const std::string &label, const Eigen::Map< const Eigen::Matrix< float_t, -1, -1 > > data_view) const
Attaches a list of vertex data to the VTK grid.
Definition mesh_exporter.hpp:584
void attachMetadata(const MeshDerived &mesh) const
Attaches metadata (field data) to the VTK grid.
Definition mesh_exporter.hpp:702
void attachVertexData(const std::string &label, const Eigen::Matrix< float_t, -1, -1 > &data) const
Attaches a list of vertex data to the VTK grid.
Definition mesh_exporter.hpp:488
void buildVtkMesh2D()
Builds a 2D VTK mesh from the internal mesh data.
Definition mesh_exporter.hpp:733
void attachCellData(const std::string &label, const std::vector< DataType > &data) const
Attaches a vector of cell data to the VTK grid.
Definition mesh_exporter.hpp:545
void attachCellData(const std::string &label, const Eigen::Map< const Eigen::Vector< DataType, -1 > > data_view) const
Attaches a vector of cell data to the VTK grid.
Definition mesh_exporter.hpp:657
void buildVtkMesh3D()
Builds a 3D VTK mesh from the internal mesh data.
Definition mesh_exporter.hpp:779
MeshDerived::index_t index_t
The index type used by the mesh.
Definition mesh_exporter.hpp:364
MeshDerived::float_t float_t
The float type used by the mesh.
Definition mesh_exporter.hpp:360
MeshExporter(const MeshDerived &mesh, const VtuOptions &options={})
Constructs a MeshExporter for a given mesh.
Definition mesh_exporter.hpp:375
void attachVertexData(const std::string &label, const std::vector< float_t > &data) const
Attaches an instance of vertex data to the VTK grid.
Definition mesh_exporter.hpp:507
Performs tetrahedralization of a 3D cell using the TetGen library.
Definition simplexify.hpp:214
const PointsViewType & getPointList() const
Gets the list of points in the tetrahedralization.
Definition simplexify.hpp:280
const SimplexesViewType & getTetrahedronList() const
Gets the list of tetrahedra in the tetrahedralization.
Definition simplexify.hpp:289
static const tetgen::tetgenbehavior s_tetgen_default_options
Definition simplexify.hpp:235
Performs triangulation of a 2D cell using the Triangle library.
Definition simplexify.hpp:49
const SimplexesViewType & getTriangleList() const
Gets the list of triangles in the triangulation.
Definition simplexify.hpp:125
const PointsViewType & getPointList() const
Gets the list of points in the triangulation.
Definition simplexify.hpp:116
static const triangle::behavior s_triangle_default_options
Definition simplexify.hpp:70
Mesh2D< FloatType, IndexType > openPeriodicTopology(const Mesh2D< FloatType, IndexType > &mesh)
Definition mesh_2d.cpp:1775
bool isPeriodic(const Mesh2D< FloatType, IndexType > &mesh)
Definition mesh_2d.cpp:1598
Definition abs_agg_model.cpp:40
Mesh2D< ScalarType, IndexType > reopenPeriodicMeshForExport(const Mesh2D< ScalarType, IndexType > &mesh)
Reopens a closed 2D periodic mesh for export.
Definition mesh_exporter.hpp:1233
CoordinatePrecision
Specifies the precision for point coordinates in VTU files.
Definition mesh_exporter.hpp:112
@ Float64
64-bit floating-point precision (double).
Definition mesh_exporter.hpp:124
@ Float32
32-bit floating-point precision (float).
Definition mesh_exporter.hpp:118
void exportMesh(const MeshType &mesh, const std::string &filename)
Definition mesh_exporter.hpp:1181
DataMode
Specifies the data mode for writing XML files.
Definition mesh_exporter.hpp:89
@ Ascii
Data is written as plain text (ASCII).
Definition mesh_exporter.hpp:93
@ Binary
Data is written as raw binary.
Definition mesh_exporter.hpp:97
@ Base64
Data is appended in a Base64-encoded format.
Definition mesh_exporter.hpp:103
bool shouldModifyPeriodicMesh(const MeshDerived &mesh)
Determines if a periodic mesh should be modified for export.
Definition mesh_exporter.hpp:1202
@ CellInitFaces
Definition cell.hpp:84
@ CellInitMeasure
Definition cell.hpp:87
static int rank()
Return the MPI rank in MPI_COMM_WORLD.
Definition mpi_wrappers.hpp:116
static int size()
Return the size of MPI_COMM_WORLD.
Definition mpi_wrappers.hpp:124
Definition cell_manager.hpp:38
Configuration options for VTU file export.
Definition mesh_exporter.hpp:133
DataMode data_mode
The data encoding mode.
Definition mesh_exporter.hpp:146
vtkXMLWriterBase::CompressorType compressor_type
The compression type to use for the output file.
Definition mesh_exporter.hpp:139
CoordinatePrecision coordinate_precision
The precision for point coordinates.
Definition mesh_exporter.hpp:153