@@ -20,15 +20,80 @@ class IOManager {
20
20
~IOManager () = default ;
21
21
22
22
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) {
23
90
std::ostringstream oss;
24
91
25
- std::setw (4 );
26
- std::setfill (' 0' );
27
- oss << " ite_" << iteration;
92
+ oss << " ite_" << std::setw (4 ) << std::setfill (' 0' ) << iteration;
28
93
std::string path = oss.str ();
29
94
auto flag = (iteration == 0 ? File::Truncate : File::ReadWrite);
30
95
31
- File file (params.filename_out , flag);
96
+ File file (params.filename_out + " .h5 " , flag);
32
97
33
98
if (iteration == 0 ) {
34
99
file.createAttribute (" Ntx" , params.Ntx );
0 commit comments