Skip to content

Commit a2d796b

Browse files
yasirronijd-lararodrigomha
authored
WIP fix test on missing unique_timestamps (#399)
* fix missing unique_timestamps * explicit missing state * add default true Co-authored-by: Jose Daniel Lara <jdlara@berkeley.edu> * _mechanical_torque unique_timestamps default to true --------- Co-authored-by: Muhammad Yasirroni <yasirroni@users.noreply.github.com> Co-authored-by: Jose Daniel Lara <jdlara@berkeley.edu> Co-authored-by: Rodrigo Henríquez-Auba <rodrigomha@gmail.com>
1 parent e09f4e5 commit a2d796b

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/base/simulation_results.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@ function post_proc_state_series(
7070
)
7171
global_state_index = get_global_index(res)
7272
if !haskey(global_state_index, ref[1])
73-
@error "$(keys(global_state_index))"
74-
error("State $(ref[2]) device $(ref[1]) not found in the system. ")
73+
available_devices = join(keys(global_state_index), ", ")
74+
error("Device $(ref[1]) not found. Available devices: $available_devices")
7575
end
76-
ix = get(global_state_index[ref[1]], ref[2], 0)
76+
77+
state_dict = global_state_index[ref[1]]
78+
if !haskey(state_dict, ref[2])
79+
available_states = join(keys(state_dict), ", ")
80+
error("State $(ref[2]) not found in device $(ref[1]). Available states: $available_states")
81+
end
82+
83+
ix = state_dict[ref[2]]
7784
return _post_proc_state_series(get_solution(res), ix, dt, unique_timestamps)
7885
end
7986

src/post_processing/post_proc_generator.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ function _mechanical_torque(
10561056
name::String,
10571057
res::SimulationResults,
10581058
dt::Union{Nothing, Float64, Vector{Float64}},
1059-
unique_timestamps::Bool,
1059+
unique_timestamps::Bool = true,
10601060
)
10611061
# TODO: This will not plot correctly when changing P_ref in a callback
10621062
ts, _ = _post_proc_state_series(res.solution, 1, dt, unique_timestamps)
@@ -1076,7 +1076,7 @@ function _mechanical_torque(
10761076
name::String,
10771077
res::SimulationResults,
10781078
dt::Union{Nothing, Float64, Vector{Float64}},
1079-
unique_timestamps::Bool,
1079+
unique_timestamps::Bool = true,
10801080
)
10811081
# Get params
10821082
Tc = PSY.get_Tc(tg)
@@ -1105,7 +1105,7 @@ function _mechanical_torque(
11051105
name::String,
11061106
res::SimulationResults,
11071107
dt::Union{Nothing, Float64, Vector{Float64}},
1108-
unique_timestamps::Bool,
1108+
unique_timestamps::Bool = true,
11091109
)
11101110
# TODO: This will not plot correctly when changing P_ref in a callback
11111111
# Get params
@@ -1135,7 +1135,7 @@ function _mechanical_torque(
11351135
name::String,
11361136
res::SimulationResults,
11371137
dt::Union{Nothing, Float64, Vector{Float64}},
1138-
unique_timestamps::Bool,
1138+
unique_timestamps::Bool = true,
11391139
)
11401140
# TODO: This will not plot correctly when changing P_ref in a callback
11411141
# Get params
@@ -1171,7 +1171,7 @@ function _mechanical_torque(
11711171
name::String,
11721172
res::SimulationResults,
11731173
dt::Union{Nothing, Float64, Vector{Float64}},
1174-
unique_timestamps::Bool,
1174+
unique_timestamps::Bool = true,
11751175
)
11761176
# Get params
11771177
D_turb = PSY.get_D_turb(tg)
@@ -1192,7 +1192,7 @@ function _mechanical_torque(
11921192
name::String,
11931193
res::SimulationResults,
11941194
dt::Union{Nothing, Float64},
1195-
unique_timestamps::Bool,
1195+
unique_timestamps::Bool = true,
11961196
)
11971197
ts, x_a3 = post_proc_state_series(res, (name, :x_a3), dt, unique_timestamps)
11981198
return ts, x_a3
@@ -1222,7 +1222,7 @@ function _mechanical_torque(
12221222
name::String,
12231223
res::SimulationResults,
12241224
dt::Union{Nothing, Float64, Vector{Float64}},
1225-
unique_timestamps::Bool,
1225+
unique_timestamps::Bool = true,
12261226
)
12271227
# Get params
12281228
q_nl = PSY.get_q_nl(tg)
@@ -1249,7 +1249,7 @@ function _mechanical_torque(
12491249
name::String,
12501250
res::SimulationResults,
12511251
dt::Union{Nothing, Float64, Vector{Float64}},
1252-
unique_timestamps::Bool,
1252+
unique_timestamps::Bool = true,
12531253
)
12541254
# Get params
12551255
D_turb = PSY.get_D_turb(tg)
@@ -1281,7 +1281,7 @@ function _mechanical_torque(
12811281
name::String,
12821282
res::SimulationResults,
12831283
dt::Union{Nothing, Float64, Vector{Float64}},
1284-
unique_timestamps::Bool,
1284+
unique_timestamps::Bool = true,
12851285
)
12861286
# Get params
12871287
D = PSY.get_D(tg)

0 commit comments

Comments
 (0)