File indexing completed on 2026-09-20 09:11:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef QSS_CUSTOM_STATS_HH
0033 #define QSS_CUSTOM_STATS_HH
0034
0035 #include <time.h>
0036
0037 #define GET_TIME(t0) (clock_gettime(CLOCK_MONOTONIC, &t0))
0038 #define TIME_SECS(t0, t1) ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9)
0039
0040
0041
0042
0043
0044
0045 #include "G4qss_misc.hh"
0046 #include "G4Types.hh"
0047 #include "G4ios.hh"
0048
0049 #include <atomic>
0050 #include <map>
0051
0052
0053
0054
0055
0056 struct QSSStats
0057 {
0058 G4double precision_dQMin;
0059 G4double precision_dQRel;
0060 G4int currentStep;
0061 G4int substeps;
0062 std::atomic<G4int> stepperSteps;
0063 std::map<G4int, std::map<G4int, G4int>> substepsByStepNumberByTrackID;
0064
0065 G4double reset_time;
0066 G4double integration_time;
0067
0068 G4int dqrel_changes[Qss_misc::VAR_IDX_END];
0069 G4int dqmin_changes[Qss_misc::VAR_IDX_END];
0070 G4double max_error[Qss_misc::VAR_IDX_END];
0071
0072 QSSStats()
0073 {
0074 substeps = 0;
0075 reset_time = 0;
0076 integration_time = 0;
0077
0078 for (std::size_t i = 0; i < Qss_misc::VAR_IDX_END; ++i)
0079 {
0080 dqrel_changes[i] = 0;
0081 dqmin_changes[i] = 0;
0082 max_error[i] = 0;
0083 }
0084 };
0085
0086 void print() const
0087 {
0088 G4int steps = stepperSteps.load();
0089
0090 std::vector<std::string> vars{"x", "y", "z", "vx", "vy", "vz"};
0091
0092 G4double avg_substeps = (G4double)substeps / steps;
0093 G4double avg_integration_time = (G4double)integration_time / steps;
0094 G4double avg_substeps_integration_time = (G4double)integration_time / substeps;
0095 G4double avg_reset_time = (G4double)reset_time / steps;
0096
0097 std::stringstream ss;
0098
0099 ss << "QSS stats:" << std::endl;
0100 ss << "dQMin: " << precision_dQMin << std::endl;
0101 ss << "dQRel: " << precision_dQRel << std::endl;
0102
0103 ss << " Total steps: " << steps << std::endl
0104 << " Total substeps: " << substeps << std::endl
0105 << " Substeps average per step: " << avg_substeps << std::endl;
0106
0107 ss << " Substeps by track-step:" << std::endl;
0108 for (const auto& stp : substepsByStepNumberByTrackID)
0109 {
0110 ss << " Track #" << stp.first << std::endl;
0111 for (const auto& stp2 : stp.second)
0112 {
0113 ss << " Step " << stp2.first << " => " << stp2.second << " substeps" << std::endl;
0114 }
0115 }
0116
0117 ss << " Integration time: " << integration_time << std::endl
0118 << " Integration time average (step): " << avg_integration_time << std::endl
0119 << " Integration time average (substep): " << avg_substeps_integration_time << std::endl;
0120
0121 ss << " Reset time: " << reset_time << std::endl
0122 << " Reset time average: " << avg_reset_time << std::endl;
0123
0124 for (std::size_t index = 0; index < Qss_misc::VAR_IDX_END; ++index)
0125 {
0126 ss << " Variable " << vars[index] << ":" << std::endl;
0127 ss << " dQRel changes: " << dqrel_changes[index] << std::endl;
0128 ss << " dQMin changes: " << dqmin_changes[index] << std::endl;
0129 ss << " Max error: " << max_error[index] << std::endl;
0130 }
0131
0132 G4cout << ss.rdbuf();
0133 };
0134 };
0135
0136 #endif