Skip to content

Commit

Permalink
Added prefix argument to Grid writeTimeStep
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJoy8 committed Mar 21, 2024
1 parent 9a1ad60 commit 9b66034
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 12 additions & 8 deletions grid/src/Cabana_Grid_BovWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,17 @@ 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
\param gather_array Gather the array before writing to make parallel
consistent.
*/
template <class ExecutionSpace, class Array_t>
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<typename Array_t::mesh_type>::value,
"ViSIT BOV writer can only be used with uniform mesh" );
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -393,18 +394,21 @@ void writeTimeStep( ExecutionSpace, const int time_step_index,
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 <class Array_t>
void writeTimeStep( const int time_step_index, const double time,
const Array_t& array, const bool gather_array = true )
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{}, time_step_index, time, array, gather_array );
writeTimeStep( exec_space{}, prefix, time_step_index, time, array,
gather_array );
}

//---------------------------------------------------------------------------//
Expand Down
12 changes: 8 additions & 4 deletions grid/unit_test/tstBovWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9b66034

Please sign in to comment.