Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions num/private/mod_root.f90
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ subroutine do_look_for_brackets(x, dx, x1, x3, f, y1, y3, imax, lrpar, rpar, lip

end do

! if we made it here, we failed. Reset ierr, since the function
! calls would have set it to 0 if they were successful
ierr = -1

!write(*,1) 'exit do_look_for_brackets'

end subroutine do_look_for_brackets
Expand Down
1 change: 1 addition & 0 deletions num/test/src/test_num.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ program test_num
call test_root_with_brackets
call test_root2
call test_root3
call test_root_no_brackets

! explicit solvers
call test_dopri(.false., show_all)
Expand Down
39 changes: 39 additions & 0 deletions num/test/src/test_support.f90
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,45 @@ subroutine test_root3
write (*, *)
end subroutine test_root3

subroutine test_root_no_brackets
! any imax that will fail here (just need to keep it below 31 so
! we don't overflow)
integer, parameter :: imax = 3, lipar = 0, lrpar = 0
real(dp) :: x1, x3, y1, y3
integer :: ierr
real(dp), target :: rpar_ary(lrpar)
integer, target :: ipar_ary(lipar)
real(dp), pointer :: rpar(:)
integer, pointer :: ipar(:)

ipar => ipar_ary
rpar => rpar_ary

! Function evaluations succeed, but x*x + 1 has no real root.
call look_for_brackets(0d0, 1d0, x1, x3, no_root_f, y1, y3, &
imax, lrpar, rpar, lipar, ipar, ierr)

write (*, '(a, i4, a, i4)') &
'look_for_brackets no root expected ierr', -1, ' got', ierr

contains

real(dp) function no_root_f(x, dfdx, lrpar, rpar, lipar, ipar, ierr)
real(dp), intent(in) :: x
real(dp), intent(out) :: dfdx
integer, intent(in) :: lrpar, lipar
real(dp), intent(inout), pointer :: rpar(:)
integer, intent(inout), pointer :: ipar(:)
integer, intent(out) :: ierr

! this has no real roots
no_root_f = x*x + 1d0
dfdx = 2d0*x
ierr = 0
end function no_root_f

end subroutine test_root_no_brackets

subroutine van_der_Pol_derivs(n, x, h, y, f, lrpar, rpar, lipar, ipar, ierr)
integer, intent(in) :: n, lrpar, lipar
real(dp), intent(in) :: x, h
Expand Down
1 change: 1 addition & 0 deletions num/test/test_output
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ g_05(x) = exp( x ) - 2x + 1/(100x) - 1/(1000000x^2)
first safe_root_with_guess 4.9999999999999362D-01
second safe_root_with_guess 5.0000000000003031D-01

look_for_brackets no root expected ierr -1 got -1

vdpol
dopri5
Expand Down
Loading