Arcane  v4.1.2.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DynamicMeshKindInfos.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/* DynamicMeshKindInfos.h (C) 2000-2025 */
9/* */
10/* Infos de maillage pour un genre d'entité donnée. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_DYNAMICMESHKINDINFOS_H
13#define ARCANE_MESH_DYNAMICMESHKINDINFOS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/String.h"
19#include "arcane/utils/HashTableMap.h"
20#include "arcane/utils/TraceAccessor.h"
21#include "arcane/utils/Event.h"
22
23#include "arcane/core/ItemGroup.h"
24#include "arcane/core/ItemInternal.h"
26
27#include "arcane/mesh/ItemInternalMap.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32// Define pour désactiver les évènements si on souhaite tester
33// l'influence sur les performances (a priori il n'y en a pas).
34#define ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Arcane::mesh
40{
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
50class ARCANE_MESH_EXPORT DynamicMeshKindInfos
51: public TraceAccessor
52{
53 public:
54
55 // TODO: a supprimer
56 typedef Arcane::mesh::ItemInternalMap ItemInternalMap;
57
58 private:
59
60 using ItemInternalMapData = ItemInternalMap::BaseData;
61
62 public:
63
65 DynamicMeshKindInfos(IMesh* mesh,eItemKind kind,const String& kind_name);
68
69 public:
70
71 void build();
72
74
78
84 Integer maxUsedLocalId() const { return m_internals.size(); }
85
87 void prepareForDump();
88
90 void readFromDump();
91
93 ItemGroup allItems() const { return m_all_group; }
94
96 Int32ConstArrayView addedItems () const { return m_added_items; }
97 Int32ConstArrayView removedItems() const { return m_removed_items;}
98
100
102
103 ItemInternal* itemInternal(Int32 local_id) const { return m_internals[local_id]; }
104
107 {
108 bool need_alloc = false;
109 ItemInternal* next = _allocOne(need_alloc);
110#ifdef ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
111 _notifyAdd(next,unique_id);
112#endif
113 if (m_has_unique_id_map)
114 if (!m_items_map.add(unique_id,next))
115 _badSameUniqueId(unique_id);
116 return next;
117 }
118
120 ItemInternal* allocOne(Int64 unique_id,bool& need_alloc)
121 {
122 ItemInternal* next = _allocOne(need_alloc);
123#ifdef ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
124 _notifyAdd(next,unique_id);
125#endif
126 if (m_has_unique_id_map)
127 if (!m_items_map.add(unique_id,next))
128 _badSameUniqueId(unique_id);
129 return next;
130 }
131
134 {
135#ifdef ARCANE_CHECK
136 _checkActiveItem(item);
137#endif
138 _setSuppressed(item);
139 if (m_has_unique_id_map){
140 Int64 uid = item->uniqueId().asInt64();
141 if (uid != NULL_ITEM_UNIQUE_ID)
142 m_items_map.remove(uid);
143 }
144 m_free_internals.add(item->localId());
145 m_removed_items.add(item->localId());
146#ifdef ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
147 _notifyRemove(item);
148#endif
149 --m_nb_item;
150 }
151
154 {
155#ifdef ARCANE_CHECK
156 _checkActiveItem(item);
157#endif
158 _setSuppressed(item);
159#ifndef REMOVE_UID_ON_DETACH
160 if (m_has_unique_id_map)
161 m_items_map.remove(item->uniqueId().asInt64());
162#endif
163 m_free_internals.add(item->localId());
164 m_removed_items.add(item->localId());
165#ifdef ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
166 _notifyRemove(item);
167#endif
168 --m_nb_item;
169 }
170
178 {
179#ifdef ARCANE_CHECK
180 _checkActiveItem(item);
181#endif
182 // Peut-être faut-il la marquer supprimée.
183 //_setSuppressed(item);
184#ifdef REMOVE_UID_ON_DETACH
185 if (m_has_unique_id_map)
186 m_items_map.remove(item->uniqueId().asInt64());
187#endif /* REMOVE_UID_ON_DETACH */
188 item->setDetached(true);
189 }
190
192 void removeMany(Int32ConstArrayView local_ids);
193
195 ItemInternal* findOrAllocOne(Int64 uid,bool& is_alloc)
196 {
197#ifdef ARCANE_CHECK
198 if (!m_has_unique_id_map)
199 _badUniqueIdMap();
200#endif
201 ItemInternalMap::LookupData item_data = m_items_map._lookupAdd(uid, 0, is_alloc);
202 if (is_alloc){
203 bool need_alloc;
204 item_data.setValue(_allocOne(need_alloc));
205#ifdef ARCANE_ENABLE_EVENT_FOR_DYNAMICMESHKINDINFO
206 _notifyAdd(item_data.value(),uid);
207#endif
208 }
209 return item_data.value();
210 }
211
214 {
215#ifdef ARCANE_CHECK
216 if (!m_has_unique_id_map)
217 _badUniqueIdMap();
218#endif
219 return m_items_map._tryFindItemInternal(uid);
220 }
221
223 void checkValid();
224
225 ItemInternalMap& itemsMap() { return m_items_map; }
226
227 Integer nbItem() const { return m_nb_item; }
228
229 eItemKind kind() const { return m_kind; }
230
231 bool changed() const
232 {
233 return !m_added_items.empty() || !m_removed_items.empty();
234 }
235
236 void beginCompactItems(ItemFamilyCompactInfos& compact_infos);
237
244 ARCANE_DEPRECATED_240 Int32ConstArrayView oldToNewLocalIds() const;
245
247 void clear();
248
255 ARCANE_DEPRECATED_240 Int32ConstArrayView newToOldLocalIds() const;
256
257 void finishCompactItems(ItemFamilyCompactInfos& compact_infos);
258
259 void itemsUniqueIdToLocalId(ArrayView<Int64> ids,bool do_fatal) const;
260 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
261 Int64ConstArrayView unique_ids,
262 bool do_fatal) const;
263 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
264 ConstArrayView<ItemUniqueId> unique_ids,
265 bool do_fatal) const;
266
267 ItemFamily* itemFamily() const
268 {
269 return m_item_family;
270 }
271
272 void setItemFamily(ItemFamily* item_family);
273
274 bool hasUniqueIdMap() const
275 {
276 return m_has_unique_id_map;
277 }
278
279 void setHasUniqueIdMap(bool v);
280
281 void printFreeInternals(Integer max_print);
282
283 public:
284
285 EventObservableView<const ItemFamilyItemListChangedEventArgs&> itemListChangedEvent();
286
287 private:
288
291 ItemInternal* _allocOne(bool& need_alloc)
292 {
293 ItemInternal* new_item = 0;
294 Integer nb_free = m_free_internals.size();
295 Int32 lid = 0;
296 if (nb_free!=0){
297 new_item = m_internals[m_free_internals.back()];
298 m_free_internals.popBack();
299 _setAdded(new_item);
300 lid = new_item->localId();
301 need_alloc = false;
302 }
303 else{
304 Integer nb_free2 = m_free_internals_in_multi_buffer.size();
305 if (nb_free2!=0){
306 new_item = m_free_internals_in_multi_buffer.back();
307 m_free_internals_in_multi_buffer.popBack();
308 }
309 else
310 new_item = m_item_internals_buffer->allocOne();
311 lid = m_internals.size();
312 new_item->setLocalId(lid);
313 m_internals.add(new_item);
314 _updateItemSharedInfoInternalView();
315 need_alloc = true;
316 }
317 m_added_items.add(lid);
318 ++m_nb_item;
319 return new_item;
320 }
321
322 private:
323
329 ItemInternalMap m_items_map;
330 ItemGroup m_all_group;
332 bool m_is_verbose;
333 Int32UniqueArray m_added_items;
334 Int32UniqueArray m_removed_items;
335 bool m_use_new_finalize;
336 bool m_is_first_finalize;
337 bool m_has_unique_id_map;
340 ItemSharedInfo* m_common_item_shared_info = nullptr;
342
343 public:
344
348 UniqueArray<ItemInternal*> m_free_internals_in_multi_buffer;
349
350 private:
351
358
359 private:
360
361 inline void _setSuppressed(ItemInternal* item)
362 {
363 int f = item->flags();
364 f &= ~ItemFlags::II_Added;
366 item->setFlags(f);
367 }
368
369 inline void _setAdded(ItemInternal* item)
370 {
371 int f = item->flags();
373 f &= ~ItemFlags::II_Suppressed;
374 item->setFlags(f);
375 }
376
377 void _checkActiveItem(ItemInternal* item);
378 void _dumpList();
379 void _badSameUniqueId(Int64 unique_id) const;
380 void _badUniqueIdMap() const;
381 void _updateItemSharedInfoInternalView();
382 void _notifyRemove(ItemInternal* item)
383 {
384 if (m_item_list_change_event.hasObservers())
385 _notifyRemove2(item);
386 }
387 void _notifyAdd(ItemInternal* item,Int64 uid)
388 {
389 if (m_item_list_change_event.hasObservers())
390 _notifyAdd2(item,uid);
391 }
392 void _notifyRemove2(ItemInternal* item);
393 void _notifyAdd2(ItemInternal* item,Int64 uid);
394};
395
396/*---------------------------------------------------------------------------*/
397/*---------------------------------------------------------------------------*/
398
399} // End namespace Arcane::mesh
400
401/*---------------------------------------------------------------------------*/
402/*---------------------------------------------------------------------------*/
403
404#endif
Fichier contenant les mécanismes de gestion des évènements.
Vue constante d'un tableau de type T.
Classe de base d'un handler d'évènement.
ItemUniqueId uniqueId() const
Numéro unique de l'entité
Int32 flags() const
Flags de l'entité
Int32 localId() const
Numéro local (au sous-domaine) de l'entité
Informations pour gérer le compactage des entités d'une famille.
Flags pour les caractéristiques des entités.
Definition ItemFlags.h:38
@ II_Suppressed
L'entité vient d'être supprimée.
Definition ItemFlags.h:57
@ II_Added
L'entité vient d'être ajoutée.
Definition ItemFlags.h:56
Groupe d'entités de maillage.
Definition ItemGroup.h:49
Structure interne d'une entité de maillage.
Structure interne partagée d'une entité de maillage.
Tampon pour allocation multiple.
Definition MultiBuffer.h:44
void setDetached(bool v)
Positionne l'état détachée de l'entité
void setFlags(Int32 f)
Positionne les flags de l'entité
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 m_nb_item
Groupe de toutes les entités.
String m_kind_name
Nom du genre des entités (Node, Cell, ...)
Integer maxUsedLocalId() const
Numéro local le plus grand utilisé.
MultiBufferT< ItemInternal > * m_item_internals_buffer
Tampon pour stocker une instance de ItemInternal.
void finalizeMeshChanged()
Réalloue et recalcule les structures après modification du maillage.
ItemGroup allItems() const
Groupe de toutes les entités.
void removeOne(ItemInternal *item)
Supprime l'entité item.
ItemInternal * allocOne(Int64 unique_id, bool &need_alloc)
Ajoute une entité de numéro unique unique_id.
UniqueArray< ItemInternal * > m_internals
ItemInternal des entités.
ItemInternal * findOrAllocOne(Int64 uid, bool &is_alloc)
Recherche l'entité de numéro unique unique_id et la créé si elle n'existe pas.
ConstArrayView< ItemInternal * > itemsInternal() const
Liste interne des ItemInternal's.
ItemInternal * _allocOne(bool &need_alloc)
Ajoute une entité.
Int32ConstArrayView addedItems() const
Liste des entitées ajoutées ou retirées depuis le dernier endUpdate()
DynamicMeshKindInfos(IMesh *mesh, eItemKind kind, const String &kind_name)
Créé une instance pour un maillage et un genre donnée.
ItemInternal * allocOne(Int64 unique_id)
Ajoute une entité de numéro unique unique_id.
void removeDetachedOne(ItemInternal *item)
Supprime l'entité détachée item.
ItemFamilyCompactInfos * m_compact_infos
Temporaire tant que oldToNewLocalIds() et newToOldLocalIds() existent.
String m_all_group_name
Nom du groupe contenant toutes les entités.
void detachOne(ItemInternal *item)
Détache une l'entité item.
ItemInternalMap m_items_map
Table de hachage conversion uniqueId() -> ItemInternal*.
Int32UniqueArray m_free_internals
Liste des ItemInternal de m_item_internals_buffer libres.
ItemInternal * findOne(Int64 uid)
Recherche l'entité de numéro unique uid.
eItemKind m_kind
Genre correspondant.
ItemFamily * m_item_family
Famille de maillage associée.
Famille d'entités.
Definition ItemFamily.h:76
Tableau associatif de ItemInternal.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:482
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:341
eItemKind
Genre d'entité de maillage.
std::int32_t Int32
Type entier signé sur 32 bits.