Skip to content

Commit

Permalink
add test58
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Aug 23, 2024
1 parent a5a4e1f commit 0778917
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 5 deletions.
6 changes: 3 additions & 3 deletions test/benchmarks/psse/PIDGOV/ThreeBusMulti.raw
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
102,'BUS 2', 138.0000,2, 1, 1, 1,1.02000, -0.9440,1.10000,0.90000,1.10000,0.90000
103,'BUS 3', 138.0000,1, 1, 1, 1,0.99341, -8.7697,1.10000,0.90000,1.10000,0.90000
0 /End of Bus data, Begin Load data
103,'1 ',1, 1, 1, 250.000, 30.000, 0.000, 0.000, 0.000, 0.000, 1,1,0
103,'1 ',1, 1, 1, 200.000, 30.000, 0.000, 0.000, 0.000, 0.000, 1,1,0
0 /End of Load data, Begin Fixed shunt data
0 /End of Fixed shunt data, Begin Generator data
101,'1 ', 153.335, 73.271, 100.000, -100.000,1.05000, 0, 100.000, 0.00000E+0, 1.00000E-5, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000
102,'1 ', 100.000, -3.247, 100.000, -100.000,1.02000, 0, 100.000, 0.00000E+0, 2.500E-1, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000
101,'1 ', 133.335, 73.271, 100.000, -100.000,1.05000, 0, 100.000, 0.00000E+0, 1.00000E-5, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000
102,'1 ', 70.000, -3.247, 100.000, -100.000,1.02000, 0, 100.000, 0.00000E+0, 2.500E-1, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000
0 /End of Generator data, Begin Branch data
101, 102,'1 ', 1.00000E-2, 1.20000E-1, 0.00000, 250.00, 250.00, 250.00, 0.00000, 0.00000, 0.00000, 0.00000,1,1, 0.00, 1,1.0000
101, 103,'1 ', 1.00000E-2, 1.20000E-1, 0.00000, 250.00, 250.00, 250.00, 0.00000, 0.00000, 0.00000, 0.00000,1,1, 0.00, 1,1.0000
Expand Down
36 changes: 36 additions & 0 deletions test/results/results_eigenvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -935,3 +935,39 @@ test_57_eigvals = [
0.0 + 0.0im,
0.0 + 0.0im,
]

test58_eigvals_PowerFlag = [
-99.99999037034084 + 0.0im
-41.17481961789709 + 0.0im
-38.789855128930164 + 0.0im
-5.647427439841257 + 0.0im
-3.8982943228132214 - 1.5754284098308229im
-3.8982943228132214 + 1.5754284098308229im
-2.000000000000001 + 0.0im
-0.9492553729947647 + 0.0im
-0.8686675700247483 - 8.496111510550772im
-0.8686675700247483 + 8.496111510550772im
-0.28282148961179976 - 1.1097759323927108im
-0.28282148961179976 + 1.1097759323927108im
-0.1975067616652887 - 0.17956822187766im
-0.1975067616652887 + 0.17956822187766im
-0.11697960134622151 + 0.0im
]

test58_eigvals_GateFlag = [
-100.00010646060846 + 0.0im
-41.17482850153586 + 0.0im
-38.789870976223455 + 0.0im
-5.718238174509167 + 0.0im
-3.7935658880265133 + 0.0im
-2.0454156913133885 + 0.0im
-1.9999999999999976 + 0.0im
-1.2228555790477964 - 0.7200047656459937im
-1.2228555790477964 + 0.7200047656459937im
-0.9655206559688869 + 0.0im
-0.9001334037955144 - 8.447836359367825im
-0.9001334037955144 + 8.447836359367825im
-0.19849913626541832 - 0.17939599481963514im
-0.19849913626541832 + 0.17939599481963514im
-0.04238523317744444 + 0.0im
]
60 changes: 60 additions & 0 deletions test/results/results_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1721,3 +1721,63 @@ test_57_x0_init = Dict(
1.0
],
)

test58_x0_init_PowerFlag = Dict(
"V_R" => [
1.05
1.0197944718502572
0.9923907751848658
],
"V_I" => [
0.0
-0.020475233421259967
-0.1243212484458825
],
"generator-102-1" => [
0.7538967192769663
0.5555487379562241
0.7042452148052647
0.7246287886385533
0.9158416020737494
1.0
1.4986692863524897
0.044960078577949814
0.0
0.95
0.95
0.0
0.95
0.95
2.099999999999999
],
)

test58_x0_init_GateFlag = Dict(
"V_R" => [
1.05
1.0197944718502572
0.9923907751848658
],
"V_I" => [
0.0
-0.020475233421259967
-0.1243212484458825
],
"generator-102-1" => [
0.7538967192769663
0.5555487379562241
0.7042452148052647
0.7246287886385533
0.9158416020737494
1.0
1.4986692863524897
0.044960078577949814
0.0
0.95
0.95
0.0
0.95
0.95
2.099999999999999
],
)
202 changes: 200 additions & 2 deletions test/test_case58_pidgov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,203 @@ The fault drop the line connecting the infinite bus and GENROU
############### SOLVE PROBLEM ####################
##################################################

raw_file = joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/ThreeBusMulti.raw")
dyr_file = joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/ThreeBus_PIDGOV_PowerFlag.dyr")
# Define dyr files

names = ["PIDGOV Power Flag", "PIDGOV Gate Flag"]

dyr_files = [
joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/ThreeBus_PIDGOV_PowerFlag.dyr"),
joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/ThreeBus_PIDGOV_GateFlag.dyr"),
]

csv_files = [
joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/PIDGOV_results_PowerFlag.csv"),
joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/PIDGOV_results_GateFlag.csv"),
]

init_conditions = [test58_x0_init_PowerFlag, test58_x0_init_GateFlag]

eigs_values = [test58_eigvals_PowerFlag, test58_eigvals_GateFlag]

raw_file_dir = joinpath(TEST_FILES_DIR, "benchmarks/psse/PIDGOV/ThreeBusMulti.raw")
tspan = (0.0, 20.0)

function test_pidgov_implicit(dyr_file, csv_file, init_cond, eigs_value)
path = (joinpath(pwd(), "test-psse-pidgov"))
!isdir(path) && mkdir(path)
try
sys = System(raw_file_dir, dyr_file)
for l in get_components(PSY.StandardLoad, sys)
transform_load_to_constant_impedance(l)
end

# Define Simulation Problem
sim = Simulation!(
ResidualModel,
sys, #system
path,
tspan, #time span
BranchTrip(1.0, Line, "BUS 1-BUS 2-i_1"), #Type of Fault
) #Type of Fault

# Test Initial Condition
diff_val = [0.0]
res = get_init_values_for_comparison(sim)
for (k, v) in init_cond
diff_val[1] += LinearAlgebra.norm(res[k] - v)
end

@test (diff_val[1] < 1e-3)

# Obtain small signal results for initial conditions. Testing the simulation reset
small_sig = small_signal_analysis(sim)
eigs = small_sig.eigenvalues
@test small_sig.stable

# Test Eigenvalues
@test LinearAlgebra.norm(eigs - eigs_value) < 1e-3

# Solve problem
@test execute!(sim, IDA(); dtmax = 0.005, saveat = 0.005) ==
PSID.SIMULATION_FINALIZED
results = read_results(sim)

# Obtain data for voltage magnitude at bus 102
series = get_voltage_magnitude_series(results, 102)
t = series[1]
V = series[2]
# Test Vf, τm and branch series flows with PSSE
_, P101_103 = get_activepower_branch_flow(results, "BUS 1-BUS 3-i_1", :from)
_, Q101_103 = get_reactivepower_branch_flow(results, "BUS 1-BUS 3-i_1", :from)
_, P103_101 = get_activepower_branch_flow(results, "BUS 1-BUS 3-i_1", :to)
_, Q103_101 = get_reactivepower_branch_flow(results, "BUS 1-BUS 3-i_1", :to)
_, Vf = get_field_voltage_series(results, "generator-102-1")
_, τm = get_mechanical_torque_series(results, "generator-102-1")

# TODO: Get PSSE CSV files and enable tests
#M = get_csv_data(csv_file)
#t_psse = M[:, 1]
#V_psse = M[:, 2]
#P101_103_psse = M[:, 3] ./ 100.0 # convert to pu
#Q101_103_psse = M[:, 4] ./ 100.0 # convert to pu
#P103_101_psse = M[:, 5] ./ 100.0 # convert to pu
#Q103_101_psse = M[:, 6] ./ 100.0 # convert to pu
#Vf_psse = M[:, 7]
#τm_psse = M[:, 8]

# Test Transient Simulation Results
#@test LinearAlgebra.norm(V - V_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(P101_103 - P101_103_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Q101_103 - Q101_103_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(P103_101 - P103_101_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Q103_101 - Q103_101_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Vf - Vf_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(τm - τm_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(t - round.(t_psse, digits = 3)) == 0.0
finally
@info("removing test files")
rm(path; force = true, recursive = true)
end
end

function test_pidgov_mass_matrix(dyr_file, csv_file, init_cond, eigs_value)
path = (joinpath(pwd(), "test-psse-pidgov"))
!isdir(path) && mkdir(path)
try
sys = System(raw_file_dir, dyr_file)
for l in get_components(PSY.StandardLoad, sys)
transform_load_to_constant_impedance(l)
end

# Define Simulation Problem
sim = Simulation!(
MassMatrixModel,
sys, #system
path,
tspan, #time span
BranchTrip(1.0, Line, "BUS 1-BUS 2-i_1"), #Type of Fault
) #Type of Fault

# Test Initial Condition
diff_val = [0.0]
res = get_init_values_for_comparison(sim)
for (k, v) in init_cond
diff_val[1] += LinearAlgebra.norm(res[k] - v)
end

@test (diff_val[1] < 1e-3)

# Obtain small signal results for initial conditions. Testing the simulation reset
small_sig = small_signal_analysis(sim)
eigs = small_sig.eigenvalues
@test small_sig.stable

# Test Eigenvalues
@test LinearAlgebra.norm(eigs - eigs_value) < 1e-3

# Solve problem
@test execute!(sim, Rodas4(); dtmax = 0.005, saveat = 0.005) ==
PSID.SIMULATION_FINALIZED
results = read_results(sim)

# Obtain data for voltage magnitude at bus 102
series = get_voltage_magnitude_series(results, 102)
t = series[1]
V = series[2]
# Test Vf, τm and branch series flows with PSSE
_, P101_103 = get_activepower_branch_flow(results, "BUS 1-BUS 3-i_1", :from)
_, Q101_103 = get_reactivepower_branch_flow(results, "BUS 1-BUS 3-i_1", :from)
_, P103_101 = get_activepower_branch_flow(results, "BUS 1-BUS 3-i_1", :to)
_, Q103_101 = get_reactivepower_branch_flow(results, "BUS 1-BUS 3-i_1", :to)
_, Vf = get_field_voltage_series(results, "generator-102-1")
_, τm = get_mechanical_torque_series(results, "generator-102-1")

# TODO: Get PSSE CSV files and enable tests
#M = get_csv_data(csv_file)
#t_psse = M[:, 1]
#V_psse = M[:, 2]
#P101_103_psse = M[:, 3] ./ 100.0 # convert to pu
#Q101_103_psse = M[:, 4] ./ 100.0 # convert to pu
#P103_101_psse = M[:, 5] ./ 100.0 # convert to pu
#Q103_101_psse = M[:, 6] ./ 100.0 # convert to pu
#Vf_psse = M[:, 7]
#τm_psse = M[:, 8]

# Test Transient Simulation Results
#@test LinearAlgebra.norm(V - V_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(P101_103 - P101_103_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Q101_103 - Q101_103_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(P103_101 - P103_101_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Q103_101 - Q103_101_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(Vf - Vf_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(τm - τm_psse, Inf) <= 1e-2
#@test LinearAlgebra.norm(t - round.(t_psse, digits = 3)) == 0.0
finally
@info("removing test files")
rm(path; force = true, recursive = true)
end
end

@testset "Test 58 PIDGOV ResidualModel" begin
for (ix, name) in enumerate(names)
@testset "$(name)" begin
dyr_file = dyr_files[ix]
csv_file = csv_files[ix]
init_cond = init_conditions[ix]
eigs_value = eigs_values[ix]
test_pidgov_implicit(dyr_file, csv_file, init_cond, eigs_value)
end
end
end

@testset "Test 58 PIDGOV MassMatrixModel" begin
for (ix, name) in enumerate(names)
@testset "$(name)" begin
dyr_file = dyr_files[ix]
csv_file = csv_files[ix]
init_cond = init_conditions[ix]
eigs_value = eigs_values[ix]
test_pidgov_mass_matrix(dyr_file, csv_file, init_cond, eigs_value)
end
end
end

0 comments on commit 0778917

Please sign in to comment.