Arcane  4.2.1.0
Developer documentation
Loading...
Searching...
No Matches
MDVariableViews.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/* MDVariableViews.h (C) 2000-2026 */
9/* */
10/* multi-dimensional variable view management for accelerators. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
13#define ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayLayout.h"
18
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Accelerator
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
32template <typename ItemType_, typename Accessor_, typename Extents_>
33class MeshMDVariableViewBase
34{
35 using Accessor = Accessor_;
36 using AddedFirstExtentsType = typename Extents_::template AddedFirstExtentsType<DynExtent>;
37
38 public:
39
40 using ItemType = ItemType_;
41 using DataType = Accessor::ValueType;
42 using AccessorReturnType = Accessor::AccessorReturnType;
43 using Extents = Extents_;
44 using ItemLocalIdType = ItemType::LocalIdType;
45
46 protected:
47
49
50 protected:
51
52 explicit constexpr ARCCORE_HOST_DEVICE MeshMDVariableViewBase(const MDSpanType& v)
53 : m_mdspan(v)
54 {
55 }
56
57 public:
58
59 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType id) const
60 requires(Extents::rank() == 0)
61 {
62 return Accessor::build(m_mdspan.ptrAt(id.localId()));
63 }
64 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType id, Int32 i1) const
65 requires(Extents::rank() == 1)
66 {
67 return Accessor::build(m_mdspan.ptrAt(id.localId(), i1));
68 }
69
70 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
71 requires(Extents::rank() == 2)
72 {
73 return Accessor::build(m_mdspan.ptrAt(id.localId(), i1, i2));
74 }
75
76 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType id, Int32 i, Int32 j, Int32 k) const
77 requires(Extents::rank() == 3)
78 {
79 return Accessor::build(m_mdspan.ptrAt(id.localId(), i, j, k));
80 }
81
82 private:
83
84 MDSpanType m_mdspan;
85};
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
92template <typename ItemType_, typename DataType_, typename Extents>
93class MeshMDVariableInView
94: protected MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>
95{
96 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>;
97
98 public:
99
100 using ItemType = ItemType_;
101 using DataType = DataType_;
102 using ExtentsType = Extents;
103 using ItemLocalIdType = ItemType::LocalIdType;
105
106 using BaseClass::operator();
107
108 private:
109
110 using MDSpanType = VariableRefType::MDSpanType;
111
112 public:
113
114 MeshMDVariableInView(const ViewBuildInfo& view_bi, const VariableRefType& var_ref)
115 : BaseClass(var_ref.m_mdspan)
116 {
117 IVariable* var = var_ref.underlyingVariable().variable();
118 VariableViewBase vb(view_bi, var);
119 }
120};
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
127template <typename ItemType_, typename DataType_, typename Extents>
128class MeshMDVariableInOutView
129: protected MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>
130{
131 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>;
132
133 public:
134
135 using ItemType = ItemType_;
136 using DataType = DataType_;
137 using ExtentsType = Extents;
138 using ItemLocalIdType = ItemType::LocalIdType;
140
141 using BaseClass::operator();
142
143 private:
144
145 using MDSpanType = VariableRefType::MDSpanType;
146
147 public:
148
149 MeshMDVariableInOutView(const ViewBuildInfo& view_bi, VariableRefType& var_ref)
150 : BaseClass(var_ref.m_mdspan)
151 {
152 IVariable* var = var_ref.underlyingVariable().variable();
153 VariableViewBase vb(view_bi, var);
154 }
155};
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
167template <typename ItemType_, typename MatrixAccessor_, typename Extents>
168class MeshMatrixMDVariableViewBase
169{
170 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
171
172 public:
173
174 using ItemType = ItemType_;
175 using MatrixAccessor = MatrixAccessor_;
176 using MatrixElementAccessor = MatrixAccessor_::MatrixElemenAccessor;
177 using NumMatrixType = MatrixAccessor::NumMatrixType;
178 using MatrixAccessorReturnType = MatrixAccessor::AccessorReturnType;
179 using MatrixElementAccessorReturnType = MatrixElementAccessor::AccessorReturnType;
180 using ItemLocalIdType = ItemType::LocalIdType;
181
182 private:
183
185
186 public:
187
188 MeshMatrixMDVariableViewBase(const MDSpanType& matrix_mdspan)
189 : m_matrix_mdspan(matrix_mdspan)
190 {
191 }
192
193 public:
194
197
199 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType operator()(ItemLocalIdType id) const
200 requires(Extents::rank() == 0)
201 {
202 return MatrixAccessor::build(m_matrix_mdspan.ptrAt(id.localId()));
203 }
204
206 constexpr ARCCORE_HOST_DEVICE MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
207 requires(Extents::rank() == 0)
208 {
209 return MatrixElementAccessor::build(&m_matrix_mdspan(id.localId())(i, j));
210 }
211
212
215 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType operator()(ItemLocalIdType id, Int32 index) const
216 requires(Extents::rank() == 1)
217 {
218 return MatrixAccessor::build(m_matrix_mdspan.ptrAt(id.localId(), index));
219 }
220
222 constexpr ARCCORE_HOST_DEVICE MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
223 requires(Extents::rank() == 1)
224 {
225 return MatrixElementAccessor::build(&m_matrix_mdspan(id.localId(), index)(i, j));
226 }
227
228
229 private:
230
231 MDSpanType m_matrix_mdspan;
232};
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
239template <typename ItemType_, typename DataType_, int Row, int Column, typename Extents>
240class MeshMatrixMDVariableInView
241: public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>
242{
243 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>;
244
245 public:
246
247 using ItemType = ItemType_;
248 using DataType = DataType_;
249 using ItemLocalIdType = ItemType::LocalIdType;
250 using ConstReferenceType = NumMatrixDataViewGetter<DataType, Row, Column>;
252
253 private:
254
255 using MDSpanType = VariableRefType::MDSpanType;
256
257 public:
258
259 MeshMatrixMDVariableInView(const ViewBuildInfo& view_bi, const VariableRefType& var_ref)
260 : BaseClass(var_ref.m_matrix_mdspan)
261 {
262 IVariable* var = var_ref.underlyingVariable().variable();
263 VariableViewBase vvb(view_bi, var);
264 }
265};
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
272template <typename ItemType_, typename DataType_, int Row, int Column, typename Extents>
273class MeshMatrixMDVariableInOutView
274: public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>
275{
276 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>;
277
278 public:
279
280 using ItemType = ItemType_;
281 using DataType = DataType_;
282 using ItemLocalIdType = ItemType::LocalIdType;
283 using ConstReferenceType = NumMatrixDataViewGetter<DataType, Row, Column>;
285
286 private:
287
288 using MDSpanType = VariableRefType::MDSpanType;
289
290 public:
291
292 MeshMatrixMDVariableInOutView(const ViewBuildInfo& view_bi, const VariableRefType& var_ref)
293 : BaseClass(var_ref.m_matrix_mdspan)
294 {
295 IVariable* var = var_ref.underlyingVariable().variable();
296 VariableViewBase vvb(view_bi, var);
297 }
298};
299
300/*---------------------------------------------------------------------------*/
301/*---------------------------------------------------------------------------*/
305template <typename ItemType, typename DataType, int Row, int Column, typename Extents>
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
316template <typename ItemType, typename DataType, typename Extents>
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
327template <typename ItemType, typename DataType, int Row, int Column, typename Extents>
332
333/*---------------------------------------------------------------------------*/
334/*---------------------------------------------------------------------------*/
338template <typename ItemType, typename DataType, typename Extents>
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
346
347} // End namespace Arcane::Accelerator
348
349/*---------------------------------------------------------------------------*/
350/*---------------------------------------------------------------------------*/
351
352#endif
Read-write view of multi-dimensional variable over a mesh item.
Read-only view of multi-dimensional variable over a mesh item.
Read-write view of multi-dimensional matrix variable over a mesh item.
Read-only view of multi-dimensional matrix variable over a mesh item.
constexpr __host__ __device__ MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
accessor for the element (i,j) of the matrix for item id
constexpr __host__ __device__ MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
Accessor for the element (i,j) of the matrix for item id and index index.
constexpr __host__ __device__ MatrixAccessorReturnType operator()(ItemLocalIdType id) const
Accessor of the matrix for item id.
Base class for variable views.
Interface of a variable.
Definition IVariable.h:40
Base class for multidimensional views.
constexpr DataType * ptrAt(ExtentIndexType i, ExtentIndexType j, ExtentIndexType k, ExtentIndexType l) const
Pointer to the value for element i,j,k,l.
const UnderlyingVariableType & underlyingVariable() const
Associated underlying variable.
Class managing a multi-dimensional variable on a mesh entity.
Class managing a multi-dimensional NumMatrix type variable on a mesh entity.
Read-only view for a NumMatrix<DataType_,Row,Column>.
IVariable * variable() const
Associated variable.
auto viewInOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Read/write view for scalar material variables.
auto viewIn(const ViewBuildInfo &vbi, const CellMaterialVariableScalarRef< DataType > &var)
Read view for scalar material variables.
std::int32_t Int32
Signed integer type of 32 bits.