Skip to content

Commit

Permalink
Merge branch 'dispatches_cleanup' of https://github.com/MarcusHolly/d…
Browse files Browse the repository at this point in the history
…ispatches into dispatches_cleanup
  • Loading branch information
MarcusHolly committed Dec 22, 2023
2 parents 8a36ac7 + c2b58b4 commit 562b43f
Show file tree
Hide file tree
Showing 56 changed files with 38,559 additions and 45,529 deletions.
8 changes: 7 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ version: 2
sphinx:
fail_on_warning: true

build:
os: "ubuntu-22.04"
tools:
python: "3.8"

python:
version: "3.8"
install:
- requirements: requirements-dev.txt
- method: pip
path: .
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def SRD_eqn(b, t):
elif b.config.CO2_capture_rate_surrogates == Surrogates.PZ_97_capture:
return b.SRD[t] == - 912.90813190561812007218 * CO2leanloading + 963.87626280230563224904 * exp(CO2leanloading) - 840.95461087585590576055 * (molality/2.)**2 - 614.38277546147764951456 * CO2leanloading**2 + 274.40532024830611135258 * (molality/2.)**3 - 0.61984641382653959951199 * (molality*CO2leanloading/2.)**3 + 0.26430328623580695568407 * (molality/CO2leanloading/2.) - 11.869291574687059309667 * (CO2leanloading/molality/0.5) - 0.23630953358941128236714E-002 * (molality/CO2leanloading/2.)**2
elif b.config.CO2_capture_rate_surrogates == Surrogates.PZ_90to97_capture:
return b.SRD[t] == - 0.10526756950236890175709 * Capture + 0.52057178809591142520929 * lean_loading + 0.98788205977359255793857 * molality + 2.0990364304677582296677 * Capture**0.5 + 3.5938248110847506033849 * lean_loading**0.5 - 6.3111812164050720141972 * molality**0.5 + 2.4029805693688151002618 * lean_loading**3 - 0.10937466124959506139080E-001 * Capture/molality - 41.496993880686794398116 * lean_loading/Capture + 0.36946342949766633467767E-001 * molality/lean_loading
return b.SRD[t] == - 0.10526756950236890175709 * Capture + 0.52057178809591142520929 * CO2leanloading + 0.98788205977359255793857 * molality + 2.0990364304677582296677 * Capture**0.5 + 3.5938248110847506033849 * CO2leanloading**0.5 - 6.3111812164050720141972 * molality**0.5 + 2.4029805693688151002618 * CO2leanloading**3 - 0.10937466124959506139080E-001 * Capture/molality - 41.496993880686794398116 * CO2leanloading/Capture + 0.36946342949766633467767E-001 * molality/CO2leanloading
elif b.config.CO2_capture_rate_surrogates == Surrogates.rel_PZAS_5mol_capture:
return (- 22.312295301354438947783 * CO2leanloading + 117.51384451486856619340 * CO2leanloading**2 - 269.05987870514132964672 * CO2leanloading**3 + 234.98153128275288281657 * CO2leanloading**4 + 3.9380879255782788028739)
elif b.config.CO2_capture_rate_surrogates == Surrogates.PZ_ref1_90_capture:
Expand Down Expand Up @@ -365,7 +365,7 @@ def LL_flowrate(b, t):
elif b.config.CO2_capture_rate_surrogates == Surrogates.PZ_97_capture:
return - 11073017307.372232437134 * CO2leanloading + 868882.20868137793149799 * log(CO2leanloading) - 73653243483.647430419922 * exp(molality/2.) + 11052450134.832271575928 * exp(CO2leanloading) + 141797181109.30328369141 * (molality/2.)**2 - 5395322021.3101339340210 * CO2leanloading**2 - 920354.31067807460203767 * (molality*CO2leanloading/2.) - 117144381.90464735031128 * (molality*CO2leanloading/2.)**3 - 6153045658.4519367218018 * (CO2leanloading/molality/0.5)**3
elif b.config.CO2_capture_rate_surrogates == Surrogates.PZ_90to97_capture:
return 21493.893918343124823878 * Capture - 18837259.090658042579889 * lean_loading - 303798.35064064717153087 * molality - 547220.78199295536614954 * Capture**0.5 + 7997911.0828296802937984 * lean_loading**0.5 + 1594229.8231671806424856 * molality**0.5 + 16593654.797202151268721 * lean_loading**2 + 58165.759382280644786078 * Capture*lean_loading + 60595.207259644026635215 * Capture/molality + 60446137.647265411913395 * (lean_loading/molality)**2
return 21493.893918343124823878 * Capture - 18837259.090658042579889 * CO2leanloading - 303798.35064064717153087 * molality - 547220.78199295536614954 * Capture**0.5 + 7997911.0828296802937984 * CO2leanloading**0.5 + 1594229.8231671806424856 * molality**0.5 + 16593654.797202151268721 * CO2leanloading**2 + 58165.759382280644786078 * Capture*CO2leanloading + 60595.207259644026635215 * Capture/molality + 60446137.647265411913395 * (CO2leanloading/molality)**2
# No data for PZAS, using same as PZ 95 capture
elif b.config.CO2_capture_rate_surrogates == Surrogates.rel_PZAS_5mol_capture:
return - 8128346023.5960435867310 * CO2leanloading + 8097036304.4302654266357 * exp(CO2leanloading) + 143943.79958957055350766 * (molality/4.)**2 - 3906104299.9280681610107 * CO2leanloading**2 - 1694548695.5476403236389 * CO2leanloading**3 - 326827.12907762406393886 * (molality*CO2leanloading/4.)**2 + 14089575.472042093053460 * (CO2leanloading/molality/0.25) - 4257.3482804741406653193 * (molality/CO2leanloading/4.)**2 - 22772347.982399865984917 * (CO2leanloading/molality/0.25)**2 + 131.22409336241202026940 * (molality/CO2leanloading/4.)**3 + 22174561.087608262896538 * (CO2leanloading/molality/0.25)**3 - 8094525387.7033281326294
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from pyomo.util.infeasible import (log_infeasible_constraints,
log_close_to_bounds)
from IPython import embed
logging.getLogger('pyomo.repn.plugins.nl_writer').setLevel(logging.ERROR)
logging.basicConfig(level=logging.INFO)


Expand Down Expand Up @@ -961,33 +962,146 @@ def initialize(m, solver=None, optarg=None, outlvl=idaeslog.NOTSET):
"""Initialize the units included in the discharge model
"""

# Include scaling factors
iscale.calculate_scaling_factors(m)
iscale.calculate_scaling_factors(m)

# Initialize splitter
propagate_state(m.fs.discharge.fwh4_source_disjunct.fwh4_to_essplit)
propagate_state(m.fs.discharge.condpump_source_disjunct.condpump_to_essplit)
propagate_state(m.fs.discharge.booster_source_disjunct.booster_to_essplit)
propagate_state(m.fs.discharge.bfp_source_disjunct.bfp_to_essplit)
propagate_state(m.fs.discharge.fwh9_source_disjunct.fwh9_to_essplit)
m.fs.discharge.es_split.initialize(outlvl=outlvl,
optarg=optarg)

# Deactivate feed water heat constraints for initialization
for i in m.set_fwh:
m.fs.fwh[i].fwh_vfrac_constraint.deactivate()

# Initialize feed water heat 1
propagate_state(m.fs.discharge.condpump_source_disjunct.essplit_to_fwh1)
propagate_state(m.fs.discharge.fwh4_source_disjunct.condpump_to_fwh1)
propagate_state(m.fs.discharge.booster_source_disjunct.condpump_to_fwh1)
propagate_state(m.fs.discharge.bfp_source_disjunct.condpump_to_fwh1)
propagate_state(m.fs.discharge.fwh9_source_disjunct.condpump_to_fwh1)
m.fs.fwh[1].initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize feed water heat 5
propagate_state(m.fs.discharge.condpump_source_disjunct.fwh4_to_fwh5)
propagate_state(m.fs.discharge.fwh4_source_disjunct.essplit_to_fwh5)
propagate_state(m.fs.discharge.booster_source_disjunct.fwh4_to_fwh5)
propagate_state(m.fs.discharge.bfp_source_disjunct.fwh4_to_fwh5)
propagate_state(m.fs.discharge.fwh9_source_disjunct.fwh4_to_fwh5)
m.fs.fwh[5].initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize feed water heat 6
propagate_state(m.fs.discharge.condpump_source_disjunct.booster_to_fwh6)
propagate_state(m.fs.discharge.fwh4_source_disjunct.booster_to_fwh6)
propagate_state(m.fs.discharge.booster_source_disjunct.essplit_to_fwh6)
propagate_state(m.fs.discharge.bfp_source_disjunct.booster_to_fwh6)
propagate_state(m.fs.discharge.fwh9_source_disjunct.booster_to_fwh6)
m.fs.fwh[6].initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize feed water heat 8
propagate_state(m.fs.discharge.condpump_source_disjunct.bfp_to_fwh8)
propagate_state(m.fs.discharge.fwh4_source_disjunct.bfp_to_fwh8)
propagate_state(m.fs.discharge.booster_source_disjunct.bfp_to_fwh8)
propagate_state(m.fs.discharge.bfp_source_disjunct.essplit_to_fwh8)
propagate_state(m.fs.discharge.fwh9_source_disjunct.bfp_to_fwh8)
m.fs.fwh[8].initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize boiler
propagate_state(m.fs.discharge.condpump_source_disjunct.fwh9_to_boiler)
propagate_state(m.fs.discharge.fwh4_source_disjunct.fwh9_to_boiler)
propagate_state(m.fs.discharge.booster_source_disjunct.fwh9_to_boiler)
propagate_state(m.fs.discharge.bfp_source_disjunct.fwh9_to_boiler)
propagate_state(m.fs.discharge.fwh9_source_disjunct.essplit_to_boiler)
m.fs.boiler.initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize discharge heat exchanger
propagate_state(m.fs.discharge.essplit_to_hxd)
m.fs.discharge.hxd.initialize(outlvl=outlvl,
optarg=optarg)

# Deactivate IP-LP source turbine constraint for initialization
m.fs.discharge.iplp_source_disjunct.es_turbine.constraint_esturbine_temperature_out.deactivate()

# Initialize IP-LP source turbine
propagate_state(m.fs.discharge.iplp_source_disjunct.hxd_to_esturbine)

m.fs.discharge.iplp_source_disjunct.es_turbine.initialize(outlvl=outlvl,
optarg=optarg)

# Initialize turbine splitter 6
m.fs.turbine_splitter[6].initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize IP-LP source CCS splitter
propagate_state(m.fs.discharge.iplp_source_disjunct.t6split_to_ccsplit)
m.fs.discharge.iplp_source_disjunct.ccs_split.initialize(outlvl=outlvl,
optarg=solver.options)

# Initialize boiler feed pump turbine
propagate_state(m.fs.discharge.hxd_source_disjunct.t6split_to_bfpt)
propagate_state(m.fs.discharge.iplp_source_disjunct.bfptsplit_to_bfpt)
m.fs.bfpt.initialize(outlvl=outlvl,
optarg=solver.options)

# Deactivate CCS reboiler constraint for initialization
# m.fs.eq_reboiler_heat_duty.deactivate()

# Initialize CCS reboiler
propagate_state(m.fs.discharge.hxd_source_disjunct.hxd_to_ccs)
propagate_state(m.fs.discharge.iplp_source_disjunct.ccsplit_to_ccs)
m.fs.ccs_reboiler.initialize(outlvl=outlvl,
optarg=solver.options)

# Reactivate feed water heater and IP-LP source turbine constraints
for j in m.set_fwh:
m.fs.fwh[j].fwh_vfrac_constraint.activate()
m.fs.discharge.iplp_source_disjunct.es_turbine.constraint_esturbine_temperature_out.activate()
m.fs.eq_reboiler_heat_duty.activate()

# Fix disjuncts for initialization
m.fs.discharge.condpump_source_disjunct.indicator_var.fix(False)
m.fs.discharge.fwh4_source_disjunct.indicator_var.fix(False)
m.fs.discharge.booster_source_disjunct.indicator_var.fix(False)
m.fs.discharge.bfp_source_disjunct.indicator_var.fix(False)
m.fs.discharge.fwh9_source_disjunct.indicator_var.fix(False)

m.fs.discharge.iplp_source_disjunct.indicator_var.fix(False)
m.fs.discharge.hxd_source_disjunct.indicator_var.fix(False)

# Add options to GDPopt
m_init = m.clone()
m_init_var_names = [v for v in m_init.component_data_objects(Var)]
m_orig_var_names = [v for v in m.component_data_objects(Var)]

# propagate_state(m.fs.discharge.hxd_to_esturbine)
# m.fs.discharge.es_turbine.initialize(outlvl=outlvl,
# optarg=optarg)

TransformationFactory("gdp.fix_disjuncts").apply_to(m_init)

# Check and raise an error if the degrees of freedom are not 0
if not degrees_of_freedom(m) == 0:
if not degrees_of_freedom(m_init) == 0:
raise ConfigurationError(
"The degrees of freedom after building the model are not 0. "
"You have {} degrees of freedom. "
"Please check your inputs to ensure a square problem "
"before initializing the model.".format(degrees_of_freedom(m))
)

# Solve initialization
init_results = solver.solve(m, options=optarg)
init_results = solver.solve(m_init, options=optarg)
print("Discharge model initialization solver termination = ",
init_results.solver.termination_condition)

for v1, v2 in zip(m_init_var_names, m_orig_var_names):
v2.value == v1.value


print("Discharge model initialization solver termination:",
init_results.solver.termination_condition)
print("************* Discharge Model Initialized ******************")
Expand Down Expand Up @@ -1194,11 +1308,34 @@ def op_cost_rule(b):
)

# Solve cost initialization
print()
# Add options to NLP solver

# Add options to GDPopt
m_init = m.clone()
m_init_var_names = [v for v in m_init.component_data_objects(Var)]
m_orig_var_names = [v for v in m.component_data_objects(Var)]

TransformationFactory("gdp.fix_disjuncts").apply_to(m_init)

# Check and raise an error if the degrees of freedom are not 0
if not degrees_of_freedom(m_init) == 0:
raise ConfigurationError(
"The degrees of freedom after building the model are not 0. "
"You have {} degrees of freedom. "
"Please check your inputs to ensure a square problem "
"before initializing the model.".format(degrees_of_freedom(m))
)

# Solve initialization
# Add options to NLP solver
optarg = {"tol": 1e-8,
"max_iter": 300}
cost_results = solver.solve(m, options=optarg)
cost_results = solver.solve(m_init, options=optarg)
print("Cost pre-initialization solver termination = ",
cost_results.solver.termination_condition)

for v1, v2 in zip(m_init_var_names, m_orig_var_names):
v2.value == v1.value
print()
print("Cost initialization solver termination:",
cost_results.solver.termination_condition)
print("******************** Costing Initialized *************************")
Expand Down Expand Up @@ -1387,6 +1524,16 @@ def main(m_usc, solver=None, optarg=None):
# Add cost correlations
build_costing(m, solver=solver)

# Unfix disjuncts after initialization
m.fs.discharge.condpump_source_disjunct.indicator_var.unfix()
m.fs.discharge.fwh4_source_disjunct.indicator_var.unfix()
m.fs.discharge.booster_source_disjunct.indicator_var.unfix()
m.fs.discharge.bfp_source_disjunct.indicator_var.unfix()
m.fs.discharge.fwh9_source_disjunct.indicator_var.unfix()

m.fs.discharge.iplp_source_disjunct.indicator_var.unfix()
m.fs.discharge.hxd_source_disjunct.indicator_var.unfix()

# Add bounds
add_bounds(m, power_max=power_max)

Expand Down Expand Up @@ -1740,11 +1887,11 @@ def model_analysis(m, heat_duty=None):

# Build discharge model
m = main(m_usc, solver=solver, optarg=optarg)

# Solve design model optimization problem
heat_duty_data = 148.5
model_analysis(m, heat_duty=heat_duty_data)

# Solve model using GDPopt
print()
print('**********Start solution of GDP discharge model using GDPopt')
Expand All @@ -1760,11 +1907,11 @@ def model_analysis(m, heat_duty=None):

source = "iplp"
# source = "hxd"

results = run_nlps(m,
solver=solver,
fluid=fluid,
source=source)

# Print results
print_results(m, results)
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@
# IDAES Imports
from idaes.core.util.model_statistics import degrees_of_freedom
from idaes.core.util.initialization import propagate_state
from idaes.power_generation.unit_models.boiler_fireside import BoilerFireside
from idaes.generic_models.unit_models import Heater, MomentumMixingType
from idaes.core.util import get_solver
from idaes.models_extra.power_generation.unit_models.boiler_fireside import BoilerFireside
from idaes.models.unit_models import Heater, MomentumMixingType
from idaes.core.solvers import get_solver
import idaes.core.util.scaling as iscale
import idaes.logger as idaeslog
from idaes.power_generation.unit_models.helm import HelmMixer, HelmSplitter
from idaes.power_generation.properties import FlueGasParameterBlock
from idaes.models_extra.power_generation.unit_models.helm import HelmMixer, HelmSplitter
from idaes.models_extra.power_generation.properties import FlueGasParameterBlock
# Dispatches Imports
from dispatches.models.fossil_case.ultra_supercritical_plant import (
from dispatches.case_studies.fossil_case.ultra_supercritical_plant import (
ultra_supercritical_powerplant as usc)
# from idaes.power_generation.carbon_capture.piperazine_surrogates.\
# co2_capture_system import CO2Capture
from dispatches.models.fossil_case.ultra_supercritical_plant.\
co2_capture_system import CO2Capture
from co2_capture_system import CO2Capture


def add_fireside(m):
Expand All @@ -53,13 +52,13 @@ def add_fireside(m):
'NOx': '140'} # NOx PPM

m.fs.boiler_fireside = BoilerFireside(
default={"dynamic": False,
"property_package": m.fs.prop_fluegas,
"calculate_PA_SA_flows": True,
"number_of_zones": 1,
"has_platen_superheater": True,
"has_roof_superheater": True,
"surrogate_dictionary": boiler_input_dict})
dynamic=False,
property_package=m.fs.prop_fluegas,
calculate_PA_SA_flows=True,
number_of_zones=1,
has_platen_superheater=True,
has_roof_superheater=True,
surrogate_dictionary=boiler_input_dict)
m.fs.boiler_fireside.eq_surr_waterwall_heat.deactivate()
m.fs.boiler_fireside.eq_surr_platen_heat.deactivate()
m.fs.boiler_fireside.eq_surr_roof_heat.deactivate()
Expand Down Expand Up @@ -197,25 +196,19 @@ def eq_pressure(b, t):

# Add a dummy heater block to extract steam for specific reformer duty
m.fs.ccs_reformer = Heater(
default={
"dynamic": False,
"property_package": m.fs.prop_water,
"has_pressure_change": True
}
dynamic=False,
property_package=m.fs.prop_water,
has_pressure_change=True
)
# Add a splitter to take the main steam from boiler for CO2 Capture
m.fs.ccs_splitter = HelmSplitter(
default={
"property_package": m.fs.prop_water
}
property_package=m.fs.prop_water
)
# Add a mixer to add the ccs exhaust to condenser
m.fs.ccs_mix = HelmMixer(
default={
"momentum_mixing_type": MomentumMixingType.minimize,
"inlet_list": ["bfpt", "ccs"],
"property_package": m.fs.prop_water,
}
momentum_mixing_type=MomentumMixingType.minimize,
inlet_list=["bfpt", "ccs"],
property_package=m.fs.prop_water,
)

# Add constraint to equate the co2 capture reformer duty with ccs heater
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@
"print(\"Cost Parameters:\")\n",
"print(f\"Wind Capital Cost\\t\\t\\t{wind_cap_cost} $/kW\")\n",
"print(f\"Wind Fixed Operating Cost\\t\\t{wind_op_cost} $/kW-yr\")\n",
"print(f\"Battery Capital Cost\\t\\t\\t{batt_cap_cost} $/kW\")\n",
"print(f\"Battery Power Capital Cost \\t\\t\\t{batt_cap_cost_kw} $/kW\")\n",
"print(f\"Battery Energy Capital Cost \\t\\t\\t{batt_cap_cost_kwh} $/kWh\")\n",
"print(f\"PEM Capital Cost\\t\\t\\t{pem_cap_cost} $/kW\")\n",
"print(f\"PEM Fixed Operating Cost\\t\\t{pem_op_cost} $/kW-yr\")\n",
"print(f\"PEM Variable Operating Cost\\t\\t{pem_var_cost} $/kWh\")\n",
Expand Down Expand Up @@ -829,8 +830,7 @@
"tank_type = 'simple'\n",
"input_params['wind_resource'] = {t:\n",
" {'wind_resource_config': {\n",
" 'resource_speed': [wind_speeds[t]]\n",
" }\n",
" 'capacity_factor': [wind_cfs[t]]}\n",
" } for t in range(7)}\n",
" \n",
"mp_model = MultiPeriodModel(n_time_points=7,\n",
Expand Down
Loading

0 comments on commit 562b43f

Please sign in to comment.