• Aucun résultat trouvé

Efficient C++ finite element computing with Rheolef : volume 2: discontinuous Galerkin methods

N/A
N/A
Protected

Academic year: 2021

Partager "Efficient C++ finite element computing with Rheolef : volume 2: discontinuous Galerkin methods"

Copied!
67
0
0

Texte intégral

(1)

HAL Id: cel-00863021

https://cel.archives-ouvertes.fr/cel-00863021v3

Submitted on 3 Jun 2016

HAL is a multi-disciplinary open access

archive for the deposit and dissemination of

sci-entific research documents, whether they are

pub-lished or not. The documents may come from

teaching and research institutions in France or

abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est

destinée au dépôt et à la diffusion de documents

scientifiques de niveau recherche, publiés ou non,

émanant des établissements d’enseignement et de

recherche français ou étrangers, des laboratoires

publics ou privés.

volume 2: discontinuous Galerkin methods

Pierre Saramito

To cite this version:

Pierre Saramito. Efficient C++ finite element computing with Rheolef : volume 2: discontinuous

Galerkin methods. DEA. Grenoble, France, France. 2015, pp.56. �cel-00863021v3�

(2)

computing with Rheolef

volume 2:

discontinuous Galerkin methods

Pierre Saramito

version 6.7 update 24 March 2016

0

0.5

1

0

0.5

1

h = 1/20

x

φ(x)

φ

h

(x)

Re = 10 000

(3)

GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

(4)

Notations 2

I

Getting started with simple problems

5

1 Scalar first-order problems 7

1.1 The transport equation . . . 7

1.2 Nonlinear scalar hyperbolic problems . . . 10

1.3 Example: the Burgers equation . . . 14

2 Scalar second-order problems 21 2.1 The Poisson problem with Dirichlet boundary conditions. . . 21

2.2 The Helmholtz problem with Neumann boundary conditions. . . 23

2.3 Nonlinear scalar hyperbolic problems with diffusion. . . 25

2.4 Example: the Burgers equation with diffusion . . . 25

II

Fluids and solids computations

31

3 The linear elasticity and the Stokes problems 33 3.1 The linear elasticity problem . . . 33

3.2 The Stokes problem . . . 35

3.3 The stationnary Navier-Stokes problem . . . 37

III

Technical appendices

53

A GNU Free Documentation License 55

List of example files 62

List of commands 64

Index 64

(5)

Notations

Rheolef mathematics description

d d∈ {1, 2, 3} dimension of the physical space

dot(u,v) u.v =

d−1

X

i=0

uivi vector scalar product

ddot(sigma,tau) σ : τ =

d−1

X

i,j=0

σi,jτi,j tensor scalar product

tr(sigma) tr(σ) =

d−1

X

i=0

σi,i trace of a tensor

trans(sigma) σT tensor transposition

sqr(phi) norm2(phi) φ 2 square of a scalar norm2(u) |u|2= d−1 X i=0 u2

i square of the vector norm

norm2(sigma) |σ|2=

d−1

X

i,j=0

σ2

i,j square of the tensor norm

abs(phi)

norm(phi) |φ| absolute value of a scalar

norm(u) |u| = d−1 X i=0 u2 i !1/2 vector norm norm(sigma) |σ| =   d−1 X i,j=0 σ2 i,j   1/2 tensor norm grad(phi) ∇φ =  ∂φ ∂xi  06i<d

gradient of a scalar field in Ω⊂ Rd

grad(u) ∇u =  ∂ui ∂xj  06i,j<d

gradient of a vector field

div(u) div(u) = tr(∇u) =

d−1

X

i=0

∂ui

∂xi

divergence of a vector field

D(u) D(u) = ∇u + ∇uT/2 symmetric part of

the gradient of a vector field curl(u) curl(u) =∇ ∧ u curl of a vector field, whend = 3

curl(phi) curl(φ) = ∂φ ∂x1 ,∂φ ∂x0 

curl of a scalar field, when d = 2

curl(u) curl(u) = ∂u1 ∂x0 −

∂u0

∂x1

curl of a vector field, whend = 2

grad_s(phi) ∇sφ = P∇φ

(6)

Rheolef mathematics description

grad_s(u) su=∇uP tangential gradient of a vector

Ds(u) Ds(u) = P D(u)P symmetrized tangential gradient

div_s(u) divs(u) = tr(Ds(u)) tangential divergence

unit outward normal onΓ = ∂Ω

normal() n or on an oriented surfaceΩ

or on an internal oriented sideS jump(phi) [[φ]] = φ|K0− φ|K1 jump accros inter-element side

S = ∂K0∩ K1

average(phi) {{φ}} = (φ|K0+ φ|K1)/2 average accross S

inner(phi) φ|K0 inner trace on S

outer(phi) φ|K1 outer trace on S

h_local() hK= meas(K)1/d length scale on an elementK

penalty() $s= max meas(∂K 0) meas(K0) , meas(∂K1) meas(K1)  penalty coefficient onS

grad_h(phi) (∇hφ)|K=∇(φ|K),∀K ∈ Th broken gradient

div_h(u) (divhu)|K= div(u|K),∀K ∈ Th broken divergence of a vector field

Dh(u) (Dh(u))|K= D(u|K),∀K ∈ Th broken symmetric part of

the gradient of a vector field

sin(phi) sin(φ) standard mathematical functions

cos(phi) cos(φ) extended to scalar fields

tan(phi) tan(φ) acos(phi) cos−1(φ) asin(phi) sin−1(φ) atan(phi) tan−1(φ) cosh(phi) cosh(φ) sinh(phi) sinh(φ) tanh(phi) tanh(φ) exp(phi) exp(φ) log(phi) log(φ) log10(phi) log 10(φ)

floor(phi) bφc largest integral not greater thanφ

ceil(phi) dφe smallest integral not less thanφ

(7)

Rheolef mathematics description max(phi,psi) max(φ, ψ)

pow(phi,psi) φψ

atan2(phi,psi) tan−1(ψ/φ)

fmod(phi,psi) φ− bφ/ψ + 1/2c ψ floating point remainder

compose(f,phi) f◦ φ = f(φ) applies an unary functionf

compose(f,phi1,...,phin) f (φ1, . . . , φn) applies a n-ary function f , n > 1

(8)

Getting started with simple

problems

(9)
(10)

Scalar first-order problems

The aim of this chapter is to introduce to discontinuous Galerkin methods within the Rheolef environment. For some recent presentations of discontinuous Galerkin methods, see [11] for theo-retical aspects and [16] for algorithmic and implementation. The discontinuous Galerkin methods are in active development in Rheolef, and new features will appear soon.

1.1

The transport equation

The steady scalar transport problem writes: (P ): find φ, defined in Ω, such that

u.∇φ + σφ = f in Ω φ = φΓ on∂Ω−

where u, σ > 0, f and φΓ being known. Notice that this is the steady version of the unsteady

diffusion-convection problem previously introduced in section6.2, page86and when the diffusion coefficientν vanishes. Here, the ∂Ω− notation is the upstream boundary part, defined by

∂Ω−={x ∈ ∂Ω; u(x).n(x) < 0}

Let us suppose that u∈ W1,∞(Ω)d and introduce the space:

X ={ϕ ∈ L2

(Ω); (u.∇)ϕ ∈ L2

(Ω)d} and, for allφ, ϕ∈ X

a(φ, ϕ) = Z Ω (u.∇φ ϕ + σ φ ϕ) dx + Z ∂Ω max (0,−u.n) φ ϕ ds l(ϕ) = Z Ω f ϕ dx + Z ∂Ω max (0,−u.n) φΓϕ ds

Then, the variational formulation writes: (F V ): find φ∈ X such that

a(φ, ϕ) = l(ϕ), ∀ϕ ∈ X

Notice that the termmax(0,−u.n) = (|u.n| − u.n)/2 is positive and vanishes everywhere except on∂Ω−. Thus, the boundary conditionφ = φΓis weakly imposed on∂Ω− via the integrals on the

boundary. The discontinuous finite element space is defined by: Xh={ϕh∈ L2(Ω); ϕh|K ∈ Pk, ∀K ∈ Th}

(11)

wherek > 0 is the polynomial degree. Notice that Xh6⊂ X and that the ∇φh term has no more

sense for discontinous functionsφh∈ Xh. Following [11, p. 14], we introduce the broken gradient

∇h as a convenient notation: (hφh)|K=∇(φh|K), ∀K ∈ Th Thus Z Ω u.∇hφhϕhdx = X K∈Th Z K u.∇φhϕhdx, ∀φh, ϕh∈ Xh

This leads to a discrete version ah of the bilinear form a, defined for all φh, ϕh ∈ Xh by (see

e.g. [11, p. 57], eqn. (2.34)): ah(φh, ϕh) = Z Ω (u.hφhϕh+ σφh ϕh) dx + Z ∂Ω max (0,−u.n) φhϕhds + X S∈Sh(i) Z S  − u.n [[φh]]{{ϕh}} + α 2|u.n| [[φh]] [[ϕh]]  ds

The last term involves a sum overSh(i), the set of internal sides of the meshTh. Each internal side

K+ S K n = n−=−n+ on S n− n+ φ−h φ+h

Figure 1.1: Discontinuous Galerkin method: an internal side, its two neighbor elements and their opposite normals.

S ∈ Sh(i) has two possible orientations: one is choosen definitively. In practice, this orientation

is defined in the ‘.geo’ file containing the mesh, where all sides are listed, together with their orientation. Let n the normal to the oriented side S: as S is an internal side, there exists two elements K− and K+ such that S = ∂K− ∩ ∂K+ and n is the outward unit normal of K− on

∂K−∩ S and the inward unit normal of K+ on∂K+∩ S, as shown on Fig.1.1. For allφh∈ Xh,

recall that φh is in general discontinuous accross the internal side S. We define on S the inner

value φ−h = φh|K− of φh as the restriction φh|K− of φh in K− along ∂K− ∩ S. Conversely, we

define the outer value φ+

h = φh|K+. We also denote on S the jump [[φh]] = φ

− h − φ + h and the average{{φh}} = (φ−h + φ +

h)/2. The last term in the definition of ah is ponderated by a coefficient

α > 0. Choosing α = 0 correspond to the so-called centered flux approximation, while α = 1 is the upwinding flux approximation. The caseα = 1 and k = 0 (piecewise constant approximation) leads to the popular upwinding finite volume scheme. Finally, the discrete variational formulation writes:

(F V )h: find φh∈ Xh such that

ah(φh, ϕh) = l(ϕh), ∀ϕh∈ Xh

(12)

Example file 1.1: transport_dg.cc

1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ;

4 int m a i n (int argc , c h a r** a r g v ) { 5 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 6 geo o m e g a ( ar g v [ 1 ] ) ; 7 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 8 F l o a t a l p h a = ( a r g c > 3) ? a t o f ( a r g v [ 3 ] ) : 1; 9 F l o a t s i g m a = ( a r g c > 4) ? a t o f ( a r g v [ 4 ] ) : 3; 10 p o i n t u (1 ,0 ,0); 11 t r i a l phi ( Xh ); t e s t psi ( Xh );

12 f o r m ah = i n t e g r a t e ( dot ( u , g r a d _ h ( phi ))* psi + s i g m a * phi * psi )

13 + i n t e g r a t e (" b o u n d a r y ", max (0 , - dot ( u , n o r m a l ( ) ) ) * phi * psi ) 14 + i n t e g r a t e (" i n t e r n a l _ s i d e s ",

15 - dot ( u , n o r m a l ( ) ) * j u m p ( phi )* a v e r a g e ( psi )

16 + 0 . 5 * a l p h a * abs ( dot ( u , n o r m a l ( ) ) ) * j u m p ( phi )* j u m p ( psi )); 17 f i e l d lh = i n t e g r a t e (" b o u n d a r y ", max (0 , - dot ( u , n o r m a l ( ) ) ) * psi ); 18 s o l v e r sah ( ah . uu ( ) ) ; 19 f i e l d p h i _ h ( Xh ); 20 p h i _ h . s e t _ u () = sah . s o l v e ( lh . u ( ) ) ; 21 d o u t < < c a t c h m a r k(" s i g m a ") < < s i g m a < < en d l 22 < < c a t c h m a r k(" phi ") < < p h i _ h ; 23 }

Comments

The data areφγ = 1 and u = (1, 0, 0), and then the exact solution is known: φ(x) = exp(−σx0).

The numerical tests are running withσ = 3 by default. The one-dimensional case writes: make transport_dg

mkgeo_grid -e 10 > line.geo ./transport_dg line P0 | field ./transport_dg line P1d | field ./transport_dg line P2d | field

-Observe the jumps accross elements: these jumps decreases with mesh refinement or when poly-nomial approximation increases. The two-dimensional case writes:

mkgeo_grid -t 10 > square.geo

./transport_dg square P0 | field elevation ./transport_dg square P1d | field elevation ./transport_dg square P2d | field elevation

-The elevation view shows details on inter-element jumps. Finaly, the three-dimensional case writes: mkgeo_grid -T 5 > cube.geo

./transport_dg cube P0 | field ./transport_dg cube P1d | field ./transport_dg cube P2d | field

-Fig.1.2plots the solution whend = 1 and k = 0: observe that the boundary condition φ = 1 at x0= 0 is only weakly satified. It means that the approximation φh(0) tends to 1 when h tnds to

zero. Fig. 1.3 plots the errorφ− φh in L2 andL∞ norms: these errors behave asO hk+1

 for allk > 0, which is optimal. A theoreticalO hk+1/2error bound was shown in [17]. The present

numerical results confirm that these theoretical error bounds can be improved for some families of meshes, as pointed out by Richter [19], that showed aO hk+1optimal bound for the transport

problem. This result was recently extended by Cockburn et al. [6], while Peterson [18] showed that the estimateO hk+1/2is sharp for general families of quasi-uniform meshes.

(13)

0 0.5 1 0 0.5 1 h = 1/20 x φ(x) φh(x) 0 0.5 1 0 0.5 1 h = 1/40 x φ(x) φh(x)

Figure 1.2: The discontinuous Galerkin method for the transport problem whenk = 0 and d = 1.

10−15 10−10 10−5 1 10−2 10−1 kφ − φhkL2 1 = k + 1 5 = k + 1 h k = 0 k = 1 k = 2 k = 3 k = 4 10−15 10−10 10−5 1 10−2 10−1 kφ − φhkL∞ 1 = k + 1 5 = k + 1 h k = 0 k = 1 k = 2 k = 3 k = 4

Figure 1.3: The discontinuous Galerkin method for the transport problem: convergence when d = 2.

1.2

Nonlinear scalar hyperbolic problems

The aim of this paragraph is to study the discontinuous Galerkin discretization of scalar nonlinear hyperbolic equations. This section presents the general framework and discretization tools while the next section illustrates the method for the Burgers equation.

1.2.1

Problem setting

A time-dependent nonlinear hyperbolic problem writes in general form [11, p. 99]: (P ): find u, defined in ]0, T [×Ω, such that

∂u

∂t + div f (u) = 0 in ]0, T [×Ω (1.1a)

u(t = 0) = u0 inΩ (1.1b)

f(u).n = Φ(n; u, g) on ]0, T [×∂Ω (1.1c) whereT > 0, Ω⊂ Rd,d = 1, 2, 3 and the initial condition u

0being known. As usual, n denotes the

(14)

to be continuously differentiable. The initial data u0, defined in Ω, and the boundary one, g,

defined on ∂Ω are given. The function Φ, called the Godunov flux associated to f , is defined, for allν∈ Rd anda, b ∈ R, by Φ(ν; a, b) =    min v∈[a,b] f(v).ν whena 6 b max v∈[b,a] f(v).ν otherwise (1.1d)

1.2.2

Space discretization

In this section, we consider first the semi-discretization with respect to space while the problem remains continuous with respect to time. The semi-discrete problem writes in variational form [11, p. 100]:

(P )h: find uh∈ C1([0, T ], Xh) such that

Z Ω ∂uh ∂t vhdx− Z Ω f(uh).∇hvhdx + X S∈Sh(i) Φ(n; u−h, u + h)[[vh]] ds + Z ∂Ω Φ(n; uh, g)vhds = 0, ∀vh∈ Xh uh(t = 0) = πh(u0)

whereπhdenotes the Lagrange interpolation operator onXhand others notations has been

intro-duced in the previous section.

For convenience, we introduce the discrete operatorGh, defined for alluh, vh∈ Xh by

Z Ω Gh(uh)vhdx =− Z Ω f(uh).∇hvhdx + X S∈Sh(i) Z S Φ(n; u−h, u+ h)[[vh]] ds + Z ∂Ω Φ(n; uh, g)vhds(1.2)

For a givenuh∈ Xh, we also define the linear formgh as

g(vh) =

Z

Gh(uh)vhdx

As the matrix M , representing the L2 scalar product in X

h, is block-diagonal, it can be easily

inverted at the element level, and for a given uh ∈ Xh, we have G(uh) = M−1gh. Then, the

problem writes equivalently as a set of coupled nonlinear ordinary differential equations. (P )h: find uh∈ C1([0, T ], Xh) such that

∂uh

∂t + Gh(uh) = 0

1.2.3

Time discretization

Let∆t > 0 be the time step. The previous nonlinear ordinary differential equations are discretized by using a specific explicit Runge-Kutta with intermediates states [13,14,22]. This specific variant of the usual Runge-Kutta scheme, called strong stability preserving, is suitable for avoiding possible spurious oscillations of the approximate solution when the exact solution has a poor regularity. Let un

h denotes the approximation of uh at time tn = n∆t, n > 0. Then un+1h is defined by

recurrence: un,0h = un h un,ih = i−1 X j=0 αi,jun,jh − ∆t βi,jGh  un,jh  , 1 6 i 6 p un+1 h = u n,p h

(15)

where the coefficients satisfy αi,j > 0 and βi,j > 0 for all 1 6 i 6 p and 0 6 j 6 i− 1, and

Pi−1

j=0αi,j= 1 for all 1 6 i 6 p. Notice that when p = 1 this scheme coincides with the usual

explicit Euler scheme. For a generalp > 1 order scheme, there are p− 1 intermediate states un,ih ,

i = 1 . . . p− 1. Computation of the coefficients αi,jandβi,j can be founded in [13,14,22] and are

grouped in file ‘runge_kutta_ssp.icc’ of the examples directory for convenience.

1.2.4

Slope limiters

Slope limiters are required when the solution develops discontinuities: this is a very classical feature of most solutions of nonlinear hyperbolic equations. A preliminary version of the slope limiter proposed by Cocburn et al. [5, p. 208] is implemented in Rheolef:Âăthis preliminary version only supports the d = 1 dimension and k = 1 polynomial degree. Recall that the k = 0 case do not need any limiter. More general implementation will support thed = 2, 3 and k > 2 cases in the future. The details of the limiter implementation is presented in this section: the impatient reader, who is interested by applications, can jump to the next section, devoted to the Burgers equation. K K2 xK0 xS0 K1 K0 xK xK1 xK2 J(0, 1) = 1

Figure 1.4: Limiter: the neighbors elements and the middle edge points.

Fig.1.4shows thed+1 neighbor elements Ki,i = 0 . . . d around an element d. Let Si= ∂K∩∂Ki,

i = 0 . . . d be the i-th side of K. We denote by xK,xKi adxSi the barycenters of these elements

and sides, i = 0 . . . d. When d = 2, the barycenter xSi of the edge belongs to the interior of a

triangle(xK, xKi, xKJi,1) for exactly one of the two possible Ji,16= i and 0 6 Ji,16 d. When d = 3,

the barycenter xSi of the face belongs to the interior of a tetrahedron(xK, xKi, xKJi,1, xKJi,2)

for exactly one pair(Ji,1, Ji,2), up to a permutation, of the three possible pairs Ji,1, Ji,2 6= i and

0 6 Ji,1, Ji,2 6 d. Let us denote Ji,0 = i. Then, the vector −−−−→xKxSi decompose on the basis

(−−−−−−→xKxKJi,k)06k6d−1 as −−−−→ xKxSi = d−1 X k=0 αi,k−−−−−−→xKxKJi,k (1.3)

where αi,k > 0, k = 0 . . . d− 1. Let us consider now the patch ωK composed of K and its d

neighbors:

(16)

For any affine functionξ∈ P1(ωK) over this patch, let us denote δK,i(ξ) = d−1 X k=0 αi,k  ξ(xKJi,k)− ξ(xK)  , i = 0 . . . d− 1 = ξ(xSi)− ξ(xK) from (1.3)

In other terms,δK,i(ξ) represents the departure of the value of ξ at xSi from its average ξ(xK on

the elementK.

Let now(ϕi)06i6d−1denote the Lagrangian basis inK associated to the set of nodes (xSi)06i6d−1:

ϕi(xSj) = δi,j, 0 6 i, j 6 d− 1

d−1

X

i=0

ϕi(x) = 1, ∀x ∈ K

The affine functionξ∈ P1(ωK) expresses on this basis as

ξ(x) = ξ(xK) + d−1

X

i=0

δK,i(ξ) ϕi(x), ∀x ∈ K

Let nowuh∈ P1d(Th). On any element K∈ Th, let us introduce its average value:

¯ uK = 1 meas(K) Z K uh(x) dx

and its departure from its average value: ˜

uK(x) = uh|K(x)− ¯uK, ∀x ∈ K

Notice thatuh6∈ P1(ωK). Let us extends δK,i touh as

δK,i(uh) = d−1 X k=0 αi,k  ¯ uKJi,k − ¯uK  , i = 0 . . . d− 1

Since uh 6∈ P1(ωK), we have ˜uK(xKJi,k)6= δK,i(uh) in general. The idea is then to capture

oscillations by controlling the departure of the valuesu˜K(xKJi,k) from the values δK,i(uh). Thus,

associate touh∈ P1d(Th) the quantities

∆K,i(uh) = minmodTVB

 ˜

uK(xKJi,k), θδK,i(uh)

 for alli = 0 . . . d− 1 and where θ > 1 is a parameter of the limiter and

minmodTVB(a, b) =



a when|a| 6 Mh2

minmod(a, b) otherwise

where M > 0 is a tunable parameter which can be evaluated from the curvature of the initial datum at its extrema by setting

M = sup

x∈Ω,∇u0(x)=0

|∇ ⊗ ∇u0| (1.4)

Introduced in [21], the basic idea is to deactivate the limiter when space derivatives are of orderh2.

This improves the limiter behavior near smooth local extrema. The minmod function is defined by

minmod(a, b) = 

sgn(a) min(|a|, |b|) whensgn(a) = sgn(b)

(17)

Then, for alli = 0 . . . d− 1 we define rK(uh) = d−1 X j=0 max(0,−∆K,j(uh)) d−1 X j=0 max(0, ∆K,j(uh)) > 0 ˆ

∆K,i(uh) = min(1, rK(uh)) max(0, ∆K,i(uh))

− min(1, 1/rK(uh)) max(0,−∆K,i(uh)), i = 0 . . . d− 1 when rK(uh)6= 0

Finally, the limited function Λh(uh) is defined element by element for all element K∈ Th for all

x∈ K by Λh(uh)|K(x) =            ¯ uK+ d−1 X i=1 ∆K,i(uh) ϕi(x) whenrK(uh) = 0 ¯ uK+ d−1 X i=1 ˆ ∆K,i(uh) ϕi(x) otherwise

Notice that there are two types of computations involved in the limiter: one part is independent of uh and depends only upon the mesh: Ji,k and αi,k on each element. It can be computed one

time for all. The other part depends upon the values ofuh.

Notice that the limiter preserves the average value ofuhon each elementK and also the functions

that are globally affine on the patch ωK. Also we have, inside each elementK and for all side

indexi = 0 . . . d− 1:

Λh(uh)|K(xSi)− ¯uK

6 max|∆K,i(uh)|, | ˆ∆K,i(uh)|

 6 |∆K,i(uh)| 6 uh|K(xSi)− ¯uK It means that, inside each element, the gradient of the P1 limited function is no larger than that

of the original one.

The limiter on an element close to the boundary should takes into account the inflow condition. In [7], the modifications are described.

1.3

Example: the Burgers equation

As an illustration, let us consider now the test with the one-dimensional (d = 1) Burgers equation for a propagating slant step (see e.g. [3, p. 87]) inΩ =]0, 1[. We have f (u) = u2/2, for all u

∈ R. In that case, the Godunov flux (1.1d), introduced page 11, can be computed explicitly for any ν = (ν0)∈ Rd anda, b∈ R:

Φ(ν; a, b) = 

ν0min a2, b2



/2 whenν0> 0 and a 6 b or ν06 0 and a > b

ν0max a2, b2



/2 otherwise

Example file 1.2: burgers.icc

1 p o i n t f (c o n s t F l o a t& u ) { r e t u r n p o i n t (sqr( u ) / 2 ) ; }

Example file 1.3: burgers_flux_godunov.icc

1 F l o a t phi (c o n s t p o i n t& nu , F l o a t a , F l o a t b ) { 2 if (( nu [0] >= 0 && a <= b ) || ( nu [0] <= 0 && a >= b )) 3 r e t u r n nu [ 0 ] * min (sqr( a ) ,sqr( b ) ) / 2 ; 4 e l s e 5 r e t u r n nu [ 0 ] * max (sqr( a ) ,sqr( b ) ) / 2 ; 6 }

(18)

1.3.1

Computing an exact solution

An exact solution is useful for testing numerical methods. The computation of such an exact solution for the one dimensional Burgers equation is described by Hartens et al. [15]. The authors consider first the problem with a periodic boundary condition:

(P ): find u : ]0, T [×]− 1, 1[7−→ R such that ∂u ∂t + ∂ ∂x u2 2  = 0 in ]0, T [×] − 1, 1[

u(t = 0, x) = α + β sin(πx + γ), a.e. x∈] − 1, 1[ u(t, x =−1) = u(t, x=1) a.e. t ∈]0, T [

where α, β and γ are real parameters. Let us denote w the solution of the problem when β = 1 and α = γ = 0; i.e. with the initial condition w(t = 0, x) = sin(πx), a.e. x∈] − 1, 1[. For any x∈ [0, 1[ and t > 0, the solution ¯w = w(t, x) satisfies the characteristic relation

¯

w = sin(π(x− ¯wt))

This nonlinear relation can be solved by a Newton algorithm. Then, forx∈]−1, 0[, the solution is completed by symmetry: w(t, x) =−w(t, −x). Finally, the general solution for any α, β and γ = 0 writes u(t, x) = α + w(βt, x− αt + γ). File ‘harten.icc’ implements this approach.

Example file 1.4: harten.icc

1 # i n c l u d e " h a r t e n 0 . icc " 2 s t r u c t h a r t e n { 3 F l o a t o p e r a t o r() (c o n s t p o i n t& x ) c o n s t { 4 F l o a t x0 = x [0] - a * t + c ; 5 F l o a t s h i f t = -2* f l o o r (( x0 + 1 ) / 2 ) ; 6 F l o a t xs = x0 + s h i f t ; 7 c h e c k _ m a c r o ( xs >= -1 && xs <= 1 , " i n v a l i d xs = "< < xs ); 8 r e t u r n a + b * h0 (p o i n t( xs )); 9 } 10 h a r t e n (F l o a t t1 =0 , F l o a t a1 =1 , F l o a t b1 =0.5 , F l o a t c1 = 0) : 11 h0 ( b1 * t1 ) , t ( t1 ) , a ( a1 ) , b ( b1 ) , c ( c1 ) {} 12 F l o a t M () c o n s t { c o n s t e x p r F l o a t pi = a c o s ( -1.0); r e t u r n sqr( pi )* b ; } 13 F l o a t min () c o n s t { r e t u r n a - b ; } 14 F l o a t max () c o n s t { r e t u r n a + b ; } 15 p r o t e c t e d: 16 h a r t e n 0 h0 ; 17 F l o a t t , a , b , c ; 18 }; 19 u s i n g u _ i n i t = h a r t e n ; 20 u s i n g g = h a r t e n ;

Example file 1.5: harten_show.cc

1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ; 4 # i n c l u d e " h a r t e n . icc "

5 int m a i n (int argc , c h a r** a r g v ) { 6 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 7 geo o m e g a ( ar g v [ 1 ] ) ; 8 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 9 s i z e _ t nm a x = ( a r g c > 3) ? a t o i ( a r g v [3 ] ) : 1 0 0 0 ; 10 F l o a t tf = ( a r g c > 4) ? a t o f ( a r g v [ 4 ] ) : 2 . 5 ; 11 F l o a t a = ( a r g c > 5) ? a t o f ( a r g v [ 5 ] ) : 1; 12 F l o a t b = ( a r g c > 6) ? a t o f ( a r g v [ 6 ] ) : 0 . 5 ; 13 F l o a t c = ( a r g c > 7) ? a t o f ( a r g v [ 7 ] ) : 0; 14 b r a n c h ev e n (" t "," u "); 15 for (s i z e _ t n = 0; n <= n m a x ; ++ n ) { 16 F l o a t t = n * tf / nm a x ; 17 f i e l d p i _ h _ u = i n t e r p o l a t e ( Xh , h a r t e n ( t , a , b , c )); 18 d o u t < < e v e n ( t , p i _ h _ u ); 19 } 20 }

(19)

The included file ‘harten0.icc’ is not shown here by is available in the example directory.

Comments

Notice that the constant M , used by the limiter in (1.4), can be explicitly computed for this solution: M = βπ2.

The animation of this exact solution is performed by the following commands:

make harten_show

mkgeo_grid -e 2000 -a -1 -b 1 > line2.geo

./harten_show line2 P1 1000 2.5 > line2-exact.branch branch line2-exact -gnuplot

Fig.1.5shows the solutionu for α = 1, β = 1/2 and γ = 0. It is regular until t = 2/π (Fig.1.5.c) and then develops a chock fort > 2/π (Fig.1.5.d). After its apparition, this chock interacts with the expansion wave in]− 1, 1[: this brings about a fast decay of the solution (Figs.1.5.e and f). Fig.1.5 plots also a numerical solution: its computation is the aim of the next section.

1.3.2

Numerical resolution

When replacing the periodic boundary condition with a inflow one, associated with the boundary datag, we choose g to be the value of the exact solution of the problem with periodic boundary conditions: g(t, x) = α + w(βt, x− αt) for x ∈ {−1, 1}.

(20)

Example file 1.6: burgers_dg.cc 1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ; 4 # i n c l u d e " h a r t e n . icc " 5 # i n c l u d e " b u r g e r s . icc " 6 # i n c l u d e " b u r g e r s _ f l u x _ g o d u n o v . icc " 7 # i n c l u d e " r u n g e _ k u t t a _ s s p . icc " 8 int m a i n (int argc , c h a r** a r g v ) { 9 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 10 geo o m e g a ( ar g v [ 1 ] ) ; 11 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 12 F l o a t cfl = 1; 13 l i m i t e r _ o p t i o n _ t y p e l o p t ; 14 s i z e _ t nm a x = ( a r g c > 3) ? a t o i ( a r g v [3 ] ) : n u m e r i c _ l i m i t s <size_t>:: max (); 15 F l o a t tf = ( a r g c > 4) ? a t o f ( a r g v [ 4 ] ) : 2 . 5 ; 16 s i z e _ t p = ( a r g c > 5) ? a t o i ( a r g v [ 5 ] ) : p m a x ; 17 l o p t . M = ( a rg c > 6) ? a to i ( a r g v [ 6 ] ) : u _ i n i t (). M (); 18 if ( n m a x == n u m e r i c _ l i m i t s <size_t>:: max ()) { 19 n m a x = f l o o r (1+ tf /( cfl * o m e g a . h m i n ( ) ) ) ; 20 } 21 F l o a t d e l t a _ t = tf / n m a x ; 22 f o r m _ o p t i o n _ t y p e f o p t ; 23 f o p t . i n v e r t = t r u e; 24 t r i a l u ( Xh ); t es t v ( Xh ); 25 f o r m i n v _ m = i n t e g r a t e ( u * v , f o p t ); 26 vector <field> uh ( p +1 , f i e l d( Xh , 0 ) ) ; 27 uh [0] = i n t e r p o l a t e ( Xh , u _ i n i t ( ) ) ; 28 b r a n c h ev e n (" t "," u "); 29 d o u t < < c a t c h m a r k(" d e l t a _ t ") < < d e l t a _ t < < e n d l 30 < < e v e n (0 , uh [ 0 ] ) ; 31 for (s i z e _ t n = 1; n <= n m a x ; ++ n ) { 32 for (s i z e _ t i = 1; i <= p ; ++ i ) { 33 uh [ i ] = 0; 34 for (s i z e _ t j = 0; j < i ; ++ j ) { 35 f i e l d lh = 36 - i n t e g r a t e ( dot (c o m p o s e( f , uh [ j ]) , g r a d _ h ( v ))) 37 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", 38 c o m p o s e ( phi , n o r m a l () , i n n e r ( uh [ j ]) , o u t e r ( uh [ j ] ) ) * j u m p ( v )) 39 + i n t e g r a t e (" b o u n d a r y ", 40 c o m p o s e ( phi , n o r m a l () , uh [ j ] , g ( n * d e l t a _ t ))* v ); 41 uh [ i ] += a l p h a [ p ][ i ][ j ]* uh [ j ] - d e l t a _ t * b e t a [ p ][ i ][ j ]*( i n v _ m * lh ); 42 } 43 uh [ i ] = l i m i t e r ( uh [ i ] , g ( n * d e l t a _ t )(p o i n t( -1)) , l o p t ); 44 } 45 uh [0] = uh [ p ]; 46 d o u t < < e v e n ( n * delta_t , uh [ 0 ] ) ; 47 } 48 }

Comments

The Runge-Kutta time discretization combined with the discontinuous Galerkin space discretiza-tion is implemented for this test case.

TheP0 approximation is performed by the following commands:

make burgers_dg

mkgeo_grid -e 200 -a -1 -b 1 > line2-200.geo

./burgers_dg line2-200.geo P0 1000 2.5 > line2-200-P0.branch branch line2-200-P0.branch -gnuplot

The two last commands compute the P0 approximation of the solution, as shown on Fig. 1.5.

Observe the robust behavior of the solution at the vicinity of the chock. By replacing P0 by P1d in the previous commands, we obtain theP1-discontinuous approximation.

(21)

./burgers_dg line2-200.geo P1d 1000 2.5 > line2-200-P1d.branch branch line2-200-P1d.branch -gnuplot

Fig.1.6 plots the error vs h for k = 0 and k = 1. Fig. 1.6.a plots in a time interval[0, T ] with T = 1/π, before the chock that occurs at t = 2/π. In that interval, the solution is regular and the error approximation behaves asO(hk+1). The time interval has been chosen sufficiently small for

the error to depend only upon h. Fig. 1.6.b plots in a larger time interval [0, T ] with T = 5/2, that includes the chock. Observe that the error behaves as O(h) for both k = 0 and 1. This is optimal whenk = 0 but not when k = 1. This is due to the loss of regularity of the exact solution that presents a discontinuity; A similar observation can be found in [26], table 4.1.

(22)

0.5 1 1.5 −1 0 1 u(t, x) (a) t = 0 x 0.5 1 1.5 −1 0 1 (b) t = 1/2 x exact P0 0.5 1 1.5 −1 0 1 (c) t = 2/π x exact P0 0.5 1 1.5 −1 0 1 u(t, x) (d) t = 0, 75 x exact P0 0.5 1 1.5 −1 0 1 u(t, x) (e) t = 1 x exact P0 0.5 1 1.5 −1 0 1 u(t, x) (f) t = 1.75 x exact P0

Figure 1.5: Harten’s exact solution of the Burgers equation (α = 1, β = 1/2, γ = 0). Comparison with theP0 appromation (h = 1/100, RK-SSP(3)).

(23)

10−5 10−4 10−3 10−2 10−1 10−3 10−2 10−1 ku − uhkL∞(0,T ;L1) (a) T = 2/π 0.96 1.9 h k = 0 k = 1 10−3 10−2 10−1 10−3 10−2 10−1 ku − uhkL∞(0,T ;L1) (b) T = 5/2 0.85 1 h k = 0 k = 1

Figure 1.6: Burgers equation: error between the P0 approximation and the exact solution of the

Harten’s problem (α = 1, β = 1/2, γ = 0): (a) before chock, with T = 1/pi; (b) after chock, with T = 5/2.

(24)

Scalar second-order problems

2.1

The Poisson problem with Dirichlet boundary conditions

The Poisson problem with non-homogeneous Dirichlet boundary conditions has been already in-troduced in volume 1, section2.1, page27:

(P ): find u, defined in Ω, such that

−∆u = f in Ω u = g on ∂Ω wheref and g are given.

The discontinuous finite element space is defined by:

Xh={vh∈ L2(Ω); vh|K∈ Pk, ∀K ∈ Th}

where k > 1 is the polynomial degree. As elements of Xh do not belongs to H1(Ω), due to

discontinuities at inter-elements, we introduce the broken Sobolev space: H1(Th) ={v ∈ L2(Ω); v|K∈ H1(K), ∀K ∈ Th}

such that Xh ⊂ H1(Th). We introduce the folowing bilinear form ah(., .) and linear for lh(.),

defined for allu, v∈ H1(

Th) by (see e.g. [11, p. 125 and 127], eqn. (4.12)):

ah(u, v) = Z Ω∇ hu.∇hv dx + X S∈Sh Z S

(ηs[[u]] [[v]]− {{∇hu.n}} [[v]] − [[u]] {{∇hv.n}}) ds (2.1)

lh(v) = Z Ω f u dx + Z ∂Ω (ηsg v− g ∇hv.n) ds (2.2)

The last term involves a sum overSh, the set of all sides of the meshTh, i.e. the internal sides

and the boundary sides. By convenience, the definition of the jump and average are extended to all boundary sides as [[u]] = {{u}} = u. Notice that, as for the previous transport problem, the Dirichlet boundary condition u = g is weakly imposed on ∂Ω via the integrals on the boundary. Finally,ηs> 0 is a stabilization parameter on a side S. The stabilization term associated to ηsis

present in order to achieve coercivity: it penalize interface and boundary jumps. A common choice isηs= β h−1s whereβ > 0 is a constant and hsis a local length scale associated to the current side

S. One drawnback to this choice is that it requires the end user to specify the numerical constant β. From one hand, if the value of this parameter is not sufficiently large, the form ah(., .) is not

coercive and the approximate solution develops instabilities an do not converge [12]. From other hand, if the value of this parameter is too large, its affect the overall efficiency of the iterative solver of the linear system: the spectral condition number of the matrix associated to ah(., .)

(25)

grows linearly with this paramater [4]. An explicit choice of penalty parameter is proposed in [20]: ηs= β $swhereβ = (k + 1)(k + d)/d and $s =        meas(∂K)

meas(K) whenS = K∩ ∂Ω is a boundary side max  meas(∂K0) meas(K0) , meas(∂K1) meas(K1) 

whenS = K0∩ K1 is an internal side

Notice that $sscales as h−1s . Now, the computation of the penalty parameter is fully automatic

and the convergence of the method is always guaranted to converge. Moreover, this choice has been founded to be sharp and it preserves the optimal efficiency of the iterative solvers. Finally, the discrete variational formulation writes:

(F V )h: find uh∈ Xh such that

ah(uh, vh) = lh(vh), ∀vh∈ Xh

The following code implement this problem in the Rheolef environment. Example file 2.1: dirichlet_dg.cc

1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ;

4 # i n c l u d e " c o s i n u s p r o d _ l a p l a c e . icc " 5 int m a i n (int argc , c h a r** a r g v ) { 6 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 7 geo o m e g a ( ar g v [ 1 ] ) ; 8 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 9 s i z e _ t d = o m e g a . d i m e n s i o n (); 10 s i z e _ t k = Xh . d e g r e e (); 11 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 12 t r i a l u ( Xh ); t es t v ( Xh ); 13 f o r m a = i n t e g r a t e ( dot ( g r a d _ h ( u ) , g r a d _ h ( v ))) 14 + i n t e g r a t e (" s i d e s ", b e t a * p e n a l t y ()* j u m p ( u )* j u m p ( v ) 15 - j u m p ( u )* a v e r a g e ( dot ( g r a d _ h ( v ) , n o r m a l ( ) ) ) 16 - j u m p ( v )* a v e r a g e ( dot ( g r a d _ h ( u ) , n o r m a l ( ) ) ) ) ; 17 f i e l d lh = i n t e g r a t e ( f ( d )* v ) 18 + i n t e g r a t e (" b o u n d a r y ", b e t a * p e n a l t y ()* g ( d )* v 19 - g ( d )* dot ( g r a d _ h ( v ) , n o r m a l ( ) ) ) ; 20 s o l v e r sa ( a . uu ( ) ) ; 21 f i e l d uh ( Xh ); 22 uh . s e t _ u () = sa . s o l v e ( lh . u ( ) ) ; 23 d o u t < < uh ; 24 }

Comments

The penalty() pseudo-function implements the computation of$sin Rheolef. The right-hand

side f and g are given by (2.1), volume 1, page 28. In that case, the exact solution is known. Running the one-dimensional case writes:

make dirichlet_dg

mkgeo_grid -e 10 > line.geo ./dirichlet_dg line P1d | field ./dirichlet_dg line P2d | field

-Fig.2.1plots the one-dimensional solution whenk = 1 for two meshes. Observe that the jumps at inter-element nodes decreases very fast with mesh refinement and are no more perceptible on the plots. Recall that the Dirichlet boundary conditions atx = 0 and x = 1 is only weakly imposed: the corresponding jump at the boundary is also not perceptible.

(26)

−1 0 1 0 0.5 1 h = 1/10 x u(x) uh(x) −1 0 1 0 0.5 1 h = 1/20 x u(x) uh(x)

Figure 2.1: The discontinuous Galerkin method for the Poisson problem whenk = 1 and d = 1.

mkgeo_grid -t 10 > square.geo

./dirichlet_dg square P1d | field elevation ./dirichlet_dg square P2d | field elevation

-and the three-dimensional one mkgeo_grid -T 10 > cube.geo ./dirichlet_dg cube P1d | field ./dirichlet_dg cube P2d | field

-Error analysis

The spaceH1(

Th) is equiped with the normk.k1,h, defined for allv∈ H1(Th by [11, p. 128]:

kvk2 1,h=k∇hvk20,Ω+ X S∈Sh Z S h−1 s [[v]] 2ds

The code cosinusprod_error_dg.cc compute the error in these norms. This code it is not listed here but is available in the Rheolef example directory. The computation of the error writes:

make cosinusprod_error_dg

./dirichlet_dg square P1d | cosinusprod_error_dg

Fig. 2.2 plots the error u− uh in L2, L∞ and the k.k1,h norms. The L2 and L∞ error norms

behave asO hk+1for allk > 0, while thek.k1,hone behaves as O hk



, which is optimal.

2.2

The Helmholtz problem with Neumann boundary

condi-tions

The Poisson problem with non-homogeneous Neumann boundary conditions has been already introduced in volume 1, section2.2, page35:

(P ): find u, defined in Ω, such that

u− ∆u = f in Ω ∂u

(27)

10−15 10−10 10−5 1 10−2 10−1 ku − uhk0,Ω 2 = k + 1 5 = k + 1 h k = 1 k = 2 k = 3 k = 4 10−15 10−10 10−5 1 10−2 10−1 ku − uhk∞,Ω 2 = k + 1 5 = k + 1 h k = 1 k = 2 k = 3 k = 4 10−10 10−5 1 10−2 10−1 ku − uhk1,h 1 = k 4 = k h k = 1 k = 2 k = 3 k = 4

Figure 2.2: The discontinuous Galerkin method for the Poisson problem: convergence whend = 2.

where f and g are given. We introduce the folowing bilinear form ah(., .) and linear for lh(.),

defined for allu, v∈ H1(

Th) by (see e.g. [11, p. 127], eqn. (4.16)):

ah(u, v) = Z Ω (u v +hu.∇hv) dx (2.3) + X S∈Sh(i) Z S

(β$s[[u]] [[v]]− {{∇hu.n}} [[v]] − [[u]] {{∇hv.n}}) ds (2.4)

lh(v) = Z Ω f u dx + Z ∂Ω g v ds (2.5)

Let us comment the changes between these forms and those used for the Poisson problem with Dirichlet boundary conditions. The Poisson operator−∆ has been replaced by the Helmholtz one I− ∆ in order to have an unique solution. Remark also that the sum is performed in (2.1) for all internal sides inSh(i), while, in (2.1), for Dirichlet boundary conditions, it was for all sides inSh,

i.e. for both boundary and internal sides. Also, the right-hand-side linear formlh(.). do no more

involves any sum over sides.

Finally, the discrete variational formulation writes: (F V )h: find uh∈ Xh such that

ah(uh, vh) = lh(vh), ∀vh∈ Xh

(28)

Example file 2.2: neumann_dg.cc

1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ;

4 # i n c l u d e " s i n u s p r o d _ h e l m h o l t z . icc " 5 int m a i n (int argc , c h a r** a r g v ) { 6 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 7 geo o m e g a ( ar g v [ 1 ] ) ; 8 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 9 s i z e _ t d = o m e g a . d i m e n s i o n (); 10 s i z e _ t k = Xh . d e g r e e (); 11 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 12 t r i a l u ( Xh ); t es t v ( Xh ); 13 f o r m a = i n t e g r a t e ( u * v + dot ( g r a d _ h ( u ) , g r a d _ h ( v ))) 14 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", 15 b e t a * p e n a l t y ()* j u m p ( u )* j u m p ( v ) 16 - j u m p ( u )* a v e r a g e ( dot ( g r a d _ h ( v ) , n o r m a l ( ) ) ) 17 - j u m p ( v )* a v e r a g e ( dot ( g r a d _ h ( u ) , n o r m a l ( ) ) ) ) ; 18 f i e l d lh = i n t e g r a t e ( f ( d )* v ) + i n t e g r a t e (" b o u n d a r y ", g ( d )* v ); 19 s o l v e r sa ( a . uu ( ) ) ; 20 f i e l d uh ( Xh ); 21 uh . s e t _ u () = sa . s o l v e ( lh . u ( ) ) ; 22 d o u t < < uh ; 23 }

Comments

The right-hand sidef and g are given by (2.2), volume 1, page28. In that case, the exact solution is known. Running the program is obtained from the non-homogeneous Dirichlet case, by replacing dirichlet_dg by neumann_dg.

2.3

Nonlinear scalar hyperbolic problems with diffusion

A time-dependent nonlinear second order problem with nonlinear first order dominated terms problem writes:

(P ): find u, defined in ]0, T [×Ω, such that ∂u

∂t + div f (u)− ε∆u = 0 in ]0, T [×Ω (2.6a)

u(t = 0) = u0 in Ω (2.6b)

u = g on ]0, T [×∂Ω (2.6c)

where ε > 0, T > 0, Ω⊂ Rd, d = 1, 2, 3 and the initial condition u

0 being known. The function

f : R−→ Rd is also known and supposed to be continuously differentiable. The initial data u 0,

defined inΩ, and the boundary one, g, defined on ∂Ω are given.

Comparing (2.6a)-(2.6c) with the non-diffusive case (1.1a)-(1.1c) page10, the second order term has been added in (2.6a) and the upstrem boundary condition has been replaced by a Dirichlet one (2.6c).

2.4

Example: the Burgers equation with diffusion

2.4.1

Problem statement and its exact solution

Our model problem in this chapter is the one-dimensional Burgers equation. It was introduced in section1.3, page 14with the choice f(u) = u2/2, for all u

(29)

0 1 2 −1 0 1 u(t, x) x t = 0 t = 1

Figure 2.3: An exact solution for the Burgers equation with diffusion (ε = 10−1,x

0=−1/2). solution u(t, x) = 1− tanh  x− x0− t 2ε  (2.7)

Example file 2.3: burgers_diffusion_exact.icc

1 s t r u c t u _ e x a c t { 2 F l o a t o p e r a t o r() (c o n s t p o i n t& x ) c o n s t { 3 r e t u r n 1 - t a n h (( x [0] - x0 - t ) / ( 2 * e p s i l o n )); } 4 u _ e x a c t (F l o a t e1 , F l o a t t1 =0) : e p s i l o n ( e1 ) , t ( t1 ) , x0 ( -0.5) {} 5 F l o a t M () c o n s t { r e t u r n 0; } 6 F l o a t epsilon , t , x0 ; 7 }; 8 u s i n g u _ i n i t = u _ e x a c t ; 9 u s i n g g = u _ e x a c t ;

The solution is represente on Fig.2.3. Herex0 represent the position of the front att = 0 and ε

is a characteristic width of the front. The initial and boundary condition are choosen such that u(t, x) is the solution of (2.6a)-(2.6c).

Fig. 2.4.a plots the error versus ∆t for the semi-implicit scheme when k = 1 and 2, and for h = 2/50. The time step for which the error becomes independent upon ∆t and depends only uponh is of about ∆t = 10−3 whenk = 1 and of about 10−5whenk = 2. This approach is clearly inefficient for hight order polynomialk and a hiher order time scheme is required.

Fig.2.4.b plots the error versus∆t for the Runge-Kutta semi-implicit scheme with p = 3, k = 1 and h = 2/200. The scheme is clearly only first-order, which is still unexpected. More work is required...

2.4.2

Space discretization

The discontinuous finite element space is defined by:

Xh={vh∈ L2(Ω); vh|K∈ Pk, ∀K ∈ Th}

where k > 1 is the polynomial degree. As elements of Xh do not belongs to H1(Ω), due to

discontinuities at inter-elements, we introduce the broken Sobolev space: H1(

(30)

10−5 10−4 10−3 10−2 10−1 10−6 10−5 10−4 10−3 10−2 10−1 ku − uhkL∞(0,T ;L2) (a) k = 1, h = 2/50 1 ∆t k = 1 k = 2 10−5 10−4 10−3 10−2 10−1 10−5 10−4 10−3 10−2 10−1 ku − uhkL∞(0,T ;L2) (b) k = 1, h = 2/400 1 2 3 ∆t p = 1 p = 2 p = 3

Figure 2.4: Convergence of the first order semi-implicit scheme for the Burgers equation with diffusion ( = 0.1, T = 1). (a) first order semi-implicit scheme ; (b) Runge-Kutta semi-implicit scheme withp = 3.

such thatXh⊂ H1(Th). As for the Dirichlet problem, introduce the folowing bilinear form ah(., .)

and linear forlh(.), defined for all u, v∈ H1(Th) by (see e.g. [11, p. 125 and 127], eqn. (4.12)):

ah(u, v) = Z Ω∇ hu.∇hv dx + X S∈Sh Z S

(ηs[[u]] [[v]]− {{∇hu.n}} [[v]] − [[u]] {{∇hv.n}}) ds (2.8)

`h(v) =

Z

∂Ω

(ηsg v− g ∇hv.n) ds (2.9)

The semi-discrete problem writes in variational form [11, p. 100]: (P )h: find uh∈ C1([0, T ], Xh) such that

Z Ω ∂uh ∂t vhdx Z Ω Gh(uh) vhdx + ε ah(uh, vh) = ε `h(vh), ∀vh∈ Xh uh(t = 0) = πh(u0)

whereGh has been introduced in (1.2), page11.

2.4.3

Time discretization

Explicit Runge-Kutta scheme is possible for this problem but it leads to an excessive Courant-Friedrichs-Levy condition for the time step∆t, that is required to be lower than an upper bound that varies inO(h2). The idea here is to continue to explicit the first order nonlinearr terms and implicit the linear second order terms. Semi-implicit second order Runge-Kutta scheme was first introduced in 1997 by Ascher, Ruuth and Spiteri [1] and then extended in 2001 to third and fourth order by Calvo, de Frutos and Novo [2]. In 2015, Wang, Shu and Zhang [24,25] applied it in the context of the discontinuous Galerkin method. The finite dimensional problem can be rewritten as

(P )h: find uh∈ C1([0, T ], Xh) such that

∂uh

∂t + Gh(t, uh) + Ah(t, uh) = 0, ∀t ∈]0, T [ uh(t = 0) = πh(u0)

(31)

where Gh has been introduced in (1.2), page 11 and Ah denotes the diffusive term. The

semi-implicit Runge-Kutta scheme withp > 0 intermediate steps writes at time step tn:

un,0h = u n h (2.10a) un,ih = un h− ∆t i X j=1 αi,jAh  tn,j, un,jh  − ∆t i−1 X j=0 ˜ αi,jGh  tn,j, un,jh  , i = 1, . . . , p(2.10b) un+1h = u n h− ∆t p X i=1 βiAh  tn,i, un,ih  − ∆t p X i=0 ˜ βiGh  tn,i, un,ih  (2.10c) whereun,ih 

16i6pare thep > 1 intermediate states, tn,i= tn+ γi∆t, γi=

Pi

j=1αi,j=P i−1 j=0α˜i,j,

and(αi,j)06i,j6p,(˜αi,j)06i,j6p,(βi)06i6pand( ˜βi)06i6pare the coefficients of the scheme [1,2,25].

At each time step, have to solvep linear systems. From (2.10b) we get for alli = 1, . . . , p:

(I + ∆t αi,iAh(tn,i)) un,ih = unh− ∆t i−1 X j=1 αi,jAh  tn,j, un,jh  − ∆t i−1 X j=0 ˜ αi,jGh  tn,j, un,jh 

Notice that when the matrix coefficients ofAh(t, .) are indepencdent of t, the matrix involved on

(32)

Example file 2.4: burgers_diffusion_dg.cc 1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ; 4 # i n c l u d e " b u r g e r s . icc " 5 # i n c l u d e " b u r g e r s _ f l u x _ g o d u n o v . icc " 6 # i n c l u d e " r u n g e _ k u t t a _ s e m i i m p l i c i t . icc " 7 # i n c l u d e " b u r g e r s _ d i f f u s i o n _ e x a c t . icc " 8 # u n d e f N E U M A N N 9 # i n c l u d e " b u r g e r s _ d i f f u s i o n _ o p e r a t o r s . icc " 10 int m a i n (int argc , c h a r** a r g v ) {

11 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 12 geo o m e g a ( ar g v [ 1 ] ) ; 13 s p a c e Xh ( omega , a r g v [ 2 ] ) ; 14 s i z e _ t k = Xh . d e g r e e (); 15 F l o a t e p s i l o n = ( a r g c > 3) ? a t o f ( a r g v [ 3 ] ) : 0 . 1 ; 16 s i z e _ t nm a x = ( a r g c > 4) ? a t o i ( a r g v [ 4 ] ) : 5 0 0 ; 17 F l o a t tf = ( a r g c > 5) ? a t o f ( a r g v [5 ] ) : 1; 18 s i z e _ t p = ( a r g c > 6) ? a t o i ( a r g v [ 6 ] ) : min ( k +1 , rk :: p m a x ); 19 F l o a t d e l t a _ t = tf / n m a x ; 20 s i z e _ t d = o m e g a . d i m e n s i o n (); 21 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 22 t r i a l u ( Xh ); t es t v ( Xh ); 23 f o r m m = i n t e g r a t e ( u * v ); 24 f o r m _ o p t i o n _ t y p e f o p t ; 25 f o p t . i n v e r t = t r u e; 26 f o r m i n v _ m = i n t e g r a t e ( u * v , f o p t ); 27 f o r m a = e p s i l o n *( 28 i n t e g r a t e ( dot ( g r a d _ h ( u ) , g r a d _ h ( v ))) 29 # i f d e f N E U M A N N 30 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", 31 # e l s e // N E U M A N N 32 + i n t e g r a t e (" s i d e s ", 33 # e n d i f // N E U M A N N 34 b e t a * p e n a l t y ()* j u m p ( u )* j u m p ( v ) 35 - j u m p ( u )* a v e r a g e ( dot ( g r a d _ h ( v ) , n o r m a l ( ) ) ) 36 - j u m p ( v )* a v e r a g e ( dot ( g r a d _ h ( u ) , n o r m a l ( ) ) ) ) ) ; 37 vector <solver> sc ( p + 1 ) ; 38 for (s i z e _ t i = 1; i <= p ; ++ i ) { 39 f o r m ci = m + d e l t a _ t * rk :: a l p h a [ p ][ i ][ i ]* a ; 40 sc [ i ] = s o l v e r( ci . uu ( ) ) ; 41 } 42 vector <field> uh ( p +1 , f i e l d( Xh , 0 ) ) ; 43 uh [0] = i n t e r p o l a t e ( Xh , u _ i n i t ( e p s i l o n )); 44 b r a n c h ev e n (" t "," u "); 45 d o u t < < c a t c h m a r k(" e p s i l o n ") < < e p s i l o n < < e n d l 46 < < e v e n (0 , uh [ 0 ] ) ; 47 for (s i z e _ t n = 0; n < n m a x ; ++ n ) { 48 F l o a t tn = n * d e l t a _ t ; 49 F l o a t t = tn + d e l t a _ t ; 50 f i e l d u h _ n e x t = uh [0] - d e l t a _ t * rk :: t i l d e _ b e t a [ p ] [ 0 ] * ( i n v _ m * gh ( epsilon , tn , uh [0] , v )); 51 for (s i z e _ t i = 1; i <= p ; ++ i ) { 52 F l o a t ti = tn + rk :: g a m m a [ p ][ i ]* d e l t a _ t ; 53 f i e l d rhs = m * uh [0] - d e l t a _ t * rk :: t i l d e _ a l p h a [ p ][ i ] [ 0 ] * gh ( epsilon , tn , uh [0] , v ); 54 for (s i z e _ t j = 1; j <= i -1; ++ j ) { 55 F l o a t tj = tn + rk :: g a m m a [ p ][ j ]* d e l t a _ t ; 56 rhs -= d e l t a _ t *( rk :: a l p h a [ p ][ i ][ j ]*( a * uh [ j ] - lh ( epsilon , tj , v )) 57 + rk :: t i l d e _ a l p h a [ p ][ i ][ j ]* gh ( epsilon , tj , uh [ j ] , v )); 58 } 59 rhs += d e l t a _ t * rk :: a l p h a [ p ][ i ][ i ]* lh ( epsilon , ti , v ); 60 uh [ i ]. s e t _ u () = sc [ i ]. s o l v e ( rhs . u ( ) ) ; 61 u h _ n e x t -= d e l t a _ t *( i n v _ m *( rk :: b e t a [ p ][ i ]*( a * uh [ i ] - lh ( epsilon , ti , v )) 62 + rk :: t i l d e _ b e t a [ p ][ i ]* gh ( epsilon , ti , uh [ i ] , v ) ) ) ; 63 } 64 u h _ n e x t = l i m i t e r ( u h _ n e x t ); 65 d o u t < < e v e n ( tn + delta_t , u h _ n e x t ); 66 uh [0] = u h _ n e x t ; 67 } 68 }

(33)

Example file 2.5: burgers_diffusion_operators.icc 1 f i e l d lh (F l o a t epsilon , F l o a t t , c o n s t t e s t& v ) { 2 # i f d e f N E U M A N N 3 r e t u r n f i e l d ( v . g e t _ v f _ s p a c e () , 0); 4 # e l s e // N E U M A N N 5 s i z e _ t d = v . g e t _ v f _ s p a c e (). g e t _ g e o (). d i m e n s i o n (); 6 s i z e _ t k = v . g e t _ v f _ s p a c e (). d e g r e e (); 7 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 8 r e t u r n e p s i l o n *i n t e g r a t e (" b o u n d a r y ", 9 b e t a * p e n a l t y ()* g ( epsilon , t )* v 10 - g ( epsilon , t )* dot ( g r a d _ h ( v ) , n o r m a l ( ) ) ) ; 11 # e n d i f // N E U M A N N 12 }

13 f i e l d gh (F l o a t epsilon , F l o a t t , c o n s t f i e l d& uh , c o n s t t e s t& v ) { 14 r e t u r n - i n t e g r a t e ( dot (c o m p o s e( f , uh ) , g r a d _ h ( v ))) 15 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", 16 c o m p o s e ( phi , n o r m a l () , i n n e r ( uh ) , o u t e r ( uh ))* ju m p ( v )) 17 + i n t e g r a t e (" b o u n d a r y ", 18 c o m p o s e ( phi , n o r m a l () , uh , g ( epsilon , t ))* v ); 19 }

Running the program

0 1 2 −1 0 1 u(t, x) x t = 0 t = 1 0 1 2 −1 0 1 u(t, x) x t = 0 t = 1

Figure 2.5: Burgers equation with a small diffusion (ε = 10−3). Third order in time semi-implicit

scheme withP1d element. (left) without limiter ; (right) with limiter.

Running the program writes withh = 2/400 and ε = 10−2 writes:

make burgers_diffusion_dg

mkgeo_grid -e 400 -a -1 -b 1 > line.geo

./burgers_diffusion_dg line P1d 0.01 1000 1 3 > line.branch branch -gnuplot line.branch -umin -0.1 -umax 2.1

Decreasingε = 10−3 leads to a sharper solution:

./burgers_diffusion_dg line P1d 0.001 1000 1 3 > line.branch branch -gnuplot line.branch -umin -0.1 -umax 2.1

As mentioned in [25], the time step should be chosen smaller when ε decreases. The result is shown on Fig.2.5.left. Observe the oscillations near the smoothed shock when there is no limiter while the value goes outside[0, 2]. Conversely, with a limiter (see Fig.2.5.right) the approximate solution is decreasing and there is no more oscilattions: the values remains in the range[0 : 2].

(34)

Fluids and solids computations

(35)
(36)

The linear elasticity and the Stokes

problems

3.1

The linear elasticity problem

The elasticity problem (4.2) has been introduced in volume 1, section4.1, page51. (P ): find u such that

−div (λdiv(u).I + 2D(u)) = f in Ω u = g on ∂Ω

where λ >−1 is a constant and f, g given. This problem is a natural extension to vector-valued field of the Poisson problem with Dirichlet boundary conditions.

The variational formulation writes: (F V )h: find u∈ V(g) such that

a(u, v) = lh(v), ∀v ∈ V(0) where V(g) = {v ∈ H1(Ω)d; v = g on ∂Ω } a(u, v) = Z Ω

(λ div(u) div(v) + 2D(u) : D(v)) dx l(v) =

Z

f.v dx The discrete variational formulation writes:

(F V )h: find uh∈ Xh such that

ah(uh, vh) = lh(vh), ∀vh∈ Xh where Xh = {vh∈ L2(Ω)d; vh|K∈ Pkd, ∀K ∈ Th} ah(u, v) = Z Ω

(λ divh(u) divh(v) + 2Dh(u) : Dh(v)) dx

+ X

S∈Sh

Z

S

(β$s[[u]].[[v]]− [[u]].{{λdivh(v)n + 2Dh(v)n}} − [[v]].{{λdivh(u)n + 2Dh(u)n}}) ds

lh(v) = Z Ω f.v dx + Z ∂Ω g. (β$sv− λdivh(v)n− 2Dh(v)n) ds 33

(37)

wherek > 1 is the polynomial degree in Xh.

Example file 3.1: elasticity_taylor_dg.cc

1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ; 4 # i n c l u d e " t a y l o r . icc "

5 int m a i n (int argc , c h a r** a r g v ) { 6 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 7 geo o m e g a ( ar g v [ 1 ] ) ; 8 s p a c e Xh ( omega , a r g v [2] , " v e c t o r "); 9 F l o a t l a m b d a = ( a r g c > 3) ? a t o f ( a r g v [ 3 ] ) : 1; 10 s i z e _ t d = o m e g a . d i m e n s i o n (); 11 s i z e _ t k = Xh . d e g r e e (); 12 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 13 t r i a l u ( Xh ); t es t v ( Xh ); 14 f o r m a = i n t e g r a t e ( l a m b d a * d i v _ h ( u )* d i v _ h ( v ) + 2* d d o t ( Dh ( u ) , Dh ( v ))) 15 + i n t e g r a t e ( o m e g a . s i d e s () , 16 b e t a * p e n a l t y ()* dot ( j u m p ( u ) , j u m p ( v )) 17 - l a m b d a * dot ( j u m p ( u ) , a v e r a g e ( d i v _ h ( v )* n o r m a l ( ) ) ) 18 - l a m b d a * dot ( j u m p ( v ) , a v e r a g e ( d i v _ h ( u )* n o r m a l ( ) ) ) 19 - 2* dot ( j um p ( u ) , a v e r a g e ( Dh ( v )* n o r m a l ( ) ) ) 20 - 2* dot ( j um p ( v ) , a v e r a g e ( Dh ( u )* n o r m a l ( ) ) ) ) ; 21 f i e l d lh = i n t e g r a t e ( dot ( f () , v )) 22 + i n t e g r a t e ( o m e g a . b o u n d a r y () , 23 b e t a * p e n a l t y ()* dot ( g () , j u m p ( v )) 24 - l a m b d a * dot ( g () , a v e r a g e ( d i v _ h ( v )* n o r m a l ( ) ) ) 25 - 2* dot ( g () , a v e r a g e ( Dh ( v )* n o r m a l ( ) ) ) ) ; 26 s o l v e r sa ( a . uu ( ) ) ; 27 f i e l d uh ( Xh ); 28 uh . s e t _ u () = sa . s o l v e ( lh . u ( ) ) ; 29 d o u t < < uh ; 30 }

Comments

The data are given whend = 2 by: g(x) =  − cos(πx0) sin(πx1) sin(πx0) cos(πx1)  and f = 2π2g (3.1)

This choice is convenient since the exact solution is known u = g. This benmark solution was proposed in 1923 by Taylor [23] in the context of the Stokes problem. Notice that the solution is independent ofλ since div(u) = 0.

Example file 3.2: taylor.icc

1 s t r u c t g { 2 p o i n t o p e r a t o r() (c o n s t p o i n t& x ) c o n s t { 3 r e t u r n p o i n t( - cos ( pi * x [ 0 ] ) * sin ( pi * x [1]) , 4 sin ( pi * x [ 0 ] ) * cos ( pi * x [ 1 ] ) ) ; } 5 g () : pi ( a c o s (F l o a t( - 1 . 0 ) ) ) {} 6 c o n s t F l o a t pi ; 7 }; 8 s t r u c t f { 9 p o i n t o p e r a t o r() (c o n s t p o i n t& x ) c o n s t { r e t u r n 2*sqr( pi )* _g ( x ); } 10 f () : pi ( a c o s (F l o a t( -1.0))) , _g () {} 11 c o n s t F l o a t pi ; g _g ; 12 };

As the exact solution is known, the error can be computed. The code code elasticity_taylor_error_dg.cc compute the error in L2, Land energy norms. This code

it is not listed here but is available in the Rheolef example directory. The computation writes: make elasticity_taylor_dg elasticity_taylor_error_dg

(38)

mkgeo_grid -t 10 > square.geo

./elasticity_taylor_dg square P1d | ./elasticity_taylor_error_dg ./elasticity_taylor_dg square P2d | ./elasticity_taylor_error_dg

3.2

The Stokes problem

Let us consider the Stokes problem for the driven cavity inΩ =]0, 1[d, d = 2, 3. The problem has

been introduced in volume 1, section4.4, page62. (P ): find u and p, defined in Ω, such that

− div(2D(u)) + ∇p = f in Ω,

− div u = 0 in Ω,

u = g on ∂Ω

where f and g are given. This problem is the extension to divergence free vector fields of the elasticity problem. The variational formulation writes:

(V F )h find u∈ V(g) and p ∈ L2(Ω) such that:

a(u, v) + b(v, p) = l(v), ∀v ∈ V(0), b(u, q) = 0, ∀q ∈ L2(Ω) (3.2) where V(g) = {v ∈ H1(Ω)d; v = g on ∂Ω } a(u, v) = Z Ω 2D(u) : D(v) dx b(u, q) = Z Ω div(u) q dx l(v) = Z Ω f.v dx

The discrete variational formulation writes: (V F )h find uh∈ Xh andph∈ Qh such that:

ah(uh, vh) + bh(vh, ph) = lh(vh), ∀vh∈ Xh,

bh(uh, qh) − ch(ph, qh) = kh(q), ∀qh∈ Qh.

(3.3)

The discontinuous finite element spaces are defined by:

Xh = {vh∈ L2(Ω)d; vh|K ∈ Pkd, ∀K ∈ Th}

Qh = {qh∈ L2(Ω)d; qh|K∈ Pkd, ∀K ∈ Th}

wherek > 1 is the polynomial degree. Notice that velocity and presure are approximated by the same polynomial order. This method was introduced by [9] and some recent theoretical results can be founded in [10]. The forms are defined for all u, v ∈ H1(

(39)

e.g. [11, p. 249]): ah(u, v) = Z Ω 2Dh(u) : Dh(v) dx + X S∈Sh Z S

(β$s[[u]].[[v]]− [[u]].{{2Dh(v)n}} − [[v]].{{2Dh(u)n}}) ds

bh(u, q) = Z Ω u.∇hq dx− X S∈Sh(i) Z S{{u}}.n [[q]] ds ch(p, q) = X S∈Sh(i) Z S hs[[p]] [[q]] ds lh(v) = Z Ω f.v ds + Z ∂Ω g. (β$sv− 2Dh(v) n) ds kh(q) = Z ∂Ω g.n q ds

The stabilization form ch controls the pressure jump accross internal sides. This stabilization

term is necessary when using equal order polynomial approximation for velocity and pressure. The definition of the forms is grouped in a subroutine: it will be reused later for the Navier-Stokes problem.

Example file 3.3: stokes_dirichlet_dg.icc

1 v o i d s t o k e s _ d i r i c h l e t _ d g (c o n s t s p a c e& Xh , c o n s t s p a c e& Qh , 2 f o r m& a , f o r m& b , f o r m& c , f o r m& mp , f i e l d& lh , f i e l d& kh , 3 q u a d r a t u r e _ o p t i o n _ t y p e q o p t = q u a d r a t u r e _ o p t i o n _ t y p e()) 4 { 5 s i z e _ t k = Xh . d e g r e e (); 6 s i z e _ t d = Xh . g e t _ g e o (). d i m e n s i o n (); 7 F l o a t b e t a = ( k + 1 ) * ( k + d )/ d ; 8 t r i a l u ( Xh ) , p ( Qh ); 9 t e s t v ( Xh ) , q ( Qh ); 10 a = i n t e g r a t e (2* d d o t ( Dh ( u ) , Dh ( v )) , q o p t ) 11 + i n t e g r a t e (" s i d e s ", b e t a * p e n a l t y ()* dot ( j u m p ( u ) , j u m p ( v )) 12 - 2* dot ( j um p ( u ) , a v e r a g e ( Dh ( v )* n o r m a l ( ) ) ) 13 - 2* dot ( j um p ( v ) , a v e r a g e ( Dh ( u )* n o r m a l ())) , q o p t ); 14 lh = i n t e g r a t e ( dot ( f () , v ) , q o p t ) 15 + i n t e g r a t e (" b o u n d a r y ", b e t a * p e n a l t y ()* dot ( g () , v ) 16 - 2* dot ( g () , Dh ( v )* n o r m a l ()) , q o p t ); 17 b = i n t e g r a t e ( dot ( u , g r a d _ h ( q )) , q o p t ) 18 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", - dot ( a v e r a g e ( u ) , n o r m a l ( ) ) * j u m p ( q ) , q o p t ); 19 kh = i n t e g r a t e (" b o u n d a r y ", dot ( g () , n o r m a l () ) * q , q o p t ); 20 c = i n t e g r a t e (" i n t e r n a l _ s i d e s ", h _ l o c a l ()* j u m p ( p )* j u m p ( q ) , q o p t ); 21 mp = i n t e g r a t e ( p * q , qo p t ); 22 }

(40)

Example file 3.4: stokes_taylor_dg.cc 1 # i n c l u d e " r h e o l e f . h " 2 u s i n g n a m e s p a c e r h e o l e f ; 3 u s i n g n a m e s p a c e std ; 4 # i n c l u d e " t a y l o r . icc " 5 # i n c l u d e " s t o k e s _ d i r i c h l e t _ d g . icc " 6 int m a i n (int argc , c h a r** a r g v ) { 7 e n v i r o n m e n t r h e o l e f ( argc , a r g v ); 8 geo o m e g a ( ar g v [ 1 ] ) ; 9 s p a c e Xh ( omega , a r g v [2] , " v e c t o r "); 10 s p a c e Qh ( omega , a r g v [ 2 ] ) ; 11 f o r m a , b , c , mp ; 12 f i e l d lh , kh ; 13 s t o k e s _ d i r i c h l e t _ d g ( Xh , Qh , a , b , c , mp , lh , kh ); 14 f i e l d uh ( Xh , 0) , ph ( Qh , 0); 15 s o l v e r _ a b t b s t o k e s ( a . uu () , b . uu () , c . uu () , mp . uu ( ) ) ; 16 s t o k e s . s o l v e ( lh . u () , kh . u () , uh . s e t _ u () , ph . s e t _ u ( ) ) ; 17 d o u t < < c a t c h m a r k(" u ") < < uh 18 < < c a t c h m a r k(" p ") < < ph ; 19 }

Comments

The data are given when d = 2 by (3.1). This choice is convenient since the exact solution is known u= g and p = 0. The code stokes_taylor_error_dg.cc compute the error in L2, L

and energy norms. This code it is not listed here but is available in the Rheolef example directory. The computation writes:

make stokes_taylor_dg stokes_taylor_error_dg mkgeo_grid -t 10 > square.geo

./stokes_taylor_dg square P1d | ./stokes_taylor_error_dg ./stokes_taylor_dg square P2d | ./stokes_taylor_error_dg

3.3

The stationnary Navier-Stokes problem

3.3.1

Problem statemment

The Navier-Stokes problem has been already introduced in volume 1, section 3.3 page37. Here we consider the stationnary version of this problem. LetRe > 0 be the Reynolds number. The problem writes:

(P ): find u and p, defined in Ω, such that

Re (u.∇)u − div(2D(u)) + ∇p = f in Ω,

− div u = 0 in Ω,

u = g on ∂Ω

Notice that, whenRe > 0, the problem is nonlinear, due to the inertia term u.∇u. When Re = 0 the problem reduces to the linear Stokes problem, presented in the previous section/

The variationnal formulation of this nonlinear problem writes: (F V ): find u∈ V(g) and p ∈ L2(Ω) such that

Re t(u; u, v) + a(u, v) + b(v, p) = l(v), ∀v ∈ V(0), b(u, q) = 0, ∀q ∈ L2(Ω)

where the space V(g) and forms a, b and l are given as in the previous section3.2for the Stokes problem and the trilinear formt(.; ., .) is given by:

t(w; u, v) = Z

(41)

3.3.2

The discrete problem

Let t(w; u, u) = Z Ω (w.∇u).u dx Observe that, for all u, w∈ H1(Ω)d we have

Z Ω (w.∇u).u dx = d−1 X i,j=0 Z Ω uiwj∂j(ui) dx = d−1 X i,j=0 − Z Ω ui∂j(uiwj) dx + Z ∂Ω u2 i wjnjdx = d−1 X i,j=0 − Z Ω ui∂j(ui) wjdx− Z Ω u2 i ∂j(wj) dx + Z ∂Ω u2 iwjnjdx = Z Ω (w.∇u).u dx − Z Ω div(w)|u|2dx +Z ∂Ω w.n|u|2ds (3.4) Thus t(w; u, u) = Z Ω (w.∇u).u dx = −1 2 Z Ω div(w)|u|2dx +1 2 Z ∂Ω w.n|u|2ds

When div(w) = 0, the trilinear form t(.; ., .) reduces to a boundary term: it is formaly skew-symmetric. The skew-symmetry oft is an important property: let (v, q) = (u, p) as test functions in(F V ). We obtain:

a(u, u) = l(u)

In other words, we obtain the same energy balance as for the Stokes flow and inertia do not contribute to the energy balance. This is an important property and we aim at obtaining the same one at the discrete level. As the discrete solution uhis not exactly divergence free, following

Temam, we introduce the following modified trilinear form: t∗(w; u, v) =

Z



(w.∇u) .v +12div(w) u.v  dx−12 Z ∂Ω (w.n) u.v ds, ∀u, v, w ∈ H1 (Ω)d This form integrates the non-vanishing terms and we have:

t∗(w; u, u) = 0, ∀u, w ∈ H1(Ω)d

When the discrete solution is not exactly divergence free, it is better to uset∗thant.

The discontinuous finite element spaces Xh andQh and formsah,bh,ch,lh andkhare defined as

in the previous section. Let us introducet∗

h, the following discrete trilinear form, defined for all

uh, vh, wh∈ Xh: t∗h(wh; uh, vh) = Z Ω  (wh.∇huh) .vh+ 1 2divh(wh) uh.vh  dx−12 Z ∂Ω (wh.n) uh.vhds Notice that t∗

h is similar to t∗: the gradient and divergence has been replaced by their broken

counterpart in the first term. As Xh6⊂ H1(Ω)d, the skew-symmetry property is not expected to

be true at the discrete level. Then t∗ h(wh; uh, uh) = X K∈Th Z K  (wh.∇uh) .uh+ 1 2div(wh)|uh| 2  dx1 2 Z ∂Ω (wh.n)|uh|2ds

(42)

As the restriction of uh and wh to each K ∈ Th belongs to H1(K)d, we have, using a similar integration by part: Z K (wh.∇uh).uhdx =− 1 2 Z K div(wh)|uh|2dx + 1 2 Z ∂K (wh.n)|uh|2ds Thus t∗h(wh; uh, uh) = 1 2 X K∈Th Z ∂K (wh.n)|uh|2ds− 1 2 Z ∂Ω (wh.n)|uh|2ds

The terms on boundary sides vanish while those on internal sides can be grouped:

t∗h(wh; uh, uh) = 1 2 X S∈Sh(i) Z S [[|uh|2wh]].n ds

The jump term[[(uh.vh) wh]].n is not easily manageable and could be developed. A short

compu-tation shows that, for all scalar fieldsφ, ϕ we have on any internal side:

[[φϕ]] = [[φ]]{{ϕ}} + {{φ}}[[ϕ]] (3.5) {{φϕ}} = {{φ}}{{ϕ}} +14[[φ]][[ϕ]] (3.6) Then t∗h(wh; uh, uh) = 1 2 X S∈Sh(i) Z S {{w h}}.n [[|uh|2]] + [[wh]].n{{|uh|2}}ds = X S∈Sh(i) Z S  {{wh}}.n ([[uh]].{{uh}}) + 1 2[[wh]].n{{|uh| 2 }}  ds

Thus, as expected, the skew-symmetry property is no more satisfied at the discrete level, due to the jumps of the fields at the inter-element boundaries. Following the previous idea, we introduce the following modified discrete trilinear form:

th(wh; uh, vh) = t∗h(wh; uh, vh)− X S∈Sh(i) Z S  {{wh}}.n ([[uh]].{{vh}}) + 1 2[[wh]].n{{uh.vh}}  ds = Z Ω  (wh.∇huh) .vh+ 1 2divh(wh) uh.vh  dx−12 Z ∂Ω (wh.n) uh.vhds − X S∈Sh(i) Z S  {{wh}}.n ([[uh]].{{vh}}) + 1 2[[wh]].n{{uh.vh}}  ds (3.7)

This expression has been proposed by Pietro and Ern [10, p. 22], eqn (72) (see also [11, p. 272], eqn (6.57)). The boundary term introduced inth may be compensated in the right-hand side:

l∗h(v) := lh(v)− Re 2 Z ∂Ω (g.n) g.vhds

(43)

Example file 3.5: inertia.icc 1 t e m p l a t e<c l a s s W , c l a s s U , c l a s s V > 2 f o r m i n e r t i a ( W w , U u , V v , 3 q u a d r a t u r e _ o p t i o n _ t y p e q o p t = q u a d r a t u r e _ o p t i o n _ t y p e()) 4 { 5 r e t u r n 6 i n t e g r a t e ( dot ( g r a d _ h ( u )* w , v ) + 0 . 5 * d i v _ h ( w )* dot ( u , v ) , q o p t ) 7 + i n t e g r a t e (" b o u n d a r y ", - 0 . 5 * dot ( w , n o r m a l ( ) ) * dot ( u , v ) , q o p t ) 8 + i n t e g r a t e (" i n t e r n a l _ s i d e s ", 9 - dot ( a v e r a g e ( w ) , n o r m a l ( ) ) * dot ( j u m p ( u ) , a v e r a g e ( v )) 10 - 0 . 5 * dot ( j u m p ( w ) , n o r m a l ()) 11 *( dot ( a v e r a g e ( u ) , a v e r a g e ( v )) + 0 . 2 5 * dot ( j u m p ( u ) , ju m p ( v ))) , q o p t ); 12 } 13 f i e l d i n e r t i a _ f i x _ r h s (t e s t v , 14 q u a d r a t u r e _ o p t i o n _ t y p e q o p t = q u a d r a t u r e _ o p t i o n _ t y p e()) 15 { 16 r e t u r n i n t e g r a t e(" b o u n d a r y ", - 0 . 5 * dot ( g () , n o r m a l ( ) ) * dot ( g () , v ) , q o p t ); 17 }

The discrete problem is

(F V )h: find uh∈ Xh andp∈ Qh such that

Re th(uh; uh, vh) + ah(uh, vh) + bh(vh, ph) = l∗h(vh), ∀vh∈ Xh,

bh(uh, qh) − ch(ph, qh) = kh(q), ∀qh∈ Qh

(3.8)

The simplest approach for solving the discrete problem is to consider a fixed-point algorithm. The sequenceu(k)h 

k>0 is defined by reccurence as:

• k = 0: let u(0)h ∈ Xh being known.

• k > 0: let u(k−1)h ∈ Xh given. Find u (k) h ∈ Xhandp (k) h ∈ Qhsuch that Re th  u(k−1)h ; u(k)h , vh  + ah  u(k)h , vh  + bh  vh, p (k) h  = l∗ h(vh), ∀vh∈ Xh, bh  u(k)h , qh  − ch  p(k)h , qh  = kh(q), ∀qh∈ Qh.

Figure

Figure 1.1: Discontinuous Galerkin method: an internal side, its two neighbor elements and their opposite normals.
Fig. 1.2 plots the solution when d = 1 and k = 0 : observe that the boundary condition φ = 1 at x 0 = 0 is only weakly satified
Figure 1.3: The discontinuous Galerkin method for the transport problem: convergence when d = 2.
Figure 1.4: Limiter: the neighbors elements and the middle edge points.
+7

Références

Documents relatifs

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the

Abstract — Under the sole assumption of non-degeneracy of the continuous solution and the knowledge of an U-error estimate, we prove rates of convergence in measure{and in distance)

Manuel Sésamath 5e Copyright © 2010 SESAMATH Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3

The difference between the conservative and dissipative scheme only exits in the choices of numerical flux f which is reflected in the term H j , yet the same estimate results for H

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the