Home > COMSOL 

Introduction to COMSOL - numerical simulation using the finite element method

Screen captures and word processing in the 239 EBU2 lab 

Specifiying constants and expressions
 See this report for examples of specifying the values of constants and variable expressions. Specifically, see Figs. 4-11.
Constants:  Let's say you have a constant value, e.g., a reference temperature, that will appear several places in the model. Under the Options menu, select Constants. Then define the constant (see Figs. 4 and 5 of the report), e.g., To = 273.15. Later, when you are need to supply the reference temperature, instead of typing 273.15 every time, you just type To. 
Expressions: In other places, you may need to enter in several places the value of an expression whose value will change as the primary variables change. Instead of typing that equation everywhere you need it, define a variable to be equal to that equation. For example, for an expression which is used in a subdomain (as opposed to a boundary), go to Options menu and select Subdomain Expressions. See Fig. 6 in the report for an example of specifying a subdomain expression for reaction rate in the fluid Rf. Elsewhere, whenever you need the local value of the reaction rate, you just type Rf.

Setup for laminar flow in long-thin tube

Getting started with COMSOL 

Comsol is a Finite-Element Method (FEM) model builder and solver. You can use it to solve "multiphysics" problems, i.e., those involving coupled material, energy, momentum transport. This page is the equivalent of a "hello world" program in Comsol. It only shows a zillionth of the program's capabilities.

You can access Comsol in the 239 EBU2 lab. Restart the PC, select the Linux operating system in the first screen, pick the first Linux in the next screen, then log into your MAE 221A course account on the server ieng6.ucsd.edu.

You can find your MAE 221A course account info using the Account Lookup Tool at http://sdacs.ucsd.edu/~icc/

After you log in to your account, open a terminal window: click Redhat icon in upper-left corner, select Accessories, select Terminal (in the past it was at lower-left corner and System Tools).

In the terminal window, first enter "prep comsol" without the quotes, ignore the line "finished: label not found." and then enter "comsol" at the next prompt. You must leave the Terminal window open while you use COMSOL. If you close it, then COMSOL quits.

When Comsol starts up, you first see the Model Navigator window. You can select from example models (Model Library), your old models (User Models) or you can create a new model at the New tab. In addition to the basic COMSOL multiphysics model templates, we also have available the Chemical Engineering Module templates. The Chem E templates have common combinations of multiphysics problems combined into template, e.g., combined fluid flow and heat transfer. For this example, I have selected the Conduction template.



After clicking OK, the model window opens. I clicked on the rectangle icon in the list of geometric shapes to the left of the drawing area, then clicked in the drawing area and drew a rectangle. We are just trying to get a model up and running here, so I'm not going to worry about dimensions, units and other "details".

You can make more complicated shapes by using the other drawing tools and combining shapes. You can model fluid-surface interactions by specifying boundary conditions at surfaces joining two shapes. You can import shapes from CAD programs.



Now, click on the rectangle to select it, then select "Subdomain Settings" under the "Physics" menu. The rectangle is a "subdomain."  As an alternative to using the Physics menu, you can simply double-click on the rectangle to open the subdomain settings window. However, at least on my system, you have to double-click very fast to get this to work.



The subdomain property window will open. For now, I just accept all the default properties. So far, we have specified the geometry of our system and have essentially "written" the governing equations (well, the equations were written by Comsol and we just picked them).



In these property windows, you can click OK to apply the settings and close the window. Or, you can click Apply button to apply the settings and leave the window open - you would do this if you want to solve the model, then make a change in a property, then solve it again, etc.

Now, select "Boundary Settings" under the "Physics" menu so we can specify the boundary conditions for the system equations. Our rectangle (subdomain) has four boundaries, which are listed by number in the "Boundary selection" list. Below I have selected boundary 1 (left side), and then clicked the menu button to the right of "Boundary condition" and selected a condition of a specified temperature, and finally entered a T of 300 K at the bottom.



Insulation (zero-flux) conditions were selected for boundaries 2 and 3 (top and bottom sides). For boundary 4 (right side), I selected constant heat flux, and entered a flux q of 1.



Now, click the triangle icon under the Mesh menu (or open the Mesh menu to make more detailed mesh selections). Comsol then draws a finite-element mesh inside the subdomain.



Now, we are ready to solve the model. Click the = icon under the "Postprocessing" menu (or select the Solve menu to specify solution conditions). A window showing the solution progress opens.

The solution converges for this simple problem. However, as models get more complex, you may find that you don't always get a converged solution. You then have to double-check your model, and may have to make changes, such as increase the mesh resolution in some regions of the subdomain, etc. To do this, you are going to have to read the Comsol documentation and help files.

Here is our solution shown in terms of a color surface plot showing the temperature distribution. Note that the maximum T is only 1 mK above that of the constant-T surface. I could have specified a higher heat flux on the right boundary to get a higher max T but why bother, since the dimensionless T field and, thus, the color plot wouldn't change.




You can change which variables are displayed and how they are displayed by choosing "plot parameters" under the "Postprocessing" menu.



I added contour lines of T to the T surface color plot.



So far, we have just used one "physics" mode, that of heat transfer. We can also build "multiphysics" models that combine modes such as combining fluid flow and heat transfer.  Cick on the blank page in the upper-left of the model window, select new model, and the Model Navigator window opens again.

In the Model Navigator window, first select steady-state incompressible Navier-Stokes flow under Fluid Dynamics. Then I click the "Multiphysics" button (just above OK, Cancel). Then select steady-state convection and conduction under Heat Transfer. Then click the "Add" button, then finally the OK button.




As before, I draw a rectangle. Before I open the subdomain and boundary properties windows, I go to the "Multiphysics" menu and select which mode for which I want to set properties.



Then I specified settings for flow of fluid at a specified temperature in through the left boundary, an insulated surface at the top boundary, and a specified heat flux at the bottom boundary. Here are the solutions: first the velocity field and second the temperature field. Enjoy using Comsol!