From f9910200b51570c9192b7a6f3748bb9c42a99d2c Mon Sep 17 00:00:00 2001 From: Maddy Fontaine <84877960+mfontaine218@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:22:32 -0700 Subject: [PATCH 1/5] Update vtk_writer.h Adding physical time to vtk output --- include/io/vtk_writer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/io/vtk_writer.h b/include/io/vtk_writer.h index eb0591d7e..549114d78 100644 --- a/include/io/vtk_writer.h +++ b/include/io/vtk_writer.h @@ -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: From ae3dbe71c176d46546745c8f5a43b377d03fd016 Mon Sep 17 00:00:00 2001 From: Maddy Fontaine <84877960+mfontaine218@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:27:53 -0700 Subject: [PATCH 2/5] Update vtk_writer.cc Adding physical time to vtk output --- src/io/vtk_writer.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/io/vtk_writer.cc b/src/io/vtk_writer.cc index 6a6a51e9b..d5b1b3ef9 100644 --- a/src/io/vtk_writer.cc +++ b/src/io/vtk_writer.cc @@ -1,4 +1,5 @@ #include "vtk_writer.h" +#include #ifdef USE_VTK @@ -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; @@ -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("\\/")); + 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\n"; + group_vtk << group_data; + } else { + group_vtk.open(group_filename); + group_data = + "\n\n\n\t\n"; + group_vtk << group_data; + } + + if (step == max_steps - 1) { + std::string closing = "\n"; + group_vtk << closing; + } + + group_vtk.close(); } #endif From abc860bb56b5a3c1823b16be8a5b913cae4e7264 Mon Sep 17 00:00:00 2001 From: Maddy Fontaine <84877960+mfontaine218@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:32:25 -0700 Subject: [PATCH 3/5] Update vtk_writer_test.cc Adding physical time to vtk output --- tests/io/vtk_writer_test.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/io/vtk_writer_test.cc b/tests/io/vtk_writer_test.cc index da07b83cb..a0f6c1ccd 100644 --- a/tests/io/vtk_writer_test.cc +++ b/tests/io/vtk_writer_test.cc @@ -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 = @@ -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 = From 8b92996d95eb7d79438de9491d954347c50bb083 Mon Sep 17 00:00:00 2001 From: Maddy Fontaine <84877960+mfontaine218@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:37:22 -0700 Subject: [PATCH 4/5] Update mpm_base.tcc Adding physical time to vtk output --- include/solvers/mpm_base.tcc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/solvers/mpm_base.tcc b/include/solvers/mpm_base.tcc index f829b5f95..9df2b65cb 100644 --- a/include/solvers/mpm_base.tcc +++ b/include/solvers/mpm_base.tcc @@ -541,7 +541,7 @@ void mpm::MPMBase::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 } @@ -562,7 +562,7 @@ void mpm::MPMBase::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 } @@ -583,7 +583,7 @@ void mpm::MPMBase::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 } @@ -609,7 +609,7 @@ void mpm::MPMBase::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 } From bd3284d560fc818f71cecd2887c376c9cc60a3b9 Mon Sep 17 00:00:00 2001 From: Maddy Fontaine Date: Thu, 28 Apr 2022 22:04:20 -0700 Subject: [PATCH 5/5] Updated Format with clang-format --- src/io/vtk_writer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/io/vtk_writer.cc b/src/io/vtk_writer.cc index d5b1b3ef9..1239ddc1b 100644 --- a/src/io/vtk_writer.cc +++ b/src/io/vtk_writer.cc @@ -279,7 +279,7 @@ 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("\\/")); @@ -297,11 +297,11 @@ void VtkWriter::write_parallel_vtk(const std::string& filename, 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\n"; + "\" file=\"./" + group_parts_file.str() + "\"/>\n"; group_vtk << group_data; } else { group_vtk.open(group_filename); @@ -317,7 +317,7 @@ void VtkWriter::write_parallel_vtk(const std::string& filename, std::string closing = "\n"; group_vtk << closing; } - + group_vtk.close(); }