Skip to content

Commit f2d52a3

Browse files
committed
Simplify calculation_results
1 parent a41cfc1 commit f2d52a3

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

calculation_results.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <chrono>
2+
3+
namespace partdiff {
4+
5+
struct calculation_results {
6+
using time_point = std::chrono::time_point<std::chrono::high_resolution_clock>;
7+
int m;
8+
uint64_t stat_iteration;
9+
double stat_accuracy;
10+
time_point start_time;
11+
time_point end_time;
12+
};
13+
14+
} // namespace partdiff

partdiff.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "calculation_results.hpp"
12
#include "tensor.hpp"
23
#include <cmath>
34
#include <numbers>
@@ -15,15 +16,14 @@ namespace partdiff {
1516
static constexpr double pi = std::numbers::pi;
1617
static constexpr double two_pi_square = (2 * pi * pi);
1718

18-
calculation_results::calculation_results() {
19-
this->m = 0;
20-
this->stat_iteration = 0;
21-
this->stat_accuracy = 0;
22-
}
19+
static calculation_results calculate(calculation_arguments &arguments, const calculation_options &options) {
20+
21+
const auto now = std::chrono::high_resolution_clock::now;
2322

24-
static void calculate(calculation_arguments &arguments, calculation_results &results,
25-
const calculation_options &options) {
26-
results.start_time = std::chrono::high_resolution_clock::now();
23+
const auto start_time = now();
24+
25+
uint64_t stat_iteration = 0;
26+
double stat_accuracy = 0.0;
2727

2828
const int N = arguments.N;
2929
const double h = arguments.h;
@@ -72,8 +72,8 @@ namespace partdiff {
7272
}
7373
}
7474

75-
results.stat_iteration++;
76-
results.stat_accuracy = maxresiduum;
75+
stat_iteration++;
76+
stat_accuracy = maxresiduum;
7777

7878
const int temp = m1;
7979
m1 = m2;
@@ -88,8 +88,10 @@ namespace partdiff {
8888
}
8989
}
9090

91-
results.m = m2;
92-
results.end_time = std::chrono::high_resolution_clock::now();
91+
const auto end_time = now();
92+
93+
calculation_results results = {m2, stat_iteration, stat_accuracy, start_time, end_time};
94+
return results;
9395
}
9496

9597
static void display_statistics(const calculation_arguments &arguments, const calculation_results &results,
@@ -140,9 +142,8 @@ int main(const int argc, char const *argv[]) {
140142
argument_parser parser(argc, argv);
141143
calculation_options options = parser.get_options();
142144
calculation_arguments arguments(options);
143-
calculation_results results;
144145

145-
calculate(arguments, results, options);
146+
calculation_results results = calculate(arguments, options);
146147

147148
display_statistics(arguments, results, options);
148149
display_matrix(arguments, results, options);

partdiff.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,4 @@ namespace partdiff {
9898
void init_matrices();
9999
};
100100

101-
struct calculation_results {
102-
using time_point = std::chrono::time_point<std::chrono::high_resolution_clock>;
103-
uint64_t m;
104-
uint64_t stat_iteration;
105-
double stat_accuracy;
106-
time_point start_time;
107-
time_point end_time;
108-
calculation_results();
109-
};
110-
111101
} // namespace partdiff

0 commit comments

Comments
 (0)