Skip to content

Commit

Permalink
update has series checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Nov 30, 2024
1 parent ed6210d commit f57fb0d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
27 changes: 16 additions & 11 deletions src/devices_models/devices/common/objective_function/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,26 @@ end
################## Fuel Cost #####################
##################################################

function _get_fuel_cost_value(
function get_fuel_cost_value(
container::OptimizationContainer,
component::T,
time_period::Int,
::Val{true},
) where {T <: PSY.Component}
# TODO: Check time series for derating to work later
if PSY.has_time_series(component)
parameter_array = get_parameter_array(container, FuelCostParameter(), T)
parameter_multiplier =
get_parameter_multiplier_array(container, FuelCostParameter(), T)
name = PSY.get_name(component)
return parameter_array[name, time_period] * parameter_multiplier[name, time_period]
else
return PSY.get_fuel_cost(component)
end
parameter_array = get_parameter_array(container, FuelCostParameter(), T)
parameter_multiplier =
get_parameter_multiplier_array(container, FuelCostParameter(), T)
name = PSY.get_name(component)
return parameter_array[name, time_period] * parameter_multiplier[name, time_period]
end

function get_fuel_cost_value(
::OptimizationContainer,
component::T,
::Int,
::Val{false},
) where {T <: PSY.Component}
return PSY.get_fuel_cost(component)
end

function _add_time_varying_fuel_variable_cost!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,11 @@ function _add_variable_cost_to_objective!(

is_time_variant_ = is_time_variant(cost_function)
for t in get_time_steps(container)
fuel_cost_value = _get_fuel_cost_value(
fuel_cost_value = get_fuel_cost_value(
container,
component,
t,
Val{is_time_variant_}(),
)
pwl_cost_expression = pwl_fuel_consumption_expressions[t] * fuel_cost_value
add_to_expression!(
Expand Down
9 changes: 4 additions & 5 deletions src/parameters/add_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ function _add_parameters!(
)
end
time_steps = get_time_steps(container)
# TODO: Check for timeseries only for fuel cost
device_names = [PSY.get_name(x) for x in devices if PSY.has_time_series(x)]
ts_name = get_time_series_names(model)[T]
device_names =
[PSY.get_name(x) for x in devices if PSY.has_time_series(x, ts_type, ts_name)]
if isempty(device_names)
return
end
Expand All @@ -300,10 +301,8 @@ function _add_parameters!(
time_steps,
)

ts_name = get_time_series_names(model)[T]

for device in devices
if !PSY.has_time_series(device)
if !PSY.has_time_series(device, ts_type, ts_name)
continue
end
ts_vals = get_time_series_initial_values!(container, ts_type, device, ts_name)
Expand Down
8 changes: 6 additions & 2 deletions test/test_device_thermal_generation_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,13 @@ end
store_variable_names = true,
optimizer_solve_log_print = false,
)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.ModelBuildStatus.BUILT
@test build!(model; output_dir = mktempdir(; cleanup = true)) ==
PSI.ModelBuildStatus.BUILT
solve!(model)
moi_tests(model, 288, 0, 192, 120, 72, false)
container = PSI.get_optimization_container(model)
@test isa(PSI.get_invariant_terms(PSI.get_objective_expression(container)), JuMP.QuadExpr)
@test isa(
PSI.get_invariant_terms(PSI.get_objective_expression(container)),
JuMP.QuadExpr,
)
end

0 comments on commit f57fb0d

Please sign in to comment.