Skip to content

Commit

Permalink
Support ODESystem in the alternative build targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Mar 22, 2020
1 parent 683b469 commit 53ac691
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelingToolkit"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
authors = ["Chris Rackauckas <[email protected]>"]
version = "1.4.0"
version = "1.4.1"

[deps]
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Expand Down
8 changes: 7 additions & 1 deletion src/build_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ function numbered_expr(O::Operation,vars,parameters;
[numbered_expr(x,vars,parameters;derivname=derivname,
varname=varname,paramname=paramname) for x in O.args]...)
end

function numbered_expr(de::ModelingToolkit.DiffEq,vars,parameters;
derivname=:du,varname=:u,paramname=:p)
i = findfirst(x->isequal(x.op.name,de.x.name),vars)
:($derivname[$i] = $(numbered_expr(de.rhs,vars,parameters;
derivname=derivname,
varname=varname,paramname=paramname)))
end
numbered_expr(c::ModelingToolkit.Constant,args...;kwargs...) = c.value

function _build_function(target::StanTarget, eqs, vs, ps, iv,
Expand Down
1 change: 0 additions & 1 deletion src/systems/diffeqs/diffeqsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function flatten_differential(O::Operation)
return (x, t, order + 1)
end


struct DiffEq # dⁿx/dtⁿ = rhs
x::Variable
n::Int
Expand Down
11 changes: 11 additions & 0 deletions test/build_targets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ eqs = [D(x) ~ a*x - x*y,
@test ModelingToolkit.build_function(eqs,[x,y],[a],t,target = ModelingToolkit.MATLABTarget()) ==
"""
diffeqf = @(t,internal_var___u) [internal_var___p(1) * internal_var___u(1) - internal_var___u(1) * internal_var___u(2); -3 * internal_var___u(2) + internal_var___u(1) * internal_var___u(2)];"""

sys = ODESystem(eqs,t,[x,y],[a])

@test ModelingToolkit.build_function(eqs,[x,y],[a],t,target = ModelingToolkit.CTarget()) ==
ModelingToolkit.build_function(sys.eqs,[x,y],[a],t,target = ModelingToolkit.CTarget())

@test ModelingToolkit.build_function(eqs,[x,y],[a],t,target = ModelingToolkit.StanTarget()) ==
ModelingToolkit.build_function(sys.eqs,[x,y],[a],t,target = ModelingToolkit.StanTarget())

@test ModelingToolkit.build_function(eqs,[x,y],[a],t,target = ModelingToolkit.MATLABTarget()) ==
ModelingToolkit.build_function(sys.eqs,[x,y],[a],t,target = ModelingToolkit.MATLABTarget())

0 comments on commit 53ac691

Please sign in to comment.