Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
IncrementalItemConnectivity.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/* IncrementalItemConnectivity.h (C) 2000-2024 */
9/* */
10/* Incremental connectivity of entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_INCREMENTALITEMCONNECTIVITY_H
13#define ARCANE_MESH_INCREMENTALITEMCONNECTIVITY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arcane/utils/TraceAccessor.h"
20
21#include "arcane/core/IItemFamily.h"
22#include "arcane/core/ItemVector.h"
23#include "arcane/core/VariableTypes.h"
24#include "arcane/core/IIncrementalItemConnectivity.h"
25
26#include "arcane/mesh/MeshGlobal.h"
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
34}
35
36namespace Arcane::mesh
37{
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
53class ARCANE_MESH_EXPORT AbstractIncrementalItemConnectivity
54: public TraceAccessor
57{
59
60 public:
61
62 AbstractIncrementalItemConnectivity(IItemFamily* source_family,
63 IItemFamily* target_family,
64 const String& connectivity_name);
65
66 public:
67
68 String name() const final { return m_name; }
69
70 public:
71
72 ConstArrayView<IItemFamily*> families() const override { return m_families.constView(); }
73 IItemFamily* sourceFamily() const override { return m_source_family; }
74 IItemFamily* targetFamily() const override { return m_target_family; }
75
76 Ref<IIncrementalItemSourceConnectivity> toSourceReference() override;
77 Ref<IIncrementalItemTargetConnectivity> toTargetReference() override;
78
79 protected:
80
81 ConstArrayView<IItemFamily*> _families() const { return m_families.constView(); }
82 IItemFamily* _sourceFamily() const { return m_source_family; }
83 IItemFamily* _targetFamily() const { return m_target_family; }
84
85 private:
86
87 IItemFamily* m_source_family;
88 IItemFamily* m_target_family;
89 SharedArray<IItemFamily*> m_families;
90 String m_name;
91};
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
98class ARCANE_MESH_EXPORT IncrementalItemConnectivityBase
99: public AbstractIncrementalItemConnectivity
100{
101 class InternalApi;
102
103 public:
104
105 template <class SourceFamily, class TargetFamily, class LegacyType, class CustomType>
106 friend class NewWithLegacyConnectivity;
107
108 public:
109
110 IncrementalItemConnectivityBase(IItemFamily* source_family, IItemFamily* target_family,
111 const String& aname);
112 ~IncrementalItemConnectivityBase() override;
113
114 public:
115
116 // Copying is forbidden because of \a m_p
117 IncrementalItemConnectivityBase(const IncrementalItemConnectivityBase&) = delete;
118 IncrementalItemConnectivityBase(IncrementalItemConnectivityBase&&) = delete;
119 IncrementalItemConnectivityBase& operator=(const IncrementalItemConnectivityBase&) = delete;
120 IncrementalItemConnectivityBase& operator=(IncrementalItemConnectivityBase&&) = delete;
121
122 public:
123
124 void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override;
125 void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids) override;
127 {
128 return m_connectivity_nb_item[lid];
129 }
131 {
132 return m_connectivity_list[m_connectivity_index[lid] + index];
133 }
134
135 IndexedItemConnectivityViewBase connectivityView() const;
136 IndexedItemConnectivityAccessor connectivityAccessor() const;
137 ItemConnectivityContainerView connectivityContainerView() const;
138
139 Int32 maxNbConnectedItem() const override;
140
141 void reserveMemoryForNbSourceItems(Int32 n, bool pre_alloc_connectivity) override;
142 IIncrementalItemConnectivityInternal* _internalApi() override;
143
144 public:
145
146 Int32ConstArrayView _connectedItemsLocalId(ItemLocalId lid) const
147 {
148 Int32 nb = m_connectivity_nb_item[lid];
149 Int32 index = m_connectivity_index[lid];
150 return { nb, &m_connectivity_list[index] };
151 }
152
153 // TODO: see if we should keep this method. Use as little as possible.
154 Int32ArrayView _connectedItemsLocalId(ItemLocalId lid)
155 {
156 Int32 nb = m_connectivity_nb_item[lid];
157 Int32 index = m_connectivity_index[lid];
158 return { nb, &m_connectivity_list[index] };
159 }
160
161 public:
162
163 Int32ArrayView connectivityIndex() { return m_connectivity_index; }
164 Int32ArrayView connectivityList() { return m_connectivity_list; }
165
166 void setItemConnectivityList(ItemInternalConnectivityList* ilist, Int32 index);
167 void dumpInfos();
168
169 protected:
170
171 void _initializeStorage(ConnectivityItemVector* civ) override
172 {
173 ARCANE_UNUSED(civ);
174 }
175 ItemVectorView _connectedItems(ItemLocalId item, ConnectivityItemVector& con_items) const final;
176
177 protected:
178
179 bool m_is_empty = true;
189 bool m_is_lazy = false;
190 Int32ArrayView m_connectivity_nb_item;
191 Int32ArrayView m_connectivity_index;
192 Int32ArrayView m_connectivity_list;
194 ItemInternalConnectivityList* m_item_connectivity_list = nullptr;
195 Integer m_item_connectivity_index = -1;
196 std::unique_ptr<InternalApi> m_internal_api;
197
198 protected:
199
200 void _lazyNotifySourceItemAdded(Int32 lid);
201 void _publishLazyViews(Int32 nb_source);
202 void _setLazyViews(ConstArrayView<Int32> zeros);
203 void _trimLazyViews();
204 void _materialize();
207 {
208 if (m_is_lazy)
209 _materialize();
210 }
211 void _notifyConnectivityListChanged();
212 void _notifyConnectivityIndexChanged();
213 void _notifyConnectivityNbItemChanged();
214 void _notifyConnectivityNbItemChangedFromObservable();
215 void _computeMaxNbConnectedItem();
216 void _setNewMaxNbConnectedItems(Int32 new_max);
217 void _setMaxNbConnectedItemsInConnectivityList();
218
219 private:
220
221 void _shrinkMemory();
222 void _addMemoryInfos(ItemConnectivityMemoryInfo& mem_info);
223};
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
230class ARCANE_MESH_EXPORT IncrementalItemConnectivity
231: public IncrementalItemConnectivityBase
232{
233 private:
234
237
238 public:
239
240 IncrementalItemConnectivity(IItemFamily* source_family, IItemFamily* target_family,
241 const String& aname);
242 ~IncrementalItemConnectivity() override;
243
244 public:
245
246 void addConnectedItems(ItemLocalId source_item, Integer nb_item);
247 void setConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
248
262
269 void resizeBulkConnectivity(Int32 nb_source, Int64 list_size,
270 Int32ArrayView& nb_items, Int32ArrayView& indexes,
271 Int32ArrayView& list);
273 void endBulkConnectivity();
274 void removeConnectedItems(ItemLocalId source_item) override;
275 void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
276 void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
277 void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override;
278 void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
279 bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override;
280 void notifySourceItemAdded(ItemLocalId item) override;
281 void notifyReadFromDump() override;
282
283 private:
284
285 void _internalNotifySourceItemsAdded(ConstArrayView<Int32> local_ids) override;
286
287 public:
288
289 Integer preAllocatedSize() const final { return m_pre_allocated_size; }
290 void setPreAllocatedSize(Integer value) final;
291
292 void dumpStats(std::ostream& out) const override;
293
294 void compactConnectivityList();
295
296 private:
297
298 Int64 m_nb_add = 0;
299 Int64 m_nb_remove = 0;
300 Int64 m_nb_memcopy = 0;
301 Integer m_pre_allocated_size = 0;
302
303 private:
304
305 inline void _increaseIndexList(Int32 lid, Integer size, Int32 target_lid);
306 inline Integer _increaseConnectivityList(Int32 new_lid);
307 inline Integer _increaseConnectivityList(Int32 new_lid, Integer nb_value);
308 inline Integer _computeAllocSize(Integer nb_item);
309 void _checkAddNullItem();
310 void _resetConnectivityList();
311};
312
313/*---------------------------------------------------------------------------*/
314/*---------------------------------------------------------------------------*/
326class ARCANE_MESH_EXPORT OneItemIncrementalItemConnectivity
327: public IncrementalItemConnectivityBase
328{
329 private:
330 public:
331
332 OneItemIncrementalItemConnectivity(IItemFamily* source_family, IItemFamily* target_family,
333 const String& aname);
334 ~OneItemIncrementalItemConnectivity() override;
335
336 public:
337
338 void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override;
339 void removeConnectedItems(ItemLocalId source_item) override;
340 void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
341 void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
342 void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override;
343 void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
344 bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override;
345 void notifySourceItemAdded(ItemLocalId item) override;
346 void notifyReadFromDump() override;
347 Integer preAllocatedSize() const final { return 1; }
348 void setPreAllocatedSize([[maybe_unused]] Int32 value) final {}
349
350 public:
351
352 void dumpStats(std::ostream& out) const override;
353
354 void compactConnectivityList();
355
356 private:
357
358 inline void _checkResizeConnectivityList();
359};
360
361/*---------------------------------------------------------------------------*/
362/*---------------------------------------------------------------------------*/
363
364} // End namespace Arcane::mesh
365
366/*---------------------------------------------------------------------------*/
367/*---------------------------------------------------------------------------*/
368
369#endif
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
Manages the retrieval of connectivity information.
Constant view of an array of type T.
Internal Arcane API for IIncrementalItemConnectivity.
Interface for managing an incremental connectivity.
Interface of an entity family.
Definition IItemFamily.h:85
Base class for a view on unstructured connectivity.
Views of containers holding connectivity. This class allows the containers used to be opaque outside ...
Memory usage information for connectivities.
Connectivity information, for an entity family, allowing transition between old and new connectivity ...
Index of an Item in a variable.
Definition ItemLocalId.h:42
View on a vector of entities.
Reference to an instance.
Thread-safe implementation of a reference counter.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
String name() const final
Name of the connectivity.
ConstArrayView< IItemFamily * > families() const override
List of families (sourceFamily() + targetFamily()).
IItemFamily * sourceFamily() const override
Source family.
IItemFamily * targetFamily() const override
Target family.
bool m_is_lazy
True while this connectivity has never had a connected item.
void _checkMaterialize()
Leaves the lazy state if this connectivity is still in it.
void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override
Notifies the connectivity that the source family has been compacted.
void _initializeStorage(ConnectivityItemVector *civ) override
Implements the initialization of civ for this connectivity.
void _publishLazyViews(Int32 nb_source)
Points both per-source views at the shared zero buffer, so a reader of nbConnectedItem() gets 0 for e...
Int32 connectedItemLocalId(ItemLocalId lid, Integer index) const final
localId() of the index-th entity connected to the source entity with local ID lid
Integer nbConnectedItem(ItemLocalId lid) const final
Number of entities connected to the source entity with local ID lid.
void _trimLazyViews()
Moves the lazy views to one zero buffer of the size of the mesh.
void _materialize()
Leaves the lazy state: allocates the two per-source arrays for real.
void notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids) override
Notifies the connectivity that the target family has been compacted.
void resizeBulkConnectivity(Int32 nb_source, Int64 list_size, Int32ArrayView &nb_items, Int32ArrayView &indexes, Int32ArrayView &list)
Sizes the storage for a bulk fill and hands out the arrays to write.
bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override
Tests the existence of a connectivity between source_item and the entity with localId() target_local_...
void setConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Allocates and positions entities connected to source_item.
void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Removes the entity with localId() target_local_id from the connectivity of source_item.
void endBulkConnectivity()
Closes a fill started by resizeBulkConnectivity().
void notifySourceItemAdded(ItemLocalId item) override
Notifies the connectivity that an entity has been added to the source family.
void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Adds the entity with localId() target_local_id to the connectivity of source_item.
void removeConnectedItems(ItemLocalId source_item) override
Removes all entities connected to source_item.
void notifyReadFromDump() override
Notifies the connectivity that a read has been performed from a dump.
friend class IndexedIncrementalItemConnectivityMng
For access to _internalNotifySourceItemsAdded().
void setBulkConnectivity(Int32ConstArrayView nb_items, Int32ConstArrayView indexes, Int32ConstArrayView list)
Replaces the whole connectivity with one the caller already knows.
Integer preAllocatedSize() const final
Number of entities pre-allocated for the connectivity of each entity.
void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Replaces the entities of source_item with the entities with localId() target_local_ids.
void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override
Replaces the entity at index index of source_item with the entity with localId() target_local_id.
void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Removes the entity with localId() target_local_id from the connectivity of source_item.
void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override
Replaces the entities of source_item with the entities with localId() target_local_ids.
void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override
Adds the entity with localId() target_local_id to the connectivity of source_item.
void notifyReadFromDump() override
Notifies the connectivity that a read has been performed from a dump.
bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override
Tests the existence of a connectivity between source_item and the entity with localId() target_local_...
void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override
Notifies the connectivity that the source family has been compacted.
void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override
Replaces the entity at index index of source_item with the entity with localId() target_local_id.
Integer preAllocatedSize() const final
Number of entities pre-allocated for the connectivity of each entity.
void notifySourceItemAdded(ItemLocalId item) override
Notifies the connectivity that an entity has been added to the source family.
void setPreAllocatedSize(Int32 value) final
Sets the number of entities to pre-allocate for the connectivity of each entity.
void removeConnectedItems(ItemLocalId source_item) override
Removes all entities connected to source_item.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
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
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:447
std::int32_t Int32
Signed integer type of 32 bits.