-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanna.cpp
More file actions
50 lines (46 loc) · 1.65 KB
/
Copy pathmanna.cpp
File metadata and controls
50 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "manna.hpp"
#include "precise_output.hpp"
#include "progress.hpp"
manna::manna()
: nr_samples("nr_samples", std::cin, std::cout),
lattice_size("lattice_size", std::cin, std::cout),
nr_steps("nr_steps", std::cin, std::cout),
record_every("record_every", std::cin, std::cout),
number_density("number_density", std::cin, std::cout),
lattice(lattice_size(), std::round(number_density() * lattice_size()))
{
if (nr_samples() == 0 || lattice_size() < 4 || nr_steps() % record_every()) {
throw std::runtime_error("manna: illegal input");
}
for (index_t i = 0; i < 1 + nr_steps() / record_every(); ++i) {
order_parameter.push_back(std::make_shared<variable>());
}
run();
print_results();
}
void manna::run()
{
progress status(nr_samples());
for (index_t i = 0; i < nr_samples(); ++i) {
simulate_sample();
status.next(i);
}
}
void manna::simulate_sample()
{
lattice.reset();
order_parameter[0]->add(lattice.order_parameter());
for (index_t i = 1; i < order_parameter.size(); ++i) {
lattice.take_step(record_every());
order_parameter[i]->add(lattice.order_parameter());
}
}
void manna::print_results()
{
std::cout << "Fixed energy Manna model\n";
precise_output<float_t> out("M_" + std::to_string(nr_samples()) + "_L_" + std::to_string(lattice_size()) + "_S_" + std::to_string(nr_steps()) + "_R_" + std::to_string(number_density()) + ".txt");
for (index_t i = 0; i < order_parameter.size(); ++i) {
out << i * record_every() << "\t" << order_parameter[i]->mean();
out << "\t" << order_parameter[i]->error() << "\n";
}
}