Skip to content

Commit

Permalink
Pump power: Curve reading and linear fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
hskkanth committed Sep 14, 2023
1 parent 6f4dcfc commit 47a6f1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
33 changes: 28 additions & 5 deletions src/core/pump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,39 @@ function _calc_pump_power_points_ne(wm::AbstractWaterModel, nw::Int, pump_id::In
return q_build, max.(0.0, density * gravity * inv.(eff) .* f_build)
end

# pump_power_updates
function modify_pump_power_points(wm::AbstractWaterModel, nw::Int)
power_curve_unscaled = ref(wm, nw, :pump_power_curve)
bf = wm.ref[:it][wm_it_sym][:base_flow]
bm = wm.ref[:it][wm_it_sym][:base_mass]
bl = wm.ref[:it][wm_it_sym][:base_length]
bt = wm.ref[:it][wm_it_sym][:base_time]
bp = bm*(bl^2 / bt^3)

Check warning on line 466 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L462-L466

Added lines #L462 - L466 were not covered by tests

function _calc_pump_power(wm::AbstractWaterModel, nw::Int, pump_id::Int, q::Vector{Float64})
q_points_scaled = power_curve_unscaled["q_points"] ./bf
f_points_sclaed = power_curve_unscaled["f_points"] ./bp

Check warning on line 469 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L468-L469

Added lines #L468 - L469 were not covered by tests

return q_points_scaled, f_points_sclaed

Check warning on line 471 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L471

Added line #L471 was not covered by tests
# make the scaling consistent
end

function _calc_pump_power_linear_coeff(wm::AbstractWaterModel, nw::Int, z::JuMP.VariableRef)
q_true, f_true = modify_pump_power_points(wm, nw)
q_array = hcat(q_true, ones(length(q_true)))
linear_coefficients = q_array \ f_true
return q -> sum(linear_coefficients .*[q, z])

Check warning on line 479 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L477-L479

Added lines #L477 - L479 were not covered by tests
end


function _calc_pump_power(wm::AbstractWaterModel, nw::Int, pump_id::Int)

Check warning on line 483 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L483

Added line #L483 was not covered by tests
q_true, f_true = _calc_pump_power_points(wm, nw, pump_id, 100)
return max.(Interpolations.linear_interpolation(q_true, f_true).(q), 0.0)
return q -> max.(Interpolations.linear_interpolation(q_true, f_true).(q), 0.0)

Check warning on line 485 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L485

Added line #L485 was not covered by tests
end


function _calc_pump_power_ne(wm::AbstractWaterModel, nw::Int, pump_id::Int, q::Vector{Float64})
function _calc_pump_power_ne(wm::AbstractWaterModel, nw::Int, pump_id::Int)

Check warning on line 489 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L489

Added line #L489 was not covered by tests
q_true, f_true = _calc_pump_power_points_ne(wm, nw, pump_id, 100)
return max.(Interpolations.linear_interpolation(q_true, f_true).(q), 0.0)
return q -> max.(Interpolations.linear_interpolation(q_true, f_true).(q), 0.0)

Check warning on line 491 in src/core/pump.jl

View check run for this annotation

Codecov / codecov/patch

src/core/pump.jl#L491

Added line #L491 was not covered by tests
end


Expand Down Expand Up @@ -561,7 +584,7 @@ function _calc_pump_power_quadratic_approximation(wm::AbstractWaterModel, nw::In

# Ensure that a negative constant term does not exist.
linear_coefficients[3] = max(0.0, linear_coefficients[3])

# Return the least squares-fitted quadratic approximation.
return x -> sum(linear_coefficients .* [x * x, x, z])
end
Expand Down
1 change: 1 addition & 0 deletions src/core/pump_power_updates.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 7 additions & 6 deletions src/form/ncd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,10 @@ function constraint_on_off_pump_power(
z = var(wm, n, :z_pump, a)

# Add constraint equating power with respect to the power curve.
power_qa = _calc_pump_power_quadratic_approximation(wm, n, a, z)
c_1 = JuMP.@constraint(wm.model, power_qa(q) <= P)
c_2 = JuMP.@constraint(wm.model, power_qa(q) >= P)
power_qa = _calc_pump_power_linear_coeff(wm, n, z)
# power_qa = _calc_pump_power_quadratic_approximation(wm, n, a, z)
c_1 = JuMP.@constraint(wm.model, power(q) <= P)
c_2 = JuMP.@constraint(wm.model, power(q) >= P)

Check warning on line 741 in src/form/ncd.jl

View check run for this annotation

Codecov / codecov/patch

src/form/ncd.jl#L740-L741

Added lines #L740 - L741 were not covered by tests

# Append the :on_off_pump_power constraint array.
append!(con(wm, n, :on_off_pump_power)[a], [c_1, c_2])
Expand All @@ -756,9 +757,9 @@ function constraint_on_off_pump_power_ne(
z = var(wm, n, :z_ne_pump, a)

# Add constraint equating power with respect to the power curve.
power_qa = _calc_pump_power_quadratic_approximation_ne(wm, n, a, z)
c_1 = JuMP.@constraint(wm.model, power_qa(q) <= P)
c_2 = JuMP.@constraint(wm.model, power_qa(q) >= P)
power = _calc_pump_power_linear_coeff(wm, n, z)
c_1 = JuMP.@constraint(wm.model, power(q) <= P)
c_2 = JuMP.@constraint(wm.model, power(q) >= P)

Check warning on line 762 in src/form/ncd.jl

View check run for this annotation

Codecov / codecov/patch

src/form/ncd.jl#L760-L762

Added lines #L760 - L762 were not covered by tests

# Append the :on_off_pump_power constraint array.
append!(con(wm, n, :on_off_pump_power_ne)[a], [c_1, c_2])
Expand Down

0 comments on commit 47a6f1d

Please sign in to comment.