Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemEnumerator.h
Go to the documentation of this file.
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/* ItemEnumerator.h (C) 2000-2025 */
9/* */
10/* Enumerator over mesh entity groups. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMENUMERATOR_H
13#define ARCANE_CORE_ITEMENUMERATOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemInternalEnumerator.h"
18#include "arcane/core/Item.h"
19#include "arcane/core/EnumeratorTraceWrapper.h"
20#include "arcane/core/IItemEnumeratorTracer.h"
21#include "arcane/core/ItemEnumeratorBase.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27/*!
28 * \file ItemEnumerator.h
29 *
30 * \brief Types and macros for iterating over mesh entities.
31 *
32 * This file contains the different enumerator types and macros
33 * for iterating over mesh entities.
34 */
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Arcane
40{
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45class ItemEnumeratorCS;
46class ItemGroupImpl;
48
49// This method is reserved for SWIG
50extern "C++" ARCANE_CORE_EXPORT void _arcaneInternalItemEnumeratorSwigSet(const ItemEnumerator* ie, ItemEnumeratorPOD* vpod);
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55/*!
56 * \brief Enumerator over a list of entities.
57 */
58class ItemEnumerator
59: public ItemEnumeratorBaseT<Item>
60{
61 friend class ItemEnumeratorCS;
62 friend class ItemGroup;
63 friend class ItemVector;
64 friend class ItemVectorView;
65 friend class ItemPairEnumerator;
66 template <int Extent> friend class ItemConnectedListView;
67 // NOTE: Normally, it would suffice to do this:
68 // template<class T> friend class ItemEnumeratorBase;
69 // but this does not work with GCC 8. So we do the specialization
70 // manually
71 //template<class T> friend class ItemEnumeratorBaseT;
72 friend class ItemEnumeratorBaseT<Item>;
73 friend class ItemEnumeratorBaseT<Node>;
74 friend class ItemEnumeratorBaseT<ItemWithNodes>;
75 friend class ItemEnumeratorBaseT<Edge>;
76 friend class ItemEnumeratorBaseT<Face>;
77 friend class ItemEnumeratorBaseT<Cell>;
78 friend class ItemEnumeratorBaseT<Particle>;
79 friend class ItemEnumeratorBaseT<DoF>;
80 friend ARCANE_CORE_EXPORT void _arcaneInternalItemEnumeratorSwigSet(const ItemEnumerator* ie, ItemEnumeratorPOD* vpod);
81
82 public:
83
84 typedef ItemInternal* ItemInternalPtr;
85 using BaseClass = ItemEnumeratorBaseT<Item>;
86
87 public:
88
89 ItemEnumerator() = default;
90
91 ItemEnumerator(const ItemInternalVectorView& view)
92 : BaseClass(view, nullptr)
93 {}
94
95 ItemEnumerator(const ItemInternalEnumerator& rhs)
96 : BaseClass(rhs, true)
97 {}
98
99 ItemEnumerator(const impl::ItemIndexedListView<DynExtent>& rhs)
100 : BaseClass(rhs)
101 {}
102
103 public:
104
105 // For testing
106 template <int E> ItemEnumerator(const ItemConnectedListView<E>& rhs)
107 : BaseClass(ItemConnectedListViewT<Item, E>(rhs))
108 {}
109
110 private:
111
112 // Constructor reserved for ItemGroup
113 ItemEnumerator(const ItemInfoListView& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup = nullptr)
114 : BaseClass(items, local_ids, agroup)
115 {}
116
117 public:
118
119 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
120 ItemEnumerator(const ItemInternalPtr* items, const Int32* local_ids, Integer n, const ItemGroupImpl* agroup = nullptr)
121 : BaseClass(items, local_ids, n, agroup)
122 {}
123
124 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
125 ItemEnumerator(const ItemInternalArrayView& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup = nullptr)
126 : BaseClass(items, local_ids, agroup)
127 {}
128
129 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
130 ItemEnumerator(const ItemInternalVectorView& view, const ItemGroupImpl* agroup)
131 : BaseClass(view, agroup)
132 {}
133
134 protected:
135
136 // TODO To be removed
137 ItemEnumerator(ItemSharedInfo* s, const Int32ConstArrayView& local_ids)
138 : BaseClass(s, local_ids)
139 {}
140
141 ItemEnumerator(ItemSharedInfo* s, const impl::ItemLocalIdListContainerView& view)
142 : BaseClass(s, view)
143 {}
144
145 public:
146
147 static ItemEnumerator fromItemEnumerator(const ItemEnumerator& rhs)
148 {
149 return ItemEnumerator(rhs);
150 }
151
152 private:
153
154 ItemEnumerator(const impl::ItemLocalIdListContainerView& view, Int32 index,
155 const ItemGroupImpl* agroup, Item item_base)
156 : BaseClass(view, index, agroup, item_base)
157 {}
158 ItemSharedInfo* _sharedInfo() const { return _internalItemBase().m_shared_info; }
159};
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167//! Constructor only used by fromItemEnumerator()
168inline ItemEnumeratorBase::
169ItemEnumeratorBase(const ItemEnumerator& rhs, bool)
170: m_view(rhs.m_view)
171, m_index(rhs.index())
172, m_group_impl(rhs.group())
173{
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179//! Constructor only used by fromItemEnumerator()
180template <typename ItemType> inline ItemEnumeratorBaseT<ItemType>::
181ItemEnumeratorBaseT(const ItemEnumerator& rhs, bool v)
182: ItemEnumeratorBase(rhs, v)
183, m_item(rhs._internalItemBase())
184{
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190inline ItemEnumeratorBase::
191ItemEnumeratorBase(const ItemEnumerator& rhs)
192: m_view(rhs.m_view)
193, m_index(rhs.index())
194, m_group_impl(rhs.group())
195{
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201template <typename ItemType> inline ItemEnumeratorBaseT<ItemType>::
202ItemEnumeratorBaseT(const ItemEnumerator& rhs)
203: ItemEnumeratorBase(rhs)
204, m_item(rhs._internalItemBase())
205{
206}
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211template <typename ItemType> inline ItemEnumeratorBaseT<ItemType>::
214{
215}
216
217/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
219
220template <typename ItemType> inline ItemEnumerator ItemEnumeratorBaseT<ItemType>::
221toItemEnumerator() const
222{
223 return ItemEnumerator(m_view, m_index, m_group_impl, m_item);
224}
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228
229/*---------------------------------------------------------------------------*/
230/*---------------------------------------------------------------------------*/
231
232/*!
233 * \brief Enumerator over a typed list of entities of type \a ItemType
234 */
235template <typename ItemType>
236class ItemEnumeratorT
237: public ItemEnumeratorBaseT<ItemType>
238{
239 private:
240
241 using ItemInternalPtr = ItemInternal*;
242 using LocalIdType = typename ItemType::LocalIdType;
243 using BaseClass = ItemEnumeratorBaseT<ItemType>;
244 friend class ItemVectorT<ItemType>;
245 friend class ItemVectorViewT<ItemType>;
246 friend class ItemConnectedListViewT<ItemType>;
247 friend class SimdItemEnumeratorT<ItemType>;
248 template <typename I1, typename I2> friend class ItemPairEnumeratorT;
249
250 public:
251
252 ItemEnumeratorT() = default;
253 ItemEnumeratorT(const ItemVectorView& rhs)
254 : BaseClass(rhs)
255 {}
256 ItemEnumeratorT(const ItemVectorViewT<ItemType>& rhs)
257 : BaseClass(rhs)
258 {}
259
260 public:
261
262 [[deprecated("Y2021: Use strongly typed enumerator (Node, Face, Cell, ...) instead of generic (Item) enumerator")]]
263 ItemEnumeratorT(const ItemEnumerator& rhs)
264 : BaseClass(rhs)
265 {}
266
267 [[deprecated("Y2021: Use strongly typed enumerator (Node, Face, Cell, ...) instead of generic (Item) enumerator")]]
268 ItemEnumeratorT(const ItemInternalEnumerator& rhs)
269 : BaseClass(rhs)
270 {}
271
272 public:
273
274 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
275 ItemEnumeratorT(const ItemInternalPtr* items, const Int32* local_ids, Integer n, const ItemGroupImpl* agroup = nullptr)
276 : BaseClass(items, local_ids, n, agroup)
277 {}
278
279 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
280 ItemEnumeratorT(const ItemInternalArrayView& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup = nullptr)
281 : BaseClass(items, local_ids, agroup)
282 {}
283
284 ARCANE_DEPRECATED_REASON("Y2022: Internal to Arcane. Use other constructor")
285 ItemEnumeratorT(const ItemInternalVectorView& view, const ItemGroupImpl* agroup = nullptr)
286 : BaseClass(view, agroup)
287 {}
288
289 public:
290
291 // For testing
292 ItemEnumeratorT(const ItemConnectedListViewT<ItemType>& rhs)
293 : BaseClass(rhs)
294 {}
295
296 private:
297
298 // Constructor reserved for ItemGroup
299 ItemEnumeratorT(const ItemInfoListViewT<ItemType>& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup = nullptr)
300 : BaseClass(items, local_ids, agroup)
301 {}
302
303 private:
304
305 // TODO: to be removed
306 ItemEnumeratorT(ItemSharedInfo* s, const Int32ConstArrayView& local_ids)
307 : BaseClass(s, local_ids)
308 {}
309
310 ItemEnumeratorT(ItemSharedInfo* s, const impl::ItemLocalIdListContainerView& view)
311 : BaseClass(s, view)
312 {}
313
314 public:
315
316 //! Conversion to an ItemEnumerator
317 operator ItemEnumerator() const { return this->toItemEnumerator(); }
318
319 public:
320
321 static ItemEnumeratorT<ItemType> fromItemEnumerator(const ItemEnumerator& rhs)
322 {
323 return ItemEnumeratorT<ItemType>(rhs, true);
324 }
325
326 private:
327
328 //! Constructor only used by fromItemEnumerator()
329 ItemEnumeratorT(const ItemEnumerator& rhs, bool v)
330 : BaseClass(rhs, v)
331 {}
332};
333
334/*---------------------------------------------------------------------------*/
335/*---------------------------------------------------------------------------*/
336
337inline ItemEnumerator ItemVectorView::
338enumerator() const
339{
340 return ItemEnumerator(m_shared_info, m_index_view._localIds());
341}
342
343/*---------------------------------------------------------------------------*/
344/*---------------------------------------------------------------------------*/
345
346template <int Extent>
348enumerator() const
349{
350 return ItemEnumerator(m_shared_info, m_index_view._localIds());
351}
352
353/*---------------------------------------------------------------------------*/
354/*---------------------------------------------------------------------------*/
355
356template <typename ItemType> inline ItemLocalId::
357ItemLocalId(ItemEnumeratorT<ItemType> enumerator)
358: m_local_id(enumerator.asItemLocalId())
359{
360}
361
362/*---------------------------------------------------------------------------*/
363/*---------------------------------------------------------------------------*/
364
365inline ItemLocalId::
366ItemLocalId(ItemConnectedEnumerator enumerator)
367: m_local_id(enumerator.asItemLocalId())
368{
369}
370
371/*---------------------------------------------------------------------------*/
372/*---------------------------------------------------------------------------*/
373
374template <typename ItemType> inline ItemLocalId::
375ItemLocalId(ItemConnectedEnumeratorT<ItemType> enumerator)
376: m_local_id(enumerator.asItemLocalId())
377{
378}
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
382
383// TODO: add type checking
384template <typename ItemType> inline ItemLocalIdT<ItemType>::
386: ItemLocalId(enumerator.asItemLocalId())
387{
388}
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392
393template <typename ItemType> inline ItemLocalIdT<ItemType>::
395: ItemLocalId(enumerator.asItemLocalId())
396{
397}
398
399/*---------------------------------------------------------------------------*/
400/*---------------------------------------------------------------------------*/
401
402} // namespace Arcane
403
404/*---------------------------------------------------------------------------*/
405/*---------------------------------------------------------------------------*/
406
407#define ARCANE_CHECK_ENUMERATOR(enumerator, testgroup) \
408 ARCANE_ASSERT(((enumerator).group() == (testgroup).internal()), ("Invalid access on partial data using enumerator not associated to underlying group %s", testgroup.name().localstr()))
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
413#define A_ENUMERATE_ITEM(_EnumeratorClassName, iname, view) \
414 for (A_TRACE_ITEM_ENUMERATOR(_EnumeratorClassName) iname(_EnumeratorClassName ::fromItemEnumerator((view).enumerator()) A_TRACE_ENUMERATOR_WHERE); iname.hasNext(); ++iname)
415
416#define A_ENUMERATE_ITEM_NO_TRACE(_EnumeratorClassName, iname, view) \
417 for (_EnumeratorClassName iname(_EnumeratorClassName ::fromItemEnumerator((view).enumerator())); iname.hasNext(); ++iname)
418
419/*---------------------------------------------------------------------------*/
420/*---------------------------------------------------------------------------*/
421
422//! Generic enumerator for an entity group
423#define ENUMERATE_NO_TRACE_(type, name, group) A_ENUMERATE_ITEM_NO_TRACE(::Arcane::ItemEnumeratorT<type>, name, group)
424
425//! Generic enumerator for an entity group
426#define ENUMERATE_(type, name, group) A_ENUMERATE_ITEM(::Arcane::ItemEnumeratorT<type>, name, group)
427
428//! Generic enumerator for an entity group
429#define ENUMERATE_GENERIC(type, name, group) A_ENUMERATE_ITEM(::Arcane::ItemEnumeratorT<type>, name, group)
430
431//! Generic enumerator for a node group
432#define ENUMERATE_ITEM(name, group) A_ENUMERATE_ITEM(::Arcane::ItemEnumerator, name, group)
433
434#define ENUMERATE_ITEMWITHNODES(name, group) ENUMERATE_ (::Arcane::ItemWithNodes, name, group)
435
436//! Generic enumerator for a node group
437#define ENUMERATE_NODE(name, group) ENUMERATE_ (::Arcane::Node, name, group)
438
439//! Generic enumerator for an edge group
440#define ENUMERATE_EDGE(name, group) ENUMERATE_ (::Arcane::Edge, name, group)
441
442//! Generic enumerator for a face group
443#define ENUMERATE_FACE(name, group) ENUMERATE_ (::Arcane::Face, name, group)
444
445//! Generic enumerator for a cell group
446#define ENUMERATE_CELL(name, group) ENUMERATE_ (::Arcane::Cell, name, group)
447
448//! Generic enumerator for a particle group
449#define ENUMERATE_PARTICLE(name, group) ENUMERATE_ (::Arcane::Particle, name, group)
450
451//! Generic enumerator for a degree of freedom group
452#define ENUMERATE_DOF(name, group) ENUMERATE_ (::Arcane::DoF, name, group)
453
454/*---------------------------------------------------------------------------*/
455/*---------------------------------------------------------------------------*/
456
457/*!
458 * \brief Enumerator over an ItemPairGroup.
459 * \param _item_type1 Type of the group entity
460 * \param _item_type2 Type of the sub-entities of the group
461 * \param _name Name of the enumerator
462 * \param _array Instance of ItemPairGroup
463 */
464#define ENUMERATE_ITEMPAIR(_item_type1, _item_type2, _name, _array) \
465 for (::Arcane::ItemPairEnumeratorT<_item_type1, _item_type2> _name(_array); _name.hasNext(); ++_name)
466
467/*!
468 * \brief Generic enumerator over an ItemPairGroup.
469 * \sa ENUMERATE_ITEMPAIR
470 */
471#define ENUMERATE_ITEMPAIR_DIRECT(_name, _array) \
472 for (::Arcane::ItemPairEnumerator _name(_array); _name.hasNext(); ++_name)
473
474/*---------------------------------------------------------------------------*/
475/*---------------------------------------------------------------------------*/
476
477/*!
478 * \brief Enumerator over a sub-element of an ItemPairGroup.
479 * \param _item_type Type of the sub-entity
480 * \param _name Name of the enumerator
481 * \param _parent_item Instance of the parent entity or the enumerator
482 * on the parent entity.
483 */
484#define ENUMERATE_SUB_ITEM(_item_type, _name, _parent_item) \
485 for (::Arcane::ItemEnumeratorT<_item_type> _name(_parent_item.subItems()); _name.hasNext(); ++_name)
486
487/*!
488 * \brief Generic enumerator over a sub-element of an ItemPairGroup.
489 * \sa ENUMERATE_SUB_ITEM
490 */
491#define ENUMERATE_SUB_ITEM_DIRECT(_name, _parent_item) \
492 for (::Arcane::ItemInternalEnumerator _name(_parent_item.subItems()); _name.hasNext(); ++_name)
493
494/*---------------------------------------------------------------------------*/
495/*---------------------------------------------------------------------------*/
496
497#endif
Types and macros for iterating over mesh entities connected to another entity.
Cell of a mesh.
Definition Item.h:1300
degree of freedom class.
Definition Item.h:1649
Edge of a cell.
Definition Item.h:875
Face of a cell.
Definition Item.h:1032
Enumerator over a typed list of connected entities of type ItemType.
Enumerator over a list of entities connected to another.
View of a list of entities connected to another.
View of a list of entities connected to another entity.
Base class for enumerators over a list of entities.
constexpr const ItemGroupImpl * group() const
Underlying group if it exists (nullptr otherwise).
constexpr Integer index() const
Current index of the enumerator.
Enumerator over a typed list of entities of type ItemType.
Enumerator over a list of entities.
Base class for specialized views of entity information.
View of a list to obtain information about entities.
Index of an ItemType entity in a variable.
Definition ItemLocalId.h:92
Index of an Item in a variable.
Definition ItemLocalId.h:42
Typed entity vector.
Definition ItemVector.h:168
View on a typed array of entities.
View on a vector of entities.
Mesh element based on nodes (Edge,Face,Cell).
Definition Item.h:773
Base class for a mesh element.
Definition Item.h:84
Node of a mesh.
Definition Item.h:598
Particle.
Definition Item.h:1529
Enumerator over a list of entities.
Definition SimdItem.h:494
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
std::int32_t Int32
Signed integer type of 32 bits.