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

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>

Inheritance diagram for GridPoint:
Collaboration diagram for GridPoint:

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

Detailed Description

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.


Constructor & Destructor Documentation

GridPoint::GridPoint ( UniformGrid ug,
Int  mPos,
Int  nPos 
) [inline]

Definition at line 359 of file gridDriver.h.

        : GridUser( ug ), m( mPos ), n( nPos )
    {}

Member Function Documentation

void GridPoint::clear ( Real  value = NAN) [inline]

Resets all the variables to a specific value (by default NAN).

Definition at line 365 of file gridDriver.h.

    {
        for( Int gf = 0; gf < GFCNT; ++gf ) {
            GF( gf, m, n ) = value;
        }
    }
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.

Warning:
The order of fields in data[] (output data record) should match the Mathematica notebook!
Todo:
fld::output should be dynamic in ID class

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

Field Documentation

Int GridPoint::m [private]

Definition at line 356 of file gridDriver.h.

Int GridPoint::n [private]

Definition at line 356 of file gridDriver.h.


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