Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Real3x3.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/* Real3x3.h (C) 2000-2025 */
9/* */
10/* 3x3 Matrix of 'Real'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_REAL3X3_H
13#define ARCANE_UTILS_REAL3X3_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Real3.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
32{
33 public:
34
35 Real3POD x;
36 Real3POD y;
37 Real3POD z;
38};
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
66class ARCANE_UTILS_EXPORT Real3x3
67{
68 public:
69
71 constexpr ARCCORE_HOST_DEVICE Real3x3()
72 : x(Real3::zero())
73 , y(Real3::zero())
74 , z(Real3::zero())
75 {}
76
78 constexpr ARCCORE_HOST_DEVICE Real3x3(Real3 ax, Real3 ay, Real3 az)
79 : x(ax)
80 , y(ay)
81 , z(az)
82 {}
83
88 ARCANE_DEPRECATED_116 Real3x3(Real ax, Real ay, Real az, Real bx, Real by, Real bz, Real cx, Real cy, Real cz)
89 : x(ax, bx, cx)
90 , y(ay, by, cy)
91 , z(az, bz, cz)
92 {}
93
95 Real3x3(const Real3x3& f) = default;
96
98 constexpr ARCCORE_HOST_DEVICE explicit Real3x3(const Real3x3POD& f)
99 : x(f.x)
100 , y(f.y)
101 , z(f.z)
102 {}
103
105 constexpr ARCCORE_HOST_DEVICE explicit Real3x3(Real v)
106 {
107 x = y = z = v;
108 }
109
111 constexpr ARCCORE_HOST_DEVICE explicit Real3x3(ConstArrayView<Real> av)
112 : x(av[0], av[1], av[2])
113 , y(av[3], av[4], av[5])
114 , z(av[6], av[7], av[8])
115 {}
116
118 Real3x3& operator=(const Real3x3& f) = default;
119
121 constexpr ARCCORE_HOST_DEVICE Real3x3& operator=(Real v)
122 {
123 x = y = z = v;
124 return (*this);
125 }
126
127 public:
128
132
133 public:
134
136 constexpr ARCCORE_HOST_DEVICE static Real3x3 null() { return Real3x3(); }
137
139 constexpr ARCCORE_HOST_DEVICE static Real3x3 zero() { return Real3x3(); }
140
142 constexpr ARCCORE_HOST_DEVICE static Real3x3 identity() { return Real3x3(Real3(1.0, 0.0, 0.0), Real3(0.0, 1.0, 0.0), Real3(0.0, 0.0, 1.0)); }
143
145 constexpr ARCCORE_HOST_DEVICE static Real3x3 fromColumns(Real ax, Real ay, Real az, Real bx, Real by, Real bz, Real cx, Real cy, Real cz)
146 {
147 return Real3x3(Real3(ax, bx, cx), Real3(ay, by, cy), Real3(az, bz, cz));
148 }
149
151 constexpr ARCCORE_HOST_DEVICE static Real3x3 fromLines(Real ax, Real bx, Real cx, Real ay, Real by, Real cy, Real az, Real bz, Real cz)
152 {
153 return Real3x3(Real3(ax, bx, cx), Real3(ay, by, cy), Real3(az, bz, cz));
154 }
155
156 public:
157
159 constexpr ARCCORE_HOST_DEVICE Real3x3 copy() const { return (*this); }
160
162 constexpr ARCCORE_HOST_DEVICE Real3x3& reset()
163 {
164 *this = zero();
165 return (*this);
166 }
167
169 constexpr ARCCORE_HOST_DEVICE Real3x3& assign(Real3 ax, Real3 ay, Real3 az)
170 {
171 x = ax;
172 y = ay;
173 z = az;
174 return (*this);
175 }
176
178 constexpr ARCCORE_HOST_DEVICE Real3x3& assign(Real3x3 f)
179 {
180 x = f.x;
181 y = f.y;
182 z = f.z;
183 return (*this);
184 }
185
188 constexpr ARCCORE_HOST_DEVICE ArrayView<Real> view()
189 {
190 return { 9, &x.x };
191 }
192
195 constexpr ARCCORE_HOST_DEVICE ConstArrayView<Real> constView() const
196 {
197 return { 9, &x.x };
198 }
199
204 std::istream& assign(std::istream& i);
205
207 std::ostream& print(std::ostream& o) const;
208
210 std::ostream& printXyz(std::ostream& o) const;
211
213 constexpr ARCCORE_HOST_DEVICE Real3x3& add(Real3x3 b)
214 {
215 x += b.x;
216 y += b.y;
217 z += b.z;
218 return (*this);
219 }
220
222 constexpr ARCCORE_HOST_DEVICE Real3x3& sub(Real3x3 b)
223 {
224 x -= b.x;
225 y -= b.y;
226 z -= b.z;
227 return (*this);
228 }
229
231 constexpr ARCCORE_HOST_DEVICE Real3x3& addSame(Real3 b)
232 {
233 x += b;
234 y += b;
235 z += b;
236 return (*this);
237 }
238
240 constexpr ARCCORE_HOST_DEVICE Real3x3& subSame(Real3 b)
241 {
242 x -= b;
243 y -= b;
244 z -= b;
245 return (*this);
246 }
247
249 constexpr ARCCORE_HOST_DEVICE Real3x3& operator+=(Real3x3 b) { return add(b); }
250
252 constexpr ARCCORE_HOST_DEVICE Real3x3& operator-=(Real3x3 b) { return sub(b); }
253
255 constexpr ARCCORE_HOST_DEVICE void operator*=(Real b)
256 {
257 x *= b;
258 y *= b;
259 z *= b;
260 }
261
263 constexpr ARCCORE_HOST_DEVICE void operator/=(Real b)
264 {
265 x /= b;
266 y /= b;
267 z /= b;
268 }
269
271 constexpr ARCCORE_HOST_DEVICE Real3x3 operator+(Real3x3 b) const { return Real3x3(x + b.x, y + b.y, z + b.z); }
272
274 constexpr ARCCORE_HOST_DEVICE Real3x3 operator-(Real3x3 b) const { return Real3x3(x - b.x, y - b.y, z - b.z); }
275
277 constexpr ARCCORE_HOST_DEVICE Real3x3 operator-() const { return Real3x3(-x, -y, -z); }
278
285 constexpr ARCCORE_HOST_DEVICE bool operator==(Real3x3 b) const
286 {
287 return x == b.x && y == b.y && z == b.z;
288 }
289
296 constexpr ARCCORE_HOST_DEVICE bool operator!=(Real3x3 b) const
297 {
298 return !operator==(b);
299 }
300
305 ARCCORE_HOST_DEVICE Real3 operator[](Integer i) const
306 {
307 ARCCORE_CHECK_AT(i, 3);
308 return (&x)[i];
309 }
310
315 ARCCORE_HOST_DEVICE Real3 operator()(Integer i) const
316 {
317 ARCCORE_CHECK_AT(i, 3);
318 return (&x)[i];
319 }
320
326 ARCCORE_HOST_DEVICE Real operator()(Integer i, Integer j) const
327 {
328 ARCCORE_CHECK_AT(i, 3);
329 ARCCORE_CHECK_AT(j, 3);
330 return (&x)[i][j];
331 }
332
337 ARCCORE_HOST_DEVICE Real3& operator[](Integer i)
338 {
339 ARCCORE_CHECK_AT(i, 3);
340 return (&x)[i];
341 }
342
347 ARCCORE_HOST_DEVICE Real3& operator()(Integer i)
348 {
349 ARCCORE_CHECK_AT(i, 3);
350 return (&x)[i];
351 }
352
358 ARCCORE_HOST_DEVICE Real& operator()(Integer i, Integer j)
359 {
360 ARCCORE_CHECK_AT(i, 3);
361 ARCCORE_CHECK_AT(j, 3);
362 return (&x)[i][j];
363 }
364
366 constexpr ARCCORE_HOST_DEVICE Real determinant() const
367 {
368 return (x.x * (y.y * z.z - y.z * z.y) + x.y * (y.z * z.x - y.x * z.z) + x.z * (y.x * z.y - y.y * z.x));
369 }
370
372 friend std::ostream& operator<<(std::ostream& o, Real3x3 t)
373 {
374 return t.printXyz(o);
375 }
376
378 friend std::istream& operator>>(std::istream& i, Real3x3& t)
379 {
380 return t.assign(i);
381 }
382
384 friend constexpr ARCCORE_HOST_DEVICE Real3x3 operator*(Real sca, Real3x3 vec)
385 {
386 return Real3x3(vec.x * sca, vec.y * sca, vec.z * sca);
387 }
388
390 friend constexpr ARCCORE_HOST_DEVICE Real3x3 operator*(Real3x3 vec, Real sca)
391 {
392 return Real3x3(vec.x * sca, vec.y * sca, vec.z * sca);
393 }
394
396 friend constexpr ARCCORE_HOST_DEVICE Real3x3 operator/(Real3x3 vec, Real sca)
397 {
398 return Real3x3(vec.x / sca, vec.y / sca, vec.z / sca);
399 }
400
407 friend constexpr ARCCORE_HOST_DEVICE bool operator<(Real3x3 v1, Real3x3 v2)
408 {
409 if (v1.x == v2.x) {
410 if (v1.y == v2.y)
411 return v1.z < v2.z;
412 else
413 return v1.y < v2.y;
414 }
415 return (v1.x < v2.x);
416 }
417
418 public:
419
420 // TODO: deprecate mid-2025: ARCANE_DEPRECATED_REASON("Y2024: Use math::isNearlyZero(const Real3x3&) instead")
421 inline constexpr ARCCORE_HOST_DEVICE bool isNearlyZero() const;
422
423 private:
424
430 constexpr ARCCORE_HOST_DEVICE static bool _eq(Real a, Real b)
431 {
432 return TypeEqualT<Real>::isEqual(a, b);
433 }
434};
435
436/*---------------------------------------------------------------------------*/
437/*---------------------------------------------------------------------------*/
438
439namespace math
440{
452 inline constexpr ARCCORE_HOST_DEVICE bool isNearlyZero(const Real3x3& v)
453 {
454 return isNearlyZero(v.x) && isNearlyZero(v.y) && isNearlyZero(v.z);
455 }
456} // namespace math
457
458/*---------------------------------------------------------------------------*/
459/*---------------------------------------------------------------------------*/
460
461inline constexpr ARCCORE_HOST_DEVICE bool Real3x3::
462isNearlyZero() const
463{
464 return math::isNearlyZero(*this);
465}
466
467/*---------------------------------------------------------------------------*/
468/*---------------------------------------------------------------------------*/
469
470} // End namespace Arcane
471
472/*---------------------------------------------------------------------------*/
473/*---------------------------------------------------------------------------*/
474
475#endif
Modifiable view of an array of type T.
Constant view of an array of type T.
Class managing a 3-dimensional real vector.
Definition Real3.h:132
Class managing a 3x3 real matrix.
Definition Real3x3.h:67
constexpr __host__ __device__ Real3x3 operator-(Real3x3 b) const
Creates a triplet that equals b subtracted from this triplet.
Definition Real3x3.h:274
constexpr __host__ static __device__ Real3x3 null()
Constructs the null tensor.
Definition Real3x3.h:136
Real3x3(const Real3x3 &f)=default
Constructs a triplet identical to f.
friend constexpr __host__ __device__ Real3x3 operator*(Real sca, Real3x3 vec)
Multiplication by a scalar.
Definition Real3x3.h:384
constexpr __host__ __device__ Real3x3 & add(Real3x3 b)
Adds b to the triplet.
Definition Real3x3.h:213
constexpr __host__ static __device__ Real3x3 identity()
Constructs the identity matrix.
Definition Real3x3.h:142
constexpr __host__ __device__ Real3x3 & subSame(Real3 b)
Subtracts b from each component of the triplet.
Definition Real3x3.h:240
std::ostream & printXyz(std::ostream &o) const
Writes the triplet to the stream o in the form (x,y,z).
Definition Real3x3.cc:49
constexpr __host__ __device__ Real3x3 & assign(Real3 ax, Real3 ay, Real3 az)
Assigns the rows (ax,ay,az) to the instance.
Definition Real3x3.h:169
Real3 z
first element of the triplet
Definition Real3x3.h:131
constexpr __host__ __device__ bool operator==(Real3x3 b) const
Compares the current instance component by component to b.
Definition Real3x3.h:285
friend constexpr __host__ __device__ bool operator<(Real3x3 v1, Real3x3 v2)
Comparison operator.
Definition Real3x3.h:407
constexpr __host__ __device__ Real3x3 & sub(Real3x3 b)
Subtracts b from the triplet.
Definition Real3x3.h:222
constexpr __host__ static __device__ Real3x3 fromLines(Real ax, Real bx, Real cx, Real ay, Real by, Real cy, Real az, Real bz, Real cz)
Constructs the matrix ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
Definition Real3x3.h:151
constexpr __host__ __device__ Real3x3 & operator=(Real v)
Assigns the triplet (v,v,v) to the instance.
Definition Real3x3.h:121
constexpr __host__ __device__ Real3x3 & reset()
Resets the coefficients of the matrix to zero.
Definition Real3x3.h:162
Real3 y
first element of the triplet
Definition Real3x3.h:130
constexpr __host__ __device__ Real3x3 & assign(Real3x3 f)
Copies matrix f.
Definition Real3x3.h:178
constexpr __host__ __device__ Real determinant() const
Determinant of the matrix.
Definition Real3x3.h:366
__host__ __device__ Real3 operator()(Integer i) const
Read-only access to the i-th (between 0 and 2 inclusive) row of the instance.
Definition Real3x3.h:315
constexpr __host__ static __device__ Real3x3 fromColumns(Real ax, Real ay, Real az, Real bx, Real by, Real bz, Real cx, Real cy, Real cz)
Constructs the matrix ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
Definition Real3x3.h:145
constexpr __host__ __device__ Real3x3()
Constructs the matrix with all coefficients zero.
Definition Real3x3.h:71
constexpr __host__ __device__ Real3x3(ConstArrayView< Real > av)
Constructs the triplet ((av[0], av[1], av[2]), (av[3], av[4], av[5]), (av[6], av[7],...
Definition Real3x3.h:111
__host__ __device__ Real3 operator[](Integer i) const
Read-only access to the i-th (between 0 and 2 inclusive) row of the instance.
Definition Real3x3.h:305
constexpr __host__ __device__ Real3x3 & addSame(Real3 b)
Adds b to each component of the triplet.
Definition Real3x3.h:231
Real3x3 & operator=(const Real3x3 &f)=default
Copy assignment operator.
constexpr __host__ __device__ ArrayView< Real > view()
Definition Real3x3.h:188
constexpr __host__ __device__ ConstArrayView< Real > constView() const
Definition Real3x3.h:195
constexpr __host__ __device__ Real3x3(const Real3x3POD &f)
Constructs a triplet identical to f.
Definition Real3x3.h:98
constexpr __host__ __device__ bool operator!=(Real3x3 b) const
Compares two triplets. For the notion of equality, see operator==().
Definition Real3x3.h:296
Real3 x
first element of the triplet
Definition Real3x3.h:129
constexpr __host__ __device__ Real3x3(Real v)
Constructs the instance with the triplet (v,v,v).
Definition Real3x3.h:105
friend std::ostream & operator<<(std::ostream &o, Real3x3 t)
Writes the triplet t to the stream o.
Definition Real3x3.h:372
__host__ __device__ Real3 & operator[](Integer i)
Access to the i-th row (between 0 and 2 inclusive) of the instance.
Definition Real3x3.h:337
constexpr __host__ static __device__ bool _eq(Real a, Real b)
Compares the values of a and b with the TypeEqualT comparator.
Definition Real3x3.h:430
constexpr __host__ static __device__ Real3x3 zero()
Constructs the zero matrix.
Definition Real3x3.h:139
__host__ __device__ Real operator()(Integer i, Integer j) const
Read-only access to the i-th row and j-th column.
Definition Real3x3.h:326
friend std::istream & operator>>(std::istream &i, Real3x3 &t)
Reads the triplet t from the stream o.
Definition Real3x3.h:378
constexpr __host__ __device__ Real3x3(Real3 ax, Real3 ay, Real3 az)
Constructs the matrix with rows (ax,ay,az).
Definition Real3x3.h:78
constexpr __host__ __device__ Real3x3 & operator+=(Real3x3 b)
Adds b to the triplet.
Definition Real3x3.h:249
constexpr __host__ __device__ void operator/=(Real b)
Divides each component of the matrix by the real b.
Definition Real3x3.h:263
constexpr __host__ __device__ Real3x3 copy() const
Returns a copy of the matrix.
Definition Real3x3.h:159
constexpr __host__ __device__ Real3x3 operator-() const
Creates a tensor opposite to the current tensor.
Definition Real3x3.h:277
constexpr __host__ __device__ Real3x3 operator+(Real3x3 b) const
Creates a triplet that equals this triplet added to b.
Definition Real3x3.h:271
ARCANE_DEPRECATED_116 Real3x3(Real ax, Real ay, Real az, Real bx, Real by, Real bz, Real cx, Real cy, Real cz)
Constructs the tensor ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
Definition Real3x3.h:88
constexpr __host__ __device__ void operator*=(Real b)
Multiplies each component of the matrix by the real b.
Definition Real3x3.h:255
__host__ __device__ Real & operator()(Integer i, Integer j)
Access to the i-th row and j-th column.
Definition Real3x3.h:358
constexpr __host__ __device__ Real3x3 & operator-=(Real3x3 b)
Subtracts b from the triplet.
Definition Real3x3.h:252
friend constexpr __host__ __device__ Real3x3 operator/(Real3x3 vec, Real sca)
Division by a scalar.
Definition Real3x3.h:396
friend constexpr __host__ __device__ Real3x3 operator*(Real3x3 vec, Real sca)
Multiplication by a scalar.
Definition Real3x3.h:390
__host__ __device__ Real3 & operator()(Integer i)
Access to the i-th row (between 0 and 2 inclusive) of the instance.
Definition Real3x3.h:347
constexpr __host__ static __device__ bool isEqual(const T &a, const T &b)
Compares a to b.
Definition Numeric.h:94
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
POD structure for a Real3x3.
Definition Real3x3.h:32