DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
HardEigen.hpp
Go to the documentation of this file.
1#pragma once
2/// @file HardEigen.hpp
3/// @brief Robust linear-algebra primitives for small / moderately-sized
4/// Eigen matrices that are more numerically careful than Eigen's default paths.
5///
6/// These are used on the "hot" side of reconstruction / limiter code where
7/// matrices may be nearly rank-deficient and a plain `A.inverse()` or
8/// `A.jacobiSvd().solve(b)` would introduce large errors.
9
10#include "Defines.hpp"
11
12namespace DNDS::HardEigen
13{
14
15 /// @brief Moore-Penrose pseudoinverse via SVD, dropping singular values below
16 /// `svdTol` (relative to the largest). Returns the largest / smallest ratio
17 /// (condition number).
18 real EigenLeastSquareInverse(const Eigen::MatrixXd &A, Eigen::MatrixXd &AI, real svdTol = 0);
19
20 /**
21 * @brief Pseudoinverse with a choice of singular-value filter.
22 *
23 * @param A Input matrix.
24 * @param AI Output pseudoinverse.
25 * @param svdTol Filter tolerance (relative to the largest singular value).
26 * @param mode Filter selection:
27 * - `0`: standard "lsqminnorm" -- drop *smallest* singular values
28 * below the tolerance (stabilises rank-deficient systems);
29 * - `1`: drop *largest* singular values above `1/svdTol` relative
30 * to the smallest (inverse filtering, rarely needed).
31 * @return Condition number of `A` (ratio of largest to smallest
32 * post-filter singular value).
33 */
34 real EigenLeastSquareInverse_Filtered(const Eigen::MatrixXd &A, Eigen::MatrixXd &AI, real svdTol = 0, int mode = 0);
35
36 /// @brief Least-squares solve `A * AIB ~= B` via a rank-revealing QR-style
37 /// decomposition; returns the computed rank of `A`.
38 Eigen::Index EigenLeastSquareSolve(const Eigen::MatrixXd &A, const Eigen::MatrixXd &B, Eigen::MatrixXd &AIB);
39
40 /// @brief Analytic eigen-decomposition of a 3x3 real symmetric matrix.
41 /// Returns the eigenvector matrix (columns = eigenvectors, scaled so that
42 /// diagonal == eigenvalues).
43 Eigen::Matrix3d Eigen3x3RealSymEigenDecomposition(const Eigen::Matrix3d &A);
44 /// @brief Analytic 2x2 analogue of @ref Eigen3x3RealSymEigenDecomposition.
45 Eigen::Matrix2d Eigen2x2RealSymEigenDecomposition(const Eigen::Matrix2d &A);
46
47 /// @brief Condition number of a 3x3 SPD matrix from its eigenvalues.
48 real Eigen3x3RealSymEigenDecompositionGetCond(const Eigen::Matrix3d &A);
49 /// @brief Like @ref Eigen3x3RealSymEigenDecompositionGetCond but returns
50 /// `lambda0 / lambda1` only (ignores the smallest eigenvalue).
51 real Eigen3x3RealSymEigenDecompositionGetCond01(const Eigen::Matrix3d &A);
52 /// @brief 2x2 analogue of @ref Eigen3x3RealSymEigenDecompositionGetCond.
53 real Eigen2x2RealSymEigenDecompositionGetCond(const Eigen::Matrix2d &A);
54
55 /// @brief Eigen-decomposition with eigenvector columns normalised to unit length.
56 Eigen::Matrix3d Eigen3x3RealSymEigenDecompositionNormalized(const Eigen::Matrix3d &A);
57 /// @brief 2x2 analogue of @ref Eigen3x3RealSymEigenDecompositionNormalized.
58 Eigen::Matrix2d Eigen2x2RealSymEigenDecompositionNormalized(const Eigen::Matrix2d &A);
59}
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
Eigen::Index EigenLeastSquareSolve(const Eigen::MatrixXd &A, const Eigen::MatrixXd &B, Eigen::MatrixXd &AIB)
Least-squares solve A * AIB ~= B via a rank-revealing QR-style decomposition; returns the computed ra...
real EigenLeastSquareInverse_Filtered(const Eigen::MatrixXd &A, Eigen::MatrixXd &AI, real svdTol, int mode)
Pseudoinverse with a choice of singular-value filter.
Definition HardEigen.cpp:25
real Eigen3x3RealSymEigenDecompositionGetCond01(const Eigen::Matrix3d &A)
Like Eigen3x3RealSymEigenDecompositionGetCond but returns lambda0 / lambda1 only (ignores the smalles...
Eigen::Matrix3d Eigen3x3RealSymEigenDecompositionNormalized(const Eigen::Matrix3d &A)
Eigen-decomposition with eigenvector columns normalised to unit length.
Eigen::Matrix2d Eigen2x2RealSymEigenDecompositionNormalized(const Eigen::Matrix2d &A)
2x2 analogue of Eigen3x3RealSymEigenDecompositionNormalized.
Eigen::Matrix3d Eigen3x3RealSymEigenDecomposition(const Eigen::Matrix3d &A)
Analytic eigen-decomposition of a 3x3 real symmetric matrix. Returns the eigenvector matrix (columns ...
Definition HardEigen.cpp:72
Eigen::Matrix2d Eigen2x2RealSymEigenDecomposition(const Eigen::Matrix2d &A)
Analytic 2x2 analogue of Eigen3x3RealSymEigenDecomposition.
Definition HardEigen.cpp:88
real Eigen3x3RealSymEigenDecompositionGetCond(const Eigen::Matrix3d &A)
Condition number of a 3x3 SPD matrix from its eigenvalues.
real EigenLeastSquareInverse(const Eigen::MatrixXd &A, Eigen::MatrixXd &AI, real svdTol)
Moore-Penrose pseudoinverse via SVD, dropping singular values below svdTol (relative to the largest)....
Definition HardEigen.cpp:13
real Eigen2x2RealSymEigenDecompositionGetCond(const Eigen::Matrix2d &A)
2x2 analogue of Eigen3x3RealSymEigenDecompositionGetCond.
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105