Flash¶
Tutorial: Flash Unit Model with Modular Property Package¶
Learning Outcomes¶
- Demonstrate use of the flash unit model in IDAES
Problem Statement¶
In this example, we will be flashing a liquid feed stream of benzene and toluene to form a liquid outlet stream and a vapor outlet stream. The inlet conditions are as follows:
Inlet:
Flow Rate = 100 mol/s
Mole Fraction (Benzene) = 0.6
Mole Fraction (Toluene) = 0.4
Temperature = 298 K
Pressure = 101325 Pa
For more details, please refer to the IDAES documentation: https://idaes-pse.readthedocs.io/en/stable
Importing necessary tools¶
In the following cell, we will be importing the necessary components from Pyomo and IDAES.
# Import objects from pyomo package
from pyomo.environ import ConcreteModel, value
# Import the solver
from idaes.core.solvers import get_solver
# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model
from idaes.core import FlowsheetBlock
# Import the flash unit model
from idaes.models.unit_models import Flash
# Import idaes logger to set output levels
import idaes.logger as idaeslog
# Import the modular property package to create a property block for the flowsheet
from idaes.models.properties.modular_properties.base.generic_property import GenericParameterBlock
# Import the BT_Ideal property package to create a configuration file for the GenericParameterBlock
from idaes.models.properties.modular_properties.examples.BT_ideal import configuration
# Import the degrees_of_freedom function from the idaes.core.util.model_statistics package
# DOF = Number of Model Variables - Number of Model Constraints
from idaes.core.util.model_statistics import degrees_of_freedom
Setting up the flowsheet¶
In the following cell, we will create the ConcreteModel
foundation, attach the steady state flowsheet, and declare the property parameter block that will used.
More information on this general workflow can be found here: https://idaes-pse.readthedocs.io/en/stable/how_to_guides/workflow/general.html
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False) # dynamic or ss flowsheet needs to be specified here
m.fs.properties = GenericParameterBlock(**configuration)
In the following cell, we will be creating the flash unit model, assigning a property package to it, and determining the initial degrees of freedom associated with the flash unit model.
m.fs.flash = Flash(property_package=m.fs.properties)
DOF_initial = degrees_of_freedom(m)
print('The initial degrees of freedom are: {0}'.format(DOF_initial))
The initial degrees of freedom are: 7
Fixing input specifications¶
In the following cell, we will be specifying the inlet conditions for the flash block and re-evaluating the degrees of freedom to ensure the problem is square (i.e. DOF=0). It will be assumed that the flash unit has a heat duty of 100,000 W and no pressure change.
m.fs.flash.inlet.flow_mol.fix(100) # converting to mol/s as unit basis is mol/s
m.fs.flash.inlet.mole_frac_comp[0, "benzene"].fix(0.6)
m.fs.flash.inlet.mole_frac_comp[0, "toluene"].fix(0.4)
m.fs.flash.inlet.pressure.fix(101325) # Pa
m.fs.flash.inlet.temperature.fix(353) # K
m.fs.flash.heat_duty.fix(1e5) # W
m.fs.flash.deltaP.fix(0)
DOF_final = degrees_of_freedom(m)
print('The final degrees of freedom is: {0}'.format(DOF_final))
The final degrees of freedom is: 0
Flowsheet Initialization¶
IDAES includes pre-written initialization routines for all unit models. Failing to initialize or having a poor intialization of a flowsheet may result in the problem being unsolvable. The output from initialization can be set to 7 different levels depending on the details required by the user. In general, when a particular output level is set, any information at that level and above gets picked up by logger. The default level taken by the logger is INFO.
More information on these levels can be found in the IDAES documentation: https://idaes-pse.readthedocs.io/en/stable/reference_guides/logging.html
m.fs.flash.initialize(outlvl=idaeslog.WARNING)
Obtaining Simulation Results¶
In the following cell, the flowsheet will be solved using the IDAES get_solver
tool. Setting tee=True
will display the solver output.
solver = get_solver()
result = solver.solve(m, tee=True)
Ipopt 3.13.2: nlp_scaling_method=gradient-based tol=1e-06 max_iter=200 ****************************************************************************** This program contains Ipopt, a library for large-scale nonlinear optimization. Ipopt is released as open source code under the Eclipse Public License (EPL). For more information visit http://projects.coin-or.org/Ipopt This version of Ipopt was compiled from source code available at https://github.com/IDAES/Ipopt as part of the Institute for the Design of Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse. This version of Ipopt was compiled using HSL, a collection of Fortran codes for large-scale scientific computation. All technical papers, sales and publicity material resulting from use of the HSL codes within IPOPT must contain the following acknowledgement: HSL, a collection of Fortran codes for large-scale scientific computation. See http://www.hsl.rl.ac.uk. ****************************************************************************** This is Ipopt version 3.13.2, running with linear solver ma27. Number of nonzeros in equality constraint Jacobian...: 135 Number of nonzeros in inequality constraint Jacobian.: 0 Number of nonzeros in Lagrangian Hessian.............: 70 Total number of variables............................: 37 variables with only lower bounds: 12 variables with lower and upper bounds: 21 variables with only upper bounds: 0 Total number of equality constraints.................: 37 Total number of inequality constraints...............: 0 inequality constraints with only lower bounds: 0 inequality constraints with lower and upper bounds: 0 inequality constraints with only upper bounds: 0 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 0 0.0000000e+00 8.07e+02 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0 1 0.0000000e+00 8.03e+00 3.44e-01 -1.0 1.00e-02 - 9.90e-01 9.90e-01h 1 2 0.0000000e+00 3.87e-02 5.17e+00 -1.0 9.95e-05 - 9.90e-01 9.95e-01h 1 3 0.0000000e+00 5.82e-11 8.85e+02 -1.0 4.79e-07 - 9.91e-01 1.00e+00h 1 Number of Iterations....: 3 (scaled) (unscaled) Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00 Dual infeasibility......: 0.0000000000000000e+00 0.0000000000000000e+00 Constraint violation....: 3.3466117403534772e-14 5.8207660913467407e-11 Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00 Overall NLP error.......: 3.3466117403534772e-14 5.8207660913467407e-11 Number of objective function evaluations = 4 Number of objective gradient evaluations = 4 Number of equality constraint evaluations = 4 Number of inequality constraint evaluations = 0 Number of equality constraint Jacobian evaluations = 4 Number of inequality constraint Jacobian evaluations = 0 Number of Lagrangian Hessian evaluations = 3 Total CPU secs in IPOPT (w/o function evaluations) = 0.000 Total CPU secs in NLP function evaluations = 0.000 EXIT: Optimal Solution Found.
View Results¶
As expected, the report below shows that part of the feed stream has been vaporized such that there is a pure liquid outlet stream and a pure vapor outlet stream
m.fs.flash.report()
==================================================================================== Unit : fs.flash Time: 0.0 ------------------------------------------------------------------------------------ Unit Performance Variables: Key : Value : Units : Fixed : Bounds Heat Duty : 1.0000e+05 : watt : True : (None, None) Pressure Change : 0.0000 : pascal : True : (None, None) ------------------------------------------------------------------------------------ Stream Table Units Inlet Vapor Outlet Liquid Outlet Total Molar Flowrate mole / second 100.00 - - Total Mole Fraction benzene dimensionless 0.60000 - - Total Mole Fraction toluene dimensionless 0.40000 - - Temperature kelvin 353.00 - - Pressure pascal 1.0132e+05 - - flow_mol mole / second - 2.4408 97.559 mole_frac_comp benzene dimensionless - 0.78730 0.59531 mole_frac_comp toluene dimensionless - 0.21270 0.40469 temperature kelvin - 362.69 362.69 pressure pascal - 1.0132e+05 1.0132e+05 ====================================================================================