This action might not be possible to undo. Are you sure you want to continue?
Getting Started Customizing Unit Operation Models
Version Number: V7.2 July 2010
Copyright (c) 1981-2010 by Aspen Technology, Inc. All rights reserved. Aspen Plus, aspenONE, the aspen leaf logo and Plantelligence and Enterprise Optimization are trademarks or registered trademarks of Aspen Technology, Inc., Burlington, MA. All other brand and product names are trademarks or registered trademarks of their respective companies. This document is intended as a guide to using AspenTech's software. This documentation contains AspenTech proprietary and confidential information and may not be disclosed, used, or copied without the prior consent of AspenTech or as set forth in the applicable license agreement. Users are solely responsible for the proper use of the software and the application of the results obtained. Although AspenTech has tested the software and reviewed the documentation, the sole warranty for the software may be found in the applicable license agreement between AspenTech and the user. ASPENTECH MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESSED OR IMPLIED, WITH RESPECT TO THIS DOCUMENTATION, ITS QUALITY, PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. Aspen Technology, Inc. 200 Wheeler Road Burlington, MA 01803-5501 USA Phone: (1) (781) 221-6400 Toll Free: (1) (888) 996-7100 URL: http://www.aspentech.com
Who Should Read this Guide ...................................................................................1 Introducing Aspen Plus ...........................................................................................2 Sessions in this Manual .....................................................................................2 Files Created in these Sessions ..........................................................................3 Integration Features for Custom Unit Operation Models.........................................4 Aspen Plus Excel Unit Operations .......................................................................4 Aspen Plus Fortran Models.................................................................................4 Creating GUI forms for Proprietary Models...........................................................4 Supporting Files ...............................................................................................5 Related Documentation .....................................................................................5 Technical Support ............................................................................................5 1 Creating an Excel Unit Operation Model ..............................................................7 Defining the Simulation.....................................................................................8 Setting Up the Model in Aspen Plus.....................................................................8 To Start Aspen Plus ................................................................................8 To Specify the Application Type and Run Type for the New Run....................9 Build the Process Flowsheet................................................................... 10 Enter Title, Components, Base Method, and Feed Specifications ................. 10 Enter Excel Path and User Array Data ..................................................... 12 Setup a Product Stream Flash................................................................ 13 Setting Up the Excel Model .............................................................................. 13 Copy and Examine the Excel Template.................................................... 14 Edit the Excel Sheets ............................................................................ 15 Enter Membrane Model Equations and Parameters.................................... 18 Running the Excel Model ................................................................................. 19 Examining Simulation Results .......................................................................... 19 To View the Results from the Excel Model................................................ 19 To View the Block Results...................................................................... 22 2 Customizing the Excel/Aspen Plus Interface.....................................................25 Revising the Excel Model ................................................................................. 25 Revising the User Subroutine........................................................................... 27 Code Listing – Subroutine MEM2 ...................................................................... 27 Code Description – Subroutine MEM2................................................................ 35 Compiling and Linking the Subroutine ............................................................... 37 Compile the Excel Interface Subroutine................................................... 37 Create a Shared Library ........................................................................ 37 Running the Simulation................................................................................... 38 Results from the Custom Excel Model ............................................................... 40
................................................................ 45 Create the Custom Model from the Template ..........................57 Putting the Model Equations in the User Subroutine....... 49 Create a Custom Icon ...............................................................................................................................68 Setting Up the Visual Basic Environment ...................................................... 79 Register the OCX File ...................3 Customizing the Aspen Plus Model Library ............ 65 Results from the Custom Fortran Model..................................................................... 58 Code Description – Subroutine HFUM ...................................................................................................................................... 68 Creating the Visual Basic Form................................................................................................................................................. 70 Build the Tab Control ................... 45 Editing the Custom Model. 63 Compiling and Linking the Subroutine ............................................ 67 5 Creating an Aspen Plus Custom Form .......... 53 Compile.............................................................................................................. 52 Check and Edit Setup Sheets ................................................................................................................................. 43 Create an Empty Custom Model Library................................................................86 iv Contents ........... 81 Testing the New Form...................................................................................................................................................................... 65 Running the Simulation... 72 Build the Input Control... 79 Create OCR and OCX Files for Your Model.................................................................... and Run .................................. 44 Create a Template for Your Custom Model ...................... 78 Integrating Forms with Aspen Plus ............................................ Link...................................... 51 Inserting the New Model and Running the Simulation .................................. 50 Create References to the Real and Integer Parameters ................................... 52 Insert the New Model.................................................................................................................... 74 Build the Results Control ............................................................................................................................................................. 70 Create Three Named Controls .......................................... 83 Results from the Custom Form.................................................. 58 Code Listing – Subroutine HFUM ................. 54 4 Creating an Aspen Plus Fortran Model .........................................................................43 Creating a Model Library ......................................................................................... 84 6 Connecting to the Aspen Plus Simulation Engine.........
Who Should Read this Guide 1 .Who Should Read this Guide This guide is suitable for advanced Aspen Plus users who want to customize the unit operation models available in Aspen Plus and create new models. Users should be familiar with the procedures covered in Aspen Plus Getting Started Building and Running a Process Model before starting these examples.
2 Introducing Aspen Plus . and Excel. This guide is designed for advanced users of Aspen Plus who have a working knowledge of Fortran. Visual Basic development software. anyone who has completed the tutorials in Getting Started Building and Running a Process Model. will be able to work through the tutorials here by following the step-by-step instructions. Fortran development software. Even though most users of the customizing options described in this guide are highly experienced with Aspen Plus. Sessions in this Manual Follow the steps in this chapter: 1 Creating an Excel Unit Operation Model 2 Customizing the Excel/Aspen Plus Interface 3 Customizing the Aspen Plus Model Library 4 Creating an Aspen Plus Fortran Model 5 Creating an Aspen Plus Custom Form To learn how to: Create a simulation that uses an Excel model to determine product stream properties. The tutorials in this guide illustrate key features of this capability by building a simulation based on an external membrane model and performing the model calculations using either an Excel file or a Fortran subroutine. Alter the Fortran interface subroutine to accommodate an expanded Excel model. Create your own Aspen Plus GUI forms to handle input and results for your custom models. Create a model with pre-defined parameters for repeated use. Perform model calculations in a Fortran subroutine instead of in an Excel spreadsheet.Introducing Aspen Plus Aspen Plus offers the option of using custom or proprietary models in Aspen Plus simulations. This guide assumes that you are have installed Aspen Plus. Visual Basic. and Microsoft Excel on your computer.
Custom Model Library created by the user.ocx ModelName.xls MemCalc_Custom_PreRun.opt Membrane2. USER2 model.dll Membrane2_Loc_dll.bkp ProjectFile.opt HFUM.obj.dll. DLL file w/ Mem2 subroutine. Renamed Visual Basic OCX file to be linked to a particular model.opt HFUM. DLL w/ HFUM and Mem2Vars.bkp MemCalc_PreRun. InputControlFile. of HFUM.dll Membrane2_CM.ctl. ResultsControlFile. Excel calculations custom interface. Excel file after the run.ocx ModelName.vbp.xls MemCalc_Custom.opt Membrane2. 5 5 5 5 Visual Basic OCX file containing custom form. Custom model. DLOPT file w/ location of Mem2.obj and Mem2Vars.ocr HFUM_CF. Excel file after the run. Excel calculations.xls MemCalc.f/obj Membrane2_List_OBJs.ctl. Code written by Aspen Plus for named references. DLOPT w/ location of Mem2. Excel file w/ viscosity and cgs units for use with custom interface. DLOPT w/ loc. Custom model + custom form.f /obj Membrane2_List_OBJs. custom interface.obj.dll HFUM_Loc_dll.apm Mem2Vars.opt Membrane2. Excel file for use with default interface (before simulation run). Fortran calculations. TabControlFile. DLL w/ Mem2 and Mem2Vars Custom model. Introducing Aspen Plus 3 . no interface.obj and Mem2Vars. DLOPT w/ location of HFUM.f/obj HFUM_List_OBJs. no interface. Code w/ model equations. default interface.bkp Chpt 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 Description USER2 model. Excel calculations. DLOPT w/ location of Membrane2.bkp HFUM.dll.obj. Code for custom interface. Visual Basic files to for custom Aspen Plus form. Text OCR file containing specifications for custom form.Files Created in these Sessions Filename Membrane1. Fortran calculations.ctl ProjectFile.bkp Ultrafiltration.xls Mem2.
User-defined variables can be easily linked to these forms. real and character data. you can develop and test the model within Excel without performing iterative compile and link steps that are required when developing and testing a Fortran model. You can develop rich data structures for user-defined unit operation models involving integer. You can utilize the full power of Excel including all of its built-in functions and specialized Visual Basic routines that are provided in the Aspen Plus Excel template. and standard and default model input templates. The parameters can either be scalar or vector. Vector data can be automatically dimensioned based on nine standard lengths such as Number of Components or Number of Inlet Streams. This simplifies user-defined parameter mapping into external user routines. Creating GUI forms for Proprietary Models You can create your own user interface forms for proprietary or custom models using the same environment employed to create built-in Aspen Plus forms. or can be dynamically dimensioned based on a user-defined integer variable.Integration Features for Custom Unit Operation Models Aspen Plus offers powerful features that make it easy to use Aspen Plus simulations containing proprietary models. The forms can have a free format layout to suit the needs of your model. 4 Introducing Aspen Plus . Once you identify the input variables and physical properties used by Excel. custom icons to better represent the equipment that your models describe. You can create: Custom Model Libraries. Aspen Plus Excel Unit Operations You can use an Excel Workbook as an Aspen Plus user-defined unit operation model. Aspen Plus Fortran Models Aspen Plus provides utilities for convenient read and write access to named user-defined variables from within the Fortran user model routine. user-defined variables that become part of the Aspen Plus data structure as an alternative to Real and Integer arrays.
it is possible to create forms for an existing plant unit that hides design parameters for users interested in performing rating only calculations. A prerequisite for the other Getting Started guides Tutorials covering the use of equation-oriented models in Aspen Plus Tutorials covering the Aspen Plus features designed to handle solids Tutorials covering the Aspen Plus features designed to handle electrolytes Tutorials covering the Aspen Plus features designed to handle petroleum Instructions for installing Aspen Plus and other Aspen Engineering Suite products Procedures for using Aspen Plus Specifications for custom models Technical Support AspenTech customers with a valid license and software maintenance agreement can register to access the online AspenTech Support Center at: http://support.aspentech. Supporting Files The Aspen Plus backup.The ability to create forms. Fortran and Visual Basic files described in this book are delivered in the GUI\xmp directory of the Aspen Plus installation. For example. Visual Basic template files are distributed with Aspen Plus to help reduce the development effort. Excel.com This Web support site allows you to: Access current product documentation Search for tech tips. solutions and frequently asked questions (FAQs) Introducing Aspen Plus 5 . combined with the templating capabilities outlined in this guide. These forms are easily inserted into Aspen Plus by registering the OCX file created by Visual Basic using the Aspen Plus ApFormSetup utility. Related Documentation Title Aspen Plus Getting Started Building and Running a Process Model Aspen Plus Getting Started Using Equation Oriented Modeling Aspen Plus Getting Started Modeling Processes with Solids Aspen Plus Getting Started Modeling Processes with Electrolytes Aspen Plus Getting Started Modeling Petroleum Processes Aspen Engineering Suite Installation Manual Aspen Plus User Guide Aspen Plus User Models Content Tutorials covering basic use of Aspen Plus. is a very powerful customization capability.
fax.aspentech.com. Search for and download application examples Search for and download service packs and product updates Submit and track technical issues Send suggestions Report product defects Review lists of known deficiencies and defects Registered users can also subscribe to our Technical Support e-Bulletins. and email. 6 Introducing Aspen Plus . The most up-todate contact information is available at the AspenTech Support Center at http://support. These e-Bulletins are used to alert users to important technical support information such as: Technical advisories Product updates and releases Customer support is also available by phone.
Place blocks and streams. The tutorial sessions in this Getting Started Guide assume that you have completed all of the sessions in Getting Started Building and Running a Process Model. Save a simulation. 1 Creating an Excel Unit Operation Model 7 . Aspen Plus will write data to and read data from the Excel spreadsheet.1 Creating an Excel Unit Operation Model Aspen Plus offers several interfaces for including custom or proprietary models in Aspen Plus simulations. View the data in the results sheets. you must be able to: Start Aspen Plus (using a blank simulation. and enter real and integer parameters corresponding to the membrane. Enter data into the required fields in the input sheets. Run a simulation. Then use Excel to create a spreadsheet to calculate product stream properties. First use Aspen Plus to build a process flowsheet. In particular. Allow about 60 minutes for this session. In this session you will create a User2 Excel model for an ultrafiltration membrane. or existing simulation). Navigate from form to form using the Data Browser menu tree. specify feed and product streams. Among these is the option to use a User2 unit operation block in your Aspen Plus simulation with an Excel spreadsheet to perform the calculations. template.
8 1 Creating an Excel Unit Operation Model . Ultrafiltration is a pressuredriven membrane process used to separate components based on molecular size and shape. Figure 1. The solvent and small solute species pass through the membrane and are termed the permeate. Setting Up the Model in Aspen Plus To Start Aspen Plus 1 2 From your desktop. such as proteins.Defining the Simulation Construct an Ultrafiltration Membrane model. Large solute species. Results will be displayed in the Excel file and on Aspen Plus results forms. click Start and then select Programs. The simulation that you will construct is shown below in Figure 1. one unit operation block (an ultrafiltration membrane). are retained by the membrane and are termed the retentate. Excel will calculate product stream data such as mole flow rates and solute concentrations using a user-specified set of equations. There is one feed stream (a water-protein feed).1. Aspen Plus will read the product stream data from Excel. and two product streams (permeate and retentate). Select AspenTech | Process Modeling <version> | Aspen Plus | Aspen Plus User Interface.1 Ultrafiltration Membrane Model Aspen Plus will write feed stream data and real and integer membrane parameters (such as physical dimensions) to Excel.
Click OK to apply this option.The Aspen Plus Startup dialog box appears. use an Aspen Plus template. Flowsheet. The default run type. 3 4 Select Template. In this simulation. 1 Creating an Excel Unit Operation Model 9 . Aspen Plus uses the application type to automatically set various defaults appropriate to your application. Aspen Plus displays a dialog box whenever you must enter information or make a selection before proceeding. Use this dialog box to specify the application type and the run type for the new run. To Specify the Application Type and Run Type for the New Run 5 Select the General with Metric Units template. The New dialog box appears. is appropriate for this simulation.
Create one input stream and two product streams. Name the second product stream you created PERMEATE. you might call it Membrane1. Components. rightclicking. Go to the Setup | Specifications | Global sheet and enter a title. 10 1 Creating an Excel Unit Operation Model . next to the User 2 block icon to display all the User 2 model Move the mouse over the icons to see a name (or label) for each. First. build the process flowsheet. Base Method. Note: It matters which stream was created first because you will be passing Excel (and. For example. Aspen Plus will handle everything but the calculations that correspond to the ultrafiltration process itself. In the Component ID field. Build the Process Flowsheet 1 From the Model Library. For this customized simulation. Your process flowsheet should look similar to Figure 1. Fortran) data to an Aspen Plus array that contains product stream data. Drag the FILTER icon to the Process Flowsheet window. type WATER and press Enter on the keyboard. Note: If the Connect to Engine dialog box appears.1. The Aspen Plus main window is now active. Enter Title. select the User Models tab. Aspen Plus accepts eight letters and displays them as upper case. the property method. specify the components used in the simulation. Name the first product stream you created RETENTAT. and selecting Rename Stream. 10 Name the block MEMBRANE. The first stream declared also comes first in the data array. The next step is to enter a title.6 Click OK to apply these options. Go to the Components | Specifications | Selection sheet. Name the input stream FEED by selecting the stream or its label. and feed stream characteristics. It takes a few seconds for Aspen Plus to apply these options. in the next chapter. and Feed Specifications 1 2 3 4 Press F8 to open the Data Browser. 2 3 4 5 6 7 8 9 Click icons. and select it. see "Connecting to the Aspen Plus Simulation Engine" on page 86. Locate the User 2 icon FILTER in the fourth row of icons.
and press Enter on the keyboard. and protein mass concentration as indicated below. 1 Creating an Excel Unit Operation Model 11 . change the type of units displayed to Volume. 7 8 9 Go to the Properties | Specifications | Global sheet and select the IDEAL model in the Base method field. Go to the Streams | FEED | Input | Specifications sheet. type LYSINE in the Component name field. In the Total flow section of the State variables area.” Another row opens up in the table. pressure. Aspen Plus recognizes the amino acid lysine and fills in the Formula field.The Component name and Formula are automatically filled in because Aspen Plus recognizes the ID “WATER. change the type of units displayed to MassConc. Lysine will stand in as a protein for the purposes of this illustration. solvent. total flow. 12 Click the Flash Options tab to open the Streams | FEED | Input | Flash Options sheet. 10 In the Composition area. type PROTEIN and press Enter on the keyboard. The Solvent field is now available. so the Component name and Formula fields remain blank. 5 In the next Component ID field. Protein is not in the Aspen Plus databank. 6 In the Protein row. 11 Enter the temperature.
The integer and real parameter user array will also hold results that do not correspond to standard Aspen Plus stream properties. The last two real parameters are Excel-calculated results and will appear (filled in) in the copy of the User Array table that is written to the Blocks | MEMBRANE | Results sheet after the simulation run. the full path must be specified (and is limited to 219 characters). and 13 in the Character field. select Liquid-Only. Next.xls Note: This corresponds to an Excel file in the Aspen Plus working folder. 12 1 Creating an Excel Unit Operation Model . enter the name of the (future) Excel file. but we recommend putting the Excel file in the working folder. If the file is located elsewhere. Enter Excel Path and User Array Data 1 2 Go to the Blocks | MEMBRANE | Setup | Subroutines sheet. For example. 3 4 5 Click the User Arrays tab to open the Blocks | MEMBRANE | Setup | User Arrays sheet. 13 in the Real field. specify the location of the Excel file that performs membrane calculations and enter the integer and real parameters that define the physical and calculational characteristics of the particular membrane being used for this simulation. enter 1 in the Integer field. No other fields on this sheet need to be specified for this example. The character entries are optional here. you might enter MemCalc. they are just for convenience in this example. In the Excel file name area. In the Number of parameters area. Enter the parameters as indicated below. a customized Fortran subroutine is used to interface with the Excel spreadsheet and the name of the subroutine is entered in the Model field in the User 2 subroutines area. A customized Fortran subroutine allows you to control which data is passed between the Excel spreadsheet and Aspen Plus.13 In the Valid phases field. In the next chapter.
select RETENTAT. . In the Flash type field. Save your Aspen Plus file as Membrane1. use this template: . .xls is available for use with Excel 95. In the Flash type field. select Temperature & pressure. For Excel 97 and later. 1 Creating an Excel Unit Operation Model 13 . select Temperature & pressure. In the Stream field. Setting Up the Excel Model An Excel template is available to expedite the specification process.xls Another template named userxlTemplate95.apw. Setup a Product Stream Flash 1 2 3 4 5 6 Click the Stream Flash tab to open the Blocks | MEMBRANE | Setup | Stream Flash sheet. make a product flash specification to cause Aspen Plus to evaluate the enthalpy and other product stream properties based on the temperature and pressure calculated by Excel.\Engine\User\userxlTemplate. select PERMEATE. In the Stream field.Next.
Copy and Examine the Excel Template 1 2 Place one of the templates in the folder you specified on the Aspen Plus Blocks | MEMBRANE | Setup Subroutines sheet. click the Options button in the security notice. If Excel says that macros are disabled. Then close the document and re-open it. follow the directions given to lower your security setting in Excel to allow the macros to run. When you open it. Aspen_Output: The mole flow rates (kmol/s) of each component of each product stream and the three product stream parameters that o o o 14 1 Creating an Excel Unit Operation Model . then click Excel Options | Trust Center | Trust Center Settings and set the option For macros in documents not in a trusted location to Disable all macros with notification. Aspen_RealParams: Eleven real parameters read from the Real User Array and two results (protein concentration in each product stream) calculated by Excel on Sheet 1. This second file will be changed by Aspen Plus and you may wish to compare the changed version to the original MemCalc_PreRun. you will save a copy of this file as MemCalc. Excel may give you one of a few different warnings about macros. For example. select Enable this content. If using Excel 2007 and you do not get a warning about macros when opening this file. Model calculations will be performed on Sheet 1 (now empty). and click OK.xls. go to Tools | Options. This file contains macros used to communicate with Aspen Plus. and set the security level to Medium. Open the template. Then close the file and re-open it with the macros enabled.xls. pick this option. Aspen_Input: The mole flow rates (in kmol/s) of each component of the feed stream and nine stream parameters. in Excel 2003. click the Office button in the upper left corner of the window. The four data sheets and the data they will contain after the simulation is run are listed below: o Aspen_IntParams: One integer parameter read from the Integer User Array (entered on the Blocks MEMBRANE Setup User Arrays Aspen Plus sheet). o o 3 Save a copy as MemCalc_PreRun. and click the Options button in the security notice to enable the macros. Note: Later. click Macro Security. In Excel 2007. o If Excel offers you the option to Enable Macros.xls in your working folder. Excel 2007 may not even warn you macros are being disabled. 4 Use the tabs on the bottom of the screen to view the four named Excel sheets in the template that contain data. Security tab.
Cell B2 will contain the integer parameter from the Aspen Plus User Arrays sheet. All data read from MSIN or written to SOUT must be in SI units. Note: The flow rates and nine stream parameters are stored in Aspen Plus in two arrays: MSIN (input streams) and SOUT (output streams). Aspen Plus will fill in these cells when you run the simulation. Only the NTUBES entry in cell C2 is strictly necessary. The other six product stream parameters are calculated by Aspen Plus. (In Excel 2007. 2 3 Select NTUBES and click Insert | Name | Define. modify the four Excel sheets to reflect the number of input and output streams and input and output parameters in this example.) Edit the Refers to field so that NTUBES represents the value in cell B2. In Excel 2003 this looks like: 1 Creating an Excel Unit Operation Model 15 . Aspen Plus first transfers input data from MSIN to Excel and then transfers output results from Excel to SOUT. The entries in the first two columns are dummies. Use these variables in the model calculations performed on Sheet 1. Edit the Excel Sheets 1 Edit the Aspen_IntParams sheet as shown below. Next. Mole flow data must be in kmol/s. rightclick the cell and select Name a Range. Define variables to reference data-containing cells.will be calculated by Excel.
Again. In Excel 2007. Note: Since CP and CR haven’t been defined yet. To display the equations (instead of an error message) click Tools | Options | View and select the Formulas checkbox.In Excel 2007. For example. The units column is optional. 6 16 1 Creating an Excel Unit Operation Model . Edit the Excel Aspen_Input sheet as shown below. The Fortran interface subroutine reads the actual values of the feed stream properties from the Aspen Plus MSIN array and writes to column B the Excel sheet. Excel will not be able to determine values for cells B13 and B14. the entries in the first and second column are dummies except for the equations in cells B13 and B14. Aspen Plus will fill in the first two columns but will not overwrite equations. select DIAM and click Insert | Name | Define (right-click and select Name a Range on Excel 2007) and change $C$2 to $B$2 in the Refers to field. 5 Define the boldfaced variables (one at a time) in the third column to refer to the cells in the second column. click the Office button at the far upper left | Excel Options | Advanced and select the Show formulas in cells instead of their calculated results checkbox. it looks like: 4 Edit the Aspen_RealParams sheet as shown below.
8 9 The four sheets you just built hold data that the Fortran interface subroutine reads from Aspen Plus as well as results that are passed to Aspen Plus.7 Redefine the variable Aspen_Input to refer to the proper range of input variables. contains the unit operation model equations. Click Tools | Options | View and select Formulas to display the equations. In this case Aspen_Input!$B$2:$B$12 is the correct definition. Define the variables in the fourth column to refer to the cells in the second column. The remaining Excel sheet. and change the last letter and/or number in the definition. Create the model by entering equations and parameters on Sheet1. it calculates the product stream properties using input from the first four sheets. (In Excel 2007. The units column is optional.) The equations won’t produce numbers yet because variables such as FP must be determined on Sheet1. 1 Creating an Excel Unit Operation Model 17 . then select the Aspen_Input variable. run the menu command Insert | Name | Define (Formulas | Name Manager in Excel 2007). Edit the Aspen_Output sheet as shown below. Sheet1. To do this. click the Office button at the far upper left | Excel Options | Advanced and select the Show formulas in cells instead of their calculated results checkbox.
They are implemented as Visual Basic routines. Define each variable in column A to refer to the cell to its right in column B. you could use =ahGetValue(Aspen_Input. In the Visual Basic Editor.) 18 1 Creating an Excel Unit Operation Model . click the Office button at the far upper left | Excel Options | Advanced and clear the Show formulas in cells instead of their calculated results checkbox. and click Create. Variables that are used in other sheets are shown in boldface.Note: To facilitate construction of the Excel model. The first argument of this function is the Aspen_Input variable mentioned previously and the second argument is a first-column string to search for within the specified range. (To look at the code. type any name. “DENSITY”) / 1000. for example. Turn on formulas. (In Excel 2007. or in Excel 2007 select View | Macros | View Macros. The helper functions are described in the Aspen Plus User Models manual. Instead of using =DENS_FEED/1000 in cell B9 on Sheet1. lets you refer to data using a label in the first column.) The ahGetValue function. 2 Click Tools | Options | View and clear the Formulas checkbox. double-click the AspenHooks module. select Tools | Macro | Visual Basic Editor. the template comes with a number of aspen helper functions built in. Notes in column C are optional. Enter Membrane Model Equations and Parameters 1 Edit Sheet1 as shown below.
xls. Column B contains the eleven real parameters from the Aspen Plus User Arrays sheet that describe the membrane. Go to the Blocks | MEMBRANE | Setup | Subroutines sheet and verify that the path to the Excel file is correct. and Aspen_Input sheets. Note: Opening Excel before Aspen Plus saves startup time. Save a copy as MemCalc. This file will be altered by Aspen Plus. The interface routine reads the data in columns B and C and writes to the Aspen Plus SOUT array. Once you are satisfied with the Excel ultrafiltration membrane model. Turn off formulas in each sheet and reformat numbers as needed using the Excel Format | Cells command (Home | Format | Format Cells in Excel 2007). save your MemCalc_PreRun. open MemCalc. for example. Because there is no data yet. Aspen Plus performs a product stream flash to replace the zeroes in SOUT with data so that. Aspen_RealParams. enthalpy data is available to Aspen Plus even though it is not calculated by Excel. Optional: Put sensible data in the Aspen_IntParams.xls and then open Membrane1. Cells B12 and B13 contain equations and are therefore not directly changed by the interface routine. Cell B2 contains the number of tubes in the membrane model as specified on the Aspen Plus User Arrays sheet. Press F5 to run the simulation. Column C is not changed. Aspen_RealParams: Column A contains the row number because no labels are specified in the default interface routine. 1 2 3 If necessary. Turn off formulas in the Aspen_Output and the Aspen_RealParams sheets as well and check that there is a number in each cell. Columns B and C are initialized to zero except for the cells containing equations which are not changed. these numbers are meaningless.apw.xls file.3 4 5 6 7 Verify that your equations produce a number in each cell. The subroutine CalculateData invokes the Excel calculations and product stream results appear in cells B2:B6 and C2:C6. Aspen_Output: Column A already has the correct labels – the interface routine overwrites with the same labels. o o 1 Creating an Excel Unit Operation Model 19 . The sheets are changed as follows: o Aspen_IntParams: Column A contains the row number because no labels are specified in the default interface routine. Examining Simulation Results To View the Results from the Excel Model 1 Examine the altered Excel file. Running the Excel Model The Excel sheet can remain open when the simulation is run.
Sheet 1: Using the feed stream data and real and integer parameters read from Aspen Plus arrays to the Excel sheets. the data-filled Excel sheets and Aspen Plus results sheets are reproduced here. These data are read from the Aspen Plus MSIN array. o o For convenience. Column B now contains the input parameters for the feed stream. Aspen_IntParams: Aspen_RealParams: 20 1 Creating an Excel Unit Operation Model .o Aspen_Input: Column A already has the correct labels – the interface routine overwrites with the same labels. the equations on Sheet1 determine concentrations and flow rates for the two output streams. The interface routine does not read or write directly to or from this sheet. Aspen_Output_MEMBRANE: This is a new sheet created via a call to EndIteration which copies the contents of Aspen_Output to this new sheet.
Aspen_Input: Aspen_Output (and Aspen_Output_MEMBRANE): 1 Creating an Excel Unit Operation Model 21 .
4 5 Go to the Setup | Specifications | Global sheet and change the Output results field to SI and run the simulation again. You find that the units are different. For example. Go back to the Stream Results form and compare the flow rates now reported in kmol/s to those listed in the Excel sheets.Sheet1: To View the Block Results 2 3 Go back to the Aspen Plus simulation environment. the component mole flow rates are reported in kmol/hr instead of kmol/sec. 22 1 Creating an Excel Unit Operation Model . Aspen Plus did read the correct output values from Excel but it assumed (correctly) that they were in SI units and converted the data to METCBAR units before displaying it on the Stream Results sheet. Go to the Blocks | MEMBRANE | Stream Results | Material sheet and the Blocks | MEMBRANE | Results | Summary sheet to verify that Aspen Plus data and Excel data are the same.
Aspen Plus read these values from the Excel Aspen_RealParams sheet without regard to units. Save the changed version of your Excel file. Exit Aspen Plus. MemCalc.xls. Save the run. Membrane1. The last two real parameters displayed on this Aspen Plus sheet contain values. 7 8 9 10 Exit Excel. This Aspen Plus file.apw will be used in the next chapter. Aspen Plus Blocks | MEMBRANE | Stream Results | Material sheet: 1 Creating an Excel Unit Operation Model 23 .6 Go to the Blocks | MEMBRANE | Results | Summary sheet to view the real and integer parameter data read from Excel.
Aspen Plus Blocks | MEMBRANE | Results | Summary sheet: 24 1 Creating an Excel Unit Operation Model .
and then converted back to mole basis in Aspen_Output so that the data could be transferred to Aspen Plus. By customizing the subroutine. 2 Customizing the Excel/Aspen Plus Interface 25 . This was necessary because the Aspen Plus MSIN and SOUT arrays expect flow rate data in mole basis.0 (or a later version) to compile your customized interface routine using the aspcomp command in Aspen Plus Simulation Engine Window.0 or later may also work. The new interface routine will then pass the viscosity to the Excel model so that the user doesn’t have to enter this parameter by hand (on Sheet1) as in the previous chapter. calculated the product stream flow rates. it will obtain the viscosity of the feed stream by calling the appropriate Aspen Plus built-in subroutines. Compaq Visual Fortran 6. More importantly. The interface subroutine passes feed stream data from Aspen Plus to Excel and it passes product stream data from Excel to Aspen Plus. In this session you will revise the interface routine to convert the input data to mass basis and the results data back to mole basis. it is passed to Sheet1. You need Intel Fortran 9.2 Customizing the Excel/Aspen Plus Interface Aspen Plus allows the user to customize the Fortran interface subroutine that communicates with the Excel model. Revising the Excel Model Alter the Excel file from the previous chapter so that when the revised interface routine writes the feed stream viscosity to the Excel Aspen_Input sheet. The new interface routine will create custom labels for the Aspen_RealParams Excel sheet. Allow about 60 minutes for this session. converted to the appropriate units. The Excel model in the previous chapter used Aspen Plus feed stream data in mole basis from the Aspen_Input sheet. and used in the model calculations. converted to mass basis in Sheet1. the user can control which data is passed back and forth and can manipulate the data before or after it is processed in the Excel spreadsheet.
xls. Alter Sheet1 to use the viscosity calculated by Aspen Plus. 3. 1 2 Open MemCalc_PreRun.Also. Aspen_Output. B7. Add row 13 to the Aspen_Input sheet as shown below. and B8) require minor changes. 3 Define MU_ASPEN to be the viscosity that will be written to cell B13 using the Insert | Name | Define (or right-click | Name a Range on Excel 2007) command. and Sheet1 so that they use mass basis. Two rows are no longer needed (PMF and TMF) and three cells (B4. and 4 to indicate mass basis.xls and save a copy as MemCalc_Custom_PreRun. Change the units in rows 2. Convert the viscosity (Aspen Plus always uses SI units) to cgs units and change two equations in the Excel model to use mass basis. 4 26 2 Customizing the Excel/Aspen Plus Interface . The three new equations are shown in boldface. change Aspen_Input.
The argument list must not be lengthened or shortened. Save a copy of the new Excel file as MemCalc_Custom. 2 3 Code Listing – Subroutine MEM2 C C C C C C User2 Unit Operation Model Subroutine for Excel Models You can use any subroutine name up to six characters as long as you identify the name on the Blocks BLOCKNAME Setup Subroutines sheet in Aspen Plus. copy this file to d:\Program Files\AspenTech\Working Folders\Aspen Plus\Membrane\Mem2.f in a folder in your working directory. and 4 to indicate mass basis.f) have been shortened while others have been added. 3.xls so that you retain the original version after the run. Numbers in parentheses following the boldface comments refer to the relevant part of the Code Description that follows the listing.f and change the name of the subroutine to Mem2. Open Mem2. Some of the comments from the template (usrxls.f. The new equations are shown in boldface. The complete revised subroutine is listed below with changes marked. 6 7 Save your new Excel file.5 Alter the Excel Aspen_Output sheet to calculate component flow rates in mass basis. Make sure this version is stored in the folder specified on the Aspen Plus Subroutines sheet. 1 Put a copy of \Engine\User\usrxls. Edit the file as indicated in the code listing that follows. 2 Customizing the Excel/Aspen Plus Interface 27 . For example. Change the units in rows 2.xls. Revising the User Subroutine The code for the default subroutine provides a template that will make creating the customized subroutine easier. MemCalc_Custom_PreRun.
IDS. (4) Character*8 RealLabels(13) !Realparam row ID's. IWORK. LEN. X(10) !Calc component mass flow. (5) REAL*8 INSTREAM(NTOT*NMATI).cmn" #include "ppexec_user. NREAL INTEGER IDSMI(2. IPROG(2). NSUBS. + DESC_LENGTH.KOUTSOL(3).NCOMP_NCC+10) !Ten labels instead of nine. NINFI.K. WORK. + IBLANK(2). NIWORK. SOR_LENGTH. + DESCRIPTION(128) !Moved LABELS and ROWNAMES declarations. + EXCEL_NAME(64). ERRNUMBER. SINFO. HOL_STRLEN. NBOPST.10). C_OFF. + LDATA. NUM_LINES. KREAL(3).NMATI).NMATI). IDSII. I. NUM_ROWS. EXCEL_NAME_LEN. NINFO. IDSMO. NINFI. KDIAG. IDSMO(2. INTSIZ(NSIZE). SOUT(NTOT.3).cmn" REAL*8 B(1) EQUIVALENCE (B(1). KOUTPUT(2). NPO. NWORK. NCP !Conversion and Viscosity. NMATO. NINT. IDXSUB(NSUBS). ESIZE. NREAL.NINFO). SSID(2). then other variables. NTOT. REALV(NREAL) C C-----------. (2) Integer LMW. NSIZE. NINFO.NMATO). INTV(NINT). KINT(3). NPO. (1) Integer LABELS(2. -----C INTEGER DMS_IRRCHK. RETCODE.Declare Aspen Plus utility functions that will be used.Local Variable Declarations -------------------C INTEGER OFFSET. SINFO(NINFO). NSUBS. DMS_IFCMNC C C--------------------. NINT. IWORK(NIWORK). C C C + + Declare variables used in dimensioning first. SINFI. NWORK. INTV. IDSMI. NIWORK.NMATO). ESIZE(NSIZE).cmn" #include "dms_plex.2 3 4 5 6 7 C SUBROUTINE MEM2 (NMATI. NMATO.NTOT+1) !Hollerith Realparam row ID's.IB(1)) C C-------. LID. IDXSUB. LD + + + MSIN(NTOT. ROWNAMES(2. ITYPE. XMW. INTEGER NMATI. (1) Integer REALROWS(2. (3) Real*8 FLOW. IDX(10). NCD. NSIZE. SINFI(NINFI). WORK(NWORK).OUTSTREAM(NTOT*NMATO) 28 2 Customizing the Excel/Aspen Plus Interface . ITYPE(NSUBS). NUM_COLS.J.NINFI). IDS(2. REAL*8 + + IDSII(2. LD ) IMPLICIT NONE MSIN.cmn" #include "dms_ncomp. NBOPST(6. INTSIZ. + LIDSC. + SOURCE(16). NTOT. REALV. IDSIO. IDSIO(2. KINPUT(2). SOUT. KINPSOL(3). ----------C #include "dms_errout.NPO).Aspen Plus Common Definitions Start in Column 1.
C C--------------------------- Data Section ----------------------------C
DATA DATA DATA DATA DATA DATA DATA DATA
KINPUT KOUTPUT KREAL KINT KINPSOL KOUTSOL IPROG IBLANK
/4HINPU, 4HT / /4HOUTP, 4HUT / /4HREAL, 4HPARA, 4HMS /4HINTP, 4HARAM, /4HINP_, 4H , 4H /4HOUT_, 4H , 4H /4HUSRX, 4HLS / /4HIMIS, 4HS / /4HTOTF, 4HTEMP, 4HPRES, 4HENTH, 4HVAP , 4HLIQ , 4HENTR, 4HDENS, 4HMOLE, 4HMUMX, 4HLOW , 4H , 4H , 4HALPY, 4HFRAC, 4HFRAC, 4HOPY , 4HITY , 4H WT , 4H / ', ', ', ', ', ', ', ', ', ', ', ', '
/ 4HS / /
DATA LABELS + + + + + + + + +
!MUMX is viscosity label. (6) !Labels for Realparam table !(each total eight chars). (7)
DATA RealLabels + + + + + + + + + + + +
/'x 'L 'Dab 'Cg 'R 'C1 'C2 'C3 'C4 'Pperm 'DeltaP 'Cp 'Cr
C--- Establish Excel link and call StartIteration Workbook Hook Function --CALL USRUTL_GETEXCEL(EXCEL_NAME, EXCEL_NAME_LEN) CALL StartIteration(RETCODE, EXCEL_NAME,256, IDS(1,1), 8) IF(RETCODE .NE. 0) GOTO 1000 C--------------- Build Aspen_Input Data Table -----------------------------C First get name of each of the NCOMP_NCC components for C first NCOMP_NCC rows in column 1 of the table. Names are in C two four letter blocks. Component names in column 1 label C component flow rates in column 2. OFFSET = DMS_IFCMNC('IDSCC') DO J=1, NCOMP_NCC I = OFFSET + 2*(J-1) + 1 ROWNAMES(1,J) = IB(I) ROWNAMES(2,J) = IB(I+1) END DO
2 Customizing the Excel/Aspen Plus Interface
After the component names, list the nine standard stream properties plus any extras (in this case, there is one extra). DO K=1, 10 J = K + NCOMP_NCC ROWNAMES(1,J) = LABELS(1,K) ROWNAMES(2,J) = LABELS(2,K) END DO NUM_ROWS = NCOMP_NCC + 10 ! Change 910 (8)
! Change 910 (8)
C C C C
Now fill in column 2 (using the INSTREAM array) with Aspen Plus feed stream data (from the MSIN array). Convert to mass basis using molecular weights. Make a column for each feed stream. Also have Aspen Plus calculate viscosity of feed stream. LMW = DMS_IFCMNC('MW') NUM_COLS = NMATI DO J=1, NUM_COLS OFFSET = (J-1)*(NCOMP_NCC+10) ! Change 910 (8) DO I=1, NUM_ROWS IF (I .EQ. NUM_ROWS) THEN !To do last row (10) Call SHS_CPACK(MSIN(1,J), NCP, IDX, X, FLOW) !"pack" data KDIAG = 4 !then get K = NCOMP_NCC !viscosity. (11) Call PPMON_VISCL(MSIN(K+2,J), MSIN(K+3,J), X, NCP, + IDX, NBOPST, KDIAG, + INSTREAM(OFFSET+I), RETCODE) ELSE XMW = 1 !Only convert flow rates. IF(I .LE. NCOMP_NCC) XMW = B(LMW + I) !If doing flow rates, !make XMW molecular wgt. (12) INSTREAM(OFFSET + I) = MSIN(I,J)*XMW !Convert and fill INSTREAM. END IF IF (I .EQ. NCOMP_NCC+1) INSTREAM(OFFSET+I) = + INSTREAM(OFFSET+I)*MSIN(I+8,J) !Convert total mole flow ! to total mass flow using molec wgt of stream. (13) END DO END DO !Will need molecular weights of individual !components to do flow rate conversions. (9)
C--------------- Send Aspen_Input table LDATA = 8*NUM_ROWS*NUM_COLS CALL WRITETABLE(RETCODE , KINPUT, + ROWNAMES, 8 , + 8 , 2 , IF (RETCODE .NE. 0) GO TO 1000
to Excel. ---------------------8 , NUM_ROWS, NUM_COLS, IDSMI , INSTREAM, LDATA )
C------------ Send Aspen_IntParams table to Excel. --------------------LDATA = 8*NINT CALL WRITETABLE(RETCODE, KINT, 12 , NINT , + IBLANK , 0 , 1 , IBLANK, + 0 , 1 , INTV,LDATA ) IF (RETCODE .NE. 0) GO TO 1000
2 Customizing the Excel/Aspen Plus Interface
C-------------- Send Aspen_RealParams table to Excel. ------------------DO I = 1, 13 !Make the 13 labels into Holleriths. (14) CALL USRUTL_CHARTOH(RealLabels(I), RealRows(1,I), 8) END DO LDATA = 8*NREAL CALL WRITETABLE(RETCODE, + RealRows, + 0 , IF (RETCODE .NE. 0) GO TO
KREAL, 12 , NREAL , 8 , 1 , IBLANK, 2 , REALV, LDATA ) 1000
!Send Labels, !Length to Excel.
C-------- Initialize the Aspen_Output Excel table. --------------------NUM_ROWS = NCOMP_NCC + 9 !No viscosity for output streams. (15) DO J=1, NMATO OFFSET = (J-1)*(NCOMP_NCC+9) !Still 9 here. (15) DO I=1, NUM_ROWS OUTSTREAM(OFFSET+I) = 0.D0 END DO END DO NUM_COLS = NMATO LDATA = 8*NUM_ROWS*NUM_COLS CALL WRITETABLE(RETCODE , KOUTPUT, 8 , NUM_ROWS, + ROWNAMES, 8 , NUM_COLS , IDSMO , + 8 , 2 , OUTSTREAM, LDATA ) IF (RETCODE .NE. 0) GO TO 1000 C C------------- Solid Substream Section -------------------------------C C When a simulation contains either conventional or nonconventional C solids, another Excel sheet will be created as the interface with C a separate sheet being created for each substream. The name of C substream will be appended onto the sheet name. For example, a C sheet called Aspen_INP_CISOLID will be created for the CISOLID C substream. The component names and stream properties for this C stream will be prepared similarly to Aspen_Input. A separate C column will be used for each feed. NSUBS will be greater than 1 C if any solid substreams exist. IF (NSUBS .GT. 1) Then C Build the input tale for each solid substream DO K=2,NSUBS IF (ITYPE(K) .EQ. 3) THEN Nonconventional solid LIDSC = DMS_IFCMNC('IDSNCC') NCD = NCOMP_NNCC ELSE Conventional solid LIDSC = DMS_IFCMNC('IDSCC') NCD = NCOMP_NCC ENDIF DO J=1, NCD LID = LIDSC + 2*(J-1)
2 Customizing the Excel/Aspen Plus Interface
ROWNAMES(1,J) = IB(LID+1) ROWNAMES(2,J) = IB(LID+2) END DO C C Place stream property labels in column 1 DO J=1, 9 I=NCD+J ROWNAMES(1,I) = LABELS(1,J) ROWNAMES(2,I) = LABELS(2,J) END DO NUM_ROWS = NCD+9 Append the substream name onto the end of the input and output Excel sheet name. CALL SHS_PID(LD, K, SSID) KINPSOL(2) = SSID(1) KINPSOL(3) = SSID(2) KOUTSOL(2) = SSID(1) KOUTSOL(3) = SSID(2) Register the stream data NUM_COLS = NMATI DO J=1, NUM_COLS OFFSET = (J-1)*(NCD+9) DO I=1, NCD+9 INSTREAM(OFFSET+I) = MSIN(IDXSUB(K)+I-1,J) END DO END DO Send interface table to Excel LDATA = 8*NUM_ROWS*NUM_COLS CALL WriteTable(RETCODE , KINPSOL, 12 , NUM_ROWS, + ROWNAMES, 8 , NUM_COLS, IDSMI , + 8 , 2 , INSTREAM, LDATA ) IF (RETCODE .NE. 0) GO TO 1000 Initialize the Excel output interface for the substream NUM_COLS = NMATO DO J=1, NUM_COLS OFFSET = (J-1)*(NCD+9) DO I=1, NCD+9 OUTSTREAM(OFFSET+I) = 0.D0 END DO END DO Send interface table to Excel NUM_ROWS = NCD+9 LDATA = 8*NUM_ROWS*NUM_COLS CALL WriteTable(RETCODE , KOUTSOL, 12 , NUM_ROWS, ROWNAMES, 8 , NUM_COLS , IDSMO , 8 , 2 , OUTSTREAM, LDATA ) IF (RETCODE .NE. 0) GO TO 1000 END DO End If
C C C
C C C
2 Customizing the Excel/Aspen Plus Interface
C------------ Invoke Excel Workbook Calculations ---------------------CALL CalculateData(RETCODE) IF (RETCODE .NE. 0) GOTO 1000 C---------- Read Excel values into Aspen Plus Arrays ---------C----- Read back integer parameter table in case it has results. LDATA = 8*NINT CALL READTABLE(RETCODE, KINT, 12 , NINT , + 1 , 1 , INTV, LDATA) IF (RETCODE .NE. 0) GOTO 1000 C ---- Read back real parameter table in case it has results. LDATA = 8*NREAL CALL READTABLE(RETCODE, KREAL, 12 , NREAL, + 1 , 2 , REALV, LDATA) IF (RETCODE .NE. 0) GOTO 1000 C C C C C C
Read product stream data from Excel Aspen_Output sheet to OUTSTREAM. Only have component flow rates, total flow rate, temperature and pressure. First column of data (the retentate stream data) comes first in the 1 dimensional OUTSTREAM array. NUM_ROWS = NCOMP_NCC + 3 ! Change 93; Two flow rates + tot flow, NUM_COLS = NMATO ! temp, pres. (16) LDATA = 8*NUM_ROWS*NUM_COLS CALL READTABLE(RETCODE , KOUTPUT, 8 , NUM_ROWS, + NUM_COLS, 2 , OUTSTREAM, LDATA ) IF (RETCODE .NE. 0) GOTO 1000
C C C C C C C C C C
Put results from two product streams (OUTSTREAM array) in Aspen Plus product stream array (2 dimensional SOUT). The second dimension of SOUT is the number of streams; the first stream placed by the user on the Aspen Plus process flowsheet comes first in SOUT. Retentate stream was placed first and it must also be listed first in the Excel Aspen_Output sheet. SOUT expects flow rate data in mole basis so convert back to mole basis using molecular weights. This time get total mole flow by just adding up component mole flows. DO J = 1, NMATO FLOW = 0 ! Holds the total mole flow. OFFSET = (J-1)*NUM_ROWS ! NUM_ROWS, not NCOMP_NCC+9 DO I = 1, NUM_ROWS IF(I .LE. NCOMP_NCC) THEN SOUT(I, J) = OUTSTREAM(OFFSET+I)/B(LMW+I) !Convert flow !rates to mole basis and fill Aspen Plus array. (17) FLOW = FLOW + SOUT(I,J) !Store total. (17) ELSE IF(I .EQ. NCOMP_NCC+1) THEN SOUT(I,J) = FLOW !Total flow to SOUT (3rd row). (17) ELSE !For other rows, just fill array. SOUT(I,J) = OUTSTREAM(OFFSET + I) END IF END DO END DO
2 Customizing the Excel/Aspen Plus Interface
NMATO OFFSET= (J-1)*(NCD+9) DO I=1.GT. J) = OUTSTREAM(OFFSET+I) END DO END DO END DO End If C--------------. NCD+9 SOUT(IDXSUB(K)+I-1. K. SSID) KOUTSOL(2) = SSID(1) KOUTSOL(3) = SSID(2) C C Read Excel interface product sheet for substream NUM_ROWS = NCD+9 NUM_COLS = NMATO LDATA = 8*NUM_ROWS*NUM_COLS CALL ReadTable(RETCODE . LDATA ) IF(RETCODE . KOUTSOL. 2 . NUM_COLS. C HOL_STRLEN = 64 DESC_LENGTH= 512 SOR_LENGTH = 64 CALL GetLastTableDataErr(RETCODE.!No more changes.C---------------------------------------------------------------------C For solid substreams.End of Current Iteration ------------. 1) Then C C Retrieve data for each substream DO K = 2. 12 . DESCRIPTION.NSUBS IF (ITYPE(K) . SOURCE. obtain product info from Excel interface sheets C IF (NSUBS . + DESC_LENGTH. 0) GO TO 1000 + C C Store data into outlet stream vector DO J=1. CALL EndIteration(RETCODE) RETURN C-----------------------. ERRNUMBER. 3) THEN NCD = NCOMP_NNCC ELSE NCD = NCOMP_NCC ENDIF CALL SHS_PID(LD.EQ. + SOR_LENGTH) 34 2 Customizing the Excel/Aspen Plus Interface .Error Handling Section ---------------------1000 CONTINUE C C ALL ERRORS COME HERE TO REPORT ERRORS C C Call GetLastTableDataErr() C C HOL_STRLEN SETS THE PADDING FOR ERROR HANDLING STRING RETURNED C FROM THE EXCEL INTERFACE. NUM_ROWS.NE. HOL_STRLEN. OUTSTREAM.
4. We want to add labels (stored in REALROWS) to the Aspen_RealParams table. 8 ) NUM_LINES = 8 C MOVE STRINGS TO ERROUT_IEROUT ARRAY OF STRINGS. 11) + ( DESCRIPTION(I+C_OFF). XMW will hold the molecular weight data for a given component.NE. 1.NUM_LINES C_OFF = (J-1) * HOL_STRLEN/4 WRITE(ERROUT_IEROUT(J+2). X will contain the mole fraction of each component actually present in the stream and is sent to 2 3 4 2 Customizing the Excel/Aspen Plus Interface 35 . 0) THEN C DETERMINE NUMBER OF LINES OF LENGTH HOL_STRLEN TO PRINT C MAX IS 10 SO WE CAN USE 8 FOR DESCRIPTION OF ERROR NUM_LINES = ( (DESC_LENGTH+HOL_STRLEN-1) /HOL_STRLEN) IF (NUM_LINES . I=1.C REGISTER SEVERE SIMULATION ERROR FROM USER2 WITH ENGINE USER_ICONVG = -3 IF (DMS_IRRCHK(IPROG. USER_IUMISS. 2) . 4. + 0. 10) WRITE(ERROUT_IEROUT(2). FLOW will hold the total mole flow for the output streams.GT. CALL EndIteration(RETCODE) 999 CONTINUE C FORMAT STATEMENTS 10 FORMAT(' MS EXCEL Interface Reports:') 11 FORMAT(' '. WILL BE PRINTED C TO HISTRY FILE BY ERRPRT().(HOL_STRLEN+3)/4 ) 111 CONTINUE C PRINT ERROR MESSAGES TO HISTORY FILE USING THE FIRST NUMLINES+2 C LINES OF THE ERROUT_IEROUT ARRAY OF STRINGS.(SOR_LENGTH+3)/4) C WRITE ERROR MESSAGE RETURNED FROM EXCEL API TO THE HISTORY FILE DO 111 J=1. I=1. 11)(SOURCE(I). LMW will hold the offset to the location of the molecular weight data for each component. NCP will hold the actual number of components present in the stream. FIRST WRITE "MS Excel" THEN SOURCE C STRING RETURNED BY API AS ERROR HEADING.16A4) END Code Description – Subroutine MEM2 1 The MUMX (viscosity) addition to the list of stream properties means that there will be 10 properties read from Aspen Plus instead of the usual 9 so LABELS and ROWNAMES must be redimensioned. CALL DMS_ERRPRT(NUM_LINES+2) ENDIF C END ERROR REPORTING TO HISTORY FILE 2000 CONTINUE C Call EndIteration() C EndIteration IS CALLED EVEN WHEN A SEVERE ERROR OCCURS ABOVE. WRITE(ERROUT_IEROUT(1). 0.
the Physical Property Monitor subroutine PPMON_VISCL which calculates the viscosity of the stream. The first two (NCOMP_NCC) are the component mole flows. 12 The B array is used to get the molecular weight which is used to convert component flow rates. enthalpy. 11 The subroutine PPMON_VISCL returns the viscosity of the stream. pressure. and pressure. density. 5 6 RealLabels is a character array for the labels of the Aspen_RealParams Excel sheet that will be converted to Hollerith format. There are now 10 rows in the Aspen_Input and Aspen_Output tables in addition to the NCOMP_NCC = 2 rows that correspond to the component flow rates so DO loops have to be lengthened. 14 The subroutine USRUTS_CHARTOH converts the explicitly entered character labels into Hollerith format so that they may be sent to the WRITETABLE subroutine. In the subroutine in this example.cmn" REAL*8 B(1) EQUIVALENCE (B(1). vapor fraction. and molecular weight. The character strings to feed to the DMS_IFCMN function are listed in the Universal Constant Names and Definitions table in Chapter 6 of the User Models manual. The PPMON_VISCL subroutine needs a packed stream array when it calculates stream viscosity. 15 Only the viscosity of the feed stream is calculated so the output table still has the usual (NCOMP_NCC + 9) rows. 10 The subroutine SHS_CPACK packs the stream array by determining which components are actually present (have a non-zero flow rate) and putting their mole fractions in the X array. MUMX is stored in Hollerith format and will be written to the Aspen_Input and Aspen_Output Excel sheets along with the standard nine stream property labels. The user subroutine includes the following statements: #include "dms_plex. DMS_IFCMNC is an integer function that determines the location of the data such as molecular weight and critical temperature that corresponds to each component. The integer variable NCOMP_NCC is equal to the number of conventional components (in this case 2) declared in the Components Specifications Selection sheet and is passed through the common DMS_NCOMP also included in this subroutine. 13 The total mole flow is the third (NCOMP_NCC + 1) entry in the Aspen Plus stream input array called MSIN. entropy. the viscosity is placed in the INSTREAM array. there is no point sending it a bunch of zeroes for the other 7 8 9 36 2 Customizing the Excel/Aspen Plus Interface . The next eight stream properties are temperature. The molecular weight of the first component will be found at B(LMW + 1) where LMW is the offset returned by the function. Labels for the Aspen_RealParam table are entered explicitly as a character array. 16 Since the Excel model only calculates flow rates.IB(1)) These statements allow the subroutine to access component data. These are listed in Appendix C of the User Models manual and these are the data that appear in the Aspen_Input and Aspen_Output Excel sheets. liquid fraction. temperature.
Keep the DOS window available for the linking step and use a text editor to create a DLOPT file to control the creation of a shared library (also known as a dynamic linking library). these data will be available in Aspen Plus results sheets. type cd membrane if your Fortran file is in a subfolder called membrane in your working directory. The properties that Excel does calculate are placed in OUTSTREAM when READTABLE is called.OBJ files and another tells Aspen Plus where to find the DLL being used for a particular run. 4 Use the DOS cd command to set the default directory to the location of Mem2. If you have not already done so. 3 5 Create a Shared Library 1 2 Use a text editor such as Notepad to create a text file called Membrane2_List_OBJs. Type Mem2. The MSIN and SOUT arrays contain component and total flow rates in mole basis (kmol/s) and eight other properties in standard SI units. Compile the Excel Interface Subroutine 1 2 Save your customized Fortran file as Mem2. An object file (Mem2. Launch the Aspen Plus Simulation Engine Window.OBJ file and ensure consistent compiler options. total flow. Compiling and Linking the Subroutine The aspcomp command delivered in the Simulation Engine DOS prompt window will create the .) A DOS window appears with the working directory as the default directory.opt in your working folder. Two DLOPT (dynamic linking option) files control the linking process: one creates a DLL from specified .f.f.f. set your compiler option by running Start | Programs | AspenTech | Process Modeling <version> | Aspen Plus | Select Compiler for Aspen Plus. and 8 other properties as MSIN (see item 13 above). For example. (From the Start menu click Programs | AspenTech | Process Modeling <version> | Aspen Plus | Aspen Plus Simulation Engine.properties.obj) is created in the same directory as Mem2.obj in the top line of the text file. 2 Customizing the Excel/Aspen Plus Interface 37 . 17 The array SOUT contains the same NCOMP_NCC component mole flows. Choose the option which represents the combination of Fortran compiler and linker you want to use. Type aspcomp Mem2 to compile the subroutine. When the SOUT array is filled with the OUTSTREAM values.
opt] membrane2.dll. you will tell Aspen Plus the name of this file so that the shared library will be available. change the title to membrane2. Note: If you have both the GUI and the Simulation Engine Window open at the same time. it can be used with Aspen Plus even if you don’t have a Fortran compiler available. type asplink [dlopt membrane2_list_objs. 3 4 Go to the Setup Specifications Global sheet. Once you have the shared library. change the name of the Excel file to MemCalc_Custom. you can run the simulation using membrane1. 5 38 2 Customizing the Excel/Aspen Plus Interface . This is a Fortran shared library. In the DOS window of the Aspen Plus Simulation Engine. A file called membrane2. On the Subroutines sheet. 7 8 Save the text file and exit the text editor. an asplink command will fail unless you reinitialize the open run. Using a shared library avoids the need for a linking step when Aspen Plus runs. Put a copy of the Membrane2_Loc_DLL. Running the Simulation Now that you have your revised Excel file and have created a shared library containing your customized Fortran subroutine.dll is created.apw from the previous chapter.apw. Select Run | Reinitialize (or press Shift-F5) and click OK twice to clear data from the previous run.opt in your Aspen Plus Working Directory. 5 6 Create another DLOPT text file called Membrane2_Loc_DLL. At run time.dll using all the object files in the default directory. In the top line of this file type membrane2.xls. Note: If you simply type asplink membrane2 Aspen Plus will create membrane2. 1 2 Open membrane1.3 4 Save the file and exit the text editor. Go to the Blocks MEMBRANE Setup Subroutines sheet and type MEM2 in the Model field in the User2 subroutines area so that Aspen Plus knows what your new subroutine is called.opt. and make sure SI units are selected for the output.
2 Customizing the Excel/Aspen Plus Interface 39 . The Run Settings dialog box appears.6 From the Aspen Plus menu.opt so that Aspen Plus knows the name of the file containing the location of the library that contains your customized subroutine. select Run | Settings. This DLOPT file must be in your Aspen Plus Working Folder. 7 In the Linker options field in the Miscellaneous files area type membrane2_loc_dll.
The original label Aspen Viscosity was overwritten with the new label MUMX specified in the interface routine. 8 9 Click OK.Note: You can change the default Aspen Plus working directory in the Tools | Options | Startup tab. It now contains labels in column A specified in the interface routine. It now contains viscosity data as calculated by Aspen Plus. The Excel Aspen_RealParams sheet appears below. 10 Compare your Aspen Plus and Excel Results to those displayed below.opt file must be saved in the same directory as the simulation file. Results from the Custom Excel Model For convenience Excel and Aspen Plus sheets are shown here. The membrane2_loc_dll. The Excel Aspen_Input sheet appears below. Run the simulation. 40 2 Customizing the Excel/Aspen Plus Interface .apw and exit Aspen Plus. 11 Save the run as membrane2.
The value of Cr in cell B14 is slightly different from that in the previous chapter because the viscosity used in this example is more accurate: The Excel Aspen_Output sheet appears below. It contains flow rates in mass basis. 2 Customizing the Excel/Aspen Plus Interface 41 .
The Aspen Plus Blocks | MEMBRANE |Stream | Results | Material sheet: The Aspen Plus Blocks | MEMBRANE | Results Summary sheet: 42 2 Customizing the Excel/Aspen Plus Interface .
Finally. you can enter these parameters once and they will be automatically included whenever the customized block is placed on the Process Flowsheet. containing a customized model for the ultrafiltration membrane. Each model is represented by an icon (multiple icons may be created and used for strictly aesthetic reasons) and has default parameters associated with it. They could be represented as separate models. Creating a Model Library A model library has three levels: the library itself consists of a set of categories each identified by a tab in the Model Library palette. a Configured Variables sheet is available in which the set of real and integer parameters are associated with character strings and identified as input or output. In the previous chapter you entered a set of real and integer parameters for the physical characteristics and calculational coefficients of the model using the Aspen Plus User Arrays data sheet. The icon itself can be custom drawn. Use the same model parameters as in the previous chapter to specify the membrane characteristics. Ultrafiltration. Each category consists of a set of models. thereby simplifying the code. In addition.apm. With a customized unit operation model. Then replace the User 2 block in membrane2. Allow about 30 minutes for this session. create a new Aspen Plus Library. 3 Customizing the Aspen Plus Model Library 43 . This data can be accessed in the user Fortran subroutine by referring to the variable names. In this session. Create a custom icon for your model. The present hollow fiber ultrafiltration membrane has 180 tubes but another might have only 90.3 Customizing the Aspen Plus Model Library Your customized Excel model can have its own unit operation model stored in an Aspen Plus Library file (.apw with your custom block and run the simulation again.apm extension) and displayed in the Model Library palette. the name of the user Fortran subroutine and Excel file can be associated with the customized model.
Click Create. It contains no categories and no models. Open an Aspen Plus blank simulation. The Create Aspen Plus User Model Library dialog box appears. 44 3 Customizing the Aspen Plus Model Library . for example. The New User Model Library dialog box appears. 6 7 Click Save. You have created an empty library. Click (it’s a Browse button).Create an Empty Custom Model Library 1 2 3 Create a sub-folder in your Aspen Plus Working Folder called. Select Library | New. The previous dialog box reappears. The next step is to create a template that contains default parameters for your customized model. 4 5 In the Enter Display Name field. to contain library files. type Ultrafiltration. Navigate to the directory where you wish to store library files. lib.
It gets the default ID B1. type the name of the Fortran subroutine that will be used with the customized block. place a User Models | User 2 | FILTER block on the process flowsheet. type Mem2. Open the Data Browser and go to the Blocks | B1 | Setup | Subroutines sheet. Create the Custom Model from the Template 1 2 Go back to the Process Flowsheet. 3 Customizing the Aspen Plus Model Library 45 . and select Add to Model Library.Create a Template for Your Custom Model 1 2 3 4 5 From the Model Library. For this example. right click. In the Model field. type the name of the Excel file that contains the equations for the model.xls. Now your template is prepared and you are ready to create the customized model. Select your template block. For example. MemCalc_Custom. In the Excel file name area. Click the User Arrays tab and enter the same real and integer parameters as in the previous chapter including two empty real parameters for results data.
4 5 In the Choose Custom Model Category dialog box. and click Next. 3 Select Add: Create a new …. click Create New Category. and select your library (Ultrafiltration). The Add Custom Model Type to User Model Library Wizard dialog box appears. . Select Library | Save Default to make sure the selected library is available whenever you start Aspen Plus. Note: If you leave the Save User Model Library after Addition box checked. Type Membranes and click OK. select Library | References . 46 3 Customizing the Aspen Plus Model Library . Then select Library | Ultrafiltration | Writable so that you can edit it or add a model to it. Aspen Plus will automatically save the new model at the end of the creation process. The Choose Custom Model Category dialog box reappears.Note: If you start Aspen Plus in the future and find the Add to Model Library option unavailable.
3 Customizing the Aspen Plus Model Library 47 .
Later. you will delete the icon and create a custom icon. The Choose Custom Model Type Creation Options dialog box appears with the block ID (B1) entered automatically. The Choose Single Block or Multi Record Custom Model Type dialog box appears. 8 9 Replace B1 with HollowF. 48 3 Customizing the Aspen Plus Model Library . 7 Select Single Block Custom Model and click Next. Choose any icon option.6 Select Membranes and click Next.
11 Make sure the Copy/create user model configuration checkbox is selected. you will have access to the HollowF unit operation model with default user subroutine name. you can overwrite the default entries to the Blocks | BLOCKNAME | Setup | Subroutines and User Array sheets. Aspen Plus will copy the data you entered on the Subroutines sheet and on the User Arrays sheet into the new model. 17 Exit Aspen Plus. however. 15 From the Model Library. Aspen Plus will make the Configured Variables sheet available to the new model so that you can associate variable names with your real and integer parameters. Aspen Plus automatically saves the new library. in the following ways: you can delete it.10 Make sure the Copy/create model template checkbox is selected. 16 Open the Data Browser and go to the Blocks | B2 | Setup form and check that the default data appears correctly on the Subroutines sheet and on the User Arrays sheet. 14 Delete the block on the Process Flowsheet that you used as a template. rename it. whenever you start Aspen Plus and select Library | References and click the Ultrafiltration checkbox. For example.apm. Excel file path. 12 Click Finish. in the next chapter. Note: Any Aspen Plus model from the Model Library can be moved into the new library by dragging the icon into the Model Library Editor (select Library | Ultrafiltration | Edit to open the Editor). redraw the icon.) A tab for the Membranes category of the Ultrafiltration library now appears alongside the tabs of the Built-in library. The HollowF model can be edited. The defaults for the HollowF model remain intact. This change only affects the block to which it is applied. There is no need to save an apw file since the library is already saved as Ultrafiltration. The model you created is visible. The Add Custom Model Type to User Model Library Wizard appears automatically. and add named variables that refer to the real and integer parameters on the User Arrays sheet. drag a HollowF unit operation model onto the Process Flowsheet. you will place a HollowF block. Editing the Custom Model When you use a model from a custom library. delete the path to the Excel file and use a revised Fortran subroutine to perform the model calculations. 13 In the Model Library click the Membranes tab. the Save option should be shaded. (Select Library | Ultrafiltration. Now. and real and integer parameters. 3 Customizing the Aspen Plus Model Library 49 . These changes are stored in the library when you select Library | LIBNAME | Save.
then add named references to the real and integer parameters. .Open the simulation from the previous chapter and edit the HollowF model. Keep your custom drawing reasonably well centered.at(0. drag the divider between the pane with the icon and the pane below it upward and scroll to find this statement. right click. . 50 3 Customizing the Aspen Plus Model Library . The Icon Editor appears. The small enclosed crosshair indicates the automatic position of the block ID. First customize the icon. 7 Click and hold and drag across the entire icon to enclose it in a dashed box.) If the coordinates are far from zero.0. The call Label.1) statement in the lower pane indicates that it will be placed very close to the spot where the user clicks on the process flowsheet. In the Ultrafiltration – Model Library Editor window. block placement could be unpredictable. Move the universal port arrows so they are attached to the icon. Select Library | References. 8 9 Use the graphics tools to create a custom icon for the hollow fiber ultrafiltration membrane. (If necessary. From the tools menu. . select the HollowF model. select Library | Ultrafiltration | Writable. Click the right mouse button and select Delete.apw. . The icon disappears except for two arrows that represent the universal input and output ports. select Library | Ultrafiltration | Edit. From the tools menu. Create a Custom Icon 1 2 3 4 5 6 Open Membrane2. and select Edit Current Icon . Click OK. and select the checkbox next to Ultrafiltration to make your library available.
3 Real is the default type. 11 Drag a P1(OUT) port from the left-hand pane and place it directly over the universal output arrow. 16 Exit the Model Library Editor by closing the window. 12 Select Icon | Update icon to update the code in the lower pane. 3 Customizing the Aspen Plus Model Library 51 . add named references to the real and integer parameter arrays. These names will be used in the Fortran code in the next chapter. the two parameters designated as output data will appear in a new results sheet. and select Edit User Configuration. Next. For the simulation in this chapter. Otherwise this run will be identical to the run in the previous chapter. Note: Aspen Plus will correctly identify the integer no matter where you put it. For NTUBES. 15 Select Library | Ultrafiltration | Save to save the changes to the library.10 Drag an F1(IN) port from the left-hand pane and place it directly over the universal input arrow. When the Icon Editor is active. 13 Exit the Icon Editor by closing the window. a main Icon menu becomes available on the menu bar for the main window. Create References to the Real and Integer Parameters 1 Select Library | Ultrafiltration | Edit. The User Model Configuration Editor appears. Note: Existing AutoCAD DXF files can also be imported into the Icon Editor. 2 Create names for the 1 integer and 13 real parameters in the order that they appear on the Blocks MEMBRANE Setup User Arrays sheet. 14 Click Yes when prompted to save the new icon. Select Import DXF from the Icon menu. click in the Type field and select Integer from the drop-down menu. right click the icon.
and coef4 real parameters with a depth of 1. For the last two real parameters. 52 3 Customizing the Aspen Plus Model Library . coef2. The Model Library Editor will write this new subroutine for you. Insert the New Model 1 2 3 Open Membrane2. create a new dll file containing the new subroutine. Note: It is also possible to create a structure called coefficients by choosing structure in the type field and then making coef1. select Remove Row.apw. Note: To delete a row. and respecifying the product stream flash. and link along with the user model subroutine Mem2. The new icon and the variable names will now appear whenever you use the HollowF model. compile. Select Library | References… and select Ultrafiltration. Exit the Model Library Editor by closing the window.f. then run the simulation and examine the results. 5 6 7 Exit the Configuration Editor by closing the window. Press Shift-F5 and click OK twice to reinitialize the simulation. This will be discussed further in the next chapter. select it. Select Library | Ultrafiltration | Save. Insert the HollowF model. The named references on the Configured Variables sheet must be supported by a short Fortran subroutine that you must create.4 Parameters are designated as Input by default. coef3. Inserting the New Model and Running the Simulation Delete the old model and replace it with your new HollowF model. This allows the user to access the parameters using the structure name and an index value and then place the real parameter in an array. click in the Input/Output field and select Output only. reconnecting the streams. right click. The completed table is shown below.
Reconnect the PERMEATE stream. the defaults will remain intact. If you accidentally select the PERMEATE stream first. press Esc on the keyboard to cancel. Check the Subroutines sheet and make sure the subroutine name and path to the Excel file are correct. Move the cursor over the Feed port and click once to reconnect the stream. The two results parameters that you defined for the HollowF model in the Configuration Editor do not appear on the Configured Variables sheet because they were specified as output parameters. 3 Customizing the Aspen Plus Model Library 53 . the same change will automatically appear on the other sheet. 4 5 6 7 8 On the Process Flowsheet. Select the FEED stream. HFUM180. right-click. Note: The data in the User Arrays sheet and Configured Variables sheet are the same. Make sure all the data included with the model by default is correct and add the product stream flash specification. select Reconnect Destination. Check the User Arrays and Configured Variables sheets. If you change any of the numbers on one sheet. The order matters because the first stream connected comes first in the output stream data array (SOUT). Place a HollowF block on the Process Flowsheet. check the data sheets for the HFUM180 block. they will appear on a results sheet. 4 Go to the Stream Flash sheet and specify a Temperature & pressure Flash for each product stream. For future block placements. delete the MEMBRANE block. No data is needed in the Flash specifications area.Your Ultrafiltration library has one category called Membranes and its tab appears in the Model Library. Now that the Process Flowsheet is complete. Once both streams are connected they can be separated for clarity. a Hollow Fiber Ultrafiltration Membrane with 180 tubes. 9 10 Rename the block. You can alter the numerical data if you wish and it will be changed for the particular block that you placed. Reconnect the RETENTAT stream to the Product port using the Reconnect Source option. Check and Edit Setup Sheets 1 2 3 Open the Data Browser and go to the Blocks | HFUM180 | Setup form.
create a shared library including your user subroutine and this new subroutine. Select Fortran | Export and save the Fortran file as Mem2Vars.f to the folder that contains Mem2.) 4 5 6 Exit the Configuration Editor by closing the window. right-click. and select Edit User Configuration to open the User Model Configuration Editor. Link. Select the HollowF model. and Run 1 2 3 Select Library | Ultrafiltration | Writable and then Library | Ultrafiltration | Edit to open the Model Library Editor. Save your run as Membrane2_CM. and run the simulation.Now create the Fortran file to handle the new variable names. Save the library (Library | Ultrafiltration | Save) and exit the Model Library Editor.f (\Working Folders\Aspen Plus\Membrane. 54 3 Customizing the Aspen Plus Model Library . compile it.apw and then exit Aspen Plus so that you can run asplink in a moment. Compile.
10 Type aspcomp Mem2Vars and press Enter to compile the new Fortran subroutine. 12 Close the Aspen Plus Simulation Engine Window window. A new version of Membrane2. 11 Type asplink [DLOPT Membrane2_List_OBJs.obj. 18 Go to the Blocks | HFUM180 | Results | Summary sheet to see the entire real and integer parameter lists including the two real parameters that were specified as output only. If necessary. 14 Start Aspen Plus.apw. type cd Membrane and press Enter to set the directory to the location of your Fortran files. 17 Run the simulation.opt and add a line indicating Mem2Vars. Save the new DLOPT file and exit the text editor. Membrane2_List_OBJs. The Mem2 subroutine was compiled in the previous chapter. 3 Customizing the Aspen Plus Model Library 55 .opt in the Linker Options field to tell Aspen Plus where to find the shared library. and open Membrane2_CM.dll is placed in your Membrane subfolder. 16 Click OK. type Membrane2_Loc_dll. Membrane2_Loc_dll. 9 Start the Aspen Plus Simulation Engine to get the DOS window. so the obj file should already exist. 19 Go to the Configured Variables sheet to see just the two output parameters.dll.7 8 From the Membrane sub-folder.opt] Membrane2 and press Enter to create a new shared library from the two obj files. open your DLOPT file. 13 Check that your other DLOPT file.opt is still in the Aspen Plus Working Folder and contains Membrane2. 15 Select Run | Settings.
opt file as in the previous chapter and produces the same results.apw to emphasize this connection to the previous simulation.opt.20 Save the simulation as Membrane2_CM.apw.dll. 56 3 Customizing the Aspen Plus Model Library . It has been named Membrane2_CM. an updated version of Membrane2_List_OBJs. It uses an updated version of Membrane2. and the same Membrane2_Loc_dll. Note: This simulation file uses the same Mem2 subroutine as Membrane2.apw and exit Aspen Plus.
Use the named references (such as “DIAM”) you specified when you created the model. A complete listing is provided here. Use Aspen Plus utility functions that read from and write to the real and integer array stored with the HollowF customized model. build a User2 Fortran model to replace the Excel model that you developed previously. once the model is developed. 4 Creating an Aspen Plus Fortran Model 57 .4 Creating an Aspen Plus Fortran Model Excel is useful for testing and troubleshooting a new model because it is selfcontained – during the testing phase. The absence of Excel interface functions and the presence of the Aspen Plus utility functions make for compact code in the new subroutine. you may wish to perform the model calculations in the user Fortran subroutine and transfer the results directly to Aspen Plus. Allow about 30 minutes for this session. However. In this chapter. it is not necessary to run Aspen Plus simulations.
cmn passes arrays containing component data such as molecular weight. IWORK. Numbers in parentheses after the boldface comments refer to the relevant part of the Code Description that follows the listing. SINFO. The complete subroutine is listed below.cmn passes NCOMP_NCC. LD ) MSIN.f extension is allowed and any subroutine name up to six characters is allowed.f and change the name of the subroutine to HFUM. (2) Dms_ncomp. NINFO. NIWORK. NPO.f in the folder you are using for your Fortran subroutines. NINFI. (3) C ------------------. NINT. NINT. NSUBS. NINFI. NSIZE. NSIZE. NREAL. INTSIZ. INT. For example. REAL.cmn passes USER_NHSTRY. IDS.IB(1)) #include "dms_ncomp. NTOT. NMATO. Edit Usrus2. WORK. NINFO. NWORK. Ppexec_user.Declare arguments ------------------------------------INTEGER NMATI. IDSIO.cmn" C C C C Include files pass additional variables via COMMONs. IDSMO. NSUBS. IDSII. NPO. NMATO. SOUT. 3 Rewrite the subroutine following the complete Code Listing below. (1) Dms_plex. copy this file to Aspen Plus working directory. NTOT.cmn" #include "dms_plex.Putting the Model Equations in the User Subroutine A Fortran template is available that will make creating a subroutine to perform the calculations for the HollowF model easier.cmn" Real*8 B(1) Equivalence (B(1). NWORK. IDSMI. ITYPE. 2 Note: Any filename with the . NREAL + + 58 4 Creating an Aspen Plus Fortran Model . NBOPST. IDXSUB. 1 Put a copy of \Engine\User\Usrus2. NIWORK. IMPLICIT NONE #include "ppexec_user. SINFI. Code Listing – Subroutine HFUM 2 3 4 5 6 7 SUBROUTINE HFUM (NMATI. SIZE.
*) ' ERROR FETCHING LENGTH' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('DIFF'. KM. J. X(10). C2. INT(NINT).Begin Executable Code ---------------------------------C ----------------. IDSII(2. IPERM. IDSMO(2. 0) THEN WRITE(USER_NHSTRY. LD REAL*8 MSIN(NTOT. IDXSUB(NSUBS). (7) IF (IERR . and to write results data ! to Aspen Plus. LDATA. PIN. P_PERM. C3. CR. DIAM) !Put Configured ! Variable called "DIAM" in local variable DIAM.Declare Local Variables --------------------------------INTEGER OFFSET. DIFF.NPO). ! These functions allow access to real USRUTL_GET_INT_PARAM. UAVE. FP. LEN.NE.*) ' ERROR FETCHING DIFFUSIVITY' IFAIL = 1 END IF 4 Creating an Aspen Plus Fortran Model 59 .*) ' ERROR FETCHING HYDRAULIC DIAMETER' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('LEN'. --------IFAIL = 0 INDEX = 0 !Used for passing a structure. NCP. IRET. SIZE(NSIZE). NBOPST(6. NTUBES. REAL(NREAL) + + C --------------. (8) WRITE(USER_NHSTRY. IWORK(NIWORK). SINFO(NINFO).NMATI). INDEX. KDIAG. CG. IDS(2. + + C ----------------. C4. IDX(10). FLOW + C ----------------.NE. ITYPE(NSUBS). DELTA_P. CIN. CP.Get configured REAL variables from Aspen Plus. IDSIO(2. INDEX. RE.NE. IERR. (5) REAL*8 DLOG !Standard Fortran function. REJ_COEF. 0) THEN !Write to History file if error. LMW.NMATI). (4) INTEGER DMS_IFCMNC !Determines offset to universal constant data. INDEX. (6) IERR = USRUTL_GET_REAL_PARAM('DIAM'. SOUT(NTOT.IFAIL REAL*8 + + DIAM.3).NMATO).NMATO). LEN) IF (IERR .NINFO). 0) THEN WRITE(USER_NHSTRY. SC. DIFF) IF (IERR .Declare Functions -------------------------------------INTEGER USRUTL_GET_REAL_PARAM. ! and integer parameters using named USRUTL_SET_REAL_PARAM ! references. JM. SINFI(NINFI). C1. I. RHO. INDEX. XMW. INTSIZ(NSIZE). WORK(NWORK).+ + + + INTEGER IDSMI(2. FIN. PRET.NINFI). MU.
C3) IF (IERR . 0) THEN WRITE(USER_NHSTRY. 0) THEN WRITE(USER_NHSTRY. DELTA_P) IF (IERR .NE.IERR = USRUTL_GET_REAL_PARAM('GEL_CONC'. INDEX. C2) IF (IERR . 0) THEN WRITE(USER_NHSTRY. 0) THEN WRITE(USER_NHSTRY.NE.*) ' ERROR FETCHING COEF1' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('COEF2'.*) ' ERROR FETCHING PRESSURE DROP' IFAIL = 1 END IF C ---------------.NE.*) ' ERROR FETCHING COEF4' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('PERM_PRES'.*) ' ERROR FETCHING COEF2' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('COEF3'.*) ' ERROR FETCHING PERMEATE PRESSURE' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('DELTA_P'.NE. INDEX. INDEX. NTUBES) IF (IERR . C4) IF (IERR . REJ_COEF) IF (IERR .Get configured INTEGER variables from Aspen Plus -------IERR = USRUTL_GET_INT_PARAM('NTUBES'. INDEX. CG) !Local variable IF (IERR .*) ' ERROR FETCHING REJECTION COEFFICIENT' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('COEF1'.NE. 0) THEN WRITE(USER_NHSTRY.*) ' ERROR FETCHING NUMBER OF TUBES' IFAIL = 1 END IF 60 4 Creating an Aspen Plus Fortran Model . INDEX. 0) THEN WRITE(USER_NHSTRY. C1) IF (IERR . P_PERM) IF (IERR .*) ' ERROR FETCHING GEL CONCENTRATION' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('REJ_COEF'. INDEX. INDEX. INDEX. INDEX. 0) THEN WRITE(USER_NHSTRY.NE.NE. WRITE(USER_NHSTRY.NE.NE. 0) THEN WRITE(USER_NHSTRY. 0) THEN !can have any name.*) ' ERROR FETCHING COEF3' IFAIL = 1 END IF IERR = USRUTL_GET_REAL_PARAM('COEF4'.
!Protein conc.------------------LMW = DMS_IFCMNC('MW') !Offset to component molecular weight data.EQ.) * 1000.CP) / (CIN .1) . NCP. (11) CIN = MSIN(2. JM = KM * DLOG((CG .DELTA_P !Retentate stream pressure in atm.CP)) !Volumetric flux in m/s. switch if not. ---------IPERM = 1 IRET = 2 IF (IDSMO(1. (11) PIN = MSIN(NCOMP_NCC+3.1) / 1000. / B(LMW+1) !Approximate water flow !in kmol/s. KDIAG.Fill SOUT array for PERMEATE stream. 1) RETURN C ---------------. !Bulk average velocity in cm/s.1) / 101325. in g/l. !put result in MU. MU. (13) 4 Creating an Aspen Plus Fortran Model 61 . ! Feed stream pressure !in atmospheres. SC = MU / (RHO * DIFF) !Schmidt number. + IDX. C --------------. (10) C ---------------.14*NTUBES/4. NCP. IDX.1) / RHO * 3600.FP/FIN*CP) / (1 .IPERM) = FP * RHO / 3600. !Viscosity of feed stream in g/cm/s. --------------------SOUT(1.C ---------------.Model Equations ----------------------------------------RHO = MSIN(NCOMP_NCC+8. (12) C --------------. !Feed flow in l/hr. !Density of feed stream !in g/cm^3.1) * B(LMW+2) / FIN * 3600000.EQ. !in feed stream in g/l. RE = DIAM * UAVE * RHO / MU !Reynolds number.14 * NTUBES*100*3600/1000. *) ' ERROR EVALUATING VISCOSITY FOR FEED' IFAIL = 1 END IF IF (IFAIL . It contains the outlet !stream ID’s. 0) THEN WRITE(USER_NHSTRY. IERR) !Calculate viscosity. CP = CG * (1 . X. ! in g/l. !Permeate stream flow rate in l/hr CR = (CIN . FIN = MSIN(NCOMP_NCC+1. (9) IF (IERR . MSIN(NCOMP_NCC+3. (9) KDIAG = 4 CALL PPMON_VISCL(MSIN(NCOMP_NCC+2.REJ_COEF) !Permeate stream protein conc.1).1) * MSIN(NCOMP_NCC+9. FP = JM * DIAM * LEN * 3. (11) UAVE = FIN / (DIAM**2*3. X. PRET = PIN .Calculate viscosity ------------------------------------CALL SHS_CPACK(MSIN(1.1).FP/FIN) !Retentate stream protein conc. NBOPST. 'RETE') THEN IPERM = 2 IRET = 1 END IF !IDSMO is an argument passed to the !subroutine. [= kg/l] (11) MU = MU * 10.1).NE.Get location of molecular weight data. KM = C1 * RE**C2 * SC**C3 * (DIAM/LEN)**C4 * DIFF/DIAM/100. / 3600.Assume PERMEATE stream is first. FLOW) !Pack stream data. !Mass xfer coef in m/s.
IRET) + SOUT(2. CR) IF (IERR .SOUT(2.IRET) SOUT(5.IRET) SOUT(2. (13) C -.1) !Temp. (13) SOUT(5.Fill SOUT array for RETENTAT stream using values from PERMEATE stream.IRET) SOUT(4. (13) MSIN(4.IPERM) !Water flow in kmol/s. -IERR = USRUTL_SET_REAL_PARAM('CP_PROT'.IPERM) + SOUT(2. (14) IF (IERR .IPERM) = SOUT(1.SOUT(2. / 3600. (13) SOUT(1.Now set values of the two variables designated as output parameters. CP) !The HollowF ! model was designed to accept 2 output parameters. SOUT(1.IRET) !Total flow in kmol/s.*) ' ERROR STORING RETENTATE PROT CONC' IFAIL = 1 END IF RETURN END 62 4 Creating an Aspen Plus Fortran Model .SOUT(1. 0) THEN WRITE(USER_NHSTRY.IPERM) = P_PERM * 101325. !Pressure in N/m^2. (13) C -.1) .NE. unchanged from feed (K).IPERM) !Total flow in kmol/s. (13) SOUT(3.IPERM) = MSIN(4. INDEX. (13) MSIN(2.IPERM) !Protein flow in kmol/s.NE. (13) PRET * 101325.*) ' ERROR STORING PERMEATE PROT CONC' IFAIL = 1 END IF IERR = USRUTL_SET_REAL_PARAM('CR_PROT'. / B(LMW+2) !Protein flow in kmol/s.IRET) SOUT(3. unchanged from feed (K). !Pressure in N/m^2.IRET) = = = = = MSIN(1.IPERM) = FP * CP / 1000. INDEX.1) . 0) THEN WRITE(USER_NHSTRY. (13) SOUT(4.1) !Temp.
coefficients. 4 Creating an Aspen Plus Fortran Model 63 . DO i = 1. USRUTL_GET_REAL_PARAM. The three USRUTL functions return an integer which will have the value zero if there were no errors. Each element must be set once per loop. NCOMP_NCC is the number of conventional components in the simulation. C2). ID. and str2c.C(i)) END DO The 1-based INDEX array contains only as many elements as there are levels of structure. The integer function DMS_IFCMCN takes a character string as input (for example. set INDEX(1) = 2 and INDEX(2) = 3. suppose you have nested structures with str1 containing str2a. The data is accessed by using a function to find the offset to the location of the data in the B or IB array. str2b. there are two. Aspen Plus will also save a History File if you save the simulation as an apw file. Its value is irrelevant in the present example since none of the data are structures. . For example. 0. INDEX is an array of indices used in the USRUTL functions when handling a structure. In this example. If str2b has five scalar elements and you wish to access the third. see the User Models manual and step 10 in this list. you can access this file by selecting View | History. From Aspen Plus. i REAL*8 C(4) . These functions allow the user to pass values between the Fortran subroutine and Aspen Plus according to the names defined using the User Model Configuration Editor. For more information and examples. This command will open the history file with a text editor and it can be saved using the text editor.INDEX. ‘MW’ for molecular weight) and returns the offset to an area of the “Plex” data array.Code Description – Subroutine HFUM 1 USER_NHSTRY is the Fortran unit number for the History File.coef2) may also be referenced directly by its lowest level name ('coef2' in this example) as if it were not in a structure at all: USRUTL_GET_REAL_PARAM('coef2'. water and protein. The common DMS_PLEX contains data for all components including the formula. A scalar element within a structure (for example. if you created a coefficients structure with four elements you could access them using the following code: 2 3 4 5 6 INTEGER INDEX(1). Ierr. For more discussion of the DMS_PLEX common and examples see the User Models manual and steps 5 and 10 in this list. and physical property parameters such as molecular weight. However.4 INDEX(1) = i Ierr = USRUTL_GET_REAL_PARAM(‘coefficients’.
and calculates the pressure of each stream. pressure. set the product stream temperatures equal to the feed stream temperature. also discussed in Step 1 above. 11 The input (feed) stream array MSIN contains NCOMP_NCC+9 elements for each feed stream. For example. The program calculates flow rates for each component. Alternatively. Of course any declared Real*8 variable is allowed to hold the value of this parameter. In this example. there are 2 four-character labels. The first index may be 1 through 11 since there are two components. For more information about accessing physical properties see Chapters 3 and 4 of the User Models manual. the user can see that one of the real parameters is called DIAM. temperature. It contains the mole flow. a reduced list of component mole fractions with the zeroes removed) produced by a packing utility such as SHS_CPACK. liquid fraction. and other data for the two product streams. pressure. The following nine elements are total mole flow. in this example. the streams are distinguished by the first four letters in the label of each (RETE and PERM). The molecular weight of protein (really lysine) is stored in B(LMW + 2).*) 'diam = '. is named DIAM. This History File. enthalpy. and molecular weight of the stream. Since the model equations in this example use other units. temperature. They are listed in Appendix C of the User Models manual and are in SI units. entropy. density. IDSMO is an array with dimension (2. 14 Other data not included in SOUT will appear on the Blocks | HFUM180 | Results | Configured | Variables sheet because two variables were 64 4 Creating an Aspen Plus Fortran Model . In this example. 13 The SOUT array has the same structure as the MSIN array. NMATO) where NMATO is the number of material outlet streams. 12 The argument list for User 2 models is documented in Chapter 5 of the User Models manual. a statement like might be useful if your calculations aren’t coming out properly and you want zero in on the problem. 10 For a list of the names to feed to DMS_IFCMNC in order to retrieve component data from Aspen Plus. 8 WRITE (user_nhstry. conversions must be performed. see Chapter 6 of the User Models manual. The function USRUTL_GET_REAL_PARAM retrieves the value of this parameter and puts it into a local Fortran variable that. diam 9 The user can call physical property monitors such as PPMON_VISCL to access the Aspen Plus Physical Property system. is a useful place for error messages and troubleshooting output statements. the offset (LMW) to the molecular weight data is obtained using the string ‘MW. the programmer can instruct users to always connect the Retentate stream first. These data are sent to Aspen Plus by filling the first five elements of the SOUT array for each stream. the total flow rates. vapor fraction. The PPMON subroutines require the stream information in “packed” form (that is.’ The molecular weight of the first component listed by the user on the Aspen Plus Components Specifications Selection sheet (water) is stored in B(LMW + 1). In this example there is only one feed stream so the second index is always 1. The first two elements are the mole flows in kmol/s for water and protein. For each stream.7 On the Aspen Plus Blocks | HFUM180 | Setup | Configured Variables sheet.
(From the Start menu click Programs | AspenTech | Process Modeling <version> | Aspen Plus | Aspen Plus Simulation Engine. Type aspcomp HFUM to compile the subroutine to create HFUM. Compiling and Linking the Subroutine Use the aspcomp command to compile the subroutine. Then create a new DLOPT file that contains the name of the new subroutine. 1 2 Save your Fortran code as HFUM. Save the file as HFUM_Loc_DLL.opt and exit the text editor. From the Aspen Plus Working Folder. Then enter the name of the DLOPT file containing the location of the dll file and run the simulation. Open Membrane2_List_OBJs. Running the Simulation Use the membrane2_cm.opt and exit the text editor. 4 Creating an Aspen Plus Fortran Model 65 . Aspen Plus makes no assumptions about units. Since your model calculations will be performed by the Fortran subroutine.obj.) In the DOS prompt window type cd membrane if your Fortran files are in a sub-folder of your Aspen Plus Working Directory called membrane.designated output only when the user set up the configured variables for the HollowF model. remove the reference to the Excel file. 3 4 5 6 7 8 9 In the DOS window of the Aspen Plus Simulation Engine.obj with HFUM. open Membrane2_Loc_dll.opt and replace Mem2.f and exit the development environment. Start the Aspen Plus Simulation Engine Window.dll.dll.opt and replace Membrane2.obj. type asplink [dlopt HFUM_List_OBJs.opt] HFUM to create HFUM.dll with HFUM. Create the DLL file and place a DLOPT file in the Aspen Plus Working Folder that contains the path to this new DLL. Since this is user-specified output data. Save the file as HFUM_List_OBJs. The protein concentration in g/l for both product streams appears on the results sheet.apw simulation from the previous chapter.
66 4 Creating an Aspen Plus Fortran Model .1 2 3 4 Open membrane2_cm.apw. Select Run | Reinitialize (or press Shift-F5) and click OK twice. Run the simulation. and click OK. Go to the Setup | Specifications | Global sheet and change the title to HFUM. type HFUM_Loc_DLL. change the name of the Fortran subroutine to HFUM and delete the reference to the Excel file. Save the run as HFUM. Compare your results to those obtained using the Excel model or to the results displayed below. Go to the Blocks | HFUM180 | Setup | Subroutines sheet. 5 6 7 8 Select Run | Settings.apw and exit Aspen Plus.opt in the Linker Options field.
Results from the Custom Fortran Model Blocks HFUM180 Stream Results Material sheet: Blocks HFUM180 Results Configured Variables sheet: 4 Creating an Aspen Plus Fortran Model 67 .
NET cannot be used with this example. Allow about 40 minutes for this session. Include the new form as an addition to the usual forms associated with the HollowF model and create a new model that contains the special form. It is now possible to create forms for an existing plant unit that hides design parameters for users interested in performing rating only calculations for example.5 Creating an Aspen Plus Custom Form Creating graphical forms using Microsoft Visual Basic is the last level of customization for supporting custom models in Aspen Plus. create a model that will “own” the form. This example uses literal naming 68 5 Creating an Aspen Plus Custom Form . It is important to keep track of file names. The ability to create forms combined with the templating capabilities that you used in the previous chapter is a very powerful customization capability. create a special Blocks BLOCKNAME Input_And_Results form containing two sheets: an Input sheet that provides access to two important membrane parameters and a Results sheet that contains results of particular interest. Note: Visual Basic . Configured variables that were defined for these models can be linked into these forms. Visual Basic 6 template files are provided with Aspen Plus to reduce the amount of time required to develop custom forms. project and control names. Fields commonly used by the Aspen Plus GUI can be applied to a new sheet by dragging it from a Controls Toolbox. and the model name so that the interface works. These forms are easily inserted into Aspen Plus by registering the OCX file created by Visual Basic 6 using the Aspen Plus ApFormSetup utility. then create a text (OCR) file with specifications. and test the new form. run a program that automatically sets up the Aspen Plus/Visual Basic interface. Setting Up the Visual Basic Environment Use Visual Basic to create your form (an OCX file). In this example.
ctl tabtemplate.ctx formtemplate.ctl and to your project in the same way. Save the project as ProjectFile.ctx 3 Copy the following file from the GUI\xeq folder of the APrSystem <version> folder to your VB folder: Open the Visual Basic project by double clicking Template.vbp 4 5 6 Note: When creating forms after this exercise. create d:\Program Files\AspenTech\Working Folders\Aspen Plus\VB Copy the following files from the GUI\xeq folder of the Aspen Plus folder to your VB folder: tabtemplate.ctl). select formtemplate.ctx. you may wish to have ProjectFile = ProjectName = ModelName.vbp). To see clearly how the Aspen Plus/Visual Basic interface works. and ModelName. Aspen Plus provides a Visual Basic project file (. Your VB window should look something like this: 8 5 Creating an Aspen Plus Custom Form 69 . ProjectName. Select Project | MyModel Properties… and change the Project Name to ProjectName. Add tabtemplate. However.vbp. For example. Use these template files to set up an environment in which you can easily create custom forms that have the same look and functionality as the standard Aspen Plus forms. the example uses ordinary names for the form and its two sheets: FormName = Input_And_Results and Sheet1Name = Input.ctl and click open to add the control used for creating forms to your project.ctl formtemplate. keep these three names separate for this example.such as ProjectFile. Now you are ready to create an Aspen Plus form. two Visual Basic control files (. Sheet2Name = Results.vbp. and two graphics files (. 7 Select Project | Add User Control | Existing (tab). Template. 1 2 Create a new folder to use as a Visual Basic Working Folder. to support the control files) to define the development environment for creating Aspen Plus GUI forms.
70 5 Creating an Aspen Plus Custom Form . and save the file as TabControlFile.ctl). Creating the Visual Basic Form Create three controls: one parent control (Tab). right-click. Create Three Named Controls 1 2 3 4 Go to the Project window and expand ProjectName (ProjectFile. and two daughter controls (Input and Results). create labeled fields and indicate the Aspen Plus Path to the variables corresponding to each field. rename the two templates.ocr) that you will create provides Aspen Plus with the name of the tab control which has links to the two sheets which in turn have links to Aspen Plus variables. and import another instance of FormTemplate and rename it as well. The Toolbox (displayed via View | Toolbox) contains a number of tools in addition to MMTabStrip designed expressly for creating Aspen Plus GUI forms.vbp) so that the two control templates appear. The text file (. specify two labeled tabs. For the Input and Results controls. Click in the Properties window.ctl. Double click TabTemplate (TabControlFile.The cursor in the picture is hovering over the MMTabStrip tool that you will use to create your custom form. Select TabTemplate (tabtemplate. and specify the daughter control corresponding to each tab. The MM prefix indicates an Aspen Plus tool. For the Tab control.ctl). First. change the entry in the (Name) field to TabControlName and press Enter. A graphics window appears and the Properties window fills with data.
The Tab control is now listed in the Project window as TabControlName (TabControlFile. Select Project | Add User Control | Existing (tab) and import another instance of formtemplate. 5 6 7 Change FormTemplate (formtemplate.ctl) to InputControlName (InputControlFile. 5 Creating an Aspen Plus Custom Form 71 .ctl).ctl) to ResultsControlName (ResultsControlFile. Change FormTemplate (formtemplate.ctl.ctl) by repeating steps 2 – 4 above.ctl).
Build the Tab Control 1 2 3 4 From your VB project. Use the MMTabStrip tool and make two tabs (the default is three so you’ll have to delete one) linked to the Input and Results sheets.After cleaning up. Move the cursor onto the drawing area in the TabControlName window (it becomes a crosshair). your window will look something like this: Next. 72 5 Creating an Aspen Plus Custom Form . This “box with three tabs” is called a tab strip. click . build the Tab control. maximize the TabControlName window. Click and drag diagonally across the drawing area and release the mouse to create a box with three tabs. From the toolbox on the left-hand side of the VB window.
5 Creating an Aspen Plus Custom Form 73 . and select Properties. In the Caption field. type Input. Create the link to the Input control by typing ProjectName. the 0th and 1st. 12 Click Remove Tab as you need only two tabs. The Property Pages dialog box appears. close-up view: 8 9 Advance the Current Tab field from 0 to 1 by clicking the up arrow to the right of the field. right-click. Property Pages dialog. 10 Create the link to the Results control by typing ProjectName.ResultsControlName in the FormName field.5 6 7 Select the tab strip. In the Caption field.InputControlName in the FormName field. type Results. 11 Advance the Current Tab field to 2.
Click and drag in the drawing area of the Input control to create a Frame. You will specify the Aspen Plus paths to these variables in the Input control you are about to build. In the HollowF model.13 Click OK. 14 Reduce the TabControlName window so that you can access the other controls. Now two of these variables will also appear on your new Input sheet. 74 5 Creating an Aspen Plus Custom Form . The tab strip. 15 Select TabControlName (TabControlFile.ctl Next. you created named variables for the membrane parameters and they appeared on the Configured Variables sheet. Use the MMFrame tool to create a frame for two input fields. right-click.ctl) in the project window. Then use the MMLBUText tool to create the two fields – one labeled Channel Hydraulic Diameter and the other labeled Channel Length. and select Save TabControlFile. build the Input control. click . From the toolbox. Select View | Properties Window or press F4 to open the Properties window. Build the Input Control 1 2 3 4 Maximize the InputControlName window. (most-recently-edited tab is bold): Note: The MMTabStrip object selected above and the User Control object (selected if you click in the drawing area outside the tab strip) are separate objects with separate properties.
click . Click and drag in the upper half of the Frame to create a field area. From the toolbox. and clear the checkboxes for the Basis and Units fields. The Properties window : 6 7 8 9 Close the Properties window. Use it to position and label the field and assign it a path to an Aspen Plus variable. It won’t look nice right away. Another Property Pages dialog box appears. 10 Select the MMLBTUText tab.5 Enter Membrane Parameters in the Caption field. 5 Creating an Aspen Plus Custom Form 75 . 11 Set the Width for the Label to 2350. right-click. Select the new field area. and select Properties. 12 Set the Left parameter for the Text to 2400.
This is important because any given block could have any user-chosen name at run time. enter main. type Channel Hydraulic Diameter in the Label Caption field. 76 5 Creating an Aspen Plus Custom Form .B1 in this example. The variable main used above is automatically assigned to the path to the block containing your form: Application. 15 In the first Path column. Use a space between the words User and Table. User Table. click Add to create a variable having a Node datatype.Blocks.13 Select the MMLBTUTextLabel tab.Data. The full path to variable you defined as DIAM when you created the HollowF model is shown below in the Aspen Plus Variable Explorer window which is accessed by via the Tools | Variable Explorer… command.Tree. Input. 14 On the Variable tab. DIAM respectively into the first four cells.
17 Select the Channel Hydraulic Diameter field area and resize it so that it doesn’t take up too much space in the Membrane Parameters frame. The eventual Blocks BLOCKNAME Input_And_Results Input sheet looks like this: 5 Creating an Aspen Plus Custom Form 77 .Input.16 Click OK to close the Property Pages dialog box. 18 Click in the tool box. and select Save. select Properties and enter cm in the Caption field. 23 Select InputControlName (InputControlFile. right-click. 24 Repeat steps 7-23 and create a Channel Length field mapped to the LEN variable with path: main. right-click.User Table.ctl) in the Project window. 22 Reduce the InputControlName window. 19 Click and drag in the frame to create a small label. 20 Select the label.. 21 Resize the label and move it to the right of the Channel Hydraulic Diameter field.LEN.
use standard Visual Basic controls and use GetVar to access the Aspen Plus variables. Output. User Tree. It is fine to mix and match these. Create two fields. Save the Visual Basic Project. When you don't need to connect a control to an Aspen Plus variable. Specify paths to the two Output only variables. Next. See Using GetVar to Access Aspen Plus Variables in the online help. 8 78 5 Creating an Aspen Plus Custom Form . CR_PROT. you can use standard Visual Basic controls. User Tree. that you defined in the HollowF model. If you are going to write more sophisticated forms which operate on the input data before writing it into the Aspen Plus variables. Exit the VB development environment. CP_PROT. Permeate Protein Concentration and Retentate Protein Concentration. Output. Select File | Make ProjectFile.Note: In this example we used a mixture of MMControls (the MMLBTU from the template) and standard Visual Basic controls (the Label control). Make a field for Permeate Protein Concentration and map the variable to: main.ctl file. The eventual Blocks BLOCKNAME Input_And_Results Results sheet looks like this: 5 6 7 Save the ResultsControlFile. build the Results control. CP_PROT and CR_PROT. Add the concentration units (g/l) next to each field. An abbreviated procedure is given below – refer to steps 7 – 21. Make a field for Retentate Protein Concentration and map the variable to: main. Build the Results Control 1 2 3 4 Make a frame called Membrane Performance.ocx… and click OK to create the ocx file that will be registered with the operating system and thereby integrated with Aspen Plus. The MMControls already have the code defined within them to reference values from the Aspen Plus variable tree as specified through the property page in step 15 of the above example.
A text file with the OCR extension will contain specifications for the form. Create an OCR file called ModelName. The OCX file created above contains the actual form. The OCR file contains the name of the unit operation model that uses the form.exe in GUI\xeq to register your OCX file (the OCR file is processed automatically). Copy and paste specifications for the usual USER2 forms from the Aspen Plus OCR files in GUI\forms to your OCR file.ocx. Then do this: Rename the OCX file to ModelName. A step-by-step procedure is provided below.ocx.ocx to ModelName. the name of the form as it will appear on the Data Browser menu tree. Letters in the name of the unit operation model (in this case 5 Creating an Aspen Plus Custom Form 79 .ocr. The new form should appear only with this particular model. and information specifying the placement of the new form in the list of forms. Create a text file called ModelName. Put the specification for the new form into your OCR file.The Finished Project Integrating Forms with Aspen Plus The connection between Aspen Plus and your custom form is accomplished by means of two files. Put copies of your OCR and OCX file in GUI\forms.ocr with the first line as shown below. Your new form applies only to a USER2-based custom model (called ModelName in this example) for a hollow fiber ultrafiltration membrane. Use ApFormSetup. Create OCR and OCX Files for Your Model 1 2 Rename ProjectFile. The ModelName model should contain all the usual USER2 forms. the name of the tab control.
(Show/Hide Console Tree). right-click Indexing Service on Local Machine. ensure the checkbox Index files with unknown extensions is selected. 80 5 Creating an Aspen Plus Custom Form . j. Click With Indexing Service (for faster local searches). Close the Indexing Service console and re-run your original search. Aspen Plus will use the tab control object called ProjectName. Click Start | Search | For Files or Folders. The number “5” is for position in the form list and the number “1” indicates a tabbed form. Click Change Indexing Service Settings (Advanced). 3 Use the Windows Search tool (Start | Search | For Files or Folders) to find . On the Generation tab.MODELNAME) must ALL be capitalized even if the actual Aspen Plus model is called ModelName. A Search Results window appears. click f.OCR files in the GUI\forms folders in Aspen Plus and APrSystem that contain Blocks\USER2 specifications. Click Change Preferences. A form called Input_And_Results will appear in the Blocks folder on the Data Browser menu tree when a ModelName block is placed in the Process Flowsheet. g. To do this: a. Click Properties. On the toolbar. i.TabControlName to create the form. b. the search will not find any files unless you have set the Indexing Service to Index file types with unknown extensions. e. with all options available. In the left pane. Click OK. h. Note: On Windows XP. d. c. Note: You do not need to turn on the Index service.
register the ocx file with the operating system to give Aspen Plus access to the three controls you created: o o o ProjectName.InputControlName ProjectName. The Register Forms dialog box appears listing all OCX files in the GUI\Forms folder.ocx to the GUI\Forms folder of the Aspen Plus installation. Next. Replace Blocks\USER2 with Blocks\MODELNAME.ocr and ModelName. 5 Creating an Aspen Plus Custom Form 81 .TabControlName ProjectName. NodeName entries are for the Aspen Plus completion checking system. Copy ModelName. The CC.ocr and exit the text editor. 6 7 Save ModelName. 2 Click Deselect All to clear all the selections.4 5 Open the files containing the Blocks\USER2 specifications and copy and paste these lines into ModelName. Your new form called Input_And_Results (position 5) will be placed after the Setup and Petro Characterization forms (positions 0 and 1 respectively).ocr. The Setup form will open by default when you click on the BLOCKNAME folder in the Data Browser. 1 Run ApFormSetup. ensure that Aspen Plus is not running.ResultsControlName Register the OCX File Before you follow this procedure.exe in the GUI\xeq folder of the Aspen Plus installation.
ocx and click it so that only it is selected.3 4 In the Product specific forms list.exe announces success. The Data Browser updates (new entries are made in the System Registry) so that Aspen Plus has access to the new form. Select Update Data Browser Menu since you are only adding a form to a previously-built menu. 6 7 8 Click Deselect All and then click Finish since you have no new plot wizard files to register. Optional: Run Regedit. 82 5 Creating an Aspen Plus Custom Form .) and examine the new entries under HKEY_CLASSES_ROOT. Exit the Registry Editor without changing anything.exe (click Start | Run. scroll down to ModelName. The Register PlotWizard dialog box appears. Click OK when ApFormSetup. 5 Click Next. The three VB control objects that you created are listed. type Regedit in the Open field and click OK.
and click the results tab to see the changes. There is no data there yet. Single Block Custom Model. replace it with a ModelName model. and select Add to Model Library.. 11 Go to the Blocks | CFTEST | Setup | Stream Flash sheet and set Temperature & pressure flashes for both product streams. Name the new block CFTEST. 1 2 3 4 5 Open HFUM. called HFUM180. run the simulation again. 13 Run the simulation. and Copy current icon only. Open the Data Browser and go to the Blocks | CFTEST | Input_And_Results | Input sheet.apw and create a new model called ModelName in your ultrafiltration library. If it is not already there. and reconnect the streams.apw. change the input values of the two parameters. 12 Select Run | Settings and type HFUM_Loc_dll. Check the Results sheet. Select Library | Ultrafiltration | Writable. Select the HollowF block. Then replace the HollowF model with the new model and run the simulation.. 5 Creating an Aspen Plus Custom Form 83 . 14 Go to the Blocks | CFTEST | Input_And _Results | Results sheet to check the results. A series of dialog boxes appears. type HFUM in the Model field and eliminate the reference to the Excel file.. 7 8 9 10 Go to the Blocks | CFTEST | Setup | Subroutines sheet. Press Shift-F5 to reinitialize the run. Select Library | References… and check Ultrafiltration.opt in the Linker Options field if it is not already there. Then click Finish. Step 6 contains abbreviated instructions – refer to Chapter 3 for details. type ModelName. right-click. etc. Otherwise. 15 Go to the Blocks | CFTEST | Input_And_Results | Input sheet. select the following options: Add: Create a New etc. 16 Save the simulation as HFUM_CF.Testing the New Form Open HFUM. 6 When the Enter name to use for the model type field appears.apw and exit Aspen Plus. Note the data in the two fields. Delete the HollowF model on the Process Flowsheet. Membranes.
Results from the Custom Form The customized Data Browser menu tree: 84 5 Creating an Aspen Plus Custom Form .
The Blocks CFTEST Input_And_Results Input sheet with new data: The Blocks CFTEST Input_And_Results Results sheet after the run with new data: 5 Creating an Aspen Plus Custom Form 85 .
Note: You should select Local PC and ensure the simulation engine is installed on your PC. Your password for the above user name. and select the type of host computer If you choose Local PC as the server for the simulation engine. When the network connection is established. the Connect to Engine dialog box appears. you do not need to enter any more information into the dialog box. 5 Click OK. 1 2 In the Server type field. If you choose Windows server as the server for the simulation engine. click for the simulation engine. but the Activator security device is not connected to your PC. Some features are known not to work in client-server. The simulation engine is installed on your PC. If the Connection Established message does not appear. In the other fields. enter the following information: User name Password Working directory Your user name for the specified host/server. The associated working directory.6 Connecting to the Aspen Plus Simulation Engine If either of the following conditions exist. 86 6 Connecting to the Aspen Plus Simulation Engine . you will be prompted to specify the host computer for the Aspen Plus simulation engine after you start the Aspen Plus User Interface: The simulation engine is not installed on your PC. In these cases. enter the node name of the computer on which the Aspen Plus simulation engine will execute. Click OK to continue. enter the following additional information: 3 4 In the Node name field. the message Connection Established appears in the message box. see your Aspen Plus system administrator for more information on network protocols and host computers for the Aspen Plus simulation engine. Client-server configurations are no longer supported.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.