![]() |
Gowdy solver
|
Writes checkpoints from the grid to the output data file. More...
#include <gridOutput.h>
Data Structures | |
struct | skipInfo |
Public Member Functions | |
Int | get_mSkip () const |
Int | get_nOut () const |
Int | get_nSkip () const |
Int | recordSizeInBytes () const |
Retrieve the size (in bytes) of the output record. | |
GridOutputWriter (Parameters ¶ms, UniformGrid &ug) | |
Constructs the output writer as specified in the parameter file. | |
~GridOutputWriter () | |
void | gridFunctions (const std::vector< Int > &gfs) |
The given grid functions will be written to the output. | |
bool | open () |
Opens output data file for storing the results. | |
void | close () |
Closes the output file. | |
void | write (Int m, Real cur_t, Real &delta_t) |
Private Member Functions | |
void | write (Int m, Int nFrom, Int nTo, Int nSkip=1) |
Writes the results for a particular grid row to output. | |
Private Attributes | |
UniformGrid * | gridDriver |
bool | binaryFormat |
The grid-driver. | |
FILE * | outf |
Output stream for the results. | |
std::string | fileName |
Output filename. | |
std::string | prefixFileName |
Filename that is copied out (reversed) before start. | |
std::vector< Int > | output |
List of grid functions to write out. | |
std::deque< skipInfo > | skipSetter |
Apply new "skips" at the given time point. | |
Int | mSkip |
Output every mSkip rows. | |
Int | nOut |
Number of grid points to get in the output. | |
Int | nSkip |
Output every nSkip points. | |
Int | chunkSize |
Size (in bytes) of the output chunk. |
Writes checkpoints from the grid to the output data file.
Definition at line 12 of file gridOutput.h.
GridOutputWriter::GridOutputWriter | ( | Parameters & | params, |
UniformGrid & | ug | ||
) | [inline] |
Constructs the output writer as specified in the parameter file.
Definition at line 51 of file gridOutput.h.
References binaryFormat, chunkSize, GridOutputWriter::skipInfo::delta_t, fileName, Parameters::get(), GridOutputWriter::skipInfo::mSkip, mSkip, nOut, nSkip, output, prefixFileName, fld::r, skipSetter, slog, GridOutputWriter::skipInfo::t, and fld::t.
: gridDriver( &ug ), binaryFormat(false), outf(NULL) { output.reserve( 100 ); output.push_back( fld::t ); output.push_back( fld::r ); params.get( "output.file", fileName, "stdout" ); params.get( "output.binary", binaryFormat, true ); params.get( "output.prefix", prefixFileName, "" ); slog << "Output Writer:" << std::endl << std::endl << " file = " << fileName << ", binary = " << binaryFormat << std::endl << std::endl; params.get( "output.nOut", nOut, 10 ); params.get( "output.nSkip", nSkip, 1 ); params.get( "output.mSkip", mSkip, 1 ); chunkSize = 0; // still not defined slog << "Output Filter:" << std::endl << std::endl << " nOut = " << nOut << ", nSkip = " << nSkip << ", mSkip = " << mSkip << std::endl << std::endl; // Get skip setters // for( int i = 1; i < 10; ++i ) { std::string tag = "at" + std::to_string( i ); skipInfo info; params.get( tag + ".t", info.t, NAN ); params.get( tag + ".mSkip", info.mSkip, 1 ); params.get( tag + ".delta_t", info.delta_t, NAN ); if ( ! std::isnan( info.t ) ) { skipSetter.push_back( info ); } } if( skipSetter.size() > 0 ) { slog << "Skip Setter:" << std::endl << std::endl; for( auto i: skipSetter ) { slog << " t = " << i.t << ", mSkip = " << i.mSkip << ", delta_t = " << i.delta_t << std::endl; } slog << std::endl; } }
GridOutputWriter::~GridOutputWriter | ( | ) | [inline] |
void GridOutputWriter::close | ( | ) | [inline] |
Closes the output file.
Definition at line 167 of file gridOutput.h.
References outf.
Referenced by ~GridOutputWriter().
Int GridOutputWriter::get_mSkip | ( | ) | const [inline] |
Definition at line 41 of file gridOutput.h.
References mSkip.
Referenced by MoLIntegrator::integrate_AvgICN(), MoLIntegrator::integrate_MoL(), MoLIntegrator::MoLIntegrator(), and MoLIntegrator::reportIntegrationTime().
{ return mSkip; }
Int GridOutputWriter::get_nOut | ( | ) | const [inline] |
Definition at line 42 of file gridOutput.h.
References nOut.
Referenced by MoLIntegrator::integStep_Checkpoint().
{ return nOut; }
Int GridOutputWriter::get_nSkip | ( | ) | const [inline] |
void GridOutputWriter::gridFunctions | ( | const std::vector< Int > & | gfs | ) | [inline] |
bool GridOutputWriter::open | ( | ) | [inline] |
Opens output data file for storing the results.
Definition at line 115 of file gridOutput.h.
References binaryFormat, chunkSize, fileName, UniformGrid::get_grid(), UniformGrid::get_nGhost(), gridDriver, UniformGrid::mpiRank(), UniformGrid::mpiSize(), nOut, nSkip, outf, output, prefixFileName, and slog.
Referenced by main().
{ GridPoint** grid = gridDriver->get_grid (); Int nGhost = gridDriver->get_nGhost(); chunkSize = ( 2 * nGhost + nOut / nSkip ) * output.size() * sizeof(Real); if( fileName == "stdout" ) { binaryFormat = false; outf = stdout; return false; } if ( gridDriver->mpiSize() > 1 ) { outf = fopen( ( std::to_string( gridDriver->mpiRank() + 100 ) + "-" + fileName ).c_str(), binaryFormat ? "wb+" : "w+" ); } else { outf = fopen( fileName.c_str(), binaryFormat ? "wb+" : "w+" ); } if( binaryFormat && prefixFileName != "" ) { std::ifstream pref( prefixFileName, std::ios::in | std::ios::binary ); if( pref ) { slog << "*** Appending the reversed-t: " << prefixFileName << std::endl; pref.seekg( 0, std::ios::end ); // Go to end of file auto len = pref.tellg (); // Get the length of file (in bytes) if ( ( len % chunkSize ) != 0 ) { std::cerr << "Error: Invalid grid alignment." << std::endl; return false; } // While len > 0 means skip the last record (at t_0) for( len -= chunkSize; len > 0; len -= chunkSize ) { pref.seekg( len, std::ios::beg ); pref.read( (char*)&grid[0][0], chunkSize ); fwrite( &grid[0][0], chunkSize, 1, outf ); } pref.close (); } } return true; }
Int GridOutputWriter::recordSizeInBytes | ( | ) | const [inline] |
Retrieve the size (in bytes) of the output record.
Definition at line 47 of file gridOutput.h.
References chunkSize.
Referenced by MoLIntegrator::MoLIntegrator().
{ return chunkSize; }
void GridOutputWriter::write | ( | Int | m, |
Int | nFrom, | ||
Int | nTo, | ||
Int | nSkip = 1 |
||
) | [inline, private] |
Writes the results for a particular grid row to output.
Definition at line 31 of file gridOutput.h.
References binaryFormat, UniformGrid::get_grid(), gridDriver, nSkip, outf, output, and IORecord::write().
Referenced by MoLIntegrator::integStep_Checkpoint(), and write().
{ GridPoint* row = gridDriver->get_grid() [m]; for( Int n = nFrom; n < nTo; n += nSkip ) { IORecord( row[n] ).write( outf, binaryFormat, output ); } }
void GridOutputWriter::write | ( | Int | m, |
Real | cur_t, | ||
Real & | delta_t | ||
) | [inline] |
Definition at line 175 of file gridOutput.h.
References UniformGrid::get_nGhost(), UniformGrid::get_nLen(), gridDriver, mSkip, nOut, nSkip, skipSetter, slog, and write().
{ Int nLen = gridDriver->get_nLen (); Int nGhost = gridDriver->get_nGhost (); write( m, 0, nGhost ); write( m, nGhost, nGhost + (nLen < nOut ? nLen : nOut), nSkip ); write( m, nGhost + nLen, nGhost + nLen + nGhost ); if( skipSetter.size() > 0 && cur_t >= skipSetter.front().t ) { mSkip = skipSetter.front().mSkip; Real new_dt = skipSetter.front().delta_t; if( ! std::isnan( new_dt ) ) { delta_t = new_dt; slog << std::endl << std::endl << "*** at t = " << cur_t << " new mSkip = " << mSkip << ", delta_t = " << delta_t << std::endl << std::endl; } else { slog << std::endl << std::endl << "*** at t = " << cur_t << " new mSkip = " << mSkip << std::endl << std::endl; } skipSetter.pop_front (); } }
bool GridOutputWriter::binaryFormat [private] |
The grid-driver.
Write binary data to output file.
Definition at line 15 of file gridOutput.h.
Referenced by GridOutputWriter(), open(), and write().
Int GridOutputWriter::chunkSize [private] |
Size (in bytes) of the output chunk.
Definition at line 27 of file gridOutput.h.
Referenced by GridOutputWriter(), open(), and recordSizeInBytes().
std::string GridOutputWriter::fileName [private] |
Output filename.
Definition at line 17 of file gridOutput.h.
Referenced by GridOutputWriter(), and open().
UniformGrid* GridOutputWriter::gridDriver [private] |
Definition at line 14 of file gridOutput.h.
Int GridOutputWriter::mSkip [private] |
Output every mSkip
rows.
Definition at line 24 of file gridOutput.h.
Referenced by get_mSkip(), GridOutputWriter(), and write().
Int GridOutputWriter::nOut [private] |
Number of grid points to get in the output.
Definition at line 25 of file gridOutput.h.
Referenced by get_nOut(), GridOutputWriter(), open(), and write().
Int GridOutputWriter::nSkip [private] |
Output every nSkip
points.
Definition at line 26 of file gridOutput.h.
Referenced by get_nSkip(), GridOutputWriter(), open(), and write().
FILE* GridOutputWriter::outf [private] |
Output stream for the results.
Definition at line 16 of file gridOutput.h.
std::vector<Int> GridOutputWriter::output [private] |
List of grid functions to write out.
Definition at line 19 of file gridOutput.h.
Referenced by gridFunctions(), GridOutputWriter(), open(), and write().
std::string GridOutputWriter::prefixFileName [private] |
Filename that is copied out (reversed) before start.
Definition at line 18 of file gridOutput.h.
Referenced by GridOutputWriter(), and open().
std::deque<skipInfo> GridOutputWriter::skipSetter [private] |
Apply new "skips" at the given time point.
Definition at line 22 of file gridOutput.h.
Referenced by GridOutputWriter(), and write().