Skip to content

Commit

Permalink
Avoid division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Jun 21, 2024
1 parent d071a8c commit fbe1520
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/data_format_conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,24 @@ function _convert_data!(
component["storage_technology_type"] = IS.serialize(StorageTech.OTHER_CHEM)
soc_min = component["state_of_charge_limits"]["min"]
soc_max = component["state_of_charge_limits"]["max"]
# Derive storage_capacity from old state of charge limits and normalize new
# state of charge limits, initial capacity accordingly
component["storage_capacity"] = soc_max
component["storage_level_limits"] =
Dict("min" => soc_min / soc_max, "max" => 1.0)
component["initial_storage_capacity_level"] =
component["initial_energy"] / soc_max
if soc_max == 0.0
component["storage_capacity"] = 0.0
component["storage_level_limits"] = Dict("min" => 0.0, "max" => 1.0)
(component["initial_energy"] != 0.0) && throw(
ArgumentError(
"Maximum state of charge is zero but initial energy is not; cannot parse",
),
)
component["initial_storage_capacity_level"] = 0.0
else
# Derive storage_capacity from old state of charge limits and normalize new
# state of charge limits, initial capacity accordingly
component["storage_capacity"] = soc_max
component["storage_level_limits"] =
Dict("min" => soc_min / soc_max, "max" => 1.0)
component["initial_storage_capacity_level"] =
component["initial_energy"] / soc_max
end
end
if haskey(component, "rate") # Line, TapTransformer, etc.
component["rating"] = component["rate"]
Expand Down

0 comments on commit fbe1520

Please sign in to comment.