# 7. Connecting CHEMCAD to a Machine Learning Model on the Wolfram Cloud

## Description

We previuosly provided examples of connecting Mathematica to CHEMCAD or Aspen Plus. In References 1-3, we showed how to connect CHEMCAD to Mathematica using Link for Excel, with all software running locally on the desktop computer. References 4 and 5 explain how to deploy Mathematica models to the cloud. Once deployed to the cloud, functions can be accessed over the internet from Excel, which in turn is connected to CHEMCAD through data mapping. Reference 6 extends the procedure to Aspen Plus. This data set further extends the study to supervised machine learning models. As an example problem, we chose a membrane model for an air separation process [7-8]. The membrane unit is well-mixed on the retentate and permeate sides of the membrane. The feed to the membrane unit is fully specified and split by the membrane into retentate and permeate streams. There are many ways to develop a machine-learning model for this problem, and five different methods are provided here, described below. Method 1 (Proof of concept): Supervised learning with single variable linear regression applied separately to each output. The method in Mathematica uses the “Predict” function, which accepts a list of associations between one input and one output. For example, {{a1➝b1}, {a2➝b2}, etc.}. Because of this input-output structure, “Predict” was used five times to generate five output functions, one for each output. Only one input was varied, the others being held constant, as shown here, with only area changing. For example, for output x1 (retentate mole fraction), the input-output structure changes as follows: {{nF1, PR1, PR1, A1} ➝ x1}, {nF2, PR2, PR2, A2} ➝ x2}, etc.} ⇨ {{A1 ➝ x1}, {A2 ➝ x2}, etc.} This creates the input-output structure needed by “Predict.” We used the model in Ref. 5 to generate a table of data that was then entered into Mathematica to train the model. The training data are provided in the Excel data map worksheet. The trained functions were then deployed to the cloud and called from CHEMCAD. The model is not very flexible because the feed flow rate, retentate, and permeate pressures are fixed. However, the results are interesting because a wide range of AI and machine learning tools are available in the Wolfram language that could extend this technique to more general situations. Neural Net Methods: Method 2: More general model than Method 1. Neural net trained with 1000 simulations generated from the model of Reference 3. All input variables simultaneously generated from random number generators, set to the range of values tabulated below. The trained neural net is called locally from CHEMCAD with Link. Input Min Max nF 3,300 3,400 PR 140 160 PP 14 16 A 18,000 22,000 Method 3: Same as Method 2 but trained with 5000 simulations. Method 4: Same as Method 2, trained with 1000 simulations, but with result deployed to cloud.\ Method 5: Same as Method 4, trained with 5000 simulations, with result deployed to cloud.

## Files

## Steps to reproduce

We took the following steps to verify that the software connectivity, data maps, and calculations are working correctly. The work was verified by replicating a published example problem [7,8], achieving the exact same answers as in the published solutions. We also had each contributor download the files and follow the procedure in the instructions file to make sure the guidance is correct. Problem statement[7,8]: Air containing only nitrogen and oxygen is continuously separated into a nitrogen-enriched retentate stream and an oxygen-enriched permeate stream by gas permeation through a low-density polyethylene membrane. The membrane is in the form of a thin-film composite with a 0.2-μm-thick membrane skin. A total of 20,000 SCFM of clean dry air with composition 79 mol% nitrogen and 21 mole% oxygen at 150 psia and 78 degrees F is sent to the separator. The solubilities and diffusivities of nitrogen and oxygen are taken from Table 14.6 in Reference 5. The material balance and molar flux equation are used to calculate the retentate and permeate flow rates and mole fractions given the membrane area and system pressures. Pressures of 150 psia on the retentate side and 15 psia on the permeate side are assumed, with perfect mixing on both sides of the membrane, such that compositions on both sides are uniform and equal to exit compositions. A function giving the permeate cut (moles in the permeate divided by moles in the feed) is also determined. Pressure drops and any mass transfer resistances external to the membrane are neglected. References [1] Biaglow, Andrew; Cowart, Sam; Yuk, Simuck; James, Corey; Nagelli, Enoch (2024), “1. Simple Flash Unit in Mathematica Linked to CHEMCAD,” Mendeley Data, V1, doi: 10.17632/smzy2998df.1. [2] Biaglow, Andrew; Cowart, Sam; James, Corey; Nagelli, Enoch; Yuk, Simuck (2024), “2. Simple Membrane Unit in Mathematica Linked to CHEMCAD,” Mendeley Data, V1, doi: 10.17632/cdcgbsrrhc.1. [3] Biaglow, Andrew; Cowart, Sam; Yuk, Simuck; Nagelli, Enoch; James, Corey (2024), “3. Improved Membrane Unit in Mathematica Linked to CHEMCAD,” Mendeley Data, V1, doi: 10.17632/nz7p8bhhs3.1. [4] Biaglow, Andrew; Yuk, Simuck; James, Corey; Nagelli, Enoch; Cowart, Sam (2024), “4. Connecting CHEMCAD to the Wolfram Cloud for Flash Calculations,” Mendeley Data, V1, doi: 10.17632/3b8n72m28v.1. [5] Biaglow, Andrew; Yuk, Simuck; James, Corey; Nagelli, Enoch; Cowart, Sam (2024), “5. Connecting CHEMCAD to the Wolfram Cloud for Membrane Calculations,” Mendeley Data, V1, doi: 10.17632/6gw5m5d7pn.1 [6] Biaglow, Andrew (2024), “6. Connecting Aspen Plus to the Wolfram Cloud for Flash Calculations,” Mendeley Data, V1, doi: 10.17632/fhwzyk3n6g.1. [7] Seader, J.D.; Henley, E.J.; Roper, D.K.; Separation Process Principles, New York: Wiley, 2011, pp. 518-519. [8] Peters, M.S; Timmerhaus, K.D.; West, R.E.; Plant Design and Economics for Chemical Engineers, 5th Edition, New York, New York: McGraw-Hill, 2003, pp. 822-824.