Bimetric 3+1 toolkit for spherical symmetry
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GridOutputWriter Class Reference

Writes checkpoints from the grid to the output data file. More...

#include <gridOutput.h>

Inheritance diagram for GridOutputWriter:
Collaboration diagram for GridOutputWriter:

Data Structures

struct  skipInfo
 skipInfo declares a time point at which to set a new mSkip and delta_t for the integration. More...

Public Member Functions

Int get_mSkip () const
Int get_nOut () const
Int get_nSkip () const
Int get_nFrom () const
Int get_nTo () const
Int recordSizeInBytes () const
 Retrieve the size (in bytes) of the output record.
Int GFCount () const
 Output size (number of grid functions).
 GridOutputWriter (Parameters &params, UniformGrid &ug)
 Constructs the output writer as specified in the parameter file.
 ~GridOutputWriter ()
void gridFunctions (const std::vector< GF_Descriptor > &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 writeHeader ()
 Writes the header to output file with the information about grid functions.
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

bool binaryFormat
 Write binary data to output file.
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< GF_Descriptoroutput
 List of grid functions to write out.
std::deque< skipInfoskipSetter
 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.
Int checkNaNs_nFrom
 Check for NaNs from this n
Int checkNaNs_nTo
 Check for NaNs to this n

Detailed Description

Writes checkpoints from the grid to the output data file.

Definition at line 15 of file gridOutput.h.


Constructor & Destructor Documentation

GridOutputWriter::GridOutputWriter ( Parameters params,
UniformGrid ug 
) [inline]

Constructs the output writer as specified in the parameter file.

Definition at line 66 of file gridOutput.h.

        : GridUser( ug ), binaryFormat(false), outf(NULL)
    {
        chunkSize = 0; // Still not defined

        output.reserve( 256 );
        output.push_back( { fld::t, "t", "t" } );
        output.push_back( { fld::r, "r", "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;

        params.get( "output.nOut",  nOut,  10 );
        params.get( "output.nSkip", nSkip,  1 );
        params.get( "output.mSkip", mSkip,  1 );

        slog << "    nOut = " << nOut << ",  nSkip = " << nSkip << ",  mSkip = " << mSkip
             << std::endl;

        params.get( "checkNaNs.nFrom", checkNaNs_nFrom, nOut*9/10 );
        params.get( "checkNaNs.nTo",   checkNaNs_nTo,   nOut      );

        if( checkNaNs_nTo >= 0 ) {
             slog << "    Check for NaNs: nFrom = " << checkNaNs_nFrom
                  << ",  nTo = " << checkNaNs_nTo << std::endl;
        }

        slog << 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;
        }
    }

Definition at line 125 of file gridOutput.h.

    {
        close ();
    }

Member Function Documentation

void GridOutputWriter::close ( ) [inline]

Closes the output file.

Definition at line 196 of file gridOutput.h.

    {
        if( outf != NULL ) {
            fclose( outf );
            outf = NULL;
        }
    }
Int GridOutputWriter::get_mSkip ( ) const [inline]

Definition at line 49 of file gridOutput.h.

{ return mSkip; }
Int GridOutputWriter::get_nFrom ( ) const [inline]

Definition at line 53 of file gridOutput.h.

{ return checkNaNs_nFrom;  }
Int GridOutputWriter::get_nOut ( ) const [inline]

Definition at line 50 of file gridOutput.h.

{ return nOut;  }
Int GridOutputWriter::get_nSkip ( ) const [inline]

Definition at line 51 of file gridOutput.h.

{ return nSkip; }
Int GridOutputWriter::get_nTo ( ) const [inline]

Definition at line 54 of file gridOutput.h.

{ return checkNaNs_nTo;    }
Int GridOutputWriter::GFCount ( ) const [inline]

Output size (number of grid functions).

Definition at line 62 of file gridOutput.h.

{ return output.size(); }
void GridOutputWriter::gridFunctions ( const std::vector< GF_Descriptor > &  gfs) [inline]

The given grid functions will be written to the output.

Definition at line 132 of file gridOutput.h.

    {
        output.insert( output.end(), gfs.begin(), gfs.end() );
        // slog << "    Added " << gfs.size () << " GFs to the output" << std::endl;
    }
bool GridOutputWriter::open ( ) [inline]

Opens output data file for storing the results.

Definition at line 140 of file gridOutput.h.

    {
        // Each record has two ghost regions in addition to the middle nOut/nSkip part
        //
        chunkSize = ( 2 * nGhost + nOut / nSkip ) * output.size() * sizeof(Real);

        if( fileName == "stdout" ) {
            binaryFormat = false;
            outf = stdout;
            return false;
        }

        // When using MPI, insert our rank number in the filename
        //
        if ( mpiSize() > 1 )
        {
            size_t lastdot = fileName.find_last_of( "." );
            fileName = fileName.substr( 0, lastdot ) + "-"
                       + std::to_string( 1000 + mpiRank() ).substr( 1 )
                       + fileName.substr( lastdot );
        }

        outf = mpiRank() >= 4 ? NULL
                : 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;
    }

Retrieve the size (in bytes) of the output record.

Definition at line 58 of file gridOutput.h.

{ 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 40 of file gridOutput.h.

    {
        for( Int n = nFrom; n < nTo; n += nSkip ) {
            GridPoint( *gridDriver, m, n ).write( outf, binaryFormat, output );
        }
    }
void GridOutputWriter::write ( Int  m,
Real  cur_t,
Real delta_t 
) [inline]

Definition at line 217 of file gridOutput.h.

    {
        if ( outf != NULL )
        {
            write( m, 0, nGhost );
            write( m, nGhost, nGhost + std::min( nLen, nOut ), nSkip );
            write( m, nGhost + nLen, nTotal );
        }

        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 ();
        }
    }
void GridOutputWriter::writeHeader ( ) [inline]

Writes the header to output file with the information about grid functions.

Definition at line 206 of file gridOutput.h.

    {
        if( outf != NULL )
        {
            for( auto f: output ) {
                fprintf( outf, "%s -> \"%s\"\n", f.name.c_str(), f.tex.c_str() );
            }
            fprintf( outf, "*** DATA ***\n");
        }
    }

Field Documentation

Write binary data to output file.

Definition at line 17 of file gridOutput.h.

Check for NaNs from this n

Definition at line 35 of file gridOutput.h.

Check for NaNs to this n

Definition at line 36 of file gridOutput.h.

Size (in bytes) of the output chunk.

Definition at line 33 of file gridOutput.h.

std::string GridOutputWriter::fileName [private]

Output filename.

Definition at line 19 of file gridOutput.h.

Output every mSkip rows.

Definition at line 30 of file gridOutput.h.

Number of grid points to get in the output.

Definition at line 31 of file gridOutput.h.

Output every nSkip points.

Definition at line 32 of file gridOutput.h.

FILE* GridOutputWriter::outf [private]

Output stream for the results.

Definition at line 18 of file gridOutput.h.

std::vector<GF_Descriptor> GridOutputWriter::output [private]

List of grid functions to write out.

Definition at line 21 of file gridOutput.h.

std::string GridOutputWriter::prefixFileName [private]

Filename that is copied out (reversed) before start.

Definition at line 20 of file gridOutput.h.

std::deque<skipInfo> GridOutputWriter::skipSetter [private]

Apply new "skips" at the given time point.

Definition at line 28 of file gridOutput.h.


The documentation for this class was generated from the following file: