Skip to content

Commit

Permalink
apply the same logic to adiabatic initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alma-walmsley committed Jan 1, 2025
1 parent a9394fb commit 477a4a4
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 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 @@ -1070,6 +1078,7 @@ def init_isentropic(blk, state_args, outlvl, solver, optarg):
)

# 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:
Expand Down

0 comments on commit 477a4a4

Please sign in to comment.