public static double[] CalculateFppReactionsVector(Subdomain subdomain, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes, IVectorView solution, IVectorView dSolution, Dictionary <int, Dictionary <IDofType, double> > initialConvergedBoundaryDisplacements, Dictionary <int, Dictionary <IDofType, double> > totalBoundaryDisplacements, int nIncrement, int totalIncrements) { //TODOGerasimos: 1) Subdomain2 einai h upo kataskevh subdomain.cs ths Marias gia na mporoume na anaferthoume sthn methodo ths CalculateElementNodalDisplacements(..,..). // Otan parei telikh morfh tha taftizetai me thn Subdomain.cs // 2)IVector solution, IVector dSolution EINAI AFTA ME TA OPOIA kaloume thn GetRHSFromSolution sthn 213 tou NRNLAnalyzer double[] FppReactionVector; Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes); FppReactionVector = new double[boundaryNodesOrder.Count * scaleTransitions.PrescribedDofsPerNode()]; // h allliws subdomain.Forces.GetLength(0) var times = new Dictionary <string, TimeSpan>(); var totalStart = DateTime.Now; times.Add("rowIndexCalculation", DateTime.Now - totalStart); times.Add("element", TimeSpan.Zero); times.Add("addition", TimeSpan.Zero); foreach (Element element in subdomain.Elements) { var isEmbeddedElement = element.ElementType is IEmbeddedElement; var elStart = DateTime.Now; //IMatrix2D ElementK = elementProvider.Matrix(element); var localSolution = subdomain.GetLocalVectorFromGlobalWithoutPrescribedDisplacements(element, solution); subdomain.ImposePrescribedDisplacementsWithInitialConditionSEffect(element, localSolution, boundaryNodes, initialConvergedBoundaryDisplacements, totalBoundaryDisplacements, nIncrement, totalIncrements); double[] localdSolution = subdomain.GetLocalVectorFromGlobalWithoutPrescribedDisplacements(element, dSolution); double[] f = element.ElementType.CalculateForces(element, localSolution, localdSolution); times["element"] += DateTime.Now - elStart; elStart = DateTime.Now; var elementDOFTypes = element.ElementType.DofEnumerator.GetDofTypesForMatrixAssembly(element); var matrixAssemblyNodes = element.ElementType.DofEnumerator.GetNodesForMatrixAssembly(element); int iElementMatrixRow = 0; for (int i = 0; i < elementDOFTypes.Count; i++) { INode nodeRow = matrixAssemblyNodes[i]; if (boundaryNodes.ContainsKey(nodeRow.ID)) { for (int i1 = 0; i1 < scaleTransitions.PrescribedDofsPerNode(); i1++) { int dofrow_p = scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[nodeRow.ID] - 1) + i1; FppReactionVector[dofrow_p] += f[iElementMatrixRow + i1]; } } iElementMatrixRow += elementDOFTypes[i].Count; } times["addition"] += DateTime.Now - elStart; } var totalTime = DateTime.Now - totalStart; return(FppReactionVector); }
//int currentSubdomainID; public (Dictionary <int, double[][]>, Dictionary <int, double[][]>) UpdateSubdomainKffAndCalculateKfpDqAndKppDqpMultipleObje(Model model, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, Node> boundaryNodes, Dictionary <int, Dictionary <int, Element> > boundaryElements, ISolver solver) { IReadOnlyDictionary <int, ILinearSystem> linearSystems = solver.LinearSystems; //v2.3 Dictionary <int, double[][]> KfpDqSubdomains = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count); Dictionary <int, double[][]> KppDqVectorsSubdomains = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count); this.boundaryElements = boundaryElements; this.boundaryNodes = boundaryNodes; this.scaleTransitions = scaleTransitions; KfpDqVectors = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count); KppDqVectors = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count); foreach (Subdomain subdomain in model.Subdomains) { #region Create KfpDq and KppDq vectors KfpDqVectors[subdomain.ID] = new double[scaleTransitions.MacroscaleVariableDimension()][]; for (int j1 = 0; j1 < scaleTransitions.MacroscaleVariableDimension(); j1++) { KfpDqVectors[subdomain.ID][j1] = new double[subdomain.FreeDofOrdering.NumFreeDofs]; //v2.2 subdomain.TotalDOFs]; } KppDqVectors[subdomain.ID] = new double[scaleTransitions.MacroscaleVariableDimension()][]; boundaryNodesOrder = SubdomainCalculations.GetNodesOrderInDictionary(boundaryNodes); for (int j1 = 0; j1 < scaleTransitions.MacroscaleVariableDimension(); j1++) { KppDqVectors[subdomain.ID][j1] = new double[boundaryNodesOrder.Count * scaleTransitions.PrescribedDofsPerNode()]; // h allliws subdomain.Forces.GetLength(0) } #endregion } var StiffnessProvider = new StiffnessProviderSimu(this); Dictionary <int, IMatrix> subdomainKs = solver.BuildGlobalMatrices(StiffnessProvider); foreach (Subdomain subdomain in model.Subdomains) { //dofOrdering = subdomain.FreeDofOrdering; //.1 //FreeDofs = subdomain.FreeDofOrdering.FreeDofs;//.1 nodalDOFsDictionary = subdomain.NodalDOFsDictionary; //currentSubdomainID = subdomain.ID; //v2.4 var subdomainK= GlobalMatrixAssemblerSkyline.CalculateFreeFreeGlobalMatrix(subdomain, StiffnessProvider); linearSystems[subdomain.ID].Matrix = subdomainKs[subdomain.ID]; //v2.5 linearSystems[subdomain.ID].Matrix = subdomainK; KfpDqSubdomains.Add(subdomain.ID, KfpDqVectors[subdomain.ID]); KppDqVectorsSubdomains.Add(subdomain.ID, KppDqVectors[subdomain.ID]); } return(KfpDqSubdomains, KppDqVectorsSubdomains); }
public static double[] CalculateDqFpp(double[] FppReactionVector, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes) { double[] DqFpp = new double[scaleTransitions.MacroscaleVariableDimension()]; Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes); foreach (Node boundaryNode in boundaryNodes.Values) { double[] FppDataTriplette = new double[scaleTransitions.PrescribedDofsPerNode()]; for (int i2 = 0; i2 < scaleTransitions.PrescribedDofsPerNode(); i2++) { FppDataTriplette[i2] = FppReactionVector[scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[boundaryNode.ID] - 1) + i2]; } double[] contribution = scaleTransitions.MicroToMacroTransition(boundaryNode, FppDataTriplette); for (int i3 = 0; i3 < scaleTransitions.MacroscaleVariableDimension(); i3++) { DqFpp[i3] += contribution[i3]; } } return(DqFpp); }
public static double[,] CalculateDqCondDq(double[][] f4_vectors, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes) { double[,] DqCondDq = new double[scaleTransitions.MacroscaleVariableDimension(), scaleTransitions.MacroscaleVariableDimension()]; Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes); foreach (Node boundaryNode in boundaryNodes.Values) { for (int i1 = 0; i1 < f4_vectors.GetLength(0); i1++) { double[] f4DataTriplette = new double[scaleTransitions.PrescribedDofsPerNode()]; for (int i2 = 0; i2 < scaleTransitions.PrescribedDofsPerNode(); i2++) { f4DataTriplette[i2] = f4_vectors[i1][scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[boundaryNode.ID] - 1) + i2]; } double[] contribution = scaleTransitions.MicroToMacroTransition(boundaryNode, f4DataTriplette); for (int i3 = 0; i3 < scaleTransitions.MacroscaleVariableDimension(); i3++) { DqCondDq[i3, i1] += contribution[i3]; } } } return(DqCondDq); }
public static double[][] CalculateKpfKffinverseKfpDq(double[][] f2_vectors, Subdomain subdomain, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes) { var dofOrdering = subdomain.FreeDofOrdering; //.1 var FreeDofs = subdomain.FreeDofOrdering.FreeDofs; //.1Dictionary<int, Dictionary<DOFType, int>> nodalDOFsDictionary = subdomain.NodalDOFsDictionary; double[][] f3_vectors = new double[f2_vectors.GetLength(0)][]; for (int i1 = 0; i1 < f2_vectors.GetLength(0); i1++) { f3_vectors[i1] = new double[scaleTransitions.PrescribedDofsPerNode() * boundaryNodes.Count]; } Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes); var times = new Dictionary <string, TimeSpan>(); var totalStart = DateTime.Now; times.Add("rowIndexCalculation", DateTime.Now - totalStart); times.Add("element", TimeSpan.Zero); times.Add("addition", TimeSpan.Zero); foreach (Element element in subdomain.Elements) //.3 ElementsDictionary.Values) { var isEmbeddedElement = element.ElementType is IEmbeddedElement; var elStart = DateTime.Now; IMatrix ElementK = elementProvider.Matrix(element); times["element"] += DateTime.Now - elStart; elStart = DateTime.Now; var elementDOFTypes = element.ElementType.DofEnumerator.GetDofTypesForMatrixAssembly(element); var matrixAssemblyNodes = element.ElementType.DofEnumerator.GetNodesForMatrixAssembly(element); int iElementMatrixRow = 0; for (int i = 0; i < elementDOFTypes.Count; i++) { INode nodeRow = matrixAssemblyNodes[i]; if (boundaryNodes.ContainsKey(nodeRow.ID)) { for (int i1 = 0; i1 < scaleTransitions.PrescribedDofsPerNode(); i1++) { int dofrow_p = scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[nodeRow.ID] - 1) + i1; int iElementMatrixColumn = 0; for (int j = 0; j < elementDOFTypes.Count; j++) { INode nodeColumn = matrixAssemblyNodes[j]; int dofTypeColumnToNumber = -1; foreach (IDofType dofTypeColumn in elementDOFTypes[j]) { dofTypeColumnToNumber++; bool isFree = FreeDofs.TryGetValue(matrixAssemblyNodes[j], elementDOFTypes[j][dofTypeColumnToNumber], out int dofColumn); // v2.4 int dofColumn = nodalDOFsDictionary.ContainsKey(nodeColumn.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeColumn.ID][dofTypeColumn]; if (isFree) // TODOGerasimos edw pithanws thelei kai elegxo alliws an den ta exoume afhsei constrained ta p kai einai elefthera px me to an anhkoun sto baoundary nodes { // alla etsi einai oti akrivws thewritai kai sto assembly tou Kff opote ok for (int i2 = 0; i2 < f2_vectors.GetLength(0); i2++) { f3_vectors[i2][dofrow_p] += ElementK[iElementMatrixRow + i1, iElementMatrixColumn] * f2_vectors[i2][dofColumn]; } } iElementMatrixColumn++; } } } } iElementMatrixRow += elementDOFTypes[i].Count; } times["addition"] += DateTime.Now - elStart; } var totalTime = DateTime.Now - totalStart; return(f3_vectors); }
/// <summary> /// /// </summary> /// <param name="KfpDqSubdomains"></param> /// <param name="model"></param> /// <param name="elementProvider"></param> /// <param name="scaleTransitions"></param> /// <param name="boundaryNodes"></param> /// <param name="solver"> /// <paramref name="solver"/>.<see cref="ISolver.Initialize"/> must already have been called. Also the linear system matrices must already have been set. /// </param> public static Dictionary <int, double[][]> CalculateKffinverseKfpDqSubdomains(Dictionary <int, double[][]> KfpDqSubdomains, Model model, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, Node> boundaryNodes, ISolver solver) { IReadOnlyDictionary <int, ILinearSystem> linearSystems = solver.LinearSystems; #region Creation of solution vectors structure Dictionary <int, double[][]> f2_vectorsSubdomains = new Dictionary <int, double[][]>(); foreach (int subdomainID in KfpDqSubdomains.Keys) { f2_vectorsSubdomains.Add(subdomainID, new double[KfpDqSubdomains[subdomainID].GetLength(0)][]); } #endregion //#region Creation of linear systems with no RHS (first RHS value can be assigned too ) //ILinearSystem[] seclinearSystems = new ILinearSystem[linearSystems.Count]; //int counter = 0; //foreach (ILinearSystem subdomain in linearSystems.Values) //{ // seclinearSystems[counter] = new SkylineLinearSystem(subdomain.ID, new double[KfpDqSubdomains[subdomain.ID][0].GetLength(0)]); // seclinearSystems[counter].Matrix = subdomain.Matrix; //} //#endregion //#region creation of solver //var secSolver = new SolverSkyline(seclinearSystems[0]); //secSolver.Initialize(); //#endregion #region Consecutively(for macroscaleVariableDimension times) Set proper right hand side. Solve. Copy solution in output vector int oneSubomainID = linearSystems.First().Value.Subdomain.ID; //seclinearSystems[0].ID; for (int k = 0; k < scaleTransitions.MacroscaleVariableDimension(); k++) //KfpDqSubdomains[linearSystems[0].ID].GetLength(0)=Mac { #region Set proper RHS //var globalRHS = new Vector(model.TotalDOFs); //TODO: uncoomment if globalRHS is needed for solver foreach (ILinearSystem secSubdomain in linearSystems.Values) { secSubdomain.RhsVector = Vector.CreateFromArray(KfpDqSubdomains[secSubdomain.Subdomain.ID][k], false); //secSubdomain.RhsVector = Vector.CreateFromArray(KfpDqSubdomains[secSubdomain.Subdomain.ID][k], true); Wste sigoura na mhn peiraxthei to double[] //mappings[seclinearSystems.Select((v, i) => new { System = v, Index = i }).First(x => x.System.ID == secSubdomain.ID).Index].SubdomainToGlobalVector(subdomainRHS.Data, globalRHS.Data); //TODO: uncoomment if globalRHS is needed for solver } #endregion #region Solve solver.Solve(); #endregion #region Copy solution in output vector foreach (ILinearSystem secSubdomain in linearSystems.Values) { f2_vectorsSubdomains[secSubdomain.Subdomain.ID][k] = secSubdomain.Solution.CopyToArray(); } #endregion } #endregion return(f2_vectorsSubdomains); }
public static Dictionary <int, double[]> CalculateFppReactionsVectorSubdomains(Model model, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, Node> boundaryNodes, Dictionary <int, IVector> solution, Dictionary <int, IVector> dSolution, Dictionary <int, Dictionary <IDofType, double> > initialConvergedBoundaryDisplacements, Dictionary <int, Dictionary <IDofType, double> > totalBoundaryDisplacements, int nIncrement, int totalIncrements) { Dictionary <int, double[]> FppReactionVectorSubdomains = new Dictionary <int, double[]>(); foreach (Subdomain subdomain in model.Subdomains) { FppReactionVectorSubdomains.Add(subdomain.ID, SubdomainCalculations.CalculateFppReactionsVector(subdomain, elementProvider, scaleTransitions, boundaryNodes, solution[subdomain.ID], dSolution[subdomain.ID], initialConvergedBoundaryDisplacements, totalBoundaryDisplacements, nIncrement, totalIncrements)); } return(FppReactionVectorSubdomains); }
public static double[][] CombineMultipleSubdomainsIntegrationVectorsIntoTotal(Dictionary <int, double[][]> VectorsSubdomains, IScaleTransitions scaleTransitions) { double[][] totalVectors = new double[scaleTransitions.MacroscaleVariableDimension()][]; //or VectorsSubdomains.getLength(0); int oneSubdomainID = VectorsSubdomains.Keys.ElementAt(0); for (int i1 = 0; i1 < scaleTransitions.MacroscaleVariableDimension(); i1++) { totalVectors[i1] = new double[VectorsSubdomains[oneSubdomainID][i1].GetLength(0)]; } foreach (int subdomainID in VectorsSubdomains.Keys) { for (int i1 = 0; i1 < scaleTransitions.MacroscaleVariableDimension(); i1++) { for (int i2 = 0; i2 < VectorsSubdomains[subdomainID][i1].GetLength(0); i2++) { totalVectors[i1][i2] += VectorsSubdomains[subdomainID][i1][i2]; } } } return(totalVectors); }
public static Dictionary <int, double[][]> CalculateKpfKffinverseKfpDqSubdomains(Dictionary <int, double[][]> f2_vectorsSubdomains, Model model, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, Node> boundaryNodes) { Dictionary <int, double[][]> f3_vectorsSubdomains = new Dictionary <int, double[][]>(); foreach (Subdomain subdomain in model.Subdomains) { f3_vectorsSubdomains.Add(subdomain.ID, SubdomainCalculations.CalculateKpfKffinverseKfpDq(f2_vectorsSubdomains[subdomain.ID], subdomain, elementProvider, scaleTransitions, boundaryNodes)); } return(f3_vectorsSubdomains); }