Arcane  v3.16.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
GraphDoFs.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* GraphDoFs.h (C) 2000-2025 */
9/* */
10/*---------------------------------------------------------------------------*/
11#ifndef ARCANE_MESH_GRAPHDOFS_H
12#define ARCANE_MESH_GRAPHDOFS_H
13/*---------------------------------------------------------------------------*/
14/*---------------------------------------------------------------------------*/
15
16#include "arcane/core/IGraph2.h"
17#include "arcane/core/IGraphModifier2.h"
18#include "arcane/core/IItemConnectivityMng.h"
19
20#include "arcane/utils/TraceAccessor.h"
21#include "arcane/utils/Convert.h"
22
23#include "arcane/mesh/ItemFamily.h"
24#include "arcane/mesh/DoFManager.h"
25#include "arcane/mesh/DoFFamily.h"
26#include "arcane/mesh/ItemConnectivity.h"
27#include "arcane/mesh/IncrementalItemConnectivity.h"
28#include "arcane/mesh/GhostLayerFromConnectivityComputer.h"
29#include "arcane/mesh/DualUniqueIdMng.h"
30#include "arcane/mesh/ParticleFamily.h"
31#include "arcane/mesh/IndexedItemConnectivityAccessor.h"
32
33#include <memory>
34#include <array>
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Arcane::mesh
40{
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45template <typename T>
46class GraphConnectivityObserverT
48{
49 public:
50
51 GraphConnectivityObserverT(T* parent)
52 : m_parent(parent)
53 {}
54
55 virtual ~GraphConnectivityObserverT() {}
56
57 void notifyUpdateConnectivity()
58 {
59 m_parent->updateGraphConnectivity();
60 }
61
62 private:
63
64 T* m_parent = nullptr;
65};
66
67template <typename T>
68class GraphObserverT
69: public IGraphObserver
70{
71 public:
72
73 explicit GraphObserverT(T* parent)
74 : m_parent(parent)
75 {}
76
77 virtual ~GraphObserverT() {}
78
79 void notifyUpdate()
80 {
81 m_parent->notifyGraphUpdate();
82 }
83
84 private:
85
86 T* m_parent = nullptr;
87};
88
89class GraphDoFs;
90
91class ARCANE_MESH_EXPORT GraphIncrementalConnectivity
92: public IGraphConnectivity
93{
94 public:
95
96 GraphIncrementalConnectivity(IItemFamily const* dualnode_family,
97 IItemFamily const* link_family,
98 Arcane::mesh::IncrementalItemConnectivity* dualnode_connectivity,
100 UniqueArray<Arcane::mesh::IncrementalItemConnectivity*> const& dualitem_connectivities,
101 ItemScalarProperty<Integer> const& dualnode_to_connectivity)
102 : m_dualnode_family(dualnode_family)
103 , m_link_family(link_family)
104 , m_dualnode_connectivity(dualnode_connectivity)
105 , m_link_connectivity(link_connectivity)
106 , m_dualitem_connectivities(dualitem_connectivities)
107 , m_dualnode_to_connectivity_index(dualnode_to_connectivity)
108 {}
109
110 GraphIncrementalConnectivity(GraphIncrementalConnectivity const& rhs)
111 : m_dualnode_family(rhs.m_dualnode_family)
112 , m_link_family(rhs.m_link_family)
113 , m_dualnode_connectivity(rhs.m_dualnode_connectivity)
114 , m_link_connectivity(rhs.m_link_connectivity)
115 , m_dualitem_connectivities(rhs.m_dualitem_connectivities)
116 , m_dualnode_to_connectivity_index(rhs.m_dualnode_to_connectivity_index)
117 {}
118
119 GraphIncrementalConnectivity(GraphDoFs* graph);
120
121 virtual ~GraphIncrementalConnectivity() {}
122
123 inline Item dualItem(const DoF& dualNode) const
124 {
125 auto dualitem_connectivity_accessor = m_dualitem_connectivities[m_dualnode_to_connectivity_index[dualNode]]->connectivityAccessor();
126 return dualitem_connectivity_accessor(ItemLocalId(dualNode))[0];
127 }
128
129 inline DoFVectorView links(const DoF& dualNode) const
130 {
131 return m_dualnode_connectivity->connectivityAccessor()(ItemLocalId(dualNode));
132 }
133
134 inline DoFVectorView dualNodes(const DoF& link) const
135 {
136 return m_link_connectivity->connectivityAccessor()(ItemLocalId(link));
137 }
138
139 private:
140
141 IItemFamily const* m_dualnode_family = nullptr;
142 IItemFamily const* m_link_family = nullptr;
143 Arcane::mesh::IncrementalItemConnectivity* m_dualnode_connectivity = nullptr;
144 Arcane::mesh::IncrementalItemConnectivity* m_link_connectivity = nullptr;
145 UniqueArray<Arcane::mesh::IncrementalItemConnectivity*> const& m_dualitem_connectivities;
146 ItemScalarProperty<Integer> const& m_dualnode_to_connectivity_index;
147};
148
149class ARCANE_MESH_EXPORT GraphDoFs
150: public TraceAccessor
151, public IGraph2
152, public IGraphModifier2
153{
154 public:
155
156 friend class GraphIncrementalConnectivity;
157
158 typedef DynamicMeshKindInfos::ItemInternalMap ItemInternalMap;
159
160 static const String dualNodeFamilyName() { return "DualNodes"; }
161 static const String linkFamilyName() { return "Links"; }
162
163 public:
164
165 GraphDoFs(IMesh* mesh, String particle_family_name = ParticleFamily::defaultFamilyName());
166
167 virtual ~GraphDoFs() {}
168
169 public:
170
171 IGraphModifier2* modifier() override { return this; }
172
173 IGraphConnectivity const* connectivity() const override
174 {
175 return m_graph_connectivity.get();
176 }
177
178 Integer registerNewGraphConnectivityObserver(IGraphConnectivityObserver* observer) override
179 {
180 Integer id = CheckedConvert::toInteger(m_connectivity_observer.size());
181 m_connectivity_observer.push_back(std::unique_ptr<IGraphConnectivityObserver>(observer));
182 return id;
183 }
184
185 void releaseGraphConnectivityObserver(Integer observer_id) override
186 {
187 if ((observer_id >= 0) && (observer_id < (Integer)m_connectivity_observer.size()))
188 m_connectivity_observer[observer_id].reset();
189 }
190
191 Integer registerNewGraphObserver(IGraphObserver* observer) override
192 {
193 Integer id = CheckedConvert::toInteger(m_graph_observer.size());
194 m_graph_observer.push_back(std::unique_ptr<IGraphObserver>(observer));
195 return id;
196 }
197
198 void releaseGraphObserver(Integer observer_id) override
199 {
200 if ((observer_id >= 0) && (observer_id < (Integer)m_graph_observer.size()))
201 m_graph_observer[observer_id].reset();
202 }
203
204 IItemFamily* dualNodeFamily() override { return m_dual_node_family->itemFamily(); }
205 const IItemFamily* dualNodeFamily() const override { return m_dual_node_family->itemFamily(); }
206
207 IItemFamily* linkFamily() override { return m_link_family->itemFamily(); }
208 const IItemFamily* linkFamily() const override { return m_link_family->itemFamily(); }
209
210 inline Integer nbLink() const override { return linkFamily()->nbItem(); }
211 inline Integer nbDualNode() const override { return dualNodeFamily()->nbItem(); }
212
214 void addLinks(Integer nb_link,
215 Integer nb_dual_nodes_per_link,
216 Int64ConstArrayView links_infos) override;
217
219 void addDualNodes(Integer graph_nb_dual_node,
220 Integer dual_node_kind,
221 Int64ConstArrayView dual_nodes_infos) override;
222 void addDualNodes(Integer graph_nb_dual_node,
223 Int64ConstArrayView dual_nodes_infos) override;
224 void removeDualNodes(Int32ConstArrayView dual_node_local_ids) override;
225 void removeLinks(Int32ConstArrayView link_local_ids) override;
226
227 void removeConnectedItemsFromCells(Int32ConstArrayView cell_local_ids) override;
228
229 bool isUpdated() override;
230
231 void endUpdate() override;
232
233 void updateAfterMeshChanged() override;
234
235 void printDualNodes() const override;
236 void printLinks() const override;
237
238 private:
239
240 String _className() const { return "GraphDoFs"; }
241 inline Integer _connectivityIndex(Integer dual_node_IT) const
242 {
243 ARCANE_ASSERT((dual_node_IT < NB_BASIC_ITEM_TYPE),
244 ("dual node item type must be IT_DualNode, IT_DualEdge, IT_DualFace, IT_DualCell or IT_DualParticle"));
245 return m_connectivity_indexes_per_type[dual_node_IT];
246 }
247
248 private:
249
250 IItemFamily* _dualItemFamily(Arcane::eItemKind kind)
251 {
252 if (kind == IK_Particle) {
253 return m_mesh->findItemFamily(kind, m_particle_family_name, false);
254 }
255 else {
256 return m_mesh->itemFamily(kind);
257 }
258 }
259
260 Int64 _doFUid(Integer dual_item_kind, Item const& item)
261 {
262 switch (dual_item_kind) {
263 case IT_DualNode:
264 return Arcane::DualUniqueIdMng::uniqueIdOf<Node>(item.toNode());
265 case IT_DualEdge:
266 return Arcane::DualUniqueIdMng::uniqueIdOf<Edge>(item.toEdge());
267 case IT_DualFace:
268 return Arcane::DualUniqueIdMng::uniqueIdOf<Face>(item.toFace());
269 case IT_DualCell:
270 return Arcane::DualUniqueIdMng::uniqueIdOf<Cell>(item.toCell());
271 case IT_DualParticle:
272 return Arcane::DualUniqueIdMng::uniqueIdOf<Particle>(item.toParticle());
273 default:
274 return -1;
275 }
276 }
277
278 void _allocateGraph();
279
280 IMesh* m_mesh = nullptr;
281 IItemFamilyNetwork* m_item_family_network = nullptr;
282 bool m_graph_allocated = false;
283 Integer m_graph_id = -1;
284
285 DoFManager m_dof_mng;
286 IItemConnectivityMng* m_connectivity_mng;
287 IDoFFamily* m_dual_node_family = nullptr;
288 IDoFFamily* m_link_family = nullptr;
289
290 UniqueArray<Arcane::mesh::IncrementalItemConnectivity*> m_incremental_connectivities;
291 UniqueArray<Arcane::mesh::IncrementalItemConnectivity*> m_dual2dof_incremental_connectivities;
292 Arcane::mesh::IncrementalItemConnectivity* m_dualnodes_incremental_connectivity = nullptr;
293 Arcane::mesh::IncrementalItemConnectivity* m_links_incremental_connectivity = nullptr;
294 std::unique_ptr<GraphIncrementalConnectivity> m_graph_connectivity;
295 std::vector<std::unique_ptr<Arcane::IGraphConnectivityObserver>> m_connectivity_observer;
296
297 std::vector<std::unique_ptr<Arcane::IGraphObserver>> m_graph_observer;
298
299 std::vector<std::unique_ptr<Arcane::GhostLayerFromConnectivityComputer>> m_ghost_layer_computers;
300 Int32UniqueArray m_connectivity_indexes_per_type;
301 std::array<Integer, NB_BASIC_ITEM_TYPE> m_dualnode_kinds = { IT_DualNode, IT_DualEdge, IT_DualFace, IT_DualCell, IT_DualParticle };
302 ItemScalarProperty<Integer> m_dual_node_to_connectivity_index;
303
304 UniqueArray<Int32> m_detached_dualnode_lids;
305 UniqueArray<Int32> m_detached_link_lids;
306
307 bool m_update_sync_info = false;
308
309 String m_particle_family_name;
310};
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
315} // namespace Arcane::mesh
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
320#endif
classe degré de liberté.
Definition Item.h:1503
Interface d'un graphe du maillage.
Definition IGraph2.h:90
Outillage de connectivité d'un graphe.
Definition IGraph2.h:52
Interface d'un graphe du maillage.
Interface d'une famille d'entités.
Definition IItemFamily.h:84
Index d'un Item dans une variable.
Definition ItemLocalId.h:41
Classe de base d'un élément de maillage.
Definition Item.h:83
Chaîne de caractères unicode.
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
Vecteur 1D de données avec sémantique par valeur (style STL).
Integer nbDualNode() const override
Nombre de noeuds duaux du graphe.
Definition GraphDoFs.h:211
const IItemFamily * dualNodeFamily() const override
Retourne la famille des noeuds duaux.
Definition GraphDoFs.h:205
Integer nbLink() const override
Nombre de liaisons du graphe.
Definition GraphDoFs.h:210
const IItemFamily * linkFamily() const override
Retourne la famille des liaisons.
Definition GraphDoFs.h:208
DoFVectorView dualNodes(const DoF &link) const
accès à la vue des DualNodes constituant un liaison Link de type(DoF)
Definition GraphDoFs.h:134
Item dualItem(const DoF &dualNode) const
accès à l'Item dual d'un DualNode (detype DoF)
Definition GraphDoFs.h:123
DoFVectorView links(const DoF &dualNode) const
accès à la vue des links constitué du dualNode de type(DoF)
Definition GraphDoFs.h:129
Connectivité incrémentale item->item[].
ItemVectorViewT< DoF > DoFVectorView
Vue sur un vecteur de degre de liberte.
Definition ItemTypes.h:315
Integer toInteger(Real r)
Converti un Int64 en un Integer.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:569
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:567
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:428
eItemKind
Genre d'entité de maillage.