private double[] PCG(double[,] stiffnessMatrix, double[] forceVector) { double[] solutionVector = new double[forceVector.Length]; 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.VectorScalarProductNew(preconVector, alpha)); residual = VectorOperations.VectorVectorSubtraction(residual, VectorOperations.VectorScalarProductNew(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.VectorScalarProductNew(preconVector, beta) ); } return(solutionVector); }
private double[] LoadControlledNR(double[] forceVector) { lambda = 1.0 / numberOfLoadSteps; double[] incrementDf = VectorOperations.VectorScalarProductNew(forceVector, lambda); double[] solutionVector = new double[forceVector.Length]; double[] incrementalExternalForcesVector = new double[forceVector.Length]; double[] tempSolutionVector = new double[solutionVector.Length]; double[] deltaU = new double[solutionVector.Length]; double[] internalForcesTotalVector; double[] dU; double[] residual; double residualNorm; //Assembler.UpdateAccelerations(CalculateAccelerations(InitialValues.InitialAccelerationVector)); for (int i = 0; i < numberOfLoadSteps; i++) { incrementalExternalForcesVector = VectorOperations.VectorVectorAddition(incrementalExternalForcesVector, incrementDf); Assembler.UpdateDisplacements(solutionVector); Assembler.UpdateAccelerations(explicitAcceleration.Values.Last()); internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); double[,] tangentMatrix = CalculateHatMMatrix(); dU = LinearSolver.Solve(tangentMatrix, incrementDf); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, dU); Assembler.UpdateDisplacements(solutionVector); tangentMatrix = CalculateHatMMatrix(); internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); while (residualNorm > tolerance && iteration < maxIterations) { tangentMatrix = CalculateHatMMatrix(); deltaU = VectorOperations.VectorVectorSubtraction(deltaU, LinearSolver.Solve(tangentMatrix, residual)); tempSolutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); Assembler.UpdateDisplacements(tempSolutionVector); //Assembler.UpdateAccelerations(CalculateAccelerations(solutionVector)); internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); iteration = iteration + 1; } solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); if (iteration >= maxIterations) { Console.WriteLine("Newton-Raphson: Solution not converged at current iterations"); } } return(solutionVector); }
private double[] LoadControlledNR(double[] forceVector) { double[] incrementDf = VectorOperations.VectorScalarProductNew(forceVector, lambda); double[] solutionVector = localSolutionVector; double[] incrementalExternalForcesVector = new double[forceVector.Length]; double[] tempSolutionVector = new double[solutionVector.Length]; double[] deltaU = new double[solutionVector.Length]; double[] internalForcesTotalVector; double[] dU; double[] residual; double residualNorm; for (int i = 0; i < numberOfLoadSteps; i++) { incrementalExternalForcesVector = VectorOperations.VectorVectorAddition(incrementalExternalForcesVector, incrementDf); discretization.UpdateDisplacements(solutionVector); internalForcesTotalVector = discretization.CreateTotalInternalForcesVector(); double[,] stiffnessMatrix = discretization.CreateTotalStiffnessMatrix(); //OnConvergenceResult("Newton-Raphson: Solution not converged at load step" + i); dU = linearSolver.Solve(stiffnessMatrix, incrementDf); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, dU); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); while (residualNorm > Tolerance && iteration < MaxIterations) { stiffnessMatrix = discretization.CreateTotalStiffnessMatrix(); deltaU = VectorOperations.VectorVectorSubtraction(deltaU, linearSolver.Solve(stiffnessMatrix, residual)); tempSolutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); discretization.UpdateDisplacements(tempSolutionVector); internalForcesTotalVector = discretization.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); if (residualNorm <= Tolerance) { OnConvergenceResult("Newton-Raphson: Load Step " + i + " - Solution converged at iteration " + iteration + " - Residual Norm = " + residualNorm); } else { OnConvergenceResult("Newton-Raphson: Load Step " + i + " - Solution not converged at iteration " + iteration + " - Residual Norm = " + residualNorm); } iteration = iteration + 1; //(Application.Current.Windows[0] as MainWindow).LogTool.Text = "ok"; //OnConvergenceResult("Newton-Raphson: Solution not converged at load step" + iteration); } InternalForces.Add(i + 1, internalForcesTotalVector); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); Solutions.Add(i + 1, solutionVector); if (iteration >= MaxIterations) { OnConvergenceResult("Newton-Raphson did not converge at Load Step " + i + ". Exiting solution."); LoadStepConvergence.Add("Solution not converged."); break; } LoadStepConvergence.Add("Solution converged."); } return(solutionVector); }
private double[] CalculatePreviousDisplacementVector() { double[] previousDisp = VectorOperations.VectorVectorAddition( VectorOperations.VectorVectorSubtraction(InitialValues.InitialDisplacementVector, VectorOperations.VectorScalarProductNew(InitialValues.InitialVelocityVector, timeStep)), VectorOperations.VectorScalarProductNew(InitialValues.InitialAccelerationVector, a3)); return(previousDisp); }
private double[] BiCGSTAB(double[,] stiffnessMatrix, double[] forceVector) { double[] solutionVector = new double[forceVector.Length]; double[] xVector = new double[forceVector.Length]; double[] pVector = new double[forceVector.Length]; double[] vVector = new double[forceVector.Length]; double[,] K = stiffnessMatrix; double[] bVector = forceVector; double[] rVector = VectorOperations.VectorVectorSubtraction(bVector, VectorOperations.MatrixVectorProduct(K, xVector)); double[] r0hatVector = rVector; double rho0 = 1.0; double w = 1.0; double a = 1.0; double rho1 = VectorOperations.VectorDotProduct(r0hatVector, rVector); double b; double[] sVector; double[] tVector; int iters = 100; double converged; for (int i = 0; i < iters; i++) { b = (rho1 / rho0) * (a / w); pVector = VectorOperations.VectorVectorAddition(rVector, VectorOperations.VectorScalarProductNew( VectorOperations.VectorVectorSubtraction(pVector, VectorOperations.VectorScalarProductNew(vVector, w)), b)); vVector = VectorOperations.MatrixVectorProduct(K, pVector); a = rho1 / VectorOperations.VectorDotProduct(r0hatVector, vVector); sVector = VectorOperations.VectorVectorSubtraction(rVector, VectorOperations.VectorScalarProductNew(vVector, a)); tVector = VectorOperations.MatrixVectorProduct(K, sVector); w = VectorOperations.VectorDotProduct(tVector, sVector) / VectorOperations.VectorDotProduct(tVector, tVector); rho0 = rho1; rho1 = -w *VectorOperations.VectorDotProduct(r0hatVector, tVector); xVector = VectorOperations.VectorVectorAddition(xVector, VectorOperations.VectorScalarProductNew(pVector, a)); xVector = VectorOperations.VectorVectorAddition(xVector, VectorOperations.VectorScalarProductNew(sVector, w)); rVector = VectorOperations.VectorVectorSubtraction(sVector, VectorOperations.VectorScalarProductNew(tVector, w)); converged = VectorOperations.VectorNorm2(rVector); if (i == iters | converged < 0.00000001) { break; } } solutionVector = xVector; return(solutionVector); }
private double[] CalculateHatRVector(int i) { double[,] hatKMatrix = CalculateHatKMatrix(); double[,] hatMMatrix = CalculateHatMMatrix(); double[] hatCurrentU = VectorOperations.MatrixVectorProduct(hatKMatrix, explicitSolution[i - 1]); double[] hatPreviousU = VectorOperations.MatrixVectorProduct(hatMMatrix, explicitSolution[i - 2]); double[] hatR = VectorOperations.VectorVectorSubtraction(ExternalForcesVector, VectorOperations.VectorVectorAddition(hatCurrentU, hatPreviousU)); return(hatR); }
private double[] NewtonIterationsNewmark(double[] forceVector, int stepNumber, List <double> aConstants) { lambda = 1.0 / numberOfLoadSteps; //double[] incrementDf = VectorOperations.VectorScalarProductNew(forceVector, lambda); double[] solutionVector = new double[forceVector.Length]; double[] deltaU = new double[solutionVector.Length]; double[] internalForcesTotalVector; double[] residual; double residualNorm; double[] hatR; solutionVector = explicitSolution.Values.Last(); Assembler.UpdateDisplacements(solutionVector); //Assembler.UpdateAccelerations(explicitAcceleration.Values.Last()); hatR = CalculateHatRVectorNewmarkNL(stepNumber, aConstants, solutionVector); internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(hatR, internalForcesTotalVector); residual = VectorOperations.VectorVectorSubtraction(forceVector, Assembler.CreateTotalInternalForcesVector()); int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); for (int i = 0; i < maxIterations; i++) { double[,] tangentMatrix = CalculateHatKMatrixNewmark(aConstants); deltaU = LinearSolver.Solve(tangentMatrix, residual); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); Assembler.UpdateDisplacements(solutionVector); //Assembler.UpdateAccelerations(CalculateAccelerations()); hatR = CalculateHatRVectorNewmarkNL(stepNumber, aConstants, solutionVector); internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(hatR, internalForcesTotalVector); residualNorm = VectorOperations.VectorNorm2(residual); if (residualNorm < tolerance) { break; } iteration = iteration + 1; } //Console.WriteLine(iteration); if (iteration >= maxIterations) { Console.WriteLine("Newton-Raphson: Solution not converged at current iterations"); } return(solutionVector); }
private double[] CalculateAccelerationNewmark(int step, List <double> aConstants) { double[] dUt = explicitVelocity[step - 1]; double[] ut = explicitSolution[step - 1]; double[] utplusDt = explicitSolution[step]; double[] ddUt = explicitAcceleration[step - 1]; double[] part1 = VectorOperations.VectorScalarProductNew( VectorOperations.VectorVectorSubtraction(utplusDt, ut), aConstants[0]); double[] part2 = VectorOperations.VectorScalarProductNew(dUt, aConstants[2]); double[] part3 = VectorOperations.VectorScalarProductNew(ddUt, aConstants[3]); double[] ddUtplusDt = VectorOperations.VectorVectorSubtraction(part1, VectorOperations.VectorVectorAddition(part2, part3)); return(ddUtplusDt); }
private double[] LoadControlledNR(double[] forceVector) { double[] incrementDf = VectorOperations.VectorScalarProductNew(forceVector, lambda); double[] solutionVector = new double[forceVector.Length]; double[] incrementalExternalForcesVector = new double[forceVector.Length]; double[] tempSolutionVector = new double[solutionVector.Length]; double[] deltaU = new double[solutionVector.Length]; double[] internalForcesTotalVector; double[] dU; double[] residual; double residualNorm; for (int i = 0; i < numberOfLoadSteps; i++) { incrementalExternalForcesVector = VectorOperations.VectorVectorAddition(incrementalExternalForcesVector, incrementDf); base.UpdateDisplacements(solutionVector); internalForcesTotalVector = base.CreateTotalInternalForcesVector(); double[,] stiffnessMatrix = base.CreateTotalStiffnessMatrix(); dU = linearSolver.Solve(stiffnessMatrix, incrementDf); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, dU); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); while (residualNorm > tolerance && iteration < maxIterations) { stiffnessMatrix = base.CreateTotalStiffnessMatrix(); deltaU = VectorOperations.VectorVectorSubtraction(deltaU, linearSolver.Solve(stiffnessMatrix, residual)); tempSolutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); base.UpdateDisplacements(tempSolutionVector); internalForcesTotalVector = base.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector); residualNorm = VectorOperations.VectorNorm2(residual); iteration = iteration + 1; } solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); if (iteration >= maxIterations) { Console.WriteLine("Newton-Raphson: Solution not converged at current iterations"); } } return(solutionVector); }
private double[] CalculateInitialAccelerationsNewmark() //Bathe page 771 { if (CustomStiffnessMatrix != null) { return(InitialValues.InitialAccelerationVector); } int step = explicitSolution.Count - 1; Assembler.UpdateDisplacements(explicitSolution[step]); double[,] stiffness = Assembler.CreateTotalStiffnessMatrix(); double[,] mass = Assembler.CreateTotalMassMatrix(); double[] Ku = VectorOperations.MatrixVectorProduct(stiffness, explicitSolution[step]); double[] RHS = VectorOperations.VectorVectorSubtraction(ExternalForcesVector, Ku); double[] acceleration = LinearSolver.Solve(mass, RHS); return(acceleration); }
private double[] CalculateHatRVectorNewmarkNL(int i, List <double> aConstants, double[] previousIterationSolution) { double[,] TotalMassMatrix; double[,] TotalDampingMatrix; double[,] TotalStiffnessMatrix; if (CustomMassMatrix != null) { TotalMassMatrix = CustomMassMatrix; TotalDampingMatrix = CustomDampingMatrix; TotalStiffnessMatrix = CustomStiffnessMatrix; } else { TotalMassMatrix = Assembler.CreateTotalMassMatrix(); TotalDampingMatrix = Assembler.CreateTotalDampingMatrix(); TotalStiffnessMatrix = Assembler.CreateTotalStiffnessMatrix(); } double[] currentU = explicitSolution[i - 1]; double[] currentdU = explicitVelocity[i - 1]; double[] currentddU = explicitAcceleration[i - 1]; double[] a0U = VectorOperations.VectorScalarProductNew( VectorOperations.VectorVectorSubtraction(currentU, previousIterationSolution), aConstants[0]); double[] a2dU = VectorOperations.VectorScalarProductNew(currentdU, aConstants[2]); double[] a3ddU = VectorOperations.VectorScalarProductNew(currentddU, aConstants[3]); double[] a1U = VectorOperations.VectorScalarProductNew(currentU, aConstants[1]); double[] a4dU = VectorOperations.VectorScalarProductNew(currentdU, aConstants[4]); double[] a5ddU = VectorOperations.VectorScalarProductNew(currentddU, aConstants[5]); double[] vectorSum1 = VectorOperations.VectorVectorAddition(a0U, VectorOperations.VectorVectorAddition(a2dU, a3ddU)); double[] vectorSum2 = VectorOperations.VectorVectorAddition(a1U, VectorOperations.VectorVectorAddition(a4dU, a5ddU)); double[] part1 = VectorOperations.MatrixVectorProduct(TotalMassMatrix, vectorSum1); double[] part2 = VectorOperations.MatrixVectorProduct(TotalDampingMatrix, vectorSum2); double[] hatR = VectorOperations.VectorVectorAddition(ExternalForcesVector, VectorOperations.VectorVectorAddition(part1, part2)); return(hatR); }
private double[] CalculateHatRVectorNL(int i) { Assembler.UpdateDisplacements(explicitSolution[i - 1]); double[,] totalMassMatrix = Assembler.CreateTotalMassMatrix(); double[,] totalDampingMatrix = Assembler.CreateTotalDampingMatrix(); double[,] a2M = MatrixOperations.ScalarMatrixProductNew(a2, totalMassMatrix); double[,] a0M = MatrixOperations.ScalarMatrixProductNew(a0, totalMassMatrix); double[,] a1C = MatrixOperations.ScalarMatrixProductNew(-a1, totalDampingMatrix); double[,] hutM = MatrixOperations.MatrixAddition(a0M, a1C); double[] F = Assembler.CreateTotalInternalForcesVector(); double[] hatPreviousU = VectorOperations.MatrixVectorProduct(hutM, explicitSolution[i - 2]); double[] a2Mut = VectorOperations.MatrixVectorProduct(a2M, explicitSolution[i - 1]); double[] hatR1 = VectorOperations.VectorVectorSubtraction(ExternalForcesVector, F); double[] hatR2 = VectorOperations.VectorVectorSubtraction(a2Mut, hatPreviousU); double[] hatRtotal = VectorOperations.VectorVectorAddition(hatR1, hatR2); return(hatRtotal); }
private double[] StartNewtonIterations(double[] forceVector) { lambda = 1.0 / numberOfLoadSteps; double[] solutionVector = new double[forceVector.Length]; double[] tempSolutionVector = new double[solutionVector.Length]; double[] deltaU = new double[solutionVector.Length]; double[] internalForcesTotalVector; double[] dU; double[] residual; double residualNorm; discretization.UpdateDisplacements(solutionVector); residual = VectorOperations.VectorVectorSubtraction(forceVector, discretization.CreateTotalInternalForcesVector()); int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); for (int i = 0; i < MaxIterations; i++) { double[,] tangentMatrix = discretization.CreateTotalStiffnessMatrix(); deltaU = linearSolver.Solve(tangentMatrix, residual); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); discretization.UpdateDisplacements(solutionVector); internalForcesTotalVector = discretization.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(forceVector, internalForcesTotalVector); residualNorm = VectorOperations.VectorNorm2(residual); if (residualNorm < Tolerance) { continue; } iteration = iteration + 1; } if (iteration >= MaxIterations) { Console.WriteLine("Newton-Raphson: Solution not converged at current iterations"); } return(solutionVector); }
private double[] Project(double[] ksiVectorInitial) { int maxIterations = 1000; double tol = Math.Pow(10.0, -4.0); double[] deltaKsi = new double[2]; double norm = new double(); double[] ksiVector = ksiVectorInitial; double[] xUpdated = xUpdatedVector(); for (int i = 1; i <= maxIterations; i++) { double[] oldksiVector = ksiVector; Tuple <double[, ], double[, ], double[, ]> aMatrices = CalculatePositionMatrix(ksiVector[0], ksiVector[1]); List <double[]> dRho = SurfaceVectors(ksiVector[0], ksiVector[1]); double[] f = Calculate_f(dRho, aMatrices.Item1, xUpdated); double e = Calculate_e(aMatrices.Item1, xUpdated);//double e = Calculate_e(aMatrices.Item2, xUpdated); double[,] m = MetricTensor(dRho); double detm = MetricTensorDet(m); deltaKsi = CalculateDeltaKsi(detm, m, f, e); ksiVector = VectorOperations.VectorVectorAddition(ksiVector, deltaKsi);//Iterations for the CPP? norm = VectorOperations.VectorNorm2(VectorOperations.VectorVectorSubtraction(ksiVector, oldksiVector)); if (norm <= tol) { break; } } if (norm > tol) { throw new Exception("CPP not found in current iterations"); } else { return(ksiVector); } }
private double[] NewtonIterationsExplicit(int timeStep, double[] forceVector, double[,] tangentMatrix) { //lambda = 1.0 / numberOfLoadSteps; //double[] incrementDf = VectorOperations.VectorScalarProductNew(forceVector, lambda); double[] solutionVector = new double[forceVector.Length]; double[] deltaU = new double[solutionVector.Length]; //double[] internalForcesTotalVector; double[] residual; double residualNorm; double[] hatRPrevious; double[] hatRNext; solutionVector = explicitSolution.Values.Last(); Assembler.UpdateDisplacements(solutionVector); Assembler.UpdateAccelerations(explicitAcceleration.Values.Last()); hatRPrevious = CalculateHatRVectorNL(timeStep); hatRNext = hatRPrevious; //internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); //residual = VectorOperations.VectorVectorSubtraction(hatR, internalForcesTotalVector); residual = hatRPrevious; int iteration = 0; Array.Clear(deltaU, 0, deltaU.Length); for (int i = 0; i < maxIterations; i++) { if (i == 0) { //deltaU = LinearSolver.Solve(tangentMatrix, residual); //solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); solutionVector = LinearSolver.Solve(tangentMatrix, residual); Assembler.UpdateDisplacements(solutionVector); //Assembler.UpdateAccelerations(CalculateAccelerations()); hatRNext = CalculateHatRVectorNL(timeStep); //internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(hatRNext, hatRPrevious); residualNorm = VectorOperations.VectorNorm2(residual); if (residualNorm < tolerance) { break; } iteration = iteration + 1; hatRPrevious = hatRNext; } else { deltaU = LinearSolver.Solve(tangentMatrix, residual); solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU); //solutionVector = LinearSolver.Solve(tangentMatrix, residual); Assembler.UpdateDisplacements(solutionVector); //Assembler.UpdateAccelerations(CalculateAccelerations()); hatRNext = CalculateHatRVectorNL(timeStep); //internalForcesTotalVector = Assembler.CreateTotalInternalForcesVector(); residual = VectorOperations.VectorVectorSubtraction(hatRNext, hatRPrevious); residualNorm = VectorOperations.VectorNorm2(residual); if (residualNorm < tolerance) { break; } iteration = iteration + 1; hatRPrevious = hatRNext; } } //Console.WriteLine(iteration); if (iteration >= maxIterations) { Console.WriteLine("Newton-Raphson: Solution not converged at current iterations"); } return(solutionVector); }