Skip to content

Commit

Permalink
fix and test kwargs for simulate (#198)
Browse files Browse the repository at this point in the history
* fix and test kwargs for simulate

* add kwargs to signature
  • Loading branch information
lindnemi authored Jul 22, 2022
1 parent 999b5f8 commit dac55d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/faults/AbstractPerturbation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function simulate(np::AbstractPerturbation, powergrid::PowerGrid, x1::Array, tim
return PowerGridSolution(sol, powergrid)
end

simulate(np::AbstractPerturbation, op::State, timespan) = simulate(np, op.grid, op.vec, timespan)
simulate(np::AbstractPerturbation, powergrid::PowerGrid,op::State, timespan) = simulate(np, powergrid, op.vec, timespan)
simulate(np::AbstractPerturbation, op::State, timespan; solve_kwargs...) = simulate(np, op.grid, op.vec, timespan; solve_kwargs...)
simulate(np::AbstractPerturbation, powergrid::PowerGrid, op::State, timespan; solve_kwargs...) = simulate(np, powergrid, op.vec, timespan; solve_kwargs...)


"Error to be thrown if something goes wrong during power perturbation"
Expand Down
13 changes: 7 additions & 6 deletions test/faults/AbstractPerturbation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ using Graphs: edges, Edge, SimpleGraph
using PowerDynamics: SlackAlgebraic, SwingEqLVS, StaticLine, ChangeInitialConditions, Inc, Dec, simulate, PowerGrid, State, AbstractPerturbation

graph = SimpleGraph(2)
Y = 0 + 5*im
Y = 0 + 5 * im
nodes = [SlackAlgebraic(U=1), SwingEqLVS(H=1, P=-1, D=1, Ω=50, Γ=20, V=1), SwingEqLVS(H=1, P=-1, D=1, Ω=50, Γ=20, V=1)]
lines = [StaticLine(from=e.src, to=e.dst, Y=Y) for e in edges(graph)]
grid = PowerGrid(nodes, lines)
u_Sl,u_Sw1,u_Sw2 = rand(ComplexF64, 3)
u_Sl, u_Sw1, u_Sw2 = rand(ComplexF64, 3)
omega1 = 0.01
omega1_delta = 0.2
state = State(grid, [real(u_Sl), imag(u_Sl), real(u_Sw1), imag(u_Sw1), omega1, real(u_Sw2), imag(u_Sw2), -omega1])

Base.@kwdef struct DummyPerturbation<:AbstractPerturbation
Base.@kwdef struct DummyPerturbation <: AbstractPerturbation
tspan_fault
end

function (dp::DummyPerturbation)(powergrid)
powergrid
end

sol = simulate(DummyPerturbation(tspan_fault=(0.,0.1)),grid,state,(0,0.1))
sol = simulate(DummyPerturbation(tspan_fault=(0.0, 0.1)), grid, state, (0, 0.1); reltol=1e-6)
@test sol !== nothing
@test sol.dqsol.retcode == :Success

sol = simulate(DummyPerturbation(tspan_fault=(0.,0.1)),state,(0,0.1))
sol = simulate(DummyPerturbation(tspan_fault=(0.0, 0.1)), state, (0, 0.1); reltol=1e-6)
@test sol !== nothing
@test sol.dqsol.retcode == :Success
@test sol.dqsol.retcode == :Success

0 comments on commit dac55d0

Please sign in to comment.