Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ConstituentItemIndexedSelectionView.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/* ConstituentItemIndexedSelectionView.h (C) 2000-2026 */
9/* */
10/* View over a subset of a ConstituentItem container. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MATERIALS_CONSTITUENTITEMINDEXEDSELECTIONVIEW_H
13#define ARCANE_CORE_MATERIALS_CONSTITUENTITEMINDEXEDSELECTIONVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/materials/MaterialsCoreGlobal.h"
18#include "arcane/core/materials/ComponentItemVectorView.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane::Materials::Impl
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
37template <typename ContainerType_>
39
40template <typename ConstituentContainerType_>
42{
43 using ThatContainer = ConstituentContainerType_;
44 using ValueType = ThatContainer::ValueType;
45 static constexpr bool IsSpan() { return false; }
46 static Int32 size(ThatContainer v)
47 {
48 return v.nbItem();
49 }
50};
51
52template <>
54: ConstituentItemIndexedSelectionViewTraitsBase<ComponentItemVectorView>
55{
56 static ARCCORE_HOST_DEVICE ComponentCell item(ComponentItemVectorView v, Int32 i)
57 {
58 return v.componentCell(i);
59 }
60};
61
62template <>
65{
66 static ARCCORE_HOST_DEVICE MatCell item(MatCellVectorView v, Int32 i)
67 {
68 return v.matCell(i);
69 }
70};
71
72template <>
75{
76 static ARCCORE_HOST_DEVICE EnvCell item(EnvCellVectorView v, Int32 i)
77 {
78 return v.envCell(i);
79 }
80};
81
83template <typename ConstituentItemType_>
85{
86 using ThatContainer = SmallSpan<const ConstituentItemType_>;
87 using ValueType = ConstituentItemType_;
88 static constexpr bool IsSpan() { return true; }
89 static ARCCORE_HOST_DEVICE Int32 size(ThatContainer v)
90 {
91 return v.size();
92 }
93 static ARCCORE_HOST_DEVICE ValueType item(ThatContainer v, Int32 i)
94 {
95 return v[i];
96 }
97};
98
99template <>
104template <>
109template <>
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118} // namespace Arcane::Materials::Impl
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123namespace Arcane::Materials
124{
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
132class ARCANE_CORE_EXPORT ConstituentItemIndexedSelectionViewBase
133{
134 public:
135
136 using IndexArrayView = const SmallSpan<const Int32>;
137
138 protected:
139
140 explicit ConstituentItemIndexedSelectionViewBase(SmallSpan<const Int32> indices);
141 explicit ConstituentItemIndexedSelectionViewBase(IMeshComponent* constituent, Int32 selection_size);
142
143 public:
144
146 ARCCORE_HOST_DEVICE Int32 size() const { return m_selection_view.size(); }
147
148 protected:
149
157};
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
174template <typename ContainerView_>
175class ConstituentItemIndexedSelectionView
176: public ConstituentItemIndexedSelectionViewBase
177{
178 public:
179
180 using ItemVecView = ContainerView_;
181 using ThatClass = ConstituentItemIndexedSelectionView;
183 using ValueType = TraitsType::ValueType;
184 static constexpr bool IsSpanContainer() { return TraitsType::IsSpan(); }
185
186 public:
187
188 ConstituentItemIndexedSelectionView(ItemVecView ecv, IndexArrayView indices)
189 : ConstituentItemIndexedSelectionViewBase(indices)
190 , m_container_view(ecv)
191 {
192 }
193
196 requires(IsSpanContainer())
197 : ConstituentItemIndexedSelectionViewBase(constituent, TraitsType::size(ecv))
198 , m_container_view(ecv)
199 {
200 }
201
202 protected:
203
205 explicit ConstituentItemIndexedSelectionView(ItemVecView view)
206 : ConstituentItemIndexedSelectionViewBase(view.component(), TraitsType::size(view))
207 , m_container_view(view)
208 {
209 }
210
211 public:
212
213 // total number of medium cells
214 ARCCORE_HOST_DEVICE Int32 sourceSize() const { return TraitsType::size(m_container_view); }
215
216 // view over the original EnvCell vector (all medium cells)
217 ItemVecView sourceView() const { return m_container_view; }
218
219 // List of selection indices.
220 IndexArrayView selectionView() const
221 {
223 }
224
225 ARCCORE_HOST_DEVICE ValueType operator[](Int32 i) const
226 {
227 return item(i);
228 }
229
230 ARCCORE_HOST_DEVICE ValueType item(Int32 i) const
231 {
232 ARCANE_CHECK_AT(i, size());
233 return TraitsType::item(m_container_view, m_selection_view[i]);
234 }
235
236 private:
237
239 ItemVecView m_container_view;
240};
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
248template <typename ContainerView_>
249class ConstituentItemIndexedSelectionEnumerator
250{
251 public:
252
254 using ThatClass = ConstituentItemIndexedSelectionEnumerator;
255
256 using ValueType = SelectionType::ValueType;
257
258 friend class EnumeratorTracer;
259 friend class EnumeratorBuilder<ValueType>;
260
261 private:
262
263 explicit ConstituentItemIndexedSelectionEnumerator(const SelectionType& v)
264 : m_size(v.size())
265 , m_container_with_selection(v)
266 {}
267
268 public:
269
270 static ThatClass create(SelectionType container)
271 {
272 return ThatClass(container);
273 }
274
275 public:
276
277 void operator++() { ++m_index; }
278 bool hasNext() const { return m_index < m_size; }
279
280 ValueType operator*() const
281 {
282 return m_container_with_selection.item(m_index);
283 }
284
285 Int32 index() const { return m_index; }
286
287 private:
288
289 Int32 m_index = 0;
290 Int32 m_size = 0;
291 SelectionType m_container_with_selection;
292};
293
294/*---------------------------------------------------------------------------*/
295/*---------------------------------------------------------------------------*/
296
300class ComponentCellVectorSelectionView
301: public ConstituentItemIndexedSelectionView<ComponentCellVectorView>
302{
303 using BaseClass = ConstituentItemIndexedSelectionView<ComponentCellVectorView>;
304
305 public:
306
307 ComponentCellVectorSelectionView(ComponentCellVectorView vector_view, SmallSpan<const Int32> indices)
308 : BaseClass(vector_view, indices)
309 {
310 }
311
314 : BaseClass(vector_view)
315 {
316 }
317};
318
319/*---------------------------------------------------------------------------*/
320/*---------------------------------------------------------------------------*/
321
325class EnvCellVectorSelectionView
326: public ConstituentItemIndexedSelectionView<EnvCellVectorView>
327{
328 using BaseClass = ConstituentItemIndexedSelectionView<EnvCellVectorView>;
329
330 public:
331
332 EnvCellVectorSelectionView(EnvCellVectorView vector_view, SmallSpan<const Int32> indices)
333 : BaseClass(vector_view, indices)
334 {
335 }
336
339 : BaseClass(vector_view)
340 {
341 }
342};
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
346
350class MatCellVectorSelectionView
351: public ConstituentItemIndexedSelectionView<MatCellVectorView>
352{
353 using BaseClass = ConstituentItemIndexedSelectionView<MatCellVectorView>;
354
355 public:
356
357 MatCellVectorSelectionView(MatCellVectorView vector_view, SmallSpan<const Int32> indices)
358 : BaseClass(vector_view, indices)
359 {
360 }
361
364 : BaseClass(vector_view)
365 {
366 }
367};
368
369/*---------------------------------------------------------------------------*/
370/*---------------------------------------------------------------------------*/
371
375{
376 return ConstituentItemIndexedSelectionEnumerator<ComponentCellVectorView>::create(container);
377}
378
382{
383 ConstituentItemIndexedSelectionView<ComponentCellVectorView> c2(container.sourceView(), container.selectionView());
384 return ConstituentItemIndexedSelectionEnumerator<ComponentCellVectorView>::create(c2);
385}
386
390{
391 return ConstituentItemIndexedSelectionEnumerator<EnvCellVectorView>::create(container);
392}
393
394/*---------------------------------------------------------------------------*/
395/*---------------------------------------------------------------------------*/
396
397} // namespace Arcane::Materials
398
399/*---------------------------------------------------------------------------*/
400/*---------------------------------------------------------------------------*/
401
402#endif
ComponentCellVectorSelectionView(ComponentCellVectorView vector_view)
Constructs a selection containing all elements of \view.
View over a vector of entities of a component.
__host__ __device__ ComponentCell componentCell(Int32 index) const
Returns the index-th ComponentCell of the view.
Enumerator over the elements of a ConstituentItemIndexedSelectionView.
__host__ __device__ Int32 size() const
number of selected EnvCells
ConstituentItemIndexedSelectionView(ItemVecView view)
Constructs a selection containing all elements of \view (which must derive from ComponentCellVectorVi...
ConstituentItemIndexedSelectionView(IMeshComponent *constituent, SmallSpan< const ValueType > ecv)
Constructor from a view of ConstituentCell, MatCell or EnvCell.
Represents a component of a multi-material cell.
EnvCellVectorSelectionView(EnvCellVectorView vector_view)
Constructs a selection containing all elements of \view.
Arcane cell of an environment.
__host__ __device__ EnvCell envCell(Int32 index) const
Retrieves the index-th EnvCell of the view.
Interface of a component (material or environment) of a mesh.
MatCellVectorSelectionView(MatCellVectorView vector_view)
Constructs a selection containing all elements of \view.
Represents a material in a multi-material cell.
__host__ __device__ MatCell matCell(Int32 index) const
Retrieves the index-th MatCell of the view.
View of an array of elements of type T.
Definition Span.h:805
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
constexpr ConstArrayView< value_type > constSmallView() const
Constant view of this view.
Definition Span.h:401
Always enables tracing in Arcane parts concerning materials.
EnvItemVectorView EnvCellVectorView
View type for an EnvCellVector.
ConstituentItemIndexedSelectionEnumerator< ComponentCellVectorView > arcaneImplCreateConstituentEnumerator(ComponentCell, ComponentCellVectorSelectionView container)
Enumerator over a constituent selection.
ComponentItemVectorView ComponentCellVectorView
View type for a ComponentCellVector.
MatItemVectorView MatCellVectorView
View type for a MatCellVector.
std::int32_t Int32
Signed integer type of 32 bits.
Characteristics for the container associated with ConstituentItemIndexedSelectionView.