Skip to content

Commit 421926f

Browse files
committed
Specify only history function
1 parent eb68646 commit 421926f

File tree

3 files changed

+122
-64
lines changed

3 files changed

+122
-64
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1414

1515
[compat]
16-
DiffEqBase = ">= 3.0.3"
16+
DiffEqBase = ">= 5.15.0"
1717
julia = "1"
1818

1919
[extras]

src/dde/ddetst.jl

Lines changed: 104 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ function h_dde_DDETST_A1(p, t)
3636
end
3737

3838
const prob_dde_DDETST_A1 =
39-
DDEProblem(f_dde_DDETST_A1, 0.5, h_dde_DDETST_A1, (0.0, 500.0);
40-
constant_lags = [14])
39+
DDEProblem(f_dde_DDETST_A1, h_dde_DDETST_A1, (0.0, 500.0); constant_lags = [14])
4140

4241
# Problem A2
4342
@doc raw"""
@@ -79,16 +78,22 @@ function f_dde_DDETST_A2!(du, u, h, p, t)
7978
nothing
8079
end
8180

82-
function h_dde_DDETST_A2(p, t; idxs = 1)
83-
idxs == 1 || error("history function is only implemented for the first component")
81+
function h_dde_DDETST_A2(p, t; idxs::Union{Nothing,Int} = nothing)
8482
t 0 || error("history function is only implemented for t ≤ 0")
8583

86-
1.05767027/3
84+
if idxs === nothing
85+
[1.05767027/3, 1.030713491/3]
86+
elseif idxs == 1
87+
1.05767027/3
88+
elseif idxs == 2
89+
1.030713491/3
90+
else
91+
error("delay differential equation consists of two components")
92+
end
8793
end
8894

8995
const prob_dde_DDETST_A2 =
90-
DDEProblem(f_dde_DDETST_A2!, [1.05767027/3; 1.030713491/3], h_dde_DDETST_A2, (0.0, 100.0);
91-
constant_lags = [20])
96+
DDEProblem(f_dde_DDETST_A2!, h_dde_DDETST_A2, (0.0, 100.0); constant_lags = [20])
9297

9398
# Problem B2
9499
@doc raw"""
@@ -136,8 +141,8 @@ end
136141

137142
const prob_dde_DDETST_B1 =
138143
DDEProblem(DDEFunction(f_dde_DDETST_B1; analytic = fanalytic_dde_DDETST_B1),
139-
log(0.1), h_dde_DDETST_B1, (0.1, 10.0);
140-
dependent_lags = [(u, p, t) -> t - exp(1 - 1/t)])
144+
h_dde_DDETST_B1, (0.1, 10.0);
145+
dependent_lags = ((u, p, t) -> t - exp(1 - 1/t),))
141146

142147
# Problem B2
143148
@doc raw"""
@@ -200,7 +205,7 @@ end
200205

201206
const prob_dde_DDETST_B2 =
202207
DDEProblem(DDEFunction(f_dde_DDETST_B2; analytic = fanalytic_dde_DDETST_B2),
203-
1.0, h_dde_DDETST_B2, (0.0, 2 * log(66));
208+
h_dde_DDETST_B2, (0.0, 2 * log(66));
204209
dependent_lags = ((u, p, t) -> t / 2,))
205210

206211
# Problem C1
@@ -231,8 +236,8 @@ function h_dde_DDETST_C1(p, t)
231236
end
232237

233238
const prob_dde_DDETST_C1 =
234-
DDEProblem(f_dde_DDETST_C1, 0.5, h_dde_DDETST_C1, (0.0, 30.0);
235-
dependent_lags = [(u, p, t) -> 1 + abs(u)])
239+
DDEProblem(f_dde_DDETST_C1, h_dde_DDETST_C1, (0.0, 30.0);
240+
dependent_lags = ((u, p, t) -> 1 + abs(u),))
236241

237242
# Problem C2
238243
@doc raw"""
@@ -275,16 +280,23 @@ function f_dde_DDETST_C2!(du, u, h, p, t)
275280
nothing
276281
end
277282

278-
function h_dde_DDETST_C2(p, t; idxs = 1)
279-
idxs == 1 || error("history function is only implemented for the first component")
283+
function h_dde_DDETST_C2(p, t; idxs::Union{Nothing,Int} = nothing)
280284
t 0 || error("history function is only implemented for t ≤ 0")
281285

282-
1.0
286+
if idxs === nothing
287+
[1.0, 0.5]
288+
elseif idxs == 1
289+
1.0
290+
elseif idxs == 2
291+
0.5
292+
else
293+
error("delay differential equation consists of two components")
294+
end
283295
end
284296

285297
const prob_dde_DDETST_C2 =
286-
DDEProblem(f_dde_DDETST_C2!, [1.0, 0.5], h_dde_DDETST_C2, (0.0, 30.0);
287-
dependent_lags = [(u, p, t) -> u[2]])
298+
DDEProblem(f_dde_DDETST_C2!, h_dde_DDETST_C2, (0.0, 30.0);
299+
dependent_lags = ((u, p, t) -> u[2],))
288300

289301
# Problem C3
290302
@doc raw"""
@@ -327,19 +339,24 @@ const prob_dde_DDETST_C3 =
327339
nothing
328340
end
329341

330-
global function h_dde_DDETST_C3(p, t; idxs = 2)
331-
idxs == 2 || error("history function is only implemented for the second component")
342+
global function h_dde_DDETST_C3(p, t; idxs::Union{Nothing,Int} = nothing)
332343
t 0 || error("history function is only implemented for t ≤ 0")
333344

334-
if t < - T₁
335-
9.5
345+
if idxs === nothing
346+
[3.325, t < - T₁ ? 9.5 : 10.0, 120.0]
347+
elseif idxs == 1
348+
3.325
349+
elseif idxs == 2
350+
t < - T₁ ? 9.5 : 10.0
351+
elseif idxs == 3
352+
120.0
336353
else
337-
10.0
354+
error("delay differential equation consists of three components")
338355
end
339356
end
340357

341-
DDEProblem(f_dde_DDETST_C3!, [3.325, 10.0, 120.0], h_dde_DDETST_C3, (0.0, 300.0);
342-
constant_lags = [T₁], dependent_lags = [(u, p, t) -> T₁ + u[3]])
358+
DDEProblem(f_dde_DDETST_C3!, h_dde_DDETST_C3, (0.0, 300.0);
359+
constant_lags = [T₁], dependent_lags = ((u, p, t) -> T₁ + u[3],))
343360
end
344361

345362
# Problem C4
@@ -377,15 +394,24 @@ const prob_dde_DDETST_C4 =
377394
nothing
378395
end
379396

380-
global function h_dde_DDETST_C4(p, t; idxs = 2)
381-
idxs == 2 || error("history function is only implemented for the second component")
397+
global function h_dde_DDETST_C4(p, t; idxs::Union{Nothing,Int} = nothing)
382398
t 0 || error("history function is only implemented for t ≤ 0")
383399

384-
10.0
400+
if idxs === nothing
401+
[3.5, 10.0, 50.0]
402+
elseif idxs == 1
403+
3.5
404+
elseif idxs == 2
405+
10.0
406+
elseif idxs == 3
407+
50.0
408+
else
409+
error("delay differential equation consists of three components")
410+
end
385411
end
386412

387413
DDEProblem(f_dde_DDETST_C4!, [3.5, 10.0, 50.0], h_dde_DDETST_C4, (0.0, 100.0);
388-
constant_lags = [T₁], dependent_lags = [(u, p, t) -> T₁ + u[3]])
414+
constant_lags = [T₁], dependent_lags = ((u, p, t) -> T₁ + u[3],))
389415
end
390416

391417
# Problem D1
@@ -439,11 +465,18 @@ function f_dde_DDETST_D1!(du, u, h, p, t)
439465
nothing
440466
end
441467

442-
function h_dde_DDETST_D1(p, t; idxs = 2)
443-
idxs == 2 || error("history function is only implemented for the second component")
468+
function h_dde_DDETST_D1(p, t; idxs::Union{Nothing,Int} = nothing)
444469
0 < t 0.1 || error("history function is only implemented for 0 < t ≤ 0.1")
445470

446-
1 / t
471+
if idxs === nothing
472+
[log(t), 1 / t]
473+
elseif idxs == 1
474+
log(t)
475+
elseif idxs == 2
476+
1 / t
477+
else
478+
error("delay differential equation consists of two components")
479+
end
447480
end
448481

449482
function fanalytic_dde_DDETST_D1(u₀, ::typeof(h_dde_DDETST_D1), p, t)
@@ -455,8 +488,8 @@ end
455488

456489
const prob_dde_DDETST_D1 =
457490
DDEProblem(DDEFunction(f_dde_DDETST_D1!; analytic = fanalytic_dde_DDETST_D1),
458-
[log(0.1), 10], h_dde_DDETST_D1, (0.1, 5.0);
459-
dependent_lags = [(u, p, t) -> t - exp(1 - u[2])])
491+
h_dde_DDETST_D1, (0.1, 5.0);
492+
dependent_lags = ((u, p, t) -> t - exp(1 - u[2]),))
460493

461494
# Problem D2
462495
@doc raw"""
@@ -516,8 +549,8 @@ const prob_dde_DDETST_D2 =
516549
[5.0, 0.1, 0.0, 0.0]
517550
end
518551

519-
dependent_lags = [(u, p, t) -> u[4]])
520-
DDEProblem(f_dde_DDETST_D2!, h_dde_DDETST_D2(nothing, 0.0), h_dde_DDETST_D2, (0.0, 40.0);
552+
DDEProblem(f_dde_DDETST_D2!, h_dde_DDETST_D2, (0.0, 40.0);
553+
dependent_lags = ((u, p, t) -> u[4],))
521554
end
522555

523556
# Problem E1
@@ -554,7 +587,7 @@ const prob_dde_DDETST_E1 =
554587
1.0
555588
end
556589

557-
DDEProblem(f_dde_DDETST_E1, 2.0, h_dde_DDETST_E1, (0.0, 40.0);
590+
DDEProblem(f_dde_DDETST_E1, h_dde_DDETST_E1, (0.0, 40.0);
558591
constant_lags = [1], neutral = true)
559592
end
560593

@@ -599,21 +632,34 @@ const prob_dde_DDETST_E2 =
599632
nothing
600633
end
601634

602-
global function h_dde_DDETST_E2(p, t; idxs = 1)
603-
idxs == 1 || error("history function is only implemented for the first component")
635+
global function h_dde_DDETST_E2(p, t; idxs::Union{Nothing,Int} = nothing)
604636
t 0 || error("history function is only implemented for t ≤ 0")
605637

606-
0.33 - 0.1 * t
638+
if idxs === nothing
639+
[0.33 - 0.1 * t, 2.22 + 0.1 * t]
640+
elseif idxs == 1
641+
0.33 - 0.1 * t
642+
elseif idxs == 2
643+
2.22 + 0.1 * t
644+
else
645+
error("delay differential equation consists of two components")
646+
end
607647
end
608648

609-
global function h_dde_DDETST_E2(p, t, ::Type{Val{1}}; idxs = 1)
610-
idxs == 1 || error("history function is only implemented for the first component")
649+
global function h_dde_DDETST_E2(p, t, ::Type{Val{1}};
650+
idxs::Union{Nothing,Int} = nothing)
611651
t 0 || error("history function is only implemented for t ≤ 0")
612652

613-
-0.1
653+
if idxs === nothing
654+
[-0.1, -0.1]
655+
elseif idxs == 1 || idxs == 2
656+
-0.1
657+
else
658+
error("delay differential equation consists of two components")
659+
end
614660
end
615661

616-
DDEProblem(f_dde_DDETST_E2!, [0.33, 2.22], h_dde_DDETST_E2, (0.0, 2.0);
662+
DDEProblem(f_dde_DDETST_E2!, h_dde_DDETST_E2, (0.0, 2.0);
617663
constant_lags = [τ], neutral = true)
618664
end
619665

@@ -676,8 +722,8 @@ end
676722

677723
const prob_dde_DDETST_F1 =
678724
DDEProblem(DDEFunction(f_dde_DDETST_F1; analytic = fanalytic_dde_DDETST_F1),
679-
1.0, h_dde_DDETST_F1, (0.0, 0.1);
680-
dependent_lags = [(u, p, t) -> t / 2], neutral = true)
725+
h_dde_DDETST_F1, (0.0, 0.1);
726+
dependent_lags = ((u, p, t) -> t / 2,), neutral = true)
681727

682728
# Problem F2
683729
@doc raw"""
@@ -761,8 +807,8 @@ end
761807

762808
const prob_dde_DDETST_F2 =
763809
DDEProblem(DDEFunction(f_dde_DDETST_F2; analytic = fanalytic_dde_DDETST_F2),
764-
exp(-0.25^2), h_dde_DDETST_F2, (0.25, 0.499);
765-
dependent_lags = [(u, p, t) -> 1/2 - t], neutral = true)
810+
h_dde_DDETST_F2, (0.25, 0.499);
811+
dependent_lags = ((u, p, t) -> 1/2 - t,), neutral = true)
766812

767813
# Problem F3
768814
@doc raw"""
@@ -816,8 +862,9 @@ end
816862

817863
const prob_dde_DDETST_F3 =
818864
DDEProblem(DDEFunction(f_dde_DDETST_F3; analytic = fanalytic_dde_DDETST_F345),
819-
log(3), h_dde_DDETST_F345, (0.0, 10.0);
820-
dependent_lags = [(u, p, t) -> 0.5 * t * (1 + cos(2 * π * t))], neutral = true)
865+
h_dde_DDETST_F345, (0.0, 10.0);
866+
dependent_lags = ((u, p, t) -> 0.5 * t * (1 + cos(2 * π * t)),),
867+
neutral = true)
821868

822869
# Problem F4
823870
"""
@@ -910,8 +957,8 @@ end
910957

911958
const prob_dde_DDETST_G1 =
912959
DDEProblem(DDEFunction(f_dde_DDETST_G1; analytic = fanalytic_dde_DDETST_G1),
913-
1.0, h_dde_DDETST_G1, (0.0, 1.0);
914-
dependent_lags = [(u, p, t) -> u^2 / 4], neutral = true)
960+
h_dde_DDETST_G1, (0.0, 1.0);
961+
dependent_lags = ((u, p, t) -> u^2 / 4,), neutral = true)
915962

916963
# Problem G2
917964
@doc raw"""
@@ -962,8 +1009,8 @@ end
9621009

9631010
const prob_dde_DDETST_G2 =
9641011
DDEProblem(DDEFunction(f_dde_DDETST_G2; analytic = fanalytic_dde_DDETST_G2),
965-
1.0, h_dde_DDETST_G2, (0.0, 1.0);
966-
dependent_lags = [(u, p, t) -> t + 2 - u], neutral = true)
1012+
h_dde_DDETST_G2, (0.0, 1.0);
1013+
dependent_lags = ((u, p, t) -> t + 2 - u,), neutral = true)
9671014

9681015
# Problem H1
9691016
@doc raw"""
@@ -1020,8 +1067,8 @@ end
10201067

10211068
const prob_dde_DDETST_H1 =
10221069
DDEProblem(DDEFunction(f_dde_DDETST_H1; analytic = fanalytic_dde_DDETST_H1),
1023-
0.0, h_dde_DDETST_H1, (0.0, 0.225 * π);
1024-
dependent_lags = [(u, p, t) -> t / (1 + u^2)], neutral = true)
1070+
h_dde_DDETST_H1, (0.0, 0.225 * π);
1071+
dependent_lags = ((u, p, t) -> t / (1 + u^2),), neutral = true)
10251072

10261073
# Problem H2
10271074
@doc raw"""
@@ -1084,8 +1131,8 @@ end
10841131

10851132
const prob_dde_DDETST_H2 =
10861133
DDEProblem(DDEFunction(f_dde_DDETST_H2; analytic = fanalytic_dde_DDETST_H234),
1087-
0.0, h_dde_DDETST_H234, (0.0, π);
1088-
dependent_lags = [(u, p, t) -> t * (1 - u^2)], neutral = true)
1134+
h_dde_DDETST_H234, (0.0, π);
1135+
dependent_lags = ((u, p, t) -> t * (1 - u^2),), neutral = true)
10891136

10901137
# Problem H3
10911138
"""

src/dde/qs.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,25 @@ const prob_dde_qs =
6060
nothing
6161
end
6262

63-
# history function for the fourth component
64-
function h_dde_qs(p, t; idxs = 4)
65-
idxs == 4 || error("history function is only implemented for the fourth component")
63+
function h_dde_qs(p, t; idxs::Union{Nothing,Int} = nothing)
6664
t 0 || error("history function is only implemented for t ≤ 0")
6765

68-
7.6e-8
66+
if idxs === nothing
67+
[1.0, 8.4e8, 2.5e-9, 7.6e-8, 5e-15]
68+
elseif idxs == 1
69+
1.0
70+
elseif idxs == 2
71+
8.4e8
72+
elseif idxs == 3
73+
2.5e-9
74+
elseif idxs == 4
75+
7.6e-8
76+
elseif idxs == 5
77+
5e-15
78+
else
79+
error("delay differential equation consists of five components")
80+
end
6981
end
7082

71-
DDEProblem(f_dde_qs!, [1, 8.4e8, 2.5e-9, 7.6e-8, 5e-15], h_dde_qs, (0.0, 45.0);
72-
constant_lags = [τ])
83+
DDEProblem(f_dde_qs!, h_dde_qs, (0.0, 45.0); constant_lags = [τ])
7384
end

0 commit comments

Comments
 (0)