Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemLoop.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/* ItemLoop.h (C) 2000-2025 */
9/* */
10/* Utility classes for managing loops over entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMLOOP_H
13#define ARCANE_CORE_ITEMLOOP_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33
38namespace Loop
39{
40
46 template <typename IterType, typename Lambda> inline void
47 _InternalSimpleItemLoop(ItemVectorView view, const Lambda& lambda)
48 {
49 if (view.size() == 0)
50 return;
51 bool is_contigous = view.indexes().isContigous();
52 //is_contigous = false;
53 if (is_contigous) {
54 Int32 x0 = view.localIds()[0];
55 // Assuming iterations are independent
56 ARCANE_PRAGMA_IVDEP
57 for (Int32 i = 0, n = view.size(); i < n; ++i)
58 lambda(IterType(x0 + i));
59 }
60 else {
61 ENUMERATE_ITEM (iitem, view) {
62 lambda(IterType(iitem.localId()));
63 }
64 }
65 }
66
70 template <typename ItemType>
71 class ItemLoopFunctor
72 {
73 public:
74
75 typedef typename ItemType::Index IterType;
76 typedef ItemVectorViewT<ItemType> VectorViewType;
77 typedef ItemGroupT<ItemType> ItemGroupType;
78 typedef ItemLoopFunctor<ItemType> ThatClass;
79
80 private:
81
82 ItemLoopFunctor(ItemVectorView items)
83 : m_items(items)
84 {}
85
86 public:
87
88 static ThatClass create(const ItemGroupType& items)
89 {
90 return ThatClass(items.view());
91 }
92 static ThatClass create(VectorViewType items)
93 {
94 return ThatClass(items);
95 }
96
97 public:
98
99 template <typename Lambda>
100 void operator<<(Lambda&& lambda)
101 {
102 _InternalSimpleItemLoop<IterType>(m_items, lambda);
103 }
104
105 private:
106
107 ItemVectorView m_items;
108 };
109
110 typedef ItemLoopFunctor<Cell> ItemLoopFunctorCell;
111 typedef ItemLoopFunctor<Node> ItemLoopFunctorNode;
112
113} // End of namespace Loop
114
115} // End of namespace Arcane
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
151#define ENUMERATE_ITEM_LAMBDA(item_type, iter, container) \
152 Arcane::Loop::ItemLoopFunctor##item_type ::create((container)) << [=](Arcane::Loop::ItemLoopFunctor##item_type ::IterType iter)
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160#endif
Types and macros for iterating over mesh entities.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
Reference to a group of a given kind.
Definition ItemGroup.h:420
ItemVectorView view() const
View of the group entities.
Definition ItemGroup.cc:580
View on a typed array of entities.
View on a vector of entities.
Int32 size() const
Number of elements in the vector.
ItemIndexArrayView indexes() const
View on the array of indices.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
Template class to encapsulate a loop over entities.
Definition ItemLoop.h:72
Namespace containing various classes managing loops over entities.
Definition ItemLoop.h:39
void _InternalSimpleItemLoop(ItemVectorView view, const Lambda &lambda)
Entity loop functor that allows for the removal of indirections if the local indices of a view are co...
Definition ItemLoop.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.