diff options
Diffstat (limited to 'hadamard.cpp')
-rw-r--r-- | hadamard.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/hadamard.cpp b/hadamard.cpp index 0a8ba36..b8ebdde 100644 --- a/hadamard.cpp +++ b/hadamard.cpp @@ -8,15 +8,24 @@ class MeasureEnergy : public Measurement { public: unsigned N; double totalE; + unsigned n; + std::vector<unsigned> ρ_dist; - MeasureEnergy() { + MeasureEnergy(unsigned n_bins = 1e4) : ρ_dist(n_bins + 1, 0) { + n = n_bins; N = 0; totalE = 0; } - void after_sweep(double, double E, const Orthogonal&) override { + void after_sweep(double, double E, const Orthogonal& M) override { N++; totalE += E; + double max = sqrt(M.size()); + for (unsigned i = 0; i < M.size(); i++) { + for (unsigned j = 0; j < M.size(); j++) { + ρ_dist[n * (M(i, j) + max) / (2 * max)]++; + } + } } double energy() const { return totalE / N; } @@ -155,7 +164,7 @@ int main(int argc, char* argv[]) { std::vector<double> edata_old(p.As.size()); if (efile.is_open()) { - efile >> N_old; + efile >> Ne_old; for (unsigned i = 0; i < p.As.size(); i++) { double num; @@ -176,6 +185,39 @@ int main(int argc, char* argv[]) { efile_out.close(); + std::string ρfilename = "rhos_" + std::to_string(n) + "_" + std::to_string(β0) + "_" + + std::to_string(βf) + "_" + std::to_string(num) + ".dat"; + std::ifstream ρfile(ρfilename); + + std::vector<std::vector<unsigned>> ρdata_old(As.size()); + + for (unsigned i = 0; i < As.size(); i++) { + ρdata_old[i].resize(((MeasureEnergy*)As[0])->ρ_dist.size()); + } + + if (ρfile.is_open()) { + for (unsigned i = 0; i < As.size(); i++) { + for (unsigned j = 0; j < ((MeasureEnergy*)As[0])->ρ_dist.size(); j++) { + unsigned num; + ρfile >> num; + ρdata_old[i][j] = num; + } + } + + ρfile.close(); + } + + std::ofstream ρfile_out(ρfilename); + + for (unsigned i = 0; i < As.size(); i++) { + for (unsigned j = 0; j < ((MeasureEnergy*)As[0])->ρ_dist.size(); j++) { + ρfile_out << std::fixed << ρdata_old[i][j] + ((MeasureEnergy*)As[i])->ρ_dist[j] << " "; + } + ρfile_out << "\n"; + } + + ρfile_out.close(); + return 0; } |