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 template <
int S = RowSize,
typename = std::enable_if_t<S == 2,
void>>
72 template <
int S = RowSize,
typename = std::enable_if_t<S == 3,
void>>
81 template <
int S = RowSize,
typename = std::enable_if_t<S == 4,
void>>
92 template <
int S = RowSize,
typename = std::enable_if_t<S == 4,
void>>
107 for (
int i = 0; i < Size; ++i)
111 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare2(),
void>>
113 :
NumMatrix(VectorType(v.x), VectorType(v.y))
116 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare3(),
void>>
117 explicit constexpr ARCCORE_HOST_DEVICE
NumMatrix(Real3x3 v)
118 :
NumMatrix(VectorType(v.x), VectorType(v.y), VectorType(v.z))
124 for (
int i = 0; i < Size; ++i)
129 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare2(),
void>>
132 *
this = ThatClass(v);
136 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare3(),
void>>
137 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator=(
const Real3x3& v)
139 *
this = ThatClass(v);
143 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare2(),
void>>
144 operator Real2x2()
const
146 return Real2x2(m_values[0], m_values[1]);
149 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare3(),
void>>
150 operator Real3x3()
const
152 return Real3x3(m_values[0], m_values[1], m_values[2]);
158 constexpr ARCCORE_HOST_DEVICE
static ThatClass
zero()
164 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare3(),
void>>
165 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)
171 template <
typename X = ThatClass,
typename = std::enable_if_t<X::isSquare3(),
void>>
172 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)
192 bool is_nearly_zero =
true;
193 for (
int i = 0; i < Size; ++i)
194 is_nearly_zero = is_nearly_zero && math::isNearlyZero(m_values[i]);
195 return is_nearly_zero;
199 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator+=(
const ThatClass& b)
201 for (
int i = 0; i < Size; ++i)
202 m_values[i] += b.m_values[i];
206 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator-=(
const ThatClass& b)
208 for (
int i = 0; i < Size; ++i)
209 m_values[i] -= b.m_values[i];
215 for (
int i = 0; i < Size; ++i)
222 for (
int i = 0; i < Size; ++i)
227 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator+(
const ThatClass& a,
const ThatClass& b)
230 for (
int i = 0; i < Size; ++i)
231 v.m_values[i] = a.m_values[i] + b.m_values[i];
235 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator-(
const ThatClass& a,
const ThatClass& b)
238 for (
int i = 0; i < Size; ++i)
239 v.m_values[i] = a.m_values[i] - b.m_values[i];
243 constexpr ARCCORE_HOST_DEVICE ThatClass
operator-()
const
246 for (
int i = 0; i < Size; ++i)
247 v.m_values[i] = -m_values[i];
252 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(DataType a,
const ThatClass& mat)
255 for (
int i = 0; i < Size; ++i)
256 v.m_values[i] = a * mat.m_values[i];
260 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(
const ThatClass& mat, DataType b)
263 for (
int i = 0; i < Size; ++i)
264 v.m_values[i] = mat.m_values[i] * b;
268 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator/(
const ThatClass& mat, DataType b)
271 for (
int i = 0; i < Size; ++i)
272 v.m_values[i] = mat.m_values[i] / b;
282 friend constexpr ARCCORE_HOST_DEVICE
bool operator==(
const ThatClass& a,
const ThatClass& b)
284 for (
int i = 0; i < Size; ++i)
285 if (a.m_values[i] != b.m_values[i])
296 friend constexpr ARCCORE_HOST_DEVICE
bool operator!=(
const ThatClass& a,
const ThatClass& b)
304 constexpr ARCCORE_HOST_DEVICE VectorType operator()(Int32 i)
const
306 ARCCORE_CHECK_AT(i, RowSize);
310 constexpr ARCCORE_HOST_DEVICE VectorType operator[](Int32 i)
const
312 ARCCORE_CHECK_AT(i, RowSize);
316 constexpr ARCCORE_HOST_DEVICE T& operator()(Int32 i, Int32 j)
318 ARCCORE_CHECK_AT(i, RowSize);
319 ARCCORE_CHECK_AT(j, ColumnSize);
320 return m_values[i](j);
323 constexpr ARCCORE_HOST_DEVICE T operator()(Int32 i, Int32 j)
const
325 ARCCORE_CHECK_AT(i, RowSize);
326 ARCCORE_CHECK_AT(j, ColumnSize);
327 return m_values[i](j);
333 ARCCORE_CHECK_AT(i, RowSize);
339 template <
int S = RowSize,
typename = std::enable_if_t<S >= 1,
void>>
344 template <
int S = RowSize,
typename = std::enable_if_t<S >= 1,
void>>
345 VectorType vx()
const
350 template <
int S = RowSize,
typename = std::enable_if_t<S >= 2,
void>>
355 template <
int S = RowSize,
typename = std::enable_if_t<S >= 2,
void>>
356 VectorType vy()
const
361 template <
int S = RowSize,
typename = std::enable_if_t<S >= 3,
void>>
366 template <
int S = RowSize,
typename = std::enable_if_t<S >= 3,
void>>
367 VectorType vz()
const
374 VectorType m_values[RowSize] = {};
383 constexpr ARCCORE_HOST_DEVICE
static bool _eq(T a, T b)
Petite matrice de taille fixe contenant RowSize lignes et ColumnSize colonnes.
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__ 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__ 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.
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__ ThatClass & operator*=(T b)
Multiple chaque composante de la matrice par le réel b.
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 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)).
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).
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__ NumMatrix(const VectorType &ax, const VectorType &ay)
Construit la matrice avec les lignes (ax,ay)
friend constexpr __host__ __device__ ThatClass operator+(const ThatClass &a, const ThatClass &b)
Créé un triplet qui vaut ce triplet ajouté à b.
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.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-