Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Variable.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/* Variable.h (C) 2000-2025 */
9/* */
10/* Class managing the private part of a variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_VARIABLE_H
13#define ARCANE_CORE_VARIABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/Array.h"
19
21#include "arcane/core/IVariable.h"
22#include "arcane/core/IData.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33class VariableInfo;
35template <typename T> class IDataTracerT;
36class VariablePrivate;
38class IParallelMng;
39class VariableResizeArgs;
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44/*!
45 * \internal
46 * \brief Instance of a variable.
47 *
48This class manages the data of a variable. This instance should generally
49not be used by code developers.
50 \todo explain better
51
52A variable is characterized by:
53 <ul>
54 <li>its <b>name</b>,</li>
55 <li>its <b>type</b>: real, integer, tensor, ...</li>,
56 <li>its <b>kind</b>: scalar, array, nodal quantity, cell-center quantity ...</li>
57 </ul>
58
59A variable based on a type of mesh entity is called a mesh variable.
60
61The variable is generally used by a module (IModule) via a reference (VariableRef).
62
63Variables are <b>persistent</b> and their reading/writing is done
64by the read() and write() methods.
65
66 \warning This class is entirely managed by Arcane, and modules
67that use it should generally only use it to retrieve information. Operations
68that modify this instance (such as setItemGroup())
69should only be used if the developer has a good understanding
70of their functioning.
71
72 * This class must not be copied.
73 */
74class ARCANE_CORE_EXPORT Variable
75: public TraceAccessor
76, public IVariable
77{
78 protected:
79
80 //! Creates a variable linked to the reference \a v.
81 Variable(const VariableBuildInfo& v, const VariableInfo& vi);
82
83 public:
84
85 //! Frees resources
86 ~Variable() override;
87
88 public:
89
90 //! Copy constructor (do not use)
91 Variable(const Variable& from) = delete;
92 //! Copy assignment operator (do not use)
93 Variable& operator=(const Variable& from) = delete;
94
95 public:
96
97 ISubDomain* subDomain() override;
98 IVariableMng* variableMng() const override;
99 String fullName() const final;
100 String name() const final;
101 String itemFamilyName() const final;
102 String meshName() const final;
103 String itemGroupName() const final;
104 int property() const override;
105 void notifyReferencePropertyChanged() override;
106
107 public:
108
109 //! Sets the usage state of the variable
110 void setUsed(bool v) override;
111
112 //! Usage state of the variable
113 bool isUsed() const override;
114
115 bool isPartial() const override;
116
117 public:
118
119 void setTraceInfo(Integer, eTraceType) override {}
120
121 public:
122
123 void read(IDataReader* d) override;
124 void write(IDataWriter* d) override;
125 void notifyEndRead() override;
126 void notifyBeginWrite() override;
127
128 public:
129
130 void addVariableRef(VariableRef* ref) override;
131 void removeVariableRef(VariableRef* ref) override;
132 VariableRef* firstReference() const override;
133 Integer nbReference() const override;
134
135 VariableMetaData* createMetaData() const override;
136 Ref<VariableMetaData> createMetaDataRef() const override;
137 void syncReferences() override;
138
139 IMesh* mesh() const final;
140 MeshHandle meshHandle() const final;
141 ItemGroup itemGroup() const final;
142 IItemFamily* itemFamily() const final;
143
144 eItemKind itemKind() const override;
145 Integer dimension() const override;
146 Integer multiTag() const override;
147 Int32 checkIfSync(Integer max_print) final;
148 Int32 checkIfSameOnAllReplica(Integer max_print) final;
149 Int32 checkIfSame(IDataReader* reader, Integer max_print, bool compare_ghost) final;
150
151 eDataType dataType() const override;
152 bool initialize(const ItemGroup& /*group*/, const String& /*value*/) override { return true; }
153
154 IDataFactoryMng* dataFactoryMng() const final;
155 void serialize(ISerializer* sbuffer, IDataOperation* operation) override;
156 void serialize(ISerializer* sbuffer, Int32ConstArrayView ids, IDataOperation* operation) override;
157
158 void resize(Integer n) override;
159 void resizeFromGroup() override;
160
161 void setAllocationInfo(const DataAllocationInfo& v) override;
162 DataAllocationInfo allocationInfo() const override;
163
164 public:
165
166 IObservable* writeObservable() override;
167 IObservable* readObservable() override;
168 IObservable* onSizeChangedObservable() override;
169
170 public:
171
172 void addTag(const String& tagname, const String& tagvalue) override;
173 void removeTag(const String& tagname) override;
174 bool hasTag(const String& tagname) override;
175 String tagValue(const String& tagname) override;
176
177 public:
178
179 void update() override;
180 void setUpToDate() override;
181 Int64 modifiedTime() override;
182 void addDepend(IVariable* var, eDependType dt) override;
183 void addDepend(IVariable* var, eDependType dt, const TraceInfo& tinfo) override;
184 void removeDepend(IVariable* var) override;
185 void setComputeFunction(IVariableComputeFunction* v) override;
186 IVariableComputeFunction* computeFunction() override;
187 void dependInfos(Array<VariableDependInfo>& infos) override;
188
189 void update(Real wanted_time) override;
190
191 void changeGroupIds(Int32ConstArrayView old_to_new_ids) override;
192
193 IVariableInternal* _internalApi() override;
194
195 public:
196
197 IMemoryAccessTrace* memoryAccessTrace() const override { return nullptr; }
198
199 protected:
200
201 void _setProperty(int property);
202
203 /*!
204 * \brief Positions the data.
205 *
206 * If data is null, a fatal error is sent
207 */
208 void _setData(const Ref<IData>& data);
209
210 //! Indicates if the variable data is valid
211 void _setValidData(bool valid_data);
212
213 /*!
214 * \brief Indicates if the variable data is valid.
215 *
216 * The data is valid at the end of a call to setUsed().
217 */
218 bool _hasValidData() const;
219
220 protected:
221
222 virtual void _internalResize(const VariableResizeArgs& resize_args) = 0;
223
224 void _checkSwapIsValid(Variable* rhs);
225 // Temporary for memory release test
226 bool _wantShrink() const;
227
228 // Access via VariablePrivate for internal API
229 friend class VariablePrivate;
230 void _resize(const VariableResizeArgs& resize_args);
231
232 //! Comparison of values between variables
234
235 private:
236
237 VariablePrivate* m_p; //!< Implementation
238
239 private:
240
241 void _checkSetItemFamily();
242 void _checkSetItemGroup();
243 void _checkSetProperty(VariableRef*);
244 bool _hasReference() const;
245 void _removeMeshReference();
246 VariableMetaData* _createMetaData() const;
247};
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252} // End namespace Arcane
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
257#endif
258
259#include "arcane/core/VariableScalar.h"
260#include "arcane/core/VariableArray.h"
Declarations of Arcane's general types.
Base class for 1D data vectors.
Information on data allocation.
Interface for reading variable data.
Definition IDataReader.h:35
Interface for writing variable data.
Definition IDataWriter.h:45
Interface of an entity family.
Definition IItemFamily.h:83
Interface of the parallelism manager for a subdomain.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface of the functor class for recalculating a variable.
Variable manager interface.
Interface of a variable.
Definition IVariable.h:40
Mesh entity group.
Definition ItemGroup.h:51
Handle on a mesh.
Definition MeshHandle.h:48
Reference to an instance.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
Parameters necessary for building a variable.
Arguments for VariableComparer methods.
Results of a comparison operation.
Information about a variable dependency.
Information characterizing a variable.
Metadata on a variable.
Reference to a variable.
Definition VariableRef.h:56
String itemGroupName() const final
Name of the associated entity group.
Definition Variable.cc:511
bool isUsed() const override
Usage state of the variable.
Definition Variable.cc:722
Variable(const VariableBuildInfo &v, const VariableInfo &vi)
Creates a variable linked to the reference v.
Definition Variable.cc:344
bool isPartial() const override
Indicates if the variable is partial.
Definition Variable.cc:900
void notifyReferencePropertyChanged() override
Definition Variable.cc:628
IVariableMng * variableMng() const override
Variable manager associated with the variable.
Definition Variable.cc:475
String name() const final
Variable name.
Definition Variable.cc:484
virtual VariableComparerResults _compareVariable(const VariableComparerArgs &compare_args)=0
Comparison of values between variables.
bool initialize(const ItemGroup &, const String &) override
Initializes the variable on a group.
Definition Variable.h:152
Variable(const Variable &from)=delete
Copy constructor (do not use).
void setUsed(bool v) override
Sets the usage state of the variable.
Definition Variable.cc:637
String fullName() const final
Full variable name (with family prefix).
Definition Variable.cc:493
ISubDomain * subDomain() override
Subdomain associated with the variable (TODO deprecate end of 2023).
Definition Variable.cc:466
String itemFamilyName() const final
Name of the associated family (null if none).
Definition Variable.cc:502
int property() const override
Definition Variable.cc:541
Variable & operator=(const Variable &from)=delete
Copy assignment operator (do not use).
String meshName() const final
Name of the associated mesh (null if none).
Definition Variable.cc:520
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
eTraceType
Possible trace type.
Definition DataTypes.h:194
eItemKind
Mesh entity type.
double Real
Type representing a real number.
eDataType
Data type.
Definition DataTypes.h:41
std::int32_t Int32
Signed integer type of 32 bits.