Arcane  4.2.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshMDVariableRef.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* MeshMDVariableRef.h (C) 2000-2026 */
9/* */
10/* Classe gérant une variable multi-dimension sur une entité du maillage. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MESHMDVARIABLEREF_H
13#define ARCANE_CORE_MESHMDVARIABLEREF_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayLayout.h"
18#include "arcane/utils/ArrayShape.h"
19#include "arcane/utils/MDSpan.h"
20
21#include "arcane/core/DataView.h"
22
23#include "arcane/core/MeshVariableArrayRef.h"
24#include "arcane/core/datatype/DataTypeTraits.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::Impl
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35template <typename ItemType, typename DataType>
36class MeshMDVariableRefWrapperT
37: public MeshVariableArrayRefT<ItemType, DataType>
38{
39 template <typename _ItemType, typename _DataType, typename _Extents>
41
42 public:
43
45 using VariableType = typename BaseClass::PrivatePartType;
46 using ValueDataType = typename VariableType::ValueDataType;
47
48 private:
49
50 explicit MeshMDVariableRefWrapperT(const VariableBuildInfo& vbi)
51 : BaseClass(vbi)
52 {
53 }
54
55 private:
56
57 ValueDataType* trueData() { return this->m_private_part->trueData(); }
58 const ValueDataType* trueData() const { return this->m_private_part->trueData(); }
59
60 void fillShape(ArrayShape& shape_with_item)
61 {
62 this->m_private_part->fillShape(shape_with_item);
63 }
64};
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
69} // namespace Arcane::Impl
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74namespace Arcane
75{
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
82template <typename ItemType, typename DataType, typename Extents>
83class MeshMDVariableRefBaseT
84: public MeshVariableRef
85{
86 public:
87
88 using UnderlyingVariableType = MeshVariableArrayRefT<ItemType, DataType>;
90 using ItemLocalIdType = typename ItemType::LocalIdType;
91 using FullExtentsType = Extents;
92
93 public:
94
95 explicit MeshMDVariableRefBaseT(const VariableBuildInfo& b)
97 , m_underlying_var(b)
98 {
99 _internalInit(m_underlying_var.variable());
100 }
101
103 const UnderlyingVariableType& underlyingVariable() const { return m_underlying_var; }
104
106 UnderlyingVariableType& underlyingVariable() { return m_underlying_var; }
107
109 ArrayShape fullShape() const { return m_underlying_var.trueData()->shape(); }
110
111 protected:
112
113 void updateFromInternal() override
114 {
115 const Int32 nb_rank = Extents::rank();
116 ArrayShape shape_with_item;
117 shape_with_item.setNbDimension(nb_rank);
118 m_underlying_var.fillShape(shape_with_item);
119
121 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
122 }
123
124 protected:
125
127 MDSpanType m_mdspan;
128};
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
139template <typename ItemType, typename DataType, typename Extents>
140class MeshMDVariableRefT
141: public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
142{
143 // To access m_mdspan
144 friend class Arcane::Accelerator::MeshMDVariableInView<ItemType, DataType, Extents>;
145 friend class Arcane::Accelerator::MeshMDVariableInOutView<ItemType, DataType, Extents>;
146
147 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
148 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
149 static_assert(Extents::rank() >= 0 && Extents::rank() <= 3, "Only Extents of rank 0, 1, 2 or 3 are implemented");
150 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
151
152 public:
153
154 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
155 using ItemLocalIdType = typename ItemType::LocalIdType;
156 static constexpr int nb_dynamic = Extents::nb_dynamic;
157
158 public:
159
160 explicit MeshMDVariableRefT(const VariableBuildInfo& b)
161 : BaseClass(b)
162 {}
163
164 public:
165
166 DataType& operator()(ItemLocalIdType id) requires(Extents::rank() == 0)
167 {
168 return this->m_mdspan(id.localId());
169 }
170
171 const DataType& operator()(ItemLocalIdType id) const requires(Extents::rank() == 0)
172 {
173 return this->m_mdspan(id.localId());
174 }
175
176 DataType& operator()(ItemLocalIdType id, Int32 i1) requires(Extents::rank() == 1)
177 {
178 return this->m_mdspan(id.localId(), i1);
179 }
180
181 const DataType& operator()(ItemLocalIdType id, Int32 i1) const requires(Extents::rank() == 1)
182 {
183 return this->m_mdspan(id.localId(), i1);
184 }
185
186 DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
187 requires(Extents::rank() == 2)
188 {
189 return this->m_mdspan(id.localId(), i1, i2);
190 }
191
192 const DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
193 requires(Extents::rank() == 2)
194 {
195 return this->m_mdspan(id.localId(), i1, i2);
196 }
197
198 DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k)
199 requires(Extents::rank() == 3)
200 {
201 return this->m_mdspan(id.localId(), i, j, k);
202 }
203
204 const DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k) const
205 requires(Extents::rank() == 3)
206 {
207 return this->m_mdspan(id.localId(), i, j, k);
208 }
209
216 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
217 {
218 ArrayShape shape(dims);
219 this->m_underlying_var.resizeAndReshape(shape);
220 }
221};
222
223/*---------------------------------------------------------------------------*/
224/*---------------------------------------------------------------------------*/
225
226} // namespace Arcane
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231#endif
Vue en lecture/écriture de variable multidimensionnelle sur un élément de maillage.
Vue en lecture seule de variable multidimensionnelle sur un élément de maillage.
__host__ static __device__ ArrayExtentsBase fromSpan(SmallSpan< const ExtentIndexType > extents)
Construit une instance à partir des valeurs données dans extents.
Forme d'un tableau.
Definition ArrayShape.h:40
void setNbDimension(Int32 nb_value)
Positionne le rang de la forme.
Definition ArrayShape.cc:39
SmallSpan< const Int32 > dimensions() const
Valeurs de chaque dimension.
Definition ArrayShape.h:54
Classe de base des vues multi-dimensionnelles.
Classe de base gérant une variable multi-dimension sur une entité du maillage.
const UnderlyingVariableType & underlyingVariable() const
Variable sous-jacente associée.
UnderlyingVariableType & underlyingVariable()
Variable sous-jacente associée.
void updateFromInternal() override
Mise à jour à partir de la partie interne.
ArrayShape fullShape() const
Forme complète (statique + dynamique) de la variable.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Change la forme de la donnée.
Variable tableau sur un type d'entité du maillage.
MeshVariableRef(const VariableBuildInfo &vb)
Construit une référence liée au module module.
Paramètres nécessaires à la construction d'une variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Type entier signé sur 32 bits.