Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemPairGroup.cc
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/* ItemPairGroup.cc (C) 2000-2025 */
9/* */
10/* Table of entity lists. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/IFunctor.h"
15#include "arcane/utils/NotImplementedException.h"
16
17#include "arcane/core/ItemPairGroup.h"
18#include "arcane/core/IItemFamily.h"
19#include "arcane/core/ItemGroup.h"
20#include "arcane/core/ItemPairEnumerator.h"
21#include "arcane/core/ItemPairGroupBuilder.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32/*!
33 * \class ItemPairGroup
34 * \ingroup Mesh
35 * \brief Table of entity lists.
36 *
37 * This class allows managing a list of entities associated with each entity
38 * of an entity group (ItemGroup). For example, for every node in a group, the set
39 * of cells connected to this node by faces.
40 *
41 * This class has a reference semantics in the same way as the
42 * ItemGroup class.
43 *
44 * %Arcane provides a predefined set of methods to calculate the connectivities
45 * of entities connected to other entities by a specific entity type. To use these
46 * methods, you must use the following constructor:
47 * ItemPairGroup(const ItemGroup& group,const ItemGroup& sub_item_group,
48 * #eItemKind link_kind). \a link_kind then indicates the entity type
49 * that links them. For example:
50 *
51 \code
52 * CellGroup cells1;
53 * CellGroup cells2;
54 * // g1 contains for each cell in \a cells1 the cells that are
55 * // connected to it by nodes and belong to the group \a cells2
56 * CellCellGroup g1(cells1,cells2,IK_Node);
57 * ENUMERATE_ITEMPAIR(Cell,Cell,iitem,ad_list){
58 * Cell cell = *iitem;
59 * // Iterates over cells connected to 'cell'
60 * ENUMERATE_SUB_ITEM(Cell,isubitem,iitem){
61 * Cell sub_cell = *iitem;
62 * ...
63 * }
64 * }
65 \endcode
66 *
67 * It is possible for the user to specify a particular way
68 * of calculating connectivities by specifying a functor of type
69 * ItemPairGroup::CustomFunctor as an argument to the constructor.
70 *
71 * \warning The functor passed as an argument must be allocated by
72 * the new operator and will be destroyed at the same time as the associated ItemPairGroup.
73 *
74 * Here is a complete example that calculates the cells
75 * connected to the cells via faces:
76 *
77 \code
78 * auto f = [](ItemPairGroupBuilder& builder)
79 * {
80 * const ItemPairGroup& pair_group = builder.group();
81 * const ItemGroup& items = pair_group.itemGroup();
82 * const ItemGroup& sub_items = pair_group.subItemGroup();
83
84 * // Marks all entities that are not allowed to belong to
85 * // the connectivity list because they are not in \a sub_items;
86 * std::set<Int32> allowed_ids;
87 * ENUMERATE_CELL(iitem,sub_items) {
88 * allowed_ids.insert(iitem.itemLocalId());
89 * }
90
91 * Int32Array local_ids;
92 * local_ids.reserve(8);
93
94 * // List of entities already processed for the current cell
95 * std::set<Int32> already_in_list;
96 * ENUMERATE_CELL(icell,items){
97 * Cell cell = *icell;
98 * local_ids.clear();
99 * Int32 current_local_id = icell.itemLocalId();
100 * already_in_list.clear();
101
102 * // To avoid adding itself to its own connectivity list
103 * already_in_list.insert(current_local_id);
104
105 * for( FaceEnumerator iface(cell.faces()); iface.hasNext(); ++iface ){
106 * Face face = *iface;
107 * for( CellEnumerator isubcell(face.cells()); isubcell.hasNext(); ++isubcell ){
108 * const Int32 sub_local_id = isubcell.itemLocalId();
109 * // Checks if we are in the list of allowed cells and if we
110 * // have not yet been processed.
111 * if (allowed_ids.find(sub_local_id)==allowed_ids.end())
112 * continue;
113 * if (already_in_list.find(sub_local_id)!=already_in_list.end())
114 * continue;
115 * // This cell must be added. We mark it so as not to
116 * // iterate over it and we add it to the list.
117 * already_in_list.insert(sub_local_id);
118 * local_ids.add(sub_local_id);
119 * }
120 * }
121 * builder.addNextItem(local_ids);
122 * }
123 * };
124 *
125 * // Creates a group that calculates connectivities over all cells.
126 * ItemPairGroupT<Cell,Cell> ad_list(allCells(),allCells(),functor::makePointer(f));
127 \endcode
128 */
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
133/*!
134 * \internal
135 * \brief Wrapper for an ItemPairGroup::CustomFunctor.
136 */
138: public IFunctor
139{
140 public:
141
142 CustomFunctorWrapper(ItemPairGroupImpl* g, ItemPairGroup::CustomFunctor* f)
143 : m_group(g)
144 , m_functor(f)
145 {}
146 ~CustomFunctorWrapper()
147 {
148 delete m_functor;
149 }
150
151 public:
152
153 void executeFunctor() override
154 {
155 ItemPairGroup pair_group(m_group);
156 ItemPairGroupBuilder builder(pair_group);
157 m_functor->executeFunctor(builder);
158 }
159
160 public:
161
162 ItemPairGroupImpl* m_group = nullptr;
163 ItemPairGroup::CustomFunctor* m_functor = nullptr;
164};
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
170ItemPairGroup(const ItemGroup& group, const ItemGroup& sub_item_group,
171 eItemKind link_kind)
172: m_impl(nullptr)
173{
174 IItemFamily* item_family = group.itemFamily();
175 ItemPairGroup v = item_family->findAdjacencyItems(group, sub_item_group, link_kind, 1);
176 m_impl = v.internal();
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
183ItemPairGroup(const ItemGroup& group, const ItemGroup& sub_item_group,
184 CustomFunctor* functor)
185: m_impl(nullptr)
186{
187 ARCANE_CHECK_POINTER(functor);
188 m_impl = new ItemPairGroupImpl(group, sub_item_group);
189 IFunctor* f = new CustomFunctorWrapper(m_impl.get(), functor);
190 m_impl->setComputeFunctor(f);
191 m_impl->invalidate(true);
192}
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
208: m_impl(ItemPairGroupImpl::checkSharedNull())
209{
210}
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
215ItemPairEnumerator ItemPairGroup::
216enumerator() const
217{
218 return ItemPairEnumerator(*this);
219}
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224} // namespace Arcane
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemPairGroup findAdjacencyItems(const ItemGroup &group, const ItemGroup &sub_group, eItemKind link_kind, Integer nb_layer)
Searches for an adjacency list.
Mesh entity group.
Definition ItemGroup.h:51
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
Definition ItemGroup.h:128
Enumerator over an array of arrays of mesh entities.
Construction of the entity lists for the ItemPairGroup.
void executeFunctor() override
Executes the associated method.
IFunctorWithArgumentT< ItemPairGroupBuilder & > CustomFunctor
Functor for custom connectivity calculation.
ItemPairGroup()
Constructs an empty table.
AutoRefT< ItemPairGroupImpl > m_impl
Internal representation of the group.
ItemPairGroupImpl * internal() const
Returns the group implementation.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eItemKind
Mesh entity type.