22abstract type DiffSolver end
33
44" Empty solver for nonlinear discrete-time models."
5- struct EmptySolver <: DiffSolver end
6- get_solver_functions (:: DataType , :: EmptySolver , f!, h!, _ ... ) = f!, h!
5+ struct EmptySolver <: DiffSolver
6+ ns:: Int
7+ EmptySolver () = new (0 )
8+ end
9+
10+ function get_solver_functions (NT:: DataType , :: EmptySolver , f!, h!, _ ... )
11+ f_solver! (xnext, _ , x, u, d, p) = f! (xnext, x, u, d, p)
12+ return f!, h!
13+ end
714
815function Base. show (io:: IO , solver:: EmptySolver )
916 print (io, " Empty differential equation solver." )
1017end
1118
1219struct RungeKutta <: DiffSolver
20+ ns:: Int
1321 order:: Int
1422 supersample:: Int
1523 function RungeKutta (order:: Int , supersample:: Int )
@@ -22,7 +30,8 @@ struct RungeKutta <: DiffSolver
2230 if supersample < 1
2331 throw (ArgumentError (" supersample must be greater than 0" ))
2432 end
25- return new (order, supersample)
33+ ns = order # only true for order ≤ 4
34+ return new (ns, order, supersample)
2635 end
2736end
2837
5463" Get the f! function for the 4th order explicit Runge-Kutta solver."
5564function get_rk4_function (NT, solver, fc!, Ts, nx, Nc)
5665 Ts_inner = Ts/ solver. supersample
57- xcur_cache :: DiffCache{Vector{NT}, Vector{NT}} = DiffCache ( zeros (NT, nx), Nc )
58- k1_cache :: DiffCache{Vector{NT}, Vector{NT}} = DiffCache ( zeros (NT, nx), Nc )
59- k2_cache :: DiffCache{Vector{NT}, Vector{NT}} = DiffCache ( zeros (NT, nx), Nc )
60- k3_cache :: DiffCache{Vector{NT}, Vector{NT}} = DiffCache ( zeros (NT, nx), Nc )
61- k4_cache :: DiffCache{Vector{NT}, Vector{NT}} = DiffCache ( zeros (NT, nx), Nc )
66+ xcur = zeros (NT, nx)
67+ k1 = zeros (NT, nx)
68+ k2 = zeros (NT, nx)
69+ k3 = zeros (NT, nx)
70+ k4 = zeros (NT, nx)
6271 f! = function rk4_solver! (xnext, x, u, d, p)
6372 CT = promote_type (eltype (x), eltype (u), eltype (d))
64- xcur = get_tmp (xcur_cache, CT)
73+ #= xcur = get_tmp(xcur_cache, CT)
6574 k1 = get_tmp(k1_cache, CT)
6675 k2 = get_tmp(k2_cache, CT)
6776 k3 = get_tmp(k3_cache, CT)
68- k4 = get_tmp (k4_cache, CT)
77+ k4 = get_tmp(k4_cache, CT)=#
6978 xterm = xnext
7079 @. xcur = x
7180 for i= 1 : solver. supersample
0 commit comments