Arcane  4.2.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
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// Voir le fichier COPYRIGHT de niveau supérieur pour les détails.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MeshMatrixMDVariableRef.h (C) 2000-2026 */
9/* */
10/* Variable 'NumMatrix' multidimensionnelle sur une entité de maillage. */
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/*---------------------------------------------------------------------------*/
39template <typename ItemType, typename DataType_, int Row, int Column, typename Extents>
40class MeshMatrixMDVariableRefT
41: public MeshMDVariableRefBaseT<ItemType, DataType_, typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>>
42{
43 // To access m_matrix_mdspan
44 friend class Arcane::Accelerator::MeshMatrixMDVariableInOutView<ItemType, DataType_, Row, Column, Extents>;
45 friend class Arcane::Accelerator::MeshMatrixMDVariableInView<ItemType, DataType_, Row, Column, Extents>;
46
47 public:
48
49 using DataType = DataType_;
50 using NumMatrixType = NumMatrix<DataType, Row, Column>;
51
52 private:
53
54 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
55 using AddedFirstLastLastExtentsType = typename Extents::template AddedFirstLastLastExtentsType<DynExtent, Row, Column>;
56 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
57 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastLastExtentsType>;
58 static_assert(Extents::rank() >= 0 && Extents::rank() <= 1, "Only Extents of rank 0 or 1 are implemented");
59 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
60
61 public:
62
63 using ItemLocalIdType = typename ItemType::LocalIdType;
65 using ConstReferenceType = NumMatrixDataViewGetter<DataType, Row, Column>;
67 static constexpr int nb_dynamic = Extents::nb_dynamic;
68
69 public:
70
71 explicit MeshMatrixMDVariableRefT(const VariableBuildInfo& b)
72 : BaseClass(b)
73 {}
74
75 public:
76
80 ReferenceType operator()(ItemLocalIdType id) requires(Extents::rank() == 0)
81 {
82 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
83 }
84
86 ConstReferenceType operator()(ItemLocalIdType id) const requires(Extents::rank() == 0)
87 {
88 return ConstReferenceType(m_matrix_mdspan.ptrAt(id.localId()));
89 }
90
92 DataType& operator()(ItemLocalIdType id, Int32 i, Int32 j) requires(Extents::rank() == 0)
93 {
94 return m_matrix_mdspan(id.localId())(i, j);
95 }
96
98 DataType operator()(ItemLocalIdType id, Int32 i, Int32 j) const requires(Extents::rank() == 0)
99 {
100 return m_matrix_mdspan(id.localId())(i, j);
101 }
102
103
107 ReferenceType operator()(ItemLocalIdType id, Int32 index)
108 requires(Extents::rank() == 1)
109 {
110 return ReferenceType(m_matrix_mdspan.ptrAt(id.localId(), index));
111 }
112
114 ConstReferenceType operator()(ItemLocalIdType id, Int32 index) const
115 requires(Extents::rank() == 1)
116 {
117 return ConstReferenceType(m_matrix_mdspan.ptrAt(id.localId(), index));
118 }
119
121 DataType& operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j)
122 requires(Extents::rank() == 1)
123 {
124 return m_matrix_mdspan(id.localId(), index)(i, j);
125 }
126
128 DataType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
129 requires(Extents::rank() == 1)
130 {
131 return m_matrix_mdspan(id.localId(), index)(i, j);
132 }
133
134
141 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
142 {
143 std::array<Int32, nb_dynamic + 2> full_dims;
144 // We add 'Row' and 'Column' to the end of the dimensions.
145 for (int i = 0; i < nb_dynamic; ++i)
146 full_dims[i] = dims[i];
147 full_dims[nb_dynamic] = Row;
148 full_dims[nb_dynamic + 1] = Column;
149 ArrayShape shape(full_dims);
150 this->m_underlying_var.resizeAndReshape(shape);
151 }
152
153 protected:
154
155 void updateFromInternal() override
156 {
158 // Positionne la valeur de m_vector_mdspan.
159 // Il aura les mêmes dimensions que m_mdspan, sauf que nous
160 // retirons la dernière dimension et changeons le type
161 // de 'DataType' à 'NumMatrix<DataType,Row,Column>'.
162 DataType* v = this->m_mdspan.to1DSpan().data();
163 NumMatrixType* nv = reinterpret_cast<NumMatrixType*>(v);
164 m_matrix_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
165 }
166
167 private:
168
169 MDSpanType m_matrix_mdspan;
170};
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175} // namespace Arcane
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180#endif
Vue en lecture/écriture de variable matricielle multidimensionnelle sur un élément de maillage.
Vue en lecture seule de variable matricielle multidimensionnelle sur un élément de maillage.
Forme d'un tableau.
Definition ArrayShape.h:40
Classe de base des vues multi-dimensionnelles.
DataType & operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j)
Vue mutable de l'élément (i,j) de la matrice pour l'élément id et l'indice index.
ReferenceType operator()(ItemLocalIdType id, Int32 index)
ConstReferenceType operator()(ItemLocalIdType id) const
Vue en lecture seule de la matrice pour l'élément id.
DataType & operator()(ItemLocalIdType id, Int32 i, Int32 j)
Vue mutable de l'élément (i,j) de la matrice pour l'élément id.
DataType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
Vue en lecture seule de l'élément (i,j) de la matrice pour l'élément id et l'indice index.
void updateFromInternal() override
Mise à jour à partir de la partie interne.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Modifie la forme des données.
DataType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
Vue en lecture seule de l'élément (i,j) de la matrice pour l'élément id.
ReferenceType operator()(ItemLocalIdType id)
ConstReferenceType operator()(ItemLocalIdType id, Int32 index) const
Vue en lecture seule de la matrice de l'indice index pour l'élément id.
Vue modifiable pour un NumMatrix<DataType_,Row,Column>.
Vue en lecture seule pour un NumMatrix<DataType_,Row,Column>.
Petite matrice de taille fixe contenant RowSize lignes et ColumnSize colonnes.
Paramètres nécessaires à la construction d'une variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Type entier signé sur 32 bits.