12#ifndef ARCANE_MESHMDVARIABLEREF_H
13#define ARCANE_MESHMDVARIABLEREF_H
17#include "arcane/utils/ArrayLayout.h"
18#include "arcane/utils/ArrayShape.h"
19#include "arcane/utils/MDSpan.h"
21#include "arcane/DataView.h"
23#include "arcane/MeshVariableArrayRef.h"
44template <
typename ItemType,
typename DataType>
48 template <
typename _ItemType,
typename _DataType,
typename _Extents>
54 using VariableType =
typename BaseClass::PrivatePartType;
55 using ValueDataType =
typename VariableType::ValueDataType;
66 ValueDataType* trueData() {
return this->m_private_part->trueData(); }
67 const ValueDataType* trueData()
const {
return this->m_private_part->trueData(); }
71 this->m_private_part->fillShape(shape_with_item);
93template <
typename ItemType,
typename DataType,
typename Extents>
101 using ItemLocalIdType =
typename ItemType::LocalIdType;
102 using FullExtentsType = Extents;
108 , m_underlying_var(b)
110 _internalInit(m_underlying_var.variable());
123 const Int32 nb_rank = Extents::rank();
126 m_underlying_var.fillShape(shape_with_item);
129 m_mdspan =
MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
145template <
typename ItemType,
typename DataType,
typename Extents>
147:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
149 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
151 static_assert(Extents::rank() >= 0 && Extents::rank() <= 3,
"Only Extents of rank 0, 1, 2 or 3 are implemented");
152 static_assert(std::is_same_v<DataType,BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
157 using ItemLocalIdType =
typename ItemType::LocalIdType;
158 static constexpr int nb_dynamic = Extents::nb_dynamic;
168 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
169 DataType& operator()(ItemLocalIdType
id)
171 return this->m_mdspan(
id.localId());
174 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
175 const DataType& operator()(ItemLocalIdType
id)
const
177 return this->m_mdspan(
id.localId());
181 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
182 DataType& operator()(ItemLocalIdType
id, Int32 i1)
184 return this->m_mdspan(
id.localId(), i1);
187 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
188 const DataType& operator()(ItemLocalIdType
id, Int32 i1)
const
190 return this->m_mdspan(
id.localId(), i1);
193 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
194 DataType& operator()(ItemLocalIdType
id, Int32 i1, Int32 i2)
196 return this->m_mdspan(
id.localId(), i1, i2);
199 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
200 const DataType& operator()(ItemLocalIdType
id, Int32 i1, Int32 i2)
const
202 return this->m_mdspan(
id.localId(), i1, i2);
205 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 3,
void>>
206 DataType& operator()(ItemLocalIdType
id, Int32 i, Int32 j, Int32 k)
208 return this->m_mdspan(
id.localId(), i, j, k);
211 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 3,
void>>
212 const DataType& operator()(ItemLocalIdType
id, Int32 i, Int32 j, Int32 k)
const
214 return this->m_mdspan(
id.localId(), i, j, k);
223 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
226 this->m_underlying_var.resizeAndReshape(shape);
237template <
typename ItemType,
typename DataType,
int Size,
typename Extents>
238class MeshVectorMDVariableRefT
239:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>>
243 using NumVectorType = NumVector<DataType, Size>;
247 using BasicType =
typename DataTypeTraitsT<DataType>::BasicType;
248 using AddedFirstLastExtentsType =
typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>;
249 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
250 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastExtentsType>;
251 static_assert(Extents::rank() >= 0 && Extents::rank() <= 2,
"Only Extents of rank 0, 1 or 2 are implemented");
252 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
256 using ItemLocalIdType =
typename ItemType::LocalIdType;
257 using ReferenceType = DataViewGetterSetter<NumVectorType>;
258 using ConstReferenceType = DataViewGetter<NumVectorType>;
259 using MDSpanType = MDSpan<NumVectorType, AddedFirstExtentsType, RightLayout>;
260 static constexpr int nb_dynamic = Extents::nb_dynamic;
264 explicit MeshVectorMDVariableRefT(
const VariableBuildInfo& b)
271 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
272 ReferenceType operator()(ItemLocalIdType
id)
274 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
278 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
279 ConstReferenceType operator()(ItemLocalIdType
id)
const
281 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
285 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
286 ReferenceType operator()(ItemLocalIdType
id, Int32 i1)
288 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
292 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
293 ConstReferenceType operator()(ItemLocalIdType
id, Int32 i1)
const
295 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
299 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
300 ReferenceType operator()(ItemLocalIdType
id, Int32 i1, Int32 i2)
302 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
306 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
307 ConstReferenceType operator()(ItemLocalIdType
id, Int32 i1, Int32 i2)
const
309 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
318 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
320 std::array<Int32, nb_dynamic + 1> full_dims;
322 for (
int i = 0; i < nb_dynamic; ++i)
323 full_dims[i] = dims[i];
324 full_dims[nb_dynamic] = Size;
325 ArrayShape shape(full_dims);
326 this->m_underlying_var.resizeAndReshape(shape);
331 void updateFromInternal()
override
333 BaseClass::updateFromInternal();
338 DataType* v = this->m_mdspan.to1DSpan().data();
339 NumVectorType* nv =
reinterpret_cast<NumVectorType*
>(v);
340 m_vector_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
345 MDSpanType m_vector_mdspan;
355template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
356class MeshMatrixMDVariableRefT
357:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>>
361 using NumMatrixType = NumMatrix<DataType, Row, Column>;
365 using BasicType =
typename DataTypeTraitsT<DataType>::BasicType;
366 using AddedFirstLastLastExtentsType =
typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
367 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
368 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
369 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1,
"Only Extents of rank 0 or 1 are implemented");
370 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
374 using ItemLocalIdType =
typename ItemType::LocalIdType;
375 using ReferenceType = DataViewGetterSetter<NumMatrixType>;
376 using ConstReferenceType = DataViewGetter<NumMatrixType>;
377 using MDSpanType = MDSpan<NumMatrixType, AddedFirstExtentsType, RightLayout>;
378 static constexpr int nb_dynamic = Extents::nb_dynamic;
382 explicit MeshMatrixMDVariableRefT(
const VariableBuildInfo& b)
388 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
389 ReferenceType operator()(ItemLocalIdType
id)
391 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
394 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
395 ConstReferenceType operator()(ItemLocalIdType
id)
const
397 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
400 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
401 ReferenceType operator()(ItemLocalIdType
id, Int32 i1)
403 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), i1));
406 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
407 ConstReferenceType operator()(ItemLocalIdType
id, Int32 i1)
const
409 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), i1));
418 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
420 std::array<Int32, nb_dynamic + 2> full_dims;
422 for (
int i = 0; i < nb_dynamic; ++i)
423 full_dims[i] = dims[i];
424 full_dims[nb_dynamic] = Row;
425 full_dims[nb_dynamic + 1] = Column;
426 ArrayShape shape(full_dims);
427 this->m_underlying_var.resizeAndReshape(shape);
432 void updateFromInternal()
override
434 BaseClass::updateFromInternal();
439 DataType* v = this->m_mdspan.to1DSpan().data();
440 NumMatrixType* nv =
reinterpret_cast<NumMatrixType*
>(v);
441 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
446 MDSpanType m_matrix_mdspan;
__host__ static __device__ ArrayExtentsBase< Extents > fromSpan(SmallSpan< const Int32 > extents)
Construit une instance à partir des valeurs données dans extents.
void setNbDimension(Int32 nb_value)
Positionne le rang de la forme.
SmallSpan< const Int32 > dimensions() const
Valeurs de chaque dimension.
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.
Classe gérant une variable multi-dimension sur une entité du maillage.
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.
Classe de base d'une variable sur des entités du maillage.
Paramètres nécessaires à la construction d'une variable.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-