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

Pressure changer initialization guesses #1556

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 45 additions & 27 deletions idaes/models/unit_models/pressure_changer.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,6 @@ def init_adiabatic(blk, state_args, outlvl, solver, optarg):

cv = blk.control_volume
t0 = blk.flowsheet().time.first()
state_args_out = {}

if state_args is None:
state_args = {}
Expand All @@ -925,31 +924,41 @@ def init_adiabatic(blk, state_args, outlvl, solver, optarg):
else:
state_args[k] = state_dict[k].value

# Get initialisation guesses for outlet and isentropic states
# Initialize state blocks
flags = cv.properties_in.initialize(
outlvl=outlvl,
optarg=optarg,
solver=solver,
hold_state=True,
state_args=state_args,
)

# Get initialisation guesses for outlet state
state_args_out = {}
# refresh state_dict (may have changed during initialization)
state_dict = cv.properties_in[t0].define_port_members()
for k in state_args:
if k == "pressure" and k not in state_args_out:
# Work out how to estimate outlet pressure
if cv.properties_out[t0].pressure.fixed:
# Fixed outlet pressure, use this value
state_args_out[k] = value(cv.properties_out[t0].pressure)
elif blk.deltaP[t0].fixed:
state_args_out[k] = value(state_args[k] + blk.deltaP[t0])
state_args_out[k] = value(cv.properties_in[t0].pressure + blk.deltaP[t0])
elif blk.ratioP[t0].fixed:
state_args_out[k] = value(state_args[k] * blk.ratioP[t0])
state_args_out[k] = value(cv.properties_in[t0].pressure * blk.ratioP[t0])
else:
# Not obvious what to do, use inlet state
state_args_out[k] = state_args[k]
state_args_out[k] = value(cv.properties_in[t0].pressure)
elif k not in state_args_out:
state_args_out[k] = state_args[k]
# use the inlet state as a guess for the outlet state
if state_dict[k].is_indexed():
state_args_out[k] = {}
for m in state_dict[k].keys():
state_args_out[k][m] = state_dict[k][m].value
else:
state_args_out[k] = state_dict[k].value

# Initialize state blocks
flags = cv.properties_in.initialize(
outlvl=outlvl,
optarg=optarg,
solver=solver,
hold_state=True,
state_args=state_args,
)
cv.properties_out.initialize(
outlvl=outlvl,
optarg=optarg,
Expand Down Expand Up @@ -1002,7 +1011,6 @@ def init_isentropic(blk, state_args, outlvl, solver, optarg):

cv = blk.control_volume
t0 = blk.flowsheet().time.first()
state_args_out = {}

# performance curves exist and are active so initialize with them
activate_performance_curves = (
Expand Down Expand Up @@ -1060,31 +1068,41 @@ def init_isentropic(blk, state_args, outlvl, solver, optarg):
else:
state_args[k] = state_dict[k].value

# Initialize state blocks
flags = cv.properties_in.initialize(
outlvl=outlvl,
optarg=optarg,
solver=solver,
hold_state=True,
state_args=state_args,
)

# Get initialisation guesses for outlet and isentropic states
state_args_out = {}
# refresh state_dict (may have changed during initialization)
state_dict = cv.properties_in[t0].define_port_members()
for k in state_args:
if k == "pressure" and k not in state_args_out:
# Work out how to estimate outlet pressure
if cv.properties_out[t0].pressure.fixed:
# Fixed outlet pressure, use this value
state_args_out[k] = value(cv.properties_out[t0].pressure)
elif blk.deltaP[t0].fixed:
state_args_out[k] = value(state_args[k] + blk.deltaP[t0])
state_args_out[k] = value(cv.properties_in[t0].pressure + blk.deltaP[t0])
elif blk.ratioP[t0].fixed:
state_args_out[k] = value(state_args[k] * blk.ratioP[t0])
state_args_out[k] = value(cv.properties_in[t0].pressure * blk.ratioP[t0])
else:
# Not obvious what to do, use inlet state
state_args_out[k] = state_args[k]
state_args_out[k] = value(cv.properties_in[t0].pressure)
elif k not in state_args_out:
state_args_out[k] = state_args[k]
# use the inlet state as a guess for the outlet state
if state_dict[k].is_indexed():
state_args_out[k] = {}
for m in state_dict[k].keys():
state_args_out[k][m] = state_dict[k][m].value
else:
state_args_out[k] = state_dict[k].value

# Initialize state blocks
flags = cv.properties_in.initialize(
outlvl=outlvl,
optarg=optarg,
solver=solver,
hold_state=True,
state_args=state_args,
)
cv.properties_out.initialize(
outlvl=outlvl,
optarg=optarg,
Expand Down