Skip to content

Commit

Permalink
Added simpler example, worked on readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
willdickson committed Dec 11, 2022
1 parent 321ae01 commit 9b15004
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions example/minres_ez_example_1.f90
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 9b15004

Please sign in to comment.