Пример #1
0
        public static void Progress_yo4(LeapFrogState state, double dt)
        {
            var d = new double[] { 1.351207191959657, -1.702414383919315 };

            LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[0]);
            LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[1]);
            LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[0]);
        }
Пример #2
0
        public static void Progress_yo8(LeapFrogState state, double dt)
        {
            var d = new double[] { 0.104242620869991e1, 0.182020630970714e1, 0.157739928123617e0, 0.244002732616735e1, -0.716989419708120e-2, -0.244699182370524e1, -0.161582374150097e1, -0.17808286265894516e1 };

            var index = new int[] { 0, 1, 2, 3, 4, 5, 6 };

            foreach (var i in index)
            {
                LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[i]);
            }
            LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[7]);
            foreach (var i in index)
            {
                LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[i]);
            }
        }
Пример #3
0
        public static void Progress_yo6(LeapFrogState state, double dt)
        {
            var d = new double[] { 0.784513610477560e0, 0.235573213359357e0, -1.17767998417887e0, 1.31518632068391e0 };

            var index = new int[] { 0, 1, 2 };

            foreach (var i in index)
            {
                LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[i]);
            }
            LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[3]);
            foreach (var i in index)
            {
                LeapFrogIntegrator.Progress_LeapFrog(state, dt * d[i]);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            bool cancelled = false;

            Console.TreatControlCAsInput = false;
            Console.CancelKeyPress += (s, ev) =>
            {
                Console.WriteLine("Ctrl+C pressed");
                ev.Cancel = true;
                cancelled = true;
            };

            Exception caught = null;

            //Vector3.Test();

            int N = 1000;
            double G = 1.0;
            double mass = 1.0;
            double softeningLength = 0.1;
            var startState = new EulerState(N, gravitationalConstant: G, defaultMass: mass, softeningLength: softeningLength);

            StartUp_Ring(N, startState);

            //StartUp_TwoOnCircle(startState);

            //StartUp_ThreeOnEight(startState);

            //StartUp_ColdCollapse8(startState);

            INBodyIntegrator integrator = new LeapFrogIntegrator(startState);
            //INBodyIntegrator integrator = new RungeKuttaIntegrator(startState, RungeKuttaIntegrator.Flavor.rk4);
            //INBodyIntegrator integrator = new MultiStepIntegrator(startState, MultiStepIntegrator.Flavor.ms8);

            const double delta = 0.001;
            double oldTime;
            double newTime;
            INBodyState newState;
            double ekin_start = startState.Ekin();
            double epot_start = startState.Epot();
            double etot_start = ekin_start + epot_start;

            double ekin;
            double epot;
            double etot;

            int count = 0;

            string stateFileName = Path.Combine(Path.GetTempPath(), "data.txt");
            Console.Error.WriteLine("Storing to \"{0}\"", stateFileName);

            const int printModulus = 50;
            const int saveModulus = 10;

            var timeProgress = new Stopwatch();
            var beginTime = DateTime.Now;

            try
            {
                using (var stateFile = new System.IO.FileStream(stateFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                using (var stateWriter = new StreamWriter(stateFile, Encoding.UTF8))
                {
                    stateWriter.AutoFlush = true;

                    while (!cancelled && integrator.currentTMax < 240.0)
                    {
                        oldTime = integrator.currentTMax;

                        timeProgress.Start();
                        integrator.Progress(delta);
                        timeProgress.Stop();

                        newTime = integrator.currentTMax;
                        newState = integrator.currentState(newTime);

                        if (0 == (count % saveModulus) || 0 == (count % printModulus))
                        {
                            ekin = newState.Ekin();
                            epot = newState.Epot();
                            etot = ekin + epot;

                            if (0 == (count % printModulus))
                            {
                                Console.WriteLine("t:{0} Ekin:{1} Epot:{2} Etot:{3} Ediff:{4}", newTime, ekin, epot, etot, etot - etot_start);
                            }

                            if (0 == count % saveModulus)
                            {
                                var sb = new StringBuilder();
                                newState.Serialize(ekin, epot, sb);
                                stateWriter.Write(sb.ToString());
                            }
                        }

                        count++;
                    }
                }

                var endTime = DateTime.Now;
                var elapsedTime = endTime - beginTime;

                Console.Error.WriteLine("iterations per second: {0}", ((double)count) / elapsedTime.TotalSeconds);
                Console.Error.WriteLine("{0} seconds total time", elapsedTime.TotalSeconds);
                Console.Error.WriteLine("{0} seconds in Progress", timeProgress.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                caught = e;
            }
            finally
            {
            }

            if (null != caught)
            {
                Console.Error.WriteLine(caught.ToString());
            }

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Error.WriteLine("Press ENTER to finish.");
                Console.ReadLine();
            }
        }