/// <summary>
        /// Ephemeris computation
        /// </summary>
        /// <param name="Y0"></param>
        /// <param name="N_Step"></param>
        /// <param name="Step"></param>
        /// <param name="p"></param>
        /// <param name="Eph"></param>
        static void Ephemeris(Geo.Algorithm.Vector Y0, int N_Step, double Step, ForceModelOption p, Geo.Algorithm.Vector[] Eph)
        {
            int          i;
            double       t, t_end;
            double       relerr, abserr;                      // Accuracy requirements
            DeIntegrator Orb = new DeIntegrator(Deriv, 6, p); // Object for integrating the eq. of motion

            Geo.Algorithm.Vector Y = new Geo.Algorithm.Vector(Y0);

            relerr = 1.0e-13;
            abserr = 1.0e-6;
            t      = 0.0;
            // Y = Y0;
            Orb.Init(t, relerr, abserr);
            for (i = 0; i <= N_Step; i++)
            {
                t_end = Step * i;
                var Yresult = Orb.Integ(t_end, Y);
                Eph[i] = Yresult;
            }
            ;
            //var prevObj = Eph[0];
            //Console.WriteLine(prevObj);
            //var last = Eph[Eph.Length -1];
            //Console.WriteLine(last);
        }
Пример #2
0
        static void Main0(string[] args)
        {
            // Constants

            const double GM    = 1.0;                                                          // Gravitational coefficient
            const double e     = 0.9;                                                          // Eccentricity
            const double t_end = 20.0;                                                         // End time

            Geo.Algorithm.Vector Kep   = new Geo.Algorithm.Vector(1.0, e, 0.0, 0.0, 0.0, 0.0); // (a,e,i,Omega,omega,M)
            Geo.Algorithm.Vector y_ref = Kepler.State(GM, Kep, t_end);                         // Reference solution

            // Variables

            double t;                                                        // Time
            double relerr, abserr;                                           // Accuracy requirements

            Geo.Algorithm.Vector y     = new Geo.Algorithm.Vector(6);        // State vector
            AuxDataRecord        Aux   = new AuxDataRecord();                // Auxiliary satData
            DeIntegrator         Orbit = new DeIntegrator(f_Kep6D_, 6, Aux); // Object for integrating the
            // differential equation
            // defined by f_Kep6D_
            // Header

            var info = "Exercise 4-3: Step size control of DE multistep method" + "\r\n";

            info += "  Step       t           h          r " + "\r\n";
            Console.WriteLine(info);
            // Initial values
            t = 0.0;
            y = new Geo.Algorithm.Vector(1.0 - e, 0.0, 0.0, 0.0, Math.Sqrt((1 + e) / (1 - e)), 0.0);

            Aux.n_step = 0;
            Aux.t      = 0;

            relerr = 0.0;
            abserr = 1.0e-8;

            // Integration from t=t to t=t_end
            Orbit.Init(t, relerr, abserr);
            Orbit.Integ(t_end, y);

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // Constants

            const double relerr = 1.0e-13;                                                                // Relative and absolute
            const double abserr = 1.0e-6;                                                                 // accuracy requirement

            const double a   = OrbitConsts.RadiusOfEarth + 650.0e3;                                       // Semi-major axis [m]
            const double e   = 0.001;                                                                     // Eccentricity
            const double inc = OrbitConsts.RadPerDeg * 51.0;                                              // Inclination [rad]

            double n = Math.Sqrt(OrbitConsts.GM_Earth / (a * a * a));                                     // Mean motion

            Matrix Scale = Matrix.CreateDiagonal(new Geo.Algorithm.Vector(1, 1, 1, 1 / n, 1 / n, 1 / n)); // Velocity
            Matrix scale = Matrix.CreateDiagonal(new Geo.Algorithm.Vector(1, 1, 1, n, n, n));             // normalization

            const double t_end = 86400.0;
            const double step  = 300.0;

            // Variables

            int       i, j;                                           // Loop counters
            double    Mjd0;                                           // Epoch (Modified Julian Date)
            double    t;                                              // Integration time [s]
            double    max, max_Kep;                                   // Matrix error norm
            AuxParam7 Aux1 = new AuxParam7(), Aux2 = new AuxParam7(); // Auxiliary parameter records

            // Model parameters for reference solution (full 10x10 gravity model) and
            // simplified variational equations

            // Epoch state and transition matrix

            Mjd0 = OrbitConsts.MJD_J2000;

            Aux1.Mjd_0 = Mjd0; // Reference epoch
            Aux1.n_a   = 10;   // Degree of gravity field for trajectory computation
            Aux1.m_a   = 10;   // Order of gravity field for trajectory computation
            Aux1.n_G   = 10;   // Degree of gravity field for variational equations
            Aux1.m_G   = 10;   // Order of gravity field for variational equations

            Aux2.Mjd_0 = Mjd0; // Reference epoch
            Aux2.n_a   = 2;    // Degree of gravity field for trajectory computation
            Aux2.m_a   = 0;    // Order of gravity field for trajectory computation
            Aux2.n_G   = 2;    // Degree of gravity field for variational equations
            Aux2.m_G   = 0;    // Order of gravity field for variational equations



            DeIntegrator Int1 = new DeIntegrator(VarEqn, 42, Aux1);                                          // Object for integrating the variat. eqns.
            DeIntegrator Int2 = new DeIntegrator(VarEqn, 42, Aux2);                                          //

            Geo.Algorithm.Vector y0 = new Geo.Algorithm.Vector(6), y = new Geo.Algorithm.Vector(6);          // State vector
            Geo.Algorithm.Vector yPhi1 = new Geo.Algorithm.Vector(42), yPhi2 = new Geo.Algorithm.Vector(42); // State and transition matrix vector
            Matrix Phi1 = new Matrix(6, 6), Phi2 = new Matrix(6, 6);                                         // State transition matrix
            Matrix Phi_Kep = new Matrix(6, 6);                                                               // State transition matrix (Keplerian)


            y0 = Kepler.State(OrbitConsts.GM_Earth, new Geo.Algorithm.Vector(a, e, inc, 0.0, 0.0, 0.0));

            for (i = 0; i <= 5; i++)
            {
                yPhi1[i] = y0[i];
                for (j = 0; j <= 5; j++)
                {
                    yPhi1[6 * (j + 1) + i] = (i == j ? 1 : 0);
                }
            }

            yPhi2 = new Geo.Algorithm.Vector(yPhi1);



            // Initialization

            t = 0.0;
            Int1.Init(t, relerr, abserr);
            Int2.Init(t, relerr, abserr);

            // Header
            var endl = "\r\n";
            var info = "Exercise 7-1: State transition matrix" + endl
                       + endl
                       + "  Time [s]  Error (J2)  Error(Kep)" + endl;

            // Steps

            while (t < t_end)
            {
                // New output time

                t += step;

                // Integration

                Int1.Integ(t, ref yPhi1); // Reference
                Int2.Integ(t, ref yPhi2); // Simplified

                //info= setprecision(5) + setw(12)+yPhi1 + endl;
                //info= setprecision(5) + setw(12) + yPhi2 + endl;


                // Extract and normalize state transition matrices

                for (j = 0; j <= 5; j++)
                {
                    Phi1.SetCol(j, yPhi1.Slice(6 * (j + 1), 6 * (j + 1) + 5));
                }
                for (j = 0; j <= 5; j++)
                {
                    Phi2.SetCol(j, yPhi2.Slice(6 * (j + 1), 6 * (j + 1) + 5));
                }

                Phi1 = Scale * Phi1 * scale;
                Phi2 = Scale * Phi2 * scale;

                // Keplerian state transition matrix (normalized)

                Kepler.TwoBody(OrbitConsts.GM_Earth, y0, t, ref y, ref Phi_Kep);
                Phi_Kep = Scale * Phi_Kep * scale;

                // Matrix error norms

                max     = Max(Matrix.CreateIdentity(6) - Phi1 * InvSymp(Phi2));
                max_Kep = Max(Matrix.CreateIdentity(6) - Phi1 * InvSymp(Phi_Kep));

                // Output
                //   info = String.Format( "{0, 10:F }{1, 10:F }{2, 10:F } ",  t,  max , max_Kep );
                info = String.Format("{0, 10:F2}{1, 10:F2}{2, 12:F2}", t, max, max_Kep);
                Console.WriteLine(info);
            }
            ;

            // Output

            info = endl
                   + "Time since epoch [s]" + endl
                   + endl
                   + String.Format("{0, 10:F}", t) + endl
                   + endl;
            Console.Write(info);
            info = "State transition matrix (reference)" + endl
                   + endl
                   + Phi1 + endl;
            Console.Write(info);
            info = "J2 State transition matrix" + endl
                   + endl
                   + Phi2 + endl;
            Console.Write(info);
            info = "Keplerian State transition matrix" + endl
                   + endl
                   + Phi_Kep + endl;
            Console.Write(info);

            Console.ReadKey();
        }