Beispiel #1
0
        public static void TestInterfaceProblemSolution()
        {
            // Setup the model and solver
            Model model = Quads4x4MappingMatricesTests.CreateModel();
            Dictionary <int, HashSet <INode> > cornerNodes = Quads4x4MappingMatricesTests.DefineCornerNodes(model);
            var fetiMatrices        = new DenseFetiDPSubdomainMatrixManager.Factory();
            var cornerNodeSelection = new UsedDefinedCornerNodes(cornerNodes);
            var solver = new FetiDPSolver.Builder(cornerNodeSelection, fetiMatrices).BuildSolver(model);

            model.ConnectDataStructures();
            solver.OrderDofs(false);
            solver.Initialize();

            // Mock the stiffness matrices and force vectors
            Dictionary <int, IFetiDPSubdomainMatrixManager> matrixManagers = MockStiffnesses();
            Dictionary <int, IFetiSubdomainMatrixManager>   matrixManagersPreconditioning = MockStiffnessesForPreconditioning();
            Dictionary <int, Matrix> Krr = MatricesKrr;
            Vector dr = VectorDr;

            // Access private fields of FetiDPSolver
            FieldInfo fi = typeof(FetiDPSolver).GetField("lagrangeEnumerator", BindingFlags.NonPublic | BindingFlags.Instance);
            var       lagrangeEnumerator = (FetiDPLagrangeMultipliersEnumerator)fi.GetValue(solver);

            fi = typeof(FetiDPSolver).GetField("dofSeparator", BindingFlags.NonPublic | BindingFlags.Instance);
            var dofSeparator = (FetiDPDofSeparator)fi.GetValue(solver);

            // Hardcoded coarse problem matrix and rhs
            var    coarseSolver   = new DenseFetiDPCoarseProblemSolver(model.Subdomains);
            Vector globalFcStar   = VectorFcStar;
            Matrix inverseKccStar = MatrixKccStar.Invert(); // It must be set as a private field using reflection.

            fi = typeof(DenseFetiDPCoarseProblemSolver).GetField("inverseGlobalKccStar",
                                                                 BindingFlags.NonPublic | BindingFlags.Instance);
            fi.SetValue(coarseSolver, inverseKccStar);

            // Dirichlet preconditioner
            var precondFactory = new DirichletPreconditioner.Factory();
            var repackagedKrr  = new Dictionary <int, IMatrixView>();

            foreach (var idMatrixPair in Krr)
            {
                repackagedKrr[idMatrixPair.Key] = idMatrixPair.Value;
            }
            var stiffnessDistribution = new HomogeneousStiffnessDistribution(model, dofSeparator);

            stiffnessDistribution.Update(null);
            IFetiPreconditioner preconditioner = precondFactory.CreatePreconditioner(model,
                                                                                     stiffnessDistribution, dofSeparator, lagrangeEnumerator, matrixManagersPreconditioning);

            // Solve the interface problem
            FetiDPInterfaceProblemSolver interfaceSolver = new FetiDPInterfaceProblemSolver.Builder().Build();
            var flexibility = new FetiDPFlexibilityMatrix(dofSeparator, lagrangeEnumerator, matrixManagers);
            var logger      = new SolverLogger("mock FETI-DP");

            (Vector lagranges, Vector uc) = interfaceSolver.SolveInterfaceProblem(
                flexibility, preconditioner, coarseSolver, globalFcStar, dr, GlobalForcesNorm, logger);

            // Check against expected solution
            double tol = 1E-7;

            Assert.True(SolutionLagrangeMultipliers.Equals(lagranges, tol));
            Assert.True(SolutionCornerDisplacements.Equals(uc, tol));
        }
Beispiel #2
0
        public static void TestScalingMatrices()
        {
            #region Replace the next with hardcoded matrices and mocking objects
            // Run the analysis so that all objects are created
            // Setup the model
            double stiffnessRatio = 1E-2; // Do not change this! The expected solution is taken for this value
            Model  model          = CreateModel(stiffnessRatio);
            Dictionary <int, HashSet <INode> > cornerNodes = Quads4x4MappingMatricesTests.DefineCornerNodes(model);

            // Setup solver
            var interfaceSolverBuilder = new FetiDPInterfaceProblemSolver.Builder();
            interfaceSolverBuilder.PcgConvergenceTolerance = 1E-7;
            var fetiMatrices        = new DenseFetiDPSubdomainMatrixManager.Factory();
            var cornerNodeSelection = new UsedDefinedCornerNodes(cornerNodes);
            var fetiSolverBuilder   = new FetiDPSolver.Builder(cornerNodeSelection, fetiMatrices);
            fetiSolverBuilder.InterfaceProblemSolver = interfaceSolverBuilder.Build();
            fetiSolverBuilder.ProblemIsHomogeneous   = false;
            var preconditionerFactory = new DirichletPreconditioner.Factory();
            fetiSolverBuilder.PreconditionerFactory = preconditionerFactory;
            FetiDPSolver fetiSolver = fetiSolverBuilder.BuildSolver(model);

            // Run the analysis
            var problem        = new ProblemStructural(model, fetiSolver);
            var linearAnalyzer = new LinearAnalyzer(model, fetiSolver, problem);
            var staticAnalyzer = new StaticAnalyzer(model, fetiSolver, problem, linearAnalyzer);
            staticAnalyzer.Initialize();
            staticAnalyzer.Solve();
            #endregion

            // Access private fields of FetiDPSolver and DirichletPreconditioner.Factory using reflection
            FieldInfo fi = typeof(FetiDPSolver).GetField("lagrangeEnumerator", BindingFlags.NonPublic | BindingFlags.Instance);
            var       lagrangeEnumerator = (FetiDPLagrangeMultipliersEnumerator)fi.GetValue(fetiSolver);
            fi = typeof(FetiDPSolver).GetField("dofSeparator", BindingFlags.NonPublic | BindingFlags.Instance);
            var dofSeparator = (FetiDPDofSeparator)fi.GetValue(fetiSolver);
            fi = typeof(FetiDPSolver).GetField("stiffnessDistribution", BindingFlags.NonPublic | BindingFlags.Instance);
            var        stiffnessDistribution = (IStiffnessDistribution)fi.GetValue(fetiSolver);
            MethodInfo method = preconditionerFactory.GetType().GetMethod("CalcBoundaryPreconditioningBooleanMatrices",
                                                                          BindingFlags.NonPublic | BindingFlags.Instance);
            var Bpbr = (Dictionary <int, IMappingMatrix>)method.Invoke(preconditionerFactory,
                                                                       new object[] { stiffnessDistribution, dofSeparator, lagrangeEnumerator });

            // Compare the mapping matrices against the expected ones
            var expectedBpbr = new Dictionary <int, Matrix>();
            expectedBpbr[0] = Matrix.CreateFromArray(new double[, ]
            {
                { 0.5, 0, 0, 0 },
                { 0, 0.5, 0, 0 },
                { 0, 0, 0.5, 0 },
                { 0, 0, 0, 0.5 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 }
            });
            expectedBpbr[1] = Matrix.CreateFromArray(new double[, ]
            {
                { -0.5, 0, 0, 0 },
                { 0, -0.5, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0.00990099009900990, 0 },
                { 0, 0, 0, 0.00990099009900990 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 }
            });
            expectedBpbr[2] = Matrix.CreateFromArray(new double[, ]
            {
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { -0.5, 0, 0, 0 },
                { 0, -0.5, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0.00990099009900990, 0 },
                { 0, 0, 0, 0.00990099009900990 }
            });
            expectedBpbr[3] = Matrix.CreateFromArray(new double[, ]
            {
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { -0.990099009900990, 0, 0, 0 },
                { 0, -0.990099009900990, 0, 0 },
                { 0, 0, -0.990099009900990, 0 },
                { 0, 0, 0, -0.990099009900990 }
            });

            double tol = 1E-13;
            foreach (int s in expectedBpbr.Keys)
            {
                Matrix explicitBpr = Bpbr[s].MultiplyRight(Matrix.CreateIdentity(Bpbr[s].NumColumns));
                Assert.True(expectedBpbr[s].Equals(explicitBpr, tol));
            }
        }