diff --git a/README.md b/README.md index cc4fa78..ca18005 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,60 @@ I've added two things: ### Usage There are two different ways to use this library. The first is via the -minre\_ez\_t class which provides a simplified interface to the method and the +minres\_ez\_t class which provides a simplified interface to the method and the second is via the minres_solver function which give you more control, but requires a bit more work on the part of the user. +#### minres_ez_t + +To use the `minres_ez_t` class, you have to provide the matrix `A` in sparse +form, using three arrays: the row indices, column indices, and the nonzero +elements. Here is an example: + + +```fortran +program minres_ez_example_1 + ! + ! Example program demonstrating the use of minres_ez_t to solve + ! linear systems of the form Ax = b and (A - shift*I)x = b where + ! A is symmetric. + ! + use, intrinsic :: iso_fortran_env, only : dp=>real64 + use minres, only : minres_ez_t + use minres, only : minres_info_t + implicit none + + integer, parameter :: n = 3 ! size of matrix A (symmetric) + integer, parameter :: nnz = 7 ! number of nonzero elem. in A + integer, parameter :: irow(nnz) = [1, 2, 3, 2, 3, 1, 2] ! row indices nonzero elem. of A + integer, parameter :: icol(nnz) = [1, 2, 3, 1, 2, 2, 3] ! col indices nonzero elem. of A + real(dp), parameter :: a(nnz) = real([3, 2, 1, 4, 2, 4, 2], dp) ! nonzero elem. of A + real(dp), parameter :: b(n) = real([1, 1, 1], dp) ! the rhs vector b + + type(minres_ez_t) :: minres_ez ! the main ez solver class + type(minres_info_t) :: minres_info ! information on solution + real(dp) :: x(n) ! the solution vector x + + ! Set some options + minres_ez % rtol = 1.0e-13 + minres_ez % checka = .true. + + ! display settings + call minres_ez % print() + + ! Solve linear system + call minres_ez % solve(irow, icol, a, b, x, minres_info) + + ! Print info on result + call minres_info % print() + +end program minres_ez_example_1 + +``` + + + + ### Compiling A [Fortran Package Manager](https://github.com/fortran-lang/fpm) manifest file is included, so that the library and test cases can be compiled with FPM. For example: diff --git a/example/minres_ez_example_1.f90 b/example/minres_ez_example_1.f90 new file mode 100644 index 0000000..f112e55 --- /dev/null +++ b/example/minres_ez_example_1.f90 @@ -0,0 +1,36 @@ +program minres_ez_example_1 + ! + ! Example program demonstrating the use of minres_ez_t to solve + ! linear systems of the form Ax = b and (A - shift*I)x = b where + ! A is symmetric. + ! + use, intrinsic :: iso_fortran_env, only : dp=>real64 + use minres, only : minres_ez_t + use minres, only : minres_info_t + implicit none + + integer, parameter :: n = 3 ! size of matrix A (symmetric) + integer, parameter :: nnz = 7 ! number of nonzero elem. in A + integer, parameter :: irow(nnz) = [1, 2, 3, 2, 3, 1, 2] ! row indices nonzero elem. of A + integer, parameter :: icol(nnz) = [1, 2, 3, 1, 2, 2, 3] ! col indices nonzero elem. of A + real(dp), parameter :: a(nnz) = real([3, 2, 1, 4, 2, 4, 2], dp) ! nonzero elem. of A + real(dp), parameter :: b(n) = real([1, 1, 1], dp) ! the rhs vector b + + type(minres_ez_t) :: minres_ez ! the main ez solver class + type(minres_info_t) :: minres_info ! information on solution + real(dp) :: x(n) ! the solution vector x + + ! Set some options + minres_ez % rtol = 1.0e-13 + minres_ez % checka = .true. + + ! display settings + call minres_ez % print() + + ! Solve linear system + call minres_ez % solve(irow, icol, a, b, x, minres_info) + + ! Print info on result + call minres_info % print() + +end program minres_ez_example_1 diff --git a/example/minres_ez_example.f90 b/example/minres_ez_example_2.f90 similarity index 96% rename from example/minres_ez_example.f90 rename to example/minres_ez_example_2.f90 index e3be12e..8ff02e8 100644 --- a/example/minres_ez_example.f90 +++ b/example/minres_ez_example_2.f90 @@ -1,7 +1,8 @@ -program main +program minres_ez_example_2 ! ! Example program demonstrating the use of minres_ez_t to solve - ! linear systems of the form Ax = b and (A - shift*I)x = b + ! linear systems of the form Ax = b and (A - shift*I)x = b where + ! A is symmetric. ! use, intrinsic :: iso_fortran_env, only : dp=>real64 use minres, only : minres_ez_t @@ -126,4 +127,4 @@ subroutine sparse_mul(irow, icol, a, x, y) end subroutine sparse_mul -end program main +end program minres_ez_example_2