Chemical Process Simulation Using OpenModelica

self-archived


INTRODUCTION
Material and energy-balance computation of process plants helps in auditing of resource utilization. This in turn results not only in cost and energy savings but also helps in decreasing the load on the environment. If only the thousands of small-and medium-scale chemical plants carry out just material and energy-balance calculations, there can be substantial savings and also less damage to the environment. This is especially true in developing countries, which also suffer from a lack of quality work force. Making available affordable simulators and training a large number of engineers capable of using the simulators is one way to address this issue.
Modern technology is one way to address the issue raised above. Millennials are comfortable with the social media. They are not scared of working with like-minded people at distributed locations. New technologies have also shown that it is possible for experts to share their knowledge with thousands who are hungry for it. Projects like Wikipedia have shown that it is possible to produce useful content through collaborative crowdsourcing. The fact that this can work in the field of chemical engineering is already demonstrated by the collaborative work on the open-source steady-state process simulator DWSIM, 1 which has helped produce more than 100 flowsheets. 2 In the current work, an effort to extend the flowsheeting capability of the general-purpose object-oriented simulation environment OpenModelica 3 is described. OpenModelica is based on the Modelica language, 4,5 which enforces equationoriented simulation strategy. 6 It incorporates many of the recommendations of Piela et al. 7 In particular, it helps maintain models and solvers. OpenModelica is also suitable for studying dynamics, required in the analysis of continuous processes, and also batch processes that are prevalent in thousands of small chemical plants. As it is an open-source software, OpenModelica can be used by large numbers of students and small-and mediumscale chemical companies. This paper is organized as follows. Section 2 explains some features of OpenModelica that make it a suitable candidate for process simulation. A brief outline of models of unit operations created in OpenModelica is presented in Section 3. A few typical flowsheets are also solved in that section, with a comparison of results with Aspen Plus. Section 4 is devoted to conclusions and future work.

OPENMODELICA FOR PROCESS SIMULATION
As a first step in building research communities in the area of simulation, the authors undertook an exercise of crowdsourcing steady-state flowsheets. This has resulted in more than 100 DWSIM flowsheets and a conference. 8 Each of these flowsheets solves a chemical process using DWSIM and compares the results with the literature or a commercial process simulator. All the flowsheets are released under the Creative Commons Attribution Share Alike (CC-BY-SA) license. 2 The focus of the work in this article is to make available a versatile process-simulation environment that is capable of carrying out both steady-state simulations and dynamic simulations for the process industry. It should be open-source so as to benefit large numbers of researchers and small-scale manufacturing units. OpenModelica 3 is a candidate simulation environment for the above task. If successful, an attempt will be made to migrate at least some of the above-mentioned DWSIM flowsheets to OpenModelica and then explore introducing dynamic models in them.
This section summarizes the capabilities of OpenModelica from the point of view of relevance to process simulation.
2.1. Motivation To Use Modelica and OpenModelica. As mentioned earlier, the main focus of this work is to create a chemical engineering library in Modelica and to demonstrate its use by creating reasonable flowsheets. One important reason for this attempt is that Modelica is suitable for both steady-state and dynamic simulations.
The other reason to pursue Modelica is that it enables the separation of concerns, as propounded by Piela et al., 7 through a declarative modeling framework, combined with the equation oriented solution technique. 6 Here, separation refers to keeping modeling and solutions separate from each other. This approach allows modeling teams to articulate their models well, without worrying about the solution technique. At the solution stage, one can use the appropriate solvers, without worrying about the underlying modeling assumptions. This separation of concerns makes maintenance of models and solvers more tractable compared with in the systems wherein modeling and solutions are intertwined.
The Modelica modeling language is a nonproprietary, objectoriented, equation-based language for modeling physical systems consisting of components from different disciplines. 4,5 The Modelica Association ensures that the Modelica language is maintained and constantly improved. The Modelica standard library contains 1600 model components and 1350 functions from many domains. The Modelica language has been used in industry since 2000. There have been more than 10 biennial Modelica Conferences, attended by a large number of users of the Modelica language. There are about 10 commercial implementations of the Modelica language, which shows that the Modelica approach is popular in industry.
OpenModelica is an open-source implementation of the Modelica language 3 by a consortium of more than 50 members. It has a good set of solvers for different kinds of mathematical systems: algebraic, differential, and differential−algebraic. It comes with an OMEdit graphical interface, interactive DrModelica course material, and a cloud version (namely, OMWebbook). There are    also many self-teaching Spoken Tutorials and workshop campaigns to teach OpenModelica. 9,10 OpenModelica comes with a very useful debugger. It can provide model-level debugging, indicating at which model equation the problem has occurred, and it can provide the incidence matrix of the system that is being solved. At compile time, it can point out whether the number of variables is correctly, over, or under specified.
OpenModelica Compiler (OMC) translates Modelica to C code, with a symbol table having definitions of variables, functions, and classes. These definitions can be predefined, userdefined, or taken from libraries. A Modelica interpreter for interactive usage and constant expression evaluation is also a part of the OMC. The OMC produces executable code incorporating required numerical solvers. What is shipped as OpenModelica is presented schematically in Figure 1. 11 OpenModelica comes with 75 libraries in diverse fields, such as hydraulics, power-system simulation, motorcycle dynamics, servomechanisms, and thermal power, with about 1000 models. There are also efforts to make it suitable for handling large systems upward of 750 000 equations. 12 The objective of the current work is to include models of unit operations in OpenModelica and make it useful for process simulation. Property data and thermodynamic correlations have already been ported to OpenModelica by the authors. 13 Some features of OpenModelica that are useful for carrying out simulations will be discussed next.
2.2. Semibatch Steam Distillation of a Binary Organic Mixture. The capability of OpenModelica to simulate the semibatch steam distillation of a binary mixture consisting of n-octane (compound 1) and n-decane (compound 2) is demonstrated in this section. 14 This semibatch system has two phases of operation, namely, heating and distillation phases. In the heating phase, the binary mixture is taken into a vessel, and steam is bubbled into it continuously until the boiling point is reached (see Figure 2).
The system is modeled by the following equations, wherein subscripts 1 and 2 refer to the two organic compounds, w refers to water, s refers to steam, and a refers to ambient. We begin with the mass balance: The energy-balance equation is given by Equilibrium relations are given by Raoult's law: For an explanation of variables, the reader is referred to Shacham et al. 14 The heating phase continues until the sum of vapor mole fractions becomes 1 (i.e., f(T) = 1 − (y 1 + y 2 + y w ) = 0). After this point, the distillation phase starts. Let V be the flow rate of vapor that includes organic compounds and water. The model equations are given next: From the energy balance, the vapor flow rate is determined thus:

Article
The reader is referred to Shacham et al. 14 for a more detailed explanation.
An implementation of this system in OpenModelica is given in Figure 3. Required property values as suggested by Shacham et al. 14 are calculated in the code given in Figure 4. Note that both of these are presented as models. The former extends the latter. This results in equations given in both getting appended and being solved simultaneously, thereby enabling a true equation-oriented-solution approach. It is a practice in Open-Modelica to enclose the models discussed here within a package construct, as shown below, with the order in which the two models appear being immaterial: Once a package is invoked in OpenModelica, all models present within it get instantiated. When the model in Figure 3 is invoked with a simulation time of 30 min, the profiles presented below are obtained.
The code given in Figure 3 gives the values of various variables used in this specific simulation. These are identical to the ones used by Shacham et al. 14 When the simulation starts, fT = 0, and hence the heating-phase model that starts in line 25 of Figure 3 gets invoked. This variable subsequently gets redefined in line 26. When distillation starts, this variable becomes 0, and the distillation phase begins. In this declarative framework, it is easy to see the correspondence between the code and the model equations presented earlier.    In order to briefly explain the way one models in OpenModelica, a distilled version of the required code is presented here, using the correlations given by Shacham et al. 14 In general, one makes use of property databases, such as Chemsep, and thermodynamic correlations, as explained by the authors. 13 To complete the picture, a knocked-down version of the code, with the minimal required property database and thermodynamic calculations, is given in the Appendix. Although it may appear imposing, it is to be noted that one has to write the code given in lines 105−145 only, as all other calculations will be taken care of by the freely accessible thermodynamic libraries. 15 2.3. Switching between Steady-State and Dynamic Simulations. As explained earlier, the objective of this work is to create a simulation environment suitable for steady-state and dynamic simulation of chemical processes. In general, only the hold-up equations need to be changed when one goes from steady-state to dynamic models. A modeling environment that provides this capability will reduce the efforts required to do these simulations. The fact that OpenModelica meets this requirement through the parameter statement is the topic of discussion in this section.
Consider the simple tank shown in Figure 6, wherein a fluid of constant density flows in and flows out into a tank of uniform cross-section A. The outflow rate is proportional to the square root of the height of the liquid in the tank. It is desired to solve this system and determine the value of h(t).
The dynamics of this system are described by the following equations: The steady-state model of this system is given by The second equation is identical in both models.
This problem is coded in OpenModelica as given in Figure 7. The code is self-explanatory. The following values were chosen with appropriate units: F i = 16, A = 3, and x = 8.
When this code is executed through the OpenModelica GUI, an interface, as given in Figure 8, appears. Depending on the value assigned to the Boolean parameter dynamic, either the steady-state model is solved or the dynamic model is integrated. Assigning a value to this parameter is done at the compile Figure 10. Building block required to model the system given in Figure 9. It is arrived at by including connection details and a variable for h 2 − h 1 in the code of Figure 7. Figure 11. Code that, along with the code given in Figure 10, helps model the system given in Figure 9. Evolution of the heights of the two-tank system described in Figure 9.  The ability of switching the model outside the model definition may help extend OpenModelica to carry out batch process simulation, a topic currently investigated.

Industrial & Engineering Chemistry Research
2.4. Connection of Building Blocks. Connecting unit models in OpenModelica is extremely simple. In this section, two of the tanks described previously are connected and simulated. A schematic of this arrangement is given in Figure 9 The building block of this system is the tank discussed earlier, with a modification to account for the fact that we would want to connect it with the outside world. A model of the code is given in Figure 10. The required two-tank system is obtained by instantiating this model twice and connecting them, as shown in Figure 11. The resulting profiles are given in Figure 12

Chemical Engineering Models in OpenModelica.
Although OpenModelica comes with a large collection of models from many domains, a chemical-engineering library is nonexistent, with the exception of refrigeration systems. An attempt is made in this work to overcome this shortcoming. As mentioned earlier, property databases and thermodynamic correlations have already been made available in OpenModelica. 13 Material streams and unit operations are two types of models created in this work and released to the community. 15 Materialstream models do the separation into different phases and connect them to appropriate ports of unit operations. The input and output variables specific to the unit operation are defined in the respective unit operation models developed in OpenModelica. The unit operation library essentially has all equations that describe the process model for every unit operation. Additionally, the connector equations that are used to connect the inlet and outlet ports of the unit operations with its variables are also defined.
A few sample flowsheets will be presented next.

Design Problem of a Steady-State
Flash. The steady-state flash simulation of a methanol−ethanol−water system is presented in this section. The output composition of the vapor product is fixed, whereas the operating temperature of the flash column is a free variable. The feed temperature is also not specified, whereas the flow rate and the composition are fixed. Pressure is kept constant at 1 atm. Because the objective is to determine the temperature at which the flash column operates and at which the feed enters, it is a design problem (see Figure 13).
It is desired to calculate all other variables for three different values of the methanol mole fraction, y 1 . In other words, vapor compositions of ethanol and water, the temperatures of all streams, and all flow rates need to be calculated. The schematic of the problem statement is presented in Figure 13. The UNIQUAC  The code in Figure 14 depicts the flash example as developed in OpenModelica. It inherits thermodynamic correlations and implements the well-known flash algorithm. The simulation is run for three different desired vapor compositions of methanol. The minimum and maximum temperatures were taken to be the boiling points of pure methanol and water, and the initial guess for temperature was taken to be the average of these two boiling points.
Results of these calculations are presented in Table 1. One can see that these results are consistent with the general requirement that the higher the mole fraction of the least volatile component, the lower the temperature. The human effort to solve the system remains the same no matter which variable is to be solved. In a sequential modular approach; 6 however, one has to resort to a trial and error method, depending on which variable is the unknown.
3.3. Methanol−Water Distillation. In this section, a methanol−water distillation system with a preheater is studied. The schematic for the flowsheet is displayed in Figure 15. A material stream containing 36% methanol (by mole) and 64% water at 300 K and 1 atm of pressure is sent to a preheater at 60 mol/s. The feed is preheated to 325.15 K before entering the distillation column.
The feed is sent to the distillation column at the ninth stage. The condenser and reboiler pressures are maintained at 1 atm. A reflux ratio of 1.12 is defined as the top specification and a product molar flow rate of 38.4 mol/s is defined as the bottom specification. Methanol with 99% purity is obtained from the top at a temperature of 338 K. Water with 99.45% purity is obtained from the bottom at 372.75 K and is used to preheat the feed.
The streamwise results obtained from the simulated flowsheet are presented in Table 2 and are compared with the DWSIM and Aspen Plus results. It can be observed that the OpenModelica results closely match those of DWSIM and Aspen Plus.
3.4. Ethylene Glycol Production. The next example demonstrates the production of ethylene glycol (EG) from ethylene oxide (EO) and water. The schematic for the flowsheet is displayed in Figure 16. Two streams of pure ethylene oxide at 20 mol/s, 395 K, and pure water at 80 mol/s, 385 K, enter a stream mixer. The mixed output stream is used as the feed to the plug flow reactor. The following reaction takes place in the plug flow reactor: The reaction kinetics is taken as −r A = 0.005 C C 2 H 4 O for the sake of brevity. The reaction is first-order with respect to ethylene oxide.
In the reactor, 42% conversion of ethylene oxide takes place. Ethylene glycol is formed as the product. Ethylene glycol, along with unreacted reactants, are cooled and sent to a distillation column with eight stages for further purification. The feed enters at the fifth stage of the distillation column. The condenser and reboiler pressure are maintained at 1 atm.
A reflux ratio of 2 and a product molar flow rate of 10 mol/s are defined as the top and bottom specifications, respectively; 84% ethylene glycol is obtained as the bottom product.
The streamwise results obtained from the simulated flowsheet are presented in Table 3 and are compared with the DWSIM and Aspen Plus results. It can be observed that the OpenModelica results closely match those of DWSIM and Aspen Plus.
3.5. Esterification of Acetic Acid To Produce Ethyl Acetate. In this section, production of ethyl acetate from acetic acid using an esterification reaction, as given in Figure 17, is studied. Ethanol (EtOH) at 60 mol/s is mixed with acetic acid (HAc) at 40 mol/s and fed to a conversion reactor. They both enter at 300 K and 1 atm of pressure. The following reaction takes place in the conversion reactor: The outlet temperature of the reactor is maintained at 300 K, and 60% conversion is defined for the acetic acid in the conversion reactor. Ethyl acetate (EtAc) and water are formed as Table 3. Streamwise Results of Ethylene Glycol Production in OpenModelica, DWSIM, and Aspen Plus

Industrial & Engineering Chemistry Research
Article products. Unreacted acetic acid and ethanol are also present in the product stream; 75% of the product stream is recycled back to the mixer, and the rest is sent out for further processing. The NRTL thermodynamic package is used to simulate the flowsheet.
The streamwise results obtained from the simulated flowsheet are presented in Table 4 and are compared with the DWSIM and Aspen Plus results. It can be observed that the OpenModelica results closely match those of DWSIM and Aspen Plus.

CONCLUSIONS AND FUTURE WORK
The use of OpenModelica is proposed for chemical-process simulations. Some useful features for this purpose have been identified. These are (a) the short development times required for model development, (b) the reusability of the code, (c) the ability to easily connect different building blocks of a flowsheet, and (d) the ability to switch from a steady-state simulation to a dynamic simulation at the compile time.
A library of streams and unit operations has been created to make OpenModelica suitable for process simulations. Using this library, a few representative flowsheets have been solved and the results validated with those from DWSIM and Aspen Plus. The usefulness of the equation-oriented approach used in OpenModelica is verified with the help of a design problem. Semibatch steam-distillation has also been simulated, and the results are matched with literature findings.
The benefits of using OpenModelica for process simulation are manifold. It can be used to carry out dynamic simulations, and training students to use OpenModelica will raise the overall levels of education, as the use of any equation-oriented simulator requires high skills. Finally, the large number of students proposed to be trained to use OpenModelica will be available as a work force for researchers around the world.
With the above objectives in mind, the authors are embarking on OpenModelica promotion in a big way. In addition to training a large number of people, this will also result in increasing the number of examples worked out in Open-Modelica, which in turn will increase the usability of the software itself.
The following activities are proposed to be undertaken in the near future: (1) migrate more DWSIM flowsheets 2 and make them available to the community, 16 (2) create more process models for OpenModelica, (3) make the property data of more chemicals available in OpenModelica, (4) train a large number of students on the use of OpenModelica and offer them to smalland medium-scale industry, and (5) create more collaborative content for OpenModelica through activities such as Textbook Companion. 17

■ APPENDIX
The following is the OpenModelica Code for semibatch steam distillation.

Industrial & Engineering Chemistry Research
Article