Skip to content

Commit 0db3665

Browse files
committed
Implemented multiple_output backend
1 parent de70d27 commit 0db3665

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

IOManager.h

+69-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,80 @@ class IOManager {
2020
~IOManager() = default;
2121

2222
void saveSolution(const Array &Q, int iteration, real_t t, real_t dt) {
23+
if (params.multiple_outputs)
24+
saveSolutionMultiple(Q, iteration, t, dt);
25+
else
26+
saveSolutionUnique(Q, iteration, t, dt);
27+
}
28+
29+
void saveSolutionMultiple(const Array &Q, int iteration, real_t t, real_t dt) {
30+
std::ostringstream oss;
31+
32+
oss << params.filename_out << "_" << std::setw(4) << std::setfill('0') << iteration << ".h5";
33+
34+
File file(oss.str(), File::Truncate);
35+
36+
file.createAttribute("Ntx", params.Ntx);
37+
file.createAttribute("Nty", params.Nty);
38+
file.createAttribute("Nx", params.Nx);
39+
file.createAttribute("Ny", params.Ny);
40+
file.createAttribute("ibeg", params.ibeg);
41+
file.createAttribute("iend", params.iend);
42+
file.createAttribute("jbeg", params.jbeg);
43+
file.createAttribute("jend", params.jend);
44+
file.createAttribute("problem", params.problem);
45+
46+
std::vector<real_t> x;
47+
for (int i=params.ibeg; i < params.iend; ++i)
48+
x.push_back(((i-params.ibeg)+0.5) * params.dx);
49+
file.createDataSet("x", x);
50+
std::vector<real_t> y;
51+
for (int j=params.jbeg; j < params.jend; ++j)
52+
y.push_back(((j-params.jbeg)+0.5) * params.dy);
53+
file.createDataSet("y", y);
54+
55+
using Table = std::vector<std::vector<real_t>>;
56+
57+
auto Qhost = Kokkos::create_mirror(Q);
58+
Kokkos::deep_copy(Qhost, Q);
59+
60+
Table trho, tu, tv, tprs;
61+
for (int j=params.jbeg; j<params.jend; ++j) {
62+
std::vector<real_t> rrho, ru, rv, rprs;
63+
64+
for (int i=params.ibeg; i<params.iend; ++i) {
65+
real_t rho = Qhost(j, i, IR);
66+
real_t u = Qhost(j, i, IU);
67+
real_t v = Qhost(j, i, IV);
68+
real_t p = Qhost(j, i, IP);
69+
70+
rrho.push_back(rho);
71+
ru.push_back(u);
72+
rv.push_back(v);
73+
rprs.push_back(p);
74+
}
75+
76+
trho.push_back(rrho);
77+
tu.push_back(ru);
78+
tv.push_back(rv);
79+
tprs.push_back(rprs);
80+
}
81+
82+
file.createDataSet("rho", trho);
83+
file.createDataSet("u", tu);
84+
file.createDataSet("v", tv);
85+
file.createDataSet("prs", tprs);
86+
file.createAttribute("time", t);
87+
}
88+
89+
void saveSolutionUnique(const Array &Q, int iteration, real_t t, real_t dt) {
2390
std::ostringstream oss;
2491

25-
std::setw(4);
26-
std::setfill('0');
27-
oss << "ite_" << iteration;
92+
oss << "ite_" << std::setw(4) << std::setfill('0') << iteration;
2893
std::string path = oss.str();
2994
auto flag = (iteration == 0 ? File::Truncate : File::ReadWrite);
3095

31-
File file(params.filename_out, flag);
96+
File file(params.filename_out + ".h5", flag);
3297

3398
if (iteration == 0) {
3499
file.createAttribute("Ntx", params.Ntx);

SimInfo.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ enum ViscosityMode {
6969
struct Params {
7070
real_t save_freq;
7171
real_t tend;
72-
std::string filename_out = "run.h5";
72+
std::string filename_out = "run";
7373
BoundaryType boundary_x = BC_REFLECTING;
7474
BoundaryType boundary_y = BC_REFLECTING;
7575
ReconstructionType reconstruction = PCM;
7676
RiemannSolver riemann_solver = HLL;
7777
TimeStepping time_stepping = TS_EULER;
7878
real_t CFL = 0.1;
7979

80+
bool multiple_outputs = false;
81+
8082
// Parallel stuff
8183
ParallelRange range_tot;
8284
ParallelRange range_dom;
@@ -179,6 +181,7 @@ Params readInifile(std::string filename) {
179181

180182
// Run
181183
res.tend = reader.GetFloat("run", "tend", 1.0);
184+
res.multiple_outputs = reader.GetBoolean("run", "multiple_outputs", false);
182185
res.save_freq = reader.GetFloat("run", "save_freq", 1.0e-1);
183186
res.filename_out = reader.Get("run", "output_filename", "run.h5");
184187

settings/blast.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ymax=1.0
99
[run]
1010
tend=1.0
1111
save_freq=0.01
12-
12+
multiple_outputs=true
1313
boundaries_x=periodic
1414
boundaries_y=periodic
1515

0 commit comments

Comments
 (0)