Пример #1
0
        public static void SuiteSparseMemoryConsumptionDebugging()
        {
            for (int rep = 0; rep < 10; ++rep)
            {
                var benchmarkBuilder = new CantileverBeam.Builder();
                //benchmarkBuilder.Length = 5.0;
                CantileverBeam benchmark = benchmarkBuilder.BuildWithQuad4Elements(2000, 100);

                // Solver
                var solverBuilder = new SuiteSparseSolver.Builder();
                using (SuiteSparseSolver solver = solverBuilder.BuildSolver(benchmark.Model))
                {
                    // Structural problem provider
                    var provider = new ProblemStructural(benchmark.Model, solver);

                    // Linear static analysis
                    var childAnalyzer  = new LinearAnalyzer(benchmark.Model, solver, provider);
                    var parentAnalyzer = new StaticAnalyzer(benchmark.Model, solver, provider, childAnalyzer);

                    // Run the analysis
                    parentAnalyzer.Initialize();
                    parentAnalyzer.Solve();
                }
            }
        }
        internal static void TestSkylineSolver()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new SkylineSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()); // default
            ISolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
        internal static void TestSkylineSolverWithAmdReordering()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new SkylineSolver.Builder();

            solverBuilder.DofOrderer = new DofOrderer(
                new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd());
            ISolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
        internal static void TestPcgJacobiSolver()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            //LibrarySettings.LinearAlgebraProviders = LinearAlgebraProviderChoice.MKL;
            var solverBuilder = new PcgSolver.Builder();
            //var pcgBuilder = new PcgAlgorithm.Builder();
            //solverBuilder.PcgAlgorithm = pcgBuilder.Build(); // default
            //solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()); // default
            PcgSolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
        internal static void TestSuiteSparseSolver()
        {
            Skip.IfNot(TestSettings.TestSuiteSparse, TestSettings.MessageWhenSkippingSuiteSparse);

            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new SuiteSparseSolver.Builder();

            solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering());
            using (SuiteSparseSolver solver = solverBuilder.BuildSolver(benchmark.Model))
            {
                RunAnalysisAndCheck(benchmark, solver);
            }
        }
        internal static void TestPcgJacobiSolverWithAmdReordering()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new PcgSolver.Builder();

            //var pcgBuilder = new PcgAlgorithm.Builder();
            //solverBuilder.PcgAlgorithm = pcgBuilder.Build();
            solverBuilder.DofOrderer = new DofOrderer(
                new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd());
            PcgSolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
        private static Model CreateModel()
        {
            int numElementsX = 2, numElementsY = 4; // for the hardcoded stiffness matrices

            var cantileverBuilder = new CantileverBeam.Builder();

            cantileverBuilder.Length       = numElementsX;
            cantileverBuilder.Height       = numElementsY;
            cantileverBuilder.Width        = 1.0;
            cantileverBuilder.YoungModulus = 1.0;
            cantileverBuilder.PoissonRatio = 0.3;
            CantileverBeam cantilever = cantileverBuilder.BuildWithQuad4Elements(numElementsX, numElementsY);

            return(cantilever.Model);
        }
        internal static void TestDenseSolver()
        {
            Skip.IfNot(TestSettings.TestMkl, TestSettings.MessageWhenSkippingMKL);

            // Dense solver is too slow for a ~17.000 dof linear system, without MKL
            TestSettings.RunMultiproviderTest(LinearAlgebraProviderChoice.MKL, delegate()
            {
                CantileverBeam benchmark = BuildCantileverBenchmark();

                var solverBuilder        = new DenseMatrixSolver.Builder();
                DenseMatrixSolver solver = solverBuilder.BuildSolver(benchmark.Model);
                //solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()); // default

                RunAnalysisAndCheck(benchmark, solver);
            });
        }
        private static void RunAnalysisAndCheck(CantileverBeam benchmark, ISolver solver)
        {
            // Structural problem provider
            var provider = new ProblemStructural(benchmark.Model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(benchmark.Model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(benchmark.Model, solver, provider, childAnalyzer);

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            // Check output
            double endDeflectionExpected = benchmark.CalculateEndDeflectionWithEulerBeamTheory();
            double endDeflectionComputed =
                benchmark.CalculateAverageEndDeflectionFromSolution(solver.LinearSystems.First().Value.Solution);
            var comparer = new ValueComparer(1E-2);

            Assert.True(comparer.AreEqual(endDeflectionExpected, endDeflectionComputed));
        }