|
1 |
| -is_precompiling() = ccall(:jl_generating_output, Cint, ()) == 1 |
2 |
| - |
3 | 1 | using NetworkDynamics
|
4 | 2 | using ModelingToolkit
|
5 | 3 | using ModelingToolkit: t_nounits as t, D_nounits as Dt
|
6 | 4 |
|
7 | 5 | @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] |
12 | 10 | end
|
13 | 11 | @mtkmodel Swing begin
|
14 | 12 | @components begin
|
15 | 13 | terminal = Terminal()
|
16 | 14 | end
|
17 | 15 | @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) |
21 | 19 | end
|
22 | 20 | @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] |
28 | 26 | end
|
29 | 27 | @equations begin
|
30 | 28 | Dt(θ) ~ ω - ω_ref
|
|
36 | 34 | end
|
37 | 35 | @mtkmodel BusBase begin
|
38 | 36 | @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 |
59 | 41 | end
|
60 | 42 | end
|
61 | 43 | @mtkmodel BusBar begin
|
|
80 | 62 | end
|
81 | 63 | end
|
82 | 64 | @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) |
0 commit comments