From 3549a084601c2a646d198c9375f68196cacc4ece Mon Sep 17 00:00:00 2001 From: David Date: Thu, 21 Mar 2024 18:21:09 +0000 Subject: [PATCH 1/2] Added prefix argument to Grid writeTimeStep --- grid/src/Cabana_Grid_BovWriter.hpp | 60 +++++++++++++++++++++++++++--- grid/unit_test/tstBovWriter.hpp | 12 ++++-- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/grid/src/Cabana_Grid_BovWriter.hpp b/grid/src/Cabana_Grid_BovWriter.hpp index 5c43de78f..65dbce993 100644 --- a/grid/src/Cabana_Grid_BovWriter.hpp +++ b/grid/src/Cabana_Grid_BovWriter.hpp @@ -172,6 +172,7 @@ reorderView( TargetView& target, const SourceView& source, This version writes a single output and does not use bricklets. We will do this in the future to improve parallel visualization. + \param prefix The filename prefix \param time_step_index The index of the time step we are writing. \param time The current time \param array The array to write @@ -179,9 +180,9 @@ reorderView( TargetView& target, const SourceView& source, consistent. */ template -void writeTimeStep( ExecutionSpace, const int time_step_index, - const double time, const Array_t& array, - const bool gather_array = true ) +void writeTimeStep( ExecutionSpace, const std::string& prefix, + const int time_step_index, const double time, + const Array_t& array, const bool gather_array = true ) { static_assert( isUniformMesh::value, "ViSIT BOV writer can only be used with uniform mesh" ); @@ -281,8 +282,8 @@ void writeTimeStep( ExecutionSpace, const int time_step_index, // Compose a data file name prefix. std::stringstream file_name; - file_name << "grid_" << array.label() << "_" << std::setfill( '0' ) - << std::setw( 6 ) << time_step_index; + file_name << prefix << "_" << std::setfill( '0' ) << std::setw( 6 ) + << time_step_index; // Open a binary data file. std::string data_file_name = file_name.str() + ".dat"; @@ -387,6 +388,52 @@ void writeTimeStep( ExecutionSpace, const int time_step_index, } } +/*! + \brief Write a grid array to a VisIt BOV. + + This version writes a single output and does not use bricklets. We will do + this in the future to improve parallel visualization. + + \param prefix The filename prefix + \param time_step_index The index of the time step we are writing. + \param time The current time + \param array The array to write + \param gather_array Gather the array before writing to make parallel + consistent. +*/ +template +void writeTimeStep( const std::string& prefix, const int time_step_index, + const double time, const Array_t& array, + const bool gather_array = true ) +{ + using exec_space = typename Array_t::execution_space; + writeTimeStep( exec_space{}, prefix, time_step_index, time, array, + gather_array ); +} + +/*! + \brief Write a grid array to a VisIt BOV. + + This version writes a single output and does not use bricklets. We will do + this in the future to improve parallel visualization. + + \param time_step_index The index of the time step we are writing. + \param time The current time + \param array The array to write + \param gather_array Gather the array before writing to make parallel + consistent. +*/ +template ::value, int>::type = 0> +void writeTimeStep( ExecutionSpace, const int time_step_index, + const double time, const Array_t& array, + const bool gather_array = true ) +{ + writeTimeStep( ExecutionSpace{}, "grid_" + array.label(), time_step_index, + time, array, gather_array ); +} + /*! \brief Write a grid array to a VisIt BOV. @@ -404,7 +451,8 @@ void writeTimeStep( const int time_step_index, const double time, const Array_t& array, const bool gather_array = true ) { using exec_space = typename Array_t::execution_space; - writeTimeStep( exec_space{}, time_step_index, time, array, gather_array ); + writeTimeStep( exec_space{}, "grid_" + array.label(), time_step_index, time, + array, gather_array ); } //---------------------------------------------------------------------------// diff --git a/grid/unit_test/tstBovWriter.hpp b/grid/unit_test/tstBovWriter.hpp index 8eaccd059..7803f1eab 100644 --- a/grid/unit_test/tstBovWriter.hpp +++ b/grid/unit_test/tstBovWriter.hpp @@ -113,8 +113,10 @@ void writeTest3d() node_halo->gather( TEST_EXECSPACE(), *node_field ); // Write the fields to a file. - Experimental::BovWriter::writeTimeStep( 302, 3.43, *cell_field ); - Experimental::BovWriter::writeTimeStep( 1972, 12.457, *node_field ); + Experimental::BovWriter::writeTimeStep( "grid_cell_field_3d", 302, 3.43, + *cell_field ); + Experimental::BovWriter::writeTimeStep( "grid_cell_field_3d", 1972, + 12.457, *node_field ); } // Read the data back in on rank 0 and make sure it is OK. int rank; @@ -270,8 +272,10 @@ void writeTest2d() node_halo->gather( TEST_EXECSPACE(), *node_field ); // Write the fields to a file. - Experimental::BovWriter::writeTimeStep( 302, 3.43, *cell_field ); - Experimental::BovWriter::writeTimeStep( 1972, 12.457, *node_field ); + Experimental::BovWriter::writeTimeStep( "grid_cell_field_2d", 302, 3.43, + *cell_field ); + Experimental::BovWriter::writeTimeStep( "grid_cell_field_2d", 1972, + 12.457, *node_field ); } // Read the data back in on rank 0 and make sure it is OK. int rank; From b925f516f009c787a62cb39823b50614e94193ca Mon Sep 17 00:00:00 2001 From: David Date: Thu, 11 Apr 2024 14:47:43 +0000 Subject: [PATCH 2/2] Fix test case --- grid/unit_test/tstBovWriter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid/unit_test/tstBovWriter.hpp b/grid/unit_test/tstBovWriter.hpp index 7803f1eab..95140b967 100644 --- a/grid/unit_test/tstBovWriter.hpp +++ b/grid/unit_test/tstBovWriter.hpp @@ -115,7 +115,7 @@ void writeTest3d() // Write the fields to a file. Experimental::BovWriter::writeTimeStep( "grid_cell_field_3d", 302, 3.43, *cell_field ); - Experimental::BovWriter::writeTimeStep( "grid_cell_field_3d", 1972, + Experimental::BovWriter::writeTimeStep( "grid_node_field_3d", 1972, 12.457, *node_field ); } // Read the data back in on rank 0 and make sure it is OK. @@ -274,7 +274,7 @@ void writeTest2d() // Write the fields to a file. Experimental::BovWriter::writeTimeStep( "grid_cell_field_2d", 302, 3.43, *cell_field ); - Experimental::BovWriter::writeTimeStep( "grid_cell_field_2d", 1972, + Experimental::BovWriter::writeTimeStep( "grid_node_field_2d", 1972, 12.457, *node_field ); } // Read the data back in on rank 0 and make sure it is OK.