public double[] CreateInternalGlobalForcesVector() { double[] F = new double[8]; double[,] E = CalculateStressStrainMatrix(Properties.YoungMod, 0.30); //needs fixing in poisson v for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { double[] gP = GaussPoints(i, j).Item1; double[] gW = GaussPoints(i, j).Item2; Dictionary <string, double[]> localdN = CalculateShapeFunctionsLocalDerivatives(gP); double[,] J = CalculateJacobian(localdN); double[,] invJ = CalculateInverseJacobian(J).Item1; double detJ = CalculateInverseJacobian(J).Item2; Dictionary <int, double[]> globaldN = CalculateShapeFunctionsGlobalDerivatives(localdN, invJ); double[,] B = CalculateBMatrix(globaldN); double[] strainVector = CalculateStrainsVector(B); double[] stressVector = CalculateStressVector(E, strainVector); F = VectorOperations.VectorVectorAddition(F, VectorOperations.VectorScalarProductNew( VectorOperations.MatrixVectorProduct(MatrixOperations.Transpose(B), stressVector), detJ * gW[0] * gW[1] * Properties.Thickness)); } } return(F); }
public double[] CreateInternalGlobalForcesVector() { double ksi1 = ClosestPointProjection(); if (Math.Abs(ksi1) <= 1.05) { Tuple <double[, ], double[, ]> positionMatrices = CalculatePositionMatrix(ksi1); double[,] aMatrix = positionMatrices.Item1; double[,] daMatrix = positionMatrices.Item2; Tuple <double[], double, double[]> surfaceCharacteristics = SurfaceGeometry(daMatrix); double m11 = surfaceCharacteristics.Item2; double[] n = surfaceCharacteristics.Item3; double ksi3 = CalculateNormalGap(aMatrix, n); if (ksi3 <= 0) { double[,] AT = MatrixOperations.Transpose(aMatrix); double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n); double[] internalGlobalForcesVector = VectorOperations.VectorScalarProductNew(AT_n, PenaltyFactor * ksi3); return(internalGlobalForcesVector); } else { double[] internalGlobalForcesVector = new double[6]; return(internalGlobalForcesVector); } } else { double[] internalGlobalForcesVector = new double[6]; return(internalGlobalForcesVector); } }
public void SolveNewmark() { List <double> aConstants = CalculateIntegrationConstantsNewmark(); double[,] hatStiffnessMatrixNewmark = CalculateHatKMatrixNewmark(aConstants); explicitSolution.Add(0, InitialValues.InitialDisplacementVector); explicitVelocity.Add(0, InitialValues.InitialVelocityVector); explicitAcceleration.Add(0, CalculateInitialAccelerationsNewmark()); TimeAtEachStep.Add(0, 0.0); double[] nextSolution; for (int i = 1; i < timeStepsNumber; i++) { double time = i * timeStep + InitialValues.InitialTime; if (ActivateNonLinearSolution == false) { double[] hatRVectorNewmark = CalculateHatRVectorNewmark(i, aConstants); nextSolution = LinearSolver.Solve(hatStiffnessMatrixNewmark, hatRVectorNewmark); Console.WriteLine("Solution for Load Step {0} is:", i); VectorOperations.PrintVector(nextSolution); } else { nextSolution = NewtonIterationsNewmark(ExternalForcesVector, i, aConstants); Console.WriteLine("Solution for Load Step {0} is:", i); VectorOperations.PrintVector(nextSolution); } explicitSolution.Add(i, nextSolution); explicitAcceleration.Add(i, CalculateAccelerationNewmark(i, aConstants)); explicitVelocity.Add(i, CalculateVelocityNewmark(i, aConstants)); TimeAtEachStep.Add(i, time); } ExportToFile.ExportExplicitResults(explicitSolution, TimeAtEachStep, 1, 1); //ShowToGUI.ShowResults(explicitSolution, TimeAtEachStep, 1, 1); }
public double[] CreateInternalGlobalForcesVector() { double[] ksiVector = Project(new double[2]); if (Math.Abs(ksiVector[0]) <= 1.05 && ksiVector[1] <= 1.05) { Tuple <double[, ], double[, ], double[, ]> aMatrices = CalculatePositionMatrix(ksiVector[0], ksiVector[1]); List <double[]> dRho = SurfaceVectors(ksiVector[0], ksiVector[1]); double[,] m = MetricTensor(dRho); double[] n = NormalVector(m, dRho); double[] xUpdated = xUpdatedVector(); double ksi3 = CalculatePenetration(n, aMatrices.Item1, xUpdated); if (ksi3 <= 0) { double[,] AT = MatrixOperations.Transpose(aMatrices.Item1); double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n); double[] internalGlobalForcesVector = VectorOperations.VectorScalarProductNew(AT_n, PenaltyFactor * ksi3); return(internalGlobalForcesVector); } else { return(new double[15]); } } else { return(new double[15]); } }
public double[] CreateInternalGlobalForcesVector() { int nodesNumber = Properties.MasterSegmentPolynomialDegree + Properties.SlaveSegmentPolynomialDegree + 2; double[] internalGlobalForcesVector = new double[2 * nodesNumber]; for (int i = 0; i < Properties.IntegrationPoints; i++) { double ksi2 = GaussPoints(i).Item1; double gW = GaussPoints(i).Item2; double ksi1 = Project(0.0, ksi2); if (Math.Abs(ksi1) <= 1.05) { Tuple <double[, ], double[, ], double[, ], double[, ], double[, ]> positionMatrices = CalculatePositionMatrix(ksi1, ksi2); double[,] aMatrix = positionMatrices.Item1; double[,] daMatrix = positionMatrices.Item2; double[,] da2Matrix = positionMatrices.Item3; Tuple <double[], double, double[], double[], double> surfaceCharacteristics = MasterSegmentGeometry(daMatrix, da2Matrix); double[] n = surfaceCharacteristics.Item3; double ksi3 = CalculatePenetration(aMatrix, n); if (ksi3 <= 0) { double slaveMetricTensor = SlaveSegmentGeometry(positionMatrices.Item4, positionMatrices.Item5).Item2; double scalar = Math.Pow(slaveMetricTensor, 0.5) * gW; double[,] AT = MatrixOperations.Transpose(aMatrix); double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n); double[] internalLocalForcesVector = VectorOperations.VectorScalarProductNew(VectorOperations.VectorScalarProductNew(AT_n, PenaltyFactor * ksi3), scalar); internalGlobalForcesVector = VectorOperations.VectorVectorAddition(internalGlobalForcesVector, internalLocalForcesVector); } } } return(internalGlobalForcesVector); }
public static void CreateContourDataForMatlab(double[] x, double[] y, double[] z, int rows, int columns, string path) { double[,] xContour = new double[rows, columns]; double[,] yContour = new double[rows, columns]; double[,] zContour = new double[rows, columns]; //int[] arr = Enumerable.Repeat(42, 10000).ToArray(); //string[] yData = new string[rows]; //string temp; //for (int i = 0; i < rows; i++) //{ // for (int j = 0; j < columns; j++) // { // yContour[i, j] = y[i *columns+ j]; // } //} xContour = VectorOperations.ConvertVectorToMatrix(x, rows, columns); yContour = VectorOperations.ConvertVectorToMatrix(y, rows, columns); zContour = VectorOperations.ConvertVectorToMatrix(z, rows, columns); //for (int i = 0; i < rows; i++) //{ // for (int j = 0; j < columns; j++) // { // yData[i] = yData[i] + "\t" + yContour[i, j]; // } //} //File.WriteAllLines(@"C:\Users\Public\Documents\ContourDataY.dat", yData); MatrixOperations.PrintMatrixToFile(xContour, path + "xData.dat"); MatrixOperations.PrintMatrixToFile(yContour, path + "yData.dat"); MatrixOperations.PrintMatrixToFile(zContour, path + "zData.dat"); }
public double[] CreateInternalGlobalForcesVector() { double[] fInt = new double[24]; double[,] E = CalculateStressStrainMatrix(Properties.YoungMod, Properties.PoissonRatio); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { double[] gP = GaussPoints(i, j, k).Item1; double[] gW = GaussPoints(i, j, k).Item2; Dictionary <string, double[]> localdN = CalculateShapeFunctionsLocalDerivatives(gP); double[,] J = CalculateJacobian(localdN); double[,] invJ = CalculateInverseJacobian(J).Item1; double detJ = CalculateInverseJacobian(J).Item2; Dictionary <int, double[]> globaldN = CalculateShapeFunctionsGlobalDerivatives(localdN, invJ); double[,] B = CalculateBMatrix(globaldN); double[] strainVector = CalculateStrainsVector(B); double[] stressVector = CalculateStressVector(E, strainVector); fInt = VectorOperations.VectorVectorAddition(fInt, VectorOperations.VectorScalarProductNew( VectorOperations.MatrixVectorProduct(MatrixOperations.Transpose(B), stressVector), detJ * gW[0] * gW[1] * gW[2])); } } } //double[,] Kstiff = CreateGlobalStiffnessMatrix(); //double[] uDisp = DisplacementVector; //double[] fInt = VectorOperations.MatrixVectorProduct(Kstiff, uDisp); //fInt = VectorOperations.VectorScalarProductNew(fInt, 1.0); return(fInt); }
private double Project(double ksi1Initial) { int maxIterations = 1000; double tol = Math.Pow(10.0, -6.0); double deltaKsi = 0.0; double ksi = ksi1Initial; double[] xUpdated = NodalXUpdated(); for (int i = 1; i <= maxIterations; i++) { Tuple <double[, ], double[, ], double[, ]> aMatrices = CalculatePositionMatrix(ksi); //double[] slavePositionVector = new double[] { xUpdated[6], xUpdated[7] }; double[] masterSlaveRelativeVector = VectorOperations.MatrixVectorProduct(aMatrices.Item1, xUpdated); double[] surfaceVector = VectorOperations.VectorScalarProduct(VectorOperations.MatrixVectorProduct(aMatrices.Item2, xUpdated), -1); double[] surfaceVectorDerivative = VectorOperations.VectorScalarProduct(VectorOperations.MatrixVectorProduct(aMatrices.Item3, xUpdated), -1); deltaKsi = CalculateDeltaKsi(masterSlaveRelativeVector, surfaceVector, surfaceVectorDerivative); ksi += deltaKsi; if (Math.Abs(deltaKsi) <= tol) { break; } } if (Math.Abs(deltaKsi) > tol) { throw new Exception("CPP not found in current iterations"); } else { return(ksi); } }
public void RunExample() { double[,] matrix1 = MatrixOperations.CreateRandomMatrix(2000, 2000); double[,] matrix2 = MatrixOperations.CreateRandomMatrix(2000, 2000); double[] vector1 = VectorOperations.CreateRandomVector(2000); double[,] result1, result2, result1b, result2b; double[] result1c, result2c; double result1d, result2d; MatrixOperations.ParallelCalculations = false; Stopwatch watch1 = Stopwatch.StartNew(); result1 = MatrixOperations.MatrixAddition(matrix1, matrix2); result1b = MatrixOperations.MatrixProduct(matrix1, matrix2); result1c = VectorOperations.MatrixVectorProduct(result1b, vector1); result1d = VectorOperations.VectorNorm2(result1c); long first = watch1.ElapsedMilliseconds; MatrixOperations.ParallelCalculations = true; Stopwatch watch2 = Stopwatch.StartNew(); result2 = MatrixOperations.MatrixAddition(matrix1, matrix2); result2b = MatrixOperations.MatrixProduct(matrix1, matrix2); //result2 = MatrixOperations.TempVariable; result2c = VectorOperations.MatrixVectorProduct(result2b, vector1); result2d = VectorOperations.VectorNorm2(result2c); long second = watch2.ElapsedMilliseconds; string timeForCalculations = "Elapsed time for single threaded operation: " + first.ToString() + " -Result is:" + result1d + "\n" + "Elapsed time for multithreaded operation: " + second.ToString() + " -Result is:" + result2d; OnTimeElapsed(timeForCalculations); }
public double[] CreateInternalGlobalForcesVector() { double penetration = CalculateNormalGap(); if (penetration <= 0) { double[,] A = CalculatePositionMatrix(); double[,] AT = MatrixOperations.Transpose(A); double[] n = CalculateNormalUnitVector(); double[] t = CalculateTangentUnitVector(); double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n); double[] AT_t = VectorOperations.MatrixVectorProduct(AT, t); double ksi = CalculateNormalGap(); double Tr = CalculateTangentialTraction(); double[] ksi_AT_n = VectorOperations.VectorScalarProductNew(AT_n, ksi); double[] e_ksi_AT_n = VectorOperations.VectorScalarProductNew(ksi_AT_n, PenaltyFactor); double[] Tr_AT_t = VectorOperations.VectorScalarProductNew(AT_t, Tr); double[] internalForcesvector = VectorOperations.VectorVectorAddition(e_ksi_AT_n, Tr_AT_t); return(internalForcesvector); } else { double[] internalGlobalForcesVector = new double[4]; return(internalGlobalForcesVector); } }
private Tuple <double[], double, double[], double[], double> MasterSegmentGeometry(double[,] daMatrix, double[,] da2Matrix) { double Xm1 = Nodes[1].XCoordinate + DisplacementVector[0]; double Ym1 = Nodes[1].YCoordinate + DisplacementVector[1]; double Xm2 = Nodes[2].XCoordinate + DisplacementVector[2]; double Ym2 = Nodes[2].YCoordinate + DisplacementVector[3]; double Xm3 = Nodes[3].XCoordinate + DisplacementVector[4]; double Ym3 = Nodes[3].YCoordinate + DisplacementVector[5]; double Xs = Nodes[4].XCoordinate + DisplacementVector[6]; double Ys = Nodes[4].YCoordinate + DisplacementVector[7]; double[] xupd = new double[] { -Xm1, -Ym1, -Xm2, -Ym2, -Xm3, -Ym3, -Xs, -Ys }; double[] surfaceVector = VectorOperations.MatrixVectorProduct(daMatrix, xupd); double[] surfaceVectorDerivative = VectorOperations.MatrixVectorProduct(da2Matrix, xupd); double detm = VectorOperations.VectorDotProduct(surfaceVector, surfaceVector); double m11 = 1.0 / detm; double[] vector = new double[] { -surfaceVector[1], surfaceVector[0] }; double scalarCoef = 1.0 / (Math.Sqrt(detm)); double[] normalUnitVec = VectorOperations.VectorScalarProductNew(vector, scalarCoef); double[] tangentVector = VectorOperations.VectorScalarProductNew(surfaceVector, scalarCoef); double scalarCoef2 = Math.Pow(m11, 2.0); double curvatureTensor = scalarCoef2 * VectorOperations.VectorDotProduct(surfaceVectorDerivative, normalUnitVec); return(new Tuple <double[], double, double[], double[], double>(surfaceVector, m11, normalUnitVec, tangentVector, curvatureTensor)); }
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); }
public void SolveExplicit() { double[,] hatMassMatrix = CalculateHatMMatrix(); explicitSolution.Add(-1, CalculatePreviousDisplacementVector()); explicitSolution.Add(0, InitialValues.InitialDisplacementVector); explicitAcceleration.Add(0, CalculateInitialAccelerations()); TimeAtEachStep.Add(-1, -1 * timeStep + InitialValues.InitialTime); TimeAtEachStep.Add(0, 0.0); double[] nextSolution; for (int i = 1; i < timeStepsNumber; i++) { double time = i * timeStep + InitialValues.InitialTime; if (ActivateNonLinearSolution == false) { double[] hatRVector = CalculateHatRVector(i); nextSolution = LinearSolver.Solve(hatMassMatrix, hatRVector); Console.WriteLine("Solution for Load Step {0} is:", i); VectorOperations.PrintVector(nextSolution); } else { double[] hatRVector = CalculateHatRVectorNL(i); nextSolution = LinearSolver.Solve(hatMassMatrix, hatRVector); //nextSolution = NewtonIterations(hatRVector); Console.WriteLine("Solution for Load Step {0} is:", i); VectorOperations.PrintVector(nextSolution); } explicitSolution.Add(i, nextSolution); explicitAcceleration.Add(i, CalculateAccelerations()); TimeAtEachStep.Add(i, time); } ExportToFile.ExportExplicitResults(explicitSolution, TimeAtEachStep, 1, 1); }
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); }
public static Results RunStaticExample() { #region Structural IAssembly elementsAssembly = CreateAssembly(); elementsAssembly.CreateElementsAssembly(); elementsAssembly.ActivateBoundaryConditions = true; double[,] globalStiffnessMatrix = elementsAssembly.CreateTotalStiffnessMatrix(); int countContactElements = elementsAssembly.CountElementsOfSameType(typeof(ContactNtN2D)); ShowToGUI.PlotInitialGeometry(elementsAssembly); structuralSolution.LinearScheme = new LUFactorization(); structuralSolution.NonLinearScheme.Tolerance = 1e-5; structuralSolution.ActivateNonLinearSolver = true; structuralSolution.NonLinearScheme.numberOfLoadSteps = 5; double[] externalForces3 = externalForcesStructuralVector; foreach (var dof in loadedStructuralDOFs) { externalForces3[dof - 1] = externalStructuralLoad; } double[] reducedExternalForces3 = BoundaryConditionsImposition.ReducedVector(externalForces3, elementsAssembly.BoundedDOFsVector); structuralSolution.AssemblyData = elementsAssembly; structuralSolution.Solve(reducedExternalForces3); double[] solvector3 = structuralSolution.GetSolution(); elementsAssembly.UpdateDisplacements(solvector3); ShowToGUI.PlotFinalGeometry(elementsAssembly); double[] fullSolVector3 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(solvector3, elementsAssembly.BoundedDOFsVector); Dictionary <int, INode> finalNodes = Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullSolVector3); double[] xFinalNodalCoor = Assembly.NodalCoordinatesToVectors(finalNodes).Item1; double[] yFinalNodalCoor = Assembly.NodalCoordinatesToVectors(finalNodes).Item2; Dictionary <int, double[]> allStepsSolutions = structuralSolution.GetAllStepsSolutions(); Dictionary <int, double[]> allStepsFullSolutions = new Dictionary <int, double[]>(); Dictionary <int, Dictionary <int, double[]> > allStepsContactForces = new Dictionary <int, Dictionary <int, double[]> >(); Dictionary <int, double[]> elementsInternalContactForcesVector; for (int i = 1; i <= allStepsSolutions.Count; i++) { elementsInternalContactForcesVector = new Dictionary <int, double[]>(); elementsAssembly.UpdateDisplacements(allStepsSolutions[i]); elementsInternalContactForcesVector[4] = elementsAssembly.ElementsAssembly[4].CreateInternalGlobalForcesVector(); allStepsContactForces[i] = elementsInternalContactForcesVector; string name = "ContactForce" + i.ToString() + ".dat"; VectorOperations.PrintVectorToFile(allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == 4).Value, @"C:\Users\Public\Documents\" + name); } for (int i = 0; i < allStepsSolutions.Count; i++) { allStepsFullSolutions.Add(i + 1, BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions.Single(m => m.Key == i + 1).Value, elementsAssembly.BoundedDOFsVector)); int j = i + 1; string name = "solution" + j.ToString() + ".dat"; VectorOperations.PrintVectorToFile(allStepsFullSolutions.Single(m => m.Key == i + 1).Value, @"C:\Users\Public\Documents\" + name); } List <double[]> structuralSolutions = new List <double[]>(); #endregion return(new Results() { NonlinearSolution = structuralSolutions, SelectedDOF = 2, SolutionType = "Nonlinear" }); }
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 CalculatePenetration(double[] normalVector, double[,] aMatrix, double[] xUpdated) { double ksi3 = VectorOperations.VectorDotProduct( xUpdated, VectorOperations.MatrixVectorProduct( MatrixOperations.Transpose(aMatrix), normalVector)); return(ksi3); }
private double[] NormalVector(double[,] m, List <double[]> dRho) { double detm = MetricTensorDet(m); double[] drhoBydrho = VectorOperations.VectorCrossProduct(dRho[0], dRho[1]); double[] n = VectorOperations.VectorScalarProductNew(drhoBydrho, 1.0 / (Math.Sqrt(detm))); return(n); }
public double[] CreateInternalGlobalForcesVector() { double[] intForces; double[,] stiff = CreateGlobalStiffnessMatrix(); intForces = VectorOperations.MatrixVectorProduct(stiff, DisplacementVector); intForces = VectorOperations.VectorScalarProductNew(intForces, 1.0); return(intForces); }
private double CalculatePenetration(double[,] aMatrix, double[] n) { double[,] AT = MatrixOperations.Transpose(aMatrix); double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n); double[] xupd = NodalXUpdated(); double normalGap = VectorOperations.VectorDotProduct(xupd, AT_n); return(normalGap); }
private double[,] MainStiffnessPart(double penaltyFactor, double[] normalVector, double[,] aMatrix) { double[,] nxn = VectorOperations.VectorVectorTensorProduct(normalVector, normalVector); double[,] aT = MatrixOperations.Transpose(aMatrix); double[,] nxna = MatrixOperations.MatrixProduct(nxn, aMatrix); double[,] aTnxna = MatrixOperations.MatrixProduct(aT, nxna); double[,] Kmain = MatrixOperations.ScalarMatrixProductNew(penaltyFactor, aTnxna); return(Kmain); }
private double[,] MetricTensor(List <double[]> dRho) { double[,] m = new double[2, 2]; m[0, 0] = VectorOperations.VectorDotProduct(dRho[0], dRho[0]); m[0, 1] = VectorOperations.VectorDotProduct(dRho[0], dRho[1]); m[1, 0] = VectorOperations.VectorDotProduct(dRho[1], dRho[0]); m[1, 1] = VectorOperations.VectorDotProduct(dRho[1], dRho[1]); return(m); }
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 CalculateDeltaKsi(double[] masterSlaveRelativeVector, double[] surfaceVector, double[] surfaceVectorDerivative) { double scalar1 = VectorOperations.VectorDotProduct(surfaceVector, masterSlaveRelativeVector); double scalar2 = VectorOperations.VectorDotProduct(surfaceVectorDerivative, masterSlaveRelativeVector) - VectorOperations.VectorDotProduct(surfaceVector, surfaceVector); double deltaKsi = -scalar1 / scalar2; return(deltaKsi); }
public void PrintExplicitSolution() { foreach (KeyValuePair <int, double[]> element in explicitSolution) { int step = element.Key; double[] solutionInStep = element.Value; Console.WriteLine("Solution for Load Step {0} is:", step); VectorOperations.PrintVector(solutionInStep); } }
private double[,] CalculateMainStiffnessPart(double ksi1, double[] n) { double[,] mainStiffnessMatrix = new double[6, 6]; double N1 = 1.0 / 2.0 * (1.0 - ksi1); double N2 = 1.0 / 2.0 * (1.0 + ksi1); Tuple <double[, ], double[, ]> positionMatrices = CalculatePositionMatrix(ksi1); double[,] A = positionMatrices.Item1; double[,] nxn = VectorOperations.VectorVectorTensorProduct(n, n); double[,] nxn_A = MatrixOperations.MatrixProduct(nxn, A); double[,] AT_nxn_A = MatrixOperations.MatrixProduct(MatrixOperations.Transpose(A), nxn_A); mainStiffnessMatrix = MatrixOperations.ScalarMatrixProductNew(PenaltyFactor, AT_nxn_A); //mainStiffnessMatrix[0, 0] = N1 * N1 * n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[0, 1] = N1 * N1 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[0, 2] = N1 * N2 * n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[0, 3] = N1 * N1 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[0, 4] = -N1 * n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[0, 5] = -N1 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[1, 0] = mainStiffnessMatrix[0, 1]; //mainStiffnessMatrix[1, 1] = N1 * N1 * n[1] * n[1] * PenaltyFactor; //mainStiffnessMatrix[1, 2] = N1 * N2 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[1, 3] = N1 * N2 * n[1] * n[1] * PenaltyFactor; //mainStiffnessMatrix[1, 4] = -N1 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[1, 5] = -N1 * n[1] * n[1] * PenaltyFactor; //mainStiffnessMatrix[2, 0] = mainStiffnessMatrix[0, 2]; //mainStiffnessMatrix[2, 1] = mainStiffnessMatrix[1, 2]; //mainStiffnessMatrix[2, 2] = N2 * N2 * n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[2, 3] = N2 * N2 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[2, 4] = -N2 * n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[2, 5] = -N2 * n[0] *n[1] * PenaltyFactor; //mainStiffnessMatrix[3, 0] = mainStiffnessMatrix[0, 3]; //mainStiffnessMatrix[3, 1] = mainStiffnessMatrix[1, 3]; //mainStiffnessMatrix[3, 2] = mainStiffnessMatrix[2, 3]; //mainStiffnessMatrix[3, 3] = N2 * N2 * n[1] * n[1] * PenaltyFactor; //mainStiffnessMatrix[3, 4] = -N2 * n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[3, 5] = -N2 * n[1] * n[1] * PenaltyFactor; //mainStiffnessMatrix[4, 0] = mainStiffnessMatrix[0, 4]; //mainStiffnessMatrix[4, 1] = mainStiffnessMatrix[1, 4]; //mainStiffnessMatrix[4, 2] = mainStiffnessMatrix[2, 4]; //mainStiffnessMatrix[4, 3] = mainStiffnessMatrix[3, 4]; //mainStiffnessMatrix[4, 4] = n[0] * n[0] * PenaltyFactor; //mainStiffnessMatrix[4, 5] = n[0] * n[1] * PenaltyFactor; //mainStiffnessMatrix[5, 0] = mainStiffnessMatrix[0, 5]; //mainStiffnessMatrix[5, 1] = mainStiffnessMatrix[1, 5]; //mainStiffnessMatrix[5, 2] = mainStiffnessMatrix[2, 5]; //mainStiffnessMatrix[5, 3] = mainStiffnessMatrix[3, 5]; //mainStiffnessMatrix[5, 4] = mainStiffnessMatrix[4, 5]; //mainStiffnessMatrix[5, 5] = n[1] * n[1] * PenaltyFactor; return(mainStiffnessMatrix); }
private double[,] CalculateTangentialStiffnessMatrixForStick() { double[] t = CalculateTangentUnitVector(); double[,] A = CalculatePositionMatrix(); double[,] AT = MatrixOperations.Transpose(A); double[,] txt = VectorOperations.VectorVectorTensorProduct(t, t); double[,] txt_A = MatrixOperations.MatrixProduct(txt, A); double[,] AT_txt_A = MatrixOperations.MatrixProduct(AT, txt_A); double[,] tangentialStiffnessMatrix = MatrixOperations.ScalarMatrixProductNew(-PenaltyFactor, AT_txt_A); return(tangentialStiffnessMatrix); }
private double[] Calculate_f(List <double[]> dRho, double[,] aMatrix, double[] xUpdated) { double[] f = new double[2]; f[0] = VectorOperations.VectorDotProduct( dRho[0], VectorOperations.MatrixVectorProduct( aMatrix, xUpdated)); f[1] = VectorOperations.VectorDotProduct( dRho[1], VectorOperations.MatrixVectorProduct( aMatrix, xUpdated)); return(f); }
private double[,] CalculateNormalStiffnessMatrix() { double[] n = CalculateNormalUnitVector(); double[,] A = CalculatePositionMatrix(); double[,] AT = MatrixOperations.Transpose(A); double[,] nxn = VectorOperations.VectorVectorTensorProduct(n, n); double[,] nxn_A = MatrixOperations.MatrixProduct(nxn, A); double[,] AT_nxn_A = MatrixOperations.MatrixProduct(AT, nxn_A); double[,] globalStiffnessMatrix = MatrixOperations.ScalarMatrixProductNew(PenaltyFactor, AT_nxn_A); return(globalStiffnessMatrix); }