Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparse_t), | intent(in) | :: | A | |||
real(kind=wp), | intent(in), | dimension(:) | :: | b | ||
real(kind=wp), | intent(in) | :: | w | |||
real(kind=wp), | intent(in), | optional | dimension(:) | :: | x0 | |
real(kind=wp), | intent(in), | optional | :: | tol | ||
integer, | intent(in), | optional | :: | maxIts |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function successiveOverRelaxation(A,b,w,x0,tol,maxIts) result(x)
class(sparse_t),intent(in)::A
real(wp),dimension(:),intent(in)::b
real(wp),intent(in)::w
real(wp),dimension(:),intent(in),optional::x0
real(wp),intent(in),optional::tol
integer,intent(in),optional::maxIts
real(wp),dimension(:),allocatable::x
real(wp),dimension(:),allocatable::D,r
integer::lmaxIts
real(wp)::ltol
real(wp)::rss0,rss
integer::i,k
lmaxIts = 1000000
ltol = 1.0E-6_wp
if(present(maxIts)) lmaxIts = maxIts
if(present(tol )) ltol = tol
D = A%getDiagonal()
x = b/D
if(present(x0)) x = x0
r = b-matmul(A,x)
rss0 = sqrt(sum(r**2))
call startReport('SOR Solver')
do k=1,lmaxIts
do i=1,A%N
r(i) = b(i)-(A%rows(i).o.x)
x(i) = x(i)+w*r(i)/D(i)
end do
rss = sqrt(sum(r**2))
call solverProgress(k,rss/rss0,ltol,'SOR Solver')
if(rss/rss0<ltol) exit
end do
end function successiveOverRelaxation