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/** @file mcmc_progression.cpp
2 *
3 * @author Cory Alexander Balaton (coryab)
4 * @author Janita Ovidie Sandtrøen Willumsen (janitaws)
5 *
6 * @version 1.0
7 *
8 * @brief Execute the mcmc algorithm and write data to file after each
9 * Monte Carlo cycle.
10 *
11 * @bug No known bugs
12 * */
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
21/** @brief A function that displays how to use the program and quits.*/
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
31/** @brief The main function.*/
32int main(int argc, char **argv)
33{
34 // Command options
35 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
36
37 int option_index = -1;
38 int c;
39
40 while (true) {
41 c = getopt_long(argc, argv, "h", long_options, &option_index);
42
43 if (c == -1)
44 break;
45
46 switch (c) {
47 case 0:
48 switch (option_index) {
49 case 0: // Not a mistake. This just goes to the default.
50 default:
51 usage(argv[0]);
52 }
53 break;
54 case 'h':
55 default:
56 usage(argv[0]);
57 }
58 }
59 // Check that the number of arguments is at least 8.
60 if (argc < 6) {
61 usage(argv[0]);
62 }
63
64 // Timing variables
65 double t0, t1;
66 t0 = omp_get_wtime();
67
68 // Define/initialize variables
69 double temp = atoi(argv[1]);
70 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
71 std::string outfile = argv[5];
72
73 montecarlo::progression(temp, L, cycles, outfile, burn_in_time);
74
75 t1 = omp_get_wtime();
76
77 std::cout << "Time: " << t1 - t0 << " seconds\n";
78}
int main(int argc, char **argv)
The main function.
Definition: main.cpp:125
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110