laborative exercise comsol-simulations

20
Microfluidics Laborative Exercise COMSOL-simulations

Upload: others

Post on 27-Dec-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Laborative Exercise COMSOL-simulations

Microfluidics

Laborative Exercise

COMSOL-simulations

Page 2: Laborative Exercise COMSOL-simulations

Department of Electrical Measurements

LTH, Lund University

26 August 2011 Introduction

In this lab you will get acquainted with COMSOL, a program package for multiphysics simulations using the Finite Element Method (FEM). COMSOL uses physics modules

that make it very simple to build up your equations. You do not need detailed knowledge about how the equations that control the system work.

During the lab you will study one of the chips in the first lab. You will look at velocity fields, lamination, diffusion, convection, animation of flows and particle tracing. The first

half of the lab will be limited to stationary solutions since these will be fast to solve. In the second half of the lab we will calculate time-dependant solutions and animate flow fields etc. In order to fit all moments into the lab schedule, we will only use 2D-

simulations. The principle for 3D simulation is similar but it takes much longer time to compute and demands a lot more of the computer in terms of memory.

The typical workflow in COMSOL is:

Draw the model

Enter material parameters

Define boundary conditions

Mesh the model

Solve the problem

Visualise the solution

Simulation software packages are powerful tools that can give you important clues on the best way to design a system. However, bear in mind that a simulation always contains

simplifications and may lead to a solution that is not always in agreement with reality.

Page 3: Laborative Exercise COMSOL-simulations

Model wizard 1. Start COMSOL version 4.2. 2. Two fields automatically shown up when starting COMSOL: The Model Builder

that shows and overview of the current model and what features that have been added to it. The Model Wizard that guides you through the mandatory steps in

building any kind of model. 3. In the Model Wizard select Space Dimension to 2D and press the little arrow to

proceed.

4. To set the physics to fluidic simulations relevant to microfluidics, select fluid flow > single phase flow > laminar flow and press the plus sign to add it to the model.

We have now specified the model to simulate fluidics in the non turbulent (laminar) regime and also elected only to consider a single phase such as water. A typical two-phase flow in microfluidics is oil and water and such a system would

have to be modeled using multiphase flow. Press the arrow to proceed. 5. As the study type select stationary, this means that all time dependence will be

excluded from the model and that the results will show what happens in a steady state. We will expand the model with time dependence later but for now press the finish flag to continue.

Drawing the model We will start out with doing a stationary simulation of the flows in the channel used in

the first lab and see how this compares with our experimental knowledge.

Page 4: Laborative Exercise COMSOL-simulations

1. The first thing we need to do is to draw the model and the final result should be a channel that looks like what was used in the first lab.

2. Look to the model builder to get an overview of the current model. Under Model1

select Geometry1, right click to get a list of possible actions and choose rectangle.

We now see that a rectangle has been added to the geometry. 3. Go to settings for the new rectangle and specify a width of 6 cm and a height of

800 m. Edit the corner position of the rectangle to be at (0, -400e-6) so that the

channel is centered around the x-axis. Press build selected.

4. Build another rectangle that is 6 mm wide and 800 m high (also centered around

the x-axis). 5. Rotate the new rectangle by right-clicking on geometry 1 and choose transforms

> rotate. Select the smaller rectangle by double clicking on it (double clicking where both rectangles are located will toggle between them) and add it to the input objects by using the plus sign. Specify a rotation of -45 degrees and the

centre of rotation to (6e-3, 0) down along the x-axis.

Page 5: Laborative Exercise COMSOL-simulations

6. Now mirror the rotated rectangle over the x-axis by right-clicking geometry1 and

selecting transforms > mirror. Select the rectangle as input object and check the keep input object button. The mirror-line is specified by a point on the line and a

normal vector; input a point on the x-axis and a vector that is normal to it. 7. To create the outlet channels, mirror both of the inlet channels over a vertical line

at half the length of the channel.

8. To finalize our channel system we need to make a union of all the geometries. Select geometry1/boolean operations > union and use all of the geometries as a

input objects. Uncheck the keep interior boundaries box and build the union. The geometry is now done and should look as the chip used in the first lab.

9. Before moving on, specify what liquid is present in the channel by right-clicking

materials > open material browser.

10. In the material browser, expand the built-in tab and add water, liquid to the model

by right clicking and selecting the add material to model option. Check that

Page 6: Laborative Exercise COMSOL-simulations

selection setting is set to all domains. This means that the liquid properties (viscosity and density) in the channel are specified to those of water.

Boundary conditions and sub-domains

Boundary conditions define input variables on the edge of the model and the sub-domain defines the conditions inside. In defining the boundary conditions you make most of your assumptions necessary for solving the problem, so this is where knowledge about the

underlying physics is most important.

1. Under model1 expand the laminar flow (spf) tab, which is where we specify what physics we want to solve for. If you left click on laminar flow (spf) and expand the equation tab you can see the Navier-Stokes equation that COMSOL solves.

2. The fluid properties tab show the sub-domain setting for our model. Check that the temperature is set to room temperature (in Kelvin) and that the density and

viscosity is taken from the material (water). 3. Notice that by default all of the boundaries are set to wall which in microfluidics

is described by the no slip boundary condition; this is what generates the

parabolic flow profile. 4. Add inlet boundaries to the model by right clicking laminar flow and selecting

inlet. Specify the inlet by zooming in, shift-clicking on the boundaries and adding them to the selection. Select the boundary condition laminar inflow and set an average velocity of 1 mm/s.

Page 7: Laborative Exercise COMSOL-simulations

5. Add outlet boundaries to the model by right clicking laminar flow (spf) and selecting outlet. Specify the appropriate boundaries and use the option pressure,

no viscous stress.

Mesh

To solve a partial differential equation with the finite element method the geometry has to be divided using a mesh.

1. In the first run we will make the simplest possible mesh. Click on mesh and specify the element size to finer (this controls in how many parts the geometry

will be divided). Press the build all button.

Solve We have now specified our entire model of the fluidics and are ready to solve the

problem.

1. Since the study type was already selected in the wizard when we chose stationary,

all we need to do is right click study1 and select compute and relax while COMSOL does the calculations. It should take around 2s so don’t get too relaxed.

Visualization

1. When the simulation is finished, a solution will automatically be shown on the

screen. The default settings for the fluidic simulations are such that you see a

surface graph of the velocity field in your chip. 2. By expanding results and velocity you can select witch physical quantity that

should be plotted on the surface. This is done by pressing the little replace expression button next to expression tab. Try out some different parameters and play around with the different settings.

Page 8: Laborative Exercise COMSOL-simulations

3. To measure a quantity, you can either look at the scale at the right side of the

screen or you can click somewhere in the graph and get a point-value presented in the text window at the bottom of the program.

4. Are the results comparable to what you saw in the first lab exercise?

Save your model on the desktop before you move on!

Page 9: Laborative Exercise COMSOL-simulations

Multiphysics COMSOL’s strength is that it’s built on several physics modules, making it possible to simulate how different physical phenomena affect each other in a single model. The first

model we created consisted of a single module to simulate the fluidics in a channel. We will now add a module to be able to study diffusion as well.

1. Right-click on Model 1 and choose Add Physics. 2. Choose Chemical Species Transport and Transport of Diluted Species. Now

click the right arrow at the top of the physics window section. 3. Choose Stationary and click on the checkered flag.

4. In the model builder menu we now have a new entry under Laminar flow called Transport of Diluted Species (chds). You can also see that a new study has been

added to the model. 5. The first thing to do is to set the diffusion coefficient and couple the diffusion

module to the laminar flow module that we've already solved.

6. Under the Transport of Diluted Species menu is an item called Convection and

Diffusion 1. Click on it and it will show you a menu where you can add the

physics parameters for our diffusion simulation. 7. Under Model Inputs select Velocity Field (spf/fp1) as our velocity field.

Page 10: Laborative Exercise COMSOL-simulations

8. Further down in the same menu you can see a field where you can enter your diffusion coefficient. Enter something similar to what you measured during the first lab exercise. We are assuming that the diffusion is isotropic.

9. To set the diffusion in- and outlets, right-click on the Transport of Diluted Species text and choose Inflow.

10. Select the two side inlets (4 and 6) and set the concentration to 1. 11. Right click on laminar flow menu again, choose outflow and select all outlets.

Since you already have the solution to the laminar flow problem we will now solve only the diffusion problem.

12. Expand Study 1 and select Step1: Stationary. Under Physics Selection, disable

Transport of diluted species and make sure that laminar flow is enabled. Now go

to Study 2 and Step1: Stationary and disable Laminar flow and leave Transport of diluted species enabled. At the bottom of the menu here you will find

something called Values of dependent variables. Click it and choose Method:

Solution, Study: Study1, Stationary and Stationary: Automatic.

Page 11: Laborative Exercise COMSOL-simulations

13. Now right click on Study 2 and choose Compute. 14. Under Results you will now see a new plot group: Concentration. Click on it.

We will now be able to see a lamination of the side-inlets and the diffusion along the channel. Some distortions, caused by not having a mesh fine enough, can sometimes be seen in the channel but primarily at the inlets.

Page 12: Laborative Exercise COMSOL-simulations

15. Does the diffusion behavior seem to agree with what you saw in the first lab exercise? Try to change the diffusion coefficient and see how the diffusion is

affected. 16. A cross-section plot of the channel will give a very clear picture of the

concentration at a certain point of the channel. To create cross-section plot we need to first define the line that we want to plot along.

17. Right click on Data Sets under the Results menu. Choose Cut Line 2D. To look

at the cross-section of the middle of the channel, enter the following values and click plot.

18. Add a line plot by right clicking on results and add a 1D plot group. Right click

the 1D plot group and add a line graph to see the profile plot.

19. Now examine the concentration profile at some different distances from the inlets. Observe that the graph is automatically scaled and sometimes doesn’t cover more

than a few decimals.

Adaptive meshing If you have a stationary problem to solve, there is a small finesse in COMSOL that can be

very useful – adaptive mesh refinement. You start solving your problem with a very course mesh and COMSOL will automatically refine the mesh where it is needed in order to achieve a good solution. Care has to be taken to define the maximum number of

Page 13: Laborative Exercise COMSOL-simulations

elements COMSOL may use, otherwise you can easily end up with a simulation that is impossible to solve on anything else but a super computer. Adaptive mesh refinement

only works with triangular meshes though so in order to use we will have to define our own mesh.

1. Right click Mesh 1 and select Free triangular. Click on size and choose Extra

fine.

2. Click on Study 2 and Step1: Stationary. Expand the Extension menu and check Adaptive mesh refinement.

3. There should now be a menu item under Study 2/Solver

configurations/Solver 2/Stationary Stationary Solver 1 that is called Adaptive Mesh Refinement 1. Click it. If you can't see it, right click

Stationary Solver 1 and choose Adaptive mesh refinement. 4. Here you can change the settings for the adaptive mesh refinement. The

default maximum number of refinements is 2 and for some reason the default maximum number of elements is 10 millions. Change Maximum

number of refinements to 5 and the maximum number of elements to

100 000. 5. Right click Study 2 and select compute. It should take about 20s to

compute. 6. Once the problem is solved you should have a new plot group under results

that will show you the adaptive mesh solution to the diffusion problem.

Compare it the previous solution that was done with a simple mesh. You will notice that there is a big different along the inlet and the zone where

the concentration species is laminated into the channel. 7. To see what the adaptive mesh looks like, expand the mesh menu and click on

Mesh 2, and zoom in on the inlets. 8. Save your solution to a file on the desktop.

Computing section integrals When the solution is available, Comsol provides some tools to quantify and inspect the

behavior of the solution. An example is given by Projection Couplings. These are useful, for example, to compute cross-sectional integrals as to derive averages and plotting these as function of a normal-to-section coordinate. In formulae, we mean

( ) ∫ ( ) ( )

, where ( ) is a scalar variable defined within the

computational domain and ( ) is the section as function of the coordinate. 1. For the node Component1, right click on Definitions and select under

Component Coupling the Linear Projection node, then the new node Linear Projection (linproj1) appears, where linproj1 is the name of the operator which

can be used to recall the sectional integral one want to compute, for example by means of linproj1(u).

2. In the node Linear Projection, by the box Source Selection, select the domain for which the integral have to be computed, in our case 1. Now one has to define

the three vertices on boundaries that Comsol uses to generate the projection in

Page 14: Laborative Exercise COMSOL-simulations

Source Vertices. Vertices 1 and 2 define the x-axis, i.e. the first variable in the integral, while points 1 and 3 define the y-axis, i.e. the second variable that

disappears by integration. These numbers could vary depending on the way the geometry has been modeled. In Source Destination select the vertices

corresponding to vertices 1 and 2. Now the linproj1 operator is available on the boundary comprised between the vertices 1 and 2.

3. Update the solution by clicking on Study and selecting Update Solution.

Note: Some versions of Comsol need the computation run again after the linear projection has been set, this is not fair because computation can take long time to run, therefore is ever a good practice to define Couplings before running

simulations. 4. Create a new node under Results by selecting 1D Plot Group. Add Line Graph

to this node and select the edge bounded by vertices 1 and 2. In the y-Axis Data section under Expression box write the expression you want to compute (see figure below). Click on top Plot icon.

Page 15: Laborative Exercise COMSOL-simulations

Time dependent simulations It’s not always enough to have a stationary solution to a problem. If you, for instance,

want to study the dispersion of a plug of fluid in a channel or observe the movement of particles in a fluid flow, a time-dependent solution is required.

The downside to time dependent simulations is that they take a long time to solve. You choose within which time interval you want the solution and how small time-steps you

want. COMSOL will then solve the problem for each time and merge the solutions. In order to save some time during the lab we will cut our geometry in half and only study

what happens at the inlet.

1. Go to Geometry 1 and add a new Rectangle. Set the rectangle to have a width

of 3.1e-2 and a height of 10e-3. Set the corner to be at 3e-2, -5e-3. Build the rectangle.

2. Now right click on Geometry 1 and choose Boolean Operations/Difference.

3. Add our original structure, uni1, to Objects to add and add the new rectangle, r3, to Objects to substract. When you click build, everything inside our new

rectangle is deleted from our structure.

4. Since we deleted our outlets we need to go back into Laminar flow and add our

new outlet as outlet.

5. Now, since the velocity field will stay the same we will perform a time dependent solution on only the diffusion problem. We can add a new time-

dependent solver to our existing diffusion study but a simpler solution is to add a new study. Right click on the root item in you menu (usually the file name)

and select Add Study. Select time dependent and click on the finish flag.

6. Click on our new study, Study 3, and choose Step 1: Time dependent. Change the range to be 0:1:10 seconds. If you want a larger time span or a better time

resolution you can go back and change this value later.

7. To save more time we'll go back to our old mesh and not use the adaptive mesh

we calculated earlier. Set Geometry 1 to use Mesh 1 under Mesh selection.

8. Since we want to use our old calculated velocity field again you will have to do the same settings as we did before when we added the diffusion module.

Page 16: Laborative Exercise COMSOL-simulations

Disable the laminar flow physics interface and set the values of variables not

solved for to Solution and Study1: Stationary.

9. Since we cut our channel in half we will have to resolve our fluidics problem though so start by right clicking Study 1 and choose compute. Once the fluidic

problem has been solve you can right click on Study 3 and choose compute. It will take a little while longer than the previous solution as it calculated 10 different solutions.

10. When the simulation is finished, the solution at the very last time step is shown by default. When you click on the new plot group you can choose which time to

look at in the Time field.

Animation If you want a better visualization of a time-dependent process, you can use the animation

feature. If we for instance want to see the side inlets laminate, we can create a video showing exactly the area and times we are interested in.

1. Right click Export under the Results tab and choose Player.

2. In the new menu that appears under reports, choose Concentration 2 under

Subject. COMSOL automatically chooses the times that your time dependent simulation ran over. If you wish to only look at part of the time interval you can

choose it under the Parameter Sweep/Time settings.

Page 17: Laborative Exercise COMSOL-simulations

3. You can now either right click on the Player 1 menu item to play it or click on the play button in the graph window.

4. If you think the video is played to fast you have used to large time steps. You can either resolve the problem using finer time steps or use interpolation in the time

settings for the sweep parameters. The interpolated frames are not based on real simulations but can work well for visualisation under the asumption that no major changes occur between two real frames.

5. If you wish to make more precis animation settings and export the animation as a movie, you can choose the Animation item instead of the player item in the

Export menu.

Particle tracing Another useful way of visualizing a solution is by studying how particles are moving in

the velocity field of a fluid. Particles are commonly used in microfluidics and it is often of interest to see how they interact with the fluidics.

In COMSOL there are two main groups of particles you can study, particles with and without mass. If you use the particles with mass, you will get a more accurate

visualization. On the other hand, the movement of the particles without mass is quicker to calculate. The particle tracing can be done either in stationary or time dependent mode. If

you choose to do it with a stationary solution you will only see the streamlines that the particles would follow. If you do it in a time-dependent solution you can see and follow the particles as they move along the channel and observer how they react with specific

objects.

1. To add a particle tracing to our time dependent diffusion solution, right click the

concentration 2 plot group and click more plots and particle tracing. 2. COMSOL will automatically add the velocity field u and v as the force acting on

the particles. Under particle positioning you can choose where to "inject" the particles into the system. This can either be done over a boundary or at fix coordinates.

3. In order to inject particles in the center inlet and see how they are laminated, choose Start point controlled as positioning setting and put 3e-3 as x-value and

10 values between -3.9e-4 and 3.9e-4 (range(-3.9e-4,7.8e-4/9,3.9e-4)). When entering the values, click on the menu on the right hand side, choose start value, end value and the number of values in between. Make sure that Number of values

are chosen as input method. 4. The release time can be controlled under the release menu but we can leave it as

it is. Under coloring and style we can add a point style so we can see the particle easier. Choose point under type, set the radius to 10e-6 and specify a scaling

factor of 5.

5. When you click on plot the particle position for the choosen time will be displayed together with streamlines that show how they have moved to get there.

If you go to the animation that was previously done, you should be able to animate the particle motion as well.

Page 18: Laborative Exercise COMSOL-simulations

Dispersion Another example of a time-dependent solution is the dispersion of a ”concentration plug”

that enters our channel. The method that we will use to define an action appearing in a very short time space can be used for many different things such as changing the

direction and velocity of a flow at certain times. The technique simply tells COMSOL that the given parameter is only to exist between different time values. By adding for instance 0<t<1 to a parameter, it will only exist for times between 0 and 1. The time

argument is simple treated as a boolean operator and will set the parameter to zero for all times outside the given interval. You can use the syntax stated here but this will often

lead to problems with discontinuities at the end values. In COMSOL you have the possibility to use Heaviside functions to achieve a smoother transition between the Boolean states.

1. Go to Transport of Diluted Species and click on inflow. Change the

concentration value from 1 to 5*(flc2hs(t-0.5,0.5)-flc2hs(t-1,0.5)). This way we will create a ”pulse” with the value 5 between times 0.5 and 1. The second value (0.5) will define how the ramp of the Heaviside function will look and how

“rounded” the step will be.

En matlabplot av Heavisidefunktionen 5*(flc2hs(t-0.5,0.5)-flc2hs(t-1,0.5))

2. Change the time resolution to 0:0.1:10 in the solver parameters.

3. Solve the problem and wait a couple of minutes for the result.

4. You can now either study the dispersion by looking at different surface plots or

you can animate it as we’ve done previously.

0 1 2 3 4 5 6 7 8 9 10-5

-4

-3

-2

-1

0

1

2

3

4

5

Page 19: Laborative Exercise COMSOL-simulations

Model Library

In COMSOL there is a rather large library of already solved problems. You can find this by going to View/Model Library... Look through the different models that might seem

interesting and see how the professionals have solved the different problems.

Finally You have now tried some different modelling/simulation alternatives in COMSOL and

practised the normal approach to solve a problem. No matter what kind of problem you are trying to solve, the approach is almost always the same: draw your model, set the

boundary conditions, set the subdomain settings, mesh the model, solve the problem and visualize the parameters you are interested in as clearly as possible (not always the easiest thing to do).

Something that is important to bear in mind is that just because you get a solution in

COMSOL doesn’t have to mean that it is true. You can have missed a step, made a wrong assumption or the solution might not have converged. Do not trust the simulations blindly. Correctly used, however, they can be powerful instruments that can visualize

concepts that are otherwise hard to grasp.

If there still is time left feel free to try to simulate other things COMSOL and try out the program. Don’t hesitate to ask the lab supervisor if you have any questions or need help.

Page 20: Laborative Exercise COMSOL-simulations

The COMSOL program is available for all LTH-students through the computer management group (DDG) at http://program.ddg.lth.se.