Exemplo n.º 1
0
Table::~Table( )
{
    // Make sure to write to rest of the entries to file before closing down.
    if( useStreamer_ )
    {
        zipWithTime( vec(), data_, lastTime_ );
        StreamerBase::writeToOutFile( outfile_, format_, "a", data_, columns_ );
        clearVec();
        data_.clear();
    }
}
Exemplo n.º 2
0
/**
 * @brief This function is called at its clock tick.
 *
 * @param e
 * @param p
 */
void Streamer::process(const Eref& e, ProcPtr p)
{
    //LOG( moose::debug, "Writing to table" );
    zipWithTime( );

    // Write only if there are more than 100 entry in first table.
    if( tables_[0]->getVecSize() > 100 )
    {
        StreamerBase::writeToOutFile( outfilePath_, format_, "a", data_, columns_ );
        data_.clear( );
    }
}
Exemplo n.º 3
0
/**
 * @brief Reinitialize
 *
 * @param e
 * @param p
 */
void Table::reinit( const Eref& e, ProcPtr p )
{
    tablePath_ = e.id().path();
    unsigned int numTick = e.element()->getTick();
    Clock* clk = reinterpret_cast<Clock*>(Id(1).eref().data());
    dt_ = clk->getTickDt( numTick );

    /** Create the default filepath for this table.  */
    if( useStreamer_ )
    {
        // The first column is variable time.
        columns_.push_back( "time" );
        // And the second column name is the name of the table.
        columns_.push_back( moose::moosePathToUserPath( tablePath_ ) );

        // If user has not set the filepath, then use the table path prefixed
        // with rootdit as path.
        if( ! outfileIsSet_ )
            setOutfile( rootdir_ +
                    moose::moosePathToUserPath(tablePath_) + '.' + format_ 
                    );
    }

    input_ = 0.0;
    vec().resize( 0 );
    lastTime_ = 0;
    vector< double > ret;
    requestOut()->send( e, &ret );
    vec().insert( vec().end(), ret.begin(), ret.end() );

    if( useStreamer_ )
    {
        zipWithTime( vec(), data_, lastTime_ );
        StreamerBase::writeToOutFile( outfile_, format_, "w", data_, columns_);
        clearVec();
        data_.clear();
        clearVec();
    }
}
Exemplo n.º 4
0
void Table::process( const Eref& e, ProcPtr p )
{
    lastTime_ = p->currTime;

    // Copy incoming data to ret and insert into vector.
    vector< double > ret;
    requestOut()->send( e, &ret );
    vec().insert( vec().end(), ret.begin(), ret.end() );

    /*  If we are streaming to a file, let's write to a file. And clean the
     *  vector.  
     *  Write at every 5 seconds or whenever size of vector is more than 10k.
     */
    if( useStreamer_ )
    {
        if( fmod(lastTime_, 5.0) == 0.0 or getVecSize() >= 10000 )
        {
            zipWithTime( vec(), data_, lastTime_ );
            StreamerBase::writeToOutFile( outfile_, format_ , "a", data_, columns_ );
            data_.clear();
            clearVec();
        }
    }
}
Exemplo n.º 5
0
/**
 * @brief This function is called from Shell when simulation is called to write
 * the left-over data to streamer file.
 */
void Streamer::cleanUp( )
{
    zipWithTime( );
    StreamerBase::writeToOutFile( outfilePath_, format_, "a", data_, columns_ );
    data_.clear( );
}
Exemplo n.º 6
0
/**
 * @brief Reinit.
 *
 * @param e
 * @param p
 */
void Streamer::reinit(const Eref& e, ProcPtr p)
{

    if( tables_.size() == 0 )
    {
        moose::showWarn( "Zero tables in streamer. Disabling Streamer" );
        e.element()->setTick( -2 );             /* Disable process */
        return;
    }

    Clock* clk = reinterpret_cast<Clock*>( Id(1).eref().data() );
    for (size_t i = 0; i < tableIds_.size(); i++)
    {
        int tickNum = tableIds_[i].element()->getTick();
        double tick = clk->getTickDt( tickNum );
        tableDt_.push_back( tick );
        // Make sure that all tables have the same tick.
        if( i > 0 )
        {
            if( tick != tableDt_[0] )
            {
                moose::showWarn( "Table " + tableIds_[i].path() + " has "
                        " different clock dt. "
                        " Make sure all tables added to Streamer have the same "
                        " dt value."
                        );
            }
        }
    }


    // Push each table dt_ into vector of dt
    for( size_t i = 0; i < tables_.size(); i++)
    {
        Id tId = tableIds_[i];
        int tickNum = tId.element()->getTick();
        tableDt_.push_back( clk->getTickDt( tickNum ) );
    }

    // Make sure all tables have same dt_ else disable the streamer.
    vector<unsigned int> invalidTables;
    for (size_t i = 1; i < tableTick_.size(); i++)
    {
        if( tableTick_[i] != tableTick_[0] )
        {
            LOG( moose::warning
                    , "Table " << tableIds_[i].path()
                    << " has tick (dt) which is different than the first table."
                    << endl
                    << " Got " << tableTick_[i] << " expected " << tableTick_[0]
                    << endl << " Disabling this table."
                    );
            invalidTables.push_back( i );
        }
    }

    for (size_t i = 0; i < invalidTables.size(); i++)
    {
        tables_.erase( tables_.begin() + i );
        tableDt_.erase( tableDt_.begin() + i );
        tableIds_.erase( tableIds_.begin() + i );
    }

    if( ! isOutfilePathSet_ )
    {
        string defaultPath = "_tables/" + moose::moosePathToUserPath( e.id().path() );
        setOutFilepath( defaultPath );
    }

    // Prepare data. Add columns names and write whatever values are available
    // write now.
    currTime_ = 0.0;
    zipWithTime( );
    StreamerBase::writeToOutFile( outfilePath_, format_, "w", data_, columns_);
    data_.clear( );
}