ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
relax_history.h
Go to the documentation of this file.
1#ifndef RELAX_HISTORY_H
2#define RELAX_HISTORY_H
3
4#include <iomanip>
5#include <sstream>
6#include <string>
7#include <vector>
8
18
27inline std::string format_relax_history(
28 const std::vector<double> &hist,
29 const int per_line = 5,
30 const int max_full = 100,
31 const int keep = 10)
32{
33 std::ostringstream out;
34 out << std::scientific << std::setprecision(3);
35
36 const int n = static_cast<int>(hist.size());
37 const bool truncate = (n > max_full);
38 const int head = truncate ? keep : n;
39
40 int printed = 0;
41 auto print_one = [&out, &printed, per_line](const double value)
42 {
43 if (printed % per_line == 0)
44 {
45 out << "\n ";
46 }
47 else
48 {
49 out << " ";
50 }
51 out << value;
52 ++printed;
53 };
54
55 for (int i = 0; i < head; ++i)
56 {
57 print_one(hist[i]);
58 }
59 if (truncate)
60 {
61 const int omitted = n - 2 * keep;
62 out << "\n ... (omitted " << omitted << " step(s)) ...";
63 for (int i = n - keep; i < n; ++i)
64 {
65 print_one(hist[i]);
66 }
67 }
68 out << "\n";
69 return out.str();
70}
71
72#endif // RELAX_HISTORY_H
std::string format_relax_history(const std::vector< double > &hist, const int per_line=5, const int max_full=100, const int keep=10)
Format a per-step history for the running log.
Definition relax_history.h:27