@@ -142,11 +142,11 @@ end
142142end
143143
144144function plot_simplification_effect ()
145- prob = prob_ode_lotkavolterra
145+ prob = ODEProblem (pcr3bp!, q0, tspan, p)
146146 t0 = prob. tspan[1 ]
147147 raw = Float64[]
148148 optimized = Float64[]
149- orders = [2 , 4 , 6 , 8 , 10 , 12 ]
149+ orders = [4 , 6 , 8 , 10 , 12 ]
150150 for P in orders
151151 raw_time = @belapsed jetcoeffs ($ prob. f, $ prob. u0, $ prob. p, $ t0, Val ($ P))
152152 fast_oop, fast_iip = build_jetcoeffs (prob. f, prob. p, Val (P), length (prob. u0))
@@ -160,8 +160,8 @@ function plot_simplification_effect()
160160 f = Figure (resolution = (700 , 400 ))
161161 ax = Axis (f[1 , 1 ],
162162 xlabel = " Order" ,
163- ylabel = " Time for computing truncated Taylor series (s)" ,
164- title = " Effect of Symbolic Simplification on Computing Truncated Taylor Series " ,
163+ ylabel = " Time for computing Taylor polynomial (s)" ,
164+ title = " Effect of Symbolic Simplification on Computing Taylor Polynomial " ,
165165 xticks = orders,
166166 yscale = log10
167167 )
@@ -172,8 +172,92 @@ function plot_simplification_effect()
172172 dodge = group,
173173 color = colors[group])
174174 elements = [PolyElement (polycolor = colors[i]) for i in 1 : 2 ]
175- Legend (f[1 , 2 ], elements, [" Raw " , " Optimized " ], " Groups" )
175+ Legend (f[1 , 2 ], elements, [" Naive " , " Simplified " ], " Groups" )
176176 f
177177 end
178178 save (" simplification_effect.png" , f)
179179end
180+
181+ plot_simplification_effect ()
182+
183+ @taylorize function pcr3bp! (dq, q, param, t)
184+ local μ = param[1 ]
185+ local onemμ = 1 - μ
186+ x1 = q[1 ]- μ
187+ x1sq = x1^ 2
188+ y = q[2 ]
189+ ysq = y^ 2
190+ r1_1p5 = (x1sq+ ysq)^ 1.5
191+ x2 = q[1 ]+ onemμ
192+ x2sq = x2^ 2
193+ r2_1p5 = (x2sq+ ysq)^ 1.5
194+ dq[1 ] = q[3 ] + q[2 ]
195+ dq[2 ] = q[4 ] - q[1 ]
196+ dq[3 ] = (- ((onemμ* x1)/ r1_1p5) - ((μ* x2)/ r2_1p5)) + q[4 ]
197+ dq[4 ] = (- ((onemμ* y )/ r1_1p5) - ((μ* y )/ r2_1p5)) - q[3 ]
198+ return nothing
199+ end
200+
201+ V (x, y) = - (1 - μ)/ sqrt ((x- μ)^ 2 + y^ 2 ) - μ/ sqrt ((x+ 1 - μ)^ 2 + y^ 2 )
202+ H (x, y, px, py) = (px^ 2 + py^ 2 )/ 2 - (x* py- y* px) + V (x, y)
203+ H (x) = H (x... )
204+ t0 = 0.0
205+ μ = 0.01
206+ J0 = - 1.58
207+ function py! (q0, J0)
208+ @assert iszero (q0[2 ]) && iszero (q0[3 ]) # q0[2] and q0[3] have to be equal to zero
209+ q0[4 ] = q0[1 ] + sqrt ( q0[1 ]^ 2 - 2 ( V (q0[1 ], q0[2 ])- J0 ) )
210+ nothing
211+ end
212+ q0 = [- 0.8 , 0.0 , 0.0 , 0.0 ]
213+ py! (q0, J0)
214+ q0
215+ tspan = (0.0 , 2000.0 )
216+ p = [μ]
217+ prob = ODEProblem (pcr3bp!, q0, tspan, p)
218+ raw = Float64[]
219+ optimized = Float64[]
220+ orders = [4 , 6 , 8 , 10 , 12 ]
221+ ti_raw = Float64[]
222+ ti_optimized = Float64[]
223+ for P in orders
224+ raw_time = @belapsed jetcoeffs ($ prob. f, $ prob. u0, $ prob. p, $ t0, Val ($ P))
225+ fast_oop, fast_iip = build_jetcoeffs (prob. f, prob. p, Val (P), length (prob. u0))
226+ optimized_time = @belapsed $ fast_oop ($ prob. u0, $ t0)
227+ push! (raw, raw_time)
228+ push! (optimized, optimized_time)
229+ # TI
230+ tt = Taylor1 (0.0 , P)
231+ q = [Taylor1 (x, P) for x in q0]
232+ dq = [Taylor1 (0.0 , P) for x in q0]
233+ qaux = [Taylor1 (0.0 , P) for x in q0]
234+ a = TaylorIntegration. _allocate_jetcoeffs! (Val (pcr3bp!), tt, q, dq, p)
235+ ti_time = @belapsed TaylorIntegration. jetcoeffs! ($ pcr3bp!, $ tt, $ q, $ dq, $ qaux, $ p)
236+ ti_optimized_time = @belapsed TaylorIntegration. jetcoeffs! (Val (pcr3bp!), $ tt, $ q, $ dq, $ p, $ a)
237+ push! (ti_raw, ti_time)
238+ push! (ti_optimized, ti_optimized_time)
239+ end
240+
241+ colors = Makie. wong_colors ()
242+ f = begin
243+ f = Figure (resolution = (700 , 400 ))
244+ ax = Axis (f[1 , 1 ],
245+ xlabel = " Order" ,
246+ ylabel = " Time for computing Taylor polynomial (s)" ,
247+ title = " Effect of Symbolic Simplification on Computing Taylor Polynomial" ,
248+ xticks = orders,
249+ yscale = log10
250+ )
251+
252+ group = [fill (1 , length (orders));
253+ fill (2 , length (orders));
254+ fill (3 , length (orders));
255+ fill (4 , length (orders))]
256+ barplot! (ax, [orders; orders; orders; orders], [raw; optimized; ti_raw; ti_optimized],
257+ dodge = group,
258+ color = colors[group])
259+ elements = [PolyElement (polycolor = colors[i]) for i in 1 : 4 ]
260+ Legend (f[1 , 2 ], elements, [" Naive" , " Simplified" , " TI Naive" , " TI Simplified" ], " Groups" )
261+ f
262+ end
263+ save (" simplification_with_ti.png" , f)
0 commit comments