Arcane  4.2.1.0
User documentation
Loading...
Searching...
No Matches
MathNumeric.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/* MathNumeric.h (C) 2000-2026 */
9/* */
10/* Mathematical operations on numeric types (Real2, Real3, NumVector, ...) */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_MATHNUMERIC_H
13#define ARCCORE_BASE_MATHNUMERIC_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/NumVector.h"
18#include "arccore/base/NumMatrix.h"
19
20#include "arccore/base/MathReal2.h"
21#include "arccore/base/MathReal3.h"
22#include "arccore/base/MathReal2x2.h"
23#include "arccore/base/MathReal3x3.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::math
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33/*!
34 * \brief Compares the vector with the vector zero.
35 *
36 * The matrix is nearly zero if and only if each of its components
37 * is less than a given epsilon. The epsilon value used is that
38 * of FloatInfo<DataType>::nearlyEpsilon():
39 * \f[A=0 \Leftrightarrow |A.x|<\epsilon,|A.y|<\epsilon,|A.z|<\epsilon \f]
40 */
41template <typename DataType, int Size> constexpr ARCCORE_HOST_DEVICE bool
42isNearlyZero(const NumVector<DataType, Size>& v)
43{
44 bool is_nearly_zero = true;
45 for (int i = 0; i < Size; ++i)
46 is_nearly_zero = is_nearly_zero && math::isNearlyZero(v[i]);
47 return is_nearly_zero;
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52/*!
53 * \brief Compares the matrix with the zero matrix.
54 *
55 * The matrix is zero if and only if each of its components
56 * is less than a given epsilon. The epsilon value used is that
57 * of float_info<value_type>::nearlyEpsilon():
58 * \f[A=0 \Leftrightarrow |A.x|<\epsilon,|A.y|<\epsilon,|A.z|<\epsilon \f]
59 *
60 * \retval true if the matrix is equal to the zero matrix,
61 * \retval false otherwise.
62 */
63template <typename DataType, int RowSize, int ColumnSize> constexpr ARCCORE_HOST_DEVICE bool
65{
66 bool is_nearly_zero = true;
67 for (int i = 0; i < RowSize; ++i)
68 is_nearly_zero = is_nearly_zero && math::isNearlyZero(v.row(i));
69 return is_nearly_zero;
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75//! Returns the square of the L2 norm of the vector
76template <typename DataType, int Size> constexpr ARCCORE_HOST_DEVICE DataType
78{
79 DataType norm = {};
80 for (int i = 0; i < Size; ++i)
81 norm += v[i] * v[i];
82 return norm;
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88//! Returns the L2 norm of the vector
89template <typename DataType, int Size> ARCCORE_HOST_DEVICE Real
91{
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98} // namespace Arcane::math
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103#endif
Small fixed-size matrix containing RowSize rows and ColumnSize columns.
Small fixed-size vector of Size numerical data points.
Namespace for mathematical functions.
Definition MathUtils.h:36
constexpr __host__ __device__ DataType squareNormL2(const NumVector< DataType, Size > &v)
Returns the square of the L2 norm of the vector.
Definition MathNumeric.h:77
apfloat sqrt(apfloat v)
Square root of v.
Definition MathApfloat.h:69
double Real
Type representing a real number.