Loading...
Searching...
No Matches
eonc::tunneling::PhysicalQuadraticBath Struct Reference

V(q,b)=V_fixed(q)+source(q)^T b+b^T E(q)b/2. More...

#include <PhysicalQuadraticBath.h>

Classes

struct  CurvatureDerivatives
struct  Evaluation

Public Types

using Source
 Source, bath x retained Jacobian, one retained Hessian per bath mode.
using Curvature
 Full bath curvature in a fixed basis, with derivatives through order 0–2.

Public Member Functions

void validate (long dof) const
CurvatureDerivatives curvatureAt (const Eigen::VectorXd &q, int order) const
Eigen::MatrixXd fullHessian (const Eigen::VectorXd &q, const Eigen::MatrixXd &potentialHessian) const
 Physical curvature at the conditional bath equilibrium.
Evaluation evaluate (const std::vector< Eigen::VectorXd > &q, double c, bool needHessian=false) const
 Exact finite primitive-ring Gaussian elimination, with c=(beta_N*hbar)^-2.

Public Attributes

Eigen::MatrixXd coupling
 retained x bath, source=C^T q by default
Eigen::VectorXd curvatures
 strictly positive physical bath eigenvalues
bool relaxedPotential = false
 With V_relaxed=V_fixed-source^T E^-1 source/2, restore its counterterm.
Source source
Curvature curvature

Detailed Description

V(q,b)=V_fixed(q)+source(q)^T b+b^T E(q)b/2.

The bath represents physical coordinates, not an Ohmic ring thermostat.

Definition at line 21 of file PhysicalQuadraticBath.h.

Member Typedef Documentation

◆ Curvature

Initial value:

Full bath curvature in a fixed basis, with derivatives through order 0–2.

Definition at line 38 of file PhysicalQuadraticBath.h.

◆ Source

Initial value:
std::function<void(const Eigen::VectorXd &, Eigen::VectorXd &,
Eigen::MatrixXd &, std::vector<Eigen::MatrixXd> &)>

Source, bath x retained Jacobian, one retained Hessian per bath mode.

Definition at line 27 of file PhysicalQuadraticBath.h.

Member Function Documentation

◆ curvatureAt()

CurvatureDerivatives eonc::tunneling::PhysicalQuadraticBath::curvatureAt ( const Eigen::VectorXd & q,
int order ) const
inline

Definition at line 82 of file PhysicalQuadraticBath.h.

82 {
83 const long r = q.size(), b = curvatures.size();
84 if (!curvature || order < 0 || order > 2 || b < 1)
85 throw std::invalid_argument("invalid physical bath curvature request");
86 auto out = curvature(q, order);
87 auto valid = [&](const Eigen::MatrixXd &matrix) {
88 return matrix.rows() == b && matrix.cols() == b && matrix.allFinite() &&
89 matrix.isApprox(matrix.transpose(), 1e-12);
90 };
91 if (!valid(out.value) ||
92 (order >= 1 && out.first.size() != static_cast<size_t>(r)) ||
93 (order >= 2 && out.second.size() != static_cast<size_t>(r)))
94 throw std::invalid_argument(
95 "physical bath curvature derivative mismatch");
96 if (order >= 1)
97 for (const auto &matrix : out.first)
98 if (!valid(matrix))
99 throw std::invalid_argument(
100 "invalid physical bath curvature gradient");
101 if (order >= 2) {
102 for (long i = 0; i < r; ++i) {
103 if (out.second[i].size() != static_cast<size_t>(r))
104 throw std::invalid_argument(
105 "physical bath curvature Hessian mismatch");
106 for (long j = 0; j < r; ++j)
107 if (!valid(out.second[i][j]))
108 throw std::invalid_argument(
109 "invalid physical bath curvature Hessian");
110 }
111 for (long i = 0; i < r; ++i)
112 for (long j = 0; j < i; ++j)
113 if (!out.second[i][j].isApprox(out.second[j][i], 1e-12))
114 throw std::invalid_argument(
115 "asymmetric physical bath curvature Hessian");
116 }
117 return out;
118 }
Eigen::VectorXd curvatures
strictly positive physical bath eigenvalues

◆ evaluate()

Evaluation eonc::tunneling::PhysicalQuadraticBath::evaluate ( const std::vector< Eigen::VectorXd > & q,
double c,
bool needHessian = false ) const
inline

Exact finite primitive-ring Gaussian elimination, with c=(beta_N*hbar)^-2.

Definition at line 184 of file PhysicalQuadraticBath.h.

185 {
186 if (q.empty() || !(c > 0) || !std::isfinite(c))
187 throw std::invalid_argument(
188 "physical bath requires a nonempty ring and positive spring");
189 const long n = q.size(), r = q.front().size(), b = curvatures.size();
190 validate(r);
191 Evaluation out;
192 out.gradient.assign(n, Eigen::VectorXd::Zero(r));
193 out.bathPositions.assign(n, Eigen::VectorXd::Zero(b));
194 if (needHessian)
195 out.hessian = Eigen::MatrixXd::Zero(n * r, n * r);
196 std::vector<Eigen::VectorXd> s(n);
197 std::vector<Eigen::MatrixXd> jac(n);
198 std::vector<std::vector<Eigen::MatrixXd>> second(n);
199 for (long j = 0; j < n; ++j) {
200 if (q[j].size() != r || !q[j].allFinite())
201 throw std::invalid_argument("physical bath ring coordinate mismatch");
202 if (source)
203 source(q[j], s[j], jac[j], second[j]);
204 else {
205 s[j] = coupling.transpose() * q[j];
206 jac[j] = coupling.transpose();
207 second[j].assign(b, Eigen::MatrixXd::Zero(r, r));
208 }
209 if (s[j].size() != b || jac[j].rows() != b || jac[j].cols() != r ||
210 !s[j].allFinite() || !jac[j].allFinite() ||
211 second[j].size() != static_cast<size_t>(b))
212 throw std::invalid_argument("physical bath source derivative mismatch");
213 for (const auto &h : second[j])
214 if (h.rows() != r || h.cols() != r || !h.allFinite() ||
215 !h.isApprox(h.transpose(), 1e-12))
216 throw std::invalid_argument("physical bath source Hessian mismatch");
217 }
218 if (curvature) {
219 std::vector<Eigen::MatrixXd> blocks;
220 blocks.reserve(n);
221 Eigen::MatrixXd flatSource(n * b, 1);
222 for (long j = 0; j < n; ++j) {
223 blocks.push_back(curvatureAt(q[j], 0).value);
224 flatSource.middleRows(j * b, b) = s[j];
225 }
226 auto factor = std::make_shared<CyclicBlockBath>(blocks, c);
227 const Eigen::MatrixXd flatY = -factor->solve(flatSource);
228 out.bathLogDeterminant = factor->logDeterminant();
229 if (needHessian) {
230 out.blockBath = factor;
231 out.sourceJacobians.resize(n);
232 }
233 for (long j = 0; j < n; ++j) {
234 const Eigen::VectorXd y = flatY.middleRows(j * b, b).col(0);
235 out.bathPositions[j] = y;
236 out.energy += 0.5 * s[j].dot(y);
237 out.gradient[j].noalias() += jac[j].transpose() * y;
238 const auto state = curvatureAt(q[j], needHessian ? 2 : 1);
239 Eigen::MatrixXd mixed = jac[j];
240 for (long i = 0; i < r; ++i) {
241 out.gradient[j][i] += 0.5 * y.dot(state.first[i] * y);
242 if (needHessian) {
243 mixed.col(i).noalias() += state.first[i] * y;
244 for (long k = 0; k < r; ++k)
245 out.hessian(j * r + i, j * r + k) +=
246 0.5 * y.dot(state.second[i][k] * y);
247 }
248 }
249 if (needHessian) {
250 for (long a = 0; a < b; ++a)
251 out.hessian.block(j * r, j * r, r, r).noalias() +=
252 y[a] * second[j][a];
253 out.sourceJacobians[j] = std::move(mixed);
254 }
255 }
256 if (needHessian) {
257 for (long l = 0; l < n; ++l) {
258 Eigen::MatrixXd rhs = Eigen::MatrixXd::Zero(n * b, r);
259 rhs.middleRows(l * b, b) = out.sourceJacobians[l];
260 const Eigen::MatrixXd response = factor->solve(rhs);
261 for (long j = 0; j < n; ++j)
262 out.hessian.block(j * r, l * r, r, r).noalias() -=
263 out.sourceJacobians[j].transpose() *
264 response.middleRows(j * b, b);
265 }
266 }
267 return out;
268 }
269 // inverse[lag] is diagonal in the fixed physical bath eigenbasis.
270 std::vector<Eigen::VectorXd> inverse(n, Eigen::VectorXd::Zero(b));
271 // The positive cyclic Green function solves (E+c*L)G=I. Its two
272 // decaying branches sum periodic images without Fourier cancellation.
273 const double rootSpring = std::sqrt(c);
274 for (long a = 0; a < b; ++a) {
275 const double frequency = std::sqrt(curvatures[a]);
276 double alpha = 2 * std::asinh(frequency / (2 * rootSpring));
277 if (!std::isfinite(alpha))
278 alpha = std::log(curvatures[a]) - std::log(c);
279 const double periodic = -std::expm1(-n * alpha);
280 const double scale =
281 1 / frequency / std::hypot(frequency, 2 * rootSpring) / periodic;
282 out.bathLogDeterminant +=
283 n * (std::log(c) + alpha) + 2 * std::log(periodic);
284 for (long lag = 0; lag < n; ++lag)
285 inverse[lag][a] =
286 scale * (std::exp(-lag * alpha) + std::exp(-(n - lag) * alpha));
287 }
288 for (long j = 0; j < n; ++j) {
289 Eigen::VectorXd y = Eigen::VectorXd::Zero(b);
290 for (long l = 0; l < n; ++l)
291 y.array() += inverse[(j - l + n) % n].array() * s[l].array();
292 out.bathPositions[j] = -y;
294 y.array() -= s[j].array() / curvatures.array();
295 out.energy -= 0.5 * s[j].dot(y);
296 out.gradient[j].noalias() -= jac[j].transpose() * y;
297 if (needHessian) {
298 for (long l = 0; l < n; ++l) {
299 Eigen::VectorXd weights = inverse[(j - l + n) % n];
300 if (relaxedPotential && j == l)
301 weights.array() -= curvatures.cwiseInverse().array();
302 out.hessian.block(j * r, l * r, r, r).noalias() -=
303 jac[j].transpose() * weights.asDiagonal() * jac[l];
304 }
305 for (long a = 0; a < b; ++a)
306 out.hessian.block(j * r, j * r, r, r).noalias() -=
307 y[a] * second[j][a];
308 }
309 }
310 if (needHessian) {
311 out.inverseBath = inverse;
312 out.sourceJacobians = jac;
313 }
314 return out;
315 }
Eigen::MatrixXd coupling
retained x bath, source=C^T q by default
bool relaxedPotential
With V_relaxed=V_fixed-source^T E^-1 source/2, restore its counterterm.
CurvatureDerivatives curvatureAt(const Eigen::VectorXd &q, int order) const

◆ fullHessian()

Eigen::MatrixXd eonc::tunneling::PhysicalQuadraticBath::fullHessian ( const Eigen::VectorXd & q,
const Eigen::MatrixXd & potentialHessian ) const
inline

Physical curvature at the conditional bath equilibrium.

The negative eigenvalue of this full operator sets the dynamical crossover frequency.

Definition at line 122 of file PhysicalQuadraticBath.h.

123 {
124 const long r = q.size(), b = curvatures.size();
125 validate(r);
126 if (potentialHessian.rows() != r || potentialHessian.cols() != r ||
127 !potentialHessian.allFinite())
128 throw std::invalid_argument("physical bath potential Hessian mismatch");
129 Eigen::VectorXd s;
130 Eigen::MatrixXd jac;
131 std::vector<Eigen::MatrixXd> second;
132 if (source)
133 source(q, s, jac, second);
134 else {
135 s = coupling.transpose() * q;
136 jac = coupling.transpose();
137 second.assign(b, Eigen::MatrixXd::Zero(r, r));
138 }
139 if (s.size() != b || jac.rows() != b || jac.cols() != r || !s.allFinite() ||
140 !jac.allFinite() || second.size() != static_cast<size_t>(b))
141 throw std::invalid_argument("physical bath source derivative mismatch");
142 for (const auto &h : second)
143 if (h.rows() != r || h.cols() != r || !h.allFinite() ||
144 !h.isApprox(h.transpose(), 1e-12))
145 throw std::invalid_argument("physical bath source Hessian mismatch");
146 Eigen::MatrixXd out = Eigen::MatrixXd::Zero(r + b, r + b);
147 out.topLeftCorner(r, r) = potentialHessian;
148 if (curvature) {
149 const auto state = curvatureAt(q, 2);
150 const CyclicBlockBath factor({state.value}, 1.0);
151 const Eigen::VectorXd y = -factor.solve(s).col(0);
152 Eigen::MatrixXd mixed = jac;
153 for (long a = 0; a < b; ++a)
154 out.topLeftCorner(r, r).noalias() += y[a] * second[a];
155 for (long i = 0; i < r; ++i) {
156 mixed.col(i).noalias() += state.first[i] * y;
157 for (long j = 0; j < r; ++j)
158 out(i, j) += 0.5 * y.dot(state.second[i][j] * y);
159 }
160 out.topRightCorner(r, b) = mixed.transpose();
161 out.bottomLeftCorner(b, r) = mixed;
162 out.bottomRightCorner(b, b) = state.value;
163 if (!out.allFinite() || !out.isApprox(out.transpose(), 1e-12))
164 throw std::invalid_argument(
165 "physical bath full Hessian is not finite and symmetric");
166 return out;
167 }
169 out.topLeftCorner(r, r).noalias() +=
170 jac.transpose() * curvatures.cwiseInverse().asDiagonal() * jac;
171 else
172 for (long k = 0; k < b; ++k)
173 out.topLeftCorner(r, r).noalias() -= (s[k] / curvatures[k]) * second[k];
174 out.topRightCorner(r, b) = jac.transpose();
175 out.bottomLeftCorner(b, r) = jac;
176 out.bottomRightCorner(b, b) = curvatures.asDiagonal();
177 if (!out.allFinite() || !out.isApprox(out.transpose(), 1e-12))
178 throw std::invalid_argument(
179 "physical bath full Hessian is not finite and symmetric");
180 return out;
181 }

◆ validate()

void eonc::tunneling::PhysicalQuadraticBath::validate ( long dof) const
inline

Definition at line 71 of file PhysicalQuadraticBath.h.

71 {
72 if (dof < 1 || coupling.rows() != dof ||
73 coupling.cols() != curvatures.size() || !coupling.allFinite() ||
74 !curvatures.allFinite() || (curvatures.array() <= 0).any())
75 throw std::invalid_argument(
76 "physical bath requires finite coupling and positive bath curvature");
78 throw std::invalid_argument(
79 "variable physical bath requires a frozen potential callback");
80 }

Member Data Documentation

◆ coupling

Eigen::MatrixXd eonc::tunneling::PhysicalQuadraticBath::coupling

retained x bath, source=C^T q by default

Definition at line 22 of file PhysicalQuadraticBath.h.

◆ curvature

Curvature eonc::tunneling::PhysicalQuadraticBath::curvature

Definition at line 40 of file PhysicalQuadraticBath.h.

◆ curvatures

Eigen::VectorXd eonc::tunneling::PhysicalQuadraticBath::curvatures

strictly positive physical bath eigenvalues

Definition at line 23 of file PhysicalQuadraticBath.h.

◆ relaxedPotential

bool eonc::tunneling::PhysicalQuadraticBath::relaxedPotential = false

With V_relaxed=V_fixed-source^T E^-1 source/2, restore its counterterm.

Definition at line 25 of file PhysicalQuadraticBath.h.

◆ source

Source eonc::tunneling::PhysicalQuadraticBath::source

Definition at line 30 of file PhysicalQuadraticBath.h.


The documentation for this struct was generated from the following file: