9
Universit´ e Pierre et Marie Curie Ann´ ee 2014-2015 M2 Math´ ematiques de la Mod´ elisation Theoretical and numerical aspects for incompressible fluids Exercise sessions Instructors: Pascal Frey * , Yannick Privat * The purpose of this exercise session is to give an overview of several aspects of scientific computing through the resolution of a few ‘toy problems’. First, we focus on the solving of an elliptic boundary value problem with the Finite Element Method. In a first part, we focus on the implementation of a very basic PDE model, in order to get the reader to be familiar with FreeFem++ software, which makes it very easy to handle finite element spaces and mesh modifications, within a very few lines of black-box code. Then, we turn to more realistic PDE models from fluid dynamics. Session 1. Getting started with FreeFem++. Throughout this section, Ω R d represents a bounded domain with Lipschitz boundary, f L 2 (Ω) is a source term, and u 0 H 1 2 (Ω) is a boundary prescription. The aim is to find the solution u solving the following so-called Poisson problem : (1) -Δu = f in Ω u = u 0 on Ω Recall that, from the classical Lax-Milgram theory, this problem admits a unique solution u H 1 0 (Ω), which depends continuously on the data f . This problem arises, for instance, in electrostatics, as a link between a free charge den- sity f (up to some constants), and the resulting electric potential field u. Problem (1) enjoys another common physical interpretation, casting u as the steady state of a heat transfer with source term f . This first part is devoted to some numerical considerations over problem (1), using the software Freefem++ [1], a powerful tool for solving boundary value problems with the Finite Element Method. In particular, Freefem++ allows testing a whole lot of strategies to solve (1) within very few lines of code. For the sake of numerical issues, we consider the square (0, 1) × (0, 1) as domain Ω, and we choose f = sin(2πx) sin(2πy) and u 0 = 0; respectively. * UPMC Univ Paris 06, UMR 7598, Laboratoire J.L. Lions, F-75005 Paris, France. The authors would like to acknowledge the valuable help of Charles Dapogny (LJK, Grenoble) in preparing these class notes. 1

Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Universite Pierre et Marie Curie Annee 2014-2015M2 Mathematiques de la Modelisation

Theoretical and numerical aspectsfor incompressible fluids

Exercise sessions

Instructors: Pascal Frey∗, Yannick Privat∗

The purpose of this exercise session is to give an overview of several aspects of scientificcomputing through the resolution of a few ‘toy problems’. First, we focus on the solvingof an elliptic boundary value problem with the Finite Element Method. In a first part, wefocus on the implementation of a very basic PDE model, in order to get the reader to befamiliar with FreeFem++ software, which makes it very easy to handle finite element spacesand mesh modifications, within a very few lines of black-box code. Then, we turn to morerealistic PDE models from fluid dynamics.

Session 1. Getting started with FreeFem++.

Throughout this section, Ω ⊂ Rd represents a bounded domain with Lipschitz boundary,f ∈ L2(Ω) is a source term, and u0 ∈ H

12 (∂Ω) is a boundary prescription. The aim is to find

the solution u solving the following so-called Poisson problem :

(1)

−∆u = f in Ωu = u0 on ∂Ω

Recall that, from the classical Lax-Milgram theory, this problem admits a unique solutionu ∈ H1

0 (Ω), which depends continuously on the data f .

This problem arises, for instance, in electrostatics, as a link between a free charge den-sity f (up to some constants), and the resulting electric potential field u. Problem (1) enjoysanother common physical interpretation, casting u as the steady state of a heat transfer withsource term f .

This first part is devoted to some numerical considerations over problem (1), using thesoftware Freefem++ [1], a powerful tool for solving boundary value problems with the FiniteElement Method. In particular, Freefem++ allows testing a whole lot of strategies to solve(1) within very few lines of code.

For the sake of numerical issues, we consider the square (0, 1) × (0, 1) as domain Ω, andwe choose f = sin(2πx) sin(2πy) and u0 = 0; respectively.

∗ UPMC Univ Paris 06, UMR 7598, Laboratoire J.L. Lions, F-75005 Paris, France.The authors would like to acknowledge the valuable help of Charles Dapogny (LJK, Grenoble) in preparingthese class notes.

1

Page 2: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Question 1 : Define in FreeFem++ the domain Ω, as well as function f , using listing 1

/∗ Border o f the computat iona l domain ∗/border l e f t ( t =0 .0 ,1 .0 ) x = 0 . 0 ; y = 1 .0 −t ; l a b e l = 1 ; ;border bottom ( t =0.0 ,1 .0 ) x = t ; y = 0 . 0 ; l a b e l = 1 ; ;border r i g h t ( t =0 .0 ,1 .0 ) x = 1 . 0 ; y = t ; l a b e l = 1 ; ;border top ( t =0 .0 ,1 .0 ) x = 1.0− t ; y = 1 . 0 ; l a b e l = 1 ; ;

/∗ Create , then d i s p l a y i n i t i a l mesh , wi th 10 nodes on each par t o fthe boundary ∗/

mesh Th = buildmesh ( l e f t (10) + bottom (10) + r i g h t (10) + top ( 1 0 ) ) ;p l o t (Th, wait =1,ps="initial mesh" ) ;

/∗ Source term fo r Poisson equat ion ∗/func f = s i n ( 2 . 0∗ pi ∗x )∗ s i n ( 2 . 0∗ pi ∗y ) ;

Listing 1. Definition of the data with FreeFem++

Question 2 :

• Write the variational formulation associated to problem (1).• In FreeFem++, introduce a finite element space associated to the mesh defined at

question 1. The definition of a finite element space Vh, associated to a mesh Th, istriggered by the command

fespace Vh(Th,typeelt);

where typeelt is the type of the desired finite element ; e.g. typeelt = P1, P2,...

for Lagrange-type finite elements, but many other choices are possible.

A typical finite element problem - under variational form - is defined in FreeFem++

through the command

problem

nameProblem( uh, vh︸ ︷︷ ︸solution and unknown ∈Vh

, solver = CG︸ ︷︷ ︸type of solver

, eps = 1.0e− 6)︸ ︷︷ ︸precision parameter

=

int2d(Th)(dx(uh)*dx(vh) ...))︸ ︷︷ ︸Left-hand side of variational formula

-

int2d(Th)( ...))︸ ︷︷ ︸Right-hand side of variational formula

+ on(1,uh=0.0)︸ ︷︷ ︸boundary conditions on part labelled 1

;

Such a problem is then solved by simply calling its name as a command :

nameProblem ;

• What do you observe ? Does the problem seem properly solved ?2

Page 3: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Question 3 : For increased accuracy in the computation, the most intuitive idea would beto refine the computational mesh Th. Try solving the same problem, with the same datafunction f , but with different mesh sizes. Does this work out ? Run similar tests with datafunctions f showing sharper variations, e.g. functions of the form

f(x, y) = sin(mπx) sin(nπy), m, n ∈ N.

Question 4 : Actually, there is no realistic way to guess a priori what would be the idealsize of a mesh Th that would enable a proper resolution of a problem such as (1), from thesole knowledge of the data f . Hence the need for mesh adaptation.

The basic principle of mesh adaptation is to start from a coarse mesh, on which the problemat stake is rather poorly solved (but at a very low CPU cost), and to iteratively infer fromincreasingly refined meshes and accurate solutions (at still low CPU cost) a ‘good’ mesh,adapted to the solution of the particular problem under consideration (that is, the nodes areconcentrated only in the areas where enhanced accuracy is required).

(a) (b)

(c) (d)

Figure 1. (a) Initial mesh (143 points), (b) the associated solution (the am-plitude is altogether wrong, although it is not displayed on the figure), (c)adapted mesh, after 5 iterations (≈ 1000 points), (d) the associated solution.

3

Page 4: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

In FreeFem++, there exists a (rather sophisticated) command

Th = adaptmesh(Th,uh,tol);

which proceeds to the adaptation of a mesh Th, with respect to the variations of a functionuh defined on it, up to a tolerance tol.

Write a loop, which proceeds to the adaptation of the coarse initial mesh of question 1into a mesh amenable to the resolution of problem (1). Usually, the process converges in 4-5iterations.

Session 2. The heat equation.

We now turn to the resolution of the heat equation, which is nothing but the time-dependent version of the previous model. Let Ω ⊂ R2 a bounded domain with Lipschitzboundary, filled with a material of thermal conductivity α > 0, and heated with a sourcef ∈ L2(Ω). The temperature distribution at the initial time is described by a functionu0 ∈ H1(Ω). Ω is surrounded by another material with fixed temperature, which is set to 0for simplicity, so that temperature 0 is imposed at the boundary ∂Ω at any time.

The temperature at time t (0 ≤ t ≤ T ) in Ω is then solution to the following equation:

(2)

∂u

∂t(t, x)− α∆u(t, x) = f(x) for (t, x) ∈ (0, T )× Ω

u(t = 0, x) = u0(x) for x ∈ Ωu(t, x) = 0 for t ∈ (0, T ), x ∈ ∂Ω

.

Question 1: Write down the variational formulation for (2), at the continuous level in spaceand time (i.e. the time derivative in (2) is not yet discretized). This is achieved by:

(1) identifying the functional space V to which each function u(t, .) should belong to,(2) multiplying the first equality in (2) by a (time-independent) function v ∈ V ,(3) performing integration by parts where it is needed to end with formulae as close as

possible to those of section I..

Question 2: The sequence t 7→ u(t, .) is approximated by a series of functions un(x) ≈u(tn, x) ∈ V , where 0 < t0 < ... < tN = T is a subdivision of the time interval (0, T ), withtime step ∆t: tn = n∆t, n = 0, ..., N . Choose a finite difference discretization for ∂u

∂t(tn, .)

in terms of un−1, un, un+1. Note that several choices may be possible.

Question 3: Derive the discrete-in-time, space-continuous variational formulation for eachfunction un (involving un−1, ...).

4

Page 5: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Question 4: In this example (see 2), the domain Ω is the rectangle (0, 2)× (0, 1), and thefinal time is T = 5. The thermal conductivity of the considered material is α = 0.1, thesource f is concentrated in a small ball around point p1 = (0.5, 0.75) of the domain:

f(x) =

1 if ||x− p1||< 0.120 otherwise

,

and the initial distribution of temperature u0 inside Ω is given by:

u0(x) =

100(0.2− ||x− p2||) if ||x− p2||< 0.2

0 otherwise,

where p2 = (1.5, 0.25).

1

2

Ωp1•

p2•

Figure 2. Initial and boundary conditions for the proposed test case for thenumerical resolution of the heat equation (2).

Implement the variational formulation of question 3. into FreeFem++, and run several tests:

• using different kinds of finite elements for the approximation of functions un, n =0, ..., N (e.g. P1, P2 Lagrange finite elements).• using various finite difference approximations of the time-derivative ∂u

∂t(see question

2.).• using different values for the time ∆t.• acting on the mesh of the domain (for instance, try to use the mesh adaptation

technique presented in Section I at some iterations of the process).

What do you observe ? What is the influence of these different ways of tackling the problem ?

5

Page 6: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Session 3. The stationary Stokes equations.

In this section, we are interested in the stationary Stokes equations, posed in a domainΩ ⊂ R2 with Lipschitz boundary: a fluid with dynamic viscosity ν occupying Ω is describedby its velocity u : Ω→ R2, and pressure field p : Ω→ R2, which satisfy the system:

(3)

−ν∆u(x) +∇p(x) = f(x) for x ∈ Ωdiv u(x) = 0 for x ∈ Ωu(x) = ud for x ∈ ∂Ω

,

where ud is a prescribed velocity field on ∂Ω, and f is a source term.

Question 1: Write down the variational formulation associated to equation (3).

Consider, in FreeFem++, the classical lid driven cavity for Stokes problem: Ω is the unitsquare (0, 1) × (0, 1), filled with a fluid of unit dynamic viscosity: ν = 1. The imposedvelocity field ud on ∂Ω is:

∀x ∈ ∂Ω, ud(x) =

(1, 0) if x lies on the upper part of ∂Ω(0, 0) otherwise

,

and the source term is set to f = 0.We are interested in a particular form for the meshes of Ω, that of a Cartesian grid split

into triangles. In FreeFem++, such a mesh Th is generated using the following command:

Th = square(50, 50);

Using this command, the labels of the boundary ∂Ω are automatically set as depicted infigure 3.

1

2

3

4

Figure 3. A particular mesh of the unit square, and the boundary labels gen-erated by the FreeFem++ command square.

6

Page 7: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

Question 2: Implement the variational formulation of question 1. in FreeFem++, using P2

Lagrange finite elements for discretizing the velocity u, and P1 elements for the pressure.

Hint: use the penalization method (seen in the theoretical part of the course) to bring backthe variational formulation of question 1. to a ‘classical’ variational formulation over thecouple (u, p).

Question 3: Try out other pairs of finite elements for discretizing (u, p), and notably thepairs P1 × P0, and bubble-P1 × P0. Does the method always produce the ‘correct’ solutionto the system ? Why is that so, according to you ?

Session 4. The unsteady Stokes equations.

We are now getting closer and closer to realistic models; let us now consider the transientmodel associated to Stokes equations (3). A fluid, whose density is set to ρ = 1 for simplicity,with dynamic viscosity ν, is occupying a domain Ω, and is described by means of its (time-dependent) velocity field u(t, x) and pressure field p(t, x) all along a period of time 0, T ).

The initial state of the fluid is known, that is, u(t = 0, .) = u0, and p(t = 0, .) = p0are given. Mixed boundary conditions are considered, that is, ∂Ω is decomposed into twocomplimentary parts ΓD and ΓN . The velocity u(t, .) = ud is prescribed at every time onΓD, and an external stress g is exerted on ΓN , so that the system is driven by the system ofequations:

(4)

∂u∂t

(t, x)− ν∆u(t, x) +∇p(t, x) = f(t, x) for (t, x) ∈ (0, T )× Ωdiv u(t, x) = 0 for (t, x) ∈ (0, T )× Ωu(t, x) = ud(x) for t ∈ (0, T ) and x ∈ ΓD

ν ∂u∂n

(t, x)− p(t, x) · n(x) = g(t, x) for t ∈ (0, T ) and x ∈ ΓN

u(0, x) = u0(x) for x ∈ Ω

,

Question 1: Write down the variational formulation associated to system (4).

We now consider the benchmark obstacle test case, described in figure 4: on the left (blue)part of the boundary, a parabolic profile is imposed for the velocity: ud(x) = 4y(1 − y),whereas on the remainder of the Dirichlet boundary (in black), homogeneous Dirichlet bound-ary conditions are imposed: ud(x) = 0. Eventually, the right, red part corresponds to theNeumann part ΓN of the boundary, and no stress is applied: g = 0. Similarly, no body forcesare applied: f = 0.

The other parameters for the computation are: ν = 0.005, T = 40 and

∀x ∈ Ω, u0(x) =

(4y(1− y), 0) if x lies on blue part of ∂Ω

(0, 0) otherwise,

Question 2: Implement the previous variational formulation in FreeFem++. Once again,try different combinations of finite element spaces for the velocity and pressure fields, aswell as different discretizations of the time derivative ∂u

∂t. You may also try using the mesh

adaptation function described in section 1 to reach a higher quality result.

7

Page 8: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

1

5

0.2

0.2

0.4

0.4

Ω

0

Figure 4. The obstacle test case for the unsteady Stokes system.

Session 5. The Navier-Stokes equations.

We now come to the central model in this course, namely that of Navier-Stokes equations,which is a more realistic description of the motion of an incompressible fluid than that ofthe mere Stokes equations. Using the exact same notations as in the previous section, theycharacterize the couple velocity-pressure (u, p) of an incompressible fluid as the solution to:(5)

∂u∂t

(t, x) + u.∇u(t, x)− ν∆u(t, x) +∇p(t, x) = f(t, x) for (t, x) ∈ (0, T )× Ωdiv u(t, x) = 0 for (t, x) ∈ (0, T )× Ωu(t, x) = ud(x) for t ∈ (0, T ) and x ∈ ΓD

ν ∂u∂n

(t, x)− p(t, x) · n(x) = g(t, x) for t ∈ (0, T ) and x ∈ ΓN

u(0, x) = u0(x) for x ∈ Ω

.

The main difference between Stokes and Navier-Stokes equations lies in the nonlinear con-vective term u.∇u, induced by the acceleration of the fluid. This term can be neglected whenthe velocity of the fluid is low when compared to the viscous forces, but may become dom-inant in the high-velocity regime, in which the Stokes approximation becomes dramaticallyrough. This term is also the main cause of the difficulties in the theoretical and numericaltreatments of Navier-Stokes equations.

In this section, we propose to solve equation (5) using the method of characteristics fordealing with the (difficult) convective term.

If x0 ∈ Ω, and t0 ∈ T , denote as t 7→ X(t, t0, x0) the characteristic curve passing at x0 attime t = t0, solution to the ordinary differential equation:

∀t ∈ (0, T ), X(t, t0, x0) = u(t,X(t, t0, x0))X(t0, t0, x0) = x0

,

which is nothing but the trajectory of a fluid particle located at x0 at time t0. Then, onecan see that:

d

dt(u(t,X(t, t0, x0)) =

(∂u

∂t+ u.∇u

)(t,X(t, t0, x0)),

meaning that the convective term is the time derivative of u along the trajectories of the fluidparticles, in other terms the dynamic acceleration of the fluid. According to this remark,the following finite difference approximation can be proposed for the convective term (with

8

Page 9: Theoretical and numerical aspects for incompressible uidsfrey/cours/UPMC/NM... · Universit e Pierre et Marie Curie Ann ee 2014-2015 M2 Math ematiques de la Mod elisation Theoretical

obvious notations):(∂u

∂t+ u.∇u

)(tn, x) ≈ un(x)− un−1(X(tn−1, tn, x))

∆t

Now, in the course of an iterative computation, if un−1 is available, one only has to evaluatethe term un−1(X(tn−1, tn, x)). This can be achieved in FreeFem++ using the convect com-mand (see listing 2).

Vh ux , uy ; // components o f the v e l o c i t y f i e l dr e a l dt = 0 . 0 5 ; // time s t ep

Vh f , g ; // f= s ca l a r quan t i t y to be convected , g = r e s u l t i n g quan t i t y

g = convect ( [ ux , uy] ,−dt , f ) ; // s i gn − i n d i c a t e s back t rack ing o f the// c h a r a c t e r i s t i c curves

Listing 2. Backtracking a characteristic curve in FreeFem++

Consider the step test case, depicted in figure 5.

0

1

0.52

20

Figure 5. The step test case for the Navier-Stokes equations.

Here, T = 40, ν = 0.005, and the boundary conditions are exactly those of the previousexample, and the initial velocity field is given by:

∀x ∈ Ω, u0(x) =

(4y(1− y), 0) if x < 2

(0, 0) otherwise.

Question: Implement the Navier-Stokes model in FreeFem++, relying on the method ofcharacteristics for the discretization of the convective term.

Remark Numerous different techniques exist for the solution of the Navier-Stokes equations,among which Chorin-Temam’s projection method, and Newton’s method (seen during thetheoretical part of the course). At this point, you should have all the required knowledgeabout FreeFem++ for programming them !

References

[1] O. Pironneau, F. Hecht, A. Le Hyaric and J. Morice, FreeFem++ version 3.19-1 (2d and 3d),http://www.freefem.org/ff++

[2] P.J. Frey and P.L. George, Mesh Generation : Application to Finite Elements, Wiley, 2nd Edition,(2008).

9