32 auto simple = m_field.getInterface<Simple>();
33 auto &moab = m_field.get_moab();
38 constexpr
bool is_debug =
false;
40 if (m_field.get_comm_size() == 1)
44 CHKERR moab.get_entities_by_handle(0, all_ents,
false);
46 auto print_range_on_procs = [&](
const Range &range, std::string name) {
49 << name <<
" on proc [" << m_field.get_comm_rank() <<
"] : \n"
54 auto save_range_to_file = [&](
const Range range, std::string name =
"part") {
56 int rr = m_field.get_comm_rank();
58 ss <<
"out_" << name <<
"_" << rr <<
".vtk";
59 MOFEM_LOG(
"SELF", Sev::inform) <<
"Save debug part mesh " << ss.str();
61 CHKERR moab.create_meshset(MESHSET_SET, meshset);
62 CHKERR moab.add_entities(meshset, range);
64 CHKERR moab.write_file(ss.str().c_str(),
"VTK",
"", &meshset, 1);
65 CHKERR moab.delete_entities(&meshset, 1);
68 auto master_meshset_ptr =
69 m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
70 std::regex((boost::format(
"%s(.*)") %
"MPC_(.*)_LINKS").str()));
71 Range mpc_ents, links_ents;
72 for (
auto m : master_meshset_ptr) {
75 CHKERR moab.get_entities_by_handle(
m->getMeshset(), ents,
true);
77 links_ents.merge(ents);
78 for (
auto &link : links_ents) {
80 CHKERR moab.get_connectivity(&link, 1, verts,
true);
81 mpc_ents.merge(verts);
89 save_range_to_file(all_ents,
"all_ents");
90 print_range_on_procs(mpc_ents,
"mpc_ents");
91 print_range_on_procs(links_ents,
"links_ents");
93 const int dim =
simple->getDim();
98 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
100 Tag part_tag = pcomm->part_tag();
101 Range tagged_sets, proc_ents, off_proc_ents, all_proc_ents;
103 CHKERR moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, NULL, 1,
104 tagged_sets, moab::Interface::UNION);
105 print_range_on_procs(tagged_sets,
"tagged_sets");
106 for (
auto &mit : tagged_sets) {
108 CHKERR moab.tag_get_data(part_tag, &mit, 1, &part);
110 if (part == m_field.get_comm_rank()) {
111 CHKERR moab.get_entities_by_dimension(mit, dim, proc_ents,
true);
112 CHKERR moab.get_entities_by_handle(mit, all_proc_ents,
true);
114 CHKERR moab.get_entities_by_handle(mit, off_proc_ents,
true);
118 print_range_on_procs(proc_ents,
"proc_ents");
120 save_range_to_file(proc_ents);
121 save_range_to_file(off_proc_ents,
"all_proc_ents");
122 all_proc_ents = subtract(all_proc_ents, links_ents);
125 CHKERR moab.get_entities_by_handle(0, all_tets,
true);
129 CHKERR skin.find_skin(0, all_tets.subset_by_dimension(dim),
false, tets_skin);
133 Range proc_ents_skin[4];
134 CHKERR skin.find_skin(0, proc_ents,
false, proc_ents_skin[dim - 1]);
137 Range skin_verts, verts_to_add, edges_to_add;
138 CHKERR moab.get_connectivity(proc_ents_skin[dim - 1],
140 for (
auto &link : links_ents) {
142 CHKERR moab.get_connectivity(&link, 1, verts);
143 for (
auto &vert : verts)
144 if (skin_verts.find(vert) != skin_verts.end()) {
145 edges_to_add.insert(link);
146 verts_to_add.merge(verts);
151 proc_ents_skin[dim - 1] = subtract(proc_ents_skin[dim - 1], tets_skin);
157 CHKERR moab.get_adjacencies(proc_ents_skin[2], 1,
false, proc_ents_skin[1],
158 moab::Interface::UNION);
161 CHKERR moab.get_connectivity(proc_ents_skin[1], adj_ents,
true);
162 proc_ents_skin[0].merge(adj_ents);
164 proc_ents_skin[1].merge(edges_to_add);
165 proc_ents_skin[0].merge(verts_to_add);
167 print_range_on_procs(edges_to_add,
"edges_to_add");
168 print_range_on_procs(verts_to_add,
"verts_to_add");
174 save_range_to_file(proc_ents,
"proc_ents");
175 save_range_to_file(off_proc_ents,
"off_proc_ents");
177 all_tets = off_proc_ents;
179 if (edges_to_add.empty())
180 all_tets.merge(links_ents);
182 save_range_to_file(proc_ents_skin[0],
"proc_ents_skin0");
183 save_range_to_file(proc_ents_skin[1],
"proc_ents_skin1");
185 for (
int dd = dim;
dd >= 0; --
dd) {
186 all_tets = subtract(all_tets, proc_ents_skin[
dd]);
188 print_range_on_procs(proc_ents,
"proc_ents");
191 CHKERR moab.get_entities_by_type(0, MBENTITYSET, meshsets,
true);
192 for (
auto m : meshsets) {
193 CHKERR moab.remove_entities(
m, all_tets);
196 print_range_on_procs(all_tets.subset_by_dimension(2),
"all_tets to delete");
197 save_range_to_file(all_tets.subset_by_dimension(2),
"part_delete");
200 for (
int dd = dim;
dd > 0; --
dd) {
201 CHKERR moab.delete_entities(all_tets.subset_by_dimension(
dd));
207 CHKERR moab.get_entities_by_handle(0, all_ents);
208 std::vector<unsigned char> pstat_tag(all_ents.size(), 0);
209 save_range_to_file(all_ents,
"all_ents_part");
210 CHKERR moab.tag_set_data(pcomm->pstatus_tag(), all_ents,
211 &*pstat_tag.begin());
214 Range all_ents_before;
215 CHKERR moab.get_entities_by_handle(0, all_ents_before);
216 save_range_to_file(all_ents_before,
"all_ents_part_before");
218 CHKERR pcomm->resolve_shared_ents(0, proc_ents, dim, -1, proc_ents_skin);
220 Range all_ents_after;
221 CHKERR moab.get_entities_by_handle(0, all_ents_after);
222 save_range_to_file(all_ents_after,
"all_ents_part_after");