Skip to content

Commit 6427ec3

Browse files
[arcane,materials] Utilise 'ComponentItemInternalLocalId' pour conserver l'index du premier élément enfant d'un constituant.
1 parent 8a022e4 commit 6427ec3

File tree

6 files changed

+47
-31
lines changed

6 files changed

+47
-31
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class ARCANE_CORE_EXPORT ComponentItemInternalLocalId
3535
public:
3636

3737
ComponentItemInternalLocalId() = default;
38-
explicit ComponentItemInternalLocalId(Int32 id)
38+
explicit ARCCORE_HOST_DEVICE ComponentItemInternalLocalId(Int32 id)
3939
: m_id(id)
4040
{}
41-
Int32 localId() const { return m_id; }
41+
ARCCORE_HOST_DEVICE Int32 localId() const { return m_id; }
4242

4343
private:
4444

@@ -52,6 +52,7 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
5252
{
5353
friend class ComponentItemInternal;
5454
friend class ComponentItemInternalData;
55+
friend class CellComponentCellEnumerator;
5556

5657
private:
5758

@@ -211,7 +212,7 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
211212
Int32 m_global_item_local_id = NULL_ITEM_LOCAL_ID;
212213
ComponentItemInternalLocalId m_component_item_internal_local_id;
213214
ComponentItemInternalLocalId m_super_component_item_local_id;
214-
ComponentItemInternal* m_first_sub_component_item = nullptr;
215+
ComponentItemInternalLocalId m_first_sub_component_item_local_id;
215216
ComponentItemSharedInfo* m_shared_info = nullptr;
216217

217218
private:
@@ -256,9 +257,14 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
256257
}
257258

258259
//! Première entité sous-composant.
259-
ARCCORE_HOST_DEVICE ComponentItemInternal* _firstSubItem() const
260+
ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _firstSubItemLocalId() const
261+
{
262+
return m_first_sub_component_item_local_id;
263+
}
264+
265+
ARCCORE_HOST_DEVICE ComponentItemInternal* _subItem(Int32 i) const
260266
{
261-
return m_first_sub_component_item;
267+
return &m_shared_info->m_component_item_internal_view[m_first_sub_component_item_local_id.localId() + i];
262268
}
263269

264270
//! Positionne le nombre de sous-composants.
@@ -273,7 +279,8 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
273279
//! Positionne le premier sous-composant.
274280
void _setFirstSubItem(ComponentItemInternal* first_sub_item)
275281
{
276-
m_first_sub_component_item = first_sub_item;
282+
if (first_sub_item)
283+
m_first_sub_component_item_local_id = first_sub_item->_internalLocalId();
277284
}
278285

279286
void _setComponent(Int32 component_id)
@@ -296,7 +303,7 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
296303
m_super_component_item_local_id = {};
297304
m_component_item_internal_local_id = id;
298305
m_nb_sub_component_item = 0;
299-
m_first_sub_component_item = nullptr;
306+
m_first_sub_component_item_local_id = {};
300307
m_global_item_local_id = NULL_ITEM_LOCAL_ID;
301308
m_shared_info = shared_info;
302309
}

arcane/src/arcane/core/materials/MatItem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class EnvCell
155155
//! i-ème maille matériau de cette maille
156156
inline MatCell cell(Integer i)
157157
{
158-
return matimpl::ConstituentItemBase(m_internal->_firstSubItem() + i);
158+
return matimpl::ConstituentItemBase(m_internal->_subItem(i));
159159
}
160160

161161
//! Milieu associé
@@ -225,7 +225,7 @@ class AllEnvCell
225225
//! i-ème maille milieu
226226
EnvCell cell(Int32 i) const
227227
{
228-
return EnvCell(matimpl::ConstituentItemBase(m_internal->_firstSubItem() + i));
228+
return EnvCell(matimpl::ConstituentItemBase(m_internal->_subItem(i)));
229229
}
230230
};
231231

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

Lines changed: 21 additions & 11 deletions
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-
/* MatItemEnumerator.h (C) 2000-2023 */
8+
/* MatItemEnumerator.h (C) 2000-2024 */
99
/* */
1010
/* Enumérateurs sur les mailles materiaux. */
1111
/*---------------------------------------------------------------------------*/
@@ -341,7 +341,7 @@ class ARCANE_CORE_EXPORT EnvPartCellEnumerator
341341
/*---------------------------------------------------------------------------*/
342342
/*---------------------------------------------------------------------------*/
343343
/*!
344-
* \brief Enumérateur sur les matériaux d'une maille.
344+
* \brief Enumérateur sur les constituants d'une maille.
345345
*/
346346
class ARCANE_CORE_EXPORT CellComponentCellEnumerator
347347
{
@@ -350,7 +350,9 @@ class ARCANE_CORE_EXPORT CellComponentCellEnumerator
350350
public:
351351

352352
ARCCORE_HOST_DEVICE explicit CellComponentCellEnumerator(ComponentCell super_item)
353-
: m_index(0), m_size(super_item._internal()->nbSubItem()), m_items_begin(super_item._internal()->_firstSubItem())
353+
: m_size(super_item._internal()->nbSubItem())
354+
, m_items_begin(super_item._internal()->_firstSubItemLocalId().localId())
355+
, m_item_internal_list(super_item._internal()->m_shared_info->m_component_item_internal_view)
354356
{
355357
}
356358

@@ -362,20 +364,28 @@ class ARCANE_CORE_EXPORT CellComponentCellEnumerator
362364
ARCCORE_HOST_DEVICE ComponentCell operator*() const
363365
{
364366
ARCANE_CHECK_AT(m_index,m_size);
365-
return ComponentCell(matimpl::ConstituentItemBase(m_items_begin+m_index));
367+
return ComponentCell(_currentItemBase());
366368
}
367-
ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const { return m_items_begin[m_index].variableIndex(); }
369+
ARCCORE_HOST_DEVICE MatVarIndex _varIndex() const { return m_item_internal_list[m_items_begin+m_index].variableIndex(); }
368370
ARCCORE_HOST_DEVICE Integer index() const { return m_index; }
369371
ARCCORE_HOST_DEVICE operator ComponentItemLocalId() const
370372
{
371-
return ComponentItemLocalId(m_items_begin[m_index].variableIndex());
373+
return ComponentItemLocalId(_varIndex());
372374
}
373375

374376
protected:
375377

376-
Integer m_index;
377-
Integer m_size;
378-
ComponentItemInternal* m_items_begin;
378+
Int32 m_index = 0;
379+
Int32 m_size = 0;
380+
Int32 m_items_begin = -1;
381+
ArrayView<ComponentItemInternal> m_item_internal_list;
382+
383+
protected:
384+
385+
ARCCORE_HOST_DEVICE matimpl::ConstituentItemBase _currentItemBase() const
386+
{
387+
return matimpl::ConstituentItemBase(const_cast<ComponentItemInternal*>(m_item_internal_list.ptrAt(m_items_begin+m_index)));
388+
}
379389
};
380390

381391
/*---------------------------------------------------------------------------*/
@@ -396,7 +406,7 @@ template <typename ComponentCellType> class CellComponentCellEnumeratorT
396406
ARCCORE_HOST_DEVICE ComponentCellType operator*() const
397407
{
398408
ARCANE_CHECK_AT(m_index,m_size);
399-
return ComponentCellType(matimpl::ConstituentItemBase(m_items_begin+m_index));
409+
return ComponentCellType(_currentItemBase());
400410
}
401411
};
402412

arcane/src/arcane/materials/ComponentItemInternalData.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ _resetItemsInternal()
7474
for (ComponentItemInternalLocalId id : m_env_items_internal_range)
7575
storage[id.localId()]._reset(id, env_shared_info);
7676

77-
for (const MeshEnvironment* env : m_material_mng->trueEnvironments()) {
78-
ArrayView<ComponentItemInternal> mat_items_internal = matItemsInternal(env->id());
79-
ComponentItemSharedInfo* mat_shared_info = matSharedInfo();
80-
for (ComponentItemInternal& x : mat_items_internal) {
81-
x._reset(internal_local_id, mat_shared_info);
82-
}
77+
ComponentItemSharedInfo* mat_shared_info = matSharedInfo();
78+
for (ComponentItemInternalRange mat_range : m_mat_items_internal_range) {
79+
for (ComponentItemInternalLocalId id : mat_range)
80+
storage[id.localId()]._reset(id, mat_shared_info);
8381
}
8482
}
8583

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class ComponentItemInternalRange
3838
{
3939
public:
4040

41-
class Sentinel{};
41+
class Sentinel
42+
{};
4243
class Iterator
4344
{
4445
friend ComponentItemInternalRange;
@@ -197,10 +198,10 @@ class ComponentItemInternalData
197198
void _resetMatItemsInternal(Int32 env_index);
198199
//! Réinitialise les ComponentItemInternal associés aux EnvCell et AllEnvCell
199200
void _resetItemsInternal();
200-
};
201+
};
201202

202-
/*---------------------------------------------------------------------------*/
203-
/*---------------------------------------------------------------------------*/
203+
/*---------------------------------------------------------------------------*/
204+
/*---------------------------------------------------------------------------*/
204205

205206
} // namespace Arcane::Materials
206207

arcane/tools/wrapper/materials/csharp/ComponentItemInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public unsafe struct ComponentItemInternal
2222
internal Int32 m_global_item_local_id;
2323
internal Int32 m_component_item_internal_local_id;
2424
internal Int32 m_super_component_item_local_id;
25-
internal ComponentItemInternal* m_first_sub_component_item;
25+
internal Int32 m_first_sub_component_item_local_id;
2626
internal ComponentItemSharedInfo* m_shared_info;
2727
}
2828

0 commit comments

Comments
 (0)