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