/*!
   \brief Calculate a scale division

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.
*/
QwtScaleDiv ProbabilityScaleEngine::divideScale(double x1, double x2,
    int, int, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    interval = interval.limited(1e-4, 99.999);

    if (interval.width() <= 0 )
        return QwtScaleDiv();

    stepSize = fabs(qRound(stepSize));
    if ( stepSize == 0.0 )
        stepSize = 1.0;

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 ){
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
		buildTicks(interval, stepSize, ticks);
        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Ejemplo n.º 2
0
void Clock::handleStep( const Eref& e, unsigned int numSteps )
{
	if ( isRunning_ || doingReinit_ ) {
		cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
		return;
	}
	buildTicks( e );
	assert( currentStep_ == nSteps_ );
	assert( activeTicks_.size() == activeTicksMap_.size() );
	nSteps_ += numSteps;
	runTime_ = nSteps_ * dt_;
	for ( isRunning_ = true;
		isRunning_ && currentStep_ < nSteps_; ++currentStep_ )
	{
		// Curr time is end of current step.
		unsigned int endStep = currentStep_ + 1;
		currentTime_ = info_.currTime = dt_ * endStep;
		vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
		for ( vector< unsigned int>::iterator j = 
			activeTicks_.begin(); j != activeTicks_.end(); ++j ) {
			if ( endStep % *j == 0 ) {
				info_.dt = *j * dt_;
				processVec()[*k]->send( e, &info_ );
			}
			++k;
		}
	}
	info_.dt = dt_;
	isRunning_ = false;
	finished()->send( e );
}
Ejemplo n.º 3
0
/**
 * This is the dest function that sets off the reinit.
 */
void Clock::handleReinit( const Eref& e )
{
    if ( isRunning_ || doingReinit_ )
    {
        cout << "Clock::handleReinit: Warning: simulation already in progress.\n Command ignored\n";
        return;
    }
    currentTime_ = 0.0;
    currentStep_ = 0;
    nSteps_ = 0;
    buildTicks( e );
    doingReinit_ = true;
    // Curr time is end of current step.
    info_.currTime = 0.0;
    vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
    for ( vector< unsigned int>::iterator j =
                activeTicks_.begin(); j != activeTicks_.end(); ++j )
    {
        info_.dt = *j * dt_;
        reinitVec()[*k++]->send( e, &info_ );
    }

    info_.dt = dt_;
    doingReinit_ = false;
}
Ejemplo n.º 4
0
/*!
   \brief Calculate a scale division

   \param x1 First interval limit 
   \param x2 Second interval limit 
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.

   \sa QwtScaleEngine::stepSize(), QwtScaleEngine::subDivide()
*/
QwtScaleDiv QwtLinearScaleEngine::divideScale(double x1, double x2,
    int maxMajSteps, int maxMinSteps, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    if (interval.width() <= 0 )
        return QwtScaleDiv();

    stepSize = qwtAbs(stepSize);
    if ( stepSize == 0.0 )
    {
        if ( maxMajSteps < 1 )
            maxMajSteps = 1;

        stepSize = divideInterval(interval.width(), maxMajSteps);
    }

    QwtScaleDiv scaleDiv;

    if ( stepSize != 0.0 )
    {
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
        buildTicks(interval, stepSize, maxMinSteps, ticks);

        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Ejemplo n.º 5
0
/*!
   \brief Calculate a scale division for an interval

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajorSteps Maximum for the number of major steps
   \param maxMinorSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the engine
                   calculates one.

   \return Calculated scale division
*/
QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2,
    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
{
    QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() <= 0 )
        return QwtScaleDiv();

    const double logBase = base();

    if ( interval.maxValue() / interval.minValue() < logBase )
    {
        // scale width is less than one decade -> build linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes( attributes() );
        linearScaler.setReference( reference() );
        linearScaler.setMargins( lowerMargin(), upperMargin() );

        if ( stepSize != 0.0 )
        {
            if ( stepSize < 0.0 )
                stepSize = -qPow( logBase, -stepSize );
            else
                stepSize = qPow( logBase, stepSize );
        }

        return linearScaler.divideScale( x1, x2,
            maxMajorSteps, maxMinorSteps, stepSize );
    }

    stepSize = qAbs( stepSize );
    if ( stepSize == 0.0 )
    {
        if ( maxMajorSteps < 1 )
            maxMajorSteps = 1;

        stepSize = divideInterval( 
            qwtLogInterval( logBase, interval ).width(), maxMajorSteps );
        if ( stepSize < 1.0 )
            stepSize = 1.0; // major step must be >= 1 decade
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 )
    {
        QList<double> ticks[QwtScaleDiv::NTickTypes];
        buildTicks( interval, stepSize, maxMinorSteps, ticks );

        scaleDiv = QwtScaleDiv( interval, ticks );
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Ejemplo n.º 6
0
void Clock::handleStep( const Eref& e, unsigned long numSteps )
{
    numSteps *= stride_;
    if ( isRunning_ || doingReinit_ )
    {
        cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
        return;
    }

    time_t rawtime;
    struct tm * timeinfo;
    char now[80];

    buildTicks( e );
    assert( currentStep_ == nSteps_ );
    assert( activeTicks_.size() == activeTicksMap_.size() );
    nSteps_ += numSteps;
    runTime_ = nSteps_ * dt_;
    for ( isRunning_ = (activeTicks_.size() > 0 );
            isRunning_ && currentStep_ < nSteps_; currentStep_ += stride_ )
    {
        // Curr time is end of current step.
        unsigned long endStep = currentStep_ + stride_;
        currentTime_ = info_.currTime = dt_ * endStep;
        vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
        for ( vector< unsigned int>::iterator j =
                    activeTicks_.begin(); j != activeTicks_.end(); ++j )
        {
            if ( endStep % *j == 0 )
            {
                info_.dt = *j * dt_;
                processVec()[*k]->send( e, &info_ );
            }
            ++k;
        }

        // When 10% of simulation is over, notify user when notify_ is set to
        // true.
        if( notify_ )
        {
            if( fmod(100 * currentTime_ / runTime_ , 10.0) == 0.0 )
            {
                time( &rawtime );
                timeinfo = localtime( &rawtime );
                strftime(now, 80, "%c", timeinfo);
                cout << "@ " << now << ": " << 100 * currentTime_ / runTime_ 
                    << "% of total " << runTime_ << " seconds is over." << endl;
            }
        }
    }
	if ( activeTicks_.size() == 0 )
		currentTime_ = runTime_;

    info_.dt = dt_;
    isRunning_ = false;
    finished()->send( e );
}
/*!
   \brief Calculate a scale division

   \param x1 First interval limit 
   \param x2 Second interval limit 
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.

   \sa QwtScaleEngine::stepSize, LogTimeScaleEngine::subDivide
*/
QwtScaleDiv LogTimeScaleEngine::divideScale(double x1, double x2,
    int maxMajSteps, int maxMinSteps, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() <= 0 )
        return QwtScaleDiv();

    if (interval.maxValue() / interval.minValue() < 10.0)
    {
        // scale width is less than one decade -> build linear scale
    
        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes(attributes());
        linearScaler.setReference(reference());
        linearScaler.setMargins(
                                #if (QWT_VERSION >= 0x050200)
				lowerMargin(), upperMargin()
				#else
				loMargin(), hiMargin()
				#endif
				);

        return linearScaler.divideScale(x1, x2, 
            maxMajSteps, maxMinSteps, stepSize);
    }

    stepSize = qwtAbs(stepSize);
    if ( stepSize == 0.0 )
    {
        if ( maxMajSteps < 1 )
            maxMajSteps = 1;

        stepSize = divideInterval(log10(interval).width(), maxMajSteps);
        if ( stepSize < 1.0 )
            stepSize = 1.0; // major step must be >= 1 decade
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 )
    {
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
        buildTicks(interval, stepSize, maxMinSteps, ticks);

        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
/*!
   \brief Calculate a scale division

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.
*/
QwtScaleDiv Log2ScaleEngine::divideScale(double x1, double x2,
    int maxMajSteps, int maxMinSteps, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() <= 0 )
        return QwtScaleDiv();

    if (interval.maxValue() / interval.minValue() < 2){
        // scale width is less than 2 -> build linear scale
        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes(attributes());
        linearScaler.setReference(reference());
        linearScaler.setMargins(lowerMargin(), upperMargin());

        return linearScaler.divideScale(x1, x2,
            maxMajSteps, maxMinSteps, stepSize);
    }

    stepSize = qwtAbs(stepSize);
    if ( stepSize == 0.0 ){
        if ( maxMajSteps < 1 )
            maxMajSteps = 1;

		stepSize = ceil(log2(interval).width()/double(maxMajSteps));
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 ){
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
		buildTicks(interval, stepSize, maxMinSteps, ticks);
        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Ejemplo n.º 9
0
/*!
   \brief Calculate a scale division for an interval

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajorSteps Maximum for the number of major steps
   \param maxMinorSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the engine
                   calculates one.

   \return Calculated scale division
*/
QwtScaleDiv QwtLinearScaleEngine::divideScale( double x1, double x2,
    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
{
    QwtInterval interval = QwtInterval( x1, x2 ).normalized();

    if ( qwtIntervalWidthL( interval ) > std::numeric_limits<double>::max() )
    {
        qWarning() << "QwtLinearScaleEngine::divideScale: overflow";
        return QwtScaleDiv();
    }

    if ( interval.width() <= 0 )
        return QwtScaleDiv();

    stepSize = qAbs( stepSize );
    if ( stepSize == 0.0 )
    {
        if ( maxMajorSteps < 1 )
            maxMajorSteps = 1;

        stepSize = QwtScaleArithmetic::divideInterval( 
            interval.width(), maxMajorSteps, base() );
    }

    QwtScaleDiv scaleDiv;

    if ( stepSize != 0.0 )
    {
        QList<double> ticks[QwtScaleDiv::NTickTypes];
        buildTicks( interval, stepSize, maxMinorSteps, ticks );

        scaleDiv = QwtScaleDiv( interval, ticks );
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Ejemplo n.º 10
0
void Clock::handleStep( const Eref& e, unsigned long numSteps )
{
    numSteps *= stride_;
    if ( isRunning_ || doingReinit_ )
    {
        cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
        return;
    }

    time_t rawtime;
    struct tm * timeinfo;
    char now[80];

    buildTicks( e );
    assert( currentStep_ == nSteps_ );
    assert( activeTicks_.size() == activeTicksMap_.size() );
    nSteps_ += numSteps;
    runTime_ = nSteps_ * dt_;
    for ( isRunning_ = (activeTicks_.size() > 0 );
            isRunning_ && currentStep_ < nSteps_; currentStep_ += stride_ )
    {
        // Curr time is end of current step.
        unsigned long endStep = currentStep_ + stride_;
        currentTime_ = info_.currTime = dt_ * endStep;

#if PARALLELIZE_CLOCK_USING_CPP11_ASYNC

        // NOTE: It does not produce very promising results. The challenge here
        // is doing load-balancing.
        // TODO: To start with, we can put one solver on one thread and everything
        // else onto 1 thread. Each Hsove, Ksolve, and Gsolve can take its own
        // thread and rest are on different threads.

        unsigned int nTasks = activeTicks_.size( );
        unsigned int numThreads_ = 3;
        unsigned int blockSize = 1 + (nTasks / numThreads_);

        for( unsigned int i = 0; i < numThreads_; ++i  )
        {
            std::async( std::launch::async
                        , [this,blockSize,i,nTasks,endStep,e]
            {
                unsigned int mapI = i * blockSize;
                // Get the block we want to run in paralle.
                for( unsigned int ii = i * blockSize; ii < min((i+1) * blockSize, nTasks); ii++ )
                {
                    unsigned int j = activeTicks_[ ii ];
                    if( endStep % j == 0  )
                    {
                        info_.dt = j * dt_;
                        processVec( )[ activeTicksMap_[mapI] ]->send( e, &info_ );
                    }
                    mapI++;
                }
            }
                      );
        }
#else
        vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
        for ( vector< unsigned int>::iterator j =
                    activeTicks_.begin(); j != activeTicks_.end(); ++j )
        {
            if ( endStep % *j == 0 )
            {
                info_.dt = *j * dt_;
                processVec()[*k]->send( e, &info_ );
            }
            ++k;
        }
#endif

        // When 10% of simulation is over, notify user when notify_ is set to
        // true.
        if( notify_ )
        {
            if( fmod(100 * currentTime_ / runTime_, 10.0) == 0.0 )
            {
                time( &rawtime );
                timeinfo = localtime( &rawtime );
                strftime(now, 80, "%c", timeinfo);
                cout << "@ " << now << ": " << 100 * currentTime_ / runTime_
                     << "% of total " << runTime_ << " seconds is over." << endl;
            }
        }

        if ( activeTicks_.size() == 0 )
            currentTime_ = runTime_;
    }

    info_.dt = dt_;
    isRunning_ = false;
    finished()->send( e );
}
Ejemplo n.º 11
0
void QniteTicker::doBuildTicks() {
  buildTicks();
  emit tickersBuilt();
}