Arcane  v3.16.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemFamilyNetwork.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* ItemFamilyNetwork.cc (C) 2000-2024 */
9/* */
10/* ItemFamily relations through their connectivities. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "ItemFamilyNetwork.h"
15
16/*---------------------------------------------------------------------------*/
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane::mesh
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
28addDependency(IItemFamily* master_family, IItemFamily* slave_family,
29 IIncrementalItemConnectivity* master_to_slave_connectivity, bool is_deep_connectivity)
30{
31 m_dependency_graph.addEdge(master_family,slave_family,master_to_slave_connectivity);
32 if(master_to_slave_connectivity) {
33 m_connectivity_list.add(master_to_slave_connectivity);
34 m_connectivity_status[master_to_slave_connectivity] = std::make_pair(false,is_deep_connectivity); // connectivity not stored by default
35 }
36 m_families.insert(master_family);
37 m_families.insert(slave_family);
38
39 m_is_activated = true ;
40}
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
46addRelation(IItemFamily* source_family, IItemFamily* target_family, IIncrementalItemConnectivity* source_to_target_connectivity)
47{
48 m_relation_graph.addEdge(source_family,target_family,source_to_target_connectivity);
49 m_connectivity_list.add(source_to_target_connectivity);
50 if(m_connectivity_status.find(source_to_target_connectivity)==m_connectivity_status.end())
51 m_connectivity_status[source_to_target_connectivity] = std::make_pair(false,true); // connectivity not stored by default
52 m_families.insert(source_family);
53 m_families.insert(target_family);
54 m_is_activated = true ;
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
61getConnectivity(IItemFamily* source_family, IItemFamily* target_family, const String& name)
62{
63 bool is_dependency;
64 return getConnectivity(source_family,target_family,name,is_dependency);
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
71getDependency(IItemFamily* source_family, IItemFamily* target_family)
72{
73 auto* dependency = m_dependency_graph.getEdge(source_family,target_family);
74 if (dependency) return *dependency;
75 else return nullptr;
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81IIncrementalItemConnectivity* ItemFamilyNetwork::
82getRelation(IItemFamily* source_family, IItemFamily* target_family)
83{
84 auto* relation = m_relation_graph.getEdge(source_family,target_family);
85 if (relation) return *relation;
86 else return nullptr;
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93getConnectivity(IItemFamily* source_family, IItemFamily* target_family, const String& name, bool& is_dependency)
94{
95 // Up to now DirectedGraph and DirectedAcyclicGraph are not hypergraph, we cannot have multiple edges between two same nodes.
96 // => we just check the name is OK
97 auto* connectivity = m_dependency_graph.getEdge(source_family,target_family);
98 is_dependency = false;
99 if (connectivity)
100 {
101 _checkConnectivityName(*connectivity,name);
102 is_dependency = true;
103 return *connectivity;
104 }
105 connectivity = m_relation_graph.getEdge(source_family,target_family);
106 if (connectivity)
107 {
108 _checkConnectivityName(*connectivity,name);
109 return *connectivity;
110 }
111 else return nullptr;
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
118getStoredConnectivity(IItemFamily* source_family, IItemFamily* target_family, const String& name)
119{
120 bool is_dependency;
121 return getStoredConnectivity(source_family,target_family,name,is_dependency);
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
128getStoredConnectivity(IItemFamily* source_family, IItemFamily* target_family, const String& name, bool& is_dependency)
129{
130 IIncrementalItemConnectivity* con = getConnectivity(source_family,target_family,name,is_dependency);
131 if (con) {
132 if (!isStored(con)) con = nullptr;
133 }
134 return con;
135}
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
141{
142 return m_connectivity_list;
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
149getChildDependencies(IItemFamily* source_family)
150{
151 return _getConnectivitiesFromGraph(m_dependency_graph.outEdges(source_family));
152}
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
158getParentDependencies(IItemFamily* target_family)
159{
160 return _getConnectivitiesFromGraph(m_dependency_graph.inEdges(target_family));
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
167getChildRelations(IItemFamily* source_family)
168{
169 return _getConnectivitiesFromGraph(m_relation_graph.outEdges(source_family));
170}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
176getParentRelations(IItemFamily* target_family)
177{
178 return _getConnectivitiesFromGraph(m_relation_graph.inEdges(target_family));
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
186{
187 return _getConnectivitiesFromGraph(m_relation_graph.outEdges(source_family), m_dependency_graph.outEdges(source_family));
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
194getParentConnectivities(IItemFamily* target_family)
195{
196 return _getConnectivitiesFromGraph(m_relation_graph.inEdges(target_family), m_dependency_graph.inEdges(target_family));
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
203_getConnectivitiesFromGraph(const ConnectivityGraph::ConnectedEdgeSet& connectivity_edges)
204{
205 SharedArray<IIncrementalItemConnectivity*> connectivities(connectivity_edges.size());
206 Integer index(0);
207 for (const auto& connectivity_edge : connectivity_edges){
208 connectivities[index++] = connectivity_edge;
209 }
210 return connectivities;
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
216SharedArray<IIncrementalItemConnectivity*> ItemFamilyNetwork::
217_getConnectivitiesFromGraph(const ConnectivityGraph::ConnectedEdgeSet& connectivity_edges1, const ConnectivityGraph::ConnectedEdgeSet& connectivity_edges2)
218{
219 SharedArray<IIncrementalItemConnectivity*> connectivities(connectivity_edges1.size()+connectivity_edges2.size());
220 Integer index(0);
221 for (const auto& connectivity_edge : connectivity_edges1){
222 connectivities[index++] = connectivity_edge;
223 }
224 for (const auto& connectivity_edge : connectivity_edges2){
225 connectivities[index++] = connectivity_edge;
226 }
227 return connectivities;
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
235{
236 _getConnectivityStatus(connectivity).second.first = true;
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
244{
245 return _getConnectivityStatus(connectivity).second.first;
246}
247
250{
251 return _getConnectivityStatus(connectivity).second.second;
252}
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
255
256void ItemFamilyNetwork::
257_checkConnectivityName(IIncrementalItemConnectivity* connectivity, const String& name)
258{
259 if (connectivity->name() != name) throw FatalErrorException(String::format("Found connectivity ({0}) has not the expected name ({1}) ",connectivity->name(),name));
260}
261
262/*---------------------------------------------------------------------------*/
263/*---------------------------------------------------------------------------*/
264
266getFamilies(eSchedulingOrder order) const
267{
269
270 switch (order)
271 {
272 case TopologicalOrder:
273 for (const auto& family : m_dependency_graph.topologicalSort())
274 families.add(family);
275 break;
276 case InverseTopologicalOrder:
277 for (const auto& family : m_dependency_graph.topologicalSort().reverseOrder())
278 families.add(family);
279 break;
280 case Unknown:
281 ARCANE_FATAL("Cannot schedule task, scheduling order is unkwnown. Set Scheduling order");
282 break;
283 }
284 return families;
285}
286
288schedule(IItemFamilyNetworkTask task, eSchedulingOrder scheduling_order)
289{
290 switch (scheduling_order) {
291 case TopologicalOrder:
292 for (const auto& family : m_dependency_graph.topologicalSort())
293 task(family);
294 break;
295 case InverseTopologicalOrder:
296 for (const auto& family : m_dependency_graph.topologicalSort().reverseOrder())
297 task(family);
298 break;
299 case Unknown:
300 ARCANE_FATAL("Cannot schedule task, scheduling order is unkwnown. Set Scheduling order");
301 break;
302 }
303}
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
308std::pair<IIncrementalItemConnectivity* const,std::pair<bool,bool>>& ItemFamilyNetwork::
309_getConnectivityStatus(IIncrementalItemConnectivity* connectivity)
310{
311 auto connectivity_iterator = m_connectivity_status.find(connectivity);
312 if (connectivity_iterator == m_connectivity_status.end())
313 ARCANE_FATAL("Cannot find connectivity {0} between families {1} and {2}",
314 connectivity->name(),connectivity->sourceFamily(),connectivity->targetFamily());
315 return *(connectivity_iterator);
316}
317
318/*---------------------------------------------------------------------------*/
319/*---------------------------------------------------------------------------*/
320
322{
323 Integer graph_id = m_registred_graphs.size() ;
324 m_registred_graphs.add(graph) ;
325 return graph_id ;
326}
327
329{
330 m_registred_graphs[graph_id] = nullptr ;
331}
332
334{
335 for(auto graph : m_registred_graphs)
336 {
337 graph->modifier()->removeConnectedItemsFromCells(local_ids) ;
338 }
339}
340
341/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
343} // End namespace Arcane::mesh
344
345/*---------------------------------------------------------------------------*/
346/*---------------------------------------------------------------------------*/
347
348
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Exception lorsqu'une erreur fatale est survenue.
Interface d'un graphe du maillage.
Definition IGraph2.h:90
Interface pour gérer une connectivité incrémentale.
virtual String name() const =0
Nom de la connectivité
virtual IItemFamily * targetFamily() const =0
Famille cible.
virtual IItemFamily * sourceFamily() const =0
Famille source.
Interface d'une famille d'entités.
Definition IItemFamily.h:84
Implémentation d'une collection d'éléments sous forme de vecteur.
Definition List.h:222
Vecteur 1D de données avec sémantique par référence.
Chaîne de caractères unicode.
void setIsStored(IIncrementalItemConnectivity *connectivity) override
Positionne une connectivité comme étant stockée. A l'ajout les connectivités sont décrites comme non ...
List< IIncrementalItemConnectivity * > getConnectivities() override
Obtenir la liste de toutes les connectivités, qu'elles soient relation ou dépendance.
void addRelation(IItemFamily *source_family, IItemFamily *target_family, IIncrementalItemConnectivity *source_to_target_connectivity) override
SharedArray< IIncrementalItemConnectivity * > getChildRelations(IItemFamily *source_family) override
Obtenir la liste de toutes les relations, filles d'une famille source_family ou parentes d'une famill...
SharedArray< IIncrementalItemConnectivity * > getChildConnectivities(IItemFamily *source_family) override
Obtenir la liste de toutes les connectivités (dépendances ou relations), filles d'une famille source_...
bool isStored(IIncrementalItemConnectivity *connectivity) override
Récupère l'information relative au stockage de la connectivité
Integer registerConnectedGraph(IGraph2 *graph) override
enregistre un graphe gérant des DoFs connectés au maillage
const std::set< IItemFamily * > & getFamilies() const override
Obtenir la liste de toutes les familles.
void addDependency(IItemFamily *master_family, IItemFamily *slave_family, IIncrementalItemConnectivity *master_to_slave_connectivity, bool is_deep_connectivity) override
SharedArray< IIncrementalItemConnectivity * > getChildDependencies(IItemFamily *source_family) override
Obtenir la liste de toutes les dépendances, filles d'une famille source_family ou parentes d'une fami...
bool isDeep(IIncrementalItemConnectivity *connectivity) override
Récupère l'information relative au stockage de la connectivité
void removeConnectedDoFsFromCells(Int32ConstArrayView local_ids) override
supprime les DoFs et les liens entre DoFs connectés aux mailles supprimées
IIncrementalItemConnectivity * getConnectivity(IItemFamily *source_family, IItemFamily *target_family, const String &name) override
Obtenir une connectivité entre les familles source_family et target_family de nom name,...
IIncrementalItemConnectivity * getStoredConnectivity(IItemFamily *source_family, IItemFamily *target_family, const String &name) override
Retourne, si elle es associée à un stockage, la connectivité entre les familles source_family et targ...
void releaseConnectedGraph(Integer graph_id) override
dé enregistre un graphe gérant des DoFs connectés au maillage
IIncrementalItemConnectivity * getDependency(IItemFamily *source_family, IItemFamily *target_family) override
Retourne la connectivité de dépendance entre la famille source_family et target_family.
void schedule(IItemFamilyNetworkTask task, eSchedulingOrder order=TopologicalOrder) override
Ordonnance l'exécution d'une tâche, dans l'ordre topologique ou topologique inverse du graphe de dépe...
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