Skip to content

Commit b79acee

Browse files
[arcane,materials] Conserve le numéro du constituant et le nombre d'entités sous-consituantes dans 'ComponenItemSharedInfo'.
1 parent ab287ee commit b79acee

File tree

7 files changed

+115
-71
lines changed

7 files changed

+115
-71
lines changed

arcane/src/arcane/core/materials/ComponentItemInternal.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ ComponentItemSharedInfo* ComponentItemSharedInfo::null_shared_info_pointer = &Co
3333
/*---------------------------------------------------------------------------*/
3434
/*---------------------------------------------------------------------------*/
3535

36-
void ComponentItemInternal::
37-
_throwBadCast(Int32 v)
38-
{
39-
throw BadCastException(A_FUNCINFO,String::format("Can not cast v={0} to type 'Int16'",v));
40-
}
41-
42-
void matimpl::ConstituentItemBase::
43-
_throwBadCast(Int32 v)
44-
{
45-
throw BadCastException(A_FUNCINFO,String::format("Can not cast v={0} to type 'Int16'",v));
46-
}
47-
4836
std::ostream&
4937
operator<<(std::ostream& o,const ComponentItemInternalLocalId& id)
5038
{

arcane/src/arcane/core/materials/ComponentItemInternal.h

Lines changed: 83 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,27 @@ class ARCANE_CORE_EXPORT ComponentItemInternalLocalId
7171
*/
7272
class ARCANE_CORE_EXPORT ComponentItemSharedInfoStorageView
7373
{
74-
protected:
74+
// Les champs de cette classe sont des tableaux dont la taille est
75+
// \a m_storage_size et qui peuvent être indexés par une entité nulle
76+
// (ComponentItemInternalLocalId==(-1)).
77+
// Le conteneur est géré par ComponenItemInternalData.
78+
// Seuls ComponentItemSharedInfo et ComponenItemInternalData
79+
// doivent accéder aux champs de cette classe
7580

76-
Int32 m_storage_size = 0;
7781
// TODO: Utiliser stockage avec un seul élément pour le nullComponent
78-
ComponentItemInternalLocalId* m_first_sub_constituent_list_ptr = nullptr;
82+
83+
friend class ComponentItemInternalData;
84+
friend class ComponentItemSharedInfo;
85+
86+
private:
87+
88+
Int32 m_storage_size = 0;
89+
//! Id de la première entité sous-constituant
90+
ComponentItemInternalLocalId* m_first_sub_constituent_item_id_data = nullptr;
91+
//! Index du constituant (IMeshComponent)
92+
Int16* m_component_id_data = nullptr;
93+
//! Nombre d'entités sous-constituant
94+
Int16* m_nb_sub_constituent_item_data = nullptr;
7995
};
8096

8197
/*---------------------------------------------------------------------------*/
@@ -91,7 +107,7 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfoStorageView
91107
* d'un MeshMaterialMng.
92108
*/
93109
class ARCANE_CORE_EXPORT ComponentItemSharedInfo
94-
: ComponentItemSharedInfoStorageView
110+
: private ComponentItemSharedInfoStorageView
95111
{
96112
friend class ComponentItemInternal;
97113
friend class ComponentItemInternalData;
@@ -111,22 +127,52 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
111127

112128
inline constexpr ComponentItemInternal* _itemInternal(ComponentItemInternalLocalId id);
113129
inline constexpr matimpl::ConstituentItemBase _item(ComponentItemInternalLocalId id);
114-
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _firstSubConstituentLocalId(ComponentItemInternalLocalId id)
130+
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _firstSubConstituentLocalId(ComponentItemInternalLocalId id) const
131+
{
132+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
133+
return m_first_sub_constituent_item_id_data[id.localId()];
134+
}
135+
inline ARCCORE_HOST_DEVICE Int16 _nbSubConstituent(ComponentItemInternalLocalId id) const
115136
{
116137
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
117-
return m_first_sub_constituent_list_ptr[id.localId()];
138+
return m_nb_sub_constituent_item_data[id.localId()];
118139
}
140+
inline void _setNbSubConstituent(ComponentItemInternalLocalId id, Int16 n)
141+
{
142+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
143+
m_nb_sub_constituent_item_data[id.localId()] = n;
144+
}
145+
inline ARCCORE_HOST_DEVICE Int16 _componentId(ComponentItemInternalLocalId id) const
146+
{
147+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
148+
return m_component_id_data[id.localId()];
149+
}
150+
inline void _setComponentId(ComponentItemInternalLocalId id, Int16 component_id)
151+
{
152+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
153+
m_component_id_data[id.localId()] = component_id;
154+
}
155+
119156
inline ARCCORE_HOST_DEVICE void
120157
_setFirstSubConstituentLocalId(ComponentItemInternalLocalId id, ComponentItemInternalLocalId first_id)
121158
{
122159
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
123-
m_first_sub_constituent_list_ptr[id.localId()] = first_id;
160+
m_first_sub_constituent_item_id_data[id.localId()] = first_id;
161+
}
162+
163+
IMeshComponent* _component(ComponentItemInternalLocalId id) const
164+
{
165+
return m_components[_componentId(id)];
124166
}
167+
125168
inline void _reset(ComponentItemInternalLocalId id)
126169
{
127170
Int32 local_id = id.localId();
128171
ARCCORE_CHECK_RANGE(local_id, -1, m_storage_size);
129-
m_first_sub_constituent_list_ptr[local_id] = {};
172+
173+
m_first_sub_constituent_item_id_data[local_id] = {};
174+
m_nb_sub_constituent_item_data[local_id] = 0;
175+
m_component_id_data[local_id] = -1;
130176
}
131177

132178
private:
@@ -184,7 +230,7 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
184230
inline ARCCORE_HOST_DEVICE constexpr MatVarIndex variableIndex() const;
185231

186232
//! Identifiant du composant
187-
inline ARCCORE_HOST_DEVICE constexpr Int32 componentId() const;
233+
inline ARCCORE_HOST_DEVICE Int32 componentId() const;
188234

189235
//! Indique s'il s'agit de la maille nulle.
190236
inline ARCCORE_HOST_DEVICE constexpr bool null() const;
@@ -198,7 +244,7 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
198244
inline IMeshComponent* component() const;
199245

200246
//! Nombre de sous-composants.
201-
inline ARCCORE_HOST_DEVICE constexpr Int32 nbSubItem() const;
247+
inline ARCCORE_HOST_DEVICE Int32 nbSubItem() const;
202248

203249
//! Entité globale correspondante.
204250
inline impl::ItemBase globalItemBase() const;
@@ -239,12 +285,12 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
239285
inline ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _subItemBase(Int32 i) const;
240286

241287
//! Positionne le nombre de sous-composants.
242-
inline void _setNbSubItem(Int32 nb_sub_item);
288+
inline void _setNbSubItem(Int16 nb_sub_item);
243289

244290
//! Positionne le premier sous-composant.
245291
inline void _setFirstSubItem(ComponentItemInternalLocalId first_sub_item);
246292

247-
inline void _setComponent(Int32 component_id);
293+
inline void _setComponent(Int16 component_id);
248294

249295
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _internalLocalId() const;
250296

@@ -260,12 +306,8 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
260306

261307
private:
262308

263-
void _checkIsInt16(Int32 v)
264-
{
265-
if (v < (-32768) || v > 32767)
266-
_throwBadCast(v);
267-
}
268-
void _throwBadCast(Int32 v);
309+
inline ComponentItemSharedInfo* _sharedInfo() const;
310+
inline ComponentItemInternalLocalId _localId() const;
269311
};
270312

271313
/*---------------------------------------------------------------------------*/
@@ -334,7 +376,7 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
334376
}
335377

336378
//! Identifiant du composant
337-
ARCCORE_HOST_DEVICE constexpr Int32 componentId() const { return m_component_id; }
379+
ARCCORE_HOST_DEVICE Int32 componentId() const { return m_shared_info->_componentId(m_component_item_internal_local_id); }
338380

339381
//! Indique s'il s'agit de la maille nulle.
340382
ARCCORE_HOST_DEVICE constexpr bool null() const { return m_var_index.null(); }
@@ -345,12 +387,12 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
345387
* Cet appel n'est valide que pour les mailles matériaux ou milieux. Si on souhaite
346388
* un appel valide pour toutes les 'ComponentItem', il faut utiliser componentId().
347389
*/
348-
IMeshComponent* component() const { return m_shared_info->m_components[m_component_id]; }
390+
IMeshComponent* component() const { return m_shared_info->_component(m_component_item_internal_local_id); }
349391

350392
//! Nombre de sous-composants.
351-
ARCCORE_HOST_DEVICE constexpr Int32 nbSubItem() const
393+
ARCCORE_HOST_DEVICE Int32 nbSubItem() const
352394
{
353-
return m_nb_sub_component_item;
395+
return m_shared_info->_nbSubConstituent(m_component_item_internal_local_id);
354396
}
355397

356398
//! Entité globale correspondante.
@@ -375,22 +417,11 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
375417
// Toute modification de la structure interne doit être reportée
376418
// dans la structure C# correspondante
377419
MatVarIndex m_var_index;
378-
Int16 m_component_id = -1;
379-
Int16 m_nb_sub_component_item = 0;
380420
Int32 m_global_item_local_id = NULL_ITEM_LOCAL_ID;
381421
ComponentItemInternalLocalId m_component_item_internal_local_id;
382422
ComponentItemInternalLocalId m_super_component_item_local_id;
383423
ComponentItemSharedInfo* m_shared_info = nullptr;
384424

385-
private:
386-
387-
void _checkIsInt16(Int32 v)
388-
{
389-
if (v < (-32768) || v > 32767)
390-
_throwBadCast(v);
391-
}
392-
void _throwBadCast(Int32 v);
393-
394425
private:
395426

396427
//! Entité nulle
@@ -418,10 +449,8 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
418449
void _reset(ComponentItemInternalLocalId id, ComponentItemSharedInfo* shared_info)
419450
{
420451
m_var_index.reset();
421-
m_component_id = -1;
422452
m_super_component_item_local_id = {};
423453
m_component_item_internal_local_id = id;
424-
m_nb_sub_component_item = 0;
425454
m_global_item_local_id = NULL_ITEM_LOCAL_ID;
426455
m_shared_info = shared_info;
427456
m_shared_info->_reset(id);
@@ -452,6 +481,18 @@ ConstituentItemBase(ComponentItemSharedInfo* shared_info, ComponentItemInternalL
452481
{
453482
}
454483

484+
inline ComponentItemSharedInfo* matimpl::ConstituentItemBase::
485+
_sharedInfo() const
486+
{
487+
return m_component_item->m_shared_info;
488+
}
489+
490+
inline ComponentItemInternalLocalId matimpl::ConstituentItemBase::
491+
_localId() const
492+
{
493+
return m_component_item->m_component_item_internal_local_id;
494+
}
495+
455496
/*---------------------------------------------------------------------------*/
456497
/*---------------------------------------------------------------------------*/
457498

@@ -478,7 +519,7 @@ variableIndex() const
478519
return m_component_item->variableIndex();
479520
}
480521

481-
inline ARCCORE_HOST_DEVICE constexpr Int32 matimpl::ConstituentItemBase::
522+
inline ARCCORE_HOST_DEVICE Int32 matimpl::ConstituentItemBase::
482523
componentId() const
483524
{
484525
return m_component_item->componentId();
@@ -496,7 +537,7 @@ component() const
496537
return m_component_item->component();
497538
}
498539

499-
inline ARCCORE_HOST_DEVICE constexpr Int32 matimpl::ConstituentItemBase::
540+
inline ARCCORE_HOST_DEVICE Int32 matimpl::ConstituentItemBase::
500541
nbSubItem() const
501542
{
502543
return m_component_item->nbSubItem();
@@ -560,28 +601,22 @@ _subItemBase(Int32 i) const
560601

561602
//! Positionne le nombre de sous-composants.
562603
inline void matimpl::ConstituentItemBase::
563-
_setNbSubItem(Int32 nb_sub_item)
604+
_setNbSubItem(Int16 nb_sub_item)
564605
{
565-
#ifdef ARCANE_CHECK
566-
_checkIsInt16(nb_sub_item);
567-
#endif
568-
m_component_item->m_nb_sub_component_item = static_cast<Int16>(nb_sub_item);
606+
_sharedInfo()->_setNbSubConstituent(_localId(), nb_sub_item);
569607
}
570608

571609
//! Positionne le premier sous-composant.
572610
inline void matimpl::ConstituentItemBase::
573611
_setFirstSubItem(ComponentItemInternalLocalId first_sub_item)
574612
{
575-
m_component_item->m_shared_info->_setFirstSubConstituentLocalId(m_component_item->m_component_item_internal_local_id, first_sub_item);
613+
_sharedInfo()->_setFirstSubConstituentLocalId(_localId(), first_sub_item);
576614
}
577615

578616
inline void matimpl::ConstituentItemBase::
579-
_setComponent(Int32 component_id)
617+
_setComponent(Int16 component_id)
580618
{
581-
#ifdef ARCANE_CHECK
582-
_checkIsInt16(component_id);
583-
#endif
584-
m_component_item->m_component_id = static_cast<Int16>(component_id);
619+
_sharedInfo()->_setComponentId(_localId(), component_id);
585620
}
586621

587622
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId matimpl::ConstituentItemBase::

arcane/src/arcane/materials/AllEnvData.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ _computeInfosForEnvCells()
260260
Int32 lid = local_ids[z];
261261
Int32 pos = current_pos[lid];
262262
++current_pos[lid];
263-
Int32 nb_mat = m_component_connectivity_list->cellNbMaterial(CellLocalId(lid), env_id);
263+
Int16 nb_mat = m_component_connectivity_list->cellNbMaterial(CellLocalId(lid), env_id);
264264
matimpl::ConstituentItemBase ref_ii = m_item_internal_data.envItemBase(pos);
265265
ComponentItemInternalLocalId cii_lid = all_env_items_internal_range[lid];
266266
env->setConstituentItem(z, ref_ii._internalLocalId());
@@ -280,7 +280,7 @@ _computeInfosForEnvCells()
280280
ENUMERATE_CELL (icell, all_cells) {
281281
Cell c = *icell;
282282
Int32 lid = icell.itemLocalId();
283-
Int32 n = cells_nb_env[lid];
283+
Int16 n = cells_nb_env[lid];
284284
matimpl::ConstituentItemBase ref_ii = m_item_internal_data.allEnvItemBase(c);
285285
ref_ii._setSuperAndGlobalItem({}, c);
286286
ref_ii._setVariableIndex(MatVarIndex(0, lid));

arcane/src/arcane/materials/ComponentItemInternalData.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ namespace Arcane::Materials
3131

3232
ComponentItemInternalData::Storage::
3333
Storage(const MemoryAllocationOptions& alloc_info)
34-
: m_first_sub_constituent_list(alloc_info)
34+
: m_first_sub_constituent_item_id_list(alloc_info)
35+
, m_component_id_list(alloc_info)
36+
, m_nb_sub_constituent_item_list(alloc_info)
3537
{
3638
}
3739

@@ -44,11 +46,20 @@ resize(Int32 new_size, ComponentItemSharedInfo* shared_info)
4446
// On dimensionne au nombre d'éléments + 1.
4547
// On décale de 1 la vue pour qu'elle puisse être indexée avec l'entité
4648
// nulle (d'indice (-1)).
47-
m_first_sub_constituent_list.resize(new_size + 1);
48-
m_first_sub_constituent_list[0] = {};
49+
Int32 true_size = new_size + 1;
50+
m_first_sub_constituent_item_id_list.resize(true_size);
51+
m_first_sub_constituent_item_id_list[0] = {};
52+
53+
m_component_id_list.resize(true_size);
54+
m_component_id_list[0] = -1;
55+
56+
m_nb_sub_constituent_item_list.resize(true_size);
57+
m_nb_sub_constituent_item_list[0] = 0;
4958

5059
shared_info->m_storage_size = new_size;
51-
shared_info->m_first_sub_constituent_list_ptr = m_first_sub_constituent_list.data() + 1;
60+
shared_info->m_first_sub_constituent_item_id_data = m_first_sub_constituent_item_id_list.data() + 1;
61+
shared_info->m_component_id_data = m_component_id_list.data() + 1;
62+
shared_info->m_nb_sub_constituent_item_data = m_nb_sub_constituent_item_list.data() + 1;
5263
}
5364

5465
/*---------------------------------------------------------------------------*/

arcane/src/arcane/materials/MeshEnvironment.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ computeMaterialIndexes(ComponentItemInternalData* item_internal_data)
233233
Integer nb_mat = m_true_materials.size();
234234
for (Integer i = 0; i < nb_mat; ++i) {
235235
MeshMaterial* mat = m_true_materials[i];
236-
Int32 mat_id = mat->id();
236+
Int16 mat_id = mat->componentId();
237237
const MeshMaterialVariableIndexer* var_indexer = mat->variableIndexer();
238238
CellGroup mat_cells = mat->cells();
239239
info(4) << "COMPUTE (V2) mat_cells mat=" << mat->name() << " nb_cell=" << mat_cells.size()

arcane/src/arcane/materials/internal/ComponentItemInternalData.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class ComponentItemInternalRange
114114
class ComponentItemInternalData
115115
: public TraceAccessor
116116
{
117+
//! Conteneur pour les informations de ComponentItemSharedInfo
117118
class Storage
118119
{
119120
public:
@@ -126,7 +127,9 @@ class ComponentItemInternalData
126127

127128
private:
128129

129-
UniqueArray<ComponentItemInternalLocalId> m_first_sub_constituent_list;
130+
UniqueArray<ComponentItemInternalLocalId> m_first_sub_constituent_item_id_list;
131+
UniqueArray<Int16> m_component_id_list;
132+
UniqueArray<Int16> m_nb_sub_constituent_item_list;
130133
};
131134

132135
public:

0 commit comments

Comments
 (0)