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); }
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); }
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); }
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); }