Loading...
Searching...
No Matches
ZeroEnergyGeodesic.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <algorithm>
8#include <cmath>
9#include <functional>
10#include <string>
11
12#include "PotentialPath.h"
13
14namespace gpr::quantum {
15// Coordinates belong to a continuous mass-weighted chart. This samples its
16// polyline by arclength and returns geometry only; values need reevaluation.
17inline std::vector<Eigen::VectorXd> regridGeodesicPath(
18 const std::vector<Eigen::VectorXd>& path,
19 const std::vector<double>& weights = {})
20{
21 if (path.size() < 2 || path.front().size() < 1)
22 throw std::invalid_argument(
23 "A nonempty geodesic chart with two endpoints is required");
24 const auto count = weights.empty() ? path.size() : weights.size() + 1;
25 std::vector<double> arc(path.size(), 0), fraction(count, 0);
26 for (std::size_t j = 0; j < path.size(); ++j) {
27 if (path[j].size() != path.front().size() || !path[j].allFinite())
28 throw std::invalid_argument(
29 "Finite matching geodesic chart coordinates required");
30 if (j) {
31 const double length = (path[j] - path[j - 1]).norm();
32 if (!(length > 0) || !std::isfinite(length))
33 throw std::invalid_argument(
34 "Distinct finite geodesic chart nodes required");
35 arc[j] = arc[j - 1] + length;
36 }
37 }
38 if (!std::isfinite(arc.back()))
39 throw std::invalid_argument("Finite geodesic arclength required");
40 double scale = 1.;
41 if (!weights.empty())
42 scale = *std::max_element(weights.begin(), weights.end());
43 for (std::size_t j = 1; j < count; ++j) {
44 const double weight = weights.empty() ? 1. : weights[j - 1];
45 if (!(weight > 0) || !std::isfinite(weight))
46 throw std::invalid_argument(
47 "Positive finite geodesic sampling weights required");
48 fraction[j] = fraction[j - 1] + weight / scale;
49 if (!(fraction[j] > fraction[j - 1]) || !std::isfinite(fraction[j]))
50 throw std::invalid_argument(
51 "Resolved positive geodesic sampling fractions required");
52 }
53 std::vector<Eigen::VectorXd> result(count);
54 result.front() = path.front();
55 result.back() = path.back();
56 for (std::size_t j = 1; j + 1 < count; ++j) {
57 const double target = arc.back() * (fraction[j] / fraction.back());
58 const auto upper = std::upper_bound(arc.begin(), arc.end(), target);
59 const auto right = std::min(
60 path.size() - 1, static_cast<std::size_t>(upper - arc.begin()));
61 const auto left = right - 1;
62 const double t = (target - arc[left]) / (arc[right] - arc[left]);
63 result[j] = (1 - t) * path[left] + t * path[right];
64 }
65 return result;
66}
74// The positive well root maps a mass displacement to its harmonic tail
75// momentum. Native energies are relative to that well's minimum; only the outer
76// endpoint may lie outside the forbidden region during the search.
78 const Eigen::MatrixXd& positiveWellRoot, double radius,
79 const std::vector<Eigen::VectorXd>& path,
80 const std::vector<PotentialEvaluation>& native, double meshStiffness = 1.,
81 const std::vector<Eigen::MatrixXd>& searchHessians = {});
82// Positive link weights prescribe a graded spatial mesh. The tangent and
83// curvature use derivatives in this mesh parameter, including its speed.
85 const Eigen::MatrixXd& positiveWellRoot, double radius,
86 const std::vector<Eigen::VectorXd>& path,
87 const std::vector<PotentialEvaluation>& native, double meshStiffness,
88 const std::vector<Eigen::MatrixXd>& searchHessians,
89 const std::vector<double>& meshWeights);
90std::vector<Eigen::VectorXd> solveZeroEnergyGeodesicStep(
91 const ZeroEnergyGeodesicEvaluation& state);
93 double forceTolerance{1e-6}, momentumTolerance{1e-8},
95 double maximumStep{.1}, meshStiffness{1.};
97 std::vector<double> meshWeights{};
99};
110 std::function<std::vector<PotentialEvaluation>(
111 const std::vector<Eigen::VectorXd>&)>
113 std::function<std::vector<Eigen::MatrixXd>(
114 const std::vector<Eigen::VectorXd>&)>
116 // A surrogate supplies a target path from this owned native state. Empty
117 // requests the native Newton step. Every nonempty proposal passes the same
118 // native residual and turning-orientation checks as that Newton step.
119 std::function<std::vector<Eigen::VectorXd>(const ZeroEnergyGeodesicResult&)>
121};
123 const Eigen::MatrixXd& positiveWellRoot, double radius,
124 const std::vector<Eigen::VectorXd>& initial,
125 const ZeroEnergyGeodesicPotential& potential,
126 const ZeroEnergyGeodesicOptions& options = {},
127 const std::function<void(const ZeroEnergyGeodesicResult&)>& retain = {});
128} // namespace gpr::quantum
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
std::vector< Eigen::VectorXd > regridGeodesicPath(const std::vector< Eigen::VectorXd > &path, const std::vector< double > &weights={})
ZeroEnergyGeodesicResult optimizeZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &initial, const ZeroEnergyGeodesicPotential &potential, const ZeroEnergyGeodesicOptions &options, const std::function< void(const ZeroEnergyGeodesicResult &)> &retain)
std::vector< V > solveZeroEnergyGeodesicStep(const ZeroEnergyGeodesicEvaluation &state)
ZeroEnergyGeodesicEvaluation evaluateZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &path, const std::vector< PotentialEvaluation > &native, double stiffness, const std::vector< M > &hessians)
std::vector< Eigen::MatrixXd > diagonal
std::vector< Eigen::VectorXd > residual
std::function< std::vector< Eigen::MatrixXd >(const std::vector< Eigen::VectorXd > &)> searchHessians
std::function< std::vector< PotentialEvaluation >(const std::vector< Eigen::VectorXd > &)> evaluate
std::function< std::vector< Eigen::VectorXd >(const ZeroEnergyGeodesicResult &)> propose
std::vector< PotentialEvaluation > native
std::vector< Eigen::VectorXd > path
ZeroEnergyGeodesicEvaluation evaluation