Spring 2018 (Dr. C. Sert) Handout 9 Unsteady...
Transcript of Spring 2018 (Dr. C. Sert) Handout 9 Unsteady...
ME 582 β Handout 9 β Unsteady Examples
9-1
METU Mechanical Engineering Department ME 582 Finite Element Analysis in Thermofluids
Spring 2018 (Dr. C. Sert) Handout 9 β Unsteady Examples
Note: You can use unsteady1D.m code to obtain the 1D solutions given in this handout. The code comes with input files prepared for these examples.
Example 1 β Cooling Bar:
Consider the unsteady heat diffusion in a 1D domain governed by the following DE
ππ
ππ‘βπ2π
ππ₯2= 0 , β 1 β€ π₯ β€ 1 , 0 β€ π‘ β€ 1
Initial condition βΆ π(0, π₯) = (1 β π₯2)
Boundary conditions : π(π‘, π₯ = β1) = 0 , π(π‘, π₯ = 1) = 0
Obtain the solution using the 1st order forward Euler scheme with a time step of Ξπ‘ = 0.1.
This can be seen as a model of the cooling of a 1D bar that is initially heated to have a parabolic temperature distribution,
with the maximum value being at its center. Its ends are kept at a fixed low (zero) temperature. The bar gives heat to the
surrounding through its ends and its temperature reduces in time.
Letβs solve this problem using the following mesh of 5 linear elements, each having a length of βπ = 0.4 and π½π = 0.2
Elemental mass matrix is defined as follows
ππππ = β«ππππ ππ₯
Ξ©e
= β« ππππ π½π ππ
1
β1
which is the same for each element because all elements have the same size. Entries of [ππ] can be evaluated as follows
π11π = β«
1
2(1 β π)
1
2(1 β π)(0.2) ππ
1
β1
=2
15
π12π = β«
1
2(1 β π)
1
2(1 + π)(0.2) ππ
1
β1
=1
15
π21π = π12
π (due to the symmetry of [ππ] )
e=1
π₯
e=2 e=3 e=4 e=5
1 2 3 4 5 6
ME 582 β Handout 9 β Unsteady Examples
9-2
π22π = β«
1
2(1 + π)
1
2(1 + π) (0.2) ππ
1
β1
=2
15
For each element, the mass matrix is
[ππ] =1
15[2 11 2
]
Assembled global mass matrix is
[π] =1
15
[ 2 1 1 4 1 1 4 1 1 4 1 1 4 1 1 2]
Elemental stiffness matrix is defined as
πΎπππ = β«
πππππ 1
π½π πππ
ππ 1
π½π π½π ππ
1
β1
β [πΎπ] = [2.5 β2.5β2.5 2.5
]
Elemental stiffness matrices are also the same for all elements. Assembled global stiffness matrix is
[πΎ] =
[ 2.5 β2.5 β2.5 5 β2.5 β2.5 5 β2.5 β2.5 5 β2.5 β2.5 5 β2.5 β2.5 2.5]
At level π = 0 nodal unknown vector {π}0 can be obtained from the given initial condition as follows
{π}0 =
{
00.640.960.960.640 }
Following is the forward Euler formula that weβll use to βmarch in timeβ. [πΎ] and {πΉ} do not depend on time, so we
removed their subscript π .
[π] {π}π +1 = ([π] β βπ‘[πΎ]){π}π + βπ‘ {πΉ}β=0
{π}π
Actually {πΉ} is zero for this problem. After applying reduction for the EBCs, the following 4x4 system is obtained.
1
15[
4 1 1 4 1 1 4 1 1 4
] {
π2π3π4π5
}
1
= (1
15[
4 1 1 4 1 1 4 1 1 4
] β 0.1 [
5 β2.5 β2.5 5 β2.5 β2.5 5 β2.5 β2.5 5
]){
0.640.960.960.64
}
ME 582 β Handout 9 β Unsteady Examples
9-3
Solving this system, we get the following result for π = 1 time level.
{
π2π3π4π5
}
1
= {
0.38740.77050.77050.3874
}
We can continue like this and calculate one more solution using
[π] {π}2 = ([π] β βπ‘[πΎ]){π}1
After applying reduction for EBCs and solving the system we get
{
π2π3π4π5
}
2
= {
0.45880.46890.46890.4588
}
If we continue a few more time steps we get the following results.
{
π2π3π4π5
}
3
= {
0.01790.54950.54950.0179
} , {
π2π3π4π5
}
4
= {
0.62980.02840.02840.6298
} , {
π2π3π4π5
}
5
= {
β0.70380.74620.7462β0.7038
}
The results are not physical. We expect to have the mid-point temperatures to be higher than the ones close to the
boundaries, but that is not the case. At time level π = 5 we get negative temperature values, but the smallest temperature
that can appear in this problem is zero. This solution is unstable. Forward Euler scheme is only conditionally stable and
the selected Ξπ‘ exceeds the critical Ξπ‘ of this problem.
Example 2 β A Stable Solution with Forward Euler:
If we decrease the time step to 0.05 forward
Euler becomes stable, at least up to π‘πππππ = 1,
which is reached in 20 steps.
Important: Critical Ξπ‘ depends on the DE being
solved, the time discretization scheme and the
size of the elements. If we increase the number
of elements to 10, i.e. decrease the element size
to 0.2, Ξπ‘ = 0.05 exceeds the critical Ξπ‘ and the
solution again becomes unstable. Therefore, as
the mesh gets finer and finer stability restriction
of an explicit scheme becomes more and more
severe. With a 10 element uniform mesh,
Ξπ‘ = 0.005 gives a stable solution. With a 50
element mesh, Ξπ‘ of about 2.5 Γ 10β4 is stable.
π = 0, π‘ = 0
π = 2, π‘ = 0.1
π = 4, π‘ = 0.2
π = 20, π‘ = 1
ME 582 β Handout 9 β Unsteady Examples
9-4
Example 3 β Time Step Independence Analysis:
Backward Euler scheme is unconditionally stable. We can get a stable solution no matter what Ξπ‘ we use. But Ξπ‘ still
needs to be small enough to get an accurate solution. Letβs solve the previous problem using the 1st order backward Euler
scheme with 50 elements and with different Ξπ‘βs, and check the accuracy of the solution by looking at the value of π at
π₯ = 0 and π‘ = π‘πππππ = 1. Results are as follows.
Ξπ‘ π(π₯ = 0, π‘ = 1) Percent relative error wrt.
the last solution
0.2 0.1388 59 %
0.1 0.1137 30 %
0.01 0.09011 3 %
10β3 0.08772 0.3 %
10β4 0.08748 0.03 %
10β5 0.08745 -----
Plot of this table is given below. After Ξπ‘ = 10β3, the solution is not changing considerably. We do not need to use smaller
time steps. Depending on how much accuracy we want, even Ξπ‘ = 10β2 can be considered as enough. This is a time step
independence study. Similar to a mesh independence study, we also need to perform this one for an unsteady problem.
Important: As discussed in the previous example, with 50 elements, forward Euler scheme needed a Ξπ‘ of about
2.5 Γ 10β4 for a stable solution. This value is 4 times larger than 10β3, which is roughly what we need to get a Ξπ‘
independent solution. If 3 % error is good enough, even using Ξπ‘ = 0.01 is acceptable, which is 40 times larger than the
critical Ξπ‘ limit of the forward Euler scheme. So compared to backward Euler, forward Euler needs a much smaller time
step due to stability. This is usually the case, i.e. for an explicit scheme the time step is usually restricted by stability, not
by accuracy. But what if we use mass lumping with forward Euler? Solution time per time step will reduce and the overall
run time can be comparable to (or even faster than) the backward Euler solution. Next example is about the use of mass
lumping.
Converged value
ME 582 β Handout 9 β Unsteady Examples
9-5
Example 4 β Mass Lumping with the Forward Euler Scheme:
Forward Euler is an explicit scheme. But unlike FDM or FVM, in FEM it still requires the solution of a system of equations
at each time step, which is as costly as an implicit scheme. It already has a stability issue. So to be of any use, we need to
apply mass lumping to make it truly explicit, so that no solution of an equation system is necessary. This way, the forward
Euler scheme will be less costly per time step and may compete with implicit schemes in terms of overall run time.
Here weβll not compare run times, but rather concentrate on the accuracy loss brought by mass lumping. When we solve
the same problem with 50 elements using forward Euler scheme with mass lumping, the result is not good. With mass
lumping the temperature profile becomes almost totally flat at the end of the solution with π(π₯ = 0, π‘ = 1) = 0.0063.
Mass lumping caused too much accuracy loss for this problem. Of course what we have here is a very limited test, but the
least we should conclude is that we need to use mass lumping with caution. An important detail here is that we used the
simplest for of lumping, known as βrow sum lumpingβ. Other more advanced techniques may give better results.
Example 5 β Crank Nicolson (C-N) Scheme:
Letβs repeat what we did in Example 3 using the Crank-Nicolson scheme. Again we have 50 elements.
Ξπ‘ π(π₯ = 0, π‘ = 1) Percent relative error wrt.
the last solution
0.2 0.08249 5.7 %
0.1 0.08634 1.3 %
0.01 0.08744 0.01 %
0.001 0.08745 -----
This study clearly demonstrates the higher accuracy provided by the Crank-Nicolson scheme. With Ξπ‘ = 0.1 we are able
to get a solution with 1.3 % error. In Example 3, 1st order backward Euler used with this Ξπ‘ resulted in 30 % error.
Ξπ‘ = 0.1 is 400 times larger than 2.5 Γ 10β4, which is the stability limit of the forward Euler scheme for 50 elements.
Converged value
ME 582 β Handout 9 β Unsteady Examples
9-6
Note that the range of the vertical axis of the above plot and the one given in Example 3 are quite different. If we had
used the same range for both, the curve in this one would look much more flat and converged.
Example 6 β Unsteady Problem with a Steady State Final Solution:
Some problems go through an unsteady transition to reach a steady state solution. And sometimes what we are interested
in is only the final steady state solution, not how we reach there. In such a case, using an unconditionally implicit scheme
with a large time step makes sense.
Letβs modify the DE that we solved in the earlier examples by adding a force function.
ππ
ππ‘βπ2π
ππ₯2= π , β 1 β€ π₯ β€ 1 , 0 β€ π‘ β€ 15
π = {40 if β 0.1 β€ π₯ β€ 0.1else
Initial condition βΆ π(0, π₯) = 0
Boundary conditions : π(π‘, π₯ = β1) = 0 , ππ
ππ₯|π‘,π₯=1
= 0
This time the physical interpretation is as such; Initially the bar is at zero temperature. While keeping the left end at zero
and insulating the right end, we supply concentrated heat to the middle part of the bar and its temperature rises until a
steady state is reached.
Letβs first perform a very accurate reference solution using the Crank-Nicolson scheme with 500 elements and Ξπ‘ = 0.001.
The result at different times are as follows. At the steady state the temperature at the insulated boundary reaches to 0.8
and that happens approximately at π‘ = 10 s. Here we solve the problem up to π‘πππππ = 15.
π‘ = 15
π‘ = 0
π‘ = 0.5
π‘ = 1
ME 582 β Handout 9 β Unsteady Examples
9-7
Now letβs reduce the number of elements to 50, which is enough to get an acceptable solution. Weβll solve the problem
using different schemes and time steps up to π‘πππππ = 15 s, and record the final steady state temperature at the right
boundary, i.e. π(π‘ = 15, π₯ = 1).
Scheme Ξπ‘ π(π‘ = 15, π₯ = 1) Relative error wrt the
exact value of 0.8
Notes
C-N 0.001 0.7928 0.9 %
C-N 0.01 0.7928 0.9 %
C-N 0.1 0.7928 0.9 %
C-N 1 0.7944 0.7 % Oscillatory
C-N 3 0.7562 5.5 % Oscillatory
Backward Euler 0.001 0.7928 0.9 %
Backward Euler 0.01 0.7928 0.9 %
Backward Euler 0.1 0.7928 0.9 %
Backward Euler 1 0.7922 1.0 %
Backward Euler 3 0.7881 1.5 %
Forward Euler 0.001 Unstable -----
Forward Euler 0.01 Unstable -----
Forward Euler 0.1 Unstable -----
Forward Euler 1 Unstable -----
Both implicit schemes provide acceptable steady state results using very high time steps such as Ξπ‘ = 1. With this Ξπ‘,
both schemes provide an error less than 1 % reaching π‘πππππ in only 15 steps. However, with 50 elements, the explicit
forward Euler scheme is unstable even with Ξπ‘ = 0.001.
Important: As seen in the last column of the above table, C-N becomes oscillatory for very high Ξπ‘ values. Progress of such
a solution with Ξπ‘ = 1 is shown below. As seen, the rise of temperature from π‘ = 0 to π‘πππππ is not monotonic, i.e. curves
corresponding to different time levels are crossing each other. At certain instants of time we see values slightly exceeding
the maximum steady state value of 0.8. This is not physical. But it is not instability, i.e. these oscillations do not grow
unboundedly in time. This is the typical oscillatory behavior of C-N seen with high Ξπ‘ values. Backward Euler scheme
shows no such oscillations, even when the solution is obtained with Ξπ‘ = 15, i.e. using a single time step to reach steady
state (Of course such a result is not very accurate. Try and see).
Conclusion: Using a low order implicit scheme such as 1st order backward Euler with a high Ξπ‘ is the best approach to
determine a steady state solution without paying attention to unsteady transitions. If the unsteady transition part also
needs to be captured accurately, a higher order scheme such as C-N and a lower Ξπ‘ can be suggested.
ME 582 β Handout 9 β Unsteady Examples
9-8
Example 7 β Moving Cosine Hill:
Up to this point we solved unsteady diffusion. Letβs now consider the following unsteady advection problem.
ππ
ππ‘+ π
ππ
ππ₯= 0 for π₯ β [0, 1.4] , π‘ β [0, 1]
π(0, π‘) = 0
π(π₯, 0) = {
1 + cos (5π(π₯ β 0.2))
2 if π₯ < 0.4
0 else
Initial condition given at π‘ = 0 is a smooth cosine hill centered at point π₯ = 0.2 with height 1 and base length 0.4. This
hill will move in the positive π₯ direction with a speed of π = 1. Since this is a pure advection problem, the shape of the
hill is expected to remain the same as it travels. The equation is hyperbolic and only one BC at the left end of the domain
is necessary. No BC should be given at the right end. But our unsteady1D.m code asks for a BC there also, and we can
provide zero flux (do nothing) condition.
Forward Euler, backward Euler and Crank-Nicolson (C-N) schemes with 100 linear elements are used for the solutions.
Oscillatory nature of C-N seen with high Ξπ‘ values.
ME 582 β Handout 9 β Unsteady Examples
9-9
Results at π‘ = 1 obtained using the forward Euler scheme with different Ξπ‘βs are shown below. Forward Euler scheme is
only conditionally stable and the solution is stable and acceptable only for small enough time steps. When time step is
increased, unphysical waves develop behind the main traveling cosine hill and they grow in magnitude. These waves are
an indication of dispersion errors of the approximation. When the combined space and time discretization has dominant
dispersion type truncation errors, these kind of extra unphysical waves appear in the solution.
Ξπ‘ = 10β4 Ξπ‘ = 5 Γ 10β4
Ξπ‘ = 10β3
ME 582 β Handout 9 β Unsteady Examples
9-10
Next figure shows the solutions obtained with the backward Euler scheme, which is unconditionally stable. The solution
is smooth even for very large time steps. However, for large time steps the solution is too diffusive, as seen by the drop
of the hillβs height. This drop is an indication of diffusion errors. When the combined space and time discretization has
dominant diffusion type truncation errors, sharp features of the solution diffuse out and become too smooth.
Important: Altough the results with high Ξπ‘βs are smooth and free of oscillations, they are not accurate. Here we can easily
say this because we know the exact solution. But for a real-life flow problem with no known exact solution, it would be
difficult to judge the correctness of the solution. Accepting a smooth looking solution as accurate just because it looks
smooth is a commonly made mistake.
Ξπ‘ = 10β4 Ξπ‘ = 10β3
Ξπ‘ = 10β2 Ξπ‘ = 10β1
ME 582 β Handout 9 β Unsteady Examples
9-11
The following figure shows results obtained with the C-N scheme, which is second order accurate in time. For large time
steps its diffusive error is less than the backward Euler scheme. However it is not as βoscillation-freeβ as the backward
Euler scheme, and similar to the previous example, it starts to create oscillations for high Ξπ‘βs. Again, these oscillations
are not a sign of instability because they do not grow in time unboundedly.
Very Important: All these results are at π‘ = 1. In one unit time, the cosine hill travels a distance of 1 unit with the given
unit velocity. The hill travels a distance of πΞπ‘ units at each time step. For a given element size of βπ, the hill passes over πΞπ‘
βπ elements. For the mesh of 100 elements used in these simulations, one element length is 0.014 units. Therefore with
Ξπ‘ of say 0.1, the hill passes over about (1)(0.1)
0.014= 7 elements in one time step, which is simply too much for the explicit
forward Euler scheme. The hill tries to move too fast, but this is not allowed and the solution goes unstable.
The above calculation is usually presented in terms of the nondimensional Courant number defined as
πΆ =πΞπ‘
βπ
Courant number is important in studying stability characteristics of time discretization schemes. For explicit schemes
Courant Friedrichs Lewy (CFL) stability condition puts a maximum upper limit for πΆ as follows
CFL condition: πΆ < πΆπππ₯ β Ξπ‘ < Ξπ‘ππππ‘ππππ
Ξπ‘ = 10β4 Ξπ‘ = 10β3
Ξπ‘ = 10β2 Ξπ‘ = 10β1
ME 582 β Handout 9 β Unsteady Examples
9-12
For explicit schemes, for a given π and βπ, CFL condition puts a stability limit on the maximum allowed Ξπ‘. πΆπππ₯ value
depends on the PDE that is being solved and the details of space and time discretizations, such as the polynomial order
of elements and order of the time discretization scheme. For simple PDES such as the one we have in this problem that
describes pure advection, we can calculate the value of πΆπππ₯ by performing a stability analysis, which is not a subject of
our course.
CFL condition does not apply to implicit schemes that are unconditionally stable.
Important: As seen in the CFL condition equation, for a given π value, the critical Ξπ‘ depends on the element size βπ. If
we decrease the element size to get a more accurate solution, we should also decrease the time step so that the CFL
condition is not violated.
For multi-dimensiopnal problems where the velocity vector is not constant in magnitude, and the mesh not unfiorm, the
small elements over which we have the high advection speed, i.e. the combination which results in the highest Courant
number, are the most critical ones for stability and they are the ones that define the critical Ξπ‘.
Important: We have to be careful when deriving conclusions based on the solutions of a single problem. This example is
about pure advection, i.e. there is no diffusion. Real life problems usually include some amount of diffusion, which helps
us to stabilize the solution to a certain degree. Shape of the initial cosine hill is also important. For example if we try to
work with a square wave with sharp corners, the solutions will be much more oscillatory.
Example 8 β Rotating Cosine Hill:
2D version of the previous problem is sketched below. Now we have a roating cosine hill in a square domain.
Governing PDE and the boundary and initial conditions are as follows
ππ
ππ‘+ οΏ½βοΏ½ β βπ = 0 , Ξ© β [β1,1] Γ [β1,1] , π‘ β [0, 2π]
π = 0 at all boundaries
View BB at π‘ = 0
H = 1
D = 0.5
π¦
π₯
Point A (-0.5, 0)
Flow
direction
B B
οΏ½βοΏ½ = βπ¦π + π₯π
(-1, -1)
(1, 1)
ME 582 β Handout 9 β Unsteady Examples
9-13
π(π₯, π¦, 0) = { 1
2[cos (4ππ) + 1] if π < 0.25
0 else } where π = β(π₯ + 0.5)2 + π¦2
Problem domain is a 2x2 square. Initially the unknown π is specified to be zero everywhere except the cosine hill centered
at point A with a height of 1 and a diameter of 0.5. A velocity field is specified as οΏ½βοΏ½ = βπ¦π + π₯π , which rotates the cosine
hill around the origin in CCW direction. EBC of value zero is given at all boundaries. Similar to the previous problem, this
is also a pure advection case and the exact solution should have the hill rotating around the origin, without changing its
shape. Unfortunately due to diffusive errors of a numerical solution, the hill will diffuse out as it rotates, which will be
seen as a decrease in its height and an increase in its radius. Also due to the dispersive errors, there will be trailing waves
behind the rotating hill. The simulations are run for a total time of 2π, which corresponds to one revolution of the hill.
Following figure shows the results obtained using a uniform mesh of 100 bilinear quadrilateral elements. For each case
backward Euler (BE) and Crank-Nicolson (C-N) schemes are tested with two different time steps. Considering its unstable
charateristics, forward Euler scheme is not used for this problem.
As seen, a mesh of 100 elements gives totally unacceptable results. Even the small time step gives no meaningful result,
because space discretization errors are very dominant for this very coarse mesh.
BE Ξπ‘ = π/100
C-N Ξπ‘ = π/100
BE Ξπ‘ = π/1000
C-N Ξπ‘ = π/1000
π
ME 582 β Handout 9 β Unsteady Examples
9-14
Following results are obtained with 400 elements. Now it is possible to identify the rotating hill. Similar to the previous
1D problem, backward Euler scheme has excessively large diffusive errors, especially for the larger Ξπ‘. Using C-N scheme
with Ξπ‘ = π/1000, height of the hill reduces to 0.75 after one rotation (it should stay at 1 for the exact solution) and
trailing waves have a maximum undershoot of 0.17.
BE Ξπ‘ = π/100
C-N Ξπ‘ = π/100
BE Ξπ‘ = π/1000
C-N Ξπ‘ = π/1000
π
ME 582 β Handout 9 β Unsteady Examples
9-15
Following results are obtained with 900 elements. Backward Euler is still too diffusive for the large time step and the result
is unacceptable. When the time step is reduced, backward Euler result gets considerably better. Best reult is obtained
using the C-N scheme with the small time step, for which height of the hill after one rotation reduces to only 0.92 and
trailing waves have a maximum undershoot of only 0.08.
Important: Errors accumulate as the time elapses. Results get worse if we increase π‘πππππ, i.e. allow the hill to make more
rotations. For example, if the 900 element case with the C-N scheme and t = /1000 is run for 3 rotations, maximum
height of the hill reduces to 0.80 and the trailing waves show a maximum undershoot of 0.17. Backward Euler performs
much worse. Using a high order accurate time discretization scheme becomes especially important for problems that
require long time integration. Here Adams-Moulton, Adams-Bashforth and Runge-Kutta schemes become good
alternatives.
BE Ξπ‘ = π/100
C-N Ξπ‘ = π/100
BE Ξπ‘ = π/1000
C-N Ξπ‘ = π/1000
π