Skip to content

Commit 0d02919

Browse files
[arcane,materials] Conserve le 'MatVarIndex' dans 'ComponentItemSharedInfo'.
1 parent 04be222 commit 0d02919

File tree

5 files changed

+59
-37
lines changed

5 files changed

+59
-37
lines changed

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class ARCANE_CORE_EXPORT ComponentItemInternalLocalId
5757
return a.m_id != b.m_id;
5858
}
5959
ARCANE_CORE_EXPORT friend std::ostream&
60-
operator<<(std::ostream& o,const ComponentItemInternalLocalId& id);
60+
operator<<(std::ostream& o, const ComponentItemInternalLocalId& id);
61+
62+
ARCCORE_HOST_DEVICE constexpr bool isNull() const { return m_id == (-1); }
6163

6264
private:
6365

@@ -96,6 +98,8 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfoStorageView
9698
Int32* m_global_item_local_id_data = nullptr;
9799
//! Id de l'entité sous-constituant parente
98100
ComponentItemInternalLocalId* m_super_component_item_local_id_data = nullptr;
101+
//! MatVarIndex de l'entité
102+
MatVarIndex* m_var_index_data = nullptr;
99103
};
100104

101105
/*---------------------------------------------------------------------------*/
@@ -120,6 +124,8 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
120124
friend class ConstituentItemLocalIdListView;
121125
friend class matimpl::ConstituentItemBase;
122126

127+
static const int MAT_INDEX_OFFSET = 10;
128+
123129
private:
124130

125131
//! Pour l'entité nulle
@@ -184,11 +190,31 @@ class ARCANE_CORE_EXPORT ComponentItemSharedInfo
184190
m_super_component_item_local_id_data[id.localId()] = super_id;
185191
}
186192

193+
ARCCORE_HOST_DEVICE MatVarIndex _varIndex(ComponentItemInternalLocalId id)
194+
{
195+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
196+
return m_var_index_data[id.localId()];
197+
}
198+
ARCCORE_HOST_DEVICE void _setVarIndex(ComponentItemInternalLocalId id, MatVarIndex mv_index)
199+
{
200+
ARCCORE_CHECK_RANGE(id.localId(), -1, m_storage_size);
201+
m_var_index_data[id.localId()] = mv_index;
202+
}
203+
204+
//! Numéro unique de l'entité component
205+
Int64 _componentUniqueId(ComponentItemInternalLocalId id) const
206+
{
207+
// TODO: Vérifier que arrayIndex() ne dépasse pas (1<<MAT_INDEX_OFFSET)
208+
impl::ItemBase item_base(_globalItemBase(id));
209+
return (Int64)m_var_index_data[id.localId()].arrayIndex() + ((Int64)item_base.uniqueId() << MAT_INDEX_OFFSET);
210+
}
211+
187212
inline void _reset(ComponentItemInternalLocalId id)
188213
{
189214
Int32 local_id = id.localId();
190215
ARCCORE_CHECK_RANGE(local_id, -1, m_storage_size);
191216

217+
m_var_index_data[local_id].reset();
192218
m_first_sub_constituent_item_id_data[local_id] = {};
193219
m_nb_sub_constituent_item_data[local_id] = 0;
194220
m_component_id_data[local_id] = -1;
@@ -248,7 +274,7 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
248274
public:
249275

250276
//! Indexeur dans les variables matériaux
251-
inline ARCCORE_HOST_DEVICE constexpr MatVarIndex variableIndex() const;
277+
inline ARCCORE_HOST_DEVICE MatVarIndex variableIndex() const;
252278

253279
//! Identifiant du composant
254280
inline ARCCORE_HOST_DEVICE Int32 componentId() const;
@@ -327,8 +353,8 @@ class ARCANE_CORE_EXPORT ConstituentItemBase
327353

328354
private:
329355

330-
inline ComponentItemSharedInfo* _sharedInfo() const;
331-
inline ComponentItemInternalLocalId _localId() const;
356+
inline ARCCORE_HOST_DEVICE ComponentItemSharedInfo* _sharedInfo() const;
357+
inline ARCCORE_HOST_DEVICE ComponentItemInternalLocalId _localId() const;
332358
};
333359

334360
/*---------------------------------------------------------------------------*/
@@ -376,31 +402,26 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
376402

377403
private:
378404

379-
static const int MAT_INDEX_OFFSET = 10;
380-
381405
//! Entité nulle
382406
static ComponentItemInternal nullComponentItemInternal;
383407

384408
public:
385409

386-
ComponentItemInternal()
387-
{
388-
m_var_index.reset();
389-
}
410+
ComponentItemInternal() = default;
390411

391412
public:
392413

393414
//! Indexeur dans les variables matériaux
394-
ARCCORE_HOST_DEVICE constexpr MatVarIndex variableIndex() const
415+
ARCCORE_HOST_DEVICE MatVarIndex variableIndex() const
395416
{
396-
return m_var_index;
417+
return m_shared_info->_varIndex(m_component_item_internal_local_id);
397418
}
398419

399420
//! Identifiant du composant
400421
ARCCORE_HOST_DEVICE Int32 componentId() const { return m_shared_info->_componentId(m_component_item_internal_local_id); }
401422

402423
//! Indique s'il s'agit de la maille nulle.
403-
ARCCORE_HOST_DEVICE constexpr bool null() const { return m_var_index.null(); }
424+
ARCCORE_HOST_DEVICE constexpr bool null() const { return m_component_item_internal_local_id.isNull(); }
404425

405426
/*!
406427
* \brief Composant associé.
@@ -427,17 +448,15 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
427448
//! Numéro unique de l'entité component
428449
Int64 componentUniqueId() const
429450
{
430-
// TODO: Vérifier que arrayIndex() ne dépasse pas (1<<MAT_INDEX_OFFSET)
431-
impl::ItemBase item_base(globalItemBase());
432-
return (Int64)m_var_index.arrayIndex() + ((Int64)item_base.uniqueId() << MAT_INDEX_OFFSET);
451+
return m_shared_info->_componentUniqueId(m_component_item_internal_local_id);
433452
}
434453

435454
protected:
436455

437456
// NOTE : Cette classe est partagée avec le wrapper C#
438457
// Toute modification de la structure interne doit être reportée
439458
// dans la structure C# correspondante
440-
MatVarIndex m_var_index;
459+
//MatVarIndex m_var_index;
441460
ComponentItemInternalLocalId m_component_item_internal_local_id;
442461
ComponentItemSharedInfo* m_shared_info = nullptr;
443462

@@ -469,8 +488,6 @@ class ARCANE_CORE_EXPORT ComponentItemInternal
469488
{
470489
m_component_item_internal_local_id = id;
471490
m_shared_info = shared_info;
472-
473-
m_var_index.reset();
474491
m_shared_info->_reset(id);
475492
}
476493
};
@@ -541,10 +558,10 @@ _superItemBase() const
541558
/*---------------------------------------------------------------------------*/
542559
/*---------------------------------------------------------------------------*/
543560

544-
inline ARCCORE_HOST_DEVICE constexpr MatVarIndex matimpl::ConstituentItemBase::
561+
inline ARCCORE_HOST_DEVICE MatVarIndex matimpl::ConstituentItemBase::
545562
variableIndex() const
546563
{
547-
return m_component_item->variableIndex();
564+
return _sharedInfo()->_varIndex(_localId());
548565
}
549566

550567
inline ARCCORE_HOST_DEVICE Int32 matimpl::ConstituentItemBase::
@@ -592,7 +609,7 @@ componentUniqueId() const
592609
inline void matimpl::ConstituentItemBase::
593610
_setVariableIndex(MatVarIndex index)
594611
{
595-
m_component_item->m_var_index = index;
612+
_sharedInfo()->_setVarIndex(_localId(), index);
596613
}
597614

598615
inline matimpl::ConstituentItemBase matimpl::ConstituentItemBase::

arcane/src/arcane/materials/ComponentItemInternalData.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Storage(const MemoryAllocationOptions& alloc_info)
3636
, m_component_id_list(alloc_info)
3737
, m_nb_sub_constituent_item_list(alloc_info)
3838
, m_global_item_local_id_list(alloc_info)
39+
, m_var_index_list(alloc_info)
3940
{
4041
}
4142

@@ -64,12 +65,16 @@ resize(Int32 new_size, ComponentItemSharedInfo* shared_info)
6465
m_global_item_local_id_list.resize(true_size);
6566
m_global_item_local_id_list[0] = NULL_ITEM_LOCAL_ID;
6667

68+
m_var_index_list.resize(true_size);
69+
m_var_index_list[0].reset();
70+
6771
shared_info->m_storage_size = new_size;
6872
shared_info->m_first_sub_constituent_item_id_data = m_first_sub_constituent_item_id_list.data() + 1;
6973
shared_info->m_super_component_item_local_id_data = m_super_component_item_local_id_list.data() + 1;
7074
shared_info->m_component_id_data = m_component_id_list.data() + 1;
7175
shared_info->m_nb_sub_constituent_item_data = m_nb_sub_constituent_item_list.data() + 1;
7276
shared_info->m_global_item_local_id_data = m_global_item_local_id_list.data() + 1;
77+
shared_info->m_var_index_data = m_var_index_list.data() + 1;
7378
}
7479

7580
/*---------------------------------------------------------------------------*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class ComponentItemInternalData
132132
UniqueArray<Int16> m_component_id_list;
133133
UniqueArray<Int16> m_nb_sub_constituent_item_list;
134134
UniqueArray<Int32> m_global_item_local_id_list;
135+
UniqueArray<MatVarIndex> m_var_index_list;
135136
};
136137

137138
public:

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public ComponentItemInternal* Internal
2323
}
2424

2525
public Cell GlobalCell { get { return m_internal->m_shared_info->GlobalCell(m_internal->m_component_item_internal_local_id); } }
26-
public MatVarIndex MatVarIndex { get { return m_internal->m_var_index; } }
27-
internal int _matvarArrayIndex { get { return m_internal->m_var_index.ArrayIndex; } }
28-
internal int _matvarValueIndex { get { return m_internal->m_var_index.ValueIndex; } }
26+
public MatVarIndex MatVarIndex { get { return m_internal->m_shared_info->VarIndex(m_internal->m_component_item_internal_local_id); } }
27+
internal int _matvarArrayIndex { get { return MatVarIndex.ArrayIndex; } }
28+
internal int _matvarValueIndex { get { return MatVarIndex.ValueIndex; } }
2929

3030
[Obsolete("This method is internal to Arcane")]
3131
public ComponentItem(ComponentItemInternal* ci)
@@ -46,9 +46,9 @@ public ComponentItemInternal* Internal
4646
set { m_internal = value; }
4747
}
4848
public Cell GlobalCell { get { return m_internal->m_shared_info->GlobalCell(m_internal->m_component_item_internal_local_id); } }
49-
public MatVarIndex MatVarIndex { get { return m_internal->m_var_index; } }
50-
internal int _matvarArrayIndex { get { return m_internal->m_var_index.ArrayIndex; } }
51-
internal int _matvarValueIndex { get { return m_internal->m_var_index.ValueIndex; } }
49+
public MatVarIndex MatVarIndex { get { return m_internal->m_shared_info->VarIndex(m_internal->m_component_item_internal_local_id); } }
50+
internal int _matvarArrayIndex { get { return MatVarIndex.ArrayIndex; } }
51+
internal int _matvarValueIndex { get { return MatVarIndex.ValueIndex; } }
5252
[Obsolete("This method is internal to Arcane")]
5353
public MatItem(ComponentItemInternal* ci)
5454
{
@@ -67,9 +67,9 @@ public ComponentItemInternal* Internal
6767
}
6868

6969
public Cell GlobalCell { get { return m_internal->m_shared_info->GlobalCell(m_internal->m_component_item_internal_local_id); } }
70-
public MatVarIndex MatVarIndex { get { return m_internal->m_var_index; } }
71-
internal int _matvarArrayIndex { get { return m_internal->m_var_index.ArrayIndex; } }
72-
internal int _matvarValueIndex { get { return m_internal->m_var_index.ValueIndex; } }
70+
public MatVarIndex MatVarIndex { get { return m_internal->m_shared_info->VarIndex(m_internal->m_component_item_internal_local_id); } }
71+
internal int _matvarArrayIndex { get { return MatVarIndex.ArrayIndex; } }
72+
internal int _matvarValueIndex { get { return MatVarIndex.ValueIndex; } }
7373

7474
[Obsolete("This method is internal to Arcane")]
7575
public EnvItem(ComponentItemInternal* ci)

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public unsafe struct ComponentItemSharedInfo
1313
Int16* m_nb_sub_constituent_item_data;
1414
Int32* m_global_item_local_id_data;
1515
Int32* m_super_component_item_local_id_data;
16+
MatVarIndex* m_var_index_data;
1617

1718
// Structure de la classe C++ ComponentItemSharedInfo
1819
internal ItemSharedInfo* m_item_shared_info;
@@ -27,18 +28,16 @@ internal Cell GlobalCell(Int32 constituent_local_id)
2728
Int32 global_local_id = m_global_item_local_id_data[constituent_local_id];
2829
return new Cell(m_item_shared_info->m_items_internal[global_local_id]);
2930
}
31+
internal MatVarIndex VarIndex(Int32 constituent_local_id)
32+
{
33+
return m_var_index_data[constituent_local_id];
34+
}
3035
}
3136

3237
[StructLayout(LayoutKind.Sequential)]
3338
public unsafe struct ComponentItemInternal
3439
{
35-
internal MatVarIndex m_var_index;
36-
//internal Int16 m_component_id;
37-
//internal Int16 m_nb_sub_component_item;
38-
//internal Int32 m_global_item_local_id;
3940
internal Int32 m_component_item_internal_local_id;
40-
//internal Int32 m_super_component_item_local_id;
41-
//internal Int32 m_first_sub_component_item_local_id;
4241
internal ComponentItemSharedInfo* m_shared_info;
4342
}
4443

0 commit comments

Comments
 (0)