Beispiel #1
0
    virtual void updateInternalState( Real aStepInterval )
    {
        const VariableVector::size_type aSize( getReadOnlyVariableOffset() );

        clearVariables();

        fireProcesses();
        setVariableVelocity( theTaylorSeries[ 0 ] );

        DifferentialStepper::updateInternalState( aStepInterval );
    }
void AdaptiveDifferentialStepper::updateInternalState( Real aStepInterval )
{
    theStateFlag = false;

    clearVariables();

    Integer theRejectedStepCounter( 0 );

    while ( !calculate( aStepInterval ) )
    {
        if ( ++theRejectedStepCounter >= theTolerableRejectedStepCount )
        {
            THROW_EXCEPTION_INSIDE( SimulationError,
                String( "The times of rejections of step calculation "
                    "exceeded a maximum tolerable count (" )
                + stringCast( theTolerableRejectedStepCount ) + ")." );
        }
 
        // shrink it if the error exceeds 110%
        aStepInterval = aStepInterval * safety * std::pow( getMaxErrorRatio(),
                                                  -1.0 / getOrder() );
    }

    const Real maxError( getMaxErrorRatio() );

    // an extra calculation for resetting the activities of processes
    fireProcesses();

    setTolerableStepInterval( aStepInterval );

    theStateFlag = true;

    // grow it if error is 50% less than desired
    Real aNewStepInterval( aStepInterval );
    if ( maxError < 0.5 )
    {
        aNewStepInterval = aNewStepInterval * safety * std::pow( maxError,
                                            -1.0 / ( getOrder() + 1 ) );
    }

    setNextStepInterval( aNewStepInterval );

    DifferentialStepper::updateInternalState( aStepInterval );
}