summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--metastable.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/metastable.cpp b/metastable.cpp
index cb47ffc..bebb96a 100644
--- a/metastable.cpp
+++ b/metastable.cpp
@@ -1,17 +1,25 @@
#define WOLFF_USE_FINITE_STATES
-#include <iostream>
#include <cstring>
#include <fstream>
-
+#include <iostream>
+#include <sstream>
#include "randutils/randutils.hpp"
#include "wolff/lib/wolff_models/ising.hpp"
using namespace wolff;
-void update_distribution_file(std::string id, const std::vector<uint64_t>& data, std::string model_string) {
+template <typename T> std::string to_string_with_precision(const T a_value, const int n = 12) {
+ std::ostringstream out;
+ out.precision(n);
+ out << std::fixed << a_value;
+ return out.str();
+}
+
+void update_distribution_file(std::string id, const std::vector<uint64_t>& data,
+ std::string model_string) {
std::string filename = model_string + id + ".dat";
std::ifstream file(filename);
@@ -30,13 +38,14 @@ void update_distribution_file(std::string id, const std::vector<uint64_t>& data,
std::ofstream file_out(filename);
for (unsigned i = 0; i < data.size(); i++) {
- file_out <<std::fixed<< data_old[i] + data[i] << " ";
+ file_out << std::fixed << data_old[i] + data[i] << " ";
}
file_out.close();
}
-void update_distribution_file(std::string id, const std::vector<std::vector<uint64_t>>& data, std::string model_string) {
+void update_distribution_file(std::string id, const std::vector<std::vector<uint64_t>>& data,
+ std::string model_string) {
std::string filename = model_string + id + ".dat";
std::ifstream file(filename);
@@ -81,13 +90,15 @@ private:
std::string model_string;
public:
- meas(const system<ising_t, ising_t, graph<>>& S, double H) : mag_dist(S.nv + 1, 0), energy_mag_dist(S.nv + 1) {
+ meas(const system<ising_t, ising_t, graph<>>& S, double H)
+ : mag_dist(S.nv + 1, 0), energy_mag_dist(S.nv + 1) {
M = S.nv * S.s[0];
E = S.ne;
for (std::vector<uint64_t>& d : energy_mag_dist) {
d.resize(S.ne + 1, 0);
}
- model_string = "metastable_" + std::to_string(S.G.D) + "_" + std::to_string(S.G.L) + "_" + std::to_string(S.T) + "_" + std::to_string(H) + "_";
+ model_string = "metastable_" + std::to_string(S.G.D) + "_" + std::to_string(S.G.L) + "_" +
+ to_string_with_precision(S.T) + "_" + to_string_with_precision(H) + "_";
}
~meas() {
@@ -95,8 +106,8 @@ public:
update_distribution_file("e", energy_mag_dist, model_string);
}
- void plain_bond_visited(const system<ising_t, ising_t, graph<>>&, const typename graph<>::halfedge&, const ising_t&,
- double dE) override {
+ void plain_bond_visited(const system<ising_t, ising_t, graph<>>&,
+ const typename graph<>::halfedge&, const ising_t&, double dE) override {
if (dE > 0) {
E -= 2;
} else {