Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peng-Robinson failing to solve pure #9

Open
Mahaki-Leach opened this issue Nov 19, 2024 · 4 comments
Open

Peng-Robinson failing to solve pure #9

Mahaki-Leach opened this issue Nov 19, 2024 · 4 comments

Comments

@Mahaki-Leach
Copy link
Collaborator

Idaes fails to solve single components
e.g. build_package("peng-robinson", ["benzene"], ["Liq", "Vap"])

currently assuming state definition change to enthalpy will fix this.

@alma-walmsley
Copy link
Collaborator

alma-walmsley commented Jan 4, 2025

from pyomo.environ import ConcreteModel, Constraint, Var, SolverFactory, value, assert_optimal_termination
from idaes.core import FlowsheetBlock
from property_packages.build_package import build_package

m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.properties = build_package("peng-robinson", ["water"])
m.fs.state = m.fs.properties.build_state_block([0], defined_state=True)
sb = m.fs.state[0]

sb.flow_mol.fix(1)
sb.pressure.fix(101325)
sb.constrain("enth_mol", -40000)
sb.mole_frac_comp["water"].fix(1)

m.fs.state.initialize(outlvl=1)

opt = SolverFactory('ipopt')

def try_solve(enth_val):
    sb.constraints.del_component("enth_mol")
    sb.constrain("enth_mol", enth_val)
    res = opt.solve(m)
    assert_optimal_termination(res)
    print(f"[enth_mol={enth_val}]: Temperature: {value(sb.temperature)}")

# now try to solve the block with different enthalpy values
# and observe the temperature
try_solve(-40000)
try_solve(-41000)
try_solve(-42000)
try_solve(-43000)
try_solve(-44000)
try_solve(-45000)
try_solve(-46000)

the temperature values we're getting here might suggest a modelling error

[enth_mol=-40000]: Temperature: 1843.1391638994066
[enth_mol=-41000]: Temperature: 1860.375110055527
[enth_mol=-42000]: Temperature: 1851.107709183429
[enth_mol=-43000]: Temperature: 1769.2528300282333
[enth_mol=-44000]: Temperature: 1781.3766245135319
[enth_mol=-45000]: Temperature: 1795.091817831292
[enth_mol=-46000]: Temperature: 1810.0660459820208

@alma-walmsley
Copy link
Collaborator

alma-walmsley commented Jan 4, 2025

The problems with initialization come at the "Phase equilibrium initialization" step.

before initialization:

Vars:
fs.state[0].flow_mol: 1 fixed
fs.state[0].mole_frac_comp: water: 1.0 fixed
fs.state[0].pressure: 101325 fixed
fs.state[0].temperature: 298.15 fixed
fs.state[0].flow_mol_phase: Liq: 0.99999 unfixed
fs.state[0].flow_mol_phase: Vap: 1e-05 unfixed
fs.state[0].mole_frac_phase_comp: ('Liq', 'water'): 1.0 unfixed
fs.state[0].mole_frac_phase_comp: ('Vap', 'water'): 1.0000005210883731 unfixed
fs.state[0].phase_frac: Liq: 0.99999 unfixed
fs.state[0].phase_frac: Vap: 1e-05 unfixed
fs.state[0]._teq: ('Vap', 'Liq'): 374.51545147861975 unfixed
fs.state[0]._t1_Vap_Liq: 374.51545535191264 unfixed
fs.state[0].temperature_bubble: ('Vap', 'Liq'): 374.51545535191264 unfixed
fs.state[0]._mole_frac_tbub: ('Vap', 'Liq', 'water'): 1.0000005210883731 unfixed
fs.state[0].log_mole_frac_comp: water: -4.073182704905997e-08 unfixed
fs.state[0].log_mole_frac_tbub: ('Vap', 'Liq', 'water'): -4.4723563077377095e-08 unfixed
fs.state[0].temperature_dew: ('Vap', 'Liq'): 374.51545147861975 unfixed
fs.state[0]._mole_frac_tdew: ('Vap', 'Liq', 'water'): 0.9999995664086361 unfixed
fs.state[0].log_mole_frac_tdew: ('Vap', 'Liq', 'water'): -8.029931331992884e-08 unfixed
fs.state[0].log_mole_frac_phase_comp: ('Liq', 'water'): 0.0 unfixed
fs.state[0].log_mole_frac_phase_comp: ('Vap', 'water'): 5.210883731177063e-07 unfixed

--------------------------------
Constraints:
fs.state[0].total_flow_balance: active
fs.state[0].component_flow_balances: water: active
fs.state[0].sum_mole_frac: active
fs.state[0].phase_fraction_constraint: Liq: active
fs.state[0].phase_fraction_constraint: Vap: active
fs.state[0]._t1_constraint_Vap_Liq: active
fs.state[0].eq_temperature_bubble: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_comp_eqn: water: active
fs.state[0].log_mole_frac_tbub_eqn: ('Vap', 'Liq', 'water'): active
fs.state[0].eq_mole_frac_tbub: ('Vap', 'Liq'): active
fs.state[0]._teq_constraint_Vap_Liq: active
fs.state[0].eq_temperature_dew: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_tdew_eqn: ('Vap', 'Liq', 'water'): active
fs.state[0].eq_mole_frac_tdew: ('Vap', 'Liq'): active
fs.state[0].equilibrium_constraint: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_phase_comp_eqn: ('Liq', 'water'): active
fs.state[0].log_mole_frac_phase_comp_eqn: ('Vap', 'water'): active

after:

Vars:
fs.state[0].flow_mol: 1 fixed
fs.state[0].mole_frac_comp: water: 1 fixed
fs.state[0].pressure: 101325 fixed
fs.state[0].temperature: 298.15 fixed
fs.state[0].flow_mol_phase: Liq: 0.011998855736683581 unfixed
fs.state[0].flow_mol_phase: Vap: 0.9880011442633164 unfixed
fs.state[0].mole_frac_phase_comp: ('Liq', 'water'): 1.0000002858083423 unfixed
fs.state[0].mole_frac_phase_comp: ('Vap', 'water'): 0.999999996175808 unfixed
fs.state[0].phase_frac: Liq: 0.011998855736683581 unfixed
fs.state[0].phase_frac: Vap: 0.9880011442633164 unfixed
fs.state[0]._teq: ('Vap', 'Liq'): 374.515200140377 unfixed
fs.state[0]._t1_Vap_Liq: 374.5154503041165 unfixed
fs.state[0].temperature_bubble: ('Vap', 'Liq'): 374.51544997674324 unfixed
fs.state[0]._mole_frac_tbub: ('Vap', 'Liq', 'water'): 1.0000000000033347 unfixed
fs.state[0].log_mole_frac_comp: water: 3.190064691904021e-15 unfixed
fs.state[0].log_mole_frac_tbub: ('Vap', 'Liq', 'water'): 0.0 unfixed
fs.state[0].temperature_dew: ('Vap', 'Liq'): 374.5154499767442 unfixed
fs.state[0]._mole_frac_tdew: ('Vap', 'Liq', 'water'): 0.9999999999966523 unfixed
fs.state[0].log_mole_frac_tdew: ('Vap', 'Liq', 'water'): -6.695188269298816e-12 unfixed
fs.state[0].log_mole_frac_phase_comp: ('Liq', 'water'): 6.290014676962778e-07 unfixed
fs.state[0].log_mole_frac_phase_comp: ('Vap', 'water'): -7.983200736531084e-06 unfixed

--------------------------------
Constraints:
fs.state[0].total_flow_balance: active
fs.state[0].component_flow_balances: water: active
fs.state[0].sum_mole_frac: active
fs.state[0].phase_fraction_constraint: Liq: active
fs.state[0].phase_fraction_constraint: Vap: active
fs.state[0]._t1_constraint_Vap_Liq: active
fs.state[0].eq_temperature_bubble: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_comp_eqn: water: active
fs.state[0].log_mole_frac_tbub_eqn: ('Vap', 'Liq', 'water'): active
fs.state[0].eq_mole_frac_tbub: ('Vap', 'Liq'): active
fs.state[0]._teq_constraint_Vap_Liq: active
fs.state[0].eq_temperature_dew: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_tdew_eqn: ('Vap', 'Liq', 'water'): active
fs.state[0].eq_mole_frac_tdew: ('Vap', 'Liq'): active
fs.state[0].equilibrium_constraint: ('Vap', 'Liq', 'water'): active
fs.state[0].log_mole_frac_phase_comp_eqn: ('Liq', 'water'): active
fs.state[0].log_mole_frac_phase_comp_eqn: ('Vap', 'water'): active

Notice the change in phase_frac. It gets driven down for some reason. I suspect this is because of the equilibrium_constraint constraint.

@alma-walmsley
Copy link
Collaborator

alma-walmsley commented Jan 4, 2025

Solving through 373 K proved infeasible. (water)

image

@alma-walmsley
Copy link
Collaborator

Okay this is the weirdest thing. Same T values, different initial values

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants