Skip to content

Commit 35b473e

Browse files
committed
Initial commit continuous and rename benchmarks
1 parent 02fcfba commit 35b473e

11 files changed

Lines changed: 69 additions & 4 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ datetime = now()
5454
sim = Simulation(datetime)
5555
@process datetimetest(sim)
5656
run(sim, datetime+Month(3))
57-
println(nowDatetime(sim))
5857
```
5958
* The discrete event features are on par with version 0.3. (STABLE)
6059
* Two ways of making `Processes` are provided:

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
julia 0.6
22
DataStructures
3+
TaylorSeries

src/SimJulia.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module SimJulia
77

88
using DataStructures
99
using Base.Dates
10+
using TaylorSeries
1011

1112
import Base.run, Base.now, Base.isless, Base.show, Base.interrupt, Base.yield
1213
import Base.(&), Base.(|)
@@ -26,6 +27,8 @@ module SimJulia
2627
export Coroutine, @coroutine
2728
export Container, Resource, Store
2829
export Put, Get, Request, Release, cancel, capacity, request, @request
30+
export Continuous
31+
export @model, @continuous
2932

3033
include("base.jl")
3134
include("events.jl")
@@ -36,10 +39,11 @@ module SimJulia
3639
include("processes.jl")
3740
include("finitestatemachines/utils.jl")
3841
include("finitestatemachines/transforms.jl")
39-
include("finitestatemachines/macro.jl")
42+
include("finitestatemachines/macros.jl")
4043
include("coroutines.jl")
4144
include("resources/base.jl")
4245
include("resources/containers.jl")
4346
include("resources/stores.jl")
44-
47+
include("odes/macros.jl")
48+
include("continuous.jl")
4549
end

src/continuous.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
struct Continuous <: AbstractProcess
2+
bev :: BaseEvent
3+
f :: Vector{Function}
4+
order :: UInt8
5+
stiff :: Bool
6+
q :: Vector{Taylor1}
7+
x :: Vector{Taylor1}
8+
p :: Vector{Float64}
9+
function Continuous(func::Function, env::Environment, q::Vector{Float64}, p::Vector{Float64}=Float64[]; order::Number=4, stiff::Bool=false)
10+
cont = new(BaseEvent(env), func(), UInt8(order), stiff, Vector{Taylor1}(), Vector{Taylor1}(), p)
11+
for q₀ in q
12+
push!(cont.q, q₀ + Taylor1(Float64, order+1))
13+
end
14+
t = now(env) + Taylor1(Float64, order+1)
15+
for (i, q₀) in enumerate(q)
16+
push!(cont.x, integrate(cont.f[i](t, cont.q, cont.p), q₀))
17+
end
18+
cont
19+
end
20+
end
21+
22+
macro continuous(expr::Expr)
23+
expr.head != :call && error("Expression is not a function call!")
24+
func = expr.args[1]
25+
params = Vector{Expr}()
26+
args = Vector{Any}()
27+
for i in 2:length(expr.args)
28+
if expr.args[i] isa Expr && expr.args[i].head == :parameters
29+
for ex in expr.args[i].args
30+
push!(params, ex)
31+
end
32+
else
33+
push!(args, expr.args[i])
34+
end
35+
end
36+
esc(:(Continuous($(func), $(args...); $(params...))))
37+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ abstract type FiniteStateMachine end
77
iscoroutinedone(fsm::FiniteStateMachine) = fsm._state == 0xff
88

99
macro stateful(expr::Expr)
10-
expr.head != :function && error("Not a function definition!")
10+
expr.head != :function && error("Expression is not a function definition!")
1111
args = getArguments(expr)
1212
func_name = shift!(args)
1313
type_name = gensym()

src/odes/macros.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
macro model(expr::Expr)
2+
expr.head != :function && error("Expression is not a function definition!")
3+
args = getArguments(expr)
4+
func_name = shift!(args)
5+
f_vec = Vector{Expr}()
6+
for ex in expr.args[2].args
7+
ex isa Expr && ex.head == Symbol("=") && push!(f_vec, ex)
8+
end
9+
esc(:(function $func_name()
10+
f = Array{Function}(length($f_vec))
11+
$((:(f[$(f_vec[i].args[1].args[2])] = (t::TaylorSeries.Taylor1, q::Vector{TaylorSeries.Taylor1}, p::Vector{Float64})->$(f_vec[i].args[2])) for i in 1:length(:($f_vec)))...)
12+
f
13+
end))
14+
end
File renamed without changes.

0 commit comments

Comments
 (0)