Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemGroupImpl.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/* ItemGroupImpl.h (C) 2000-2025 */
9/* */
10/* Implementation of a mesh entity group. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ITEMGROUPIMPL_H
13#define ARCANE_ITEMGROUPIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/core/SharedReference.h"
19#include "arcane/utils/SharedPtr.h"
20
21#include "arcane/core/GroupIndexTable.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31// Macro to detect design changes in ItemGroupImpl
32#define ITEMGROUP_USE_OBSERVERS
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
38class IObservable;
40class IMesh;
41class ItemGroupInternal;
43class GroupIndexTable;
45class ItemGroupImplInternal;
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50/*!
51 * \internal
52 * \brief Brief: Implementation of a mesh entity group.
53
54 A group is a set of mesh entities (nodes, faces, cells, etc.)
55 of the same type.
56
57 An instance of this class should not be used directly, but
58 through an instance of ItemGroup.
59
60 An element entity can only be present once.
61
62 The developer should not directly keep instances of this
63 class but go through an ItemGroup. Since some groups are determined
64 dynamically based on the content of another group (for example, the groups
65 of entities specific to subdomains are calculated from the group of
66 all entities of the subdomain), this ensures that group updates
67 are performed correctly.
68
69 This instance is managed by a reference counter and is destroyed
70 automatically when it reaches zero.
71 */
72class ARCANE_CORE_EXPORT ItemGroupImpl
73: public SharedReference
74{
75 private:
76
77 friend class ItemGroupSubPartsByType;
78 friend ItemGroup;
79 class ItemSorter;
80
81 public:
82
83 //! Constructs a null group.
85
86 /*! \brief Brief: Constructs a group.
87 * Constructs an empty group named \a name, associated with the family \a family.
88 */
89 ItemGroupImpl(IItemFamily* family, const String& name);
90
91 /*! \brief Brief: Constructs a child group of another group.
92 * Constructs a group named \a name which is a child of group \a parent. The type of this
93 * group is the same as that of the family it belongs to.
94 */
96
97 virtual ~ItemGroupImpl(); //!< Releases resources.
98
99 private:
100
101 static ItemGroupImpl* shared_null;
102
103 public:
104
105 static ItemGroupImpl* checkSharedNull();
106
107 public:
108
109 virtual ISharedReference& sharedReference() { return *this; }
110
111 public:
112
113 //! Group name.
114 const String& name() const;
115
116 //! Full group name (with mesh + family).
117 const String& fullName() const;
118
119 //! Number of references on the group.
120 virtual Integer nbRef() const { return refCount(); }
121
122 //! Parent group (0 if none).
123 ItemGroupImpl* parent() const;
124
125 //! Returns \a true if the group is null.
126 bool null() const;
127
128 //! Returns whether the group contains only elements specific to the subdomain.
129 bool isOwn() const;
130
131 //! Sets whether the group property is local or not.
132 void setOwn(bool v);
133
134 //! Group of entities owned by the entities of this group.
135 ItemGroupImpl* ownGroup();
136
137 //! Items in the group not owned by the subdomain
138 ItemGroupImpl* ghostGroup();
139
140 // Items in the group lying on the boundary between two subdomains
141 // Implemented for faces only
142 ItemGroupImpl* interfaceGroup();
143
144 //! Group of nodes of the elements of this group.
145 ItemGroupImpl* nodeGroup();
146
147 //! Group of edges of the elements of this group.
148 ItemGroupImpl* edgeGroup();
149
150 //! Group of faces of the elements of this group.
151 ItemGroupImpl* faceGroup();
152
153 //! Group of cells of the elements of this group.
154 ItemGroupImpl* cellGroup();
155
156 //! Creates a calculated subgroup
157 /*! The memory management of the functor is then delegated to the group */
158 ItemGroupImpl* createSubGroup(const String& suffix, IItemFamily* family, ItemGroupComputeFunctor* functor);
159
160 //! Accesses a calculated subgroup
161 /*! The memory management of the functor is then delegated to the group */
162 ItemGroupImpl* findSubGroup(const String& suffix);
163
164 /*!
165 * \brief Brief: Group of internal faces of the elements of this group.
166 *
167 * This group only exists for a cell group (itemKind()==IK_Cell).
168 * A face is internal if it is connected to two cells of this group.
169 */
170 ItemGroupImpl* innerFaceGroup();
171
172 /*!
173 * \brief Brief: Group of external faces of the elements of this group.
174 *
175 * This group only exists for a cell group (itemKind()==IK_Cell).
176 * A face is external if it is connected to only one cell of this group.
177 */
178 ItemGroupImpl* outerFaceGroup();
179
180 //! AMR
181 /*!
182 * \brief Brief: Group of active cells of this group.
183 *
184 * An active cell is a leaf cell in the AMR tree.
185 */
186 ItemGroupImpl* activeCellGroup();
187
188 /*!
189 * \brief Brief: Group of own active cells of this group.
190 */
191 ItemGroupImpl* ownActiveCellGroup();
192
193 /*!
194 * \brief Brief: Group of active cells of this group.
195 *
196 * An active cell is a leaf cell in the AMR tree.
197 */
198 ItemGroupImpl* levelCellGroup(const Integer& level);
199
200 /*!
201 * \brief Brief: Group of own active cells of this group.
202 */
203 ItemGroupImpl* ownLevelCellGroup(const Integer& level);
204
205 /*!
206 * \brief Brief: Group of domain-specific active faces.
207 *
208 * This group only exists for a cell group (itemKind()==IK_Cell).
209 * An active face is internal if it is connected to two active
210 * cells of this group.
211 */
212 ItemGroupImpl* activeFaceGroup();
213
214 /*!
215 * \brief Brief: Group of active external faces of the elements of this group.
216 *
217 * This group only exists for a cell group (itemKind()==IK_Cell).
218 * An active face is external if it is connected to only one cell
219 * of this group and is active.
220 */
221 ItemGroupImpl* ownActiveFaceGroup();
222
223 /*!
224 * \brief Brief: Group of active internal faces of the elements of this group.
225 *
226 * This group only exists for a cell group (itemKind()==IK_Cell).
227 * An active face is internal if it is connected to two active cells of this group.
228 */
229 ItemGroupImpl* innerActiveFaceGroup();
230
231 /*!
232 * \brief Brief: Group of active external faces of the elements of this group.
233 *
234 * This group only exists for a cell group (itemKind()==IK_Cell).
235 * An active face is external if it is connected to only one cell of this
236 * group and is active.
237 */
238 ItemGroupImpl* outerActiveFaceGroup();
239
240 //! AMR OFF
241
242 //! True if the group is local to the subdomain.
243 bool isLocalToSubDomain() const;
244
245 //! Sets the boolean indicating if the group is local to the subdomain.
246 void setLocalToSubDomain(bool v);
247
248 //! Mesh to which the group belongs (0 for the null group).
249 IMesh* mesh() const;
250
251 //! Type of the group. It is the type of its elements.
252 eItemKind itemKind() const;
253
254 //! Family to which the group belongs (or 0 if none)
255 IItemFamily* itemFamily() const;
256
257 //! Number of entities in the group
258 Integer size() const;
259
260 //! True if the group is empty
261 bool empty() const;
262
263 //! Removes the entities from the group
264 void clear();
265
266 //! Parent group
267 ItemGroup parentGroup();
268
269 /*!
270 * \brief Invalidates the group
271 *
272 * A very aggressive operation that causes the invalidation of all dependencies,
273 * both of observers and constructed sub-groups.
274 */
275 void invalidate(bool force_recompute);
276
277 /*!
278 * \brief Adds entities with local IDs \a items_local_id.
279 * \sa ItemGroup::addItems()
280 */
281 void addItems(Int32ConstArrayView items_local_id, bool check_if_present);
282
283 //! Positions the group entities at \a items_local_id
284 void setItems(Int32ConstArrayView items_local_id);
285
286 //! Positions the group entities at \a items_local_id, optionally sorting them.
287 void setItems(Int32ConstArrayView items_local_id, bool do_sort);
288
289 //! Removes the entities \a items_local_id from the group
290 void removeItems(Int32ConstArrayView items_local_id, bool check_if_present);
291
292 //! Removes and adds the entities \a removed_local_id and \a added_local_id from the group
293 void removeAddItems(Int32ConstArrayView removed_local_id,
294 Int32ConstArrayView added_local_id,
295 bool check_if_present);
296
297 /*!
298 * \brief Removes entities from the group whose isSuppressed() flag is true
299 */
300 void removeSuppressedItems();
301
302 //! Checks that the group is valid.
303 void checkValid();
304
305 /*! \brief Updates the group if necessary.
306 *
307 A group must be updated when it becomes invalid, for example
308 after calling invalidate().
309 \retval true if the group was updated,
310 \retval false otherwise.
311 */
312 bool checkNeedUpdate();
313
314 //! List of local IDs of the entities in this group.
315 Int32ConstArrayView itemsLocalId() const;
316
317 /*!
318 * \brief Starts a transaction.
319 *
320 * A transaction allows write access to protected groups.
321 * Using this mechanism indicates to Arcane that the user
322 * is aware that they are modifying a group 'at their own risk'.
323 */
324 void beginTransaction();
325
326 //! Ends a transaction
327 void endTransaction();
328
329 ARCANE_DEPRECATED_REASON("Y2022: Use itemInfoListView() instead")
330 //! List of entities that the group relies on
331 ItemInternalList itemsInternal() const;
332
333 //! List of entities that the group relies on
334 ItemInfoListView itemInfoListView() const;
335
336 /*!
337 * \internal
338 * \brief Indicates to this group that it is the group of all entities
339 * in the family.
340 */
341 void setIsAllItems();
342
343 //! Indicates if the group is the group of all entities
344 bool isAllItems() const;
345
346 //! Changes the indices of the group entities
347 void changeIds(Int32ConstArrayView old_to_new_ids);
348
349 //! Applies the operation \a operation to the group entities.
350 void applyOperation(IItemOperationByBasicType* operation);
351
352 //! Indicates if the group structurally needs parallel synchronization
353 bool needSynchronization() const;
354
355 //! Returns the group's timestamp. This time is incremented after every modification.
356 Int64 timestamp() const;
357
358 /*!
359 * \brief Attaches an observer.
360 *
361 * \param ref reference of the observer emitter
362 * \param obs Observer
363 */
364 void attachObserver(const void* ref, IItemGroupObserver* obs);
365
366 /*!
367 * \brief Detaches an observer.
368 *
369 * \param ref reference of the observer emitter
370 */
371 void detachObserver(const void* ref);
372
373 /*!
374 * \brief Indicates if the content of this group is observed.
375 *
376 * This has the effect of enabling incremental modification mechanisms.
377 *
378 * A group may only be observed for its structure
379 * by non-incrementally recalculated objects.
380 */
381 bool hasInfoObserver() const;
382
383 //! Defines a group calculation function
384 void setComputeFunctor(IFunctor* functor);
385
386 //! Indicates if the group is calculated
387 bool hasComputeFunctor() const;
388
389 /*!
390 * \brief Destroys the group. After this call, the group becomes a null group.
391 *
392 * \warning This method should only be called with extreme caution
393 * even in Arcane's low-level code. If references remain on this group
394 * the behavior is undefined.
395 */
396 void destroy();
397
398 //! Table of local IDs to a position for all entities in the group
399 SharedPtrT<GroupIndexTable> localIdToIndex();
400
401 //! Group synchronizer
402 IVariableSynchronizer* synchronizer();
403
404 //! Indicates if this group has a synchronizer
405 bool hasSynchronizer();
406
407 /*!
408 * \brief Checks and returns whether the group is sorted by increasing uniqueId().
409 */
410 bool checkIsSorted() const;
411
412 //! \deprecated Use isContiguousLocalIds() instead
413 bool isContigousLocalIds() const { return isContiguousLocalIds(); }
414
415 //! Indicates if the group entities have contiguous localIds().
416 bool isContiguousLocalIds() const;
417
418 //! \deprecated Use checkLocalIdsAreContiguous() instead
420
421 /*!
422 * \brief Checks if the group entities have contiguous localIds().
423 *
424 * If so, \a isContiguousLocalIds() will return \a true.
425 */
426 void checkLocalIdsAreContiguous() const;
427
428 /*!
429 * \brief Limits the maximum memory used by the group.
430 *
431 * If the group is a calculated group, it is invalidated and all its
432 * allocated memory is released.
433 *
434 * If the group is a user-created group (i.e., persistent),
435 * it ensures that the consumed memory is minimal. Normally, %Arcane allocates
436 * a few more elements than necessary to avoid frequent reallocations.
437 */
438 void shrinkMemory();
439
440 //! Number of allocated elements
441 Int64 capacity() const;
442
443 //! Internal Arcane API
444 ItemGroupImplInternal* _internalApi() const;
445
446 public:
447
448 /*!
449 * \internal
450 * \brief List of local IDs of the entities in this group.
451 * \warning Use with extreme caution, generally
452 * only by the recalculation functor.
453 */
454 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
455 Int32Array& unguardedItemsLocalId(const bool self_invalidate = true);
456
457 public:
458
459 //! Internal
460 static void _buildSharedNull();
461 //! Internal
462 static void _destroySharedNull();
463
464 private:
465
466 //! Method for calculating sub-groups by type
467 void _computeChildrenByType();
468 //! Sub-group invalidation
469 void _executeExtend(const Int32ConstArrayView* info);
470 //! Sub-group invalidation
471 void _executeReduce(const Int32ConstArrayView* info);
472 //! Sub-group invalidation
473 void _executeCompact(const Int32ConstArrayView* info);
474 //! Sub-group invalidation
475 void _executeReorder(const Int32ConstArrayView* info);
476 //! Sub-group invalidation
477 void _executeInvalidate();
478 //! Forced update of the restructuring information flag
479 void _updateNeedInfoFlag(const bool flag);
480 //! Recursive forced invalidation
481 /*! Does not notify observers. Must be followed by a normal invalidate() */
482 void _forceInvalidate(const bool self_invalidate);
483
484 void _checkUpdateSimdPadding();
485 //! Notification from SharedReference indicating that the instance must be destroyed.
486 virtual void deleteMe();
487
488 private:
489
490 ItemGroupInternal* m_p = nullptr; //!< Group implementation
491
492 private:
493
494 //! Removes the entities \a items_local_id from the group
495 void _removeItems(SmallSpan<const Int32> items_local_id);
496 bool _checkNeedUpdateNoPadding();
497 bool _checkNeedUpdateWithPadding();
498 bool _checkNeedUpdate(bool do_padding);
499};
500
501/*---------------------------------------------------------------------------*/
502/*---------------------------------------------------------------------------*/
503
504} // End namespace Arcane
505
506/*---------------------------------------------------------------------------*/
507/*---------------------------------------------------------------------------*/
508
509#endif
Declarations of types on entities.
Interface of an entity family.
Definition IItemFamily.h:83
Interface of an operator on entities sorted by type.
Interface of a reference counter.
Interface of a variable synchronization service.
Functor for calculating elements of a group.
virtual Integer nbRef() const
Number of references on the group.
ItemGroupImpl * parent() const
Parent group (0 if none).
void checkLocalIdsAreContiguous() const
Checks if the group entities have contiguous localIds().
const String & fullName() const
Full group name (with mesh + family).
void checkLocalIdsAreContigous() const
bool isContiguousLocalIds() const
Indicates if the group entities have contiguous localIds().
bool isContigousLocalIds() const
ItemGroupImpl()
Constructs a null group.
const String & name() const
Group name.
Mesh entity group.
Definition ItemGroup.h:51
View of a list to obtain information about entities.
Int32 refCount() const override
Returns the value of the reference counter.
View of an array of elements of type T.
Definition Span.h:805
-- 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
ConstArrayView< ItemInternal * > ItemInternalList
Type of the internal list of entities.
Definition ItemTypes.h:466
eItemKind
Mesh entity type.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
std::int32_t Int32
Signed integer type of 32 bits.