Skip to content

Commit

Permalink
Correctly pad filenames in the wave project
Browse files Browse the repository at this point in the history
  • Loading branch information
tretre91 committed Jan 21, 2025
1 parent 5b69600 commit e9a04d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
20 changes: 14 additions & 6 deletions projects/01_wave/openmp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void write_grid(const std::vector<double>& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it);
unsigned int it,
unsigned int padding);

// __________________________________________________________________________
//
Expand Down Expand Up @@ -154,6 +155,12 @@ int main(int argc, char* argv[]) {
system("rm -rf diags");
system("mkdir -p diags");

// Maximum number of characters for the iteration number
const unsigned int iteration_number_padding =
number_of_iteration == 0
? 1
: static_cast<unsigned int>(std::log10(number_of_iteration)) + 1;

// __________________________________________________________________________
// Print summary of parameters

Expand Down Expand Up @@ -218,7 +225,7 @@ int main(int argc, char* argv[]) {
}
}

write_grid(U, Nx, Ny, dx,dy, 0);
write_grid(U, Nx, Ny, dx,dy, 0, iteration_number_padding);


// __________________________________________________________________________
Expand Down Expand Up @@ -290,7 +297,7 @@ int main(int argc, char* argv[]) {

// write the grid to a file
if (it % output_period == 0) {
write_grid(U, Nx, Ny, dx,dy, it);
write_grid(U, Nx, Ny, dx,dy, it, iteration_number_padding);
}

// Print iteration information in the terminal
Expand Down Expand Up @@ -341,11 +348,12 @@ void write_grid(const std::vector<double>& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it) {
unsigned int it,
unsigned int padding) {

// File name of the form grid_0000.json
std::stringstream filename("");
filename << "diags/grid_" << std::setfill('0') << std::setw(4) << it << ".json";
filename << "diags/grid_" << std::setfill('0') << std::setw(padding) << it << ".json";

std::ofstream file(filename.str());
file << "{\n";
Expand All @@ -369,4 +377,4 @@ void write_grid(const std::vector<double>& U,
file << "}\n";

file.close();
}
}
20 changes: 14 additions & 6 deletions projects/01_wave/sequential/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void write_grid(const std::vector<double>& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it);
unsigned int it,
unsigned int padding);

// __________________________________________________________________________
//
Expand Down Expand Up @@ -152,6 +153,12 @@ int main(int argc, char* argv[]) {
system("rm -rf diags");
system("mkdir -p diags");

// Maximum number of characters for the iteration number
const unsigned int iteration_number_padding =
number_of_iteration == 0
? 1
: static_cast<unsigned int>(std::log10(number_of_iteration)) + 1;

// __________________________________________________________________________
// Print summary of parameters

Expand Down Expand Up @@ -210,7 +217,7 @@ int main(int argc, char* argv[]) {
}
}

write_grid(U, Nx, Ny, dx,dy, 0);
write_grid(U, Nx, Ny, dx,dy, 0, iteration_number_padding);


// __________________________________________________________________________
Expand Down Expand Up @@ -273,7 +280,7 @@ int main(int argc, char* argv[]) {

// write the grid to a file
if (it % output_period == 0) {
write_grid(U, Nx, Ny, dx,dy, it);
write_grid(U, Nx, Ny, dx,dy, it, iteration_number_padding);
}

// Print iteration information in the terminal
Expand Down Expand Up @@ -322,11 +329,12 @@ void write_grid(const std::vector<double>& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it) {
unsigned int it,
unsigned int padding) {

// File name of the form grid_0000.json
std::stringstream filename("");
filename << "diags/grid_" << std::setfill('0') << std::setw(4) << it << ".json";
filename << "diags/grid_" << std::setfill('0') << std::setw(padding) << it << ".json";

std::ofstream file(filename.str());
file << "{\n";
Expand All @@ -350,4 +358,4 @@ void write_grid(const std::vector<double>& U,
file << "}\n";

file.close();
}
}
20 changes: 14 additions & 6 deletions projects/01_wave/solution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void write_grid(const Kokkos::View<double**>::HostMirror& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it);
unsigned int it,
unsigned int padding);

// __________________________________________________________________________
//
Expand Down Expand Up @@ -152,6 +153,12 @@ int main(int argc, char* argv[]) {
system("rm -rf diags");
system("mkdir -p diags");

// Maximum number of characters for the iteration number
const unsigned int iteration_number_padding =
number_of_iteration == 0
? 1
: static_cast<unsigned int>(std::log10(number_of_iteration)) + 1;

// __________________________________________________________________________
// Print summary of parameters

Expand Down Expand Up @@ -227,7 +234,7 @@ int main(int argc, char* argv[]) {

Kokkos::fence();

write_grid(U_host, Nx, Ny, dx,dy, 0);
write_grid(U_host, Nx, Ny, dx,dy, 0, iteration_number_padding);

Kokkos::deep_copy(U, U_host);
Kokkos::deep_copy(U_prev, U_prev_host);
Expand Down Expand Up @@ -319,7 +326,7 @@ int main(int argc, char* argv[]) {
// write the grid to a file
if (it % output_period == 0) {
Kokkos::deep_copy(U_host, U);
write_grid(U_host, Nx, Ny, dx,dy, it);
write_grid(U_host, Nx, Ny, dx,dy, it, iteration_number_padding);
}

// Print iteration information in the terminal
Expand Down Expand Up @@ -372,11 +379,12 @@ void write_grid(const Kokkos::View<double**>::HostMirror& U,
unsigned int Ny,
double dx,
double dy,
unsigned int it) {
unsigned int it,
unsigned int padding) {

// File name of the form grid_0000.json
std::stringstream filename("");
filename << "diags/grid_" << std::setfill('0') << std::setw(4) << it << ".json";
filename << "diags/grid_" << std::setfill('0') << std::setw(padding) << it << ".json";

std::ofstream file(filename.str());
file << "{\n";
Expand All @@ -400,4 +408,4 @@ void write_grid(const Kokkos::View<double**>::HostMirror& U,
file << "}\n";

file.close();
}
}

0 comments on commit e9a04d9

Please sign in to comment.