Product¶
Tutorial: Product Unit Model with Modular Property Package¶
Learning Outcomes¶
- Demonstrate use of the Product unit model in IDAES
Problem Statement¶
In this tutorial, we will be feeding a mixed stream of liquid benzene and liquid toluene. This unit model has no outlets and only one inlet. The inlet conditions are as follows:
Flow Rate = 100 mol/s
Mole Fraction (benzene) = 0.6
Mole Fraction (toluene) = 0.4
Temperature = 298 K
Pressure = 101325 Pa
Product blocks are used to represent sinks of materials in flowsheets. This model does not functionally change the flowsheet in any way and is mainly used as a convenience for visualizing and reporting the characterisitics of a product or byproduct stream. More information on the product model can be found here: https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/unit_models/product.html
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 product unit model
from idaes.models.unit_models import Product
# 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 product unit model, assigning a property package to it, and determining the initial degrees of freedom associated with the product unit model.
m.fs.product = Product(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: 5
Fixing input specifications¶
In the following cell, we will be specifying the inlet conditions for the product block and re-evaluating the degrees of freedom to ensure the problem is square (i.e. DOF=0).
m.fs.product.flow_mol.fix(100) # converting to mol/s as unit basis is mol/s
m.fs.product.mole_frac_comp[0, "benzene"].fix(0.6)
m.fs.product.mole_frac_comp[0, "toluene"].fix(0.4)
m.fs.product.pressure.fix(101325) # Pa
m.fs.product.temperature.fix(298) # K
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.product.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...: 39 Number of nonzeros in inequality constraint Jacobian.: 0 Number of nonzeros in Lagrangian Hessian.............: 13 Total number of variables............................: 16 variables with only lower bounds: 6 variables with lower and upper bounds: 8 variables with only upper bounds: 0 Total number of equality constraints.................: 16 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 9.90e-01 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0 1 0.0000000e+00 9.89e-03 3.42e-01 -1.0 1.00e-02 - 9.90e-01 9.90e-01h 1 2 0.0000000e+00 9.07e-05 9.17e+00 -1.0 9.99e-05 - 1.00e+00 9.91e-01h 1 3 0.0000000e+00 5.82e-11 1.33e-03 -2.5 9.16e-07 - 1.00e+00 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....: 4.3596189116537901e-14 5.8207660913467407e-11 Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00 Overall NLP error.......: 4.3596189116537901e-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 product shown in the report below matches the feed conditions that were set earlier.
m.fs.product.report()
==================================================================================== Unit : fs.product Time: 0.0 ------------------------------------------------------------------------------------ Stream Table Units Inlet Total Molar Flowrate mole / second 100.00 Total Mole Fraction benzene dimensionless 0.60000 Total Mole Fraction toluene dimensionless 0.40000 Temperature kelvin 298.00 Pressure pascal 1.0132e+05 ====================================================================================