Skip to content

Commit

Permalink
Merge pull request #311 from jaredthomas68/run_optimization
Browse files Browse the repository at this point in the history
GreenHEART optimization interface
  • Loading branch information
jaredthomas68 committed Apr 29, 2024
2 parents 7b9c161 + 8199057 commit 95b1738
Show file tree
Hide file tree
Showing 21 changed files with 1,690 additions and 122 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,24 @@ ENV/
*.gz
*.db-wal

# GreenHEART structure specific
tests/greenheart/data/*
tests/greenheart/output.txt
tests/greenheart/test_hydrogen/data/*
tests/greenheart/test_hydrogen/output.txt
hopp/simulation/resource_files/*/*.csv
hopp/simulation/resource_files/*/*.srw
examples/reference_plants/*/output/*
*speed_dir_data.csv
examples/greenheart/*/data
examples/greenheart/*/figures
tests/greenheart/reports/
tests/greenheart/test_hydrogen/output/
tests/hopp/data/
tests/reports/
tests/data/
tests/resource_files/
tests/test_dump.txt
output*
snopt_history.txt
reports/*
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,89 @@ steel:
"capital gains tax rate": 0.15
"leverage after tax nominal discount rate": 0.10893
"debt equity ratio of initial financing": 0.624788
"debt interest rate": 0.050049
"debt interest rate": 0.050049

opt_options:
opt_flag: True
general:
folder_output: "output"
fname_output: "optimization_log"
design_variables:
electrolyzer_rating_kw:
flag: True
lower: 1000.0
upper: 2000000.0
units: "kW"
pv_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
wave_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
battery_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
battery_capacity_kwh:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
turbine_x:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
turbine_y:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
constraints:
turbine_spacing:
flag: False
lower: 0.0
boundary_distance:
flag: False
lower: 0.0
user: {}
merit_figure: "lcos"
merit_figure_user:
name: "lcos"
max_flag: False
ref: 1.0 # value of objective that scales to 1.0
driver:
optimization:
flag: True
solver: "SNOPT"
tol: 1E-6
gradient_method: "snopt_fd" # can be one of ['pyopt_fd', 'openmdao', 'snopt_fd']
max_major_iter: 10
max_minor_iter: 30
# time_limit: 10 # (sec) optional
# "hist_file_name: "snopt_history.txt", # optional
verify_level: 0 # optional
step_calc: None
form: "forward" # type of finite differences to use, can be one of ["forward", "backward", "central"]
debug_print: False
design_of_experiments:
flag: False
run_parallel: False
generator: FullFact # [Uniform, FullFact, PlackettBurman, BoxBehnken, LatinHypercube]
num_samples: 5 # Number of samples to evaluate model at (Uniform and LatinHypercube only)
seed: 2
levels: 5 # Number of evenly spaced levels between each design variable lower and upper bound (FullFactorial only)
criterion: None # [None, center, c, maximin, m, centermaximin, cm, correelation, corr]
iterations: 1
debug_print: False
step_size_study:
flag: False
recorder:
flag: True
file_name: "record.sql"
includes: False
23 changes: 11 additions & 12 deletions examples/reference_plants/01-onshore-steel-mn/onshore-steel-mn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
run_simulation,
GreenHeartSimulationConfig,
)
from greenheart.tools.optimization.gc_run_greenheart import run_greenheart

# run the stuff
if __name__ == "__main__":
Expand All @@ -44,18 +45,16 @@
output_level=7,
)

config.hopp_config["technologies"]["wind"]["fin_model"]["system_costs"]["om_fixed"][
0
] = config.hopp_config["config"]["cost_info"]["wind_om_per_kw"]
config.hopp_config["technologies"]["pv"]["fin_model"]["system_costs"]["om_fixed"][
0
] = config.hopp_config["config"]["cost_info"]["pv_om_per_kw"]
config.hopp_config["technologies"]["battery"]["fin_model"]["system_costs"][
"om_batt_fixed_cost"
] = config.hopp_config["config"]["cost_info"]["battery_om_per_kw"]
# for analysis
prob, config = run_greenheart(config, run_only=True)

lcoe, lcoh, steel_finance, _ = run_simulation(config)
# for optimization
# prob, config = run_greenheart(config, run_only=False)

lcoe = prob.get_val("lcoe", units="USD/(MW*h)")
lcoh = prob.get_val("lcoh", units="USD/kg")
lcos = prob.get_val("lcos", units="USD/t")

print("LCOE: ", lcoe * 1e3, "[$/MWh]")
print("LCOE: ", lcoe, "[$/MWh]")
print("LCOH: ", lcoh, "[$/kg]")
print("LCOS: ", steel_finance.sol.get("price"), "[$/metric-tonne]")
print("LCOS: ", lcos, "[$/metric-tonne]")
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,89 @@ ammonia:
"capital gains tax rate": 0.15
"leverage after tax nominal discount rate": 0.10893
"debt equity ratio of initial financing": 0.624788
"debt interest rate": 0.050049
"debt interest rate": 0.050049

opt_options:
opt_flag: True
general:
folder_output: "output"
fname_output: "optimization_log"
design_variables:
electrolyzer_rating_kw:
flag: True
lower: 1000.0
upper: 2000000.0
units: "kW"
pv_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
wave_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
battery_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
battery_capacity_kwh:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
turbine_x:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
turbine_y:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
constraints:
turbine_spacing:
flag: False
lower: 0.0
boundary_distance:
flag: False
lower: 0.0
user: {}
merit_figure: "lcoa"
merit_figure_user:
name: "lcoa"
max_flag: False
ref: 1.0 # value of objective that scales to 1.0
driver:
optimization:
flag: True
solver: "SNOPT"
tol: 1E-6
gradient_method: "snopt_fd" # can be one of ['pyopt_fd', 'openmdao', 'snopt_fd']
max_major_iter: 10
max_minor_iter: 30
# time_limit: 10 # (sec) optional
# "hist_file_name: "snopt_history.txt", # optional
verify_level: 0 # optional
step_calc: None
form: "forward" # type of finite differences to use, can be one of ["forward", "backward", "central"]
debug_print: False
design_of_experiments:
flag: False
run_parallel: False
generator: FullFact # [Uniform, FullFact, PlackettBurman, BoxBehnken, LatinHypercube]
num_samples: 5 # Number of samples to evaluate model at (Uniform and LatinHypercube only)
seed: 2
levels: 5 # Number of evenly spaced levels between each design variable lower and upper bound (FullFactorial only)
criterion: None # [None, center, c, maximin, m, centermaximin, cm, correelation, corr]
iterations: 1
debug_print: False
step_size_study:
flag: False
recorder:
flag: True
file_name: "record.sql"
includes: False
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
run_simulation,
GreenHeartSimulationConfig,
)
from greenheart.tools.optimization.gc_run_greenheart import run_greenheart

# run the stuff
if __name__ == "__main__":
Expand All @@ -44,18 +45,16 @@
output_level=7,
)

config.hopp_config["technologies"]["wind"]["fin_model"]["system_costs"]["om_fixed"][
0
] = config.hopp_config["config"]["cost_info"]["wind_om_per_kw"]
config.hopp_config["technologies"]["pv"]["fin_model"]["system_costs"]["om_fixed"][
0
] = config.hopp_config["config"]["cost_info"]["pv_om_per_kw"]
config.hopp_config["technologies"]["battery"]["fin_model"]["system_costs"][
"om_batt_fixed_cost"
] = config.hopp_config["config"]["cost_info"]["battery_om_per_kw"]
# for analysis
prob, config = run_greenheart(config, run_only=True)

lcoe, lcoh, _, ammonia_finance = run_simulation(config)
# for optimization
# prob, config = run_greenheart(config, run_only=False)

lcoe = prob.get_val("lcoe", units="USD/(MW*h)")
lcoh = prob.get_val("lcoh", units="USD/kg")
lcoa = prob.get_val("lcoa", units="USD/kg")

print("LCOE: ", lcoe * 1e3, "[$/MWh]")
print("LCOE: ", lcoe, "[$/MWh]")
print("LCOH: ", lcoh, "[$/kg]")
print("LCOA: ", ammonia_finance.sol.get("price"), "[$/kg-NH3]")
print("LCOA: ", lcoa, "[$/kg]")
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,88 @@ plant_design:
wind_location: "offshore" # can be one of ["onshore", "offshore"]
pv_location: "platform" # can be one of ["none", "onshore", "platform"]
battery_location: "none" # can be one of ["none", "onshore", "platform"]

opt_options:
opt_flag: True
general:
folder_output: "output"
fname_output: "optimization_log"
design_variables:
electrolyzer_rating_kw:
flag: True
lower: 1000.0
upper: 2000000.0
units: "kW"
pv_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
wave_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
battery_capacity_kw:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW"
battery_capacity_kwh:
flag: False
lower: 1000.0
upper: 2000000.0
units: "kW*h"
turbine_x:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
turbine_y:
flag: False
lower: 0.0
upper: 20000.0
units: "m"
constraints:
turbine_spacing:
flag: False
lower: 0.0
boundary_distance:
flag: False
lower: 0.0
user: {}
merit_figure: "lcoh"
merit_figure_user:
name: "lcoh"
max_flag: False
ref: 1.0 # value of objective that scales to 1.0
driver:
optimization:
flag: True
solver: "SNOPT"
tol: 1E-6
gradient_method: "snopt_fd" # can be one of ['pyopt_fd', 'openmdao', 'snopt_fd']
max_major_iter: 1
max_minor_iter: 2
# time_limit: 10 # (sec) optional
# "hist_file_name: "snopt_history.txt", # optional
verify_level: 0 # optional
step_calc: None
form: "forward" # type of finite differences to use, can be one of ["forward", "backward", "central"]
debug_print: False
design_of_experiments:
flag: False
run_parallel: False
generator: FullFact # [Uniform, FullFact, PlackettBurman, BoxBehnken, LatinHypercube]
num_samples: 5 # Number of samples to evaluate model at (Uniform and LatinHypercube only)
seed: 2
levels: 5 # Number of evenly spaced levels between each design variable lower and upper bound (FullFactorial only)
criterion: None # [None, center, c, maximin, m, centermaximin, cm, correelation, corr]
iterations: 1
debug_print: False
step_size_study:
flag: False
recorder:
flag: True
file_name: "record.sql"
includes: False

0 comments on commit 95b1738

Please sign in to comment.