Skip to content

Commit

Permalink
add test 62 tgsimple
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Sep 20, 2024
1 parent abd4ac3 commit de2ccc4
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/data_tests/dynamic_test_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ tg_type2() = TGTypeII(
(min = 0.1, max = 1.5), #τ_lims
)

tg_simple() = TGSimple(;
d_t = 130.0,
Tm = 0.2,
)

######## AVR Data #########

avr_none() = AVRFixed(0.0)
Expand Down
54 changes: 54 additions & 0 deletions test/data_tests/test62.jl
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)))[:, :]
17 changes: 17 additions & 0 deletions test/results/results_eigenvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1015,3 +1015,20 @@ test61_eigvals = [
-0.3644442941887857 + 0.0im
-0.025119358661025975 + 0.0im
]

test62_eigvals = [
-10459.358851619487 + 0.0im
-9518.115670613777 + 0.0im
-187.2382951105011 + 0.0im
-6.27581492402704 + 0.0im
-4.386996429201749 + 0.0im
-3.411988679439486 + 0.0im
-1.794938559823694 - 18.61457224254591im
-1.794938559823694 + 18.61457224254591im
-0.925460254940432 - 14.645727550143585im
-0.925460254940432 + 14.645727550143585im
-0.8920346522905136 - 0.5103528532335275im
-0.8920346522905136 + 0.5103528532335275im
-0.7855979325597521 - 3.4230121753657374im
-0.7855979325597521 + 3.4230121753657374im
]
31 changes: 31 additions & 0 deletions test/results/results_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1862,3 +1862,34 @@ test61_x0_init = Dict(
0.7941264727636811
],
)

test61_x0_init = Dict(
"V_R" => [
1.02
1.0135824431277969
1.0058149733250097
],
"V_I" => [
0.0
-0.03538744103614196
0.013078586896530407
],
"generator-102-1" => [
1.0767866298987512
0.42832746888394896
0.5202803856576895
1.0
2.41771421082291
1.813285658117182
-0.10879713948703092
1.0142
1.0
],
"generator-103-1" => [
0.8114728517709782
0.6034056242089947
0.859059349494541
1.0
1.7138202875847097
],
)
108 changes: 108 additions & 0 deletions test/test_case62_tgsimple.jl
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

0 comments on commit de2ccc4

Please sign in to comment.