|
171 | 171 |
|
172 | 172 | @named piline = DQPiLine()
|
173 | 173 | l = EdgeModel(piline, [:src_u_r, :src_u_i], [:dst_u_r, :dst_u_i], [:src_i_r, :src_i_i], [:dst_i_r, :dst_i_i])
|
| 174 | + |
| 175 | +## test nested model |
| 176 | +@mtkmodel Shaft begin |
| 177 | + @variables begin |
| 178 | + θ(t), [description = "Shaft angle"] |
| 179 | + ω(t), [description = "Shaft speed"] |
| 180 | + Pmech(t), [description = "Mechanical Power"] |
| 181 | + Pel(t), [description = "Electrical Power"] |
| 182 | + end |
| 183 | + @parameters begin |
| 184 | + M = 1, [description = "Inertia"] |
| 185 | + D = 0.1, [description = "Friction Damping"] |
| 186 | + end |
| 187 | + @equations begin |
| 188 | + Dt(θ) ~ ω |
| 189 | + Dt(ω) ~ 1/M * (Pmech - D*ω + Pel) |
| 190 | + end |
| 191 | +end |
| 192 | + |
| 193 | +@mtkmodel Gov begin |
| 194 | + @variables begin |
| 195 | + Pmech(t), [description = "Mechanical Power"] |
| 196 | + ω_meas(t),[description = "Measured Rotor Frequency"] |
| 197 | + end |
| 198 | + @parameters begin |
| 199 | + D = 0.1, [description = "Governor Droop"] |
| 200 | + Pref = 1.0, [description = "Reference Power"] |
| 201 | + end |
| 202 | + @equations begin |
| 203 | + Pmech ~ Pref - D*ω_meas |
| 204 | + end |
| 205 | +end |
| 206 | + |
| 207 | +@mtkmodel NestedSwing begin |
| 208 | + @components begin |
| 209 | + shaft = Shaft() |
| 210 | + gov = Gov() |
| 211 | + end |
| 212 | + @variables begin |
| 213 | + u_r(t), [description = "d-voltage", output=true] |
| 214 | + u_i(t), [description = "q-voltage", output=true] |
| 215 | + i_r(t), [description = "d-current", input=true] |
| 216 | + i_i(t), [description = "d-current", input=true] |
| 217 | + end |
| 218 | + @parameters begin |
| 219 | + V = 1.0, [description = "Voltage magnitude"] |
| 220 | + end |
| 221 | + @equations begin |
| 222 | + shaft.Pel ~ real((u_r + im*u_i) * (i_r - im*i_i)) |
| 223 | + gov.ω_meas ~ shaft.ω |
| 224 | + gov.Pmech ~ shaft.Pmech |
| 225 | + u_r ~ V*cos(shaft.θ) |
| 226 | + u_i ~ V*sin(shaft.θ) |
| 227 | + end |
| 228 | +end |
| 229 | + |
| 230 | +@named nestedswing = NestedSwing() |
| 231 | +v = VertexModel(nestedswing, [:i_r, :i_i], [:u_r, :u_i]) |
| 232 | +@test v.mass_matrix == Diagonal([1,1]) |
| 233 | +data = NetworkDynamics.rand_inputs_fg(v) |
| 234 | +b = @b $(NetworkDynamics.compfg(v))($data...) |
| 235 | +@test b.allocs == 0 |
0 commit comments