Arcane  4.2.1.0
User documentation
Loading...
Searching...
No Matches
MeshMDVariableRef.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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-2026 */
9/* */
10/* Class managing a multi-dimensional variable on a mesh entity. */
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
29namespace Arcane::Impl
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35template <typename ItemType, typename DataType>
36class MeshMDVariableRefWrapperT
37: public MeshVariableArrayRefT<ItemType, DataType>
38{
39 template <typename _ItemType, typename _DataType, typename _Extents>
41
42 public:
43
45 using VariableType = typename BaseClass::PrivatePartType;
46 using ValueDataType = typename VariableType::ValueDataType;
47
48 private:
49
50 explicit MeshMDVariableRefWrapperT(const VariableBuildInfo& vbi)
51 : BaseClass(vbi)
52 {
53 }
54
55 private:
56
57 ValueDataType* trueData() { return this->m_private_part->trueData(); }
58 const ValueDataType* trueData() const { return this->m_private_part->trueData(); }
59
60 void fillShape(ArrayShape& shape_with_item)
61 {
62 this->m_private_part->fillShape(shape_with_item);
63 }
64};
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
69} // namespace Arcane::Impl
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74namespace Arcane
75{
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79/*!
80 * \brief Base class managing a multi-dimensional variable on a mesh entity.
81 */
82template <typename ItemType, typename DataType, typename Extents>
83class MeshMDVariableRefBaseT
84: public MeshVariableRef
85{
86 public:
87
88 using UnderlyingVariableType = MeshVariableArrayRefT<ItemType, DataType>;
90 using ItemLocalIdType = typename ItemType::LocalIdType;
91 using FullExtentsType = Extents;
92
93 public:
94
95 explicit MeshMDVariableRefBaseT(const VariableBuildInfo& b)
97 , m_underlying_var(b)
98 {
99 _internalInit(m_underlying_var.variable());
100 }
101
102 //! Associated underlying variable.
103 const UnderlyingVariableType& underlyingVariable() const { return m_underlying_var; }
104 //! Associated underlying variable.
105 UnderlyingVariableType& underlyingVariable() { return m_underlying_var; }
106
107 //! Full shape (static + dynamic) of the variable.
108 ArrayShape fullShape() const { return m_underlying_var.trueData()->shape(); }
109
110 protected:
111
112 void updateFromInternal() override
113 {
114 const Int32 nb_rank = Extents::rank();
115 ArrayShape shape_with_item;
116 shape_with_item.setNbDimension(nb_rank);
117 m_underlying_var.fillShape(shape_with_item);
118
120 m_mdspan = MDSpanType(m_underlying_var.trueData()->view().data(), new_extents);
121 }
122
123 protected:
124
126 MDSpanType m_mdspan;
127};
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131/*!
132 * \brief Class managing a multi-dimensional variable on a mesh entity.
133 *
134 * \warning You need to call the method reshape() before using this kind
135 * of variables.
136 *
137 * For more information, see \ref arcanedoc_core_types_axl_md_variable_use.
138 */
139template <typename ItemType, typename DataType, typename Extents>
140class MeshMDVariableRefT
141: public MeshMDVariableRefBaseT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
142{
143 // To access m_mdspan
144 friend class Arcane::Accelerator::MeshMDVariableInView<ItemType, DataType, Extents>;
145 friend class Arcane::Accelerator::MeshMDVariableInOutView<ItemType, DataType, Extents>;
146
147 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
148 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
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, ... )");
151
152 public:
153
154 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstExtentsType>;
155 using ItemLocalIdType = typename ItemType::LocalIdType;
156 static constexpr int nb_dynamic = Extents::nb_dynamic;
157
158 public:
159
160 explicit MeshMDVariableRefT(const VariableBuildInfo& b)
161 : BaseClass(b)
162 {}
163
164 public:
165
166 DataType& operator()(ItemLocalIdType id) requires(Extents::rank() == 0)
167 {
168 return this->m_mdspan(id.localId());
169 }
170
171 const DataType& operator()(ItemLocalIdType id) const requires(Extents::rank() == 0)
172 {
173 return this->m_mdspan(id.localId());
174 }
175
176 DataType& operator()(ItemLocalIdType id, Int32 i1) requires(Extents::rank() == 1)
177 {
178 return this->m_mdspan(id.localId(), i1);
179 }
180
181 const DataType& operator()(ItemLocalIdType id, Int32 i1) const requires(Extents::rank() == 1)
182 {
183 return this->m_mdspan(id.localId(), i1);
184 }
185
186 DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
187 requires(Extents::rank() == 2)
188 {
189 return this->m_mdspan(id.localId(), i1, i2);
190 }
191
192 const DataType& operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
193 requires(Extents::rank() == 2)
194 {
195 return this->m_mdspan(id.localId(), i1, i2);
196 }
197
198 DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k)
199 requires(Extents::rank() == 3)
200 {
201 return this->m_mdspan(id.localId(), i, j, k);
202 }
203
204 const DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k) const
205 requires(Extents::rank() == 3)
206 {
207 return this->m_mdspan(id.localId(), i, j, k);
208 }
209
210 /*!
211 * \brief Changes the data shape.
212 *
213 * The number of elements in \a dims must correspond to the number of dynamic values
214 * in \a Extents.
215 */
216 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
217 {
218 ArrayShape shape(dims);
219 this->m_underlying_var.resizeAndReshape(shape);
220 }
221};
222
223/*---------------------------------------------------------------------------*/
224/*---------------------------------------------------------------------------*/
225
226} // namespace Arcane
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231#endif
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.
Array shape.
Definition ArrayShape.h:42
void setNbDimension(Int32 nb_value)
Sets the rank of the shape.
Definition ArrayShape.cc:39
SmallSpan< const Int32 > dimensions() const
Values of each dimension.
Definition ArrayShape.h:56
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.
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.