Пример #1
0
 public StaticMechanicSolution(ISolve <double[, ]> solver)
 {
     this.solver  = solver;
     globalMatrix = solver.GlobalMatrix;
     loads        = new double[globalMatrix.GetLength(0)];
     results      = new double[globalMatrix.GetLength(0)];
 }
 public StaticMechanicDictMemSolution(ISolve <Dictionary <int, IntPtr> > solver)
 {
     this.solver  = solver;
     globalMatrix = solver.GlobalMatrix;
     loads        = new double[globalMatrix.Count];
     results      = new double[globalMatrix.Count];
 }
Пример #3
0
        private void backgroundSolver_DoWork(object sender, DoWorkEventArgs e)
        {
            this.solver = new TaquinSolveSteps();
            var solution = this.solver.Solve(this.game, this.result.State);

            e.Result = solution;
        }
Пример #4
0
        static void TimedSolvesWithPrint(ISolve solver, int averageOver = 10)
        {
            var answer = solver.Solve();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"--- {solver.Day}.{solver.Part} ---");
            Console.ResetColor();
            Console.Write("An: ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(answer);
            Console.ResetColor();

            var times = new List <double>();

            for (var i = 0; i < averageOver; i++)
            {
                _stopwatch.Restart();
                solver.Solve();
                _stopwatch.Stop();

                times.Add(_stopwatch.Elapsed.TotalMilliseconds);
            }

            if (times.Any())
            {
                Console.WriteLine($@"
Hi: {times.Max():N3}ms
Lo: {times.Min():N3}ms
Av: {times.Average():N3}ms");
            }
        }
Пример #5
0
 public StaticMechanicMappedMatrixSolution(ISolve <string[]> solver)
 {
     this.solver  = solver;
     globalMatrix = solver.GlobalMatrix;
     loads        = new double[solver.GlobalMatrix.Length];
     results      = new double[solver.GlobalMatrix.Length];
 }
Пример #6
0
 public StaticMechanicSparseSolution(ISolve <SparseMatrix> solver, IScene scene)
 {
     this.solver  = solver;
     globalMatrix = solver.GlobalMatrix;
     length       = scene.Nodes.Count * DEGREES_OF_FREEDOM;
     loads        = new double[length];
     results      = new double[length];
 }
 public StaticMechanicCudaSolution(ISolve <SparseMatrix> solver, FeModel model)
 {
     this.solver  = solver;
     globalMatrix = solver.GlobalMatrix;
     length       = model.Nodes.Count * DEGREES_OF_FREEDOM;
     loads        = new double[length];
     results      = new double[length];
 }
Пример #8
0
 public StaticMechanicMemorySolution(ISolve <IntPtr> solver, int lengthMatrix)
 {
     this.solver       = solver;
     globalMatrix      = solver.GlobalMatrix;
     this.lengthMatrix = lengthMatrix;
     loads             = new double[lengthMatrix];
     results           = new double[lengthMatrix];
 }
Пример #9
0
        public Game(int numberOfPlayers, ISolve solver)
        {
            if (numberOfPlayers < 2 || numberOfPlayers > 20)
            {
                throw new ArgumentException("numberOfPlayers");
            }
            this.numberOfPlayers = numberOfPlayers;
            this.solver          = solver ?? throw new ArgumentNullException("solver");
            deck = new Deck();

            Players = new List <Player>();
        }
Пример #10
0
        static bool SolveOne(ISolve solve, bool isA)
        {
            var desc = isA ? "A" : "B";

            Console.Write($"  Prove {desc}: ");
            if (!solve.Prove(isA))
            {
                Console.WriteLine("Embarrassing Failure!");
                return(false);
            }
            else
            {
                Console.WriteLine("Tremendous Success");
                var solution = solve.Solve(isA);
                Console.WriteLine($"  Solve {desc}: {solution}");
                return(true);
            }
        }
Пример #11
0
 public InputOutput(ISolve solve)
 {
     _solve = solve;
 }
Пример #12
0
        static void Main(string[] args)
        {
            ISolve[] all =
            {
                new Solve1(),
                new Solve2(),
                new Solve3(),
                new Solve4(),
                new Solve5(),
                new Solve6(),
                new Solve7(),
                new Solve8(),
                new Solve9(),
                new Solve10(),
                new Solve11(),
                new Solve12(),
                new Solve13(),
                new Solve14(),
                new Solve15(),
                new Solve16(),
                new Solve17(),
                // new Solve18(),
                new Solve19(),
                new Solve21(),
                new Solve22(),
                new Solve24(),
                new Solve25(),
                new Solve23(),
            };

            ISolve[] toSolve;
            if (args.Length > 0 && args[0] == "last")
            {
                toSolve = new ISolve[] { all[all.Length - 1] };
            }
            else
            {
                toSolve = all;
            }

            var failed     = new List <ISolve>();
            var timeForAll = new Stopwatch();

            timeForAll.Start();
            var timeForEach = new Dictionary <ISolve, long>();

            foreach (var solve in toSolve)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                Console.WriteLine($"Solving: {solve.Description()}");
                if (SolveOne(solve, true) && SolveOne(solve, false))
                {
                    Console.WriteLine("Success!");
                }
                else
                {
                    failed.Add(solve);
                }
                var elapsed = stopwatch.ElapsedMilliseconds;
                timeForEach[solve] = elapsed;
                Console.WriteLine();
            }

            var padding = 8;

            foreach (var t in timeForEach)
            {
                var timing = t.Value.ToString().PadLeft(padding) + " ms";
                Console.WriteLine($"{timing}   {t.Key.Description()}");
            }
            Console.WriteLine($"{"-----------".PadLeft(padding)}   ------");
            var allTiming = timeForAll.ElapsedMilliseconds.ToString().PadLeft(padding) + " ms";

            Console.WriteLine($"{allTiming}   Total");
            Console.WriteLine();

            if (failed.Count > 0)
            {
                Console.WriteLine();
                Console.WriteLine(" FAILURES DETECTED:");
                failed.ForEach(f => Console.WriteLine($"   {f.Description()}"));
            }
        }
Пример #13
0
        private void Button2_Click(object sender, EventArgs e)
        {
            //trnglRepository = new StlTriangularRepository<string>();
            tetrahedralRepository = new StlTetrahedralRepository <string>();
            trinagleRepository    = new StlTriangularRepository2 <string>();

            List <List <Triangle> > vertebras  = new List <List <Triangle> >();
            List <Triangle>         myvertebra = new List <Triangle>();

            myvertebra = ReadVertebra(1, "Vertebras/st1/");

            vertebras.Add(myvertebra);

            //vertebras.Add(ReadVertebra(1, "Vertebras/st2/"));
            //int countVertebras = 5;
            //for (int i = 2; i <= countVertebras; i++)
            //{
            //    vertebras.Add(ReadVertebra(i, "Vertebras/st2/"));
            //}

            List <Triangle> allVertebras = new List <Triangle>();

            vertebras.ForEach(trngls => allVertebras.AddRange(trngls));

            double shiftX = Math.Abs(allVertebras.Min(tngl => tngl.Center.X));
            double shiftY = Math.Abs(allVertebras.Min(tngl => tngl.Center.Y));
            double shiftZ = Math.Abs(allVertebras.Min(tngl => tngl.Center.Z));

            double minX   = allVertebras.Min(tngl => tngl.Center.X);
            double minY   = allVertebras.Min(tngl => tngl.Center.Y);
            double minZ   = allVertebras.Min(tngl => tngl.Center.Z);
            double maxX   = allVertebras.Max(tngl => tngl.Center.X);
            double maxY   = allVertebras.Max(tngl => tngl.Center.Y);
            double maxZ   = allVertebras.Max(tngl => tngl.Center.Z);
            double avX    = (minX + maxX) / 2.0;
            double avY    = (minY + maxY) / 2.0;
            double lenght = maxX - minX;
            double width  = maxY - minY;

            width = (lenght > width) ? lenght : width;
            double height = maxZ - minZ;

            ShiftModel(ref vertebras, shiftX, shiftY, shiftZ);
            //ShiftModel(ref disks, shiftX, shiftY, shiftZ);

            toolStripStatusLabel1.Text = $"Генерация конечно-элементной сетки...";
            this.Refresh();

            FeModel scene = GenerateTetrahedralModel(width, height + STEP_HEIGHT, STEP_WIDTH, STEP_HEIGHT, VERTEBRA_MATERIAL_ID);

            model = GetGeneralModelFromScene(scene, vertebras);
            var aaaaaa = model.Triangles;
            var bbbbbb = model.Tetrahedrons;

            //load = new Force(SelectedSide.TOP, new Node((int)avX, (int)avY, maxZ - 10), forceValue, true, model.Triangles);

            toolStripStatusLabel1.Text = $"Учет граничных условий и внешних нагрузок...";
            this.Refresh();

            //load = new Force(SelectedSide.TOP, new Node((int)avY, (int)avX, maxZ - 10), forceValue, true, model.Triangles);
            //load = new Pressure(SelectedSide.TOP, new Node((int)avX, (int)avY, maxZ - 10), forceValue, true, model.Triangles);
            //load = new ConcentratedForce(SelectedSide.TOP, forceValue, true, model.Nodes, height / 10.0);
            load       = new Force(SelectedSide.TOP, forceValue, true, model.Nodes, height / 18.0);
            conditions = new VolumeBoundaryCondition(SelectedSide.BOTTOM, model.Nodes, height / 20.0);
            //conditions = new VolumeBoundaryCondition(SelectedSide.BOTTOM, new Node((int)avX, (int)avY, minZ), model.Triangles);
            tetrahedralRepository.Create(model.Id + "in", model.Tetrahedrons);

            int         concentratedIndex = load.LoadVectors.FirstOrDefault().Key;
            int         step      = (int)(STEP_HEIGHT / 4.0);
            Node        tmpNode   = model.Nodes.FirstOrDefault(nd => nd.GlobalIndex == concentratedIndex);
            List <Node> nearNodes = new List <Node>(model.Nodes.Where(nd =>
                                                                      (nd.X > model.Nodes[concentratedIndex].X - step && nd.X < model.Nodes[concentratedIndex].X + step) &&
                                                                      (nd.Y > model.Nodes[concentratedIndex].Y - step && nd.Y < model.Nodes[concentratedIndex].Y + step) &&
                                                                      (nd.Z > model.Nodes[concentratedIndex].Z - step && nd.Z < model.Nodes[concentratedIndex].Z + step))
                                                    .ToList());

            nearNodes.Remove(tmpNode);

            concentratedIndex = TrueIndexOfCenter(concentratedIndex, nearNodes, 0);
            if (concentratedIndex != load.LoadVectors.FirstOrDefault().Key)
            {
                LoadVector vector = new LoadVector(load.LoadVectors.FirstOrDefault().Value.Value, VectorDirection.Z);
                load.LoadVectors.Clear();
                load.LoadVectors.Add(concentratedIndex, vector);
            }

            //trnglRepository.Create(model.Id + "in", model.Triangles);
            //trnglRepository.Create(model.Id + "load", ((Force)load).LoadedTriangles);
            //trnglRepository.Create(model.Id + "fix", ((VolumeBoundaryCondition)conditions).FixedTriangles);



            solver   = new StressStrainSparseMatrix(model);
            solution = new StaticMechanicSparseSolution(solver, model);

            var begin = DateTime.Now;

            solution.Solve(TypeOfFixation.RIGID, conditions, load);

            TimeSpan endSolve = DateTime.Now - begin;

            double[] results = solution.Results;

            toolStripStatusLabel1.Text = $"Расчет завершен.";
            this.Refresh();

            using (StreamWriter writer = new StreamWriter("results.txt"))
            {
                writer.WriteLine($"Total time solving SLAE: {endSolve.TotalSeconds} sec.");
                writer.WriteLine();
                double max = solution.Results[2];
                for (int i = 2; i < solution.Results.Length; i += 3)
                {
                    if (Math.Abs(solution.Results[i]) > Math.Abs(max))
                    {
                        max = solution.Results[i];
                    }
                }

                writer.WriteLine($"Max deformation: {max} mm.");
                writer.WriteLine();

                for (int i = 0; i < solution.Results.Length; i++)
                {
                    writer.WriteLine(solution.Results[i]);
                }
            }

            TotalEpure(model.Nodes, solution.Results, "TotalEpureSpine");

            List <Tetrahedron> outList = ApplyResultsToTetrahedrons(results);
            List <Node>        nodlist = ApplyResultsToGenList(results);

            tetrahedralRepository.Create(model.Id + "out", outList);
            tetrahedralRepository.Create2(model.Id + "out2", outList);
            trinagleRepository.Create2(model.Id + "out3", myvertebra, nodlist);

            lastname          = model.Id + "out3.stl";
            lastname_fullpath = Environment.CurrentDirectory + "\\" + lastname;

            MessageBox.Show($"Total time solving SLAE: {endSolve.TotalSeconds} sec.");

            //Process.Start("notepad.exe", "results.txt");
        }