コード例 #1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            List <string> lineStrings = new List <string>(this.notMoveLines.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList <string>());
            List <MyLine> fixedLines  = new List <MyLine>();

            foreach (string str in lineStrings)
            {
                int idx;
                if (!int.TryParse(str, out idx))
                {
                    MessageBox.Show("Неверно заданы линии!");
                    return;
                }

                MyLine line = (MyLine)parent.currentFullModel.geometryModel.StraightLines.Find(l => l.Id == idx) ?? (MyLine)parent.currentFullModel.geometryModel.Arcs.Find(a => a.Id == idx);
                if (line == null)
                {
                    MessageBox.Show("Не найдена линия с номером " + idx.ToString());
                    return;
                }
                fixedLines.Add(line);
            }
            parent.precision = parent.DefinePrecision();
            if (parent.currentFullModel.geometryModel.Areas.Count != 0)
            {
                errorMessage1.Visible    = false;
                errorBadGridName.Visible = false;

                // создаем новый объект "конечно-элементная модель" и добавляем его в список конечно-элементных моделей.
                foreach (MyFiniteElementModel model in parent.currentFullModel.FiniteElementModels) // проверяем, нет ли модели с таким именем
                {
                    if (model.ModelName == gridName.Text)
                    {
                        errorBadGridName.Visible = true;
                        return;
                    }
                }
                this.Hide();
                parent.StartProgress("Выполняется оптимизация");
                // создаем для новой КЭ модели id
                int id = parent.currentFullModel.IdCandidate;
                currentModel           = (MyFiniteElementModel)Util.getObjectCopy(currentModel);
                currentModel.ModelName = gridName.Text;
                currentModel.Id        = id;
                currentModel.restoreArraysForOldMethods(parent.currentFullModel.geometryModel);

                int[] notMove = new int[currentModel.INOUT.Count];
                notMove.Initialize();
                if (notMoveLines.TextLength != 0)
                {
                    foreach (MyLine fixedLine in fixedLines)
                    {
                        List <MyNode> tempNodes = new List <MyNode>();
                        if (fixedLine is MyStraightLine)
                        {
                            findNodesAtStraightLine(tempNodes, (MyStraightLine)fixedLine);
                            foreach (MyNode node in tempNodes)
                            {
                                node.Type        = NodeType.Fixed;
                                notMove[node.Id] = 1;
                            }
                        }
                        else
                        {
                            findNodesAtArc(tempNodes, (MyArc)fixedLine);
                            foreach (MyNode node in tempNodes)
                            {
                                node.Type        = NodeType.Fixed;
                                notMove[node.Id] = 1;
                                //currentModel.INOUT[node.Id] = 1;
                            }
                        }
                    }
                }

                Regularization(currentModel.NRC, parent.currentFullModel.geometryModel.Areas.Count, currentModel, notMove);
                currentModel.FiniteElements.Clear();
                currentModel.Nodes.Clear();

                for (int i = 1; i <= currentModel.NP; i++) // MAXNP - число узлов
                {
                    currentModel.Nodes.Add(new MyNode(currentModel.CORD[2 * (i - 1) + 1], currentModel.CORD[2 * (i - 1) + 2], i));
                }

                for (int temp = 1; temp <= currentModel.NE; temp++)
                {
                    int           numOfFE    = currentModel.FiniteElements.Count;
                    int           numOfNodes = currentModel.Nodes.Count;
                    List <MyNode> tempNodes  = new List <MyNode>();

                    double X1 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 1] - 1) + 1];
                    double Y1 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 1] - 1) + 2];
                    double X2 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 2] - 1) + 1];
                    double Y2 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 2] - 1) + 2];
                    double X3 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 3] - 1) + 1];
                    double Y3 = currentModel.CORD[2 * (currentModel.NOP[3 * (temp - 1) + 3] - 1) + 2];

                    foreach (MyNode node in currentModel.Nodes)
                    {
                        if (Math.Abs(node.X - X1) <= 0.001 && Math.Abs(node.Y - Y1) <= 0.001)
                        {
                            tempNodes.Add(node);
                        }
                        if (Math.Abs(node.X - X2) <= 0.001 && Math.Abs(node.Y - Y2) <= 0.001)
                        {
                            tempNodes.Add(node);
                        }
                        if (Math.Abs(node.X - X3) <= 0.001 && Math.Abs(node.Y - Y3) <= 0.001)
                        {
                            tempNodes.Add(node);
                        }
                    }
                    MyFiniteElement elem = new MyFiniteElement(numOfFE + 1, 0, tempNodes);
                    elem.DefineArea(parent.currentFullModel.geometryModel.Areas);
                    currentModel.FiniteElements.Add(elem);
                    tempNodes.Clear();
                }
                parent.EndProgress();
                parent.ModelCreated(currentModel);
                Close();
            }
            else
            {
                errorMessage1.Visible = true;
            }
        }
コード例 #2
0
        // чтение вариантов сетки из файла (Рапперт)
        public void ReadRuppertVariants(string file)
        {
            string[] lines = File.ReadAllLines(file, Encoding.Default);

            int NRC               = Convert.ToInt32(lines[0]);
            int countOfZones      = Convert.ToInt32(lines[1]);
            int CountOfBasePoints = Convert.ToInt32(lines[2]);

            int j = 3;
            // создаем для новой сетки id
            MyFiniteElementModel model = new MyFiniteElementModel(currentModel.Id, currentModel.ModelName, MyFiniteElementModel.GridType.Ruppert);
            int cur = parent.GetCurrentModelIndex();

            model.INOUT = parent.currentFullModel.FiniteElementModels[cur].INOUT;

            model.NP = Convert.ToInt32(lines[j++]); // число узлов в варианте сетки

            model.CORD.Add(0.0);
            for (int n = 1; n <= model.NP; n++)
            {
                int    Number = Convert.ToInt32(lines[j++]);
                double X      = Convert.ToDouble(lines[j++].Replace(".", ","));
                double Y      = Convert.ToDouble(lines[j++].Replace(".", ","));
                //int SeNum = Convert.ToInt32(slines[j++]);
                //int ZoneNum = Convert.ToInt32(slines[j++]);
                //string s = slines[j++];
                //s = slines[j++];
                j += 9;

                model.Nodes.Add(new MyNode(X, Y, Number));
                model.CORD.Add(X);
                model.CORD.Add(Y);
            }

            model.NE = Convert.ToInt32(lines[j++]); // число КЭ в варианте сетки

            for (int e = 1; e <= model.NE; e++)
            {
                int Number   = Convert.ToInt32(lines[j++]);
                int Node1    = Convert.ToInt32(lines[j++]);
                int Node2    = Convert.ToInt32(lines[j++]);
                int Node3    = Convert.ToInt32(lines[j++]);
                int Material = Convert.ToInt32(lines[j++]);

                List <MyNode> nodes = new List <MyNode>();
                nodes = model.Nodes.FindAll(n => n.Id == Node1 || n.Id == Node2 || n.Id == Node3);
                MyFiniteElement elem = new MyFiniteElement(Number, Material, nodes);
                elem.DefineArea(parent.currentFullModel.geometryModel.Areas);
                model.FiniteElements.Add(elem);
                nodes.Clear();
            }

            model.NOP.Add(0);
            for (int i = 0; i < model.NE; i++)
            {
                int n1 = model.FiniteElements[i].Nodes[0].Id;
                int n2 = model.FiniteElements[i].Nodes[1].Id;
                int n3 = model.FiniteElements[i].Nodes[2].Id;
                model.NOP.Add(n1);
                model.NOP.Add(n2);
                model.NOP.Add(n3);
            }

            File.Delete(Path.GetDirectoryName(this.parent.FullProjectFileName) + "\\grid.Ralg");
            parent.ModelCreated(model);
        }