Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
VariableRefScalar.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/* VariableRefScalar.cc (C) 2000-2024 */
9/* */
10/* Reference to a scalar variable. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/VariableRefScalar.h"
15#include "arcane/core/VariableScalar.h"
16#include "arcane/core/VariableBuildInfo.h"
17#include "arcane/core/VariableInfo.h"
18#include "arcane/core/VariableDataTypeTraits.h"
19#include "arcane/core/VariableFactoryRegisterer.h"
20#include "arcane/core/IParallelMng.h"
21#include "arcane/core/IVariableMng.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32template <typename DataType> VariableFactoryRegisterer
34m_auto_registerer(_autoCreate, _buildVariableTypeInfo());
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39template <typename DataType> VariableTypeInfo
42{
43 return VariableTypeInfo(IK_Unknown, VariableDataTypeTraitsT<DataType>::type(), 0, 0, false);
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49template <typename DataType> VariableInfo
52{
53 VariableTypeInfo vti = _buildVariableTypeInfo();
54 DataStorageTypeInfo sti = vti._internalDefaultDataStorage();
55 return VariableInfo(vbi.name(), vbi.itemFamilyName(), vbi.itemGroupName(), vbi.meshName(), vti, sti);
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61template <typename DataType> VariableRef*
64{
65 return new ThatClass(vb);
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71template <typename DataType>
74: VariableRef(vb)
75, m_private_part(PrivatePartType::getReference(vb, _buildVariableInfo(vb)))
76{
77 _internalInit(m_private_part);
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83template <typename DataType>
86: VariableRef(var)
87, m_private_part(PrivatePartType::getReference(var))
88{
89 _internalInit(m_private_part);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95template <class DataType>
98: VariableRef(rhs)
99, m_private_part(rhs.m_private_part)
100{
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107template <class DataType> void
110{
112 m_private_part = rhs.m_private_part;
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119template <typename DataType> void
121assign(const DataType& v)
122{
123 m_private_part->value() = v;
124 m_private_part->syncReferences();
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130namespace
131{
132 template <typename T>
133 void _reduce(T& value, IParallelMng* pm, IParallelMng::eReduceType t, FalseType)
134 {
135 ARCANE_UNUSED(value);
136 ARCANE_UNUSED(pm);
137 ARCANE_UNUSED(t);
138 }
139
140 template <typename T>
141 void _reduce(T& value, IParallelMng* pm, IParallelMng::eReduceType t, TrueType)
142 {
143 T r = value;
144 value = pm->reduce(t, r);
145 }
146} // namespace
147
148template <typename DataType> void
150reduce(IParallelMng::eReduceType type)
151{
152 typedef typename VariableDataTypeTraitsT<ElementType>::HasReduce HasReduce;
153 ElementType v = m_private_part->value();
154 _reduce(v, variableMng()->parallelMng(), type, HasReduce());
155 assign(v);
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161template <typename T> void
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171/*!
172 * \brief Exchange the values of variable \a rhs with those of the instance.
173 */
174template <typename DataType> void
177{
178 this->m_private_part->swapValues(*(rhs.m_private_part));
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE(VariableRefScalarT);
185template class VariableRefScalarT<String>;
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190} // End namespace Arcane
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
Type information for a data container.
Interface of the parallelism manager for a subdomain.
Interface of a variable.
Definition IVariable.h:40
Parameters necessary for building a variable.
Information characterizing a variable.
Reference to a scalar variable.
VariableRefScalarT(const VariableBuildInfo &b)
Constructs a reference to a scalar variable specified in vb.
void refersTo(const VariableRefScalarT< DataType > &rhs)
Positions the instance's reference to the variable rhs.
void swapValues(VariableRefScalarT< DataType > &rhs)
Exchange the values of variable rhs with those of the instance.
VariableRefScalarT()
Default constructor.
void reduce(Parallel::eReduceType type)
Performs a type type reduction on the variable.
void assign(const DataType &v)
Assigns the value v to the variable.
virtual void updateFromInternal()
Updates from the internal part.
DataType ElementType
Type of the variable elements.
Reference to a variable.
Definition VariableRef.h:56
virtual void updateFromInternal()
Updates from the internal part.
VariableRef(const VariableBuildInfo &vbi)
Constructs a reference to a variable with the infos vbi.
VariableRef & operator=(const VariableRef &from)
Copy assignment operator.
void _internalInit(IVariable *)
Internal initialization of the variable.
IVariableMng * variableMng() const
Variable manager associated with the variable.
Information characterizing the type of a variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ IK_Unknown
Unknown or uninitialized mesh entity.