Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshEnvironmentVariableRef.cc
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/* MeshMaterialVariableRef.cc (C) 2000-2024 */
9/* */
10/* Reference to a variable on a mesh material. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/TraceInfo.h"
18#include "arcane/utils/NumericTypes.h"
19
20#include "arcane/MeshVariableScalarRef.h"
21#include "arcane/ArcaneException.h"
22
23#include "arcane/core/materials/IMeshMaterialMng.h"
24#include "arcane/core/materials/IMeshMaterial.h"
25#include "arcane/core/materials/MaterialVariableBuildInfo.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane::Materials
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36template <typename DataType> CellEnvironmentVariableScalarRef<DataType>::
37CellEnvironmentVariableScalarRef(const VariableBuildInfo& vb)
39{
40}
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45template <typename DataType> CellEnvironmentVariableScalarRef<DataType>::
46CellEnvironmentVariableScalarRef(const MaterialVariableBuildInfo& vb)
47: m_private_part(PrivatePartType::BuilderType::getVariableReference(vb, MatVarSpace::Environment))
48, m_value(nullptr)
49{
50 _init();
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56template <typename DataType> CellEnvironmentVariableScalarRef<DataType>::
58: m_private_part(rhs.m_private_part)
59, m_value(nullptr)
60{
61 // The reference counter must be manually incremented because normally
62 // this is done in getReference(), but here it is not called
63 if (m_private_part)
64 m_private_part->incrementReference();
65
66 _init();
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75template <typename DataType> void
77_init()
78{
79 if (m_private_part) {
80 this->_setContainerView();
81 _internalInit(m_private_part->toMeshMaterialVariable());
82 }
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88template <typename DataType> void
90refersTo(const CellEnvironmentVariableScalarRef<DataType>& rhs)
91{
92 if (rhs.m_private_part == m_private_part)
93 return;
94 if (_isRegistered())
96
97 m_private_part = rhs.m_private_part;
98 m_value = nullptr;
99 m_container_value = {};
100
101 // The reference counter must be manually incremented because normally
102 // this is done in getReference(), but here it is not called
103 if (m_private_part)
104 m_private_part->incrementReference();
105 _init();
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111template <typename DataType> void
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121template <typename DataType> DataType
123envValue(AllEnvCell c, Int32 env_id) const
124{
125 ENUMERATE_CELL_ENVCELL (ienvcell, c) {
126 EnvCell ec = *ienvcell;
127 Int32 eid = ec.environmentId();
128 if (eid == env_id)
129 return this->operator[](ienvcell);
130 }
131 return DataType();
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
140template <typename DataType> void
142fill(const DataType& value)
143{
144 globalVariable().fill(value);
145 fillPartialValues(value);
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
154template <typename DataType> void
156fillPartialValues(const DataType& value)
157{
158 m_private_part->fillPartialValues(value);
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167template <typename DataType> MeshVariableScalarRefT<Cell, DataType>&
170{
171 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
172 if (!rt)
173 ARCANE_FATAL("null global variable");
174 return *rt;
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180template <typename DataType> const MeshVariableScalarRefT<Cell, DataType>&
182globalVariable() const
183{
184 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
185 if (!rt)
186 ARCANE_FATAL("null global variable");
187 return *rt;
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193template <typename DataType> void
196{
197 if (m_private_part) {
198 m_container_value = m_private_part->_internalFullValuesView();
199 m_value = m_container_value.data();
200 }
201 else {
202 m_container_value = {};
203 m_value = nullptr;
204 }
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213// TODO: merge with the scalar version
214template <typename DataType> CellEnvironmentVariableArrayRef<DataType>::
215CellEnvironmentVariableArrayRef(const VariableBuildInfo& vb)
217{
218}
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
222
223// TODO: merge with the scalar version
226: m_private_part(PrivatePartType::BuilderType::getVariableReference(vb, MatVarSpace::Environment))
227, m_value(nullptr)
228{
229 _init();
230}
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
235// TODO: merge with the scalar version
236template <typename DataType> CellEnvironmentVariableArrayRef<DataType>::
238: m_private_part(rhs.m_private_part)
239, m_value(nullptr)
240{
241 // The reference counter must be manually incremented because normally
242 // this is done in getReference(), but here it is not called
243 if (m_private_part)
244 m_private_part->incrementReference();
245
246 _init();
247}
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252// TODO: merge with the scalar version
253template <typename DataType> void
255_init()
256{
257 if (m_private_part) {
258 _setContainerView();
259 _internalInit(m_private_part->toMeshMaterialVariable());
260 }
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
266// TODO: merge with the scalar version
267template <typename DataType> void
269refersTo(const CellEnvironmentVariableArrayRef<DataType>& rhs)
270{
271 if (rhs.m_private_part == m_private_part)
272 return;
273 if (_isRegistered())
275
276 m_private_part = rhs.m_private_part;
277 m_value = nullptr;
278 m_container_value = {};
279
280 // The reference counter must be manually incremented because normally
281 // this is done in getReference(), but here it is not called
282 if (m_private_part)
283 m_private_part->incrementReference();
284 _init();
285}
286
287/*---------------------------------------------------------------------------*/
288/*---------------------------------------------------------------------------*/
289
290// TODO: merge with the scalar version
291template <typename DataType> void
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
300
301template <typename DataType> MeshVariableArrayRefT<Cell, DataType>&
304{
305 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
306 if (!rt)
307 ARCANE_FATAL("null global variable");
308 return *rt;
309}
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
314template <typename DataType> const MeshVariableArrayRefT<Cell, DataType>&
316globalVariable() const
317{
318 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
319 if (!rt)
320 ARCANE_FATAL("null global variable");
321 return *rt;
322}
323
324/*---------------------------------------------------------------------------*/
325/*---------------------------------------------------------------------------*/
326
327template <typename DataType> void
329resize(Integer dim2_size)
330{
331 m_private_part->resize(dim2_size);
332}
333
334/*---------------------------------------------------------------------------*/
335/*---------------------------------------------------------------------------*/
336
337template <typename DataType> void
340{
341 if (m_private_part) {
342 m_container_value = m_private_part->_internalFullValuesView();
343 m_value = m_container_value.data();
344 }
345 else {
346 m_container_value = {};
347 m_value = nullptr;
348 }
349}
350
351/*---------------------------------------------------------------------------*/
352/*---------------------------------------------------------------------------*/
353
354/*---------------------------------------------------------------------------*/
355/*---------------------------------------------------------------------------*/
356
357#define ARCANE_INSTANTIATE_MAT(type) \
358 template class ARCANE_TEMPLATE_EXPORT CellEnvironmentVariableScalarRef<type>; \
359 template class ARCANE_TEMPLATE_EXPORT CellEnvironmentVariableArrayRef<type>
360
361ARCANE_INSTANTIATE_MAT(Byte);
362ARCANE_INSTANTIATE_MAT(Int8);
363ARCANE_INSTANTIATE_MAT(Int16);
364ARCANE_INSTANTIATE_MAT(Int32);
365ARCANE_INSTANTIATE_MAT(Int64);
366ARCANE_INSTANTIATE_MAT(BFloat16);
367ARCANE_INSTANTIATE_MAT(Float16);
368ARCANE_INSTANTIATE_MAT(Float32);
369ARCANE_INSTANTIATE_MAT(Real);
370ARCANE_INSTANTIATE_MAT(Real2);
371ARCANE_INSTANTIATE_MAT(Real3);
372ARCANE_INSTANTIATE_MAT(Real2x2);
373ARCANE_INSTANTIATE_MAT(Real3x3);
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
377
378} // namespace Arcane::Materials
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Arcane cell with material and environment information.
Array variable on the cells of a mesh material. For now, this class is only instantiated for cells.
GlobalVariableRefType & globalVariable()
Global variable associated with this material variable.
virtual void refersTo(const ThatClass &rhs)
Positions the instance reference to the variable rhs.
CellEnvironmentVariableArrayRef()=delete
Default constructor (deleted).
void resize(Integer dim2_size)
Resizes the number of elements in the array.
DataType envValue(AllEnvCell c, Int32 env_id) const
Value of the variable for the environment index env_id of cell or 0 if absent from the cell.
void fillPartialValues(const DataType &value)
Fills the partial values of the variable with the value value.
GlobalVariableRefType & globalVariable()
Global variable associated with this material variable.
virtual void refersTo(const ThatClass &rhs)
Positions the instance reference to the variable rhs.
CellEnvironmentVariableScalarRef()=delete
Default constructor (deleted).
void fill(const DataType &value)
Fills the partial and global values of the variable with the value value.
Arcane cell of an environment.
__host__ __device__ Int32 environmentId() const
Environment identifier.
void unregisterVariable()
Unregisters the variable (internal).
Array variable on a mesh entity type.
Scalar variable on a mesh entity type.
#define ENUMERATE_CELL_ENVCELL(iname, all_env_cell)
Macro to iterate over all EnvCell cells of a cell.
Always enables tracing in Arcane parts concerning materials.
MatVarSpace
Definition space for a material variable.
@ Environment
Variable having values only on environments.
std::int8_t Int8
Signed integer type of 8 bits.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
float Float32
IEEE-753 single-precision floating-point type.
std::int32_t Int32
Signed integer type of 32 bits.