Skip to content

Commit b98f424

Browse files
working invw
1 parent 67dbacc commit b98f424

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/ModelingToolkit.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module ModelingToolkit
22

33
using DiffEqBase
4+
using StaticArrays
5+
46
import MacroTools: splitdef, combinedef
57
import IterTools: product
68

src/simplify.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ function _simplify_constants(O,shorten_tree = true)
7777
else
7878
return O
7979
end
80-
#=
8180
elseif O.op == identity
8281
return O.args[1]
83-
=#
8482
elseif Symbol(O.op) == :- && length(O.args) == 1
8583
return Operation(*,Expression[-1,O.args[1]])
8684
else

src/systems/diffeqs/diffeqsystem.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,26 @@ function generate_ode_jacobian(sys::DiffEqSystem,simplify=true)
8989
:((J,u,p,t)->$(block))
9090
end
9191

92-
const _γ_ = Variable(:_γ_)
93-
9492
function generate_ode_iW(sys::DiffEqSystem,simplify=true)
9593
var_exprs = [:($(sys.dvs[i].name) = u[$i]) for i in 1:length(sys.dvs)]
9694
param_exprs = [:($(sys.ps[i].name) = p[$i]) for i in 1:length(sys.ps)]
9795
diff_idxs = map(eq->eq.args[1].diff !=nothing,sys.eqs)
9896
diff_exprs = sys.eqs[diff_idxs]
9997
jac = sys.jac
100-
iW = inv(I - _γ_*jac)
98+
99+
gam = Variable(:gam)
100+
101+
W = I - gam*jac
102+
W = SMatrix{size(W,1),size(W,2)}(W)
103+
iW = inv(W)
101104

102105
if simplify
103106
iW = simplify_constants.(iW)
104107
end
105108

106-
iW_t = inv(I/_γ_ - jac)
109+
W = inv(I/gam - jac)
110+
W = SMatrix{size(W,1),size(W,2)}(W)
111+
iW_t = inv(W)
107112
if simplify
108113
iW_t = simplify_constants.(iW_t)
109114
end
@@ -115,7 +120,7 @@ function generate_ode_iW(sys::DiffEqSystem,simplify=true)
115120
iW_t_exprs = [:(iW[$i,$j] = $(Expr(iW_t[i,j]))) for i in 1:size(iW_t,1), j in 1:size(iW_t,2)]
116121
exprs = vcat(var_exprs,param_exprs,vec(iW_t_exprs))
117122
block2 = expr_arr_to_block(exprs)
118-
:((iW,u,p,_γ_,t)->$(block)),:((iW,u,p,_γ_,t)->$(block2))
123+
:((iW,u,p,gam,t)->$(block)),:((iW,u,p,gam,t)->$(block2))
119124
end
120125

121126
function DiffEqBase.DiffEqFunction(sys::DiffEqSystem)

src/variables.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# <: Real to make tracing easier. Maybe a bad idea?
2-
struct Variable <: Expression
1+
mutable struct Variable <: Expression
32
name::Symbol
43
value
54
value_type::DataType

0 commit comments

Comments
 (0)