-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from lanl-ansi/linearapprox
Linear Approximation
- Loading branch information
Showing
9 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# 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...) | ||
return run_model( | ||
file, | ||
model_type, | ||
optimizer, | ||
build_ogf_comp_power_and_pipe_proxy; | ||
solution_processors = [ | ||
sol_psqr_to_p!, | ||
sol_compressor_p_to_r!, | ||
sol_regulator_p_to_r!, | ||
], | ||
kwargs..., | ||
) | ||
end | ||
|
||
|
||
"" | ||
function run_soc_ogf_comp_power_and_pipe_proxy(file, optimizer; kwargs...) | ||
return run_ogf_comp_power_and_pipe_proxy(file, CRDWPGasModel, optimizer; kwargs...) | ||
end | ||
|
||
|
||
"" | ||
function run_dwp_ogf_comp_power_and_pipe_proxy(file, optimizer; kwargs...) | ||
return run_ogf_comp_power_and_pipe_proxy(file, DWPGasModel, optimizer; kwargs...) | ||
end | ||
|
||
|
||
"construct the new ogf problem" | ||
function build_ogf_comp_power_and_pipe_proxy(gm::AbstractGasModel) | ||
bounded_compressors = Dict( | ||
x for x in ref(gm, :compressor) if | ||
_calc_is_compressor_energy_bounded( | ||
get_specific_heat_capacity_ratio(gm.data), | ||
get_gas_specific_gravity(gm.data), | ||
get_temperature(gm.data), | ||
x.second | ||
) | ||
) | ||
|
||
variable_pressure(gm) | ||
variable_pressure_sqr(gm) | ||
variable_flow(gm) | ||
variable_on_off_operation(gm) | ||
variable_load_mass_flow(gm) | ||
variable_production_mass_flow(gm) | ||
variable_transfer_mass_flow(gm) | ||
variable_compressor_ratio_sqr(gm) | ||
variable_compressor_minpower_proxy(gm) | ||
variable_storage(gm) | ||
variable_form_specific(gm) | ||
|
||
objective_min_proxy_economic_costs(gm) | ||
|
||
for (i, junction) in ref(gm, :junction) | ||
constraint_mass_flow_balance(gm, i) | ||
|
||
if (junction["junction_type"] == 1) | ||
constraint_pressure(gm, i) | ||
end | ||
end | ||
|
||
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) | ||
end | ||
|
||
for i in ids(gm, :resistor) | ||
constraint_resistor_pressure(gm, i) | ||
constraint_resistor_mass_flow(gm,i) | ||
constraint_resistor_darcy_weisbach(gm,i) | ||
end | ||
|
||
for i in ids(gm, :loss_resistor) | ||
constraint_loss_resistor_pressure(gm, i) | ||
constraint_loss_resistor_mass_flow(gm, i) | ||
end | ||
|
||
for i in ids(gm, :short_pipe) | ||
constraint_short_pipe_pressure(gm, i) | ||
constraint_short_pipe_mass_flow(gm, i) | ||
end | ||
|
||
for i in ids(gm, :compressor) | ||
constraint_compressor_ratios(gm, i) | ||
constraint_compressor_mass_flow(gm, i) | ||
constraint_compressor_ratio_value(gm, i) | ||
constraint_compressor_minpower_proxy(gm, i) | ||
end | ||
|
||
for i in keys(bounded_compressors) | ||
constraint_compressor_energy(gm, i) | ||
end | ||
|
||
for i in ids(gm, :valve) | ||
constraint_on_off_valve_mass_flow(gm, i) | ||
constraint_on_off_valve_pressure(gm, i) | ||
end | ||
|
||
for i in ids(gm, :regulator) | ||
constraint_on_off_regulator_mass_flow(gm, i) | ||
constraint_on_off_regulator_pressure(gm, i) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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)" | ||
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) | ||
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal] | ||
@test isapprox(result["objective"], -230.534; atol = 1e-2) | ||
GasModels.make_si_units!(result["solution"]) | ||
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 100.53; atol = 1e-2) | ||
end | ||
|
||
@testset "case 6 new ogf weymouth lin rel" begin | ||
@info "Testing OGF with compressor power proxy and pipe weymouth proxy" | ||
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) | ||
@test result["termination_status"] in [LOCALLY_SOLVED, ALMOST_LOCALLY_SOLVED, OPTIMAL, :Suboptimal] | ||
@test isapprox(result["objective"], -230.534; atol = 1e-2) | ||
GasModels.make_si_units!(result["solution"]) | ||
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 100.53; 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" | ||
data = GasModels.parse_file("../test/data/matgas/case-6.m") | ||
result = run_ogf_comp_power_and_pipe_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) | ||
GasModels.make_si_units!(result["solution"]) | ||
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 67.01; 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" | ||
data = GasModels.parse_file("../test/data/matgas/case-6-elevation.m") | ||
result = run_ogf_comp_power_and_pipe_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) | ||
GasModels.make_si_units!(result["solution"]) | ||
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 86.33; atol = 1e-2) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,4 @@ | |
@test isapprox(result["solution"]["receipt"]["1"]["fg"], 102.5677; atol = 1e-2) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters