You are on page 1of 33

Intro to Comsol

Presented by Matthew Coblyn


For CHE 331, fall 2013
Models and Simulations
A computer model refers to the algorithms and equations used to
capture the behavior of the system being modeled. However, a
computer simulation refers to the actual running of the program
which contains these equations or algorithms. Sir Wikipedia

At a certain point a problem will become too complex to solve


analytically. We create a computer model and run a simulation to
arrive at a numerical solution.

(flow over an edge)


Solutions via numerical methods

Solve

1. Let dy = y2 y1

2. Let dx = x2 x1
3. Solve for y2 y2 = 2x1(x2 x1) + y1

4. Plug in x1, x2, y1

5. Use previously computed values to calculated the next step in the


solution. Repeat n times based on how youve segmented the
range you are solving for. Segmenting a continuous function or
distribution is called discretization.

Courtesy of Travis Campbell


Numerical solution approaches analytical
solution with decreasing step size

Analytical

This is just one approach in a family of methods called the Finite Difference Method.
Comsol uses the Finite Element Method. That requires not only discretization of the
system but also iterative calculations in order to converge on a unique solution for your
problem.
Plot courtesy of Travis Campbell
Many physics modules combined in one software package that
allows for communication between modules.

Modules
Fluid flow, heat transfer, electrical, chemical reaction, stress analysis

Examples of multiphysics problems


Heat transfer across a cooling fin in laminar flow
Chemical reaction through a
tube reactor
There are many modules available in Comsol
Access to Comsol
Engineering labs or Citrix app

Citrix app solves faster because it runs off


the engr server but you may prefer setting
up the problem running Comsol natively
on an engr lab computer.
Laminar flow through a pipe
Inlet: 1 cm3/s

No slip at wall
Ignore gravity
Isothermal conditions
Steady state
Cylindrical coordinates
2 cm water

Outlet: P=0
Building a model
1. Select relevant physics modules
2. Build geometry
3. Define materials
4. Define boundary conditions (and initial
conditions if necessary)
5. Build mesh
6. Solve!
Comsol interface

Displays the model


Model geometry, along
Builder with results and
outlines all This window gives plots after solving.
aspect of you various options
the model. depending on what
is selected in the
model builder.

Displays feedback from program, activity log,


solution progress.
Choose your dimensions
Click the little greenish-bluish arrow to continue

Space dimensions depend on


the problem you are solving.

Examples:
Flow through pipe 2D
axisymmetric

Flow around an infinitely long


pipe 2D

Flow around a cube 3D

Increasing dimensions increases


complexity of problem and
required computing resources to
solve
Add relevant modules
Lots of modules to choose
from. You should only use
modules you understand.

We only need to add laminar


flow for our problem. Select
Laminar Flow (spf) and click
( ) to add.
Steady state or time dependent?

Select Stationary and then


click the checkered flag( ) to
complete setup.

Stationary model will solve quicker


than a time dependent because each
time step in the time dependent
problem must go through the solving
process. Time dependent problems
are often unavoidable when
attempting to model more complex
systems. Ex. a dynamic event occurs
at the inlet such as change in
concentration
Choose your units

Axis of rotation

Next, click the rectangle button

You can also right click Geometry to access these options


Draw a rectangle with one corner at the origin

Modify dimensions to match problem

To make a complete pipe


you must have an edge on
the axis of rotation or else
youll get a skinny donut
thingy
Finalize your geometry

Select Form Union in your model builder and click Build


All

This step is not necessary for our model. For other models
that involve multiple shapes, Form Union will link the
separate shapes into one object
Define materials in your system

Select Materials in the


model builder and then
Material Browser tab

Expand list until you find


Water. Right click to add
material to model.
The rectangle is domain 1
and already listed as water.
More complex problems
may involve more that one
domain and material.

Built in material properties


are listed along with
relevant properties for this
model indicated by a green
check mark
Define system conditions

By default all edges are defined as


a wall except the axis of rotation.
We will adjust for an inlet and outlet.

Define the wall B.C. as No Slip


Right click Laminar Flow and
select Inlet and Outlet

There are lots of built-in options for


defining your system. Volume
Force can be used to define a body
force such as gravity. Open
Boundary can be used to allow two
domains to trade material.
Additional walls can be added if
certain walls have different
conditions such as slip or moving
boundary.
Click on the edge we want to convert to inlet and click the + to add.

Define the inlet condition. For this model well use laminar inflow and flow rate. Well define an entrance
length of 0.5m which should be more than sufficient for the flow to fully develop (L/D=0.6*Re)
Define the outlet

Outlet is defined by pressure equal to zero


If we go back to Wall 1 we can see that boundary 2 and 3 are now overridden
because they are defined as the inlet and outlet.
Creating the mesh

Set the sequence type to Physics-controlled mesh and keep the element size as
Normal. The mesh describes the matrix that will contain our complete solution.
Comsol computes a solution at every node of the mesh. A tighter mesh results in
higher resolution results but longer computing time.
Run the simulation

Click it.

Notice the Step 1: Stationary option


under Study 1. This exists because
we selected it when initially creating
the model. It would say time
dependent if we were solving an
unsteady state problem and we could
use this branch to control the time
step of the solution.
It solved! But its currently displaying a 2D plot of velocity magnitude. This is pretty
to look at but not as useful for analysis. Lets make a plot of the velocity profile.

This window becomes useful while the


computer is solving. It give you information
such as which step its at in the computing
process, solution convergence and memory
usage.
Right click Data Sets and then Cut
Line 2D

We will create a cut line in the 2D


geometry and plot every point along
that line in terms of velocity
magnitude.

There are 1D to 3D options for


collecting specific data points in your
solution matrix.
Define the cutline end points. We will place the line in the middle
of the pipe, starting at the center (r = 0cm) and extending to the
wall (r = R = 5cm). Then click Plot to verify location.
Right click Results and select 1D Plot Group

Right click 1D Plot Group


and select Line Graph
Change data set to Cut Line 2D 1
and click Plot button to update

We can change the x and y-axis to plot different


values such as pressure and concentration (if that
were in the model). Notice that velocity magnitude is
defined as spf.U
We can determine the variable names
for different properties through the
model builder and these variables
carry over throughout the entire model.
Exporting data

Right click Export and add Plot. In


Plot 1, select the plot group and plot
you want to export. Define the file
name and export as a spreadsheet. It
will create a text file that you can
import into excel or matlab.
The end stuff
Save often. Especially after the solution is computed.

Search comsol tutorial online. First result is a pdf that walks through
another example. It has good explanations of the interface.

There is a lot of built-in functionality that we did not cover. Click around and
explore. This is expensive software offered free by COE!

Simulations are a powerful solving tool but we still require a strong


understanding of the concepts to set up the problem and assumptions
correctly.

Understand how model variables talk to each other. Think of Comsol as a


big matlab code. You can define and use variables in different locations. Ex.
define inlet flow as a linear function of time.

You might also like