Skip to content

WIP fix test on missing unique_timestamps #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/base/simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ function post_proc_state_series(
)
global_state_index = get_global_index(res)
if !haskey(global_state_index, ref[1])
@error "$(keys(global_state_index))"
error("State $(ref[2]) device $(ref[1]) not found in the system. ")
available_devices = join(keys(global_state_index), ", ")
error("Device $(ref[1]) not found. Available devices: $available_devices")
end
ix = get(global_state_index[ref[1]], ref[2], 0)

state_dict = global_state_index[ref[1]]
if !haskey(state_dict, ref[2])
available_states = join(keys(state_dict), ", ")
error("State $(ref[2]) not found in device $(ref[1]). Available states: $available_states")
end

ix = state_dict[ref[2]]
return _post_proc_state_series(get_solution(res), ix, dt, unique_timestamps)
end

Expand Down
27 changes: 15 additions & 12 deletions src/post_processing/post_proc_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
ts, _ = _post_proc_state_series(res.solution, 1, dt, unique_timestamps)
Expand All @@ -1038,7 +1038,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
Tc = PSY.get_Tc(tg)
Expand Down Expand Up @@ -1067,7 +1067,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
# Get params
Expand Down Expand Up @@ -1097,7 +1097,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
# Get params
Expand Down Expand Up @@ -1133,7 +1133,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
D_turb = PSY.get_D_turb(tg)
Expand All @@ -1154,6 +1154,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64},
unique_timestamps::Bool = true,
)
ts, x_a3 = post_proc_state_series(res, (name, :x_a3), dt, unique_timestamps)
return ts, x_a3
Expand All @@ -1167,7 +1168,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
q_nl = PSY.get_q_nl(tg)
Expand All @@ -1194,6 +1195,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool = true,
)
# Get params
D_turb = PSY.get_D_turb(tg)
Expand All @@ -1204,9 +1206,9 @@ function _mechanical_torque(
setpoints = get_setpoints(res)
ω_ref = setpoints[name]["ω_ref"]
# Get state results
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt)
_, ω = post_proc_state_series(res, (name, :ω), dt)
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt, unique_timestamps)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt, unique_timestamps)
_, ω = post_proc_state_series(res, (name, :ω), dt, unique_timestamps)
Pe = similar(x_g7)
for (ix, x7) in enumerate(x_g7)
x6 = x_g6[ix]
Expand All @@ -1225,6 +1227,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool = true,
)
# Get params
D = PSY.get_D(tg)
Expand All @@ -1235,9 +1238,9 @@ function _mechanical_torque(
ω_ref = setpoints[name]["ω_ref"]

# Get state results
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt)
_, ω = post_proc_state_series(res, (name, :ω), dt)
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt, unique_timestamps)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt, unique_timestamps)
_, ω = post_proc_state_series(res, (name, :ω), dt, unique_timestamps)
Pm = similar(x_g7)

for (ix, x7) in enumerate(x_g7)
Expand Down