Skip to content

Commit de119ea

Browse files
Merge pull request #1194 from arcaneframework/dev/gg-use-one-container-per-type-for-componentiteminternal-storage
Use one container of 'ComponentItemInternal' for each type of constituent item
2 parents fb472ca + 14895da commit de119ea

13 files changed

+128
-136
lines changed

arcane/src/arcane/core/materials/CellToAllEnvCellConverter.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* CellToAllEnvCellConverter.h (C) 2000-2023 */
8+
/* CellToAllEnvCellConverter.h (C) 2000-2024 */
99
/* */
1010
/* Conversion de 'Cell' en 'AllEnvCell'. */
1111
/*---------------------------------------------------------------------------*/
@@ -71,7 +71,7 @@ class CellToAllEnvCellConverter
7171
{
7272
public:
7373

74-
explicit CellToAllEnvCellConverter(ArrayView<ComponentItemInternal> v)
74+
explicit CellToAllEnvCellConverter(ConstArrayView<ComponentItemInternal> v)
7575
: m_all_env_items_internal(v){}
7676

7777
explicit CellToAllEnvCellConverter(IMeshMaterialMng* mm)
@@ -84,7 +84,7 @@ class CellToAllEnvCellConverter
8484
//! Converti une maille \a Cell en maille \a AllEnvCell
8585
AllEnvCell operator[](Cell c)
8686
{
87-
return AllEnvCell(matimpl::ConstituentItemBase(&m_all_env_items_internal[c.localId()]));
87+
return operator[](CellLocalId(c));
8888
}
8989
//! Converti une maille \a CellLocalId en maille \a AllEnvCell
9090
ARCCORE_HOST_DEVICE AllEnvCell operator[](CellLocalId c) const
@@ -95,7 +95,7 @@ class CellToAllEnvCellConverter
9595

9696
private:
9797

98-
ArrayView<ComponentItemInternal> m_all_env_items_internal;
98+
ConstArrayView<ComponentItemInternal> m_all_env_items_internal;
9999
};
100100

101101
/*---------------------------------------------------------------------------*/

arcane/src/arcane/core/materials/ComponentItem.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* ComponentItem.cc (C) 2000-2022 */
8+
/* ComponentItem.cc (C) 2000-2024 */
99
/* */
1010
/* Entités matériau et milieux. */
1111
/*---------------------------------------------------------------------------*/
@@ -26,10 +26,10 @@ namespace Arcane::Materials
2626
/*---------------------------------------------------------------------------*/
2727

2828
void ComponentCell::
29-
_badConversion(Int32 level,Int32 expected_level)
29+
_badConversion(ComponentItemInternal* item_internal, Int32 level,Int32 expected_level)
3030
{
31-
ARCANE_FATAL("bad level for internal component cell level={0} expected={1}",
32-
level,expected_level);
31+
ARCANE_FATAL("bad level for internal component cell level={0} expected={1} cid={2} component_id={3}",
32+
level,expected_level,item_internal->_internalLocalId(),item_internal->componentId());
3333
}
3434

3535
/*---------------------------------------------------------------------------*/

arcane/src/arcane/core/materials/ComponentItem.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,18 @@ class ARCANE_CORE_EXPORT ComponentCell
117117

118118
protected:
119119

120-
static ARCCORE_HOST_DEVICE void _checkLevel([[maybe_unused]] ComponentItemInternal* internal,
120+
static ARCCORE_HOST_DEVICE void _checkLevel([[maybe_unused]] ComponentItemInternal* item_internal,
121121
[[maybe_unused]] Int32 expected_level)
122122
{
123123
#if !defined(ARCCORE_DEVICE_CODE)
124-
if (internal->null())
124+
if (item_internal->null())
125125
return;
126-
Int32 lvl = internal->level();
127-
if (!internal->null() && lvl != expected_level)
128-
_badConversion(lvl, expected_level);
126+
Int32 lvl = item_internal->level();
127+
if (lvl != expected_level)
128+
_badConversion(item_internal, lvl, expected_level);
129129
#endif
130130
}
131-
static void _badConversion(Int32 level, Int32 expected_level);
131+
static void _badConversion(ComponentItemInternal* item_internal, Int32 level, Int32 expected_level);
132132

133133
protected:
134134

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

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ _throwBadCast(Int32 v)
3939
throw BadCastException(A_FUNCINFO,String::format("Can not cast v={0} to type 'Int16'",v));
4040
}
4141

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+
4248
std::ostream&
4349
operator<<(std::ostream& o,const ComponentItemInternalLocalId& id)
4450
{

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

+40-55
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Arcane::Materials
2525
{
2626
class MeshEnvironment;
2727
class MeshComponentData;
28+
class AllEnvData;
29+
class MeshMaterialMng;
2830
namespace matimpl
2931
{
3032
class ConstituentItemBase;
@@ -103,7 +105,8 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
103105
ItemSharedInfo* m_item_shared_info = ItemSharedInfo::nullInstance();
104106
Int16 m_level = (-1);
105107
ConstArrayView<IMeshComponent*> m_components;
106-
ComponentItemSharedInfo* m_parent_component_item_shared_info = null_shared_info_pointer;
108+
ComponentItemSharedInfo* m_super_component_item_shared_info = null_shared_info_pointer;
109+
ComponentItemSharedInfo* m_sub_component_item_shared_info = null_shared_info_pointer;
107110
ArrayView<ComponentItemInternal> m_component_item_internal_view;
108111
};
109112

@@ -126,6 +129,8 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
126129
friend Arcane::Materials::AllEnvCell;
127130
friend Arcane::Materials::EnvCell;
128131
friend Arcane::Materials::MatCell;
132+
friend Arcane::Materials::AllEnvData;
133+
friend Arcane::Materials::MeshMaterialMng;
129134

130135
friend Arcane::Materials::MeshEnvironment;
131136
friend Arcane::Materials::MeshComponentData;
@@ -220,6 +225,15 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
220225
private:
221226

222227
ComponentItemInternal* m_component_item = nullptr;
228+
229+
private:
230+
231+
void _checkIsInt16(Int32 v)
232+
{
233+
if (v < (-32768) || v > 32767)
234+
_throwBadCast(v);
235+
}
236+
void _throwBadCast(Int32 v);
223237
};
224238

225239
/*---------------------------------------------------------------------------*/
@@ -354,60 +368,17 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
354368
return &nullComponentItemInternal;
355369
}
356370

357-
//! Positionne l'indexeur dans les variables matériaux.
358-
void _setVariableIndex(MatVarIndex index)
359-
{
360-
m_var_index = index;
361-
}
362-
363-
//! Composant supérieur (0 si aucun)
364-
matimpl::ConstituentItemBase _superItemBase() const
365-
{
366-
return &m_shared_info->m_component_item_internal_view[m_super_component_item_local_id.localId()];
367-
}
368-
369-
void _setSuperAndGlobalItem(ComponentItemInternalLocalId cii, ItemLocalId ii)
370-
{
371-
m_super_component_item_local_id = cii;
372-
m_global_item_local_id = ii.localId();
373-
}
374-
375-
void _setGlobalItem(ItemLocalId ii)
376-
{
377-
m_global_item_local_id = ii.localId();
378-
}
371+
//! Composant supérieur (null si aucun)
372+
inline matimpl::ConstituentItemBase _superItemBase() const;
379373

380-
//! Première entité sous-composant.
374+
//! Première entité du sous-constituant
381375
ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _firstSubItemLocalId() const
382376
{
383377
return m_first_sub_component_item_local_id;
384378
}
385379

386380
ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _subItemBase(Int32 i) const;
387381

388-
//! Positionne le nombre de sous-composants.
389-
void _setNbSubItem(Int32 nb_sub_item)
390-
{
391-
#ifdef ARCANE_CHECK
392-
_checkIsInt16(nb_sub_item);
393-
#endif
394-
m_nb_sub_component_item = static_cast<Int16>(nb_sub_item);
395-
}
396-
397-
//! Positionne le premier sous-composant.
398-
void _setFirstSubItem(ComponentItemInternalLocalId first_sub_item)
399-
{
400-
m_first_sub_component_item_local_id = first_sub_item;
401-
}
402-
403-
void _setComponent(Int32 component_id)
404-
{
405-
#ifdef ARCANE_CHECK
406-
_checkIsInt16(component_id);
407-
#endif
408-
m_component_id = static_cast<Int16>(component_id);
409-
}
410-
411382
ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _internalLocalId() const
412383
{
413384
return m_component_item_internal_local_id;
@@ -457,7 +428,14 @@ inline ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase ComponentItemInternal::
457428
_subItemBase(Int32 i) const
458429
{
459430
ComponentItemInternalLocalId lid(m_first_sub_component_item_local_id.localId() + i);
460-
return m_shared_info->_item(lid);
431+
return m_shared_info->m_sub_component_item_shared_info->_item(lid);
432+
}
433+
434+
matimpl::ConstituentItemBase ComponentItemInternal::
435+
_superItemBase() const
436+
{
437+
ComponentItemInternalLocalId lid(m_super_component_item_local_id.localId());
438+
return m_shared_info->m_super_component_item_shared_info->_item(lid);
461439
}
462440

463441
/*---------------------------------------------------------------------------*/
@@ -514,7 +492,7 @@ componentUniqueId() const
514492
inline void matimpl::ConstituentItemBase::
515493
_setVariableIndex(MatVarIndex index)
516494
{
517-
m_component_item->_setVariableIndex(index);
495+
m_component_item->m_var_index = index;
518496
}
519497

520498
inline matimpl::ConstituentItemBase matimpl::ConstituentItemBase::
@@ -526,13 +504,14 @@ _superItemBase() const
526504
inline void matimpl::ConstituentItemBase::
527505
_setSuperAndGlobalItem(ComponentItemInternalLocalId cii, ItemLocalId ii)
528506
{
529-
m_component_item->_setSuperAndGlobalItem(cii, ii);
507+
m_component_item->m_super_component_item_local_id = cii;
508+
m_component_item->m_global_item_local_id = ii.localId();
530509
}
531510

532511
inline void matimpl::ConstituentItemBase::
533512
_setGlobalItem(ItemLocalId ii)
534513
{
535-
m_component_item->_setGlobalItem(ii);
514+
m_component_item->m_global_item_local_id = ii.localId();
536515
}
537516

538517
//! Première entité sous-composant.
@@ -552,26 +531,32 @@ _subItemBase(Int32 i) const
552531
inline void matimpl::ConstituentItemBase::
553532
_setNbSubItem(Int32 nb_sub_item)
554533
{
555-
m_component_item->_setNbSubItem(nb_sub_item);
534+
#ifdef ARCANE_CHECK
535+
_checkIsInt16(nb_sub_item);
536+
#endif
537+
m_component_item->m_nb_sub_component_item = static_cast<Int16>(nb_sub_item);
556538
}
557539

558540
//! Positionne le premier sous-composant.
559541
inline void matimpl::ConstituentItemBase::
560542
_setFirstSubItem(ComponentItemInternalLocalId first_sub_item)
561543
{
562-
m_component_item->_setFirstSubItem(first_sub_item);
544+
m_component_item->m_first_sub_component_item_local_id = first_sub_item;
563545
}
564546

565547
inline void matimpl::ConstituentItemBase::
566548
_setComponent(Int32 component_id)
567549
{
568-
m_component_item->_setComponent(component_id);
550+
#ifdef ARCANE_CHECK
551+
_checkIsInt16(component_id);
552+
#endif
553+
m_component_item->m_component_id = static_cast<Int16>(component_id);
569554
}
570555

571556
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId matimpl::ConstituentItemBase::
572557
_internalLocalId() const
573558
{
574-
return m_component_item->_internalLocalId();
559+
return m_component_item->m_component_item_internal_local_id;
575560
}
576561

577562
inline void matimpl::ConstituentItemBase::

arcane/src/arcane/core/materials/MatItemEnumerator.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ARCANE_CORE_EXPORT AllEnvCellVectorView
7676

7777
protected:
7878

79-
AllEnvCellVectorView(Int32ConstArrayView local_ids,ArrayView<ComponentItemInternal> items_internal)
79+
AllEnvCellVectorView(Int32ConstArrayView local_ids, ConstArrayView<ComponentItemInternal> items_internal)
8080
: m_local_ids(local_ids), m_items_internal(items_internal)
8181
{
8282
}
@@ -89,8 +89,8 @@ class ARCANE_CORE_EXPORT AllEnvCellVectorView
8989
// \i ème maille du vecteur
9090
AllEnvCell operator[](Integer index)
9191
{
92-
Int32 lid = m_local_ids[index];
93-
return AllEnvCell(matimpl::ConstituentItemBase(&m_items_internal[lid]));
92+
const ComponentItemInternal* c = &m_items_internal[m_local_ids[index]];
93+
return AllEnvCell(matimpl::ConstituentItemBase(const_cast<ComponentItemInternal*>(c)));
9494
}
9595

9696
// localId() de la \i ème maille du vecteur
@@ -102,7 +102,7 @@ class ARCANE_CORE_EXPORT AllEnvCellVectorView
102102
private:
103103

104104
Int32ConstArrayView m_local_ids;
105-
ArrayView<ComponentItemInternal> m_items_internal;
105+
ConstArrayView<ComponentItemInternal> m_items_internal;
106106
};
107107

108108
/*---------------------------------------------------------------------------*/
@@ -365,7 +365,7 @@ class ARCANE_CORE_EXPORT CellComponentCellEnumerator
365365
ARCCORE_HOST_DEVICE explicit CellComponentCellEnumerator(ComponentCell super_item)
366366
: m_size(super_item._internal()->nbSubItem())
367367
, m_items_begin(super_item._internal()->_firstSubItemLocalId().localId())
368-
, m_item_internal_list(super_item._internal()->m_shared_info->m_component_item_internal_view)
368+
, m_item_internal_list(super_item._internal()->m_shared_info->m_sub_component_item_shared_info->m_component_item_internal_view)
369369
{
370370
}
371371

arcane/src/arcane/materials/AllEnvData.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ _computeInfosForEnvCells()
219219
ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
220220

221221
ComponentItemInternalRange all_env_items_internal_range = m_item_internal_data.allEnvItemsInternalRange();
222-
ArrayView<ComponentItemInternal> all_env_items_internal = m_item_internal_data.allEnvItemsInternal();
223-
ArrayView<ComponentItemInternal> env_items_internal = m_item_internal_data.envItemsInternal();
224222
ComponentItemInternalRange env_items_internal_range = m_item_internal_data.envItemsInternalRange();
225223
ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
226224

@@ -263,7 +261,7 @@ _computeInfosForEnvCells()
263261
Int32 pos = current_pos[lid];
264262
++current_pos[lid];
265263
Int32 nb_mat = m_component_connectivity_list->cellNbMaterial(CellLocalId(lid), env_id);
266-
ComponentItemInternal& ref_ii = env_items_internal[pos];
264+
matimpl::ConstituentItemBase ref_ii = m_item_internal_data.envItemBase(pos);
267265
ComponentItemInternalLocalId cii_lid = all_env_items_internal_range[lid];
268266
env->setConstituentItem(z, ref_ii._internalLocalId());
269267
ref_ii._setSuperAndGlobalItem(cii_lid, ItemLocalId(lid));
@@ -283,7 +281,7 @@ _computeInfosForEnvCells()
283281
Cell c = *icell;
284282
Int32 lid = icell.itemLocalId();
285283
Int32 n = cells_nb_env[lid];
286-
ComponentItemInternal& ref_ii = all_env_items_internal[lid];
284+
matimpl::ConstituentItemBase ref_ii = m_item_internal_data.allEnvItemBase(c);
287285
ref_ii._setSuperAndGlobalItem({}, c);
288286
ref_ii._setVariableIndex(MatVarIndex(0, lid));
289287
ref_ii._setNbSubItem(n);

0 commit comments

Comments
 (0)