Skip to content

Commit 37558fe

Browse files
committed
add precompile workload back
1 parent f50ebe4 commit 37558fe

File tree

4 files changed

+32
-72
lines changed

4 files changed

+32
-72
lines changed

ext/MTKExt.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,9 @@ end
475475

476476
_all_rhs_symbols(eqs) = mapreduce(eq->get_variables(eq.rhs), , eqs, init=Set{Symbolic}())
477477

478-
using PrecompileTools: @setup_workload, @compile_workload
479-
@setup_workload begin
480-
@compile_workload begin
481-
# include("precompile_workload.jl")
482-
end
478+
using PrecompileTools: @compile_workload
479+
@compile_workload begin
480+
include("precompile_workload.jl")
483481
end
484482

485483
end

ext/precompile_workload.jl

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
is_precompiling() = ccall(:jl_generating_output, Cint, ()) == 1
2-
31
using NetworkDynamics
42
using ModelingToolkit
53
using ModelingToolkit: t_nounits as t, D_nounits as Dt
64

75
@connector Terminal begin
8-
u_r(t), [description="d-voltage"]
9-
u_i(t), [description="q-voltage"]
10-
i_r(t), [description="d-current", connect=Flow]
11-
i_i(t), [description="q-current", connect=Flow]
6+
u_r(t)
7+
u_i(t)
8+
i_r(t), [connect=Flow]
9+
i_i(t), [connect=Flow]
1210
end
1311
@mtkmodel Swing begin
1412
@components begin
1513
terminal = Terminal()
1614
end
1715
@variables begin
18-
ω(t)=0.0, [description="Rotor frequency"]
19-
θ(t)=0.0, [description="Rotor angle"]
20-
Pel(t), [description="Electrical Power injected into the grid"]
16+
ω(t), [description="Rotor frequency", guess=0]
17+
θ(t), [description="Rotor angle", guess=0]
18+
Pel(t)
2119
end
2220
@parameters begin
23-
M=1, [description="Inertia"]
24-
D=0.1, [description="Damping"]
25-
V=1.0, [description="Voltage magnitude"]
26-
ω_ref=0, [description="Reference frequency"]
27-
Pm, [description="Mechanical Power"]
21+
M=0.005
22+
D=0.1
23+
V, [guess=1]
24+
ω_ref=0
25+
Pm, [description="Mechanical Power", guess=-1]
2826
end
2927
@equations begin
3028
Dt(θ) ~ ω - ω_ref
@@ -36,26 +34,10 @@ end
3634
end
3735
@mtkmodel BusBase begin
3836
@variables begin
39-
u_r(t)=1, [description="bus d-voltage", output=true]
40-
u_i(t)=0, [description="bus q-voltage", output=true]
41-
i_r(t), [description="bus d-current (flowing into bus)", input=true]
42-
i_i(t), [description="bus d-current (flowing into bus)", input=true]
43-
P(t), [description="bus active power (flowing into network)"]
44-
Q(t), [description="bus reactive power (flowing into network)"]
45-
u_mag(t), [description="bus voltage magnitude"]
46-
u_arg(t), [description="bus voltage argument"]
47-
i_mag(t), [description="bus current magnitude"]
48-
i_arg(t), [description="bus current argument"]
49-
ω(t), [description="bus angular frequency"]
50-
end
51-
@equations begin
52-
P ~ u_r * (-i_r) + u_i * (-i_i)
53-
Q ~ u_i * (-i_r) - u_r * (-i_i)
54-
u_mag ~ sqrt(u_r^2 + u_i^2)
55-
u_arg ~ atan(u_i, u_r)
56-
i_mag ~ sqrt(i_r^2 + i_i^2)
57-
i_arg ~ atan(i_i, i_r)
58-
ω ~ Dt(u_arg)
37+
u_r(t)=1.0
38+
u_i(t)=0.0
39+
i_r(t)=1.0
40+
i_i(t)=0.0
5941
end
6042
end
6143
@mtkmodel BusBar begin
@@ -80,10 +62,5 @@ end
8062
end
8163
end
8264
@named swingbus = Bus()
83-
84-
if is_precompiling()
85-
VertexModel(swingbus, [:busbar₊i_r, :busbar₊i_i], [:busbar₊u_r, :busbar₊u_i]; verbose=false)
86-
else
87-
@info "ODEVertex"
88-
@time @eval VertexModel(swingbus, [:busbar₊i_r, :busbar₊i_i], [:busbar₊u_r, :busbar₊u_i]; verbose=false)
89-
end
65+
vm = VertexModel(swingbus, [:busbar₊i_r, :busbar₊i_i], [:busbar₊u_r, :busbar₊u_i]; verbose=false)
66+
NetworkDynamics.initialize_component!(vm; verbose=false)

src/NetworkDynamics.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ function reloadfaces!()
125125
end
126126
# NetworkDynamics.reloadfaces!()
127127

128-
using PrecompileTools: @setup_workload, @compile_workload
129-
@setup_workload begin
130-
@compile_workload begin
131-
# include("precompile_workload.jl")
132-
end
128+
using PrecompileTools: @compile_workload
129+
@compile_workload begin
130+
include("precompile_workload.jl")
133131
end
134132

135133
end

src/precompile_workload.jl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
is_precompiling() = ccall(:jl_generating_output, Cint, ()) == 1
2-
3-
using TimerOutputs: TimerOutput, @timeit, print_timer
41
using NetworkDynamics
52
using Graphs: complete_graph
63

@@ -13,21 +10,11 @@ Base.@propagate_inbounds function diffusionvertex!(dv, _, acc, _, _)
1310
nothing
1411
end
1512

16-
to = TimerOutput();
17-
@timeit to "precompile workload" begin
18-
@timeit to "create graph" begin
19-
g = complete_graph(3)
20-
end
21-
@timeit to "create network" begin
22-
edge = EdgeModel(g=AntiSymmetric(diffusionedge!), outdim=1, pdim=1, pdef=[1])
23-
vert = VertexModel(f=diffusionvertex!, g=1, dim=1, pdim=0)
24-
nd = Network(g, vert, edge)
25-
end
26-
u = rand(dim(nd))
27-
du = similar(u)
28-
p = rand(pdim(nd))
29-
@timeit to "coreloop" begin
30-
nd(du,u,p,0.0)
31-
end
32-
end
33-
is_precompiling() || print_timer(to)
13+
g = complete_graph(3)
14+
edge = EdgeModel(g=AntiSymmetric(diffusionedge!), outdim=1, pdim=1, pdef=[1])
15+
vert = VertexModel(f=diffusionvertex!, g=1, dim=1, pdim=0)
16+
nd = Network(g, vert, edge)
17+
u = rand(dim(nd))
18+
du = similar(u)
19+
p = rand(pdim(nd))
20+
nd(du,u,p,0.0)

0 commit comments

Comments
 (0)