Skip to content

Commit 1b75a74

Browse files
committed
add tinyformat.h for better formatting
1 parent 76ec51d commit 1b75a74

File tree

15 files changed

+1118
-9003
lines changed

15 files changed

+1118
-9003
lines changed

src/main.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,44 @@ void MonteCarlo(markov &Markov) {
9090
while (Step < Para.TotalStep) {
9191
Step++;
9292
for (int i = 0; i < 1000000; i++) {
93-
Markov.Hop(SWEEP);
93+
Para.Counter++;
94+
// if (Para.Counter == 9) {
95+
// cout << "Before: " << Para.Counter << endl;
96+
// PrintDeBugMCInfo();
97+
// }
98+
99+
double x = Random.urn();
100+
if (x < 1.0 / MCUpdates)
101+
Markov.IncreaseOrder();
102+
else if (x < 2.0 / MCUpdates)
103+
Markov.DecreaseOrder();
104+
else if (x < 3.0 / MCUpdates)
105+
Markov.ChangeGroup();
106+
else if (x < 4.0 / MCUpdates)
107+
Markov.ChangeMomentum();
108+
// ;
109+
else if (x < 5.0 / MCUpdates)
110+
Markov.ChangeTau();
111+
// ;
112+
113+
// if (Para.Counter == 8831001) {
114+
// cout << "After: " << Para.Counter << endl;
115+
// PrintDeBugMCInfo();
116+
// }
117+
118+
// double Tau = Var.Tau[1] - Var.Tau[0];
119+
// momentum G1, G2;
120+
// for (int i = 0; i < D; i++) {
121+
// G1[i] = Var.LoopMom[0][i] + Var.LoopMom[1][i];
122+
// G2[i] = Var.LoopMom[1][i];
123+
// }
124+
// ASSERT_ALLWAYS(Equal(Green(Tau, G1, UP, 0),
125+
// Var.CurrGroup->Diag[0].G[0]->Weight, 1.0e-8),
126+
// Weight._DebugInfo());
127+
128+
// ASSERT_ALLWAYS(Equal(Green(-Tau, G2, UP, 0),
129+
// Var.CurrGroup->Diag[0].G[1]->Weight, 1.0e-8),
130+
// Weight._DebugInfo());
94131
Markov.Measure();
95132

96133
if (i % 100 == 0) {
@@ -115,6 +152,7 @@ void MonteCarlo(markov &Markov) {
115152
}
116153
}
117154
}
155+
118156
Markov.PrintMCInfo();
119157
Interrupt.Delay(); // the process can not be killed in saving
120158
Markov.SaveToFile();

src/markov.cpp

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright (c) 2019 Kun Chen. All rights reserved.
66
//
77
#include "markov.h"
8+
#include "utility/tinyformat.h"
89
#include <stdio.h>
910

1011
extern parameter Para;
@@ -21,55 +22,6 @@ using namespace std;
2122

2223
int markov::DynamicTest() { return Weight.DynamicTest(); }
2324

24-
void markov::Hop(int Sweep) {
25-
for (int i = 0; i < Sweep; i++) {
26-
Para.Counter++;
27-
// if (Para.Counter == 9) {
28-
// cout << "Before: " << Para.Counter << endl;
29-
// PrintDeBugMCInfo();
30-
// }
31-
32-
double x = Random.urn();
33-
if (x < 1.0 / MCUpdates)
34-
IncreaseOrder();
35-
else if (x < 2.0 / MCUpdates)
36-
DecreaseOrder();
37-
else if (x < 3.0 / MCUpdates)
38-
ChangeGroup();
39-
else if (x < 4.0 / MCUpdates)
40-
ChangeMomentum();
41-
// ;
42-
else if (x < 5.0 / MCUpdates)
43-
ChangeTau();
44-
// ;
45-
// if (x < 0.5)
46-
// ChangeMomentum();
47-
// // ;
48-
// else
49-
// ChangeTau();
50-
// // ;
51-
52-
// if (Para.Counter == 8831001) {
53-
// cout << "After: " << Para.Counter << endl;
54-
// PrintDeBugMCInfo();
55-
// }
56-
57-
// double Tau = Var.Tau[1] - Var.Tau[0];
58-
// momentum G1, G2;
59-
// for (int i = 0; i < D; i++) {
60-
// G1[i] = Var.LoopMom[0][i] + Var.LoopMom[1][i];
61-
// G2[i] = Var.LoopMom[1][i];
62-
// }
63-
// ASSERT_ALLWAYS(Equal(Green(Tau, G1, UP, 0),
64-
// Var.CurrGroup->Diag[0].G[0]->Weight, 1.0e-8),
65-
// Weight._DebugInfo());
66-
67-
// ASSERT_ALLWAYS(Equal(Green(-Tau, G2, UP, 0),
68-
// Var.CurrGroup->Diag[0].G[1]->Weight, 1.0e-8),
69-
// Weight._DebugInfo());
70-
}
71-
}
72-
7325
void markov::PrintDeBugMCInfo() {
7426
string msg;
7527
msg = string(80, '=') + "\n";
@@ -159,30 +111,33 @@ void markov::Measure() {
159111
void markov::SaveToFile() {
160112
for (int i = 0; i < Polar.size(); i++) {
161113
ofstream PolarFile;
162-
string FileName = +"Group" + ToString(Weight.Groups[i].ID) + "_" +
163-
ToString(Para.PID) + ".dat";
114+
string FileName =
115+
tfm::format("group%d_pid%d.dat", Weight.Groups[i].ID, Para.PID);
164116
PolarFile.open(FileName, ios::out | ios::trunc);
165117
if (PolarFile.is_open()) {
166-
PolarFile << "#PID: " << Para.PID << ", rs: " << Para.Rs
167-
<< ", Beta: " << Para.Beta << ", Group: " << i << endl;
118+
PolarFile << tfm::format(
119+
"#PID: %d, rs:%.3f, Beta: %.3f, Group: %d, Step: %d\n", Para.PID,
120+
Para.Rs, Para.Beta, Weight.Groups[i].ID, Para.Counter);
121+
168122
for (int j = 0; j < Polar[i].size(); j++)
169-
PolarFile << Var.ExtMomTable[j][0] << " " << Polar[i][j] << endl;
170-
PolarFile << endl;
123+
PolarFile << tfm::format("%13.6f\t%13.6f\n", Var.ExtMomTable[j][0],
124+
Polar[i][j]);
171125
PolarFile.close();
172126
} else {
173127
LOG_WARNING("Polarization for PID " << Para.PID << " fails to save!");
174128
}
175129
}
176130

177131
ofstream StaticPolarFile;
178-
string FileName = "output.dat";
179-
StaticPolarFile.open(FileName, ios::out | ios::app);
132+
string FileName = tfm::format("output%d.dat", Para.PID);
133+
StaticPolarFile.open(FileName, ios::out | ios::trunc);
180134
if (StaticPolarFile.is_open()) {
181135
for (int i = 0; i < PolarStatic.size(); i++) {
182-
StaticPolarFile << "#PID: " << Para.PID << ", rs: " << Para.Rs
183-
<< ", Beta: " << Para.Beta << endl;
184-
StaticPolarFile << i << " " << PolarStatic[i] << endl;
185-
StaticPolarFile << endl;
136+
StaticPolarFile << tfm::format(
137+
"PID:%-4d Group:%-4d rs:%-.3f "
138+
"Beta:%-.3f Lambda:%-.3f Polar: % 13.6f\n",
139+
Para.PID, Weight.Groups[i].ID, Para.Rs, Para.Beta, Para.Mass2,
140+
PolarStatic[i]);
186141
}
187142
StaticPolarFile.close();
188143
} else {

src/markov.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ class markov {
1919
long long Counter;
2020

2121
void Initialization(std::string FilePrefix);
22-
void Hop(const int);
2322
void PrintMCInfo();
2423
void PrintDeBugMCInfo();
2524
void AdjustGroupReWeight();
2625

26+
// MC updates
27+
void ChangeTau();
28+
void ChangeMomentum();
29+
void IncreaseOrder();
30+
void DecreaseOrder();
31+
void ChangeGroup();
32+
2733
void Measure();
2834
void SaveToFile();
2935

@@ -37,11 +43,6 @@ class markov {
3743
vector<double> PolarStatic;
3844

3945
// MC updates
40-
void ChangeTau();
41-
void ChangeMomentum();
42-
void IncreaseOrder();
43-
void DecreaseOrder();
44-
void ChangeGroup();
4546

4647
double ShiftExtK(const int &, int &);
4748
double ShiftK(const momentum &, momentum &);

0 commit comments

Comments
 (0)