9
Advanced Finite Elements MA5337 - WS17/18 Programming tutorial 2 The goal of this programming tutorial is to apply the time-integration techniques for parabolic and hyperbolic PDEs from the exercises to the instationary Stokes equation and a problem of dynamical linear elasticity. Also a simple treatment of the nonlinearities arrising in the Navier-Stokes equations will be implemented and the differences between Stokes and Navier- Stokes-equation can be studied on benchmark examples. Finally also the locking phenomenon in elasticity will be observed and treated. Exercise P8 (A first dynamical problem - The Heat equation) As in the last tutorium we start with a completely given code - this time for the time-dependent heat equation - such that you can adapt to the FEniCS syntax. Download from the lecture homepage the code Heat.py. It solves the following problem: t u - κΔu = f in (0,T ) × Ω u = g on (0,T ) × Ω u = u 0 at {0Ω over the domain Ω = [0, 1] 2 with heat-conductivity κ =0.01, heat-source f = 0, initial condition u 0 = 0 and boundary data of g = ±100 sin(π · y) 2 at the left / right boundary and g = 0 at the top and bottom boundary. The time stepping is performed with the one-step-θ-method from exercise 11). The Paraview-Output with the “warp-by-scalar”-filter (scaled down!) looks as follows: Get familiar with the code, run it and recreate the picture in Paraview. Also watch the heat-field evolve over time in Paraview. 1

Programming tutorial 2

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Programming tutorial 2

Advanced Finite ElementsMA5337 - WS17/18

Programming tutorial 2

The goal of this programming tutorial is to apply the time-integration techniques for parabolicand hyperbolic PDEs from the exercises to the instationary Stokes equation and a problemof dynamical linear elasticity. Also a simple treatment of the nonlinearities arrising in theNavier-Stokes equations will be implemented and the differences between Stokes and Navier-Stokes-equation can be studied on benchmark examples. Finally also the locking phenomenonin elasticity will be observed and treated.

Exercise P8 (A first dynamical problem - The Heat equation)As in the last tutorium we start with a completely given code - this time for the time-dependentheat equation - such that you can adapt to the FEniCS syntax. Download from the lecturehomepage the code Heat.py. It solves the following problem:

∂tu− κ∆u = f in (0, T )× Ωu = g on (0, T )× ∂Ωu = u0 at 0 × Ω

over the domain Ω = [0, 1]2 with heat-conductivity κ = 0.01, heat-source f = 0, initial conditionu0 = 0 and boundary data of g = ±100 sin(π · y)2 at the left / right boundary and g = 0 at thetop and bottom boundary. The time stepping is performed with the one-step-θ-method fromexercise 11). The Paraview-Output with the “warp-by-scalar”-filter (scaled down!) looks asfollows:

Get familiar with the code, run it and recreate the picture in Paraview. Also watch the heat-fieldevolve over time in Paraview.

1

Page 2: Programming tutorial 2

Exercise P9 (Instationary Stokes flow)In this exercise we now want to apply the θ-scheme for time-integration to the instationaryStokes-equation, i.e.:

∂tu− µ∆u+∇p = f in (0, T )× Ω∇ · u = 0 in (0, T )× Ω

u = uD on (0, T )× ΓDu = u0 at 0 × Ω

The geometry is given below in the pictures. The left end is a velocity boundary also calledmain-inlet with a parabolic velocity inflow-profile that is constant in time. The lowest end ofthe configuration is also a velocity boundary called crossflow-inlet. Here the velocity profile istime dependent.

umain-inlet(y) =(−4(y − 1)(y − 2)

0

)ucrossflow-inlet(t) =

(0

0.4 · sin(π · t)

)

The right end of the channel is either a do-nothing boundary or we prescribe p = 0. The remain-ing boundaries are all walls where u = (0, 0)T (no-slip) is prescribed. For the whole simulationf = 0 holds. The initial conditions are (u0, p0) = (0, 0)

Implement the given flow configuration in FEniCS. For the spatial discretization use any stableStokes pairing, for example (and simplicity) the P2 − P0-pairing. For the time discretizationuse the one-step-θ scheme from the exercises with final time T = 10 and 1000 time steps. Fora working syntax of the θ-scheme compare to exercise P8. The only difference is that we nowhave a time dependent boundary condition. This can be handled in the following way:

• In the beginning (before the time loop) where you define the boundary conditions, use:

2

Page 3: Programming tutorial 2

bv_crossflow_inlet = Expression((’0’, ’0.4*sin(DOLFIN_PI*t)’), t=0, degree=2)

• In the time loop, when you want to update the boundary condition to the new time, use:

bv_crossflow_inlet.t = time

Try to recreate the pictures from above with Paraview. Again use the Glyph and Streamtracerfilters to do so. The left column of the pictures shows the flow in a moment, where the crossflowinlet is injecting with maximal intensity into the flow, the right column shows a timepoint whereit is blowing fluid out out of the channel, hence splitting the main stream into the two pipes.

Exercise P10 (From Stokes to Navier-Stokes)We again look at the “backward-facing step”-configuration, that we have already seen in thefirst programming tutorial. We use the same geometry and boundary conditions, but this timewith the instationary Navier-Stokes-equation instead of the stationary Stokes equation.

∂tu+∇u · u− ν∆u+ 1ρ∇p = 1

ρf

∇ · u = 0

For the discretization in space and time, use the same parameters and values as in Exercise P9).The nonlinearity∇u·u can be treated in a lot of different ways rangeing from Newton-methods tofixed-point-iterations, pressure correction schemes etc. For now we will use an explicite methodto treat the nonlinearity, i.e. in every timestep un → un+1 where we actually solve for un+1

and hence also ∇un+1 is actually unknown, we simply use ∇un from the last timestep (which isknown) and treat it like a constant.

Use the same time discretization as in exercise 9) and a mesh-fineness of 32 and run the simu-lation once for ν = 0.1 (left pictures) and then for ν = 0.01 (right pictures). Always use ρ = 1and f = 0. What is the main difference? Also when comparing with the simulation resultsfor Stokes equation from the last tutorial? Explain the behaviour using the mathematical fluidmodel.

3

Page 4: Programming tutorial 2

Exercise P11 (Navier-Stokes-equation - Carman vortex street)

Warning! Might involve quite long computation time!

An other benchmark example of fluid mechanics is the Carman-vortex street. It consists of aflow channel confined by straight walls with the usual in- and outflow conditions but with anobstacle (usually a cylinder or sphere) placed in it.

a) Create a channel geometry of length 1.5 and width 0.41 as well as a cylinder (in 2D acircle) at point (0.2, 0.2)T with diameter D = 0.1 and 60 polygonal points, which yousubtract from the domain as usual in order to let FEniCS know that it is supposed to bean obstacle.

b) At the obstacle prescribe no-slip boundary conditions as on the channel walls. The inflowis again given by a parabolic velocity profile normed to U0.

u =(−23.79536 · U0 · y · (y − 0.41)

0

)

c) Use a density of ρ = 1432.87 and a kinematic viscosity ν = 0.01, which is approximatelythe viscosity of honey or a similar viscous fluid. Set the inflow velocity U0 in such a way,that the Reynolds number Re = U0·D

ν = 200.

d) Use a mesh fineness of 64 and a spatial discretization with the Taylor-Hood element (P2−P1-coupling). In time, simulate a total time of T = 0.25 with 5000 timesteps and θ = 1(of course you can also simulate a shorter final time with less time steps, as long as theratio is the same). No external forces are present, i.e. f = 0 and the initial condition isu(t = 0) = 0, p(t = 0) = 0.

e) Inspect the solution in Paraview and export it as a video by klicking on File –> Saveanimation... . For a reasonable video length / speed, choose 150 fps and leave theother parameters as they are.

f) What happens if you set the Reynolds number to a much higher value like 1000, 100000?Typical values in science and engineering are for example:• Blood flow: 100− 1000• Human swimmer: 105 − 106

• Car: 106 − 108

• Aircraft: 107 − 109

4

Page 5: Programming tutorial 2

Exercise P12 (Linear elasticity - Locking and remedies)Leaving fluid mechanics we now come to a different problem from linear elasticity. We wantto simulate the deformation of a steel-beam, that is clamped on one end, under its own weight.Also we want to do the simulation in a full 3D-setting.

a) Create a regular mesh for a beam of length L = 1 and width and height W = H = 0.2.This can be done with the BoxMesh(Point(0,0,0), Point(L,W,H), ndx, ndy, ndz)command (geometry does not have to be set up before). Use ndx=10, ndy=ndz=3 elementsper direction.

b) As usual set up a finite element space of degree 1 for the vectorial displacement u that wewant to solve for and define the clamped (u = 0) boundary, trial- and test-functions etc.

c) In the present situation the equations of linear elasticity are given by:

Strain-tensor:ε(u) = 1

2(∇u+∇uT

)Stress-tensor:

σ(u) = 2µε(u) + λ(∇ · u)1

Balance-equation (strong form):

−∇ · σ(u) = f in Ωu = 0 on ΓD

⇐⇒ −2µ∇ · ε(u)− λ∇(∇ · u) = f in Ωu = 0 on ΓD

Variational (weak) form:

Find u ∈ H1ΓD

(Ω) such that:

2µ∫

Ωε(u) : ε(v) dΩ + λ

∫Ω

(∇ · u)(∇ · v) dΩ =∫

Ωf · v dΩ ∀v ∈ H1

ΓD(Ω)

It might be helpful to implement the strain and stress tensor as “functions” before you setup the variational problem in FEniCS like for exmaple:

def epsilon(u):return 0.5*(grad(u) + grad(u).T)

Set up the variational form.

d) Solve the variational problem for the following parameters (they are the material param-eters for steel)• f = (0, 0,−g · ρ)T

• µ = E

2(1 + ν)

• λ = νE

(1 + ν)(1− 2ν)

5

Page 6: Programming tutorial 2

• ρ = 7860 kgm3 , g = 9.81m

s2

• Elastic modulus E = 210GPa: It is a measure of stiffness of a material (steel has ahigher E-value than rubber for example)• Poisson-ratio ν = 0.3: Measures the amount of transversal expansion in relation to

the axial compression (a perfect rubber would have ν = 0.5, other usual materialshave a value between 0 and 0.5)

Create Paraview-Plots using the Glyph and Warp-by-Vector-filters and compare to theleft picture below. In order to see anything you have to scale the displacement, which isactually very very small due to the high stiffness of steel, up by a factor of 20000.

e) Repeat the simulation with ν = 0.4999 (right picture). What did you expect, what didyou get?

f) Similar to exercise 2) from sheet 1, where we did this for Darcy’s (Poisson’s) equation, wecan reformulate the pure displacement based version of linear elasticity as a saddle-pointproblem by introducing the solid-pressure (it has nothing to do with a physical pressure,the analogy is w.r.t. to Stokes equation and will be visible in a moment) p = λ∇ · u.Plugging this into the strong form of the balance equation yields:

Saddle-point-form of linear elasticity (strong):

−2µ∇ · ε(u)−∇p = f in Ω

∇ · u = 1λp in Ω

u = 0 on ΓD

Variational (weak) saddle-point-form:

2µ∫

Ωε(u) : ε(v) dΩ +

∫Ωp · ∇ · v dΩ =

∫Ωf · v dΩ ∀v∫

Ω∇ · u · q dΩ = 1

λ

∫Ωp · q dΩ ∀q

Implement this variational saddle-point-form in FEniCS and solve it with any stable Stokespairing, for example the P2−P1-Taylor-Hood-element. Use ndx=30, ndy=ndz=5 elements.How does it behave for ν close to 0.5?

6

Page 7: Programming tutorial 2

g) For any of your elasticity simulations, also implement as a post-processing step (after thesolution is computed) the scalar von Mises reference stress, which is a measure of howmuch stress “in total” is applied to different parts of the geometry. In 3D it is given by:

s :=√

32 ·(σ(u)− 1

3tr (σ(u)) · 1)

:(σ(u)− 1

3tr (σ(u)) · 1)

Exercise P13? (A dynamical elasticity problem)In the last exercise P12) we have seen an example of static elasticity. We computed an equi-librium between internal stresses and constant external forces. Now we want to change thisby applying external forces that vary in time. In fact we will simulate a beam that is at firstdeflected by an external force (similar as before just with a Neumann-surface force instead ofa body force like gravity), then we use this deflected configuration as an initial datum for adynamic calculation, where all external forces suddenly vanish (we let the beam go). The inter-nal stresses - that now lack a counter force - will induce a movement of the beam, which canbe expressed by a second time derivative of the displacement ∂ttu in the equation (Newton’s law).

Dynamic balance equation (strong form):

∂ttu−∇ · σ(u) = 0 in (0, T )× Ωu = 0 on (0, T )× ΓDu = u0 at 0 × Ω

∂tu = u1 at 0 × Ω

⇐⇒ ∂ttu− 2µ∇ · ε(u)− λ∇(∇ · u) = 0 in (0, T )× Ωu = 0 on (0, T )× ΓDu = u0 at 0 × Ω

∂tu = u1 at 0 × Ω

Variational (weak) form:

Find u ∈ H1ΓD

(Ω) such that for a.e. t ∈ (0, T ):∫Ωu · v dΩ + 2µ

∫Ωε(u) : ε(v) dΩ + λ

∫Ω

(∇ · u)(∇ · v) dΩ = 0 ∀v ∈ H1ΓD

(Ω)

You can do the following steps either with the pure displacement formulation or the saddle-point-form of elasticity. For the sake of simplicity of implementing the Newmark-time integrator(at least in a first try) as well as computational time, I would recommend to use the puredisplacement approach.

7

Page 8: Programming tutorial 2

a) At first, solve the static elasticity problem with the material parameter for steel and anexternal surface force of t = (0,−F,−F )T , where F = 200 · 9.81 N

m2 , which is applied asa Neumann-condition at the tip boundary of the beam. Use ndx=30, ndy=ndz=5 linearelements and no body force, i.e. f = (0, 0, 0)T .

Explanation: While a body force like gravity acts on the whole body, a surface force likehere is meant to be only applied on a certain part of the boundary. This simulates forexample a force that is applied by pressing down the steel beam or (like here) by glu-ing/hanging some weight on a part of its surface.

Hint: To implement a Neumann-force proceed as follows:• Define the Neumann boundary where you also define the clamped boundary as

class Right(SubDomain):def inside(self,x,on_boundary):

return on_boundary and near(x[0],1)

• After the mesh is created, define a surface measure via

boundaries = FacetFunction("size_t", mesh)boundaries.set_all(0)rightbound = Right()rightbound.mark(boundaries, 1)ds = ds(subdomain_data = boundaries)

• Don’t forget to add the Neumann part to the variational form as

... + inner(T,y)*ds(1)

b) Use the solution from a) as the initial displacement u0 (assign(u_old, u_sol)) and inter-polate the initial datum u(0) = 0 into the finite element space by v_old = interpolate(Constant((0,0,0)), V).

c) Set up a variational form that can be used to solve the algebraic system of Newmark’smethod in every timestep. Since our dynamic equation does not contain a first derivative,the matrix A from exercise 12) is zero (not present) and external forces are zero, hence thevariational form to set up should resemble the discrete system (M+β∆t2K)·a = −K ·upred,i.e. look like ∫

Ωa · y dΩ + β∆t2

∫Ω∇a : ∇y dΩ = −

∫Ω∇upred : ∇y dΩ

where y is just an other name for the test functions v to not confuse them with thevelocity v = u. In the zeroth time step, i.e. to get an initial value for a you can solve thisvariational problem for β = 0, which is then nothing else but a discrete representation ofthe semi-discrete system M · a+K · u0 = 0.

8

Page 9: Programming tutorial 2

d) In the time-integration you have to update (predict and correct) the coefficient vectors ofthe solutions u_sol, v_sol and a_sol. Those vectors can be accessed via

u_sol.vector()[:]

if you want to write something at it and

u_sol.vector().array()

if you just want to read the data. So for example the predictor step for the displacementcould be implemented as:

u_pred.vector()[:] = u_old.vector().array() + dt*v_old.vector().array() + \pow(dt,2)/2*(1-2*beta)*a_old.vector().array()

e) Use Newmark-parameters γ = 12 , β = 1

4 , final time T = 0.00025 and discretize time by500 degrees of freedom. To speed up the computation, comment out the live plot of thedisplacement. You can look at the results in Paraview later and even save them as a video,where the following pictures are snapshots from. Again use a scaling factor of 20000 inorder to see the small displacements.

9