Skip to content

Commit

Permalink
Updated the market surrogates code
Browse files Browse the repository at this point in the history
  • Loading branch information
radhakrishnatg committed Jul 21, 2023
1 parent a0360a6 commit 214cc0f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dispatches/case_studies/nuclear_case/report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ This script performs price-taker analysis. The function `run_exhaustive_enumerat
### `market_surrogates.py`

Solves the conceptual design problem by embedding the surrogate models for market interactions. To run this script, `tensorflow` must be installed in the current environment. If it is not installed, the user can do so by running `pip install tensorflow` in a command window. The trained neural network surrogate models are included in the folder `nn_steady_state`. The function `run_exhaustive_enumeration` fixes the capacity of the electrolyzer and the selling price of hydrogen and computes the revenue from both electricity, and hydrogen markets and the annualized net present value, and saves the results in a `json` file.

### `generate_contour_plots.py`
This script generates the contour plots shown in the report.
18 changes: 17 additions & 1 deletion dispatches/case_studies/nuclear_case/report/market_surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def input_variable_equality_revenue(blk, i):
assert degrees_of_freedom(m) == 1

m.total_operating_cost = Expression(
expr=366 * 24 * (NP_CAPACITY * NPP_VOM + m.net_energy_to_pem * PEM_VOM)
expr=NUM_HOURS * (NP_CAPACITY * NPP_VOM + m.net_energy_to_pem * PEM_VOM)
)

m.pem_cap_cost = Expression(expr=ANN_FACTOR * PEM_CAPEX * 1000 * m.pem_capacity)
Expand Down Expand Up @@ -235,6 +235,7 @@ def run_exhaustive_enumeration(reserve, max_lmp):
results = {
"h2_price": h2_price, "pem_cap": pem_cap, "pem_cap_factor": {},
"elec_rev": {}, "h2_rev": {}, "net_npv": {}, "solver_stat": {},
"opt_pem_bid": {},
}

solver = get_solver()
Expand All @@ -257,13 +258,25 @@ def run_exhaustive_enumeration(reserve, max_lmp):

unsolved_cases = []

m.feasibility_constraint = Constraint(
expr=m.npp_capacity_factor >= 1 - m.pem_np_cap_ratio
)
m.feasibility_constraint.deactivate()

for idx2, pc in enumerate(pem_cap):
# This loop actually solves the problem and records the unsolved cases
m.threshold_price_definition.deactivate()
assert degrees_of_freedom(m) == 1

print("Solving case: ", (idx1, idx2))
m.pem_capacity.fix(pc * NP_CAPACITY)

soln = solver.solve(m)

m.feasibility_constraint.activate()
soln = solver.solve(m)
m.feasibility_constraint.deactivate()

if str(soln.solver.termination_condition) == "infeasible":
unsolved_cases.append((idx2, pc))
continue
Expand All @@ -274,6 +287,7 @@ def run_exhaustive_enumeration(reserve, max_lmp):
results["solver_stat"][str(idx1) + str(idx2)] = str(soln.solver.termination_condition)
results["pem_cap_factor"][str(idx1) + str(idx2)] = \
m.net_energy_to_pem.value / (m.pem_capacity.value * NUM_HOURS)
results["opt_pem_bid"][str(idx1) + str(idx2)] = m.threshold_price.value

if idx1 == 0 and idx2 == 1:
# Attempts to solve a few cases which failed earlier
Expand All @@ -294,6 +308,7 @@ def run_exhaustive_enumeration(reserve, max_lmp):
results["solver_stat"][str(idx1) + str(idx2)] = str(soln.solver.termination_condition)
results["pem_cap_factor"][str(idx1) + str(idx2)] = \
m.net_energy_to_pem.value / (m.pem_capacity.value * NUM_HOURS)
results["opt_pem_bid"][str(idx1) + str(idx2)] = m.threshold_price.value

for idx2, pc in unsolved_cases:
print("Solving case: ", (idx1, idx2))
Expand All @@ -311,6 +326,7 @@ def run_exhaustive_enumeration(reserve, max_lmp):
results["solver_stat"][str(idx1) + str(idx2)] = str(soln.solver.termination_condition)
results["pem_cap_factor"][str(idx1) + str(idx2)] = \
m.net_energy_to_pem.value / (m.pem_capacity.value * NUM_HOURS)
results["opt_pem_bid"][str(idx1) + str(idx2)] = m.threshold_price.value

print(remaining_cases)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ def run_exhaustive_enumeration(pem_capex=400):


if __name__ == "__main__":
run_exhaustive_enumeration(pem_capex=400)
run_exhaustive_enumeration(pem_capex=1200)

0 comments on commit 214cc0f

Please sign in to comment.