Arcane  v3.15.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ConstituentItem.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* ConstituentItem.h (C) 2000-2024 */
9/* */
10/* Entité représentant un constituant d'une maille multi-matériaux. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MATERIALS_CONSTITUENTITEM_H
13#define ARCANE_CORE_MATERIALS_CONSTITUENTITEM_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/materials/ComponentItemInternal.h"
18
19#include "arcane/Item.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Materials
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
51class ARCANE_CORE_EXPORT ConstituentItem
52{
53 // Pour accéder à _internal()
55 friend EnvCellVector;
56 friend MatCellVector;
57 friend MeshMaterialMng;
58 friend AllEnvCell;
59 friend EnvCell;
60 friend MatCell;
62
63 public:
64
65 ARCCORE_HOST_DEVICE ConstituentItem(const matimpl::ConstituentItemBase& mii)
66 : m_constituent_item_index(mii.m_constituent_item_index)
67 , m_shared_info(mii.m_shared_info)
68 {}
69
70 ARCCORE_HOST_DEVICE ConstituentItem()
71 {
72#ifndef ARCCORE_DEVICE_CODE
73 m_shared_info = ComponentItemSharedInfo::_nullInstance();
74#endif
75 }
76
77 public:
78
80 ARCCORE_HOST_DEVICE operator ComponentItemLocalId() const { return ComponentItemLocalId{ _varIndex() }; }
81
82 public:
83
85 ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const { return m_shared_info->_varIndex(m_constituent_item_index); }
86
87 ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase constituentItemBase() const { return { m_shared_info, m_constituent_item_index }; }
88
93 IMeshComponent* component() const { return m_shared_info->_component(m_constituent_item_index); }
94
96 ARCCORE_HOST_DEVICE Int32 componentId() const { return m_shared_info->_componentId(m_constituent_item_index); }
97
99 ARCCORE_HOST_DEVICE bool null() const { return m_constituent_item_index.isNull(); }
100
102 ARCCORE_HOST_DEVICE ComponentCell superCell() const { return ComponentCell(_superItemBase()); }
103
105 ARCCORE_HOST_DEVICE Int32 level() const { return m_shared_info->m_level; }
106
108 ARCCORE_HOST_DEVICE Int32 nbSubItem() const { return m_shared_info->_nbSubConstituent(m_constituent_item_index); }
109
112 {
113 return Cell(m_shared_info->_globalItemBase(m_constituent_item_index));
114 }
115
117 ARCCORE_HOST_DEVICE CellLocalId globalCellId() const
118 {
119 return CellLocalId(m_shared_info->_globalItemId(m_constituent_item_index));
120 }
121
130 Int64 componentUniqueId() const { return m_shared_info->_componentUniqueId(m_constituent_item_index); }
131
133 ARCCORE_HOST_DEVICE inline CellComponentCellEnumerator subItems() const;
134
136 ARCANE_CORE_EXPORT friend std::ostream&
137 operator<<(std::ostream& o, const ComponentCell& mvi);
138
139 protected:
140
141 static ARCCORE_HOST_DEVICE void _checkLevel([[maybe_unused]] matimpl::ConstituentItemBase item_base,
143 {
144#if !defined(ARCCORE_DEVICE_CODE)
145 if (item_base.null())
146 return;
147 Int32 lvl = item_base.level();
148 if (lvl != expected_level)
149 _badConversion(item_base, lvl, expected_level);
150#endif
151 }
152 static void _badConversion(matimpl::ConstituentItemBase item_base, Int32 level, Int32 expected_level);
153
154 ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _subItemBase(Int32 index) const
155 {
156 return m_shared_info->_subItemBase(m_constituent_item_index, index);
157 }
158 ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _superItemBase() const
159 {
160 return m_shared_info->_superItemBase(m_constituent_item_index);
161 }
162 ARCCORE_HOST_DEVICE ConstituentItemIndex _firstSubConstituentLocalId() const
163 {
164 return m_shared_info->_firstSubConstituentLocalId(m_constituent_item_index);
165 }
166
167 protected:
168
169 ConstituentItemIndex m_constituent_item_index;
170 ComponentItemSharedInfo* m_shared_info = nullptr;
171
172 private:
173
175 ARCCORE_HOST_DEVICE ConstituentItemIndex _constituentItemIndex() const
176 {
177 return m_constituent_item_index;
178 }
179};
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
186class ARCANE_CORE_EXPORT CellComponentCellEnumerator
187{
188 friend class EnumeratorTracer;
189
190 public:
191
193 {};
195 {
196 friend class CellComponentCellEnumerator;
197
198 public:
199
200 using iterator_category = std::forward_iterator_tag;
202
203 private:
204
205 ARCCORE_HOST_DEVICE explicit Iterator(CellComponentCellEnumerator enumerator)
206 : m_index(enumerator.m_index)
207 , m_size(enumerator.m_size)
208 , m_first_sub_index(enumerator.m_first_sub_index)
209 , m_sub_constituent_shared_info(enumerator.m_sub_constituent_shared_info)
210 {}
211
212 public:
213
214 ARCCORE_HOST_DEVICE void operator++() { ++m_index; }
215 ARCCORE_HOST_DEVICE ComponentCell operator*() const
216 {
217 ARCANE_CHECK_AT(m_index, m_size);
218 return ComponentCell(_currentSubItemBase());
219 }
220 ARCCORE_HOST_DEVICE operator ComponentItemLocalId() const
221 {
222 return ComponentItemLocalId(_varIndex());
223 }
224 friend ARCCORE_HOST_DEVICE bool operator==(const Iterator& x, const Sentinel&)
225 {
226 return x.m_index == x.m_size;
227 }
228
229 private:
230
231 Int32 m_index = 0;
232 Int32 m_size = 0;
233 Int32 m_first_sub_index = -1;
234 ComponentItemSharedInfo* m_sub_constituent_shared_info = nullptr;
235
236 private:
237
238 ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _currentSubItemBase() const
239 {
240 return m_sub_constituent_shared_info->_item(ConstituentItemIndex(m_first_sub_index + m_index));
241 }
242 ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const
243 {
244 return m_sub_constituent_shared_info->_varIndex(ConstituentItemIndex(m_first_sub_index + m_index));
245 }
246 };
247
248 template <typename ConstituentItemType>
249 class IteratorT : public Iterator
250 {
251 public:
252
255
256 private:
257
258 ARCCORE_HOST_DEVICE explicit IteratorT(CellComponentCellEnumeratorT<ConstituentItemType> enumerator)
259 : Iterator(enumerator)
260 {}
261
262 public:
263
264 ARCCORE_HOST_DEVICE ConstituentItemType operator*() const
265 {
266 ARCANE_CHECK_AT(m_index, m_size);
267 return ConstituentItemType(_currentSubItemBase());
268 }
269 };
270
271 public:
272
273 ARCCORE_HOST_DEVICE explicit CellComponentCellEnumerator(ComponentCell super_item)
274 : m_size(super_item.nbSubItem())
275 , m_first_sub_index(super_item._firstSubConstituentLocalId().localId())
276 , m_sub_constituent_shared_info(super_item.m_shared_info->m_sub_component_item_shared_info)
277 {
278 }
279
280 public:
281
282 ARCCORE_HOST_DEVICE void operator++() { ++m_index; }
283 ARCCORE_HOST_DEVICE bool hasNext() const { return m_index < m_size; }
284
285 ARCCORE_HOST_DEVICE ComponentCell operator*() const
286 {
287 ARCANE_CHECK_AT(m_index, m_size);
288 return ComponentCell(_currentSubItemBase());
289 }
290 ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const
291 {
292 return m_sub_constituent_shared_info->_varIndex(ConstituentItemIndex(m_first_sub_index + m_index));
293 }
294 ARCCORE_HOST_DEVICE Int32 index() const { return m_index; }
295 ARCCORE_HOST_DEVICE operator ComponentItemLocalId() const
296 {
297 return ComponentItemLocalId(_varIndex());
298 }
299 ARCCORE_HOST_DEVICE Iterator begin() const { return Iterator(*this); }
300 ARCCORE_HOST_DEVICE Sentinel end() const { return {}; }
301
302 protected:
303
304 Int32 m_index = 0;
305 Int32 m_size = 0;
306 Int32 m_first_sub_index = -1;
307 ComponentItemSharedInfo* m_sub_constituent_shared_info = nullptr;
308
309 protected:
310
311 ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _currentSubItemBase() const
312 {
313 return m_sub_constituent_shared_info->_item(ConstituentItemIndex(m_first_sub_index + m_index));
314 }
315};
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
322template <typename ComponentCellType> class CellComponentCellEnumeratorT
324{
325 public:
326
328
329 public:
330
331 explicit ARCCORE_HOST_DEVICE CellComponentCellEnumeratorT(ComponentCell super_item)
333 {}
334
335 public:
336
337 ARCCORE_HOST_DEVICE ComponentCellType operator*() const
338 {
339 ARCANE_CHECK_AT(m_index, m_size);
340 return ComponentCellType(_currentSubItemBase());
341 }
342 ARCCORE_HOST_DEVICE IteratorType begin() const { return IteratorType(*this); }
343 ARCCORE_HOST_DEVICE Sentinel end() const { return {}; }
344};
345
346/*---------------------------------------------------------------------------*/
347/*---------------------------------------------------------------------------*/
348
350subItems() const
351{
352 return CellComponentCellEnumerator(*this);
353}
354
355/*---------------------------------------------------------------------------*/
356/*---------------------------------------------------------------------------*/
357
358} // End namespace Arcane::Materials
359
360/*---------------------------------------------------------------------------*/
361/*---------------------------------------------------------------------------*/
362
363#endif
Maille d'un maillage.
Definition Item.h:1178
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:149
Maille arcane avec info matériaux et milieux.
Enumérateur typés sur les mailles composants d'une maille.
Enumérateur sur les constituants d'une maille.
Index d'une entité constituant dans la liste des entités constituants.
Index d'un ConstituentItem dans une variable.
Informations partagées sur les 'ComponentItem'.
Implémentation de ComponentItemVector.
Représente un composant d'une maille multi-matériau.
ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const
ARCCORE_HOST_DEVICE Int32 level() const
Niveau hiérarchique de l'entité
ARCCORE_HOST_DEVICE Int32 nbSubItem() const
Nombre de sous-éléments.
ARCCORE_HOST_DEVICE ConstituentItemIndex _constituentItemIndex() const
ARCCORE_HOST_DEVICE CellComponentCellEnumerator subItems() const
Liste des sous-constituents de cette entité
ARCCORE_HOST_DEVICE ComponentCell superCell() const
Maille de niveau supérieur dans la hiérarchie.
ARCCORE_HOST_DEVICE bool null() const
Indique s'il s'agit de la maille nulle.
Int64 componentUniqueId() const
Numéro unique de l'entité constituant.
ARCCORE_HOST_DEVICE CellLocalId globalCellId() const
localId() de la maille globale
Cell globalCell() const
Maille globale.
IMeshComponent * component() const
Constituant associé.
ARCCORE_HOST_DEVICE Int32 componentId() const
Identifiant du composant dans la liste des composants de ce type.
Vecteur sur les entités d'un milieu.
Maille arcane d'un milieu.
Interface d'un composant (matériau ou milieu) d'un maillage.
Vecteur sur les entités d'un matériau.
Représente un matériau d'une maille multi-matériau.
Représente un index sur les variables matériaux et milieux.
Implémentation d'un gestion des matériaux.
Informations génériques sur une entité d'un constituant.
Active toujours les traces dans les parties Arcane concernant les matériaux.