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());
114 const Int32 nb_rank = Extents::rank();
117 m_underlying_var.fillShape(shape_with_item);
120 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
139template <
typename ItemType,
typename DataType,
typename Extents>
140class MeshMDVariableRefT
141:
public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
147 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
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, ... )");
154 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
155 using ItemLocalIdType =
typename ItemType::LocalIdType;
156 static constexpr int nb_dynamic = Extents::nb_dynamic;
166 DataType& operator()(ItemLocalIdType
id)
requires(Extents::rank() == 0)
168 return this->m_mdspan(
id.localId());
171 const DataType& operator()(ItemLocalIdType
id)
const requires(Extents::rank() == 0)
173 return this->m_mdspan(
id.localId());
176 DataType& operator()(ItemLocalIdType
id,
Int32 i1)
requires(Extents::rank() == 1)
178 return this->m_mdspan(
id.localId(), i1);
181 const DataType& operator()(ItemLocalIdType
id,
Int32 i1)
const requires(Extents::rank() == 1)
183 return this->m_mdspan(
id.localId(), i1);
186 DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
187 requires(Extents::rank() == 2)
189 return this->m_mdspan(
id.localId(), i1, i2);
192 const DataType& operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
const
193 requires(Extents::rank() == 2)
195 return this->m_mdspan(
id.localId(), i1, i2);
199 requires(Extents::rank() == 3)
201 return this->m_mdspan(
id.localId(), i, j, k);
204 const DataType& operator()(ItemLocalIdType
id,
Int32 i,
Int32 j,
Int32 k)
const
205 requires(Extents::rank() == 3)
207 return this->m_mdspan(
id.localId(), i, j, k);
216 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
219 this->m_underlying_var.resizeAndReshape(shape);
Read-write view of multi-dimensional variable over a mesh item.
Read-only view of multi-dimensional variable over a mesh item.
__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.
Base class for multidimensional views.
Base class managing a multi-dimensional variable on a mesh entity.
const UnderlyingVariableType & underlyingVariable() const
Associated underlying variable.
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.
Array variable on a mesh entity type.
MeshVariableArrayRefT(const VariableBuildInfo &b)
MeshVariableRef(const VariableBuildInfo &vb)
Constructs a reference linked to the module.
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.