示例#1
0
        /// <summary>
        /// Predict a new solution based on the previous ones
        /// </summary>
        /// <param name="ckt">The circuit</param>
        public override void Predict(Circuit ckt)
        {
            // Get the state
            var state = ckt.State.Real;

            // Predict a solution
            double          a, b;
            Vector <double> dd0, dd1;

            switch (Order)
            {
            case 1:
                // Divided difference approach
                dd0        = (Solutions[0] - Solutions[1]) / DeltaOld[1];
                Prediction = Solutions[0] + DeltaOld[0] * dd0;
                Prediction.CopyTo(state.Solution);
                break;

            case 2:
                // Adams-Bashforth method (second order for variable timesteps)
                b          = -DeltaOld[0] / (2.0 * DeltaOld[1]);
                a          = 1 - b;
                dd0        = (Solutions[0] - Solutions[1]) / DeltaOld[1];
                dd1        = (Solutions[1] - Solutions[2]) / DeltaOld[2];
                Prediction = Solutions[0] + (b * dd1 + a * dd0) * DeltaOld[0];
                Prediction.CopyTo(state.Solution);
                break;

            default:
                throw new CircuitException("Invalid order");
            }
        }