Skip to content

Commit

Permalink
Revert "Pipe approximation constraint and new problem"
Browse files Browse the repository at this point in the history
This reverts commit 4ca98ac.
  • Loading branch information
hskkanth committed Apr 24, 2024
1 parent 7e45742 commit 6802e25
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/GasModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module GasModels
include("prob/ls.jl")
include("prob/nels.jl")
include("prob/ogf.jl")
include("prob/ogf_comp_power_and_pipe_proxy.jl")
include("prob/ogf_comp_power_proxy.jl")
include("prob/transient_ogf.jl")
include("prob/transient_ogf_archived_storage.jl")

Expand Down
16 changes: 0 additions & 16 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@ end
#################################################################################################
# Constraints associated with pipes
#################################################################################################
"Constraint: Linear approximation for Weymouth equation"
function constraint_pipe_weymouth_linear_approx(gm::AbstractGasModel, n::Int, k, i, j, f_min, f_max, w, pd_min, pd_max)
pi = var(gm, n, :psqr, i)
pj = var(gm, n, :psqr, j)
f = var(gm, n, :f_pipe, k)

slope = max(abs(f_max),abs(f_min))
if w == 0.0
_add_constraint!(gm, n, :weymouth1, k, JuMP.@constraint(gm.model, (pi - pj) == 0.0))
elseif f_min == f_max
_add_constraint!(gm, n, :weymouth1, k, JuMP.@constraint(gm.model, w * (pi - pj) == f_min))
else
_add_constraint!(gm, n, :weymouth1, k, JuMP.@constraint(gm.model, w * (pi - pj) == slope*f))
end

end

"Constraint: on/off constraints on flow across pipes for expansion pipes"
function constraint_pipe_ne(gm::AbstractGasModel, n::Int, k, w, f_min, f_max)
Expand Down
22 changes: 0 additions & 22 deletions src/core/constraint_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,6 @@ function constraint_pipe_weymouth(gm::AbstractGasModel, k; n::Int = nw_id_defaul
end
end

"Template: Weymouth equation for defining the relationship between pressure drop and flow across a pipe"
function constraint_pipe_weymouth_linear_approx(gm::AbstractGasModel, k; n::Int = nw_id_default)
pipe = ref(gm, n, :pipe, k)
i = pipe["fr_junction"]
j = pipe["to_junction"]
pd_min, pd_max = _calc_pipe_pd_bounds_sqr(pipe, ref(gm, n, :junction, i), ref(gm, n, :junction, j))
f_min = pipe["flow_min"]
f_max = pipe["flow_max"]
theta = pipe["theta"]
D = pipe["diameter"]

if(D!=0.0)
if(rad2deg(abs(theta)) <= 5)
w = _calc_pipe_resistance(pipe, gm.ref[:it][gm_it_sym][:base_length], gm.ref[:it][gm_it_sym][:base_pressure], gm.ref[:it][gm_it_sym][:base_flow], gm.ref[:it][gm_it_sym][:sound_speed])
constraint_pipe_weymouth_linear_approx(gm, n, k, i, j, f_min, f_max, w, pd_min, pd_max)
else
r_1,r_2 = _calc_inclined_pipe_resistance(pipe,gm.ref[:it][gm_it_sym][:base_length], gm.ref[:it][gm_it_sym][:base_pressure], gm.ref[:it][gm_it_sym][:base_flow], gm.ref[:it][gm_it_sym][:sound_speed])
constraint_inclined_pipe_pressure_drop(gm, n, k, i, j, r_1, r_2)
end
end
end


"Template: Constraint associatd with turning off flow depending on the status of expansion pipes"
function constraint_pipe_ne(gm::AbstractGasModel, k; n::Int = nw_id_default)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Definitions for running the new optimal gas flow (ogf) (with a proxy compressor power term in the objective)

"entry point into running the new ogf problem"
function run_ogf_comp_power_and_pipe_proxy(file, model_type, optimizer; kwargs...)
function run_ogf_comp_power_proxy(file, model_type, optimizer; kwargs...)
return run_model(
file,
model_type,
optimizer,
build_ogf_comp_power_and_pipe_proxy;
build_ogf_comp_power_proxy;
solution_processors = [
sol_psqr_to_p!,
sol_compressor_p_to_r!,
Expand All @@ -19,18 +19,18 @@ end

""
function run_soc_new_ogf(file, optimizer; kwargs...)
return run_ogf_comp_power_and_pipe_proxy(file, CRDWPGasModel, optimizer; kwargs...)
return run_ogf_comp_power_proxy(file, CRDWPGasModel, optimizer; kwargs...)
end


""
function run_dwp_new_ogf(file, optimizer; kwargs...)
return run_ogf_comp_power_and_pipe_proxy(file, DWPGasModel, optimizer; kwargs...)
return run_ogf_comp_power_proxy(file, DWPGasModel, optimizer; kwargs...)
end


"construct the new ogf problem"
function build_ogf_comp_power_and_pipe_proxy(gm::AbstractGasModel)
function build_ogf_comp_power_proxy(gm::AbstractGasModel)
bounded_compressors = Dict(
x for x in ref(gm, :compressor) if
_calc_is_compressor_energy_bounded(
Expand Down Expand Up @@ -66,8 +66,7 @@ function build_ogf_comp_power_and_pipe_proxy(gm::AbstractGasModel)
for i in ids(gm, :pipe)
constraint_pipe_pressure(gm, i)
constraint_pipe_mass_flow(gm, i)
# constraint_pipe_weymouth(gm, i)
constraint_pipe_weymouth_linear_approx(gm, i)
constraint_pipe_weymouth(gm, i)
end

for i in ids(gm, :resistor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
@testset "test new ogf" begin
@testset "test wp new ogf" begin
@testset "case 6 new ogf" begin
@info "Testing OGF with compressor power and pipe weymouth proxy (linear)"
@info "Testing OGF with compressor power proxy (linear)"
data = GasModels.parse_file("../test/data/matgas/case-6-no-power-limits.m")
result = run_ogf_comp_power_and_pipe_proxy(data, WPGasModel, nlp_solver)
result = run_ogf_comp_power_proxy(data, WPGasModel, nlp_solver)
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal]
@test isapprox(result["objective"], -230.534; atol = 1e-2)
@test isapprox(result["objective"], -253.683; atol = 1e-2)
GasModels.make_si_units!(result["solution"])
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 100.53; atol = 1e-2)
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 123.6822; atol = 1e-2)
end

@testset "case 6 new ogf weymouth lin rel" begin
@info "Testing OGF with compressor power proxy and pipe weymouth proxy"
@info "Testing OGF with compressor power proxy Linear Relaxation of Pipe Weymouth Physics"
data = GasModels.parse_file("../test/data/matgas/case-6-no-power-limits.m")
result = run_ogf_comp_power_and_pipe_proxy(data, LRWPGasModel, lp_solver)
result = run_ogf_comp_power_proxy(data, LRWPGasModel, lp_solver)
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal]
@test isapprox(result["objective"], -230.534; atol = 1e-2)
@test isapprox(result["objective"], -260.00; atol = 1e-2)
GasModels.make_si_units!(result["solution"])
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 100.53; atol = 1e-2)
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 130.00; atol = 1e-2)
end


@testset "case 6 wp new ogf binding energy constraint" begin
@info "Testing OGF with compressor power and pipe weymouth proxy Binding Energy Cosntraint"
@info "Testing OGF with compressor power proxy Binding Energy Cosntraint"
data = GasModels.parse_file("../test/data/matgas/case-6.m")
result = run_ogf_comp_power_and_pipe_proxy(data, WPGasModel, nlp_solver)
result = run_ogf_comp_power_proxy(data, WPGasModel, nlp_solver)
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal]
@test isapprox(result["objective"], -187.253; atol = 1e-2)
@test isapprox(result["objective"], -237.718; atol = 1e-2)
GasModels.make_si_units!(result["solution"])
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 67.01; atol = 1e-2)
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 97.33; atol = 1e-2)
end

@testset "case 6 wp new ogf elevation constraint" begin
@info "Testing OGF with compressor power and pipe weymouth proxy Elevation Cosntraint"
@info "Testing OGF with compressor power proxy Elevation Cosntraint"
data = GasModels.parse_file("../test/data/matgas/case-6-elevation.m")
result = run_ogf_comp_power_and_pipe_proxy(data, WPGasModel, nlp_solver)
result = run_ogf_comp_power_proxy(data, WPGasModel, nlp_solver)
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal]
@test isapprox(result["objective"], -219.461; atol = 1e-2)
@test isapprox(result["objective"], -245.251; atol = 1e-2)
GasModels.make_si_units!(result["solution"])
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 86.33; atol = 1e-2)
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 102.5677; atol = 1e-2)
end
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ include("common.jl")

include("ogf.jl")

include("ogf_comp_power_and_pipe_proxy.jl")
include("ogf_comp_power_proxy.jl")

include("ls.jl")

Expand Down

0 comments on commit 6802e25

Please sign in to comment.