32 const std::vector<PotentialEvaluation>& values,
33 double period,
double hbar)
34 : path_(path), period_(period)
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;
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");
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);
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");
75 V
at(
double time)
const
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)
86 modalCut_[j] * std::exp(logCosh(frequencies_[j] * time) -
87 logCosh(frequencies_[j] *
88 match_.tailHalfDuration));
89 return modes_ * modal;
91 time -= match_.tailHalfDuration;
92 for (std::size_t j = 0; j < times_.size(); ++j) {
93 if (time > times_[j] && j + 1 < times_.size()) {
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 =
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");
108 std::clamp(fraction, 0., 1.) * (path_[j + 1] - path_[j]);
110 throw std::runtime_error(
"Thermal seed arc has no containing link");