Skip to content

Commit 8c4b57c

Browse files
committed
Inital commit of step
1 parent c815833 commit 8c4b57c

5 files changed

Lines changed: 29 additions & 9 deletions

File tree

src/SimJulia.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module SimJulia
2828
export Coroutine, @coroutine
2929
export Container, Resource, Store
3030
export Put, Get, Request, Release, cancel, capacity, request, @request
31-
export Continuous
31+
export Continuous, Variable
3232
export @model, @continuous
3333

3434
include("base.jl")
@@ -49,5 +49,6 @@ module SimJulia
4949
include("odes/macros.jl")
5050
include("odes/QSS.jl")
5151
include("continuous.jl")
52+
include("odes/utils.jl")
5253
include("odes/commons.jl")
5354
end

src/odes/QSS.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ struct ImplicitQuantizer <: Quantizer end
66

77
struct QSS <: Integrator
88
order :: UInt8
9+
deps :: Matrix{Bool}
910
quantizer :: Quantizer
1011
q :: Vector{Taylor1}
1112
t :: Vector{Float64}
1213
function QSS(;order::Number=4, stiff::Bool=false)
1314
quantizer = stiff ? ImplicitQuantizer() : DirectQuantizer()
14-
new(UInt8(order), quantizer, Vector{Taylor1}(), Vector{Float64}())
15+
new(UInt8(order), Matrix{Bool}(0, 0), quantizer, Vector{Taylor1}(), Vector{Float64}())
1516
end
1617
end

src/odes/commons.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ function step(var::Variable, cont::Continuous, integrator::QSS)
3232
i = var.id
3333
env = environment(var)
3434
t = now(env)
35-
println(integrator.q)
35+
x₀ = advance_time(var, t)
36+
#update_quantized_state(cont, integrator, i)
37+
#for (j, istrue) in enumerate(integrator.deps[i, :])
38+
# istrue && advance_time(cont, j, t)
39+
#end
40+
q₋ = deepcopy(integrator.q)
3641
end

src/odes/macros.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function check_dependencies(ex, deps::Array{Bool}, i::Int)
1+
function check_dependencies(ex, deps::Array{Bool}, i::Int, x::Symbol)
22
if ex isa Expr
3-
if ex.head == :ref
3+
if ex.head == :ref && x == ex.args[1]
44
deps[i, ex.args[2]] = true
55
else
66
for arg in ex.args
7-
check_dependencies(arg, deps, i)
7+
check_dependencies(arg, deps, i, x)
88
end
99
end
1010
end
@@ -21,9 +21,7 @@ macro model(expr::Expr)
2121
n = length(f_vec)
2222
deps = zeros(Bool, n, n)
2323
for ex in expr.args[2].args
24-
if ex isa Expr && ex.head == Symbol("=")
25-
check_dependencies(ex.args[2], deps, ex.args[1].args[2])
26-
end
24+
ex isa Expr && ex.head == Symbol("=") && check_dependencies(ex.args[2], deps, ex.args[1].args[2], expr.args[1].args[3])
2725
end
2826
esc(:(function $func_name()
2927
f = Array{Function}(length($f_vec))

src/odes/utils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function advance_time(var::Variable, t::Float64)
2+
x = var.x
3+
Δt = t - var.t
4+
var.x = evaluate(x, Δt + Taylor1(x.order))
5+
var.t = t
6+
var.x.coeffs[1]
7+
end
8+
9+
function advance_time(integrator::QSS, i::Int, t::Float64)
10+
q = integrator.q[i]
11+
Δt = t - integrator.t[i]
12+
integrator.q[i] = evaluate(q, Δt + Taylor1(q.order))
13+
integrator.t[i] = t
14+
integrator.q[i].coeffs[1]
15+
end

0 commit comments

Comments
 (0)