Arcane  4.1.12.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;
180 Int32ArrayView m_connectivity_nb_item;
181 Int32ArrayView m_connectivity_index;
182 Int32ArrayView m_connectivity_list;
184 ItemInternalConnectivityList* m_item_connectivity_list = nullptr;
185 Integer m_item_connectivity_index = -1;
186 std::unique_ptr<InternalApi> m_internal_api;
187
188 protected:
189
190 void _notifyConnectivityListChanged();
191 void _notifyConnectivityIndexChanged();
192 void _notifyConnectivityNbItemChanged();
193 void _notifyConnectivityNbItemChangedFromObservable();
194 void _computeMaxNbConnectedItem();
195 void _setNewMaxNbConnectedItems(Int32 new_max);
196 void _setMaxNbConnectedItemsInConnectivityList();
197
198 private:
199
200 void _shrinkMemory();
201 void _addMemoryInfos(ItemConnectivityMemoryInfo& mem_info);
202};
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
209class ARCANE_MESH_EXPORT IncrementalItemConnectivity
210: public IncrementalItemConnectivityBase
211{
212 private:
213
216
217 public:
218
219 IncrementalItemConnectivity(IItemFamily* source_family, IItemFamily* target_family,
220 const String& aname);
221 ~IncrementalItemConnectivity() override;
222
223 public:
224
225 void addConnectedItems(ItemLocalId source_item, Integer nb_item);
226 void setConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
227 void removeConnectedItems(ItemLocalId source_item) override;
228 void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
229 void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
230 void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override;
231 void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
232 bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override;
233 void notifySourceItemAdded(ItemLocalId item) override;
234 void notifyReadFromDump() override;
235
236 private:
237
238 void _internalNotifySourceItemsAdded(ConstArrayView<Int32> local_ids) override;
239
240 public:
241
242 Integer preAllocatedSize() const final { return m_pre_allocated_size; }
243 void setPreAllocatedSize(Integer value) final;
244
245 void dumpStats(std::ostream& out) const override;
246
247 void compactConnectivityList();
248
249 private:
250
251 Int64 m_nb_add = 0;
252 Int64 m_nb_remove = 0;
253 Int64 m_nb_memcopy = 0;
254 Integer m_pre_allocated_size = 0;
255
256 private:
257
258 inline void _increaseIndexList(Int32 lid, Integer size, Int32 target_lid);
259 inline Integer _increaseConnectivityList(Int32 new_lid);
260 inline Integer _increaseConnectivityList(Int32 new_lid, Integer nb_value);
261 inline Integer _computeAllocSize(Integer nb_item);
262 void _checkAddNullItem();
263 void _resetConnectivityList();
264};
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
279class ARCANE_MESH_EXPORT OneItemIncrementalItemConnectivity
280: public IncrementalItemConnectivityBase
281{
282 private:
283 public:
284
285 OneItemIncrementalItemConnectivity(IItemFamily* source_family, IItemFamily* target_family,
286 const String& aname);
287 ~OneItemIncrementalItemConnectivity() override;
288
289 public:
290
291 void notifySourceFamilyLocalIdChanged(Int32ConstArrayView new_to_old_ids) override;
292 void removeConnectedItems(ItemLocalId source_item) override;
293 void addConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
294 void removeConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) override;
295 void replaceConnectedItem(ItemLocalId source_item, Integer index, ItemLocalId target_local_id) override;
296 void replaceConnectedItems(ItemLocalId source_item, Int32ConstArrayView target_local_ids) override;
297 bool hasConnectedItem(ItemLocalId source_item, ItemLocalId target_local_id) const override;
298 void notifySourceItemAdded(ItemLocalId item) override;
299 void notifyReadFromDump() override;
300 Integer preAllocatedSize() const final { return 1; }
301 void setPreAllocatedSize([[maybe_unused]] Int32 value) final {}
302
303 public:
304
305 void dumpStats(std::ostream& out) const override;
306
307 void compactConnectivityList();
308
309 private:
310
311 inline void _checkResizeConnectivityList();
312};
313
314/*---------------------------------------------------------------------------*/
315/*---------------------------------------------------------------------------*/
316
317} // End namespace Arcane::mesh
318
319/*---------------------------------------------------------------------------*/
320/*---------------------------------------------------------------------------*/
321
322#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:83
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.
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.
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 notifyTargetFamilyLocalIdChanged(Int32ConstArrayView old_to_new_ids) override
Notifies the connectivity that the target family has been compacted.
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 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().
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:482
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
std::int32_t Int32
Signed integer type of 32 bits.