28 const std::string &path,
29 const Eigen::MatrixXd &points,
30 const Eigen::MatrixXi &cells,
31 const std::vector<int> &body_ids,
35 std::vector<std::vector<int>> cells_vector(cells.rows(), std::vector<int>(cells.cols()));
36 for (
int i = 0; i < cells.rows(); ++i)
37 for (
int j = 0; j < cells.cols(); ++j)
38 cells_vector[i][j] = cells(i, j);
40 return write(path, points, cells_vector, body_ids, is_volume, binary);
44 const std::string &path,
45 const Eigen::MatrixXd &points,
46 const std::vector<std::vector<int>> &cells,
47 const std::vector<int> &body_ids,
51 assert(body_ids.size() == 0 || body_ids.size() == cells.size());
55 auto &format = out.mesh_format;
56 format.version =
"4.1";
57 format.file_type = binary ? 1 : 0;
58 format.data_size =
sizeof(size_t);
60 auto &nodes = out.nodes;
61 nodes.num_entity_blocks = 1;
62 nodes.num_nodes = points.rows();
63 nodes.min_node_tag = 1;
64 nodes.max_node_tag = points.rows();
65 nodes.entity_blocks.resize(1);
67 auto &block = nodes.entity_blocks[0];
68 block.entity_dim = points.cols();
71 block.num_nodes_in_block = points.rows();
73 for (
int i = 0; i < points.rows(); ++i)
75 block.tags.push_back(i + 1);
76 const auto p = points.row(i);
77 block.data.push_back(p(0));
78 block.data.push_back(p(1));
79 block.data.push_back(is_volume ? p(2) : 0);
83 auto &elements = out.elements;
84 elements.num_entity_blocks = cells.size();
85 elements.num_elements = cells.size();
86 elements.min_element_tag = 1;
87 elements.max_element_tag = cells.size();
88 elements.entity_blocks.resize(cells.size());
90 for (
int i = 0; i < cells.size(); ++i)
92 auto &block = elements.entity_blocks[i];
93 block.entity_dim = points.cols();
95 const int n_local_v = cells[i].size();
97 assert(n_local_v == 3 || n_local_v == 4);
99 block.element_type = n_local_v == 3 ? 2 : 4;
100 block.num_elements_in_block = 1;
101 block.data.push_back(i + 1);
102 for (
int j = 0; j < n_local_v; ++j)
103 block.data.push_back(cells[i][j] + 1);
130 mshio::save_msh(path, out);