COMSOL introduction

From Interactive System for Ice sheet Simulation
Revision as of 16:16, 6 August 2009 by Chulbe (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Increasingly, modelers are utilizing higher level software packages for their work. By higher level, I mean that considerable software has already been written, and the modeler is customizing the existing software for their particular needs. Low level, by comparison, would be writing fortran 90 programs from scratch.

Examples of higher level tools

Many of you have used Matlab, and see the utility of letting someone else take care of basics like solving systems of linear equations and graphing results. Newer packages do even more for you, like setting up the system of linear equations to be solved for various classes of PDEs that the user defines. My hunch is that the sophistication and use of such software will increase in the next 10 years, and that it's wise to familiarize yourself with it. In a way, community models such as Glimmer are just high level tools with a very limited range of application.

One of the better ones I've used is called COMSOL multi-physics. In the words of Doug MacAyael, the software appears to be "pregnant with possibilities". I mostly agree, but would also be quick to point out that there are serious limitations that arise when using such a high level package. Easy things are easy, and some hard things are impossible. Hard things are probably what are needed for research problems. Nevertheless, there is enough to like that we're going to give this a try.

Getting started

Open the program and choose an application mode

Begin by opening the application. Do this with the commmand

/usr/local/comsol35a/bin/comsol -np 2

You should see a dialog box, asking you to tell COMSOL which application mode you want. Let's return to the now familiar convection-diffusion problem. Select a 1D problem, and conduct a steady state analysis. Leave the name of the dependent variable to c, but notice how you would do this, it is often helpful.

The initial dialog in COMSOL.

Finding what you need

You should now see the initial COMSOL screen. The first thing you need to do is find help. Then I won't have to type as much. From the Help menu, select the help desk. You should get a window to open in a web browser. This is how you learn COMSOL. In the help browser, select the User's Guide. Now, on the left panel select Diffusion, and then The Convection-Diffusion Application Mode. The discussion there is helpful back ground. Now, let's try and do something.

The initial screen in COMSOL 2D and 3D modes.

Creating the geometry

If you are doing 1D modeling, it's quite easy to create the model domain, or geometry. All you need to do is

  1. Make sure you are in draw mode, this is done by clicking the pencil on top of a blue triangle icon that is sixth from the right on the horizontal bar of icons across the top. Recognize that the interface is modal, meaning that you can do different things in different modes. eg, one creates geometry in the draw mode, one specifies physics in the sub-domain mode, etc. There is typically a dialog box associated with each mode.
  2. Select the line drawing tool. This is the second from the top in the leftmost vertical stack of icons. It looks like two red dots connected by a black line.
  3. Create a line from 0 to 1 by left clicking end points
  4. The domain will be off centered in the viewing window. Click the Zoom extents icon, seventh from the left on the top horizontal bar. It looks like a red coordinate axes with a small magnifying glass on it.

Specifying the physics

After the commonly used notation of \Omega for the domain, and \partial \Omega for the boundary, COMSOL marks two more important modes for specification of the field equations and boundary specification. Because we are in a fairly specific application mode, convection diffusion, there are limited choices for the specification of field equations and boundary conditions. Later that will change.

The field equations

  1. Open the Subdomains Settings... dialog from under the Physics menu.
  2. Select subdomain 1, the only subdomain you have specified for this problem.
  3. We want to solve a non-dimensional form of the convection-diffusion equation
\frac{\partial \phi}{\partial t} + u \phi -  \frac{\partial }{\partial x}\mathrm{Pe}^{-1} \frac{\partial }{\partial x} \phi = q

so, D in Comsol's dialog corresponds to \mathrm{Pe}^{-1} , the inverse of the Peclet number, the ratio of the velocity scale U times the length scale L to the diffusivity D,

 \mathrm{Pe} = \frac{UL}{D}.
  1. While still in the dialog for subdomain settings, set the u, or velocity to 1.

The boundary conditions

  1. Now open the Boundary Settings... dialog from under the Physics menu. Set the left boundary to "a", and the right boundary to "b". We will specify a and b in just a moment.

Constants and expressions

  1. Open the Options and then Constants... dialog. Specify a= .2, b=1, and Pe = 10.
  2. Open the Options and then Scalar Expressions... dialog. Specify that c_a(x), the analytic solution of the equation, is
 c_a(x) = a + (b-a)*\frac{\exp((x-1)\mathrm{Pe}) - \exp(\mathrm{-Pe})}{1-\exp(\mathrm{-Pe})}

note that Comsol allows you to use coordinate axes in formulas. Call this expression ca.

Create a mesh

To create a mesh for this problem, simply push the third icon from the right, the mesh mode icon. It looks like a circle with a tiny mesh in it.

Solve the problem

To solve the problem, press the icon with an equals on it.

Understanding the result

The result will be displayed on the screen. To see how accurate this result is, open the plot dialog (12th from right, it looks like a colored contour plot with a question mark on it). Under the Line tab, change things so that abs(c-ca) is now plotted.


You now know enough about the software that you can probably start exploring ways to reduce the error. Try getting the mesh to change. See how the error changes when the Peclet number changes. See if you can find how to use different basis functions, or elements. As you improve the solution, observe the number of degrees of freedom that is displayed in the lower left as you solve. The goal is always to obtain maximal accuracy with minimal degrees of freedom. See how you can do.