silly_mc.cpp 1.07 KB
Newer Older
1
#include "silly_mc.h"
2
#include <valarray>
3

4
silly_mc::silly_mc(const loadl::parser &p) : loadl::mc(p) {}
5
6
7
8
9
10

void silly_mc::do_update() {
	idx_++;
}

void silly_mc::do_measurement() {
11
	std::vector<double> silly = {1. * idx_, 1. * (3 - idx_ % 5) * idx_};
12
	measure.add("MagicNumber", silly);
13
14
	measure.add("MagicNumber2", idx_ * idx_);
	std::valarray<double> silly2 = {1. * idx_, 1. * (3 - idx_ % 5) * idx_};
15
	measure.add("MagicNumberValarray", silly2);
16
17
18
}

void silly_mc::init() {
19
	idx_ = 0;
20

21
	measure.register_observable("MagicNumberValarray", 10);
22
23
24
25
26
27
28
29
30
31
}

void silly_mc::checkpoint_write(const loadl::iodump::group &d) {
	d.write("idx", idx_);
}

void silly_mc::checkpoint_read(const loadl::iodump::group &d) {
	d.read("idx", idx_);
}

32
void silly_mc::register_evalables(loadl::evaluator &eval, const loadl::parser &) {
33
34
35
36
	eval.evaluate("AntimagicNumber", {"MagicNumber", "MagicNumber2"},
	              [](const std::vector<std::vector<double>> &obs) {
		              double mag = obs[0][0];
		              double mag2 = obs[1][0];
37

38
39
		              return std::vector{mag * mag / mag2};
	              });
40
}