-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_exporter.cpp
55 lines (47 loc) · 1.73 KB
/
data_exporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Conni Bilham & Lucy Coward 2022, All Rights Reserved.
#include "data_exporter.h"
#define VEC(x) #x << "_x" << "," << #x << "_y" << "," << #x << "_z"
#define writeVector(VAR) VAR.x << ',' << (VAR).y << ',' << (VAR).z << ','
void data_exporter::csv_full_dump_Star(Star star) {
if(!fileDump.is_open()) {
logging::error("[ data_exporter::csv_full_dump_Star ] File is not open");
return;
}
for (int i = 0; i < simulationFrames; ++i) {
history_record_t history = star.history.at(i);
auto position = history.position;
auto velocity = history.velocity;
auto acceleration = history.acceleration;
fileDump
<< std::fixed << std::setprecision(16)
<< star.id << ',' << (i + 1) << ','
<< writeVector(position)
<< writeVector(velocity)
<< writeVector(acceleration)
<< writeVector(Vectorr(
velocity.size(),
velocity.length(),
star.kinetic_energy()
))
<< std::endl;
}
}
void data_exporter::dump_csv() {
fileDump.open(file_path.c_str());
fileDump.precision(32);
// Output header
fileDump << "Star ID,"
<< "Accel ID,"
<< VEC(position) << ","
<< VEC(velocity) << ","
<< VEC(acceleration) << ","
<< "Total Energy 1,"
<< "Total Energy 2,"
<< "Total Energy 3"
<< std::endl;
for (auto star: *star_list) {
// star->history_position.erase(star->history_position.begin());
this->csv_full_dump_Star(*star);
}
fileDump.close();
}