Skip to content

Commit 2434aff

Browse files
Merge pull request #1190 from arcaneframework/dev/gg-add-componentiteminternal-localid-list
Add class 'ConstituentItemLocalIdList' to handle list of 'ComponentItemInternal*'
2 parents ee57660 + 5403967 commit 2434aff

15 files changed

+392
-156
lines changed

Diff for: arcane/src/arcane/core/materials/ComponentItemInternal.h

+80-29
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace Arcane::Materials
2525
{
2626

27-
2827
/*---------------------------------------------------------------------------*/
2928
/*---------------------------------------------------------------------------*/
3029
/*!
@@ -47,12 +46,22 @@ class ARCANE_CORE_EXPORT ComponentItemInternalLocalId
4746

4847
/*---------------------------------------------------------------------------*/
4948
/*---------------------------------------------------------------------------*/
50-
49+
/*!
50+
* \internal
51+
* \brief Informations partagées sur les 'ComponentItemInternal'.
52+
*
53+
* Il y a 3 instances de cette classe : une pour les AllEnvCell, une pour les
54+
* EnvCell et une pour les MatCell. Ces instances sont gérées par la classe
55+
* ComponentItemInternalData. Il est possible de conserver un pointeur sur
56+
* les intances de cette classe car ils sont valides durant toute la vie
57+
* d'un MeshMaterialMng.
58+
*/
5159
class ARCANE_CORE_EXPORT ComponentItemSharedInfo
5260
{
5361
friend class ComponentItemInternal;
5462
friend class ComponentItemInternalData;
5563
friend class CellComponentCellEnumerator;
64+
friend class ConstituentItemLocalIdList;
5665

5766
private:
5867

@@ -61,6 +70,10 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
6170
static ComponentItemSharedInfo* null_shared_info_pointer;
6271
static ComponentItemSharedInfo* _nullInstance() { return null_shared_info_pointer; }
6372

73+
private:
74+
75+
inline ComponentItemInternal* _itemInternal(ComponentItemInternalLocalId id);
76+
6477
private:
6578

6679
// NOTE : Cette classe est partagée avec le wrapper C#
@@ -76,45 +89,74 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
7689
/*---------------------------------------------------------------------------*/
7790
/*---------------------------------------------------------------------------*/
7891

79-
namespace matimpl
92+
}
93+
94+
namespace Arcane::Materials::matimpl
95+
{
96+
97+
/*---------------------------------------------------------------------------*/
98+
/*---------------------------------------------------------------------------*/
99+
/*!
100+
* \internal
101+
*/
102+
class ARCANE_CORE_EXPORT ComponentItemInternalLocalIdListView
103+
{
104+
private:
105+
106+
ComponentItemSharedInfo* m_component_shared_info = nullptr;
107+
ArrayView<ComponentItemInternalLocalId> m_ids;
108+
};
109+
110+
/*---------------------------------------------------------------------------*/
111+
/*---------------------------------------------------------------------------*/
112+
113+
class ARCANE_CORE_EXPORT ConstituentItemBase
80114
{
81-
class ARCANE_CORE_EXPORT ConstituentItemBase
115+
friend Arcane::Materials::ComponentCell;
116+
friend Arcane::Materials::AllEnvCell;
117+
friend Arcane::Materials::EnvCell;
118+
friend Arcane::Materials::MatCell;
119+
120+
public:
121+
122+
ARCCORE_HOST_DEVICE constexpr ConstituentItemBase(ComponentItemInternal* component_item)
123+
: m_component_item(component_item)
82124
{
83-
friend Arcane::Materials::ComponentCell;
84-
friend Arcane::Materials::AllEnvCell;
85-
friend Arcane::Materials::EnvCell;
86-
friend Arcane::Materials::MatCell;
125+
}
87126

88-
public:
127+
public:
89128

90-
ARCCORE_HOST_DEVICE constexpr ConstituentItemBase(ComponentItemInternal* component_item)
91-
: m_component_item(component_item)
92-
{
93-
}
129+
ARCCORE_HOST_DEVICE constexpr friend bool
130+
operator==(const ConstituentItemBase& a, const ConstituentItemBase& b)
131+
{
132+
return a.m_component_item == b.m_component_item;
133+
}
134+
ARCCORE_HOST_DEVICE constexpr friend bool
135+
operator!=(const ConstituentItemBase& a, const ConstituentItemBase& b)
136+
{
137+
return a.m_component_item != b.m_component_item;
138+
}
94139

95-
public:
140+
private:
96141

97-
ARCCORE_HOST_DEVICE constexpr friend bool
98-
operator==(const ConstituentItemBase& a, const ConstituentItemBase& b)
99-
{
100-
return a.m_component_item == b.m_component_item;
101-
}
102-
ARCCORE_HOST_DEVICE constexpr friend bool
103-
operator!=(const ConstituentItemBase& a, const ConstituentItemBase& b)
104-
{
105-
return a.m_component_item != b.m_component_item;
106-
}
142+
ARCCORE_HOST_DEVICE constexpr ComponentItemInternal* _internal() const { return m_component_item; }
107143

108-
private:
144+
private:
109145

110-
ARCCORE_HOST_DEVICE constexpr ComponentItemInternal* _internal() const { return m_component_item; }
146+
ComponentItemInternal* m_component_item = nullptr;
147+
};
111148

112-
private:
149+
/*---------------------------------------------------------------------------*/
150+
/*---------------------------------------------------------------------------*/
113151

114-
ComponentItemInternal* m_component_item = nullptr;
115-
};
116152
} // namespace matimpl
117153

154+
/*---------------------------------------------------------------------------*/
155+
/*---------------------------------------------------------------------------*/
156+
157+
namespace Arcane::Materials
158+
{
159+
118160
/*---------------------------------------------------------------------------*/
119161
/*---------------------------------------------------------------------------*/
120162
/*!
@@ -310,6 +352,15 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
310352
/*---------------------------------------------------------------------------*/
311353
/*---------------------------------------------------------------------------*/
312354

355+
inline ComponentItemInternal* ComponentItemSharedInfo::
356+
_itemInternal(ComponentItemInternalLocalId id)
357+
{
358+
return m_component_item_internal_view.ptrAt(id.localId());
359+
}
360+
361+
/*---------------------------------------------------------------------------*/
362+
/*---------------------------------------------------------------------------*/
363+
313364
} // End namespace Arcane::Materials
314365

315366
/*---------------------------------------------------------------------------*/

Diff for: arcane/src/arcane/core/materials/internal/IMeshMaterialMngInternal.h

+6-4
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-
/* IMeshMaterialMngInternal.h (C) 2000-2023 */
8+
/* IMeshMaterialMngInternal.h (C) 2000-2024 */
99
/* */
1010
/* API interne Arcane de 'IMeshMaterialMng'. */
1111
/*---------------------------------------------------------------------------*/
@@ -22,6 +22,7 @@
2222

2323
namespace Arcane::Materials
2424
{
25+
class ComponentItemSharedInfo;
2526

2627
/*---------------------------------------------------------------------------*/
2728
/*---------------------------------------------------------------------------*/
@@ -83,15 +84,13 @@ class ARCANE_CORE_EXPORT IMeshMaterialMngInternal
8384
public:
8485

8586
/*!
86-
* \internal
8787
* \brief Renvoie la table de "connectivité" CellLocalId -> AllEnvCell
8888
* destinée à être utilisée dans un RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL
8989
* en conjonction de la macro ENUMERATE_CELL_ALLENVCELL
9090
*/
9191
virtual AllCellToAllEnvCell* getAllCellToAllEnvCell() const = 0;
9292

9393
/*!
94-
* \internal
9594
* \brief Construit la table de "connectivité" CellLocalId -> AllEnvCell
9695
* destinée à être utilisée dans un RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL
9796
* en conjonction de la macro ENUMERATE_CELL_ALLENVCELL
@@ -100,6 +99,9 @@ class ARCANE_CORE_EXPORT IMeshMaterialMngInternal
10099
* platform::getDefaultDataAllocator() est utilisée
101100
*/
102101
virtual void createAllCellToAllEnvCell(IMemoryAllocator* alloc) = 0;
102+
103+
//! Instance générique de ComponentItemSharedInfo
104+
virtual ComponentItemSharedInfo* componentItemSharedInfo() const =0;
103105
};
104106

105107
/*---------------------------------------------------------------------------*/

Diff for: arcane/src/arcane/materials/AllEnvData.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ _computeInfosForEnvCells()
254254

255255
ConstArrayView<MatVarIndex> matvar_indexes = var_indexer->matvarIndexes();
256256

257-
ArrayView<ComponentItemInternal*> env_items_internal_pointer = env->itemsInternalView();
258257
Int32ConstArrayView local_ids = var_indexer->localIds();
259258

260259
for (Integer z = 0, nb_id = matvar_indexes.size(); z < nb_id; ++z) {
@@ -265,8 +264,9 @@ _computeInfosForEnvCells()
265264
++current_pos[lid];
266265
Int32 nb_mat = m_component_connectivity_list->cellNbMaterial(CellLocalId(lid), env_id);
267266
ComponentItemInternal& ref_ii = env_items_internal[pos];
268-
env_items_internal_pointer[z] = &env_items_internal[pos];
269-
ref_ii._setSuperAndGlobalItem(all_env_items_internal_range[lid], ItemLocalId(lid));
267+
ComponentItemInternalLocalId cii_lid = all_env_items_internal_range[lid];
268+
env->setConstituentItem(z, ref_ii._internalLocalId());
269+
ref_ii._setSuperAndGlobalItem(cii_lid, ItemLocalId(lid));
270270
ref_ii._setNbSubItem(nb_mat);
271271
ref_ii._setVariableIndex(mvi);
272272
ref_ii._setComponent(env_id);
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2+
//-----------------------------------------------------------------------------
3+
// Copyright 2000-2024 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+
/* ConstituentItemLocalIdList.cc (C) 2000-2024 */
9+
/* */
10+
/* Gestion des listes d'identifiants locaux de 'ComponentItemInternal'. */
11+
/*---------------------------------------------------------------------------*/
12+
/*---------------------------------------------------------------------------*/
13+
14+
#include "arcane/materials/internal/ConstituentItemLocalIdList.h"
15+
16+
#include "arcane/utils/MemoryUtils.h"
17+
18+
#include "arcane/materials/internal/MeshMaterialMng.h"
19+
20+
/*---------------------------------------------------------------------------*/
21+
/*---------------------------------------------------------------------------*/
22+
23+
namespace Arcane::Materials
24+
{
25+
26+
/*---------------------------------------------------------------------------*/
27+
/*---------------------------------------------------------------------------*/
28+
29+
ConstituentItemLocalIdList::
30+
ConstituentItemLocalIdList(ComponentItemSharedInfo* shared_info)
31+
: m_item_internal_local_id_list(MemoryUtils::getAllocatorForMostlyReadOnlyData())
32+
, m_shared_info(shared_info)
33+
{
34+
}
35+
36+
/*---------------------------------------------------------------------------*/
37+
/*---------------------------------------------------------------------------*/
38+
39+
/*---------------------------------------------------------------------------*/
40+
/*---------------------------------------------------------------------------*/
41+
42+
void ConstituentItemLocalIdList::
43+
resize(Int32 new_size)
44+
{
45+
m_items_internal.resize(new_size);
46+
m_item_internal_local_id_list.resize(new_size);
47+
}
48+
49+
/*---------------------------------------------------------------------------*/
50+
/*---------------------------------------------------------------------------*/
51+
52+
} // End namespace Arcane::Materials
53+
54+
/*---------------------------------------------------------------------------*/
55+
/*---------------------------------------------------------------------------*/

Diff for: arcane/src/arcane/materials/MeshComponentData.cc

+28-19
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ namespace Arcane::Materials
3232
/*---------------------------------------------------------------------------*/
3333

3434
MeshComponentData::
35-
MeshComponentData(IMeshComponent* component,const String& name,
36-
Int16 component_id,bool create_indexer)
35+
MeshComponentData(IMeshComponent* component, const String& name,
36+
Int16 component_id, ComponentItemSharedInfo* shared_info,
37+
bool create_indexer)
3738
: TraceAccessor(component->traceMng())
3839
, m_component(component)
3940
, m_component_id(component_id)
4041
, m_name(name)
41-
, m_is_indexer_owner(false)
42-
, m_variable_indexer(nullptr)
43-
, m_part_data(nullptr)
42+
, m_constituent_local_id_list(shared_info)
4443
{
45-
if (create_indexer){
46-
m_variable_indexer = new MeshMaterialVariableIndexer(traceMng(),name);
44+
if (create_indexer) {
45+
m_variable_indexer = new MeshMaterialVariableIndexer(traceMng(), name);
4746
m_is_indexer_owner = true;
4847
}
4948
}
@@ -66,11 +65,20 @@ MeshComponentData::
6665
/*---------------------------------------------------------------------------*/
6766

6867
void MeshComponentData::
69-
_resizeItemsInternal(Integer nb_item)
68+
_setPartInfo()
7069
{
71-
m_items_internal.resize(nb_item);
7270
if (m_part_data)
73-
m_part_data->_setComponentItemInternalView(m_items_internal);
71+
m_part_data->_setComponentItemInternalView(_itemsInternalView());
72+
}
73+
74+
/*---------------------------------------------------------------------------*/
75+
/*---------------------------------------------------------------------------*/
76+
77+
void MeshComponentData::
78+
_resizeItemsInternal(Integer nb_item)
79+
{
80+
m_constituent_local_id_list.resize(nb_item);
81+
_setPartInfo();
7482
}
7583

7684
/*---------------------------------------------------------------------------*/
@@ -101,7 +109,7 @@ void MeshComponentData::
101109
_buildPartData()
102110
{
103111
m_part_data = new MeshComponentPartData(m_component);
104-
m_part_data->_setComponentItemInternalView(m_items_internal);
112+
_setPartInfo();
105113
}
106114

107115
/*---------------------------------------------------------------------------*/
@@ -118,24 +126,24 @@ _changeLocalIdsForInternalList(Int32ConstArrayView old_to_new_ids)
118126
{
119127
// TODO: regarder s'il est possible de supprimer le tableau temporaire
120128
// new_internals (c'est à peu près sur que c'est possible).
121-
ConstArrayView<ComponentItemInternal*> current_internals(_itemsInternalView());
122-
UniqueArray<ComponentItemInternal*> new_internals;
129+
ConstArrayView<ComponentItemInternalLocalId> current_internals(m_constituent_local_id_list.localIds());
130+
UniqueArray<ComponentItemInternalLocalId> new_internals;
123131

124132
Int32ConstArrayView local_ids = variableIndexer()->localIds();
125133

126-
for( Integer i=0, nb=current_internals.size(); i<nb; ++i ){
134+
for (Integer i = 0, nb = current_internals.size(); i < nb; ++i) {
127135
Int32 lid = local_ids[i];
128136
Int32 new_lid = old_to_new_ids[lid];
129-
if (new_lid!=NULL_ITEM_LOCAL_ID){
137+
if (new_lid != NULL_ITEM_LOCAL_ID) {
130138
new_internals.add(current_internals[i]);
131-
current_internals[i]->_setGlobalItem(ItemLocalId(new_lid));
139+
m_constituent_local_id_list.itemInternal(i)->_setGlobalItem(ItemLocalId(new_lid));
132140
}
133141
}
134142

135143
// TODO: regarder supprimer cette copie aussi.
136144
{
137145
_resizeItemsInternal(new_internals.size());
138-
_itemsInternalView().copy(new_internals);
146+
m_constituent_local_id_list.copy(new_internals);
139147
}
140148
}
141149

@@ -147,7 +155,7 @@ _rebuildPartData()
147155
{
148156
if (!m_part_data)
149157
_buildPartData();
150-
m_part_data->_setComponentItemInternalView(m_items_internal);
158+
_setPartInfo();
151159
m_part_data->_setFromMatVarIndexes(m_variable_indexer->matvarIndexes());
152160
}
153161

@@ -210,8 +218,9 @@ checkValid()
210218
info(4) << "CheckValid component_name=" << name()
211219
<< " matvar_indexes=" << mat_var_indexes;
212220
info(4) << "Cells=" << m_variable_indexer->cells().view().localIds();
221+
ConstArrayView<ComponentItemInternal*> internal_view = m_constituent_local_id_list.itemsInternalView();
213222
for( Integer i=0; i<nb_val; ++ i){
214-
MatVarIndex component_mvi = m_items_internal[i]->variableIndex();
223+
MatVarIndex component_mvi = internal_view[i]->variableIndex();
215224
MatVarIndex mvi = mat_var_indexes[i];
216225
if (component_mvi!=mvi)
217226
ARCANE_FATAL("Bad 'var_index' environment={3} component='{0}' direct='{1}' i={2}",

0 commit comments

Comments
 (0)