Skip to content

Commit

Permalink
Merge d6eff50 into 1cabfea
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed May 28, 2019
2 parents 1cabfea + d6eff50 commit 35ce568
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ModelingToolkit.jl
Expand Up @@ -3,7 +3,7 @@ module ModelingToolkit
export Operation, Expression
export calculate_jacobian, generate_jacobian, generate_function
export independent_variables, dependent_variables, parameters
export @register
export @register, @mt_setup


using DiffEqBase
Expand Down Expand Up @@ -39,5 +39,6 @@ include("systems/nonlinear/nonlinear_system.jl")
include("function_registration.jl")
include("simplify.jl")
include("utils.jl")
include("mt_setup.jl")

end # module
6 changes: 6 additions & 0 deletions src/mt_setup.jl
@@ -0,0 +1,6 @@
macro mt_setup(expr)
MacroTools.postwalk(expr) do x
x == :ODEFunction ? :generate_function : x
end
expr
end
20 changes: 20 additions & 0 deletions test/mt_setup.jl
@@ -0,0 +1,20 @@
using ModelingToolkit
using Test

f = @mt_setup begin
@parameters t σ ρ β
@variables x(t) y(t) z(t)
@derivatives D'~t

eqs = [D(x) ~ σ*(y-x),
D(y) ~ x*-z)-y,
D(z) ~ x*y - β*z]
de = ODESystem(eqs)
ODEFunction(de, [x,y,z], [σ,ρ,β])
end

du = zeros(3)
u = collect(1:3)
p = collect(4:6)
f(du, u, p, 0.1)
@test du == [4, 0, -16]
1 change: 1 addition & 0 deletions test/runtests.jl
Expand Up @@ -4,3 +4,4 @@ using ModelingToolkit, Test
@testset "Differentiation Test" begin include("derivatives.jl") end
@testset "Simplify Test" begin include("simplify.jl") end
@testset "System Construction Test" begin include("system_construction.jl") end
@testset "mt_setup Test" begin include("mt_setup.jl") end

0 comments on commit 35ce568

Please sign in to comment.