Loading...
Searching...
No Matches
gpr::quantum::HarmonicTurningTail Class Reference

#include <gpr/quantum/HarmonicTurningTail.h>

Public Member Functions

 HarmonicTurningTail (const Eigen::MatrixXd &curvature)
HarmonicTail evaluate (const Eigen::VectorXd &q, double t, double hbar) const
double halfDurationForLogEnergy (const Eigen::VectorXd &q, double logEnergy, double hbar) const

Detailed Description

Definition at line 18 of file HarmonicTurningTail.h.

Constructor & Destructor Documentation

◆ HarmonicTurningTail()

gpr::quantum::HarmonicTurningTail::HarmonicTurningTail ( const Eigen::MatrixXd & curvature)
inlineexplicit

Definition at line 23 of file HarmonicTurningTail.h.

24 {
25 if (curvature.rows() == 0 || curvature.rows() != curvature.cols() ||
26 !curvature.allFinite() ||
27 (curvature - curvature.transpose()).norm() >
28 1e-12 * std::max(1., curvature.norm()))
29 throw std::invalid_argument(
30 "A finite symmetric harmonic well is required");
31 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(curvature);
32 if (eigen.info() != Eigen::Success ||
33 !(eigen.eigenvalues().array() > 0).all())
34 throw std::invalid_argument(
35 "The harmonic turning tail requires a positive well");
36 modes_ = eigen.eigenvectors();
37 frequencies_ = eigen.eigenvalues().array().sqrt();
38 }

Member Function Documentation

◆ evaluate()

HarmonicTail gpr::quantum::HarmonicTurningTail::evaluate ( const Eigen::VectorXd & q,
double t,
double hbar ) const
inline

Definition at line 41 of file HarmonicTurningTail.h.

42 {
43 if (q.size() != frequencies_.size() || !q.allFinite() ||
44 !(t > 0 && hbar > 0) || !std::isfinite(t) || !std::isfinite(hbar))
45 throw std::invalid_argument(
46 "Invalid harmonic tail geometry or scales");
47 const double logTwo = std::log(2.), pi = std::acos(-1.);
48 const Eigen::VectorXd modal = modes_.transpose() * q;
49 Eigen::VectorXd momentum(q.size()), turn(q.size()), logTerms(q.size()),
50 slopes(q.size());
51 HarmonicTail result;
52 result.logEnergy = -std::numeric_limits<double>::infinity();
53 for (Eigen::Index i = 0; i < q.size(); ++i) {
54 const double omega = frequencies_[i], x = omega * t;
55 if (!(x > 0) || !std::isfinite(2 * x))
56 throw std::invalid_argument(
57 "Unresolved harmonic tail duration");
58 const double tangent = std::tanh(x),
59 logSech = logTwo - x - std::log1p(std::exp(-2 * x));
60 momentum[i] = omega * tangent * modal[i];
61 turn[i] = std::exp(logSech) * modal[i];
62 result.action += modal[i] * momentum[i];
63 const double squared = x < .01 ? x * x : 0;
64 const double abbreviated =
65 x < .01
66 ? x * squared *
67 (2. / 3 +
68 squared * (-8. / 15 +
69 squared * (34. / 105 +
70 squared * (-496. / 2835 +
71 squared * 2764. /
72 31185))))
73 : tangent - std::exp(std::log(x) + 2 * logSech);
74 result.abbreviatedAction +=
75 omega * modal[i] * modal[i] * abbreviated;
76 const double logSinh =
77 2 * x + std::log(-std::expm1(-4 * x)) - logTwo;
78 result.logDiagonalKernel +=
79 .5 * (std::log(omega) - logTwo - std::log(pi) - std::log(hbar) -
80 logSinh);
81 logTerms[i] = modal[i] == 0
82 ? -std::numeric_limits<double>::infinity()
83 : -logTwo + 2 * std::log(omega) +
84 2 * std::log(std::abs(modal[i])) +
85 2 * logSech;
86 slopes[i] = -2 * omega * tangent;
87 result.logEnergy = std::max(result.logEnergy, logTerms[i]);
88 }
89 if (std::isfinite(result.logEnergy)) {
90 double sum = 0, derivative = 0;
91 for (Eigen::Index i = 0; i < q.size(); ++i) {
92 const double weight = std::exp(logTerms[i] - result.logEnergy);
93 sum += weight;
94 derivative += weight * slopes[i];
95 }
96 result.logEnergy += std::log(sum);
97 result.logEnergyDerivative = derivative / sum;
98 result.energy = std::exp(result.logEnergy);
99 }
100 result.logDiagonalKernel -= result.action / hbar;
101 result.momentum = modes_ * momentum;
102 result.turningPoint = modes_ * turn;
103 if (!std::isfinite(result.action) ||
104 !std::isfinite(result.abbreviatedAction) ||
105 !std::isfinite(result.energy) ||
106 !std::isfinite(result.logDiagonalKernel) ||
107 !result.momentum.allFinite() || !result.turningPoint.allFinite())
108 throw std::invalid_argument("Nonfinite harmonic tail result");
109 return result;
110 }
@ x
Definition Enums.h:28
DoubleDouble abs(DoubleDouble a)
double log(double x) noexcept
double exp(double x) noexcept

◆ halfDurationForLogEnergy()

double gpr::quantum::HarmonicTurningTail::halfDurationForLogEnergy ( const Eigen::VectorXd & q,
double logEnergy,
double hbar ) const
inline

Definition at line 112 of file HarmonicTurningTail.h.

114 {
115 if (!std::isfinite(logEnergy) || q.size() != frequencies_.size() ||
116 !q.allFinite() || !(q.array() != 0).any())
117 throw std::invalid_argument(
118 "A nonzero matching point and finite log energy are required");
119 const Eigen::VectorXd modal = modes_.transpose() * q;
120 Eigen::VectorXd terms(q.size());
121 double largest = -std::numeric_limits<double>::infinity();
122 for (Eigen::Index i = 0; i < q.size(); ++i) {
123 terms[i] = modal[i] == 0
124 ? -std::numeric_limits<double>::infinity()
125 : -std::log(2.) + 2 * std::log(frequencies_[i]) +
126 2 * std::log(std::abs(modal[i]));
127 largest = std::max(largest, terms[i]);
128 }
129 double sum = 0;
130 for (double term: terms)
131 sum += std::exp(term - largest);
132 const double initialLog = largest + std::log(sum);
133 if (!std::isfinite(initialLog) || !(logEnergy < initialLog))
134 throw std::invalid_argument(
135 "Tail energy must lie below the matching potential");
136 double left = 0, right = 1 / frequencies_.minCoeff();
137 for (unsigned iteration = 0;
138 evaluate(q, right, hbar).logEnergy > logEnergy; ++iteration) {
139 if (iteration >= 1024 || !std::isfinite(2 * right))
140 throw std::domain_error("Cannot bracket harmonic tail energy");
141 right *= 2;
142 }
143 double t = .5 * right;
144 for (unsigned iteration = 0; iteration < 100; ++iteration) {
145 const auto state = evaluate(q, t, hbar);
146 const double residual = state.logEnergy - logEnergy;
147 if (std::abs(residual) <= 2e-13 * std::max(1., std::abs(logEnergy)))
148 return t;
149 if (residual > 0)
150 left = t;
151 else
152 right = t;
153 const double proposed = t - residual / state.logEnergyDerivative;
154 t = std::isfinite(proposed) && proposed > left && proposed < right
155 ? proposed
156 : .5 * (left + right);
157 }
158 throw std::domain_error(
159 "Harmonic tail energy inversion did not converge");
160 }
HarmonicTail evaluate(const Eigen::VectorXd &q, double t, double hbar) const

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