HILA
Loading...
Searching...
No Matches
integrator.h
1#ifndef INTEGRATOR_H
2#define INTEGRATOR_H
3
4#include <sys/time.h>
5#include <ctime>
6
7/// Define the standard action term class.
8/// Action terms are used in the HMC algorithm and
9/// implement calculating the action itself and
10/// updating the underlying fields
12 public:
13 /// Calculate and return the action
14 virtual double action() { return 0; }
15
16 /// Draw any fields with a gaussian distribution,
17 /// including the momentum
18 virtual void draw_gaussian_fields() {}
19
20 /// Update the momentum with the derivative
21 /// of the action term
22 virtual void force_step(double eps) {}
23
24 /// Make a copy of fields updated in a trajectory
25 virtual void backup_fields() {}
26
27 /// Restore the previous backup
28 virtual void restore_backup() {}
29};
30
31/// Represents a sum of two action terms. Useful for adding them
32/// to the same integrator level.
33class action_sum : public action_base {
34 public:
35 /// left hand side
37 /// right hand side
39
40 /// Construct as sum of two actions
41 action_sum(action_base &_a1, action_base &_a2) : a1(_a1), a2(_a2) {}
42
43 /// Copy
44 action_sum(action_sum &asum) : a1(asum.a1), a2(asum.a2) {}
45
46 /// The action
47 double action() { return a1.action() + a2.action(); }
48
49 /// Gaussian random momentum for each element
53 }
54
55 /// Update the momentum with the gauge field
56 void force_step(double eps) {
57 a1.force_step(eps);
58 a2.force_step(eps);
59 }
60
61 /// Make a copy of fields updated in a trajectory
65 }
66
67 /// Restore the previous backup
71 }
72};
73
74/// Sum operator for creating an action_sum object
76 action_sum sum(a1, a2);
77 return sum;
78}
79
80/// A base for an integrator. An integrator updates the gauge and
81/// momentum fields in the HMC trajectory, approximately conserving
82/// the action
84 public:
85 /// Return the sum of the action terms at this integrator and
86 /// all levels below
87 virtual double action() { return 0; }
88
89 /// Refresh fields that can be drawn from a gaussian distribution
90 /// This is needed at the beginning of a trajectory
91 virtual void draw_gaussian_fields() {}
92
93 /// Make a copy of fields updated in a trajectory
94 virtual void backup_fields() {}
95
96 /// Restore the previous backup
97 virtual void restore_backup() {}
98
99 /// Update the momentum with the gauge field
100 virtual void force_step(double eps) {}
101
102 /// Run a lower level integrator step
103 virtual void step(double eps) {}
104};
105
106/// Build integrator hierarchically by adding a force step on
107/// top of an existing integrator
109 public:
110 /// The action term used to update the momentum on
111 /// this level
113 /// Lower level integrator, updates the momentum
115
116 /// Constructor from action and lower level integrator.
117 /// also works with momentum actions as long as it inherits
118 /// the integrator_base.
120 : action_term(a), lower_integrator(i) {}
121
122 /// The current total action of fields updated by this
123 /// integrator. This is kept constant up to order eps^3.
125
126 /// Refresh fields that can be drawn from a gaussian distribution
127 /// This is needed at the beginning of a trajectory
131 }
132
133 /// Make a copy of fields updated in a trajectory
137 }
138
139 /// Restore the previous backup
143 }
144
145 /// Update the momentum with the gauge field
146 void force_step(double eps) { action_term.force_step(eps); }
147
148 /// Update the gauge field with momentum
149 void momentum_step(double eps) { lower_integrator.step(eps); }
150};
151
152/// Define an integration step for a Molecular Dynamics
153/// trajectory.
155 public:
156 int n = 1;
158 : action_term_integrator(a, i), n(steps) {}
160 : action_term_integrator(a, i) {}
161
162 // Run the integrator update
163 void step(double eps) {
164 for (int i = 0; i < n; i++)
165 this->lower_integrator.step(0.5 * eps / n);
166 force_step(eps);
167 for (int i = 0; i < n; i++)
168 this->lower_integrator.step(0.5 * eps / n);
169 }
170};
171
172/// Define an integration step for a Molecular Dynamics
173/// trajectory.
175 public:
176 int n = 1;
177
178 O2_integrator(action_base &a, integrator_base &i, int steps)
179 : action_term_integrator(a, i), n(steps) {}
181
182 // Run the integrator update
183 void step(double eps) {
184 double zeta = eps * 0.1931833275037836;
185 double middlestep = eps - 2 * zeta;
186 for (int i = 0; i < n; i++) {
187 this->lower_integrator.step(zeta / n);
188 }
189 force_step(0.5 * eps);
190 for (int i = 0; i < n; i++) {
191 this->lower_integrator.step(middlestep / n);
192 }
193 force_step(0.5 * eps);
194 for (int i = 0; i < n; i++) {
195 this->lower_integrator.step(zeta / n);
196 }
197 }
198};
199
200#endif
auto operator+(const Array< n, m, A > &a, const Array< n, m, B > &b)
Addition operator.
Definition array.h:740
void step(double eps)
Run a lower level integrator step.
Definition integrator.h:183
virtual double action()
Calculate and return the action.
Definition integrator.h:14
virtual void force_step(double eps)
Definition integrator.h:22
virtual void restore_backup()
Restore the previous backup.
Definition integrator.h:28
virtual void backup_fields()
Make a copy of fields updated in a trajectory.
Definition integrator.h:25
virtual void draw_gaussian_fields()
Definition integrator.h:18
void restore_backup()
Restore the previous backup.
Definition integrator.h:68
action_base & a1
left hand side
Definition integrator.h:36
void backup_fields()
Make a copy of fields updated in a trajectory.
Definition integrator.h:62
void force_step(double eps)
Update the momentum with the gauge field.
Definition integrator.h:56
double action()
The action.
Definition integrator.h:47
action_base & a2
right hand side
Definition integrator.h:38
action_sum(action_sum &asum)
Copy.
Definition integrator.h:44
action_sum(action_base &_a1, action_base &_a2)
Construct as sum of two actions.
Definition integrator.h:41
void draw_gaussian_fields()
Gaussian random momentum for each element.
Definition integrator.h:50
integrator_base & lower_integrator
Lower level integrator, updates the momentum.
Definition integrator.h:114
void force_step(double eps)
Update the momentum with the gauge field.
Definition integrator.h:146
action_base & action_term
Definition integrator.h:112
action_term_integrator(action_base &a, integrator_base &i)
Definition integrator.h:119
void momentum_step(double eps)
Update the gauge field with momentum.
Definition integrator.h:149
void restore_backup()
Restore the previous backup.
Definition integrator.h:140
void backup_fields()
Make a copy of fields updated in a trajectory.
Definition integrator.h:134
virtual void backup_fields()
Make a copy of fields updated in a trajectory.
Definition integrator.h:94
virtual double action()
Definition integrator.h:87
virtual void force_step(double eps)
Update the momentum with the gauge field.
Definition integrator.h:100
virtual void step(double eps)
Run a lower level integrator step.
Definition integrator.h:103
virtual void restore_backup()
Restore the previous backup.
Definition integrator.h:97
virtual void draw_gaussian_fields()
Definition integrator.h:91
void step(double eps)
Run a lower level integrator step.
Definition integrator.h:163