Gowdy solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GridInitialData Class Reference

Reads the initial data from the given file. More...

#include <gridInitialData.h>

Collaboration diagram for GridInitialData:

Public Member Functions

 GridInitialData (Parameters &params, UniformGrid &ug)
 The list of grid functions.
void gridFunctions (const std::vector< Int > &gfs)
 The given grid functions will be read as the initial data.
bool load ()
 Loads the initial data.

Private Attributes

UniformGridgridDriver
 The grid.
bool binaryFormat
 Read binary data from the input file.
std::string fileName
 Input filename.
std::vector< Intinput

Detailed Description

Reads the initial data from the given file.

Definition at line 10 of file gridInitialData.h.


Constructor & Destructor Documentation

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

The list of grid functions.

Constructs the initial data reader as specified in the parameter file.

Definition at line 21 of file gridInitialData.h.

References binaryFormat, fileName, Parameters::get(), input, fld::r, and slog.

        : gridDriver(&ug), binaryFormat(false)
    {
        input.reserve( 100 );
        input.push_back( fld::r );

        params.get( "input.file",   fileName, "stdin" );
        params.get( "input.binary", binaryFormat, true );

        slog << "Initial Data:" << std::endl << std::endl
             << "    file = " << fileName << ",  binary = " << binaryFormat
             << std::endl << std::endl;
    }

Member Function Documentation

void GridInitialData::gridFunctions ( const std::vector< Int > &  gfs) [inline]

The given grid functions will be read as the initial data.

Definition at line 37 of file gridInitialData.h.

References input.

    {
        input.insert( input.end(), gfs.begin(), gfs.end() );
    }
bool GridInitialData::load ( ) [inline]

Loads the initial data.

Definition at line 44 of file gridInitialData.h.

References binaryFormat, fileName, UniformGrid::get_grid(), UniformGrid::get_nGhost(), UniformGrid::get_nLen(), gridDriver, input, UniformGrid::mpiRank(), UniformGrid::mpiSize(), and IORecord::read().

    {
        GridPoint** grid = gridDriver->get_grid ();
        Int nLen   = gridDriver->get_nLen ();
        Int nGhost = gridDriver->get_nGhost ();

        FILE* inf = fileName == "stdin" ? stdin
                  : fopen( fileName.c_str(), binaryFormat ? "rb" : "r" );
        if( ! inf ) {
            std::cerr << "Error: Could not open " << fileName << std::endl;
            return false;
        }

        // If using MPI, offset the initial data depending on our rank
        if ( gridDriver->mpiSize () > 1 )
        {
            for( Int n = 0; n < nLen * gridDriver->mpiRank(); ++n )
            {
                if( ! IORecord( grid[0][0] ).read( inf, binaryFormat, input ) ) { // dummy read
                    return false;
                }
            }
        }

        for( Int n = nGhost; n < nGhost + nLen; ++n )
        {
            if( ! IORecord( grid[0][n] ).read( inf, binaryFormat, input ) ) {
                return false;
            }
        }

        if ( inf != stdin ) {
            fclose( inf );
        }

        return true;
    }

Field Documentation

Read binary data from the input file.

Definition at line 13 of file gridInitialData.h.

Referenced by GridInitialData(), and load().

std::string GridInitialData::fileName [private]

Input filename.

Definition at line 14 of file gridInitialData.h.

Referenced by GridInitialData(), and load().

The grid.

Definition at line 12 of file gridInitialData.h.

Referenced by load().

std::vector<Int> GridInitialData::input [private]

Definition at line 15 of file gridInitialData.h.

Referenced by gridFunctions(), GridInitialData(), and load().


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