Skip to content

Commit

Permalink
Added one more test for AC flow, comparing against a value calculated…
Browse files Browse the repository at this point in the history
… with other tools.
  • Loading branch information
Mastomaki committed Oct 30, 2023
1 parent 0d45f50 commit 6570fdc
Showing 1 changed file with 92 additions and 3 deletions.
95 changes: 92 additions & 3 deletions test/constraints/constraint_node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function test_constraint_nodal_balance()
end
end

function test_constraint_node_voltage()
function test_node_voltage1()
@testset "constraint_node_voltage" begin

nl_solver_options = Map(["solver", "options"], ["SCS.jl", Map(["verbose"],[0])] )
Expand Down Expand Up @@ -197,7 +197,7 @@ end
function test_constraint_unit_flow_reactive()
@testset "constraint_unit_flow_reactive" begin

nl_solver_options = Map(["solver", "options"], ["SCS.jl", Map(["verbose"],[0])] )
nl_solver_options = Map(["solver", "options"], ["SCS.jl", Map(["verbose", "eps_abs"],[0, 1e-6])] )

#solver_options = unparse_db_value(Map(["Juniper.jl"], [Map(["nl_solver"], ["solver:SCS.jl"])]))
solver_options = unparse_db_value(Map(["Juniper.jl"], [Map(["nl_solver"], [nl_solver_options])]))
Expand Down Expand Up @@ -272,6 +272,94 @@ function test_constraint_unit_flow_reactive()
end
end

"""
Testing the node voltage in AC flow over two connections
"""
function test_node_voltage2()

@testset "acflow1" begin

nl_solver_options = Map(["solver", "options"], ["SCS.jl", Map(["verbose", "eps_abs"],[0, 1e-6])] )

#solver_options = unparse_db_value(Map(["Juniper.jl"], [Map(["nl_solver"], ["solver:SCS.jl"])]))
solver_options = unparse_db_value(Map(["Juniper.jl"], [Map(["nl_solver"], [nl_solver_options])]))

url_in = _test_constraint_node_setup()

objects = [
["connection", "connection_cd"],
["node", "node_d"],
]

object_parameter_values = [
["model", "instance", "db_mip_solver", "Juniper.jl"],
["model", "instance", "db_lp_solver", "Juniper.jl"],
["model", "instance", "db_mip_solver_options", solver_options],
["model", "instance", "db_lp_solver_options", solver_options],
["node", "node_b", "has_voltage", true],
["node", "node_b", "demand_reactive", 0.0],
["node", "node_b", "min_voltage", 0.7],
["node", "node_c", "has_voltage", true],
["node", "node_c", "min_voltage", 0.7],
["node", "node_c", "demand", 0.0],
["node", "node_c", "demand_reactive", 0.2],
["node", "node_d", "has_voltage", true],
["node", "node_d", "min_voltage", 0.7],
["node", "node_d", "demand", 0.0],
["node", "node_d", "demand_reactive", 0.2],
["connection","connection_bc","connection_resistance",0.2],
["connection","connection_bc","connection_reactance",0.2],
["connection","connection_bc","connection_current_max",1.0],
["connection","connection_cd","connection_resistance",0.2],
["connection","connection_cd","connection_reactance",0.2],
["connection","connection_cd","connection_current_max",1.0]

]
relationships = [
["connection__from_node", ["connection_cd", "node_c"]],
["connection__to_node", ["connection_cd", "node_d"]],
["connection__node__node", [ "connection_bc", "node_b", "node_c"]],
["connection__node__node", [ "connection_cd", "node_c", "node_d"]],
["node__temporal_block", ["node_d", "hourly"]],
["node__stochastic_structure", ["node_d", "stochastic"]],

]
relationship_parameter_values = [
["unit__to_node", ["unit_ab", "node_b"], "vom_cost", 10.0],
["unit__to_node", ["unit_ab", "node_b"], "vom_cost_reactive", 20.0],
["connection__node__node",
["connection_bc", "node_b", "node_c"], "connection_has_ac_flow", true],
["connection__node__node",
["connection_cd", "node_c", "node_d"], "connection_has_ac_flow", true]
]

SpineInterface.import_data(
url_in;
objects = objects,
relationships=relationships,
object_parameter_values=object_parameter_values,
relationship_parameter_values=relationship_parameter_values,
)

m = run_spineopt(url_in; log_level=0, optimize=true)

time_slices = time_slice(m; temporal_block=temporal_block(:hourly))

# aliases for the model OPF variables
vsq = m.ext[:spineopt].variables[:node_voltage_squared]

println("voltage")
println(value( vsq[node(:node_b), stochastic_scenario(:parent), time_slices[1]] ) )
println(value( vsq[node(:node_c), stochastic_scenario(:parent), time_slices[1]] ) )
println(value( vsq[node(:node_d), stochastic_scenario(:parent), time_slices[1]] ) )

@test value( vsq[node(:node_d), stochastic_scenario(:parent),
time_slices[1]] ) 0.7302 atol=0.0001
end
end



function test_constraint_nodal_balance_group()
@testset "constraint_nodal_balance_group" begin
url_in = _test_constraint_node_setup()
Expand Down Expand Up @@ -1069,8 +1157,9 @@ end

@testset "node-based constraints" begin
#test_constraint_nodal_balance()
test_constraint_node_voltage()
test_node_voltage1()
test_constraint_unit_flow_reactive()
test_node_voltage2()
#=test_constraint_nodal_balance_group()
test_constraint_node_injection()
test_constraint_node_state_capacity()
Expand Down

0 comments on commit 6570fdc

Please sign in to comment.