1
+ @testitem " Default Algorithm for AbstractSteadyStateProblem" tags= [:core ] begin
2
+ using SciMLBase, StaticArrays
3
+
4
+ # Test with in-place function
5
+ function f_iip (du, u, p, t)
6
+ du[1 ] = 2 - 2 u[1 ]
7
+ du[2 ] = u[1 ] - 4 u[2 ]
8
+ end
9
+
10
+ u0 = zeros (2 )
11
+ prob_iip = SteadyStateProblem (f_iip, u0)
12
+
13
+ @testset " In-place SteadyStateProblem" begin
14
+ # Test with default algorithm (nothing)
15
+ sol = solve (prob_iip)
16
+ @test SciMLBase. successful_retcode (sol. retcode)
17
+ @test maximum (abs, sol. resid) < 1e-6
18
+
19
+ # Test with explicit nothing
20
+ sol = solve (prob_iip, nothing )
21
+ @test SciMLBase. successful_retcode (sol. retcode)
22
+ @test maximum (abs, sol. resid) < 1e-6
23
+
24
+ # Test init interface
25
+ cache = init (prob_iip)
26
+ sol = solve! (cache)
27
+ @test SciMLBase. successful_retcode (sol. retcode)
28
+ @test maximum (abs, sol. resid) < 1e-6
29
+
30
+ # Test init with nothing
31
+ cache = init (prob_iip, nothing )
32
+ sol = solve! (cache)
33
+ @test SciMLBase. successful_retcode (sol. retcode)
34
+ @test maximum (abs, sol. resid) < 1e-6
35
+ end
36
+
37
+ # Test with out-of-place function
38
+ f_oop (u, p, t) = [2 - 2 u[1 ], u[1 ] - 4 u[2 ]]
39
+ u0 = zeros (2 )
40
+ prob_oop = SteadyStateProblem (f_oop, u0)
41
+
42
+ @testset " Out-of-place SteadyStateProblem" begin
43
+ # Test with default algorithm (nothing)
44
+ sol = solve (prob_oop)
45
+ @test SciMLBase. successful_retcode (sol. retcode)
46
+ @test maximum (abs, sol. resid) < 1e-6
47
+
48
+ # Test with explicit nothing
49
+ sol = solve (prob_oop, nothing )
50
+ @test SciMLBase. successful_retcode (sol. retcode)
51
+ @test maximum (abs, sol. resid) < 1e-6
52
+
53
+ # Test init interface
54
+ cache = init (prob_oop)
55
+ sol = solve! (cache)
56
+ @test SciMLBase. successful_retcode (sol. retcode)
57
+ @test maximum (abs, sol. resid) < 1e-6
58
+
59
+ # Test init with nothing
60
+ cache = init (prob_oop, nothing )
61
+ sol = solve! (cache)
62
+ @test SciMLBase. successful_retcode (sol. retcode)
63
+ @test maximum (abs, sol. resid) < 1e-6
64
+ end
65
+
66
+ # Test that SteadyStateProblem conversion works
67
+ @testset " Problem conversion" begin
68
+ # Create equivalent NonlinearProblem
69
+ function f_nl (u, p)
70
+ [2 - 2 u[1 ], u[1 ] - 4 u[2 ]]
71
+ end
72
+
73
+ prob_nl = NonlinearProblem (f_nl, u0)
74
+
75
+ # Convert SteadyStateProblem to NonlinearProblem
76
+ prob_converted = NonlinearProblem (prob_oop)
77
+
78
+ # Both should solve to the same solution
79
+ sol_nl = solve (prob_nl)
80
+ sol_converted = solve (prob_converted)
81
+
82
+ @test sol_nl. u ≈ sol_converted. u atol= 1e-10
83
+ end
84
+
85
+ # Test with StaticArrays
86
+ @testset " StaticArrays support" begin
87
+ f_static (u, p, t) = @SVector [2 - 2 u[1 ], u[1 ] - 4 u[2 ]]
88
+ u0_static = @SVector [0.0 , 0.0 ]
89
+ prob_static = SteadyStateProblem (f_static, u0_static)
90
+
91
+ sol = solve (prob_static)
92
+ @test SciMLBase. successful_retcode (sol. retcode)
93
+ @test maximum (abs, sol. resid) < 1e-6
94
+ end
95
+
96
+ # Test that solve works with various problem types
97
+ @testset " Mixed problem types" begin
98
+ # Regular arrays
99
+ prob1 = SteadyStateProblem (f_oop, [0.5 , 0.5 ])
100
+ sol1 = solve (prob1)
101
+ @test SciMLBase. successful_retcode (sol1. retcode)
102
+
103
+ # With parameters
104
+ f_param (u, p, t) = [p[1 ] - 2 u[1 ], u[1 ] - 4 u[2 ]]
105
+ prob2 = SteadyStateProblem (f_param, [0.5 , 0.5 ], [2.0 ])
106
+ sol2 = solve (prob2)
107
+ @test SciMLBase. successful_retcode (sol2. retcode)
108
+ end
109
+ end
0 commit comments