Implementing MOSAICmodeling Models into Aspen Plus
by Alberto Penteado
This description can also be obtained as a PDF here.
This is a step-by-step guide on how to export self-implemented models from MOSAICmodeling to Aspen Custom Modeler (ACM) and Aspen Plus in order to take advantage of Aspen’s property functions and integrate customized unit operation models into a flowsheet. Knowledge of modeling in MOSAICmodeling and the use of functions, connectors, and ports are pre-requisites. No knowledge of ACM’s language is required, but some knowledge on setting up a simulation in Aspen Plus is expected.
Creating a MOSAICmodeling Model
The first step is to create a MOSAICmodeling model. In this example, an adiabatic two liquid stream mixer is to be simulated based on a MESHI equation system as described below:
Interfaces are necessary to embed external function calls and to connect ports to external elements. The interfaces contain the required variables for the connectivity. An interface is needed for the enthalpy function, which is calculated by the ACM procedure named Calculate Molar Liquid Enthalpy. Another interface is needed for the external ports to be able to connect with ACM streams.
In the Interface / Pattern Assistance tab load the public notation and then select the box that says Other. Select ACM Calculate Molar Liquid Enthalpy in the combo box. The required fields will appear below under Fields of Specific Interface.
These fields need to be introduced in the Interface Fields tab as shown below. Besides the variable naming, it necessary to give a Name (description), a Dim (scalar or vector), Engineering Unit and information flow (in or out or in/out). For the ACM Molar Liquid Enthalpy function, the enthalpy is an output variable, while pressure, temperature and composition are input variables. Once these fields have been introduced it is possible to click on Test Pattern Compliance to verify if all the required fields are met.
Save the interface for the ACM molar liquid enthalpy and click on New to create an interface for ACM stream data. Load the public notation again and select ACM Stream Data on the pattern assistance.
In the Interface Fields tab, enter the required fields as specified in the pattern assistance and as shown below. As this interface will be used for both inlet and outlet streams, the information flow of every field is selected as In/Out. Save the interface for ACM Stream Data.
Introducing Embeded Functions
Aspen Custom Modeler has many built-in functions (procedures), for enthalpy, density, viscosity, fugacity, activity coefficient and etc. These functions can be embeded in a MOSAICmodeling model. These are generic function calls, which are independent of the selected property package. The calculations will be performed according to the selected property package (NRTL, SRK, PENG-ROB, etc.) for every simulation. This allows easy model reutilization.
In this example, the enthalpy of the liquid streams is going to be calculated by an Aspen Custom Modeler procedure. As the enthalpy is a function of pressure, composition and temperature, the procedure has the following structure:
h() = ACM Calculate Molar Liquid Enthalpy
Where is the liquid molar enthalpy in GJ/kmol, p is the pressure in bar, is the molar fraction of component and is the temperature in °C. Note that these units matter, since ACM cannot know which units are being used in the MOSAICmodeling model. Additional equations for unit conversion may be necessary.
In the Functions tab, click on the combo box under Interface settings and change from the default (Free interface) to Load interface. Load the previously created interface for the liquid enthalpy. Input and output variables should be filled automatically. Enter a description and save the function.
This function can be added to the equation system with the following 3 applications, for each one of the streams:
|Generic Naming||Application I||Application II||Application II|
Ports are necessary to allow the model to be connected to streams. They consist of an Interface, containing the required variables for connectivity, and a Connector, which translates the variable names between the model and the interface. Two inlet ports and one outlet port are necessary. The interface for ACM Stream Data was already created, but connectors need to be created following the nomenclature matching as following. It is not necessary to translate variables for molar volume as these variables are not included in the mixer model.
|Super Naming||Sub Naming I||Sub Naming II||Sub Naming II|
Create and save the three connectors in the Connectors tab. Now the ports can be added to the equation system in the tab Equation System / External Ports. An Id is automatically assigned (numbering all ports) as well as a directional Id (numbering input and output ports separately), which can be changed manually. User has to define the direction of the external port (in/out) and a name.
Enter a description and save the equation system containing the 4 equations, the molar liquid enthalpy function with 3 applications, and the 3 external ports.
Open the newly created equation system in the Evaluate/Simulation tab. Select the value for the index i (number of components) as 2 and confirm. In the Info tab, it is possible to give user-defined names for the namespaces. This is very important if many ports are used. Since ACM stream interface is selected as the super notation, the namespaces are the only way to differentiate the variables.
In the Variable Specification tab, select the design variables. The enthalpies of the three streams should appear in the calculated variables table. Give proper starting values for the flow, composition, temperature and pressure of the outlet stream. An example of problem specification is given below:
|Variable||Initial Value||Lower Bound||Upper Bound||Units|
In the Evaluation tab select ACM NLE Functions as Equations in the language specification and press generate code. The code is now ready to be copied and compiled in Aspen Custom Modeler.
Solution in Aspen Custom Modeler
Configuring the Component List
Open the ACM user interface. For this example we are using version 8.4. Before creating the model, it is necessary to configure a component list and a property package. In the Model Explorer select Component List and then double click on Default. Select the use Aspen property system option and click on Edit using Aspen Properties.
This will open the Aspen Properties user interface. Here the component list and property methods can be specified normally as when starting an Aspen Plus simulation. In order to verify the non-ideal enthalpy calculations, a binary mixture of water and methanol will be used. Add water and methanol to the component list.
Click Next to go to the Methods tab and select NRTL as the main property method.
Click Next one more time to retrieve the binary interaction parameters and again to run the property analysis. Once this is completed successfully, close the Aspen Property window and save the file when asked.
Back to the ACM window, it should state that the Component List setup was completed. Click on OK and add the available components to the ACM component list.
Creating a New Model
Now it is necessary to create a new model that will receive the code generated in MOSAICmodeling. Again on the Model Explorer palette, select Custom Modeling Models and then Add Model as highlighted below.
Name the model and paste the ACM code exported from MOSAICmodeling in the code window.
By default, the MOSAICmodeling code generation will:
- Name the model as mosaic_model
- Name the component list as prop
- Name components as COMP1, COMP2, etc.
- Name inlet ports as Feed1, Feed2, etc.
- Name outlet ports as Prod3, Prod4, etc.
The model name appearing on the code window must be the same as the name previously given, so change the fist line from mosaic_model to your given name. Comment by adding // or erase the line with the component list declaration to make ACM use the default component list as desired. It is essential to keep consistency in the component names, therefore the Component ID for water should be WATER and for methanol it should be METHANOL as previously defined. By using the tools search for and replace, it is possible to replace COMP1 and COMP2 by WATER and METHANOL.
One might also want to rename the ports to make it clear to the user where to connect the streams. In a distillation column, for example, it’s advisable to rename the outlet ports as Distillate and Bottom Product, rather than Prod2 and Prod3. This is not important for the mixer.
The default icon for all models generated in ACM is the flash vessel. It is possible to change this icon and design customized icons that reassemble the real equipment. Under the Contents of your model, there’s an option to Add Icon.
Once these minor modifications are done, right-click on the coding window and click on compile (sh. Compilation should be completed without any errors. Close the window containing the code. In the Model Explorer palette, click on the mixer model and drag it to the Process Flowsheet Window to add a mixer unit to the flowsheet.
A light-green square on the lower right part of the ACM window indicates that the degree of freedom is zero and the simulation is ready to be executed. It would show a red arrow pointing upwards if the model is overspecified and pointing downwards if it is underspecified. Run the model by clicking on the run button in the upper part of the screen. Check the results.
Exporting an ACM Model to Aspen Plus
Now the model is to be exported to Aspen Plus. For this example we are using Aspen Plus version 8.6. When simulating a unit in an Aspen Plus flowsheet, the inlet ports will be connected to streams. Streams in Aspen Plus already have a built-in function to calculate the enthalpy once pressure, composition, and temperature are specified. This means that there is no need to calculate the enthalpy of the inlet stream using a function anymore. Therefore, these lines must be commented by adding // or deleted from the ACM code. This can be done in the Model Palette/Models then selecting the highlighted icon under contents.
- ADD: HOW TO OPEN AND EDIT THE CODE. FEED info can be retained as initials
It is necessary to have a proper version of Microsoft Visual Studio installed in order to export the model. It is possible to export to DLL, in order to generate a .dll file which can be read by Aspen Plus as a unit operation. It is also possible to export to MSI, which will generate a .msi file that can later be used to install the .dll file.
In the Model Explorer right click on the model name and select EXPORT TO MSI. When asked “Do you want to install the model now?” click yes and follow the installation steps. Keep the default location for the file.
Once the file has been installed correctly, start a new Aspen Plus simulation file, select WATER and METHANOL as components and NRTL as property package. Run a property analysis and then enter the simulation environment. To enable the ACM models to be shown in the Model Palette, select the tab Customize and then Manage Libraries and then activate the ACM Models.
Add the customized mixer model to the flowsheet and repeat the simulation done in ACM. The results should be the same.