Loading...
Searching...
No Matches
FrequencyFittedKinetic.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
3
4#include <Eigen/Eigenvalues>
5#include <algorithm>
6#include <cmath>
7#include <limits>
8#include <numbers>
9namespace gpr::quantum {
10gaussian::Segment frequencyFittedKinetic(const Eigen::MatrixXd& curvature,
11 double h)
12{
13 const auto d = curvature.rows();
14 if (!d || curvature.cols() != d || !curvature.allFinite() || !(h > 0) ||
15 !std::isfinite(h) ||
16 (curvature - curvature.transpose()).norm() >
17 1e-12 * std::max(1., curvature.norm()))
18 throw std::invalid_argument(
19 "Finite symmetric fitting curvature and positive duration "
20 "required");
21 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
22 .5 * (curvature + curvature.transpose()));
23 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
24 throw std::runtime_error(
25 "Frequency-fitted curvature eigensolve failed");
26 Eigen::VectorXd coupling(d);
27 double logarithm = 0, caustic = std::numeric_limits<double>::infinity();
28 for (Eigen::Index i = 0; i < d; ++i) {
29 const double lambda = eigen.eigenvalues()[i],
30 x = .5 * h * std::sqrt(std::abs(lambda));
31 if (!std::isfinite(x))
32 throw std::overflow_error("Unrepresentable fitted phase");
33 double ratio = 1;
34 if (lambda < 0) {
35 if (!(x < std::numbers::pi / 2))
36 throw std::domain_error(
37 "Fitted unstable link reaches its reference caustic");
38 if (x > 0) ratio = x / std::sin(x);
39 caustic = std::min(caustic, std::numbers::pi - 2 * x);
40 } else if (x > 0) {
41 ratio = x < 20 ? x / std::sinh(x)
42 : 2 * x * std::exp(-x) / (-std::expm1(-2 * x));
43 }
44 coupling[i] = ratio * ratio / h;
45 if (!(coupling[i] > 0) || !std::isfinite(coupling[i]))
46 throw std::overflow_error(
47 "Unrepresentable positive fitted kinetic coupling");
48 logarithm += std::log(coupling[i]);
49 }
50 Eigen::MatrixXd l = eigen.eigenvectors() * coupling.asDiagonal() *
51 eigen.eigenvectors().transpose();
52 l = (.5 * l + .5 * l.transpose()).eval();
53 if (!l.allFinite() || !std::isfinite(logarithm))
54 throw std::overflow_error("Nonfinite fitted kinetic link");
55 return {l, l, logarithm, h, caustic, {}};
56}
57} // namespace gpr::quantum
@ x
Definition Enums.h:28
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
gaussian::Segment frequencyFittedKinetic(const Eigen::MatrixXd &curvature, double h)