metu mechanical engineering department me 582...

18
ME 582 – Handout 10 –COMSOL Tutorial 1 10-1 METU Mechanical Engineering Department ME 582 Finite Element Analysis in Thermofluids Spring 2018 (Dr. C. Sert) Handout 10 – COMSOL 1 Tutorial 2 In this second COMSOL tutorial let’s solve the following 2D advection-diffusion equation, which is Q3 of Study Set 5. Governing equation is 2 2 =0 The problem domain and the BCs are as follows We are interested in solving the following 3 cases Case 1: =1 , =0 (zero diffusion) Case 2: =1 , = 0.003 (low diffusion) Case 3: =1 , = 0.03 (high diffusion) Step 1. Start COMSOL. Press Model Wizard. Select 2D. Select Mathematics – Classical PDEs – Convection-Diffusion Equation (cdec). Press the Add button. Press the Study button. Select Stationary. Press the Done button. Note: The terms “advection” and “convection” are used interchangeably. COMSOL calls it convection and in this tutorial we’ll use convection. 1 COMSOL 5.3a is used to prepare this tutorial (10,3) = =0 =0 =0 =0 =0 =1

Upload: others

Post on 31-Aug-2020

4 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-1

METU Mechanical Engineering Department ME 582 Finite Element Analysis in Thermofluids

Spring 2018 (Dr. C. Sert) Handout 10 – COMSOL1 Tutorial 2

In this second COMSOL tutorial let’s solve the following 2D advection-diffusion equation, which is Q3 of Study Set 5. Governing equation is

�⃗� 𝑑𝜙

𝑑𝑥− 𝛼

𝑑2𝜙

𝑑𝑥2= 0

The problem domain and the BCs are as follows

We are interested in solving the following 3 cases

Case 1: 𝑈 = 1 , 𝛼 = 0 (zero diffusion) Case 2: 𝑈 = 1 , 𝛼 = 0.003 (low diffusion) Case 3: 𝑈 = 1 , 𝛼 = 0.03 (high diffusion)

Step 1. Start COMSOL.

Press Model Wizard.

Select 2D.

Select Mathematics – Classical PDEs – Convection-Diffusion Equation (cdec).

Press the Add button.

Press the Study button.

Select Stationary.

Press the Done button.

Note: The terms “advection” and “convection” are used interchangeably. COMSOL calls it convection and in this tutorial we’ll use convection.

1 COMSOL 5.3a is used to prepare this tutorial

(10,3)

𝑥

𝑦

�⃗� = 𝑈𝑖

𝜙 = 0

𝜙 = 0

𝜕𝜙

𝜕𝑥= 0

𝜙 = 0

𝜙 = 0

𝜙 = 1

Page 2: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-2

Step2. We’ll draw the problem geometry using 6 line segments. Left boundary of the domain will be drawn in 3 segments so that different BCs can be assigned to each segment.

In the Model Builder (MB) right click Geometry 1 and select Polygon.

Enter the following x and y coordinates to draw a polygon. Note that the last point will be automatically connected to the first point to form a closed polygon.

0 10 10 0 0 0

0 0 3 3 2 1

Click Build Selected.

To see the segments of the left boundary click Select Boundaries button in the Graphics tab.

Page 3: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-3

Step 3. In the MB tab select Convection-Diffusion Equation 1 under Convection-Diffusion Equation (cdec)

Under Equation you’ll see the convection-diffsuion equation, which is a simplified form of the generic PDE that we used in tutorial 1.

It has an unsteady term, diffusion term, convection term and force term.

To solve the first case, which is pure convection, set diffusion coefficient (𝑐) to zero.

Also set 𝑓 and 𝑑𝑎 to zero.

𝛽 is the convection velocity. Set its x component to 1 and y component to zero.

Page 4: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-4

Step 4. Right click Convection-Diffusion Equation (cdec) and select Dirichlet Boundary Condition.

Using the shift key and the mouse, select the parts of the boundaries where 𝜙 = 0 is specified (shown in blue below).

Do not change the default value of 𝑟 = 0.

To specify 𝜙 = 1 BC, right click Convection-Diffusion Equation (cdec) and select Dirichlet Boundary Condition.

Select the part of the left boundary where 𝜙 = 1 is specified.

Change the r value to 1.

Important: Right boundary is a zero flux boundary, and by default all BCs are set to this. So there is no need to do anything for that.

Page 5: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-5

Step 5. To generate a structured mesh of quadrilateral elements, on the MB tab right click Mesh 1 and select Mapped.

Select Size under Mesh 1 and change Predefined value to Extremely fine.

Click Build All.

As will be seen in the Messages tab, a mesh of 3000 elements will be generated.

Step 6. Select Study 1 in the MB tab and press the Compute button under Settings.

Solution will finish in 2 seconds and the following result will be plotted.

Page 6: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-6

This solution seems to be identical to the exact solution. The discontinuous profile specified at the inlet seems to be convected into the domain perfectly.

Let’s have a look at it in 3D to see it better.

In the MB tab right click Surface 1 under Results – 2D Plot Group 1, and select Height Expression. The following 3D plot with height being the solution itself will be displayed.

The solution is actually not that perfect. There are some overshoots (values larger than 1) and undershoots (values less than 0) around the sharp changes. The following close up view shows the overshoots better.

Important: The problem we are trying to solve is challenging in two ways

There is no physical diffusion. Pure convection is hard to solve, not only for FEM but for all techniques.

The profile at the left boundary has very sharp changes, actually discontinuities. Convecting this profile without modifying its shape and keeping all sharp changes as given at the boundary is not easy.

Page 7: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-7

Step 7:

Important: The problem is actually more severe than those seen in the above plots. Here we are solving convection that is perfectly aligned with the mesh lines, i.e. convection is in 𝑥 direction and mesh lines are either parallel or perpendicular to it. This combination actually helps us to get a good solution, but it occurs very seldom in real life problems. Let’s see what happens when we change the convection direction slightly by adding a small velocity component in the 𝑦 direction, as follows.

�⃗� = 𝑖 + 0.05𝑗

Keeping the mesh the same, now convection is not perfectly aligned with the grid lines.

Select Convection-Diffusion Equation 1 and change 𝑦 component of the convection velocity 𝛽 to 0.05.

Page 8: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-8

Step 8. Select Study 1 and press Compute to solve the problem again.

Under Results – 2D Plot Group 1 – Surface 1, right click Height Expression 1 and Disable it.

As seen, now convection has a small 𝑦 component. The given profile at the left boundary moves towards right, but also it shifts upwards.

To see how good (or bad) this solution really is, right click Height Expression 1 and Enable it.

The solution has unphysical wiggles (node-to-node oscillations). The figure on the right is a close up view at the right boundary.

Page 9: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-9

Step 9. To find out how large the overshoots are, Select Results – Derived Values – Maximum – Surface Maximum.

Select the problem domain with your mouse.

Set Element refinement to 1.

Press Evaluate.

fgh

The maximum of the calculated unknown values will be reported in the Messages tab as 1.067. Physically the maximum value should not exceed 1. Therefore, there is 7 % overshoot.

Let’s also determine the minimum calculated value. Select Results – Derived Values – Minimum – Surface Minimum. Select the domain with the mouse and set Element refinement to 1. The value is -0.063324, which corresponds to a 6% undershoot.

Page 10: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-10

Step 10. As demonstrated, when the convection direction is not aligned with the grid lines, solution of convection dominated problems may have unphysical wiggles. To show this we added a small amount of 𝑦 velocity component to the convection velocity. However, for an unstructured grid the convection speed can never be perfectly aligned with the grid lines.

Change the convection velocity back to the original value of �⃗� =𝑖 .

To get rid of the structured mesh, right click Mesh 1 and select Reset to the Physics-Induced Sequence.

Select Size under Mesh 1 and set Predefined to Extremely Fine.

Click Build All.

A mesh of 7468 triangular elements will be created.

Page 11: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-11

Select Study 1 and Press Compute. We get the following solution.

Figure on the right is a close up view at the right boundary.

The solution has wiggles. This solution needs to be compared with the one obtained in step 6.

Evaluate the maximum and minimum values again. They are 1.067 and -0.0633, i.e. almost 7 % maximum overshoot and 6 % maximum undershoot.

Hint: In order not to get confused with the previously calculated values, click the Delete Table button in the tab where the maximum and minimum values are reported and them calculate new values.

Page 12: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-12

Step 11. To see how using a finer mesh will affect the solution, select Size under Mesh 1.

Select Custom and set Maximum element size to 0.05.

Press Build All.

A mesh of 29746 elements will be created. Previous one had 7468 elements.

Compute the solution again to get the following, which is close up view at the left boundary.

This solution is even more wiggly than the previous one. To see it better, evaluate new maximum and minimum values. You’ll get 1.0878 and -0.11104, i.e. almost 9 % overshoot and 11 % undershoot. These value are worse than the ones obtained with the coarser mesh.

Conclusion: The solution is more oscillatory with the finer mesh.

Page 13: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-13

Step 12. To see how using a higher order element will affect the solution, select Size under Mesh 1 and set Predefined to Extremely fine. Click Build All. Now we are back to 7468 element mesh.

Select Convection-Diffusion Equation (cdec) and change Element order to Cubic.

Compute the solution again.

Frequency of the wiggles increased. 1.0774 and -0.082777. Slightly better than the previous one, but not much improvement.

Increasing the element order to 4 (quartic) increases the amount of overshoots and undershoots.

Conclusion: It seems to be impossible to get a smooth solution with h- or p-refinement. It is important to remember the 2 challenges in this problem; it is pure convection with zero diffusion, and it has a BC with very sharp changes.

Important: GFEM is known to have issues when used in convection dominated problems. The difficulty of solving such problems is not specific to FEM. FDM and FVM also suffer in these problems and the typical cure used is known as upwinding, which can also be used in FEM. In the FEM context, getting rid of wiggles and obtaining smooth solutions is in general known as stabilization. We’ll study it in Chapter 5.

Page 14: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-14

Step 13. Let’s now solve case 2 of the problem, which has a small amount of diffusion.

Make sure that the mesh is the 7468 element triangular mesh, obtained with the Extremely fine setting.

Set the element order to quadratic (the default value).

Make sure that convection velocity is the originally given one, i.e. �⃗� =𝑖 .

Change the Diffusion Coefficient to 0.003.

Compute the solution.

Disable and Enable Height Expression 1 to get the following 2D and 3D views.

The small physical diffusion we added smoothed out the solution. Wiggles are only seen close to the left boundary and the rest of the solution is smooth.

Page 15: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-15

Step 14. Let’s see the profiles of the solution at different sections of the problem domain.

Under Results, right click Data Sets and select Cut Line 2D.

Set the end point coordinates as (2,0) and (2,3), i.e. generate a vertical line at 𝑥 = 2.

Press Plot to see the generated line.

Page 16: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-16

To plot the unknown over this line, right click Results and select 1D Plot Group.

Right click the newly generated 1D Plot Group 1 and select Line Graph.

Set Data set to Cut Line 2D 1.

Change Legends to Manual and enter the text x=2.

Press Plot.

This is what the solution looks line along x=2 line. The sharp profile specified at the left boundary smoothened out a bit as it reached x=2.

Page 17: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-17

Step 15. Let’s generate 2 more vertical lines as Cut Line 2D 2 and Cut Line 2D 3. Generate these lines at x=5 and x=10.

Also generate 2 more line graphs as Line Graph 2 and Line Graph 3. Make sure that these use the recently generated cut lines as the data sets.

All three profiles are seen in one figure because all eunder the same 1D Plot Group 1.

The solution diffuses more and more towards the right boundary.

Note that the title of the plot is also changed. To have this I changed the title of Line Graph 1 and remove the titles of the other two.

Page 18: METU Mechanical Engineering Department ME 582 …courses.me.metu.edu.tr/courses/me582/files/Handouts...ME 582 – Handout 10 –COMSOL Tutorial 1 10-2 Step2. We’ll draw the problem

ME 582 – Handout 10 –COMSOL Tutorial 1

10-18

Step 16. To solve the third case, increase the Diffusion Coefficient to 0.03.

Compute the solution again. New solution is given below.

Profiles are automatically updated. You don’t need to do anything.

Exercise: To get solutions that can be compared with the ones obtained by our mesh2D.m code change the element order to linear and solve the 3 cases again. Also perform a mesh independence study, i.e. solve each case multiples times with different meshes