Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
VariableRefScalar.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/* VariableRefScalar.h (C) 2000-2025 */
9/* */
10/* Class managing a reference to a scalar variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_VARIABLEREFSCALAR_H
13#define ARCANE_CORE_VARIABLEREFSCALAR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/VariableRef.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
40template <typename DataType>
42: public VariableRef
43{
44 public:
45
47 typedef DataType ElementType;
50
51 typedef VariableScalarT<DataType> PrivatePartType;
52
53 typedef VariableRefScalarT<DataType> ThatClass;
54
55 public:
56
58 explicit ARCANE_CORE_EXPORT VariableRefScalarT(const VariableBuildInfo& b);
60 ARCANE_CORE_EXPORT VariableRefScalarT(const VariableRefScalarT<DataType>& rhs);
62 explicit ARCANE_CORE_EXPORT VariableRefScalarT(IVariable* var);
64 ARCANE_CORE_EXPORT void refersTo(const VariableRefScalarT<DataType>& rhs);
65
66#ifdef ARCANE_DOTNET
67 public:
68
69#else
70 protected:
71#endif
72
75 : m_private_part(nullptr)
76 {}
77
78 public:
79
80 virtual bool isArrayVariable() const { return false; }
81 virtual Integer arraySize() const { return 0; }
82 virtual ARCANE_CORE_EXPORT void updateFromInternal();
83
84 public:
85
86 ArrayView<DataType> asArray() { return ArrayView<DataType>(1, &(m_private_part->value())); }
87 ConstArrayView<DataType> asArray() const { return ConstArrayView<DataType>(1, &(m_private_part->value())); }
88
89 public:
90
91 void operator=(const DataType& v) { assign(v); }
93 {
94 assign(v());
95 return (*this);
96 }
97
99 void reset() { assign(DataType()); }
100
102 const DataType& operator()() const { return m_private_part->value(); }
103
105 const DataType& value() const { return m_private_part->value(); }
106
110 bool isEqual(const DataType& v) const
111 {
112 return math::isEqual(m_private_part->value(), v);
113 }
114
119 bool isZero() const
120 {
121 return math::isZero(m_private_part->value());
122 }
123
130 bool isNearlyEqual(const DataType& v) const
131 {
132 return math::isNearlyEqual(m_private_part->value(), v);
133 }
134
138 bool isNearlyZero() const
139 {
140 return math::isNearlyZero(m_private_part->value());
141 }
142
144 ARCANE_CORE_EXPORT void assign(const DataType& v);
145
147 ARCANE_CORE_EXPORT void reduce(Parallel::eReduceType type);
148
149 ARCANE_CORE_EXPORT void swapValues(VariableRefScalarT<DataType>& rhs);
150
151 protected:
152 private:
153
154 PrivatePartType* m_private_part;
155
156 private:
157
158 static VariableFactoryRegisterer m_auto_registerer;
159 static VariableTypeInfo _buildVariableTypeInfo();
160 static VariableInfo _buildVariableInfo(const VariableBuildInfo& vbi);
161 static VariableRef* _autoCreate(const VariableBuildInfo& vb);
162};
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167} // End namespace Arcane
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
172#endif
Various mathematical functions.
File containing declarations concerning the message passing model.
Modifiable view of an array of type T.
Constant view of an array of type T.
Interface of a variable.
Definition IVariable.h:40
Parameters necessary for building a variable.
Information characterizing a 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.
const DataType & value() const
Scalar value.
void swapValues(VariableRefScalarT< DataType > &rhs)
Exchange the values of variable rhs with those of the instance.
virtual Integer arraySize() const
If the variable is an array, returns its dimension, otherwise returns 0.
bool isNearlyZero() const
Compares the variable with the value 0.
const DataType & operator()() const
Scalar value.
void reset()
Resets the variable to its default value.
VariableRefScalarT()
Default constructor.
bool isEqual(const DataType &v) const
Compares the variable with the value v.
VariableRefScalarT(IVariable *var)
Constructs a reference from var.
bool isNearlyEqual(const DataType &v) const
Compares the variable with the value v.
void reduce(Parallel::eReduceType type)
Performs a type type reduction on the variable.
VariableRef BaseClass
Type of the base class.
VariableRefScalarT(const VariableRefScalarT< DataType > &rhs)
Constructs a reference from rhs.
bool isZero() const
Compares the variable with the value 0.
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.
VariableRef(const VariableBuildInfo &vbi)
Constructs a reference to a variable with the infos vbi.
Information characterizing the type of a variable.
eReduceType
Supported reduction types.
constexpr __host__ __device__ bool isNearlyEqual(const _Type &a, const _Type &b)
Tests if two values are approximately equal. For integer types, this function is equivalent to IsEqua...
Definition Numeric.h:219
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
Definition Numeric.h:260
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.