Skip to content
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

Jd/rename storage #92

Merged
merged 9 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 10 additions & 37 deletions src/build_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,22 @@ function build_system(
)
sys_descriptor = get_system_descriptor(category, system_catalog, name)
sys_kwargs = filter_kwargs(; kwargs...)
sys_keys = keys(sys_kwargs)

psid_kwargs = check_kwargs_psid(; kwargs...)
psid_keys = keys(psid_kwargs)

case_keys = get_supported_argument_names(sys_descriptor)

if !(isempty(intersect(sys_keys, psid_keys)))
error(
"sys_keys and psid_keys have the overlapping key(s): $(intersect(sys_keys, psid_keys))",
)
case_kwargs = filter_descriptor_kwargs(sys_descriptor; kwargs...)
if length(kwargs) > length(sys_kwargs) + length(case_kwargs)
unexpected = setdiff(keys(kwargs), union(keys(sys_kwargs), keys(case_kwargs)))
error("These keyword arguments are not supported: $unexpected")
end

if !(isempty(intersect(sys_keys, case_keys)))
error(
"sys_keys and case_keys have the overlapping key(s): $(intersect(sys_keys, psid_keys))",
)
duplicates = intersect(keys(sys_kwargs), keys(case_kwargs))
if !isempty(duplicates)
error("System kwargs and case kwargs have overlapping keys: $duplicates")
end

if !isempty(psid_kwargs)
kwarg_type = first(values(psid_kwargs))
name = "$(name)_$kwarg_type"
end

non_sys_psid_kwargs = setdiff(kwargs, merge(psid_kwargs, sys_kwargs))
non_sys_psid_args = Dict{Symbol, Any}(k => v for (k, v) in non_sys_psid_kwargs)
key_diff = setdiff(keys(non_sys_psid_args), case_keys)
if !isempty(key_diff)
throw(ArgumentError("unsupported kwargs are specified: $key_diff"))
end

case_args = Dict{Symbol, Any}(
merge(get_supported_arguments_dict(sys_descriptor), non_sys_psid_args),
)

return _build_system(
name,
sys_descriptor,
case_args,
case_kwargs,
sys_kwargs,
psid_kwargs,
print_stat;
force_build,
assign_new_uuids,
Expand All @@ -78,7 +53,6 @@ function _build_system(
sys_descriptor::SystemDescriptor,
case_args::Dict{Symbol, <:Any},
sys_args::Dict{Symbol, <:Any},
psid_args::Dict{Symbol, <:Any},
print_stat::Bool = false;
force_build::Bool = false,
assign_new_uuids::Bool = false,
Expand All @@ -98,14 +72,13 @@ function _build_system(
raw_data = sys_descriptor.raw_data,
case_args...,
sys_args...,
psid_args...,
)
construct_time = time() - start
#construct_time = time() - start
serialized_filepath = get_serialized_filepath(name, case_args)
start = time()
if !skip_serialization
PSY.to_json(sys, serialized_filepath; force = true)
serialize_time = time() - start
#serialize_time = time() - start
serialize_case_parameters(case_args)
end
# set_stats!(sys_descriptor, SystemBuildStats(construct_time, serialize_time))
Expand Down
1 change: 0 additions & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const SERIALIZED_DIR = joinpath(PACKAGE_DIR, "data", "serialized_system")
const SERIALIZE_FILE_EXTENSIONS =
[".json", "_metadata.json", "_validation_descriptors.json", "_time_series_storage.h5"]

const ACCEPTED_PSID_TEST_SYSTEMS_KWARGS = [:avr_type, :tg_type, :pss_type, :gen_type]
const AVAILABLE_PSID_PSSE_AVRS_TEST =
["AC1A", "AC1A_SAT", "EXAC1", "EXST1", "SEXS", "SEXS_noTE"]

Expand Down
2 changes: 1 addition & 1 deletion src/library/psi_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line
PSY.add_component!(main_sys, new_ACLine)
end

for bat in get_components(GenericBattery, main_sys)
for bat in get_components(EnergyReservoirStorage, main_sys)
set_base_power!(bat, get_base_power(bat) * 10)
end

Expand Down
173 changes: 55 additions & 118 deletions src/library/psitest_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,18 +747,18 @@ function build_c_sys5_bat(;
PSY.add_service!(
c_sys5_bat,
reserve_bat[1],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
PSY.add_service!(
c_sys5_bat,
reserve_bat[2],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
# ORDC
PSY.add_service!(
c_sys5_bat,
reserve_bat[3],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
for (ix, serv) in enumerate(PSY.get_components(PSY.VariableReserve, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeSeries.TimeArray}()
Expand Down Expand Up @@ -2403,107 +2403,6 @@ function build_duration_test_sys(; raw_data, kwargs...)
return duration_test_sys
end

function build_pwl_marketbid_sys(; raw_data, kwargs...)
sys_kwargs = filter_kwargs(; kwargs...)
node =
PSY.ACBus(1, "nodeA", "REF", 0, 1.0, (min = 0.9, max = 1.05), 230, nothing, nothing)
load = PSY.PowerLoad("Bus1", true, node, 0.4, 0.9861, 100.0, 1.0, 2.0)
gens_cost = [
PSY.ThermalStandard(;
name = "Alta",
available = true,
status = true,
bus = node,
active_power = 0.52,
reactive_power = 0.010,
rating = 0.5,
prime_mover_type = PSY.PrimeMovers.ST,
fuel = PSY.ThermalFuels.COAL,
active_power_limits = (min = 0.22, max = 0.55),
reactive_power_limits = nothing,
time_limits = nothing,
ramp_limits = nothing,
operation_cost = PSY.MarketBidCost(;
no_load_cost = 0.0,
start_up = (hot = 0.0, warm = 0.0, cold = 0.0),
shut_down = 0.0,
),
base_power = 100.0,
),
PSY.ThermalMultiStart(;
name = "115_STEAM_1",
available = true,
status = true,
bus = node,
active_power = 0.05,
reactive_power = 0.010,
rating = 0.12,
prime_mover_type = PSY.PrimeMovers.ST,
fuel = PSY.ThermalFuels.COAL,
active_power_limits = (min = 0.05, max = 0.12),
reactive_power_limits = (min = -0.30, max = 0.30),
ramp_limits = (up = 0.2 * 0.12, down = 0.2 * 0.12),
power_trajectory = (startup = 0.05, shutdown = 0.05),
time_limits = (up = 4.0, down = 2.0),
start_time_limits = (hot = 2.0, warm = 4.0, cold = 12.0),
start_types = 3,
operation_cost = PSY.MarketBidCost(;
no_load_cost = 0.0,
start_up = (hot = 393.28, warm = 455.37, cold = 703.76),
shut_down = 0.0,
),
base_power = 100.0,
),
]
ini_time = DateTime("1/1/2024 0:00:00", "d/m/y H:M:S")
DA_load_forecast = Dict{Dates.DateTime, TimeSeries.TimeArray}()
market_bid_gen1_data = Dict(
ini_time => [
PiecewiseStepData([22.0, 33.0, 44.0, 55.0], [26.82, 29.55, 30.31]),
PiecewiseStepData([22.0, 33.0, 44.0, 55.0], [26.82, 29.55, 30.31]),
],
ini_time + Hour(1) => [
PiecewiseStepData([22.0, 33.0, 44.0, 55.0], [26.82, 29.55, 30.31]),
PiecewiseStepData([22.0, 33.0, 44.0, 55.0], [26.82, 29.55, 30.31]),
],
)
market_bid_gen1 = PSY.Deterministic(;
name = "variable_cost",
data = market_bid_gen1_data,
resolution = Hour(1),
)
market_bid_gen2_data = Dict(
ini_time => [
PiecewiseStepData([5.0, 7.33, 9.67, 12.0], [124.51, 125.05, 133.64]),
PiecewiseStepData([5.0, 7.33, 9.67, 12.0], [128.80, 128.47, 128.49]),
],
ini_time + Hour(1) => [
PiecewiseStepData([5.0, 7.33, 9.67, 12.0], [124.51, 125.05, 133.64]),
PiecewiseStepData([5.0, 7.33, 9.67, 12.0], [128.80, 128.47, 128.49]),
],
)
market_bid_gen2 = PSY.Deterministic(;
name = "variable_cost",
data = market_bid_gen2_data,
resolution = Hour(1),
)
market_bid_load = [[0.5, 0.6], [0.5, 0.6]]
for (ix, date) in enumerate(range(ini_time; length = 2, step = Hour(1)))
DA_load_forecast[date] =
TimeSeries.TimeArray([date, date + Hour(1)], market_bid_load[ix])
end
load_forecast_cost_market_bid = PSY.Deterministic("max_active_power", DA_load_forecast)
cost_test_sys = PSY.System(100.0; sys_kwargs...)
PSY.add_component!(cost_test_sys, node)
PSY.add_component!(cost_test_sys, load)
PSY.add_component!(cost_test_sys, gens_cost[1])
PSY.add_component!(cost_test_sys, gens_cost[2])
PSY.add_time_series!(cost_test_sys, load, load_forecast_cost_market_bid)
PSY.set_variable_cost!(cost_test_sys, gens_cost[1], market_bid_gen1)
PSY.set_variable_cost!(cost_test_sys, gens_cost[2], market_bid_gen2)
return cost_test_sys
end

function build_5_bus_matpower_DA(; raw_data, kwargs...)
sys_kwargs = filter_kwargs(; kwargs...)
data_dir = dirname(dirname(raw_data))
Expand Down Expand Up @@ -2597,7 +2496,7 @@ function build_test_RTS_GMLC_sys_with_hybrid(; raw_data, add_forecasts, kwargs..
thermal_unit = first(get_components(ThermalStandard, sys))
bus = get_bus(thermal_unit)
electric_load = first(get_components(PowerLoad, sys))
storage = first(get_components(GenericBattery, sys))
storage = first(get_components(EnergyReservoirStorage, sys))
renewable_unit = first(get_components(RenewableDispatch, sys))

name = "Test H"
Expand Down Expand Up @@ -2664,7 +2563,7 @@ function build_c_sys5_bat_ems(;
Deterministic("max_active_power", forecast_data),
)
end
for (ix, r) in enumerate(get_components(PSY.BatteryEMS, c_sys5_bat))
for (ix, r) in enumerate(get_components(PSY.EnergyReservoirStorage, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeArray}()
for t in 1:2
ini_time = timestamp(storage_target_DA[t][1])[1]
Expand Down Expand Up @@ -2694,7 +2593,7 @@ function build_c_sys5_bat_ems(;
),
)
end
for (ix, b) in enumerate(PSY.get_components(PSY.BatteryEMS, c_sys5_bat))
for (ix, b) in enumerate(PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat))
PSY.add_time_series!(
c_sys5_bat,
b,
Expand All @@ -2707,10 +2606,22 @@ function build_c_sys5_bat_ems(;
end
if add_reserves
reserve_bat = reserve5_re(get_components(RenewableDispatch, c_sys5_bat))
add_service!(c_sys5_bat, reserve_bat[1], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(c_sys5_bat, reserve_bat[2], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(
c_sys5_bat,
reserve_bat[1],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
add_service!(
c_sys5_bat,
reserve_bat[2],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
# ORDC
add_service!(c_sys5_bat, reserve_bat[3], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(
c_sys5_bat,
reserve_bat[3],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
for (ix, serv) in enumerate(get_components(VariableReserve, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeArray}()
for t in 1:2
Expand Down Expand Up @@ -2785,9 +2696,10 @@ function build_c_sys5_hybrid(; add_forecasts, raw_data, kwargs...)
thermals = thermal_generators5(nodes)
loads = loads5(nodes)
renewables = renewable_generators5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -2969,9 +2881,10 @@ function build_c_sys5_hybrid_uc(; add_forecasts, raw_data, kwargs...)
loads = loads5(nodes)
renewables = renewable_generators5(nodes)
branches = branches5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -3098,9 +3011,10 @@ function build_c_sys5_hybrid_ed(; add_forecasts, raw_data, kwargs...)
loads = loads5(nodes)
branches = branches5(nodes)
renewables = renewable_generators5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -3546,9 +3460,10 @@ function build_batt_test_case_b_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 5.0,
Expand Down Expand Up @@ -3622,9 +3537,10 @@ function build_batt_test_case_c_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3698,9 +3614,10 @@ function build_batt_test_case_d_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3774,9 +3691,10 @@ function build_batt_test_case_e_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3850,9 +3768,10 @@ function build_batt_test_case_f_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 1.0,
Expand Down Expand Up @@ -4280,3 +4199,21 @@ function build_pwl_incremental_fuel_test_sys_ts(; kwargs...)
thermal_generator_pwl_incremental_fuel_ts(base_sys, node)
return base_sys
end

### Systems with fixed market bid cost

function build_fixed_market_bid_cost_test_sys(; kwargs...)
base_sys = _build_cost_base_test_sys(; kwargs...)
node = PSY.get_component(ACBus, base_sys, "nodeA")
test_gens = thermal_generators_market_bid(node)
PSY.add_component!(base_sys, test_gens[1])
PSY.add_component!(base_sys, test_gens[2])
return base_sys
end

function build_pwl_marketbid_sys_ts(; kwargs...)
base_sys = _build_cost_base_test_sys(; kwargs...)
node = PSY.get_component(ACBus, base_sys, "nodeA")
thermal_generators_market_bid_ts(base_sys, node)
return base_sys
end
Loading
Loading