Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Real3Proxy.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/* Real3Proxy.h (C) 2000-2018 */
9/* */
10/* Proxy for a 'Real3'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_REAL3PROXY_H
13#define ARCANE_UTILS_REAL3PROXY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Real3.h"
18#include "arcane/utils/BuiltInProxy.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29typedef BuiltInProxy<Real> RealProxy;
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
37class ARCANE_UTILS_EXPORT Real3Proxy
38: public Real3POD
39{
40 public:
41
43 Real3Proxy(Real3& value, const MemoryAccessInfo& info)
44 : x(value.x, info)
45 , y(value.y, info)
46 , z(value.z, info)
47 , m_value(value)
48 , m_info(info)
49 {}
50
53 : x(f.x)
54 , y(f.y)
55 , z(f.z)
56 , m_value(f.m_value)
57 , m_info(f.m_info)
58 {}
59 Real3 operator=(const Real3Proxy f)
60 {
61 x = f.x;
62 y = f.y;
63 z = f.z;
64 return m_value;
65 }
66 Real3 operator=(Real3 f)
67 {
68 x = f.x;
69 y = f.y;
70 z = f.z;
71 return m_value;
72 }
73
76 {
77 x = v;
78 y = v;
79 z = v;
80 return m_value;
81 }
82 operator Real3() const
83 {
84 return getValue();
85 }
86 //operator Real3&()
87 //{
88 // return getValueMutable();
89 //}
90 public:
91
92 RealProxy x;
93 RealProxy y;
94 RealProxy z;
95
96 private:
97
98 Real3& m_value;
99 MemoryAccessInfo m_info;
100
101 public:
102
104 Real3 copy() const { return Real3(x, y, z); }
105
108 {
109 x = y = z = 0.;
110 return (*this);
111 }
112
115 {
116 x = ax;
117 y = ay;
118 z = az;
119 return (*this);
120 }
121
124 {
125 x = f.x;
126 y = f.y;
127 z = f.z;
128 return (*this);
129 }
130
146 bool isNearlyZero() const
147 {
148 return math::isNearlyZero(x.getValue()) && math::isNearlyZero(y.getValue()) && math::isNearlyZero(z.getValue());
149 }
150
152 Real abs2() const
153 {
154 return x * x + y * y + z * z;
155 }
156
158 Real abs() const
159 {
160 return _sqrt(abs2());
161 }
162
167 std::istream& assign(std::istream& i);
168
170 std::ostream& print(std::ostream& o) const;
171
173 std::ostream& printXyz(std::ostream& o) const;
174
177 {
178 x += b.x;
179 y += b.y;
180 z += b.z;
181 return (*this);
182 }
183
186 {
187 x -= b.x;
188 y -= b.y;
189 z -= b.z;
190 return (*this);
191 }
192
195 {
196 x *= b.x;
197 y *= b.y;
198 z *= b.z;
199 return (*this);
200 }
201
204 {
205 x /= b.x;
206 y /= b.y;
207 z /= b.z;
208 return (*this);
209 }
210
213 {
214 x += b;
215 y += b;
216 z += b;
217 return (*this);
218 }
219
222 {
223 x -= b;
224 y -= b;
225 z -= b;
226 return (*this);
227 }
228
231 {
232 x *= b;
233 y *= b;
234 z *= b;
235 return (*this);
236 }
237
240 {
241 x /= b;
242 y /= b;
243 z /= b;
244 return (*this);
245 }
246
248 Real3Proxy& operator+=(Real3 b) { return add(b); }
249
251 Real3Proxy& operator-=(Real3 b) { return sub(b); }
252
254 Real3Proxy& operator*=(Real3 b) { return mul(b); }
255
258 {
259 x *= b;
260 y *= b;
261 z *= b;
262 }
263
265 Real3Proxy& operator/=(Real3 b) { return div(b); }
266
269 {
270 x /= b;
271 y /= b;
272 z /= b;
273 }
274
276 Real3 operator+(Real3 b) const { return Real3(x + b.x, y + b.y, z + b.z); }
277
279 Real3 operator-(Real3 b) const { return Real3(x - b.x, y - b.y, z - b.z); }
280
282 Real3 operator-() const { return Real3(-x, -y, -z); }
283
288 Real3 operator*(Real3 b) const { return Real3(x * b.x, y * b.y, z * b.z); }
289
294 Real3 operator/(Real3 b) const { return Real3(x / b.x, y / b.y, z / b.z); }
295
304 {
305 Real d = abs();
306 if (!math::isZero(d))
307 divSame(d);
308 return (*this);
309 }
310
328 {
329 return _eq(a.x, b.x) && _eq(a.y, b.y) && _eq(a.z, b.z);
330 }
331
339 {
340 return !(a == b);
341 }
342
343 public:
344
345 Real3 getValue() const
346 {
347 m_info.setRead();
348 return m_value;
349 }
350 Real3& getValueMutable()
351 {
352 m_info.setReadOrWrite();
353 return m_value;
354 }
355
356 private:
357
363 static bool _eq(Real a, Real b)
364 {
365 return math::isEqual(a, b);
366 }
367
369 static Real _sqrt(Real a)
370 {
371 return math::sqrt(a);
372 }
373};
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
377
381inline Real3 operator*(Real sca, Real3Proxy vec)
382{
383 return Real3(vec.x * sca, vec.y * sca, vec.z * sca);
384}
385
386/*---------------------------------------------------------------------------*/
387/*---------------------------------------------------------------------------*/
388
392inline Real3
393operator*(Real3Proxy vec, Real sca)
394{
395 return Real3(vec.x * sca, vec.y * sca, vec.z * sca);
396}
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
404inline Real3
406{
407 return Real3(vec.x / sca, vec.y / sca, vec.z / sca);
408}
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
419inline bool
420operator<(const Real3Proxy v1, const Real3Proxy v2)
421{
422 return v1.getValue() < v2.getValue();
423}
424
425/*---------------------------------------------------------------------------*/
426/*---------------------------------------------------------------------------*/
427
432inline std::ostream&
433operator<<(std::ostream& o, Real3Proxy t)
434{
435 return t.printXyz(o);
436}
437
442inline std::istream&
443operator>>(std::istream& i, Real3Proxy& t)
444{
445 return t.assign(i);
446}
447
448/*---------------------------------------------------------------------------*/
449/*---------------------------------------------------------------------------*/
450
451} // namespace Arcane
452
453/*---------------------------------------------------------------------------*/
454/*---------------------------------------------------------------------------*/
455
456#endif
Proxy of a language type.
Proxy for a Real3.
Definition Real3Proxy.h:39
Real3Proxy & assign(Real3 f)
Copies the triplet f.
Definition Real3Proxy.h:123
Real3 operator-(Real3 b) const
Creates a triplet that equals b subtracted from this triplet.
Definition Real3Proxy.h:279
RealProxy x
first component of the triplet
Definition Real3Proxy.h:92
void operator*=(Real b)
Multiplies each component of the triplet by the real number b.
Definition Real3Proxy.h:257
Real3Proxy & reset()
Resets the triplet with default constructors.
Definition Real3Proxy.h:107
void operator/=(Real b)
Divides each component of the triplet by the real number b.
Definition Real3Proxy.h:268
Real3Proxy & operator*=(Real3 b)
Multiplies each component of the triplet by the corresponding component of b.
Definition Real3Proxy.h:254
Real abs2() const
Returns the square of the norm of the triplet .
Definition Real3Proxy.h:152
friend bool operator!=(Real3Proxy a, Real3Proxy b)
Compares two triplets. For the notion of equality, see operator==().
Definition Real3Proxy.h:338
RealProxy z
third component of the triplet
Definition Real3Proxy.h:94
Real3 operator=(Real v)
Assigns the triplet (v,v,v) to the instance.
Definition Real3Proxy.h:75
Real3 operator+(Real3 b) const
Creates a triplet that equals this triplet added to b.
Definition Real3Proxy.h:276
Real3Proxy & operator/=(Real3 b)
Divides each component of the triplet by the corresponding component of b.
Definition Real3Proxy.h:265
Real3 operator/(Real3 b) const
Creates a triplet that equals this triplet whose each component has been divided by the corresponding...
Definition Real3Proxy.h:294
bool isNearlyZero() const
Compares the triplet with the zero triplet.
Definition Real3Proxy.h:146
Real3 copy() const
Returns a copy of the triplet.
Definition Real3Proxy.h:104
Real3Proxy(Real3 &value, const MemoryAccessInfo &info)
Constructs the triplet (ax,ay,az).
Definition Real3Proxy.h:43
RealProxy y
second component of the triplet
Definition Real3Proxy.h:93
Real3Proxy & addSame(Real b)
Adds b to each component of the triplet.
Definition Real3Proxy.h:212
Real3 operator-() const
Creates a triplet opposite to the current triplet.
Definition Real3Proxy.h:282
Real3Proxy & assign(Real ax, Real ay, Real az)
Assigns the triplet (ax,ay,az) to the instance.
Definition Real3Proxy.h:114
static bool _eq(Real a, Real b)
Compares the values of a and b using the TypeEqualT comparator.
Definition Real3Proxy.h:363
Real abs() const
Returns the norm of the triplet .
Definition Real3Proxy.h:158
Real3Proxy & add(Real3 b)
Adds b to the triplet.
Definition Real3Proxy.h:176
Real3Proxy & divSame(Real b)
Divides each component of the triplet by b.
Definition Real3Proxy.h:239
Real3Proxy & sub(Real3 b)
Subtracts b from the triplet.
Definition Real3Proxy.h:185
std::ostream & printXyz(std::ostream &o) const
Writes the triplet to the stream o in the form (x,y,z).
Definition Real3.cc:81
Real3Proxy(const Real3Proxy &f)
Constructs a triplet identical to f.
Definition Real3Proxy.h:52
friend bool operator==(Real3Proxy a, Real3Proxy b)
Compares the triplet to b.
Definition Real3Proxy.h:327
Real3Proxy & mul(Real3 b)
Multiplies each component of the triplet by the corresponding component of b.
Definition Real3Proxy.h:194
Real3Proxy & operator+=(Real3 b)
Adds b to the triplet.
Definition Real3Proxy.h:248
Real3Proxy & div(Real3 b)
Divides each component of the triplet by the corresponding component of b.
Definition Real3Proxy.h:203
Real3Proxy & mulSame(Real b)
Multiplies each component of the triplet by b.
Definition Real3Proxy.h:230
static Real _sqrt(Real a)
Returns the square root of a.
Definition Real3Proxy.h:369
Real3Proxy & operator-=(Real3 b)
Subtracts b from the triplet.
Definition Real3Proxy.h:251
Real3 operator*(Real3 b) const
Creates a triplet that equals this triplet whose each component has been multiplied by the correspond...
Definition Real3Proxy.h:288
Real3Proxy & normalize()
Normalizes the triplet.
Definition Real3Proxy.h:303
Real3Proxy & subSame(Real b)
Subtracts b from each component of the triplet.
Definition Real3Proxy.h:221
Class managing a 3-dimensional real vector.
Definition Real3.h:132
std::istream & operator>>(std::istream &i, Real3Proxy &t)
Reads the triplet t from the stream o.
Definition Real3Proxy.h:443
friend std::ostream & operator<<(std::ostream &o, Real3 t)
Writes the triplet t to the stream o.
Definition Real3.h:421
__host__ __device__ double sqrt(double v)
Square root of v.
Definition Math.h:142
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 --
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
Real y
second component of the triplet
Definition Real3.h:36
Real z
third component of the triplet
Definition Real3.h:37
Real x
first component of the triplet
Definition Real3.h:35