Arcane  v4.1.1.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MeshMDVariableRef.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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-2025 */
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
29/*
30 * ATTENTION:
31 *
32 * Toutes les classes de ce fichier sont expérimentales et l'API n'est pas
33 * figée. A NE PAS UTILISER EN DEHORS DE ARCANE.
34 */
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Arcane::impl
40{
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45template <typename ItemType, typename DataType>
46class MeshMDVariableRefWrapperT
47: public MeshVariableArrayRefT<ItemType, DataType>
48{
49 template <typename _ItemType, typename _DataType, typename _Extents>
51
52 public:
53
55 using VariableType = typename BaseClass::PrivatePartType;
56 using ValueDataType = typename VariableType::ValueDataType;
57
58 private:
59
60 explicit MeshMDVariableRefWrapperT(const VariableBuildInfo& vbi)
61 : BaseClass(vbi)
62 {
63 }
64
65 private:
66
67 ValueDataType* trueData() { return this->m_private_part->trueData(); }
68 const ValueDataType* trueData() const { return this->m_private_part->trueData(); }
69
70 void fillShape(ArrayShape& shape_with_item)
71 {
72 this->m_private_part->fillShape(shape_with_item);
73 }
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79} // namespace Arcane::impl
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
84namespace Arcane
85{
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89/*!
90 * \brief Classe de base gérant une variable multi-dimension sur une entité du maillage.
91 *
92 * \warning API en cours de définition. Ne pas utiliser en dehors de Arcane.
93 */
94template <typename ItemType, typename DataType, typename Extents>
95class MeshMDVariableRefBaseT
96: public MeshVariableRef
97{
98 public:
99
100 using UnderlyingVariableType = MeshVariableArrayRefT<ItemType, DataType>;
102 using ItemLocalIdType = typename ItemType::LocalIdType;
103 using FullExtentsType = Extents;
104
105 public:
106
107 explicit MeshMDVariableRefBaseT(const VariableBuildInfo& b)
109 , m_underlying_var(b)
110 {
111 _internalInit(m_underlying_var.variable());
112 }
113
114 //! Variable sous-jacente associée.
115 UnderlyingVariableType& underlyingVariable() { return m_underlying_var; }
116
117 //! Forme complète (statique + dynamique) de la variable.
118 ArrayShape fullShape() const { return m_underlying_var.trueData()->shape(); }
119
120 protected:
121
122 void updateFromInternal() override
123 {
124 const Int32 nb_rank = Extents::rank();
125 ArrayShape shape_with_item;
126 shape_with_item.setNbDimension(nb_rank);
127 m_underlying_var.fillShape(shape_with_item);
128
130 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
131 }
132
133 protected:
134
136 MDSpanType m_mdspan;
137};
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141/*!
142 * \brief Classe gérant une variable multi-dimension sur une entité du maillage.
143 *
144 * \warning API en cours de définition. Ne pas utiliser en dehors de Arcane.
145 */
146template <typename ItemType, typename DataType, typename Extents>
147class MeshMDVariableRefT
148: public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
149{
150 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
151 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
152 static_assert(Extents::rank() >= 0 && Extents::rank() <= 3, "Only Extents of rank 0, 1, 2 or 3 are implemented");
153 static_assert(std::is_same_v<DataType,BasicType>,"DataType should be a basic type (Real, Int32, Int64, ... )");
154
155 public:
156
157 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
158 using ItemLocalIdType = typename ItemType::LocalIdType;
159 static constexpr int nb_dynamic = Extents::nb_dynamic;
160
161 public:
162
163 explicit MeshMDVariableRefT(const VariableBuildInfo& b)
164 : BaseClass(b)
165 {}
166
167 public:
168
169 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
170 DataType& operator()(ItemLocalIdType id)
171 {
172 return this->m_mdspan(id.localId());
173 }
174
175 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
176 const DataType& operator()(ItemLocalIdType id) const
177 {
178 return this->m_mdspan(id.localId());
179 }
180
181
182 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
183 DataType& operator()(ItemLocalIdType id, Int32 i1)
184 {
185 return this->m_mdspan(id.localId(), i1);
186 }
187
188 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
189 const DataType& operator()(ItemLocalIdType id, Int32 i1) const
190 {
191 return this->m_mdspan(id.localId(), i1);
192 }
193
194 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 2, void>>
195 DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
196 {
197 return this->m_mdspan(id.localId(), i1, i2);
198 }
199
200 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 2, void>>
201 const DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
202 {
203 return this->m_mdspan(id.localId(), i1, i2);
204 }
205
206 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 3, void>>
207 DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k)
208 {
209 return this->m_mdspan(id.localId(), i, j, k);
210 }
211
212 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 3, void>>
213 const DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k) const
214 {
215 return this->m_mdspan(id.localId(), i, j, k);
216 }
217
218 /*!
219 * \brief Change la forme de la donnée.
220 *
221 * Le nombre d'éléments de \a dims doit correspondre aux nombre de valeurs
222 * dynamiques de \a Extents.
223 */
224 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
225 {
226 ArrayShape shape(dims);
227 this->m_underlying_var.resizeAndReshape(shape);
228 }
229};
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233/*!
234 * \brief Classe gérant une variable multi-dimension de type 'NumVector' sur une entité du maillage.
235 *
236 * \warning API en cours de définition. Ne pas utiliser en dehors de Arcane.
237 */
238template <typename ItemType, typename DataType, int Size, typename Extents>
239class MeshVectorMDVariableRefT
240: public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>>
241{
242 public:
243
244 using NumVectorType = NumVector<DataType, Size>;
245
246 private:
247
248 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
249 using AddedFirstLastExtentsType = typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>;
250 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
251 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastExtentsType>;
252 static_assert(Extents::rank() >= 0 && Extents::rank() <= 2, "Only Extents of rank 0, 1 or 2 are implemented");
253 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
254
255 public:
256
257 using ItemLocalIdType = typename ItemType::LocalIdType;
258 using ReferenceType = DataViewGetterSetter<NumVectorType>;
259 using ConstReferenceType = DataViewGetter<NumVectorType>;
261 static constexpr int nb_dynamic = Extents::nb_dynamic;
262
263 public:
264
265 explicit MeshVectorMDVariableRefT(const VariableBuildInfo& b)
266 : BaseClass(b)
267 {}
268
269 public:
270
271 //! Accède à la donnée en lecture/écriture
272 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
273 ReferenceType operator()(ItemLocalIdType id)
274 {
275 return ReferenceType(m_vector_mdspan.ptrAt(id.localId()));
276 }
277
278 //! Accède à la donnée en lecture
279 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
280 ConstReferenceType operator()(ItemLocalIdType id) const
281 {
282 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId()));
283 }
284
285 //! Accède à la donnée en lecture/écriture
286 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
287 ReferenceType operator()(ItemLocalIdType id, Int32 i1)
288 {
289 return ReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1));
290 }
291
292 //! Accède à la donnée en lecture
293 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
294 ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
295 {
296 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1));
297 }
298
299 //! Accède à la donnée en lecture/écriture
300 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 2, void>>
301 ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
302 {
303 return ReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1, i2));
304 }
305
306 //! Accède à la donnée en lecture
307 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 2, void>>
308 ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
309 {
310 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1, i2));
311 }
312
313 /*!
314 * \brief Change la forme de la donnée.
315 *
316 * Le nombre d'éléments de \a dims doit correspondre aux nombre de valeurs
317 * dynamiques de \a Extents.
318 */
319 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
320 {
321 std::array<Int32, nb_dynamic + 1> full_dims;
322 // On ajoute 'Size' à la fin des dimensions.
323 for (int i = 0; i < nb_dynamic; ++i)
324 full_dims[i] = dims[i];
325 full_dims[nb_dynamic] = Size;
326 ArrayShape shape(full_dims);
327 this->m_underlying_var.resizeAndReshape(shape);
328 }
329
330 protected:
331
332 void updateFromInternal() override
333 {
335 // Positionne la valeur de m_vector_mdspan.
336 // Il aura les mêmes dimensions que m_mdspan sauf qu'on
337 // enlève la dernière dimension et qu'on change le type
338 // de 'DataType' en 'NumVector<DataType,Size>.
339 DataType* v = this->m_mdspan.to1DSpan().data();
340 NumVectorType* nv = reinterpret_cast<NumVectorType*>(v);
341 m_vector_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
342 }
343
344 private:
345
346 MDSpanType m_vector_mdspan;
347};
348
349/*---------------------------------------------------------------------------*/
350/*---------------------------------------------------------------------------*/
351/*!
352 * \brief Classe gérant une variable multi-dimension de type 'NumMatrix' sur une entité du maillage.
353 *
354 * \warning API en cours de définition. Ne pas utiliser en dehors de Arcane.
355 */
356template <typename ItemType, typename DataType, int Row, int Column, typename Extents>
357class MeshMatrixMDVariableRefT
358: public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>>
359{
360 public:
361
362 using NumMatrixType = NumMatrix<DataType, Row, Column>;
363
364 private:
365
366 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
367 using AddedFirstLastLastExtentsType = typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
368 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
369 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
370 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1, "Only Extents of rank 0 or 1 are implemented");
371 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
372
373 public:
374
375 using ItemLocalIdType = typename ItemType::LocalIdType;
376 using ReferenceType = DataViewGetterSetter<NumMatrixType>;
377 using ConstReferenceType = DataViewGetter<NumMatrixType>;
379 static constexpr int nb_dynamic = Extents::nb_dynamic;
380
381 public:
382
383 explicit MeshMatrixMDVariableRefT(const VariableBuildInfo& b)
384 : BaseClass(b)
385 {}
386
387 public:
388
389 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
390 ReferenceType operator()(ItemLocalIdType id)
391 {
392 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
393 }
394
395 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 0, void>>
396 ConstReferenceType operator()(ItemLocalIdType id) const
397 {
398 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
399 }
400
401 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
402 ReferenceType operator()(ItemLocalIdType id, Int32 i1)
403 {
404 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId(), i1));
405 }
406
407 template <typename X = Extents, typename = std::enable_if_t<X::rank() == 1, void>>
408 ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
409 {
410 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId(), i1));
411 }
412
413 /*!
414 * \brief Change la forme de la donnée.
415 *
416 * Le nombre d'éléments de \a dims doit correspondre aux nombre de valeurs
417 * dynamiques de \a Extents.
418 */
419 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
420 {
421 std::array<Int32, nb_dynamic + 2> full_dims;
422 // On ajoute 'Row' et 'Column' à la fin des dimensions.
423 for (int i = 0; i < nb_dynamic; ++i)
424 full_dims[i] = dims[i];
425 full_dims[nb_dynamic] = Row;
426 full_dims[nb_dynamic + 1] = Column;
427 ArrayShape shape(full_dims);
428 this->m_underlying_var.resizeAndReshape(shape);
429 }
430
431 protected:
432
433 void updateFromInternal() override
434 {
436 // Positionne la valeur de m_vector_mdspan.
437 // Il aura les mêmes dimensions que m_mdspan sauf qu'on
438 // enlève la dernière dimension et qu'on change le type
439 // de 'DataType' en 'NumMatrix<DataType,Row,Column>.
440 DataType* v = this->m_mdspan.to1DSpan().data();
441 NumMatrixType* nv = reinterpret_cast<NumMatrixType*>(v);
442 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
443 }
444
445 private:
446
447 MDSpanType m_matrix_mdspan;
448};
449
450/*---------------------------------------------------------------------------*/
451/*---------------------------------------------------------------------------*/
452
453} // namespace Arcane
454
455/*---------------------------------------------------------------------------*/
456/*---------------------------------------------------------------------------*/
457
458#endif
__host__ static __device__ ArrayExtentsBase< Extents > fromSpan(SmallSpan< const Int32 > 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 pour accéder à un élément d'une vue en lecture/écriture.
Classe pour accéder à un élément d'une vue en lecture.
Classe de base des vues multi-dimensionnelles.
Classe de base gérant une variable multi-dimension sur une entité du maillage.
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.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Change la forme de la donnée.
void updateFromInternal() override
Mise à jour à partir de la partie interne.
Variable tableau sur un type d'entité du maillage.
MeshVariableRef(const VariableBuildInfo &vb)
Construit une référence liée au module module.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Change la forme de la donnée.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
Accède à la donnée en lecture.
ReferenceType operator()(ItemLocalIdType id, Int32 i1)
Accède à la donnée en lecture/écriture.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
Accède à la donnée en lecture.
ReferenceType operator()(ItemLocalIdType id)
Accède à la donnée en lecture/écriture.
void updateFromInternal() override
Mise à jour à partir de la partie interne.
ConstReferenceType operator()(ItemLocalIdType id) const
Accède à la donnée en lecture.
ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
Accède à la donnée en lecture/écriture.
Petite matrice de taille fixe contenant RowSize lignes et ColumnSize colonnes.
Definition NumMatrix.h:42
Petit vecteur de taille fixe de N données numériques.
Definition NumVector.h:43
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.