Arcane  4.2.3.0
Developer 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/*---------------------------------------------------------------------------*/
38template <typename ItemType, typename DataType_, int Size, typename Extents>
39class MeshVectorMDVariableRefT
40: public MeshMDVariableRefBaseT<ItemType, DataType_, typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>>
41{
42 // To access m_matrix_mdspan
43 friend class Arcane::Accelerator::MeshVectorMDVariableInOutView<ItemType, DataType_, Size, Extents>;
44 friend class Arcane::Accelerator::MeshVectorMDVariableInView<ItemType, DataType_, Size, Extents>;
45
46 public:
47
48 using DataType = DataType_;
49 using NumVectorType = NumVector<DataType, Size>;
50
51 private:
52
53 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
54 using AddedFirstLastExtentsType = typename Extents::template AddedFirstLastExtentsType<DynExtent, Size>;
55 using AddedFirstExtentsType = typename Extents::template AddedFirstExtentsType<DynExtent>;
56 using BaseClass = MeshMDVariableRefBaseT<ItemType, DataType, AddedFirstLastExtentsType>;
57 static_assert(Extents::rank() >= 0 && Extents::rank() <= 2, "Only Extents of rank 0, 1 or 2 are implemented");
58 static_assert(std::is_same_v<DataType, BasicType>, "DataType should be a basic type (Real, Int32, Int64, ... )");
59
60 public:
61
62 using ItemLocalIdType = typename ItemType::LocalIdType;
63 using ReferenceType = DataViewGetterSetter<NumVectorType>;
64 using ConstReferenceType = DataViewGetter<NumVectorType>;
66 static constexpr int nb_dynamic = Extents::nb_dynamic;
67
68 public:
69
70 explicit MeshVectorMDVariableRefT(const VariableBuildInfo& b)
71 : BaseClass(b)
72 {}
73
74 public:
75
79 ReferenceType operator()(ItemLocalIdType id)
80 requires(Extents::rank() == 0)
81 {
82 return ReferenceType(m_vector_mdspan.ptrAt(id.localId()));
83 }
84
86 ConstReferenceType operator()(ItemLocalIdType id) const
87 requires(Extents::rank() == 0)
88 {
89 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId()));
90 }
91
92
96 ReferenceType operator()(ItemLocalIdType id, Int32 i1)
97 requires(Extents::rank() == 1)
98 {
99 return ReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1));
100 }
101
103 ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
104 requires(Extents::rank() == 1)
105 {
106 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1));
107 }
108
109
113 ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
114 requires(Extents::rank() == 2)
115 {
116 return ReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1, i2));
117 }
118
120 ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
121 requires(Extents::rank() == 2)
122 {
123 return ConstReferenceType(m_vector_mdspan.ptrAt(id.localId(), i1, i2));
124 }
125
126
133 void reshape(std::array<Int32, Extents::nb_dynamic> dims)
134 {
135 std::array<Int32, nb_dynamic + 1> full_dims;
136 // We add 'Size' to the end of the dimensions.
137 for (int i = 0; i < nb_dynamic; ++i)
138 full_dims[i] = dims[i];
139 full_dims[nb_dynamic] = Size;
140 ArrayShape shape(full_dims);
141 this->m_underlying_var.resizeAndReshape(shape);
142 }
143
144 protected:
145
146 void updateFromInternal() override
147 {
149 // Positions the value of m_vector_mdspan.
150 // It will have the same dimensions as m_mdspan except that we
151 // remove the last dimension and change the type
152 // from 'DataType' to 'NumVector<DataType,Size>'.
153 DataType* v = this->m_mdspan.to1DSpan().data();
154 NumVectorType* nv = reinterpret_cast<NumVectorType*>(v);
155 m_vector_mdspan = MDSpanType(nv, this->m_mdspan.extents().dynamicExtents());
156 }
157
158 private:
159
160 MDSpanType m_vector_mdspan;
161};
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166} // namespace Arcane
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171#endif
Read-write view of multi-dimensional vector variable over a mesh item.
Read-only view of multi-dimensional vector variable over a mesh item.
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.
ReferenceType operator()(ItemLocalIdType id, Int32 i1)
ConstReferenceType operator()(ItemLocalIdType id) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2)
void updateFromInternal() override
Updates from the internal part.
void reshape(std::array< Int32, Extents::nb_dynamic > dims)
Changes the data shape.
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1, Int32 i2) const
Accesses the data for reading.
ReferenceType operator()(ItemLocalIdType id)
ConstReferenceType operator()(ItemLocalIdType id, Int32 i1) const
Accesses the data for reading.
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.