Ejemplo n.º 1
0
 private double [] PCG()
 {
     double [,] preconditioner = new double[stiffnessMatrix.GetLength(0), stiffnessMatrix.GetLength(1)];
     for (int i = 0; i < preconditioner.GetLength(0); i++)
     {
         preconditioner [i, i] = 1 / stiffnessMatrix [i, i];
     }
     double[] residual = VectorOperations.VectorVectorSubtraction(
         forceVector,
         VectorOperations.MatrixVectorProduct(stiffnessMatrix, solutionVector)
         );
     double[] preconVector = VectorOperations.MatrixVectorProduct(preconditioner, residual);
     for (int iter = 0; iter < maxIterations; iter++)
     {
         double[] u = VectorOperations.MatrixVectorProduct(stiffnessMatrix, preconVector);
         double   residualDotOld = VectorOperations.VectorDotProduct(residual, preconVector);
         double   alpha          = residualDotOld / VectorOperations.VectorDotProduct(preconVector, u);
         solutionVector = VectorOperations.VectorVectorAddition(solutionVector, VectorOperations.VectorScalarProduct(preconVector, alpha));
         residual       = VectorOperations.VectorVectorSubtraction(residual, VectorOperations.VectorScalarProduct(u, alpha));
         if (VectorOperations.VectorDotProduct(residual, residual) < tolerance)
         {
             break;
         }
         double residualDotNew = VectorOperations.VectorDotProduct(residual, VectorOperations.MatrixVectorProduct(preconditioner, residual));
         double beta           = residualDotNew / residualDotOld;
         preconVector = VectorOperations.VectorVectorAddition(
             VectorOperations.MatrixVectorProduct(preconditioner, residual),
             VectorOperations.VectorScalarProduct(preconVector, beta)
             );
     }
     return(solutionVector);
 }
Ejemplo n.º 2
0
        public void NewtonRaphson()
        {
            internalForcesTotalVector = discretization.CreateTotalInternalForcesVector();

            residual = VectorOperations.VectorVectorSubtraction(BoundaryConditionsImposition.ReducedVector(internalForcesTotalVector, boundaryDof), forceVector);

            residualNorm = VectorOperations.VectorNorm2(residual);
            int iteration = 0;

            while (residualNorm > tolerance && iteration < maxIterations)
            {
                Array.Clear(discretization.TotalStiffnessMatrix, 0, discretization.TotalStiffnessMatrix.Length);
                discretization.CreateTotalStiffnessMatrix();
                double[,] reducedStiffnessMatrix = BoundaryConditionsImposition.ReducedTotalStiff(discretization.TotalStiffnessMatrix, boundaryDof);

                DirectSolver linearSolution = new DirectSolver(reducedStiffnessMatrix, residual);
                linearSolution.SolveWithMethod("PCG");
                deltaU = linearSolution.GetSolutionVector;

                double[] reducedSolutionVector = BoundaryConditionsImposition.ReducedVector(solutionVector, boundaryDof);
                reducedSolutionVector = VectorOperations.VectorVectorSubtraction(reducedSolutionVector, deltaU);
                solutionVector        = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(reducedSolutionVector, boundaryDof);

                discretization.UpdateValues(solutionVector);
                Array.Clear(discretization.internalForcesTotalVector, 0, discretization.internalForcesTotalVector.Length);
                internalForcesTotalVector = discretization.CreateTotalInternalForcesVector();

                residual = VectorOperations.VectorVectorSubtraction(BoundaryConditionsImposition.ReducedVector(internalForcesTotalVector, boundaryDof), forceVector);

                residualNorm = VectorOperations.VectorNorm2(residual);

                iteration = iteration + 1;
            }
        }
Ejemplo n.º 3
0
        public override double[,] CreateLocalStiffnessMatrix()
        {
            double length = VectorOperations.CalculateVectorLengthFromEndPoints(nodesX [0], nodesX [1], nodesY [0], nodesY [1]);                   localStiffnessMatrix = new[, ]
            {
                { E *A / length, 0, 0, -E *A / length, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { -E * A / length, 0, 0, E *A / length, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 }
            };

            return(localStiffnessMatrix);
        }
        public override double[,] CreateLocalStiffnessMatrix()
        {
            double[,] transposeBmatrix = MatrixOperations.Transpose(Bmatrix);
            double[] zVector = new[] { sinCurrent, -cosCurrent, 0, -sinCurrent, cosCurrent, 0 };
            double[] vVector = new[] { -cosCurrent, -sinCurrent, 0, cosCurrent, sinCurrent, 0 };
            double[,] zzMatrix             = VectorOperations.VectorVectorTensorProduct(zVector, zVector);
            double[,] vzMatrix             = VectorOperations.VectorVectorTensorProduct(vVector, zVector);
            double[,] zvMatrix             = VectorOperations.VectorVectorTensorProduct(zVector, vVector);
            double[,] vzPluszv             = MatrixOperations.MatrixAddition(vzMatrix, zvMatrix);
            double[,] firstMember          = MatrixOperations.ScalarMatrixProduct(internalLocalForcesVector[0] / lengthCurrent, zzMatrix);
            double[,] secondMember         = MatrixOperations.ScalarMatrixProduct((internalLocalForcesVector[1] + internalLocalForcesVector[2]) / Math.Pow(lengthCurrent, 2), vzPluszv);
            double[,] thirdMember          = MatrixOperations.MatrixProduct(transposeBmatrix, MatrixOperations.MatrixProduct(Dmatrix, Bmatrix));
            double[,] localStiffnessMatrix = MatrixOperations.MatrixAddition(MatrixOperations.MatrixAddition(firstMember, secondMember), thirdMember);

            return(localStiffnessMatrix);
        }
Ejemplo n.º 5
0
        public override double[,] CreateLocalStiffnessMatrix()
        {
            double length = VectorOperations.CalculateVectorLengthFromEndPoints(nodesX [0], nodesX [1], nodesY [0], nodesY [1]);

            localStiffnessMatrix = new[, ]
            {
                { E *A / length, 0, 0, -E *A / length, 0, 0 },
                { 0, 12 * E * I / Math.Pow(length, 3), 6 * E * I / Math.Pow(length, 2), 0, -12 * E * I / Math.Pow(length, 3), 6 * E * I / Math.Pow(length, 2) },
                { 0, 6 * E * I / Math.Pow(length, 2), 4 * E * I / length, 0, -6 * E * I / Math.Pow(length, 2), 2 * E * I / length },
                { -E * A / length, 0, 0, E *A / length, 0, 0 },
                { 0, -12 * E * I / Math.Pow(length, 3), -6 * E * I / Math.Pow(length, 2), 0, 12 * E * I / Math.Pow(length, 3), -6 * E * I / Math.Pow(length, 2) },
                { 0, 6 * E * I / Math.Pow(length, 2), 2 * E * I / length, 0, -6 * E * I / Math.Pow(length, 2), 4 * E * I / length }
            };

            return(localStiffnessMatrix);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            //Declaration of basic frame info
            InputData data = new InputData();

            data.ReadAllData();

            if (data.elementType.Contains("NLBeam") | data.elementType.Contains("NLTruss"))
            {
                //Creation of local, global and total stiffness matrices
                Discretization2DFrame Exercise1Frame = new Discretization2DFrame(data);
                Exercise1Frame.GetStiffnessMatrices();
                //Exercise1Frame.CreateTotalStiffnessMatrix();

                NLSolver solution = new NLSolver(Exercise1Frame, 1000, data);

                solution.SolveWithMethod("Newton-Raphson");
                VectorOperations.PrintVector(solution.solutionVector);
            }
            else
            {
                //Creation of local, global and total stiffness matrices
                Discretization2DFrame Exercise1Frame = new Discretization2DFrame(data);
                Exercise1Frame.GetStiffnessMatrices();
                Exercise1Frame.CreateTotalStiffnessMatrix();

                //Creation reduced matrix depended on boundary conditions
                double[,] reducedTotalStiff = BoundaryConditionsImposition.ReducedTotalStiff(Exercise1Frame.TotalStiffnessMatrix, data.boundaryDof);

                //Solution using Cholesky factorization with forward and backward substitution
                DirectSolver solution = new DirectSolver(reducedTotalStiff, data.externalForcesVector);
                solution.SolveWithMethod("Gauss");

                VectorOperations.PrintVector(solution.GetSolutionVector);

                Console.WriteLine();
                IterativeSolver solution2 = new IterativeSolver(reducedTotalStiff, data.externalForcesVector, 1000);
                solution2.SolveWithMethod("PCG");

                VectorOperations.PrintVector(solution2.GetSolutionVector);
            }
        }
Ejemplo n.º 7
0
 private double[] Jacobi()
 {
     double[] oldSolution = new double[forceVector.Length];
     double[,] Diag = MatrixOperations.PutZerosInDiag(stiffnessMatrix);
     MatrixOperations.InvertDiagMatrix(Diag);
     double[,] zeroDiagStiff = MatrixOperations.GetDiagMatrix(stiffnessMatrix);
     for (int i = 0; i < maxIterations; i++)
     {
         oldSolution    = solutionVector;
         solutionVector = VectorOperations.MatrixVectorProduct(
             Diag,
             VectorOperations.VectorVectorSubtraction(
                 forceVector,
                 VectorOperations.MatrixVectorProduct(zeroDiagStiff, solutionVector)
                 ));
         if (VectorOperations.VectorDotProduct(solutionVector, oldSolution) < tolerance)
         {
             break;
         }
     }
     return(solutionVector);
 }
 private double[] CalculateInternalGlobalForcesVector()
 {
     internalGlobalForcesVector = VectorOperations.MatrixVectorProduct(MatrixOperations.Transpose(Bmatrix), internalLocalForcesVector);
     return(internalGlobalForcesVector);
 }
 private double[] CalculateInternalLocalForcesVector()
 {
     internalLocalForcesVector = VectorOperations.MatrixVectorProduct(Dmatrix, localDisplacementVector);
     return(internalLocalForcesVector);
 }