HILA
Loading...
Searching...
No Matches
xy.cpp
1#include <sstream>
2#include <iostream>
3#include <string>
4#include <math.h>
5
6#define NDIM 2
7
8// Include the lattice field definition
9#include "plumbing/field.h"
10
11// Define some parameters for the simulation
12double beta = 0.1;
13int n_measurements = 100;
14int n_updates_per_measurement = 10;
15long seed = 123456;
16CoordinateVector nd = {64, 64};
17int VOLUME = nd[0] * nd[1];
18
19int main(int argc, char **argv) {
20
21 // Basic setup
22 hila::initialize(argc, argv);
23 lattice.setup(nd);
24 // Define a field
25 Field<double> spin;
26
28
29 // Set to 1
30 spin[ALL] = 0;
31
32 // Run update-measure loop
33 for (int i = 0; i < n_measurements; i++) {
34
35 // Run a number of updates, starting with EVEN sites
36 // and alternating between parities
37 Parity p = EVEN;
38 for (int j = 0; j < 2 * n_updates_per_measurement; j++) {
39 onsites(p) {
40 double deltaS;
41 double tspin = spin[X];
42 double tnspin = tspin + M_PI * (1. - 2. * hila::random());
43 deltaS = cos(spin[X + e_x] - tspin) + cos(spin[X - e_x] - tspin) +
44 cos(spin[X + e_y] - tspin) + cos(spin[X - e_y] - tspin);
45 deltaS -= cos(spin[X + e_x] - tnspin) + cos(spin[X - e_x] - tnspin) +
46 cos(spin[X + e_y] - tnspin) + cos(spin[X - e_y] - tnspin);
47
48 if (deltaS < 0 || hila::random() < exp(-beta * deltaS)) {
49 if (tnspin < -M_PI) {
50 tnspin += 2.0 * M_PI;
51 } else if (tnspin > M_PI) {
52 tnspin -= 2.0 * M_PI;
53 }
54 spin[X] = tnspin;
55 }
56 }
57 if (hila::random() < 0.5) {
58 p = opp_parity(p);
59 }
60 }
61
62 // Measure magnetisation
63 double M = 0;
64 onsites(ALL) { M += cos(spin[X]); }
65 hila::out0 << "Magnetisation " << M / VOLUME << "\n";
66 }
67
69 return 0;
70}
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
Definition array.h:1059
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
Definition array.h:1089
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
void setup(const CoordinateVector &siz)
General lattice setup.
Definition lattice.cpp:33
Parity
Parity enum with values EVEN, ODD, ALL; refers to parity of the site. Parity of site (x,...
constexpr Parity EVEN
bit pattern: 001
constexpr Parity ALL
bit pattern: 011
This files containts definitions for the Field class and the classes required to define it such as fi...
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:121
std::ostream out0
This writes output only from main process (node 0)
void initialize(int argc, char **argv)
Read in command line arguments. Initialise default stream and MPI communication.
void seed_random(uint64_t seed, bool device_rng=true)
Seed random generators with 64-bit unsigned value. On MPI shuffles the seed so that different MPI ran...
Definition random.cpp:86
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...