2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
phase_transition.cpp
Go to the documentation of this file.
1
16#include "data_type.hpp"
17#include "monte_carlo.hpp"
18#include "utils.hpp"
19
20#include <getopt.h>
21#include <omp.h>
22#include <string>
23
25void usage(std::string filename)
26{
27 std::cout << "Usage: " << filename
28 << " <start temperature> <end temperature> <points> "
29 "<lattice size> <cycles> <burn-in-time> <output file>\n\n"
30 << "\t[ -h | --help ]\n";
31 exit(-1);
32}
33
35int main(int argc, char **argv)
36{
37 // Command options
38 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
39
40 int option_index = -1;
41 int c;
42
43 while (true) {
44 c = getopt_long(argc, argv, "h", long_options, &option_index);
45
46 if (c == -1)
47 break;
48
49 switch (c) {
50 case 0:
51 switch (option_index) {
52 case 0: // Not a mistake. This just goes to the default.
53 default:
54 usage(argv[0]);
55 }
56 break;
57 case 'h':
58 default:
59 usage(argv[0]);
60 }
61 }
62 // Check that the number of arguments is at least 8.
63 if (argc < 8) {
64 usage(argv[0]);
65 }
66
67 // Timing variables
68 double t0, t1;
69 t0 = omp_get_wtime();
70
71 // Define/initialize variables
72 double start = atof(argv[1]), end = atof(argv[2]);
73 int points = atoi(argv[3]), cycles = atoi(argv[5]), L = atoi(argv[4]),
74 burn_in_time = atoi(argv[6]), N = L * L;
75 std::string outfile = argv[7];
76
77 montecarlo::phase_transition(L, start, end, points, cycles,
78 montecarlo::mcmc_parallel, outfile, burn_in_time);
79
80 t1 = omp_get_wtime();
81
82 std::cout << "Time: " << t1 - t0 << " seconds\n";
83}
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.
int main()
The main function.
Definition: test_suite.cpp:110
Function prototypes and macros that are useful.