-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expansion data file and model for expansion pumps #154
base: v0.10-cleanup
Are you sure you want to change the base?
Changes from 1 commit
61accbb
7d6d45e
aa17241
6f4dcfc
47a6f1d
48cb3e2
f0529dc
c12702f
e47ced8
88e9280
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,17 +72,19 @@ function _check_connectivity(data::Dict{String,<:Any}) | |
end | ||
|
||
for comp_type in _LINK_COMPONENTS | ||
for (i, comp) in data[comp_type] | ||
if !(comp["node_fr"] in node_ids) | ||
error_message = "From node $(comp["node_fr"]) in " | ||
error_message *= "$(replace(comp_type, "_" => " ")) $(i) is not defined." | ||
Memento.error(_LOGGER, error_message) | ||
end | ||
if(haskey(data,comp_type)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for (i, comp) in data[comp_type] | ||
if !(comp["node_fr"] in node_ids) | ||
error_message = "From node $(comp["node_fr"]) in " | ||
error_message *= "$(replace(comp_type, "_" => " ")) $(i) is not defined." | ||
Memento.error(_LOGGER, error_message) | ||
end | ||
|
||
if !(comp["node_to"] in node_ids) | ||
error_message = "To node $(comp["node_to"]) in " | ||
error_message *= "$(replace(comp_type, "_" => " ")) $(i) is not defined." | ||
Memento.error(_LOGGER, error_message) | ||
if !(comp["node_to"] in node_ids) | ||
error_message = "To node $(comp["node_to"]) in " | ||
error_message *= "$(replace(comp_type, "_" => " ")) $(i) is not defined." | ||
Memento.error(_LOGGER, error_message) | ||
end | ||
end | ||
end | ||
end | ||
|
@@ -112,17 +114,19 @@ function _check_status(data::Dict{String,<:Any}) | |
end | ||
|
||
for comp_type in _LINK_COMPONENTS | ||
for (i, comp) in data[comp_type] | ||
if comp["status"] != STATUS_INACTIVE && !(comp["node_fr"] in active_node_ids) | ||
warning_message = "Active $(comp_type) $(i) is connected to inactive " | ||
warning_message *= "from node $(comp["node_fr"])." | ||
Memento.warn(_LOGGER, warning_message) | ||
end | ||
if(haskey(data,comp_type)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here concerning the |
||
for (i, comp) in data[comp_type] | ||
if comp["status"] != STATUS_INACTIVE && !(comp["node_fr"] in active_node_ids) | ||
warning_message = "Active $(comp_type) $(i) is connected to inactive " | ||
warning_message *= "from node $(comp["node_fr"])." | ||
Memento.warn(_LOGGER, warning_message) | ||
end | ||
|
||
if comp["status"] != STATUS_INACTIVE && !(comp["node_to"] in active_node_ids) | ||
warning_message = "Active $(comp_type) $(i) is connected to inactive " | ||
warning_message *= "to node $(comp["node_to"])." | ||
Memento.warn(_LOGGER, warning_message) | ||
if comp["status"] != STATUS_INACTIVE && !(comp["node_to"] in active_node_ids) | ||
warning_message = "Active $(comp_type) $(i) is connected to inactive " | ||
warning_message *= "to node $(comp["node_to"])." | ||
Memento.warn(_LOGGER, warning_message) | ||
end | ||
end | ||
end | ||
end | ||
|
@@ -512,6 +516,14 @@ function _calc_head_max(data::Dict{String, <:Any}) | |
head_max = max(head_max, node_to["elevation"] + head_gain) | ||
end | ||
|
||
for (i, pump) in wm_data["ne_pump"] | ||
# Consider possible pump head gains in computation of head_max. | ||
node_fr = wm_data["node"][string(pump["node_fr"])] | ||
node_to = wm_data["node"][string(pump["node_to"])] | ||
head_gain = _calc_pump_head_gain_max(pump, node_fr, node_to) | ||
head_max = max(head_max, node_to["elevation"] + head_gain) | ||
end | ||
|
||
for (i, regulator) in wm_data["regulator"] | ||
# Consider possible downstream regulator heads in computation of head_max. | ||
p_setting, node_to_index = regulator["setting"], string(regulator["node_to"]) | ||
|
@@ -1023,7 +1035,7 @@ end | |
|
||
function _apply_pipe_unit_transform!(data::Dict{String,<:Any}, transform_length::Function, head_loss::String) | ||
wm_data = get_wm_data(data) | ||
|
||
if !haskey(wm_data, "pipe") | ||
return | ||
end | ||
|
@@ -1139,6 +1151,78 @@ function _apply_pump_unit_transform!( | |
end | ||
end | ||
|
||
function _apply_ne_pump_unit_transform!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there additional constants associated with network expansion, here, that need to be scaled? For example, construction cost? |
||
data::Dict{String,<:Any}, transform_mass::Function, transform_flow::Function, | ||
transform_length::Function, transform_time::Function) | ||
wm_data = get_wm_data(data) | ||
|
||
if !haskey(wm_data, "ne_pump") | ||
return | ||
end | ||
|
||
power_scalar = transform_mass(1.0) * transform_length(1.0)^2 / transform_time(1.0)^3 | ||
energy_scalar = transform_mass(1.0) * transform_length(1.0)^2 / transform_time(1.0)^2 | ||
|
||
for (_, ne_pump) in wm_data["ne_pump"] | ||
if haskey(ne_pump, "head_curve") | ||
ne_pump["head_curve"] = [(transform_flow(x[1]), x[2]) for x in ne_pump["head_curve"]] | ||
ne_pump["head_curve"] = [(x[1], transform_length(x[2])) for x in ne_pump["head_curve"]] | ||
end | ||
|
||
if haskey(ne_pump, "efficiency_curve") | ||
ne_pump["efficiency_curve"] = [(transform_flow(x[1]), x[2]) for x in ne_pump["efficiency_curve"]] | ||
end | ||
|
||
if haskey(ne_pump, "energy_price") | ||
ne_pump["energy_price"] /= energy_scalar | ||
end | ||
|
||
if haskey(ne_pump, "E") | ||
ne_pump["E"] *= energy_scalar | ||
end | ||
|
||
if haskey(ne_pump, "power_fixed") | ||
ne_pump["power_fixed"] *= power_scalar | ||
end | ||
|
||
if haskey(ne_pump, "P") | ||
ne_pump["P"] *= power_scalar | ||
end | ||
|
||
if haskey(ne_pump, "c") | ||
ne_pump["c"] *= energy_scalar | ||
end | ||
|
||
if haskey(ne_pump, "min_inactive_time") | ||
ne_pump["min_inactive_time"] = transform_time(ne_pump["min_inactive_time"]) | ||
end | ||
|
||
if haskey(ne_pump, "min_active_time") | ||
ne_pump["min_active_time"] = transform_time(ne_pump["min_active_time"]) | ||
end | ||
|
||
if haskey(ne_pump, "power_per_unit_flow") | ||
ne_pump["power_per_unit_flow"] *= power_scalar / transform_flow(1.0) | ||
end | ||
end | ||
|
||
if haskey(wm_data, "time_series") && haskey(wm_data["time_series"], "ne_pump") | ||
for ne_pump in values(wm_data["time_series"]["ne_pump"]) | ||
if haskey(ne_pump, "energy_price") | ||
ne_pump["energy_price"] ./= energy_scalar | ||
end | ||
|
||
if haskey(ne_pump, "power_fixed") | ||
ne_pump["power_fixed"] .*= power_scalar | ||
end | ||
|
||
if haskey(ne_pump, "power_per_unit_flow") | ||
ne_pump["power_per_unit_flow"] .*= power_scalar / transform_flow(1.0) | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
function _apply_regulator_unit_transform!(data::Dict{String,<:Any}, transform_head::Function, transform_length::Function) | ||
wm_data = get_wm_data(data) | ||
|
@@ -1169,7 +1253,7 @@ function _calc_scaled_gravity(data::Dict{String, <:Any}) | |
|
||
if wm_data["per_unit"] | ||
base_time = 1.0 / _calc_time_per_unit_transform(wm_data)(1.0) | ||
base_length = 1.0 / _calc_length_per_unit_transform(wm_data)(1.0) | ||
base_length = 1.0 / _calc_length_per_unit_transform(wm_data)(1.0) | ||
return _calc_scaled_gravity(base_length, base_time) | ||
else | ||
return _GRAVITY | ||
|
@@ -1368,6 +1452,8 @@ function _transform_nw!( | |
_apply_des_pipe_unit_transform!(wm_nw_data, length_transform, head_loss) | ||
_apply_pump_unit_transform!(wm_nw_data, mass_transform, | ||
flow_transform, length_transform, time_transform) | ||
_apply_ne_pump_unit_transform!(wm_nw_data, mass_transform, | ||
flow_transform, length_transform, time_transform) | ||
_apply_regulator_unit_transform!(wm_nw_data, head_transform, length_transform) | ||
|
||
# Apply transformations to nodal components. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,12 @@ end | |
|
||
|
||
function correct_ne_pumps!(data::Dict{String, <:Any}) | ||
wm_data = get_wm_data(data) | ||
base_flow = wm_data["per_unit"] ? wm_data["base_flow"] : 1.0 | ||
correction_func = x -> _correct_ne_pumps!(x, base_flow) | ||
apply_wm!(correction_func, data; apply_to_subnetworks = true) | ||
if(haskey(data,"ne_pump")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment that |
||
wm_data = get_wm_data(data) | ||
base_flow = wm_data["per_unit"] ? wm_data["base_flow"] : 1.0 | ||
correction_func = x -> _correct_ne_pumps!(x, base_flow) | ||
apply_wm!(correction_func, data; apply_to_subnetworks = true) | ||
end | ||
end | ||
|
||
|
||
|
@@ -407,7 +409,7 @@ function _calc_pump_power_points(wm::AbstractWaterModel, nw::Int, pump_id::Int, | |
q_min = max(get(pump, "flow_min_forward", _flow_min), _flow_min) | ||
|
||
q_max = max(q_min, pump["flow_max"]) | ||
q_build = range(0.0, stop = q_max + 1.0e-7, length = num_points) | ||
q_build = range(q_min - 1.0e-7, stop = q_max + 1.0e-7, length = num_points) | ||
f_build = head_curve_function.(collect(q_build)) .* q_build | ||
|
||
if haskey(pump, "efficiency_curve") | ||
|
@@ -427,7 +429,7 @@ function _calc_pump_power_points(wm::AbstractWaterModel, nw::Int, pump_id::Int, | |
end | ||
|
||
|
||
function _calc_ne_pump_power_points(wm::AbstractWaterModel, nw::Int, pump_id::Int, num_points::Int) | ||
function _calc_pump_power_points_ne(wm::AbstractWaterModel, nw::Int, pump_id::Int, num_points::Int) | ||
ne_pump = ref(wm, nw, :ne_pump, pump_id) | ||
head_curve_function = ref(wm, nw, :ne_pump, pump_id, "head_curve_function") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,9 @@ dictionary of data). Here, `skip_correct` will skip data correction routines | |
(e.g., component status propagation) if set to `true`, and `per_unit` will | ||
translate the data model to a per-unit measurement system if set to `true`. | ||
""" | ||
function parse_file(path::String; skip_correct::Bool = false, per_unit::Bool = true) | ||
function parse_file(path::String; ne_path::String = "", skip_correct::Bool = false, per_unit::Bool = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this should be the preferred method for passing in network expansion data. For nonstandard network components, the preferred way would be to pass in modifications via an auxiliary JSON file, then update the base network data with these modifications. For example, network = WaterModels.parse_file(network_path)
modifications = WaterModels.parse_file(modifications_path; skip_correct = true)
InfrastructureModels.update_data!(network, modifications)
WaterModels.correct_network_data!(network) Here, |
||
if endswith(path, ".inp") | ||
network_data = WaterModels.parse_epanet(path) | ||
network_data = WaterModels.parse_epanet(path,ne_filename = ne_path) | ||
elseif endswith(path, ".json") | ||
network_data = WaterModels.parse_json(path) | ||
correct_enums!(network_data) | ||
|
@@ -70,7 +70,9 @@ function correct_network_data!(data::Dict{String, <:Any}; per_unit::Bool = true) | |
correct_pipes!(data) | ||
correct_des_pipes!(data) | ||
correct_pumps!(data) | ||
correct_ne_pumps!(data) | ||
if(haskey(data,"ne_pump")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove per comments above. |
||
correct_ne_pumps!(data) | ||
end | ||
correct_regulators!(data) | ||
correct_short_pipes!(data) | ||
correct_ne_short_pipes!(data) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed.