forked from s9w/magneto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
physics.cpp
32 lines (26 loc) · 825 Bytes
/
physics.cpp
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
#include "physics.h"
double calc_E(std::vector<std::vector<int> > &grid) {
unsigned int L = grid.size();
double E = 0.0;
for(int i = 0; i < L; ++i){
for (int j = 0; j < L; ++j)
E += -grid[i][j] * ( grid[i][(j+1)%L] + grid[(i+1)%L][j] );
}
return E/(L*L);
}
int calc_dE(std::vector<std::vector<int> >& grid, int idx1, int idx2, const int L) {
return 2 * grid[idx1][idx2] * (
grid[idx1][(idx2 + 1) % L] +
grid[(idx1 + 1) % L][idx2] +
grid[idx1][(idx2 - 1 + L) % L] +
grid[(idx1 - 1 + L) % L][idx2]);
}
double calc_m_abs(std::vector<std::vector<int> >& grid) {
unsigned int L = grid.size();
int m = 0;
for (int i = 0; i < L; ++i){
for (int j = 0; j < L; ++j)
m += grid[i][j];
}
return abs(m)*1.0f/(L*L);
}