12#ifndef ARCANE_CORE_MESHMDVARIABLEREF_H
13#define ARCANE_CORE_MESHMDVARIABLEREF_H
17#include "arcane/utils/ArrayLayout.h"
18#include "arcane/utils/ArrayShape.h"
19#include "arcane/utils/MDSpan.h"
21#include "arcane/core/DataView.h"
23#include "arcane/core/MeshVariableArrayRef.h"
24#include "arcane/core/datatype/DataTypeTraits.h"
45template <
typename ItemType,
typename DataType>
46class MeshMDVariableRefWrapperT
49 template <
typename _ItemType,
typename _DataType,
typename _Extents>
55 using VariableType =
typename BaseClass::PrivatePartType;
56 using ValueDataType =
typename VariableType::ValueDataType;
67 ValueDataType* trueData() {
return this->m_private_part->trueData(); }
68 const ValueDataType* trueData()
const {
return this->m_private_part->trueData(); }
72 this->m_private_part->fillShape(shape_with_item);
95template <
typename ItemType,
typename DataType,
typename Extents>
96class MeshMDVariableRefBaseT
103 using ItemLocalIdType =
typename ItemType::LocalIdType;
104 using FullExtentsType = Extents;
110 , m_underlying_var(b)
112 _internalInit(m_underlying_var.variable());
125 const Int32 nb_rank = Extents::rank();
128 m_underlying_var.fillShape(shape_with_item);
131 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
148template <
typename ItemType,
typename DataType,
typename Extents>
149class MeshMDVariableRefT
150:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
152 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
154 static_assert(Extents::rank() >= 0 && Extents::rank() <= 3,
"Only Extents of rank 0, 1, 2 or 3 are implemented");
155 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
159 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
160 using ItemLocalIdType =
typename ItemType::LocalIdType;
161 static constexpr int nb_dynamic = Extents::nb_dynamic;
171 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
172 DataType& operator()(ItemLocalIdType
id)
174 return this->m_mdspan(
id.localId());
177 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
178 const DataType& operator()(ItemLocalIdType
id)
const
180 return this->m_mdspan(
id.localId());
183 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
184 DataType& operator()(ItemLocalIdType
id,
Int32 i1)
186 return this->m_mdspan(
id.localId(), i1);
189 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
190 const DataType& operator()(ItemLocalIdType
id,
Int32 i1)
const
192 return this->m_mdspan(
id.localId(), i1);
195 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
196 DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
198 return this->m_mdspan(
id.localId(), i1, i2);
201 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
202 const DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
const
204 return this->m_mdspan(
id.localId(), i1, i2);
207 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 3,
void>>
210 return this->m_mdspan(
id.localId(), i, j, k);
213 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 3,
void>>
214 const DataType& operator()(ItemLocalIdType
id,
Int32 i,
Int32 j,
Int32 k)
const
216 return this->m_mdspan(
id.localId(), i, j, k);
225 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
228 this->m_underlying_var.resizeAndReshape(shape);
240template <
typename ItemType,
typename DataType,
int Size,
typename Extents>
241class MeshVectorMDVariableRefT
242:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>>
251 using AddedFirstLastExtentsType =
typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>;
252 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
253 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastExtentsType>;
254 static_assert(Extents::rank() >= 0 && Extents::rank() <= 2,
"Only Extents of rank 0, 1 or 2 are implemented");
255 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
259 using ItemLocalIdType =
typename ItemType::LocalIdType;
263 static constexpr int nb_dynamic = Extents::nb_dynamic;
274 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
277 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
281 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
284 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
288 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
291 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
295 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
298 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
302 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
305 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
309 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 2,
void>>
312 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
321 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
323 std::array<Int32, nb_dynamic + 1> full_dims;
325 for (
int i = 0; i < nb_dynamic; ++i)
326 full_dims[i] = dims[i];
327 full_dims[nb_dynamic] = Size;
329 this->m_underlying_var.resizeAndReshape(shape);
341 DataType* v = this->m_mdspan.to1DSpan().data();
342 NumVectorType* nv =
reinterpret_cast<NumVectorType*
>(v);
343 m_vector_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
348 MDSpanType m_vector_mdspan;
360template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
361class MeshMatrixMDVariableRefT
362:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>>
371 using AddedFirstLastLastExtentsType =
typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
372 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
373 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
374 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1,
"Only Extents of rank 0 or 1 are implemented");
375 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
379 using ItemLocalIdType =
typename ItemType::LocalIdType;
383 static constexpr int nb_dynamic = Extents::nb_dynamic;
393 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
394 ReferenceType operator()(ItemLocalIdType
id)
396 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
399 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 0,
void>>
400 ConstReferenceType operator()(ItemLocalIdType
id)
const
402 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
405 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
406 ReferenceType operator()(ItemLocalIdType
id,
Int32 i1)
408 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), i1));
411 template <
typename X = Extents,
typename = std::enable_if_t<X::rank() == 1,
void>>
412 ConstReferenceType operator()(ItemLocalIdType
id,
Int32 i1)
const
414 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), i1));
423 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
425 std::array<Int32, nb_dynamic + 2> full_dims;
427 for (
int i = 0; i < nb_dynamic; ++i)
428 full_dims[i] = dims[i];
429 full_dims[nb_dynamic] = Row;
430 full_dims[nb_dynamic + 1] = Column;
432 this->m_underlying_var.resizeAndReshape(shape);
444 DataType* v = this->m_mdspan.to1DSpan().data();
445 NumMatrixType* nv =
reinterpret_cast<NumMatrixType*
>(v);
446 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
451 MDSpanType m_matrix_mdspan;
__host__ static __device__ ArrayExtentsBase< Extents > fromSpan(SmallSpan< const Int32 > extents)
Constructs an instance from the values given in extents.
void setNbDimension(Int32 nb_value)
Sets the rank of the shape.
SmallSpan< const Int32 > dimensions() const
Values of each dimension.
Class for accessing an element of a read/write view.
Class for accessing an element of a read view.
Base class for multi-dimensional views.
Base class managing a multi-dimensional variable on a mesh entity.
UnderlyingVariableType & underlyingVariable()
Associated underlying variable.
void updateFromInternal() override
Updates from the internal part.
ArrayShape fullShape() const
Full shape (static + dynamic) of the variable.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Changes the data shape.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Changes the data shape.
void updateFromInternal() override
Updates from the internal part.
Array variable on a mesh entity type.
MeshVariableArrayRefT(const VariableBuildInfo &b)
MeshVariableRef(const VariableBuildInfo &vb)
Constructs a reference linked to the module.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Changes the data shape.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id, Int32 i1)
Accesses the data for reading/writing.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id)
Accesses the data for reading/writing.
void updateFromInternal() override
Updates from the internal part.
ConstReferenceType operator()(ItemLocalIdType id) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
Accesses the data for reading/writing.
Small fixed-size matrix containing RowSize rows and ColumnSize columns.
Small fixed-size vector of N numerical data points.
Parameters necessary for building a variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.