Loading...
Searching...
No Matches
PathIntegral.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** i-PI Copyright (C) 2014-2015 i-PI developers
5**
6** Permission is hereby granted, free of charge, to any person obtaining
7** a copy of this software and associated documentation files (the
8** "Software"), to deal in the Software without restriction, including
9** without limitation the rights to use, copy, modify, merge, publish,
10** distribute, sublicense, and/or sell copies of the Software, and to
11** permit persons to whom the Software is furnished to do so, subject to
12** the following conditions:
13**
14** The above copyright notice and this permission notice shall be
15** included in all copies or substantial portions of the Software.
16**
17** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24** SOFTWARE.
25**
26** SPDX-License-Identifier: MIT
27*/
28#pragma once
29
30#include "eon/Eigen.h"
31#include "eon/Potential.h"
32
33#include <cstdint>
34#include <string>
35#include <vector>
36
37namespace eonc::pathintegral {
38
42enum class Springs { Trotter, Eco };
43
46enum class Thermostat { Pile, Piglet };
47
48struct Options {
49 long beads{8};
50 double temperature{1.0};
51 double kB{1.0};
52 double hbar{1.0};
53 double dt{0.005};
57 double pileTau{0.2};
59 double pileScale{1.0};
61 double ecoOmegaMax{0.0};
64 std::string gleFile;
65 std::uint64_t seed{1};
66};
67
68struct Sample {
69 double kineticCv{0.0};
72 double meanForce{0.0};
73 long batches{0};
74};
75
78void requireTrotterSprings(const std::string &springs, const char *use);
79
83VectorXd trotterEigenvalues(long nBeads);
84VectorXd ecoEigenvalues(long nBeads, double xmax);
85
87MatrixXd normalModeMatrix(long nBeads);
88
93public:
94 RingPolymer(long nAtoms, std::vector<double> masses,
95 std::vector<int> atomicNumbers, std::vector<char> free,
96 Options opt);
97
98 void setAllBeads(const double *q);
101 void setBeads(const std::vector<VectorXd> &beads);
102 [[nodiscard]] const std::vector<VectorXd> &beads() const { return q_; }
103 [[nodiscard]] const std::vector<VectorXd> &momenta() const { return p_; }
106 void setMomenta(const std::vector<VectorXd> &momenta);
107 void thermalMomenta();
108
111 void setHyperplane(const VectorXd &normal, const VectorXd &origin);
112
113 void step(Potential &pot, const double *box, bool record);
116 void nveStep(Potential &pot, const double *box);
117
118 [[nodiscard]] double kineticCv() const;
119 [[nodiscard]] double meanForce() const;
120 [[nodiscard]] long batches() const { return batches_; }
121 [[nodiscard]] VectorXd centroid() const;
122 [[nodiscard]] VectorXd centroidVelocity() const;
123
124 void resetAverages();
125
126 Sample sample(Potential &pot, const double *box, long equilibration,
127 long production);
128
129private:
130 void forces(Potential &pot, const double *box);
131 void thermostat(double h);
132 void kick(double h, bool dropParallel);
133 void propagate(double h);
134 void projectPosition();
135 void projectMomentum();
136 void toNormal(const std::vector<VectorXd> &src,
137 std::vector<VectorXd> &dst) const;
138 void fromNormal(const std::vector<VectorXd> &src,
139 std::vector<VectorXd> &dst) const;
140 double gauss();
141 void initGle();
142
144 long nAtoms_{0};
145 long nDof_{0};
146 long nBeads_{0};
147 long nFree_{0};
148 std::vector<double> mass_;
149 std::vector<int> atomicNumbers_;
150 std::vector<char> free_;
151 std::vector<long> freeIndex_;
153 VectorXd omegaK_;
154 std::vector<VectorXd> q_;
155 std::vector<VectorXd> p_;
156 std::vector<VectorXd> f_;
157 std::vector<VectorXd> qnm_;
158 std::vector<VectorXd> pnm_;
159 VectorXd planeNormal_;
160 VectorXd planeOrigin_;
161 bool constrain_{false};
162 bool haveForces_{false};
163
171 std::vector<ModeGle> gle_;
172
173 std::uint64_t rng_;
174 long batches_{0};
175 long recorded_{0};
176 double kineticSum_{0.0};
177 double forceSum_{0.0};
178};
179
180} // namespace eonc::pathintegral
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition Eigen.h:33
std::vector< int > atomicNumbers_
void setAllBeads(const double *q)
std::vector< long > freeIndex_
std::vector< VectorXd > pnm_
std::vector< ModeGle > gle_
std::vector< double > mass_
std::vector< VectorXd > f_
void setMomenta(const std::vector< VectorXd > &momenta)
One momentum vector of length 3 * nAtoms per bead; fixed coordinates are zeroed.
void nveStep(Potential &pot, const double *box)
Thermostat-free RPMD step: velocity Verlet with the free ring propagated exactly in normal modes.
RingPolymer(long nAtoms, std::vector< double > masses, std::vector< int > atomicNumbers, std::vector< char > free, Options opt)
Sample sample(Potential &pot, const double *box, long equilibration, long production)
void toNormal(const std::vector< VectorXd > &src, std::vector< VectorXd > &dst) const
void setBeads(const std::vector< VectorXd > &beads)
One position vector of length 3 * nAtoms per bead.
std::vector< VectorXd > p_
void forces(Potential &pot, const double *box)
void setHyperplane(const VectorXd &normal, const VectorXd &origin)
Hold n · (q_centroid - origin) = 0.
std::vector< VectorXd > q_
void kick(double h, bool dropParallel)
void step(Potential &pot, const double *box, bool record)
const std::vector< VectorXd > & momenta() const
void fromNormal(const std::vector< VectorXd > &src, std::vector< VectorXd > &dst) const
const std::vector< VectorXd > & beads() const
std::vector< VectorXd > qnm_
MatrixXd normalModeMatrix(long nBeads)
Orthogonal bead-to-normal-mode matrix. Row k is mode k.
VectorXd trotterEigenvalues(long nBeads)
Dimensionless free-ring eigenvalues, mode 0 equal to 0.
void requireTrotterSprings(const std::string &springs, const char *use)
Economised springs and a normal-mode GLE are refused.
Springs
Trotter springs, or economised springs fitted to harmonic radii of gyration up to a maximum frequency...
VectorXd ecoEigenvalues(long nBeads, double xmax)
Thermostat
PILE-L, or a normal-mode GLE on the internal modes with a separate Langevin thermostat on the centroi...
double ecoOmegaMax
Highest physical frequency the economised springs reproduce.
std::string gleFile
Normal-mode GLE matrices.
double pileScale
Scales the critical PILE damping of the internal modes.
double pileTau
Centroid Langevin time, in the same time unit as dt.
double meanForce
Average of n · f_centroid.