예제 #1
0
        public static void OpenInputData(StreamReader sr, out Polygon polygon, out Model model, out Boundary boundary)
        {
            int countNodes = int.Parse(sr.ReadLine());

            polygon = new Polygon();
            for (int i = 0; i < countNodes; i++)
            {
                polygon.AddVertex(Node.Parse(sr.ReadLine()));
            }
            model = new Model();
            string k = sr.ReadLine();

            string[] kItems = k.Split();
            model.K[0, 0] = double.Parse(kItems[0]);
            model.K[0, 1] = double.Parse(kItems[1]);
            model.K[1, 0] = double.Parse(kItems[2]);
            model.K[1, 1] = double.Parse(kItems[3]);
            model.D       = double.Parse(sr.ReadLine());
            model.F       = double.Parse(sr.ReadLine());
            List <BoundaryCharacteristic> listBoundaryCharacteristic = new List <BoundaryCharacteristic>();

            for (int i = 0; i < countNodes; i++)
            {
                listBoundaryCharacteristic.Add(BoundaryCharacteristic.Parse(sr.ReadLine()));
            }
            boundary = new Boundary(listBoundaryCharacteristic.ToArray());
        }
예제 #2
0
        private void Save(int i)
        {
            BoundaryCharacteristic bc = new BoundaryCharacteristic();

            bc.Delta        = double.Parse(textBox1.Text);
            bc.Beta         = double.Parse(textBox2.Text);
            bc.UC           = double.Parse(textBox3.Text);
            bc.U0           = double.Parse(textBox4.Text);
            bc.Condition    = (BoundaryCondition)comboBox1.SelectedIndex;
            listBoundary[i] = bc;
        }
예제 #3
0
        public static Vector GetBoundaryVector(Matrix K, double d, double f, Domain domain, int k)
        {
            Vector     v        = new Vector(3);
            Triangle   triangle = domain.mesh.triangles[k];
            List <int> indexs   = new List <int>();

            indexs.Add(triangle.IndexA);
            indexs.Add(triangle.IndexB);
            indexs.Add(triangle.IndexC);

            Segment s1 = new Segment(domain.mesh.nodes[indexs[0]], domain.mesh.nodes[indexs[1]], ElemType.Boundary, indexs[0], indexs[1]);
            Segment s2 = new Segment(domain.mesh.nodes[indexs[1]], domain.mesh.nodes[indexs[2]], ElemType.Boundary, indexs[1], indexs[2]);
            Segment s3 = new Segment(domain.mesh.nodes[indexs[2]], domain.mesh.nodes[indexs[0]], ElemType.Boundary, indexs[2], indexs[0]);


            for (int q = 0; q < domain.mesh.boundary.Count; q++)
            {
                Segment segment = domain.mesh.boundary[q];
                BoundaryCharacteristic curCharacteristic = domain.boundary.GetCharacteristic(segment.EdgeNumber);
                if (curCharacteristic.Condition == BoundaryCondition.Third)
                {
                    double length = segment.length();
                    double coef   = curCharacteristic.Delta / curCharacteristic.Beta;

                    if (segment.Equal(s1))
                    {
                        List <int> ind = new List <int>();
                        ind.Add(0);
                        ind.Add(1);
                        for (int i = 0; i < ind.Count; i++)
                        {
                            v[ind[i]] += coef * curCharacteristic.UC * length / 2;
                        }
                    }

                    if (segment.Equal(s2))
                    {
                        List <int> ind = new List <int>();
                        ind.Add(1);
                        ind.Add(2);
                        for (int i = 0; i < ind.Count; i++)
                        {
                            v[ind[i]] += coef * curCharacteristic.UC * length / 2;
                        }
                    }

                    if (segment.Equal(s3))
                    {
                        List <int> ind = new List <int>();
                        ind.Add(2);
                        ind.Add(0);
                        for (int i = 0; i < ind.Count; i++)
                        {
                            v[ind[i]] += coef * curCharacteristic.UC * length / 2;
                        }
                    }
                }
            }


            return(v);
        }
예제 #4
0
        public static Vector Solve(Matrix K, double d, double f, Domain domain)
        {
            Matrix totalMatrix = new Matrix(domain.mesh.nodes.Count, domain.mesh.nodes.Count);
            Vector totalVector = new Vector(domain.mesh.nodes.Count);

            // Surface integral
            foreach (Triangle triangle in domain.mesh.triangles)
            {
                List <int> indexs = new List <int>();
                indexs.Add(triangle.IndexA);
                indexs.Add(triangle.IndexB);
                indexs.Add(triangle.IndexC);
                double square = Triangle.Square(domain.mesh.nodes[indexs[0]],
                                                domain.mesh.nodes[indexs[1]],
                                                domain.mesh.nodes[indexs[2]]);

                double[] b = new double[3];
                double[] c = new double[3];

                c[0] = domain.mesh.nodes[indexs[1]].X - domain.mesh.nodes[indexs[2]].X;
                b[0] = domain.mesh.nodes[indexs[2]].Y - domain.mesh.nodes[indexs[1]].Y;

                c[1] = domain.mesh.nodes[indexs[2]].X - domain.mesh.nodes[indexs[0]].X;
                b[1] = domain.mesh.nodes[indexs[0]].Y - domain.mesh.nodes[indexs[2]].Y;

                c[2] = domain.mesh.nodes[indexs[0]].X - domain.mesh.nodes[indexs[1]].X;
                b[2] = domain.mesh.nodes[indexs[1]].Y - domain.mesh.nodes[indexs[0]].Y;


                for (int i = 0; i < indexs.Count; i++)
                {
                    for (int j = 0; j < indexs.Count; j++)
                    {
                        if (i == j)
                        {
                            totalMatrix[indexs[i], indexs[j]] += (K[0, 0] * b[j] * b[i] + K[1, 1] * c[j] * c[i]) / (4 * square) + d * square / 6;
                        }
                        else
                        {
                            totalMatrix[indexs[i], indexs[j]] += (K[0, 0] * b[j] * b[i] + K[1, 1] * c[j] * c[i]) / (4 * square) + d * square / 12;
                        }
                    }
                    totalVector[indexs[i]] += f * square / 3;
                }
            }



            //Line integral

            List <int>    firstConditionNodes  = new List <int>();
            List <double> firstConditionValues = new List <double>();

            foreach (Segment segment in domain.mesh.boundary)
            {
                BoundaryCharacteristic curCharacteristic = domain.boundary.GetCharacteristic(segment.EdgeNumber);
                if (curCharacteristic.Condition == BoundaryCondition.Third)
                {
                    List <int> indexs = new List <int>();
                    indexs.Add(segment.IndexA);
                    indexs.Add(segment.IndexB);

                    double length = Node.length(domain.mesh.nodes[indexs[0]], domain.mesh.nodes[indexs[1]]);//segment.length();
                    double coef   = curCharacteristic.Delta / curCharacteristic.Beta;

                    for (int i = 0; i < indexs.Count; i++)
                    {
                        for (int j = 0; j < indexs.Count; j++)
                        {
                            if (i == j)
                            {
                                totalMatrix[indexs[i], indexs[j]] += coef * length / 3;
                            }
                            else
                            {
                                totalMatrix[indexs[i], indexs[j]] += coef * length / 6;
                            }
                        }
                        totalVector[indexs[i]] += coef * curCharacteristic.UC * length / 2;
                    }
                }
                else
                {
                    if (curCharacteristic.Condition == BoundaryCondition.First)
                    {
                        if (firstConditionNodes.FindItem(segment.IndexA) == -1)
                        {
                            firstConditionNodes.Add(segment.IndexA);
                            firstConditionValues.Add(curCharacteristic.U0);
                        }
                        else
                        {
                            int k = firstConditionNodes.FindItem(segment.IndexA);
                            firstConditionValues[k] = (firstConditionValues[k] + curCharacteristic.U0) / 2;
                        }
                        if (firstConditionNodes.FindItem(segment.IndexB) == -1)
                        {
                            firstConditionNodes.Add(segment.IndexB);
                            firstConditionValues.Add(curCharacteristic.U0);
                        }
                        else
                        {
                            int k = firstConditionNodes.FindItem(segment.IndexB);
                            firstConditionValues[k] = (firstConditionValues[k] + curCharacteristic.U0) / 2;
                        }
                    }
                }
            }


            //First boundary condition
            for (int i = 0; i < firstConditionNodes.Count; i++)
            {
                for (int j = 0; j < totalVector.Length; j++)
                {
                    totalVector[j] -= firstConditionValues[i] * totalMatrix[j, firstConditionNodes[i]];
                }
            }

            totalMatrix = Matrix.DecreaseMatrix(totalMatrix, firstConditionNodes);
            totalVector = Vector.DecreaseVector(totalVector, firstConditionNodes);

            Vector notBoundaryElements = totalMatrix.LUalgorithm(totalVector);

            Vector res = new Vector(domain.mesh.nodes.Count);
            int    curNotBoundaryElements = 0;

            for (int i = 0; i < res.Length; i++)
            {
                if (firstConditionNodes.FindItem(i) == -1)
                {
                    res[i] = notBoundaryElements[curNotBoundaryElements];
                    curNotBoundaryElements++;
                }
                else
                {
                    res[i] = firstConditionValues[firstConditionNodes.FindItem(i)];
                }
            }


            return(res);
        }