-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMC_coord.hpp
60 lines (50 loc) · 2.01 KB
/
MC_coord.hpp
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
//
// MC_coord.hpp
//
//
// Created by Marton Kanasz-Nagy on 9/19/16.
//
//
// We perform our numerics on a two-dimensional lattice. There are two ways of indexing each lattice site:
// - by its (x,y) coordinates:
// (-N,N) (-N+1,-N) (-N+2,-N) ... (N-1,-N)
// ... ... ... ... ...
// ... ... ... ... ...
// (-N,-N+2) (-N+1,-N+2) (-N+2,-N+2) ... (N-1,-N+2)
// (-N,-N+1) (-N+1,-N+1) (-N+2,-N+1) ... (N-1,-N+1)
// (-N,-N) (-N+1,-N) (-N+2,-N) ... (N-1,-N)
// - a single site index, identifying the sites:
// 4N 4N+1 4N+2 4N+3 4N+4 ... 6N-1
// 2N 2N+1 2N+2 2N+3 2N+4 ... 4N-1
// 0 1 2 3 4 ... 2N-1
// where N=LATTICE_SIZE is the size of the sides of the 2D lattice
//
// The functions below simply convert the site indices between these two representations
#ifndef MC_coord_hpp
#define MC_coord_hpp
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>
#include "MC_clusterRunQ.hpp"
static const int LATTICE_SIZE = 1; // global constant
// size of the sides of the 2D lattice: x and y go from -LATTICE_SIZE to LATTICE_SIZE-1.
// we use periodic boundary conditions
// modulo function (not identical to the symbol %, which does not work properly )
inline int mod(int x, int N) {
return (x>=0) ? (x % N) : (N - 1 - ((-x-1) % N));
}
// converts x and y coordinates into site index
inline int coordToIndex(int x, int y) {
return mod(x+LATTICE_SIZE, 2*LATTICE_SIZE) + mod(y + LATTICE_SIZE,2*LATTICE_SIZE)*(2*LATTICE_SIZE);
}
// converts site index into x coordinate
inline int indexToX(int ind) {
return (mod(ind, 2*LATTICE_SIZE) - LATTICE_SIZE);
}
// converts site index into y coordinate
inline int indexToY(int ind) {
return (mod(ind/(2*LATTICE_SIZE), 2*LATTICE_SIZE) - LATTICE_SIZE);
}
#endif /* MC_coord_hpp */