![]() |
Bimetric 3+1 toolkit for spherical symmetry
|
A wrapper for a grid point so that the all of the grid functions can be treated as a compound object when reading/writing. More...
#include <gridDriver.h>
Public Member Functions | |
GridPoint (UniformGrid &ug, Int mPos, Int nPos) | |
void | clear (Real value=NAN) |
Resets all the variables to a specific value (by default NAN). | |
bool | read (FILE *inf, bool isBinary, const std::vector< Int > &input) |
Reads the variable values from a file stream. | |
void | write (FILE *outf, bool isBinary, const std::vector< GF_Descriptor > output) |
Writes the variable values to a file stream. | |
Private Attributes | |
Int | m |
Int | n |
A wrapper for a grid point so that the all of the grid functions can be treated as a compound object when reading/writing.
Definition at line 354 of file gridDriver.h.
GridPoint::GridPoint | ( | UniformGrid & | ug, |
Int | mPos, | ||
Int | nPos | ||
) | [inline] |
Definition at line 359 of file gridDriver.h.
void GridPoint::clear | ( | Real | value = NAN | ) | [inline] |
bool GridPoint::read | ( | FILE * | inf, |
bool | isBinary, | ||
const std::vector< Int > & | input | ||
) | [inline] |
Reads the variable values from a file stream.
Definition at line 374 of file gridDriver.h.
{ auto len = input.size(); Real* data = (Real*)alloca( len * sizeof(Real) ); if( isBinary ) { if( len != fread( data, sizeof(data[0]), len, inf ) ) { std::cerr << "Error: Premature end of grid." << std::endl; return false; } } else { char* line = (char*)alloca( input.size() * 80 * sizeof(char) ); line[0] = '\0'; do { if( ! fgets( line, input.size() * 80 - 1, inf ) ) { std::cerr << "Error: Premature end of grid." << std::endl; return false; } } while( line[0] == '*' ); // Ignore comments (starting with '*') size_t count = sscanf_Real( line, data, len ); if( count != len ) { std::cerr << "Error: Wrong number of variables." << std::endl; return false; } } for( size_t gf = 0; gf < len; ++gf ) { GF( input[gf], m, n ) = data[gf]; } return true; }
void GridPoint::write | ( | FILE * | outf, |
bool | isBinary, | ||
const std::vector< GF_Descriptor > | output | ||
) | [inline] |
Writes the variable values to a file stream.
Definition at line 415 of file gridDriver.h.
{ auto len = output.size(); /// @todo fld::output should be dynamic in ID class Real* data = (Real*)alloca( len * sizeof(Real) ); for( size_t gf = 0; gf < len; ++gf ) { data[gf] = GF( output[gf].gf, m, n ); } if( isBinary ) { fwrite( data, sizeof(data[0]), len, outf ); } else { for( size_t i = 0; i < len; ++i ) { if ( i > 0 ) fputs( "\t", outf ); fputReal( outf, data[i] ); } fputs( "\n", outf ); } }
Int GridPoint::m [private] |
Definition at line 356 of file gridDriver.h.
Int GridPoint::n [private] |
Definition at line 356 of file gridDriver.h.