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" }); }
public static void ExportCondactivityForAllLoadSteps(List <Dictionary <int, double> > contactContactivityForEachStep) { int k = 0; foreach (var loadStep in contactContactivityForEachStep) { k = k + 1; double[] contactContactivity = loadStep.Values.ToArray(); VectorOperations.PrintVectorToFile(contactContactivity, "Results/contactivity" + k.ToString() + ".dat"); } }
public static Results RunStaticExample() { #region Structural IAssembly elementsAssembly = CreateAssembly(); elementsAssembly.CreateElementsAssembly(); elementsAssembly.ActivateBoundaryConditions = true; double[,] globalStiffnessMatrix = elementsAssembly.CreateTotalStiffnessMatrix(); //Gnuplot graphs ShowToGUI.PlotInitialGeometry(elementsAssembly); Dictionary <int, INode> initialNodes = elementsAssembly.Nodes; double[] initialXCoord = Assembly.NodalCoordinatesToVectors(initialNodes).Item1; double[] initialYCoord = Assembly.NodalCoordinatesToVectors(initialNodes).Item2; double[] Xvec1Initial = new double[totalNodes / 2]; double[] Yvec1Initial = new double[totalNodes / 2]; double[] Xvec2Initial = new double[totalNodes / 2]; double[] Yvec2Initial = new double[totalNodes / 2]; double[] Ζvec1Initial = Enumerable.Repeat(1.0, totalNodes / 2).ToArray(); double[] Ζvec2Initial = Enumerable.Repeat(1.0, totalNodes / 2).ToArray(); Array.Copy(initialXCoord, 0, Xvec1Initial, 0, totalNodes / 2); Array.Copy(initialYCoord, 0, Yvec1Initial, 0, totalNodes / 2); Array.Copy(initialXCoord, totalNodes / 2, Xvec2Initial, 0, totalNodes / 2); Array.Copy(initialYCoord, totalNodes / 2, Yvec2Initial, 0, totalNodes / 2); string pathForContour1 = @"C:\Users\Public\Documents\Total\1"; string pathForContour2 = @"C:\Users\Public\Documents\Total\2"; ExportToFile.CreateContourDataForMatlab(Xvec1Initial, Yvec1Initial, Ζvec1Initial, nodesInYCoor, nodesInXCoor, pathForContour1); ExportToFile.CreateContourDataForMatlab(Xvec2Initial, Yvec2Initial, Ζvec2Initial, nodesInYCoor, nodesInXCoor, pathForContour2); ///structuralSolution = new StaticSolver(); structuralSolution.LinearScheme = new PCGSolver(); //structuralSolution.NonLinearScheme = new LoadControlledNewtonRaphson(); structuralSolution.NonLinearScheme.Tolerance = 1e-6; structuralSolution.ActivateNonLinearSolver = true; structuralSolution.NonLinearScheme.numberOfLoadSteps = 40; 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, Dictionary <int, double[]> > allStepsContactForces = new Dictionary <int, Dictionary <int, double[]> >(); Dictionary <int, Dictionary <int, double> > allStepsProjectionPoints = new Dictionary <int, Dictionary <int, double> >(); Dictionary <int, double[]> elementsInternalContactForcesVector; Dictionary <int, double> projectionPointForEachElement; for (int i = 1; i <= allStepsSolutions.Count; i++) { elementsInternalContactForcesVector = new Dictionary <int, double[]>(); projectionPointForEachElement = new Dictionary <int, double>(); elementsAssembly.UpdateDisplacements(allStepsSolutions[i]); for (int j = totalElements + 1; j <= totalElements + totalContactElements - 1; j++) { elementsInternalContactForcesVector[j] = elementsAssembly.ElementsAssembly[j].CreateInternalGlobalForcesVector(); projectionPointForEachElement[j] = elementsAssembly.ElementsAssembly[j].ClosestPointProjection(); } allStepsContactForces[i] = elementsInternalContactForcesVector; allStepsProjectionPoints[i] = projectionPointForEachElement; } List <double[]> structuralSolutions = new List <double[]>(); ExportToFile.ExportMatlabInitialGeometry(elementsAssembly); #endregion #region Thermal List <double[]> thermalSolutions = new List <double[]>(); List <Dictionary <int, double> > contactContactivityForEachStep = new List <Dictionary <int, double> >(); for (int k = 1; k <= allStepsSolutions.Count; k++) { IAssembly elementsAssembly2 = CreateThermalAssembly(); for (int j = totalElements + 1; j <= totalElements + totalContactElements - 1; j++) { double[] contactForce = allStepsContactForces[k][j]; elementsAssembly2.ElementsProperties[j].ContactForceValue = -contactForce[5]; double projectionPoint = allStepsProjectionPoints[k][j]; elementsAssembly2.ElementsProperties[j].Dx1 = projectionPoint; } elementsAssembly2.CreateElementsAssembly(); elementsAssembly2.ActivateBoundaryConditions = true; double[,] globalStiffnessMatrix2 = elementsAssembly2.CreateTotalStiffnessMatrix(); ISolver thermalSolution = new StaticSolver(); thermalSolution.LinearScheme = new LUFactorization(); thermalSolution.NonLinearScheme = new LoadControlledNewtonRaphson(); thermalSolution.NonLinearScheme.Tolerance = 1e-9; thermalSolution.ActivateNonLinearSolver = true; thermalSolution.NonLinearScheme.numberOfLoadSteps = 40; thermalSolution.AssemblyData = elementsAssembly2; double[] externalHeatFlux = externalHeatLoafVector; //externalHeatFlux[0] = externalHeatLoad; //externalHeatFlux[15] = externalHeatLoad; //externalHeatFlux[30] = externalHeatLoad; //externalHeatFlux[45] = externalHeatLoad; //externalHeatFlux[60] = externalHeatLoad; foreach (var dof in loadedThermalDOFs) { if ((dof == ThermalDof1 | dof == ThermalDof2)) { externalHeatFlux[dof - 1] = externalHeatLoad / 2; } else { externalHeatFlux[dof - 1] = externalHeatLoad; } } //foreach (var dof in loadedThermalDOFs) //{ // externalHeatFlux[dof - 1] = externalHeatLoad; //} //for (int i = 61; i <= 75; i++) //{ // externalHeatFlux[61] = externalHeatLoad; //} double[] reducedExternalHeatFlux = BoundaryConditionsImposition.ReducedVector(externalHeatFlux, thermalSolution.AssemblyData.BoundedDOFsVector); thermalSolution.Solve(reducedExternalHeatFlux); double[] tempSol = thermalSolution.GetSolution(); thermalSolutions.Add(tempSol); Dictionary <int, double> contactContactivity = AssemblyHelpMethods.RetrieveContactContactivity(thermalSolution.AssemblyData); contactContactivityForEachStep.Add(contactContactivity); } int[] thermalBoundCond = thermalBoundaryConditions; double[] fullStructuralSol1 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[8], elementsAssembly.BoundedDOFsVector); double[] fullStructuralSol2 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[16], elementsAssembly.BoundedDOFsVector); double[] fullStructuralSol3 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[24], elementsAssembly.BoundedDOFsVector); double[] fullStructuralSol4 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[32], elementsAssembly.BoundedDOFsVector); double[] fullStructuralSol5 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[40], elementsAssembly.BoundedDOFsVector); double[] fullThermalSol1 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(thermalSolutions[7], thermalBoundCond); double[] fullThermalSol2 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(thermalSolutions[15], thermalBoundCond); double[] fullThermalSol3 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(thermalSolutions[23], thermalBoundCond); double[] fullThermalSol4 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(thermalSolutions[31], thermalBoundCond); double[] fullThermalSol5 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(thermalSolutions[39], thermalBoundCond); double[] fullThermalSolfinal1 = new double[fullThermalSol1.Length + 1]; double[] fullThermalSolfinal2 = new double[fullThermalSol1.Length + 1]; double[] fullThermalSolfinal3 = new double[fullThermalSol1.Length + 1]; double[] fullThermalSolfinal4 = new double[fullThermalSol1.Length + 1]; double[] fullThermalSolfinal5 = new double[fullThermalSol1.Length + 1]; for (int runs = 0; runs < fullThermalSol1.Length; runs++) { fullThermalSolfinal1[runs] = fullThermalSol1[runs]; fullThermalSolfinal2[runs] = fullThermalSol2[runs]; fullThermalSolfinal3[runs] = fullThermalSol3[runs]; fullThermalSolfinal4[runs] = fullThermalSol4[runs]; fullThermalSolfinal5[runs] = fullThermalSol5[runs]; } double[] contactContactivityForLoadStep1 = contactContactivityForEachStep[3].Values.ToArray(); double[] contactContactivityForLoadStep2 = contactContactivityForEachStep[7].Values.ToArray(); double[] contactContactivityForLoadStep3 = contactContactivityForEachStep[11].Values.ToArray(); double[] contactContactivityForLoadStep4 = contactContactivityForEachStep[15].Values.ToArray(); double[] contactContactivityForLoadStep5 = contactContactivityForEachStep[19].Values.ToArray(); ExportToFile.ExportGeometryDataWithTemperatures(Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullStructuralSol1), fullThermalSolfinal1, @"C:\Users\Public\Documents\Results1.dat"); ExportToFile.ExportGeometryDataWithTemperatures(Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullStructuralSol2), fullThermalSolfinal2, @"C:\Users\Public\Documents\Results2.dat"); ExportToFile.ExportGeometryDataWithTemperatures(Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullStructuralSol3), fullThermalSolfinal3, @"C:\Users\Public\Documents\Results3.dat"); ExportToFile.ExportGeometryDataWithTemperatures(Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullStructuralSol4), fullThermalSolfinal4, @"C:\Users\Public\Documents\Results4.dat"); ExportToFile.ExportGeometryDataWithTemperatures(Assembly.CalculateFinalNodalCoordinates(elementsAssembly.Nodes, fullStructuralSol5), fullThermalSolfinal5, @"C:\Users\Public\Documents\Results5.dat"); VectorOperations.PrintVectorToFile(contactContactivityForLoadStep1, @"C:\Users\Public\Documents\contactivity1.dat"); VectorOperations.PrintVectorToFile(contactContactivityForLoadStep2, @"C:\Users\Public\Documents\contactivity2.dat"); VectorOperations.PrintVectorToFile(contactContactivityForLoadStep3, @"C:\Users\Public\Documents\contactivity3.dat"); VectorOperations.PrintVectorToFile(contactContactivityForLoadStep4, @"C:\Users\Public\Documents\contactivity4.dat"); VectorOperations.PrintVectorToFile(contactContactivityForLoadStep5, @"C:\Users\Public\Documents\contactivity5.dat"); structuralSolutions.Add(fullStructuralSol1); structuralSolutions.Add(fullStructuralSol2); structuralSolutions.Add(fullStructuralSol3); structuralSolutions.Add(fullStructuralSol4); structuralSolutions.Add(fullStructuralSol5); double[] Xvec1Final = new double[totalNodes / 2]; double[] Yvec1Final = new double[totalNodes / 2]; double[] Xvec2Final = new double[totalNodes / 2]; double[] Yvec2Final = new double[totalNodes / 2]; double[] Ζvec1Final = new double[totalNodes / 2]; double[] Ζvec2Final = new double[totalNodes / 2]; Array.Copy(xFinalNodalCoor, 0, Xvec1Final, 0, totalNodes / 2); Array.Copy(yFinalNodalCoor, 0, Yvec1Final, 0, totalNodes / 2); Array.Copy(fullThermalSol4, 0, Ζvec1Final, 0, totalNodes / 2); Array.Copy(xFinalNodalCoor, totalNodes / 2, Xvec2Final, 0, totalNodes / 2); Array.Copy(yFinalNodalCoor, totalNodes / 2, Yvec2Final, 0, totalNodes / 2); Array.Copy(fullThermalSol4, totalNodes / 2, Ζvec2Final, 0, totalNodes / 2); List <HeatMapData> plots2 = new List <HeatMapData>(); plots2.Add(new HeatMapData() { Xcoordinates = Xvec1Final, Ycoordinates = Yvec1Final, Temperatures = Ζvec1Final }); plots2.Add(new HeatMapData() { Xcoordinates = Xvec2Final, Ycoordinates = Yvec2Final, Temperatures = Ζvec2Final }); ShowToGUI.PlotHeatMap(plots2); string path = @"C:\Users\Public\Documents\Total\1final"; string path2 = @"C:\Users\Public\Documents\Total\2final"; ExportToFile.CreateContourDataForMatlab(Xvec1Final, Yvec1Final, Ζvec1Final, nodesInYCoor, nodesInXCoor, path); ExportToFile.CreateContourDataForMatlab(Xvec2Final, Yvec2Final, Ζvec2Final, nodesInYCoor, nodesInXCoor, path2); //ExportToFile.ExportGeometryDataWithTemperatures(finalNodes, fullTempSol); GnuPlot.Close(); while (true) { if (File.Exists(AppContext.BaseDirectory + "gnuplot.png") && new FileInfo(AppContext.BaseDirectory + "gnuplot.png").Length > 0) { break; } Thread.Sleep(100); } GnuPlot.KillProcess(); #endregion return(new Results() { NonlinearSolution = structuralSolutions, SelectedDOF = 2, SolutionType = "Nonlinear" }); }
public static Results RunStaticExample() { #region Structural IAssembly elementsAssembly = CreateAssembly(); elementsAssembly.CreateElementsAssembly(); elementsAssembly.ActivateBoundaryConditions = true; double[,] globalStiffnessMatrix = elementsAssembly.CreateTotalStiffnessMatrix(); int countContactElements = elementsAssembly.CountElementsOfSameType(typeof(ContactStS2D)); ShowToGUI.PlotInitialGeometry(elementsAssembly); structuralSolution.LinearScheme = new LUFactorization(); structuralSolution.NonLinearScheme.Tolerance = 1e-5; structuralSolution.ActivateNonLinearSolver = true; structuralSolution.NonLinearScheme.numberOfLoadSteps = 30; 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(); Dictionary <int, double[]> allStepsSolutions = structuralSolution.GetAllStepsSolutions(); Dictionary <int, List <double[]> > gPointsStress = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > gPointsStrain = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > gPoints = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > nodalStress = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > nodalStrain = new Dictionary <int, List <double[]> >(); for (int i = 1; i <= allStepsSolutions.Count; i++) { string name = "NodalCoordinates" + i.ToString() + ".dat"; ExportToFile.ExportUpdatedNodalCoordinates(elementsAssembly, BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions.Single(m => m.Key == i).Value, elementsAssembly.BoundedDOFsVector), name); gPointsStress = elementsAssembly.GetElementsStresses(allStepsSolutions[i]); gPointsStrain = elementsAssembly.GetElementsStains(allStepsSolutions[i]); gPoints = elementsAssembly.GetElementsGaussPoints(allStepsSolutions[i]); nodalStress = elementsAssembly.GetElementsNodesStresses(allStepsSolutions[i]); nodalStrain = elementsAssembly.GetElementsNodesStains(allStepsSolutions[i]); string name1 = "GPointsStress" + i.ToString() + ".dat"; string name2 = "GPointsStrain" + i.ToString() + ".dat"; string name3 = "GPointsCoordinates" + i.ToString() + ".dat"; string name4 = "NodalStress" + i.ToString() + ".dat"; string name5 = "NodalStrain" + i.ToString() + ".dat"; VectorOperations.PrintDictionaryofListsofVectorsToFile(gPointsStress, @"C:\Users\Public\Documents\" + name1); VectorOperations.PrintDictionaryofListsofVectorsToFile(gPointsStrain, @"C:\Users\Public\Documents\" + name2); VectorOperations.PrintDictionaryofListsofVectorsToFile(gPoints, @"C:\Users\Public\Documents\" + name3); VectorOperations.PrintDictionaryofListsofVectorsToFile(nodalStress, @"C:\Users\Public\Documents\" + name4); VectorOperations.PrintDictionaryofListsofVectorsToFile(nodalStrain, @"C:\Users\Public\Documents\" + name5); } 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[]> 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]); for (int j = 1; j <= contactElements; j++) { elementsInternalContactForcesVector[elementsNumber + j] = elementsAssembly.ElementsAssembly[elementsNumber + j].CreateInternalGlobalForcesVector(); } allStepsContactForces[i] = elementsInternalContactForcesVector; string name = "ContactForces" + i.ToString() + ".dat"; double[] Vector = new double[contactElements * 12]; int count = 0; for (int j = 1; j <= contactElements; j++) { Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[0]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[1]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[2]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[3]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[4]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[5]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[6]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[7]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[8]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[9]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[10]; count += 1; Vector[count] = allStepsContactForces.Single(m => m.Key == i).Value.Single(n => n.Key == elementsNumber + j).Value[11]; count += 1; } VectorOperations.PrintVectorToFile(Vector, @"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" }); }
public static Results RunExample() { IAssembly elementsAssembly = CreateAssembly(); elementsAssembly.CreateElementsAssembly(); elementsAssembly.ActivateBoundaryConditions = true; ShowToGUI.PlotInitialGeometry(elementsAssembly); var AccelerationVector = new double[nodesNumber * 2]; var DisplacementVector = new double[nodesNumber * 2]; var VelocityVector = new double[nodesNumber * 2]; for (int i = 1; i <= 2 * (nodesInPerimeter * 4 + 13) - 1; i += 2) { VelocityVector[i] = -30.0; } InitialConditions initialValues = new InitialConditions(); initialValues.InitialAccelerationVector = BoundaryConditionsImposition.ReducedVector(AccelerationVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialDisplacementVector = BoundaryConditionsImposition.ReducedVector(DisplacementVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialVelocityVector = BoundaryConditionsImposition.ReducedVector(VelocityVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialTime = 0.0; //ExplicitSolver newSolver = new ExplicitSolver(0.0534, 100); ExplicitSolver newSolver = new ExplicitSolver(0.002906, 6000); newSolver.Assembler = elementsAssembly; double[] externalForces = externalForcesStructuralVector; foreach (var dof in loadedStructuralDOFs) { externalForces[dof - 1] = externalForce; } newSolver.InitialValues = initialValues; newSolver.ExternalForcesVector = BoundaryConditionsImposition.ReducedVector(externalForces, elementsAssembly.BoundedDOFsVector); newSolver.LinearSolver = new LUFactorization(); newSolver.ActivateNonLinearSolution = true; newSolver.SolveExplicit(); Tuple <Dictionary <int, double[]>, Dictionary <int, double> > solvectors = newSolver.GetResults(); //int max = solvectors.Item1.OrderByDescending(m => m.Key).FirstOrDefault().Key; //elementsAssembly.UpdateDisplacements(solvectors.Item1.Single(m => m.Key == max).Value); Dictionary <int, double[]> allStepsSolutions = solvectors.Item1; //for (int i = 1; i < allStepsSolutions.Count; i++) for (int i = 0; i < allStepsSolutions.Count - 1; i++) { elementsAssembly.UpdateDisplacements(allStepsSolutions[i]); } ShowToGUI.PlotFinalGeometry(elementsAssembly); double[] fullDynamicSol1 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[510], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol2 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[520], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol3 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[530], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol4 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[540], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol5 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[550], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol6 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[560], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol7 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[570], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol8 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[580], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol9 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[590], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol10 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[599], elementsAssembly.BoundedDOFsVector); VectorOperations.PrintVectorToFile(fullDynamicSol1, @"C:\Users\Public\Documents\Results1.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol2, @"C:\Users\Public\Documents\Results2.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol3, @"C:\Users\Public\Documents\Results3.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol4, @"C:\Users\Public\Documents\Results4.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol5, @"C:\Users\Public\Documents\Results5.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol6, @"C:\Users\Public\Documents\Results6.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol7, @"C:\Users\Public\Documents\Results7.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol8, @"C:\Users\Public\Documents\Results8.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol9, @"C:\Users\Public\Documents\Results9.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol10, @"C:\Users\Public\Documents\Results10.dat"); //newSolver.PrintExplicitSolution(); Results finalResults = new Results() { DynamicSolution = newSolver.explicitSolution, TimeSteps = newSolver.TimeAtEachStep, SelectedDOF = 1, SelectedInterval = 1, SolutionType = "Dynamic" }; return(finalResults); }
public static Results RunExample() { IAssembly elementsAssembly = CreateAssembly(); elementsAssembly.CreateElementsAssembly(); elementsAssembly.ActivateBoundaryConditions = true; ShowToGUI.PlotInitialGeometry(elementsAssembly); var AccelerationVector = new double[nodesNumber * 2]; var DisplacementVector = new double[nodesNumber * 2]; var VelocityVector = new double[nodesNumber * 2]; for (int i = 1; i <= 2 * (3 * circles - 1) * steps - 1; i += 2) { VelocityVector[i] = -50.0; } InitialConditions initialValues = new InitialConditions(); initialValues.InitialAccelerationVector = BoundaryConditionsImposition.ReducedVector(AccelerationVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialDisplacementVector = BoundaryConditionsImposition.ReducedVector(DisplacementVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialVelocityVector = BoundaryConditionsImposition.ReducedVector(VelocityVector, elementsAssembly.BoundedDOFsVector); initialValues.InitialTime = 0.0; //ExplicitSolver newSolver = new ExplicitSolver(0.0035, 3500); ExplicitSolver newSolver = new ExplicitSolver(0.003, 300); newSolver.Assembler = elementsAssembly; double[] externalForces = externalForcesStructuralVector; foreach (var dof in loadedStructuralDOFs) { externalForces[dof - 1] = externalForce; } newSolver.InitialValues = initialValues; newSolver.ExternalForcesVector = BoundaryConditionsImposition.ReducedVector(externalForces, elementsAssembly.BoundedDOFsVector); newSolver.LinearSolver = new LUFactorization(); newSolver.ActivateNonLinearSolution = true; newSolver.SolveNewmark(); Tuple <Dictionary <int, double[]>, Dictionary <int, double> > solvectors = newSolver.GetResults(); //int max = solvectors.Item1.OrderByDescending(m => m.Key).FirstOrDefault().Key; //elementsAssembly.UpdateDisplacements(solvectors.Item1.Single(m => m.Key == max).Value); Dictionary <int, double[]> allStepsSolutions = solvectors.Item1; Dictionary <int, List <double[]> > stress = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > strain = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > gPoints = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > nodesStress = new Dictionary <int, List <double[]> >(); Dictionary <int, List <double[]> > nodesStrain = new Dictionary <int, List <double[]> >(); //for (int i = 1; i < allStepsSolutions.Count; i++) for (int i = 0; i <= allStepsSolutions.Count - 1; i++) { elementsAssembly.UpdateDisplacements(allStepsSolutions[i]); if (i == allStepsSolutions.Count - 1) { stress = elementsAssembly.GetElementsStresses(allStepsSolutions[i]); strain = elementsAssembly.GetElementsStains(allStepsSolutions[i]); gPoints = elementsAssembly.GetElementsGaussPoints(allStepsSolutions[i]); nodesStress = elementsAssembly.GetElementsNodesStresses(allStepsSolutions[i]); nodesStrain = elementsAssembly.GetElementsNodesStains(allStepsSolutions[i]); ExportToFile.ExportMatlabFinalGeometry(elementsAssembly, BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[i], elementsAssembly.BoundedDOFsVector)); } } ShowToGUI.PlotFinalGeometry(elementsAssembly); double[] fullDynamicSol1 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[200], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol2 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[210], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol3 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[220], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol4 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[230], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol5 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[240], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol6 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[250], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol7 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[260], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol8 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[270], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol9 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[280], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol10 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[285], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol11 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[290], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol12 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[291], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol13 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[292], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol14 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[293], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol15 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[294], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol16 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[295], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol17 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[296], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol18 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[297], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol19 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[298], elementsAssembly.BoundedDOFsVector); double[] fullDynamicSol20 = BoundaryConditionsImposition.CreateFullVectorFromReducedVector(allStepsSolutions[299], elementsAssembly.BoundedDOFsVector); VectorOperations.PrintVectorToFile(fullDynamicSol1, @"C:\Users\Public\Documents\Results1.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol2, @"C:\Users\Public\Documents\Results2.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol3, @"C:\Users\Public\Documents\Results3.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol4, @"C:\Users\Public\Documents\Results4.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol5, @"C:\Users\Public\Documents\Results5.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol6, @"C:\Users\Public\Documents\Results6.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol7, @"C:\Users\Public\Documents\Results7.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol8, @"C:\Users\Public\Documents\Results8.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol9, @"C:\Users\Public\Documents\Results9.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol10, @"C:\Users\Public\Documents\Results10.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol11, @"C:\Users\Public\Documents\Results11.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol12, @"C:\Users\Public\Documents\Results12.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol13, @"C:\Users\Public\Documents\Results13.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol14, @"C:\Users\Public\Documents\Results14.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol15, @"C:\Users\Public\Documents\Results15.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol16, @"C:\Users\Public\Documents\Results16.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol17, @"C:\Users\Public\Documents\Results17.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol18, @"C:\Users\Public\Documents\Results18.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol19, @"C:\Users\Public\Documents\Results19.dat"); VectorOperations.PrintVectorToFile(fullDynamicSol20, @"C:\Users\Public\Documents\Results20.dat"); VectorOperations.PrintDictionaryofListsofVectorsToFile(stress, @"C:\Users\Public\Documents\Stress.dat"); VectorOperations.PrintDictionaryofListsofVectorsToFile(strain, @"C:\Users\Public\Documents\Strain.dat"); VectorOperations.PrintDictionaryofListsofVectorsToFile(gPoints, @"C:\Users\Public\Documents\GaussPoints.dat"); VectorOperations.PrintDictionaryofListsofVectorsToFile(nodesStress, @"C:\Users\Public\Documents\StressNodes.dat"); VectorOperations.PrintDictionaryofListsofVectorsToFile(nodesStrain, @"C:\Users\Public\Documents\StrainNodes.dat"); //newSolver.PrintExplicitSolution(); Results finalResults = new Results() { DynamicSolution = newSolver.explicitSolution, TimeSteps = newSolver.TimeAtEachStep, SelectedDOF = 1, SelectedInterval = 1, SolutionType = "Dynamic" }; return(finalResults); }