Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Improved error handling in linear solver
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed May 14, 2021
1 parent cb64464 commit 4041b4d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util/util_solve_linear_system.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function util_solve_linear_system(A,b,n,lerr) result(x)
real(QP), dimension(:), allocatable :: qx

qx = solve_wbs(ge_wpp(real(A, kind=QP), real(b, kind=QP)),lerr)
where(abs(qx(:)) < tiny(1._DP)) qx(:) = 0._QP
x = real(qx, kind=DP)
return

Expand All @@ -37,11 +38,15 @@ function solve_wbs(u, lerr) result(x) ! solve with backward substitution
integer(I4B) :: i,n
real(DP), parameter :: epsilon = 10 * tiny(1._DP)

if (allocated(x)) deallocate(x)
allocate(x(n))

lerr = any(abs(u(:,:)) < epsilon)
if (lerr) return
if (lerr) then
x(:) = 0._DP
return
end if

n = size(u,1)
allocate(x(n))
do i = n,1,-1
x(i) = (u(i, n + 1) - sum(u(i, i + 1:n) * x(i + 1:n))) / u(i, i)
end do
Expand Down

0 comments on commit 4041b4d

Please sign in to comment.