@@ -44,7 +44,7 @@ Each operation builds an `Operation` type, and thus `eqs` is an array of
44
44
analyzed by other programs. We can turn this into a ` ODESystem ` via:
45
45
46
46
``` julia
47
- de = ODESystem (eqs)
47
+ de = ODESystem (eqs, t, [x,y,z], [σ,ρ,β] )
48
48
```
49
49
50
50
where we tell it the variable types and ordering in the first version, or let it
@@ -54,49 +54,53 @@ generated code via:
54
54
55
55
``` julia
56
56
using MacroTools
57
- myode_oop = generate_function (de, [x,y,z], [σ,ρ,β] )[1 ] # first one is the out-of-place function
57
+ myode_oop = generate_function (de)[1 ] # first one is the out-of-place function
58
58
MacroTools. striplines (myode_oop) # print without line numbers
59
59
60
60
#=
61
61
:((u, p, t)->begin
62
- @inbounds begin
63
- X = @inbounds(begin
64
- let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
65
- (σ * (y - x), x * (ρ - z) - y, x * y - β * z)
66
- end
67
- end)
68
- end
62
+ if u isa Array
63
+ return @inbounds(begin
64
+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
65
+ [σ * (y - x), x * (ρ - z) - y, x * y - β * z]
66
+ end
67
+ end)
68
+ else
69
+ X = @inbounds(begin
70
+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
71
+ (σ * (y - x), x * (ρ - z) - y, x * y - β * z)
72
+ end
73
+ end)
74
+ end
69
75
T = promote_type(map(typeof, X)...)
70
- convert. (T, X)
76
+ map (T, X)
71
77
construct = if u isa ModelingToolkit.StaticArrays.StaticArray
72
78
ModelingToolkit.StaticArrays.similar_type(typeof(u), eltype(X))
73
79
else
74
80
x->begin
75
- du = similar(u, T, 3)
76
- vec(du) .= x
77
- du
81
+ convert(typeof(u), x)
78
82
end
79
83
end
80
84
construct(X)
81
85
end)
82
86
=#
83
87
84
- myode_iip = generate_function (de, [x,y,z], [σ,ρ,β] )[2 ] # second one is the in-place function
88
+ myode_iip = generate_function (de)[2 ] # second one is the in-place function
85
89
MacroTools. striplines (myode_iip) # print without line numbers
86
90
87
91
#=
88
- ( var"##MTIIPVar#409 ", u, p, t)->begin
89
- @inbounds begin
90
- @inbounds begin
91
- let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
92
- var"##MTIIPVar#409 "[1] = σ * (y - x)
93
- var"##MTIIPVar#409 "[2] = x * (ρ - z) - y
94
- var"##MTIIPVar#409 "[3] = x * y - β * z
95
- end
96
- end
97
- end
98
- nothing
99
- end
92
+ :(( var"##MTIIPVar#793 ", u, p, t)->begin
93
+ @inbounds begin
94
+ @inbounds begin
95
+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
96
+ var"##MTIIPVar#793 "[1] = σ * (y - x)
97
+ var"##MTIIPVar#793 "[2] = x * (ρ - z) - y
98
+ var"##MTIIPVar#793 "[3] = x * y - β * z
99
+ end
100
+ end
101
+ end
102
+ nothing
103
+ end)
100
104
=#
101
105
```
102
106
0 commit comments