-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abd4ac3
commit de2ccc4
Showing
5 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using PowerSystems | ||
using NLsolve | ||
const PSY = PowerSystems | ||
|
||
############### Data Network ######################## | ||
include(joinpath(dirname(@__FILE__), "dynamic_test_data.jl")) | ||
|
||
############### Data Network ######################## | ||
threebus_file_dir = joinpath(dirname(@__FILE__), "ThreeBusNetwork.raw") | ||
threebus_sys = System(threebus_file_dir; runchecks = false) | ||
add_source_to_ref(threebus_sys) | ||
|
||
function dyn_gen_tg_simple(generator) | ||
return PSY.DynamicGenerator(; | ||
name = get_name(generator), #static generator | ||
ω_ref = 1.0, # ω_ref | ||
machine = machine_oneDoneQ(), #machine | ||
shaft = shaft_no_damping(), #shaft | ||
avr = avr_type2(), #avr | ||
prime_mover = tg_simple(), #tg | ||
pss = pss_none(), | ||
) #pss | ||
end | ||
|
||
function dyn_gen_simple_avr(generator) | ||
return PSY.DynamicGenerator(; | ||
name = get_name(generator), #static generator | ||
ω_ref = 1.0, # ω_ref | ||
machine = machine_oneDoneQ(), #machine | ||
shaft = shaft_no_damping(), #shaft | ||
avr = avr_propr(), #avr | ||
prime_mover = tg_none(), #tg | ||
pss = pss_none(), | ||
) #pss | ||
end | ||
|
||
for l in get_components(PSY.StandardLoad, threebus_sys) | ||
transform_load_to_constant_impedance(l) | ||
end | ||
|
||
# Add dynamic generators to the system (each gen is linked through a static one) | ||
for g in get_components(Generator, threebus_sys) | ||
if get_number(get_bus(g)) == 102 | ||
case_gen = dyn_gen_tg_simple(g) | ||
add_component!(threebus_sys, case_gen, g) | ||
elseif get_number(get_bus(g)) == 103 | ||
case_gen = dyn_gen_simple_avr(g) | ||
add_component!(threebus_sys, case_gen, g) | ||
end | ||
end | ||
|
||
#Compute Y_bus after fault | ||
fault_branches = deepcopy(collect(get_components(Branch, threebus_sys))[2:end]) | ||
Ybus_fault = PNM.Ybus(fault_branches, collect(get_components(ACBus, threebus_sys)))[:, :] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
""" | ||
Case 62: | ||
This case study a three bus system with 2 machines (One d- One q-: 4th order model) and an infinite source. | ||
The case is similar to case 13, with different AVR and TG models. | ||
""" | ||
|
||
################################################## | ||
############### LOAD DATA ######################## | ||
################################################## | ||
|
||
include(joinpath(TEST_FILES_DIR, "data_tests/test62.jl")) | ||
|
||
################################################## | ||
############### SOLVE PROBLEM #################### | ||
################################################## | ||
|
||
# Time span | ||
tspan = (0.0, 20.0) | ||
|
||
#Define Fault: Change of YBus | ||
Ybus_change = NetworkSwitch( | ||
1.0, #change at t = 1.0 | ||
Ybus_fault, | ||
) #New YBus | ||
|
||
@testset "Test 13 AVR ResidualModel" begin | ||
path = mktempdir() | ||
try | ||
# Define Simulation Problem | ||
sim = Simulation( | ||
ResidualModel, | ||
threebus_sys, #system, | ||
path, | ||
tspan, #time span | ||
Ybus_change, #Type of Fault | ||
) | ||
|
||
# Test Initial Condition | ||
diff_val = [0.0] | ||
res = get_init_values_for_comparison(sim) | ||
for (k, v) in test62_x0_init | ||
diff_val[1] += LinearAlgebra.norm(res[k] - v) | ||
end | ||
|
||
@test (diff_val[1] < 1e-3) | ||
|
||
# Obtain small signal results for initial conditions | ||
small_sig = small_signal_analysis(sim) | ||
eigs = small_sig.eigenvalues | ||
@test small_sig.stable | ||
|
||
# Test Eigenvalues | ||
@test LinearAlgebra.norm(eigs - test62_eigvals) < 1e-3 | ||
|
||
#Solve problem | ||
@test execute!(sim, IDA(); dtmax = 0.02) == PSID.SIMULATION_FINALIZED | ||
results = read_results(sim) | ||
|
||
#Obtain data for angles | ||
series = get_state_series(results, ("generator-102-1", :δ)) | ||
series2 = get_mechanical_torque_series(results, "generator-102-1") | ||
finally | ||
@info("removing test files") | ||
rm(path; force = true, recursive = true) | ||
end | ||
end | ||
|
||
@testset "Test 13 AVR MassMarixcModel" begin | ||
path = mktempdir() | ||
try | ||
# Define Simulation Problem | ||
sim = Simulation( | ||
MassMatrixModel, | ||
threebus_sys, #system, | ||
path, | ||
tspan, #time span | ||
Ybus_change, #Type of Fault | ||
) | ||
|
||
# Test Initial Condition | ||
diff_val = [0.0] | ||
res = get_init_values_for_comparison(sim) | ||
for (k, v) in test62_x0_init | ||
diff_val[1] += LinearAlgebra.norm(res[k] - v) | ||
end | ||
|
||
@test (diff_val[1] < 1e-3) | ||
|
||
# Obtain small signal results for initial conditions | ||
small_sig = small_signal_analysis(sim) | ||
eigs = small_sig.eigenvalues | ||
@test small_sig.stable | ||
|
||
# Test Eigenvalues | ||
@test LinearAlgebra.norm(eigs - test62_eigvals) < 1e-3 | ||
|
||
#Solve problem | ||
@test execute!(sim, Rodas4(); dtmax = 0.02) == PSID.SIMULATION_FINALIZED | ||
results = read_results(sim) | ||
|
||
#Obtain data for angles | ||
series = get_state_series(results, ("generator-102-1", :δ)) | ||
series2 = get_mechanical_torque_series(results, "generator-102-1") | ||
finally | ||
@info("removing test files") | ||
rm(path; force = true, recursive = true) | ||
end | ||
end |