Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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);
            }
        }