This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a1a088
commit 2f49790
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using SciMLNLSolve, SciMLBase | ||
# Test the autodiff technique | ||
function f!(fvec, x, p) | ||
fvec[1] = (x[1]+3)*(x[2]^3-7)+18 | ||
fvec[2] = sin(x[2]*exp(x[1])-1) | ||
end | ||
|
||
prob = NonlinearProblem{true}(f!,[ 0.1; 1.2]) | ||
sol = solve(prob,NLSolveJL(autodiff=:forward)) | ||
|
||
du = zeros(2) | ||
f!(du, sol.u, nothing) | ||
@test maximum(du) < 1e-6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using SciMLNLSolve, SciMLBase | ||
# Test the finite differencing technique | ||
function f!(fvec, x, p) | ||
fvec[1] = (x[1]+3)*(x[2]^3-7)+18 | ||
fvec[2] = sin(x[2]*exp(x[1])-1) | ||
end | ||
|
||
prob = NonlinearProblem{true}(f!,[ 0.1; 1.2]) | ||
sol = solve(prob,NLSolveJL(autodiff=:central)) | ||
|
||
du = zeros(2) | ||
f!(du, sol.u, nothing) | ||
@test maximum(du) < 1e-6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using SciMLNLSolve, SciMLBase | ||
|
||
# IIP Tests | ||
function f_iip(du, u, p, t) | ||
du[1] = 2 - 2u[1] | ||
du[2] = u[1] - 4u[2] | ||
end | ||
u0 = zeros(2) | ||
prob_iip = SteadyStateProblem(f_iip, u0) | ||
abstol = 1e-8 | ||
|
||
for alg in [NLSolveJL()] | ||
sol = solve(prob_iip, alg) | ||
@test sol.retcode == :Success | ||
p = nothing | ||
|
||
du = zeros(2) | ||
f_iip(du, sol.u, nothing, 0) | ||
@test maximum(du) < 1e-6 | ||
end | ||
|
||
# OOP Tests | ||
f_oop(u, p, t) = [2 - 2u[1],u[1] - 4u[2]] | ||
u0 = zeros(2) | ||
prob_oop = SteadyStateProblem(f_oop, u0) | ||
|
||
for alg in [NLSolveJL()] | ||
sol = solve(prob_oop, alg) | ||
@test sol.retcode == :Success | ||
|
||
du = zeros(2) | ||
du = f_oop(sol.u, nothing, 0) | ||
@test maximum(du) < 1e-6 | ||
end | ||
|
||
# NonlinearProblem Tests | ||
|
||
function f_iip(du, u, p) | ||
du[1] = 2 - 2u[1] | ||
du[2] = u[1] - 4u[2] | ||
end | ||
u0 = zeros(2) | ||
prob_iip = NonlinearProblem{true}(f_iip, u0) | ||
abstol = 1e-8 | ||
for alg in [NLSolveJL()] | ||
local sol | ||
sol = solve(prob_iip, alg) | ||
@test sol.retcode == :Success | ||
p = nothing | ||
|
||
du = zeros(2) | ||
f_iip(du, sol.u, nothing) | ||
@test maximum(du) < 1e-6 | ||
end | ||
|
||
# OOP Tests | ||
f_oop(u, p) = [2 - 2u[1],u[1] - 4u[2]] | ||
u0 = zeros(2) | ||
prob_oop = NonlinearProblem{false}(f_oop, u0) | ||
for alg in [NLSolveJL(),] | ||
local sol | ||
sol = solve(prob_oop, alg) | ||
@test sol.retcode == :Success | ||
|
||
du = zeros(2) | ||
du = f_oop(sol.u, nothing) | ||
@test maximum(du) < 1e-6 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters