Loading...
Searching...
No Matches
ThermalGeodesicSeed.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <algorithm>
8#include <limits>
9
10#include "ThermalJacobiPeriod.h"
11
12namespace gpr::quantum {
13// Coordinates sample a harmonic dwell joined to the measured spatial arc.
14// Interpolated points carry no assertion of native stationarity or forces.
16 using V = Eigen::VectorXd;
17 using M = Eigen::MatrixXd;
18 M modes_;
19 V frequencies_, modalCut_;
20 std::vector<V> path_;
21 std::vector<double> energies_, times_;
23 double period_{};
24
25 static double logCosh(double x)
26 {
27 return x + std::log1p(std::exp(-2 * x)) - std::log(2.);
28 }
29
30public:
31 ThermalGeodesicSeed(const M& well, const std::vector<V>& path,
32 const std::vector<PotentialEvaluation>& values,
33 double period, double hbar)
34 : path_(path), period_(period)
35 {
36 match_ = matchThermalJacobiPeriod(well, path, values, period, hbar);
37 Eigen::SelfAdjointEigenSolver<M> eigen(well);
38 if (eigen.info() != Eigen::Success ||
39 eigen.eigenvalues().minCoeff() <= 0)
40 throw std::invalid_argument("Positive thermal seed well required");
41 modes_ = eigen.eigenvectors();
42 frequencies_ = eigen.eigenvalues().cwiseSqrt();
43 modalCut_ = modes_.transpose() * path.front();
44 path_.back() = match_.outerTurningPoint;
45 for (const auto& value: values)
46 energies_.push_back(value.energy);
47 energies_.back() = match_.energy;
48 double duration = 0.;
49 for (std::size_t j = 0; j + 1 < path_.size(); ++j) {
50 const double a = energies_[j] - match_.energy;
51 const double b = energies_[j + 1] - match_.energy;
52 const double length = (path_[j + 1] - path_[j]).norm();
53 if (!(a > 0) || !(b >= 0) || !(length > 0) ||
54 !std::isfinite(length))
55 throw std::domain_error("Resolved thermal seed arc required");
56 const double time =
57 std::sqrt(2.) * length / (std::sqrt(a) + std::sqrt(b));
58 if (!(time > 0) || !std::isfinite(time))
59 throw std::domain_error(
60 "Finite thermal seed traversal time required");
61 times_.push_back(time);
62 duration += time;
63 }
64 if (std::abs(2 * (match_.tailHalfDuration + duration) - period_) >
65 1e-10 * std::max(1., period_))
66 throw std::runtime_error(
67 "Thermal seed traversal does not match its period");
68 }
69
71 {
72 return match_;
73 }
74
75 V at(double time) const
76 {
77 if (!std::isfinite(time) || time < 0 || time > period_)
78 throw std::invalid_argument(
79 "Thermal seed time must lie in one period");
80 time = std::min(time, period_ - time);
81 if (time >= .5 * period_) return path_.back();
82 if (time <= match_.tailHalfDuration) {
83 V modal(modalCut_.size());
84 for (Eigen::Index j = 0; j < modal.size(); ++j)
85 modal[j] =
86 modalCut_[j] * std::exp(logCosh(frequencies_[j] * time) -
87 logCosh(frequencies_[j] *
88 match_.tailHalfDuration));
89 return modes_ * modal;
90 }
91 time -= match_.tailHalfDuration;
92 for (std::size_t j = 0; j < times_.size(); ++j) {
93 if (time > times_[j] && j + 1 < times_.size()) {
94 time -= times_[j];
95 continue;
96 }
97 const double length = (path_[j + 1] - path_[j]).norm();
98 const double scaledTime = std::clamp(time, 0., times_[j]) / length;
99 const double fraction =
100 scaledTime *
101 (std::sqrt(2 * (energies_[j] - match_.energy)) +
102 .5 * (energies_[j + 1] - energies_[j]) * scaledTime);
103 if (!std::isfinite(fraction) || fraction < -1e-12 ||
104 fraction > 1 + 1e-12)
105 throw std::runtime_error(
106 "Thermal seed interpolation leaves its link");
107 return path_[j] +
108 std::clamp(fraction, 0., 1.) * (path_[j + 1] - path_[j]);
109 }
110 throw std::runtime_error("Thermal seed arc has no containing link");
111 }
112
113 std::vector<V> ring(std::size_t beads) const
114 {
115 if (beads < 4)
116 throw std::invalid_argument(
117 "At least four thermal seed beads required");
118 std::vector<V> result(beads);
119 result[0] = at(0.);
120 for (std::size_t j = 1; j <= beads / 2; ++j) {
121 result[j] = at(period_ * (double(j) / beads));
122 result[beads - j] = result[j];
123 }
124 return result;
125 }
126};
127} // namespace gpr::quantum
@ x
Definition Enums.h:28
const ThermalJacobiPeriod & matching() const
std::vector< V > ring(std::size_t beads) const
ThermalGeodesicSeed(const M &well, const std::vector< V > &path, const std::vector< PotentialEvaluation > &values, double period, double hbar)
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
ThermalJacobiPeriod matchThermalJacobiPeriod(const Eigen::MatrixXd &well, const std::vector< Eigen::VectorXd > &path, const std::vector< PotentialEvaluation > &native, double thermalPeriod, double hbar)