Rodin::Math namespace

Module for general mathematical operations.

Classes

template<class Operator, class Vector>
class LinearSystem
Represents a linear system of equations.
template<class MatrixScalar, class VectorScalar>
class LinearSystem<Math::Matrix<MatrixScalar>, Math::Vector<VectorScalar>>
Linear system specialization for dense matrices.
template<class MatrixScalar, class VectorScalar>
class LinearSystem<Math::SparseMatrix<MatrixScalar>, Math::Vector<VectorScalar>>
Linear system specialization for sparse matrices.
template<class Matrix, class Vector, class Derived>
class LinearSystemBase
Base class for linear systems of the form $ Ax = b $ .
class Rad
Represents an angle in radians.
template<class Derived, class T>
class Unit
Base class for units using CRTP.

Typedefs

template<class ScalarType>
using Matrix = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>
Dynamic-size dense matrix type.
using RealMatrix = Matrix<Real>
Real-valued dense matrix.
using ComplexMatrix = Matrix<Complex>
Complex-valued dense matrix.
template<class ScalarType>
using SpatialMatrix = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic, 0, RODIN_MAXIMAL_SPACE_DIMENSION, RODIN_MAXIMAL_SPACE_DIMENSION>
Spatial matrix with bounded maximum dimensions.
using PointMatrix = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, 0, RODIN_MAXIMAL_SPACE_DIMENSION, Eigen::Dynamic>
Point matrix with bounded row dimension.
template<class ScalarType, size_t Rows, size_t Cols>
using FixedSizeMatrix = Eigen::Matrix<ScalarType, Rows, Cols>
Fixed-size matrix type.
template<class ScalarType>
using SparseMatrix = Eigen::SparseMatrix<ScalarType>
Sparse matrix type.
template<class ScalarType>
using Vector = Eigen::VectorX<ScalarType>
Dynamic-size dense vector type.
using ComplexVector = Vector<Complex>
Dynamic-size complex-valued vector.
template<class ScalarType>
using SpatialVector = Eigen::Matrix<ScalarType, Eigen::Dynamic, 1, 0, RODIN_MAXIMAL_SPACE_DIMENSION, 1>
Spatial vector with bounded maximum size.
using SpatialPoint = SpatialVector<Real>
Real-valued spatial vector for point coordinates.
template<class ScalarType, size_t Size>
using FixedSizeVector = Eigen::Vector<ScalarType, Size>
Fixed-size vector type.
template<class ScalarType>
using Vector2 = FixedSizeVector<ScalarType, 2>
2D fixed-size vector.
template<class ScalarType>
using Vector3 = FixedSizeVector<ScalarType, 3>
3D fixed-size vector.
template<class ScalarType>
using Vector4 = FixedSizeVector<ScalarType, 4>
4D fixed-size vector.
template<class ScalarType>
using Vector8 = FixedSizeVector<ScalarType, 8>
8D fixed-size vector.
template<class ScalarType>
using Vector16 = FixedSizeVector<ScalarType, 16>
16D fixed-size vector.
template<class ScalarType>
using Vector32 = FixedSizeVector<ScalarType, 32>
32D fixed-size vector.
template<class ScalarType>
using Vector64 = FixedSizeVector<ScalarType, 64>
64D fixed-size vector.
template<class ScalarType>
using Vector128 = FixedSizeVector<ScalarType, 128>
128D fixed-size vector.

Functions

template<class T>
auto abs(const T& x) -> auto constexpr
Computes the absolute value of a value.
template<class T>
auto exp(const T& x) -> auto constexpr
Computes the exponential function.
auto conj(const Complex& x) -> Complex constexpr
Computes the complex conjugate of a complex number.
template<class T>
auto conj(const Eigen::MatrixBase<T>& x) -> auto constexpr
Computes the conjugate of an Eigen matrix.
auto conj(const Real& x) -> Real constexpr
Identity conjugate for real numbers.
template<class Base, class Exponent>
auto pow2(const Base& base) -> auto constexpr
Computes the square of a value.
template<class Base, class Exponent>
auto pow(const Base& base, const Exponent& exponent) -> auto constexpr
Computes a power with arbitrary exponent.
template<class T>
auto sqrt(const T& x) -> auto constexpr
Computes the square root of a value.
template<class T>
auto isNaN(const T& x) -> Boolean constexpr
Determines if a floating point number is not-a-number (NaN).
auto isNaN(const Complex& x) -> Boolean constexpr
Determines if a complex number is not-a-number (NaN).
template<class T>
auto isInf(const T& x) -> Boolean constexpr
Determines if a floating point number is infinite.
template<class T>
auto cos(const T& x) -> auto constexpr
Computes the cosine function.
template<class T>
auto cosh(const T& x) -> auto constexpr
Computes the hyperbolic cosine function.
template<class T>
auto sin(const T& x) -> auto constexpr
Computes the sine function.
template<class T>
auto sinh(const T& x) -> auto constexpr
Computes the hyperbolic sine function.
template<class T>
auto tan(const T& x) -> auto constexpr
Computes the tangent function.
template<typename T>
auto sgn(const T& x) -> T constexpr
Computes the sign (signum) function.
template<class T>
auto binom(const T& n, const T& k) -> T constexpr
Computes the binomial coefficient.
template<class T>
auto factorial(const T& n) -> T constexpr
Computes the factorial function.
template<class T>
auto permutation(const T& n, const T& k) -> T constexpr
Computes the permutation function.
template<class T>
auto nan() -> auto constexpr
Returns a quiet NaN (not-a-number) value.
auto nan() -> Complex constexpr
Returns a complex NaN value.
template<class LHS, class RHS>
auto sum(const LHS& lhs, const RHS& rhs) -> auto constexpr
Computes the sum of two values.
template<class Operand>
auto minus(const Operand& op) -> auto constexpr
Computes the unary minus (negation).
template<class LHS, class RHS>
auto minus(const LHS& lhs, const RHS& rhs) -> auto constexpr
Computes the difference of two values.
template<class LHS, class RHS>
auto mult(const LHS& lhs, const RHS& rhs) -> auto constexpr
Computes the product of two values.
template<class LHS, class RHS>
auto division(const LHS& lhs, const RHS& rhs) -> auto constexpr
Computes the division of two values.
auto dot(const Real& lhs, const Real& rhs) -> Real constexpr
Computes the dot product of two real numbers.
auto dot(const Complex& lhs, const Complex& rhs) -> Complex constexpr
Computes the dot product of two complex numbers.
template<class LHSDerived, class RHSDerived>
auto dot(const Eigen::MatrixBase<LHSDerived>& lhs, const Eigen::MatrixBase<RHSDerived>& rhs) -> auto constexpr
Computes the dot product of two Eigen vectors/matrices.
template<class AScalarType, class YScalarType, class XScalarType>
void axpy(SparseMatrix<YScalarType>& y, AScalarType alpha, const SparseMatrix<XScalarType>& x)
Performs the AXPY operation on sparse matrices.

Typedef documentation

template<class ScalarType>
using Rodin::Math::Matrix = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>

Dynamic-size dense matrix type.

Template parameters
ScalarType The element type (e.g., Real, Complex)

A dense matrix with both dimensions determined at runtime. The matrix is stored in column-major order (Fortran style) and supports standard linear algebra operations.

using Rodin::Math::RealMatrix = Matrix<Real>

Real-valued dense matrix.

Convenience alias for Matrix<Real>.

using Rodin::Math::ComplexMatrix = Matrix<Complex>

Complex-valued dense matrix.

Convenience alias for Matrix<Complex>, commonly used in eigenvalue problems, frequency-domain analysis, and other applications requiring complex arithmetic.

template<class ScalarType>
using Rodin::Math::SpatialMatrix = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic, 0, RODIN_MAXIMAL_SPACE_DIMENSION, RODIN_MAXIMAL_SPACE_DIMENSION>

Spatial matrix with bounded maximum dimensions.

Template parameters
ScalarType The element type

A dynamic-size matrix with maximum dimensions bounded by RODIN_MAXIMAL_SPACE_DIMENSION. Used for geometric transformations, Jacobians, and other spatial operators to optimize memory allocation.

Typical uses:

  • Jacobian matrices: $ J = \frac{\partial \mathbf{f}}{\partial \mathbf{x}} $
  • Metric tensors
  • Local coordinate transformations

using Rodin::Math::PointMatrix = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, 0, RODIN_MAXIMAL_SPACE_DIMENSION, Eigen::Dynamic>

Point matrix with bounded row dimension.

A dynamic-size matrix where the number of rows is bounded by RODIN_MAXIMAL_SPACE_DIMENSION. Commonly used to store collections of spatial points as columns.

Example: storing vertex coordinates of a mesh element where each column represents one vertex's coordinates.

template<class ScalarType, size_t Rows, size_t Cols>
using Rodin::Math::FixedSizeMatrix = Eigen::Matrix<ScalarType, Rows, Cols>

Fixed-size matrix type.

Template parameters
ScalarType The element type
Rows The number of rows (must be known at compile time)
Cols The number of columns (must be known at compile time)

A compile-time fixed-size matrix. Both dimensions are known at compile time, enabling optimizations and stack allocation.

Example uses:

  • 2×2 rotation matrices
  • 3×3 transformation matrices
  • Small dense blocks in larger systems

template<class ScalarType>
using Rodin::Math::SparseMatrix = Eigen::SparseMatrix<ScalarType>

Sparse matrix type.

Template parameters
ScalarType The element type (e.g., Real, Complex)

A sparse matrix stores only the non-zero elements, making it memory-efficient for large matrices arising from finite element discretizations where most entries are zero. The matrix uses compressed column storage (CCS) format by default.

Storage Format

Eigen's SparseMatrix uses Compressed Column Storage (CCS), also known as Compressed Sparse Column (CSC) format, which stores:

  • Non-zero values
  • Row indices for each non-zero value
  • Column pointers indicating where each column starts
Typical Applications
  • Stiffness matrices: $ K $ in $ Ku = f $
  • Mass matrices: $ M $ in $ M\ddot{u} + Ku = f $
  • Discretized differential operators

template<class ScalarType>
using Rodin::Math::Vector = Eigen::VectorX<ScalarType>

Dynamic-size dense vector type.

Template parameters
ScalarType The element type (e.g., Real, Complex)

A column vector with dynamic size determined at runtime. The vector supports standard linear algebra operations.

using Rodin::Math::ComplexVector = Vector<Complex>

Dynamic-size complex-valued vector.

Convenience alias for Vector<Complex>.

template<class ScalarType>
using Rodin::Math::SpatialVector = Eigen::Matrix<ScalarType, Eigen::Dynamic, 1, 0, RODIN_MAXIMAL_SPACE_DIMENSION, 1>

Spatial vector with bounded maximum size.

Template parameters
ScalarType The element type

A dynamic-size vector with maximum size bounded by RODIN_MAXIMAL_SPACE_DIMENSION. Used for geometric quantities in 2D or 3D space to optimize memory allocation.

using Rodin::Math::SpatialPoint = SpatialVector<Real>

Real-valued spatial vector for point coordinates.

Convenience alias for SpatialVector<Real>, commonly used to represent points in 2D or 3D space.

template<class ScalarType, size_t Size>
using Rodin::Math::FixedSizeVector = Eigen::Vector<ScalarType, Size>

Fixed-size vector type.

Template parameters
ScalarType The element type
Size The number of elements (must be known at compile time)

A compile-time fixed-size column vector. The size is known at compile time, enabling optimizations and stack allocation.

template<class ScalarType>
using Rodin::Math::Vector2 = FixedSizeVector<ScalarType, 2>

2D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 2 elements.

template<class ScalarType>
using Rodin::Math::Vector3 = FixedSizeVector<ScalarType, 3>

3D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 3 elements.

template<class ScalarType>
using Rodin::Math::Vector4 = FixedSizeVector<ScalarType, 4>

4D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 4 elements.

template<class ScalarType>
using Rodin::Math::Vector8 = FixedSizeVector<ScalarType, 8>

8D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 8 elements.

template<class ScalarType>
using Rodin::Math::Vector16 = FixedSizeVector<ScalarType, 16>

16D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 16 elements.

template<class ScalarType>
using Rodin::Math::Vector32 = FixedSizeVector<ScalarType, 32>

32D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 32 elements.

template<class ScalarType>
using Rodin::Math::Vector64 = FixedSizeVector<ScalarType, 64>

64D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 64 elements.

template<class ScalarType>
using Rodin::Math::Vector128 = FixedSizeVector<ScalarType, 128>

128D fixed-size vector.

Template parameters
ScalarType The element type

A vector with exactly 128 elements.

Function documentation

template<class T>
auto Rodin::Math::abs(const T& x) constexpr

Computes the absolute value of a value.

Template parameters
T Type of value (Real, Complex, etc.)
Parameters
in Value
Returns Absolute value $ |x| $

Returns $ |x| $ , the absolute value (magnitude) of $ x $ .

template<class T>
auto Rodin::Math::exp(const T& x) constexpr

Computes the exponential function.

Template parameters
T Type of value
Parameters
in Exponent
Returns $ e^x $

Returns $ e^x $ where $ e \approx 2.71828 $ is Euler's number.

Complex Rodin::Math::conj(const Complex& x) constexpr

Computes the complex conjugate of a complex number.

Parameters
in Complex number
Returns Complex conjugate $ \bar{x} $

For $ z = a + bi $ , returns $ \bar{z} = a - bi $ .

template<class T>
auto Rodin::Math::conj(const Eigen::MatrixBase<T>& x) constexpr

Computes the conjugate of an Eigen matrix.

Template parameters
T Eigen matrix type
Parameters
in Matrix
Returns Conjugate matrix

For matrices with complex entries, returns the element-wise conjugate.

Real Rodin::Math::conj(const Real& x) constexpr

Identity conjugate for real numbers.

Parameters
in Real number
Returns $ x $

For real numbers, the conjugate is the number itself.

template<class Base, class Exponent>
auto Rodin::Math::pow2(const Base& base) constexpr

Computes the square of a value.

Template parameters
Base Type of the value
Exponent Unused template parameter for compatibility
Parameters
base in Value to square
Returns $ \text{base}^2 $

Returns $ x^2 = x \times x $ efficiently without calling std::pow.

template<class Base, class Exponent>
auto Rodin::Math::pow(const Base& base, const Exponent& exponent) constexpr

Computes a power with arbitrary exponent.

Template parameters
Base Type of the base
Exponent Type of the exponent
Parameters
base in Base value $ x $
exponent in Exponent value $ y $
Returns $ x^y $

Returns $ x^y $ where $ x $ is the base and $ y $ is the exponent.

template<class T>
auto Rodin::Math::sqrt(const T& x) constexpr

Computes the square root of a value.

Template parameters
T Type of value
Parameters
in Value (must be non-negative for real types)
Returns $ \sqrt{x} $

Returns $ \sqrt{x} $ , the principal square root of $ x $ .

template<class T>
Boolean Rodin::Math::isNaN(const T& x) constexpr

Determines if a floating point number is not-a-number (NaN).

Template parameters
T Type of value
Parameters
in Value to check
Returns True if $ x $ is NaN, false otherwise

Checks if $ x $ is NaN (not a number), which typically results from undefined operations like $ 0/0 $ or $ \sqrt{-1} $ for reals.

Boolean Rodin::Math::isNaN(const Complex& x) constexpr

Determines if a complex number is not-a-number (NaN).

Parameters
in Complex number to check
Returns True if real or imaginary part is NaN, false otherwise

Returns true if either the real or imaginary part is NaN.

template<class T>
Boolean Rodin::Math::isInf(const T& x) constexpr

Determines if a floating point number is infinite.

Template parameters
T Type of value
Parameters
in Value to check
Returns True if $ x $ is $ +\infty $ or $ -\infty $ , false otherwise

Checks if $ x = \pm\infty $ , which can result from overflow or operations like $ 1/0 $ .

template<class T>
auto Rodin::Math::cos(const T& x) constexpr

Computes the cosine function.

Template parameters
T Type of value
Parameters
in Angle in radians
Returns $ \cos(x) $

Returns $ \cos(x) $ where $ x $ is in radians.

template<class T>
auto Rodin::Math::cosh(const T& x) constexpr

Computes the hyperbolic cosine function.

Template parameters
T Type of value
Parameters
in Value
Returns $ \cosh(x) $

Returns $ \cosh(x) = \frac{e^x + e^{-x}}{2} $ .

template<class T>
auto Rodin::Math::sin(const T& x) constexpr

Computes the sine function.

Template parameters
T Type of value
Parameters
in Angle in radians
Returns $ \sin(x) $

Returns $ \sin(x) $ where $ x $ is in radians.

template<class T>
auto Rodin::Math::sinh(const T& x) constexpr

Computes the hyperbolic sine function.

Template parameters
T Type of value
Parameters
in Value
Returns $ \sinh(x) $

Returns $ \sinh(x) = \frac{e^x - e^{-x}}{2} $ .

template<class T>
auto Rodin::Math::tan(const T& x) constexpr

Computes the tangent function.

Template parameters
T Type of value
Parameters
in Angle in radians
Returns $ \tan(x) $

Returns $ \tan(x) = \frac{\sin(x)}{\cos(x)} $ where $ x $ is in radians.

template<typename T>
T Rodin::Math::sgn(const T& x) constexpr

Computes the sign (signum) function.

Template parameters
T Type of value
Parameters
in Value
Returns Sign of $ x $ : -1, 0, or +1

Returns:

\[ \text{sgn}(x) = \begin{cases} -1 & \text{if } x < 0 \\ 0 & \text{if } x = 0 \\ +1 & \text{if } x > 0 \end{cases} \]

template<class T>
T Rodin::Math::binom(const T& n, const T& k) constexpr

Computes the binomial coefficient.

Template parameters
T Type of value (typically Integer)
Parameters
in Total number of items
in Number of items to choose
Returns $ \binom{n}{k} $

Returns $ \binom{n}{k} = \frac{n!}{k!(n-k)!} $ , the number of ways to choose $ k $ items from $ n $ items without regard to order.

template<class T>
T Rodin::Math::factorial(const T& n) constexpr

Computes the factorial function.

Template parameters
T Type of value (typically Integer)
Parameters
in Non-negative integer
Returns $ n! $

Returns $ n! = 1 \times 2 \times 3 \times \cdots \times n $ .

template<class T>
T Rodin::Math::permutation(const T& n, const T& k) constexpr

Computes the permutation function.

Template parameters
T Type of value (typically Integer)
Parameters
in Total number of items
in Number of items to arrange
Returns $ P(n, k) $

Returns $ P(n, k) = \frac{n!}{(n-k)!} $ , the number of ways to arrange $ k $ items from $ n $ items where order matters.

template<class T>
auto Rodin::Math::nan() constexpr

Returns a quiet NaN (not-a-number) value.

Template parameters
T Type of value (must be a floating point type)
Returns Quiet NaN value of type T

Returns a NaN value of the specified type, useful for indicating undefined or invalid results.

Complex Rodin::Math::nan() constexpr

Returns a complex NaN value.

Returns Complex NaN value

Returns a complex number where both real and imaginary parts are NaN.

template<class LHS, class RHS>
auto Rodin::Math::sum(const LHS& lhs, const RHS& rhs) constexpr

Computes the sum of two values.

Template parameters
LHS Type of left-hand side
RHS Type of right-hand side
Parameters
lhs in Left-hand side operand
rhs in Right-hand side operand
Returns $ \text{lhs} + \text{rhs} $

Returns $ \text{lhs} + \text{rhs} $ . This function is used internally for type deduction in the form language.

template<class Operand>
auto Rodin::Math::minus(const Operand& op) constexpr

Computes the unary minus (negation).

Template parameters
Operand Type of operand
Parameters
op in Operand to negate
Returns $ -\text{op} $

Returns $ -\text{op} $ . This function is used internally for type deduction in the form language.

template<class LHS, class RHS>
auto Rodin::Math::minus(const LHS& lhs, const RHS& rhs) constexpr

Computes the difference of two values.

Template parameters
LHS Type of left-hand side
RHS Type of right-hand side
Parameters
lhs in Left-hand side operand
rhs in Right-hand side operand
Returns $ \text{lhs} - \text{rhs} $

Returns $ \text{lhs} - \text{rhs} $ . This function is used internally for type deduction in the form language.

template<class LHS, class RHS>
auto Rodin::Math::mult(const LHS& lhs, const RHS& rhs) constexpr

Computes the product of two values.

Template parameters
LHS Type of left-hand side
RHS Type of right-hand side
Parameters
lhs in Left-hand side operand
rhs in Right-hand side operand
Returns $ \text{lhs} \times \text{rhs} $

Returns $ \text{lhs} \times \text{rhs} $ . This function is used internally for type deduction in the form language.

template<class LHS, class RHS>
auto Rodin::Math::division(const LHS& lhs, const RHS& rhs) constexpr

Computes the division of two values.

Template parameters
LHS Type of left-hand side
RHS Type of right-hand side
Parameters
lhs in Left-hand side operand (numerator)
rhs in Right-hand side operand (denominator)
Returns $ \text{lhs} / \text{rhs} $

Returns $ \text{lhs} / \text{rhs} $ . This function is used internally for type deduction in the form language.

Real Rodin::Math::dot(const Real& lhs, const Real& rhs) constexpr

Computes the dot product of two real numbers.

Parameters
lhs in Left-hand side operand
rhs in Right-hand side operand
Returns $ \text{lhs} \times \text{rhs} $

For real numbers, the dot product is simply multiplication: $ \text{lhs} \cdot \text{rhs} = \text{lhs} \times \text{rhs} $ .

Complex Rodin::Math::dot(const Complex& lhs, const Complex& rhs) constexpr

Computes the dot product of two complex numbers.

Parameters
lhs in Left-hand side complex number
rhs in Right-hand side complex number
Returns $ \text{lhs} \times \overline{\text{rhs}} $

For complex numbers, the dot product uses conjugation: $ z_1 \cdot z_2 = z_1 \times \overline{z_2} $ .

template<class LHSDerived, class RHSDerived>
auto Rodin::Math::dot(const Eigen::MatrixBase<LHSDerived>& lhs, const Eigen::MatrixBase<RHSDerived>& rhs) constexpr

Computes the dot product of two Eigen vectors/matrices.

Template parameters
LHSDerived Eigen type of left-hand side
RHSDerived Eigen type of right-hand side
Parameters
lhs in Left-hand side vector/matrix
rhs in Right-hand side vector/matrix
Returns Dot product (scalar)

For vectors $ \mathbf{u} $ and $ \mathbf{v} $ , computes:

\[ \mathbf{u} \cdot \mathbf{v} = \sum_i u_i \overline{v_i} \]

where $ \overline{v_i} $ is the complex conjugate (identity for real values).

template<class AScalarType, class YScalarType, class XScalarType>
void Rodin::Math::axpy(SparseMatrix<YScalarType>& y, AScalarType alpha, const SparseMatrix<XScalarType>& x)

Performs the AXPY operation on sparse matrices.

Template parameters
AScalarType Scalar type for alpha
YScalarType Scalar type for matrix y
XScalarType Scalar type for matrix x
Parameters
in/out Matrix to be updated (accumulated result)
alpha in Scalar multiplier for x
in Matrix to be scaled and added to y

Computes $ y \leftarrow y + \alpha x $ where $ y $ and $ x $ are sparse matrices and $ \alpha $ is a scalar.

This is the sparse matrix version of the Level 1 BLAS AXPY operation.