12#ifndef ARCANE_UTILS_NUMMATRIX_H
13#define ARCANE_UTILS_NUMMATRIX_H
17#include "arcane/utils/NumVector.h"
18#include "arcane/utils/Real2x2.h"
19#include "arcane/utils/Real3x3.h"
40template <
typename T,
int RowSize,
int ColumnSize>
43 static_assert(RowSize > 1,
"RowSize has to be strictly greater than 1");
44 static_assert(ColumnSize > 1,
"RowSize has to be strictly greater than 1");
46 static_assert(std::is_same_v<T, Real>,
"Only type 'Real' is allowed");
47 static constexpr int Size = RowSize;
48 static constexpr bool isSquare() {
return RowSize == ColumnSize; }
49 static constexpr bool isSquare2() {
return RowSize == 2 && ColumnSize == 2; }
50 static constexpr bool isSquare3() {
return RowSize == 3 && ColumnSize == 3; }
64 constexpr ARCCORE_HOST_DEVICE
NumMatrix(
const VectorType&
ax,
const VectorType& ay)
65 requires(RowSize == 2)
72 constexpr ARCCORE_HOST_DEVICE
NumMatrix(
const VectorType&
ax,
const VectorType& ay,
const VectorType& az)
73 requires(RowSize == 3)
81 constexpr ARCCORE_HOST_DEVICE
NumMatrix(
const VectorType& a1,
const VectorType& a2,
82 const VectorType& a3,
const VectorType& a4)
83 requires(RowSize == 4)
92 constexpr ARCCORE_HOST_DEVICE
NumMatrix(
const VectorType& a1,
const VectorType& a2,
93 const VectorType& a3,
const VectorType& a4,
95 requires(RowSize == 5)
107 for (
int i = 0; i < Size; ++i)
111 explicit constexpr ARCCORE_HOST_DEVICE
NumMatrix(
Real2x2 v)
requires(isSquare2())
112 :
NumMatrix(VectorType(v.x), VectorType(v.y))
115 explicit constexpr ARCCORE_HOST_DEVICE
NumMatrix(Real3x3 v)
requires(isSquare3())
116 :
NumMatrix(VectorType(v.x), VectorType(v.y), VectorType(v.z))
122 for (
int i = 0; i < Size; ++i)
127 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator=(
const Real2x2& v)
requires(isSquare2())
129 *
this = ThatClass(v);
133 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator=(
const Real3x3& v)
requires(isSquare3())
135 *
this = ThatClass(v);
139 operator Real2x2() const requires(isSquare2())
141 return Real2x2(m_values[0], m_values[1]);
144 operator Real3x3() const requires(isSquare3())
146 return Real3x3(m_values[0], m_values[1], m_values[2]);
152 constexpr ARCCORE_HOST_DEVICE
static ThatClass
zero()
158 constexpr ARCCORE_HOST_DEVICE
static ThatClass
fromColumns(T
ax, T ay, T az, T bx, T by, T bz, T cx, T cy, T cz)
159 requires(isSquare3())
161 return ThatClass(VectorType(
ax, bx, cx), VectorType(ay, by, cy), VectorType(az, bz, cz));
165 constexpr ARCCORE_HOST_DEVICE
static ThatClass
fromLines(T
ax, T bx, T cx, T ay, T by, T cy, T az, T bz, T cz)
166 requires(isSquare3())
168 return ThatClass(VectorType(
ax, bx, cx), VectorType(ay, by, cy), VectorType(az, bz, cz));
186 bool is_nearly_zero =
true;
187 for (
int i = 0; i < Size; ++i)
188 is_nearly_zero = is_nearly_zero && math::isNearlyZero(m_values[i]);
189 return is_nearly_zero;
193 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator+=(
const ThatClass& b)
195 for (
int i = 0; i < Size; ++i)
196 m_values[i] += b.m_values[i];
200 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator-=(
const ThatClass& b)
202 for (
int i = 0; i < Size; ++i)
203 m_values[i] -= b.m_values[i];
209 for (
int i = 0; i < Size; ++i)
216 for (
int i = 0; i < Size; ++i)
221 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator+(
const ThatClass& a,
const ThatClass& b)
224 for (
int i = 0; i < Size; ++i)
225 v.m_values[i] = a.
m_values[i] + b.m_values[i];
229 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator-(
const ThatClass& a,
const ThatClass& b)
232 for (
int i = 0; i < Size; ++i)
233 v.m_values[i] = a.
m_values[i] - b.m_values[i];
237 constexpr ARCCORE_HOST_DEVICE ThatClass
operator-()
const
240 for (
int i = 0; i < Size; ++i)
241 v.m_values[i] = -m_values[i];
246 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(DataType a,
const ThatClass& mat)
249 for (
int i = 0; i < Size; ++i)
250 v.m_values[i] = a * mat.m_values[i];
254 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(
const ThatClass& mat, DataType b)
257 for (
int i = 0; i < Size; ++i)
258 v.m_values[i] = mat.m_values[i] * b;
262 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator/(
const ThatClass& mat, DataType b)
265 for (
int i = 0; i < Size; ++i)
266 v.m_values[i] = mat.m_values[i] / b;
276 friend constexpr ARCCORE_HOST_DEVICE
bool operator==(
const ThatClass& a,
const ThatClass& b)
278 for (
int i = 0; i < Size; ++i)
279 if (a.m_values[i] != b.m_values[i])
290 friend constexpr ARCCORE_HOST_DEVICE
bool operator!=(
const ThatClass& a,
const ThatClass& b)
298 constexpr ARCCORE_HOST_DEVICE VectorType operator()(
Int32 i)
const
300 ARCCORE_CHECK_AT(i, RowSize);
304 constexpr ARCCORE_HOST_DEVICE VectorType operator[](Int32 i)
const
306 ARCCORE_CHECK_AT(i, RowSize);
310 constexpr ARCCORE_HOST_DEVICE T& operator()(
Int32 i,
Int32 j)
312 ARCCORE_CHECK_AT(i, RowSize);
313 ARCCORE_CHECK_AT(j, ColumnSize);
314 return m_values[i](j);
317 constexpr ARCCORE_HOST_DEVICE T operator()(
Int32 i,
Int32 j)
const
319 ARCCORE_CHECK_AT(i, RowSize);
320 ARCCORE_CHECK_AT(j, ColumnSize);
321 return m_values[i](j);
325 constexpr ARCCORE_HOST_DEVICE
void setLine(
Int32 i,
const VectorType& v)
327 ARCCORE_CHECK_AT(i, RowSize);
333 VectorType& vx()
requires(RowSize >= 1)
338 VectorType vx() const requires(RowSize >= 1)
343 VectorType& vy()
requires(RowSize >= 2)
348 VectorType vy() const requires(RowSize >= 2)
353 VectorType& vz()
requires(RowSize >= 3)
358 VectorType vz() const requires(RowSize >= 3)
365 VectorType m_values[RowSize] = {};
374 constexpr ARCCORE_HOST_DEVICE
static bool _eq(T a, T b)
Petite matrice de taille fixe contenant RowSize lignes et ColumnSize colonnes.
constexpr __host__ static __device__ bool _eq(T a, T b)
Compare les valeurs de a et b avec le comparateur TypeEqualT.
friend constexpr __host__ __device__ ThatClass operator/(const ThatClass &mat, DataType b)
Division par un scalaire.
friend constexpr __host__ __device__ bool operator!=(const ThatClass &a, const ThatClass &b)
Compare deux triplets. Pour la notion d'égalité, voir operator==()
constexpr __host__ __device__ ThatClass & operator+=(const ThatClass &b)
Ajoute b au triplet.
constexpr __host__ static __device__ ThatClass zero()
Construit la matrice nulle.
constexpr __host__ __device__ bool isNearlyZero() const
Compare la matrice avec la matrice nulle.
constexpr __host__ __device__ ThatClass operator-() const
Créé un tenseur opposé au tenseur actuel.
constexpr __host__ __device__ ThatClass & operator/=(T b)
Divise chaque composante de la matrice par le réel b.
constexpr __host__ __device__ ThatClass & operator-=(const ThatClass &b)
Soustrait b au triplet.
constexpr __host__ static __device__ ThatClass fromLines(T ax, T bx, T cx, T ay, T by, T cy, T az, T bz, T cz)
Construit la matrice ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
friend constexpr __host__ __device__ bool operator==(const ThatClass &a, const ThatClass &b)
Compare composant pas composante l'instance courante à b.
NumMatrix()=default
Construit la matrice avec tous les coefficiants nuls.
friend constexpr __host__ __device__ ThatClass operator-(const ThatClass &a, const ThatClass &b)
Créé un triplet qui vaut b soustrait de ce triplet.
constexpr __host__ __device__ NumMatrix(const VectorType &ax, const VectorType &ay)
Construit la matrice avec les lignes (ax,ay)
constexpr __host__ __device__ ThatClass & operator*=(T b)
Multiple chaque composante de la matrice par le réel b.
constexpr __host__ __device__ NumMatrix(const VectorType &ax, const VectorType &ay, const VectorType &az)
Construit la matrice avec les lignes (ax,ay,az)
constexpr __host__ __device__ void setLine(Int32 i, const VectorType &v)
Positionne à v la valeur de la i-ème ligne.
constexpr __host__ __device__ NumMatrix(const VectorType &a1, const VectorType &a2, const VectorType &a3, const VectorType &a4, const VectorType &a5)
Construit la matrice avec les lignes (a1,a2,a3,a4,a5)
constexpr __host__ static __device__ ThatClass fromColumns(T ax, T ay, T az, T bx, T by, T bz, T cx, T cy, T cz)
Construit la matrice ((ax,bx,cx),(ay,by,cy),(az,bz,cz)).
constexpr __host__ __device__ NumMatrix(const VectorType &a1, const VectorType &a2, const VectorType &a3, const VectorType &a4)
Construit la matrice avec les lignes (a1,a2,a3,a4)
friend constexpr __host__ __device__ ThatClass operator*(const ThatClass &mat, DataType b)
Multiplication par un scalaire.
constexpr __host__ __device__ ThatClass & operator=(T v)
Affecte à l'instance le triplet (v,v,v).
friend constexpr __host__ __device__ ThatClass operator*(DataType a, const ThatClass &mat)
Multiplication par un scalaire.
constexpr __host__ __device__ NumMatrix(T v)
Construit l'instance avec le triplet (v,v,v).
friend constexpr __host__ __device__ ThatClass operator+(const ThatClass &a, const ThatClass &b)
Créé un triplet qui vaut ce triplet ajouté à b.
Petit vecteur de taille fixe de N données numériques.
T m_values[Size]
Valeurs du vecteur.
Classe gérant une matrice de réel de dimension 2x2.
constexpr __host__ static __device__ bool isEqual(const T &a, const T &b)
Compare a à b.
Espace de nom pour l'utilisation des accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int32_t Int32
Type entier signé sur 32 bits.