1
+ # TEST: Function registration in a module.
2
+ # ------------------------------------------------
3
+ module MyModule
4
+ using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
5
+ @parameters t x
6
+ @variables u (t)
7
+ @derivatives Dt' ~ t
8
+
9
+ function do_something (a)
10
+ a + 10
11
+ end
12
+ @register do_something (a)
13
+
14
+ eq = Dt (u) ~ do_something (x)
15
+ sys = ODESystem ([eq], t, [u], [x])
16
+ fun = ODEFunction (sys)
17
+
18
+ @test fun ([0.5 ], [5.0 ], 0. ) == [15.0 ]
19
+ end
20
+
21
+ # TEST: Function registration in a nested module.
22
+ # ------------------------------------------------
23
+ module MyModule2
24
+ module MyNestedModule
25
+ using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
26
+ @parameters t x
27
+ @variables u (t)
28
+ @derivatives Dt' ~ t
29
+
30
+ function do_something_2 (a)
31
+ a + 20
32
+ end
33
+ @register do_something_2 (a)
34
+
35
+ eq = Dt (u) ~ do_something_2 (x)
36
+ sys = ODESystem ([eq], t, [u], [x])
37
+ fun = ODEFunction (sys)
38
+
39
+ @test fun ([0.5 ], [3.0 ], 0. ) == [23.0 ]
40
+ end
41
+ end
42
+
43
+ # TEST: Function registration outside any modules.
44
+ # ------------------------------------------------
45
+ using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
46
+ @parameters t x
47
+ @variables u (t)
48
+ @derivatives Dt' ~ t
49
+
50
+ function do_something_3 (a)
51
+ a + 30
52
+ end
53
+ @register do_something_3 (a)
54
+
55
+ eq = Dt (u) ~ do_something_3 (x)
56
+ sys = ODESystem ([eq], t, [u], [x])
57
+ fun = ODEFunction (sys)
58
+
59
+ @test fun ([0.5 ], [7.0 ], 0. ) == [37.0 ]
0 commit comments