11 template <
class TDATA>
16 std::vector<TDATA> Vs;
21 template <
class Finit>
24 Finit &&finit = [](TDATA &) {}) : kSubspace(NkSubspace)
26 Vs.resize(kSubspace + 1);
46 template <
class TFA,
class TFML,
class TFDot,
class TFstop>
47 bool solve(TFA &&FA, TFML &&FML, TFDot &&fDot, TDATA &
b, TDATA &
x, uint32_t nRestart, TFstop &&FStop)
50 real scale_MLb = std::sqrt(fDot(MLb, MLb));
52 h.setZero(kSubspace + 1, kSubspace);
53 uint32_t iRestart = 0;
54 for (iRestart = 0; iRestart <= nRestart; iRestart++)
58 Vs[0].addTo(MLb, -1.0);
60 beta = std::sqrt(fDot(Vs[0], Vs[0]));
61 if (FStop(iRestart, beta, scale_MLb))
64 (iRestart == nRestart))
69 for (;
j < kSubspace;
j++)
72 FML(V_temp, Vs[
j + 1]);
73 for (uint32_t
i = 0;
i <=
j;
i++)
76 h(
i,
j) = fDot(Vs[
j + 1], (Vs[
i]));
78 for (uint32_t
i = 0;
i <=
j;
i++)
81 Vs[
j + 1].addTo(Vs[
i], -h(
i,
j));
83 h(
j + 1,
j) = std::sqrt(fDot(Vs[
j + 1], Vs[
j + 1]));
84 if (h(
j + 1,
j) < scale_MLb * 1e-32)
86 std::cout <<
"early stop" << std::endl;
89 Vs[
j + 1] *= 1.0 / h(
j + 1,
j);
111 MatrixXR hPart = h(Eigen::seq(0,
j + 1 - 1), Eigen::seq(0,
j - 1));
112 DNDS_assert_info(hPart.allFinite(),
"GMRES_LeftPreconditioned acquired inf or nan coefficient");
120 for (uint32_t jj = 0; jj <
j; jj++)
122 x.addTo(Vs[jj], y(jj));
131 return iRestart < nRestart;
135 template <
class TDATA,
class TScalar>
138 bool initialized =
false;
144 index pHistorySize{0};
147 template <
class Finit>
149 Finit &&finit = [](TDATA &) {})
158 void reset() { initialized =
false, pHistorySize = 0; }
162 template <
class TFA,
class TFM,
class TFResPrec,
class TFDot,
class TFstop>
163 bool solve(TFA &&FA, TFM &&FM, TFResPrec &&FResPrec, TFDot &&fDot, TDATA &
x, uint32_t niter, TFstop &&FStop)
173 for (
int iter = 1; iter <= niter; iter++)
180 TScalar zrDotNew = fDot(
z,
r);
181 TScalar zDotz = fDot(
z,
z);
182 if (FStop(iter, zrDotNew, zDotz))
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Robust linear-algebra primitives for small / moderately-sized Eigen matrices that are more numericall...
GMRES_LeftPreconditioned(uint32_t NkSubspace, Finit &&finit=[](TDATA &) {})
bool solve(TFA &&FA, TFML &&FML, TFDot &&fDot, TDATA &b, TDATA &x, uint32_t nRestart, TFstop &&FStop)
PCG_PreconditionedRes(Finit &&finit=[](TDATA &) {})
bool solve(TFA &&FA, TFM &&FM, TFResPrec &&FResPrec, TFDot &&fDot, TDATA &x, uint32_t niter, TFstop &&FStop)
index getPHistorySize() const
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...
DNDS_CONSTANT const real verySmallReal
Catch-all lower bound ("effectively zero").
DNDS_CONSTANT const real UnInitReal
Sentinel "not initialised" real value (NaN). Cheap to detect with std::isnan or IsUnInitReal; survive...
Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > MatrixXR
Column-major dynamic Eigen matrix of reals (default layout).
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Eigen::Vector< real, Eigen::Dynamic > VectorXR
Dynamic Eigen vector of reals.
const tPoint const tPoint const tPoint & p