2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
mcmc_progression.cpp
Go to the documentation of this file.
1
13#include "data_type.hpp"
14#include "monte_carlo.hpp"
15#include "utils.hpp"
16
17#include <getopt.h>
18#include <omp.h>
19#include <string>
20
22void usage(std::string filename)
23{
24 std::cout << "Usage: " << filename
25 << " <temperature> <lattice size> "
26 "<cycles> <burn-in-time> <output file>\n\n"
27 << "\t[ -h | --help ]\n";
28 exit(-1);
29}
30
32int main(int argc, char **argv)
33{
34 // Command options
35 struct option long_options[] = {
36 {"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
37
38 int option_index = -1;
39 int c;
40
41 while (true) {
42 c = getopt_long(argc, argv, "h", long_options, &option_index);
43
44 if (c == -1)
45 break;
46
47 switch (c) {
48 case 0:
49 switch (option_index) {
50 case 0: // Not a mistake. This just goes to the default.
51 default:
52 usage(argv[0]);
53 }
54 break;
55 case 'h':
56 default:
57 usage(argv[0]);
58 }
59 }
60 // Check that the number of arguments is at least 6.
61 if (argc < 6) {
62 usage(argv[0]);
63 }
64
65 bool ordered = false;
66
67 if (argc == 7) {
68 ordered = true;
69 }
70
71 // Timing variables
72 double t0, t1;
73 t0 = omp_get_wtime();
74
75 // Define/initialize variables
76 double temp = atoi(argv[1]);
77 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
78 std::string outfile = argv[5];
79
80 if (ordered) {
81 DEBUG("Hello");
82 montecarlo::progression(temp, L, cycles, 1, outfile, burn_in_time);
83 }
84 else {
85 montecarlo::progression(temp, L, cycles, outfile, burn_in_time);
86 }
87
88 t1 = omp_get_wtime();
89
90 std::cout << "Time: " << t1 - t0 << " seconds\n";
91}
Header for the data_t type.
void usage(std::string filename)
A function that displays how to use the program and quits.
Functions for Monte Carlo simulations.
int main()
The main function.
Definition: test_suite.cpp:110
Function prototypes and macros that are useful.
#define DEBUG(msg)
Writes a debug message.
Definition: utils.hpp:39