Arcane  4.2.1.0
User documentation
Loading...
Searching...
No Matches
MeshMatrixMDVariableRef.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/* MeshMatrixMDVariableRef.h (C) 2000-2026 */
9/* */
10/* Multi-dimensional 'NumMatrix' variable on a mesh entity. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MESHMATRIXMDVARIABLEREF_H
13#define ARCANE_CORE_MESHMATRIXMDVARIABLEREF_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/NumMatrix.h"
18#include "arcane/utils/NumMatrixDataView.h"
19
20#include "arcane/core/MeshMDVariableRef.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30/*!
31 * \brief Class managing a multi-dimensional NumMatrix type variable on a
32 * mesh entity.
33 *
34 * The dimension of the matrix is fixed and is given by (Row,Column).
35 *
36 * \warning You need to call the method reshape() before using this kind
37 * of variables.
38 *
39 * For more information, see \ref arcanedoc_core_types_axl_md_variable_use.
40 */
41template <typename ItemType, typename DataType_, int Row, int Column, typename Extents>
42class MeshMatrixMDVariableRefT
43: public MeshMDVariableRefBaseT<ItemType, DataType_, typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>>
44{
45 // To access m_matrix_mdspan
46 friend class Arcane::Accelerator::MeshMatrixMDVariableInOutView<ItemType, DataType_, Row, Column, Extents>;
47 friend class Arcane::Accelerator::MeshMatrixMDVariableInView<ItemType, DataType_, Row, Column, Extents>;
48
49 public:
50
51 using DataType = DataType_;
52 using NumMatrixType = NumMatrix<DataType, Row, Column>;
53
54 private:
55
56 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
57 using AddedFirstLastLastExtentsType = typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
58 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
59 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
60 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1, "Only Extents of rank 0 or 1 are implemented");
61 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
62
63 public:
64
65 using ItemLocalIdType = typename ItemType::LocalIdType;
67 using ConstReferenceType = NumMatrixDataViewGetter<DataType, Row, Column>;
69 static constexpr int nb_dynamic = Extents::nb_dynamic;
70
71 public:
72
73 explicit MeshMatrixMDVariableRefT(const VariableBuildInfo& b)
74 : BaseClass(b)
75 {}
76
77 public:
78
79 //! \name Operations for variable of dimension MDDim0
80 ///@{
81 //! Mutable view of the matrix for item \a id
82 ReferenceType operator()(ItemLocalIdType id) requires(Extents::rank() == 0)
83 {
84 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
85 }
86
87 //! Read-only view of the matrix for item \a id
88 ConstReferenceType operator()(ItemLocalIdType id) const requires(Extents::rank() == 0)
89 {
90 return ConstReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
91 }
92
93 //! Mutable view of the element (i,j) of the matrix for item \a id
94 DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j) requires(Extents::rank() == 0)
95 {
96 return m_matrix_mdspan(id.localId())(i, j);
97 }
98
99 //! Read-only view of the element (i,j) of the matrix for item \a id
100 DataType operator()(ItemLocalIdType id, Int32 i, Int32 j) const requires(Extents::rank() == 0)
101 {
102 return m_matrix_mdspan(id.localId())(i, j);
103 }
104 ///@}
105
106 //! \name Operations for variable of dimension MDDim1
107 ///@{
108 //! Mutable view of the matrix of index \a index for item \a id
109 ReferenceType operator()(ItemLocalIdType id, Int32 index)
110 requires(Extents::rank() == 1)
111 {
112 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId(), index));
113 }
114
115 //! Read-only view of the matrix of index \a index for item \a id
116 ConstReferenceType operator()(ItemLocalIdType id, Int32 index) const
117 requires(Extents::rank() == 1)
118 {
119 return ConstReferenceType(m_matrix_mdspan.ptrAt(id.localId(), index));
120 }
121
122 //! Mutable view of the element (i,j) of the matrix for item \a id and index \a index
123 DataType& operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j)
124 requires(Extents::rank() == 1)
125 {
126 return m_matrix_mdspan(id.localId(), index)(i, j);
127 }
128
129 //! Read-only view of the element (i,j) of the matrix for item \a id and index \a index
130 DataType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
131 requires(Extents::rank() == 1)
132 {
133 return m_matrix_mdspan(id.localId(), index)(i, j);
134 }
135 ///@}
136
137 /*!
138 * \brief Changes the data shape.
139 *
140 * The number of elements in \a dims must correspond to the number of dynamic values
141 * in \a Extents.
142 */
143 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
144 {
145 std::array<Int32, nb_dynamic + 2> full_dims;
146 // We add 'Row' and 'Column' to the end of the dimensions.
147 for (int i = 0; i < nb_dynamic; ++i)
148 full_dims[i] = dims[i];
149 full_dims[nb_dynamic] = Row;
150 full_dims[nb_dynamic + 1] = Column;
151 ArrayShape shape(full_dims);
152 this->m_underlying_var.resizeAndReshape(shape);
153 }
154
155 protected:
156
157 void updateFromInternal() override
158 {
160 // Positions the value of m_vector_mdspan.
161 // It will have the same dimensions as m_mdspan except that we
162 // remove the last dimension and change the type
163 // from 'DataType' to 'NumMatrix<DataType,Row,Column>'.
164 DataType* v = this->m_mdspan.to1DSpan().data();
165 NumMatrixType* nv = reinterpret_cast<NumMatrixType*>(v);
166 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
167 }
168
169 private:
170
171 MDSpanType m_matrix_mdspan;
172};
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177} // namespace Arcane
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182#endif
Read-write view of multi-dimensional matrix variable over a mesh item.
Read-only view of multi-dimensional matrix variable over a mesh item.
Array shape.
Definition ArrayShape.h:42
Base class for multidimensional views.
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)
ConstReferenceType operator()(ItemLocalIdType id) const
Read-only view of the matrix for item id.
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.
DataType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
Read-only view of the element (i,j) of the matrix for item id.
ReferenceType operator()(ItemLocalIdType id)
ConstReferenceType operator()(ItemLocalIdType id, Int32 index) const
Read-only view of the matrix of index index for item id.
Mutable view for a NumMatrix<DataType_,Row,Column>.
Read-only view for a NumMatrix<DataType_,Row,Column>.
Small fixed-size matrix containing RowSize rows and ColumnSize columns.
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.