Example #1
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();
    }
}
Example #2
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( );
}