23using ParentChildKey = std::array<int, 5>;
25struct ParentChildCopy {
33using ParentChildCopies = std::map<int, ParentChildCopy>;
34using ParentChildRecords = std::map<ParentChildKey, ParentChildCopies>;
39 int error = local_error, global_error;
40 CHKERR MPI_Allreduce(&error, &global_error, 1, MPI_INT, MPI_MAX,
comm);
42 SETERRQ(
comm, global_error,
43 "Collective mesh operation failed validation on an MPI rank");
53 const auto type =
mb.type_from_handle(entity);
55 if (
type == MBVERTEX) {
60 "Parent-child synchronisation requires linear simplices");
61 const EntityHandle *conn;
63 CHKERR mb.get_connectivity(entity, conn, count,
false);
64 if (count != moab::CN::Dimension(
type) + 1)
66 "Parent-child synchronisation requires linear connectivity");
69 std::sort(
key.begin() + 1,
key.begin() + 1 + count);
70 if (std::adjacent_find(
key.begin() + 1,
key.begin() + 1 + count) !=
71 key.begin() + 1 + count)
73 "Element has repeated global vertex IDs");
77 "Every selected vertex requires a positive GLOBAL_ID");
82 ParallelComm &pcomm,
const Range &parents,
84 std::vector<ParentChildCopy> &copies) {
87 const auto ids =
mb.globalId_tag();
88 const auto parent_tag =
89 m_field.
getInterface<BitRefManager>()->get_th_RefParentHandle();
90 std::set<ParentChildKey> keys;
91 const auto vertices = entities.subset_by_type(MBVERTEX);
92 for (
auto entity : entities) {
95 CHKERR parentChildKey(
mb, ids, entity, copy.key, copy.connectivity);
96 if (!keys.insert(copy.key).second)
98 "Duplicate global entity identity on one MPI rank");
99 if (
mb.type_from_handle(entity) != MBVERTEX) {
101 CHKERR mb.get_connectivity(&entity, 1, corners);
104 "Selected level is missing bounding vertices");
107 CHKERR pcomm.get_owner(entity, copy.owner);
108 CHKERR pcomm.get_pstatus(entity, copy.status);
109 }
else if (parents.find(entity) == parents.end()) {
114 "Child parent is absent from the selected parent level");
115 std::array<int, 4> unused;
118 copies.push_back(copy);
125 const std::vector<ParentChildCopy> &local,
126 ParentChildRecords &records) {
130 CHKERR parentChildAgree(
comm, local.size() >
static_cast<size_t>(INT_MAX) /
131 sizeof(ParentChildCopy)
134 const int bytes = local.size() *
sizeof(ParentChildCopy);
136 CHKERR MPI_Allgather(&bytes, 1, MPI_INT, counts.data(), 1, MPI_INT,
comm);
138 for (
int rank = 0; rank !=
size; ++rank) {
139 offsets[rank] = total <= INT_MAX ? total : 0;
140 total += counts[rank];
143 std::vector<ParentChildCopy> all(total /
sizeof(ParentChildCopy));
144 CHKERR MPI_Allgatherv(local.data(), bytes, MPI_BYTE, all.data(),
147 for (
int rank = 0; rank !=
size; ++rank)
148 for (
size_t i =
offsets[rank] /
sizeof(ParentChildCopy);
149 i != (
offsets[rank] + counts[rank]) /
sizeof(ParentChildCopy); ++
i)
150 records[all[
i].
key].emplace(rank, all[
i]);
154MoFEMErrorCode parentChildValidate(
const ParentChildRecords &parents,
155 const ParentChildRecords &children) {
157 auto validate_copies = [](
const auto &copies,
bool source) {
159 const auto &first = copies.begin()->second;
160 if (copies.size() > MAX_SHARING_PROCS)
162 "MOAB MAX_SHARING_PROCS exceeded");
163 for (
const auto &[rank, copy] : copies) {
164 if (copy.parent != first.parent || (
source && copy.owner != first.owner))
166 "Copies disagree on ancestry or source owner");
168 if (
source && copies.find(first.owner) == copies.end())
170 "Source owner has no resident source entity");
173 for (
const auto &[
key, copies] : parents)
174 CHKERR validate_copies(copies, true);
175 std::map<ParentChildKey, std::map<int, std::set<ParentChildKey>>>
177 for (
const auto &[
key, copies] : children) {
178 CHKERR validate_copies(copies,
false);
179 const auto &carrier = copies.begin()->second.parent;
180 if (carrier != ParentChildKey{} && parents.count(
key))
182 "New child identity collides with an existing source entity");
184 parents.find(carrier == ParentChildKey{} ?
key : carrier);
185 if (
parent == parents.end())
187 "Child has no selected source carrier");
188 for (
const auto &[rank, copy] : copies) {
191 "Producer does not have the source carrier");
192 if (carrier != ParentChildKey{})
193 subdivisions[carrier][rank].insert(
key);
195 if (
key[0] != MBVERTEX)
197 i <= moab::CN::Dimension(static_cast<EntityType>(
key[0])) + 1; ++
i) {
198 const auto vertex = children.find(ParentChildKey{MBVERTEX,
key[
i]});
199 if (vertex == children.end())
201 "Child connectivity is missing a selected vertex");
202 const auto &v_parent = vertex->second.begin()->second.parent;
203 const auto &residents =
204 parents.at(v_parent == ParentChildKey{} ? vertex->first : v_parent);
205 for (
const auto &[rank, unused] :
parent->second)
206 if (residents.find(rank) == residents.
end())
208 "Parent layout cannot supply child bounding closure");
211 for (
const auto &[
parent, producers] : subdivisions)
212 for (const auto &[rank, subdivision] : producers)
213 if (subdivision != producers.begin()->second)
215 "Concurrent producers disagree on a parent's subdivision");
220 const ParentChildRecords &parents,
221 const ParentChildRecords &children) {
223 const int rank = pcomm.rank();
224 for (
const auto &[
key, copies] : children) {
225 const auto local = copies.find(rank);
226 if (local == copies.end() || local->second.parent == ParentChildKey{} ||
229 const auto &
source = parents.at(local->second.parent);
230 const int inherited_owner =
source.begin()->second.owner;
232 copies.count(inherited_owner) ? inherited_owner : copies.begin()->first;
233 std::vector<int> procs;
234 std::vector<EntityHandle> handles;
235 for (
const auto &[other, copy] : copies)
237 procs.push_back(other);
238 handles.push_back(copy.handle);
240 const auto entity = local->second.handle;
241 CHKERR pcomm.update_remote_data(entity, procs, handles);
246 source.at(rank).status & (PSTATUS_INTERFACE | PSTATUS_GHOST);
251 status |= PSTATUS_NOT_OWNED;
252 if (copies.size() > 2) {
253 status |= PSTATUS_MULTISHARED;
254 std::array<int, MAX_SHARING_PROCS> ps;
255 std::array<EntityHandle, MAX_SHARING_PROCS> hs{};
258 hs[0] = copies.at(
owner).handle;
260 for (
const auto &[other, copy] : copies)
261 if (other !=
owner) {
263 hs[
i++] = copy.handle;
265 CHKERR mb.tag_set_data(pcomm.sharedps_tag(), &entity, 1, ps.data());
266 CHKERR mb.tag_set_data(pcomm.sharedhs_tag(), &entity, 1, hs.data());
282 auto broadcast = [&](
auto &
values) {
284 using Value =
typename std::decay_t<
decltype(
values)>::value_type;
285 unsigned long long count =
values.size();
286 CHKERR MPI_Bcast(&count, 1, MPI_UNSIGNED_LONG_LONG, root,
comm);
287 if (count >
static_cast<unsigned long long>(INT_MAX) /
sizeof(Value))
289 "Mesh transport exceeds MPI count range");
291 CHKERR MPI_Bcast(
values.data(), count *
sizeof(Value), MPI_BYTE, root,
313 std::array<int, 4> ids, owners;
317 std::vector<Cell> local;
318 auto snapshot = [&]() {
321 cells.size() >
static_cast<size_t>(INT_MAX) /
sizeof(Cell))
323 for (
auto cell :
cells) {
324 const EntityHandle *conn;
326 CHKERR mb.get_connectivity(cell, conn,
n,
true);
327 if (
mb.type_from_handle(cell) != MBTET ||
n != 4)
329 "Gather requires linear tetrahedra");
332 CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 4,
row.ids.data());
333 CHKERR mb.get_coords(conn, 4,
row.coordinates.data());
334 for (
int i = 0;
i != 4; ++
i)
336 CHKERR mb.tag_get_data(pc->part_tag(), &cell, 1, &
row.part);
337 for (
int id :
row.ids)
340 "Missing vertex global ID");
343 "Invalid source cell partition");
344 local.push_back(
row);
349 const int bytes = local.size() *
sizeof(Cell);
351 CHKERR MPI_Allgather(&bytes, 1, MPI_INT, counts.data(), 1, MPI_INT,
comm);
353 for (
size_t n = 0;
n != counts.size(); ++
n) {
354 if (total + counts[
n] > INT_MAX)
356 "Global mesh exceeds MPI count range");
362 CHKERR MPI_Gatherv(local.data(), bytes, MPI_BYTE,
rows.data(), counts.data(),
370 std::pair<bool, int> priority;
373 std::map<std::array<int, 4>, Cell> unique;
376 std::sort(
key.begin(),
key.end());
377 auto [
it, inserted] = unique.emplace(
key,
row);
378 if (!inserted &&
it->second.part !=
row.part)
380 "Conflicting source partitions");
381 for (
int n = 0;
n != 4; ++
n) {
382 const std::array<double, 3> x{
row.coordinates[3 *
n],
383 row.coordinates[3 *
n + 1],
384 row.coordinates[3 *
n + 2]};
387 const Vertex vertex{x, {
row.owners[
n] !=
row.rank,
row.rank}};
389 if (!added && vertex.priority <
v->second.priority)
394 std::map<int, int> indices;
395 for (
const auto &[
id, vertex] :
vertices) {
396 indices[id] = next.
points.size();
398 next.
points.push_back(vertex.coordinates);
400 for (
const auto &[
key,
row] : unique) {
401 std::array<int, 4>
c;
402 for (
int n = 0;
n != 4; ++
n)
403 c[
n] = indices.at(
row.ids[
n]);
407 data = std::move(next);
415 const Range &child_entities) {
422 for (
auto entity : subtract(child_entities, source_entities)) {
428 CHKERR mb.tag_set_data(pc->part_tag(), &entity, 1, &part);
436 const Range &preserve) {
441 if (active_bit.none())
444 for (
auto cell : entities.subset_by_type(MBTET)) {
446 CHKERR mb.tag_get_data(pc->part_tag(), &cell, 1, &part);
452 for (
int dim : {0, 1, 2}) {
454 CHKERR mb.get_adjacencies(keep.subset_by_type(MBTET), dim,
false, adj,
455 moab::Interface::UNION);
458 const auto inactive = subtract(entities, keep);
460 intersect(inactive, preserve),
462 auto remove = subtract(inactive, preserve);
463 if (!remove.empty()) {
464 Range shared = remove;
465 CHKERR pc->filter_pstatus(shared, PSTATUS_SHARED, PSTATUS_OR);
468 "Prune the output before registering its sharing");
472 CHKERR mb.get_entities_by_type(0, MBENTITYSET, sets);
473 for (
auto set : sets)
474 CHKERR mb.remove_entities(set, remove);
475 for (
int dim = 3; dim >= 0; --dim) {
476 auto batch = remove.subset_by_dimension(dim);
488 int complete_mesh_rank) {
495 complete_mesh_rank < -1 ||
499 int first_rank, last_rank;
500 CHKERR MPI_Allreduce(&complete_mesh_rank, &first_rank, 1, MPI_INT, MPI_MIN,
502 CHKERR MPI_Allreduce(&complete_mesh_rank, &last_rank, 1, MPI_INT, MPI_MAX,
504 if (first_rank != last_rank)
506 std::vector<ParentChildCopy> local;
507 auto snapshot = [&]() {
509 std::set<ParentChildKey> keys;
510 for (
auto entity : entities) {
514 if (
status & PSTATUS_SHARED)
516 "Connectivity synchronisation requires unregistered output "
518 CHKERR parentChildKey(
mb,
mb.globalId_tag(), entity,
row.key,
520 if (!keys.insert(
row.key).second)
522 "Duplicate local entity identity");
523 if (
mb.type_from_handle(entity) != MBVERTEX) {
531 row.status = PSTATUS_INTERFACE | (
status & PSTATUS_GHOST);
532 CHKERR mb.tag_get_data(pc->part_tag(), &entity, 1, &
row.owner);
534 row.status = PSTATUS_GHOST;
535 local.push_back(
row);
540 ParentChildRecords records;
541 CHKERR parentChildGather(
comm, local, records);
542 for (
const auto &[
key, copies] : records) {
543 if (copies.size() > MAX_SHARING_PROCS ||
544 (
key[0] == MBTET && complete_mesh_rank < 0 && copies.size() != 1))
546 "Invalid cell ownership or sharing count");
547 for (
const auto &[rank, copy] : copies)
548 if (copy.owner != copies.begin()->second.owner)
550 "Inconsistent connectivity copies");
551 const int owner = copies.begin()->second.owner;
552 if (
key[0] == MBTET && !copies.count(
owner))
554 if (
key[0] == MBTET && complete_mesh_rank >= 0 &&
555 !copies.count(complete_mesh_rank))
557 "The complete-mesh rank is missing an active cell");
559 CHKERR parentChildSharing(
mb, *pc, records, records);
560 std::map<std::vector<int>, std::vector<EntityHandle>> interfaces;
561 for (
const auto &[
key, copies] : records) {
563 if (local_copy == copies.end() || copies.size() == 1)
565 std::vector<int> ranks;
566 for (
const auto &[rank, copy] : copies)
568 ranks.push_back(rank);
569 interfaces[ranks].push_back(local_copy->second.handle);
571 CHKERR pc->create_interface_sets(interfaces);
572 CHKERR parentChildSharing(
mb, *pc, records, records);
574 auto part_tag = pc->part_tag();
575 CHKERR mb.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
nullptr, 1,
577 for (
auto set : old_sets) {
578 CHKERR mb.tag_delete_data(part_tag, &set, 1);
580 pc->partition_sets().clear();
582 CHKERR pc->create_part(part);
583 Range part_entities = entities;
584 if (complete_mesh_rank >= 0) {
585 part_entities.clear();
586 for (
auto cell : entities.subset_by_type(MBTET)) {
590 part_entities.insert(cell);
592 for (
int dim : {0, 1, 2}) {
594 CHKERR mb.get_adjacencies(part_entities.subset_by_type(MBTET), dim,
false,
595 closure, moab::Interface::UNION);
599 CHKERR mb.add_entities(part, part_entities);
600 std::set<unsigned int> interface_procs;
601 CHKERR pc->get_interface_procs(interface_procs,
true);
602 CHKERR pc->check_all_shared_handles();
611 auto *pcomm = ParallelComm::get_pcomm(
614 CHKERR parentChildAgree(
comm, !pcomm || parent_bit.none() ||
616 (parent_bit & child_bit).any()
619 const std::array<unsigned long long, 2> levels{parent_bit.to_ullong(),
620 child_bit.to_ullong()};
621 std::array<unsigned long long, 2> lo, hi;
622 CHKERR MPI_Allreduce(levels.data(), lo.data(), 2, MPI_UNSIGNED_LONG_LONG,
624 CHKERR MPI_Allreduce(levels.data(), hi.data(), 2, MPI_UNSIGNED_LONG_LONG,
632 children = subtract(children, children.subset_by_type(MBENTITYSET));
633 std::vector<ParentChildCopy> local_source, local_children;
636 parentChildSnapshot(m_field, *pcomm,
source,
source,
true, local_source));
638 parentChildSnapshot(m_field, *pcomm,
source, children,
639 false, local_children));
640 ParentChildRecords parent_records, child_records;
641 CHKERR parentChildGather(
comm, local_source, parent_records);
642 CHKERR parentChildGather(
comm, local_children, child_records);
644 parentChildValidate(parent_records, child_records));
649 for (
const auto &[
key, copies] : child_records)
650 if (copies.begin()->second.parent == ParentChildKey{}) {
651 const auto local = parent_records.at(
key).find(pcomm->rank());
652 if (local != parent_records.at(
key).end())
653 retained.insert(local->second.handle);
655 CHKERR bits->setEntitiesBitRefLevel(retained, child_bit, verb);
659 for (
int dim = 0; dim != 4; ++dim) {
660 CHKERR parentChildSharing(
mb, *pcomm, parent_records, child_records);
661 std::vector<Range> outgoing(pcomm->size());
662 std::set<int> neighbors;
663 bool transfer =
false;
664 for (
const auto &[
key, copies] : child_records) {
665 const auto &carrier = copies.begin()->second.parent;
666 if (carrier == ParentChildKey{} ||
667 moab::CN::Dimension(
static_cast<EntityType
>(
key[0])) != dim)
669 const auto &destinations = parent_records.at(carrier);
670 const auto owner = destinations.begin()->second.owner;
671 const auto publisher =
672 copies.count(
owner) ?
owner : copies.begin()->first;
673 for (
const auto &[destination, unused] : destinations)
674 if (!copies.count(destination)) {
676 if (publisher ==
static_cast<int>(pcomm->rank())) {
677 outgoing[destination].insert(copies.at(publisher).handle);
678 neighbors.insert(destination);
679 }
else if (destination ==
static_cast<int>(pcomm->rank())) {
680 neighbors.insert(publisher);
686 std::vector<unsigned int> peers(neighbors.begin(), neighbors.end());
687 std::vector<Range *> ranges;
688 for (
auto peer : peers)
689 ranges.push_back(&outgoing[peer]);
690 std::vector<MPI_Request> entity_requests, handle_requests;
693 comm, pcomm->exchange_owned_mesh(peers, ranges, entity_requests,
694 handle_requests,
false,
true,
true));
697 children = subtract(children, children.subset_by_type(MBENTITYSET));
698 local_children.clear();
702 CHKERR parentChildGather(
comm, local_children, child_records);
704 CHKERR parentChildSharing(
mb, *pcomm, parent_records, child_records);
706 const auto parent_tag = bits->get_th_RefParentHandle();
709 for (
const auto &[
key, copies] : child_records) {
710 const auto local = copies.find(pcomm->rank());
711 if (local == copies.end() || local->second.parent == ParentChildKey{})
713 const auto child = local->second.handle;
715 parent_records.at(local->second.parent).at(pcomm->rank()).
handle;
716 const auto indexed = ref_entities->find(child);
717 if (indexed == ref_entities->end()) {
719 }
else if ((*indexed)->getParentEnt() !=
parent) {
722 "Could not update refinement parent index");
725 CHKERR bits->setBitRefLevel(children, child_bit,
false, verb);
727 const auto part_tag = pcomm->part_tag();
728 CHKERR mb.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
nullptr, 1,
732 const auto new_children = subtract(children,
source);
733 for (
auto partition : meshsets)
734 CHKERR mb.remove_entities(partition, new_children);
736 for (
auto it = meshsets_manager->getBegin();
it != meshsets_manager->getEnd();
738 meshsets.insert(
it->getMeshset());
739 for (
auto meshset : meshsets)
740 CHKERR bits->updateMeshsetByEntitiesChildren(meshset, child_bit, meshset,
741 MBMAXTYPE,
false, verb);
742 std::map<std::vector<int>, std::vector<EntityHandle>> interfaces;
743 for (
auto child : children) {
746 std::array<int, MAX_SHARING_PROCS> procs;
747 std::array<EntityHandle, MAX_SHARING_PROCS> handles;
750 CHKERR pcomm->get_sharing_data(child, procs.data(), handles.data(),
status,
752 if (
status & PSTATUS_INTERFACE) {
753 std::sort(procs.begin(), procs.begin() + count);
754 interfaces[std::vector<int>(procs.begin(), procs.begin() + count)]
760 for (
auto meshset : pcomm->interface_sets()) {
761 std::array<int, MAX_SHARING_PROCS> procs;
762 std::array<EntityHandle, MAX_SHARING_PROCS> handles;
765 CHKERR pcomm->get_sharing_data(meshset, procs.data(), handles.data(),
status,
767 std::sort(procs.begin(), procs.begin() + count);
768 const auto group = interfaces.find(
769 std::vector<int>(procs.begin(), procs.begin() + count));
770 if (group != interfaces.end()) {
771 CHKERR mb.add_entities(meshset, group->second.data(), group->second.size());
772 interfaces.erase(group);
775 CHKERR pcomm->create_interface_sets(interfaces);
776 CHKERR parentChildSharing(
mb, *pcomm, parent_records, child_records);
777 std::set<unsigned int> interface_procs;
778 CHKERR pcomm->get_interface_procs(interface_procs,
true);
779 CHKERR pcomm->check_all_shared_handles();
784 Range &ents, std::map<int, Range> *received_ents,
int verb) {
786 ParallelComm *pcomm = ParallelComm::get_pcomm(
790 auto get_pstatus = [&](
const auto ent) {
791 unsigned char pstatus;
794 "can not get pstatus");
798 auto get_sharing_procs = [&](
const auto ent,
const auto pstatus) {
799 std::vector<int> sharing_procs(MAX_SHARING_PROCS, -1);
800 if (pstatus & PSTATUS_MULTISHARED) {
803 pcomm->sharedps_tag(), &ent, 1, &sharing_procs[0]),
804 "can not ger sharing_procs_ptr");
805 }
else if (pstatus & PSTATUS_SHARED) {
808 1, &sharing_procs[0]),
809 "can not get sharing proc");
811 return sharing_procs;
814 auto get_sharing_handles = [&](
const auto ent,
const auto pstatus) {
815 std::vector<EntityHandle> sharing_handles(MAX_SHARING_PROCS, 0);
816 if (pstatus & PSTATUS_MULTISHARED) {
819 pcomm->sharedhs_tag(), &ent, 1, &sharing_handles[0]),
820 "get shared handles");
821 }
else if (pstatus & PSTATUS_SHARED) {
824 1, &sharing_handles[0]),
825 "get sharing handle");
827 return sharing_handles;
831 std::vector<std::vector<EntityHandle>> sbuffer(m_field.
get_comm_size());
833 for (
auto ent : ents) {
835 auto pstatus = get_pstatus(ent);
837 auto sharing_procs = get_sharing_procs(ent, pstatus);
838 auto sharing_handles = get_sharing_handles(ent, pstatus);
841 MOFEM_LOG(
"SYNC", Sev::noisy) <<
"pstatus " << std::bitset<8>(pstatus);
844 for (
int proc = 0; proc < MAX_SHARING_PROCS && -1 != sharing_procs[proc];
846 if (sharing_procs[proc] == -1)
848 "sharing processor not set");
853 const auto handle_on_sharing_proc = sharing_handles[proc];
855 sbuffer[sharing_procs[proc]].push_back(handle_on_sharing_proc);
857 MOFEM_LOG_C(
"SYNC", Sev::noisy,
"send %lu (%lu) to %d at %d\n", ent,
858 handle_on_sharing_proc, sharing_procs[proc],
862 if (!(pstatus & PSTATUS_MULTISHARED))
872 std::vector<int> sbuffer_lengths(
874 const size_t block_size =
875 sizeof(EntityHandle) /
879 if (!sbuffer[proc].
empty()) {
881 sbuffer_lengths[proc] = sbuffer[proc].size() * block_size;
886 sbuffer_lengths[proc] = 0;
898 CHKERR PetscGatherNumberOfMessages(
comm, NULL, &sbuffer_lengths[0], &nrecvs);
904 CHKERR PetscGatherMessageLengths(
comm, nsends, nrecvs, &sbuffer_lengths[0],
917 MPI_Request *r_waits;
921 CHKERR PetscPostIrecvInt(
comm,
tag, nrecvs, onodes, olengths, &rbuf,
924 MPI_Request *s_waits;
925 CHKERR PetscMalloc1(nsends, &s_waits);
928 for (
int proc = 0, kk = 0; proc < m_field.
get_comm_size(); proc++) {
929 if (!sbuffer_lengths[proc])
931 CHKERR MPI_Isend(&(sbuffer[proc])[0],
932 sbuffer_lengths[proc],
947 MOFEM_LOG_C(
"SYNC", Sev::verbose,
"Rank %d nb. before ents %zu\n",
953 for (
int kk = 0; kk < nrecvs; kk++) {
955 int len = olengths[kk];
956 int *data_from_proc = rbuf[kk];
958 for (
int ee = 0; ee < len;) {
960 bcopy(&data_from_proc[ee], &ent,
sizeof(EntityHandle));
964 (*received_ents)[onodes[kk]].insert(ent);
970 MOFEM_LOG_C(
"SYNC", Sev::noisy,
"received %lu from %d at %d\n", ent,
980 MOFEM_LOG_C(
"SYNC", Sev::verbose,
"Rank %d nb. after ents %zu",
986 CHKERR PetscFree(s_waits);
987 CHKERR PetscFree(rbuf[0]);
989 CHKERR PetscFree(r_waits);
991 CHKERR PetscFree(olengths);
1007 CHKERR m_field.
get_moab().get_entities_by_handle(idm, ents,
false);
1016 ParallelComm *pcomm = ParallelComm::get_pcomm(
1021 Range shared = ents;
1022 CHKERR pcomm->filter_pstatus(shared, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1,
1024 CHKERR pcomm->filter_pstatus(shared, PSTATUS_SHARED | PSTATUS_MULTISHARED,
1025 PSTATUS_OR, -1,
nullptr);
1030 auto get_pstatus = [&](
const auto ent) {
1031 unsigned char pstatus;
1034 "can not get pstatus");
1038 auto get_sharing_procs = [&](
const auto ent,
const auto pstatus) {
1039 std::vector<int> sharing_procs(MAX_SHARING_PROCS, -1);
1040 if (pstatus & PSTATUS_MULTISHARED) {
1043 pcomm->sharedps_tag(), &ent, 1, &sharing_procs[0]),
1044 "can not ger sharing_procs_ptr");
1045 }
else if (pstatus & PSTATUS_SHARED) {
1048 1, &sharing_procs[0]),
1049 "can not get sharing proc");
1051 return sharing_procs;
1054 auto get_sharing_handles = [&](
const auto ent,
const auto pstatus) {
1055 std::vector<EntityHandle> sharing_handles(MAX_SHARING_PROCS, 0);
1056 if (pstatus & PSTATUS_MULTISHARED) {
1059 pcomm->sharedhs_tag(), &ent, 1, &sharing_handles[0]),
1060 "get shared handles");
1061 }
else if (pstatus & PSTATUS_SHARED) {
1064 1, &sharing_handles[0]),
1065 "get sharing handle");
1067 return sharing_handles;
1070 auto get_parent_and_bit = [&](
const auto ent) {
1073 m_field.
get_moab().tag_get_data(th_RefParentHandle, &ent, 1, &
parent),
1077 m_field.
get_moab().tag_get_data(th_RefBitLevel, &ent, 1, &
bit),
1082 auto set_parent = [&](
const auto ent,
const auto parent) {
1083 return m_field.
get_moab().tag_set_data(th_RefParentHandle, &ent, 1,
1087 auto set_bit = [&](
const auto ent,
const auto bit) {
1088 return m_field.
get_moab().tag_set_data(th_RefBitLevel, &ent, 1, &
bit);
1092 std::vector<std::vector<unsigned long long>> sbuffer(m_field.
get_comm_size());
1094 for (
auto ent : shared) {
1096 auto pstatus = get_pstatus(ent);
1097 auto sharing_procs = get_sharing_procs(ent, pstatus);
1098 auto sharing_handles = get_sharing_handles(ent, pstatus);
1099 auto [
parent,
bit] = get_parent_and_bit(ent);
1102 MOFEM_LOG(
"SYNC", Sev::noisy) <<
"pstatus " << std::bitset<8>(pstatus);
1105 auto pstatus_parent = get_pstatus(
parent);
1106 auto sharing_procs_parent = get_sharing_procs(
parent, pstatus_parent);
1107 auto sharing_handles_parent = get_sharing_handles(
parent, pstatus_parent);
1109 for (
int proc = 0; proc < MAX_SHARING_PROCS && -1 != sharing_procs[proc];
1111 if (sharing_procs[proc] == -1)
1113 "sharing processor not set");
1117 auto it = std::find(sharing_procs_parent.begin(),
1118 sharing_procs_parent.end(), sharing_procs[proc]);
1119 if (
it == sharing_procs_parent.end()) {
1121 "Sharing proc for parent entity can not be found proc = %u",
1122 sharing_procs[proc]);
1125 auto handle_on_sharing_proc = sharing_handles[proc];
1126 auto parent_handle_on_sharing_proc =
1127 sharing_handles_parent[std::distance(sharing_procs_parent.begin(),
1129 sbuffer[sharing_procs[proc]].push_back(handle_on_sharing_proc);
1130 sbuffer[sharing_procs[proc]].push_back(parent_handle_on_sharing_proc);
1132 sbuffer[sharing_procs[proc]].push_back(
bit.to_ullong());
1133 }
catch (std::exception &ex) {
1134 MOFEM_LOG(
"SELF", Sev::warning) << ex.what();
1136 <<
"On " << ent <<
" "
1138 MOFEM_LOG(
"SELF", Sev::warning) <<
"For bit ref " <<
bit;
1141 MOFEM_LOG_C(
"SYNC", Sev::noisy,
"send %lu (%lu) to %d at %d\n", ent,
1142 handle_on_sharing_proc, sharing_procs[proc],
1145 if (!(pstatus & PSTATUS_MULTISHARED))
1150 for (
int proc = 0; proc < MAX_SHARING_PROCS && -1 != sharing_procs[proc];
1152 if (sharing_procs[proc] == -1)
1154 "sharing processor not set");
1157 auto handle_on_sharing_proc = sharing_handles[proc];
1158 sbuffer[sharing_procs[proc]].push_back(handle_on_sharing_proc);
1159 sbuffer[sharing_procs[proc]].push_back(
parent);
1162 sbuffer[sharing_procs[proc]].push_back(
bit.to_ullong());
1163 }
catch (std::exception &ex) {
1164 MOFEM_LOG(
"SELF", Sev::warning) << ex.what();
1166 <<
"On " << ent <<
" "
1168 MOFEM_LOG(
"SELF", Sev::warning) <<
"For bit ref " <<
bit;
1172 MOFEM_LOG_C(
"SYNC", Sev::noisy,
"send %lu (%lu) to %d at %d\n", ent,
1173 handle_on_sharing_proc, sharing_procs[proc],
1176 if (!(pstatus & PSTATUS_MULTISHARED))
1184 std::vector<int> sbuffer_lengths(
1187 const size_t block_size =
sizeof(
unsigned long long) /
sizeof(
int);
1188 for (
int proc = 0; proc < m_field.
get_comm_size(); proc++) {
1190 if (!sbuffer[proc].
empty()) {
1192 sbuffer_lengths[proc] = sbuffer[proc].size() * block_size;
1197 sbuffer_lengths[proc] = 0;
1209 CHKERR PetscGatherNumberOfMessages(
comm, NULL, &sbuffer_lengths[0], &nrecvs);
1215 CHKERR PetscGatherMessageLengths(
comm, nsends, nrecvs, &sbuffer_lengths[0],
1216 &onodes, &olengths);
1228 MPI_Request *r_waits;
1232 CHKERR PetscPostIrecvInt(
comm,
tag, nrecvs, onodes, olengths, &rbuf,
1235 MPI_Request *s_waits;
1236 CHKERR PetscMalloc1(nsends, &s_waits);
1239 for (
int proc = 0, kk = 0; proc < m_field.
get_comm_size(); proc++) {
1240 if (!sbuffer_lengths[proc])
1242 CHKERR MPI_Isend(&(sbuffer[proc])[0],
1243 sbuffer_lengths[proc],
1259 "Rank %d nb. shared to synchronise parents ents %zu\n",
1264 for (
int kk = 0; kk < nrecvs; kk++) {
1266 int len = olengths[kk];
1267 int *data_from_proc = rbuf[kk];
1269 for (
int ee = 0; ee < len;) {
1272 unsigned long long uulong_bit;
1273 bcopy(&data_from_proc[ee], &ent,
sizeof(EntityHandle));
1275 bcopy(&data_from_proc[ee], &
parent,
sizeof(EntityHandle));
1277 bcopy(&data_from_proc[ee], &uulong_bit,
sizeof(
unsigned long long));
1284 MOFEM_LOG_C(
"SYNC", Sev::noisy,
"received %lu (%lu) from %d at %d\n",
1292 CHKERR PetscFree(s_waits);
1293 CHKERR PetscFree(rbuf[0]);
1295 CHKERR PetscFree(r_waits);
1296 CHKERR PetscFree(onodes);
1297 CHKERR PetscFree(olengths);
1307 const Problem *problem_ptr,
const std::string &fe_name,
int verb) {
1310 ParallelComm *pcomm = ParallelComm::get_pcomm(
1312 std::vector<int> shprocs(MAX_SHARING_PROCS, 0);
1313 std::vector<EntityHandle> shhandles(MAX_SHARING_PROCS, 0);
1320 CHKERR PetscLayoutGetRange(layout, &gid, &last_gid);
1321 CHKERR PetscLayoutDestroy(&layout);
1331 0, (*fe_miit)->getFEUId()));
1335 get_id_for_max_type<MBENTITYSET>(), (*fe_miit)->getFEUId()));
1336 for (; fit != hi_fe_it; ++fit) {
1338 auto ent = (*fit)->getEnt();
1339 auto part = (*fit)->getPart();
1342 CHKERR m_field.
get_moab().tag_set_data(pcomm->part_tag(), &ent, 1, &part);
1343 if (part == pcomm->rank()) {
1350 if (pcomm->size() > 1) {
1352 unsigned char pstatus = 0;
1353 if (pcomm->rank() != part) {
1354 pstatus = PSTATUS_NOT_OWNED;
1355 pstatus |= PSTATUS_GHOST;
1358 if (pcomm->size() > 2) {
1359 pstatus |= PSTATUS_SHARED;
1360 pstatus |= PSTATUS_MULTISHARED;
1362 pstatus |= PSTATUS_SHARED;
1366 for (
size_t rr = 0; rr < pcomm->size(); ++rr) {
1367 if (rr != pcomm->rank()) {
1368 shhandles[rrr] = ent;
1373 for (; rrr != pcomm->size(); ++rrr)
1376 if (pstatus & PSTATUS_SHARED) {
1377 CHKERR m_field.
get_moab().tag_set_data(pcomm->sharedp_tag(), &ent, 1,
1379 CHKERR m_field.
get_moab().tag_set_data(pcomm->sharedh_tag(), &ent, 1,
1383 if (pstatus & PSTATUS_MULTISHARED) {
1384 CHKERR m_field.
get_moab().tag_set_data(pcomm->sharedps_tag(), &ent, 1,
1386 CHKERR m_field.
get_moab().tag_set_data(pcomm->sharedhs_tag(), &ent, 1,
1389 CHKERR m_field.
get_moab().tag_set_data(pcomm->pstatus_tag(), &ent, 1,
1395 CHKERR pcomm->exchange_tags(th_gid, ents);
1400 const std::string
name,
const std::string &fe_name,
int verb) {
1411 const int num_entities,
1412 const int owner_proc,
int verb) {
1418 ParallelComm *pcomm = ParallelComm::get_pcomm(
1421 Range all_ents_range;
1422 all_ents_range.insert_list(entities, entities + num_entities);
1424 auto get_tag = [&]() {
1425 const int negone = -1;
1427 m_field.
get_moab().tag_get_handle(
"TMP_GLOBAL_ID_TAG_NAME", 1,
1428 MB_TYPE_INTEGER,
th,
1429 MB_TAG_CREAT | MB_TAG_SPARSE, &negone);
1433 auto delete_tag = [&](
auto &&th_gid) {
1439 auto resolve_shared_ents = [&](
auto &&th_gid,
auto &all_ents_range) {
1440 auto set_gid = [&](
auto &th_gid) {
1441 std::vector<int> gids(num_entities);
1442 for (
size_t g = 0;
g != all_ents_range.size(); ++
g)
1450 auto get_skin_ents = [&](
auto &all_ents_range) {
1451 std::array<Range, 4> proc_ents_skin;
1452 proc_ents_skin[3] = all_ents_range.subset_by_dimension(3);
1453 proc_ents_skin[2] = all_ents_range.subset_by_dimension(2);
1454 proc_ents_skin[1] = all_ents_range.subset_by_dimension(1);
1455 proc_ents_skin[0] = all_ents_range.subset_by_dimension(0);
1456 return proc_ents_skin;
1459 auto resolve_dim = [&](
auto &all_ents_range) {
1460 for (
int resolve_dim = 3; resolve_dim >= 0; --resolve_dim) {
1461 if (all_ents_range.num_of_dimension(resolve_dim))
1467 auto get_proc_ent = [&](
auto &all_ents_range) {
1470 proc_ent = all_ents_range;
1474 auto resolve_shared_ents = [&](
auto &&proc_ents,
auto &&skin_ents) {
1475 return pcomm->resolve_shared_ents(
1476 0, proc_ents, resolve_dim(all_ents_range),
1477 resolve_dim(all_ents_range), skin_ents.data(), set_gid(th_gid));
1480 CHKERR resolve_shared_ents(get_proc_ent(all_ents_range),
1481 get_skin_ents(all_ents_range));
1486 CHKERR delete_tag(resolve_shared_ents(get_tag(), all_ents_range));
1488 if (verb >=
NOISY) {
1490 auto print_owner = [&](
const EntityHandle e) {
1492 int moab_owner_proc;
1493 EntityHandle moab_owner_handle;
1494 CHKERR pcomm->get_owner_handle(e, moab_owner_proc, moab_owner_handle);
1496 unsigned char pstatus = 0;
1498 CHKERR m_field.
get_moab().tag_get_data(pcomm->pstatus_tag(), &e, 1,
1501 std::vector<int> shprocs(MAX_SHARING_PROCS, 0);
1502 std::vector<EntityHandle> shhandles(MAX_SHARING_PROCS, 0);
1504 CHKERR m_field.
get_moab().tag_get_data(pcomm->sharedp_tag(), &e, 1,
1506 CHKERR m_field.
get_moab().tag_get_data(pcomm->sharedh_tag(), &e, 1,
1508 if (pstatus & PSTATUS_MULTISHARED) {
1509 CHKERR m_field.
get_moab().tag_get_data(pcomm->sharedps_tag(), &e, 1,
1511 CHKERR m_field.
get_moab().tag_get_data(pcomm->sharedhs_tag(), &e, 1,
1515 std::ostringstream ss;
1518 if (!(pstatus & PSTATUS_NOT_OWNED))
1520 if (pstatus & PSTATUS_SHARED)
1521 ss <<
"PSTATUS_SHARED ";
1522 if (pstatus & PSTATUS_MULTISHARED)
1523 ss <<
"PSTATUS_MULTISHARED ";
1525 ss <<
"owner " << moab_owner_proc <<
" (" << owner_proc <<
") ";
1529 ss << shprocs[r] <<
" ";
1531 ss <<
"shhandles: ";
1533 ss << shhandles[r] <<
" ";
1536 MOFEM_LOG(
"SYNC", Sev::noisy) << ss.str();
1542 for (
auto e : all_ents_range)
1551 const int owner_proc,
1556 const int num_ents = entities.size();
1557 std::vector<EntityHandle> vec_ents(num_ents);
1558 std::copy(entities.begin(), entities.end(), vec_ents.begin());
1567 const int owner_proc,
int verb) {
1572 std::vector<EntityHandle> field_ents;
1573 CHKERR m_field.
get_moab().get_entities_by_handle(field_meshset, field_ents,
1587 Range exchange_ents_data_verts, exchange_ents_data;
1596 for (
auto it = lo;
it != hi; ++
it)
1599 ((*it)->getPStatus()) &&
1601 (*it)->getNbDofsOnEnt()
1604 if ((*it)->getEntType() == MBVERTEX)
1605 exchange_ents_data_verts.insert((*it)->getEnt());
1607 exchange_ents_data.insert((*it)->getEnt());
1611 ParallelComm *pcomm = ParallelComm::get_pcomm(
1614 auto exchange = [&](
const Range &ents,
Tag th) {
1616 if (!ents.empty()) {
1617 std::vector<Tag> tags;
1619 CHKERR pcomm->exchange_tags(tags, tags, ents);
1624 CHKERR exchange(exchange_ents_data_verts, field_ptr->th_FieldDataVerts);
1625 CHKERR exchange(exchange_ents_data, field_ptr->th_FieldData);
1631 const Range &ents,
const int dim,
const int adj_dim,
const int n_parts,
1632 Tag *th_vertex_weights,
Tag *th_edge_weights,
Tag *th_part_weights,
1633 int verb,
const bool debug,
const bool preserve_vertex_ids) {
1638 int rstart, rend, nb_elems;
1642 CHKERR PetscLayoutSetBlockSize(layout, 1);
1643 CHKERR PetscLayoutSetSize(layout, ents.size());
1644 CHKERR PetscLayoutSetUp(layout);
1645 CHKERR PetscLayoutGetSize(layout, &nb_elems);
1646 CHKERR PetscLayoutGetRange(layout, &rstart, &rend);
1647 CHKERR PetscLayoutDestroy(&layout);
1650 <<
"Finite elements in problem: row lower " << rstart <<
" row upper "
1651 << rend <<
" nb. elems " << nb_elems <<
" ( " << ents.size() <<
" )";
1656 std::vector<EntityHandle> weight_ents;
1657 weight_ents.reserve(rend - rstart + 1);
1661 std::vector<int> adj;
1662 AdjBridge(
const EntityHandle ent, std::vector<int> &adj)
1663 : ent(ent), adj(adj) {}
1666 typedef multi_index_container<
1670 hashed_unique<member<AdjBridge, EntityHandle, &AdjBridge::ent>>
1675 auto get_it = [&](
auto i) {
1676 auto it = ents.begin();
1677 for (;
i > 0; --
i) {
1678 if (
it == ents.end())
1686 proc_ents.insert(get_it(rstart), get_it(rend));
1687 if (proc_ents.size() != rend - rstart)
1689 "Wrong number of elements in range %zu != %zu", proc_ents.size(),
1690 static_cast<size_t>(rend - rstart));
1694 proc_ents, adj_dim,
true, all_dim_ents, moab::Interface::UNION);
1696 AdjBridgeMap adj_bridge_map;
1697 auto hint = adj_bridge_map.begin();
1698 std::vector<int> adj;
1699 for (
auto ent : all_dim_ents) {
1701 CHKERR m_field.
get_moab().get_adjacencies(&ent, 1, dim,
false, adj_ents);
1702 adj_ents = intersect(adj_ents, ents);
1704 adj.reserve(adj_ents.size());
1705 for (
auto a : adj_ents)
1706 adj.emplace_back(ents.index(
a));
1707 hint = adj_bridge_map.emplace_hint(hint, ent, adj);
1713 const int nb_loc_elements = rend - rstart;
1714 std::vector<int>
i(nb_loc_elements + 1, 0),
j;
1716 std::vector<int> row_adj;
1717 Range::iterator fe_it;
1719 size_t max_row_size;
1720 for (fe_it = proc_ents.begin(), ii = rstart, jj = 0, max_row_size = 0;
1721 fe_it != proc_ents.end(); ++fe_it, ++ii) {
1725 "not yet implemented, don't know what to do for meshset "
1730 CHKERR m_field.
get_moab().get_adjacencies(&*fe_it, 1, adj_dim,
false,
1732 dim_ents = intersect(dim_ents, all_dim_ents);
1735 for (
auto e : dim_ents) {
1736 auto adj_it = adj_bridge_map.find(e);
1737 if (adj_it != adj_bridge_map.end()) {
1739 for (
const auto idx : adj_it->adj)
1740 row_adj.push_back(idx);
1744 "Entity not found");
1747 std::sort(row_adj.begin(), row_adj.end());
1748 auto end = std::unique(row_adj.begin(), row_adj.end());
1750 size_t row_size = std::distance(row_adj.begin(),
end);
1751 max_row_size = std::max(max_row_size, row_size);
1752 if (
j.capacity() < (nb_loc_elements - jj) * max_row_size)
1753 j.reserve(nb_loc_elements * max_row_size);
1756 auto diag = ents.index(*fe_it);
1757 for (
auto it = row_adj.begin();
it !=
end; ++
it)
1764 if (th_vertex_weights != NULL)
1765 weight_ents.push_back(*fe_it);
1771 CHKERR PetscMalloc(
i.size() *
sizeof(
int), &_i);
1772 CHKERR PetscMalloc(
j.size() *
sizeof(
int), &_j);
1773 copy(
i.begin(),
i.end(), _i);
1774 copy(
j.begin(),
j.end(), _j);
1778 int *vertex_weights = NULL;
1779 if (th_vertex_weights != NULL) {
1780 CHKERR PetscMalloc(weight_ents.size() *
sizeof(
int), &vertex_weights);
1782 &*weight_ents.begin(),
1783 weight_ents.size(), vertex_weights);
1789 CHKERR MatCreateMPIAdj(m_field.
get_comm(), rend - rstart, nb_elems, _i, _j,
1790 PETSC_NULLPTR, &Adj);
1791 CHKERR MatSetOption(Adj, MAT_STRUCTURALLY_SYMMETRIC, PETSC_TRUE);
1795 CHKERR MatConvert(Adj, MATMPIAIJ, MAT_INITIAL_MATRIX, &
A);
1796 CHKERR MatView(
A, PETSC_VIEWER_DRAW_WORLD);
1803 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"Start";
1805 MatPartitioning part;
1809 CHKERR MatPartitioningSetAdjacency(part, Adj);
1810 CHKERR MatPartitioningSetFromOptions(part);
1811 CHKERR MatPartitioningSetNParts(part, n_parts);
1812 if (th_vertex_weights != NULL) {
1813 CHKERR MatPartitioningSetVertexWeights(part, vertex_weights);
1815 CHKERR MatPartitioningApply(part, &is);
1817 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"End";
1820 IS is_gather, is_num, is_gather_num;
1821 CHKERR ISAllGather(is, &is_gather);
1822 CHKERR ISPartitioningToNumbering(is, &is_num);
1823 CHKERR ISAllGather(is_num, &is_gather_num);
1825 const int *part_number, *gids;
1826 CHKERR ISGetIndices(is_gather, &part_number);
1827 CHKERR ISGetIndices(is_gather_num, &gids);
1830 ParallelComm *pcomm = ParallelComm::get_pcomm(
1832 Tag part_tag = pcomm->part_tag();
1833 CHKERR m_field.
get_moab().tag_set_data(part_tag, ents, part_number);
1836 std::map<int, Range> parts_ents;
1839 Range::iterator eit = ents.begin();
1840 for (
int ii = 0; eit != ents.end(); eit++, ii++) {
1841 parts_ents[part_number[ii]].insert(*eit);
1845 0, MBENTITYSET, &part_tag, NULL, 1, tagged_sets,
1846 moab::Interface::UNION);
1847 if (!tagged_sets.empty())
1848 CHKERR m_field.
get_moab().tag_delete_data(part_tag, tagged_sets);
1850 if (n_parts > (
int)tagged_sets.size()) {
1852 int num_new = n_parts - tagged_sets.size();
1853 for (
int i = 0;
i < num_new;
i++) {
1854 EntityHandle new_set;
1856 tagged_sets.insert(new_set);
1858 }
else if (n_parts < (
int)tagged_sets.size()) {
1860 int num_del = tagged_sets.size() - n_parts;
1861 for (
int i = 0;
i < num_del;
i++) {
1862 EntityHandle old_set = tagged_sets.pop_back();
1868 std::vector<int> dum_ids(n_parts);
1869 for (
int i = 0;
i < n_parts;
i++)
1876 for (
int pp = 0; pp != n_parts; pp++) {
1877 Range dim_ents = parts_ents[pp].subset_by_dimension(dim);
1878 for (
int dd = dim - 1; dd >= 0; dd--) {
1881 dim_ents, dd,
false, adj_ents, moab::Interface::UNION);
1882 parts_ents[pp].merge(adj_ents);
1885 for (
int pp = 1; pp != n_parts; pp++) {
1886 for (
int ppp = 0; ppp != pp; ppp++) {
1887 parts_ents[pp] = subtract(parts_ents[pp], parts_ents[ppp]);
1891 for (
int pp = 0; pp != n_parts; pp++) {
1892 CHKERR m_field.
get_moab().add_entities(tagged_sets[pp], parts_ents[pp]);
1895 auto set_part = [&]() {
1897 for (EntityType
t = MBEDGE;
t != MBENTITYSET; ++
t) {
1898 for (
int pp = 0; pp != n_parts; pp++) {
1899 Range type_ents = parts_ents[pp].subset_by_type(
t);
1900 CHKERR m_field.
get_moab().tag_clear_data(part_tag, type_ents, &pp);
1906 auto set_gid = [&]() {
1908 for (
int d = 0;
d != 4; ++
d) {
1909 if (
d == 0 && preserve_vertex_ids)
1916 for (
int pp = 0; pp != n_parts; pp++) {
1917 Range type_ents = parts_ents[pp].subset_by_dimension(
d);
1919 auto eit = type_ents.begin();
1920 for (; eit != type_ents.end();) {
1922 gid_tag, eit, type_ents.end(), count, ptr);
1923 auto gid_tag_ptr =
static_cast<int *
>(ptr);
1924 for (; count > 0; --count) {
1943 for (
int rr = 0; rr != n_parts; rr++) {
1945 ss <<
"out_part_" << rr <<
".vtk";
1946 MOFEM_LOG(
"SELF", Sev::inform) <<
"Save debug part mesh " << ss.str();
1947 EntityHandle meshset;
1950 CHKERR m_field.
get_moab().write_file(ss.str().c_str(),
"VTK",
"",
1957 CHKERR ISRestoreIndices(is_gather, &part_number);
1958 CHKERR ISRestoreIndices(is_gather_num, &gids);
1959 CHKERR ISDestroy(&is_num);
1960 CHKERR ISDestroy(&is_gather_num);
1961 CHKERR ISDestroy(&is_gather);
1963 CHKERR MatPartitioningDestroy(&part);
1971 moab::Interface &moab,
const char *file_name,
int dim,
1979 CHKERR moab.load_file(file_name, 0, options);
1984 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
1986 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
1987 if (pcomm->size() == 1)
1990 Skinner
skin(&moab);
1992 auto print_range_on_procs = [&](
const Range &range, std::string
name) {
1994 <<
"] : " << range.size();
1998 auto save_range_to_file = [&](
const Range range, std::string
name =
"part") {
2001 int rr = pcomm->rank();
2003 ss <<
"out_" <<
name <<
"_" << rr <<
".vtk";
2004 MOFEM_LOG(
"SYNC",
sev) <<
"Save debug part mesh " << ss.str();
2005 EntityHandle meshset;
2006 CHKERR moab.create_meshset(MESHSET_SET, meshset);
2007 CHKERR moab.add_entities(meshset, range);
2009 CHKERR moab.write_file(ss.str().c_str(),
"VTK",
"", &meshset, 1);
2011 CHKERR moab.delete_entities(&meshset, 1);
2015 auto get_skin = [&](
auto e) {
2017 CHKERR skin.find_skin(0, e.subset_by_dimension(dim),
false,
s);
2021 auto get_adj = [&](
auto ents,
auto dim) {
2023 CHKERR moab.get_adjacencies(ents, dim,
false, adj, moab::Interface::UNION);
2028 CHKERR moab.get_entities_by_handle(0, all_ents,
false);
2029 save_range_to_file(all_ents,
"all_ents");
2031 Tag part_tag = pcomm->part_tag();
2032 Range tagged_sets, proc_ents, off_proc_ents;
2034 CHKERR moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, NULL, 1,
2035 tagged_sets, moab::Interface::UNION);
2036 print_range_on_procs(tagged_sets,
"tagged_sets");
2037 for (
auto &mit : tagged_sets) {
2039 CHKERR moab.tag_get_data(part_tag, &mit, 1, &part);
2040 if (part == pcomm->rank()) {
2041 CHKERR moab.get_entities_by_handle(mit, proc_ents,
true);
2043 CHKERR moab.get_entities_by_handle(mit, off_proc_ents,
true);
2048 for (
auto &mit : tagged_sets) {
2050 CHKERR moab.tag_get_data(part_tag, &mit, 1, &part);
2052 CHKERR moab.get_entities_by_handle(mit, ents,
true);
2053 CHKERR moab.tag_clear_data(part_tag, ents, &part);
2056 print_range_on_procs(proc_ents,
"proc_ents");
2057 save_range_to_file(proc_ents,
"proc_ents");
2059 auto get_proc_ents_skin = [&]() {
2060 std::array<Range, 4>
2062 auto all_skin = get_skin(all_ents.subset_by_dimension(dim));
2063 auto proc_skin = get_skin(proc_ents.subset_by_dimension(dim));
2065 proc_ents_skin[2] = subtract(proc_skin, all_skin);
2066 proc_ents_skin[1] = get_adj(proc_ents_skin[dim - 1], 1);
2069 proc_ents_skin[1] = subtract(proc_skin, all_skin);
2071 CHKERR moab.get_connectivity(proc_ents_skin[dim - 1], proc_ents_skin[0],
2073 return proc_ents_skin;
2076 auto add_post_proc_skin = [&](
auto &&proc_ents_skin) {
2079 Tag nsTag, ssTag, nsTag_data, ssTag_data, bhTag, bhTag_header;
2081 bhTag, bhTag_header,
QUIET);
2084 CHKERR moab.get_entities_by_type(0, MBENTITYSET, meshsets,
false);
2085 for (
auto m : meshsets) {
2090 auto p = cubit_meshsets_index.insert(block);
2095 CHKERR moab.get_entities_by_handle(
m, ents,
true);
2096 CHKERR moab.add_entities(p.first->getMeshset(), ents);
2097 CHKERR moab.delete_entities(&
m, 1);
2102 for (
auto &
m : cubit_meshsets_index) {
2107 std::vector<const CubitMeshSets *> vec_ptr;
2108 for (
auto &
m : cubit_meshsets_index) {
2109 vec_ptr.push_back(&
m);
2113 return proc_skin_fun(std::move(proc_ents_skin), std::move(vec_ptr));
2116 auto remove_off_proc_ents = [&](
auto &all_ents,
auto &off_proc_ents,
2117 auto &proc_ents_skin) {
2118 auto to_remove = off_proc_ents;
2119 for (
auto d = dim - 1;
d >= 0; --
d) {
2120 to_remove = subtract(to_remove, proc_ents_skin[
d]);
2124 CHKERR moab.get_entities_by_type(0, MBENTITYSET, meshsets,
true);
2125 for (
auto m : meshsets) {
2126 CHKERR moab.remove_entities(
m, to_remove);
2128 for (
int dd = dim; dd > 0; --dd) {
2129 CHKERR moab.delete_entities(to_remove.subset_by_dimension(dd));
2133 auto proc_ents_skin = add_post_proc_skin(get_proc_ents_skin());
2134 for (
auto d = dim - 1;
d >= 0; --
d) {
2135 save_range_to_file(proc_ents_skin[
d],
"proc_ents_skin" + std::to_string(
d));
2138 if (pcomm->rank()) {
2139 remove_off_proc_ents(all_ents, off_proc_ents, proc_ents_skin);
2142 for (
auto d = dim - 1;
d >= 0; --
d) {
2143 print_range_on_procs(proc_ents_skin[
d],
2144 "proc_ents_skin by dim" + std::to_string(
d));
2147 CHKERR pcomm->resolve_shared_ents(0, proc_ents, dim, -1,
2148 proc_ents_skin.data());
2153 auto gid_tag = moab.globalId_tag();
2157 CHKERR moab.tag_get_handle(
"TestGather", 1, MB_TYPE_INTEGER, tag_handle,
2158 MB_TAG_DENSE | MB_TAG_CREAT, &def_val);
2160 if (pcomm->rank() > 0) {
2161 gather_ents = proc_ents.subset_by_dimension(3);
2162 std::vector<int> vals(gather_ents.size());
2163 std::for_each(vals.begin(), vals.end(), [](
auto &
v) { v = std::rand(); });
2164 CHKERR moab.tag_set_data(tag_handle, gather_ents, vals.data());
2165 CHKERR pcomm->gather_data(gather_ents, tag_handle, gid_tag, 0, 0);
2167 gather_ents = proc_ents.subset_by_dimension(3);
2168 CHKERR pcomm->gather_data(gather_ents, tag_handle, gid_tag, 0, 0);
2172 Range all_ents_after;
2173 CHKERR moab.get_entities_by_handle(0, all_ents_after);
2174 save_range_to_file(all_ents_after.subset_by_dimension(3),
2175 "all_ents_part_after");
2185 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
2187 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
2188 if (pcomm->size() == 1) {
2191 "get_entities_by_handle failed");
2192 return subtract(ents, ents.subset_by_type(MBENTITYSET));
2197 auto get_proc_ents = [&]() {
2200 auto get_all_mesh_entities = [&]() {
2202 CHKERR moab.get_entities_by_handle(0, proc_ents,
false);
2203 proc_ents = subtract(proc_ents, proc_ents.subset_by_type(MBENTITYSET));
2207 Tag part_tag = pcomm->part_tag();
2210 moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, NULL, 1,
2211 tagged_sets, moab::Interface::UNION);
2212 if (
rval == MB_TAG_NOT_FOUND ||
rval == MB_ENTITY_NOT_FOUND ||
2213 tagged_sets.empty()) {
2215 <<
"Partition tag or partition sets not found, returning all mesh "
2217 CHKERR get_all_mesh_entities();
2222 for (
auto &mit : tagged_sets) {
2224 CHKERR moab.tag_get_data(part_tag, &mit, 1, &part_set);
2225 if (part_set == part) {
2226 rval = moab.get_entities_by_handle(mit, proc_ents,
true);
2227 if (
rval == MB_SUCCESS) {
2230 if (
rval == MB_ENTITY_NOT_FOUND) {
2232 <<
"Partition set is stale, returning all mesh entities";
2234 CHKERR get_all_mesh_entities();
2242 <<
"Partition set for requested part not found, returning all mesh "
2244 CHKERR get_all_mesh_entities();
2256 const EntityHandle meshset,
2257 const int pcomm_id) {
2259 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, pcomm_id);
2262 Tag part_tag = pcomm->part_tag();
2265 auto rval = moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
2266 nullptr, 1, tagged_sets,
2267 moab::Interface::UNION);
2268 if (
rval == MB_TAG_NOT_FOUND ||
rval == MB_ENTITY_NOT_FOUND)
2271 for (
auto s : tagged_sets)
2273 CHKERR moab.remove_entities(
s, &meshset, 1);
2278 MPI_Comm
comm, moab::Interface &moab,
2279 std::function<
Range(
Range)> get_entities_fun,
const int nb_coeffs,
Sev sev,
2280 int root_rank,
bool get_vertices) {
2283 Range r, ghost_ents;
2285 auto get_gids = [&](
Range &ents) {
2286 std::vector<int> ids(ents.size());
2287 auto gid_tag = moab.globalId_tag();
2288 CHKERR moab.tag_get_data(gid_tag, ents, ids.data());
2292 auto create_ao = [&](
auto &&ids) {
2295 AOCreateMapping(
comm, ids.size(), ids.data(), PETSC_NULLPTR, &ao_raw),
2296 "create ao failed");
2300 auto apply_ao = [&](
auto ao, std::vector<int> &&ids) {
2302 "AOApplicationToPetsc failed");
2306 auto get_tag_ids = [&](
auto ao,
Range &ents) {
2307 return apply_ao(ao, get_gids(ents));
2313 Tag part_tag = pcomm->part_tag();
2315 CHKERR moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, NULL, 1,
2317 moab::Interface::UNION);
2318 auto get_proc_and_off_proc_ents = [&]() {
2319 Range proc_ents, off_proc_ents;
2321 if (pcomm->size() == 1) {
2323 "get_entities_by_handle failed");
2324 proc_ents = subtract(proc_ents, proc_ents.subset_by_type(MBENTITYSET));
2325 proc_ents = subtract(proc_ents, proc_ents.subset_by_type(MBVERTEX));
2326 return std::make_pair(proc_ents,
Range());
2328 for (
auto &mit : tagged_sets) {
2331 "tag_get_data failed");
2332 if (part == pcomm->rank()) {
2333 CHK_MOAB_THROW(moab.get_entities_by_handle(mit, proc_ents,
false),
2334 "get_entities_by_handle failed");
2336 CHK_MOAB_THROW(moab.get_entities_by_handle(mit, off_proc_ents,
false),
2337 "get_entities_by_handle failed");
2339 proc_ents = subtract(proc_ents, off_proc_ents);
2341 return std::make_pair(proc_ents, off_proc_ents);
2344 auto get_proc_and_off_proc_verts = [&]() {
2345 Range proc_ents, off_proc_ents;
2346 if (pcomm->size() == 1 || tagged_sets.empty()) {
2347 CHK_MOAB_THROW(moab.get_entities_by_type(0, MBVERTEX, proc_ents),
2348 "get_entities_by_type failed");
2349 return std::make_pair(proc_ents,
Range());
2351 std::map<int, Range> parts_ents;
2352 for (
auto &mit : tagged_sets) {
2355 "tag_get_data failed");
2357 moab.get_entities_by_handle(mit, parts_ents[part],
false),
2358 "get_entities_by_handle failed");
2359 parts_ents[part] = subtract(
2360 parts_ents[part], parts_ents[part].subset_by_type(MBENTITYSET));
2364 "get_connectivity failed");
2366 for (; p != pcomm->rank(); ++p) {
2369 "get_connectivity failed");
2370 v = subtract(
v, vv);
2371 off_proc_ents.merge(vv);
2373 for (; p != pcomm->size(); ++p) {
2376 "get_connectivity failed");
2377 vv = subtract(vv,
v);
2378 off_proc_ents.merge(vv);
2381 return std::make_pair(proc_ents, off_proc_ents);
2384 auto [proc_ents, off_proc_ents] = get_proc_and_off_proc_ents();
2387 auto [proc_verts, off_proc_verts] = get_proc_and_off_proc_verts();
2388 proc_ents.merge(proc_verts);
2389 off_proc_ents.merge(off_proc_verts);
2391 r = get_entities_fun(proc_ents);
2392 auto o = get_entities_fun(off_proc_ents);
2393 auto ao = create_ao(get_gids(r));
2395 auto set_ghosts = [&](
auto &&ghosts_gids) {
2396 std::vector<int> ghosts_dofs(nb_coeffs * ghosts_gids.size());
2397 for (
int i = 0;
i < ghosts_gids.size(); ++
i)
2398 for (
int j = 0;
j < nb_coeffs; ++
j)
2399 ghosts_dofs[
i * nb_coeffs +
j] = nb_coeffs * ghosts_gids[
i] +
j;
2403 std::vector<int> ghosts;
2404 if (pcomm->rank() == root_rank) {
2405 ghosts = set_ghosts(get_tag_ids(ao, o));
2409 CHKERR moab.get_entities_by_handle(0, ents,
true);
2410 ents = get_entities_fun(ents);
2411 ents = subtract(ents, r);
2412 ghosts = set_ghosts(get_tag_ids(ao, ents));
2416 auto create_vec = [&]() {
2419 ghosts.size(), ghosts.data());
2429 auto out = std::make_pair(std::make_pair(r, ghost_ents), vec);
2434 auto check = [&](
auto &ents,
auto &id,
auto &idx) {
2437 for (
int i = 0;
i < ents.size(); ++
i) {
2438 for (
int j = 0;
j < nb_coeffs; ++
j) {
2439 if (idx[
i * nb_coeffs +
j] != nb_coeffs *
id[
i] +
j) {
2442 <<
"indexes not equal: " << idx[
i * nb_coeffs +
j]
2443 <<
" != " << nb_coeffs * idx[
i] +
j;
2453 std::vector<double> def_val(nb_coeffs, 0.0);
2455 CHKERR moab.tag_get_handle(
"TestGather", nb_coeffs, MB_TYPE_DOUBLE,
tag,
2456 MB_TAG_SPARSE | MB_TAG_CREAT, def_val.data());
2457 auto ao = create_ao(get_gids(r));
2458 auto id = get_tag_ids(ao, r);
2459 std::vector<double> idx(nb_coeffs * r.size());
2460 for (
int i = 0;
i < r.size(); ++
i) {
2461 for (
int j = 0;
j < nb_coeffs; ++
j) {
2462 idx[
i * nb_coeffs +
j] = nb_coeffs *
id[
i] +
j;
2465 CHKERR moab.tag_set_data(
tag, r, idx.data());
2467 idx.resize(nb_coeffs * r.size());
2468 CHKERR moab.tag_get_data(
tag, r, idx.data());
2470 auto ghost_id = get_tag_ids(ao, ghost_ents);
2471 idx.resize(nb_coeffs * ghost_ents.size());
2472 CHKERR moab.tag_get_data(
tag, ghost_ents, idx.data());
2474 "ghost indexes do not match")
2488 CHKERR VecGetLocalSize(vec.second, &local_size);
2490 CHKERR moab.tag_get_length(
tag, nb_coeffs);
2491 if (vec.first.first.size() * nb_coeffs != local_size) {
2493 "Local size of vector does not match number of entities");
2496 auto set_vec_from_tags = [&]() {
2500 CHKERR VecGetArray(vec.second, &v_array);
2501 CHKERR moab.tag_get_data(
tag, vec.first.first, v_array);
2502 CHKERR moab.tag_get_data(
tag, vec.first.second, &v_array[local_size]);
2503 CHKERR VecRestoreArray(vec.second, &v_array);
2507 CHKERR set_vec_from_tags();
2518 CHKERR VecGetLocalSize(vec.second, &local_size);
2520 CHKERR moab.tag_get_length(
tag, nb_coeffs);
2521 if (vec.first.first.size() * nb_coeffs != local_size) {
2523 "Local size of vector does not match number of entities");
2526 auto set_tags_from_vec = [&]() {
2529 CHKERR VecGetArray(vec.second, &v_array);
2530 CHKERR moab.tag_set_data(
tag, vec.first.first, v_array);
2531 CHKERR moab.tag_set_data(
tag, vec.first.second, &v_array[local_size]);
2532 CHKERR VecRestoreArray(vec.second, &v_array);
2536 CHKERR set_tags_from_vec();
2543 int dim,
const int nb_coeffs,
Sev sev,
2548 [dim](
Range r) {
return r.subset_by_dimension(dim); }
2551 nb_coeffs,
sev, root_rank, (dim != 0) ?
false :
true);
2561 CHKERR update_ghosts(vec.second);
CGALInterfaceImpl & owner
std::vector< int > source
std::vector< int > vertices
Vec t
Removal: the ring edge.
std::vector< int > parent
bool closure
The face (f0, f1, w) closes a corner at f0 or f1.
std::vector< Cell > cells
std::array< int, 4 > connectivity
std::map< EntityHandle, size_t > offsets
std::vector< double > empty
One value per component.
std::vector< std::array< double, 3 > > coordinates
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
std::vector< FieldBitNumber > row
SmartPetscObj< Vec > values
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
multi_index_container< boost::shared_ptr< FiniteElement >, indexed_by< hashed_unique< tag< FiniteElement_Meshset_mi_tag >, member< FiniteElement, EntityHandle, &FiniteElement::meshset > >, hashed_unique< tag< BitFEId_mi_tag >, const_mem_fun< FiniteElement, BitFEId, &FiniteElement::getId >, HashBit< BitFEId >, EqBit< BitFEId > >, ordered_unique< tag< FiniteElement_name_mi_tag >, const_mem_fun< FiniteElement, boost::string_ref, &FiniteElement::getNameRef > > > > FiniteElement_multiIndex
MultiIndex for entities for FiniteElement.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const FieldEntity_multiIndex * get_field_ents() const =0
Get the field ents object.
virtual const FiniteElement_multiIndex * get_finite_elements() const =0
Get the finite elements object.
virtual const RefEntity_multiIndex * get_ref_ents() const =0
Get the ref ents object.
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
MoFEMErrorCode synchroniseFieldEntities(const std::string name, int verb=DEFAULT_VERBOSITY)
#define MOFEM_LOG(channel, severity)
Log.
SeverityLevel
Severity levels.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
MoFEMErrorCode getTags(int verb=-1)
Get tag handles used on meshsets.
MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false, const bool preserve_vertex_ids=false)
Set partition tag to each finite element in the problem.
MoFEMErrorCode resolveSharedFiniteElements(const Problem *problem_ptr, const std::string &fe_name, int verb=DEFAULT_VERBOSITY)
resolve shared entities for finite elements in the problem
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'j', 3 > j
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< 32 > CubitBCType
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
auto type_from_handle(const EntityHandle h)
get type from entity handle
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< ordered_unique< tag< Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt > >, ordered_non_unique< tag< Ent_Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >, ordered_non_unique< tag< Composite_EntType_and_ParentEntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityType, &RefEntity::getParentEntType > > >, ordered_non_unique< tag< Composite_ParentEnt_And_EntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > > > > > RefEntity_multiIndex
multi_index_container< CubitMeshSets, indexed_by< hashed_unique< tag< Meshset_mi_tag >, member< CubitMeshSets, EntityHandle, &CubitMeshSets::meshset > >, ordered_non_unique< tag< CubitMeshsetType_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getBcTypeULong > >, ordered_non_unique< tag< CubitMeshsetMaskedType_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaskedBcTypeULong > >, ordered_non_unique< tag< CubitMeshsets_name >, const_mem_fun< CubitMeshSets, std::string, &CubitMeshSets::getName > >, hashed_unique< tag< Composite_Cubit_msId_And_MeshsetType_mi_tag >, composite_key< CubitMeshSets, const_mem_fun< CubitMeshSets, int, &CubitMeshSets::getMeshsetId >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaskedBcTypeULong > > > > > CubitMeshSet_multiIndex
Stores data about meshsets (see CubitMeshSets) storing data about boundary conditions,...
auto createGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Create smart ghost vector.
constexpr auto field_name
FTensor::Index< 'm', 3 > m
static MoFEMErrorCode updateEntitiesPetscVector(moab::Interface &moab, EntitiesPetscVector &vec, Tag tag, UpdateGhosts update_gosts=defaultUpdateGhosts)
Exchange data between vector and data.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
std::function< MoFEMErrorCode(Vec vec)> UpdateGhosts
MoFEMErrorCode inheritPartitions(const Range &source_entities, const Range &child_entities)
static Range getPartEntities(moab::Interface &moab, int part)
MoFEMErrorCode synchroniseByConnectivity(const Range &entities, int complete_mesh_rank=-1)
CommInterface(const MoFEM::Core &core)
MoFEMErrorCode retainPartition(Range &entities, const BitRefLevel &active_bit, const Range &preserve={})
MoFEMErrorCode makeEntitiesMultishared(const EntityHandle *entities, const int num_entities, const int owner_proc=0, int verb=DEFAULT_VERBOSITY)
make entities from proc 0 shared on all proc
static MoFEMErrorCode loadFileRootProcAllRestDistributed(moab::Interface &moab, const char *file_name, int dim, LoadFileFun proc_skin_fun=defaultProcSkinFun, const char *options="PARALLEL=BCAST;PARTITION=")
Root proc has whole mesh, other procs only part of it.
MoFEMErrorCode synchroniseEntities(Range &ent, std::map< int, Range > *received_ents, int verb=DEFAULT_VERBOSITY)
synchronize entity range on processors (collective)
MoFEMErrorCode synchroniseByParentChild(const BitRefLevel &parent_bit, const BitRefLevel &child_bit, int verb=DEFAULT_VERBOSITY)
std::function< std::array< Range, 4 >(std::array< Range, 4 > &&, std::vector< const CubitMeshSets * > &&)> LoadFileFun
static MoFEMErrorCode setVectorFromTag(moab::Interface &moab, EntitiesPetscVector &vec, Tag tag)
Set the Vector From Tag object.
static MoFEMErrorCode removeMeshsetFromPartition(moab::Interface &moab, const EntityHandle meshset, const int pcomm_id=MYPCOMM_INDEX)
Remove a meshset from all partition sets before it is deleted.
static MoFEMErrorCode setTagFromVector(moab::Interface &moab, EntitiesPetscVector &vec, Tag tag)
Set the Tag From Vector object.
MoFEMErrorCode makeFieldEntitiesMultishared(const std::string field_name, const int owner_proc=0, int verb=DEFAULT_VERBOSITY)
make field entities multi shared
std::pair< std::pair< Range, Range >, SmartPetscObj< Vec > > EntitiesPetscVector
MoFEMErrorCode resolveParentEntities(const Range &ent, int verb=DEFAULT_VERBOSITY)
Synchronise parent entities.
MoFEMErrorCode gatherMesh(const Range &cells, TetMeshData &data, int root=0)
MoFEMErrorCode exchangeFieldData(const std::string field_name, int verb=DEFAULT_VERBOSITY)
Exchange field data.
static EntitiesPetscVector createEntitiesPetscVector(MPI_Comm comm, moab::Interface &moab, std::function< Range(Range)> get_entities_fun, const int nb_coeffs, Sev sev=Sev::verbose, int root_rank=0, bool get_vertices=true)
Create a ghost vector for exchanging data.
MoFEMErrorCode broadcastMesh(TetMeshData &data, int root=0)
virtual int get_comm_size() const =0
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
virtual MPI_Comm & get_comm() const =0
virtual MoFEMErrorCode remove_ents(const Range ents, int verb=DEFAULT_VERBOSITY)=0
Remove entities from MoFEM database.
virtual int get_comm_rank() const =0
virtual boost::shared_ptr< BasicEntityData > & get_basic_entity_data_ptr()=0
Get pointer to basic entity data.
Tag get_th_RefBitLevel() const
Tag get_th_RefParentHandle() const
this struct keeps basic methods for moab meshset about material and boundary conditions
Deprecated interface functions.
UId getLocalUniqueIdCalculate() const
Generate UId for finite element entity.
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
Interface for managing meshsets containing materials and boundary conditions.
static void sortMeshsets(std::vector< const CubitMeshSets * > &vec_ptr)
static bool broadcastMeshsetsOn
keeps basic data about problem
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
intrusive_ptr for managing petsc objects
std::vector< int > partitions
Optional cell-to-rank assignment.
std::vector< std::array< int, 3 > > boundary
std::vector< int > cellLabels
std::vector< std::array< int, 4 > > cells
Zero-based point indices.
std::vector< std::array< double, 3 > > points
std::vector< int > vertexIds
std::vector< int > surfaceLabels
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.