-
Notifications
You must be signed in to change notification settings - Fork 0
/
lattice.c
61 lines (48 loc) · 1013 Bytes
/
lattice.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "lattice.h"
int masterLattice[100][100];
struct Lattice * initLattice(int size )
{
struct Lattice *L;
L = malloc(sizeof(struct Lattice));
L->S = size;
L->cursor = &masterLattice[0][0];// initializing the cursor
memset(masterLattice,0,sizeof(masterLattice));// clearing up master lattice.
return L;
}
void setSpinEx(bool spin, struct Lattice *L)
{
int i = 0;
if(spin) {
for(i = 0; i <= (L->S)*(L->S) -1; i++)
*(L->cursor + i) = 1;
}
else {
for(i = 0; i <= (L->S)*(L->S) -1; i++)
*(L->cursor + i) = -1;
}
}
int getMag(struct Lattice *L)
{
int i;
int M = 0;
for (i = 0; i <= (L->S)*(L->S) - 1; i++) {
M += *(L->cursor + i);
}
M = abs(M);
return M;
}
void setSpin(struct Lattice *L, int i, int j, bool spin)
{
*(L->cursor + L->S * i + j) = spin;
}
int getSpin(struct Lattice *L, int i, int j)
{
return *(L->cursor + L->S * i + j);
}
// void printLattice(struct Lattice *L)
// {
// }