System Mass Balances in Excel

I’ve added some more material to the web site – solving mass balances for processes with recycle streams, using Comsol. In process simulators, one usually solves the equations by taking the input to a unit, solving that unit, taking the output and putting it into the next unit. If there are no recycle streams, you are done. If there are recycle streams, though, you do this over and over until the problem converges (it usually does). When using Comsol, however, you are writing algebraic equations like you would in Excel (i.e. like the formulas you’d put in the cells there). Then you must solve those algebraic equations, which are usually nonlinear. Sometimes that type of calculation does not converge, and you need to supply a reasonable guess to get a solution. You can see in the example when that was necessary for the problems solved. Go to the book web site, www. and look at Download or system mass balances.

Posted in Chemical engineering computing | Tagged | Leave a comment

How to solve CSTRs in Comsol

I’ve added some material to the web site – solving equations for Continuous Stirred Tank Reactors (CSTR) using Comsol. There are some things you have to be careful of when the parameters lead to multiple solutions or to no steady solutions at all. This material repeats, using Comsol, what is in the book on pages 161-168: steady CSTRs, transient CSTRs, and ones with weird oscillations. In the latter case one must adjust tolerances in the numerical integration, and the writeup shows how to do that. Here is one of the graphs that indicates a problem.Image

Posted in Chemical engineering computing | 1 Comment

For Beginners with Comsol and with Excel

If you are a new user of Comsol Multiphysics, there is a nifty way to work through the first example in the book. A pdf version of the first example in Chapter 9 (heat conduction) is available at You can download that and put it on the left side of your screen, and then open Comsol and put it on the right. Then just follow along the steps shown in the book, one by one.

Also, I’ve put up an expanded Appendix A, Excel. The second edition assumes that most users have used Excel before, but all haven’t. Thus the pdf version on the web site is an expanded one, like that in the first edition but redone for more modern versions of Excel. So that is a place to start if you are not a whiz with Excel.

Posted in Chemical engineering computing | Tagged | Leave a comment

New Resources Added to Website

I’ve added new resources to the website, There you will find Problem 9.26 worked. This is a problem to examine the proposition that if one has a transport problem with a large velocity (Peclet number) it is easier if one converts to gamma= exp(c). You can see there the amount of improvement.

Also available are the meshes for the gradient problem in 11.29. This is used for creating a concentration profile across a width. While the geometry isn’t hard to create, it is tedious, so I’ve done it for you. Also there is the mesh for the hole pressure problem (10.28) and the serpentine mixer (text in Ch. 10 and 11 and problems 10.26 and 11.24.

Posted in Chemical engineering computing | Tagged | Leave a comment

In the December 2nd blog, I talk about solving the algebraic equations in early chapters of the book using Comsol Multiphysics rather than just Excel, MATLAB, and AspenPlus. I’ve added some examples – another case of two simultaneous equations from Eq. 4.16 and a new one representing vapor-liquid equilibrium, Eq. (3.9), page 32, and the problem in Figure 2.1, page 14. Next up: Chapters 5 and 6.

Posted in Chemical engineering computing | Tagged , , , , , | 2 Comments

More on Solving Algebraic Equations in Comsol Multiphysics

In the December 2nd blog, I talk about solving the algebraic equations in early chapters of the book using Comsol Multiphysics rather than just Excel, MATLAB, and AspenPlus. I’ve added some examples – another case of two simultaneous equations from Eq. 4.16 and a new one representing vapor-liquid equilibrium, Eq. (3.9), page 32. Next up: Chapters 2, 5, and 6.

Posted in Chemical engineering computing | Leave a comment

Solving algebraic equations with Comsol

On the website, I have added a link to a pdf document that shows how to set up a simple problem of transient heat transfer in a sphere. A reader asked me details about doing this in 1D (where you have to add the (2/r)(dT/dr) term to the equation) and in 3D.

At the Comsol Multiphysics meeting in Boston in October, I heard a talk for a Minicourse entitled “Equation Based Modeling”. It described, among other things, how to solve algebraic equations in Comsol. The way the problem was stated was to solve a problem in the context of another simulation of a 2D transport problem, even though the 2D transport problem was not used. The example solved for the specific volume of a gas using the cubic equation that comes from various methods: Redlich-Kwong, Peng-Robinson, etc. I got to thinking: Could I solve all the algebraic problems in my book using Comsol? I would want to solve them by themselves, not inside a transport problem: Why solve a PDE if you only want to solve a nonlinear algebraic equations?

So I tried it and it works using the 0D option and Global ODEs. When I first did it, though, it got a funny solution. Eventually I realized that the problem I was solving had two solutions, one of which was physically meaningless, and for the initial guess I had chosen the method converged to the wrong solution. I had never seen that solution before so I thought Comsol was not working correctly for a single nonlinear algebraic equation. Upon further reflection I realized my mistake, which again emphasizes the point of the book: check your work carefully. In this case, the program worked, but it gave a solution that I didn’t want and I had to figure out how to prevent that.

Thus, you do have to be careful. I will be posting a pdf file of that problem soon ( and show how to examine the results to get the correct solution. As time permits, I will prepare the Comsol instructions to solve a typical problem from Chapters 2, 3, 4, 5, and 6. It already solves problems in Chapters 8-11. Chapter 7 (Aspen process simulation) involves so much thermodynamic data and specialized methods that it isn’t practical to use Comsol there. But, being able to solve most of the problems in chapters 2-6, 8-11 is a pretty good percentage!  So, take a look at them as they are added to the book website:

Posted in Chemical engineering computing | Leave a comment

Hints for using MATLAB

What do I do first? BE A DETECTIVE!

1. Try the command: help commandname (replacing commandname with the subroutine or subprogram you are trying to use).

2. Next, remove the ; from your statements and verify that each step in the calculation is correct.

3. Check that your path is correct (use the set path command or menu item), so that MATLAB can look at the files you want it to.

4. Use clear all to eliminate all traces of variables stored in memory. Sometimes somethingstored there is wrong for your problem (like an extra element in a vector), and was put there in a prior calculation.

How do I check for errors?

1. Remove the ; from your statements and verify that each step in the calculation is correct.

2. Issue the command disp(x) to see the value of x, or just say x; do this in the command window, or for a variable only in a subroutine, do it in the subroutine.

3. ???Undefined function or variable ‘q’. When you see this, Matlab is saying it doesn’t have a value for q. Do step 2. If q is in a subroutine, it has to get in there in one of three ways: (a) as a global variable, defined as global in the calling program (or command window) and the subroutine; (b) set in the subroutine (use step 2 to examine); (c) from the calling arguments (only if it is an independent or dependent variable.

What if the matrices are not the right shape.We can always find the shape of a vector/matrix with

size (u)

If u is a matrix with 544 rows and 3 columns, size(u) would give [544 3]. If you want to access a whole row, you can use u(:,1), for example.

How can I calculate with matrices?

Suppose we wanted to post-process u. If u(:,3) is T (K) we might want it in C.

u3 = u(:,3) – 273.

This will create a vector u3(i), i=1,…,nlength in which every entry is the value of u(i,3) minus 273. u(:,3) would have nlength entries.

If we wanted u(:,1)/u(:,3), though, we would use

u4 = u(:,1) . / u(:,3)

(Yes, that is a period then divide.) The . / means divide every element of u(:,1) by the element of u(:,3) and make an element of u4(:). You may have to experiment with this since the syntax is not always clear in Matlab. Create vectors/matrices of the appropriate sizes and try your expressions with them.

How can I get rows out of a matrix?

If we have run ode45 to get the result

[t,u] = ode45(…)

where there are 2 or more variables u, we may want to plot them separately. We can transfer them to a vector:

u1 = u(:,1)

u2 = u(:,2)

u3 = u(:,3)

and plot(t,u1,,’r’,t,u3,’b’)

(This is useful if some of the variables are molar flows and some are T or p.) We could also use:


to do the same thing.

Posted in Chemical engineering computing | Leave a comment

Guidelines for CFD work and reports

Here are some suggestions for what a report using computational fluid dynamics (CFD) should include:
A.    Describe the problem in prose.
B.    This is a checklist of items to be written down:

  1. Equations solved, and values of any parameters in the equations;
  2. Geometry, including dimensions;
  3. Boundary conditions on all boundaries, including any parameter values;
  4. Mesh information, at first the number of elements and degrees of freedom, and the final report should include at least one plot of the mesh.

C.    Examine your results carefully.

  1. Plot lots of things;
  2. Look for oscillations (bad) and funny things;
  3. Do hand calculations of a simple case using standard formulas;
  4. Do at least some mesh refinement.

D.    Present results in tables, contour and surface plots, and line plots.
E.    What have you learned? Recommendations for improved solutions or new information.

Posted in Chemical engineering computing | 1 Comment

More information about the second edition

The book now has a website with lots of information (– some things that go beyond the book and give additional theory:

shortcut distillation,

links for energy problems in Aspen,

theory and simplifications for laminar diffusion fluid interfaces,

parameter estimation using Excel and MATLAB,

why there is a mesh size limitation if the velocity is high,

information on numerical methods, Gear, RKF45, MacCormack with flux correction.

In addition, the preface, Chapter 1 (general info), and table of contents are there. There is a section of Problem Objectives which helps instructors choose problems that illustrate specific points.

An index is provided to undergraduate research projects that have been done under my direction – over 100 of them during the 2002-2009 time period. You can look at them by subject, or by a timeline. The timeline is interesting because it shows how computing has advanced during that period (not that I expect you to read them all!). I’ve constantly found that students are creative if given the tools, and sometimes they will do things that I wouldn’t do, but they succeed. Thus, they taught me a lot during this time.

See it all at

Comsol wrote a very nice blog about my the new edition – see it at:

Mathworks, the maker of MATLAB, has a site, too, about it:

What would you like to see on the website? Let me know.

Posted in Chemical engineering computing | Leave a comment