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"
35template <
typename ItemType,
typename DataType>
36class MeshMDVariableRefWrapperT
39 template <
typename _ItemType,
typename _DataType,
typename _Extents>
45 using VariableType =
typename BaseClass::PrivatePartType;
46 using ValueDataType =
typename VariableType::ValueDataType;
57 ValueDataType* trueData() {
return this->m_private_part->trueData(); }
58 const ValueDataType* trueData()
const {
return this->m_private_part->trueData(); }
62 this->m_private_part->fillShape(shape_with_item);
82template <
typename ItemType,
typename DataType,
typename Extents>
83class MeshMDVariableRefBaseT
90 using ItemLocalIdType =
typename ItemType::LocalIdType;
91 using FullExtentsType = Extents;
99 _internalInit(m_underlying_var.variable());
112 const Int32 nb_rank = Extents::rank();
115 m_underlying_var.fillShape(shape_with_item);
118 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
137template <
typename ItemType,
typename DataType,
typename Extents>
138class MeshMDVariableRefT
139:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
141 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
143 static_assert(Extents::rank() >= 0 && Extents::rank() <= 3,
"Only Extents of rank 0, 1, 2 or 3 are implemented");
144 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
148 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
149 using ItemLocalIdType =
typename ItemType::LocalIdType;
150 static constexpr int nb_dynamic = Extents::nb_dynamic;
160 DataType& operator()(ItemLocalIdType
id)
requires(Extents::rank() == 0)
162 return this->m_mdspan(
id.localId());
165 const DataType& operator()(ItemLocalIdType
id)
const requires(Extents::rank() == 0)
167 return this->m_mdspan(
id.localId());
170 DataType& operator()(ItemLocalIdType
id,
Int32 i1)
requires(Extents::rank() == 1)
172 return this->m_mdspan(
id.localId(), i1);
175 const DataType& operator()(ItemLocalIdType
id,
Int32 i1)
const requires(Extents::rank() == 1)
177 return this->m_mdspan(
id.localId(), i1);
180 DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
181 requires(Extents::rank() == 2)
183 return this->m_mdspan(
id.localId(), i1, i2);
186 const DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
const
187 requires(Extents::rank() == 2)
189 return this->m_mdspan(
id.localId(), i1, i2);
193 requires(Extents::rank() == 3)
195 return this->m_mdspan(
id.localId(), i, j, k);
198 const DataType& operator()(ItemLocalIdType
id,
Int32 i,
Int32 j,
Int32 k)
const
199 requires(Extents::rank() == 3)
201 return this->m_mdspan(
id.localId(), i, j, k);
210 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
213 this->m_underlying_var.resizeAndReshape(shape);
227template <
typename ItemType,
typename DataType,
int Size,
typename Extents>
228class MeshVectorMDVariableRefT
229:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>>
238 using AddedFirstLastExtentsType =
typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>;
239 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
240 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastExtentsType>;
241 static_assert(Extents::rank() >= 0 && Extents::rank() <= 2,
"Only Extents of rank 0, 1 or 2 are implemented");
242 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
246 using ItemLocalIdType =
typename ItemType::LocalIdType;
250 static constexpr int nb_dynamic = Extents::nb_dynamic;
264 requires(Extents::rank() == 0)
266 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
271 requires(Extents::rank() == 0)
273 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId()));
281 requires(Extents::rank() == 1)
283 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
288 requires(Extents::rank() == 1)
290 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1));
298 requires(Extents::rank() == 2)
300 return ReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
305 requires(Extents::rank() == 2)
307 return ConstReferenceType(m_vector_mdspan.ptrAt(
id.localId(), i1, i2));
317 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
319 std::array<Int32, nb_dynamic + 1> full_dims;
321 for (
int i = 0; i < nb_dynamic; ++i)
322 full_dims[i] = dims[i];
323 full_dims[nb_dynamic] = Size;
325 this->m_underlying_var.resizeAndReshape(shape);
337 DataType* v = this->m_mdspan.to1DSpan().data();
338 NumVectorType* nv =
reinterpret_cast<NumVectorType*
>(v);
339 m_vector_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
344 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>>
366 using DataType = DataType_;
372 using AddedFirstLastLastExtentsType =
typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
373 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
374 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
375 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1,
"Only Extents of rank 0 or 1 are implemented");
376 static_assert(std::is_same_v<DataType, BasicType>,
"DataType should be a basic type (Real, Int32, Int64, ... )");
380 using ItemLocalIdType =
typename ItemType::LocalIdType;
384 static constexpr int nb_dynamic = Extents::nb_dynamic;
397 ReferenceType
operator()(ItemLocalIdType
id)
requires(Extents::rank()==0)
399 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
403 ConstReferenceType
operator()(ItemLocalIdType
id)
const requires(Extents::rank()==0)
405 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId()));
411 return m_matrix_mdspan(
id.localId())(i, j);
417 return m_matrix_mdspan(
id.localId())(i, j);
425 requires(Extents::rank() == 1)
427 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), index));
432 requires(Extents::rank() == 1)
434 return ReferenceType(m_matrix_mdspan.ptrAt(
id.localId(), index));
439 requires(Extents::rank() == 1)
441 return m_matrix_mdspan(
id.localId(), index)(i, j);
446 requires(Extents::rank() == 1)
448 return m_matrix_mdspan(
id.localId(), index)(i, j);
458 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
460 std::array<Int32, nb_dynamic + 2> full_dims;
462 for (
int i = 0; i < nb_dynamic; ++i)
463 full_dims[i] = dims[i];
464 full_dims[nb_dynamic] = Row;
465 full_dims[nb_dynamic + 1] = Column;
467 this->m_underlying_var.resizeAndReshape(shape);
479 DataType* v = this->m_mdspan.to1DSpan().data();
480 NumMatrixType* nv =
reinterpret_cast<NumMatrixType*
>(v);
481 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
486 MDSpanType m_matrix_mdspan;
__host__ static __device__ ArrayExtentsBase fromSpan(SmallSpan< const ExtentIndexType > 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 multidimensional 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.
DataType & operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j)
Mutable view of the element (i,j) of the matrix for item id and index index.
ReferenceType operator()(ItemLocalIdType id, Int32 index)
DataType & operator()(ItemLocalIdType id, Int32 i, Int32 j)
Mutable view of the element (i,j) of the matrix for item id.
DataType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
Read-only view of the element (i,j) of the matrix for item id and index index.
void updateFromInternal() override
Updates from the internal part.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Changes the data shape.
ConstReferenceType operator()(ItemLocalIdType id) const
Read-only view of the matrix for item id.
DataType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
Read-only view of the element (i,j) of the matrix for item id.
ConstReferenceType operator()(ItemLocalIdType id, Int32 index) const
Read-only view of the matrix of index index for item id.
ReferenceType operator()(ItemLocalIdType id)
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.
ReferenceType operator()(ItemLocalIdType id, Int32 i1)
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
Accesses the data for reading.
ConstReferenceType operator()(ItemLocalIdType id) const
Accesses the data for reading.
void updateFromInternal() override
Updates from the internal part.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
ReferenceType operator()(ItemLocalIdType id)
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.