Skip to content

Commit b936c8b

Browse files
author
fchen121
committed
Create test case for FDE to ODE
1 parent 8d21234 commit b936c8b

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

src/ModelingToolkit.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbanc
298298
tunable_parameters, isirreducible, getdescription, hasdescription,
299299
hasunit, getunit, hasconnect, getconnect,
300300
hasmisc, getmisc, state_priority
301-
export liouville_transform, change_independent_variable, substitute_component,
302-
add_accumulations, noise_to_brownians, Girsanov_transform, change_of_variables
301+
export liouville_transform, change_independent_variable, substitute_component, add_accumulations,
302+
noise_to_brownians, Girsanov_transform, change_of_variables, fractional_to_ordinary
303303
export PDESystem
304304
export Differential, expand_derivatives, @derivatives
305305
export Equation, ConstrainedEquation

src/systems/diffeqs/basic_transformations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ function change_of_variables(
184184
return new_sys
185185
end
186186

187-
function FDE_to_ODE(eqs, variables, alphas, epsilon, T; initials=0)
187+
function fractional_to_ordinary(eqs, variables, alphas, epsilon, T; initials = 0)
188188
@independent_variables t
189189
D = Differential(t)
190190
i = 0
191191
all_eqs = Equation[]
192192
all_def = Pair{Num, Int64}[]
193193

194-
function FDE_helper(sub_eq, sub_var, α; initial=0)
194+
function fto_helper(sub_eq, sub_var, α; initial=0)
195195
alpha_0 = α
196196
if> 1)
197197
coeff = 1/- 1)
@@ -260,7 +260,7 @@ function FDE_to_ODE(eqs, variables, alphas, epsilon, T; initials=0)
260260
end
261261

262262
for (eq, cur_var, alpha, init) in zip(eqs, variables, alphas, initials)
263-
(new_eqs, def) = FDE_helper(eq, cur_var, alpha; initial=init)
263+
(new_eqs, def) = fto_helper(eq, cur_var, alpha; initial=init)
264264
append!(all_eqs, new_eqs)
265265
append!(all_def, def)
266266
end

test/fractional_to_ordinary.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using ModelingToolkit, OrdinaryDiffEq, ODEInterfaceDiffEq, SpecialFunctions
2+
using Test
3+
4+
# Testing for α < 1
5+
# Uses example 1 from Section 7 of https://arxiv.org/pdf/2506.04188
6+
@independent_variables t
7+
@variables x(t)
8+
D = Differential(t)
9+
tspan = (0., 1.)
10+
11+
function expect(t, α)
12+
return (3/2*t^/2) - t^4)^2
13+
end
14+
15+
α = 0.5
16+
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2))
17+
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^/2)-t^4)^3 - x^(3/2)
18+
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
19+
20+
prob = ODEProblem(sys, [], tspan)
21+
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
22+
23+
time = 0
24+
while(time <= 1)
25+
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-3)
26+
time += 0.1
27+
end
28+
29+
α = 0.3
30+
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2))
31+
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^/2)-t^4)^3 - x^(3/2)
32+
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
33+
34+
prob = ODEProblem(sys, [], tspan)
35+
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
36+
37+
time = 0
38+
while(time <= 1)
39+
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-3)
40+
time += 0.1
41+
end
42+
43+
α = 0.9
44+
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2))
45+
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^/2)-t^4)^3 - x^(3/2)
46+
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
47+
48+
prob = ODEProblem(sys, [], tspan)
49+
sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
50+
51+
time = 0
52+
while(time <= 1)
53+
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-3)
54+
time += 0.1
55+
end
56+
57+
# Testing for example 2 of Section 7
58+
@independent_variables t
59+
@variables x(t) y(t)
60+
D = Differential(t)
61+
tspan = (0., 220.)
62+
63+
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8], 10^-6, 220; initials=[[1.2, 1], 2.8])
64+
prob = ODEProblem(sys, [], tspan)
65+
sol = solve(prob, radau5(), abstol = 1e-8, reltol = 1e-8)
66+
67+
@test isapprox(1.0097684171, sol(220, idxs=x), atol=1e-3)
68+
@test isapprox(2.1581264031, sol(220, idxs=y), atol=1e-3)

0 commit comments

Comments
 (0)