Loading...
Searching...
No Matches
QuadraticBath.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3** SPDX-License-Identifier: BSD-3-Clause
4** Copyright (c) 2010--present, eOn Development Team
5*/
6#pragma once
7
8#include <Eigen/Dense>
9#include <Eigen/Eigenvalues>
10#include <Eigen/QR>
11#include <cmath>
12#include <limits>
13#include <stdexcept>
14
15namespace eonc::tunneling {
16
23public:
24 QuadraticBath(const Eigen::MatrixXd &hessian,
25 const Eigen::MatrixXd &reactionBasis) {
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()) ||
30 reactionBasis.rows() != n || reactionBasis.cols() < 1 ||
31 reactionBasis.cols() > n || !reactionBasis.allFinite() ||
32 !(reactionBasis.transpose() * reactionBasis)
33 .isApprox(Eigen::MatrixXd::Identity(reactionBasis.cols(),
34 reactionBasis.cols()),
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();
40 Eigen::MatrixXd retained = reactionBasis;
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) {
48 frequenciesSquared_.resize(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) {
61 bath_ = bath_ * eig.eigenvectors();
62 frequenciesSquared_ = eig.eigenvalues();
63 break;
64 }
65 retained.resize(n, reaction_.cols() + promote);
66 retained.leftCols(reaction_.cols()) = reaction_;
67 retained.rightCols(promote) =
68 bath_ * eig.eigenvectors().leftCols(promote);
69 }
70 a_ = reaction_.transpose() * h * reaction_;
71 c_ = reaction_.transpose() * h * bath_;
72 }
73
74 const Eigen::MatrixXd &reactionBasis() const { return reaction_; }
75 const Eigen::MatrixXd &bathBasis() const { return bath_; }
76 const Eigen::MatrixXd &reactionCurvature() const { return a_; }
77 const Eigen::MatrixXd &coupling() const { return c_; }
78 const Eigen::VectorXd &bathCurvatures() const { return frequenciesSquared_; }
79
81 Eigen::MatrixXd kernel(double nu) const {
82 const double nu2 = squaredFrequency(nu);
83 Eigen::MatrixXd result = a_;
84 result.diagonal().array() += nu2;
85 for (Eigen::Index k = 0; k < frequenciesSquared_.size(); ++k)
86 result.noalias() -=
87 c_.col(k) * c_.col(k).transpose() / (frequenciesSquared_[k] + nu2);
88 return result;
89 }
90
92 Eigen::MatrixXd memory(double s) const {
93 const double s2 = squaredFrequency(s);
94 if (s < 0)
95 throw std::invalid_argument("Laplace frequency must be nonnegative");
96 Eigen::MatrixXd result = Eigen::MatrixXd::Zero(a_.rows(), a_.cols());
97 for (Eigen::Index k = 0; k < frequenciesSquared_.size(); ++k) {
98 const double e = frequenciesSquared_[k];
99 result.noalias() +=
100 (s / e / (e + s2)) * c_.col(k) * c_.col(k).transpose();
101 }
102 return result;
103 }
104
105 double logBathDeterminant(double nu) const {
106 const double nu2 = squaredFrequency(nu);
107 return (frequenciesSquared_.array() + nu2).log().sum();
108 }
109
112 double logBathPartition(double betaHbar) const {
113 if (!(betaHbar > 0) || !std::isfinite(betaHbar))
114 throw std::invalid_argument("beta*hbar must be positive and finite");
115 double value = 0;
116 for (Eigen::Index k = 0; k < frequenciesSquared_.size(); ++k) {
117 const double z = betaHbar * std::sqrt(frequenciesSquared_[k]);
118 if (!(z > 0) || !std::isfinite(z))
119 throw std::invalid_argument(
120 "thermal bath frequency overflows or underflows");
121 value -= z / 2 + std::log(-std::expm1(-z));
122 }
123 return value;
124 }
125
126private:
127 static double squaredFrequency(double nu) {
128 if (!std::isfinite(nu) || !std::isfinite(nu * nu))
129 throw std::invalid_argument("frequency must have a finite square");
130 return nu * nu;
131 }
132 Eigen::MatrixXd reaction_, bath_, a_, c_;
133 Eigen::VectorXd frequenciesSquared_;
134};
135} // namespace eonc::tunneling
const Eigen::MatrixXd & bathBasis() const
static double squaredFrequency(double nu)
Eigen::MatrixXd kernel(double nu) const
Schur complement of H+nu^2 I, including reaction kinetic curvature.
const Eigen::VectorXd & bathCurvatures() const
QuadraticBath(const Eigen::MatrixXd &hessian, const Eigen::MatrixXd &reactionBasis)
const Eigen::MatrixXd & reactionBasis() const
double logBathPartition(double betaHbar) const
Normalized quantum partition of the uncoupled conditional harmonic bath.
const Eigen::MatrixXd & coupling() const
const Eigen::MatrixXd & reactionCurvature() const
double logBathDeterminant(double nu) const
Eigen::MatrixXd memory(double s) const
Laplace transform of the physical harmonic memory kernel for s >= 0.