Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Real2x2Proxy.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/* Real2x2Proxy.h (C) 2000-2008 */
9/* */
10/* Proxy of type 'Real2x2'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_REAL2X2PROXY_H
13#define ARCANE_UTILS_REAL2X2PROXY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Real2x2.h"
18#include "arcane/utils/Real2Proxy.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29/*!
30 * \brief Proxy of type 'Real2x2'.
31 */
32class ARCANE_UTILS_EXPORT Real2x2Proxy
33{
34 public:
35
36 //! Constructs the pair (ax,ay)
38 : x(value.x, info)
39 , y(value.y, info)
40 , m_value(value)
41 , m_info(info)
42 {}
43
44 //! Constructs a pair identical to \a f
46 : x(f.x)
47 , y(f.y)
48 , m_value(f.m_value)
49 , m_info(f.m_info)
50 {}
51 const Real2x2Proxy& operator=(const Real2x2Proxy& f)
52 {
53 x = f.x;
54 y = f.y;
55 return (*this);
56 }
57 const Real2x2Proxy& operator=(Real2x2 f)
58 {
59 x = f.x;
60 y = f.y;
61 return (*this);
62 }
63
64 //! Assigns the triplet (v,v,v) to the instance.
66 {
67 x = v;
68 y = v;
69 return (*this);
70 }
71
72 public:
73
74 Real2Proxy x; //!< First component
75 Real2Proxy y; //!< Second component
76
77 private:
78
79 Real2x2& m_value;
80 MemoryAccessInfo m_info;
81
82 public:
83
84 //! Returns a copy of the pair.
85 Real2x2 copy() const { return getValue(); }
86
87 //! Resets the pair using default constructors.
89 {
90 *this = Real2x2::null();
91 return (*this);
92 }
93
94 //! Assigns the triplet (ax,ay,az) to the instance
96 {
97 x = ax;
98 y = ay;
99 return (*this);
100 }
101
102 //! Copies the pair \a f
104 {
105 x = f.x;
106 y = f.y;
107 return (*this);
108 }
109 operator const Real2x2&() const
110 {
111 return getValue();
112 }
113 //operator Real2x2&()
114 //{
115 // return getValueMutable();
116 //}
117
118 /*!
119 * \brief Compares the matrix with the zero matrix.
120 *
121 * The matrix is zero if and only if each of its components
122 * is less than a given epsilon. The epsilon value used is that
123 * of float_info<value_type>::nearlyEpsilon():
124 * \f[A=0 \Leftrightarrow |A.x|<\epsilon,|A.y|<\epsilon\f]
125 *
126 * \retval true if the matrix is equal to the zero matrix,
127 * \retval false otherwise.
128 */
129 bool isNearlyZero() const
130 {
131 return x.isNearlyZero() && y.isNearlyZero();
132 }
133
134 /*!
135 * \brief Reads the matrix from the stream \a i
136 * The matrix is read in the form of three Real2s.
137 */
138 istream& assign(istream& i);
139
140 //! Writes the pair to the stream \a o readable by an assign()
141 ostream& print(ostream& o) const;
142
143 //! Writes the pair to the stream \a o in the form (x,y,z)
144 ostream& printXy(ostream& o) const;
145
146 //! Adds \a b to the pair
148 {
149 x += b.x;
150 y += b.y;
151 return (*this);
152 }
153
154 //! Subtracts \a b from the pair
156 {
157 x -= b.x;
158 y -= b.y;
159 return (*this);
160 }
161
162 //! Multiplies each component of the pair by the corresponding component of \a b
163 //Real2x2Proxy& mul(Real2x2Proxy b) { x*=b.x; y*=b.y; return (*this); }
164
165 //! Divides each component of the pair by the corresponding component of \a b
167 {
168 x /= b.x;
169 y /= b.y;
170 return (*this);
171 }
172
173 //! Adds \a b to each component of the pair
175 {
176 x += b;
177 y += b;
178 return (*this);
179 }
180
181 //! Subtracts \a b from each component of the pair
183 {
184 x -= b;
185 y -= b;
186 return (*this);
187 }
188
189 //! Multiplies each component of the pair by \a b
191 {
192 x *= b;
193 y *= b;
194 return (*this);
195 }
196
197 //! Divides each component of the pair by \a b
199 {
200 x /= b;
201 y /= b;
202 return (*this);
203 }
204
205 //! Adds \a b to the pair.
207
208 //! Subtracts \a b from the pair
210
211 //! Multiplies each component of the pair by the corresponding component of \a b
212 //Real2x2Proxy& operator*=(Real2x2Proxy b) { return mul(b); }
213
214 //! Multiplies each component of the matrix by the real \a b
216 {
217 x *= b;
218 y *= b;
219 }
220
221 //! Divides each component of the pair by the corresponding component of \a b
222 //Real2x2Proxy& operator/= (Real2x2 b) { return div(b); }
223
224 //! Divides each component of the matrix by the real \a b
226 {
227 x /= b;
228 y /= b;
229 }
230
231 //! Creates a pair that equals this pair added to \a b
232 Real2x2 operator+(Real2x2 b) const { return Real2x2(x + b.x, y + b.y); }
233
234 //! Creates a pair that equals \a b subtracted from this pair
235 Real2x2 operator-(Real2x2 b) const { return Real2x2(x - b.x, y - b.y); }
236
237 //! Creates a tensor opposite to the current tensor
238 Real2x2 operator-() const { return Real2x2(-x, -y); }
239
240 /*!
241 * \brief Creates a pair that equals this pair whose each component has been
242 * multiplied by the corresponding component of \a b.
243 */
244 //Real2x2 operator*(Real2x2Proxy b) const { return Real2x2Proxy(x*b.x,y*b.y); }
245
246 /*!
247 * \brief Creates a pair that equals this pair whose each component has been divided
248 * by the corresponding component of \a b.
249 */
250 //Real2x2Proxy operator/(Real2x2Proxy b) const { return Real2x2Proxy(x/b.x,y/b.y); }
251
252 public:
253
254 const Real2x2& getValue() const
255 {
256 m_info.setRead();
257 return m_value;
258 }
259 Real2x2& getValueMutable()
260 {
261 m_info.setReadOrWrite();
262 return m_value;
263 }
264
265 private:
266
267 /*!
268 * \brief Compares the values of \a a and \a b with the TypeEqualT comparator
269 * \retval true if \a a and \a b are equal,
270 * \retval false otherwise.
271 */
272 static bool _eq(Real a, Real b)
273 {
274 return TypeEqualT<Real>::isEqual(a, b);
275 }
276};
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
281inline bool
282operator==(const Real2x2& a, const Real2x2Proxy& b)
283{
284 return a == b.getValue();
285}
286inline bool
287operator==(const Real2x2Proxy& a, const Real2x2& b)
288{
289 return a.getValue() == b;
290}
291inline bool
292operator==(const Real2x2Proxy& a, const Real2x2Proxy& b)
293{
294 return a.getValue() == b.getValue();
295}
296
297/*---------------------------------------------------------------------------*/
298/*---------------------------------------------------------------------------*/
299
300inline bool
301operator!=(const Real2x2& a, const Real2x2Proxy& b)
302{
303 return a != b.getValue();
304}
305inline bool
306operator!=(const Real2x2Proxy& a, const Real2x2& b)
307{
308 return a.getValue() != b;
309}
310inline bool
311operator!=(const Real2x2Proxy& a, const Real2x2Proxy& b)
312{
313 return a.getValue() != b.getValue();
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
319/*!
320 * \brief Writes the pair \a t to the stream \a o
321 * \relates Real2x2Proxy
322 */
323inline ostream&
324operator<<(ostream& o, const Real2x2Proxy& t)
325{
326 return t.printXy(o);
327}
328
329/*!
330 * \brief Reads the pair \a t from the stream \a o.
331 * \relates Real2x2Proxy
332 */
333inline istream&
335{
336 return t.assign(i);
337}
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342/*! \brief Multiplication by a scalar. */
343inline Real2x2
345{
346 return Real2x2(vec.x * sca, vec.y * sca);
347}
348
349/*---------------------------------------------------------------------------*/
350/*---------------------------------------------------------------------------*/
351
352/*! \brief Multiplication by a scalar. */
353inline Real2x2
355{
356 return Real2x2(vec.x * sca, vec.y * sca);
357}
358
359/*---------------------------------------------------------------------------*/
360/*---------------------------------------------------------------------------*/
361
362/*! \brief Division by a scalar. */
363inline Real2x2
365{
366 return Real2x2(vec.x / sca, vec.y / sca);
367}
368
369/*---------------------------------------------------------------------------*/
370/*---------------------------------------------------------------------------*/
371
372/*!
373 * \brief Comparison operator.
374 *
375 * This operator allows Real2s to be sorted for example
376 * in std::set
377 */
378inline bool
379operator<(const Real2x2Proxy& v1, const Real2x2Proxy& v2)
380{
381 return (v1.getValue() < v2.getValue());
382}
383
384/*---------------------------------------------------------------------------*/
385/*---------------------------------------------------------------------------*/
386
387} // namespace Arcane
388
389/*---------------------------------------------------------------------------*/
390/*---------------------------------------------------------------------------*/
391
392#endif
Class managing a 2-dimensional real vector.
Definition Real2Proxy.h:41
RealProxy x
first component of the pair
Definition Real2Proxy.h:88
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Proxy of type 'Real2x2'.
Real2x2 operator-(Real2x2 b) const
Creates a pair that equals b subtracted from this pair.
Real2x2Proxy & divSame(Real2 b)
Divides each component of the pair by b.
ostream & print(ostream &o) const
Writes the pair to the stream o readable by an assign().
Real2x2Proxy & add(Real2x2 b)
Adds b to the pair.
bool isNearlyZero() const
Compares the matrix with the zero matrix.
istream & operator>>(istream &i, Real2x2Proxy &t)
Reads the pair t from the stream o.
void operator*=(Real b)
Multiplies each component of the pair by the corresponding component of b.
Real2x2Proxy & assign(Real2x2Proxy f)
Copies the pair f.
Real2x2Proxy(const Real2x2Proxy &f)
Constructs a pair identical to f.
Real2x2Proxy & mulSame(Real2 b)
Multiplies each component of the pair by b.
Real2x2 operator-() const
Creates a tensor opposite to the current tensor.
Real2x2Proxy & operator+=(Real2x2 b)
Adds b to the pair.
Real2x2Proxy & subSame(Real2 b)
Subtracts b from each component of the pair.
Real2x2Proxy(Real2x2 &value, const MemoryAccessInfo &info)
Constructs the pair (ax,ay).
Real2x2 operator+(Real2x2 b) const
Creates a pair that equals this pair added to b.
Real2x2Proxy & addSame(Real2 b)
Adds b to each component of the pair.
const Real2x2Proxy & operator=(Real v)
Assigns the triplet (v,v,v) to the instance.
Real2x2Proxy & operator-=(Real2x2 b)
Subtracts b from the pair.
Real2x2Proxy & div(Real2x2 b)
Multiplies each component of the pair by the corresponding component of b.
const Real2x2 & getValue() const
Creates a pair that equals this pair whose each component has been multiplied by the corresponding co...
Real2Proxy x
First component.
istream & assign(istream &i)
Reads the matrix from the stream i The matrix is read in the form of three Real2s.
Real2x2Proxy & assign(Real2 ax, Real2 ay)
Assigns the triplet (ax,ay,az) to the instance.
Real2Proxy y
Second component.
Real2x2Proxy & reset()
Resets the pair using default constructors.
Real2x2Proxy & sub(Real2x2 b)
Subtracts b from the pair.
Real2x2 copy() const
Returns a copy of the pair.
ostream & printXy(ostream &o) const
Writes the pair to the stream o in the form (x,y,z).
void operator/=(Real b)
Divides each component of the pair by the corresponding component of b.
Class managing a 2x2 matrix of reals.
Definition Real2x2.h:55
Real2 x
First component.
Definition Real2x2.h:112
Real2 y
Second component.
Definition Real2x2.h:113
constexpr __host__ static __device__ Real2x2 null()
Constructs the zero matrix.
Definition Real2x2.h:118
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Real2 operator*(Real sca, const Real2Proxy &vec)
Multiplication by a scalar.
Definition Real2Proxy.h:364
bool operator<(const Item &item1, const Item &item2)
Compare two entities.
Definition Item.h:566
double Real
Type representing a real number.
Real2 operator/(const Real2Proxy &vec, Real sca)
Division by a scalar.
Definition Real2Proxy.h:388
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.