-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmaction.hh
217 lines (192 loc) · 6.65 KB
/
qmaction.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifndef QMACTION_HH
#define QMACTION_HH QMACTION_HH
#include "action/action.hh"
#include "action/renormalisation.hh"
#include "common/parameters.hh"
#include "common/samplestate.hh"
#include "lattice/lattice1d.hh"
#include "mpi/mpi_wrapper.hh"
#include <string>
/** @file qmaction.hh
* @brief Header file for quantum mechanical action base class
*/
/** @brief Enum for different actions
* - 0: Harmonic Oscillator
* - 1: Quartic Oscillator
* - 2: Quantum mechanical rotor
*/
enum ActionType {
ActionHarmonicOscillator = 0,
ActionQuarticOscillator = 1,
ActionRotor = 2
};
/** @class QMParameters
*
* @brief Class for storing general quantum mechanics parameter
*
*/
class QMParameters : public Parameters {
public:
/** @brief Construct a new instance */
QMParameters()
: Parameters("quantummechanics"), action_(ActionHarmonicOscillator) {
addKey("action", String);
}
/** @brief Read parameters from file
*
* @param[in] filename Name of file to read
*/
int readFile(const std::string filename) {
int readSuccess = Parameters::readFile(filename);
if (!readSuccess) {
std::string action_str = getContents("action")->getString();
if (action_str == "harmonicoscillator") {
action_ = ActionHarmonicOscillator;
} else if (action_str == "quarticoscillator") {
action_ = ActionQuarticOscillator;
} else if (action_str == "rotor") {
action_ = ActionRotor;
} else {
}
}
return readSuccess;
}
/** @brief Return the action type */
ActionType action() const { return action_; }
private:
/** @brief Type of action */
ActionType action_;
};
/** @class QMAction
*
* @brief Base class for quantum mechanical actions
*
* Allows calculation of action
* \f[
S[X]=\sum_{j=0}^{M-1}\left(\frac{m_0}{2}\frac{(X_{j+1}-X_j)}{a^2}+V(x)\right)
\f]
* for one-dimensional quantum problem with periodic boundary conditions.
*/
class QMAction : public Action {
public:
/** @brief Initialise class
*
*
* @param[in] lattice_ Underlying lattice
* @param[in] renormalisation_ Type of renormalisation
* @param[in] m0_ Mass of particle \f$m_0\f$
*/
QMAction(const std::shared_ptr<Lattice1D> lattice_,
const RenormalisationType renormalisation_, const double m0_)
: Action(renormalisation_), lattice(lattice_),
M_lat(std::dynamic_pointer_cast<Lattice1D>(lattice_)->getM_lat()),
a_lat(std::dynamic_pointer_cast<Lattice1D>(lattice_)->geta_lat()),
T_final(std::dynamic_pointer_cast<Lattice1D>(lattice_)->getT_final()),
m0(m0_) {
assert(m0 > 0.0);
}
/** @brief return size of samples */
virtual unsigned int sample_size() const { return M_lat; }
/** @brief Return mass \f$m_0\f$ */
double getm0() const { return m0; }
/** @brief Cost of one action evaluation */
virtual double evaluation_cost() const { return lattice->getM_lat(); }
/** @brief Get coarsening level
*
* This will return the coarsening level of the underlying lattice */
virtual int get_coarsening_level() { return lattice->get_coarsening_level(); }
/** @brief Get underlying lattice */
std::shared_ptr<Lattice1D> get_lattice() { return lattice; }
/** @brief Evaluate action for a specific path
*
* Calculate \f$S[X]\f$ for a specific path
*
* @param[in] x_path Path, has to be an array of length \f$M\f$
*/
virtual const double
evaluate(const std::shared_ptr<SampleState> x_path) const = 0;
/** @brief Calculate force for HMC integrator for a specific path
*
* Calculate \f$P = \frac{\partial S[X]}{\partial X}\f$ for a specific
* path and return the resulting force as a path.
*
* @param[in] x_path Path \f$X\f$ on which to evaluate the force
* @param[out] p_path Resulting force \f$P\f$ at every point
*
*/
virtual void force(const std::shared_ptr<SampleState> x_path,
std::shared_ptr<SampleState> p_path) const = 0;
/** @brief Initialise path
*
* Set initial values of path, those values will be used to start the
* sampling process
*
* @param[out] x_path Path \f$X\f$ to be set
*/
virtual void initialise_state(std::shared_ptr<SampleState> x_path) const = 0;
/** @brief Second derivative \f$W''_{x_-,x_+}(x)\f$ of conditioned
* action at its minimum.
*
* The second derivative (=curvature) of the conditioned action
* \f$W_{x_-,x_+}(x)=S(\dots,x_-,x,x_+,\dots)\f$ at its minimum. In the
* special case of a Lagrangian of the form \f$\frac{m_0}{2}\dot{x}^2+V(x)\f$
* this becomes
\f[
W_{\overline{x}}(x)=\frac{m_0}{2a}\left((x-x_+)^2+(x-x_-)^2\right)+aV(x)
\f]
* where \f$\overline{x}=\frac{x_++x_-}{2}\f$.
* This quantity is required for sampling of the fine lattice sites.
*
* @param[in] x_m Value of \f$x_-\f$
* @param[in] x_p Value of \f$x_+\f$
*/
double virtual inline getWcurvature(const double x_m,
const double x_p) const = 0;
/** @brief Find minimum of conditioned action \f$W_{x_-,x_+}(x)\f$
*
* Given \f$x_-\f$ and \f$x_+\f$, find the minimum \f$x_0\f$
* of the conditioned action \f$W_{\overline{x}}(x)\f$
*
* @param[in] x_m Value of \f$x_-\f$
* @param[in] x_p Value of \f$x_+\f$
*/
double virtual inline getWminimum(const double x_m,
const double x_p) const = 0;
/** @brief Copy coarse data points from sample on coarser level
*
* @param[in] x_coarse Coarse sample to copy from
* @param[in] x_path Fine path to copy to (same level as action)
*/
virtual void copy_from_coarse(const std::shared_ptr<SampleState> x_coarse,
std::shared_ptr<SampleState> x_path);
/** @brief Copy coarse data points from path on finer level
*
* @param[in] x_fine Fine path to copy from
* @param[in] x_path Coarse path to copy to (same level as action)
*/
virtual void copy_from_fine(const std::shared_ptr<SampleState> x_fine,
std::shared_ptr<SampleState> x_path);
/** @brief Get coarsening level
*
* This will return the coarsening level of the underlying lattice */
virtual int get_coarsening_level() const {
return lattice->get_coarsening_level();
}
/** @brief Action information string
*
* return some information on this instance of the action
*/
virtual std::string info_string() const;
protected:
/** @brief Underlying lattice */
const std::shared_ptr<Lattice1D> lattice;
/** @brief Number of lattice points */
const unsigned int M_lat;
/** @brief Lattice spacing */
const double a_lat;
/** @brief Physical lattice size */
const double T_final;
/** @brief Particle mass */
const double m0;
};
#endif // QMACTION_HH