Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Physical Time to VTK Outputs for #727 #729

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/io/vtk_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class VtkWriter {
//! \param[in] mpi_size Number of MPI tasks
//! \param[in] step Current time step
//! \param[in] max_steps Maximum number of steps in the simulation
//! \param[in] step_size Physical time step size
//! \param[in] ncomponents Number of components to write
void write_parallel_vtk(const std::string& filename,
const std::string& attribute, int mpi_size,
unsigned step, unsigned max_steps,
unsigned step, unsigned max_steps, double step_size,
unsigned ncomponents = 3);

private:
Expand Down
8 changes: 4 additions & 4 deletions include/solvers/mpm_base.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void mpm::MPMBase<Tdim>::write_vtk(mpm::Index step, mpm::Index max_steps) {
.string();

vtk_writer->write_parallel_vtk(parallel_file, attribute, mpi_size, step,
max_steps);
max_steps, dt_);
}
#endif
}
Expand All @@ -562,7 +562,7 @@ void mpm::MPMBase<Tdim>::write_vtk(mpm::Index step, mpm::Index max_steps) {
.string();

vtk_writer->write_parallel_vtk(parallel_file, attribute, mpi_size, step,
max_steps);
max_steps, dt_);
}
#endif
}
Expand All @@ -583,7 +583,7 @@ void mpm::MPMBase<Tdim>::write_vtk(mpm::Index step, mpm::Index max_steps) {
.string();

vtk_writer->write_parallel_vtk(parallel_file, attribute, mpi_size, step,
max_steps, 9);
max_steps, dt_, 9);
}
#endif
}
Expand All @@ -609,7 +609,7 @@ void mpm::MPMBase<Tdim>::write_vtk(mpm::Index step, mpm::Index max_steps) {
.string();
unsigned ncomponents = 1;
vtk_writer->write_parallel_vtk(parallel_file, phase_attribute, mpi_size,
step, max_steps, ncomponents);
step, max_steps, dt_, ncomponents);
}
#endif
}
Expand Down
43 changes: 42 additions & 1 deletion src/io/vtk_writer.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "vtk_writer.h"
#include <boost/filesystem.hpp>

#ifdef USE_VTK

Expand Down Expand Up @@ -223,7 +224,7 @@ void VtkWriter::write_mesh(
void VtkWriter::write_parallel_vtk(const std::string& filename,
const std::string& attribute, int mpi_size,
unsigned step, unsigned max_steps,
unsigned ncomponents) {
double step_size, unsigned ncomponents) {

// If the number of components is 1, set as scalar or vector / tensor
std::string data_type;
Expand Down Expand Up @@ -278,6 +279,46 @@ void VtkWriter::write_parallel_vtk(const std::string& filename,
pvtk.open(filename);
pvtk << ppolydata;
pvtk.close();

// Write parallel grouping VTK file

std::string output_path = filename.substr(0, filename.find_last_of("\\/"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens on a Windows system?

std::ofstream group_vtk;
std::string group_filename = output_path + "/" + attribute + ".pvd";
std::string group_data;

std::stringstream group_parts_file;
group_parts_file.str(std::string());
group_parts_file << attribute;
group_parts_file.fill('0');
int digits = log10(max_steps) + 1;
group_parts_file.width(digits);
group_parts_file << step;
group_parts_file << ".pvtp";

boost::filesystem::path file_check(group_filename);

if (boost::filesystem::exists(file_check)) {
group_vtk.open(group_filename, std::fstream::app);
group_data = "\t<DataSet timestep=\"" + std::to_string(step * step_size) +
"\" file=\"./" + group_parts_file.str() + "\"/>\n";
group_vtk << group_data;
} else {
group_vtk.open(group_filename);
group_data =
"<?xml version=\"1.0\"?>\n<VTKFile type=\"Collection\" version=\"0.1\" "
"byte_order=\"LittleEndian\">\n<Collection>\n\t<DataSet timestep=\"" +
std::to_string(step * step_size) + "\" file=\"./" +
group_parts_file.str() + "\"/>\n";
group_vtk << group_data;
}

if (step == max_steps - 1) {
std::string closing = "</Collection>\n</VTKFile>";
group_vtk << closing;
}

group_vtk.close();
}

#endif
6 changes: 4 additions & 2 deletions tests/io/vtk_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ TEST_CASE("VTK Writer is checked", "[vtk][writer]") {
int mpi_size = 2;
unsigned step = 1000;
unsigned max_steps = 10000;
double step_size = 0.5;
vtk_writer->write_parallel_vtk(parallel_vtk_file, attribute, mpi_size, step,
max_steps);
max_steps, step_size);

// Check file data
std::string ppolydata =
Expand Down Expand Up @@ -98,8 +99,9 @@ TEST_CASE("VTK Writer is checked", "[vtk][writer]") {
int mpi_size = 2;
unsigned step = 1000;
unsigned max_steps = 10000;
double step_size = 0.5;
vtk_writer->write_parallel_vtk(parallel_vtk_file, attribute, mpi_size, step,
max_steps, 1);
max_steps, step_size, 1);

// Check file data
std::string ppolydata =
Expand Down