Exemplo n.º 1
0
        public double[] Modal(int nelx,
                              int nely,
                              double[] x,
                              double p,
                              double q,
                              out double[,] V)
        {
            var ke = K_Plain_strain(1e10, 0.3);
            var me = M_Plain_strain(1000, 1);
            int N  = 2 * (nelx + 1) * (nely + 1);

            double[][] K = new double[N][];
            double[][] M = new double[N][];
            for (int i = 0; i < N; i++)
            {
                K[i] = new double[N];
                M[i] = new double[N];
            }
            for (int elx = 0; elx < nelx; elx++)
            {
                for (int ely = 0; ely < nely; ely++)
                {
                    int n1   = (nely + 1) * elx + ely;
                    int n2   = (nely + 1) * (elx + 1) + ely;
                    var edof = np.array(2 * n1, 2 * n1 + 1, 2 * n2, 2 * n2 + 1, 2 * n2 + 2, 2 * n2 + 3, 2 * n1 + 2, 2 * n1 + 3);
                    for (int i = 0; i < edof.size; i++)
                    {
                        for (int j = 0; j < edof.size; j++)
                        {
                            K[edof[i]][edof[j]] = K[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], p) * ke[i][j];
                            M[edof[i]][edof[j]] = M[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], q) * me[i][j];
                        }
                    }
                }
            }

            int[] inds = new int[4 * (nely + 1)];
            //left and right border fix
            for (int i = 0; i < 2 * (nely + 1); i++)
            {
                inds[i] = i;
                inds[i + 2 * (nely + 1)] = N - 2 * (nely + 1) + i - 1;
            }


            double[,] Kmm = MatrixMath.To2D <double>(K);
            double[,] Mmm = MatrixMath.To2D <double>(M);


            Kmm = MatrixMath.CrossOut(Kmm, inds);
            Mmm = MatrixMath.CrossOut(Mmm, inds);


            int reducedN = Kmm.GetLength(0);

            double[] wr = new double[reducedN];
            //solve
            alglib.smatrixgevd(Kmm, reducedN, false, Mmm, false, 1, 1, out wr, out V);
            for (int i = 0; i < V.GetLength(0); i++)
            {
                for (int j = 0; j < V.GetLength(1); j++)
                {
                    V[i, j] = Math.Cos(wr[i]) * V[i, j];
                }
            }
            V = MatrixMath.FillOnWeird(V, inds);


            return(wr);
        }
Exemplo n.º 2
0
        public double[] FE_inded(int nelx, int nely, double[] x, Dictionary <int, double> f_map, double p)
        {
            var ke = KE;
            int N  = 2 * (nelx + 1) * (nely + 1);

            double[][] K_m = new double[N][];
            for (int i = 0; i < N; i++)
            {
                K_m[i] = new double[N];
            }
            for (int elx = 0; elx < nelx; elx++)
            {
                for (int ely = 0; ely < nely; ely++)
                {
                    int n1   = (nely + 1) * elx + ely;
                    int n2   = (nely + 1) * (elx + 1) + ely;
                    var edof = np.array(2 * n1, 2 * n1 + 1, 2 * n2, 2 * n2 + 1, 2 * n2 + 2, 2 * n2 + 3, 2 * n1 + 2, 2 * n1 + 3);
                    for (int i = 0; i < edof.size; i++)
                    {
                        for (int j = 0; j < edof.size; j++)
                        {
                            K_m[edof[i]][edof[j]] = K_m[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], p) * ke[i][j]; //?diagonal
                        }
                    }
                }
            }


            int[] inds = new int[2 * (nely + 1)];
            //left and right border fix
            for (int i = 0; i < 2 * (nely + 1); i++)
            {
                inds[i] = i;
            }
            Random r = new Random(123);

            double[,] Kmm = MatrixMath.To2D <double>(K_m);
            Kmm           = MatrixMath.CrossOut(Kmm, inds);
            int           reducedN = Kmm.GetLength(0);
            List <double> F_full   = Enumerable.Repeat(0.0, N).ToList();

            double[] X = new double[N];
            double[] F = new double[reducedN];
            //index crossout
            int c = 0;

            foreach (var q in f_map)
            {
                F_full[q.Key] = q.Value;
            }

            for (int i = 0; i < N; i++)
            {
                if (c < inds.Length && inds[c] == i)
                {
                    c++;
                }
                else
                {
                    F[i - c] = F_full[i];
                }
            }
            // F[reducedN -1] = -1e6;

            alglib.rmatrixsolvefast(Kmm, reducedN, ref F, out _);
            //index backfill
            c = 0;
            for (int i = 0; i < N; i++)
            {
                if (c < inds.Length && inds[c] == i)
                {
                    X[i] = 0;
                    c++;
                }
                else
                {
                    X[i] = F[i - c];
                }
            }
            return(X);
        }
Exemplo n.º 3
0
        public double[] FE(int nelx, int nely, double[] x, double p)
        {
            var ke = KE;
            int N  = 2 * (nelx + 1) * (nely + 1);

            double[][] K_m = new double[N][];
            for (int i = 0; i < N; i++)
            {
                K_m[i] = new double[N];
            }
            for (int elx = 0; elx < nelx; elx++)
            {
                for (int ely = 0; ely < nely; ely++)
                {
                    int n1   = (nely + 1) * elx + ely;
                    int n2   = (nely + 1) * (elx + 1) + ely;
                    var edof = np.array(2 * n1, 2 * n1 + 1, 2 * n2, 2 * n2 + 1, 2 * n2 + 2, 2 * n2 + 3, 2 * n1 + 2, 2 * n1 + 3);
                    for (int i = 0; i < edof.size; i++)
                    {
                        for (int j = 0; j < edof.size; j++)
                        {
                            K_m[edof[i]][edof[j]] = K_m[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], p) * ke[i][j]; //?diagonal
                        }
                    }
                }
            }


            int[] inds = new int[2 * (nely + 1)];
            //left and right border fix
            for (int i = 0; i < 2 * (nely + 1); i++)
            {
                inds[i] = i;
            }
            Random r = new Random(123);

            double[,] Kmm = MatrixMath.To2D <double>(K_m);
            Kmm           = MatrixMath.CrossOut(Kmm, inds);
            int reducedN = Kmm.GetLength(0);

            double[] F = new double[reducedN];
            double[] X = new double[N];
            for (int i = 0; i < nely; i++)
            {
                F[(2 * nely + 1) * nelx + i * 2 - 1] = -1;
            }
            F[reducedN - nely - 1] = r.NextDouble();
            alglib.rmatrixsolvefast(Kmm, reducedN, ref F, out _);
            int c = 0;

            for (int i = 0; i < N; i++)
            {
                if (c < inds.Length && inds[c] == i)
                {
                    X[i] = 0;
                    c++;
                }
                else
                {
                    X[i] = F[i - c];
                }
            }
            return(X);
        }
Exemplo n.º 4
0
        public double[] Harmonic(int nelx, int nely, double[] x, double p, double q, double wmega)
        {
            var ke = K_Plain_strain(1e10, 0.3);
            var me = M_Plain_strain(1000, 1);
            int N  = 2 * (nelx + 1) * (nely + 1);

            double[][] K = new double[N][];
            double[][] M = new double[N][];
            for (int i = 0; i < N; i++)
            {
                K[i] = new double[N];
                M[i] = new double[N];
            }
            for (int elx = 0; elx < nelx; elx++)
            {
                for (int ely = 0; ely < nely; ely++)
                {
                    int n1   = (nely + 1) * elx + ely;
                    int n2   = (nely + 1) * (elx + 1) + ely;
                    var edof = np.array(2 * n1, 2 * n1 + 1, 2 * n2, 2 * n2 + 1, 2 * n2 + 2, 2 * n2 + 3, 2 * n1 + 2, 2 * n1 + 3);
                    for (int i = 0; i < edof.size; i++)
                    {
                        for (int j = 0; j < edof.size; j++)
                        {
                            K[edof[i]][edof[j]] = K[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], p) * ke[i][j];
                            M[edof[i]][edof[j]] = M[edof[i]][edof[j]] + Math.Pow(x[ely + elx * (nely)], q) * me[i][j];
                        }
                    }
                }
            }

            int[] inds = new int[2 * (nely + 1)];
            //left border fix
            for (int i = 0; i < 2 * (nely + 1); i++)
            {
                inds[i] = i;
            }


            double[,] Kmm = MatrixMath.To2D <double>(K);
            double[,] Mmm = MatrixMath.To2D <double>(M);


            Kmm = MatrixMath.CrossOut(Kmm, inds);
            Mmm = MatrixMath.CrossOut(Mmm, inds);

            List <double> X        = new List <double>();
            int           reducedN = Kmm.GetLength(0);

            double[,] DSW = new double[reducedN, reducedN];

            for (int ik = 0; ik < Kmm.GetLength(0); ik++)
            {
                for (int jk = 0; jk < Kmm.GetLength(1); jk++)
                {
                    double l = wmega * 2 * Math.PI;
                    l           = l * l;
                    DSW[ik, jk] = Kmm[ik, jk] - l * Mmm[ik, jk];
                }
            }
            double[] F = new double[reducedN];
            double[] U = new double[reducedN];
            F[reducedN - 1] = -1e6;
            alglib.rmatrixsolve(DSW, reducedN, F, out _, out _, out U);
            int c = 0;

            for (int i = 0; i < N; i++)
            {
                if (c < inds.Length && inds[c] == i)
                {
                    X.Add(0);
                    c++;
                }
                else
                {
                    X.Add(U[i - c]);
                }
            }
            return(X.ToArray());
        }