Using user models in Matlab ® within the Aspen Plus ® interface with an Excel ® link

Process intensification and new technologies require tools for process design that can be integrated into well-known simulation software, such as Aspen Plus ® . Thus, unit operations that are not included in traditional Aspen Plus software packages can be simulated with Matlab ® and integrated within the Aspen Plus interface. In this way, the user can take advantage of all of the tools of Aspen Plus, such as optimization, sensitivity analysis and cost estimation. This paper gives a detailed description of how to implement this integration. The interface between Matlab and Aspen Plus is accomplished by sending the relevant information from Aspen Plus to Excel, which feeds the information to a Matlab routine. Once the Matlab routine processes the information, it is returned to Excel and to Aspen Plus. This paper includes the Excel and Matlab template files so the reader can implement their own simulations. By applying the protocol described here, a hybrid distillation-vapor permeation system has been simulated as an example of the applications that can be implemented. For the hybrid system, the effect of membrane selectivity on membrane area and reboiler duty for the partial dehydration of ethanol is studied. Very high selectivities are not necessarily required for an optimum hybrid distillation and vapor permeation system.


Introduction 1
Process intensification is a strategy for achieving dramatic reductions in environmental impacts, energy consumption, plant footprint, and operating costs while increasing the productivity of an industrial plant compared with conventional ones Moulijn, 2002, 2000;Van Gerven and Stankiewicz, 2009). In order to design new plants and to evaluate their performance and im-pacts, process simulation software has become important, and several options are available in the market.
Aspen Plus ® is a well-known software for process design with integrated tools for optimization, sensitivity analysis and economic evaluation. Although Aspen Plus possesses an important number of unit operations that can be simulated, some new technologies and units used for process intensification are not included. How-ever, user models and special units required for process intensification can be simulated with programming software, such as Matlab ® . Thus, a tool that keeps the full functionality and numerical power of Aspen Plus and that can integrate Matlab user models is important for designing new and intensified processes. Some years ago, Fontalvo et al. (Fontalvo et al., 2005) presented simulation results of a hybrid distillation-membrane process using an integrated system of Matlab within the Aspen Plus interface. In this publication, the specific details for this connection were not shown. Although other authors have also used this integration between Aspen Plus and Matlab (Kiss et al., 2012;Vázquez-Ojeda et al., 2013), no specific information can be found on the web or in the Aspen Customer support web page. This paper describes a detailed protocol for using the Aspen Plus user interface for calling Matlab user models. It does not intend to show the specific numerical performance or computation speed of this integration, which depends on each specific application. The described integration retains the capabilities of Aspen Plus for optimization, sensitivity analysis and cost estimation. Additionally, a hybrid distillation and vapor permeation process is shown as an application example. The effect of membrane selectivity on the required membrane area and reboiler duty is presented.

Incorporating Matlab ® within the Aspen Plus ® Interface
Within the Aspen Plus interface, a Matlab user model (MUM) can be included by a process that is described in Figure 1. Aspen Plus supplies to Excel properties of the several streams of the user block or user model and some additional parameters. The Excel file organizes and sends this information to the Matlab routine. The Matlab routine calculates, for the user block, the properties of the outlet streams and, if required, additional parameters. This information is returned to Excel ® which then returns it to the Aspen Plus interface. Once the information is obtained by Aspen Plus, the modeling of other units within Aspen Plus will continue as usual. Due to the structure presented in Figure 1, it is possible to use tools of Aspen Plus for optimization, sensitivity analysis and plotting. Also specific plots generated by the Matlab routine regarding the user model itself can be obtained within the Aspen Plus simulation.  Table 1 presents the inlet and outlet stream structure used by Aspen Plus. The stream structure is a vector with n + 9 elements, where n is the number of components in the mixture. The units of physical quantities used for each property are indicated in the table. The order of these properties is important because once the information is received by Matlab, it has to be processed taking into account the given structure and units.
The outlet stream properties (and the inlet stream properties) calculated by the MUM should be a matrix with a size of (n + 9) x m, where m corresponds to the number of outlet (or inlet) streams, and each of the m columns have the same order and the same units of physical quantities to those presented in Table 1. However, in the Matlab routine, it is necessary to calculate only the first n+3 elements of each of the outlet stream vectors. Elements n+4 to n+9 can be calculated by Aspen Plus using stream composition, temperature and pressure. The MUM file (usermodel.m) is an example routine that evaluates a vapor permeation membrane (VP) unit for the selective removal of water from ethanol. The simulation of this unit operation is demonstrative, and it is not the aim for this paper to simulate a rigorous vapor permeation membrane unit. However, some important conclusions will be presented in the design example below. The routine uses ideal gas and constant temperature for the retentate and permeate streams. Permeability values for water and ethanol remain constant.
In Aspen Plus, go to "User Models" and insert a unit operation called "User2". The User2 block allows any number of inlet and outlet streams. There are five steps in extending the User2 model to incorporate a Matlab user model: 1. Place a User2 block. 2. Connect any streams. 3. Specify the name of the Excel workbook file that calls the Matlab routine that represents the unit operation model for the block. 4. Enter the operating parameters by filling out the real and integer parameter arrays. 5. Specify the "stream flash" for the outlet streams to calculate stream properties that are dependent on composition, temperature and pressure.
Insert the corresponding inlet streams. The order of these streams is important because the inlet stream information is supplied to the Matlab routine in this specific order. Specifically, for the Matlab file that is provided with this paper (usermodel.m), two inlet streams, FEED and SWEEP, will be used to preserve this order. Insert the outlet streams preserving this order: RETENTATE and PERMEATE. Table 2 shows the properties for the FEED and SWEEP streams. It is important to remark that regardless of the units of the physical quantities the user has supplied in the Aspen Plus interface for the inlet streams (Table 2), the units reported to the MUM routine will always be those found in Table 1.

Figure 2. "User Array" input form as shown by Aspen Plus interface
Double click on the User2 block and a new window will pop-up; click the subroutine input form. In "Excel file name" browse for the Excel file, usermodel.xls. For this specific example, the MUM will work with 2 integer (i.e., the number of membrane tubes and the number of differential elements for simulating the membrane unit) and 7 real parameters (i.e., the size of a differential element, outside tube diameter, outlet water molar fraction in the retentate, water permeance, ethanol permeance, membrane area and membrane tube length) that have to be specified in the Aspen Plus interface. Thus, in the "User Arrays" input form ( Figure 2) input 2 integer parameters, 7 real parameters and 7 characters (the number of "characters" has been specified in 7, so one can include a short description of each of the integer and real parameters) and input the information shown in Table 3. Integer and real parameters in Aspen Plus are treated as both input and output. The cells filled with an "X" correspond to unknown information that will be calculated by the Matlab routine. The column Character in the table presents a brief description of the corresponding integer and real parameters.
Select the "Stream Flash" sheet; in the stream dialog box, select each of the outlet streams (RETENTAT and PERMEATE), and for each stream in the flash type dialog box, select "Temperature & pressure". By selecting "Temperature & pressure" other properties such as enthalpy, entropy, molecular weight, vapor fraction and other properties in Table 1 are calculated by Aspen Plus using the composition, temperature and pressure. Once the simulation is run, the following results are found: 1. Number of differential elements: 827. 2. Membrane area: 1558.9 m 2 . 3. Tube Length: 8.3 m. Table 4 presents results for the outlet streams. The water molar fraction in the RETENTAT stream, shown in Table 4, corresponds to the required water molar fraction in the retentate, specified in Table 3.

An example for a hybrid distillation-vapor permeation process
A more complex application example of the protocol described above is presented in this section for a hybrid system. Figure 3 presents a hybrid distillation and vapor permeation system for the partial dehydration of ethanol. The information for the vapor permeation (VP) unit is given in Table 3, except: 100 tubes have been used in the calculation, the required water molar fraction is 0.05 and ethanol permeability has been modified depending on membrane selectivity. The retentate stream is split: a small fraction (4.167 kg/h) is recycled as a sweep stream to the VP unit and a product stream of 98 wt% of ethanol is obtained. The permeate stream from the VP unit is condensed, pumped and recycled to the reboiler of the distillation tower. The permeate pressure is 0.05 atm, and thus, cooling water can be used.
The specific configuration used for the distillation column in Figure  3 is shown in Table 5, and the corresponding feed stream properties are presented in Table 6.
Membrane selectivity is defined as the ratio of the water-to-ethanol permeance (Baker et al., 2010). Using a constant water permeance (Table 3) but changing the ethanol permeance makes it possible to simulate the influence of the membrane selectivity on the required membrane area and reboiler duty for the hybrid system ( Figure 3).  Table 5. Configuration of the distillation column shown in Figure 2 Calculation type Equilibrium

Number of stages 30
Condenser Partial Distillate rate, (kg/h) 5208.334 Reflux ratio (mass) 3 Feed tray 20 Column pressure, (bar) 1.2 Table 6. Feed stream properties in the hybrid process shown in Figure 2 Property FEED Membrane selectivity is defined as the ratio of the water-to-ethanol permeance (Baker et al., 2010). Using a constant water permeance (Table 3) but changing the ethanol permeance makes it possible to simulate the influence of the membrane selectivity on the required membrane area and reboiler duty for the hybrid system ( Figure 3).
This simulation can be performed using the tool sensitivity of Aspen Plus, and the results are presented in Figure 4. As the membrane selectivity decreases, the required membrane area is also reduced. Due to the relative high pressure in the permeate side, very highly selective membranes will produce high permeate water concentrations, reducing the water driving force and consequently, the water flux through the membrane. The lower the water flux through the membrane, the greater the membrane area. However, the drawback of low membrane selectivities is the resultant high energy consumption in the reboiler. Two opposite factors influence the operating cost of this hybrid system. For low selectivities, the required membrane area is low but the reboiler duty is high. Thus, the economic optimal membrane selectivity will be placed at relative low membrane selectivities. Essentially, very high selectivities are not necessarily required for hybrid distillation and vapor permeation systems. More results regarding this analysis can be found elsewhere (Fahmy et al., 2001;Fontalvo et al., 2005).

Conclusions
Process intensification and new technologies require tools for process design that can be integrated into well-known simulation software, such as Aspen Plus. A protocol is described for integrating Matlab user models within the Aspen Plus interface. With this integration, the user can take advantage of all of the tools of Aspen Plus, such as optimization, sensitivity analysis and cost estimation. The interface between Matlab and Aspen Plus is accomplished by sending the relevant information from Aspen Plus to Excel, which in turn feeds the information to a Matlab routine. Once the Matlab routine processes the information, it is returned to Excel and to Aspen Plus. This paper includes the Excel and Matlab template files so the reader can perform their own simulations. By implementing the protocol described in this paper a hybrid distillation-vapor permeation system has been simulated in order to show an example of the applications that can be implemented. In this example, the effect of membrane selectivity on membrane area and reboiler duty for the partial dehydration of ethanol has been explored using the sensitivity analysis tool of Aspen Plus. Very high selectivities are not necessarily required for designing optimal hybrid distillation and vapor permeation systems.