25 {
26 const Eigen::Index n = hessian.rows();
27 if (n < 1 || hessian.cols() != n || !hessian.allFinite() ||
28 !hessian.isApprox(hessian.transpose(),
29 32 * std::numeric_limits<double>::epsilon()) ||
35 1e-12)) {
36 throw std::invalid_argument("quadratic bath requires symmetric finite H "
37 "and orthonormal reaction basis");
38 }
39 const Eigen::MatrixXd h = 0.5 * hessian + 0.5 * hessian.transpose();
41 for (;;) {
42 Eigen::HouseholderQR<Eigen::MatrixXd> qr(retained);
43 const Eigen::MatrixXd orthogonal =
44 qr.householderQ() * Eigen::MatrixXd::Identity(n, n);
45 reaction_ = orthogonal.leftCols(retained.cols());
46 bath_ = orthogonal.rightCols(n - retained.cols());
47 if (
bath_.cols() == 0) {
49 break;
50 }
51 const Eigen::MatrixXd e =
bath_.transpose() * h *
bath_;
52 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eig(e);
53 if (eig.info() != Eigen::Success || !eig.eigenvalues().allFinite()) {
54 throw std::runtime_error("quadratic bath eigensolver failed");
55 }
56 Eigen::Index promote = 0;
57 while (promote < eig.eigenvalues().size() &&
58 eig.eigenvalues()[promote] <= 0.0)
59 ++promote;
60 if (promote == 0) {
63 break;
64 }
65 retained.resize(n,
reaction_.cols() + promote);
67 retained.rightCols(promote) =
68 bath_ * eig.eigenvectors().leftCols(promote);
69 }
72 }
const Eigen::MatrixXd & reactionBasis() const
Eigen::VectorXd frequenciesSquared_
Eigen::MatrixXd reaction_