Example #1
0
        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());
        }
        //TODO: Use Skyline assembler
        private SkylineMatrix CreateGlobalKccStar(Dictionary <int, HashSet <INode> > cornerNodesOfSubdomains,
                                                  FetiDPDofSeparator dofSeparator, Dictionary <int, IFetiDPSubdomainMatrixManager> matrixManagers)
        {
            int[] skylineColHeights = FindSkylineColumnHeights(cornerNodesOfSubdomains, dofSeparator);
            var   skylineBuilder    = SkylineBuilder.Create(dofSeparator.NumGlobalCornerDofs, skylineColHeights);

            for (int s = 0; s < subdomains.Count; ++s)
            {
                IFetiDPSubdomainMatrixManager matrices = matrixManagers[s];

                // KccStar[s] = Kcc[s] - Krc[s]^T * inv(Krr[s]) * Krc[s]
                if (subdomains[s].StiffnessModified)
                {
                    Debug.WriteLine($"{this.GetType().Name}: Calculating Schur complement of remainder dofs"
                                    + " for the stiffness of subdomain {s}");
                    matrices.CalcSchurComplementOfRemainderDofs(); //TODO: At this point Kcc and Krc can be cleared. Maybe Krr too.
                }

                int[]       subdomainToGlobalIndices = dofSeparator.CornerBooleanMatrices[s].GetRowsToColumnsMap();
                IMatrixView subdomainMatrix          = matrices.SchurComplementOfRemainderDofs;
                skylineBuilder.AddSubmatrixSymmetric(subdomainMatrix, subdomainToGlobalIndices);
            }

            return(skylineBuilder.BuildSkylineMatrix());
        }
Example #3
0
                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);
        }