25
25
nl_prob = NonlinearProblem (steady_state_network_1, u0, p)
26
26
27
27
# Solves it using standard algorithm and simulation based algorithm.
28
- sol1 = solve (nl_prob; abstol= 1e-15 , reltol= 1e-15 ). u
29
- sol2 = solve (nl_prob, DynamicSS (Tsit5 (); abstol= 1e-15 , reltol= 1e-15 ); abstol= 1e-15 , reltol= 1e-15 ). u
28
+ sol1 = solve (nl_prob; abstol= 1e-12 , reltol= 1e-12 ). u
29
+ sol2 = solve (nl_prob, DynamicSS (Rosenbrock23 (); abstol= 1e-12 , reltol= 1e-12 ); abstol= 1e-12 , reltol= 1e-12 ). u
30
30
31
31
# Tests solutions are correct.
32
- @test abs . (sol1[1 ] - p[1 ] / p[2 ]) < 1e-8
33
- @test abs . (sol1[2 ]^ 3 / factorial (3 ) - p[3 ] / p[4 ]) < 1e-8
34
- @test abs . (sol1[3 ] * sol1[4 ] - p[5 ] / p[6 ]) < 1e-8
35
- @test sol1 ≈ sol2
32
+ @test isapprox (sol1[1 ], p[1 ] / p[2 ]; atol = 1e-10 )
33
+ @test isapprox (sol1[2 ]^ 3 / factorial (3 ), p[3 ] / p[4 ]; atol = 1e-10 )
34
+ @test isapprox (sol1[3 ] * sol1[4 ], p[5 ] / p[6 ]; atol = 1e-10 )
35
+ @test isapprox ( sol1, sol2; atol = 1e-10 )
36
36
end
37
37
38
38
# Creates a system with multiple steady states.
52
52
nl_prob = NonlinearProblem (steady_state_network_2, u0, p)
53
53
54
54
# Solves it using standard algorithm and simulation based algorithm.
55
- sol1 = solve (nl_prob; abstol= 1e-18 , reltol= 1e-18 ). u
56
- sol2 = solve (nl_prob, DynamicSS (Tsit5 (); abstol= 1e-18 , reltol= 1e-18 ); abstol= 1e-18 , reltol= 1e-18 ). u
55
+ sol1 = solve (nl_prob; abstol= 1e-12 , reltol= 1e-12 ). u
56
+ sol2 = solve (nl_prob, DynamicSS (Rosenbrock23 (); abstol= 1e-12 , reltol= 1e-12 ); abstol= 1e-12 , reltol= 1e-12 ). u
57
57
58
58
# Computes NonlinearFunction (manually and automatically).
59
59
nfunc = NonlinearFunction (convert (NonlinearSystem, steady_state_network_2))
64
64
end
65
65
66
66
# Tests solutions are correct.
67
- @test nfunc (sol1, last .(p))[1 ] ≈ 0.0
68
- @test nfunc (sol2, last .(p))[1 ] ≈ 0.0
69
- @test nf_manual (sol1, last .(p)) ≈ 0.0
70
- @test nf_manual (sol2, last .(p)) ≈ 0.0
67
+ @test isapprox ( nfunc (sol1, last .(p))[1 ], 0.0 ; atol = 1e-10 )
68
+ @test isapprox ( nfunc (sol2, last .(p))[1 ], 0.0 ; atol = 1e-10 )
69
+ @test isapprox ( nf_manual (sol1, last .(p)), 0.0 ; atol = 1e-10 )
70
+ @test isapprox ( nf_manual (sol2, last .(p)), 0.0 ; atol = 1e-10 )
71
71
end
72
72
73
73
# Checks for system with conservation laws.
88
88
nl_prob_2 = NonlinearProblem (steady_state_network_3, u0, p)
89
89
90
90
# Solves it using standard algorithm and simulation based algorithm.
91
- sol1 = solve (nl_prob_1; abstol= 1e-18 , reltol= 1e-18 )
92
- sol2 = solve (nl_prob_2, DynamicSS (Tsit5 (); abstol= 1e-18 , reltol= 1e-18 ); abstol= 1e-18 , reltol= 1e-18 )
91
+ sol1 = solve (nl_prob_1; abstol= 1e-12 , reltol= 1e-12 )
92
+ sol2 = solve (nl_prob_2, DynamicSS (Rosenbrock23 (); abstol= 1e-12 , reltol= 1e-12 ); abstol= 1e-12 , reltol= 1e-12 )
93
93
94
94
# Checks output using NonlinearFunction.
95
95
nfunc = NonlinearFunction (convert (NonlinearSystem, steady_state_network_3))
96
- @test all (nfunc ([sol1[X], sol1[Y], sol1[Y2], sol1[XY2]], last .(p)) .≈ 0.0 )
97
- @test all (nfunc ([sol2[X], sol2[Y], sol2[Y2], sol2[XY2]], last .(p)) .≈ 0.0 )
96
+ @test isapprox (nfunc ([sol1[X], sol1[Y], sol1[Y2], sol1[XY2]], last .(p)), [ 0.0 , 0.0 , 0.0 , 0.0 ]; atol = 1e-10 )
97
+ @test isapprox (nfunc ([sol2[X], sol2[Y], sol2[Y2], sol2[XY2]], last .(p)), [ 0.0 , 0.0 , 0.0 , 0.0 ]; atol = 1e-10 )
98
98
end
0 commit comments