public SkylineMatrix BuildGlobalMatrix(ISubdomainFreeDofOrdering dofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { if (!areIndexersCached) { skylineBuilder = SkylineBuilder.Create(dofOrdering.NumFreeDofs, FindSkylineColumnHeights(elements, dofOrdering.NumFreeDofs, dofOrdering.FreeDofs)); areIndexersCached = true; } else { skylineBuilder.ClearValues(); } foreach (IElement element in elements) { //if (element.ID != 2) continue; // TODO: perhaps that could be done and cached during the dof enumeration to avoid iterating over the dofs twice (int[] elementDofIndices, int[] subdomainDofIndices) = dofOrdering.MapFreeDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); skylineBuilder.AddSubmatrixSymmetric(elementMatrix, elementDofIndices, subdomainDofIndices); } //// Print matrix //var writer = new LinearAlgebra.Output.FullMatrixWriter(); ////writer.NumericFormat = new FixedPointFormat() { NumDecimalDigits = 2 }; //writer.ArrayFormat = new LinearAlgebra.Output.Formatting.Array2DFormat("", "", "", "\n", ","); //writer.WriteToFile(skylineBuilder.BuildSkylineMatrix()/*.DoToAllEntries(x => Math.Round(x * 1E-6, 3))*/, @"C:\Users\Serafeim\Desktop\xfem.txt"); return(skylineBuilder.BuildSkylineMatrix()); }
IMatrixView matrixConstrConstr) BuildGlobalSubmatrices( ISubdomainFreeDofOrdering freeDofOrdering, ISubdomainConstrainedDofOrdering constrainedDofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { int numFreeDofs = freeDofOrdering.NumFreeDofs; var subdomainMatrix = Matrix.CreateZero(numFreeDofs, numFreeDofs); //TODO: also reuse the indexers of the constrained matrices. constrainedAssembler.InitializeNewMatrices(freeDofOrdering.NumFreeDofs, constrainedDofOrdering.NumConstrainedDofs); // Process the stiffness of each element foreach (IElement element in elements) { (int[] elementDofsFree, int[] subdomainDofsFree) = freeDofOrdering.MapFreeDofsElementToSubdomain(element); //IReadOnlyDictionary<int, int> elementToGlobalDofs = dofOrdering.MapFreeDofsElementToSubdomain(element); (int[] elementDofsConstrained, int[] subdomainDofsConstrained) = constrainedDofOrdering.MapConstrainedDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); AddElementToGlobalMatrix(subdomainMatrix, elementMatrix, elementDofsFree, subdomainDofsFree); constrainedAssembler.AddElementMatrix(elementMatrix, elementDofsFree, subdomainDofsFree, elementDofsConstrained, subdomainDofsConstrained); } (CsrMatrix matrixConstrFree, CsrMatrix matrixConstrConstr) = constrainedAssembler.BuildMatrices(); return(subdomainMatrix, matrixConstrFree.TransposeToCSC(false), matrixConstrFree, matrixConstrConstr); }
public Dictionary <int, IMatrix> BuildGlobalMatrices(IElementMatrixProvider elementMatrixProvider) { HandleMatrixWillBeSet(); //TODO: temporary solution to avoid this getting called once for each linear system/observable var watch = new Stopwatch(); watch.Start(); var matrices = new Dictionary <int, IMatrix>(); foreach (ISubdomain subdomain in model.Subdomains) //TODO: this must be done in parallel { int s = subdomain.ID; IMatrix Kff; if (subdomain.StiffnessModified) { Debug.WriteLine($"{this.GetType().Name}: Assembling the free-free stiffness matrix of subdomain {s}"); Kff = matrixManagers[s].BuildGlobalMatrix(subdomain.FreeDofOrdering, subdomain.Elements, elementMatrixProvider); linearSystems[s].Matrix = Kff; //TODO: This should be done by the solver not the analyzer. This method should return void. } else { Kff = (IMatrix)(linearSystems[s].Matrix); //TODO: remove the cast } matrices[s] = Kff; } watch.Stop(); Logger.LogTaskDuration("Matrix assembly", watch.ElapsedMilliseconds); this.Initialize(); //TODO: Should this be called by the analyzer? Probably not, since it must be called before DistributeBoundaryLoads(). return(matrices); }
public CsrMatrix BuildGlobalMatrix(ISubdomainFreeDofOrdering dofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { int numFreeDofs = dofOrdering.NumFreeDofs; var subdomainMatrix = DokRowMajor.CreateEmpty(numFreeDofs, numFreeDofs); foreach (IElement element in elements) { (int[] elementDofIndices, int[] subdomainDofIndices) = dofOrdering.MapFreeDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); subdomainMatrix.AddSubmatrixSymmetric(elementMatrix, elementDofIndices, subdomainDofIndices); } (double[] values, int[] colIndices, int[] rowOffsets) = subdomainMatrix.BuildCsrArrays(sortColsOfEachRow); if (!isIndexerCached) { cachedColIndices = colIndices; cachedRowOffsets = rowOffsets; isIndexerCached = true; } else { Debug.Assert(Utilities.AreEqual(cachedColIndices, colIndices)); Debug.Assert(Utilities.AreEqual(cachedRowOffsets, rowOffsets)); } return(CsrMatrix.CreateFromArrays(numFreeDofs, numFreeDofs, values, cachedColIndices, cachedRowOffsets, false)); }
public SymmetricCscMatrix BuildGlobalMatrix(ISubdomainFreeDofOrdering dofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { int numFreeDofs = dofOrdering.NumFreeDofs; var subdomainMatrix = DokSymmetric.CreateEmpty(numFreeDofs); foreach (IElement element in elements) { // TODO: perhaps that could be done and cached during the dof enumeration to avoid iterating over the dofs twice (int[] elementDofIndices, int[] subdomainDofIndices) = dofOrdering.MapFreeDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); subdomainMatrix.AddSubmatrixSymmetric(elementMatrix, elementDofIndices, subdomainDofIndices); } (double[] values, int[] rowIndices, int[] colOffsets) = subdomainMatrix.BuildSymmetricCscArrays(sortColsOfEachRow); if (!isIndexerCached) { cachedRowIndices = rowIndices; cachedColOffsets = colOffsets; isIndexerCached = true; } else { Debug.Assert(Utilities.AreEqual(cachedRowIndices, rowIndices)); Debug.Assert(Utilities.AreEqual(cachedColOffsets, colOffsets)); } return(SymmetricCscMatrix.CreateFromArrays(numFreeDofs, values, cachedRowIndices, cachedColOffsets, false)); }
public override Dictionary <int, IMatrix> BuildGlobalMatrices(IElementMatrixProvider elementMatrixProvider) { #region Code to facilitate debugging //var writer = new FullMatrixWriter(); //writer.NumericFormat = new ExponentialFormat() { NumDecimalDigits = 2 }; //var dofOrderingSimple = (new SimpleDofOrderer()).OrderDofs(model, subdomain); //Matrix simpleOrderK = (Matrix)assembler.BuildGlobalMatrix( // dofOrderingSimple, subdomain.Elements, elementMatrixProvider); //Console.WriteLine(); //Console.WriteLine("Global matrix with simple ordering"); //writer.WriteToConsole(simpleOrderK); //var dofOrderingNodeMajor = (new NodeMajorDofOrderer()).OrderDofs(model, subdomain); //Matrix nodeMajorK = (Matrix)assembler.BuildGlobalMatrix( // dofOrderingNodeMajor, subdomain.Elements, elementMatrixProvider); //Console.WriteLine(); //Console.WriteLine("Global matrix with node major ordering"); //writer.WriteToConsole(nodeMajorK); //var permutationNodeMajorToSimple = new int[dofOrderingNodeMajor.NumFreeDofs]; //foreach ((INode node, DOFType dofType, int nodeMajorIdx) in dofOrderingNodeMajor.FreeDofs) //{ // permutationNodeMajorToSimple[nodeMajorIdx] = dofOrderingSimple.FreeDofs[node, dofType]; //} //Matrix reorderedK = nodeMajorK.Reorder(permutationNodeMajorToSimple, true); //Console.WriteLine(); //Console.WriteLine("Global matrix with node major ordering, reordered to simple"); //writer.WriteToConsole(reorderedK); //Console.WriteLine("Existing global dof enumeration:"); //Utilities.PrintDofOrder(subdomain); //Console.WriteLine(); //Console.WriteLine("Using dof orderer:"); //Console.WriteLine(dofOrderer.FreeDofs.ToString()); //Console.WriteLine(); //Console.WriteLine("Global matrix"); //SkylineMatrix matrix = assembler.BuildGlobalMatrix(dofOrderer, subdomain.ΙElementsDictionary.Values, elementMatrixProvider); //var writer = new FullMatrixWriter(); //writer.NumericFormat = new ExponentialFormat() { NumDecimalDigits = 2 }; //writer.WriteToConsole(matrix); #endregion var watch = new Stopwatch(); watch.Start(); Matrix matrix = assembler.BuildGlobalMatrix(subdomain.FreeDofOrdering, subdomain.Elements, elementMatrixProvider); watch.Stop(); Logger.LogTaskDuration("Matrix assembly", watch.ElapsedMilliseconds); return(new Dictionary <int, IMatrix> { { subdomain.ID, matrix } }); }
matrixConstrConstr) BuildGlobalSubmatrices(ISubdomainFreeDofOrdering freeDofRowOrdering, ISubdomainFreeDofOrdering freeDofColOrdering, ISubdomainConstrainedDofOrdering constrainedDofRowOrdering, ISubdomainConstrainedDofOrdering constrainedDofColOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { int numFreeRowDofs = freeDofRowOrdering.NumFreeDofs; int numFreeColDofs = freeDofColOrdering.NumFreeDofs; var subdomainMatrix = DokRowMajor.CreateEmpty(numFreeRowDofs, numFreeColDofs); constrainedAssembler.InitializeNewMatrices(freeDofRowOrdering.NumFreeDofs, constrainedDofRowOrdering.NumConstrainedDofs); foreach (var element in elements) { (int[] elementRowDofsFree, int[] subdomainRowDofsFree) = freeDofRowOrdering.MapFreeDofsElementToSubdomain(element); (int[] elementColDofsFree, int[] subdomainColDofsFree) = freeDofColOrdering.MapFreeDofsElementToSubdomain(element); (int[] elementRowDofsConstrained, int[] subdomainRowDofsConstrained) = constrainedDofRowOrdering.MapConstrainedDofsElementToSubdomain(element); (int[] elementColDofsConstrained, int[] subdomainColDofsConstrained) = constrainedDofColOrdering.MapConstrainedDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); subdomainMatrix.AddSubmatrix(elementMatrix, elementRowDofsFree, subdomainRowDofsFree, elementColDofsFree, subdomainColDofsFree); constrainedAssembler.AddElementMatrix(elementMatrix, elementRowDofsFree, subdomainRowDofsFree, elementRowDofsConstrained, subdomainRowDofsConstrained); //TODO: check validity } (double[] values, int[] colIndices, int[] rowOffsets) = subdomainMatrix.BuildCsrArrays(sortColsOfEachRow); if (!isIndexerCached) { cachedColIndices = colIndices; cachedRowOffsets = rowOffsets; isIndexerCached = true; } else { Debug.Assert(Utilities.AreEqual(cachedColIndices, colIndices)); Debug.Assert(Utilities.AreEqual(cachedRowOffsets, rowOffsets)); } subdomainMatrix = null; var matrixFreeFree = CsrMatrix.CreateFromArrays(numFreeRowDofs, numFreeColDofs, values, cachedColIndices, cachedRowOffsets, false); (CsrMatrix matrixConstrFree, CsrMatrix matrixConstrConstr) = constrainedAssembler.BuildMatrices(); // TODO: see if this work return(matrixFreeFree, matrixConstrFree, matrixConstrFree.TransposeToCSC(false), matrixConstrConstr); }
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); }
public virtual Dictionary <int, IMatrix> BuildGlobalMatrices(IElementMatrixProvider elementMatrixProvider) { var watch = new Stopwatch(); watch.Start(); TMatrix matrix = assembler.BuildGlobalMatrix(subdomain.FreeDofOrdering, subdomain.Elements, elementMatrixProvider); watch.Stop(); Logger.LogTaskDuration("Matrix assembly", watch.ElapsedMilliseconds); return(new Dictionary <int, IMatrix> { { subdomain.ID, matrix } }); }
IMatrixView matrixConstrConstr) BuildGlobalSubmatrices( ISubdomainFreeDofOrdering freeDofOrdering, ISubdomainConstrainedDofOrdering constrainedDofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { int numFreeDofs = freeDofOrdering.NumFreeDofs; var subdomainMatrix = DokSymmetric.CreateEmpty(numFreeDofs); //TODO: also reuse the indexers of the constrained matrices. constrainedAssembler.InitializeNewMatrices(freeDofOrdering.NumFreeDofs, constrainedDofOrdering.NumConstrainedDofs); // Process the stiffness of each element foreach (IElement element in elements) { // TODO: perhaps that could be done and cached during the dof enumeration to avoid iterating over the dofs twice (int[] elementDofsFree, int[] subdomainDofsFree) = freeDofOrdering.MapFreeDofsElementToSubdomain(element); (int[] elementDofsConstrained, int[] subdomainDofsConstrained) = constrainedDofOrdering.MapConstrainedDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); subdomainMatrix.AddSubmatrixSymmetric(elementMatrix, elementDofsFree, subdomainDofsFree); constrainedAssembler.AddElementMatrix(elementMatrix, elementDofsFree, subdomainDofsFree, elementDofsConstrained, subdomainDofsConstrained); } // Create and cache the CSC arrays for the free dofs. (double[] values, int[] rowIndices, int[] colOffsets) = subdomainMatrix.BuildSymmetricCscArrays(sortColsOfEachRow); if (!isIndexerCached) { cachedRowIndices = rowIndices; cachedColOffsets = colOffsets; isIndexerCached = true; } else { Debug.Assert(Utilities.AreEqual(cachedRowIndices, rowIndices)); Debug.Assert(Utilities.AreEqual(cachedColOffsets, colOffsets)); } // Create the free and constrained matrices. subdomainMatrix = null; // Let the DOK be garbaged collected early, in case there isn't sufficient memory. var matrixFreeFree = SymmetricCscMatrix.CreateFromArrays(numFreeDofs, values, cachedRowIndices, cachedColOffsets, false); (CsrMatrix matrixConstrFree, CsrMatrix matrixConstrConstr) = constrainedAssembler.BuildMatrices(); return(matrixFreeFree, matrixConstrFree.TransposeToCSC(false), matrixConstrFree, matrixConstrConstr); }
public Matrix BuildGlobalMatrix(ISubdomainFreeDofOrdering dofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider elementMatrixProvider) { int numFreeDofs = dofOrdering.NumFreeDofs; var subdomainMatrix = Matrix.CreateZero(numFreeDofs, numFreeDofs); // Process the stiffness of each element foreach (IElement element in elements) { // TODO: perhaps that could be done and cached during the dof enumeration to avoid iterating over the dofs twice (int[] elementDofIndices, int[] subdomainDofIndices) = dofOrdering.MapFreeDofsElementToSubdomain(element); //IReadOnlyDictionary<int, int> elementToGlobalDofs = dofOrdering.MapFreeDofsElementToSubdomain(element); IMatrix elementMatrix = elementMatrixProvider.Matrix(element); AddElementToGlobalMatrix(subdomainMatrix, elementMatrix, elementDofIndices, subdomainDofIndices); } return(subdomainMatrix); }
IMatrixView matrixConstrConstr) BuildGlobalSubmatrices( ISubdomainFreeDofOrdering freeDofOrdering, ISubdomainConstrainedDofOrdering constrainedDofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) { if (!areIndexersCached) { skylineBuilder = SkylineBuilder.Create(freeDofOrdering.NumFreeDofs, FindSkylineColumnHeights(elements, freeDofOrdering.NumFreeDofs, freeDofOrdering.FreeDofs)); areIndexersCached = true; } else { skylineBuilder.ClearValues(); } //TODO: also reuse the indexers of the constrained matrices. constrainedAssembler.InitializeNewMatrices(freeDofOrdering.NumFreeDofs, constrainedDofOrdering.NumConstrainedDofs); // Process the stiffness of each element foreach (IElement element in elements) { // TODO: perhaps that could be done and cached during the dof enumeration to avoid iterating over the dofs twice (int[] elementDofsFree, int[] subdomainDofsFree) = freeDofOrdering.MapFreeDofsElementToSubdomain(element); (int[] elementDofsConstrained, int[] subdomainDofsConstrained) = constrainedDofOrdering.MapConstrainedDofsElementToSubdomain(element); IMatrix elementMatrix = matrixProvider.Matrix(element); skylineBuilder.AddSubmatrixSymmetric(elementMatrix, elementDofsFree, subdomainDofsFree); constrainedAssembler.AddElementMatrix(elementMatrix, elementDofsFree, subdomainDofsFree, elementDofsConstrained, subdomainDofsConstrained); } // Create the free and constrained matrices. SkylineMatrix matrixFreeFree = skylineBuilder.BuildSkylineMatrix(); (CsrMatrix matrixConstrFree, CsrMatrix matrixConstrConstr) = constrainedAssembler.BuildMatrices(); return(matrixFreeFree, matrixConstrFree.TransposeToCSC(false), matrixConstrFree, matrixConstrConstr); }
public (IMatrix Kff, IMatrixView Kfc, IMatrixView Kcf, IMatrixView Kcc) BuildGlobalSubmatrices( ISubdomainFreeDofOrdering freeDofOrdering, ISubdomainConstrainedDofOrdering constrainedDofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) => assembler.BuildGlobalSubmatrices(freeDofOrdering, constrainedDofOrdering, elements, matrixProvider);
public IMatrix BuildGlobalMatrix(ISubdomainFreeDofOrdering dofOrdering, IEnumerable <IElement> elements, IElementMatrixProvider matrixProvider) => assembler.BuildGlobalMatrix(dofOrdering, elements, matrixProvider);
public ElementPoreMassProvider(IElementMatrixProvider solidMassProvider, double massCoefficient) { this.solidMassProvider = solidMassProvider; this.massCoefficient = massCoefficient; }
IMatrixView matrixConstrConstr)> BuildGlobalSubmatrices(IElementMatrixProvider elementMatrixProvider) { HandleMatrixWillBeSet(); //TODO: temporary solution to avoid this getting called once for each linear system/observable var watch = new Stopwatch(); watch.Start(); var matrices = new Dictionary <int, (IMatrix Aff, IMatrixView Afc, IMatrixView Acf, IMatrixView Acc)>(); foreach (ISubdomain subdomain in model.Subdomains) //TODO: this must be done in parallel { int s = subdomain.ID; if (!subdomain.StiffnessModified) { throw new NotImplementedException("This optimization is not implemented"); } if (subdomain.ConstrainedDofOrdering == null) { throw new InvalidOperationException("In order to build the matrices corresponding to constrained dofs of," + $" subdomain {s}, they must have been ordered first."); } (IMatrix Kff, IMatrixView Kfc, IMatrixView Kcf, IMatrixView Kcc) = matrixManagers[s].BuildGlobalSubmatrices(subdomain.FreeDofOrdering, subdomain.ConstrainedDofOrdering, subdomain.Elements, elementMatrixProvider); matrices[s] = (Kff, Kfc, Kcf, Kcc); linearSystems[s].Matrix = Kff; //TODO: This should be done by the solver not the analyzer. This method should return void. } watch.Stop(); Logger.LogTaskDuration("Matrix assembly", watch.ElapsedMilliseconds); this.Initialize(); //TODO: Should this be called by the analyzer? Probably not, since it must be called before DistributeBoundaryLoads(). return(matrices); }
//private static int[] CalculateRowIndex(Subdomain subdomain) //{ // return CalculateRowIndex(subdomain, subdomain.NodalDOFsDictionary); //} public static SkylineMatrix2D <double> CalculateGlobalMatrix(Subdomain subdomain, Dictionary <int, Dictionary <DOFType, int> > nodalDOFsDictionary, IElementMatrixProvider elementProvider) { // TODO: should encapsulate DOF logic into a separate entity that will manage things if embedded or not (should return element matrix and globaldofs correspondence list var times = new Dictionary <string, TimeSpan>(); var totalStart = DateTime.Now; SkylineMatrix2D <double> K = new SkylineMatrix2D <double>(GlobalMatrixAssemblerSkyline.CalculateRowIndex(subdomain, nodalDOFsDictionary)); times.Add("rowIndexCalculation", DateTime.Now - totalStart); times.Add("element", TimeSpan.Zero); times.Add("addition", TimeSpan.Zero); foreach (Element element in subdomain.ElementsDictionary.Values) { var isEmbeddedElement = element.ElementType is IEmbeddedElement; var elStart = DateTime.Now; IMatrix2D <double> ElementK = elementProvider.Matrix(element); times["element"] += DateTime.Now - elStart; elStart = DateTime.Now; var elementDOFTypes = element.ElementType.DOFEnumerator.GetDOFTypes(element); var matrixAssemblyNodes = element.ElementType.DOFEnumerator.GetNodesForMatrixAssembly(element); int iElementMatrixRow = 0; for (int i = 0; i < elementDOFTypes.Count; i++) { Node nodeRow = matrixAssemblyNodes[i]; foreach (DOFType dofTypeRow in elementDOFTypes[i]) { int dofRow = nodalDOFsDictionary.ContainsKey(nodeRow.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeRow.ID][dofTypeRow]; if (dofRow != -1) { int iElementMatrixColumn = 0; for (int j = 0; j < elementDOFTypes.Count; j++) { Node nodeColumn = matrixAssemblyNodes[j]; foreach (DOFType dofTypeColumn in elementDOFTypes[j]) { int dofColumn = nodalDOFsDictionary.ContainsKey(nodeColumn.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeColumn.ID][dofTypeColumn]; if (dofColumn != -1) { int height = dofRow - dofColumn; if (height >= 0) { K.Data[K.RowIndex[dofRow] + height] += ElementK[iElementMatrixRow, iElementMatrixColumn]; } } iElementMatrixColumn++; } } } iElementMatrixRow++; } } times["addition"] += DateTime.Now - elStart; } var totalTime = DateTime.Now - totalStart; return(K); }
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); }
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); }
//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); }
/// <summary> /// ELEMENT provider tha perastei profanws o ElementStructuralStiffnessProvider elementProvider = new ElementStructuralStiffnessProvider(); /// kai subdomain prosoxh sta ID idia me ta linearsystems /// </summary> /// <param name="subdomain"></param> /// <param name="elementProvider"></param> public EquivalentContributionsAssebler(Subdomain subdomain, IElementMatrixProvider elementProvider) { this.subdomain = subdomain; this.elementProvider = elementProvider; }
public ElementPoreStiffnessProvider(IElementMatrixProvider solidStiffnessProvider, double stiffnessCoefficient) { this.solidStiffnessProvider = solidStiffnessProvider; this.stiffnessCoefficient = stiffnessCoefficient; }
private IElementMatrixProvider elementProvider; //TODO: not sure if df = K * du is the best way to calcuate df. public DirichletEquivalentLoadsStructural(IElementMatrixProvider elementProvider) { this.elementProvider = elementProvider; }
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); }
IMatrixView matrixConstrConstr)> BuildGlobalSubmatrices(IElementMatrixProvider elementMatrixProvider) { var watch = new Stopwatch(); watch.Start(); if (subdomain.ConstrainedDofOrdering == null) { throw new InvalidOperationException("In order to build the matrices corresponding to constrained dofs," + " they must have been ordered first."); } (IMatrix Aff, IMatrixView Afc, IMatrixView Acf, IMatrixView Acc) = assembler.BuildGlobalSubmatrices( subdomain.FreeDofRowOrdering, subdomain.FreeDofColOrdering, subdomain.ConstrainedDofRowOrdering, subdomain.ConstrainedDofColOrdering, subdomain.Elements, elementMatrixProvider); watch.Stop(); Logger.LogTaskDuration("Matrix assembly", watch.ElapsedMilliseconds); return(new Dictionary <int, (IMatrix, IMatrixView, IMatrixView, IMatrixView)> { { subdomain.ID, (Aff, Afc, Acf, Acc) } }); }
/// <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 ElementPoreDampingProvider(IElementMatrixProvider solidDampingProvider, double dampingCoefficient) { this.solidDampingProvider = solidDampingProvider; this.dampingCoefficient = dampingCoefficient; }
public static SkylineMatrix2D <double> CalculateGlobalMatrix(Subdomain subdomain, IElementMatrixProvider elementProvider) { return(CalculateGlobalMatrix(subdomain, subdomain.NodalDOFsDictionary, elementProvider)); }