diff --git a/src/post_processing/post_proc_generator.jl b/src/post_processing/post_proc_generator.jl index e9a63b74f..230c6c9d9 100644 --- a/src/post_processing/post_proc_generator.jl +++ b/src/post_processing/post_proc_generator.jl @@ -1116,3 +1116,34 @@ function _mechanical_torque( τm = Pe ./ ω return ts, τm end + +function _mechanical_torque( + tg::PSY.WPIDHY, + name::String, + res::SimulationResults, + dt::Union{Nothing, Float64, Vector{Float64}}, +) + # Get params + D = PSY.get_D(tg) + gate_openings = PSY.get_gate_openings(tg) + power_gate_openings = PSY.get_power_gate_openings(tg) + Tw = PSY.get_Tw(tg) + 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) + Pm = similar(x_g7) + + for (ix, x7) in enumerate(x_g7) + x6 = x_g6[ix] + power_at_gate = + three_level_gate_to_power_map(x6, gate_openings, power_gate_openings) + ll_out, _ = lead_lag(power_at_gate, x7, 1.0, -Tw, Tw / 2.0) + Pm[ix] = ll_out - D * (ω[ix] - ω_ref) + end + τm = Pm ./ ω + return ts, τm +end