From 1f68ed393f5f5cc9f9fe12271b646f3fdd3865a4 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 18 Feb 2021 11:18:47 +0100 Subject: Converted variation calculation to be direction-specific. --- langevin.cpp | 9 +++++++-- stokes.hpp | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/langevin.cpp b/langevin.cpp index e466860..c3f8436 100644 --- a/langevin.cpp +++ b/langevin.cpp @@ -167,7 +167,7 @@ int main(int argc, char* argv[]) { prevdist = abs(imag(H1 - H2)); εJ = 1e4 * prevdist; - if (abs(imag(H1 - H2)) < 1e-10 && dist > 1e-2) { + if (abs(imag(H1 - H2)) < 1e-13 && dist > 1e-2) { std::cerr << "Found distinct critical points with sufficiently similar Im H." << std::endl; break; } @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) { } } - Rope stokes(10, z1, z2); + Rope stokes(10, z1, z2, Jp); std::cout << stokes.cost(Jp) << " " << stokes.length() << " " << stokes.error(Jp) << std::endl; @@ -203,5 +203,10 @@ int main(int argc, char* argv[]) { std::cout << stokes.cost(Jp) << " " << stokes.length() << " " << stokes.error(Jp) << std::endl; + stokes = stokes.interpolate(); + stokes.relax(Jp, 1e5, 1e-1); + + std::cout << stokes.cost(Jp) << " " << stokes.length() << " " << stokes.error(Jp) << std::endl; + return 0; } diff --git a/stokes.hpp b/stokes.hpp index 0756dc3..3814cf4 100644 --- a/stokes.hpp +++ b/stokes.hpp @@ -22,9 +22,9 @@ Vector variation(const Vector& z, const Vector& z´, con Matrix::Identity(ddH.rows(), ddH.cols()) - z.conjugate() * z.transpose() / z² ); - Vector dLdz = - Reż·z´ * ( + Vector dLdz = - ( dżc * z´ + dż * z´.conjugate() - (dż * ż.conjugate() + dżc * ż) * Reż·z´ / ż² - ) / (ż² * z´²); + ) / sqrt(ż² * z´²) / 2; Vector ż´ = -(ddH * z´).conjugate() + ((ddH * z´).dot(z) / z²) * z.conjugate() + ( dH.dot(z) * z´.conjugate() + dH.dot(z´) * z.conjugate() - ( @@ -35,17 +35,16 @@ Vector variation(const Vector& z, const Vector& z´, con double dReż·z´ = real(ż.dot(z´´) + ż´.dot(z´)); Vector ddtdLdz´ = - ( - Reż·z´ * ( + ( ż´.conjugate() - ( Reż·z´ * z´´.conjugate() + dReż·z´ * z´.conjugate() - (Reż·z´ / z´²) * (z´´.dot(z´) + z´.dot(z´´)) * z´.conjugate() ) / z´² ) - + dReż·z´ * (ż.conjugate() - Reż·z´ / z´² * z´.conjugate()) - - Reż·z´ * ( + - 0.5 * ( (ż.dot(ż´) + ż´.dot(ż)) / ż² + (z´´.dot(z´) + z´.dot(z´´)) / z´² ) * (ż.conjugate() - Reż·z´ / z´² * z´.conjugate()) - ) / (ż² * z´²); + ) / sqrt(ż² * z´²) / 2; return dLdz - ddtdLdz´; } @@ -55,6 +54,27 @@ class Rope { public: std::vector> z; + Rope(unsigned N) : z(N + 2) {} + + template + Rope(unsigned N, const Vector& z1, const Vector& z2, const Tensor& J) : z(N + 2) { + Scalar H1, H2; + std::tie(H1, std::ignore, std::ignore) = hamGradHess(J, z1); + std::tie(H2, std::ignore, std::ignore) = hamGradHess(J, z2); + + if (real(H1) > real(H2)) { + z.front() = z1; + z.back() = z2; + } else { + z.front() = z2; + z.back() = z1; + } + + for (unsigned i = 0; i < N + 2; i++) { + z[i] = normalize(z.front() + (z.back() - z.front()) * ((double)i / (N + 1.0))); + } + } + unsigned n() const { return z.size() - 2; } @@ -89,12 +109,6 @@ class Rope { return sqrt(err); } - Rope(unsigned N, const Vector& z1, const Vector& z2) : z(N + 2) { - for (unsigned i = 0; i < N + 2; i++) { - z[i] = normalize(z1 + (z2 - z1) * ((double)i / (N + 1.0))); - } - } - Vector dz(unsigned i) const { return z[i + 1] - z[i - 1]; } @@ -208,14 +222,14 @@ class Rope { Vector zD = zDot(z[i], dH); - c += 1.0 - pow(real(zD.dot(dz(i))), 2) / zD.squaredNorm() / dz(i).squaredNorm(); + c += 1.0 - real(zD.dot(dz(i))) / zD.norm() / dz(i).norm(); } return c; } Rope interpolate() const { - Rope r(2 * n() + 1, z[0], z[z.size() - 1]); + Rope r(2 * n() + 1); for (unsigned i = 0; i < z.size(); i++) { r.z[2 * i] = z[i]; -- cgit v1.2.3-70-g09d2