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