19 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
21 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
23 char mesh_out_file[255] =
"out.h5m";
25 char meshset_to_write[255] =
"";
26 PetscBool meshset_to_write_set = PETSC_FALSE;
31 PetscBool bit_ref_set = PETSC_FALSE;
32 int bit_ref_level = 0;
34 CHKERR PetscOptionsBegin(m_field.
get_comm(),
"",
"Read MED tool",
"none");
37 CHKERR PetscOptionsInt(
"-bit_ref_level",
"bit ref level",
"", bit_ref_level,
38 &bit_ref_level, &bit_ref_set);
40 meshset_to_write, 255, &meshset_to_write_set);
41 CHKERR PetscOptionsInt(
"-med_time_step",
"time step",
"", time_step,
42 &time_step, PETSC_NULL);
43 CHKERR PetscOptionsString(
"-output_file",
"output mesh file name",
"",
44 "out.h5m", mesh_out_file, 255, PETSC_NULL);
45 ierr = PetscOptionsEnd();
48 const char *option =
"";
57 Range entities_to_write;
62 bit_level.set(bit_ref_level);
69 entities_to_write = subtract(entities_to_write,
70 entities_to_write.subset_by_type(MBPRISM));
73 subtract(entities_to_write, entities_to_write.subset_by_type(MBQUAD));
75 <<
"Total number of entities in bit ref level " << bit_ref_level
76 <<
": " << entities_to_write.size() << std::endl;
79 <<
"Removing interior edges and face entities"<< std::endl;
81 Range entities_3d = entities_to_write.subset_by_dimension(3);
82 Range entities_2d = entities_to_write.subset_by_dimension(2);
83 Range entities_1d = entities_to_write.subset_by_dimension(1);
89 CHKERR skin.find_skin(0, entities_3d,
false, skin_2d);
90 CHKERR moab.get_adjacencies(skin_2d, 1,
false, skin_1d,
91 moab::Interface::UNION);
94 entities_2d = subtract(entities_2d, skin_2d);
95 entities_to_write = subtract(entities_to_write, entities_2d);
97 entities_1d = subtract(entities_1d, skin_1d);
98 entities_to_write = subtract(entities_to_write, entities_1d);
101 <<
"Removing nodes with no connectivity"<< std::endl;
105 nodes = entities_to_write.subset_by_type(MBVERTEX);
108 for (
auto node : nodes) {
111 CHKERR moab.get_adjacencies(&node_handle, 1, 1,
false, adj_edges,
112 moab::Interface::UNION);
113 if (adj_edges.empty()) {
114 free_nodes.insert(node);
118 for (
auto node : free_nodes) {
120 CHKERR moab.get_coords(&node, 1, coords);
124 entities_to_write = subtract(entities_to_write, free_nodes);
136 Range entities_10000;
137 Range entities_10001;
138 moab.get_entities_by_handle(meshset_10000, entities_10000);
139 moab.get_entities_by_handle(meshset_10001, entities_10001);
141 auto check_face_orientation = [&moab](
const Range &faces) {
142 for (
auto face : faces) {
146 CHKERR(moab.get_adjacencies(&face, 1, 3,
false, adj_tets,
147 moab::Interface::UNION));
150 actual_tets = adj_tets.subset_by_type(MBTET);
155 for (
auto tet : actual_tets) {
156 CHKERR(moab.side_number(tet, face, side_number, sense, offset));
159 std::vector<EntityHandle> nodes_face;
160 CHKERR(moab.get_connectivity(&face, 1, nodes_face));
161 std::vector<EntityHandle> face_nodes_new;
163 face_nodes_new = {nodes_face[1], nodes_face[0], nodes_face[2]};
164 CHKERR(moab.set_connectivity(face, face_nodes_new.data(), 3));
166 CHKERR(moab.side_number(tet, face, side_number, sense, offset));
169 <<
"Face: " << face <<
" has wrong orientation";
176 check_face_orientation(entities_10000);
177 check_face_orientation(entities_10001);
179 }
else if (meshset_to_write_set) {
184 for (
auto &meshset : meshsets_idx) {
185 auto meshset_name = meshset.getName();
186 auto trim_name = [&](std::string &name) {
187 name.erase(std::remove(name.begin(), name.end(),
' '), name.end());
189 trim_name(meshset_name);
191 if (meshset_to_write == meshset_name) {
192 CHKERR moab.get_entities_by_handle(meshset.getMeshset(),
193 entities_to_write,
true);
198 <<
"Wrtiting all entitiies from meshset: " << meshset_to_write
202 CHKERR moab.get_entities_by_handle(0, entities_to_write,
true);
204 <<
"Wrtiting all entitiies" << std::endl;
207 <<
"Number of entities to write: " << entities_to_write.size()
210 for (EntityType ent_type = MBVERTEX; ent_type < MBMAXTYPE; ent_type++) {
212 moab.get_entities_by_type(0, ent_type, entities,
true);
214 ents_to_write = intersect(entities, entities_to_write);
216 if (ents_to_write.empty())
220 <<
"Number of entities to write: " << ents_to_write.size()
221 <<
" of type: " << moab::CN::EntityTypeName(ent_type)
222 <<
" from total of: " << entities.size() << std::endl;
226 boost::shared_ptr<Range> entities_to_write_ptr =
227 boost::make_shared<Range>(entities_to_write);