Skip to content

Commit

Permalink
Add new outputs for results related to hydrogen technologies
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiangk1 committed Jul 31, 2023
1 parent bc3d152 commit ed038b9
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/REopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ include("results/thermal_storage.jl")
include("results/outages.jl")
include("results/wind.jl")
include("results/electric_load.jl")
include("results/hydrogen_load.jl")
include("results/existing_boiler.jl")
include("results/boiler.jl")
include("results/existing_chiller.jl")
Expand All @@ -214,6 +213,10 @@ include("results/flexible_hvac.jl")
include("results/ghp.jl")
include("results/steam_turbine.jl")
include("results/heating_cooling_load.jl")
include("results/hydrogen_load.jl")
include("results/hydrogen_storage.jl")
include("results/electrolyzer.jl")
include("results/compressor.jl")

include("core/reopt.jl")
include("core/reopt_multinode.jl")
Expand Down
12 changes: 12 additions & 0 deletions src/constraints/tech_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ function add_tech_size_constraints(m, p; _n="")
m[Symbol("dvRatedProduction"*_n)][t,ts] <= m[:dvSize][t]
)
end

if !isempty(p.techs.electrolyzer)
@constraint(m, [t in p.techs.electrolyzer, ts in p.time_steps],
m[Symbol("dvRatedProduction"*_n)][t,ts] <= m[:dvSize][t]
)
end

if !isempty(p.techs.compressor)
@constraint(m, [t in p.techs.compressor, ts in p.time_steps],
m[Symbol("dvRatedProduction"*_n)][t,ts] <= m[:dvSize][t]
)
end
end


Expand Down
72 changes: 72 additions & 0 deletions src/results/compressor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# *********************************************************************************
# REopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# *********************************************************************************
"""
`Compressor` results keys:
- `size_kw` Optimal compressor capacity
- `lifecycle_om_cost_after_tax` Lifecycle operations and maintenance cost in present value, after tax
- `year_one_hydrogen_compressed_kg` Total hydrogen compressed over the first year
- `year_one_electricity_consumed_kwh` Total energy consumed by the compressor over the first year
- `electricity_consumed_series_kw` Vector of power consumed by the compressor over the first year
- `hydrogen_compressed_series_kg` Vector of hydrogen compressed going into the high pressure tank
!!! note "'Series' and 'Annual' energy outputs are average annual"
REopt performs load balances using average annual production values for technologies that include degradation.
Therefore, all timeseries (`_series`) and `annual_` results should be interpretted as energy outputs averaged over the analysis period.
"""
function add_compressor_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dict; _n="")
# Adds the `Compressor` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# Note: the node number is an empty string if evaluating a single `Site`.
print()
r = Dict{String, Any}()
r["size_kw"] = round(value(m[Symbol("dvSize"*_n)]["Compressor"]), digits=4)

CompressorConsumption = @expression(m, [ts in p.time_steps],
sum(m[Symbol("dvProductionToCompressor"*_n)][t, ts] for t in p.techs.elec)
+ m[Symbol("dvGridToCompressor"*_n)][ts]
+ sum(m[Symbol("dvStorageToCompressor"*_n)][b, ts] for b in p.s.storage.types.elec)
)
r["electricity_consumed_series_kw"] = round.(value.(CompressorConsumption), digits=3)
r["year_one_electricity_consumed_kwh"] = round(sum(r["electricity_consumed_series_kw"]), digits=2)

CompressorProduction = @expression(m, [ts in p.time_steps],
sum(p.s.compressor.efficiency_kwh_per_kg * p.production_factor[t, ts] * p.levelization_factor[t] *
m[Symbol("dvRatedProduction"*_n)][t,ts] for t in p.techs.compressor)
)
r["hydrogen_compressed_series_kg"] = round.(value.(CompressorProduction), digits=3)
r["year_one_hydrogen_compressed_kg"] = round(sum(r["hydrogen_compressed_series_kg"]), digits=2)

# PVPerUnitSizeOMCosts = p.om_cost_per_kw[t] * p.pwf_om * m[Symbol("dvSize"*_n)][t]
# r["lifecycle_om_cost_after_tax"] = round(value(PVPerUnitSizeOMCosts) * (1 - p.s.financial.owner_tax_rate_fraction), digits=0)
# r["lcoe_per_kwh"] = calculate_lcoe(p, r, get_pv_by_name(t, p.s.pvs))

d["Compressor"] = r

end
10 changes: 10 additions & 0 deletions src/results/electric_storage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ function add_electric_storage_results(m::JuMP.AbstractModel, p::REoptInputs, d::
))
end
end

if !isempty(p.techs.electrolyzer)
BattToElectrolyzer = (m[Symbol("dvStorageToElectrolyzer"*_n)][b, ts] for ts in p.time_steps)
r["storage_to_electrolyzer_series_kw"] = round.(value.(BattToElectrolyzer), digits=3)
end

if !isempty(p.techs.compressor)
BattToCompressor = (m[Symbol("dvStorageToCompressor"*_n)][b, ts] for ts in p.time_steps)
r["storage_to_compressor_series_kw"] = round.(value.(BattToCompressor), digits=3)
end
else
r["soc_series_fraction"] = []
r["storage_to_load_series_kw"] = []
Expand Down
10 changes: 10 additions & 0 deletions src/results/electric_utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ function add_electric_utility_results(m::JuMP.AbstractModel, p::AbstractInputs,
r["electric_to_load_series_kw"] = round.(value.(GridToLoad), digits=3)
r["electric_to_storage_series_kw"] = round.(value.(GridToBatt), digits=3)

if !isempty(p.techs.electrolyzer)
GridToElectrolyzer = (m[Symbol("dvGridToElectrolyzer"*_n)][ts] for ts in p.time_steps)
r["electric_to_electrolyzer_series_kw"] = round.(value.(GridToElectrolyzer), digits=3)
end

if !isempty(p.techs.compressor)
GridToCompressor = (m[Symbol("dvGridToCompressor"*_n)][ts] for ts in p.time_steps)
r["electric_to_compressor_series_kw"] = round.(value.(GridToCompressor), digits=3)
end

if _n=="" #only output emissions results if not a multinode model
r["annual_emissions_tonnes_CO2"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_CO2]*TONNE_PER_LB), digits=2)
r["annual_emissions_tonnes_NOx"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_NOx]*TONNE_PER_LB), digits=2)
Expand Down
72 changes: 72 additions & 0 deletions src/results/electrolyzer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# *********************************************************************************
# REopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# *********************************************************************************
"""
`Electrolyzer` results keys:
- `size_kw` Optimal electrolyzer capacity
- `lifecycle_om_cost_after_tax` Lifecycle operations and maintenance cost in present value, after tax
- `year_one_hydrogen_produced_kg` Total hydrogen produced over the first year
- `year_one_electricity_consumed_kwh` Total energy consumed by the electrolyzer over the first year
- `electricity_consumed_series_kw` Vector of power consumed by the electrolyzer to produce hydrogen over the first year
- `hydrogen_produced_series_kg` Vector of hydrogen produced by the electrolyzer going into the low pressure tank
!!! note "'Series' and 'Annual' energy outputs are average annual"
REopt performs load balances using average annual production values for technologies that include degradation.
Therefore, all timeseries (`_series`) and `annual_` results should be interpretted as energy outputs averaged over the analysis period.
"""
function add_electrolyzer_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dict; _n="")
# Adds the `Electrolyzer` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# Note: the node number is an empty string if evaluating a single `Site`.
print()
r = Dict{String, Any}()
r["size_kw"] = round(value(m[Symbol("dvSize"*_n)]["Electrolyzer"]), digits=4)

ElectrolyzerConsumption = @expression(m, [ts in p.time_steps],
sum(m[Symbol("dvProductionToElectrolyzer"*_n)][t, ts] for t in p.techs.elec)
+ m[Symbol("dvGridToElectrolyzer"*_n)][ts]
+ sum(m[Symbol("dvStorageToElectrolyzer"*_n)][b, ts] for b in p.s.storage.types.elec)
)
r["electricity_consumed_series_kw"] = round.(value.(ElectrolyzerConsumption), digits=3)
r["year_one_electricity_consumed_kwh"] = round(sum(r["electricity_consumed_series_kw"]), digits=2)

ElectrolyzerProduction = @expression(m, [ts in p.time_steps],
sum(p.s.electrolyzer.efficiency_kwh_per_kg * p.production_factor[t, ts] * p.levelization_factor[t] *
m[Symbol("dvRatedProduction"*_n)][t,ts] for t in p.techs.electrolyzer)
)
r["hydrogen_produced_series_kg"] = round.(value.(ElectrolyzerProduction), digits=3)
r["year_one_hydrogen_produced_kg"] = round(sum(r["hydrogen_produced_series_kg"]), digits=2)

# PVPerUnitSizeOMCosts = p.om_cost_per_kw[t] * p.pwf_om * m[Symbol("dvSize"*_n)][t]
# r["lifecycle_om_cost_after_tax"] = round(value(PVPerUnitSizeOMCosts) * (1 - p.s.financial.owner_tax_rate_fraction), digits=0)
# r["lcoe_per_kwh"] = calculate_lcoe(p, r, get_pv_by_name(t, p.s.pvs))

d["Electrolyzer"] = r

end
23 changes: 12 additions & 11 deletions src/results/hydrogen_load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ function add_hydrogen_load_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dic

r["load_series_kg"] = p.s.hydrogen_load.loads_kg
r["critical_load_series_kg"] = p.s.hydrogen_load.critical_loads_kg
r["annual_calculated_kg"] = round(
sum(r["load_series_kg"]) / p.s.settings.time_steps_per_hour, digits=2
)
r["annual_calculated_kg"] = round(sum(r["load_series_kg"]), digits=2)
# r["annual_calculated_kg"] = round(
# sum(r["load_series_kg"]) / p.s.settings.time_steps_per_hour, digits=2
# )

d["HydrogenLoad"] = r
nothing
end


function add_hydrogen_load_results(m::JuMP.AbstractModel, p::MPCInputs, d::Dict; _n="")
# Adds the `HydrogenLoad` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# Note: the node number is an empty string if evaluating a single `Site`.
# function add_hydrogen_load_results(m::JuMP.AbstractModel, p::MPCInputs, d::Dict; _n="")
# # Adds the `HydrogenLoad` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# # Note: the node number is an empty string if evaluating a single `Site`.

r = Dict{String, Any}()
# r = Dict{String, Any}()

r["load_series_kg"] = p.s.hydrogen_load.loads_kg
# r["load_series_kg"] = p.s.hydrogen_load.loads_kg

d["HydrogenLoad"] = r
nothing
end
# d["HydrogenLoad"] = r
# nothing
# end
100 changes: 100 additions & 0 deletions src/results/hydrogen_storage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# *********************************************************************************
# REopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# *********************************************************************************
"""
`HydrogenStorageLP` and `HydrogenStorageHP` results keys:
- `size_kg` Optimal inverter capacity
- `soc_series_fraction` Vector of normalized (0-1) state of charge values over the first year
- `storage_to_compressor_series_kw` Vector of power used to meet load over the first year
- `initial_capital_cost` Upfront capital cost for the hydrogen storage tank
"""
function add_hydrogen_storage_lp_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dict, b::String; _n="")
# Adds the `Storage` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# Note: the node number is an empty string if evaluating a single `Site`.

r = Dict{String, Any}()
r["size_kg"] = round(value(m[Symbol("dvStorageEnergy"*_n)][b]), digits=2)

if r["size_kg"] != 0
soc = (m[Symbol("dvStoredEnergy"*_n)][b, ts] for ts in p.time_steps)
r["soc_series_fraction"] = round.(value.(soc) ./ r["size_kg"], digits=3)

discharge = (m[Symbol("dvDischargeFromStorage"*_n)][b, ts] for ts in p.time_steps)
r["storage_to_compressor_series_kg"] = round.(value.(discharge), digits=3)

r["initial_capital_cost"] = r["size_kg"] * p.s.storage.attr[b].installed_cost_per_kg
else
r["soc_series_fraction"] = []
r["storage_to_compressor_series_kg"] = []
end

d[b] = r
nothing
end

function add_hydrogen_storage_hp_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dict, b::String; _n="")
# Adds the `Storage` results to the dictionary passed back from `run_reopt` using the solved model `m` and the `REoptInputs` for node `_n`.
# Note: the node number is an empty string if evaluating a single `Site`.

r = Dict{String, Any}()
r["size_kg"] = round(value(m[Symbol("dvStorageEnergy"*_n)][b]), digits=2)

if r["size_kg"] != 0
soc = (m[Symbol("dvStoredEnergy"*_n)][b, ts] for ts in p.time_steps)
r["soc_series_fraction"] = round.(value.(soc) ./ r["size_kg"], digits=3)

discharge = (m[Symbol("dvDischargeFromStorage"*_n)][b, ts] for ts in p.time_steps)
r["storage_to_h2_load_series_kg"] = round.(value.(discharge), digits=3)

r["initial_capital_cost"] = r["size_kg"] * p.s.storage.attr[b].installed_cost_per_kg
else
r["soc_series_fraction"] = []
r["storage_to_h2_load_series_kg"] = []
end

d[b] = r
nothing
end

# """
# MPC `ElectricStorage` results keys:
# - `soc_series_fraction` Vector of normalized (0-1) state of charge values over time horizon
# """
# function add_electric_storage_results(m::JuMP.AbstractModel, p::MPCInputs, d::Dict, b::String; _n="")
# r = Dict{String, Any}()

# soc = (m[Symbol("dvStoredEnergy"*_n)][b, ts] for ts in p.time_steps)
# r["soc_series_fraction"] = round.(value.(soc) ./ p.s.storage.attr[b].size_kwh, digits=3)

# discharge = (m[Symbol("dvDischargeFromStorage"*_n)][b, ts] for ts in p.time_steps)
# r["to_load_series_kw"] = round.(value.(discharge), digits=3)

# d[b] = r
# nothing
# end
13 changes: 12 additions & 1 deletion src/results/pv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ function add_pv_results(m::JuMP.AbstractModel, p::REoptInputs, d::Dict; _n="")
PVPerUnitSizeOMCosts = p.om_cost_per_kw[t] * p.pwf_om * m[Symbol("dvSize"*_n)][t]
r["lifecycle_om_cost_after_tax"] = round(value(PVPerUnitSizeOMCosts) * (1 - p.s.financial.owner_tax_rate_fraction), digits=0)
r["lcoe_per_kwh"] = calculate_lcoe(p, r, get_pv_by_name(t, p.s.pvs))

if !isempty(p.techs.electrolyzer)
PVtoElectrolyzer = (m[Symbol("dvProductionToElectrolyzer"*_n)][t, ts] for ts in p.time_steps)
r["to_electrolyzer_series_kw"] = round.(value.(PVtoElectrolyzer), digits=3)
end

if !isempty(p.techs.compressor)
PVtoCompressor = (m[Symbol("dvProductionToCompressor"*_n)][t, ts] for ts in p.time_steps)
r["to_compressor_series_kw"] = round.(value.(PVtoCompressor), digits=3)
end

d[t] = r
end
nothing
Expand Down Expand Up @@ -136,7 +147,7 @@ function add_pv_results(m::JuMP.AbstractModel, p::MPCInputs, d::Dict; _n="")
)
r["to_load_series_kw"] = round.(value.(PVtoLoad), digits=3)
Year1PvProd = (sum(m[Symbol("dvRatedProduction"*_n)][t,ts] * p.production_factor[t, ts] for ts in p.time_steps) * p.hours_per_time_step)
r["energy_produced_kwh"] = round(value(Year1PvProd), digits=0)
r["energy_produced_kwh"] = round(value(Year1PvProd), digits=0)
d[t] = r
end
nothing
Expand Down
Loading

0 comments on commit ed038b9

Please sign in to comment.