Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshVariableArrayRef.inst.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/* MeshVariableArrayRef.inst.h (C) 2000-2025 */
9/* */
10/* Mesh variable vector. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/MeshVariableArrayRef.h"
15
16#include "arcane/utils/ValueConvert.h"
17#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/core/ItemGroup.h"
20#include "arcane/core/VariableDataTypeTraits.h"
21#include "arcane/core/VariableTypeInfo.h"
22#include "arcane/core/VariableBuildInfo.h"
23#include "arcane/core/VariableInfo.h"
24#include "arcane/core/VariableFactoryRegisterer.h"
25#include "arcane/core/internal/IDataInternal.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36template <typename DataType> VariableTypeInfo
39{
40 eDataType dt = VariableDataTypeTraitsT<DataType>::type();
41 return VariableTypeInfo(ik, dt, 2, 0, false);
42}
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47template <typename DataType> VariableInfo
50{
51 VariableTypeInfo vti = _internalVariableTypeInfo(ik);
52 DataStorageTypeInfo sti = vti._internalDefaultDataStorage();
53 return VariableInfo(vbi.name(), vbi.itemFamilyName(), vbi.itemGroupName(), vbi.meshName(), vti, sti);
54}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59template <class DataType>
62: PrivateVariableArrayT<DataType>(vb, _internalVariableInfo(vb, ik))
63{
64 if (!vb.isNull()) {
65 this->_internalInit();
66 if (this->m_private_part->isPartial())
67 ARCANE_FATAL("Can not assign a partial variable to a full variable");
68 }
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74template <class DataType> ItemVariableArrayRefT<DataType>::
76: PrivateVariableArrayT<DataType>(var)
77{
78 this->_internalInit();
79 if (this->m_private_part->isPartial())
80 ARCANE_FATAL("Can not assign a partial variable to a full variable");
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86template <class DataType> ItemVariableArrayRefT<DataType>::
88: PrivateVariableArrayT<DataType>(rhs)
89{
90 if (this->m_private_part)
91 this->updateFromInternal();
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97template <class DataType> ItemVariableArrayRefT<DataType>&
100{
101 if (this != &rhs) {
102 BaseClass::operator=(rhs);
103 if (this->m_private_part) {
104 this->m_private_part = rhs.m_private_part;
105 this->updateFromInternal();
106 }
107 }
108 return (*this);
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117template <class ItemType, class DataType> VariableFactoryRegisterer
119m_auto_registerer(_autoCreate, _internalVariableTypeInfo());
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
124template <typename ItemType, typename DataType> VariableTypeInfo
127{
129 eDataType dt = VariableDataTypeTraitsT<DataType>::type();
130 return VariableTypeInfo(ik, dt, 2, 0, false);
131}
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136template <typename ItemType, typename DataType> VariableInfo
137MeshVariableArrayRefT<ItemType, DataType>::
138_internalVariableInfo(const VariableBuildInfo& vbi)
139{
140 VariableTypeInfo vti = _internalVariableTypeInfo();
141 DataStorageTypeInfo sti = vti._internalDefaultDataStorage();
142 return VariableInfo(vbi.name(), vbi.itemFamilyName(), vbi.itemGroupName(), vbi.meshName(), vti, sti);
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148template <class ItemType, class DataType> VariableRef*
151
152{
153 return new ThatClass(vb);
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159template <class ItemType, class DataType>
162: ItemVariableArrayRefT<DataType>(vb, ItemTraitsT<ItemType>::kind())
163{
164 // Normally, this class should perform the initialization but
165 // since this class is just a wrapper around ItemVariableArrayRefT
166 // and does nothing else, we leave the initialization to the base class,
167 // which allows a variable to be generically created on
168 // a mesh entity based on its type.
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174template <class ItemType, class DataType>
177: ItemVariableArrayRefT<DataType>(var)
178{
179 // Normally, this class should perform the initialization but
180 // since this class is just a wrapper around ItemVariableArrayRefT
181 // and does nothing else, we leave the initialization to the base class,
182 // which allows a variable to be generically created on
183 // a mesh entity based on its type.
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189template <class ItemType, class DataType>
192: ItemVariableArrayRefT<DataType>(rhs)
193{
194 // Normally, this class should perform the initialization but
195 // since this class is just a wrapper around ItemVariableArrayRefT
196 // and does nothing else, we leave the initialization to the base class,
197 // which allows a variable to be generically created on
198 // a mesh entity based on its type.
199}
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204template <class ItemType, class DataType>
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217template <class ItemType, class DataType>
218typename Arcane::MeshVariableArrayRefT<ItemType, DataType>::GroupType
220itemGroup() const
221{
222 return GroupType(this->m_private_part->itemGroup());
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228template <class DataType>
230fill(const DataType& v)
231{
232 this->fill(v, this->itemGroup());
233}
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238template <class DataType>
240fill(const DataType& value, const ItemGroup& group)
241{
242 ENUMERATE_ITEM (iitem, group) {
243 operator[](iitem).fill(value);
244 }
245}
246
247/*---------------------------------------------------------------------------*/
248/*---------------------------------------------------------------------------*/
249
250template <typename DataType>
253{
254 this->copy(v, this->itemGroup());
255}
256
257/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260template <typename DataType>
262copy(const ItemVariableArrayRefT<DataType>& v, const ItemGroup& group)
263{
264 ENUMERATE_ITEM (iitem, group) {
265 operator[](iitem).copy(v[iitem]);
266 }
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
272template <typename DataTypeT> void
275{
276 if (!queue) {
277 copy(v);
278 return;
279 }
280 impl::copyContiguousData(this->m_private_part->data(), v.m_private_part->data(), *queue);
281}
282
283/*---------------------------------------------------------------------------*/
284/*---------------------------------------------------------------------------*/
285
286template <typename DataTypeT> void
288fill(const DataTypeT& v, RunQueue* queue)
289{
290 if (!queue) {
291 fill(v);
292 return;
293 }
294 impl::fillContiguousData(this->m_private_part->data(), v, *queue);
295}
296
297/*---------------------------------------------------------------------------*/
298/*---------------------------------------------------------------------------*/
299
308template <class ItemType, class DataTypeT> void
311{
312 this->m_private_part->swapValues(*(rhs.m_private_part));
313}
314
315/*---------------------------------------------------------------------------*/
316/*---------------------------------------------------------------------------*/
317
318} // End namespace Arcane
319
320/*---------------------------------------------------------------------------*/
321/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
IData * data() override
Data associated with the variable.
Type information for a data container.
Interface of a variable.
Definition IVariable.h:40
Mesh entity group.
Definition ItemGroup.h:51
Characteristics of mesh elements.
Definition ItemTypes.h:625
static eItemKind kind()
Entity kind.
Definition ItemTypes.h:629
Array variable on a mesh entity type.
void copy(const ItemVariableArrayRefT< DataType > &v)
Copies the values of v into this variable.
ItemVariableArrayRefT(const VariableBuildInfo &b, eItemKind ik)
Constructs a reference to the variable specified in vb.
ConstArrayType operator[](ItemLocalId item) const
Read-only value of entity item.
ItemVariableArrayRefT< DataType > & operator=(const ItemVariableArrayRefT< DataType > &rhs)
Positions the instance reference to the variable rhs.
void fill(const DataType &value)
Fills the variable with the value value.
Array variable on a mesh entity type.
GroupType itemGroup() const
Group associated with the quantity.
void swapValues(MeshVariableArrayRefT< ItemType, DataType > &rhs)
Swaps the values of the variable rhs with those of the instance.
void refersTo(const MeshVariableArrayRefT< ItemType, DataType > &rhs)
Positions the instance reference to the variable rhs.
MeshVariableArrayRefT(const VariableBuildInfo &b)
Constructs a reference to the variable specified in vb.
Parameters necessary for building a variable.
Information characterizing a variable.
Reference to a variable.
Definition VariableRef.h:56
Information characterizing the type of a variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eItemKind
Mesh entity type.
eDataType
Data type.
Definition DataTypes.h:41