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"); }