Example #1
0
 public static Vector LU(Matrix A, Vector b)
 {
     double sum;
     LU lu = new LU(A);
     Matrix Rez = lu.L_U;
     Vector B_i = lu.M * b;
     Vector X = new Vector(A.ColumnCount);
     for (int i = A.ColumnCount - 1; i >= 0; i--)
     {
         if (i == A.ColumnCount - 1)
         {
             X[i] = B_i[i] / Rez[i, i];
         }
         else
         {
             sum = 0;
             for (int j = i; j < A.ColumnCount; j++)
             {
                 sum += Rez[i, j] * X[j];
             }
             X[i] = (B_i[i] - sum) / Rez[i, i];
         }
     }
     return X;
 }
        public Vector GetResultAtPoint(Point point, double t)
        {
            Vector res = new Vector(3);

            double L = _rectangle.Width / 2;

            double x = point.X - L;
            double z = point.Y;//- model.Shape.H / 2;


            double w = wK1 * ((x - L) * (x - L) - l2)
                - wK2 / 4 * ((x - L) * (x - L) * (x - L) * (x - L) - l4)
                - wK2 * (l3 * x + l3 * L);

            double u = p * p * (1 / (6 * Lambda * D)) * ((x - L) * (x - L) * (x - L) * (x - L) * (x - L) / 5 + l3 * (x - L) * (x - L) * 0.5 - 0.3 * l5) -
                        p * p / (2 * Lambda * Lambda) * ((x - L) * (x - L) * (x - L) / 3 + l3 / 3) -
                        p * p / (72 * D * D) * ((x - L) * (x - L) * (x - L) * (x - L) * (x - L) * (x - L) * (x - L) / 7 + (x - L) * (x - L) * (x - L) * (x - L) * l3 / 2 + l6 * x + l7 / 7);
            //- p * p / (28 * D * D) * l7;


            double y = wK2 * ((x - L) * (x - L) * (x - L) + l3);

            res[0] = u + z * y;
            res[1] = 0;
            res[2] = w;

            return res;
        }
 public Material()
 {
     E = new Vector(DIMENSIONS);
     v = new Matrix(DIMENSIONS, DIMENSIONS);
     G = new Matrix(DIMENSIONS, DIMENSIONS);
     Rho = 0;
 }
        public static CauchyProblemResult AdamsBashforthMethodsSolve(Func<double, Vector, Vector> f, Vector initValue, double maxTime, int intervals)
        {
            double deltaTime = maxTime / intervals;
            CauchyProblemResult result = new CauchyProblemResult(deltaTime);

            CauchyProblemResult firstResult = CauchyProblemSolver.HeunMethodSolve(f, initValue, deltaTime * 2, 2);

            foreach (Vector res in firstResult.Results)
            {
                result.AddResult(res);
            }

            for (int t = 3; t <= intervals; t++)
            {
                int lastIndex = result.Results.Count - 1;
                Vector u_n_2 = result.Results[lastIndex - 2];
                Vector u_n_1 = result.Results[lastIndex - 1];
                Vector u_n = result.Results[lastIndex];

                Vector u = u_n + (deltaTime / 12) * (23 * f(deltaTime * lastIndex, u_n) - 16 * f(deltaTime * (lastIndex - 1), u_n_1) + 5 * f(deltaTime * (lastIndex - 2), u_n_2));
                result.AddResult(u);
            }

            return result;
        }
 public static double MaxEigenValue(Matrix val, double E = 0.01)
 {
     Matrix C = new Matrix(val);
     C *= MathM.Transpose(C);
     double rez = 0;
     Vector X = new Vector(val.ColumnCount);
     X[0] = 1;
     Vector Y;
     Vector X1 = new Vector(X);
     if (val.Squar)
     {
         double m;
         do
         {
             X = X1;
             Y = C * X;
             m = 0;
             for (int i = 0; i < Y.Count;i++ )
                 {
                     if (Math.Abs(Y[i]) > m) m = Math.Abs(Y[i]);
                 }
             X1 = (1 / m) * Y;
         }
         while (MathM.vect_norm_inf(X - X1) > E);
         rez = m;
     }
     else
     {
         throw new Exception("Матрица должна быть квадратной");
     }
     return rez;
 }
Example #6
0
 public static Vector operator *(double a, Vector op2)
 {
     Vector temp = new Vector(op2.Count);
     for (int i = 0; i < temp.Count; i++)
         temp[i] = op2[i] * a;
     return temp;
 }
        public override IEnumerable<INumericalResult> Solve(int resultsCount)
        {
            List<INumericalResult> results = new List<INumericalResult>();
            
            if (_mesh.IsMeshGenerated)
            {
                GetConstantMatrix();
                _indeciesToDelete = getIndeciesWithStaticBoundaryConditions();
                Matrix StiffnessMatrix = AsumeStaticBoundaryConditions(GetStiffnessMatrix(), _indeciesToDelete);
                Matrix MassMatrix = AsumeStaticBoundaryConditions(GetMassMatrix(), _indeciesToDelete);

                _init = AsumeStaticBoundaryConditionsToVector(_init, _indeciesToDelete);

                CauchyProblemResult newmarkResult = NewmarkSolver(MassMatrix, StiffnessMatrix, _init, 0.5, 0.5, _maxTime, _intervalsTime);
                
                SemidiscreteVibrationsNumericalResult result = new SemidiscreteVibrationsNumericalResult(_mesh.Elements, newmarkResult.DeltaTime, _maxTime);
                foreach (Vector v in newmarkResult.Results) {
                    Vector resultWithStaticPoints = addStaticPoints(v, _indeciesToDelete);
                    result.AddResult(resultWithStaticPoints);
                }

                results.Add(result);
            }
            return results;
        }
        public override IEnumerable<INumericalResult> Solve(int resultsCount)
        {
            List<INumericalResult> results = new List<INumericalResult>();
            previousRes = new StaticNumericalResult(_mesh.Elements, null);
            results.Add(previousRes);
            _iterations = 0;

            if (_mesh.IsMeshGenerated)
            {
                GetConstantMatrix();    
                Vector U = new Vector(_mesh.Nodes.Count*2);

                do
                {
                    previousRes.U = U;
                    Matrix StiffnessMatrix = GetStiffnessMatrix();
                    Vector TotalVector = GetTotalVector();
                    AsumeStaticBoundaryConditions(StiffnessMatrix, TotalVector);
                    U = StiffnessMatrix.LUalgorithm(TotalVector);
                    _iterations++;
                } while ((Vector.Norm(previousRes.U - U) > _error*Vector.Norm(U)) && (_iterations < _maxIterations));

                previousRes.U = U;
            }
            return results;
        }
        public void LogEigenVector(Vector eigenvector, int nodesOnLine)
        {
            nodesOnLine++;
            nodesOnLine *= 2;
            sw.WriteLine("In first dimenssion\n");

            for (int i = 0; i < eigenvector.Length; i++)
            {
                if (i % 2 == 0)
                {
                    sw.WriteLine(eigenvector[i]);
                }
                if ((i+1) % nodesOnLine == 0)
                {
                    sw.WriteLine();
                }
            }

            sw.WriteLine("\n\nIn second dimenssion\n");

            for (int i = 0; i < eigenvector.Length; i++)
            {
                if (i % 2 == 1)
                {
                    sw.WriteLine(eigenvector[i]);
                }

                if ((i + 1) % nodesOnLine == 0)
                {
                    sw.WriteLine();
                }
            }
        }
 public NewmarkVibrationNonLinearSolver(Model model, Mesh mesh, double error, Vector init, double maxTime, int intervalsTime)
     : base(model, mesh)
 {
     _error = error;
     _init = init;
     _maxTime = maxTime;
     _intervalsTime = intervalsTime;
 }
 public EigenValuesCylindricalPlateNumericalResult(List<IFiniteElement> elements, Vector result, double frequency, double h)
 {
     Elements = elements;
     U = result;
     _frequency = frequency;
     this.h = h;
 
 }
        public override IEnumerable<INumericalResult> Solve(int resultsCount)
        {
            IEnumerable<INumericalResult> results = new List<INumericalResult>();
            
            if (_mesh.IsMeshGenerated)
            {
                GetConstantMatrix();
                
                indeciesToDelete = getIndeciesWithStaticBoundaryConditions();

                Matrix stiffnessMatrix = GetStiffnessMatrix();
                stiffnessMatrix = applyStaticBoundaryConditions(stiffnessMatrix, indeciesToDelete);

                Matrix massMatrix = GetMassMatrix();
                massMatrix = applyStaticBoundaryConditions(massMatrix, indeciesToDelete);

                
#if (ALL_LAMBDAS)

                Vector firstEigenVector = null;
                double[] lambdas = null;
                Vector[] eigenVectors = null;
                int iterations = 0;
                do
                {
                    if (eigenVectors != null)
                    {
                        firstEigenVector = eigenVectors[0];
                    }
                    else 
                    {
                        firstEigenVector = new Vector(stiffnessMatrix.CountRows);
                    }

                    firstEigenVector = applyAmplitudeToVector(firstEigenVector);

                    Matrix nonlinearMatrix = GetNonlinearMatrix(firstEigenVector);
                    nonlinearMatrix = applyStaticBoundaryConditions(nonlinearMatrix, indeciesToDelete);

                    Matrix k = stiffnessMatrix + nonlinearMatrix;
                    lambdas = k.GetEigenvalueSPAlgorithm(massMatrix, out eigenVectors, _error, resultsCount);
                    iterations++;
                }
                while ((Vector.Norm(eigenVectors[0] - firstEigenVector) > _error) &&(iterations < _maxIterations));
                results = generateVibrationResults(lambdas, eigenVectors);

#else
                Vector eigenVector;
                double lambda = StiffnessMatrix.GetMaxEigenvalueSPAlgorithm(out eigenVector, _error);
                addStaticPoints(eigenVector);

                EigenValuesNumericalResult result = new EigenValuesNumericalResult(_mesh.Elements, eigenVector, Math.Sqrt(lambda / _model.Material.Rho));
                results.Add(result);
#endif
            }
            return results;
        }
 public Vector(Vector v)
 {
     this.n = v.n;
     vector = new double[this.n];
     for (int i = 0; i < this.n; i++)
     {
         vector[i] = v[i];
     }
 }
 public static Vector GetUByIndex(int index, Vector U)
 {
     Vector res = new Vector(2);
     if (U != null)
     {
         res[0] = U[2 * index];
         res[1] = U[2 * index + 1];
     }
     return res;
 }
        public void HeunMethodSolveTest()
        {
            Func<double, Vector, Vector> f = testF;
            
            Vector initValue = new Vector(2);
            initValue[0] = 0;
            initValue[1] = -3;

            double maxTime = 20; 
            int intervals = 200;
            CauchyProblemResult actual = CauchyProblemSolver.GirMethodsSolve(f, initValue, maxTime, intervals);
            Assert.AreEqual(actual, actual);
        }
 private Vector GetUByElement(IFiniteElement element)
 {
     Vector res = new Vector(8);
     if (U != null)
     {
         for (int i = 0; i < element.Count; i++)
         {
             res[2 * i] = U[2 * element[i].Index];
             res[2 * i + 1] = U[2 * element[i].Index + 1];
         }
     }
     return res;
 }
 public void InsertTest()
 {
     int startLength = 5;
     Vector vector = new Vector(startLength);// TODO: Initialize to an appropriate value
     vector[0] = 1;
     vector[1] = 2;
     vector[2] = 3;
     vector[3] = 4;
     vector[4] = 5;
     double value = 10; // TODO: Initialize to an appropriate value
     int index = 5; // TODO: Initialize to an appropriate value
     vector.Insert(value, index);
     Assert.AreEqual(startLength+1, vector.Length);
 }
        public static Vector Fadeev_Values(Matrix val, double e = 0.001)
        {
            Fadeev fadeev = new Fadeev(val);
            Console.WriteLine("Q=" + fadeev.Q);
            double temp = 0;
            Vector eigenvalues = new Vector(val.ColumnCount);
            Vector I = Intervals(val, fadeev.Q);
            for (int i = 0; i < val.ColumnCount; i++)
            {
                temp = method_bisection(fadeev.Q, I[i], I[i + 1], e);
                eigenvalues[i] = temp;
            }

            return eigenvalues;
        }
        public static Vector Danilevsky_Values(Matrix val, double e = 0.001)
        {
            Danilevsky dan = new Danilevsky(val);
            Console.WriteLine("Q=" + dan.Q);
            double temp = 0;
            Vector eigenvalues = new Vector(val.ColumnCount);
            Vector I = new Vector(Intervals(val, dan.Q));
            for (int i = 0; i < val.ColumnCount; i++)
            {
                temp = method_bisection(dan.Q, I[i], I[i + 1], e);
                eigenvalues[i] = temp;
            }

            return eigenvalues;
        }
 public static Vector operator +(Vector v1, Vector v2)
 {
     if (v1.Length == v2.Length)
     {
         Vector res = new Vector(v1.Length);
         for (int i = 0; i < v1.Length; i++)
         {
             res[i] = v1[i] + v2[i];
         }
         return res;
     }
     else
     {
         throw new Exception("Sum of vector cannot be count!!!");
     }
 }
Example #21
0
 public static Matrix Inverse_LU(Matrix val)
 {
     Matrix original = new Matrix(val);
     Matrix rez = new Matrix(val.RowCount, val.ColumnCount);
     Matrix E = Matrix.Get_Identity_Matrix(val.RowCount);
     Vector L = new Vector(val.RowCount);
     for (int i = 0; i < val.ColumnCount; i++)
     {
         L = SLAU.LU(original, E.Get_column(i));
         for (int j = 0; j < val.RowCount; j++)
         {
             rez[j, i] = L[j];
         }
     }
     return rez;
 }
        public static CauchyProblemResult HeunMethodSolve(Func<double, Vector, Vector> f, Vector initValue, double maxTime, int intervals)
        {
            double deltaTime = maxTime / intervals;
            CauchyProblemResult result = new CauchyProblemResult(deltaTime);
            Vector v = initValue;
            result.AddResult(v);

            for (double t = deltaTime; t <= maxTime; t += deltaTime)
            {
                Vector prevV = result.Results.Last();
                Vector prevF = f(t, prevV);
                v = prevV + (deltaTime / 2) * (f(t, prevV + deltaTime * prevF) + prevF);
                result.AddResult(v);
            }

            return result;
        }
        //static == fixed
        private void AsumeStaticBoundaryConditions(Matrix stiffnessMatrix, Vector totalVector)
        {
            foreach(Edge edge in _model.Shape.Edges)
            {
                BoundaryCondition boundaryCondition = _model.BoundaryConditions[edge];
                if (boundaryCondition.Type == BoundaryConditionsType.Static)
                {
                    IEnumerable<FiniteElementNode> nodes = _mesh.GetNodesOnEdge(edge);
                    foreach (FiniteElementNode node in nodes)
                    {
                        stiffnessMatrix[2 * node.Index, 2 * node.Index] *= 1000000000000;
                        stiffnessMatrix[2 * node.Index + 1, 2 * node.Index + 1] *= 1000000000000;
                    }
                }
                else
                {
                    IEnumerable<FiniteElementRectangleEdge> segments = _mesh.GetSegmentsOnEdge(edge);
                    foreach (FiniteElementRectangleEdge FiniteElementRectangleEdge in segments)
                    {
                        Vector localVector = GetLocalTotalVector(FiniteElementRectangleEdge, boundaryCondition.Value);
                        for (int i = 0; i < FiniteElementRectangleEdge.Count; i++)
                        {
                            totalVector[2 * FiniteElementRectangleEdge[i].Index] += localVector[2 * i];
                            totalVector[2 * FiniteElementRectangleEdge[i].Index + 1] += localVector[2 * i + 1];
                        }
                    }
                }
            }

            foreach (Point point in _model.Shape.Points)
            {
                BoundaryCondition pointCondition = _model.PointConditions[point];
                if (pointCondition.Type == BoundaryConditionsType.Static)
                {
                    FiniteElementNode node = _mesh.GetNodeOnPoint(point);
                    if (node != null)
                    {
                        stiffnessMatrix[2 * node.Index, 2 * node.Index] *= 1000000000000;
                        stiffnessMatrix[2 * node.Index + 1, 2 * node.Index + 1] *= 1000000000000;
                    }
                }
            }
        }
Example #24
0
 public static Vector Kramer(Matrix A, Vector b)
 {
     Vector X = new Vector(A.ColumnCount);
     Matrix temp = new Matrix(A.RowCount, 0);
     for (int i = 0; i < A.ColumnCount; i++)
     {
         temp = new Matrix(A.RowCount, 0);
         for (int j = 0; j < A.ColumnCount; j++)
         {
             if (j == i)
             {
                 temp = temp.AddColumn(b);
             }
             else
             {
                 temp = temp.AddColumn(A.Get_column(j));
             }
         }
         X[i] = MathM.Determinant(temp) / MathM.Determinant(A);
     }
     return X;
 }
Example #25
0
        public Fadeev(Matrix val)
        {
            double q;
            Matrix B = Matrix.Get_Identity_Matrix(val.RowCount);
            Matrix B1 = new Matrix(val.RowCount, val.ColumnCount);
            Matrix A1 = new Matrix();
            Matrix A = new Matrix(val);
            Matrix rez = new Matrix(val);
            Matrix tmp = new Matrix(B);
            Q = new Vector(val.RowCount);
            for (int i = 0; i < val.ColumnCount; i++)
            {
                A1 = A * B;
                q = MathM.Trace(A1) / Convert.ToDouble(i + 1);
                B1 = new Matrix(B);
                B = A1 - q * tmp;
                Q[i] = q;

            }
            B_n = B1;
            F = rez;
        }
        private CauchyProblemResult NewmarkSolver(Matrix massMatrix, Matrix stiffnessMatrix, Vector initValue, double gamma, double alfa, double maxTime, int intervals)
        {
            double deltaTime = maxTime / intervals;
            CauchyProblemResult result = new CauchyProblemResult(deltaTime);

            double a1 = (2 / (deltaTime * deltaTime * gamma));
            double a2 = (2 / (deltaTime * gamma));
            double a3 = ((1 / gamma) - 1);

            double a4 = deltaTime * (1-alfa); 
            double a5 = deltaTime * alfa;

            Vector u = initValue;
            Vector du = new Vector(initValue.Length);
            Vector ddu = massMatrix.LUalgorithm((-1) * stiffnessMatrix * initValue);

            result.AddResult(u);

            Matrix K = massMatrix * a1 + stiffnessMatrix;
            for (double t = deltaTime; t <= maxTime; t += deltaTime)
            {
                Vector uprev = u;
                Vector duprev = du;
                Vector dduprev = ddu;

                Vector F = massMatrix * (a1 * uprev + a2 * duprev + a3 * dduprev);
                u = K.LUalgorithm(F);

                ddu = a1 * (u - uprev) - a2 * duprev - a3 * dduprev;
                du = duprev + a4 * dduprev + a5 * ddu;

                ApplyNonlinearity(massMatrix, stiffnessMatrix, ref u, ref du, ref ddu, a1, a2, a3, a4, a5);

                result.AddResult(u);
            }

            return result;
        }
Example #27
0
 public static Vector The_method_of_simple_iteration(Matrix A, Vector b)
 {
     Matrix original = new Matrix(A);
     Matrix B = new Matrix(A.RowCount, A.ColumnCount);
     Vector T;
     Vector X = new Vector(A.ColumnCount);
     Vector X1 = new Vector(A.ColumnCount);
     Vector d = new Vector(A.ColumnCount);
     B = Matrix.Get_Identity_Matrix(A.RowCount) - original;
     if (MathM.Matrix_norm_inf(B) < 1)
     {
         X1 = new Vector(b);
         d = new Vector(X1);
         double k;
         double sum = 0;
         do
         {
             X = new Vector(X1);
             for (int i = 0; i < B.RowCount; i++)
             {
                 sum = 0;
                 for (int j = 0; j < B.ColumnCount; j++)
                 {
                     sum += B[i, j] * X[j];
                 }
                 X1[i] = sum + d[i];
             }
             T = X1 - X;
             k = MathM.vect_norm_inf(T);
         }
         while (k >= e);
         return X1;
     }
     else
     {
         throw new Exception("Итерационный процес не сходится");
     }
 }
Example #28
0
 public Danilevsky(Matrix val)
 {
     Matrix original = new Matrix(val);
     A = new Matrix(val);
     Q = new Vector(val.RowCount);
     Matrix M1 = Matrix.Get_Identity_Matrix(val.RowCount);
     Matrix M = Matrix.Get_Identity_Matrix(val.RowCount);
     S = Matrix.Get_Identity_Matrix(val.RowCount);
     for (int k = 0; k < val.ColumnCount - 1; k++)
     {
         M1 = Matrix.Get_Identity_Matrix(val.RowCount);
         M = Matrix.Get_Identity_Matrix(val.RowCount);
         for (int i = 0; i < val.ColumnCount; i++)
         {
             if (A[val.RowCount - 1 - k, val.RowCount - 2 - k] == 0)
             {
                 throw new Exception("деление на ноль");
             }
             if (i != val.RowCount - 2 - k)
             {
                 M[val.RowCount - 2 - k, i] = ((-1) * A[val.RowCount - 1 - k, i]) / A[val.RowCount - 1 - k, val.RowCount - 2 - k];
             }
             else
             {
                 M[val.RowCount - 2 - k, i] = 1 / A[val.RowCount - 1 - k, val.RowCount - 2 - k];
             }
             M1[val.RowCount - 2 - k, i] = A[val.RowCount - k - 1, i];
         }
         S *= M;
         A = M1 * A * M;
     }
     for (int i = 0; i < val.ColumnCount; i++)
     {
         Q[i] = A[0, i];
     }
     S = MathM.Inverse_Fadeev(S);
 }
        public static CauchyProblemResult GirMethodsSolve(Func<double, Vector, Vector> f, Vector initValue, double maxTime, int intervals)
        {
            double eps = 0.001;
            double deltaTime = maxTime / intervals;
            CauchyProblemResult result = new CauchyProblemResult(deltaTime);

            CauchyProblemResult firstResult = CauchyProblemSolver.HeunMethodSolve(f, initValue, deltaTime * 2, 2);

            foreach (Vector res in firstResult.Results)
            {
                result.AddResult(res);
            }

            for (int t = 3; t <= intervals; t++)
            {
                int lastIndex = result.Results.Count - 1;
                Vector u_n_2 = result.Results[lastIndex - 2];
                Vector u_n_1 = result.Results[lastIndex - 1];
                Vector u_n = result.Results[lastIndex];

                Vector u = u_n + (deltaTime / 12) * (23 * f(deltaTime * lastIndex, u_n) - 16 * f(deltaTime * (lastIndex - 1), u_n_1) + 5 * f(deltaTime * (lastIndex - 2), u_n_2));
                Vector prevU = new Vector(u.Length);

                Vector constU = (18 * u_n - 9 * u_n_1 + 2 * u_n_2) / 11;

                while (Vector.Norm(u - prevU) > eps)
                {
                    prevU = u;
                    u = ((6 * deltaTime) / 11) * f(deltaTime * lastIndex, prevU) + constU;
                }

                result.AddResult(u);
            }

            return result;
        }
 private Vector addStaticPoints(Vector resultVector, List<int> indeciesToDelete)
 {
     Vector res = new Vector(resultVector);
     indeciesToDelete.Sort();
     foreach (int index in indeciesToDelete)
     {
         res.Insert(0, index);
     }
     return res;
 }