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
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
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}
Header for the data_t type.
Functions for Monte Carlo simulations.
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: pd_estimate.cpp:22
int main()
The main function.
Definition: test_suite.cpp:110
Function prototypes and macros that are useful.