Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MeshVariableScalarRef.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/* MeshVariableScalarRef.h (C) 2000-2025 */
9/* */
10/* Class managing a scalar variable on a mesh entity. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MESHVARIABLESCALARREF_H
13#define ARCANE_CORE_MESHVARIABLESCALARREF_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/core/MeshVariableRef.h"
20#include "arcane/core/PrivateVariableScalar.h"
22#include "arcane/core/ItemGroupRangeIterator.h"
23#include "arcane/core/ItemPairEnumerator.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34template <typename DataTypeT>
36{
37 public:
38
40
41 public:
42
43 static void add(VarType&, const VarType&, const ItemGroup&) { _notSupported(); }
44 static void sub(VarType&, const VarType&, const ItemGroup&) { _notSupported(); }
45 static void mult(VarType&, const VarType&, const ItemGroup&) { _notSupported(); }
46 static void mult(VarType&, const DataTypeT&, const ItemGroup&) { _notSupported(); }
47 static void power(VarType&, const DataTypeT&, const ItemGroup&) { _notSupported(); }
48 static void _notSupported()
49 {
50 ARCANE_FATAL("ItemNumeraticOperation: operation not supported");
51 }
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57template <>
59{
60 public:
61
62 typedef ItemVariableScalarRefT<Real> VarType;
63
64 public:
65
66 static ARCANE_CORE_EXPORT void add(VarType& out, const VarType& v, const ItemGroup& group);
67 static ARCANE_CORE_EXPORT void sub(VarType& out, const VarType& v, const ItemGroup& group);
68 static ARCANE_CORE_EXPORT void mult(VarType& out, const VarType& v, const ItemGroup& group);
69 static ARCANE_CORE_EXPORT void mult(VarType& out, Real v, const ItemGroup& group);
70 static ARCANE_CORE_EXPORT void power(VarType& out, Real v, const ItemGroup& group);
71};
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76/*!
77 * \ingroup Variable
78 * \brief Scalar variable on a mesh entity type.
79 */
80template <typename DataTypeT>
82: public PrivateVariableScalarT<DataTypeT>
83{
84 public:
85
86 typedef DataTypeT DataType;
87 typedef UniqueArray<DataTypeT> ValueType;
88 typedef const DataTypeT& ConstReturnReferenceType;
89 typedef DataTypeT& ReturnReferenceType;
90
91 typedef ArrayView<DataTypeT> ArrayBase;
92 typedef PrivateVariableScalarT<DataTypeT> BaseClass;
93 typedef typename BaseClass::PrivatePartType PrivatePartType;
94 typedef typename BaseClass::DataTypeReturnReference DataTypeReturnReference;
95
96 public:
97
98 //! Constructs a reference to the variable specified in \a vb
99 ARCANE_CORE_EXPORT ItemVariableScalarRefT(const VariableBuildInfo& b, eItemKind ik);
100
101 //! Constructs a reference from \a var
102 explicit ARCANE_CORE_EXPORT ItemVariableScalarRefT(IVariable* var);
103
104 //! Constructs a reference from \a rhs
106
107 protected:
108
109 //! Positions the instance reference to the variable \a rhs.
110 ARCANE_CORE_EXPORT void operator=(const ItemVariableScalarRefT<DataTypeT>& rhs);
111
112#ifdef ARCANE_DOTNET
113 public:
114
115#else
116 protected:
117#endif
118
119 //! Default constructor
121
122 public:
123
124 void add(const ItemVariableScalarRefT<DataTypeT>& v)
125 {
126 add(v, this->itemGroup());
127 }
128 void sub(const ItemVariableScalarRefT<DataTypeT>& v)
129 {
130 sub(v, this->itemGroup());
131 }
132 void mult(const ItemVariableScalarRefT<DataTypeT>& v)
133 {
134 mult(v, this->itemGroup());
135 }
136 void mult(const DataTypeT& v)
137 {
138 mult(v, this->itemGroup());
139 }
140 void copy(const ItemVariableScalarRefT<DataTypeT>& v)
141 {
142 copy(v, this->itemGroup());
143 }
144 void power(const DataTypeT& v)
145 {
146 power(v, this->itemGroup());
147 }
148
149 void add(const ItemVariableScalarRefT<DataTypeT>& v, const ItemGroup& group)
150 {
151 ItemNumericOperation<DataTypeT>::add(*this, v, group);
152 }
153 void sub(const ItemVariableScalarRefT<DataTypeT>& v, const ItemGroup& group)
154 {
155 ItemNumericOperation<DataTypeT>::sub(*this, v, group);
156 }
157 void mult(const ItemVariableScalarRefT<DataTypeT>& v, const ItemGroup& group)
158 {
159 ItemNumericOperation<DataTypeT>::mult(*this, v, group);
160 }
161 void mult(const DataTypeT& v, const ItemGroup& group)
162 {
163 ItemNumericOperation<DataTypeT>::mult(*this, v, group);
164 }
165 void power(const DataTypeT& v, const ItemGroup& group)
166 {
167 ItemNumericOperation<DataTypeT>::power(*this, v, group);
168 }
169
170 //! Copies the values of \a v into this variable for the entities in \a group.
171 ARCANE_CORE_EXPORT void copy(const ItemVariableScalarRefT<DataTypeT>& v, const ItemGroup& group);
172 ARCANE_CORE_EXPORT void fill(const DataTypeT& value);
173 ARCANE_CORE_EXPORT void fill(const DataTypeT& value, const ItemGroup& group);
174
175 /*!
176 * \brief Copies the values of \a v into this variable via the \a queue.
177 *
178 * \a queue may be null.
179 */
180 ARCANE_CORE_EXPORT void copy(const ItemVariableScalarRefT<DataTypeT>& v, RunQueue* queue);
181 /*!
182 * \brief Fills the instance values with \a value via the \a queue.
183 *
184 * \a queue may be null.
185 */
186 ARCANE_CORE_EXPORT void fill(const DataTypeT& value, RunQueue* queue);
187
188 public:
189
190 //! Read-only value of entity \a item
191 const DataType& operator[](ItemLocalId item) const { return this->_value(item.localId()); }
192
193 //! Read/write value of entity \a item
194 DataTypeReturnReference operator[](ItemLocalId item) { return this->_value(item.localId()); }
195
196 //! Read-only value of entity \a item
197 const DataType& operator()(ItemLocalId item) const { return this->_value(item.localId()); }
198
199 //! Read/write value of entity \a item
200 DataTypeReturnReference operator()(ItemLocalId item) { return this->_value(item.localId()); }
201
202 public:
203
204 static ARCANE_CORE_EXPORT VariableInfo _internalVariableInfo(const VariableBuildInfo& vbi, eItemKind ik);
205 static ARCANE_CORE_EXPORT VariableTypeInfo _internalVariableTypeInfo(eItemKind ik);
206};
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211/*!
212 * \ingroup Variable
213 * \brief Scalar variable on a mesh entity type.
214 */
215template <typename ItemTypeT, typename DataTypeT>
217: public ItemVariableScalarRefT<DataTypeT>
218{
219 public:
220
221 typedef DataTypeT DataType;
222 typedef ItemTypeT ItemType;
223 typedef UniqueArray<DataTypeT> ValueType;
224 typedef const DataTypeT& ConstReturnReferenceType;
225 typedef DataTypeT& ReturnReferenceType;
226
227 protected:
228
229 typedef typename ItemType::LocalIdType ItemLocalIdType;
230 typedef ItemVariableScalarRefT<DataTypeT> BaseClass;
231
232 typedef typename ItemTraitsT<ItemType>::ItemGroupType GroupType;
234 typedef typename BaseClass::DataTypeReturnReference DataTypeReturnReference;
235
236 public:
237
238 //! Constructs a reference to the variable specified in \a vb
239 ARCANE_CORE_EXPORT MeshVariableScalarRefT(const VariableBuildInfo& vb);
240 //! Constructs a reference from \a var
241 explicit ARCANE_CORE_EXPORT MeshVariableScalarRefT(IVariable* var);
242 //! Constructs a reference from \a rhs
244
245 //! Positions the instance reference to the variable \a rhs.
246 ARCANE_CORE_EXPORT void refersTo(const MeshVariableScalarRefT<ItemType, DataTypeT>& rhs);
247
248 ThatClass& operator=(const ThatClass& rhs) = delete;
249
250#ifdef ARCANE_DOTNET
251 public:
252
253#else
254 protected:
255#endif
256
257 //! Default constructor
259 ThatClass& _Internal() { return *this; }
260
261 public:
262
263 void fill(const DataTypeT& value) { BaseClass::fill(value); }
264 void fill(const DataTypeT& value, RunQueue* queue) { BaseClass::fill(value, queue); }
265 void fill(const DataTypeT& value, const GroupType& group) { BaseClass::fill(value, group); }
266
268
269 //! Group associated with the quantity
270 ARCANE_CORE_EXPORT GroupType itemGroup() const;
271
272 ARCANE_CORE_EXPORT void setIsSynchronized();
273 ARCANE_CORE_EXPORT void setIsSynchronized(const GroupType& group);
274
275 public:
276
277 //! Read-only value of entity \a item
278 const DataTypeT& operator[](ItemLocalIdType i) const { return this->_value(i.localId()); }
279
280 //! Read/write value of entity \a item
281 DataTypeReturnReference operator[](ItemLocalIdType i) { return this->_value(i.localId()); }
282
283 //! Read-only value of entity \a item
284 const DataTypeT& operator()(ItemLocalIdType i) const { return this->_value(i.localId()); }
285
286 //! Read/write value of entity \a item
287 DataTypeReturnReference operator()(ItemLocalIdType i) { return this->_value(i.localId()); }
288
289 //! Read/write value of entity \a item
290 DataTypeT& getReference(ItemLocalIdType item)
291 {
292 return this->_value(item.localId());
293 }
294
295 const DataTypeT& item(ItemLocalIdType i) const
296 {
297 return this->_value(i.localId());
298 }
299 void setItem(ItemLocalIdType i, const DataTypeT& v)
300 {
301 this->_value(i.localId()) = v;
302 }
303#ifdef ARCANE_DOTNET_WRAPPER
304 const DataTypeT& item(Int32 i) const
305 {
306 return this->_value(i);
307 }
308 void setItem(Int32 i, const DataTypeT& v)
309 {
310 this->_value(i) = v;
311 }
312#endif
313
314 public:
315
316 static ARCANE_CORE_EXPORT VariableTypeInfo _internalVariableTypeInfo();
317 static ARCANE_CORE_EXPORT VariableInfo _internalVariableInfo(const VariableBuildInfo& vbi);
318
319 private:
320
321 static VariableFactoryRegisterer m_auto_registerer;
322 static VariableRef* _autoCreate(const VariableBuildInfo& vb);
323};
324
325/*---------------------------------------------------------------------------*/
326/*---------------------------------------------------------------------------*/
327
328} // End namespace Arcane
329
330/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
333#endif
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Types and macros for iterating over mesh entities.
Modifiable view of an array of type T.
Interface of a variable.
Definition IVariable.h:40
Mesh entity group.
Definition ItemGroup.h:51
Index of an Item in a variable.
Definition ItemLocalId.h:42
Scalar variable on a mesh entity type.
ItemVariableScalarRefT(IVariable *var)
Constructs a reference from var.
void operator=(const ItemVariableScalarRefT< DataTypeT > &rhs)
Positions the instance reference to the variable rhs.
ItemVariableScalarRefT()
Default constructor.
ItemVariableScalarRefT(const ItemVariableScalarRefT< DataTypeT > &rhs)
Constructs a reference from rhs.
const DataType & operator[](ItemLocalId item) const
Read-only value of entity item.
DataTypeReturnReference operator[](ItemLocalId item)
Read/write value of entity item.
void fill(const DataTypeT &value, RunQueue *queue)
Fills the instance values with value via the queue.
DataTypeReturnReference operator()(ItemLocalId item)
Read/write value of entity item.
void copy(const ItemVariableScalarRefT< DataTypeT > &v, RunQueue *queue)
Copies the values of v into this variable via the queue.
ItemVariableScalarRefT(const VariableBuildInfo &b, eItemKind ik)
Constructs a reference to the variable specified in vb.
const DataType & operator()(ItemLocalId item) const
Read-only value of entity item.
void copy(const ItemVariableScalarRefT< DataTypeT > &v, const ItemGroup &group)
Copies the values of v into this variable for the entities in group.
DataTypeReturnReference operator[](ItemLocalIdType i)
Read/write value of entity item.
MeshVariableScalarRefT()
Default constructor.
GroupType itemGroup() const
Group associated with the quantity.
DataTypeReturnReference operator()(ItemLocalIdType i)
Read/write value of entity item.
MeshVariableScalarRefT(const VariableBuildInfo &vb)
Constructs a reference to the variable specified in vb.
DataTypeT & getReference(ItemLocalIdType item)
Read/write value of entity item.
void refersTo(const MeshVariableScalarRefT< ItemType, DataTypeT > &rhs)
Positions the instance reference to the variable rhs.
void swapValues(MeshVariableScalarRefT< ItemType, DataType > &rhs)
Swaps the values of the variable rhs with those of the instance.
MeshVariableScalarRefT(const MeshVariableScalarRefT< ItemType, DataTypeT > &rhs)
Constructs a reference from rhs.
const DataTypeT & operator[](ItemLocalIdType i) const
Read-only value of entity item.
MeshVariableScalarRefT(IVariable *var)
Constructs a reference from var.
const DataTypeT & operator()(ItemLocalIdType i) const
Read-only value of entity item.
PrivateVariableScalarT(const VariableBuildInfo &vb, const VariableInfo &vi)
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Information characterizing a variable.
VariableRef(const VariableBuildInfo &vbi)
Constructs a reference to a variable with the infos vbi.
Information characterizing the type of a variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eItemKind
Mesh entity type.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.