Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ConstituentItemSharedInfo.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/* ConstituentItemSharedInfo.h (C) 2000-2024 */
9/* */
10/* Shared information for 'ConstituentItem' structures */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MATERIALS_CONSTITUENTITEMSHAREDINFO_H
13#define ARCANE_CORE_MATERIALS_CONSTITUENTITEMSHAREDINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemInternal.h"
18#include "arcane/core/Item.h"
19#include "arcane/core/materials/ConstituentItemLocalId.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Materials
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
37class ARCANE_CORE_EXPORT ConstituentItemIndex
38{
39 public:
40
41 ConstituentItemIndex() = default;
42 explicit ARCCORE_HOST_DEVICE constexpr ConstituentItemIndex(Int32 id)
43 : m_id(id)
44 {}
45 ARCCORE_HOST_DEVICE constexpr Int32 localId() const { return m_id; }
46 ARCCORE_HOST_DEVICE friend constexpr bool operator==(ConstituentItemIndex a,
47 ConstituentItemIndex b)
48 {
49 return a.m_id == b.m_id;
50 }
51 ARCCORE_HOST_DEVICE friend constexpr bool operator!=(ConstituentItemIndex a,
52 ConstituentItemIndex b)
53 {
54 return a.m_id != b.m_id;
55 }
56 ARCANE_CORE_EXPORT friend std::ostream&
57 operator<<(std::ostream& o, const ConstituentItemIndex& id);
58
59 ARCCORE_HOST_DEVICE constexpr bool isNull() const { return m_id == (-1); }
60
61 private:
62
63 Int32 m_id = -1;
64};
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
72class ARCANE_CORE_EXPORT ComponentItemSharedInfoStorageView
73{
74 // The fields of this class are arrays whose size is
75 // \a m_storage_size and which can be indexed by a null entity
76 // (ConstituentItemIndex==(-1)).
77 // The container is managed by ComponenItemInternalData.
78 // Only ComponentItemSharedInfo and ComponenItemInternalData
79 // should access the fields of this class
80
81 // TODO: Use single-element storage for the nullComponent
82
83 friend class ComponentItemInternalData;
84 friend ConstituentItemSharedInfo;
85
86 private:
87
88 Int32 m_storage_size = 0;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
116class ARCANE_CORE_EXPORT ConstituentItemSharedInfo
118{
119 friend ComponentItemInternalData;
120 friend CellComponentCellEnumerator;
121 friend ConstituentItemLocalIdList;
122 friend ConstituentItemLocalIdListView;
124 friend ConstituentItem;
125 friend CellToAllEnvCellConverter;
126 friend AllEnvCellVectorView;
127 friend ConstituentItemVectorImpl;
128
129 static const int MAT_INDEX_OFFSET = 10;
130
131 private:
132
134 static ComponentItemSharedInfo null_shared_info;
135 static ComponentItemSharedInfo* null_shared_info_pointer;
136 static ComponentItemSharedInfo* _nullInstance() { return null_shared_info_pointer; }
137 static void _setNullInstance();
138
139 private:
140
141 inline constexpr matimpl::ConstituentItemBase _item(ConstituentItemIndex id);
142 inline ARCCORE_HOST_DEVICE ConstituentItemIndex _firstSubConstituentLocalId(ConstituentItemIndex id) const
143 {
144 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
145 return m_first_sub_constituent_item_id_data[id.localId()];
146 }
147 inline ARCCORE_HOST_DEVICE void
148 _setFirstSubConstituentLocalId(ConstituentItemIndex id, ConstituentItemIndex first_id)
149 {
150 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
151 m_first_sub_constituent_item_id_data[id.localId()] = first_id;
152 }
153 inline ARCCORE_HOST_DEVICE Int16 _nbSubConstituent(ConstituentItemIndex id) const
154 {
155 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
156 return m_nb_sub_constituent_item_data[id.localId()];
157 }
158 ARCCORE_HOST_DEVICE inline void _setNbSubConstituent(ConstituentItemIndex id, Int16 n)
159 {
160 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
161 m_nb_sub_constituent_item_data[id.localId()] = n;
162 }
163 inline ARCCORE_HOST_DEVICE Int16 _componentId(ConstituentItemIndex id) const
164 {
165 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
166 return m_component_id_data[id.localId()];
167 }
168 ARCCORE_HOST_DEVICE inline void _setComponentId(ConstituentItemIndex id, Int16 component_id)
169 {
170 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
171 m_component_id_data[id.localId()] = component_id;
172 }
173 IMeshComponent* _component(ConstituentItemIndex id) const
174 {
175 return m_components[_componentId(id)];
176 }
177 impl::ItemBase _globalItemBase(ConstituentItemIndex id) const
178 {
179 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
180 return impl::ItemBase(m_global_item_local_id_data[id.localId()], m_item_shared_info);
181 }
182 ARCCORE_HOST_DEVICE Int32 _globalItemId(ConstituentItemIndex id) const
183 {
184 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
185 return m_global_item_local_id_data[id.localId()];
186 }
187 ARCCORE_HOST_DEVICE void _setGlobalItem(ConstituentItemIndex id, ItemLocalId global_item_lid)
188 {
189 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
190 m_global_item_local_id_data[id.localId()] = global_item_lid.localId();
191 }
192 ARCCORE_HOST_DEVICE inline matimpl::ConstituentItemBase _superItemBase(ConstituentItemIndex id) const;
193
194 ARCCORE_HOST_DEVICE void _setSuperItem(ConstituentItemIndex id, ConstituentItemIndex super_id)
195 {
196 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
197 m_super_component_item_local_id_data[id.localId()] = super_id;
198 }
199 inline ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _subItemBase(ConstituentItemIndex id, Int32 sub_index) const;
200
201 ARCCORE_HOST_DEVICE MatVarIndex _varIndex(ConstituentItemIndex id)
202 {
203 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
204 return m_var_index_data[id.localId()];
205 }
206 ARCCORE_HOST_DEVICE void _setVarIndex(ConstituentItemIndex id, MatVarIndex mv_index)
207 {
208 ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
209 m_var_index_data[id.localId()] = mv_index;
210 }
211
214 {
215 // TODO: Check that arrayIndex() does not exceed (1<<MAT_INDEX_OFFSET)
216 impl::ItemBase item_base(_globalItemBase(id));
217 return (Int64)m_var_index_data[id.localId()].arrayIndex() + ((Int64)item_base.uniqueId() << MAT_INDEX_OFFSET);
218 }
219
220 ARCCORE_HOST_DEVICE void _reset(ConstituentItemIndex id)
221 {
222 Int32 local_id = id.localId();
223 ARCCORE_CHECK_RANGE(local_id, -1, m_storage_size);
224
225 m_var_index_data[local_id].reset();
226 m_first_sub_constituent_item_id_data[local_id] = {};
227 m_nb_sub_constituent_item_data[local_id] = 0;
228 m_component_id_data[local_id] = -1;
229 m_global_item_local_id_data[local_id] = NULL_ITEM_LOCAL_ID;
230 m_super_component_item_local_id_data[local_id] = {};
231 }
232
233 private:
234
235 // NOTE: This class is shared with the C# wrapper
236 // Any modification to the internal structure must be reported
237 // in the corresponding C# structure
238 ItemSharedInfo* m_item_shared_info = ItemSharedInfo::nullInstance();
239 Int16 m_level = (-1);
240 ConstArrayView<IMeshComponent*> m_components;
241 ComponentItemSharedInfo* m_super_component_item_shared_info = null_shared_info_pointer;
242 ComponentItemSharedInfo* m_sub_component_item_shared_info = null_shared_info_pointer;
243};
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
248} // End namespace Arcane::Materials
249
250/*---------------------------------------------------------------------------*/
251/*---------------------------------------------------------------------------*/
252
253#include "arcane/core/materials/ConstituentItemBase.h"
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258#endif
ItemUniqueId uniqueId() const
Unique number of the entity.
Int16 * m_component_id_data
Index of the constituent (IMeshComponent).
ConstituentItemIndex * m_first_sub_constituent_item_id_data
Id of the first sub-constituent entity.
ConstituentItemIndex * m_super_component_item_local_id_data
Id of the parent sub-constituent entity.
Int32 * m_global_item_local_id_data
localId() of the associated global entity
Int16 * m_nb_sub_constituent_item_data
Number of sub-constituent entities.
Index of a constituent entity in the list of constituent entities.
static ComponentItemSharedInfo null_shared_info
For the null entity.
Int64 _componentUniqueId(ConstituentItemIndex id) const
Unique ID number of the component entity.
Represents an index on material and environment variables.
General information about a constituent entity.
Always enables tracing in Arcane parts concerning materials.
std::int64_t Int64
Signed integer type of 64 bits.
std::int16_t Int16
Signed integer type of 16 bits.
std::int32_t Int32
Signed integer type of 32 bits.