static void Main(string[] args)
        {
            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);
            OutputPanelVM outpan = new OutputPanelVM();

            outMan.link(new DisplayVM(), new FileModel(outMan), outpan, simMan);
            double precision = 0.0001;

            simMan.CompStep_ = 2;
            simMan.Duration_ = 5;
            simMan.accuracyMode = true;

            outpan.fromSim = true;
            outpan.EnableLog = true;
            outpan.DisplayEnbld = false;
            outpan.DisplayStep = "1";
            outpan.TargetFile = "C:\\Users\\Doz\\Source\\Repos\\Physics_Simulator\\ConsoleEntryPoint\\UnitTestOutputFile.txt";

            bool temp = false;
            if (!System.IO.File.Exists(outpan.TargetFile)) { temp = true; System.IO.File.Create(outpan.TargetFile); }

            simMan.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simMan.addActionPoint(0, 0.5, 1, 10.5);
            outMan.launch();

            string content = System.IO.File.ReadLines(outpan.TargetFile).Last();
            var sp = content.Split();
            double t = Double.Parse(sp[0]);
            double x = Double.Parse(sp[2]);
            double y = Double.Parse(sp[3]);
            double z = Double.Parse(sp[4]);
            if (temp == true) { System.IO.File.Delete(outpan.TargetFile); }
        }
        public void EquivalenceTest()
        {
            double precision = 0.001;
            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);

            simMan.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simMan.addActionPoint(0, 0.5, 1, 10.5);
            simMan.CompStep_ = 2;
            simMan.increment();
            //------------------------------------------------------
            OutputManager outMan2 = new OutputManager();
            SimManager simManBis = new SimManager(outMan);

            simManBis.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simManBis.addActionPoint(0, 0.5, 1, 10.5);
            simManBis.CompStep_ = 1;
            simManBis.increment();
            simManBis.increment();

            Assert.IsTrue(simMan.sceneElems_[0] - simManBis.sceneElems_[0] < precision);
            Assert.IsTrue(simMan.sceneElems_[1] - simManBis.sceneElems_[1] < precision);
            Assert.IsTrue(simMan.sceneElems_[2] - simManBis.sceneElems_[2] < precision);
        }
        public void noLogPrecModeTest()
        {
            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);
            OutputPanelVM outpan = new OutputPanelVM();

            outMan.link(new DisplayVM(), new FileModel(outMan), outpan, simMan);
            double precision = 0.0001;

            simMan.CompStep_ = 2;
            simMan.Duration_ = 5;
            simMan.accuracyMode = true;

            outpan.fromSim = true;
            outpan.EnableLog = false;
            outpan.DisplayEnbld = true;
            outpan.DisplayStep = "1";
            outpan.TargetFile = "C:\\Users\\Doz\\Source\\Repos\\Physics_Simulator\\ConsoleEntryPoint\\UnitTestOutputFile.txt";

            if (!System.IO.File.Exists(outpan.TargetFile)) { System.IO.File.Create(outpan.TargetFile); }

            simMan.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simMan.addActionPoint(0, 0.5, 1, 10.5);
            outMan.launch();

            System.IO.File.Delete(outpan.TargetFile);

            Assert.IsTrue(simMan.sceneElems_[0] - 0.5 * 0.5 * 25 < precision);
            Assert.IsTrue(simMan.sceneElems_[1] - 0.5 * 25 < precision);
            Assert.IsTrue(simMan.sceneElems_[2] - 0.5 * 10.5 * 25 < precision);
        }
        public void unitDispTest()
        {
            double precision = 0.001;
            double[] a = { 1, 2, 21 };

            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);

            simMan.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simMan.addActionPoint(0, 0.5, 1, 10.5);
            simMan.CompStep_ = 2;
            simMan.increment();

            Assert.IsTrue(simMan.sceneElems_[0] - a[0] < precision);
            Assert.IsTrue(simMan.sceneElems_[1] - a[1] < precision);
            Assert.IsTrue(simMan.sceneElems_[2] - a[2] < precision);
        }
        public void trivialTest()
        {
            double[] a = { 1, 2, 3 };
            List<double> result = new List<double>(a);

            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);

            simMan.addMaterialPoint(1, 2, 3, 0, 0, 0, 1, 0);
            simMan.CompStep_ = 12;
            simMan.increment();

            CollectionAssert.AreEqual(simMan.sceneElems_, result);
        }
        public void RToutputTest()
        {
            OutputManager outMan = new OutputManager();
            SimManager simMan = new SimManager(outMan);
            OutputPanelVM outpan = new OutputPanelVM();

            outMan.link(new DisplayVM(), new FileModel(outMan), outpan, simMan);

            simMan.CompStep_ = 2;
            simMan.accuracyMode = false;

            outpan.fromSim = true;
            outpan.EnableLog = false;
            outpan.DisplayEnbld = true;
            outpan.DisplayStep = "1";

            simMan.addMaterialPoint(0, 0, 0, 0, 0, 0, 1, 0);
            simMan.addActionPoint(0, 0.5, 1, 10.5);

            outMan.launch();
            System.Threading.Thread.Sleep(5000);
            outMan.stopTimer();
            double t = 5;
            Assert.IsTrue(simMan.sceneElems_[0] < 0.5 * 0.5 * (t + simMan.CompStep_) * (t + simMan.CompStep_));
            Assert.IsTrue(simMan.sceneElems_[0] > 0.5 * 0.5 * (t - simMan.CompStep_) * (t - simMan.CompStep_));
        }
Exemple #7
0
        public void addMPoint(object obj)
        {
            //MessageBox.Show("Trying to create a material Point");

            string message               = String.Empty;
            string massMessage           = String.Empty;
            string massRejectMessage     = String.Empty;
            string positionMessage       = String.Empty;
            string positionRejectMessage = String.Empty;

            bool creation = true;

            //Mass checking
            if (mass != null && mass > 0)
            {
                massMessage += "mass: " + mass.ToString();
            }
            else
            {
                massRejectMessage += "- Not going anywhere without a positive mass" + Environment.NewLine;
                creation           = false;
            }

            //Position Checking

            //Cx

            if (Xinput.Equals("X") && creation)
            {
                Xinput           = "0";
                positionMessage += " Cx = 0 ";
            }
            else
            {
                if (InputCx == null)
                {
                    positionRejectMessage += "- Numerical value required for Cx" + Environment.NewLine;
                    creation = false;
                }
                else
                {
                    positionMessage = (creation) ? positionMessage + " Cx = " + InputCx.ToString() : positionMessage;
                }
            }

            //Cy
            if (Yinput.Equals("Y") && creation)
            {
                Yinput = "0"; positionMessage += " Cy = 0 ";
            }
            else
            {
                if (InputCy == null)
                {
                    positionRejectMessage += "- Numerical value required for Cy" + Environment.NewLine;
                    creation = false;
                }
                else
                {
                    positionMessage = (creation) ? positionMessage + " Cy = " + InputCy.ToString() : positionMessage;
                }
            }

            //Cz
            if (Zinput.Equals("Z") && creation)
            {
                Zinput = "0"; positionMessage += " Cz = 0 ";
            }
            else
            {
                if (InputCz == null)
                {
                    positionRejectMessage += "- Numerical value required for Cz" + Environment.NewLine;
                    creation = false;
                }
                else
                {
                    positionMessage = (creation) ? positionMessage + " Cz = " + InputCz.ToString() : positionMessage;
                }
            }

            if (creation)
            {
                message =
                    massMessage + Environment.NewLine +
                    "Position of the center of mass: " + Environment.NewLine +
                    positionMessage;
                MessageBox.Show(message, "Confirmation");
                simMgr.addMaterialPoint((double)InputCx, (double)InputCy, (double)InputCz, 0, 0, 0, (double)mass, 0);
                selected++;
                Notify("SelectedItem");
                outMan.displayElements();
            }
            else
            {
                message =
                    "The Material Point will not be created:" + Environment.NewLine +
                    massRejectMessage + positionRejectMessage;
                MessageBox.Show(message, "Rejection");
            }
        }