Example #1
0
        public void Should_solve(Matrix <double> a, Vector <double> b)
        {
            var result = GmresSolver.Solve(a, b, MaxInnerIterations, MaxOuterIterations, Epsilon);

            result.IsConverged.Should().BeTrue();
            CheckSolution(a, b, result.X);
        }
Example #2
0
        public void Should_throw_argument_exception_when_matrix_is_not_square(int rowCount, int columnCount)
        {
            var a = new SparseMatrix(rowCount, columnCount);
            var b = new DenseVector(rowCount);

            Assert.Throws <ArgumentException>(() => GmresSolver.Solve(a, b));
        }
Example #3
0
        public void Should_solve_tridiagonal_matrix_system()
        {
            var a = MatrixMarketReader.ReadMatrix <double>("matrix1.mtx");
            var b = MatrixMarketReader.ReadVector <double>("vector1.mtx");

            var result = GmresSolver.Solve(a, b, 15, 1);

            result.IsConverged.Should().BeTrue();
            result.OuterIterations.Should().Be(0);
            result.InnerIterations.Should().Be(11);
            foreach (var xValue in result.X)
            {
                xValue.Should().BeApproximately(1.0, GmresSolver.DefaultEpsilon);
            }
        }
Example #4
0
        public void Should_solve_dense_matrix_system()
        {
            var a = MatrixMarketReader.ReadMatrix <double>("matrix2.mtx");
            var b = MatrixMarketReader.ReadVector <double>("vector2.mtx");

            var result = GmresSolver.Solve(a, b);

            result.IsConverged.Should().BeTrue();
            result.OuterIterations.Should().Be(0);
            result.InnerIterations.Should().Be(6);

            var expectedX = new[] { -4.0306249, 3.3608880, 3.8133424, -1.0654047, 3.4175426, -2.0298796 };

            for (var i = 0; i < expectedX.Length; i++)
            {
                result.X[i].Should().BeApproximately(expectedX[i], GmresSolver.DefaultEpsilon);
            }
        }
Example #5
0
        private void TestCollocationPointCreation()
        {
            var                model        = new CollocationModel();
            ModelCreator       modelCreator = new ModelCreator(model);
            string             filename     = "..\\..\\..\\InputFiles\\PlateWithHole.txt";
            IsogeometricReader modelReader  = new IsogeometricReader(modelCreator, filename);

            modelReader.CreateCollocationModelFromFile();

            //var solverBuilder = new SuiteSparseSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(
            //    new NodeMajorDofOrderingStrategy(), new NullReordering());
            var     solverBuilder = new GmresSolver.Builder();
            ISolver solver        = new GmresSolver(model,
                                                    new AsymmetricDofOrderer(new RowDofOrderingStrategy()),
                                                    new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()));

            // Structural problem provider
            var provider = new ProblemStructural(model, solver);

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

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

            var k = solver.LinearSystems[0].Matrix;

            Matrix <double> kmatlab = MathNet.Numerics.LinearAlgebra.CreateMatrix.Dense <double>(k.NumRows, k.NumColumns);

            for (int i = 0; i < k.NumRows; i++)
            {
                for (int j = 0; j < k.NumColumns; j++)
                {
                    kmatlab[i, j] = k[i, j];
                }
            }
            MatlabWriter.Write("..\\..\\..\\InputFiles\\KcolMsolve.mat", kmatlab, "Ktotal");
        }
Example #6
0
        public static void Execute(Options options)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Console.WriteLine($"Reading from {options.InputMatrixFileName}...");
            var a = MatrixMarketReader.ReadMatrix <double>(options.InputMatrixFileName);

            Console.WriteLine($"Reading from {options.InputVectorFileName}...");
            var b = MatrixMarketReader.ReadVector <double>(options.InputVectorFileName);

            Console.WriteLine("Start solving...");
            var result = GmresSolver.Solve(a, b, options.MaxInnerIterations, options.MaxOuterIterations, options.Epsilon, degreeOfParallelism: options.DegreeOfParallelism);

            Console.WriteLine($"Finished. IsConverged = {result.IsConverged}. Last error: {result.Errors.Last()}");
            Console.WriteLine($"Performed {result.InnerIterations} inner iterations and {result.OuterIterations} outer iterations");

            Console.WriteLine($"Writing solution to {options.OutputFileName}...");
            MatrixMarketWriter.WriteVector(options.OutputFileName, result.X);

            Console.WriteLine($"Total execution time, ms: {stopwatch.Elapsed.TotalMilliseconds}");
        }