public static MatrixFEM Count_J1_1_1(MatrixFEM J, Double[] detJ, bool count = false) //podzielenie macierzy Jakobianu J przez tablice wyznaczników detJ
        {
            if (J1_1_1 != null && !count)
            {
                return(J1_1_1);
            }

            J1_1_1 = new MatrixFEM();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    switch (i)
                    {
                    case 0:
                        J1_1_1[i, j] = J[3, i] / detJ[i];
                        break;

                    case 1:
                        J1_1_1[i, j] = J[1, i] / detJ[i];
                        break;

                    case 2:
                        J1_1_1[i, j] = J[2, i] / detJ[i];
                        break;

                    case 3:
                        J1_1_1[i, j] = J[0, i] / detJ[i];
                        break;
                    }
                }
            }
            return(J1_1_1);
        }
        public static Dictionary <IntegralPointsNames, MatrixFEM> Count_matrixC(MatrixFEM matrixN, Double c, Double ro, Double[] detJ = null)
        {
            if (detJ == null)
            {
                detJ = UniversalElementService.detJ;
            }

            var dictN = new Dictionary <IntegralPointsNames, MatrixFEM>();

            dictN[IntegralPointsNames.All] = new MatrixFEM();
            for (var k = 0; k < 4; k++)
            {
                dictN[(IntegralPointsNames)k] = new MatrixFEM();
                for (var i = 0; i < 4; i++)
                {
                    for (var j = 0; j < 4; j++)
                    {
                        dictN[(IntegralPointsNames)k][i, j]   = matrixN[i, k] * matrixN[j, k] * detJ[k] * c * ro;
                        dictN[IntegralPointsNames.All][i, j] += dictN[(IntegralPointsNames)k][i, j];
                    }
                }
            }

            return(dictN);
        }
Esempio n. 3
0
 public void ResetMatrixes()
 {
     H    = new MatrixFEM();
     Hbc  = new MatrixFEM();
     C    = new MatrixFEM();
     detJ = Enumerable.Repeat(0d, 4).ToArray();
     P    = Enumerable.Repeat(0d, 4).ToArray();
 }
Esempio n. 4
0
 public Element(Int64 id, int[] points)
 {
     ID    = id;
     Nodes = points;
     H     = new MatrixFEM();
     Hbc   = new MatrixFEM();
     C     = new MatrixFEM();
     detJ  = Enumerable.Repeat(0d, 4).ToArray();
     P     = Enumerable.Repeat(0d, 4).ToArray();
 }
Esempio n. 5
0
        public static MatrixFEM operator +(MatrixFEM a, MatrixFEM b)
        {
            var tmp = new MatrixFEM();

            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    tmp[i, j] = a[i, j] + b[i, j];
                }
            }
            return(tmp);
        }
Esempio n. 6
0
        public MatrixFEM GetTransposition()
        {
            var transposed = new MatrixFEM();

            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    transposed[i, j] = this[j, i];
                }
            }

            return(transposed);
        }
        public static MatrixFEM Count_Hbc_for_edge(Grid grid, Element element, Double alpha, BCForHbc pow)
        {
            MatrixFEM matrixHbc = new MatrixFEM();

            Node[]     nodes   = GetElementNodes(grid, element);
            Double[][] matrixN = new Double[2][];
            var        points  = UniversalElement.GetBCPoints(pow);
            Double     L       = 0;

            switch (pow)
            {
            case BCForHbc.Pow1:
                L = (Double)Math.Sqrt(Math.Pow(nodes[1].X - nodes[0].X, 2) + Math.Pow(nodes[1].Y - nodes[0].Y, 2));
                break;

            case BCForHbc.Pow2:
                L = (Double)Math.Sqrt(Math.Pow(nodes[2].X - nodes[1].X, 2) + Math.Pow(nodes[2].Y - nodes[1].Y, 2));
                break;

            case BCForHbc.Pow3:
                L = (Double)Math.Sqrt(Math.Pow(nodes[3].X - nodes[2].X, 2) + Math.Pow(nodes[3].Y - nodes[2].Y, 2));
                break;

            case BCForHbc.Pow4:
                L = (Double)Math.Sqrt(Math.Pow(nodes[0].X - nodes[3].X, 2) + Math.Pow(nodes[0].Y - nodes[3].Y, 2));
                break;
            }
            Double detJ = L / 2f;

            for (var i = 0; i < 2; i++)
            {
                matrixN[i]    = new Double[4];
                matrixN[i][0] = func_N1(points[i].Xi, points[i].Eta);
                matrixN[i][1] = func_N2(points[i].Xi, points[i].Eta);
                matrixN[i][2] = func_N3(points[i].Xi, points[i].Eta);
                matrixN[i][3] = func_N4(points[i].Xi, points[i].Eta);
            }

            for (var i = 0; i < 4; i++)
            {
                for (var j = 0; j < 4; j++)
                {
                    matrixHbc[i, j]  = matrixN[0][j] * matrixN[0][i];
                    matrixHbc[i, j] += matrixN[1][j] * matrixN[1][i];
                    matrixHbc[i, j] *= alpha * detJ;
                }
            }

            return(matrixHbc);
        }
        public static Double[] Count_detJ(MatrixFEM J, bool count = false) // wyznacznik macierzy Jakobianu przekształcenia J
        {
            if (detJ != null && !count)
            {
                return(detJ);
            }

            detJ = new Double[4];
            for (var i = 0; i < 4; i++)
            {
                detJ[i] = J[0, i] * J[3, i] - J[i, 1] * J[2, i];
            }
            return(detJ);
        }
        public static MatrixFEM GenerateMatrixFEM_WithStDerative(UniversalDeriative universalDeriative = UniversalDeriative.Without)
        {
            MatrixFEM matrix = new MatrixFEM();

            for (var i = 0; i < MatrixFEM.N; ++i)
            {
                matrix[0, i] = func_N1(UniversalElement.IntegralPoints[i].Xi, UniversalElement.IntegralPoints[i].Eta, universalDeriative);
                matrix[1, i] = func_N2(UniversalElement.IntegralPoints[i].Xi, UniversalElement.IntegralPoints[i].Eta, universalDeriative);
                matrix[2, i] = func_N3(UniversalElement.IntegralPoints[i].Xi, UniversalElement.IntegralPoints[i].Eta, universalDeriative);
                matrix[3, i] = func_N4(UniversalElement.IntegralPoints[i].Xi, UniversalElement.IntegralPoints[i].Eta, universalDeriative);
            }

            return(matrix);
        }
        public static MatrixFEM Count_J1_1(Grid grid, MatrixFEM NderEta, MatrixFEM NderXi, Element element) // obliczanie Jakobianu przekształcenia
        {
            Node[]    nodes = GetElementNodes(grid, element);
            MatrixFEM J     = new MatrixFEM();

            for (var i = 0; i < nodes.Length; i++)
            {
                J[0, i] = NderXi[0, 0] * nodes[0].X + NderXi[1, 0] * nodes[1].X + NderXi[2, 0] * nodes[2].X + NderXi[3, 0] * nodes[3].X;
                J[1, i] = NderXi[0, 0] * nodes[0].Y + NderXi[1, 0] * nodes[1].Y + NderXi[2, 0] * nodes[2].Y + NderXi[3, 0] * nodes[3].Y;
                J[2, i] = NderEta[0, 0] * nodes[0].X + NderEta[1, 0] * nodes[1].X + NderEta[2, 0] * nodes[2].X + NderEta[3, 0] * nodes[3].X;
                J[3, i] = NderEta[0, 0] * nodes[0].Y + NderEta[1, 0] * nodes[1].Y + NderEta[2, 0] * nodes[2].Y + NderEta[3, 0] * nodes[3].Y;
            }
            return(J);
        }
Esempio n. 11
0
        public static MatrixFEM operator*(MatrixFEM a, MatrixFEM b)
        {
            var tmp = new MatrixFEM();

            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    for (var k = 0; k < N; k++)
                    {
                        tmp[i, j] = a[i, k] + b[k, i];
                    }
                }
            }
            return(tmp);
        }
        public static MatrixFEM Count_dN_dy(MatrixFEM NderEta, MatrixFEM NderXi, bool count = false, MatrixFEM J = null) // macierz pochodnych funkcji kształtu po dx
        {
            if (dN_dy != null && !count)
            {
                return(dN_dy);
            }

            if (J == null)
            {
                J = J1_1_1;
            }
            dN_dy = new MatrixFEM();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    dN_dy[i, j] = J[2, i] * NderXi[i, j] + J[3, i] * NderEta[i, j];
                }
            }

            return(dN_dy);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            Net  _net  = new Net(@"E:\STUDIA\MES\PROGRAM\PROGRAM\ProgramData.json");
            Grid _grid = _net.GetGrid();

            var matrixNormal = UniversalElementService.GenerateMatrixFEM_WithStDerative();
            var matrixXi     = UniversalElementService.GenerateMatrixFEM_WithStDerative(UniversalDeriative.DerXi);
            var matrixEta    = UniversalElementService.GenerateMatrixFEM_WithStDerative(UniversalDeriative.DerEta);

            var time = _net.GetGlobalData().Time;
            var step = _net.GetGlobalData().Step;
            var nE   = _net.GetGlobalData().nE;

            var csv = new StringBuilder();

            //Console.WriteLine(NetService.PrintNodesTemperature(_net));

            for (var i = 0d; i < time; i += step)
            {
                for (var id = 0; id < nE; id++)
                {
                    var element = _grid.Elements[id];

                    var J = UniversalElementService.Count_J1_1(_grid, matrixEta, matrixXi, element);
                    element.detJ = UniversalElementService.Count_detJ(J, true);

                    var J1_1_1 = UniversalElementService.Count_J1_1_1(J, element.detJ, true);
                    var dN_dx  = UniversalElementService.Count_dN_dx(matrixEta, matrixXi, true, J1_1_1);
                    var dN_dy  = UniversalElementService.Count_dN_dy(matrixEta, matrixXi, true, J1_1_1);
                    var dictH  = UniversalElementService.Count_matrixH(_net.GetGlobalData().Conductivity, dN_dx, dN_dy, element.detJ);
                    element.H = dictH[MatrixHVariables.H][IntegralPointsNames.All];

                    var dictC = UniversalElementService.Count_matrixC(matrixNormal, _net.GetGlobalData().Specific_Heat, _net.GetGlobalData().Density, element.detJ);
                    element.C = dictC[IntegralPointsNames.All];

                    var Hbc = new MatrixFEM();
                    for (var pow = 0; pow < 4; pow++)
                    {
                        if (element.AreaBC[pow])
                        {
                            var L = 0d;
                            if ((BCForHbc)pow == BCForHbc.Pow1 || (BCForHbc)pow == BCForHbc.Pow3)
                            {
                                L = _net.GetGlobalData().l_el_W;
                            }
                            else
                            {
                                L = _net.GetGlobalData().l_el_H;
                            }

                            var vP = UniversalElementService.Count_PforPow(L, _net.GetGlobalData().T_ambient, _net.GetGlobalData().Alpha, (BCForHbc)pow);
                            element.Add_Pvector(vP);
                            Hbc = Hbc + UniversalElementService.Count_Hbc_for_edge(_grid, element, _net.GetGlobalData().Alpha, (BCForHbc)pow);
                        }
                    }
                    element.Hbc = Hbc;

                    NetService.AgregateToGlobalWithElement(element);
                }

                //Console.WriteLine("------------  [C]  -----------------\n" + NetService.PrintGlobalC());
                //Console.WriteLine("\n\n------------  [H]  -----------------\n" + NetService.PrintGlobalH());

                NetService.Count_H_C_dT(_net.GetGlobalData().nN, step);

                //Console.WriteLine("\n\n------------  [H] + [C]/dT  -----------------\n" + NetService.PrintMatrix(H_CdT));
                var P_C_T0 = NetService.Count_P_CdT_T0(_net.GetGlobalData().nN, step, _grid);
                //Console.WriteLine("\n\n------------  P_Vector  -----------------\n" + NetService.PrintMatrix(P_C_T0));
                var T_final = NetService.Count_Final_vector(_net.GetGlobalData().nN);
                NetService.PrepareToNextStep(_net.GetGlobalData().nN, _grid, T_final);

                var max = NetService.FindMax(T_final);
                var min = NetService.FindMin(T_final);

                //in your loop
                var newLine = string.Format("{0},{1},{2}", i, min, max);
                csv.AppendLine(newLine);



                //Console.WriteLine(NetService.PrintNodesTemperature(_net));
                Console.WriteLine(String.Format("{2} {0} {1}", min, max, i));
            }

            //after your loop
            File.WriteAllText(@"E:\STUDIA\MES\PROGRAM\PROGRAM\ProgramResult" + DateTime.Now.Millisecond + ".csv", csv.ToString());
        }
        public static Dictionary <MatrixHVariables, Dictionary <IntegralPointsNames, MatrixFEM> > Count_matrixH
            (Double K, MatrixFEM dN_dx = null, MatrixFEM dN_dy = null, Double[] detJ = null)
        {
            if (dN_dx == null || dN_dy == null || detJ == null)
            {
                dN_dx = UniversalElementService.dN_dx;
                dN_dy = UniversalElementService.dN_dy;
                detJ  = UniversalElementService.detJ;
            }

            //MatrixFEM dN_dxT = dN_dx.GetTransposition(), dN_dyT = dN_dy.GetTransposition();

            Dictionary <IntegralPointsNames, MatrixFEM> dictdNdx_dNdxT      = new Dictionary <IntegralPointsNames, MatrixFEM>();
            Dictionary <IntegralPointsNames, MatrixFEM> dictdNdy_dNdyT      = new Dictionary <IntegralPointsNames, MatrixFEM>();
            Dictionary <IntegralPointsNames, MatrixFEM> dictdNdx_dNdxT_detJ = new Dictionary <IntegralPointsNames, MatrixFEM>();
            Dictionary <IntegralPointsNames, MatrixFEM> dictdNdy_dNdyT_detJ = new Dictionary <IntegralPointsNames, MatrixFEM>();
            Dictionary <IntegralPointsNames, MatrixFEM> dictdNdx_dNdxT_dNdy_dNdyT_detJ_K = new Dictionary <IntegralPointsNames, MatrixFEM>();
            var dMatrixH = new Dictionary <IntegralPointsNames, MatrixFEM>();

            dMatrixH[IntegralPointsNames.All] = new MatrixFEM();

            for (var i = 0; i < 4; i++)
            {
                dictdNdx_dNdxT[(IntegralPointsNames)i]      = new MatrixFEM();
                dictdNdy_dNdyT[(IntegralPointsNames)i]      = new MatrixFEM();
                dictdNdx_dNdxT_detJ[(IntegralPointsNames)i] = new MatrixFEM();
                dictdNdy_dNdyT_detJ[(IntegralPointsNames)i] = new MatrixFEM();
                dictdNdx_dNdxT_dNdy_dNdyT_detJ_K[(IntegralPointsNames)i] = new MatrixFEM();
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (var k = 0; k < 4; k++)
                    {
                        dictdNdx_dNdxT[(IntegralPointsNames)k][i, j] = dN_dx[i, k] * dN_dx[j, k];
                        dictdNdy_dNdyT[(IntegralPointsNames)k][i, j] = dN_dy[i, k] * dN_dy[j, k];

                        dictdNdx_dNdxT_detJ[(IntegralPointsNames)k][i, j] = dictdNdx_dNdxT[(IntegralPointsNames)k][i, j] * detJ[k];
                        dictdNdy_dNdyT_detJ[(IntegralPointsNames)k][i, j] = dictdNdy_dNdyT[(IntegralPointsNames)k][i, j] * detJ[k];

                        dictdNdx_dNdxT_dNdy_dNdyT_detJ_K[(IntegralPointsNames)k][i, j] =
                            K * (dictdNdx_dNdxT_detJ[(IntegralPointsNames)k][i, j] + dictdNdy_dNdyT_detJ[(IntegralPointsNames)k][i, j]);

                        dMatrixH[IntegralPointsNames.All][i, j] += dictdNdx_dNdxT_dNdy_dNdyT_detJ_K[(IntegralPointsNames)k][i, j];
                    }
                }
            }

            var dictH = new Dictionary <MatrixHVariables, Dictionary <IntegralPointsNames, MatrixFEM> >();

            dictH[MatrixHVariables.dN_dx_T]         = dictdNdx_dNdxT;
            dictH[MatrixHVariables.dN_dy_T]         = dictdNdy_dNdyT;
            dictH[MatrixHVariables.dN_dx_T_detJ]    = dictdNdx_dNdxT_detJ;
            dictH[MatrixHVariables.dN_dy_T_detJ]    = dictdNdy_dNdyT_detJ;
            dictH[MatrixHVariables.dN_dx_dy_detJ_K] = dictdNdx_dNdxT_dNdy_dNdyT_detJ_K;
            dictH[MatrixHVariables.H] = dMatrixH;

            return(dictH);
        }