Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Real2x2.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/* Real2x2.h (C) 2000-2025 */
9/* */
10/* 2x2 Matrix of 'Real'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_REAL2X2_H
13#define ARCANE_UTILS_REAL2X2_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Real2.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
32{
33 public:
34
35 Real2POD x;
36 Real2POD y;
37};
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
54class ARCANE_UTILS_EXPORT Real2x2
55{
56 public:
57
59 constexpr ARCCORE_HOST_DEVICE Real2x2()
60 : x(Real2::null())
61 , y(Real2::null())
62 {}
63
65 constexpr ARCCORE_HOST_DEVICE Real2x2(Real2 ax, Real2 ay)
66 : x(ax)
67 , y(ay)
68 {}
69
74 ARCANE_DEPRECATED_116 Real2x2(Real ax, Real ay, Real bx, Real by)
75 : x(ax, bx)
76 , y(ay, by)
77 {}
78
80 Real2x2(const Real2x2& f) = default;
81
83 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(const Real2x2POD& f)
84 : x(f.x)
85 , y(f.y)
86 {}
87
89 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(Real v)
90 {
91 x = y = v;
92 }
93
95 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(ConstArrayView<Real> av)
96 : x(av[0], av[1])
97 , y(av[2], av[3])
98 {}
99
101 Real2x2& operator=(const Real2x2& f) = default;
102
104 constexpr ARCCORE_HOST_DEVICE Real2x2& operator=(Real v)
105 {
106 x = y = v;
107 return (*this);
108 }
109
110 public:
111
114
115 public:
116
118 constexpr ARCCORE_HOST_DEVICE static Real2x2 null() { return Real2x2(); }
119
121 constexpr ARCCORE_HOST_DEVICE static Real2x2 fromColumns(Real ax, Real ay, Real bx, Real by)
122 {
123 return Real2x2(Real2(ax, bx), Real2(ay, by));
124 }
125
127 constexpr ARCCORE_HOST_DEVICE static Real2x2 fromLines(Real ax, Real bx, Real ay, Real by)
128 {
129 return Real2x2(Real2(ax, bx), Real2(ay, by));
130 }
131
132 public:
133
135 constexpr ARCCORE_HOST_DEVICE Real2x2 copy() const { return (*this); }
136
138 constexpr ARCCORE_HOST_DEVICE Real2x2& reset()
139 {
140 *this = null();
141 return (*this);
142 }
143
145 constexpr ARCCORE_HOST_DEVICE Real2x2& assign(Real2 ax, Real2 ay)
146 {
147 x = ax;
148 y = ay;
149 return (*this);
150 }
151
153 constexpr ARCCORE_HOST_DEVICE Real2x2& assign(Real2x2 f)
154 {
155 x = f.x;
156 y = f.y;
157 return (*this);
158 }
159
162 constexpr ARCCORE_HOST_DEVICE ArrayView<Real> view()
163 {
164 return { 4, &x.x };
165 }
166
169 constexpr ARCCORE_HOST_DEVICE ConstArrayView<Real> constView() const
170 {
171 return { 4, &x.x };
172 }
173
178 std::istream& assign(std::istream& i);
179
181 std::ostream& print(std::ostream& o) const;
182
184 std::ostream& printXy(std::ostream& o) const;
185
187 constexpr ARCCORE_HOST_DEVICE Real2x2& add(Real2x2 b)
188 {
189 x += b.x;
190 y += b.y;
191 return (*this);
192 }
193
195 constexpr ARCCORE_HOST_DEVICE Real2x2& sub(Real2x2 b)
196 {
197 x -= b.x;
198 y -= b.y;
199 return (*this);
200 }
201
203 //Real2x2& mul(Real2x2 b) { x*=b.x; y*=b.y; return (*this); }
204
206 constexpr ARCCORE_HOST_DEVICE Real2x2& div(Real2x2 b)
207 {
208 x /= b.x;
209 y /= b.y;
210 return (*this);
211 }
212
214 constexpr ARCCORE_HOST_DEVICE Real2x2& addSame(Real2 b)
215 {
216 x += b;
217 y += b;
218 return (*this);
219 }
220
222 constexpr ARCCORE_HOST_DEVICE Real2x2& subSame(Real2 b)
223 {
224 x -= b;
225 y -= b;
226 return (*this);
227 }
228
230 constexpr ARCCORE_HOST_DEVICE Real2x2& mulSame(Real2 b)
231 {
232 x *= b;
233 y *= b;
234 return (*this);
235 }
236
238 constexpr ARCCORE_HOST_DEVICE Real2x2& divSame(Real2 b)
239 {
240 x /= b;
241 y /= b;
242 return (*this);
243 }
244
246 constexpr ARCCORE_HOST_DEVICE Real2x2& operator+=(Real2x2 b) { return add(b); }
247
249 constexpr ARCCORE_HOST_DEVICE Real2x2& operator-=(Real2x2 b) { return sub(b); }
250
252 //Real2x2& operator*=(Real2x2 b) { return mul(b); }
253
255 constexpr ARCCORE_HOST_DEVICE void operator*=(Real b)
256 {
257 x *= b;
258 y *= b;
259 }
260
262 //Real2x2& operator/= (Real2x2 b) { return div(b); }
263
265 constexpr ARCCORE_HOST_DEVICE void operator/=(Real b)
266 {
267 x /= b;
268 y /= b;
269 }
270
272 constexpr ARCCORE_HOST_DEVICE Real2x2 operator+(Real2x2 b) const { return Real2x2(x + b.x, y + b.y); }
273
275 constexpr ARCCORE_HOST_DEVICE Real2x2 operator-(Real2x2 b) const { return Real2x2(x - b.x, y - b.y); }
276
278 constexpr ARCCORE_HOST_DEVICE Real2x2 operator-() const { return Real2x2(-x, -y); }
279
286 constexpr ARCCORE_HOST_DEVICE bool operator==(Real2x2 b) const
287 {
288 return (x == b.x) && (y == b.y);
289 }
290
297 constexpr ARCCORE_HOST_DEVICE bool operator!=(Real2x2 b) const
298 {
299 return !operator==(b);
300 }
301
306 ARCCORE_HOST_DEVICE Real2 operator[](Integer i) const
307 {
308 ARCCORE_CHECK_AT(i, 2);
309 return (&x)[i];
310 }
311
316 ARCCORE_HOST_DEVICE Real2 operator()(Integer i) const
317 {
318 ARCCORE_CHECK_AT(i, 2);
319 return (&x)[i];
320 }
321
327 ARCCORE_HOST_DEVICE Real operator()(Integer i, Integer j) const
328 {
329 ARCCORE_CHECK_AT(i, 2);
330 ARCCORE_CHECK_AT(j, 2);
331 return (&x)[i][j];
332 }
333
338 ARCCORE_HOST_DEVICE Real2& operator[](Integer i)
339 {
340 ARCCORE_CHECK_AT(i, 2);
341 return (&x)[i];
342 }
343
348 ARCCORE_HOST_DEVICE Real2& operator()(Integer i)
349 {
350 ARCCORE_CHECK_AT(i, 2);
351 return (&x)[i];
352 }
353
359 ARCCORE_HOST_DEVICE Real& operator()(Integer i, Integer j)
360 {
361 ARCCORE_CHECK_AT(i, 2);
362 ARCCORE_CHECK_AT(j, 2);
363 return (&x)[i][j];
364 }
365
366 public:
367
369 friend std::ostream& operator<<(std::ostream& o, Real2x2 t)
370 {
371 return t.printXy(o);
372 }
373
375 friend std::istream& operator>>(std::istream& i, Real2x2& t)
376 {
377 return t.assign(i);
378 }
379
381 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator*(Real sca, Real2x2 vec)
382 {
383 return Real2x2(vec.x * sca, vec.y * sca);
384 }
385
387 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator*(Real2x2 vec, Real sca)
388 {
389 return Real2x2(vec.x * sca, vec.y * sca);
390 }
391
393 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator/(Real2x2 vec, Real sca)
394 {
395 return Real2x2(vec.x / sca, vec.y / sca);
396 }
397
404 friend constexpr ARCCORE_HOST_DEVICE bool operator<(Real2x2 v1, Real2x2 v2)
405 {
406 if (v1.x == v2.x) {
407 return v1.y < v2.y;
408 }
409 return (v1.x < v2.x);
410 }
411
412 public:
413
425 // TODO: make obsolete mid-2025: ARCANE_DEPRECATED_REASON("Y2024: Use math::isNearlyZero(const Real2x2&) instead")
426 inline constexpr ARCCORE_HOST_DEVICE bool isNearlyZero() const;
427
428 private:
429
435 constexpr ARCCORE_HOST_DEVICE static bool _eq(Real a, Real b)
436 {
437 return TypeEqualT<Real>::isEqual(a, b);
438 }
439};
440
441/*---------------------------------------------------------------------------*/
442/*---------------------------------------------------------------------------*/
443
444namespace math
445{
457 constexpr ARCCORE_HOST_DEVICE bool isNearlyZero(const Real2x2& v)
458 {
459 return math::isNearlyZero(v.x) && math::isNearlyZero(v.y);
460 }
461} // namespace math
462
463/*---------------------------------------------------------------------------*/
464/*---------------------------------------------------------------------------*/
465
466inline constexpr ARCCORE_HOST_DEVICE bool Real2x2::
467isNearlyZero() const
468{
469 return math::isNearlyZero(*this);
470}
471
472/*---------------------------------------------------------------------------*/
473/*---------------------------------------------------------------------------*/
474
475} // End namespace Arcane
476
477/*---------------------------------------------------------------------------*/
478/*---------------------------------------------------------------------------*/
479
480#endif
Modifiable view of an array of type T.
Constant view of an array of type T.
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Class managing a 2x2 matrix of reals.
Definition Real2x2.h:55
friend constexpr __host__ __device__ Real2x2 operator/(Real2x2 vec, Real sca)
Division by a scalar.
Definition Real2x2.h:393
constexpr __host__ __device__ Real2x2 & sub(Real2x2 b)
Subtracts b from the pair.
Definition Real2x2.h:195
constexpr __host__ __device__ Real2x2 operator+(Real2x2 b) const
Creates a pair that equals this pair added to b.
Definition Real2x2.h:272
constexpr __host__ __device__ Real2x2 & addSame(Real2 b)
Adds b to each component of the pair.
Definition Real2x2.h:214
friend constexpr __host__ __device__ Real2x2 operator*(Real sca, Real2x2 vec)
Multiplication by a scalar.
Definition Real2x2.h:381
constexpr __host__ __device__ Real2x2 & div(Real2x2 b)
Multiplies each component of the pair by the corresponding component of b.
Definition Real2x2.h:206
__host__ __device__ Real & operator()(Integer i, Integer j)
Access to the i-th row and j-th column.
Definition Real2x2.h:359
Real2 x
First component.
Definition Real2x2.h:112
std::ostream & printXy(std::ostream &o) const
Writes the pair to the stream o in the form (x,y,z).
Definition Real2x2.cc:48
ARCANE_DEPRECATED_116 Real2x2(Real ax, Real ay, Real bx, Real by)
Constructs the pair ((ax,bx),(ay,by)).
Definition Real2x2.h:74
Real2 y
Second component.
Definition Real2x2.h:113
constexpr __host__ __device__ Real2x2 & operator-=(Real2x2 b)
Subtracts b from the pair.
Definition Real2x2.h:249
constexpr __host__ __device__ Real2x2 & assign(Real2 ax, Real2 ay)
Assigns the pair (ax,ay) to the instance.
Definition Real2x2.h:145
constexpr __host__ static __device__ Real2x2 null()
Constructs the zero matrix.
Definition Real2x2.h:118
constexpr __host__ __device__ bool operator!=(Real2x2 b) const
Compares two pairs. For the notion of equality, see operator==().
Definition Real2x2.h:297
constexpr __host__ static __device__ Real2x2 fromColumns(Real ax, Real ay, Real bx, Real by)
Constructs the pair ((ax,bx),(ay,by)).
Definition Real2x2.h:121
constexpr __host__ __device__ void operator/=(Real b)
Divides each component of the pair by the corresponding component of b.
Definition Real2x2.h:265
constexpr __host__ __device__ Real2x2(ConstArrayView< Real > av)
Constructs the pair ((av[0], av[1]), (av[2], av[3])).
Definition Real2x2.h:95
__host__ __device__ Real2 & operator()(Integer i)
Access to the i-th row (between 0 and 1 inclusive) of the instance.
Definition Real2x2.h:348
constexpr __host__ __device__ ArrayView< Real > view()
Definition Real2x2.h:162
constexpr __host__ __device__ Real2x2(Real2 ax, Real2 ay)
Constructs the pair (ax,ay).
Definition Real2x2.h:65
friend std::istream & operator>>(std::istream &i, Real2x2 &t)
Reads the pair t from the stream o.
Definition Real2x2.h:375
constexpr __host__ static __device__ Real2x2 fromLines(Real ax, Real bx, Real ay, Real by)
Constructs the pair ((ax,bx),(ay,by)).
Definition Real2x2.h:127
constexpr __host__ __device__ Real2x2 & assign(Real2x2 f)
Copies the pair f.
Definition Real2x2.h:153
constexpr __host__ static __device__ bool _eq(Real a, Real b)
Compares the values of a and b with the TypeEqualT comparator.
Definition Real2x2.h:435
constexpr __host__ __device__ Real2x2 operator-(Real2x2 b) const
Creates a pair that equals b subtracted from this pair.
Definition Real2x2.h:275
Real2x2(const Real2x2 &f)=default
Constructs a copy identical to f.
__host__ __device__ Real2 & operator[](Integer i)
Access to the i-th row (between 0 and 1 inclusive) of the instance.
Definition Real2x2.h:338
constexpr __host__ __device__ ConstArrayView< Real > constView() const
Definition Real2x2.h:169
constexpr __host__ __device__ bool operator==(Real2x2 b) const
Compares component by component the current instance to b.
Definition Real2x2.h:286
constexpr __host__ __device__ Real2x2 & mulSame(Real2 b)
Multiplies each component of the pair by b.
Definition Real2x2.h:230
Real2x2 & operator=(const Real2x2 &f)=default
Copy assignment operator.
__host__ __device__ Real operator()(Integer i, Integer j) const
Read-only access to the i-th row and j-th column.
Definition Real2x2.h:327
friend constexpr __host__ __device__ bool operator<(Real2x2 v1, Real2x2 v2)
Comparison operator.
Definition Real2x2.h:404
friend constexpr __host__ __device__ Real2x2 operator*(Real2x2 vec, Real sca)
Multiplication by a scalar.
Definition Real2x2.h:387
__host__ __device__ Real2 operator[](Integer i) const
Read-only access to the i-th (between 0 and 1 inclusive) row of the instance.
Definition Real2x2.h:306
constexpr __host__ __device__ Real2x2()
Constructs the zero matrix.
Definition Real2x2.h:59
__host__ __device__ Real2 operator()(Integer i) const
Read-only access to the i-th (between 0 and 1 inclusive) row of the instance.
Definition Real2x2.h:316
constexpr __host__ __device__ bool isNearlyZero() const
Compares the matrix with the zero matrix.
Definition Real2x2.h:467
constexpr __host__ __device__ Real2x2 copy() const
Returns a copy of the pair.
Definition Real2x2.h:135
constexpr __host__ __device__ Real2x2 & reset()
Resets the pair with default constructors.
Definition Real2x2.h:138
friend std::ostream & operator<<(std::ostream &o, Real2x2 t)
Writes the pair t to the stream o.
Definition Real2x2.h:369
constexpr __host__ __device__ Real2x2 & operator+=(Real2x2 b)
Adds b to the pair.
Definition Real2x2.h:246
constexpr __host__ __device__ Real2x2 & divSame(Real2 b)
Divides each component of the pair by b.
Definition Real2x2.h:238
constexpr __host__ __device__ Real2x2 & subSame(Real2 b)
Subtracts b from each component of the pair.
Definition Real2x2.h:222
constexpr __host__ __device__ void operator*=(Real b)
Multiplies each component of the pair by the corresponding component of b.
Definition Real2x2.h:255
constexpr __host__ __device__ Real2x2 & add(Real2x2 b)
Adds b to the pair.
Definition Real2x2.h:187
constexpr __host__ __device__ Real2x2 & operator=(Real v)
Assigns the pair (v,v,v) to the instance.
Definition Real2x2.h:104
constexpr __host__ __device__ Real2x2(Real v)
Constructs the instance with the triplet (v,v,v).
Definition Real2x2.h:89
constexpr __host__ __device__ Real2x2(const Real2x2POD &f)
Constructs a copy identical to f.
Definition Real2x2.h:83
constexpr __host__ __device__ Real2x2 operator-() const
Creates an inverse tensor of the current tensor.
Definition Real2x2.h:278
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 Real2x2.
Definition Real2x2.h:32