Arcane  v3.16.6.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Real2x2.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* Matrice 2x2 de '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/*---------------------------------------------------------------------------*/
31{
32 public:
33
34 Real2POD x;
35 Real2POD y;
36};
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
52class ARCANE_UTILS_EXPORT Real2x2
53{
54 public:
55
57 constexpr ARCCORE_HOST_DEVICE Real2x2()
58 : x(Real2::null())
59 , y(Real2::null())
60 {}
61
63 constexpr ARCCORE_HOST_DEVICE Real2x2(Real2 ax, Real2 ay)
64 : x(ax)
65 , y(ay)
66 {}
67
72 ARCANE_DEPRECATED_116 Real2x2(Real ax, Real ay, Real bx, Real by)
73 : x(ax, bx)
74 , y(ay, by)
75 {}
76
78 Real2x2(const Real2x2& f) = default;
79
81 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(const Real2x2POD& f)
82 : x(f.x)
83 , y(f.y)
84 {}
85
87 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(Real v)
88 {
89 x = y = v;
90 }
91
93 constexpr ARCCORE_HOST_DEVICE explicit Real2x2(ConstArrayView<Real> av)
94 : x(av[0], av[1])
95 , y(av[2], av[3])
96 {}
97
99 Real2x2& operator=(const Real2x2& f) = default;
100
102 constexpr ARCCORE_HOST_DEVICE Real2x2& operator=(Real v)
103 {
104 x = y = v;
105 return (*this);
106 }
107
108 public:
109
112
113 public:
114
116 constexpr ARCCORE_HOST_DEVICE static Real2x2 null() { return Real2x2(); }
117
119 constexpr ARCCORE_HOST_DEVICE static Real2x2 fromColumns(Real ax, Real ay, Real bx, Real by)
120 {
121 return Real2x2(Real2(ax, bx), Real2(ay, by));
122 }
123
125 constexpr ARCCORE_HOST_DEVICE static Real2x2 fromLines(Real ax, Real bx, Real ay, Real by)
126 {
127 return Real2x2(Real2(ax, bx), Real2(ay, by));
128 }
129
130 public:
131
133 constexpr ARCCORE_HOST_DEVICE Real2x2 copy() const { return (*this); }
135 constexpr ARCCORE_HOST_DEVICE Real2x2& reset()
136 {
137 *this = null();
138 return (*this);
139 }
140
141 constexpr ARCCORE_HOST_DEVICE Real2x2& assign(Real2 ax, Real2 ay)
142 {
143 x = ax;
144 y = ay;
145 return (*this);
146 }
147
148 constexpr ARCCORE_HOST_DEVICE Real2x2& assign(Real2x2 f)
149 {
150 x = f.x;
151 y = f.y;
152 return (*this);
153 }
154
157 constexpr ARCCORE_HOST_DEVICE ArrayView<Real> view()
158 {
159 return { 4, &x.x };
160 }
161
164 constexpr ARCCORE_HOST_DEVICE ConstArrayView<Real> constView() const
165 {
166 return { 4, &x.x };
167 }
168
173 std::istream& assign(std::istream& i);
175 std::ostream& print(std::ostream& o) const;
177 std::ostream& printXy(std::ostream& o) const;
178
180 constexpr ARCCORE_HOST_DEVICE Real2x2& add(Real2x2 b)
181 {
182 x += b.x;
183 y += b.y;
184 return (*this);
185 }
186
187 constexpr ARCCORE_HOST_DEVICE Real2x2& sub(Real2x2 b)
188 {
189 x -= b.x;
190 y -= b.y;
191 return (*this);
192 }
193
194 //Real2x2& mul(Real2x2 b) { x*=b.x; y*=b.y; return (*this); }
196 constexpr ARCCORE_HOST_DEVICE Real2x2& div(Real2x2 b)
197 {
198 x /= b.x;
199 y /= b.y;
200 return (*this);
201 }
202
203 constexpr ARCCORE_HOST_DEVICE Real2x2& addSame(Real2 b)
204 {
205 x += b;
206 y += b;
207 return (*this);
208 }
209
210 constexpr ARCCORE_HOST_DEVICE Real2x2& subSame(Real2 b)
211 {
212 x -= b;
213 y -= b;
214 return (*this);
215 }
216
217 constexpr ARCCORE_HOST_DEVICE Real2x2& mulSame(Real2 b)
218 {
219 x *= b;
220 y *= b;
221 return (*this);
222 }
223
224 constexpr ARCCORE_HOST_DEVICE Real2x2& divSame(Real2 b)
225 {
226 x /= b;
227 y /= b;
228 return (*this);
229 }
230
231 constexpr ARCCORE_HOST_DEVICE Real2x2& operator+=(Real2x2 b) { return add(b); }
233 constexpr ARCCORE_HOST_DEVICE Real2x2& operator-=(Real2x2 b) { return sub(b); }
235 //Real2x2& operator*=(Real2x2 b) { return mul(b); }
237 constexpr ARCCORE_HOST_DEVICE void operator*=(Real b)
238 {
239 x *= b;
240 y *= b;
241 }
242
243 //Real2x2& operator/= (Real2x2 b) { return div(b); }
245 constexpr ARCCORE_HOST_DEVICE void operator/=(Real b)
246 {
247 x /= b;
248 y /= b;
249 }
250
251 constexpr ARCCORE_HOST_DEVICE Real2x2 operator+(Real2x2 b) const { return Real2x2(x + b.x, y + b.y); }
253 constexpr ARCCORE_HOST_DEVICE Real2x2 operator-(Real2x2 b) const { return Real2x2(x - b.x, y - b.y); }
255 constexpr ARCCORE_HOST_DEVICE Real2x2 operator-() const { return Real2x2(-x, -y); }
256
263 constexpr ARCCORE_HOST_DEVICE bool operator==(Real2x2 b) const
264 {
265 return (x == b.x) && (y == b.y);
266 }
267
273 constexpr ARCCORE_HOST_DEVICE bool operator!=(Real2x2 b) const
274 {
275 return !operator==(b);
276 }
277
282 ARCCORE_HOST_DEVICE Real2 operator[](Integer i) const
283 {
284 ARCCORE_CHECK_AT(i, 2);
285 return (&x)[i];
286 }
287
292 ARCCORE_HOST_DEVICE Real2 operator()(Integer i) const
293 {
294 ARCCORE_CHECK_AT(i, 2);
295 return (&x)[i];
296 }
297
303 ARCCORE_HOST_DEVICE Real operator()(Integer i, Integer j) const
304 {
305 ARCCORE_CHECK_AT(i, 2);
306 ARCCORE_CHECK_AT(j, 2);
307 return (&x)[i][j];
308 }
309
314 ARCCORE_HOST_DEVICE Real2& operator[](Integer i)
315 {
316 ARCCORE_CHECK_AT(i, 2);
317 return (&x)[i];
318 }
319
324 ARCCORE_HOST_DEVICE Real2& operator()(Integer i)
325 {
326 ARCCORE_CHECK_AT(i, 2);
327 return (&x)[i];
328 }
329
335 ARCCORE_HOST_DEVICE Real& operator()(Integer i, Integer j)
336 {
337 ARCCORE_CHECK_AT(i, 2);
338 ARCCORE_CHECK_AT(j, 2);
339 return (&x)[i][j];
340 }
341
342 public:
343
345 friend std::ostream& operator<<(std::ostream& o, Real2x2 t)
346 {
347 return t.printXy(o);
348 }
349
351 friend std::istream& operator>>(std::istream& i, Real2x2& t)
352 {
353 return t.assign(i);
354 }
355
357 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator*(Real sca, Real2x2 vec)
358 {
359 return Real2x2(vec.x * sca, vec.y * sca);
360 }
361
363 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator*(Real2x2 vec, Real sca)
364 {
365 return Real2x2(vec.x * sca, vec.y * sca);
366 }
367
369 friend constexpr ARCCORE_HOST_DEVICE Real2x2 operator/(Real2x2 vec, Real sca)
370 {
371 return Real2x2(vec.x / sca, vec.y / sca);
372 }
373
380 friend constexpr ARCCORE_HOST_DEVICE bool operator<(Real2x2 v1, Real2x2 v2)
381 {
382 if (v1.x == v2.x) {
383 return v1.y < v2.y;
384 }
385 return (v1.x < v2.x);
386 }
387
388 public:
389
401 // TODO: rendre obsolète mi-2025: ARCANE_DEPRECATED_REASON("Y2024: Use math::isNearlyZero(const Real2x2&) instead")
402 inline constexpr ARCCORE_HOST_DEVICE bool isNearlyZero() const;
403
404 private:
405
411 constexpr ARCCORE_HOST_DEVICE static bool _eq(Real a, Real b)
412 {
413 return TypeEqualT<Real>::isEqual(a, b);
414 }
415};
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
420namespace math
421{
433 constexpr ARCCORE_HOST_DEVICE bool isNearlyZero(const Real2x2& v)
434 {
435 return math::isNearlyZero(v.x) && math::isNearlyZero(v.y);
436 }
437}
438
439/*---------------------------------------------------------------------------*/
440/*---------------------------------------------------------------------------*/
441
442inline constexpr ARCCORE_HOST_DEVICE bool Real2x2::
443isNearlyZero() const
444{
445 return math::isNearlyZero(*this);
446}
447
448/*---------------------------------------------------------------------------*/
449/*---------------------------------------------------------------------------*/
450
451} // End namespace Arcane
452
453/*---------------------------------------------------------------------------*/
454/*---------------------------------------------------------------------------*/
455
456#endif
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
friend constexpr __host__ __device__ Real2x2 operator/(Real2x2 vec, Real sca)
Division par un scalaire.
Definition Real2x2.h:369
constexpr __host__ __device__ Real2x2 & sub(Real2x2 b)
Soustrait b au couple.
Definition Real2x2.h:187
constexpr __host__ __device__ Real2x2 operator+(Real2x2 b) const
Créé un couple qui vaut ce couple ajouté à b.
Definition Real2x2.h:251
constexpr __host__ __device__ Real2x2 & addSame(Real2 b)
Ajoute b à chaque composante du couple.
Definition Real2x2.h:203
friend constexpr __host__ __device__ Real2x2 operator*(Real sca, Real2x2 vec)
Multiplication par un scalaire.
Definition Real2x2.h:357
constexpr __host__ __device__ Real2x2 & div(Real2x2 b)
Multiple chaque composante du couple par la composant correspondant de b.
Definition Real2x2.h:196
__host__ __device__ Real & operator()(Integer i, Integer j)
Accès à la i-ème ligne et j-ème colonne.
Definition Real2x2.h:335
Real2 x
Première composante.
Definition Real2x2.h:110
std::ostream & printXy(std::ostream &o) const
Ecrit le couple sur le flot o sous la forme (x,y,z)
Definition Real2x2.cc:48
ARCANE_DEPRECATED_116 Real2x2(Real ax, Real ay, Real bx, Real by)
Construit le couple ((ax,bx),(ay,by)).
Definition Real2x2.h:72
Real2 y
Deuxième composante.
Definition Real2x2.h:111
constexpr __host__ __device__ Real2x2 & operator-=(Real2x2 b)
Soustrait b au couple.
Definition Real2x2.h:233
constexpr __host__ __device__ Real2x2 & assign(Real2 ax, Real2 ay)
Affecte à l'instance le couple (ax,ay,az)
Definition Real2x2.h:141
constexpr __host__ static __device__ Real2x2 null()
Construit la matrice nulle.
Definition Real2x2.h:116
constexpr __host__ __device__ bool operator!=(Real2x2 b) const
Compare deux couples. Pour la notion d'égalité, voir operator==()
Definition Real2x2.h:273
constexpr __host__ static __device__ Real2x2 fromColumns(Real ax, Real ay, Real bx, Real by)
Construit le couple ((ax,bx),(ay,by)).
Definition Real2x2.h:119
constexpr __host__ __device__ void operator/=(Real b)
Divise chaque composante du couple par la composant correspondant de b.
Definition Real2x2.h:245
constexpr __host__ __device__ Real2x2(ConstArrayView< Real > av)
Construit le couple ((av[0], av[1]), (av[2], av[3]))
Definition Real2x2.h:93
__host__ __device__ Real2 & operator()(Integer i)
Accès à la i-ème ligne (entre 0 et 1 inclus) de l'instance.
Definition Real2x2.h:324
constexpr __host__ __device__ ArrayView< Real > view()
Definition Real2x2.h:157
constexpr __host__ __device__ Real2x2(Real2 ax, Real2 ay)
Construit le couple (ax,ay)
Definition Real2x2.h:63
friend std::istream & operator>>(std::istream &i, Real2x2 &t)
Lit le couple t à partir du flot o.
Definition Real2x2.h:351
constexpr __host__ static __device__ Real2x2 fromLines(Real ax, Real bx, Real ay, Real by)
Construit le couple ((ax,bx),(ay,by)).
Definition Real2x2.h:125
constexpr __host__ __device__ Real2x2 & assign(Real2x2 f)
Copie le couple f.
Definition Real2x2.h:148
constexpr __host__ static __device__ bool _eq(Real a, Real b)
Compare les valeurs de a et b avec le comparateur TypeEqualT.
Definition Real2x2.h:411
constexpr __host__ __device__ Real2x2 operator-(Real2x2 b) const
Créé un couple qui vaut b soustrait de ce couple.
Definition Real2x2.h:253
Real2x2(const Real2x2 &f)=default
Construit un couple identique à f.
__host__ __device__ Real2 & operator[](Integer i)
Accès à la i-ème ligne (entre 0 et 1 inclus) de l'instance.
Definition Real2x2.h:314
constexpr __host__ __device__ ConstArrayView< Real > constView() const
Definition Real2x2.h:164
constexpr __host__ __device__ bool operator==(Real2x2 b) const
Compare composant pas composante l'instance courante à b.
Definition Real2x2.h:263
constexpr __host__ __device__ Real2x2 & mulSame(Real2 b)
Multiplie chaque composante du couple par b.
Definition Real2x2.h:217
Real2x2 & operator=(const Real2x2 &f)=default
Opérateur de recopie.
__host__ __device__ Real operator()(Integer i, Integer j) const
Accès en lecture seule à la i-ème ligne et j-ème colonne.
Definition Real2x2.h:303
friend constexpr __host__ __device__ bool operator<(Real2x2 v1, Real2x2 v2)
Opérateur de comparaison.
Definition Real2x2.h:380
friend constexpr __host__ __device__ Real2x2 operator*(Real2x2 vec, Real sca)
Multiplication par un scalaire.
Definition Real2x2.h:363
__host__ __device__ Real2 operator[](Integer i) const
Accès en lecture seule à la i-ème (entre 0 et 1 inclus) ligne de l'instance.
Definition Real2x2.h:282
constexpr __host__ __device__ Real2x2()
Construit la matrice nulle.
Definition Real2x2.h:57
__host__ __device__ Real2 operator()(Integer i) const
Accès en lecture seule à la i-ème (entre 0 et 1 inclus) ligne de l'instance.
Definition Real2x2.h:292
constexpr __host__ __device__ bool isNearlyZero() const
Compare la matrice avec la matrice nulle.
Definition Real2x2.h:443
constexpr __host__ __device__ Real2x2 copy() const
Retourne une copie du couple.
Definition Real2x2.h:133
constexpr __host__ __device__ Real2x2 & reset()
Réinitialise le couple avec les constructeurs par défaut.
Definition Real2x2.h:135
friend std::ostream & operator<<(std::ostream &o, Real2x2 t)
Ecrit le couple t sur le flot o.
Definition Real2x2.h:345
constexpr __host__ __device__ Real2x2 & operator+=(Real2x2 b)
Ajoute b au couple.
Definition Real2x2.h:231
constexpr __host__ __device__ Real2x2 & divSame(Real2 b)
Divise chaque composante du couple par b.
Definition Real2x2.h:224
constexpr __host__ __device__ Real2x2 & subSame(Real2 b)
Soustrait b à chaque composante du couple.
Definition Real2x2.h:210
constexpr __host__ __device__ void operator*=(Real b)
Multiple chaque composante du couple par la composant correspondant de b.
Definition Real2x2.h:237
constexpr __host__ __device__ Real2x2 & add(Real2x2 b)
Ajoute b au couple.
Definition Real2x2.h:180
constexpr __host__ __device__ Real2x2 & operator=(Real v)
Affecte à l'instance le couple (v,v,v).
Definition Real2x2.h:102
constexpr __host__ __device__ Real2x2(Real v)
Construit l'instance avec le triplet (v,v,v).
Definition Real2x2.h:87
constexpr __host__ __device__ Real2x2(const Real2x2POD &f)
Construit un couple identique à f.
Definition Real2x2.h:81
constexpr __host__ __device__ Real2x2 operator-() const
Créé un tenseur opposé au tenseur actuel.
Definition Real2x2.h:255
constexpr __host__ static __device__ bool isEqual(const T &a, const T &b)
Compare a à b.
Definition Numeric.h:92
Espace de nom pour l'utilisation des accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.
Structure POD pour un Real2x2.
Definition Real2x2.h:31