Skip to content

Commit

Permalink
add degov1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Sep 20, 2024
1 parent 6ce7cce commit 3200883
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/benchmarks/psse/DEGOV1/ThreeBusMulti.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
0, 100.00, 33, 0, 0, 60.00 / PSS(R)E 33 RAW created by rawd33 TUE, JUL 21 2020 17:55


101,'BUS 1', 138.0000,3, 1, 1, 1,1.05000, 0.0000,1.10000,0.90000,1.10000,0.90000
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
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
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
102, 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
0 /End of Branch data, Begin Transformer data
0 /End of Transformer data, Begin Area interchange data
0 /End of Area interchange data, Begin Two-terminal dc line data
0 /End of Two-terminal dc line data, Begin VSC dc line data
0 /End of VSC dc line data, Begin Impedance correction table data
0 /End of Impedance correction table data, Begin Multi-terminal dc line data
0 /End of Multi-terminal dc line data, Begin Multi-section line data
0 /End of Multi-section line data, Begin Zone data
0 /End of Zone data, Begin Inter-area transfer data
0 /End of Inter-area transfer data, Begin Owner data
0 /End of Owner data, Begin FACTS device data
0 /End of FACTS device data, Begin Switched shunt data
0 /End of Switched shunt data, Begin GNE device data
0 /End of GNE device data, Begin Induction machine data
0 /End of Induction machine data
Q
7 changes: 7 additions & 0 deletions test/benchmarks/psse/DEGOV1/ThreeBus_DEGOV1_nodelay_flag0.dyr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
101 'GENCLS' 1 0 0 /
102 'GENROU' 1 8.0000 0.30000E-01 0.40000 0.50000E-01
6.1750 0.50000E-01 1.8000 1.7000 0.30000
0.55000 0.25000 0.20000 0.10000 0.80000 /
102 'DEGOV1' 1 0 0.19050 0.47600E-01 0.18000E-01
1.0000 5.1000 0.32200 0.0000 0.0000
99.99 -99.99 0.70000E-01 0.50000E-01 /
7 changes: 7 additions & 0 deletions test/benchmarks/psse/DEGOV1/ThreeBus_DEGOV1_nodelay_flag1.dyr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
101 'GENCLS' 1 0 0 /
102 'GENROU' 1 8.0000 0.30000E-01 0.40000 0.50000E-01
6.1750 0.50000E-01 1.8000 1.7000 0.30000
0.55000 0.25000 0.20000 0.10000 0.80000 /
102 'DEGOV1' 1 1 0.19050 0.47600E-01 0.18000E-01
1.0000 5.1000 0.32200 0.0000 0.0000
99.99 -99.99 0.70000E-01 0.50000E-01 /
27 changes: 27 additions & 0 deletions test/results/results_eigenvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,30 @@ test62_eigvals = [
-0.7855979325597521 - 3.4230121753657374im
-0.7855979325597521 + 3.4230121753657374im
]

test63_eigvals_Flag0 = [
-39.22517856531171 - 0.23706643304840616im
-39.22517856531171 + 0.23706643304840616im
-13.403547886572664 + 0.0im
-8.122746726423252 + 0.0im
-5.391500486820183 - 2.241842433737118im
-5.391500486820183 + 2.241842433737118im
-0.6466138560537371 - 8.624155441599354im
-0.6466138560537371 + 8.624155441599354im
-0.20824914641735212 + 0.0im
-0.05243031034640425 + 0.0im
]

test63_eigvals_Flag1 = [
-39.224926800052884 - 0.23735163098908485im
-39.224926800052884 + 0.23735163098908485im
-19.85028250949885 + 0.0im
-13.323569303234533 + 0.0im
-7.521736802553002 + 0.0im
-5.905690613400367 - 2.3710175079240416im
-5.905690613400367 + 2.3710175079240416im
-0.5479840603712405 - 8.276315089713018im
-0.5479840603712405 + 8.276315089713018im
-0.2082414387220071 + 0.0im
-0.05252688447358956 + 0.0im
]
53 changes: 53 additions & 0 deletions test/results/results_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1893,3 +1893,56 @@ test62_x0_init = Dict(
1.7138202875847097
],
)

test63_x0_init_Flag0 = Dict(
"V_R" => [
1.05
1.0198615749401696
0.9817964461177487
],
"V_I" => [
0.0
-0.01680380791834505
-0.15145839832533242
],
"generator-102-1" => [
0.8084146853601003
0.5302614530689579
0.7288775579091269
0.7311890654084042
0.9615873122791482
1.0
0.0
0.0
0.0
0.0
0.9999999999999999
],
)

test63_x0_init_Flag1 = Dict(
"V_R" => [
1.05
1.0198615749401696
0.9817964461177487
],
"V_I" => [
0.0
-0.01680380791834505
-0.15145839832533242
],
"generator-102-1" => [
0.8084146853601003
0.5302614530689579
0.7288775579091269
0.7311890654084042
0.9615873122791482
1.0
0.0
0.0
0.0
0.0
0.9999999999999999
0.9999999999999999
],
)
208 changes: 208 additions & 0 deletions test/test_case63_degov1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
"""
Validation PSSE/PIDGOV:
This case study defines a three bus system with an infinite bus, GENROU+DEGOV1 and a load.
The fault drop the line connecting the infinite bus and GENROU
"""

##################################################
############### SOLVE PROBLEM ####################
##################################################

# Define dyr files

names = ["DEGOV1 MechTorque Flag", "DEGOV1 ElecTorque Flag"]

dyr_files = [
joinpath(TEST_FILES_DIR, "benchmarks/psse/DEGOV1/ThreeBus_DEGOV1_nodelay_flag0.dyr"),
joinpath(TEST_FILES_DIR, "benchmarks/psse/DEGOV1/ThreeBus_DEGOV1_nodelay_flag1.dyr"),
]

csv_files = [
joinpath(TEST_FILES_DIR, "benchmarks/psse/DEGOV1/DEGOV1_results_nodelay_flag0.csv"),
joinpath(TEST_FILES_DIR, "benchmarks/psse/DEGOV1/DEGOV1_results_nodelay_flag0.csv"),
]

init_conditions = [test63_x0_init_Flag0, test63_x0_init_Flag1]

eigs_values = [test63_eigvals_Flag0, test63_eigvals_Flag1]

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

function test_degov1_implicit(dyr_file, csv_file, init_cond, eigs_value)
path = (joinpath(pwd(), "test-psse-degov1"))
!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)
_, τ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_degov1_mass_matrix(dyr_file, csv_file, init_cond, eigs_value)
path = (joinpath(pwd(), "test-psse-degov1"))
!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)
_, τ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 63 DEGOV1 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_degov1_implicit(dyr_file, csv_file, init_cond, eigs_value)
end
end
end

@testset "Test 63 DEGOV1 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_degov1_mass_matrix(dyr_file, csv_file, init_cond, eigs_value)
end
end
end

0 comments on commit 3200883

Please sign in to comment.