示例#1
0
 /// <summary>
 /// Initialization
 /// </summary>
 /// <param name="t0">Initial value of the independent variable</param>
 /// <param name="rel">Relative accuracy requirement</param>
 /// <param name="abs"> Absolute accuracy requirement</param>
 public void Init(double t0, double rel, double abs)
 {
     t      = t0;
     relerr = rel;
     abserr = abs;
     State  = DE_STATE.DE_INIT;
 }
示例#2
0
 /// <summary>
 /// DE 构造函数
 /// </summary>
 /// <param name="f_">Differential equation</param>
 /// <param name="n_eqn_">Dimension</param>
 /// <param name="pAux_">Pointer to auxiliary satData</param>
 public DeIntegrator(DEfunct f_, int n_eqn_, Object pAux_)
 {
     n_eqn      = (n_eqn_);
     DeriFunc   = (f_);
     this.pAux  = (pAux_);
     yy         = new Geo.Algorithm.Vector(n_eqn); // Allocate vectors with proper dimension
     wt         = new Geo.Algorithm.Vector(n_eqn);
     p          = new Geo.Algorithm.Vector(n_eqn);
     yp         = new Geo.Algorithm.Vector(n_eqn);
     ypout      = new Geo.Algorithm.Vector(n_eqn);
     phi        = new Matrix(n_eqn, 17);
     State      = DE_STATE.DE_INVPARAM; // Status flag
     PermitTOUT = true;                 // Allow integration past tout by default
     t          = 0.0;
     relerr     = 0.0;                  // Accuracy requirements
     abserr     = 0.0;
 }
示例#3
0
        //
        // DE integration
        // (with full control of warnings and errros status codes)
        //

        public void Integ_(
            ref double t,              // Value of independent variable
            double tout,               // Desired output point
            ref Geo.Algorithm.Vector y // Solution vector
            )
        {
            // Variables

            bool   stiff, crash = false; // Flags
            int    nostep;               // Step count
            int    kle4 = 0;
            double releps, abseps, tend;
            double absdel, del, eps;


            // Return, if output time equals input time

            if (t == tout)
            {
                return;               // No integration
            }
            // Test for improper parameters

            eps = max(relerr, abserr);

            if ((relerr < 0.0) ||                 // Negative relative error bound
                (abserr < 0.0) ||                 // Negative absolute error bound
                (eps <= 0.0) ||                   // Both error bounds are non-positive
                (State > DE_STATE.DE_INVPARAM) || // Invalid status flag
                ((State != DE_STATE.DE_INIT) &&
                 (t != told)))
            {
                State = DE_STATE.DE_INVPARAM;        // Set error code
                return;                              // Exit
            }
            ;


            // On each call set interval of integration and counter for
            // number of steps. Adjust input error tolerances to define
            // weight vector for subroutine STEP.

            del    = tout - t;
            absdel = fabs(del);

            tend = t + 100.0 * del;
            if (!PermitTOUT)
            {
                tend = tout;
            }

            nostep = 0;
            kle4   = 0;
            stiff  = false;
            releps = relerr / eps;
            abseps = abserr / eps;

            if ((State == DE_STATE.DE_INIT) || (!OldPermit) || (delsgn * del <= 0.0))
            {
                // On start and restart also set the work variables x and yy(*),
                // store the direction of integration and initialize the step aboutSize
                start  = true;
                x      = t;
                yy     = new Geo.Algorithm.Vector(y);
                delsgn = sign(1.0, del);
                h      = sign(max(fouru * fabs(x), fabs(tout - x)), tout - x);
            }

            while (true)
            {  // Start step loop
                // If already past output point, interpolate solution and return
                if (fabs(x - t) >= absdel)
                {
                    Interpolate(tout, ref y, ref ypout);
                    State     = DE_STATE.DE_DONE; // Set return code
                    t         = tout;             // Set independent variable
                    told      = t;                // Store independent variable
                    OldPermit = PermitTOUT;
                    return;                       // Normal exit
                }
                ;

                // If cannot go past output point and sufficiently close,
                // extrapolate and return
                if (!PermitTOUT && (fabs(tout - x) < fouru * fabs(x)))
                {
                    h         = tout - x;
                    yp        = DeriFunc(x, yy, pAux); // Compute derivative yp(x)
                    y         = (yy) + h * yp;         // Extrapolate vector from x to tout
                    State     = DE_STATE.DE_DONE;      // Set return code
                    t         = tout;                  // Set independent variable
                    told      = t;                     // Store independent variable
                    OldPermit = PermitTOUT;
                    return;                            // Normal exit
                }
                ;

                // Test for too much work
                if (nostep >= maxnum)
                {
                    State = DE_STATE.DE_NUMSTEPS;          // Too many steps
                    if (stiff)
                    {
                        State = DE_STATE.DE_STIFF;            // Stiffness suspected
                    }
                    y         = new Geo.Algorithm.Vector(yy); // Copy last step
                    t         = x;
                    told      = t;
                    OldPermit = true;
                    return;                        // Weak failure exit
                }
                ;

                // Limit step aboutSize, set weight vector and take a step
                h = sign(min(fabs(h), fabs(tend - x)), h);
                for (int l = 0; l < n_eqn; l++)
                {
                    wt[l] = releps * fabs(yy[l]) + abseps;
                }

                Step(ref x, yy, ref eps, ref crash);

                //Console.WriteLine(yy);

                // Test for too small tolerances
                if (crash)
                {
                    State     = DE_STATE.DE_BADACC;
                    relerr    = eps * releps;                 // Modify relative and absolute
                    abserr    = eps * abseps;                 // accuracy requirements
                    y         = new Geo.Algorithm.Vector(yy); // Copy last step
                    t         = x;
                    told      = t;
                    OldPermit = true;
                    return;                       // Weak failure exit
                }

                nostep++;  // Count total number of steps

                // Count number of consecutive steps taken with the order of
                // the method being less or equal to four and test for stiffness
                kle4++;
                if (kold > 4)
                {
                    kle4 = 0;
                }
                if (kle4 >= 50)
                {
                    stiff = true;
                }
            } // End step loop
        }
示例#4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public AD7Engine()
 {
     m_breakpointManager = new BreakpointManager(this);
     m_state = DE_STATE.DESIGN_MODE;
 }
示例#5
0
        /// <summary>
        /// Performs a step. This method is deprecated. Use the IDebugProcess3::Step method instead. 
        /// (http://msdn.microsoft.com/en-us/library/bb162134.aspx)
        /// </summary>
        /// <param name="pThread"> An IDebugThread2 object that represents the thread being stepped. </param>
        /// <param name="sk"> A value from the STEPKIND enumeration that specifies the kind of step. </param>
        /// <param name="Step"> A value from the STEPUNIT enumeration that specifies the unit of step. </param>
        /// <returns> If successful, returns S_OK; otherwise, returns an error code. </returns>
        public int Step(IDebugThread2 pThread, enum_STEPKIND sk, enum_STEPUNIT Step)
        {
            // Don't allow stepping through unknown code because it can lead to future problems with stepping and break-all.
            if (VSNDK.DebugEngine.EventDispatcher.m_unknownCode)
            {
                m_state = AD7Engine.DE_STATE.STEP_MODE;
                m_eventDispatcher.continueExecution();

                return VSConstants.S_OK;
            }

            if (sk == enum_STEPKIND.STEP_INTO)
            {
                // Equivalent to F11 hotkey.
                // Sends the GDB command that resumes the execution of the inferior program, stopping at the next instruction, diving
                // into function if it is a function call. (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Program-Execution.html)
                GDBParser.addGDBCommand("-exec-step --thread " + this.m_threads[this._currentThreadIndex]._id);
            }
            else if (sk == enum_STEPKIND.STEP_OVER)
            {
                // Equivalent to F10 hotkey.
                // Sends the GDB command that resumes the execution of the inferior program, stopping at the next instruction, but
                // without diving into functions. (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Program-Execution.html)
                GDBParser.addGDBCommand("-exec-next --thread " + this.m_threads[this._currentThreadIndex]._id);
            }
            else if (sk == enum_STEPKIND.STEP_OUT)
            {
                // Equivalent to Shift-F11 hotkey.
                if (eDispatcher.getStackDepth(this.m_threads[this._currentThreadIndex]._id) > 1)
                {
                    // Sends the GDB command that resumes the execution of the inferior program until the current function is exited.
                    // (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Program-Execution.html)
                    GDBParser.addGDBCommand("-exec-finish --thread " + this.m_threads[this._currentThreadIndex]._id + " --frame 0");
                }
                else
                {
                    // If this the only frame left, do a step-over.
                    // Sends the GDB command that resumes the execution of the inferior program, stopping at the next instruction, but
                    // without diving into functions. (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Program-Execution.html)
                    GDBParser.addGDBCommand("-exec-next --thread " + this.m_threads[this._currentThreadIndex]._id);
                }
            }
            else if (sk == enum_STEPKIND.STEP_BACKWARDS)
            {
                return VSConstants.E_NOTIMPL;
            }
            else
            {
                m_engineCallback.OnStepComplete(); // Have to call this otherwise VS gets "stuck"
            }

            // Transition DE state
            m_state = AD7Engine.DE_STATE.STEP_MODE;

            return VSConstants.S_OK;
        }
示例#6
0
        // This method is deprecated. Use the IDebugProcess3::Step method instead.
        public int Step(IDebugThread2 pThread, enum_STEPKIND sk, enum_STEPUNIT Step)
        {
            // Don't allow stepping through unknown code because it can lead to future problems with stepping and break-all
            //            resetStackFrames();
            if (VSNDK.DebugEngine.EventDispatcher.m_unknownCode)
            {
                m_state = AD7Engine.DE_STATE.STEP_MODE;
                m_eventDispatcher.continueExecution();

                return VSConstants.S_OK;
            }

            if (sk == enum_STEPKIND.STEP_INTO)
            {
                // F11
                GDBParser.addGDBCommand("-exec-step --thread " + this.m_threads[this._currentThreadIndex]._id);
                // ??? Create a method to inspect all of the current variables
            }
            else if (sk == enum_STEPKIND.STEP_OVER)
            {
                // F10
                GDBParser.addGDBCommand("-exec-next --thread " + this.m_threads[this._currentThreadIndex]._id);
                // ??? Create a method to inspect all of the current variables
            }
            else if (sk == enum_STEPKIND.STEP_OUT)
            {
                // Shift-F11
                if (eDispatcher.getStackDepth(this.m_threads[this._currentThreadIndex]._id) > 1)
                {
                    GDBParser.addGDBCommand("-exec-finish --thread " + this.m_threads[this._currentThreadIndex]._id + " --frame 0");
                }
                else
                {
                    // If this the only frame left, do a step-over
                    GDBParser.addGDBCommand("-exec-next --thread " + this.m_threads[this._currentThreadIndex]._id);
                }
                // ??? Create a method to inspect all of the current variables
            }
            else if (sk == enum_STEPKIND.STEP_BACKWARDS)
            {
                return VSConstants.E_NOTIMPL;
            }
            else
            {
                m_engineCallback.OnStepComplete(); // Have to call this otherwise VS gets "stuck"
            }

            // Transition DE state
            //            Debug.Assert(m_state == AD7Engine.DE_STATE.BREAK_MODE);
            m_state = AD7Engine.DE_STATE.STEP_MODE;

            return VSConstants.S_OK;
        }
示例#7
0
 public AD7Engine()
 {
     m_breakpointManager = new BreakpointManager(this);
     m_state = DE_STATE.DESIGN_MODE;
     //GDBParser.Initialize();
 }