Esempio n. 1
0
 public void Add(Ephemeris e)
 {
     list.Add(e);
     e.MinDate     = DateTime.MinValue;
     e.MaxDate     = DateTime.MaxValue;
     isInitialized = false;
 }
Esempio n. 2
0
        private void loadEphemeres(bool AllowLoadSnapshot)
        {
            this.availableEphemeres = Ephemeris.LoadCatalog();

            foreach (var fi in IO.EnumerateFiles(DirectoryLocation.Data, "ephemeris*.txt"))
            {
                if (fi.Name != Ephemeris.CATALOG_FILENAME)
                {
                    Ephemeris e = new Ephemeris(IO.ReadFile(fi.FullName, DirectoryLocation.Data));
                    if (AllowLoadSnapshot || e.VersionCount <= 0)
                    {
                        if (e.VersionCount < MAX_SNAPSHOT_GENERATIONS)
                        {
                            this.availableEphemeres.Add(e);
                        }
                    }
                }
            }
            if (!this.availableEphemeres.HasItems)
            {
                throw new Exception("No Ephemeris Found");
            }

            if (TEST)
            {
                testEphemeris = availableEphemeres[TEST_DATE];
                availableEphemeres.Remove(testEphemeris);
            }
            availableEphemeres.Init();
        }
Esempio n. 3
0
        private static void showPhaseDistError(Ephemeris Current, Ephemeris Actual, StringBuilder sb, string Planet, string Moon)
        {
            sb.AppendLine();
            sb.AppendLine(Planet + " / " + Moon);

            var PlanetCurrent = Current.ItemDictionary[Planet].Position;
            var PlanetActual  = Actual.ItemDictionary[Planet].Position;
            var MoonCurrent   = Current.ItemDictionary[Moon].Position;
            var MoonActual    = Actual.ItemDictionary[Moon].Position;

            sb.AppendLine(string.Format("Phase Current: {0} Actual: {1} Error: {2} ({3:0.0000000}km)",
                                        (MoonCurrent - PlanetCurrent).Azimuth.NormalizeAngleZeroToTwoPi().ToDMSStringMillionthsSecond(),
                                        (MoonActual - PlanetActual).Azimuth.NormalizeAngleZeroToTwoPi().ToDMSStringMillionthsSecond(),
                                        ((MoonCurrent - PlanetCurrent).Azimuth - (MoonActual - PlanetActual).Azimuth).NormalizeAngleNegativePiToPi().ToDMSStringMillionthsSecond(),
                                        Math.Abs(Math.Sin((MoonCurrent - PlanetCurrent).Azimuth - (MoonActual - PlanetActual).Azimuth) * (MoonCurrent - PlanetCurrent).Magnitude)));

            sb.AppendLine(string.Format("Distance Current: {0:0.0000}km Actual: {1:0.0000}km Error: {2:0.00000}km",
                                        (MoonCurrent - PlanetCurrent).Magnitude,
                                        (MoonActual - PlanetActual).Magnitude,
                                        ((MoonCurrent - PlanetCurrent).Magnitude - (MoonActual - PlanetActual).Magnitude)));
        }
Esempio n. 4
0
        public Physics(IIntegrator Integrator, bool AllowLoadSnapshot, StartupDoneDelegate StartupDone)
        {
            this.clock = new Clock();

            this.integrator     = Integrator;
            startupDoneDelegate = StartupDone;
            AllBodies           = new LinkedList <CelestialBody>();

            BodyDictionary = new Dictionary <string, CelestialBody>(DEFAULT_STARTING_NUM_ALL_BODIES);
            StarDictionary = new Dictionary <int, Star>(DEFAULT_STARTING_NUM_STARS);

            SearchDatabase     = null;
            Date               = new DateTime(2011, 1, 1);
            SleepBetweenCycles = 0;

            createOrbiters();

            loadEphemeres(!TEST && AllowLoadSnapshot);

            if (TEST)
            {
                this.TargetDate = TEST_DATE;
            }
            else
            {
                GoToToday();
            }

            this.ephemeris = this.availableEphemeres.GetClosest(this.TargetDate);

            invokeEphemeris(SetTimeMode: true, Wait: false, EstablishGravitationalInfluences: true);

            loadStars();

            setupConstellations();

            setupCaptioning();
        }
Esempio n. 5
0
 public void Remove(Ephemeris e)
 {
     list.Remove(e);
     isInitialized = false;
 }
Esempio n. 6
0
        private string testReport(Ephemeris Current, Ephemeris Actual)
        {
            if (!TEST)
            {
                throw new Exception();
            }

            StringBuilder sb              = new StringBuilder();
            Vector        sunPosCurrent   = Current.ItemDictionary["Sun"].Position;
            Vector        sunPosActual    = Actual.ItemDictionary["Sun"].Position;
            Vector        earthPosCurrent = Current.ItemDictionary["Earth"].Position;
            Vector        earthPosActual  = Actual.ItemDictionary["Earth"].Position;

            List <Tuple <Orbiter, Vector, Vector> > errors = new List <Tuple <Orbiter, Vector, Vector> >();

            int days = Current.BasedOnDate.DaysBetween(Actual.Date);

            sb.AppendLine(string.Format("Error Summary: {0} days integration {1} sec/step", days, TIME_SLICE_IDEAL));
            sb.AppendLine(string.Format("Start Date: {0} End Date: {1}", Current.BasedOnDate.ToString(DATE_FORMAT_1), Current.Date.ToString(DATE_FORMAT_1)));

            foreach (var e in Current.Items.Where(e => e.Name != "Sun"))
            {
                if (Actual.ItemDictionary.ContainsKey(e.Name))
                {
                    errors.Add(new Tuple <Orbiter, Vector, Vector>(e.Orbiter,
                                                                   (e.Position - sunPosCurrent) - (Actual.ItemDictionary[e.Name].Position - sunPosActual),
                                                                   Actual.ItemDictionary[e.Name].Position));
                }
            }

            sb.AppendLine(string.Format("Average Error: {0:0.000000}km",
                                        errors.Average(e => e.Item2.Magnitude)));

            sb.AppendLine(string.Format("Large Objects Average Error (Over 1E+24 kg): {0:0.000000}km ({1:0.0000000}km per day)",
                                        errors.Where(e => e.Item1.Mass >= 1E+27)
                                        .Average(e => e.Item2.Magnitude),
                                        errors.Where(e => e.Item1.Mass >= 1E+27)
                                        .Average(e => e.Item2.Magnitude) / (double)days));

            sb.AppendLine(string.Format("Small Objects Average Error (Under 1E+24 kg): {0:0.000000}km ({1:0.0000000}km per day)",
                                        errors.Where(e => e.Item1.Mass < 1E+27)
                                        .Average(e => e.Item2.Magnitude),
                                        errors.Where(e => e.Item1.Mass < 1E+27)
                                        .Average(e => e.Item2.Magnitude) / (double)days));

            showPhaseDistError(Current, Actual, sb, "Sun", "Mercury");
            showPhaseDistError(Current, Actual, sb, "Sun", "Venus");
            showPhaseDistError(Current, Actual, sb, "Sun", "Earth");
            showPhaseDistError(Current, Actual, sb, "Sun", "Mars");
            showPhaseDistError(Current, Actual, sb, "Sun", "Jupiter");
            showPhaseDistError(Current, Actual, sb, "Sun", "Saturn");
            showPhaseDistError(Current, Actual, sb, "Sun", "Uranus");
            showPhaseDistError(Current, Actual, sb, "Sun", "Neptune");
            showPhaseDistError(Current, Actual, sb, "Sun", "Pluto");
            showPhaseDistError(Current, Actual, sb, "Earth", "Moon");
            showPhaseDistError(Current, Actual, sb, "Mars", "Phobos");
            showPhaseDistError(Current, Actual, sb, "Mars", "Deimos");
            showPhaseDistError(Current, Actual, sb, "Jupiter", "Io");
            showPhaseDistError(Current, Actual, sb, "Jupiter", "Europa");
            showPhaseDistError(Current, Actual, sb, "Jupiter", "Ganymede");
            showPhaseDistError(Current, Actual, sb, "Jupiter", "Callisto");
            showPhaseDistError(Current, Actual, sb, "Saturn", "Titan");
            showPhaseDistError(Current, Actual, sb, "Saturn", "Mimas");
            showPhaseDistError(Current, Actual, sb, "Uranus", "Titania");
            showPhaseDistError(Current, Actual, sb, "Neptune", "Triton");
            showPhaseDistError(Current, Actual, sb, "Neptune", "Larissa");
            showPhaseDistError(Current, Actual, sb, "Pluto", "Charon");

            sb.AppendLine();
            sb.AppendLine("Error Details:");

            foreach (var e in errors)
            {
                if (e.Item1.Equals(CelestialBody.Earth))
                {
                    sb.AppendLine(string.Format("{0}: Error {1:0.00000000}km",
                                                e.Item1.Name,
                                                e.Item2.Magnitude));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}: Error {1:0.00000000}km Error angle from Earth: {2}",
                                                e.Item1.Name,
                                                e.Item2.Magnitude,
                                                (e.Item1.Position / 1000.0 - earthPosCurrent).AngleDiffAbs(e.Item3 - earthPosActual).ToDMSStringMillionthsSecond()));
                }
            }

            return(sb.ToString());
        }
Esempio n. 7
0
        private void moveObjects()
        {
            clock.Reset();

            while (!cancel)
            {
                if (this.waitState == WaitState.Requested)
                {
                    this.waitState = WaitState.Confirmed;
                }

                while ((this.Paused || this.waitState == WaitState.Confirmed) && !cancel)
                {
                    System.Threading.Thread.Sleep(0);
                }

                if (timeMode == TimeMode.RealTime && clock.Seconds > 10)
                {
                    TargetDate = DateTime.UtcNow;
                }

                double diff = (TargetDate - Date).TotalSeconds;

                if (diff > TIME_SLICE_MAX)
                {
                    if (StartupDone)
                    {
                        dt = TIME_SLICE_MAX;
                    }
                    else
                    {
                        dt = TIME_SLICE_IDEAL;
                    }
                }
                else if (diff < NEGATIVE_TIME_SLICE_MAX)
                {
                    if (StartupDone)
                    {
                        dt = NEGATIVE_TIME_SLICE_MAX;
                    }
                    else
                    {
                        dt = NEGATIVE_TIME_SLICE_IDEAL;
                    }
                }
                else if (diff > TIME_SLICE_MIN || diff < -TIME_SLICE_MIN)
                {
                    dt = diff;
                }
                else
                {
                    switch (this.timeMode)
                    {
                    case TimeMode.TargetToNormal:
                        this.TimeMode = TimeMode.Normal;
                        break;

                    case TimeMode.TargetToPaused:
                        this.TimeMode = SolarMax.TimeMode.Paused;
                        break;

                    case TimeMode.TargetToRealTime:
                        this.TimeMode = TimeMode.RealTime;
                        break;
                    }

                    if (!StartupDone)
                    {
                        dt = diff;
                        doMovement();
                        StartupDone = true;
                        Ephemeris e = new Ephemeris(this.AllOrbiters, this.Date, this.ephemeris.Date, this.ephemeris.VersionCount + 1);

                        if (TEST)
                        {
                            IO.WriteFile("test_report_" + testEphemeris.Date.ToString(Ephemeris.DATE_FORMAT_FOR_FILE_NAME) + ".txt", DirectoryLocation.Data, testReport(e, testEphemeris));
                        }
                        else if (!this.availableEphemeres.HasItemWithinSeconds(e.Date, MathEx.SECONDS_PER_DAY))
                        {
                            e.Save();
                            availableEphemeres.Add(e);
                            availableEphemeres.Init();
                        }

                        startupDoneDelegate();
                        continue;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                        ExternalDate = this.Date.AddSeconds(diff);
                        continue;
                    }
                }

                doMovement();

                System.Threading.Thread.Sleep(SleepBetweenCycles);
            }
        }