Arcane  4.1.12.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
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
File containing event management mechanisms.
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.
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:482
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341
eItemKind
Mesh entity type.
std::int32_t Int32
Signed integer type of 32 bits.