Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
DynamicMeshKindInfos.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* Mesh information for a given entity kind. */
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 to disable events if one wishes to test
33// the influence on performance (there are supposedly none).
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: to be removed
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 // Maybe it should be marked suppressed.
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
254 void allocMany(Int64ConstArrayView uids, Int32ArrayView lids);
255
263 bool hasNoItemInternal() const { return m_internals.empty() && m_free_internals.empty(); }
264
266 void clear();
267
274 ARCANE_DEPRECATED_240 Int32ConstArrayView newToOldLocalIds() const;
275
276 void finishCompactItems(ItemFamilyCompactInfos& compact_infos);
277
278 void itemsUniqueIdToLocalId(ArrayView<Int64> ids, bool do_fatal) const;
279 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
280 Int64ConstArrayView unique_ids,
281 bool do_fatal) const;
282 void itemsUniqueIdToLocalId(Int32ArrayView local_ids,
284 bool do_fatal) const;
285
286 ItemFamily* itemFamily() const
287 {
288 return m_item_family;
289 }
290
291 void setItemFamily(ItemFamily* item_family);
292
293 bool hasUniqueIdMap() const
294 {
295 return m_has_unique_id_map;
296 }
297
298 void setHasUniqueIdMap(bool v);
299
300 void printFreeInternals(Integer max_print);
301
302 public:
303
304 EventObservableView<const ItemFamilyItemListChangedEventArgs&> itemListChangedEvent();
305
306 private:
307
310 ItemInternal* _allocOne(bool& need_alloc)
311 {
312 ItemInternal* new_item = 0;
313 Integer nb_free = m_free_internals.size();
314 Int32 lid = 0;
315 if (nb_free != 0) {
316 new_item = m_internals[m_free_internals.back()];
317 m_free_internals.popBack();
318 _setAdded(new_item);
319 lid = new_item->localId();
320 need_alloc = false;
321 }
322 else {
323 Integer nb_free2 = m_free_internals_in_multi_buffer.size();
324 if (nb_free2 != 0) {
325 new_item = m_free_internals_in_multi_buffer.back();
326 m_free_internals_in_multi_buffer.popBack();
327 }
328 else
329 new_item = m_item_internals_buffer->allocOne();
330 lid = m_internals.size();
331 new_item->setLocalId(lid);
332 m_internals.add(new_item);
333 _updateItemSharedInfoInternalView();
334 need_alloc = true;
335 }
336 m_added_items.add(lid);
337 ++m_nb_item;
338 return new_item;
339 }
340
341 private:
342
348 ItemInternalMap m_items_map;
349 ItemGroup m_all_group;
351 bool m_is_verbose;
352 Int32UniqueArray m_added_items;
353 Int32UniqueArray m_removed_items;
354 bool m_use_new_finalize;
355 bool m_is_first_finalize;
356 bool m_has_unique_id_map;
359 ItemSharedInfo* m_common_item_shared_info = nullptr;
361
362 public:
363
367 UniqueArray<ItemInternal*> m_free_internals_in_multi_buffer;
368
369 private:
370
377
378 private:
379
380 inline void _setSuppressed(ItemInternal* item)
381 {
382 int f = item->flags();
383 f &= ~ItemFlags::II_Added;
385 item->setFlags(f);
386 }
387
388 inline void _setAdded(ItemInternal* item)
389 {
390 int f = item->flags();
392 f &= ~ItemFlags::II_Suppressed;
393 item->setFlags(f);
394 }
395
396 void _checkActiveItem(ItemInternal* item);
397 void _dumpList();
398 void _badSameUniqueId(Int64 unique_id) const;
399 void _badUniqueIdMap() const;
400 void _updateItemSharedInfoInternalView();
401 void _notifyRemove(ItemInternal* item)
402 {
403 if (m_item_list_change_event.hasObservers())
404 _notifyRemove2(item);
405 }
406 void _notifyAdd(ItemInternal* item, Int64 uid)
407 {
408 if (m_item_list_change_event.hasObservers())
409 _notifyAdd2(item, uid);
410 }
411 void _notifyRemove2(ItemInternal* item);
412 void _notifyAdd2(ItemInternal* item, Int64 uid);
413};
414
415/*---------------------------------------------------------------------------*/
416/*---------------------------------------------------------------------------*/
417
418} // End namespace Arcane::mesh
419
420/*---------------------------------------------------------------------------*/
421/*---------------------------------------------------------------------------*/
422
423#endif
File containing event management mechanisms.
Modifiable view of an array of type T.
Constant view of an array of type T.
ItemUniqueId uniqueId() const
Unique number of the entity.
Int32 flags() const
Flags of the entity.
Int32 localId() const
Local number (in the subdomain) of the entity.
Information to manage the compaction of entities of a family.
Flags for entity characteristics.
Definition ItemFlags.h:39
@ II_Suppressed
The entity has just been suppressed.
Definition ItemFlags.h:58
@ II_Added
The entity has just been added.
Definition ItemFlags.h:57
Mesh entity group.
Definition ItemGroup.h:51
Internal structure of a mesh entity.
Internal shared structure of a mesh entity.
Buffer for multiple allocation.
Definition MultiBuffer.h:45
void setDetached(bool v)
Sets the detached state of the entity.
void setFlags(Int32 f)
Sets the entity flags.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
Integer m_nb_item
Group of all entities.
String m_kind_name
Name of the entity kind (Node, Cell, ...).
Integer maxUsedLocalId() const
Largest local ID used.
MultiBufferT< ItemInternal > * m_item_internals_buffer
Buffer to store an instance of ItemInternal.
void finalizeMeshChanged()
Reallocates and recalculates structures after mesh modification.
ItemGroup allItems() const
Group of all entities.
void removeOne(ItemInternal *item)
Removes the entity item.
ItemInternal * allocOne(Int64 unique_id, bool &need_alloc)
Adds an entity with a unique ID unique_id.
UniqueArray< ItemInternal * > m_internals
ItemInternals of the entities.
ItemInternal * findOrAllocOne(Int64 uid, bool &is_alloc)
Finds the entity with unique ID unique_id and creates it if it does not exist.
ConstArrayView< ItemInternal * > itemsInternal() const
Internal list of ItemInternals.
ItemInternal * _allocOne(bool &need_alloc)
Adds an entity.
Int32ConstArrayView addedItems() const
List of entities added or removed since the last endUpdate().
DynamicMeshKindInfos(IMesh *mesh, eItemKind kind, const String &kind_name)
Creates an instance for a given mesh and kind.
ItemInternal * allocOne(Int64 unique_id)
Adds an entity with a unique ID unique_id.
void removeDetachedOne(ItemInternal *item)
Removes the detached entity item.
ItemFamilyCompactInfos * m_compact_infos
Temporary while oldToNewLocalIds() and newToOldLocalIds() exist.
String m_all_group_name
Name of the group containing all entities.
void detachOne(ItemInternal *item)
Detaches the entity item.
ItemInternalMap m_items_map
Hash table for uniqueId() -> ItemInternal* conversion.
Int32UniqueArray m_free_internals
List of free ItemInternals from m_item_internals_buffer.
ItemInternal * findOne(Int64 uid)
Finds the entity with unique ID uid.
bool hasNoItemInternal() const
Whether the family holds no ItemInternal at all.
eItemKind m_kind
Corresponding kind.
ItemFamily * m_item_family
Associated mesh family.
Associative array of ItemInternal.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:476
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:474
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:335
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:447
eItemKind
Mesh entity type.
std::int32_t Int32
Signed integer type of 32 bits.