Simulating Coupled Heat Transfer and Fluid Flow in Comsol: AC 274 Tutorial (Fall 2017)
Simulating Coupled Heat Transfer and Fluid Flow in Comsol: AC 274 Tutorial (Fall 2017)
1 Introduction
We will be going through a computational exercise to demonstrate the principles of heat
transfer (convection) and fluid flow (laminar). As an example, we will simulate a Rayleigh-
Bénard (RB) convection cell used for performing PCR [1] in a single cell. To begin with,
we will review the basic principles of convective heat flow and fluid dynamics. The sections
below heavily borrow the theory material from Ref. [2], so you are encouraged to read
through Ref. [2] for additional details if interested. In our exercise we will build a model
of the RB cell in Comsol and solve the coupled heat/fluid flow problem using the finite-
element method. The end goal of this exercise is to understand some important parameters
for designing a single-cell PCR device using a RB convection cell.
1
assumed to be homogeneous in temperature. Also, at very short time scales Newton’s law
of cooling gives large errors.
A more general approach is to solve the heat equation in a fluid,1 which is a second
order partial differential equation. Unlike the phenomenological Newton’s law from the
previous section, the heat equation can be derived directly from first principles. The heat
equation, also known as the equation of thermal energy, is essentially a form of the energy
conservation principle, which states that the rate of change of total thermal energy is equal
to the rate of exchange of heat flux (conduction), the rate of change of energy due to
convection and pressure variations (compression or expansion), and the rate of change of
energy due to viscous dissipation. Mathematically, we can write this as shown below.
∂U
ρ + ρ~v (∇U ) + ∇ · ~q
∂t} | {z } | {z }
rate of change of
| {z
rate of change of
rate of change of energy from convection energy from conduction
total thermal energy
Here, ρ is the density, ~v is the velocity, p is the pressure, and τ is the viscous stress tensor
of the fluid.2 The thermal energy is denoted by U and the heat flux is given by ~q. We can
obtain more useful information from this equation if we write U in terms of T in Eq. (2),
which gives us the following heat equation [2].
∂T
ρC( + ~v ∇T ) = κ∇2 T − T α∇ · ~v − τ : ∇~v (3)
∂t
Here, C is the specific heat, α is the coefficient of thermal expansion, and κ is the thermal
conductivity. We have also used Fourier’s law i.e. κ∇2 T = −∇ · ~q to write the heat flux,
q, in terms of temperature, T . Now, we have the heat equation in terms of variables and
constants that can be physically measured, thus making a very useful form for engineering.
2
for a fluid can be written as follows.
ρ∂~v
+ ∇ · ρ~v~v + ∇p
∂t | {z } |{z}
|{z} rate of change of pressure
rate of change of total momentum by convection force
linear momentum
+ ∇ · τ}
| {z − ρ~g = 0 (4)
|{z}
rate of change of gravitational
momentum by viscous transfer force
Here, ~g is the acceleration due to gravity. Note that τ and the dyadic product ~v~v are
tensors. By expanding the dyadic product, i.e. ∇ · ρ~v~v = ρ~v (∇ · ~v ) + ~v (∇ · ρ~v ), we can
rewrite Eq. (4) in a more commonly used form of the Naviér-Stokes equation as shown
below.
∂~v
ρ + ρ~v (∇ · ~v ) = −~v (∇ · ρ~v ) − ∇p − ∇ · τ + ρ~g (5)
∂t
3
one after the other repeatedly (finite-difference time-domain method). The finite-difference
method is intuitively simple but becomes computationally demanding when the shapes of
the objects are complicated. Another popular method is by converting the differential
equations to their so-called weak forms by rewriting them in an integral form and dividing
the domain into small elements to set up a bunch of linear equations that can be solved
iteratively (for example using the Newton-Raphson method). This is known as the finite-
element method.
Choosing which method to use often depends on the computational resources at hand
and the kind of problem we are solving. For example, for simple rectilinear objects the
finite-difference technique is often desirable for its simplicity. Also, for time-dependent
problems, the finite-difference can be simpler to implement. On the other hand, for complex
shaped objects and steady-state analysis, the finite-element method works better. There
has been considerable advances in the area of finite-element time-domain, which can be
robust for strong time-dependent analysis where complicated geometries are involved. It
should be noted that with the increase in available computational resources, advances have
been made on particle-based simulations of fluids, where the fluid is simulated by collective
interactions between fictitious fluid particles. The lattice Boltzmann method is one an
example of such a technique. These particle-based methods can be superior in simulating
multiphase fluid problems, such as mixing of different fluids.
The Comsol Multiphysics software, as you might be aware, is based on the finite-
element method and provides a very convenient way to couple and solve partial differential
equations from different areas of physics. Comsol also provides an interface to create
geometric models and therefore not requiring any additional CAD software. So, for the
purpose of this exercise, we will be using Comsol and the sections below provide the steps
that we will perform to model the RB cell.
4
(a) (b) (c)
Figure 1: Selecting the appropriate physics modules. We can select pre-coupled physics modules
such as (a) Fluid Flow → Nonisothermal Flow → Laminar Flow or (b) Heat Transfer → Conjugate
Heat Transfer → Laminar Flow, where the multiphysics node coupling fluid flow with heat flow is
automatically added. We can also manually couple individual physics nodes by selecting (c) Fluid
Flow → Laminar Flow and Heat Transfer → Heat Transfer in Fluids, and then add a multiphysics
node to couple the equations.
5
appropriate physics modules (see Fig. 1) and then click Study. For now, select a time
dependent study, although at this point we will not perform a study.
In order to get an overview of what Comsol will be solving behind the scene when we
eventually click Compute, we will first take a look at the equations within the relevant
physics modules. Once the appropriate physics modules are selected, you will see a Model
Builder tree in a panel on the left hand side of the application. In this tree, go to Component
1 → Heat Transfer → Fluid 1. With Fluid 1 selected look at the Equation node in the
Settings tab (see Fig. 2a) to find the equation for heat transfer. Similarly, to find the
equations for fluid flow, go to Component 1 → Laminar Flow → Fluid Properties 1. In the
settings tab open the Physical Model node and select Include gravity. Open the Equation
node and find the relevant equations (see Fig. 2b).
Figure 2: Identifying the different terms in the equations that the physics modules in Comsol are
solving.
Try to identify and compare the different terms in the equations that Comsol is solving
with Eqs. (3), (5), and (6). Note that the last term on the RHS in the equation in Fig. 2a
(Qvd ) contains the viscous dissipation term of Eq. (3). Also note that the first term on
6
the RHS in the first equation in Fig. 2b is simply an expansion of the stress tensor (τ ) in
Eq. (5).
2. Temperature distributions in the cell with regions having the ranges specified above.
This list above will serve as the design goals for our simulations.
7
4 Simulating a RB Cell for PCR in Comsol
We will be modeling a RB cell that is like the one shown in the Figure 1 of Ref. [1] (See
Fig. 3). We could model the RB cell as a three dimensional box with the bottom heating
plate, top cooling plate, and the side glass walls. However, we can safely assume that the
vertical walls are ideally insulating and the top and bottom planes are able to maintain a
constant uniform temperature. Let’s also assume that the depth of the box is much larger
than the width or the height. With these assumptions we can simplify our model to two
dimensions by simply simulating a 2D slice of the rectangular box. Follow the steps below
to setup a simulation of a RB cell for PCR in Comsol.
Figure 3: Schematic of the RB cell that we will model for PCR (from Fig. 1A of Ref. [1]).
1. Start a New file in the Comsol Application using the Model Wizard. Select 2D for
the Space Dimension and add Heat Transfer → Conjugate Heat Transfer → Laminar
Flow physics modules. Click on Study, select Time Dependent, and then click Done.
Now, you will see the Model Builder tree on the left most panel in the application.
We will exclusively use this tree to edit the model, however, you can also use the
buttons in the interface or the items from the drop-down menus.3
2. Right-click the Global Definitions node in the Model Builder tree and select Parame-
ters. We will add parameter constants to be used to define our model. Later on, you
will see how we can use these parameter definitions to perform parameter sweeps.
Enter the parameters given in the table below (the “–” means don’t enter anything).
3
It is assumed that you will keep saving your work regularly, since Comsol can be a bit crash prone if
you have memory constrains.
8
Table 1: Global parameter list for RB cell
3. Right-click on the Geometry node and select a rectangle. In the Settings tab find
the Size and Shape node and enter W cell in the Width and H cell in the Height.
Now click Build All Objects to create the rectangle. This rectangle represents two
dimensional slice at a fixed depth through the interior of our 3D RB cell.
4. Next, right-click on the Materials node and select Add Material from Library. Find
the material data for water in the material library under Liquids and Gases → Liquids
→ Water. Now, with Water selected click on the Add to Component button (you
can always also right-click and find the same action).
5. Moving to the physics nodes, expand the Heat Transfer node. We, first have to
specify which parts of our model are solid and which parts are fluids. Since, we
do not have any solid object, select the Fluid 1 node. In its Settings tab, find the
Domain Selection node and make sure that it is Active and the Selection drop-down
menu has Manual selected. Select the entire rectangle by clicking on it. Note, in this
case, we could have also chosen All domains from the drop-down menu since in our
model we only have a single domain. Also, note now that if you select the Solid 1
node, you will find that the Domain Selection box will say (overridden).
6. Let’s now define the boundary conditions4 for the Heat Transfer module. By default,
Comsol applies thermal insulation boundaries, i.e. no heat flux crossing the edge, on
all edges. For the vertical walls we do want thermal insulation boundaries. However,
we want to specify the temperature at the bottom and the top, so we have to change
the boundary conditions on those two edges. Right-click the Heat Transfer node
and you will find all possible boundary conditions. Select Temperature and a new
Temperature 1 node will be added to the Heat Transfer node. In the Settings tab
of the Temperature 1 node, find the Boundary Selection node, make sure its Active
and Manual, and then click on the bottom edge of the rectangle to select it (The
4
An important side note: Boundary conditions are perhaps the single most important part of solving
differential equations that turn a general differential equation into the specific problem that you want to
solve. So, always double-check and make sure your boundary conditions are correctly specified.
9
edge turns blue when selected). Now, in the Temperature node of the Settings tab,
make sure the drop-down menu is showing User defined and in the box enter T hot.
Repeat the above instructions to add a second Temperature boundary condition on
the top edge with the temperature being T cold.
7. Moving down the ladder in the Model Builder tree, select the Laminar Flow node.
In the Settings tab, locate the Physical Model node and make sure Include gravity is
selected (It is not selected by default). When you select Include gravity, you need to
provide Reference Values, i.e., a reference pressure, temperature, and position. We
can keep the reference pressure and temperature at their default values, but change
the reference x and y positions to W cell and H cell, respectively. Also, change the
Compressibility drop-down menu item to Incompressible flow. By selecting Incom-
pressible flow along with Include gravity, we are essentially making the Boussinesq
approximation, where we assume that density variations in the fluid are negligible
expect in the gravitational force term.
8. Since, our cell volume is not very large, we don’t expect there to be large pressure
variations within the fluid. However, the small pressure variations are important for
fluid flow and we do want to accurately calculate the velocity variations in the fluid.
One way to increase the accuracy of a finite-element simulation is to increase the
order of the discrete elements (by default, Comsol creates first-order elements), but
increasing element orders comes at the cost of memory and speed of computation.
So, we strike a balance by using second-order elements for calculating the velocity
and first-order elements for calculating pressure. In order to do that, first, click
on the Model Builder view and select Discretization (this is unselected by default).
Now, when you select the Laminar Flow node, in its Settings tab, you will find a
new Discretization node. Expand this node and from the drop-down menu, select
P2+P1. This will generate second order elements for velocity and first-order elements
for pressure.
9. The default boundary condition for Laminar Flow is the wall boundary, which is
what we need in this case, since the fluid is confined within the box. Select the Wall
1 node in Laminar Flow and take a look at the Settings tab. Make sure that all the
edges are selected in the Boundary Selection node and that the Boundary Condition
node has the Wall condition at No slip. These are all true by default.
10. Now, there is one last boundary constraint we need to add, which is not quite initially
obvious. Select the Laminar Flow node and in its Settings tab, expand the Dependent
Variables node. You will find that the unknowns being solved for are three velocity
components and pressure (see also Sec. 1.3). Now, let’s revisit the equations for fluid
flow [see Fig. 2b, also see Eq. (5)]. In these equations, we find that the variable
pressure only appears after a spatial derivative operator (∇). Therefore, unless we
10
specify the pressure at some point on the boundary, we will not be able to calculate
the spatial derivative.5 In order to specify the pressure at a point, right-click on the
Laminar Flow node and from the Points section, select the Pressure Point Constraint.
This will create a new Pressure Point Constraint 1 node. In its Settings tab, expand
the Point Selection node and click on the bottom right vertex of the rectangle. Now,
for this point, we will specify a pressure of 0[atm] in the Pressure Constraint node.
Note that is the gauge pressure were are providing not the absolute pressure.
11. With the boundary conditions set, we can move to the Multiphysics node in the
Model Builder tree. Expand the Multiphysics node and select the Nonisothermal
Flow node. In its Settings tab, expand the Flow Heating node and check the boxes
for Include work done by pressure changes and Include viscous dissipation. At this
point, all the relevant physics has been implemented in the model.
12. Select the Mesh node in the Model Builder and take a look at the Settings tab. We
will keep the default mesh settings. Click Build All and notice the shape of the finite
elements. At the boundaries the elements are rectangular and small. As we move to
the interior of the domain the elements increase in size and are triangular in shape.
The rectangular elements are shown to be more accurate near the boundaries for fluid
flow problems, while triangular elements can fill any region of space more accurately
than rectangular shapes.
13. Expand the Study node and click on the Time Dependent node. In its Settings tab,
expand the Study Settings and in the Times box enter range(0,1,120) (This will run
the simulation for 120 s while saving results every second). OK, we are now done
with setting up the simulation. Go ahead and click Compute.
11
the velocity distribution. Does this RB cell satisfy the three important requirements for
PCR applications that we stated in Sec. 3? Clearly, the convective flow is not very stable
and does not allow stable temperature regions. So, let’s tweak our design and try to search
for an aspect ratio that will satisfy our design goals.
12
(a) Temperature distribution at 120 s.
Figure 4: Results from the time dependent simulation of a RB cell showing (a) temperature and
(b) velocity distributions at 120s.
13
References
[1] M. Krishnan, M. V. Ugaz, and M. A. Burns, “PCR in a Rayleigh-Bénard Convection
Cell,” Science, 298, 2002
[2] R. Byron Bird, Warren E. Stewart, and Edwin N. Lightfoot, Transport Phenomena,
John Wiley & Sons, Inc., New York, 1966.
[3] Theodore L. Bergman, Adrienne S. Lavine, Frank P. Incropera, and David P. Dewitt,
Introduction to Heat Transfer, John Wiley & Sons, Inc., 2011
14