Arcane  4.1.12.0
User 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
34/*!
35 * \brief Proxy for a Real3.
36 */
37class ARCANE_UTILS_EXPORT Real3Proxy
38: public Real3POD
39{
40 public:
41
42 //! Constructs the triplet (ax,ay,az)
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
51 //! Constructs a triplet identical to \a f
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
74 //! Assigns the triplet (v,v,v) to the instance.
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; //!< first component of the triplet
93 RealProxy y; //!< second component of the triplet
94 RealProxy z; //!< third component of the triplet
95
96 private:
97
98 Real3& m_value;
99 MemoryAccessInfo m_info;
100
101 public:
102
103 //! Returns a copy of the triplet.
104 Real3 copy() const { return Real3(x, y, z); }
105
106 //! Resets the triplet with default constructors.
108 {
109 x = y = z = 0.;
110 return (*this);
111 }
112
113 //! Assigns the triplet (ax,ay,az) to the instance
115 {
116 x = ax;
117 y = ay;
118 z = az;
119 return (*this);
120 }
121
122 //! Copies the triplet \a f
124 {
125 x = f.x;
126 y = f.y;
127 z = f.z;
128 return (*this);
129 }
130
131 /*!
132 * \brief Compares the triplet with the zero triplet.
133 *
134 * In the case of an integral type #value_type, the triplet is
135 * zero if and only if each of its components is equal to 0.
136 *
137 * For #value_type of the floating-point type (float, double or #Real), the triplet
138 * is zero if and only if each of its components is less
139 * than a given epsilon. The value of the epsilon used is that
140 * of float_info<value_type>::nearlyEpsilon():
141 * \f[A=0 \Leftrightarrow |A.x|<\epsilon,|A.y|<\epsilon,|A.z|<\epsilon \f]
142 *
143 * \retval true if the triplet is equal to the zero triplet,
144 * \retval false otherwise.
145 */
146 bool isNearlyZero() const
147 {
148 return math::isNearlyZero(x.getValue()) && math::isNearlyZero(y.getValue()) && math::isNearlyZero(z.getValue());
149 }
150
151 //! Returns the square of the norm of the triplet \f$x^2+y^2+z^2\f$
152 Real abs2() const
153 {
154 return x * x + y * y + z * z;
155 }
156
157 //! Returns the norm of the triplet \f$\sqrt{x^2+y^2+z^2}\f$
158 Real abs() const
159 {
160 return _sqrt(abs2());
161 }
162
163 /*!
164 * \brief Reads a triplet from the stream \a i
165 * The triplet is read in the form of three values of type #value_type.
166 */
167 std::istream& assign(std::istream& i);
168
169 //! Writes the triplet to the stream \a o readable by an assign()
170 std::ostream& print(std::ostream& o) const;
171
172 //! Writes the triplet to the stream \a o in the form (x,y,z)
173 std::ostream& printXyz(std::ostream& o) const;
174
175 //! Adds \a b to the triplet
177 {
178 x += b.x;
179 y += b.y;
180 z += b.z;
181 return (*this);
182 }
183
184 //! Subtracts \a b from the triplet
186 {
187 x -= b.x;
188 y -= b.y;
189 z -= b.z;
190 return (*this);
191 }
192
193 //! Multiplies each component of the triplet by the corresponding component of \a b
195 {
196 x *= b.x;
197 y *= b.y;
198 z *= b.z;
199 return (*this);
200 }
201
202 //! Divides each component of the triplet by the corresponding component of \a b
204 {
205 x /= b.x;
206 y /= b.y;
207 z /= b.z;
208 return (*this);
209 }
210
211 //! Adds \a b to each component of the triplet
213 {
214 x += b;
215 y += b;
216 z += b;
217 return (*this);
218 }
219
220 //! Subtracts \a b from each component of the triplet
222 {
223 x -= b;
224 y -= b;
225 z -= b;
226 return (*this);
227 }
228
229 //! Multiplies each component of the triplet by \a b
231 {
232 x *= b;
233 y *= b;
234 z *= b;
235 return (*this);
236 }
237
238 //! Divides each component of the triplet by \a b
240 {
241 x /= b;
242 y /= b;
243 z /= b;
244 return (*this);
245 }
246
247 //! Adds \a b to the triplet.
248 Real3Proxy& operator+=(Real3 b) { return add(b); }
249
250 //! Subtracts \a b from the triplet
251 Real3Proxy& operator-=(Real3 b) { return sub(b); }
252
253 //! Multiplies each component of the triplet by the corresponding component of \a b
254 Real3Proxy& operator*=(Real3 b) { return mul(b); }
255
256 //! Multiplies each component of the triplet by the real number \a b
258 {
259 x *= b;
260 y *= b;
261 z *= b;
262 }
263
264 //! Divides each component of the triplet by the corresponding component of \a b
265 Real3Proxy& operator/=(Real3 b) { return div(b); }
266
267 //! Divides each component of the triplet by the real number \a b
269 {
270 x /= b;
271 y /= b;
272 z /= b;
273 }
274
275 //! Creates a triplet that equals this triplet added to \a b
276 Real3 operator+(Real3 b) const { return Real3(x + b.x, y + b.y, z + b.z); }
277
278 //! Creates a triplet that equals \a b subtracted from this triplet
279 Real3 operator-(Real3 b) const { return Real3(x - b.x, y - b.y, z - b.z); }
280
281 //! Creates a triplet opposite to the current triplet
282 Real3 operator-() const { return Real3(-x, -y, -z); }
283
284 /*!
285 * \brief Creates a triplet that equals this triplet whose each component has been
286 * multiplied by the corresponding component of \a b.
287 */
288 Real3 operator*(Real3 b) const { return Real3(x * b.x, y * b.y, z * b.z); }
289
290 /*!
291 * \brief Creates a triplet that equals this triplet whose each component has been divided
292 * by the corresponding component of \a b.
293 */
294 Real3 operator/(Real3 b) const { return Real3(x / b.x, y / b.y, z / b.z); }
295
296 /*!
297 * \brief Normalizes the triplet.
298 *
299 * If the triplet is non-zero, divides each component by the norm of the triplet
300 * (abs()), so that after calling this method, abs() equals \a 1.
301 * If the triplet is zero, does nothing.
302 */
304 {
305 Real d = abs();
306 if (!math::isZero(d))
307 divSame(d);
308 return (*this);
309 }
310
311 /*!
312 * \brief Compares the triplet to \a b.
313 *
314 * In the case of an integral type #value_type, two triplets
315 * are equal if and only if each of their components are strictly
316 * equal.
317 *
318 * For #value_type of the floating-point type (float, double or #Real), two triplets
319 * are identical if and only if the absolute value of the difference
320 * between each of their corresponding components is less
321 * than a given epsilon. The value of the epsilon used is that
322 * of float_info<value_type>::nearlyEpsilon():
323 * \f[A=B \Leftrightarrow |A.x-B.x|<\epsilon,|A.y-B.y|<\epsilon,|A.z-B.z|<\epsilon \f]
324 * \retval true if the two triplets are equal,
325 * \retval false otherwise.
326 */
328 {
329 return _eq(a.x, b.x) && _eq(a.y, b.y) && _eq(a.z, b.z);
330 }
331
332 /*!
333 * \brief Compares two triplets.
334 * For the notion of equality, see operator==()
335 * \retval true if the two triplets are different,
336 * \retval false otherwise.
337 */
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
358 /*!
359 * \brief Compares the values of \a a and \a b using the TypeEqualT comparator
360 * \retval true if \a a and \a b are equal,
361 * \retval false otherwise.
362 */
363 static bool _eq(Real a, Real b)
364 {
365 return math::isEqual(a, b);
366 }
367
368 //! Returns the square root of \a a
369 static Real _sqrt(Real a)
370 {
371 return math::sqrt(a);
372 }
373};
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
377
378/*!
379 * \brief Multiplication by a scalar.
380 */
382{
383 return Real3(vec.x * sca, vec.y * sca, vec.z * sca);
384}
385
386/*---------------------------------------------------------------------------*/
387/*---------------------------------------------------------------------------*/
388
389/*!
390 * \brief Multiplication by a scalar.
391 */
392inline Real3
394{
395 return Real3(vec.x * sca, vec.y * sca, vec.z * sca);
396}
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
401/*!
402 * \brief Division by a scalar.
403 */
404inline Real3
406{
407 return Real3(vec.x / sca, vec.y / sca, vec.z / sca);
408}
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
413/*!
414 * \brief Comparison operator.
415 *
416 * This operator allows Real3s to be sorted for example
417 * in std::set
418 */
419inline bool
420operator<(const Real3Proxy v1, const Real3Proxy v2)
421{
422 return v1.getValue() < v2.getValue();
423}
424
425/*---------------------------------------------------------------------------*/
426/*---------------------------------------------------------------------------*/
427
428/*!
429 * \brief Writes the triplet \a t to the stream \a o
430 * \relates Real3
431 */
432inline std::ostream&
433operator<<(std::ostream& o, Real3Proxy t)
434{
435 return t.printXyz(o);
436}
437
438/*!
439 * \brief Reads the triplet \a t from the stream \a o.
440 * \relates Real3
441 */
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
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
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
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
-- 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.
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