-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbegrun.cpp
More file actions
109 lines (89 loc) · 2.93 KB
/
begrun.cpp
File metadata and controls
109 lines (89 loc) · 2.93 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../argparse/argparse.hpp"
#include "dt/adaptive.h"
#include "floatdef.h"
#include "gravity/step.h"
#include "io/load_particle.hpp"
#include "io/vtk_save.h"
#include "io/vtu_save.h"
#include "io/hdf5_save.h"
#include <fstream>
#include <iostream>
#include <omp.h>
#include <string>
#include <vector>
using next::OutputFormat;
int main(int argc, char **argv) {
auto args = next::parse_arguments(argc, argv);
static constexpr const char *BANNER = R"NEXTBANNER(
_ _ ________ _________
| \ | | ____\ \ / /__ __|
| \| | |__ \ V / | |
| . ` | __| > < | |
| |\ | |____ / . \ | |
|_| \_|______/_/ \_\ |_|
)NEXTBANNER";
std::cout << BANNER << '\n';
// Set threads and report
omp_set_num_threads(args.threads);
std::cout << " Threads: " << args.threads << "\n";
#ifdef NEXT_FP64
std::cout << " Precision: FP64\n";
#elif defined(NEXT_FP32)
std::cout << " Precision: FP32\n";
#endif
// --- SoA UPDATE ---
// LoadParticlesFromFile now returns a single 'Particle' struct
// which internally contains all the parallel vectors.
Particle particles = LoadParticlesFromFile(args.input_file);
std::cout << " Particles: " << particles.size() << "\n";
real simTime = 0;
real nextDump = 0;
int step = 0;
char command;
while (true) {
// Both computeAdaptiveDt and Step now take the SoA object by reference
real dtAdaptive = computeAdaptiveDt(particles, args.dt);
Step(particles, dtAdaptive);
simTime += dtAdaptive;
if (simTime >= nextDump) {
std::string out = "dump_" + std::to_string(step);
switch (args.format) {
case OutputFormat::VTK:
out += ".vtk";
SaveVTK(particles, out);
break;
case OutputFormat::VTU:
out += ".vtu";
SaveVTU(particles, out);
break;
case OutputFormat::HDF5:
out += ".hdf5";
SaveHDF5(particles, out);
break;
}
std::cout << "[Dump " << step << "] t = " << simTime
<< ", file: " << out << "\n";
nextDump += args.dump_interval;
step++;
}
// Non-blocking exit check
if (std::cin.rdbuf()->in_avail() > 0) {
std::cin >> command;
if (command == 'q' || command == 'Q') {
std::cout << "Exiting...\n";
break;
}
}
}
return 0;
}