12#include "arcane/mesh/DualUniqueIdMng.h"
13#include "arcane/mesh/GraphDoFs.h"
15#include "arcane/utils/ArgumentException.h"
17#include "arcane/IMesh.h"
18#include "arcane/IItemConnectivity.h"
19#include "arcane/IIncrementalItemConnectivity.h"
20#include "arcane/MathUtils.h"
22#include "arcane/mesh/ConnectivityNewWithDependenciesTypes.h"
32GraphIncrementalConnectivity::
33GraphIncrementalConnectivity(GraphDoFs* graph)
34: m_dualnode_family(graph->dualNodeFamily())
35, m_link_family(graph->linkFamily())
36, m_dualnode_connectivity(graph->m_dualnodes_incremental_connectivity)
37, m_link_connectivity(graph->m_links_incremental_connectivity)
38, m_dualitem_connectivities(graph->m_incremental_connectivities)
39, m_dualnode_to_connectivity_index(graph->m_dual_node_to_connectivity_index)
47GraphDoFs(IMesh* mesh, String particle_family_name)
48: TraceAccessor(mesh->traceMng())
51, m_connectivity_mng(m_dof_mng.connectivityMng())
52, m_dual_node_family(m_dof_mng.family(GraphDoFs::dualNodeFamilyName(), true))
53, m_link_family(m_dof_mng.family(GraphDoFs::linkFamilyName(), true))
54, m_update_sync_info(false)
55, m_particle_family_name(particle_family_name)
62 if (m_graph_allocated)
65 auto connectivity_index = 0;
66 m_connectivity_indexes_per_type.resize(NB_BASIC_ITEM_TYPE, -1);
67 m_connectivity_indexes_per_type[IT_DualNode] = connectivity_index++;
68 m_connectivity_indexes_per_type[IT_DualEdge] = connectivity_index++;
69 m_connectivity_indexes_per_type[IT_DualFace] = connectivity_index++;
70 m_connectivity_indexes_per_type[IT_DualCell] = connectivity_index++;
71 m_connectivity_indexes_per_type[IT_DualParticle] = connectivity_index++;
73 m_item_family_network = m_mesh->itemFamilyNetwork();
74 if (m_item_family_network ==
nullptr)
75 ARCANE_FATAL(
"ARCANE_GRAPH_CONNECTIVITY_POLICY need to be activated");
77 m_graph_id = m_item_family_network->registerConnectedGraph(
this);
79 m_dualnodes_incremental_connectivity =
80 new IncrementalItemConnectivity(dualNodeFamily(),
82 mesh::connectivityName(dualNodeFamily(), linkFamily()));
84 m_connectivity_mng->registerConnectivity(m_dualnodes_incremental_connectivity);
86 if (m_item_family_network)
87 m_item_family_network->addRelation(dualNodeFamily(), linkFamily(), m_dualnodes_incremental_connectivity);
89 m_links_incremental_connectivity =
90 new IncrementalItemConnectivity(linkFamily(),
92 mesh::connectivityName(linkFamily(), dualNodeFamily()));
93 m_connectivity_mng->registerConnectivity(m_links_incremental_connectivity);
95 if (m_item_family_network)
97 m_item_family_network->addDependency(linkFamily(), dualNodeFamily(), m_links_incremental_connectivity,
false);
99 m_incremental_connectivities.resize(NB_DUAL_ITEM_TYPE,
nullptr);
100 std::array<int, NB_DUAL_ITEM_TYPE> dual_node_kinds = { IT_DualCell, IT_DualFace, IT_DualEdge, IT_DualNode, IT_DualParticle };
101 for (
auto dual_node_kind : dual_node_kinds) {
102 IItemFamily* dual_item_family = _dualItemFamily(dualItemKind(dual_node_kind));
103 if (dual_item_family) {
104 auto dof2dual_incremental_connectivity =
105 new IncrementalItemConnectivity(dualNodeFamily(),
107 mesh::connectivityName(dualNodeFamily(), dual_item_family));
109 m_connectivity_mng->registerConnectivity(dof2dual_incremental_connectivity);
110 m_incremental_connectivities[_connectivityIndex(dual_node_kind)] = dof2dual_incremental_connectivity;
111 if (m_item_family_network)
112 m_item_family_network->addDependency(dualNodeFamily(), dual_item_family, dof2dual_incremental_connectivity,
false);
115 m_graph_connectivity.reset(
new GraphIncrementalConnectivity(dualNodeFamily(),
117 m_dualnodes_incremental_connectivity,
118 m_links_incremental_connectivity,
119 m_incremental_connectivities,
120 m_dual_node_to_connectivity_index));
122 for (
auto& obs : m_connectivity_observer)
124 obs->notifyUpdateConnectivity();
126 m_update_sync_info =
false;
127 m_graph_allocated =
true;
140 if (!m_graph_allocated)
177 m_connectivity_mng->setUpToDate(m_links_incremental_connectivity);
178 m_connectivity_mng->setUpToDate(m_dualnodes_incremental_connectivity);
180 m_update_sync_info =
false;
193 if (!m_graph_allocated)
222 if (m_item_family_network)
234 m_update_sync_info =
false;
244 if (!m_graph_allocated)
248 bool is_parallel = m_mesh->parallelMng()->isParallel();
249 Integer
domain_rank = m_mesh->parallelMng()->commRank();
265 for (Integer index = 0; index < NB_DUAL_ITEM_TYPE; ++index) {
343 if (m_item_family_network)
360 m_update_sync_info =
false;
373 m_update_sync_info =
false;
384 m_dof_mng.family(GraphDoFs::linkFamilyName()).removeDoFs(
link_local_ids);
386 m_update_sync_info =
false;
399 for (
auto face :
icell->faces()) {
400 if (face.itemBase().isSuppressed())
403 for (
auto node :
icell->nodes()) {
404 if (node.itemBase().isSuppressed())
412 for (
auto ilink : linkFamily()->itemsInternal()) {
413 if (
ilink->isSuppressed())
450 removeLinks(m_detached_link_lids);
452 m_detached_link_lids.clear();
465 for (
auto idualnode : dualNodeFamily()->itemsInternal()) {
494 if (
dual_item.itemBase().isSuppressed()) {
502 removeDualNodes(m_detached_dualnode_lids);
504 m_detached_dualnode_lids.clear();
506 m_update_sync_info =
false;
514 if (!m_graph_allocated)
517 for (Integer index = 0; index < NB_DUAL_ITEM_TYPE; ++index) {
522 m_update_sync_info =
false;
524 if (!m_connectivity_mng->isUpToDate(m_dualnodes_incremental_connectivity))
525 m_update_sync_info =
false;
527 if (!m_connectivity_mng->isUpToDate(m_links_incremental_connectivity))
528 m_update_sync_info =
false;
531 Integer
sync_info = (m_update_sync_info ? 0 : 1);
535 return m_update_sync_info;
541 if (!m_graph_allocated)
544 auto dualnode_family = dualNodeFamily();
545 auto link_family = linkFamily();
547 DualUniqueIdMng dual_uid_mng(traceMng());
548 for (Integer index = 0; index < NB_DUAL_ITEM_TYPE; ++index) {
549 Integer dual_node_kind = m_dualnode_kinds[index];
551 IItemFamily* dual_item_family = _dualItemFamily(dual_item_kind);
553 if (dual_item_family ==
nullptr || dual_item_family->nbItem() == 0)
556 auto dof2dual_incremental_connectivity = m_incremental_connectivities[_connectivityIndex(dual_node_kind)];
557 if (dof2dual_incremental_connectivity && !m_connectivity_mng->isUpToDate(dof2dual_incremental_connectivity)) {
560 Int32ArrayView source_family_added_items_lids;
561 Int32ArrayView source_family_removed_items_lids;
562 m_connectivity_mng->getSourceFamilyModifiedItems(dof2dual_incremental_connectivity, source_family_added_items_lids, source_family_removed_items_lids);
564 info() <<
" NUMBER OF REMOVE ITEMS : " << source_family_removed_items_lids.
size();
565 info() <<
" NUMBER OF ADDED ITEMS : " << source_family_added_items_lids.size();
566 Int64UniqueArray dual_item_uids;
567 dual_item_uids.
reserve(source_family_added_items_lids.size());
568 IntegerUniqueArray dual_node_lids;
569 dual_node_lids.
reserve(source_family_added_items_lids.size());
571 ItemVector source_family_added_items(dualnode_family, source_family_added_items_lids);
573 auto value = dual_uid_mng.uniqueIdOfDualItem(*idof);
574 if (std::get<0>(value) == dual_item_kind) {
575 dual_node_lids.add(idof->localId());
576 dual_item_uids.add(std::get<1>(value));
581 dual_item_family->itemsUniqueIdToLocalId(dual_item_lids, dual_item_uids);
583 ENUMERATE_DOF (idual_node, dualnode_family->view(dual_node_lids)) {
584 dof2dual_incremental_connectivity->notifySourceItemAdded(ItemLocalId(*idual_node));
585 dof2dual_incremental_connectivity->addConnectedItem(ItemLocalId(*idual_node), ItemLocalId(dual_item_lids[idual_node.index()]));
603 m_connectivity_mng->setUpToDate(dof2dual_incremental_connectivity);
607 if (!m_connectivity_mng->isUpToDate(m_links_incremental_connectivity)) {
613 m_connectivity_mng->getSourceFamilyModifiedItems(m_links_incremental_connectivity, source_family_added_items_lids, source_family_removed_items_lids);
615 info() <<
" NUMBER OF REMOVE ITEMS : " << source_family_removed_items_lids.
size();
616 info() <<
" NUMBER OF ADDED ITEMS : " << source_family_added_items_lids.size();
617 ItemVector source_family_added_items(link_family, source_family_added_items_lids);
620 link_uids.
reserve(source_family_added_items_lids.size());
622 dualnode_uids.
reserve(2 * source_family_added_items_lids.size());
624 link_uids.add(ilink->uniqueId());
625 auto value = dual_uid_mng.uniqueIdOfPairOfDualItems(*ilink);
626 eItemKind dualitem_kind_1 = std::get<0>(value.first);
627 Int64 dualitem_uid_1 = std::get<1>(value.first);
628 Int64 dof_uid_1 = dual_uid_mng.uniqueIdOf(dualitem_kind_1, dualitem_uid_1);
629 dualnode_uids.add(dof_uid_1);
631 eItemKind dualitem_kind_2 = std::get<0>(value.second);
632 Int64 dualitem_uid_2 = std::get<1>(value.second);
633 Int64 dof_uid_2 = dual_uid_mng.uniqueIdOf(dualitem_kind_2, dualitem_uid_2);
634 dualnode_uids.add(dof_uid_2);
641 Integer nb_dual_nodes_per_link = 2;
644 dualnode_family->itemsUniqueIdToLocalId(connected_dual_nodes_lids.view(), dualnode_uids);
648 m_links_incremental_connectivity->notifySourceItemAdded(ItemLocalId(*inewlink));
649 for (
auto lid : connected_dual_nodes_lids.subConstView(link_index, nb_dual_nodes_per_link)) {
650 m_links_incremental_connectivity->addConnectedItem(ItemLocalId(*inewlink), ItemLocalId(lid));
651 m_dualnodes_incremental_connectivity->addConnectedItem(ItemLocalId(lid), ItemLocalId(*inewlink));
653 link_index += nb_dual_nodes_per_link;
657 m_connectivity_mng->setUpToDate(m_links_incremental_connectivity);
658 m_connectivity_mng->setUpToDate(m_dualnodes_incremental_connectivity);
661 dualnode_family->computeSynchronizeInfos();
662 link_family->computeSynchronizeInfos();
663 m_update_sync_info =
true;
665 updateAfterMeshChanged();
667 auto* x =
new GraphIncrementalConnectivity(dualNodeFamily(),
669 m_dualnodes_incremental_connectivity,
670 m_links_incremental_connectivity,
671 m_incremental_connectivities,
672 m_dual_node_to_connectivity_index);
673 m_graph_connectivity.reset(x);
675 for (
auto& obs : m_connectivity_observer) {
677 obs->notifyUpdateConnectivity();
680 for (
auto& obs : m_graph_observer) {
693updateAfterMeshChanged()
695 if (!m_graph_allocated)
698 auto& dual_node_family = m_dof_mng.family(GraphDoFs::dualNodeFamilyName());
699 m_dual_node_to_connectivity_index.resize(&dual_node_family, -1);
701 for (Integer index = 0; index < m_incremental_connectivities.size(); ++index) {
702 auto connectivity = m_incremental_connectivities[index];
703 if (connectivity && (connectivity->maxNbConnectedItem() > 0)) {
704 ConnectivityItemVector accessor(connectivity);
705 if (accessor.connectedItems(*idof).size() > 0) {
706 m_dual_node_to_connectivity_index[*idof] = index;
718printDualNodes()
const
721 info() <<
"DualNode : lid = " << idualnode->localId();
722 info() <<
" uid = " << idualnode->uniqueId();
723 info() <<
" owner = " << idualnode->owner();
724 auto dual_item = m_graph_connectivity->dualItem(*idualnode);
725 info() <<
" DualItem : lid = " << dual_item.localId();
726 info() <<
" uid = " << dual_item.uniqueId();
727 info() <<
" kind = " << dual_item.kind();
728 info() <<
" owner = " << dual_item.owner();
729 auto links = m_graph_connectivity->links(*idualnode);
730 for (
auto const& link : links) {
731 info() <<
" Connected link : lid = " << link.localId();
732 info() <<
" uid = " << link.uniqueId();
733 info() <<
" owner = " << link.owner();
745 info() <<
"Link : LID = " << ilink.localId();
746 info() <<
" UID = " << ilink->uniqueId();
747 info() <<
" OWNER = " << ilink->owner();
748 ENUMERATE_DOF (idual_node, m_graph_connectivity->dualNodes(*ilink)) {
749 info() <<
" Dof : index = " << idual_node.index();
750 info() <<
" Dof : LID = " << idual_node->localId();
751 info() <<
" UID = " << idual_node->uniqueId();
752 info() <<
" OWNER = " << idual_node->owner();
753 auto dual_item = m_graph_connectivity->dualItem(*idual_node);
754 info() <<
" dual item UID = " << dual_item.uniqueId();
755 info() <<
" KIND = " << dual_item.kind();
756 info() <<
" OWNER = " << dual_item.owner();
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Gère la récupération des informations de connectivité.
Interface d'une famille d'entités.
Index d'un Item dans une variable.
Vue sur un tableau typé d'entités.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Connectivité incrémentale item->item[].
constexpr Integer size() const noexcept
Retourne la taille du tableau.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
Vue constante d'un tableau de type T.
Positionne une classe de message.
Vecteur 1D de données avec sémantique par valeur (style STL).
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
SharedArray< Int32 > Int32SharedArray
Tableau dynamique à une dimension d'entiers 32 bits.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
eItemKind
Genre d'entité de maillage.
@ IK_Particle
Entité de maillage de genre particule.
@ IK_Node
Entité de maillage de genre noeud.
@ IK_Cell
Entité de maillage de genre maille.
@ IK_Face
Entité de maillage de genre face.
ArrayView< Int32 > Int32ArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Int32 Integer
Type représentant un entier.