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