Example #1
0
        /// <summary>
        /// Simulation is started here. In case of benchmarking uncomment <code>Test()</code> and then after running it will perform benchmarks and close.
        /// </summary>
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            windowHeight           = background.ActualHeight;
            windowWidth            = background.ActualWidth;
            windowCalculatorHelper = new WindowCalculatorHelper(windowHeight, windowWidth, horizontalRange, new long[] { 0, 0 });
            loaded = true;

            //system = DataAccess.InitializeHardcodedSystem(timeStep, 0);
            system = DataAccess.InitializeFromJSON("system.json", timeStep);
            AddGraphics();
            RedrawAll();
            AddPlots();
            AddPlanetsToList();
            //system.Serialize("system");

            //SelectNewCenter("Sun");
            //SelectNewRange(150000000);

            //while (true)
            //{
            //    await Task.Delay(5000);
            //    SelectNewCenter("Mars");
            //    SelectNewRange(150000000);
            //    await Task.Delay(5000);
            //    SelectNewCenter("Earth");
            //    SelectNewRange(1500000000);
            //    await Task.Delay(5000);
            //    SelectNewCenter(new long[] { 0, 0 });
            //    SelectNewRange(1000000000000);
            //}
            //int days = 60;
            //double testTimeStep = 10;
            //int secondsPerDay = 86400;
            //AccuracyBenchmark.RunTest(system, (int)(days*secondsPerDay / testTimeStep), (int)(days*secondsPerDay/testTimeStep), testTimeStep, testTimeStep, true, true, true, true);
            //Test();
        }
Example #2
0
        static public void RunTest(SolarSystem sys, int eulerSteps, int RK4steps, double eulerTimeStep, double RK4TimeStep, bool runSerial, bool runParallel, bool runThreaded, bool runRK4)
        {
            system = sys;
            using (FileStream fs = new FileStream("accuracyTestLog.txt", FileMode.Append))
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.WriteLine($"Time of test: {DateTime.Now}");
                    if (runSerial)
                    {
                        (eulerSunEarthSerial, eulerEarthMoonSerial, eulerMarsPhobosSerial, eulerMarsDeimosSerial, eulerEarthMarsSerial, serialTime) = RunSerial(eulerSteps, eulerTimeStep);
                    }
                    if (runParallel)
                    {
                        (eulerSunEarthParallel, eulerEarthMoonParallel, eulerMarsPhobosParallel, eulerMarsDeimosParallel, eulerEarthMarsParallel, parallelTime) = RunParallel(eulerSteps, eulerTimeStep);
                    }
                    if (runThreaded)
                    {
                        (eulerSunEarthThreaded, eulerEarthMoonThreaded, eulerMarsPhobosThreaded, eulerMarsDeimosThreaded, eulerEarthMarsThreaded, threadedTime) = RunThreaded(eulerSteps, eulerTimeStep);
                    }
                    if (runRK4)
                    {
                        (RK4SunEarth, RK4EarthMoon, RK4MarsPhobos, RK4MarsDeimos, RK4EarthMars, RK4Time) = RunRK4(RK4steps, RK4TimeStep);
                    }

                    ses   = 100 * (1 - (double)eulerSunEarthSerial / HorizonsSunEart);
                    ems   = 100 * (1 - (double)eulerEarthMoonSerial / HorizonsEarthMoon);
                    mps   = 100 * (1 - (double)eulerMarsPhobosSerial / HorizonsMarsPhobos);
                    mds   = 100 * (1 - (double)eulerMarsDeimosSerial / HorizonsMarsDeimos);
                    emas  = 100 * (1 - (double)eulerEarthMarsSerial / HorizonsEarthMars);
                    sep   = 100 * (1 - (double)eulerSunEarthParallel / HorizonsSunEart);
                    emp   = 100 * (1 - (double)eulerEarthMoonParallel / HorizonsEarthMoon);
                    mpp   = 100 * (1 - (double)eulerMarsPhobosParallel / HorizonsMarsPhobos);
                    mdp   = 100 * (1 - (double)eulerMarsDeimosParallel / HorizonsMarsDeimos);
                    emap  = 100 * (1 - (double)eulerEarthMarsParallel / HorizonsEarthMars);
                    set   = 100 * (1 - (double)eulerSunEarthThreaded / HorizonsSunEart);
                    emt   = 100 * (1 - (double)eulerEarthMoonThreaded / HorizonsEarthMoon);
                    mpt   = 100 * (1 - (double)eulerMarsPhobosThreaded / HorizonsMarsPhobos);
                    mts   = 100 * (1 - (double)eulerMarsDeimosThreaded / HorizonsMarsDeimos);
                    emat  = 100 * (1 - (double)eulerEarthMarsThreaded / HorizonsEarthMars);
                    serk  = 100 * (1 - (double)RK4SunEarth / HorizonsSunEart);
                    emrk  = 100 * (1 - (double)RK4EarthMoon / HorizonsEarthMoon);
                    mprk  = 100 * (1 - (double)RK4MarsPhobos / HorizonsMarsPhobos);
                    mdrk  = 100 * (1 - (double)RK4MarsDeimos / HorizonsMarsDeimos);
                    emark = 100 * (1 - (double)RK4EarthMars / HorizonsEarthMars);

                    writer.WriteLine($"Euler steps: {eulerSteps}, time step: {eulerTimeStep}");
                    writer.WriteLine($"Runge Kutta RK4 steps: {RK4steps}, time step: {RK4TimeStep}");
                    writer.WriteLine();
                    writer.WriteLine("Body pair, Horizons distance, serial distance, parallel dostance, threaded distance, RK4 distance:");
                    writer.WriteLine($"Sun to Earth:   {HorizonsSunEart}, {eulerSunEarthSerial}, {eulerSunEarthParallel}, {eulerSunEarthThreaded}, {RK4SunEarth}");
                    writer.WriteLine($"Earth to Moon:  {HorizonsEarthMoon}, {eulerEarthMoonSerial}, {eulerEarthMoonParallel}, {eulerEarthMoonThreaded}, {RK4EarthMoon}");
                    writer.WriteLine($"Mars to Phobos: {HorizonsMarsPhobos}, {eulerMarsPhobosSerial}, {eulerMarsPhobosParallel}, {eulerMarsPhobosThreaded}, {RK4MarsPhobos}");
                    writer.WriteLine($"Mars to Deimos: {HorizonsMarsDeimos}, {eulerMarsDeimosSerial}, {eulerMarsDeimosParallel}, {eulerMarsDeimosThreaded}, {RK4MarsDeimos}");
                    writer.WriteLine($"Earth to Mars:  {HorizonsEarthMars}, {eulerEarthMarsSerial}, {eulerEarthMarsParallel}, {eulerEarthMarsThreaded}, {RK4EarthMars}");
                    writer.WriteLine();
                    writer.WriteLine("Body pair, serial error, parallel error, threaded error, RK4 error:");
                    writer.WriteLine($"Sun to Earth:   {ses}%, {sep}%, {set}%, {serk}%");
                    writer.WriteLine($"Earth to Moon:  {ems}%, {emp}%, {emt}%, {emrk}%");
                    writer.WriteLine($"Mars to Phobos: {mps}%, {mpp}%, {mpt}%, {mprk}%");
                    writer.WriteLine($"Mars to Deimos: {mds}%, {mdp}%, {mts}%, {mdrk}%");
                    writer.WriteLine($"Earth to Mars:  {emas}%, {emap}%, {emat}%, {emark}%");
                    writer.WriteLine();
                    writer.WriteLine($"Times: Srial: {serialTime}, Parallel: {parallelTime}, Threaded: {threadedTime}, RK4: {RK4Time}");
                    writer.WriteLine();
                    writer.WriteLine("---------------------------------------------------------------------------------------------------------");
                    writer.WriteLine();
                }
            MessageBox.Show("Tests done!");
            Environment.Exit(0);
        }
Example #3
0
 public SpeedTest(SolarSystem sys, int c)
 {
     system    = sys;
     count     = c;
     stopwatch = new Stopwatch();
 }