Skip to content

Commit

Permalink
New test files for electrolyzer and PWFU. Add new defaults to interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Dec 19, 2023
1 parent 4e6d229 commit 853ce73
Show file tree
Hide file tree
Showing 26 changed files with 800 additions and 678 deletions.
2 changes: 1 addition & 1 deletion src/load_inputs/load_dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function extract_matrix_from_dataframe(df::DataFrame, columnprefix::AbstractStri
Matrix(dropmissing(df[:, sorted_columns]))
end

function sort_dataframe_by_resource_names!(df::DataFrame, gen::Vector{<:AbstractResource})
function sort_dataframe_by_resource_names!(df::DataFrame, gen::Vector{<:AbstractResource})::Vector{String}
# get all resource names
resource_names = resource_name.(gen)
# get resources in dataframe
Expand Down
40 changes: 21 additions & 19 deletions src/load_inputs/load_resources_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ function ensure_columns!(df::DataFrame)
end
end

function _get_resource_df(path::AbstractString, scale_factor::Float64=1.0)
function _get_resource_df(path::AbstractString, scale_factor::Float64)
# load dataframe with data of a given resource
resource_in = load_dataframe(path)
# scale data if necessary
scale_resources_data!(resource_in, scale_factor)
# rename columns lowercase
rename!(resource_in, lowercase.(names(resource_in)))
# scale data if necessary
scale_resources_data!(resource_in, scale_factor)
# ensure columns
ensure_columns!(resource_in)
# return dataframe
Expand Down Expand Up @@ -124,24 +124,27 @@ end

function _get_all_resources(resources_folder::AbstractString, resources_info::NamedTuple, scale_factor::Float64=1.0)
resource_id_offset = 0
resources = Vector(undef, length(resources_info))
resources = []
# loop over available types and get all resources
for (i,(filename, resource_type)) in enumerate(values(resources_info))
# path to resources data
path = joinpath(resources_folder, filename)
# load resources data of a given type
resource_in = _get_resource_df(path, scale_factor)
# get indices of resources for later use
resources_indices = _get_resource_indices(resource_in, resource_id_offset)
# add indices to dataframe
_add_indices_to_resource_df!(resource_in, resources_indices)
# add resources of a given type to array of resources
resources_same_type = _get_resource_array(resource_in, resource_type)
resources[i] = resources_same_type
# update id offset for next type of resources
resource_id_offset += length(resources_same_type)
# print log
@info filename * " Successfully Read."
# if file exists, load resources
if isfile(path)
# load resources data of a given type
resource_in = _get_resource_df(path, scale_factor)
# get indices of resources for later use
resources_indices = _get_resource_indices(resource_in, resource_id_offset)
# add indices to dataframe
_add_indices_to_resource_df!(resource_in, resources_indices)
# add resources of a given type to array of resources
resources_same_type = _get_resource_array(resource_in, resource_type)
push!(resources, resources_same_type)
# update id offset for next type of resources
resource_id_offset += length(resources_same_type)
# print log
@info filename * " Successfully Read."
end
end
return reduce(vcat, resources)
end
Expand Down Expand Up @@ -390,8 +393,7 @@ function load_resources_data!(setup::Dict, case_path::AbstractString, input_data
"The `Generators_data.csv` file was deprecated in release v0.4. " *
"Please use the new interface for generators creation, and see the documentation for additional details.",
:load_resources_data!, force=true)
@info "Exiting GenX..."
exit(-1)
error("Exiting GenX...")
# load_generators_data!(setup, case_path, input_data)
# translate_generators_data!(setup, input_data)
else
Expand Down
7 changes: 1 addition & 6 deletions src/model/resources/hydrogen/electrolyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function electrolyzer!(EP::Model, inputs::Dict, setup::Dict)
# (and any charging by qualified storage within the zone used to help increase electrolyzer utilization).
if setup["HydrogenHourlyMatching"] == 1
HYDROGEN_ZONES = unique(zone_id.(gen.ELECTROLYZER))
QUALIFIED_SUPPLY = resources_with_qualified_hydrogen_supply(gen)
QUALIFIED_SUPPLY = has_qualified_hydrogen_supply(gen)
@constraint(EP, cHourlyMatching[z in HYDROGEN_ZONES, t in 1:T],
sum(EP[:vP][y,t] for y=intersect(resources_in_zone_by_rid(gen,z), QUALIFIED_SUPPLY)) >= sum(EP[:vUSE][y,t] for y=intersect(resources_in_zone_by_rid(gen,z), ELECTROLYZERS)) + sum(EP[:vCHARGE][y,t] for y=intersect(resources_in_zone_by_rid(gen,z), QUALIFIED_SUPPLY, STORAGE))
)
Expand All @@ -176,9 +176,4 @@ function electrolyzer!(EP::Model, inputs::Dict, setup::Dict)

end

function resources_with_qualified_hydrogen_supply(rs::Vector{AbstractResource})
electrolyzers = rs.ELECTROLYZER
condition::BitVector = qualified_hydrogen_supply.(electrolyzers) .== 1
return resource_id.(electrolyzers[condition])
end

38 changes: 22 additions & 16 deletions src/model/resources/resources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ zone_id(rs::Vector{T}) where T <: AbstractResource = rs.zone
# TODO: some of these are not required (use get() instead)
max_capacity_mw(r::AbstractResource) = r.max_cap_mw
min_capacity_mw(r::AbstractResource) = r.min_cap_mw
cap_size(r::AbstractResource) = r.cap_size
existing_capacity_mw(r::AbstractResource) = r.existing_cap_mw
cap_size(r::AbstractResource) = get(r, :cap_size, default)

qualified_hydrogen_supply(r::AbstractResource) = get(r, :qualified_hydrogen_supply, default)

# costs
start_cost_per_mw(r::AbstractResource) = r.start_cost_per_mw
reg_cost(r::AbstractResource) = get(r, :reg_cost, default)
reg_max(r::AbstractResource) = get(r, :reg_max, default)
reg_max(r::AbstractResource)::Float64 = get(r, :reg_max, default)
rsv_cost(r::AbstractResource) = get(r, :rsv_cost, default)
rsv_max(r::AbstractResource) = get(r, :rsv_max, default)
var_om_cost_per_mwh(r::AbstractResource) = get(r, :var_om_cost_per_mwh, default)
inv_cost_per_mwyr(r::AbstractResource) = r.inv_cost_per_mwyr
fixed_om_cost_per_mwyr(r::AbstractResource) = r.fixed_om_cost_per_mwyr
var_om_cost_per_mwh(r::AbstractResource) = get(r, :var_om_cost_per_mwh, default)
start_cost_per_mw(r::AbstractResource) = get(r, :start_cost_per_mw, default)

# fuel
fuel(r::AbstractResource) = get(r, :fuel, "None")
Expand All @@ -114,9 +116,9 @@ efficiency_down(r::T) where T <: Union{HYDRO,STOR} = get(r, :eff_down, 1.0)

# Ramp up and down
const TCOMMIT = Union{ELECTROLYZER, HYDRO, THERM}
min_power(r::TCOMMIT) = r.min_power
ramp_up_percentage(r::TCOMMIT) = r.ramp_up_percentage
ramp_down_percentage(r::TCOMMIT) = r.ramp_dn_percentage
min_power(r::TCOMMIT) = get(r, :min_power, default)
ramp_up_percentage(r::TCOMMIT) = get(r, :ramp_up_percentage, 1.0)
ramp_down_percentage(r::TCOMMIT) = get(r, :ramp_down_percentage, 1.0)

# Retrofit
function has_retrofit(rs::Vector{T}) where T <: AbstractResource
Expand Down Expand Up @@ -215,6 +217,11 @@ function has_existing_charge_capacity_mw(rs::Vector{T}) where T <: AbstractResou
return findall(r -> get(r, :existing_charge_cap_mw, default) >= 0, rs)
end

function has_qualified_hydrogen_supply(rs::Vector{T}) where T <: AbstractResource
condition::BitVector = qualified_hydrogen_supply.(rs) .== 1
return resource_id.(rs[condition])
end

## policies
# energy share requirement
function has_esr(rs::Vector{T}; tag::Int64=1) where T <: AbstractResource
Expand Down Expand Up @@ -269,23 +276,23 @@ inv_cost_per_mwhyr(r::STOR) = r.inv_cost_per_mwhyr
existing_charge_capacity_mw(r::STOR) = get(r, :existing_charge_cap_mw, default)
fixed_om_cost_charge_per_mwyr(r::STOR) = get(r, :fixed_om_cost_charge_per_mwyr, default)
inv_cost_charge_per_mwyr(r::STOR) = r.inv_cost_charge_per_mwyr
max_charge_capacity_mw(r::STOR) = r.max_charge_cap_mw
min_charge_capacity_mw(r::STOR) = r.min_charge_cap_mw
max_charge_capacity_mw(r::STOR) = get(r, :max_charge_cap_mw, -1)
min_charge_capacity_mw(r::STOR) = get(r, :min_charge_cap_mw, default)

var_om_cost_per_mwh_in(r::STOR) = get(r, :var_om_cost_per_mwh_in, default)

function symmetric_storage(rs::Vector{T}) where T <: AbstractResource
return findall(r -> isa(r,STOR) && r.type == 1, rs)
return findall(r -> isa(r,STOR) && r.model == 1, rs)
end

function asymmetric_storage(rs::Vector{T}) where T <: AbstractResource
return findall(r -> isa(r,STOR) && r.type == 2, rs)
return findall(r -> isa(r,STOR) && r.model == 2, rs)
end


# HYDRO interface
hydro(rs::Vector{T}) where T <: AbstractResource = findall(r -> isa(r,HYDRO), rs)
hydro_energy_to_power_ratio(r::HYDRO) = r.hydro_energy_to_power_ratio
hydro_energy_to_power_ratio(r::HYDRO) = get(r, :hydro_energy_to_power_ratio, default)

function has_hydro_energy_to_power_ratio(rs::Vector{T}) where T <: AbstractResource
return findall(r -> get(r, :hydro_energy_to_power_ratio, default) > 0, rs)
Expand All @@ -298,11 +305,11 @@ thermal(rs::Vector{T}) where T <: AbstractResource = findall(r -> isa(r,THERM),
up_time(r::THERM) = get(r, :up_time, default)
down_time(r::THERM) = get(r, :down_time, default)
function has_unit_commitment(rs::Vector{T}) where T <: AbstractResource
return findall(r -> isa(r,THERM) && r.type == 1, rs)
return findall(r -> isa(r,THERM) && r.model == 1, rs)
end
# Without unit commitment
function no_unit_commitment(rs::Vector{T}) where T <: AbstractResource
return findall(r -> isa(r,THERM) && r.type == 2, rs)
return findall(r -> isa(r,THERM) && r.model == 2, rs)
end


Expand All @@ -319,7 +326,6 @@ electrolyzer(rs::Vector{T}) where T <: AbstractResource = findall(r -> isa(r,ELE
electrolyzer_min_kt(r::ELECTROLYZER) = r.electrolyzer_min_kt
hydrogen_mwh_per_tonne(r::ELECTROLYZER) = r.hydrogen_mwh_per_tonne
hydrogen_price_per_tonne(r::ELECTROLYZER) = r.hydrogen_price_per_tonne
qualified_hydrogen_supply(r::ELECTROLYZER) = r.qualified_hydrogen_supply


# FLEX interface
Expand Down Expand Up @@ -382,7 +388,7 @@ function resources_in_zone_by_rid(rs::Vector{AbstractResource}, zone::Int)
return resource_id.(rs[zone_id.(rs) .== zone])
end

function resource_by_name(rs::Vector{AbstractResource}, name::String)
function resource_by_name(rs::Vector{AbstractResource}, name::AbstractString)
return rs[findfirst(r -> resource_name(r) == name, rs)]
end

Expand Down
26 changes: 13 additions & 13 deletions src/multi_stage/endogenous_retirement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function update_cumulative_min_ret!(inputs_d::Dict,t::Int,Resource_Set::String,d
if !isempty(inputs_d[1][Resource_Set])
gen_t = inputs_d[t][dfGen_Name]
if t==1
cum_ret_cap_api.(gen_t) = ret_cap_api.(gen_t)
gen_t.cum_ret_cap_api = ret_cap_api.(gen_t)
else
cum_ret_cap_api.(gen_t) = cum_ret_cap_api.(inputs_d[t-1][dfGen_Name]) + ret_cap_api.(gen_t)
gen_t.cum_ret_cap_api = cum_ret_cap_api.(inputs_d[t-1][dfGen_Name]) + ret_cap_api.(gen_t)
end
end
else
Expand Down Expand Up @@ -135,7 +135,7 @@ function endogenous_retirement_discharge!(EP::Model, inputs::Dict, num_stages::I

println("Endogenous Retirement (Discharge) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

NEW_CAP = inputs["NEW_CAP"] # Set of all resources eligible for new capacity
RET_CAP = inputs["RET_CAP"] # Set of all resources eligible for capacity retirements
Expand Down Expand Up @@ -190,7 +190,7 @@ function endogenous_retirement_charge!(EP::Model, inputs::Dict, num_stages::Int,

println("Endogenous Retirement (Charge) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

STOR_ASYMMETRIC = inputs["STOR_ASYMMETRIC"] # Set of storage resources with asymmetric (separte) charge/discharge capacity components

Expand Down Expand Up @@ -240,7 +240,7 @@ function endogenous_retirement_energy!(EP::Model, inputs::Dict, num_stages::Int,

println("Endogenous Retirement (Energy) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

NEW_CAP_ENERGY = inputs["NEW_CAP_ENERGY"] # Set of all storage resources eligible for new energy capacity
RET_CAP_ENERGY = inputs["RET_CAP_ENERGY"] # Set of all storage resources eligible for energy capacity retirements
Expand Down Expand Up @@ -287,7 +287,7 @@ function endogenous_retirement_vre_stor_dc!(EP::Model, inputs::Dict, num_stages:

println("Endogenous Retirement (VRE-Storage DC) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

dfVRE_STOR = inputs["dfVRE_STOR"];

Expand Down Expand Up @@ -336,7 +336,7 @@ function endogenous_retirement_vre_stor_solar!(EP::Model, inputs::Dict, num_stag

println("Endogenous Retirement (VRE-Storage Solar) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

dfVRE_STOR = inputs["dfVRE_STOR"];

Expand Down Expand Up @@ -385,7 +385,7 @@ function endogenous_retirement_vre_stor_wind!(EP::Model, inputs::Dict, num_stage

println("Endogenous Retirement (VRE-Storage Wind) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

dfVRE_STOR = inputs["dfVRE_STOR"];

Expand Down Expand Up @@ -434,7 +434,7 @@ function endogenous_retirement_vre_stor_stor!(EP::Model, inputs::Dict, num_stage

println("Endogenous Retirement (VRE-Storage Storage) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

NEW_CAP_STOR = inputs["NEW_CAP_STOR"] # Set of all resources eligible for new capacity
RET_CAP_STOR = inputs["RET_CAP_STOR"] # Set of all resources eligible for capacity retirements
Expand Down Expand Up @@ -481,7 +481,7 @@ function endogenous_retirement_vre_stor_discharge_dc!(EP::Model, inputs::Dict, n

println("Endogenous Retirement (VRE-Storage Discharge DC) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]

dfVRE_STOR = inputs["dfVRE_STOR"]

Expand Down Expand Up @@ -530,7 +530,7 @@ function endogenous_retirement_vre_stor_charge_dc!(EP::Model, inputs::Dict, num_

println("Endogenous Retirement (VRE-Storage Charge DC) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]
dfVRE_STOR = inputs["dfVRE_STOR"];
NEW_CAP_CHARGE_DC = inputs["NEW_CAP_CHARGE_DC"] # Set of all resources eligible for new capacity
RET_CAP_CHARGE_DC = inputs["RET_CAP_CHARGE_DC"] # Set of all resources eligible for capacity retirements
Expand Down Expand Up @@ -577,7 +577,7 @@ function endogenous_retirement_vre_stor_discharge_ac!(EP::Model, inputs::Dict, n

println("Endogenous Retirement (VRE-Storage Discharge AC) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]
dfVRE_STOR = inputs["dfVRE_STOR"];
NEW_CAP_DISCHARGE_AC = inputs["NEW_CAP_DISCHARGE_AC"] # Set of all resources eligible for new capacity
RET_CAP_DISCHARGE_AC = inputs["RET_CAP_DISCHARGE_AC"] # Set of all resources eligible for capacity retirements
Expand Down Expand Up @@ -624,7 +624,7 @@ function endogenous_retirement_vre_stor_charge_ac!(EP::Model, inputs::Dict, num_

println("Endogenous Retirement (VRE-Storage Charge AC) Module")

gen = inputs["RESOURCES"]
res = inputs["RESOURCES"]
dfVRE_STOR = inputs["dfVRE_STOR"]
NEW_CAP_CHARGE_AC = inputs["NEW_CAP_CHARGE_AC"] # Set of all resources eligible for new capacity
RET_CAP_CHARGE_AC = inputs["RET_CAP_CHARGE_AC"] # Set of all resources eligible for capacity retirements
Expand Down
File renamed without changes.
Loading

0 comments on commit 853ce73

Please sign in to comment.