Esempio n. 1
0
        private void rollbackImpl(ref object o, double from, double to, int steps, IStepCondition <Vector> condition)
        {
            Utils.QL_REQUIRE(from >= to, () => "trying to roll back from " + from + " to " + to);

            double dt = (from - to) / steps, t = from;

            evolver_.setStep(dt);

            for (int i = 0; i < steps; ++i, t -= dt)
            {
                double now = t, next = t - dt;
                bool   hit = false;
                for (int j = stoppingTimes_.Count - 1; j >= 0; --j)
                {
                    if (next <= stoppingTimes_[j] && stoppingTimes_[j] < now)
                    {
                        // a stopping time was hit
                        hit = true;

                        // perform a small step to stoppingTimes_[j]...
                        evolver_.setStep(now - stoppingTimes_[j]);
                        evolver_.step(ref o, now);
                        if (condition != null)
                        {
                            condition.applyTo(o, stoppingTimes_[j]);
                        }
                        // ...and continue the cycle
                        now = stoppingTimes_[j];
                    }
                }
                // if we did hit...
                if (hit)
                {
                    // ...we might have to make a small step to
                    // complete the big one...
                    if (now > next)
                    {
                        evolver_.setStep(now - next);
                        evolver_.step(ref o, now);
                        if (condition != null)
                        {
                            condition.applyTo(o, next);
                        }
                    }
                    // ...and in any case, we have to reset the
                    // evolver to the default step.
                    evolver_.setStep(dt);
                }
                else
                {
                    // if we didn't, the evolver is already set to the
                    // default step, which is ok for us.
                    evolver_.step(ref o, now);
                    if (condition != null)
                    {
                        condition.applyTo(o, next);
                    }
                }
            }
        }
Esempio n. 2
0
 protected virtual void initializeStepCondition()
 {
     if (stepConditionImpl_ == null)
     {
         throw new NotSupportedException();
     }
     else
     {
         stepCondition_ = stepConditionImpl_();
     }
 }
Esempio n. 3
0
 protected virtual void initializeStepCondition()
 {
     if (stepConditionImpl_ == null)
     {
         stepCondition_ = new NullCondition <Vector>();
     }
     else
     {
         stepCondition_ = stepConditionImpl_();
     }
 }
Esempio n. 4
0
 public void rollback(ref object a, double from, double to, int steps, IStepCondition <Vector> condition)
 {
     rollbackImpl(ref a, from, to, steps, condition);
 }