11 typedef multi_index_container<
12 boost::shared_ptr<RefElement>,
15 ordered_unique<tag<Ent_mi_tag>,
23 tag<Composite_ParentEnt_And_BitsOfRefinedEdges_mi_tag>,
28 const_mem_fun<RefElement,
int,
40 : cOre(const_cast<
Core &>(core)) {}
49 CHKERR moab.get_entities_by_type(meshset, MBEDGE, edges, recursive);
52 CHKERR moab.get_entities_by_type(meshset, MBTET, tets, recursive);
53 CHKERR moab.get_adjacencies(tets, 1,
true, edges, moab::Interface::UNION);
56 CHKERR moab.get_entities_by_type(meshset, MBPRISM, prisms, recursive);
57 for (Range::iterator pit = prisms.begin(); pit != prisms.end(); pit++) {
60 CHKERR moab.get_connectivity(*pit, conn, num_nodes,
true);
61 assert(num_nodes == 6);
64 CHKERR moab.get_adjacencies(&conn[0], 2, 1,
true, edge);
65 assert(edge.size() == 1);
66 edges.insert(edge[0]);
68 CHKERR moab.get_adjacencies(&conn[1], 2, 1,
true, edge);
69 assert(edge.size() == 1);
70 edges.insert(edge[0]);
73 CHKERR moab.get_adjacencies(conn_edge2, 2, 1,
true, edge);
74 assert(edge.size() == 1);
75 edges.insert(edge[0]);
78 CHKERR moab.get_adjacencies(&conn[3], 2, 1,
true, edge);
79 assert(edge.size() == 1);
80 edges.insert(edge[0]);
82 CHKERR moab.get_adjacencies(&conn[4], 2, 1,
true, edge);
83 assert(edge.size() == 1);
84 edges.insert(edge[0]);
87 CHKERR moab.get_adjacencies(conn_edge8, 2, 1,
true, edge);
88 assert(edge.size() == 1);
89 edges.insert(edge[0]);
104 .lower_bound(boost::make_tuple(MBVERTEX, MBEDGE));
107 .upper_bound(boost::make_tuple(MBVERTEX, MBEDGE));
109 ref_parent_ents_view.insert(miit, hi_miit);
111 Range edges = ents.subset_by_type(MBEDGE);
114 <<
"ref level " <<
bit <<
" nb. edges to refine " << edges.size();
117 std::array<std::vector<double>, 3> vert_coords;
118 for (
auto &vc : vert_coords)
119 vc.reserve(edges.size());
121 std::vector<EntityHandle> parent_edge;
122 parent_edge.reserve(edges.size());
124 std::array<double, 9> coords;
126 &coords[0], &coords[1], &coords[2]};
128 &coords[3], &coords[4], &coords[5]};
130 &coords[6], &coords[7], &coords[8]};
135 for (
auto p_eit = edges.pair_begin(); p_eit != edges.pair_end(); ++p_eit) {
136 auto miit_view = ref_parent_ents_view.lower_bound(p_eit->first);
138 Range edge_having_parent_vertex;
139 if (miit_view != ref_parent_ents_view.end()) {
140 for (
auto hi_miit_view = ref_parent_ents_view.upper_bound(p_eit->second);
141 miit_view != hi_miit_view; ++miit_view) {
142 edge_having_parent_vertex.insert(edge_having_parent_vertex.end(),
143 miit_view->get()->getParentEnt());
144 add_bit.insert(add_bit.end(), miit_view->get()->getEnt());
148 Range add_vertex_edges =
149 subtract(
Range(p_eit->first, p_eit->second), edge_having_parent_vertex);
151 for (
auto e : add_vertex_edges)
152 parent_edge.emplace_back(e);
154 for (
auto e : add_vertex_edges) {
158 CHKERR moab.get_connectivity(e, conn, num_nodes,
false);
160 CHKERR moab.get_coords(conn, num_nodes, coords.data());
163 for (
auto j : {0, 1, 2})
164 vert_coords[
j].emplace_back(t_0(
j));
166 }
else if (num_nodes == 3) {
167 for (
auto j : {0, 1, 2})
168 vert_coords[
j].emplace_back(t_2(
j));
171 "edge should have 2 or 3 nodes but have %d", num_nodes);
178 if (!vert_coords[0].empty()) {
179 ReadUtilIface *read_util;
180 CHKERR moab.query_interface(read_util);
181 int num_nodes = vert_coords[0].size();
182 vector<double *> arrays_coord;
183 CHKERR read_util->get_node_coords(3, num_nodes, 0, start_v, arrays_coord);
184 Range verts(start_v, start_v + num_nodes - 1);
185 for (
auto dd : {0, 1, 2}) {
186 std::copy(vert_coords[
dd].begin(), vert_coords[
dd].end(),
190 &*parent_edge.begin());
204 CHKERR moab.get_entities_by_type(meshset, MBTET, tets,
false);
214 auto it = ref_ents_ptr->find(ent);
215 if (it != ref_ents_ptr->end()) {
216 if (it->get()->getParentEnt() != parent && ent != parent) {
231 for (
auto mit = parentsToChange.begin(); mit != parentsToChange.end();
233 auto it = ref_ents_ptr->find(mit->first);
238 "impossible to set parent");
252 &ref_parent_ents_view,
257 for (
int ee = 0; ee != 6; ++ee) {
259 CHKERR moab.side_element(tet, 1, ee, edge);
260 auto eit = ref_parent_ents_view.find(edge);
261 if (eit != ref_parent_ents_view.end()) {
262 edge_new_nodes[ee] = (*eit)->getEnt();
263 split_edges[parent_edges_bit.count()] = ee;
264 parent_edges_bit.set(ee, 1);
285 &ref_parent_ents_view,
290 for (
int ee = 0; ee != 6; ++ee) {
292 CHKERR moab.side_element(tet, 1, ee, edge);
293 auto eit = ref_parent_ents_view.find(edge);
294 if (eit != ref_parent_ents_view.end()) {
295 edge_new_nodes[ee] = (*eit)->getEnt();
296 split_edges[parent_edges_bit.count()] = ee;
297 parent_edges_bit.set(ee, 1);
301 if(parent_edges_bit.count() < 6)
302 parent_edges_bit.reset();
320 CHKERR moab.get_entities_by_type(meshset, MBTET, tets,
false);
328 int verb,
const bool debug) {
334 ReadUtilIface *read_util;
339 Range ents_to_set_bit;
344 auto get_parent_ents_view = [&](
const auto type_child,
345 const auto type_parent) {
349 ref_ents.equal_range(boost::make_tuple(type_child, type_parent));
353 using I = decltype(range.first);
355 boost::function<
bool(
I it)> tester = [&](
I it) {
356 return ((*it)->getBitRefLevel() &
bit).any();
360 ref_parent_ents_view.insert(
f, s);
366 return ref_parent_ents_view;
369 auto ref_parent_ents_view = get_parent_ents_view(MBVERTEX, MBEDGE);
371 auto tets = _tets.subset_by_type(MBTET);
373 auto get_ele_parent_view = [&]() {
374 auto &ref_ents = refined_finite_elements_ptr->get<
Ent_mi_tag>();
376 for (
auto p = tets.pair_begin(); p != tets.pair_end(); ++p) {
377 auto tmi = ref_ents.lower_bound(p->first);
378 auto tme = ref_ents.upper_bound(p->second);
379 ref_ele_parent_view.insert(tmi, tme);
381 return ref_ele_parent_view;
384 auto ref_ele_parent_view = get_ele_parent_view();
386 std::vector<EntityHandle> parent_tets_refinded;
387 std::vector<EntityHandle> vertices_of_created_tets;
388 std::vector<BitRefEdges> parent_edges_bit_vec;
389 std::vector<int> nb_new_tets_vec;
390 std::vector<int> sub_type_vec;
392 parent_tets_refinded.reserve(tets.size());
393 vertices_of_created_tets.reserve(4 * tets.size());
394 parent_edges_bit_vec.reserve(tets.size());
395 nb_new_tets_vec.reserve(tets.size());
396 sub_type_vec.reserve(tets.size());
399 for (
auto tit : tets) {
404 CHKERR moab.get_connectivity(tit, conn, num_nodes,
true);
409 int split_edges[] = {-1, -1, -1, -1, -1, -1};
411 CHKERR set_edge_bits(moab, ref_parent_ents_view, tit, parent_edges_bit,
412 edge_new_nodes, split_edges);
414 if (parent_edges_bit.count()) {
418 std::copy(&conn[0], &conn[4], &_conn_[0]);
422 std::fill(&new_tets_conns[0], &new_tets_conns[8 * 4],
no_handle);
424 int sub_type = -1, nb_new_tets = 0;
425 switch (parent_edges_bit.count()) {
428 tet_type_1(_conn_, split_edges[0], edge_new_nodes[split_edges[0]],
434 tet_type_2(_conn_, split_edges, edge_new_nodes, new_tets_conns);
435 if (sub_type & (4 | 8 | 16)) {
438 }
else if (sub_type == 1) {
446 tet_type_3(_conn_, split_edges, edge_new_nodes, new_tets_conns);
450 }
else if (sub_type <= 7) {
457 tet_type_4(_conn_, split_edges, edge_new_nodes, new_tets_conns);
461 }
else if (sub_type <= 7) {
467 sub_type =
tet_type_5(moab, _conn_, edge_new_nodes, new_tets_conns);
472 tet_type_6(moab, _conn_, edge_new_nodes, new_tets_conns);
480 auto &ref_ele_by_parent_and_ref_edges =
483 auto it_by_ref_edges = ref_ele_by_parent_and_ref_edges.equal_range(
484 boost::make_tuple(tit, parent_edges_bit.to_ulong()));
486 std::vector<EntityHandle> ents_to_set_bit_vec;
487 if (std::distance(it_by_ref_edges.first, it_by_ref_edges.second) ==
488 static_cast<size_t>(nb_new_tets)) {
489 ents_to_set_bit_vec.reserve(nb_new_tets);
490 for (
int tt = 0; it_by_ref_edges.first != it_by_ref_edges.second;
491 it_by_ref_edges.first++, tt++) {
492 auto tet = (*it_by_ref_edges.first)->getEnt();
493 ents_to_set_bit_vec.emplace_back(tet);
497 auto ref_tet_it = refined_ents_ptr->find(tet);
498 if (ref_tet_it == refined_ents_ptr->end()) {
500 "Tetrahedron should be in database");
504 ents_to_set_bit.insert_list(ents_to_set_bit_vec.begin(),
505 ents_to_set_bit_vec.end());
511 parent_tets_refinded.emplace_back(tit);
512 for (
int tt = 0; tt != nb_new_tets; ++tt) {
513 for (
auto nn : {0, 1, 2, 3})
514 vertices_of_created_tets.emplace_back(new_tets_conns[4 * tt + nn]);
516 parent_edges_bit_vec.emplace_back(parent_edges_bit);
517 nb_new_tets_vec.emplace_back(nb_new_tets);
518 sub_type_vec.emplace_back(sub_type);
523 RefEntity_multiIndex::iterator tit_miit;
524 tit_miit = refined_ents_ptr->find(tit);
525 if (tit_miit == refined_ents_ptr->end())
527 "can not find this tet");
530 ents_to_set_bit.insert(tit);
537 const int nb_new_tets = vertices_of_created_tets.size() / 4;
538 read_util->get_element_connect(nb_new_tets, 4, MBTET, 0, start_e, conn_moab);
539 std::copy(vertices_of_created_tets.begin(), vertices_of_created_tets.end(),
541 CHKERR read_util->update_adjacencies(start_e, nb_new_tets, 4, conn_moab);
542 ents_to_set_bit.insert(start_e, start_e + nb_new_tets - 1);
546 for (
auto d : {1, 2}) {
547 CHKERR moab.get_adjacencies(ents_to_set_bit,
d,
true, ents,
548 moab::Interface::UNION);
554 for (
int idx = 0; idx != parent_tets_refinded.size(); ++idx) {
557 const BitRefEdges &parent_edges_bit = parent_edges_bit_vec[idx];
558 const int nb_new_tets = nb_new_tets_vec[idx];
560 std::array<EntityHandle, 8> ref_tets;
561 for (
int tt = 0; tt != nb_new_tets; ++tt, ++start_e)
562 ref_tets[tt] = start_e;
567 nb_new_tets, &parent_edges_bit);
573 map_ref_nodes_by_edges;
576 CHKERR moab.get_adjacencies(&tit, 1, 1,
false, tit_edges);
577 for (
auto edge : tit_edges) {
578 auto eit = ref_parent_ents_view.find(edge);
579 if (eit != ref_parent_ents_view.end()) {
580 map_ref_nodes_by_edges[(*eit)->getParentEnt()] = eit->get()->getEnt();
587 CHKERR moab.get_adjacencies(&tit, 1, 2,
false, tit_faces);
588 Range edges_nodes[6], faces_nodes[4];
592 Range::iterator eit = tit_edges.begin();
593 for (
int ee = 0; eit != tit_edges.end(); eit++, ee++) {
594 CHKERR moab.get_connectivity(&*eit, 1, edges_nodes[ee],
true);
595 auto map_miit = map_ref_nodes_by_edges.find(*eit);
596 if (map_miit != map_ref_nodes_by_edges.end()) {
597 edges_nodes[ee].insert(map_miit->second);
603 Range::iterator fit = tit_faces.begin();
604 for (
int ff = 0; fit != tit_faces.end(); fit++, ff++) {
605 CHKERR moab.get_connectivity(&*fit, 1, faces_nodes[ff],
true);
608 CHKERR moab.get_adjacencies(&*fit, 1, 1,
false, fit_edges);
609 for (Range::iterator eit2 = fit_edges.begin(); eit2 != fit_edges.end();
611 auto map_miit = map_ref_nodes_by_edges.find(*eit2);
612 if (map_miit != map_ref_nodes_by_edges.end()) {
613 faces_nodes[ff].insert(map_miit->second);
620 CHKERR moab.get_connectivity(&tit, 1, tet_nodes,
true);
621 for (std::map<EntityHandle, EntityHandle>::iterator map_miit =
622 map_ref_nodes_by_edges.begin();
623 map_miit != map_ref_nodes_by_edges.end(); map_miit++) {
624 tet_nodes.insert(map_miit->second);
628 CHKERR moab.get_adjacencies(ref_tets.data(), nb_new_tets, 1,
false,
629 ref_edges, moab::Interface::UNION);
631 for (Range::iterator reit = ref_edges.begin(); reit != ref_edges.end();
633 Range ref_edges_nodes;
634 CHKERR moab.get_connectivity(&*reit, 1, ref_edges_nodes,
true);
638 for (; ee < 6; ee++) {
642 if (intersect(edges_nodes[ee], ref_edges_nodes).size() == 2) {
644 CHKERR set_parent(*reit, edge, refined_ents_ptr,
cOre);
652 for (; ff < 4; ff++) {
655 if (intersect(faces_nodes[ff], ref_edges_nodes).size() == 2) {
657 CHKERR set_parent(*reit, face, refined_ents_ptr,
cOre);
666 if (intersect(tet_nodes, ref_edges_nodes).size() == 2) {
667 CHKERR set_parent(*reit, tit, refined_ents_ptr,
cOre);
674 "impossible refined edge");
678 CHKERR moab.get_adjacencies(ref_tets.data(), nb_new_tets, 2,
false,
679 ref_faces, moab::Interface::UNION);
680 Tag th_interface_side;
681 const int def_side[] = {0};
682 CHKERR moab.tag_get_handle(
"INTERFACE_SIDE", 1, MB_TYPE_INTEGER,
684 MB_TAG_CREAT | MB_TAG_SPARSE, def_side);
686 for (
auto rfit : ref_faces) {
687 Range ref_faces_nodes;
688 CHKERR moab.get_connectivity(&rfit, 1, ref_faces_nodes,
true);
691 for (; ff < 4; ff++) {
693 if (intersect(faces_nodes[ff], ref_faces_nodes).size() == 3) {
695 CHKERR set_parent(rfit, face, refined_ents_ptr,
cOre);
698 CHKERR moab.tag_get_data(th_interface_side, &face, 1, &side);
699 CHKERR moab.tag_set_data(th_interface_side, &rfit, 1, &side);
707 if (intersect(tet_nodes, ref_faces_nodes).size() == 3) {
708 CHKERR set_parent(rfit, tit, refined_ents_ptr,
cOre);
712 "impossible refined face");
717 CHKERR set_parent(refined_ents_ptr);
719 ents_to_set_bit,
bit,
true, verb, &ents);
736 ref_ele_parent_view.insert(
737 refined_finite_elements_ptr->get<
Ent_mi_tag>().lower_bound(
738 get_id_for_min_type<MBPRISM>()),
739 refined_finite_elements_ptr->get<
Ent_mi_tag>().upper_bound(
740 get_id_for_max_type<MBPRISM>()));
741 auto &ref_ele_by_parent_and_ref_edges =
745 auto &ref_ents_by_comp =
748 ref_parent_ents_view.insert(
749 ref_ents_by_comp.lower_bound(boost::make_tuple(MBVERTEX, MBEDGE)),
750 ref_ents_by_comp.upper_bound(boost::make_tuple(MBVERTEX, MBEDGE)));
752 CHKERR moab.get_entities_by_type(meshset, MBPRISM, prisms,
false);
753 Range::iterator pit = prisms.begin();
754 for (; pit != prisms.end(); pit++) {
755 auto miit_prism = refined_ents_ptr->get<
Ent_mi_tag>().find(*pit);
756 if (miit_prism == refined_ents_ptr->end()) {
758 "this prism is not in ref database");
762 <<
"ref prism " << **miit_prism;
767 CHKERR moab.get_connectivity(*pit, conn, num_nodes,
true);
768 assert(num_nodes == 6);
771 for (
int ee = 0; ee < 3; ee++) {
772 CHKERR moab.side_element(*pit, 1, ee, edges[ee]);
774 for (
int ee = 6; ee < 9; ee++) {
775 CHKERR moab.side_element(*pit, 1, ee, edges[ee - 3]);
780 std::fill(&edge_nodes[0], &edge_nodes[6],
no_handle);
781 for (
int ee = 0; ee < 6; ee++) {
782 RefEntity_multiIndex_view_by_hashed_parent_entity::iterator miit_view =
783 ref_parent_ents_view.find(edges[ee]);
784 if (miit_view != ref_parent_ents_view.end()) {
785 if (((*miit_view)->getBitRefLevel() &
bit).any()) {
786 edge_nodes[ee] = (*miit_view)->getEnt();
791 if (split_edges.count() == 0) {
792 *(
const_cast<RefEntity *
>(miit_prism->get())->getBitRefLevelPtr()) |=
bit;
800 std::ostringstream ss;
801 ss <<
"prism split edges " << split_edges <<
" count "
802 << split_edges.count() << std::endl;
803 PetscPrintf(m_field.
get_comm(), ss.str().c_str());
807 std::fill(&new_prism_conn[0], &new_prism_conn[4 * 6],
no_handle);
808 int nb_new_prisms = 0;
809 switch (split_edges.count()) {
825 std::ostringstream ss;
826 ss << split_edges <<
" : [ " << conn[0] <<
" " << conn[1] <<
" "
827 << conn[2] <<
" " << conn[3] <<
" " << conn[4] <<
" " << conn[5]
832 std::bitset<4> ref_prism_bit(0);
833 auto it_by_ref_edges = ref_ele_by_parent_and_ref_edges.lower_bound(
834 boost::make_tuple(*pit, split_edges.to_ulong()));
835 auto hi_it_by_ref_edges = ref_ele_by_parent_and_ref_edges.upper_bound(
836 boost::make_tuple(*pit, split_edges.to_ulong()));
837 auto it_by_ref_edges2 = it_by_ref_edges;
838 for (
int pp = 0; it_by_ref_edges2 != hi_it_by_ref_edges;
839 it_by_ref_edges2++, pp++) {
841 *(
const_cast<RefElement *
>(it_by_ref_edges2->get())
842 ->getBitRefLevelPtr()) |=
bit;
843 ref_prism_bit.set(pp, 1);
845 std::ostringstream ss;
846 ss <<
"is refined " << *it_by_ref_edges2 << std::endl;
847 PetscPrintf(m_field.
get_comm(), ss.str().c_str());
850 if (it_by_ref_edges != hi_it_by_ref_edges) {
851 if (ref_prism_bit.count() != (
unsigned int)nb_new_prisms)
853 "data inconsistency");
857 for (
int pp = 0; pp < nb_new_prisms; pp++) {
859 std::ostringstream ss;
860 ss <<
"ref prism " << ref_prism_bit << std::endl;
861 PetscPrintf(m_field.
get_comm(), ss.str().c_str());
863 if (!ref_prism_bit.test(pp)) {
864 CHKERR moab.create_element(MBPRISM, &new_prism_conn[6 * pp], 6,
867 &ref_prisms[pp], 1, &*pit);
874 ->insert(boost::shared_ptr<RefEntity>(
new RefEntity(
876 std::pair<RefElement_multiIndex::iterator, bool> p_fe;
880 ->insert(boost::shared_ptr<RefElement>(
885 ref_prism_bit.set(pp);
888 std::ostringstream ss;
889 ss <<
"add prism: " << **p_fe.first << std::endl;
891 for (
int nn = 0; nn < 6; nn++) {
892 ss << new_prism_conn[nn] <<
" ";
896 PetscPrintf(m_field.
get_comm(), ss.str().c_str());
906 const bool recursive,
int verb) {
910 auto miit = refined_ents_ptr->find(meshset);
911 if (miit == refined_ents_ptr->end()) {
913 "this meshset is not in ref database");
916 meshset,
bit, meshset, MBMAXTYPE, recursive, verb);
917 *(
const_cast<RefEntity *
>(miit->get())->getBitRefLevelPtr()) |=
bit;
928 CHKERR moab.get_entities_by_type(meshset, MBTRI, tris,
false);
940 &ref_parent_ents_view,
945 for (
int ee = 0; ee != 3; ++ee) {
947 CHKERR moab.side_element(tet, 1, ee, edge);
948 auto eit = ref_parent_ents_view.find(edge);
949 if (eit != ref_parent_ents_view.end()) {
950 edge_new_nodes[ee] = (*eit)->getEnt();
951 split_edges[parent_edges_bit.count()] = ee;
952 parent_edges_bit.set(ee, 1);
973 &ref_parent_ents_view,
978 for (
int ee = 0; ee != 3; ++ee) {
980 CHKERR moab.side_element(tet, 1, ee, edge);
981 auto eit = ref_parent_ents_view.find(edge);
982 if (eit != ref_parent_ents_view.end()) {
983 edge_new_nodes[ee] = (*eit)->getEnt();
984 split_edges[parent_edges_bit.count()] = ee;
985 parent_edges_bit.set(ee, 1);
989 if (parent_edges_bit.count() < 3) {
990 parent_edges_bit.reset();
1009 CHKERR moab.get_entities_by_type(meshset, MBTRI, tris,
false);
1017 int verb,
const bool debug) {
1022 ReadUtilIface *read_util;
1026 auto get_parent_ents_view = [&](
const auto type_child,
1027 const auto type_parent) {
1031 ref_ents.equal_range(boost::make_tuple(type_child, type_parent));
1035 using I = decltype(range.first);
1037 boost::function<
bool(
I it)> tester = [&](
I it) {
1038 return ((*it)->getBitRefLevel() &
bit).any();
1042 ref_parent_ents_view.insert(
f, s);
1048 return ref_parent_ents_view;
1051 auto ref_parent_ents_view = get_parent_ents_view(MBVERTEX, MBEDGE);
1053 auto tris = _tris.subset_by_type(MBTRI);
1055 auto get_ele_parent_view = [&]() {
1056 auto &ref_ents = refined_finite_elements_ptr->get<
Ent_mi_tag>();
1058 for (
auto p = tris.pair_begin(); p != tris.pair_end(); ++p) {
1059 auto tmi = ref_ents.lower_bound(p->first);
1060 auto tme = ref_ents.upper_bound(p->second);
1061 ref_ele_parent_view.insert(tmi, tme);
1063 return ref_ele_parent_view;
1066 auto ref_ele_parent_view = get_ele_parent_view();
1068 Range ents_to_set_bit;
1070 std::vector<EntityHandle> parent_tris_refined;
1071 std::vector<EntityHandle> vertices_of_created_tris;
1072 std::vector<BitRefEdges> parent_edges_bit_vec;
1073 std::vector<int> nb_new_tris_vec;
1075 parent_tris_refined.reserve(tris.size());
1076 vertices_of_created_tris.reserve(3 * tris.size());
1077 parent_edges_bit_vec.reserve(tris.size());
1078 nb_new_tris_vec.reserve(tris.size());
1081 for (
auto tit : tris) {
1086 CHKERR moab.get_connectivity(tit, conn, num_nodes,
true);
1091 int split_edges[] = {-1, -1, -1};
1093 CHKERR set_edge_bits(moab, ref_parent_ents_view, tit, parent_edges_bit,
1094 edge_new_nodes, split_edges);
1096 if (parent_edges_bit.count()) {
1100 std::copy(&conn[0], &conn[3], &_conn_[0]);
1104 std::fill(&new_tets_conns[0], &new_tets_conns[4 * 3],
no_handle);
1106 int nb_new_tris = 0;
1107 switch (parent_edges_bit.count()) {
1126 auto &ref_ele_by_parent_and_ref_edges =
1129 auto it_by_ref_edges = ref_ele_by_parent_and_ref_edges.equal_range(
1130 boost::make_tuple(tit, parent_edges_bit.to_ulong()));
1132 std::vector<EntityHandle> ents_to_set_bit_vec;
1133 if (std::distance(it_by_ref_edges.first, it_by_ref_edges.second) ==
1134 static_cast<size_t>(nb_new_tris)) {
1135 ents_to_set_bit_vec.reserve(nb_new_tris);
1136 for (
int tt = 0; it_by_ref_edges.first != it_by_ref_edges.second;
1137 it_by_ref_edges.first++, tt++) {
1138 auto tet = (*it_by_ref_edges.first)->getEnt();
1139 ents_to_set_bit_vec.emplace_back(tet);
1143 auto ref_tet_it = refined_ents_ptr->find(tet);
1144 if (ref_tet_it == refined_ents_ptr->end()) {
1146 "Tetrahedron should be in database");
1150 ents_to_set_bit.insert_list(ents_to_set_bit_vec.begin(),
1151 ents_to_set_bit_vec.end());
1157 parent_tris_refined.emplace_back(tit);
1158 for (
int tt = 0; tt != nb_new_tris; ++tt) {
1159 for (
auto nn : {0, 1, 2})
1160 vertices_of_created_tris.emplace_back(new_tets_conns[3 * tt + nn]);
1162 parent_edges_bit_vec.emplace_back(parent_edges_bit);
1163 nb_new_tris_vec.emplace_back(nb_new_tris);
1168 RefEntity_multiIndex::iterator tit_miit;
1169 tit_miit = refined_ents_ptr->find(tit);
1170 if (tit_miit == refined_ents_ptr->end())
1172 "can not find this tet");
1175 ents_to_set_bit.insert(tit);
1179 const int nb_new_tris = vertices_of_created_tris.size() / 3;
1187 CHKERR read_util->get_element_connect(nb_new_tris, 3, MBTRI, 0, start_e,
1189 std::copy(vertices_of_created_tris.begin(), vertices_of_created_tris.end(),
1191 CHKERR read_util->update_adjacencies(start_e, nb_new_tris, 3, conn_moab);
1192 ents_to_set_bit.insert(start_e, start_e + nb_new_tris - 1);
1196 CHKERR moab.add_entities(*meshset_ptr, ents_to_set_bit);
1197 CHKERR moab.write_file(
"out_refinded_debug.vtk",
"VTK",
"",
1198 meshset_ptr->get_ptr(), 1);
1204 for (
auto d : {1}) {
1205 CHKERR moab.get_adjacencies(ents_to_set_bit,
d,
true, ents,
1206 moab::Interface::UNION);
1212 for (
int idx = 0; idx != parent_tris_refined.size(); ++idx) {
1214 const auto tit = parent_tris_refined[idx];
1215 const auto &parent_edges_bit =
1216 parent_edges_bit_vec[idx];
1217 const auto nb_new_tris =
1218 nb_new_tris_vec[idx];
1221 std::array<EntityHandle, 4> ref_tris;
1222 for (
int tt = 0; tt != nb_new_tris; ++tt, ++start_e)
1223 ref_tris[tt] = start_e;
1228 nb_new_tris, &parent_edges_bit);
1234 map_ref_nodes_by_edges;
1239 CHKERR moab.get_adjacencies(&tit, 1, 1,
false, tit_edges);
1240 for (
auto edge : tit_edges) {
1241 auto eit = ref_parent_ents_view.find(edge);
1242 if (eit != ref_parent_ents_view.end()) {
1243 map_ref_nodes_by_edges[(*eit)->getParentEnt()] = eit->get()->getEnt();
1247 Range edges_nodes[3];
1251 Range::iterator eit = tit_edges.begin();
1252 for (
int ee = 0; eit != tit_edges.end(); eit++, ee++) {
1253 CHKERR moab.get_connectivity(&*eit, 1, edges_nodes[ee],
true);
1254 auto map_miit = map_ref_nodes_by_edges.find(*eit);
1255 if (map_miit != map_ref_nodes_by_edges.end()) {
1256 edges_nodes[ee].insert(map_miit->second);
1263 CHKERR moab.get_connectivity(&tit, 1, tri_nodes,
true);
1264 for (
auto map_miit = map_ref_nodes_by_edges.begin();
1265 map_miit != map_ref_nodes_by_edges.end(); map_miit++) {
1266 tri_nodes.insert(map_miit->second);
1271 CHKERR moab.get_adjacencies(ref_tris.data(), nb_new_tris, 1,
false,
1272 ref_edges, moab::Interface::UNION);
1275 for (
auto reit = ref_edges.begin(); reit != ref_edges.end(); ++reit) {
1276 Range ref_edges_nodes;
1277 CHKERR moab.get_connectivity(&*reit, 1, ref_edges_nodes,
true);
1280 for (; ee < 3; ee++) {
1284 if (intersect(edges_nodes[ee], ref_edges_nodes).size() == 2) {
1286 CHKERR set_parent(*reit, edge, refined_ents_ptr,
cOre);
1295 if (intersect(tri_nodes, ref_edges_nodes).size() == 2) {
1296 CHKERR set_parent(*reit, tit, refined_ents_ptr,
cOre);
1303 "impossible refined edge");
1308 CHKERR set_parent(refined_ents_ptr);
1310 ents_to_set_bit,
bit,
true, verb, &ents);