2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
pd_estimate.cpp
Go to the documentation of this file.
1/** @file pd_estimate.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 cycles.
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
32 *
33 * */
34int main(int argc, char **argv)
35{
36 // Command options
37 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
38
39 int option_index = -1;
40 int c;
41
42 while (true) {
43 c = getopt_long(argc, argv, "h", long_options, &option_index);
44
45 if (c == -1)
46 break;
47
48 switch (c) {
49 case 0:
50 switch (option_index) {
51 case 0: // Not a mistake. This just goes to the default.
52 default:
53 usage(argv[0]);
54 }
55 break;
56 case 'h':
57 default:
58 usage(argv[0]);
59 }
60 }
61 // Check that the number of arguments is at least 8.
62 if (argc < 6) {
63 usage(argv[0]);
64 }
65
66 // Timing variables
67 double t0, t1;
68 t0 = omp_get_wtime();
69
70 // Define/initialize variables
71 double temp = atoi(argv[1]);
72 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
73 std::string outfile = argv[5];
74
75 montecarlo::pd_estimate(temp, L, cycles, outfile, burn_in_time);
76
77 t1 = omp_get_wtime();
78
79 std::cout << "Time: " << t1 - t0 << " seconds\n";
80}
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
void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:91