Skip to content

Commit

Permalink
Merge pull request #36 from m-bossart/mb/reinitsys
Browse files Browse the repository at this point in the history
solve powerflow and init after changing o.p.
  • Loading branch information
m-bossart authored Dec 13, 2023
2 parents 2806c8d + 53cca11 commit f765418
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/generate_data/Perturbations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,11 @@ function add_surrogate_perturbation!(
load_multiplier_range[1]
Pnew = PSY.get_impedance_active_power(l_new) * multiplier
Qnew = PSY.get_impedance_reactive_power(l_new) * multiplier
push!(psid_perturbations, PSID.LoadChange(time, l_new, :P_ref_impedance, Pnew))
push!(psid_perturbations, PSID.LoadChange(time, l_new, :Q_ref_impedance, Qnew))
psid_perturbation_1 = PSID.LoadChange(time, l_new, :P_ref_impedance, Pnew)
psid_perturbation_2 = PSID.LoadChange(time, l_new, :Q_ref_impedance, Qnew)
@info "Perturbation", psid_perturbation_1, psid_perturbation_2
push!(psid_perturbations, psid_perturbation_1)
push!(psid_perturbations, psid_perturbation_2)
end

###############################################################################
Expand Down Expand Up @@ -533,25 +536,19 @@ function add_surrogate_perturbation!(
sys_aux,
),
)
println(PSY.get_name.(static_injectors))
if length(static_injectors) === 0
@error "Trying to change a dynamic injector but a dynamic injector not found in system"
return
end
s = rand(static_injectors)
s_new = PSY.get_component(typeof(s), sys, PSY.get_name(s))
println(PSY.get_active_power(s_new))
multiplier =
rand() * (P_multiplier_range[2] - P_multiplier_range[1]) + P_multiplier_range[1]
println(multiplier)
Pnew = PSY.get_P_ref(PSY.get_dynamic_injector(s_new)) * multiplier
#Qnew = PSY.get_impedance_reactive_power(l_new) * multiplier
println(
PSID.ControlReferenceChange(time, PSY.get_dynamic_injector(s_new), :P_ref, Pnew),
)
push!(
psid_perturbations,
PSID.ControlReferenceChange(time, PSY.get_dynamic_injector(s_new), :P_ref, Pnew),
)
psid_perturbation =
PSID.ControlReferenceChange(time, PSY.get_dynamic_injector(s_new), :P_ref, Pnew)
@info "Perturbation", psid_perturbation
push!(psid_perturbations, psid_perturbation)
#push!(psid_perturbations, PSID.LoadChange(time, d_new, :Q_ref_impedance, Qnew))
end
2 changes: 2 additions & 0 deletions src/generate_data/datasets/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function generate_surrogate_data(
########################################################################################
sys = deepcopy(sys_main)
update_operating_point!(sys, operating_points[1], sys_aux)
PSID.Simulation!(PSID.MassMatrixModel, sys, pwd(), (0.0, 0.0)) #Run power flow and re-init devices before defining perturbation
psid_perturbations = PSID.Perturbation[]
for p_single in perturbations[1]
add_surrogate_perturbation!(sys, psid_perturbations, p_single, sys_aux)
Expand Down Expand Up @@ -192,6 +193,7 @@ function generate_surrogate_data(
for (ix_p, p) in enumerate(perturbations)
sys = deepcopy(sys_main)
update_operating_point!(sys, o, sys_aux)
PSID.Simulation!(PSID.MassMatrixModel, sys, pwd(), (0.0, 0.0)) #Run power flow and re-init devices before defining perturbation
psid_perturbations = PSID.Perturbation[]
for p_single in p
add_surrogate_perturbation!(sys, psid_perturbations, p_single, sys_aux)
Expand Down

0 comments on commit f765418

Please sign in to comment.