Skip to content

Commit

Permalink
Fix bugs.
Browse files Browse the repository at this point in the history
Update tests.
  • Loading branch information
gha3mi committed Jul 9, 2023
1 parent 30f563b commit ef873b4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 127 deletions.
2 changes: 1 addition & 1 deletion ford.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project: forsolver
version: v0.3.0
version: v0.3.1
year: 2023
project_github: https://github.com/gha3mi/forsolver
author: Seyed Ali Ghasemi
Expand Down
106 changes: 53 additions & 53 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "forsolver"
version = "0.3.0"
version = "0.3.1"
author = "Seyed Ali Ghasemi"
maintainer = "info@gha3mi.com"
copyright = "Copyright (c) 2023, Seyed Ali Ghasemi"
Expand All @@ -20,70 +20,70 @@ source-form = "free"
kinds = {git="https://github.com/gha3mi/kinds.git"}
fordiff = {git="https://github.com/gha3mi/fordiff.git"}

[[test]]
name = "test1"
source-dir = "test"
main = "test1.f90"
# [[test]]
# name = "test1"
# source-dir = "test"
# main = "test1.f90"

[[test]]
name = "test2"
source-dir = "test"
main = "test2.f90"
# [[test]]
# name = "test2"
# source-dir = "test"
# main = "test2.f90"

[[test]]
name = "test3"
source-dir = "test"
main = "test3.f90"
# [[test]]
# name = "test3"
# source-dir = "test"
# main = "test3.f90"

[[test]]
name = "test4"
source-dir = "test"
main = "test4.f90"
# [[test]]
# name = "test4"
# source-dir = "test"
# main = "test4.f90"

[[test]]
name = "test5"
source-dir = "test"
main = "test5.f90"
# [[test]]
# name = "test5"
# source-dir = "test"
# main = "test5.f90"

[[test]]
name = "test6"
source-dir = "test"
main = "test6.f90"
# [[test]]
# name = "test6"
# source-dir = "test"
# main = "test6.f90"

[[test]]
name = "test7"
source-dir = "test"
main = "test7.f90"
# [[test]]
# name = "test7"
# source-dir = "test"
# main = "test7.f90"

[[test]]
name = "test8"
source-dir = "test"
main = "test8.f90"
# [[test]]
# name = "test8"
# source-dir = "test"
# main = "test8.f90"

[[test]]
name = "test9"
source-dir = "test"
main = "test9.f90"
# [[test]]
# name = "test9"
# source-dir = "test"
# main = "test9.f90"

[[test]]
name = "test10"
source-dir = "test"
main = "test10.f90"
# [[test]]
# name = "test10"
# source-dir = "test"
# main = "test10.f90"

[[test]]
name = "test11"
source-dir = "test"
main = "test11.f90"
# [[test]]
# name = "test11"
# source-dir = "test"
# main = "test11.f90"

[[test]]
name = "test12"
source-dir = "test"
main = "test12.f90"
# [[test]]
# name = "test12"
# source-dir = "test"
# main = "test12.f90"

[[test]]
name = "test13"
source-dir = "test"
main = "test13.f90"
# [[test]]
# name = "test13"
# source-dir = "test"
# main = "test13.f90"

[[test]]
name = "test14"
Expand Down
36 changes: 18 additions & 18 deletions src/forsolver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ end function dFun
if (this%verbosity == 1) then
print '(a)', '-----------------------------------------------'
print '(a)', 'maxit x0 tol'
print '(i3, 10x, f12.8, 10x, e12.4)', this%maxit, x0, this%TolFun
print '(i5, 10x, f12.8, 10x, e12.4)', this%maxit, x0, this%TolFun
print '(a)', '-----------------------------------------------'
print '(a)', 'start newton'
print '(a)', '-----------------------------------------------'
Expand Down Expand Up @@ -261,8 +261,8 @@ impure function dFun(x)
end function dFun
end interface

procedure(Fun) :: F
procedure(dFun) :: dFdx
procedure(Fun) :: F
procedure(dFun), optional :: dFdx

class(nlsolver), intent(inout) :: this
real(rk), dimension(:), intent(in) :: x0
Expand All @@ -272,7 +272,7 @@ end function dFun
if (this%verbosity == 1) then
print '(a)', '-----------------------------------------------'
print '(a)', 'maxit tol'
print '(i3, 10x, e12.4)', this%maxit, this%TolFun
print '(i5, 10x, e12.4)', this%maxit, this%TolFun
print '(a)', '-----------------------------------------------'
print '(a)', 'start newton'
print '(a)', '-----------------------------------------------'
Expand Down Expand Up @@ -327,7 +327,7 @@ end function Fun
if (this%verbosity == 1) then
print '(a)', '-----------------------------------------------'
print '(a)', 'maxit x0 tol'
print '(i3, 10x, f12.8, 10x, e12.4)', this%maxit, real(x0, kind=rk), this%TolFun
print '(i5, 10x, f12.8, 10x, e12.4)', this%maxit, real(x0, kind=rk), this%TolFun
print '(a)', '-----------------------------------------------'
print '(a)', 'start newton'
print '(a)', '-----------------------------------------------'
Expand Down Expand Up @@ -373,7 +373,7 @@ end function Fun
if (this%verbosity == 1) then
print '(a)', '-----------------------------------------------'
print '(a)', 'maxit tol'
print '(i3, 10x, f12.8, e12.4)', this%maxit, this%TolFun
print '(i5, 10x, f12.8, e12.4)', this%maxit, this%TolFun
print '(a)', '-----------------------------------------------'
print '(a)', 'start newton'
print '(a)', '-----------------------------------------------'
Expand Down Expand Up @@ -537,7 +537,7 @@ end function dFun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -598,7 +598,7 @@ end function dFun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -654,7 +654,7 @@ end function Fun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -710,7 +710,7 @@ end function Fun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, xk, F_val, dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -771,7 +771,7 @@ end function dFun
criteriaFun = norm2(F_val)

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -832,7 +832,7 @@ end function dFun
criteriaFun = norm2(F_val)

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -886,7 +886,7 @@ end function Fun
criteriaFun = norm2(F_val)

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -941,7 +941,7 @@ end function Fun
criteriaFun = norm2(F_val)

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -996,7 +996,7 @@ end function Fun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, real(xk, kind=rk), real(F_val, kind=rk), dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, real(xk, kind=rk), real(F_val, kind=rk), dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -1050,7 +1050,7 @@ end function Fun
criteriaFun = abs(F_val)

if (this%verbosity == 1) then
print '(i3, f12.4, 4x, e12.4, 4x, e12.4)', k, real(xk, kind=rk), real(F_val, kind=rk), dFdx_val
print '(i5, f12.4, 4x, e12.4, 4x, e12.4)', k, real(xk, kind=rk), real(F_val, kind=rk), dFdx_val
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -1104,7 +1104,7 @@ end function Fun
criteriaFun = norm2(real(F_val, kind=rk))

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down Expand Up @@ -1158,7 +1158,7 @@ end function Fun
criteriaFun = norm2(real(F_val, kind=rk))

if (this%verbosity == 1) then
print '(i3, e12.4)', k, criteriaFun
print '(i5, e12.4)', k, criteriaFun
end if

if (criteriaFun <= this%TolFun) then
Expand Down
8 changes: 4 additions & 4 deletions test/test10.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ program test10
implicit none

type(nlsolver) :: nls
real(rk), dimension(3) :: x_sol
real(rk), dimension(2) :: x_sol

call nls%set_options(&
nl_method = 'newton-modified',&
nmp = 2,&
nmp = 1,&
maxit = 100,&
TolFun = 1e-12_rk,&
TolFun = 1e-15_rk,&
verbosity = 1)

call nls%solve(F=F3, dFdx=dF3dx, x0=[5.0_rk,3.0_rk,1.0_rk], x_sol=x_sol)
call nls%solve(F=F3, dFdx=dF3dx, x0=[-1.0_rk,-1.0_rk], x_sol=x_sol)

end program test10
10 changes: 5 additions & 5 deletions test/test11.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ program test11
implicit none

type(nlsolver) :: nls
real(rk), dimension(3) :: x_sol
real(rk), dimension(2) :: x_sol

call nls%set_options(&
nl_method = 'newton-quasi-fd',&
fdm_method = 'central',&
fdm_tol = 1e-8_rk,&
maxit = 100,&
TolFun = 1e-12_rk,&
fdm_tol = 1e-6_rk,&
maxit = 1000000,&
TolFun = 1e-13_rk,&
verbosity = 1)

call nls%solve(F=F3, dFdx=dF3dx, x0=[5.0_rk,3.0_rk,1.0_rk], x_sol=x_sol)
call nls%solve(F=F3, x0=[-1.0_rk,-1.0_rk], x_sol=x_sol)

end program test11
12 changes: 6 additions & 6 deletions test/test12.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ program test12
implicit none

type(nlsolver) :: nls
real(rk), dimension(3) :: x_sol
real(rk), dimension(2) :: x_sol

call nls%set_options(&
nl_method = 'newton-quasi-fd-modified',&
fdm_method = 'central',&
fdm_tol = 1e-8_rk,&
nmp = 2,&
maxit = 100,&
TolFun = 1e-12_rk,&
fdm_tol = 1e-6_rk,&
nmp = 1,&
maxit = 1000000,&
TolFun = 1e-13_rk,&
verbosity = 1)

call nls%solve(F=F3, dFdx=dF3dx, x0=[5.0_rk,3.0_rk,1.0_rk], x_sol=x_sol)
call nls%solve(F=F3, x0=[-1.0_rk,-1.0_rk], x_sol=x_sol)

end program test12
8 changes: 4 additions & 4 deletions test/test13.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ program test13
implicit none

type(nlsolver) :: nls
complex(rk), dimension(3) :: x_sol
complex(rk), dimension(2) :: x_sol

call nls%set_options(&
nl_method = 'newton-quasi-cs',&
cs_tol = 1e-200_rk,&
maxit = 100,&
TolFun = 1e-15_rk,&
maxit = 10800,&
TolFun = 1e-13_rk,&
verbosity = 1)

call nls%solve(F=F4, x0=[(5.0_rk,0.0_rk) ,(3.0_rk,0.0_rk), (1.0_rk,0.0_rk)], x_sol=x_sol)
call nls%solve(F=F4, x0=[(-1.0_rk,0.0_rk) ,(-1.0_rk,0.0_rk)], x_sol=x_sol)

end program test13
Loading

0 comments on commit ef873b4

Please sign in to comment.