-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIsingMetropolis.cpp
More file actions
78 lines (66 loc) · 1.58 KB
/
Copy pathIsingMetropolis.cpp
File metadata and controls
78 lines (66 loc) · 1.58 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "IsingMetropolis.h"
#include <omp.h>
#include <cstdlib>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "common.h"
using namespace std;
// ---------- template function --------
double isingLoop(MetropolisStrategy* ms, int running, const double beta, double *flipRate)
{
//srand(1); // init seed, 1 for determinism
//int running = 1e3;
int measure = running/10; // Messung alle x flips
int i = 0;
bool random = true;
double M;
int flips = 0;
//omp_set_num_threads(0);
//#pragma omp parallel for
for (int n = 0; n <= running; n++)
{
if (random)
{
// 1. Pick random element
i = rand() % ms->spinNumber();
}
else
{
// Ein Element nach dem anderen
i++;
if (i >= ms->spinNumber())
i = 0;
}
// 2. calc the Energy
// dE = E_new - E_old;
double dE = ms->calculate_dE(i);
double W = dE > 0.0 ? exp(-beta*dE) : 1.0;
if(W >= 1.0 || drand() < W)
{
// accept
ms->flipSpin(i);
flips++;
}
else
{
// reject, do nothing
}
//running--;
// 3. Do Measure
// ...
// die Messungen aufzeichenen und am ende ergebnis zurückliefern, daher ist void wohl nicht die beste wahl....
ms->addProbability(i);
// if (n % measure == 0)
// {
// M = ms->measure();
//
// //cout << " Magnetisierung: " << M << "\n";
// }
}
M = ms->measure();
//double
*flipRate = flips / ((double) running);
return M;
}