Skip to content

Commit

Permalink
util function error_if_series_vals_not_0_to_1
Browse files Browse the repository at this point in the history
  • Loading branch information
hdunham committed Dec 13, 2024
1 parent 08b0ecb commit 9c8b6a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/core/electric_utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ struct ElectricUtility

if !is_MPC
# Check some inputs
if any(x -> x < 0 || x > 1, renewable_energy_fraction_series)
throw(@error("All values in the provided ElectricUtility renewable_energy_fraction_series must be between 0 and 1."))
end
error_if_series_vals_not_0_to_1(renewable_energy_fraction_series, "ElectricUtility", "renewable_energy_fraction_series")
if cambium_start_year < 2023 || cambium_start_year > 2050 # TODO: update?
cambium_start_year = 2025 # Must update annually
@warn("The cambium_start_year must be between 2023 and 2050. Setting cambium_start_year to $(cambium_start_year).")
Expand Down
4 changes: 2 additions & 2 deletions src/core/pv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ mutable struct PV <: AbstractTech
if !(0.0 <= dc_ac_ratio <= 2.0)
push!(invalid_args, "dc_ac_ratio must satisfy 0 <= dc_ac_ratio <= 2, got $(dc_ac_ratio)")
end
if !isnothing(production_factor_series) && any(x -> x < 0 || x > 1, production_factor_series)
throw(@error("All values in the provided PV production_factor_series must be between 0 and 1."))
if !isnothing(production_factor_series)
error_if_series_vals_not_0_to_1(production_factor_series, "PV", "production_factor_series")
end
if length(invalid_args) > 0
throw(@error("Invalid PV argument values: $(invalid_args)"))
Expand Down
6 changes: 6 additions & 0 deletions src/core/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,10 @@ function check_api_key()
Within your Julia environment, specify ENV['NREL_DEVELOPER_API_KEY']='your API key'
See https://nrel.github.io/REopt.jl/dev/ for more information."))
end
end

function error_if_series_vals_not_0_to_1(series, input_struct_name, input_name)
if any(x -> x < 0 || x > 1, series)
throw(@error("All values in the provided $(input_struct_name) $(input_name) must be between 0 and 1."))
end
end

0 comments on commit 9c8b6a5

Please sign in to comment.