You are on page 1of 7

CEE-268 Winter 2006 Introduction to Finite Element Modeling & COMSOL By Michael Cardiff Tips and Tricks What

t to do when your problem isnt solving correctly Background: Why does COMSOL hate me? In all of the previous example problems the instructions have been written such that when you solve the problem it will converge! But except for relatively simple problems (or sample problems that have been tested already by your very nice professor!), getting a model you have created to converge to a solution that looks correct may take a lot of time and effort. This can be a tedious, slow process and much like debugging code can lead to a lot of frustration. It is the hope of the author that the tips and tricks below will help to minimize these annoyances. If all of the below suggestions fail

relax, go get a cup of tea, and take a break from staring at your model!
this is often the best advice of all. What causes errors? A problem that will not run, will not converge, or gives an incorrectlooking solution may be caused by many different types of problems. When trying to debug a code or a model, it often helps to have a very structured approach for finding the error. With this in mind, lets divide the type of errors that may occur into several key areas. They are, in rough order of probability : User Error o General syntax errors o Boundary conditions or Subdomain settings not correctly defined o Direction of elevation not specified (and hence no gravity) o Multiphysics equations not linked correctly o Unreasonable initial conditions Solver Errors o Solver Tolerance not set low enough o Maximum # of Iterations reached

o Problem is Highly Nonlinear o Problem cannot be solved by the selected algorithm o Mesh is not fine enough in important areas COMSOL Error o Bug in COMSOL module or material definitions o Formula used by COMSOL is not correct or not general enough

Common User Errors (& how to fix them) Simple Typos The easiest-to-correct (and most common) errors are those that simply involve a typing mistake on the part of the user. If youve defined constants or variables in your problem, make sure you have entered these constants / variables correctly in any field where you use them. Errors relating to simple typos generally look something like those in Figure 1.

Figure 1: Common error window messages resulting from typos in variable or constant names.

A good way to check for this type of error is to look for the above error messages. Other Syntax Errors

A slightly more difficult-to-detect error set is when you have typed in an incorrect formula. In this case, you may have all of your constants and variable names correct but the formula itself does not make sense. For example, suppose we have the following code entered in a text box: Linspace(xmin,xmax,ymin,ymax) As long as xmin, xmax, ymin, and ymax are defined we do not have any variable or function name problems. HOWEVER, the function linspace only accepts 2 or 3 arguments, and we have supplied it with 4. Fortunately, MATLAB and COMSOL share a nearly identical language when it comes to defining formulas so: A good way to check for this type of error is to copy and paste any formula code into MATLAB and see if it gives you any unexpected errors. Boundary Conditions or Subdomain Settings not correctly defined Usually, its fairly easy to remember to enter all of your boundary conditions as youre going through a problem, but its often easy to forget subdomain conditions. Subdomain conditions are where you set properties of the medium itself, such as hydraulic conductivity, porosity, etc. In addition, when youve incorporated Multiphysics (for example, Darcys Law mixed with Solute Transport), its even easier to forget which menus you have visited, since they change each time you change physics. NEVER ASSUME that COMSOL has given you a reasonable value for all of your parameters. For example, if you start a new Richards Equation model for groundwater flow, the default value for Density of Fluid is 1 kg/m3. A good way to AVOID this type of error is to make sure you visit both boundary conditions and subdomain settings within each set of physics. Also, verify that physical constants chosen by COMSOL are reasonable. A good way to check for this type of error is to print out a COMSOL report using File Generate Report Direction of elevation not specified

This sort of error really falls into the category above, but it should be mentioned explicitly since this setting is easier to forget. In Physics Scalar Variables, most equations you are dealing with will have a value called D_. This variable corresponds to the direction of elevation and by default is set to 0 (i.e., you are dealing with a map-view problem). If you are dealing with a 2-D cross-sectional problem or a 3-D problem in which gravity is important, make sure to set your direction of elevation within this menu. A good way to check for this type of error is to print out a COMSOL report using File Generate Report NOTE: D_ is the direction of elevation, not gravity, so in most 2-D problems you should set it to y Multiphysics equations not linked correctly If you are dealing with a problem that has more than one set of physics, then linkages between these physics are an important part of your model. For example, if you are solving a problem that involves solute transport and Darcys Law, then you would at the very least want to make sure that solute advection is linked to the velocities obtained by solving the Darcy part of the problem. A good way to check for this sort of problem is to generate a report using File Generate Report. To make sure you are linking the correct variables, go to Physics Equation System Subdomain Settings Variables tab, and make sure you are using the correct variables to link your PDE equations. Unreasonable initial conditions Even on problems that are not being solved in a time-dependent fashion, the value given to COMSOL for initial conditions is quite important. This is because the initial condition values are used to evaluate the initial guess (or iteration) even for stationary solutions to PDEs. For example, say you are solving a problem that involves flow through an earthen dam in steady-state. Since you are not trying to model the transient flow of water through the dam, it would probably make sense to assume that the dam is pre-saturated with water. However, by

default COMSOL assumes that any modeled values are initial 0. Assuming that the head in the dam is initially 0 in this situation might mean that it takes a long time for the problem to converge to the steady-state solution, or it may not converge at all. A good way to make sure you have reasonable initial conditions is to go to Physics Subdomain Settings in ALL physics modes and make sure that the Init tab is set to reasonable values. Reasonable values implies that your final solution will bear some resemblance to your initial conditions in stationary (steady-state) problems. Solver Errors (and some tips) The distinction between User Errors and Solver Errors is somewhat arbitrary indeed you could put all blame on the user for not properly choosing a type of solver or the correct solver parameters. In general, by Solver Errors, I mean those errors that may arise even when the problem is correctly defined but convergence or a correct solution is not obtained. We will not go into each type of solver error in-depth, since they can almost all be corrected by visiting the Solver Parameter screen.

Figure 2: The Solver Parameters Screen (top) general tab and (bottom) Nonlinear tab

The Solver Parameters screen (Figure 2) can be found by either clicking on the icon that looks like an equal sign with a question mark in front of it, or by going to SolveSolver Parameters. On the general tab, you may choose the type of solver to use and can specify constants relating to that specific solver. Fortunately, COMSOL by default chooses the best (i.e., most adaptive) solver. However, if you have a large problem that has special properties (such as a symmetric matrix solve) than you may exploit these properties on this General tab. The second tab of the Solver Parameters window should be your first stop if your problem does not converge and you have verified there are no User Errors. On this screen, lowering the Relative Tolerance, raising the Maximum Number of Iterations or clicking the Highly Nonlinear Problem button can all help the problem to converge.
Aside: Meshing In general, you should also check to make sure that the solution to your problem (once obtained) is not mesh-dependent. Options relating to Meshing can be edited through the Mesh menu in COMSOL. The MeshMesh Parameters screen is especially important in that it allows you to refine the mesh near important features or suspected singularities. Also, using the MeshMap Mesh option you may define a rectangular grid by mapping the 4 sides of a quadrilateral to the boundaries in your

problem. Verifying that your solution does not change when using a rectangular grid is another good check on your solution. Also note that you may store and test your different meshes using MeshMesh Cases. For further guidance on these features see the COMSOL documentation

COMSOL Errors While the PDE-based solvers built into COMSOL (and its parent FEMLAB) are quite robust and well tested, the built-in equation systems, multi-physics linkages and physics Modules in COMSOL are quite new. As with any computer program, newer features tend to be buggier features. This is not to say that COMSOL has released a sub-par product, indeed many of the new features have been proven to be quite reliable and are great time-savers. Still, as with using any new scientific tool, it helps to maintain a healthy level of doubt about the validity or correctness of COMSOLs built-in physical formulations. In general, there are two areas where the most care should be taken. Firstly, when using pre-defined physical PDEs, be sure that the equations COMSOL provides are general enough. For instance, you would not want to blindly use COMSOLs Incompressible Navier-Stokes equation system for a problem that involves compressible flow. Secondly, when using formulas for material properties that change with temperature / pressure, etc., make sure that the formulas COMSOL gives are reasonable. It has been shown, for example, that the formula COMSOL gives currently for the viscosity of water at different temperatures is incorrect and it may be better in many cases to define the properties of the material you are dealing with yourself.