Exemplo n.º 1
0
        public static BasisStorage getBase(Vertex x, Vertex y, Vertex z)
        {
            var middleCord = new Vertex()
            {
                X = (((x.X + y.X) / 2) + z.X) / 2,
                Y = (((x.Y + y.Y) / 2) + z.Y) / 2
            };


            return(new BasisStorage()
            {
                FiX = (HeronArea.getArea(middleCord, y, z) / HeronArea.getArea(x, y, z)),
                FiY = (HeronArea.getArea(x, middleCord, z) / HeronArea.getArea(x, y, z)),
                FiZ = (HeronArea.getArea(x, y, middleCord) / HeronArea.getArea(x, y, z)),
            });
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //DataStorage storage = new DataStorage();
            List <double>          squerArea       = new List <double>();
            List <EquationStorage> equationStorage = new List <EquationStorage>();

            double a11 = double.Parse(tbA11.Text.Replace('.', ','));
            double a22 = double.Parse(tbA22.Text.Replace('.', ','));
            double a12 = double.Parse(tbA12.Text.Replace('.', ','));

            var sigma = tbSigma.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => Convert.ToDouble(s.Replace(',', '.')));
            var sigmas = new double[6] {
                sigma.ToArray().Length >= 1 ? sigma.ToArray()[0] : 0,
                sigma.ToArray().Length >= 2 ? sigma.ToArray()[1] : 0,
                sigma.ToArray().Length >= 3 ? sigma.ToArray()[2] : 0,
                sigma.ToArray().Length >= 4 ? sigma.ToArray()[3] : 0,
                sigma.ToArray().Length >= 5 ? sigma.ToArray()[4] : 0,
                sigma.ToArray().Length >= 6 ? sigma.ToArray()[5] : 0,
            };
            var beta = tbBeta.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                       .Select(b => Convert.ToDouble(b.Replace(',', '.')));
            var betas = new double[6] {
                beta.ToArray().Length >= 1 ? beta.ToArray()[0] : 0,
                beta.ToArray().Length >= 2 ? beta.ToArray()[1] : 0,
                beta.ToArray().Length >= 3 ? beta.ToArray()[2] : 0,
                beta.ToArray().Length >= 4 ? beta.ToArray()[3] : 0,
                beta.ToArray().Length >= 5 ? beta.ToArray()[4] : 0,
                beta.ToArray().Length >= 6 ? beta.ToArray()[5] : 0,
            };
            var ds = tbD.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                     .Select(b => Convert.ToDouble(b.Replace(',', '.')));
            var d = new double[6] {
                ds.ToArray().Length >= 1 ? ds.ToArray()[0] : 0,
                ds.ToArray().Length >= 2 ? ds.ToArray()[1] : 0,
                ds.ToArray().Length >= 3 ? ds.ToArray()[2] : 0,
                ds.ToArray().Length >= 4 ? ds.ToArray()[3] : 0,
                ds.ToArray().Length >= 5 ? ds.ToArray()[4] : 0,
                ds.ToArray().Length >= 6 ? ds.ToArray()[5] : 0,
            };

            value = double.Parse(tbValue.Text.Replace('.', ','));

            GenerateConditions(sigmas, betas, d);

            double squareA11 = Math.Pow(double.Parse(tbA11.Text.Replace('.', ',')), 2);
            double squareA22 = Math.Pow(double.Parse(tbA22.Text.Replace('.', ',')), 2);
            double squareA12 = Math.Pow(double.Parse(tbA12.Text.Replace('.', ',')), 2);

            foreach (var item in storage.NT)
            {
                squerArea.Add(2 * HeronArea.getArea(item[0], item[1], item[2]));
                equationStorage.Add(MatrixKeConstants.getConstants(item[0], item[1], item[2]));
                Ne.Add(Basis.getBase(item[0], item[1], item[2]));
            }

            #region GetMAtrixKe
            double constant = 0;
            for (int i = 0; i < equationStorage.Count; i++)
            {
                constant = 1d / (2d * squerArea[i]);
                Ke.Add(new double[3, 3]
                {
                    {
                        constant *(squareA11 * Math.Pow(equationStorage[i].X.B, 2) + squareA22 * Math.Pow(equationStorage[i].X.C, 2)),
                        constant * (squareA11 * equationStorage[i].X.B * equationStorage[i].Y.B + squareA22 * equationStorage[i].X.C * equationStorage[i].Y.C),
                        constant * (squareA11 * equationStorage[i].X.B * equationStorage[i].Z.B + squareA22 * equationStorage[i].X.C * equationStorage[i].Z.C)
                    },
                    {
                        constant *(squareA11 * equationStorage[i].X.B * equationStorage[i].Y.B + squareA22 * equationStorage[i].X.C * equationStorage[i].Y.C),
                        constant * (squareA11 * Math.Pow(equationStorage[i].Y.B, 2) + squareA22 * Math.Pow(equationStorage[i].Y.C, 2)),
                        constant * (squareA11 * equationStorage[i].Y.B * equationStorage[i].Z.B + squareA22 * equationStorage[i].Y.C * equationStorage[i].Z.C)
                    },
                    {
                        constant *(squareA11 * equationStorage[i].X.B * equationStorage[i].Z.B + squareA22 * equationStorage[i].X.C * equationStorage[i].Z.C),
                        constant * (squareA11 * equationStorage[i].Y.B * equationStorage[i].Z.B + squareA22 * equationStorage[i].Y.C * equationStorage[i].Z.C),
                        constant * (squareA11 * Math.Pow(equationStorage[i].Z.B, 2) + squareA22 * Math.Pow(equationStorage[i].Z.C, 2))
                    }
                });
            }
            #endregion

            #region getMatrixMe
            constant = 0;
            for (int i = 0; i < squerArea.Count; i++)
            {
                constant = squerArea[i] / 24;
                Me.Add(new double[3, 3] {
                    {
                        2 * constant, 1 * constant, 1 * constant
                    },
                    {
                        1 * constant, 2 * constant, 1 * constant
                    },
                    {
                        1 * constant, 1 * constant, 2 * constant
                    }
                });
            }
            #endregion

            #region getMatrixRe
            var Uconst = 1d;
            var index  = 0;
            var matrix = DenseMatrix.OfArray(new double[, ] {
                { 1, 2 }, { 2, 1 }
            });
            foreach (var side in GetSegments())
            {
                var leftSide  = sigmas.ToArray()[index] / betas.ToArray()[index] * matrix;
                var rigthSide = sigmas.ToArray()[index] / betas.ToArray()[index] * matrix;
                var vector    = new[] { Uconst *side.UcCof, Uconst *side.UcCof };
                index++;
                foreach (var segment in side.Segments)
                {
                    var length = Math.Sqrt(Math.Pow(segment.Vertex1.X - segment.Vertex2.X, 2) +
                                           Math.Pow(segment.Vertex1.Y - segment.Vertex2.Y, 2));

                    var reLeft  = (leftSide * length / 6);
                    var reRight = (rigthSide * length / 6) * (new DenseVector(vector));
                    ReMatrix.Add(reLeft);
                    ReVector.Add(reRight);
                }
            }
            #endregion

            #region getMatrixQe

            foreach (var item in storage.NT)
            {
                foreach (var me in Me)
                {
                    var vector = GenerateQeMatrixes(item[0], item[1], item[2]);
                    var result = DenseMatrix.OfArray(me).Multiply(vector);
                    Qe.Add(result);
                }
            }

            #endregion

            PrintMatrix();
            WriteMatrix();

            JoinAllMatrixes();

            var res = A.Solve(B);
            //PrintResult();

            JsonParser.Write(res, "Result.json");
            JsonParser.Write(A.ToArray(), "A.json");
            JsonParser.Write(B.ToArray(), "B.json");

            WriteResultsToFile(res.ToList(), "Results.txt");
        }