Mathematical Functions

Mathematical utility functions for rotations, random number generation, statistics, and numerical solving.

Overview

The Maths module provides essential mathematical utilities for continuum mechanics simulations:

  • Rotation: the Rotation class and the Voigt rotation helpers (see The Rotation Module)

  • Random numbers and statistics: random draws, probability distributions, peak functions

  • Local solvers: Newton and Fischer-Burmeister solvers of the return-mapping systems, Lagrange penalty functions, quadratic roots

  • Fixed-size kernels: 3x3 spectral decompositions and fixed-order products used in the per-point loops

Functions

enum class NCPMethod : int

Complementarity function of a local return-mapping Newton (the loops on Fischer_Burmeister_m).

A numerical setting of the run, not a material parameter: solver_params::ncp and state_variables::ncp carry its code, set by the ncp option of solve and sim.umat (see the UMAT catalogue). Fischer-Burmeister, the historical smoothing, is the default.

Values:

enumerator fischer_burmeister

normalised Fischer-Burmeister function (Fischer_Burmeister_m)

enumerator min_fb_fallback

min-NCP semi-smooth Newton on uncoupled rows, Fischer-Burmeister once the error grows

enumerator active_set

min-NCP semi-smooth Newton on every row, the coupled rows solved together on their active set, the same fallback

constexpr int voigt_index[3][3] = {{0, 3, 4}, {3, 1, 5}, {4, 5, 2}}

Voigt index of the pair (i,j): 11, 22, 33, 12, 13, 23 -> 0..5 (symmetric in i, j).

constexpr int voigt_i[6] = {0, 1, 2, 0, 0, 1}

First index i of the Voigt entry I.

constexpr int voigt_j[6] = {0, 1, 2, 1, 2, 2}

Second index j of the Voigt entry I.

bool eig_sym_3x3(arma::vec::fixed<3> &lam, arma::mat::fixed<3, 3> &Q, const arma::mat::fixed<3, 3> &A)

Eigen-decomposition of a symmetric 3x3 matrix, \( \mathbf{A} = \mathbf{Q}\,\mathrm{diag}(\boldsymbol{\lambda})\,\mathbf{Q}^T \).

Fixed-size storage, no heap allocation and no LAPACK call. Two solvers behind one contract:

  • the deviatoric closed form of Scherzinger and Dohrmann (2008): the most distinct eigenvalue \( \eta_1 \) of \( \mathbf{S} = \mathrm{dev}\,\mathbf{A} \) from the Lode angle, its eigenvector from two columns of \( \mathbf{S} - \eta_1\mathbf{I} \), then one rotation of the 2x2 restriction on the complement. Robust for double and nearly double eigenvalues, accurate to \( \epsilon\,\max_a|\lambda_a| \), about 2.4 times cheaper than Jacobi;

  • cyclic Jacobi rotations (Kopp 2008, dsyevj3), accurate to the last digits for every eigenvalue, the small ones of a stiff SPD matrix included. It serves the matrices with at most one nonzero off-diagonal entry (a diagonal A is returned exactly, Q a permutation), and replaces the closed form when \( \min_a|\lambda_a| < 10^{-2}\max_a|\lambda_a| \), where the absolute accuracy of the closed form is no longer a relative one on the small eigenvalue.

Only the upper triangle of A is read. The eigenvalues come in ascending order, as with arma::eig_sym; the eigenvectors are the orthonormal columns of Q (sign arbitrary).

This is the solver behind the per-point spectral functions of the finite-strain kinematics (polar decompositions, logarithmic strains, Daleckii-Krein derivatives).

Parameters:
  • lam – [out] eigenvalues, ascending

  • Q – [out] eigenvectors (columns)

  • A – [in] symmetric matrix (upper triangle read)

Returns:

false when A is not finite or the iteration does not converge (as arma::eig_sym)

arma::mat::fixed<3, 3> spectral_compose_3x3(const arma::mat::fixed<3, 3> &Q, const arma::vec::fixed<3> &f)

Symmetric matrix of given eigenvalues on a given eigenbasis, \( \mathbf{Q}\,\mathrm{diag}(\mathbf{f})\,\mathbf{Q}^T \).

The upper triangle is computed and mirrored: the result is exactly symmetric.

Parameters:
  • Q – eigenvectors (columns)

  • f – eigenvalues of the result

Returns:

the 3x3 symmetric matrix

inline arma::mat::fixed<3, 3> spectral_congruence(const arma::mat::fixed<3, 3> &N, const arma::mat::fixed<3, 3> &K, const arma::mat::fixed<3, 3> &X)

Spectral congruence of a 3x3 matrix on an eigenbasis, \( \sum_{a,b} K_{ab}\,\mathbf{P}_a \mathbf{X} \mathbf{P}_b = \mathbf{N}\left(\mathbf{K} \circ \mathbf{N}^T \mathbf{X} \mathbf{N}\right)\mathbf{N}^T \).

\( \mathbf{P}_a = \mathbf{n}_a \otimes \mathbf{n}_a \) are the eigenprojectors of the orthonormal columns of N and \( \circ \) the entrywise product: the form of the Daleckii-Krein derivatives of isotropic matrix functions, with \( K_{ab} \) their divided differences.

Parameters:
  • N – eigenvectors (orthonormal columns), e.g. from eig_sym_3x3

  • K – coefficients \( K_{ab} \)

  • X – the 3x3 matrix

Returns:

\( \mathbf{N}(\mathbf{K} \circ \mathbf{N}^T \mathbf{X} \mathbf{N})\mathbf{N}^T \)

bool sqrtmat_sympd_3x3(arma::mat::fixed<3, 3> &out, const arma::mat::fixed<3, 3> &A)

Square root of a symmetric positive semi-definite 3x3 matrix (as arma::sqrtmat_sympd).

Parameters:
  • out – [out] the square root

  • A – [in] symmetric matrix

Returns:

false when the decomposition fails or an eigenvalue is negative

bool logmat_sympd_3x3(arma::mat::fixed<3, 3> &out, const arma::mat::fixed<3, 3> &A)

Logarithm of a symmetric positive definite 3x3 matrix (as arma::logmat_sympd).

Parameters:
  • out – [out] the logarithm

  • A – [in] symmetric matrix

Returns:

false when the decomposition fails or an eigenvalue is not positive

bool expmat_sym_3x3(arma::mat::fixed<3, 3> &out, const arma::mat::fixed<3, 3> &A)

Exponential of a symmetric 3x3 matrix (as arma::expmat_sym).

Parameters:
  • out – [out] the exponential

  • A – [in] symmetric matrix

Returns:

false when the decomposition fails

double lagrange_exp(const double &h, const double &c, const double &p0)

Exponential Lagrange multiplier (penalty), as the exponential contact pressure in Abaqus.

\[ \lambda(h) = \frac{p_0}{e - 1}\left(\frac{h}{c} + 1\right)\left(e^{h/c + 1} - 1\right) \]
for \( h > -c \), and \( \lambda = 0 \) for \( h \leq -c \).

Parameters:
  • h – constraint function (gap)

  • c – width of the transition zone

  • p0 – multiplier value at \( h = 0 \)

Returns:

\( \lambda(h) \)

double dlagrange_exp(const double &h, const double &c, const double &p0)

First derivative \( \mathrm{d}\lambda/\mathrm{d}h \) of lagrange_exp.

Parameters:
  • h – constraint function (gap)

  • c – width of the transition zone

  • p0 – multiplier value at \( h = 0 \)

Returns:

\( \mathrm{d}\lambda/\mathrm{d}h \) (0 for \( h \leq -c \))

double lagrange_pow_0(const double &x, const double &c, const double &p0, const double &n, const double &alpha)

Power-law Lagrange multiplier enforcing \( x \geq 0 \).

\( \lambda(x) = p_0 (1 - x)\, x^{-n} \) for \( x \geq c \); below \( c \) the law is continued by its tangent at \( c \) plus \( \alpha (x - c)^2 \), so it stays finite at \( x = 0 \).

Parameters:
  • x – constrained variable

  • c – regularisation threshold

  • p0 – multiplier scale

  • n – power-law exponent

  • alpha – coefficient of the quadratic continuation below \( c \)

Returns:

\( \lambda(x) \)

double dlagrange_pow_0(const double &x, const double &c, const double &p0, const double &n, const double &alpha)

First derivative \( \mathrm{d}\lambda/\mathrm{d}x \) of lagrange_pow_0.

Parameters:
  • x – constrained variable

  • c – regularisation threshold

  • p0 – multiplier scale

  • n – power-law exponent

  • alpha – coefficient of the quadratic continuation below \( c \)

Returns:

\( \mathrm{d}\lambda/\mathrm{d}x \)

double lagrange_pow_1(const double &x, const double &c, const double &p0, const double &n, const double &alpha)

Power-law Lagrange multiplier enforcing \( x \leq 1 \).

\( \lambda(x) = p_0\, x\, (1 - x)^{-n} \) for \( x \leq 1 - c \); above \( 1 - c \) the law is continued by its tangent at \( 1 - c \) plus \( \alpha (x - 1 + c)^2 \), so it stays finite at \( x = 1 \).

Parameters:
  • x – constrained variable

  • c – regularisation threshold (distance to 1)

  • p0 – multiplier scale

  • n – power-law exponent

  • alpha – coefficient of the quadratic continuation above \( 1 - c \)

Returns:

\( \lambda(x) \)

double dlagrange_pow_1(const double &x, const double &c, const double &p0, const double &n, const double &alpha)

First derivative \( \mathrm{d}\lambda/\mathrm{d}x \) of lagrange_pow_1.

Parameters:
  • x – constrained variable

  • c – regularisation threshold (distance to 1)

  • p0 – multiplier scale

  • n – power-law exponent

  • alpha – coefficient of the quadratic continuation above \( 1 - c \)

Returns:

\( \mathrm{d}\lambda/\mathrm{d}x \)

double d2lagrange_pow_1(const double &x, const double &c, const double &p0, const double &n, const double &alpha)

Second derivative \( \mathrm{d}^2\lambda/\mathrm{d}x^2 \) of lagrange_pow_1 ( \( 2\alpha \) above \( 1 - c \)).

Parameters:
  • x – constrained variable

  • c – regularisation threshold (distance to 1)

  • p0 – multiplier scale

  • n – power-law exponent

  • alpha – coefficient of the quadratic continuation above \( 1 - c \)

Returns:

\( \mathrm{d}^2\lambda/\mathrm{d}x^2 \)

inline lane2 lanes(const double &a, const double &b)
inline lane2 mul(const lane2 &a, const lane2 &b)
inline lane2 mul_add(const lane2 &a, const lane2 &b, const lane2 &c)
void Newton_Raphon(const arma::vec &Phi, const arma::vec &Y_crit, const arma::mat &denom, arma::vec &Dp, arma::vec &dp, double &error)

One plain Newton step on the constraints: \( \delta p = -B^{-1}\,\Phi \), no complementarity.

The solvers of this file target the Kuhn-Tucker conditions \( \Phi_i \le 0,\ \Delta p_i \ge 0,\ \Phi_i\,\Delta p_i = 0 \), with \( \Delta p = \dot{p}\,\Delta t \). A singular \( B \) gives a zero step.

Parameters:
  • Phi – [in] constraints \( \Phi_i \) (N)

  • Y_crit – [in] normalisations of the error (N, non-zero)

  • denom – [in] local Jacobian \( B = \partial \Phi / \partial \Delta p \) (N x N)

  • Dp – [inout] multipliers, updated: \( \Delta p \leftarrow \Delta p + \delta p \)

  • dp – [out] the step \( \delta p \)

  • error – [out] \( \sum_i |\Phi_i| / |Y^{crit}_i| \) of the entering iterate

Throws:

simcoon::exception_det – when the determinant or solve fails

void Fischer_Burmeister(const arma::vec &Phi, const arma::vec &Y_crit, const arma::mat &denom, arma::vec &Dp, arma::vec &dp, double &error)

One Newton step of the non-normalised Fischer-Burmeister reformulation of the Kuhn-Tucker conditions.

As Fischer_Burmeister_m with \( \Delta p_i \) in place of the normalised \( \Delta p_i^* \): \( \phi_i = \sqrt{\Phi_i^2 + \Delta p_i^2} + \Phi_i - \Delta p_i \). A singular Jacobian gives a zero step.

Parameters:
  • Phi – [in] constraints \( \Phi_i \) (N)

  • Y_crit – [in] normalisations of the error (N, non-zero)

  • denom – [in] local Jacobian \( B = \partial \Phi / \partial \Delta p \) (N x N)

  • Dp – [inout] multipliers, updated: \( \Delta p \leftarrow \Delta p + \delta p \)

  • dp – [out] the step \( \delta p \)

  • error – [out] \( \sum_i |\phi_i| / |Y^{crit}_i| \) of the entering iterate

Throws:

simcoon::exception_det – when the determinant or solve fails

void Fischer_Burmeister_limits(const arma::vec &Phi_p, const arma::vec &Phi_l, const arma::vec &Y_crit, const arma::mat &denom, const arma::mat &denom_l, arma::vec &Dp, arma::vec &dp, double &error)

Fischer_Burmeister with an upper limit on each multiplier, \( \Phi^l_i \le 0 \) (e.g. \( \Phi^l = p - 1 \)).

On a row where \( \Phi^l_i \neq 0 \) the equation is \( \phi_{1,i}^2 + \phi_{2,i}^2 = 0 \), with \( \phi_1 \) the Fischer-Burmeister function of \( (\Phi^p_i, \Delta p_i) \) and \( \phi_2 = |\Phi^l_i| + \Phi^l_i \); other rows are those of Fischer_Burmeister.

Parameters:
  • Phi_p – [in] constraints of the mechanisms (N)

  • Phi_l – [in] limit constraints (N)

  • Y_crit – [in] normalisations of the error (N, non-zero)

  • denom – [in] Jacobian \( \partial \Phi^p / \partial \Delta p \) (N x N)

  • denom_l – [in] Jacobian \( \partial \Phi^l / \partial \Delta p \) (N x N)

  • Dp – [inout] multipliers, updated: \( \Delta p \leftarrow \Delta p + \delta p \)

  • dp – [out] the step \( \delta p \)

  • error – [out] \( \sum_i |\phi_i| / |Y^{crit}_i| \) of the entering iterate

Throws:

simcoon::exception_det – when the determinant or solve fails

void Fischer_Burmeister_m(const arma::vec&, const arma::vec&, const arma::mat&, arma::vec&, arma::vec&, double&)

One Newton step of the normalised Fischer-Burmeister reformulation of the local Kuhn-Tucker conditions (the default complementarity function of the cutting planes).

The return mapping seeks multipliers \( \Delta p_i \) with \( \Phi_i \le 0,\ \Delta p_i \ge 0,\ \Phi_i\,\Delta p_i = 0 \) for each surface \( i \). With the normalised multiplier \( \Delta p_i^* = \Delta p_i\,|B_{ii}| \) (a stress, as \( \Phi_i \)) these three conditions are the single equation

\[ \phi_i = \sqrt{\Phi_i^2 + \Delta p_i^{*2}} + \Phi_i - \Delta p_i^* = 0, \]
the Fischer-Burmeister function \( \sqrt{a^2+b^2} - a - b \) with \( a = -\Phi_i \), \( b = \Delta p_i^* \). It is smooth away from \( (0, 0) \) and decides by itself whether a surface is active, so the same equation serves one surface or a coupled system of N. The Newton step solves \( J\,\delta p = -\phi \) with, \( r_i = \sqrt{\Phi_i^2 + \Delta p_i^{*2}} \),
\[ J_{ij} = \left(\frac{\Phi_i}{r_i} + 1\right) B_{ij} + \delta_{ij}\,|B_{ii}| \left(\frac{\Delta p_i^*}{r_i} - 1\right), \qquad B_{ij} = \frac{\partial \Phi_i}{\partial \Delta p_j}. \]
From \( \Delta p = 0 \) on a violated surface ( \( \Phi > 0 \), \( B < 0 \)) one row gives \( \phi = 2\Phi \), \( J = 3B \): the step is two thirds of the full cutting-plane step \( -\Phi/B \), which ncp_step with NCPMethod::min_fb_fallback takes instead. A row with \( \Phi_i = \Delta p_i^* = 0 \) is frozen ( \( J_{ii} = 10^{12} \)); a singular \( J \) gives a zero step. One and two surfaces are solved in closed form, more by LAPACK.

Parameters:
  • Phi – [in] constraints \( \Phi_i \) (N)

  • Y_crit – [in] normalisations of the error (N, non-zero), typically the yield stresses

  • denom – [in] local Jacobian \( B = \partial \Phi / \partial \Delta p \) (N x N)

  • Dp – [inout] multipliers, updated: \( \Delta p \leftarrow \Delta p + \delta p \)

  • dp – [out] the step \( \delta p \)

  • error – [out] \( \sum_i |\phi_i| / |Y^{crit}_i| \) of the entering iterate (Fischer_Burmeister_residual)

Throws:

simcoon::exception_det – when LAPACK fails on a system of more than two surfaces

double Fischer_Burmeister_residual(const arma::vec &Phi, const arma::vec &Y_crit, const arma::mat &denom, const arma::vec &Dp)

The convergence measure of Fischer_Burmeister_m without its Newton step.

\( \sum_i |\phi_i| / |Y^{crit}_i| \) with the normalised Fischer-Burmeister function \( \phi_i = \sqrt{\Phi_i^2 + \Delta p_i^{*2}} + \Phi_i - \Delta p_i^* \), \( \Delta p_i^* = \Delta p_i\,|B_{ii}| \) — the very expression (branches included) Fischer_Burmeister_m returns in its error argument for the entering iterate, so a line search (closest_point_return_mapping) can rate a trial point without solving the \( N \times N \) system. Kept in step with Fischer_Burmeister_m by construction: that function’s error loop is this one.

Parameters:
  • Phi – [in] constraints (N)

  • Y_crit – [in] normalisations (N, non-zero)

  • denom – [in] local Jacobian (N x N); only |diag| is used

  • Dp – [in] multipliers (N)

Returns:

the residual

void Fischer_Burmeister_m_limits(const arma::vec &Phi_p, const arma::vec &Phi_l, const arma::vec &Y_crit, const arma::mat &denom, const arma::mat &denom_l, arma::vec &Dp, arma::vec &dp, double &error)

Fischer_Burmeister_limits with the normalised multipliers \( \Delta p_i^* = \Delta p_i\,|B_{ii}| \) of Fischer_Burmeister_m.

Parameters:
  • Phi_p – [in] constraints of the mechanisms (N)

  • Phi_l – [in] limit constraints (N)

  • Y_crit – [in] normalisations of the error (N, non-zero)

  • denom – [in] Jacobian \( B = \partial \Phi^p / \partial \Delta p \) (N x N)

  • denom_l – [in] Jacobian \( \partial \Phi^l / \partial \Delta p \) (N x N)

  • Dp – [inout] multipliers, updated: \( \Delta p \leftarrow \Delta p + \delta p \)

  • dp – [out] the step \( \delta p \)

  • error – [out] \( \sum_i |\phi_i| / |Y^{crit}_i| \) of the entering iterate

Throws:

simcoon::exception_det – when the determinant or solve fails

bool ncp_is_semismooth(const NCPMethod &method)

True for the semi-smooth (min-type) functions, whose full step the cutting plane cannot take with an Armstrong-Frederick back stress (ModularUMAT::set_ncp): min_fb_fallback and active_set.

NCPMethod ncp_method_of(const int &code, const std::string &where)

The NCP method of a code (solver_params::ncp, state_variables::ncp), checked: 0 to 2.

Parameters:
  • code – the code

  • where – the caller, for the error message

Throws:

std::invalid_argument – for any other value

arma::mat denom_FB_m(const arma::vec &Phi, const arma::mat &denom, const arma::vec &Dp)

Jacobian \( J \) of the normalised Fischer-Burmeister system of Fischer_Burmeister_m, without the step.

Parameters:
  • Phi – [in] constraints (N)

  • denom – [in] local Jacobian \( B = \partial \Phi / \partial \Delta p \) (N x N)

  • Dp – [in] multipliers (N)

Returns:

\( J \) (N x N); a row with \( \Phi_i = \Delta p_i^* = 0 \) is frozen ( \( J_{ii} = 10^{12} \))

int alea(const int &a)

Generates a random integer between 0 and a-1.

Example:

int r = alea(10);  // Returns a random integer between 0 and 9

Parameters:

a – The upper bound (exclusive) (int)

Returns:

A random integer in the range [0, a-1] (int)

int aleab(const int &a, const int &b)

Generates a random integer between a and b.

Example:

int r = aleab(5, 15);  // Returns a random integer between 5 and 15

Parameters:
  • a – The lower bound (inclusive) (int)

  • b – The upper bound (inclusive) (int)

Returns:

A random integer in the range [a, b] (int)

double alead(const double &a, const double &b)

Generates a random double between a and b.

Example:

double r = alead(0.0, 1.0);  // Returns a random double between 0.0 and 1.0

Parameters:
  • a – The lower bound (double)

  • b – The upper bound (double)

Returns:

A random double in the range [a, b] (double)

arma::cube dR_drotvec(const arma::vec::fixed<3> &omega)

Compute derivatives of R(omega) w.r.t. rotation vector components.

\( \partial \mathbf{R} / \partial \omega_k = [\mathbf{T}\,\mathbf{e}_k]_\times \mathbf{R} \) for \( \mathbf{R} = \exp([\boldsymbol{\omega}]_\times) \), with \( \mathbf{T} \) the left Jacobian dexp, both from the coefficients of dexp (series below 0.1 rad, exact to rounding at every angle including \( \boldsymbol{\omega} \to 0 \)).

Reference: Gallego & Yezzi, “A Compact Formula for the

Derivative of a 3-D Rotation in Exponential Coordinates”, J. Math. Imaging Vis., 2015.

Parameters:

omega – Rotation vector (3 elements)

Returns:

3x3x3 cube where slice(k) is dR/d(omega_k) (Python exposure: result[:, :, k]).

arma::mat::fixed<3, 3> dexp(const arma::vec::fixed<3> &omega)

Left Jacobian of the exponential map of SO(3) (tangent operator of the rotation vector).

\( \mathbf{T}(\boldsymbol{\omega}) = \mathbf{I} + \frac{1 - \cos\theta}{\theta^2} \mathbf{W} + \frac{\theta - \sin\theta}{\theta^3} \mathbf{W}^2 \), \( \mathbf{W} = [\boldsymbol{\omega}]_\times \), \( \theta = |\boldsymbol{\omega}| \): \( \mathrm{d}\mathbf{R}\,\mathbf{R}^T = [\mathbf{T}\,\mathrm{d}\boldsymbol{\omega}]_\times \) for \( \mathbf{R} = \exp(\mathbf{W}) \) (spatial spin). The right Jacobian (material spin, \( \mathbf{R}^T \mathrm{d}\mathbf{R} \)) is its transpose. Series below 0.1 rad: exact to rounding.

Parameters:

omega – Rotation vector (axis * angle, radians)

Returns:

The 3x3 left Jacobian

arma::mat::fixed<3, 3> dexp_inv(const arma::vec::fixed<3> &omega)

Inverse of the left Jacobian of SO(3), dexp: \( \mathbf{T}^{-1} = \mathbf{I} - \frac{1}{2} \mathbf{W} + \frac{1 - \frac{\theta}{2} \cot\frac{\theta}{2}}{\theta^2} \mathbf{W}^2 \) (singular at \( \theta = 2\pi \)). Series below 0.1 rad: exact to rounding.

Throws:

std::invalid_argument – for \( \theta \ge 2\pi - 10^{-6} \) (wrap accumulated rotation vectors to \( \theta \le \pi \) first)

Parameters:

omega – Rotation vector (axis * angle, radians)

Returns:

The 3x3 inverse left Jacobian

arma::vec rotate_vec(const arma::vec &v, const arma::mat &R)

Rotates a 3D vector using a rotation matrix.

Parameters:
  • v – The input 3D vector (arma::vec)

  • R – The 3x3 rotation matrix (arma::mat)

Returns:

The rotated vector (arma::vec)

arma::vec rotate_vec(const arma::vec &v, const double &angle, const int &axis)

Rotates a 3D vector by an angle around a given axis.

Parameters:
  • v – The input 3D vector (arma::vec)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

Returns:

The rotated vector (arma::vec)

inline bool is_identity_rotation(const arma::mat &DR)

Exact test of DR against the 3x3 identity, without building it.

approx_equal(DR, eye(3,3), “absdiff”, 0.): a rotation increment at 1e-17 of the identity is not the identity and is applied. A wrong size or a non-finite entry gives false (the caller then rotates, the safe side). Lets a kernel skip the rotation of its state on a still frame.

arma::mat rotate_mat(const arma::mat &m, const arma::mat &R)

Rotates a 3x3 matrix using a rotation matrix.

Parameters:
  • m – The input 3x3 matrix (arma::mat)

  • R – The 3x3 rotation matrix (arma::mat)

Returns:

The rotated matrix (arma::mat)

arma::mat rotate_mat(const arma::mat &m, const double &angle, const int &axis)

Rotates a 3x3 matrix by an angle around a given axis.

Parameters:
  • m – The input 3x3 matrix (arma::mat)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

Returns:

The rotated matrix (arma::mat)

arma::vec rotate_stress(const arma::vec &sigma, const double &angle, const int &axis, const bool &active = true)

Rotates a stress vector in Voigt notation.

Parameters:
  • sigma – The 6-component stress vector (arma::vec)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated stress vector (arma::vec)

arma::vec rotate_stress(const arma::vec &sigma, const arma::mat &R, const bool &active = true)

Rotates a stress vector using a 3x3 rotation matrix.

Parameters:
  • sigma – The 6-component stress vector (arma::vec)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated stress vector (arma::vec)

arma::vec rotate_strain(const arma::vec &epsilon, const double &angle, const int &axis, const bool &active = true)

Rotates a strain vector in Voigt notation.

Parameters:
  • epsilon – The 6-component strain vector (arma::vec)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated strain vector (arma::vec)

arma::vec rotate_strain(const arma::vec &epsilon, const arma::mat &R, const bool &active = true)

Rotates a strain vector using a 3x3 rotation matrix.

Parameters:
  • epsilon – The 6-component strain vector (arma::vec)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated strain vector (arma::vec)

arma::mat rotate_stiffness(const arma::mat &L, const double &angle, const int &axis, const bool &active = true)

Rotates a 6x6 stiffness matrix by an angle around a given axis.

Parameters:
  • L – The 6x6 stiffness matrix in Voigt notation (arma::mat)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 stiffness matrix (arma::mat)

arma::mat rotate_stiffness(const arma::mat &L, const arma::mat &R, const bool &active = true)

Rotates a 6x6 stiffness matrix using a 3x3 rotation matrix.

Parameters:
  • L – The 6x6 stiffness matrix in Voigt notation (arma::mat)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 stiffness matrix (arma::mat)

arma::mat rotate_compliance(const arma::mat &M, const double &angle, const int &axis, const bool &active = true)

Rotates a 6x6 compliance matrix by an angle around a given axis.

Parameters:
  • M – The 6x6 compliance matrix in Voigt notation (arma::mat)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 compliance matrix (arma::mat)

arma::mat rotate_compliance(const arma::mat &M, const arma::mat &R, const bool &active = true)

Rotates a 6x6 compliance matrix using a 3x3 rotation matrix.

Parameters:
  • M – The 6x6 compliance matrix in Voigt notation (arma::mat)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 compliance matrix (arma::mat)

arma::mat rotate_strain_concentration(const arma::mat &A, const double &angle, const int &axis, const bool &active = true)

Rotates a 6x6 strain concentration matrix by an angle around a given axis.

Parameters:
  • A – The 6x6 strain concentration matrix (arma::mat)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 strain concentration matrix (arma::mat)

arma::mat rotate_strain_concentration(const arma::mat &A, const arma::mat &R, const bool &active = true)

Rotates a 6x6 strain concentration matrix using a 3x3 rotation matrix.

Parameters:
  • A – The 6x6 strain concentration matrix (arma::mat)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 strain concentration matrix (arma::mat)

arma::mat rotate_stress_concentration(const arma::mat &B, const double &angle, const int &axis, const bool &active = true)

Rotates a 6x6 stress concentration matrix by an angle around a given axis.

Parameters:
  • B – The 6x6 stress concentration matrix (arma::mat)

  • angle – The rotation angle in radians (double)

  • axis – The axis of rotation: 1=x, 2=y, 3=z (int)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 stress concentration matrix (arma::mat)

arma::mat rotate_stress_concentration(const arma::mat &B, const arma::mat &R, const bool &active = true)

Rotates a 6x6 stress concentration matrix using a 3x3 rotation matrix.

Parameters:
  • B – The 6x6 stress concentration matrix (arma::mat)

  • R – The 3x3 rotation matrix (arma::mat)

  • active – If true (default), active rotation (bool)

Returns:

The rotated 6x6 stress concentration matrix (arma::mat)

arma::cube batch_voigt_stress_rotation(const arma::mat &quats, const bool &active = true)

Batch-build 6x6 stress Voigt rotation matrices from N quaternions.

Parameters:
  • quats – (4, N) matrix of quaternions [qx, qy, qz, qw] (scalar-last)

  • active – If true (default), active rotation

Returns:

(6, 6, N) cube of stress rotation matrices

arma::cube batch_voigt_strain_rotation(const arma::mat &quats, const bool &active = true)

Batch-build 6x6 strain Voigt rotation matrices from N quaternions.

Parameters:
  • quats – (4, N) matrix of quaternions [qx, qy, qz, qw] (scalar-last)

  • active – If true (default), active rotation

Returns:

(6, 6, N) cube of strain rotation matrices

inline void mul6(const double *A, const double *x, double *y)

\( \mathbf{y} = \mathbf{A}\,\mathbf{x} \) for a column-major 6x6 A and a 6-vector x.

Armadillo hands every product above 4x4 to BLAS; at this size the call costs more than the 36 multiply-adds, and the summation order depends on the BLAS backend. This loop has a fixed order (column by column), so the result is the same on every platform. y may alias x.

inline void mul6(const arma::mat &A, const arma::vec &x, arma::vec &y)

\( \mathbf{y} = \mathbf{A}\,\mathbf{x} \) for a 6x6 A and a 6-vector x (see the pointer form).

inline void mul6_At(const double *A, const double *x, double *y)

\( \mathbf{y} = \mathbf{A}^T\mathbf{x} \) for a column-major 6x6 A and a 6-vector x, without forming the transpose: the products of the heat derivatives, \( \partial\boldsymbol{\sigma}/\partial \boldsymbol{\varepsilon}^T \boldsymbol{\alpha} \). Fixed summation order (see mul6); y may not alias x.

inline arma::vec::fixed<6> mul6_At(const arma::mat &A, const arma::vec &x)

\( \mathbf{A}^T\mathbf{x} \) for a 6x6 A and a 6-vector x (see the pointer form).

inline arma::mat::fixed<6, 6> mul66(const arma::mat &A, const arma::mat &B)

\( \mathbf{C} = \mathbf{A}\,\mathbf{B} \) for 6x6 operands, fixed summation order (see mul6).

inline arma::mat::fixed<6, 6> mul66_ABt(const arma::mat &A, const arma::mat &B)

\( \mathbf{C} = \mathbf{A}\,\mathbf{B}^T \) for 6x6 operands, without forming the transpose.

inline arma::mat::fixed<3, 3> mul3(const arma::mat::fixed<3, 3> &A, const arma::mat::fixed<3, 3> &B)

\( \mathbf{C} = \mathbf{A}\,\mathbf{B} \) for 3x3 operands, each entry the three products summed in order.

inline arma::mat::fixed<3, 3> mul3_AtB(const arma::mat::fixed<3, 3> &A, const arma::mat::fixed<3, 3> &B)

\( \mathbf{C} = \mathbf{A}^T\mathbf{B} \) for 3x3 operands, without forming the transpose.

inline arma::mat::fixed<3, 3> mul3_ABt(const arma::mat::fixed<3, 3> &A, const arma::mat::fixed<3, 3> &B)

\( \mathbf{C} = \mathbf{A}\,\mathbf{B}^T \) for 3x3 operands, without forming the transpose.

inline double contract_voigt(const double *a, const double *b, const double w)

Contraction \( \mathbf{A}:\mathbf{B} \) of two symmetric tensors stored as engineering Voigt 6-vectors: \( \sum_{k<3} a_k b_k + w \sum_{k \ge 3} a_k b_k \). The shear weight w is 2 for two stresses, 1/2 for two strains and 1 for a stress with a strain (see voigt_shear_weight in tensor.hpp).

inline void dev_voigt(const double *v, double *d)

Deviator of a Voigt 6-vector, \( d = v - \tfrac{1}{3}\mathrm{tr}(v)\,\mathbf{I} \).

inline double det_sym_voigt(const double *v, const double shear)

Determinant of the symmetric 3x3 tensor stored as a Voigt 6-vector v whose shear entries map to the tensor with the factor shear (voigt_shear_in: 1 for a stress, 1/2 for a strain); closed form, no 3x3 built and no LAPACK dispatch.

inline arma::mat::fixed<6, 6> outer6(const double *a, const double *b)

\( \mathbf{C} = \mathbf{a}\,\mathbf{b}^T \) for two 6-vectors: one product per entry, no BLAS dispatch.

inline void mat_from_voigt(arma::mat::fixed<3, 3> &m, const double *v, const double shear)

Symmetric 3x3 from 6 engineering-Voigt values (11, 22, 33, 12, 13, 23).

shear scales the three shear entries on the way in: 1 for a stress (the Voigt entries are the tensor shears), 0.5 for a strain (the Voigt entries are \( \gamma_{ij} = 2\varepsilon_{ij} \)). One rounded product per shear entry, as tensor2::from_voigt.

inline arma::mat::fixed<3, 3> mat_from_voigt(const double *v, const double shear)

Same, returned by value.

inline void voigt_from_mat(double *v, const arma::mat::fixed<3, 3> &m, const double shear_sum)

6 engineering-Voigt values of a 3x3, symmetrised: \( v_I = w\,(m_{ij} + m_{ji}) \) for the shears.

shear_sum is 0.5 for a stress (the average of the two off-diagonal entries) and 1 for a strain (their sum, \( \gamma_{ij} \)). One rounded product per shear entry, as tensor2::voigt.

arma::vec quadratic(const double &a, const double &b, const double &c)

Real roots of \( a t^2 + b t + c = 0 \).

Parameters:
  • a – quadratic coefficient (if 0, the linear root \( -c/b \) is returned)

  • b – linear coefficient

  • c – constant coefficient

Returns:

the two roots \( (-b \pm \sqrt{\Delta})/(2a) \), \( \Delta = b^2 - 4ac \) (asserted \( > 0 \)), or one root when \( a = 0 \)

arma::cx_vec cx_quadratic(const double &a, const double &b, const double &c)

Complex roots of \( a t^2 + b t + c = 0 \) with real coefficients.

Parameters:
  • a – quadratic coefficient (if 0, the linear root \( -c/b \) is returned)

  • b – linear coefficient

  • c – constant coefficient

Returns:

the two roots \( (-b \pm \sqrt{\Delta})/(2a) \), or a single root when \( a = 0 \) or \( \Delta = 0 \)

arma::cx_vec cx_quadratic(const arma::cx_double &a, const arma::cx_double &b, const arma::cx_double &c)

Complex roots of \( a t^2 + b t + c = 0 \) with complex coefficients.

Parameters:
  • a – quadratic coefficient (if 0, the linear root \( -c/b \) is returned)

  • b – linear coefficient

  • c – constant coefficient

Returns:

the two roots \( (-b \pm \sqrt{\Delta})/(2a) \), or a single root when \( a = 0 \) or \( \Delta = 0 \)

double normal_distrib(const double &x, const double &mu, const double &sigma)

Computes the value of a normal (Gaussian) distribution at a given point.

The normal distribution is given by:

\[ f(x) = \frac{1}{\sigma \sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right) \]
double p = normal_distrib(0.0, 0.0, 1.0);  // Standard normal at x=0

Parameters:
  • x – The point at which to evaluate the distribution (double)

  • mu – The mean of the distribution (double)

  • sigma – The standard deviation of the distribution (double)

Returns:

The probability density value at x (double)

double proba_distrib_weibull(const double &x, const double &alpha, const double &beta)

Computes the probability density of a Weibull distribution.

The Weibull probability density function is:

\[ f(x) = \frac{\alpha}{\beta} \left(\frac{x}{\beta}\right)^{\alpha-1} \exp\left(-\left(\frac{x}{\beta}\right)^\alpha\right) \]
double p = proba_distrib_weibull(1.5, 2.0, 1.0);

Parameters:
  • x – The point at which to evaluate the distribution (double)

  • alpha – The shape parameter \( \alpha > 0 \) (double)

  • beta – The scale parameter \( \beta > 0 \) (double)

Returns:

The probability density value at x (double)

double cumul_distrib_weibull(const double &x, const double &alpha, const double &beta)

Computes the cumulative distribution function of a Weibull distribution.

The Weibull cumulative distribution function is:

\[ F(x) = 1 - \exp\left(-\left(\frac{x}{\beta}\right)^\alpha\right) \]
double F = cumul_distrib_weibull(1.5, 2.0, 1.0);

Parameters:
  • x – The point at which to evaluate the CDF (double)

  • alpha – The shape parameter \( \alpha > 0 \) (double)

  • beta – The scale parameter \( \beta > 0 \) (double)

Returns:

The cumulative probability at x (double)

int tri_sum(const int &a, const int &b)

Computes the triangular sum of two integers.

Returns \( \frac{(a+b)(a+b+1)}{2} + b \), which provides a unique mapping from pairs of integers to a single integer.

Parameters:
  • a – First integer (int)

  • b – Second integer (int)

Returns:

The triangular sum (int)

double ODF_sd(const double &Theta, const double &Phi, const arma::vec &params)

Computes a classic Orientation Distribution Function (ODF).

The ODF is given by:

\[ \textrm{ODF}(\Theta) = a_1 \cos^{2p_1}(\Theta) + a_2 \cos^{2p_2+1}(\Theta) \sin^{2p_2}(\Theta) \]

Parameters:
  • Theta – The angle \( \Theta \) in radians (double)

  • Phi – The angle \( \Phi \) in radians (double)

  • params – Vector of parameters: \( [a_1, p_1, a_2, p_2] \) (arma::vec)

Returns:

The ODF value at the given angles (double)

double ODF_hard(const double &Theta, const double &Phi, const double &alpha, const double &beta)

Computes a hardening-type Orientation Distribution Function.

Parameters:
  • Theta – The angle \( \Theta \) in radians (double)

  • Phi – The angle \( \Phi \) in radians (double)

  • alpha – Parameter \( \alpha \) (double)

  • beta – Parameter \( \beta \) (double)

Returns:

The ODF value at the given angles (double)

double Gaussian(const double &x, const double &mu, const double &sigma, const double &ampl = 1.)

Computes a Gaussian peak function.

The Gaussian is given by:

\[ G(x) = A \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right) \]
double g = Gaussian(0.5, 0.0, 1.0, 2.0);

Parameters:
  • x – The position at which to evaluate (double)

  • mu – The center of the peak (double)

  • sigma – The width parameter (standard deviation) (double)

  • ampl – The amplitude (default = 1.0) (double)

Returns:

The Gaussian value at x (double)

double Lorentzian(const double &x, const double &x0, const double &gamma, const double &ampl = 1.)

Computes a Lorentzian (Cauchy) peak function.

The Lorentzian is given by:

\[ L(x) = \frac{A}{\pi} \frac{\gamma}{(x-x_0)^2 + \gamma^2} \]
double l = Lorentzian(0.5, 0.0, 1.0, 2.0);

Parameters:
  • x – The position at which to evaluate (double)

  • x0 – The center of the peak (double)

  • gamma – The half-width at half-maximum (double)

  • ampl – The amplitude (default = 1.0) (double)

Returns:

The Lorentzian value at x (double)

double PseudoVoigt(const double &x, const double &x0, const double &sigma, const double &gamma, const double &eta, const arma::vec &params = arma::ones(1))

Computes a Pseudo-Voigt peak function (weighted sum of Gaussian and Lorentzian).

The Pseudo-Voigt is given by:

\[ V(x) = \eta \cdot L(x) + (1-\eta) \cdot G(x) \]

Parameters:
  • x – The position at which to evaluate (double)

  • x0 – The center of the peak (double)

  • sigma – The Gaussian width parameter (double)

  • gamma – The Lorentzian width parameter (double)

  • eta – The mixing parameter (0 = pure Gaussian, 1 = pure Lorentzian) (double)

  • params – Optional additional parameters (arma::vec)

Returns:

The Pseudo-Voigt value at x (double)

double Pearson7(const double &x, const double &x0, const double &w, arma::vec &params)

Computes a Pearson VII peak function.

The Pearson VII function provides flexible peak shapes that can approximate both Gaussian and Lorentzian profiles.

Parameters:
  • x – The position at which to evaluate (double)

  • x0 – The center of the peak (double)

  • w – The width parameter (double)

  • params – Vector containing additional shape parameters (arma::vec)

Returns:

The Pearson VII value at x (double)

struct lane2
#include <lanes.hpp>

Two doubles operated on together.

On GCC and Clang lane2 is a 16-byte vector type: lanes, mul and mul_add compile to one SIMD instruction each, and a loop written on lane2 serves two scalar sums per operation while each lane follows the scalar expressions exactly (same rounding as the scalar code). On other compilers lane2 is a pair of doubles and the same functions run lane by lane: same results, no speed-up. This is the only compiler-specific definition of the library; the kernels that use it (the Eshelby quadrature) stay free of preprocessor conditions.

Public Functions

inline double operator[](int i) const

Public Members

double v[2]
class ncp_step
#include <num_solve.hpp>

One Newton step per call of a local complementarity solve, with the chosen function.

NCPMethod::fischer_burmeister forwards to Fischer_Burmeister_m. NCPMethod::min_fb_fallback takes the semi-smooth Newton step of \( \min(\Delta p^*_i, -\Phi_i) = 0 \) ( \( \Delta p^*_i = \Delta p_i |B_{ii}| \)): on an active row ( \( \Phi_i > 0 \) or \( -\Phi_i < \Delta p^*_i \)) the linearised constraint \( \Phi_i + B_{i\cdot}\,\delta p = 0 \), the classic cutting plane (Ortiz and Simo 1986), on an inactive one the multiplier back to zero (primal-dual active set, Hintermueller, Ito and Kunisch 2002). The first step from \( \Delta p = 0 \) is the full Newton step, where the Fischer-Burmeister function only takes two thirds of it: a linear hardening returns in one step instead of six. Its error is \( \sum_i 2|r_i|/|Y^{crit}_i| \) of the entering iterate, the scale of the Fischer-Burmeister measure near the solution. It applies row by row when the rows are uncoupled (denom diagonal): a single surface, or a surface next to the always-satisfied rows of the viscoelastic and damage mechanisms of MODUL ( \( \Phi = -Y^{crit} \), no multiplier, no cross term), which stay at zero. A coupled system (off-diagonal terms, e.g. several yield surfaces) keeps the Fischer-Burmeister step under min_fb_fallback, the active set of coupled surfaces making the plain semi-smooth Newton cycle. When the error grows from one call to the next, or a row is singular, the solve falls back to Fischer-Burmeister for the remaining calls (a nonlinear kinematic hardening can make the full step overshoot).

NCPMethod::active_set is the min step on every row: the active rows ( \( \Phi_i > 0 \) or \( -\Phi_i < \Delta p^*_i \)) solve their linearised constraints together, \( \Phi_A + B_{AA}\,\delta p_A + B_{AI}\,\delta p_I = 0 \) with the inactive multipliers sent back to zero ( \( \delta p_I = -\Delta p_I \)); on uncoupled rows it is the min_fb_fallback step, step for step, on coupled ones the primal-dual active set of Hintermueller, Ito and Kunisch, with the same fallback to Fischer-Burmeister (error growth, singular system) as its combinatorial safeguard.

Construct one object per local solve: it holds the fallback state of that solve.

Public Functions

inline explicit ncp_step(const NCPMethod &method = NCPMethod::fischer_burmeister)
void operator()(const arma::vec &Phi, const arma::vec &Y_crit, const arma::mat &denom, arma::vec &Dp, arma::vec &dp, double &error)

Same arguments and effects as Fischer_Burmeister_m: Dp += dp, error of the entering iterate.

inline bool fell_back() const

Whether this solve fell back to Fischer-Burmeister.

class Rotation
#include <rotation.hpp>

A class representing 3D rotations using unit quaternions.

Inspired by scipy.spatial.transform.Rotation, this class provides a unified interface for working with rotations in various representations (quaternion, rotation matrix, Euler angles, rotation vector) while maintaining high numerical precision and performance.

Internal representation uses unit quaternions in scalar-last convention [qx, qy, qz, qw].

Example usage:

// Create rotation from Euler angles
Rotation r = Rotation::from_euler(0.5, 0.3, 0.7, "zxz");

// Apply to a vector
arma::vec::fixed<3> v = {1, 0, 0};
arma::vec::fixed<3> v_rot = r.apply(v);

// Compose rotations
Rotation r2 = Rotation::from_axis_angle(M_PI/4, 3);
Rotation r_combined = r * r2;

// Apply to Voigt stress tensor
arma::vec::fixed<6> sigma = {100, 50, 0, 25, 0, 0};
arma::vec::fixed<6> sigma_rot = r.apply_stress(sigma);

Public Functions

Rotation()

Default constructor creating identity rotation.

Rotation(const Rotation &other) = default

Copy constructor.

Rotation(Rotation &&other) noexcept = default

Move constructor.

Rotation &operator=(const Rotation &other) = default

Copy assignment operator.

Rotation &operator=(Rotation &&other) noexcept = default

Move assignment operator.

~Rotation() = default

Destructor.

inline arma::vec::fixed<4> as_quat() const

Get rotation as a unit quaternion.

Returns:

Quaternion in [qx, qy, qz, qw] format (scalar-last)

arma::mat::fixed<3, 3> as_matrix() const

Get rotation as a 3x3 rotation matrix.

Returns:

3x3 orthogonal rotation matrix

arma::vec::fixed<3> as_euler(const std::string &conv, bool intrinsic = true, bool degrees = false) const

Get rotation as Euler angles.

Parameters:
  • conv – Euler angle convention

  • intrinsic – If true, return intrinsic angles; if false, extrinsic (the inverse of from_euler with the same flag)

  • degrees – If true, return angles in degrees

Returns:

3-element vector of Euler angles [psi, theta, phi]

arma::vec::fixed<3> as_rotvec(bool degrees = false) const

Get rotation as a rotation vector.

Parameters:

degrees – If true, magnitude is in degrees

Returns:

Rotation vector (axis * angle)

arma::mat::fixed<6, 6> as_voigt_stress_rotation(bool active = true) const

Get 6x6 rotation matrix for stress tensors in Voigt notation.

Parameters:

active – If true (default), active rotation; if false, passive

Returns:

6x6 stress rotation matrix

arma::mat::fixed<6, 6> as_voigt_strain_rotation(bool active = true) const

Get 6x6 rotation matrix for strain tensors in Voigt notation.

Parameters:

active – If true (default), active rotation; if false, passive

Returns:

6x6 strain rotation matrix

arma::vec::fixed<3> apply(const arma::vec::fixed<3> &v, bool inverse = false) const

Apply rotation to a 3D vector.

Parameters:
  • v – 3D vector to rotate

  • inverse – If true, apply inverse rotation

Returns:

Rotated vector

arma::vec apply(const arma::vec &v, bool inverse = false) const

Apply rotation to a 3D vector (dynamic size).

Parameters:
  • v – 3D vector to rotate

  • inverse – If true, apply inverse rotation

Returns:

Rotated vector

arma::mat::fixed<3, 3> apply_tensor(const arma::mat::fixed<3, 3> &m, bool inverse = false) const

Apply rotation to a 3x3 tensor (matrix).

Parameters:
  • m – 3x3 tensor to rotate

  • inverse – If true, apply inverse rotation

Returns:

Rotated tensor: R * m * R^T (or R^T * m * R for inverse)

arma::mat apply_tensor(const arma::mat &m, bool inverse = false) const

Apply rotation to a 3x3 tensor (dynamic size).

Parameters:
  • m – 3x3 tensor to rotate

  • inverse – If true, apply inverse rotation

Returns:

Rotated tensor

arma::vec::fixed<6> apply_stress(const arma::vec::fixed<6> &sigma, bool active = true) const

Apply rotation to a stress vector in Voigt notation.

Parameters:
  • sigma – 6-component stress vector [s11, s22, s33, s12, s13, s23]

  • active – If true (default), active rotation

Returns:

Rotated stress vector

arma::vec apply_stress(const arma::vec &sigma, bool active = true) const

Apply rotation to a stress vector (dynamic size).

Parameters:
  • sigma – 6-component stress vector

  • active – If true, active rotation

Returns:

Rotated stress vector

arma::vec::fixed<6> apply_strain(const arma::vec::fixed<6> &epsilon, bool active = true) const

Apply rotation to a strain vector in Voigt notation.

Parameters:
  • epsilon – 6-component strain vector [e11, e22, e33, 2*e12, 2*e13, 2*e23]

  • active – If true (default), active rotation

Returns:

Rotated strain vector

arma::vec apply_strain(const arma::vec &epsilon, bool active = true) const

Apply rotation to a strain vector (dynamic size).

Parameters:
  • epsilon – 6-component strain vector

  • active – If true, active rotation

Returns:

Rotated strain vector

arma::mat::fixed<6, 6> apply_stiffness(const arma::mat::fixed<6, 6> &L, bool active = true) const

Apply rotation to a 6x6 stiffness matrix.

Parameters:
  • L – 6x6 stiffness matrix in Voigt notation

  • active – If true (default), active rotation

Returns:

Rotated stiffness matrix: voigt_stress * L * voigt_stress^T

arma::mat apply_stiffness(const arma::mat &L, bool active = true) const

Apply rotation to a stiffness matrix (dynamic size).

Parameters:
  • L – 6x6 stiffness matrix

  • active – If true, active rotation

Returns:

Rotated stiffness matrix

arma::mat::fixed<6, 6> apply_compliance(const arma::mat::fixed<6, 6> &M, bool active = true) const

Apply rotation to a 6x6 compliance matrix.

Parameters:
  • M – 6x6 compliance matrix in Voigt notation

  • active – If true (default), active rotation

Returns:

Rotated compliance matrix: voigt_strain * M * voigt_strain^T

arma::mat apply_compliance(const arma::mat &M, bool active = true) const

Apply rotation to a compliance matrix (dynamic size).

Parameters:
  • M – 6x6 compliance matrix

  • active – If true, active rotation

Returns:

Rotated compliance matrix

arma::mat::fixed<6, 6> apply_strain_concentration(const arma::mat::fixed<6, 6> &A, bool active = true) const

Apply rotation to a 6x6 strain concentration tensor.

Parameters:
  • A – 6x6 strain concentration tensor in Voigt notation

  • active – If true (default), active rotation

Returns:

Rotated strain concentration tensor: voigt_strain * A * voigt_stress^T

arma::mat apply_strain_concentration(const arma::mat &A, bool active = true) const

Apply rotation to a strain concentration tensor (dynamic size).

Parameters:
  • A – 6x6 strain concentration tensor

  • active – If true, active rotation

Returns:

Rotated strain concentration tensor

arma::mat::fixed<6, 6> apply_stress_concentration(const arma::mat::fixed<6, 6> &B, bool active = true) const

Apply rotation to a 6x6 stress concentration tensor.

Parameters:
  • B – 6x6 stress concentration tensor in Voigt notation

  • active – If true (default), active rotation

Returns:

Rotated stress concentration tensor: voigt_stress * B * voigt_strain^T

arma::mat apply_stress_concentration(const arma::mat &B, bool active = true) const

Apply rotation to a stress concentration tensor (dynamic size).

Parameters:
  • B – 6x6 stress concentration tensor

  • active – If true, active rotation

Returns:

Rotated stress concentration tensor

Rotation inv() const

Get the inverse (conjugate) rotation.

Returns:

Inverse rotation

double magnitude(bool degrees = false) const

Get the magnitude (rotation angle) of this rotation.

Parameters:

degrees – If true, return in degrees

Returns:

Rotation angle in radians (or degrees)

Rotation operator*(const Rotation &other) const

Compose this rotation with another (this * other).

The composition represents applying ‘other’ first, then ‘this’

Parameters:

other – Rotation to compose with

Returns:

Composed rotation

Rotation &operator*=(const Rotation &other)

Compose this rotation with another in-place.

Parameters:

other – Rotation to compose with

Returns:

Reference to this rotation

Rotation slerp(const Rotation &other, double t) const

Spherical linear interpolation between this rotation and another.

Parameters:
  • other – Target rotation

  • t – Interpolation parameter in [0, 1] (0 = this, 1 = other)

Returns:

Interpolated rotation

inline bool equals(const Rotation &other, double tol = 1e-12) const

Check if this rotation equals another within tolerance.

Parameters:
  • other – Rotation to compare with

  • tol – Tolerance for comparison

Returns:

True if rotations are equal (or antipodal quaternions)

inline bool is_identity(double tol = 1e-12) const

Check if this rotation is identity (no rotation).

Parameters:

tol – Tolerance for comparison

Returns:

True if this is the identity rotation

arma::cube dR_drotvec() const

Compute derivatives of the rotation matrix w.r.t. rotation vector components.

Uses the exact differentiation of the Rodrigues formula (Gallego & Yezzi, J. Math. Imaging Vis., 2015).

Returns:

3x3x3 cube where slice(k) is dR/d(omega_k) (Python exposure: result[:, :, k]).

Public Static Functions

static Rotation identity()

Create an identity rotation.

Returns:

Identity rotation (no rotation)

static Rotation from_quat(const arma::vec::fixed<4> &quat)

Create rotation from a unit quaternion.

Note

The quaternion will be normalized if not already unit length

Parameters:

quat – Quaternion in [qx, qy, qz, qw] format (scalar-last)

Returns:

Rotation object

static Rotation from_quat(const arma::vec &quat)

Create rotation from a unit quaternion.

Parameters:

quat – Quaternion in [qx, qy, qz, qw] format (scalar-last), dynamic size

Returns:

Rotation object

static Rotation from_matrix(const arma::mat::fixed<3, 3> &R)

Create rotation from a 3x3 rotation matrix.

Parameters:

R – 3x3 rotation matrix (must be orthogonal with det=1)

Returns:

Rotation object

static Rotation from_matrix(const arma::mat &R)

Create rotation from a 3x3 rotation matrix.

Parameters:

R – 3x3 rotation matrix (dynamic size)

Returns:

Rotation object

static Rotation from_euler(double psi, double theta, double phi, const std::string &conv, bool intrinsic = true, bool degrees = false)

Create rotation from Euler angles.

With the axes \( a_1 a_2 a_3 \) of conv, the intrinsic sequence (rotation about \( a_1 \), then about the new \( a_2 \), then about the new \( a_3 \)) is \( \mathbf{R} = \mathbf{R}_{a_1}(\psi)\,\mathbf{R}_{a_2}(\theta)\,\mathbf{R}_{a_3}(\phi) \), scipy’s uppercase sequence ("zxz" = 'ZXZ'); the extrinsic one (fixed axes) is \( \mathbf{R}_{a_3}(\phi)\,\mathbf{R}_{a_2}(\theta)\,\mathbf{R}_{a_1}(\psi) \), scipy’s lowercase sequence. "user" takes the axes axis_psi, axis_theta, axis_phi (parameter.hpp). Up to simcoon 2.5 the default (intrinsic) composed the extrinsic product: the same orientation now reads \( (\phi, \theta, \psi) \).

Parameters:
  • psi – First Euler angle in radians (or degrees if degrees=true)

  • theta – Second Euler angle in radians (or degrees if degrees=true)

  • phi – Third Euler angle in radians (or degrees if degrees=true)

  • conv – Euler angle convention: “zxz”, “zyz”, “xyz”, “xzy”, “yxz”, “yzx”, “zxy”, “zyx”, “xyx”, “xzx”, “yxy”, “yzy”, or “user”

  • intrinsic – If true (default), intrinsic rotations (rotating frame); if false, extrinsic rotations (fixed frame)

  • degrees – If true, angles are in degrees; if false (default), radians

Returns:

Rotation object

static Rotation from_euler(const arma::vec::fixed<3> &angles, const std::string &conv, bool intrinsic = true, bool degrees = false)

Create rotation from Euler angles (vector input).

Parameters:
  • angles – 3-element vector of Euler angles

  • conv – Euler angle convention

  • intrinsic – If true, intrinsic rotations; if false, extrinsic rotations

  • degrees – If true, angles are in degrees

Returns:

Rotation object

static Rotation from_rotvec(const arma::vec::fixed<3> &rotvec, bool degrees = false)

Create rotation from a rotation vector (axis-angle representation).

Parameters:
  • rotvec – Rotation vector where direction is axis and magnitude is angle

  • degrees – If true, magnitude is in degrees; if false (default), radians

Returns:

Rotation object

static Rotation from_rotvec(const arma::vec &rotvec, bool degrees = false)

Create rotation from a rotation vector (dynamic size).

Parameters:
  • rotvec – Rotation vector (3 elements)

  • degrees – If true, magnitude is in degrees

Returns:

Rotation object

static Rotation from_axis_angle(double angle, int axis, bool degrees = false)

Create rotation around a single axis.

Parameters:
  • angle – Rotation angle in radians (or degrees if degrees=true)

  • axis – Axis of rotation: 1=x, 2=y, 3=z

  • degrees – If true, angle is in degrees

Returns:

Rotation object

static Rotation random()

Create a random rotation (uniformly distributed).

Returns:

Random rotation object

class frame_rotation
#include <rotation.hpp>

A rotation with its Voigt operators materialized once, applied in place.

Rotation::apply_* rebuilds the \( 3\times3 \) matrix and the \( 6\times6 \) Voigt operators at every call. When one rotation is applied many times (a material frame at every UMAT call, see material_characteristics::frame()), this class stores the operators of the rotation and of its inverse once and applies them with a single fixed-size product each, without heap temporary. The results are those of Rotation::apply_* on the rotation (inverse = false) or on Rotation::inv() (inverse = true) to the bit: the same operator matrices are built, once instead of per call, and Armadillo’s fixed-size products of this size evaluate as the dynamic ones. On the identity rotation (Rotation::is_identity) every apply is a no-op, as the skipped product would be.

Immutable after construction, hence safe to read from several threads.

Public Types

enum direction

Which operators an apply uses: those of the rotation, or of its inverse. A named value rather than a bool, so that it cannot be confused with the active flag of Rotation::apply_*.

Values:

enumerator forward
enumerator inverse

Public Functions

frame_rotation()

The identity frame.

explicit frame_rotation(const Rotation &rot)

The operators of rot and of its inverse.

inline bool is_identity() const

True when the rotation is the identity: every apply is then a no-op.

void rotate_strain(arma::vec &e, direction d = forward) const

Strain Voigt vector (engineering shear), in place: Rotation::apply_strain of rot, or of rot.inv().

void rotate_stress(arma::vec &s, direction d = forward) const

Stress Voigt vector, in place: Rotation::apply_stress of rot, or of rot.inv().

void rotate_stiffness(arma::mat &L, direction d = forward) const

Stiffness \( \mathbf{Q}_S \mathbf{L} \mathbf{Q}_S^T \), in place: Rotation::apply_stiffness of rot, or of rot.inv().

void rotate_tensor(arma::mat &X, direction d = forward) const

Second-order tensor \( \mathbf{R}\,\mathbf{X}\,\mathbf{R}^T \), in place: Rotation::apply_tensor of rot, or of rot.inv().

template<int Nmax>
class small_lu
#include <small_lu.hpp>

LU factorization with partial pivoting of a small dense matrix (at most Nmax rows), on the stack.

For the per-point linear systems of the integrators (the 6x6 / 7x7 global Newton Jacobian, the 6x6 condensation of the closest-point return mapping): a LAPACK inverse (getrf + getri) and the products with it cost 0.5 to 0.7 us on a 6x6, far more than the arithmetic, and allocate. factor() once, then solve() for each right-hand side; both run their loops on the compile-time size when n == Nmax (factor_n<Nmax>, solve_n<Nmax>) and on the runtime one otherwise. A pivot below \( n\,\epsilon \max|A_{ij}| \), or a non-finite entry, reports a singular matrix.

Public Functions

inline bool factor(const arma::mat &A)

Factorizes the square matrix A (n <= Nmax); false when it is (numerically) singular.

inline void solve_in_place(double *b) const

Solves A x = b in place (b: n values), after a successful factor().

inline void solve_columns_in_place(arma::mat &X) const

X <- A^-1 X column by column, in place (X: n rows), after a successful factor().

inline arma::vec solve(const arma::vec &b) const

x = A^-1 b

inline arma::mat solve(const arma::mat &B) const

X = A^-1 B, column by column.

inline int n_rows() const