12#ifndef ARCANE_UTILS_NUMVECTOR_H
13#define ARCANE_UTILS_NUMVECTOR_H
17#include "arcane/utils/Real2.h"
18#include "arcane/utils/Real3.h"
42template <
typename T,
int Size>
45 static_assert(Size > 1,
"Size has to be strictly greater than 1");
46 static_assert(std::is_same_v<T, Real>,
"Only type 'Real' is allowed");
59 constexpr ARCCORE_HOST_DEVICE
NumVector(T
ax, T ay)
requires(Size == 2)
67 constexpr ARCCORE_HOST_DEVICE
NumVector(T
ax, T ay, T az)
requires(Size == 3)
76 constexpr ARCCORE_HOST_DEVICE
NumVector(T a1, T a2, T a3, T a4)
requires(Size == 4)
86 constexpr ARCCORE_HOST_DEVICE
NumVector(T a1, T a2, T a3, T a4, T a5)
requires(Size == 5)
96 template <
bool = true>
97 explicit constexpr ARCCORE_HOST_DEVICE
NumVector(
const T (&v)[Size])
99 for (
int i = 0; i < Size; ++i)
104 explicit constexpr ARCCORE_HOST_DEVICE
NumVector(std::array<T, Size> v)
106 for (
int i = 0; i < Size; ++i)
113 for (
int i = 0; i < Size; ++i)
117 explicit constexpr ARCCORE_HOST_DEVICE
NumVector(
Real2 v)
requires(Size == 2)
121 explicit constexpr ARCCORE_HOST_DEVICE
NumVector(Real3 v)
requires(Size == 3)
128 for (
int i = 0; i < Size; ++i)
133 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator=(
const Real2& v)
requires(Size == 2)
135 *
this = ThatClass(v);
139 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator=(
const Real3& v)
requires(Size == 3)
141 *
this = ThatClass(v);
145 operator Real2() const requires(Size == 2) {
return Real2(
m_values[0],
m_values[1]); }
151 constexpr ARCCORE_HOST_DEVICE
static ThatClass zero() {
return ThatClass(); }
155 constexpr ARCCORE_HOST_DEVICE
bool isNearlyZero()
const
157 bool is_nearly_zero =
true;
158 for (
int i = 0; i < Size; ++i)
159 is_nearly_zero = is_nearly_zero && math::isNearlyZero(
m_values[i]);
160 return is_nearly_zero;
167 for (
int i = 0; i < Size; ++i)
179 for (
int i = 0; i < Size; ++i)
187 for (
int i = 0; i < Size; ++i)
193 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator+=(
const ThatClass& b)
195 for (
int i = 0; i < Size; ++i)
203 for (
int i = 0; i < Size; ++i)
209 constexpr ARCCORE_HOST_DEVICE ThatClass&
operator-=(
const ThatClass& b)
211 for (
int i = 0; i < Size; ++i)
219 for (
int i = 0; i < Size; ++i)
227 for (
int i = 0; i < Size; ++i)
233 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator+(
const ThatClass& a,
const ThatClass& b)
236 for (
int i = 0; i < Size; ++i)
242 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator-(
const ThatClass& a,
const ThatClass& b)
245 for (
int i = 0; i < Size; ++i)
251 constexpr ARCCORE_HOST_DEVICE ThatClass
operator-()
const
254 for (
int i = 0; i < Size; ++i)
260 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(T a,
const ThatClass& vec)
263 for (
int i = 0; i < Size; ++i)
269 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator*(
const ThatClass& vec, T b)
272 for (
int i = 0; i < Size; ++i)
278 friend constexpr ARCCORE_HOST_DEVICE ThatClass
operator/(
const ThatClass& vec, T b)
281 for (
int i = 0; i < Size; ++i)
292 friend constexpr ARCCORE_HOST_DEVICE
bool operator==(
const ThatClass& a,
const ThatClass& b)
294 for (
int i = 0; i < Size; ++i)
304 friend constexpr ARCCORE_HOST_DEVICE
bool operator!=(
const ThatClass& a,
const ThatClass& b)
309 constexpr ARCCORE_HOST_DEVICE T& operator()(
Int32 i)
311 ARCCORE_CHECK_AT(i, Size);
314 constexpr ARCCORE_HOST_DEVICE T operator()(Int32 i)
const
316 ARCCORE_CHECK_AT(i, Size);
319 constexpr ARCCORE_HOST_DEVICE T& operator[](
Int32 i)
321 ARCCORE_CHECK_AT(i, Size);
324 constexpr ARCCORE_HOST_DEVICE T operator[](
Int32 i)
const
326 ARCCORE_CHECK_AT(i, Size);
331 T&
vx()
requires(Size >= 1)
336 T
vx() const requires(Size >= 1)
342 T&
vy()
requires(Size >= 2)
347 T
vy() const requires(Size >= 2)
353 T&
vz()
requires(Size >= 3)
358 T
vz() const requires(Size >= 3)
375 constexpr ARCCORE_HOST_DEVICE
static bool
382 ARCCORE_HOST_DEVICE
static T
_sqrt(T a)
Small fixed-size vector of N numerical data points.
T & vy()
Value of the second component.
constexpr __host__ __device__ NumVector(T ax, T ay, T az)
Constructs with the triplet (ax,ay,az).
T vz() const
Value of the third component.
constexpr __host__ __device__ ThatClass & operator=(Real v)
Assigns the triplet (v,v,v) to the instance.
constexpr __host__ __device__ ThatClass & operator*=(T b)
Multiplies each component by b.
friend constexpr __host__ __device__ bool operator!=(const ThatClass &a, const ThatClass &b)
Compares two vectors For the notion of equality, see operator==().
T vy() const
Value of the second component.
constexpr __host__ __device__ NumVector(T a1, T a2, T a3, T a4, T a5)
Constructs with the quintuplet (a1,a2,a3,a4,a5).
__host__ __device__ ThatClass absolute() const
Absolute value component by component.
NumVector()=default
Constructs the zero vector.
constexpr __host__ __device__ ThatClass & operator/=(T b)
Divides each component by b.
T & vx()
Value of the first component.
friend constexpr __host__ __device__ bool operator==(const ThatClass &a, const ThatClass &b)
Compares the current instance component by component to b.
constexpr __host__ static __device__ bool _eq(T a, T b)
Compares the values of a and b using the TypeEqualT comparator.
constexpr __host__ __device__ ThatClass & operator-=(const ThatClass &b)
Subtracts b from the instance.
friend constexpr __host__ __device__ ThatClass operator-(const ThatClass &a, const ThatClass &b)
Creates a triplet that equals b subtracted from this triplet.
friend constexpr __host__ __device__ ThatClass operator*(const ThatClass &vec, T b)
Multiplication by a scalar.
constexpr __host__ __device__ NumVector(T a1, T a2, T a3, T a4)
Constructs with the quadruplet (a1,a2,a3,a4).
constexpr __host__ __device__ NumVector(T v)
Constructs the instance with the value v for each component.
constexpr __host__ __device__ ThatClass & operator-=(T b)
Subtracts b from each component of the instance.
constexpr __host__ __device__ NumVector(std::array< T, Size > v)
Constructs the instance with the value v for each component.
friend constexpr __host__ __device__ ThatClass operator/(const ThatClass &vec, T b)
Division by a scalar.
T vx() const
Value of the first component.
constexpr __host__ __device__ NumVector(T ax, T ay)
Constructs with the pair (ax,ay).
constexpr __host__ __device__ ThatClass & operator+=(T b)
Adds b to each component of the instance.
__host__ static __device__ T _sqrt(T a)
Returns the square root of a.
constexpr __host__ __device__ Real squareNormL2() const
Returns the square of the L2 norm of the triplet .
constexpr __host__ __device__ NumVector(const T(&v)[Size])
Constructs the instance with the value v for each component.
friend constexpr __host__ __device__ ThatClass operator*(T a, const ThatClass &vec)
Multiplication by a scalar.
T & vz()
Value of the third component.
constexpr __host__ __device__ ThatClass & operator+=(const ThatClass &b)
Adds b to the instance.
__host__ __device__ Real normL2() const
Returns the L2 norm of the triplet .
constexpr __host__ __device__ ThatClass operator-() const
Creates a triplet opposite to the current triplet.
friend constexpr __host__ __device__ ThatClass operator+(const ThatClass &a, const ThatClass &b)
Creates a triplet that equals this triplet added to b.
Class managing a 2-dimensional real vector.
Namespace for accelerator usage.
__host__ __device__ double sqrt(double v)
Square root of v.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.