public void ExponentSolveToRKTest1()
 {
     foreach (var sp in Ode.RK45(0,
                                 1,
                                 (t, x) => - x,
                                 new Options {
         RelativeTolerance = 1e-3, InitialStep = 0.1
     }).SolveTo(1000))
     {
         Assert.IsTrue(Math.Abs(sp.X[0] - Math.Exp(-sp.T)) < 1e-2);
     }
 }
        private void initObs(OneDemExample calc)
        {
            pr  = calc;
            v0  = pr.Rebuild(pr.TimeSynch);
            sol = Ode.RK45(pr.TimeSynch, v0, pr.f, pr.dt).WithStepRx(0.01, out controller);
            controller.Pause();

            sol.ObserveOnDispatcher().Subscribe(sp => {
                vm.SolPointList.Update(sp);
                slider.Maximum = (double)(vm.SolPointList.Value.Count > 0 ? vm.SolPointList.Value.Count : 0);
            });
        }
        public void KernelTest3()
        {
            double h = 1;
            Func <double, Vector, Vector> tstf = (t, v) => {
                var res = Vector.Zeros(1);
                res[0] = KernelF.W(t, h);
                return(res);
            };

            var sol = Ode.RK45(-3 * h, Vector.Zeros(1), tstf, 0.01).SolveFromTo(-2.5 * h, 2.5 * h).Last();

            Assert.AreEqual(1d, sol.X[0], 0.0001);
        }
        private void initObs(RobotDynamics calc)
        {
            pr = calc;
            v0 = pr.Rebuild(pr.TimeSynch);
            var dt  = 0.0001;
            var sol = Ode.RK45(pr.TimeSynch, v0, pr.f, dt).WithStepRx(0.001, out controller).StartWith(new SolPoint(pr.TimeSynch, v0)).Publish();

            controller.Pause();

            sol.ObserveOnDispatcher().Subscribe(sp => {
                vm.SolPointList.Update(sp);
                slider.Maximum = (double)(vm.SolPointList.Value.Count > 0 ? vm.SolPointList.Value.Count : 0);
            });
            sol.Connect();
        }
        private void initObs(Sph2D calc)
        {
            pr = calc;
            v0 = pr.Rebuild(pr.TimeSynch);
            //var dt = 0.0000001;
            var dt = 5 * 10E-6;

            sol = Ode.RK45(pr.TimeSynch, v0, pr.f, dt).WithStepRx(dt * 10, out controller);//.StartWith(new SolPoint(pr.TimeSynch,v0));
            controller.Pause();

            sol.ObserveOnDispatcher().Subscribe(sp => {
                vm.SolPointList.Update(sp);
                slider.Maximum = (double)(vm.SolPointList.Value.Count > 0 ? vm.SolPointList.Value.Count : 0);
            });
        }
        public void KernelTest2()
        {
            double h = 10;
            Func <double, Vector, Vector> tstf = (t, v) => {
                var res = Vector.Zeros(1);
                res[0] = KernelF.dWdr(t, h) * Math.Sign(t);
                return(res);
            };

            var sol = Ode.RK45(-3 * h, Vector.Zeros(1), tstf, h / 100000).SolveFromTo(-3 * h, 3 * h);

            foreach (var sp in sol)
            {
                Assert.AreEqual(KernelF.W(sp.T, h), sp.X[0], 0.1);
            }
        }
Exemple #7
0
        private void initObs(Sph2D calc)
        {
            pr = calc;
            v0 = pr.Rebuild(pr.TimeSynch);
            //var dt = 0.0000001;
            var dt = 1000 * 1E-6;

            SPH2D_Ver3.dt = dt;
            sol           = Ode.RK45(pr.TimeSynch, v0, pr.f, dt).WithStepRx(dt * 10, out controller).StartWith(new SolPoint(pr.TimeSynch, v0));
            //sol = SPH2D_Ver3.CoolIntegration(calc as Sph2D_improoveIntegr).WithStepRx(dt * 100,out controller).StartWith(new SolPoint(pr.TimeSynch,v0));
            controller.Pause();

            sol.ObserveOnDispatcher().Subscribe(sp => {
                vm.SolPointList.Update(sp);
                slider.Maximum = (double)(vm.SolPointList.Value.Count > 0 ? vm.SolPointList.Value.Count : 0);
            });
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var mp = new MaterialObjectNewtow()
            {
                Name = "ball"
            };

            mp.Mass.Ix = 10;
            mp.Mass.Iy = 10;
            mp.Mass.Iz = 10;
            mp.AddForce(new ForceCenter(10, new Position3D(0, -1, 0, "Dir"), null, "G"));
            mp.AddForce(new Force(1, new Position3D(0, 1, 0, "Dir"), new Position3D(1, 0, 0, "FPoint"), null));
            mp.AddForce(new Force(1, new Position3D(0, -1, 0, "Dir"), new Position3D(-1, 0, 0, "FPoint"), null));
            //mp.AddMoment(new ForceCenter(2,new Position3D(1,0,0,"Dir"),null,"Moment"));
            //mp.Vel.X = 2;
            mp.Vel.Y = 100;
            //mp.Vel.Z = -0.1;


            var x0 = mp.Rebuild();

            var solve = Ode.RK45(0, mp.Rebuild(), mp.f);

            var res = mp.GetAllParamsValues(0, x0);

            for (int i = 0; i < res.Length; i++)
            {
                Console.WriteLine($"{mp.AllParamsNames[i]} = \t{res[i]}");
            }
            SolPoint sp        = new SolPoint();
            string   diffNames = "    V =  [ ";

            foreach (var diffpar in mp.DiffArr)
            {
                diffNames += $"{diffpar.FullName}, ";
            }
            diffNames += " ];";
            Console.WriteLine(diffNames);
            foreach (var item in solve.SolveFromToStep(0, 21, 1))
            {
                Console.WriteLine($"t = {item.T}, {item.X.ToString("G3"):-7}");
                sp = item;
            }

            res = mp.GetAllParamsValues(sp);
            for (int i = 0; i < res.Length; i++)
            {
                Console.WriteLine($"{mp.AllParamsNames[i]} = \t{res[i]}");
            }
            //==============================================================================
            //var mp = new MaterialPoint() { Name = "ball" };
            //mp.AddForce(new ForceCenter(10,new Position3D(0,-1,0,"Dir"),null));
            //mp.Vel.X = 2;
            //mp.Vel.Y = 100;
            //mp.Vel.Z = -0.1;


            //var x0 = mp.Rebuild();

            //var solve = Ode.RK45(0,mp.Rebuild(),mp.f);

            //var res = mp.GetAllParamsValues(0,x0);
            //for(int i = 0; i < res.Length; i++) {
            //    Console.WriteLine($"{mp.AllParamsNames[i]} = \t{res[i]}");
            //}
            //SolPoint sp = new SolPoint();
            //string diffNames = "    V =  [ ";
            //foreach(var diffpar in mp.DiffArr) {
            //    diffNames += $"{diffpar.FullName}, ";
            //}
            //diffNames += " ];";
            //Console.WriteLine(  diffNames);
            //foreach(var item in solve.SolveFromToStep(0,21,1)) {
            //    Console.WriteLine($"t = {item.T},   \tV = {item.X}");
            //    sp = item;
            //}

            //res = mp.GetAllParamsValues(sp);
            //for(int i = 0; i < res.Length; i++) {
            //    Console.WriteLine($"{mp.AllParamsNames[i]} = \t{res[i]}");
            //}



            //var dm = new ScnObjDummy() { Name = "Rocket" };
            //dm.AddChild(new Position3D(new Vector3D(3,77,0)));
            //dm.AddChild(new MassPoint(10));
            //dm.AddChild(new Force3D(new Vector3D(0,-8,4)));
            //dm.AddLaw(new NewtonLaw4MatPoint3D());

            //var x0 = dm.Rebuild();

            //var solve = Ode.RK45(0,dm.Rebuild(),dm.f);

            //var res = dm.GetAllParamsValues(0,x0);
            //for(int i = 0; i < res.Length; i++) {
            //    Console.WriteLine($"{dm.AllParamsNames[i]} = \t{res[i]}");
            //}

            //SolPoint sp = new SolPoint();
            //foreach(var item in solve.SolveFromToStep(0,100,1)) {
            //    Console.WriteLine($"t = {item.T},   \tV = {item.X}");
            //    sp = item;
            //}

            //res = dm.GetAllParamsValues(sp);
            //for(int i = 0; i < res.Length; i++) {
            //    Console.WriteLine($"{dm.AllParamsNames[i]} = \t{res[i]}");
            //}
            //==========================
            //var sw = new Stopwatch();

            //var pos = new Position3D(0,0,0,"pos");

            //var pos_ = new Position3D(12,17,-22,"dposDt");
            //pos.AddChild(pos_);
            //pos.AddDiffVect(pos_);

            //var interpX = new InterpXY();
            //interpX.Add(0,0);
            //interpX.Add(2,1);
            //interpX.Add(6,-1);
            //interpX.Add(8,0);
            //pos_.pX.SealInterp(interpX);



            //var solve = Ode.RK45(0,pos.Rebuild(),pos.f,0.01);

            //SolPoint sp = new SolPoint();
            //sw.Start();
            //foreach(var item in solve.SolveFromToStep(0,10000,1000)) {
            //    Console.WriteLine($"t = {item.T},   \tV = {item.X}");
            //    sp = item;
            //}
            //sw.Stop();
            //Console.WriteLine($"{sw.ElapsedMilliseconds}");
            //var res = pos.GetAllParamsValues(sp);
            //for(int i = 0; i < res.Length; i++) {
            //    Console.WriteLine($"{pos.AllParamsNames[i]} = \t{res[i]}");
            //}



            //var ww = new ScnPrm("ww", null, 1);
            //ww.SetVal(33);
            //Console.WriteLine($"ww = {ww.GetVal(1)}");

            //var obj = new ScnObjDummy();
            //obj.AddParam(ww);

            //var dww = new ScnPrmConst("_",null,2);

            //obj.AddDiffPropToParam(ww,dww);
            //obj.Rebuild();

            //foreach(var item in obj.DiffArr) {
            //    Console.WriteLine($"{item.MyDiff.Name} = {item.MyDiff.GetVal(0d)}");
            //}

            Console.ReadLine();
        }