diff --git a/src/core/electric_utility.jl b/src/core/electric_utility.jl index d70e63327..b8c15b512 100644 --- a/src/core/electric_utility.jl +++ b/src/core/electric_utility.jl @@ -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).") diff --git a/src/core/pv.jl b/src/core/pv.jl index ab7069d87..6f016118e 100644 --- a/src/core/pv.jl +++ b/src/core/pv.jl @@ -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)")) diff --git a/src/core/utils.jl b/src/core/utils.jl index 8f92c9f6f..aa99b3c71 100644 --- a/src/core/utils.jl +++ b/src/core/utils.jl @@ -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 \ No newline at end of file