0% found this document useful (0 votes)
29 views44 pages

BEP Westervelt

This document describes a finite element method for solving the 2D Westervelt equation numerically. It first presents analytical solutions to the linear wave equation in 1D and 2D. It then shows how to apply the finite element method to the linear wave equation, nonlinear diffusion, and the full Westervelt equation. Numerical solutions are obtained for 1D and circularly symmetric test cases and compared to the analytical solutions. The error in the finite element solution decreases with finer meshes and time steps.

Uploaded by

nilphilip2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views44 pages

BEP Westervelt

This document describes a finite element method for solving the 2D Westervelt equation numerically. It first presents analytical solutions to the linear wave equation in 1D and 2D. It then shows how to apply the finite element method to the linear wave equation, nonlinear diffusion, and the full Westervelt equation. Numerical solutions are obtained for 1D and circularly symmetric test cases and compared to the analytical solutions. The error in the finite element solution decreases with finer meshes and time steps.

Uploaded by

nilphilip2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Finite Element Method for two

dimensional Westervelt Equa-


tion

Leo Hendriks - 4605594

Technische Universiteit Delft


September 21, 2021
Under the supervision of
D.J.P. Lahaye and M. Verweij
Contents

1 Abstract 1
2 Introduction 2
3 Linear Wave Behaviour 3
3.1 1D Wave solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 2D Wave Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2.1 Separation of Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2.2 Green’s Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 Finite Element Method for linear Wave 12
4.1 Weak Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2 Space Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Time Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.4 Verlet Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.4.1 Verlet for linear wave equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Finite Element Method for Non-linear Diusion 15
5.1 Weak Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.2 Space Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.3 Iteration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6 Finite Element Method for Westervelt 17
6.1 Weak Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.2 Space Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.3 Verlet Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.4 Iteration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7 Implementation 20
7.1 Mesh Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.2 Base Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.3 Element-wise Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7.4 Vectorized Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.5 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8 Results 25
8.1 One Dimensional Wave Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
8.1.1 Linear Solution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
8.1.2 Westervelt Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.2 Circular Symmetric Two Dimensional Wave Example . . . . . . . . . . . . . . . . . . . . . . . 28
8.2.1 Linear Solution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.2.2 Westervelt Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.3 Non-linear Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
8.4 Mesh Size vs Error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8.5 Time Step vs Error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9 Conclusion 38
10 Discussion 39
Bibliography 41
A Appendix 42

ii
1
Abstract
This essay shows a two dimensional implementation of the finite element method for the Westervelt equa-
tion. To do this the finite element method is first applied to the linear wave equation, then to non-linear
diffusion and finally to the Westervelt equation. Both an element by element and a faster vectorized imple-
mentation are given for the finite element method. To verify the numerical solution two analytical solutions
are used. The first is a one dimensional wave and the second a circularly symmetric wave.
We found that the two-dimensional implementation was successful in computing the Westervelt equa-
tion. The error of the solution has this relation with the mesh element size ϵ ∝ l c 1.7 . It was also found that
the time step used to compute the solution needs to be small enough for the implementation to converge.

1
2
Introduction
For most applications waves can be described by the general linear wave equation. Which can be solved
analytically on simple domains or numerically approximated by using the finite difference method, finite
element method or the integral equation method, when dealing with difficult domains. However, when deal-
ing with high pressure or high frequency waves these approaches are no longer sufficient. This is due to the
non-linear effects caused by the large and fast changes in pressure.
The non-linear effects are caused by both the distortion of the wave profile due to convection and the
difference in compression which results in different propagations speeds [1]. From these two sources the
second one is by far the most influential. There are various different equations that are used to describe
non-linear wave equations. In this thesis we will be focusing on the Westervelt equation [2].

1 ∂2 u β ∂2 u 2
∇2 u − = − (2.1)
c 02 ∂t 2 ρ 0 c 04 ∂t 2
With u the pressure field, c 0 the small signal sound speed, ρ 0 the ambient density of mass and β the
coefficient of non-linearity. The coefficient of non-linearity β is a dimensionless quantity that is inherent to
the material that the wave is propagating through. This value is discussed in depth in both [1] and [2] though
it is most often found empirically.
This equation is equal to the linear wave equation when using β = 0. It can be seen that the non-linear
2 2
term depends on ∂∂tu2 which becomes more influential when the amplitude of u increases or the frequency
of change in u increases. Thus we see that the expected behaviour of this equation agrees with the theory of
non-linear waves.
There are no analytical solutions for the Westervelt equation, thus for solving non-linear wave problems
one must rely on using numerical methods. The finite element method is an incredibly powerful tool to solve
any partial differential equation on difficult domains. The finite element method can be used for a lot of
different applications like calculating the heat diffusion in a chip or the air flow around a building. In the
work of [3] and [4] it has been shown that the finite element method can be extended to solve the Westervelt
equation in one dimension. The goal of this thesis is to further expand on their work to solve the Westervelt
equation in two dimensions.
In Chapter 3 we will discuss two different analytical solutions to the linear wave equation that we will
use to verify the FEM implementation. Then in the next chapter we will first apply the regular finite element
method to solve the linear wave equation. To get familiar with non-linearities we will then use the finite
element method to solve the non-linear diffusion equation in chapter 5. After this we will solve the Westervelt
equation by using a finite element solution. The next chapter will discuss the implementation of the theory
discussed in the previous chapter. We will be using both an element by element implementation and a faster
vectorized implementation. Using these implementations we will show and discuss the results in chapter 8.
Here we will also look at the relation between the error and the time step and element size. In chapter 9 the
conclusion to this thesis can be found. Finally we will discuss the results in Chapter 10.

2
3
Linear Wave Behaviour
In this chapter we will discuss several analytical solutions to the wave equation that we can later use to verify
our FEM implementation. In classical mechanics when trying to describe a simple wave a very powerful
formula is the wave equation:
∂2 u
= c 02 ∇2 u (3.1)
∂t 2
This equation can be used to describe all kind of waves, like light, water and sound waves. the c 0 in this for-
mula is the speed of the wave and u is a function of time and space that shows the wave behaviour. This can
for example be a pressure field or the perturbation of a string in a direction.

To verify our two dimensional FEM implementation from section 4 we will find two analytical solutions
to the linear wave equation. The first is a one dimensional analytical solution with the same boundary and
initial conditions as [4]. We can compare this solution to the FEM solution in a two dimensional channel with
Neumann zero boundaries. Secondly, we will also compute a circular symmetric two dimensional solution
for a Gaussian initial condition on the infinite domain.

3.1. 1D Wave solution


In 1D we will look at the semi-infinite domain with a time dependent boundary condition at zero as was done
in [4]. Our objective is to solve the following problem:

∂2 u ∂2 u
= c 02 2

 (3.2a)
∂t ∂x



 2
∂u(x, 0)
u(x, 0) = 0 =0 0≤x <∞ (3.2b)
∂t






u(0, t ) = h(t ) (3.2c)

Here h(t) is any time dependent function. To solve this problem we will extend it to the infinite domain and
use appropriate initial conditions to simulate the boundary at x = 0. The solution to our problem is then
equal to this solution for all values 0 ≤ x < ∞. This is the definition of the new problem.

∂2 u ∂2 u
= c 02 2

(3.3a)


∂t 2 ∂x

 ∂u(x, 0)
u(x, 0) = f (x) = g (x) −∞ < x < ∞ (3.3b)


∂t

The functions f (x) and g (x) are the initial conditions. The solution to this problem can be found by using
characteristic coordinates. We now rewrite u as the sum of two new function, one that moves right with speed
c 0 and one that moves left with the same speed.

u(x, t ) = F (x − c 0 t ) +G(x + c 0 t ) = F (ζ) +G(η) (3.4)

3
4 3. Linear Wave Behaviour

This sum can be entered into our initial conditions.



 u(x, 0) = F (x) +G(x) = f (x)
 (3.5a)
∂u(x, 0) ∂h i¯
= F (x − c 0 t ) +G(x + c 0 t ) ¯ = g (x) (3.5b)
 ¯
∂t ∂t

t =0

Using the chain rule we can rewrite 3.5b to the following. After applying the chain rule we evaluate the deriva-
tives at t = 0.
h ∂(x − c t ) ∂F (x − c t ) ∂(x + c t ) ∂G(x + c t ) i¯
0 0 0 0
+ = g (x) (3.6a)
¯
∂t ∂(x − c 0 t ) ∂t ∂(x + c 0 t ) t =0
¯

dF (x) dG(x)
−c 0 + c0 = g (x) (3.6b)
dx dx

Now by rewriting 3.5a and combining that with 3.6b we can find an expression for F (x) and G(x).

df dG dG
g (x) = −c 0 + c0 + c0 (3.7a)
dx dx dx
dG df
2c 0 = c0 +g (3.7b)
dx dx
Z x
1 1
G(x) = f (x) + g (x̃) d x̃ + const (3.7c)
2 2c 0 0
Z x
1 1
F (x) = f (x) − g (x̃) d x̃ − const (3.7d)
2 2c 0 0

By filling in this result in our initial proposition 3.4 we find our solution on an infinite domain, the constants
can be neglected by adding 3.7c and 3.7d with proper shifts. This is the d’Alembert’s Solution to the one
dimensional wave problem.

f (x − c 0 t ) + f (x + c 0 t ) 1
Z x+c 0 t
u(x, t ) = + g (x̃) d x̃ (3.8)
2 2c 0 x−c 0 t

We will now return to the original problem 3.2. Our goal is extend the original problem to the infinite
domain. Our previous derivation still holds for 0 < x < ∞. We can thus apply 3.7c and 3.7d with the initial
conditions 3.2b, in other words f (x) = 0 and g (x) = 0.

F (x) = 0 x >0 (3.9a)


G(x) = 0 x >0 (3.9b)

We will now solve our problem for two different cases x > c t and x < c t . For the first case, when x > c t > 0 it
follows that x − c t > 0 and x + c t > 0. We can use this in equation 3.4 to find the solution for this case.

u(x, t ) = F (x − c 0 t ) +G(x + c 0 t ) = 0 for x > c 0 t (3.10)

This result follows directly from 3.9a and 3.9b. We now move on to the second case where x < c t . We will now
use the boundary condition at x = 0.

u(0, t ) = F (−c 0 t ) +G(c 0 t ) = h(t ) for t > 0 (3.11)

We can substitute z ≡ −c 0 t into this equation and rewrite it to F (z). Note that z < 0, since t > 0, so this does
not disagree with 3.9a.
µ ¶
−z
F (z) = h −G(−z) for z < 0 (3.12)
c0
We now again use equation 3.4 to find our solution.

x
µ ¶
u(x, t ) = F (x − c 0 t ) +G(x + c 0 t ) = h t − −G(c 0 t − x) +G(x + c 0 t ) for 0 ≤ x < c 0 t (3.13)
c0
3.2. 2D Wave Solution 5

We restrict our solution here to only x ≥ 0, since that is the only interval we are interested in. From 0 ≤ x < c 0 t
it follows that c 0 t − x > 0 and x + c 0 t > 0 . Using this we can simplify our result and write down our final
solution to problem 3.2.
h t − x
 µ ¶
0 ≤x < c 0 t
u(x, t ) = c0 (3.14)
0 x > c0 t

This solution is the boundary condition moving to the right at speed c 0 , which is exactly what one would
expect for this problem.

3.2. 2D Wave Solution


In this section we will find an analytical solution to the 2D wave equation for a circularly symmetric case.
We can use this solution to verify the FEM solution we will find in section 4. We wish to solve the following
problem on the infinite domain:

∂2 u

= c 02 ∇2 u (3.15a)


∂t 2



2
−r
∂u(r, θ, 0)


u(r, θ, 0) = u(r, 0) = Ae 2σ2

 =0 (3.15b)
∂t
This is the general linear wave equation with an initial displacement of a Gaussian peak.

3.2.1. Separation of Variables


To solve this problem we will use separation of variables. Also note that this problem is circularly symmetric,
so the solution does not depend on θ.

u(r, θ, t ) = u(r, t ) = φ(r )h(t ) (3.16)

Filling this in into the partial differential equation and dividing by c 02 φ(r )h(t ) gives us the separable solution.
As a separation constant we will use −λ.

1 d2 h 1
= −λ = ∇2 φ (3.17)
2 dt 2
c0 h φ

We can split this up into two ordinary differential equations. We can also fill in the Laplacian in polar co-
ordinates. Since φ does not depend on θ, we will also immediately drop the second term of the Laplacian.

d2 h
2
+ λc 02 h = 0 (3.18a)
µdt ¶
1 d dφ
r + λφ = 0 (3.18b)
r dr dr
The solution to the first ode is often seen in separation of variables and is equal to:
p p p
h(t ) = Acos(c λt ) + B si n(c λt ) = Acos(c 0 λt ) (3.19)

The fact that B = 0 follows from the initial condition ∂u(r,θ,0)


∂t = 0.
To solve the second ordinary differential equation we need two boundary conditions on φ(r ). Firstly, we
note that the solution should be finite, thus ¯φ(0)¯ < ∞. Secondly we will choose a sufficiently large R for
¯ ¯

which we will set φ(R) = 0. This means that our solution will be valid up to a maximum time t max where
the initial displacement reaches
p the boundary. We will now rewrite the second ordinary differential equation
slightly and substitute in z = λr .

d2 φ dφ
r2 +r + λr 2 φ = 0 ⇒ (3.20a)
dr 2 dr
d2 φ dφ
z2 2 + z + z2φ = 0 (3.20b)
dz dz
6 3. Linear Wave Behaviour

The solution to this ordinary differential equation are the Bessel functions of order 0.

p p
φ(r ) = c 1 J 0 (z) + c 2 Y0 (z) = c 1 J 0 ( λr ) + c 2 Y0 ( λr ) (3.21)
p
Since Y0 ( λr ) is infinite for r = 0, it follows from the first boundary condition that c 2 = 0. From the second
boundary condition we can find the eigenvalues of this problem.
p
J 0 ( λR) = 0 ⇒ (3.22a)
³ z ´2
n
λn = (3.22b)
R

where z n is the nth zero of J 0 . We have now found an infinite set of solutions. We can now use the principle of
superposition and fill in our two solutions to the ordinary differential equations to find the general solution
to our problem (we combine the two arbitrary constants into one constant c n ).

∞ p p
c n J 0 ( λn r )cos(c 0 λn r )
X
u(r, t ) = (3.23)
n=1

The last thing that is left is to compute the constants c n . To do this we need to use the initial solution 3.15b.
From now on it is more convenient to use z n instead of λn .

−r 2
∞ ³z ´
n
Ae 2σ2 =
X
cn J 0 r (3.24)
n=1 R

We can isolate one specific³ c n by using the orthogonality of the Bessel functions with weight r . To do this, we
zn ´
multiply both sides by r J 0 r and integrate from 0 to R.
R

−r 2 ³
RR zn ´
0 Ae 2σ2 J 0 r r dr
cn = R (3.25)
R R ³ z n ´2
0 J0 r r dr
R
The denominator of this fraction can be calculated analytically. In [5] the following result is given (note that
the Bessel functions are indeed orthogonal).

1 δnm
Z
J i (µn x)J i (µm x)x d x = J i +1 (µn )2 (3.26)
0 2

where µn is equal to the nth zero of J i . We can now find our integral by entering i = 0, substituting in r = R x
and using that µn = z n when i = 0.
Z R ³ r ´2 r d r 1
J 0 zn = J 1 (z n )2 ⇒ (3.27a)
0 R R R 2
R2
Z R ³
z n ´2
J0 r r dr = J 1 (z n )2 (3.27b)
0 R 2

Using this result we can write down our final solution for our problem.

−r 2 ³
 
∞ 2
Z R z ´ ³z ´ ³ z ´
X  2σ2 n n n
u(r, t ) =  Ae J0 r r  d r J0 r cos c 0 r (3.28)

2 2
n=1 R J 1 (z n ) 0 R R R

We will use a numerical approximation to compute this integral and choose a large enough N to approximate
the sum.
3.2. 2D Wave Solution 7

3.2.2. Green’s Function


As an alternative to separation of variables we can use the Green’s function to solve the partial differential
equation. The pro of this solution is that it is valid on the infinite domain.For a 2D wave the solution using
Green’s function is given by:

Z tÏ
u(⃗
x, t ) = G(⃗ x 0 , t 0 ) d 2 x⃗0 d t 0
x , t ; x⃗0 , t 0 )Q(⃗
0
∂u ∂G
Ï · ¸
+ x 0 , 0)G(⃗
(⃗ x , t ; x⃗0 , 0) − u(⃗ x 0 , 0) x , t ; x⃗0 , 0) d 2 x⃗0
(⃗ (3.29)
∂t 0 ∂t 0
Z t ·I ¸
− c 02 x , t ; x⃗0 , t 0 ) −G(⃗ x , t ; x⃗0 , t 0 )∇x⃗0 u(⃗
¡ ¢
u(⃗ x 0 , t 0 )∇x⃗0 G(⃗ x 0 , t 0 ) · n̂ d l d t 0
0

∂u(r,θ,0)
This equation can be simplified for our problem. Using Q(⃗
x , t ) = 0, ∂t = 0 and the fact that we are using
the infinite domain we can reduce the equation to just:

∂G
Ï
u(⃗
x, t ) = − u(⃗
x 0 , 0) x , t ; x⃗0 , 0) d 2 x 0
(⃗ (3.30)
∂t 0
From [6] we know that the Green’s function for a 2D wave is given by (with r = |x − x 0 |):

0

 r > c 0 (t − t 0 )
x , t ; x⃗0 , t 0 ) = G(r, t ; t 0 ) =
G(⃗ 1 1 (3.31)
q r < c 0 (t − t 0 )
 2πc 0 c 2 (t − t )2 − r 2


0 0

∂G
Using properties of the Green’s function we can show that ∂t 0 = − ∂G
∂t from which we find:

1 ∂ 1
Ï
u(⃗
x, t ) = u(⃗
x 0 , 0) d 2 x⃗0 (3.32)
∂t
q
2πc 0 x −x⃗0 |<c 0 t
|⃗
x − x⃗0 |2
c 02 t 2 − |⃗

Now using x⃗1 ≡ x⃗0 −⃗


x we can rewrite this into an integral over x⃗1 :

1 ∂ 1
Ï
u(⃗
x, t ) = u(⃗
x 1 +⃗
x , 0) q d 2 x⃗1 (3.33)
2πc 0 |x⃗1 |<c0 t ∂t
x 1 |2
c 02 t 2 − |⃗

We can now simplify this equation by integrating using polar coordinates.


 
∂ 
Z 2π Z c0 t q
1 1
u(r, θ, t ) = u( r 12 + r 2 + 2r 1 r cos(θ1 − θ), 0)  q  r 1 d r 1 d θ1 (3.34)

2πc 0 0 0 ∂t 2 2 2
c0 t − r 1

Now lets see if we can simplify the time derivative:

1 1 1
G(r 1 , t ) = = Q(ξ) (3.35)
2πc 0 c 2 t 2 − r 2 2πc 0 r 1
q
0 1

c0 t
where ξ = and where:
r1
1
Q(ξ) = p (3.36)
ξ2 − 1
Using Q we find the following result using the chain rule:

∂Q dQ ∂ξ c 0 t dQ dQ r 2 ∂Q
= =− 2 ⇒ =− 1 (3.37)
∂r 1 dξ ∂r 1 r 1 dξ dξ c 0 t ∂r 1
From this we can rewrite the integral from a time derivative to a derivative in r 1 .

∂G 1 ∂Q 1 dQ ∂ξ 1 dQ 1 ∂Q
= = = =− (3.38)
∂t 2πc 0 r 1 ∂t 2πc 0 r 1 dξ ∂t 2πr 12 dξ 2πc 0 t ∂r 1
8 3. Linear Wave Behaviour

We can now enter this result in our integral to find the following equation.

1 2π Z c 0 t ∂ 1
Z q
u(r, θ, t ) = − u( r 12 + r 2 + 2r 1 r cos(θ1 − θ), 0)r 1 d r 1 d θ1 (3.39)
∂r 1 µ c t ¶2
s
2πc 0 t 0 0
0
−1
r1

Integration by parts gives us:

q
q ∂u( r 12 +r 2 +2r 1 r cos(θ1 −θ),0)
1
Z 2π Z c 0 t u( r 12 + r 2 + 2r 1 r cos(θ1 − θ), 0) + r 1 ∂r 1
u(r, θ, t ) = sµ d r 1 d θ1 (3.40)
2πc 0 t 0 0 c0 t 2

−1
r1

Now filling in the original equation gives:

! −r 12 − r 2 − 2r 1 r cos(θ1 − θ)
r 12
Ã
r 1 r cos(θ1 − θ)
1− 2 − e 2σ2
1
Z 2π Z c 0 t σ σ2
u(r, θ, t ) = sµ d r 1 d θ1 (3.41)
2πc 0 t 0 0 c0 t 2

−1
r1

We can rewrite this into:

 
r1r r1r
r 12
à !
− cos(θ1 −θ) r1r − cos(θ1 −θ)
1− e σ 2
− 2 cos(θ1 − θ)e σ2
 
σ2 σ
Z 
1
Z c0 t  2π 
u(r, θ, t ) = d θ1  d r 1 (3.42)
 
r 12 + r 2 sµ

2πc 0 t 0  0 ¶2 
c0 t
 
e 2σ2 −1
 
r1

From [5] we know that the following holds for the modified Bessel function:

1
Z π si n(απ)
Z ∞
I α (x) = e xcos(θ) cos(αθ) d θ − e −xcosh(t −αt ) d t (3.43)
π 0 π 0

Using this we can find the following two results:

1
Z π
I 0 (x) = e xcos(θ) d θ (3.44a)
π 0

1
Z π
I 1 (x) = cos(θ)e xcos(θ) d θ (3.44b)
π 0

By substituting in θ = θ ′ + π and using cos(θ + π) = −cos(θ) we can find the following result. We also use that
I 0 (x) is an even function and I 1 (x) is odd.
Z 2π Z π Z 2π
e xcos(θ) d θ = e xcos(θ) d θ + e xcos(θ) d θ
0 0 π
Z π (3.45a)

= πI 0 (x) + e −xcos(θ ) d θ ′ = πI 0 (x) + πI 0 (−x) = 2πI 0 (x)
0

Z 2π Z π Z 2π
xcos(θ) xcos(θ)
cos(θ)e dθ = cos(θ)e dθ + cos(θ)e xcos(θ) d θ
0 0 π
Z π (3.45b)

= πI 1 (x) + −cos(θ ′ )e −xcos(θ ) d θ ′ = πI 1 (x) − πI 1 (−x) = 2πI 1 (x)
0
3.2. 2D Wave Solution 9

Now we substitute in θ ′ = θ1 − θ and use the fact that 0 ≤ θ < 2π.


Z 2π ′
Z 2π+θ
2πI 0 (x) = e xcos(θ ) d θ ′ = e xcos(θ1 −θ) d θ1
0 θ
Z 2π+θ Z 2π
= e xcos(θ1 −θ) d θ1 + e xcos(θ1 −θ) d θ1
2π θ
Z θ (3.46a)
Z 2π
= e xcos(θ1 −θ) d θ1 + e xcos(θ1 −θ) d θ1
0 θ
Z 2π
= e xcos(θ1 −θ) d θ1
0
Z 2π ′
Z 2π+θ
2πI 1 (x) = cos(θ ′ )e xcos(θ ) d θ ′ = cos(θ1 − θ)e xcos(θ1 −θ) d θ1
0 θ
Z 2π+θ Z 2π
= cos(θ1 − θ)e xcos(θ1 −θ) d θ1 + cos(θ1 − θ)e xcos(θ1 −θ) d θ1
2π θ
Z θ (3.46b)
Z 2π
xcos(θ1 −θ) xcos(θ1 −θ)
= cos(θ1 − θ)e d θ1 + cos(θ1 − θ)e d θ1
0 θ
Z 2π
= cos(θ1 − θ)e xcos(θ1 −θ) d θ1
0
We can fill in the result of equation [3.46a] and [3.46b] into equation [3.42].

r 12
à !
r1r r1r r1r
Z c0 t 1 − σ2 I 0 ( σ2 ) + σ2 I 1 ( σ2 )
1
u(r, θ, t ) = d r1 (3.47)
c0 t 0 r 12 + r 2 sµ ¶2
c0 t
e 2σ2 −1
r1

This can be rewritten to:


 
³r r ´
1
r I
1 c0 t ∂   1 0 σ2  1
Z 
u(r, θ, t ) = d r1 (3.48)
∂r 1  r 2 + r 2  µ
 s
c0 t 0 1 c0 t
¶2
−1
e 2σ2 r1
The equation 3.47 can be approximated numerically similar to the solution found by separation of vari-
ables. However there are two downsides to using this solution. Firstly the integral goes to infinity on the two
integration boundaries, which makes it harder to approximate. Secondly, to use this solution you need to
solve the integral for each value of r and t. For the separation of variables solution however you just need
to numerically approximate the integral once to calculate the constants. After which you can compute the
solution for any r or t values by computing a simple sum. This saves a lot of computation time. The pro of
working on the infinite domain does not outweigh these downsides and that is why we will use the separation
of variables solution in the rest of this thesis.
10 3. Linear Wave Behaviour

Figure 3.1: 2D plot of the finite element solution to the 1-dimensional problem. For more information on the parameters of the plot see
table 8.1.
3.2. 2D Wave Solution 11

Figure 3.2: 2D plot of the finite element solution to the 2-dimensional circularly symmetric problem. For more information on the
parameters of the plot see table 8.2.
4
Finite Element Method for linear Wave
In this chapter we will use the Galerkin’s finite element method to solve the linear wave equation with the
following boundary and initial conditions in 2 dimensions.

1 ∂2 u
∇2 u − 2 2 = f on Ω

(4.1a)


c 0 ∂t





∂u(x, y, 0)

u(x, y, 0) = g (x, y) = h(x, y) (4.1b)


 ∂t
∂u(x, y, t )



u(x, y, t ) = 0 ∀t on ∂ΩD n = 0 ∀t on ∂ΩN
= ∇u(x, y, t ) ·⃗ (4.1c)


∂n
Furthermore it is given that ∂ΩD ∪ ∂ΩN = ∂Ω and ∂ΩD ∩ ∂ΩN = ;. Furthermore f is an arbitrary source
function that can depend on x, y and t .

4.1. Weak Form


Before we can use the finite element method on the wave equation we first need to convert it to its weak form.
To do this we first multiply 4.1a by a test function v(x, y) and then integrate over the domain.

1 ∂2 u
Ï Ï Ï
v∇2 u d x d y − v dx dy = v f dx dy (4.2)
Ω c 02 Ω ∂t 2 Ω

For 4.2 and 4.1a to be equivalent we need to have 2 conditions on our test functions v, namely that the test
functions need to be smooth and that v(x, y, t ) = 0 on ∂ΩD .
To simplify the equation 4.2 we will make use of Green’s first identity, which is based on the divergence
theorem and ∇ (v∇u) = v∇2 u + ∇v∇u.
∂u
Ï Z
¡ 2 ¢
v∇ u + ∇v∇u d x d y = v ds (4.3)
Ω ∂Ω ∂n

Because we know that ∂u


∂n = 0 on ∂ΩN and v(x, y, z, t ) = 0 on ∂ΩD , we find that the right hand side is equal
to zero.
Using equation 4.3 we can simplify the leftmost term of equation 4.2.

1 ∂2 u
Ï Ï Ï
− ∇v∇u d x d y − v dx dy = v f dx dy (4.4)
Ω c 02 Ω ∂t 2 Ω

This is the weak form of the linear wave equation.

4.2. Space Discretization


The next step in our solution is to create a mesh of our domain consisting of a set of nodes x⃗i = (x i , y i ) and
a set of elements e k . Let η denote the number of nodes. For each of the nodes we create a basis function
x = x⃗i ) = 1 and φi (⃗
φi (x, y) with φi (⃗ x = x⃗j ) = 0 for ∀ j ̸= i .

12
4.3. Time Differentiation 13


Using these base functions we can approximate our solution u by u h (x, y, t ) = i =1 c i (t )φi (x, y) and let
our test functions equal the basis functions. By entering u ≈ u h and v = φ j into equation 4.4 we find the
following equation:

η η ·Ï ¸ 2
∂ ci
·Ï ¸
1 X
Ï
φi φ j d x d y φj f d x d y
X
− ∇φi ∇φ j d x d y c i − 2 = ∀j (4.5)
i =1 Ω c 0 i =1 Ω ∂t 2 Ω

We can rewrite this system of ordinary differential equations using matrices.

1 ∂2
− S⃗
c (t ) − M c (t ) = ⃗
⃗ f (t ) (4.6)
2
c0 ∂t 2

This equation uses the following matrices and vectors:


Ï
Si , j = ∇φi ∇φ j d x d y ∀i , j (4.7a)
ÏΩ
Mi , j = φi φ j d x d y ∀i , j (4.7b)


c j (t ) = c j (t ) ∀j (4.7c)
Ï

f j (t ) = φ j (x, y) f (x, y, t ) d x d y ∀j (4.7d)

c and ⃗
⃗ f are η × 1 vectors, since j goes from 1 to η. And S and M are η × η matrices, since i also ranges from 1 to
η.

4.3. Time Differentiation


To solve this second order system of ordinary differential equations we first rewrite our problem to have the
differential equations on the left side.

∂2
c (t ) − c 02 ⃗
³ ´
c (t ) = M −1 −c 02 S⃗
⃗ f (t ) (4.8)
∂t 2

This equation can be solved using a multitude of solvers for second order system of ordinary differential
equations. It is also possible to solve this system by using the following system of first order equations, created

using ∂t ⃗
c = σ:

∂⃗
c
Mσ = M (4.9a)
∂t
∂σ
c − c 02 ⃗
³ ´
= M −1 −c 02 S⃗ f (4.9b)
∂t

In this project we will directly solve the second order system by using Verlet integration.

4.4. Verlet Integration


The Verlet method can be used to solve second order systems of ordinary differential equations. This method
is typically used in physics for solving Newtonian problems. To use Verlet integration on a second order
system of ordinary differential equation like 4.10a one needs two initial conditions.

∂2⃗ x
=p⃗(⃗x (t ), t ) (4.10a)
∂t 2

x (t 0 ) = ⃗
x0 (4.10b)
∂⃗
x
(t 0 ) = ⃗
v0 (4.10c)
∂t

One can now integrate over time by choosing a step size ∆t . The smaller the step size chosen, the smaller the
error and the longer the computation time. We will use the following notation in the future:
14 4. Finite Element Method for linear Wave

t ℓ = t 0 + ℓ ∗ ∆t (4.11a)
xℓ = ⃗
⃗ x (t ℓ ) (4.11b)

Using this notation we can write down the formula for Verlet integration.

x0 = ⃗
⃗ x0 (4.12a)
1
x1 = ⃗
⃗ v 0 + ∆t 2 p
x 0 + ∆t⃗ ⃗(⃗ x0 , t0 ) (4.12b)
2
x ℓ = 2⃗
⃗ x ℓ−1 −⃗x ℓ−2 + ∆t 2 p x ℓ−1 , t ℓ−1 )
⃗(⃗ (4.12c)

Using Verlet integration we can calculate the value of ⃗


x (t ) for any t after t 0 .

4.4.1. Verlet for linear wave equation


For the linear wave equation we have rewritten our problem into a second order system of ordinary differ-
ential equations that we can solve using Verlet integration, since the two necessary initial conditions follow
from 4.1b.


c i (0) = u(x i , y i , 0) = g (x i , y i ) ∀i (4.13a)
∂ ∂

c i (0) = u(x i , y i , 0) = h(x i , y i ) ∀i (4.13b)
∂t ∂t

cℓ = ⃗
We now find the finite element solution to the linear wave equation (using ⃗ c (t ℓ )) by using these initial
conditions and using equation 4.8.

c0 = ⃗
⃗ c (0) (4.14a)
∂ 1
c (0) − c 02 ⃗
³ ´
c1 = ⃗
⃗ c (0) + ∆t ⃗ c (0) + ∆t 2 M −1 −c 02 S⃗ f (t 0 ) (4.14b)
∂t 2
c ℓ−1 − c 02 ⃗
³ ´
ℓ ℓ−1 ℓ−2

c = 2⃗ c c
−⃗ + ∆t M2 −1
−c 02 S⃗ f (t ℓ−1 ) (4.14c)
Finite Element Method for Non-linear
5
Diffusion
Before solving the Westervelt equation we will solve the Non-linear Diffusion equation as an intermediate
step. In this chapter we will use an iteration procedure combined with the finite element method to solve the
non-linear diffusion equation in 2 dimensions:



 ∇2 u + αu 2 = f on Ω (5.1a)

u(x, y) = 0 on ∂ΩD (5.1b)

 ∂u(x, y)
n = 0 on ∂ΩN

= ∇u(x, y) ·⃗ (5.1c)


∂n

Here α is the constant of non-linearity. It is given that ∂ΩD ∪ ∂ΩN = ∂Ω and ∂ΩD ∩ ∂ΩN = ;. Furthermore f
is an arbitrary source function that can depend on both x and y.

5.1. Weak Form


As in the previous section we first need to convert this equation to the weak form. For this we multiply by the
by a test function v(x, y) and then integrate over the domain.
Ï Ï Ï
v∇2 u d x d y + vαu 2 d x d y = v f dx dy (5.2)
Ω Ω Ω

For the weak form to be equivalent to equation 5.1a we need the same conditions on the test functions as
the previous section. To find the final weak form we again use the Green’s first identity 4.3.
Ï Ï Ï
− ∇v∇u d x d y + vαu 2 d x d y = v f dx dy (5.3)
Ω Ω Ω

5.2. Space Discretization


For the space discretization our solution we will create a mesh with basis functions as in section 4.2. Using

these base functions and approximating our solution with u h (x, y) = i =1 c i φi (x, y) we rewrite the weak form
into the following non-linear problem:
η ·Ï ¸ Ï Ï
∇φi ∇φ j d x d y c i + α φ j [u h (x, y)]2 d x d y = φj f d x d y
X
− ∀j (5.4)
i =1 Ω Ω Ω

This problem can be rewritten using vectors and matrices.

c + α⃗
− S⃗ c) = ⃗
b(⃗ f (5.5)

c and ⃗
The vectors ⃗ f and matrix S are identical to equation 4.7. We define the η × 1 vector ⃗
b as (η denotes the
number of nodes): Ï
⃗b(⃗
c)j = φ j [u h (x, y)]2 d x d y ∀j (5.6)

15
16 5. Finite Element Method for Non-linear Diffusion

5.3. Iteration
We now want to solve this non-linear problem by iterating to a better and better solution. We will use the

index n to denote the current iteration. Filling in ⃗
c n and u n = i =1 ⃗
c in φi (x, y) into equation 5.5 gives us this:

c n + α⃗
−S⃗ cn) = ⃗
b(⃗ f (5.7)
with
Ï
⃗ cn)j =
b(⃗ φ j [u n ]2 d x d y (5.8)

By using the approximation [u n ]2 ≈ u n u n−1 we can rewrite the vector ⃗ c n ) to the following matrix vector
b(⃗
product:

⃗ c n ) ≈ N (⃗
b(⃗ c n−1 )⃗
cn (5.9)
with
Ï
c n )i , j
N (⃗ = φi φ j u n d x d y (5.10)

With N of size η × η. We can do this since


Ï Ï η η ·Ï ¸
⃗ cn)j ≈ n
φj u u n−1
φj c in φi u n−1 d x d y =
⃗ φi φ j u n−1
c in
dx dy ⃗
X X
b(⃗ dx dy = ∀j (5.11)
Ω Ω i =1 i =1 Ω

In section 7.3 we will find an implementation to compute this N matrix.


Finally, we write down our complete iteration process. For our initial ⃗
c 0 we will use the solution to the
linear problem (α = 0). To make sure that our solution converges we multiply by a damping constant ω.

c 0 = −S −1 f
⃗ (5.12a)
c tnemp
⃗ = (−S + αN (⃗
c n−1 −1
)) f (5.12b)
n n−1

c =⃗
c c tnemp
+ ω(⃗ c
−⃗ n−1
) (5.12c)

The iteration will continue until either a maximum number of iterations is reached or the difference between

c n and ⃗
c n−1 is below a certain minimum difference.
6
Finite Element Method for Westervelt
In this chapter we will use the finite element method, the iteration from the previous section and Verlet inte-
gration to solve the Westervelt equation in 2 dimensions.

1 ∂2 u β ∂2 u 2
∇2 u − 2 2 +

= f on Ω (6.1a)


c 0 ∂t ρ 0 c 04 ∂t 2






u(x, y, t ) = 0 on ∂ΩD , ∀t




 (6.1b)
∂u(x, y, t )

= ∇u(x, y, t ) ·⃗n = 0 on ∂ΩN , ∀t (6.1c)



 ∂n
u(x, y, 0) = g (x, y) on Ω (6.1d)





∂u(x, y, 0)


= h(x, y) on Ω

(6.1e)


∂t

Here β is the constant of non-linearity and ρ 0 is the material ambient density. It is again given that ∂ΩD ∪
∂ΩN = ∂Ω and ∂ΩD ∩ ∂ΩN = 0. Furthermore f is again an arbitrary source function that can depend on x, y
and t .

6.1. Weak Form


As in the previous two sections, before we can use the finite element method we first need to convert the
equation to its weak form. The first step in this is to multiply by a test function v(x, y) and then integrate over
the domain.
1 ∂2 u β ∂2 u 2
Ï Ï Ï Ï
v∇2 u d x d y − v 2 2 dx dy + v d x d y = v f dx dy (6.2)
Ω c 0 ∂t Ω ρ 0 c 0 ∂t
4 2
Ω Ω

Again this is only equivalent to equation 5.1a when the test functions v(x, y) are sufficiently smooth and
v(x, y) = 0 on ∂ΩD . Now we can use Green’s Identity and our boundary conditions on u and v to write down
the weak form. " #
∂2 β 1
Ï Ï Ï
2
− ∇v∇u d x d y + v 2 u − u d x d y = v f dx dy (6.3)
Ω Ω ∂t ρ 0 c 04 c 02 Ω

6.2. Space Discretization



By now using the same mesh and test functions as in section 4.2 and approximation u by u h (x, y, t ) = c (t )φi (x, y),
i =1 i
we rewrite the weak form into this equation.
η ·Ï
"Ï Ã ! # Ï
∂2 β
¸
2 1
φj φj f d x d y
X
− ∇φi ∇φ j d x d y c i (t ) + 2 u − 2 u dx dy = ∀j (6.4)
i =1 Ω ∂t Ω ρ 0 c 04 c0 Ω

c and ⃗
We can rewrite this again into an equation with matrices and vectors. Matrix S and vectors ⃗ f are iden-
tical to equation 4.7.
∂2
c (t ) + 2 ⃗ c (t ))¯t = ⃗
¯
− S⃗ q (⃗ f (t ) (6.5)
∂t

17
18 6. Finite Element Method for Westervelt

The vector ⃗
q can be calculated using this formula and is of size η × 1.

à !
β 1
Ï
h 2 h

q (⃗
c (t )) j = φj [u (x, y, t )] − u (x, y, t ) d x d y ∀j (6.6)
Ω ρ 0 c 04 c 02

6.3. Verlet Integration


To solve this problem we will first numerically approximate the time integration by using the Verlet method.
As in section 4.4 we will use ℓ as an index to denote the time step. Thus t ℓ again follows 4.11a for a chosen
time step ∆t . From now on we will use ⃗ cℓ = ⃗c (t ℓ ) and ⃗
qℓ = ⃗ c ℓ ). We now write down an expression for ⃗
q (⃗ qℓ
with this new notation.
à !
β 1
Ï
q ℓj
⃗ = φj h
[u (x, y, t )] − ℓ 2 h ℓ
u (x, y, t ) d x d y ∀j (6.7)
Ω ρ 0 c 04 c 02
#2
η η
à " !
β 1 X
Ï
φj c iℓ φi (x, y) c iℓ φi (x, y)
X
= − dx dy ∀j (6.8)
Ω ρ 0 c 04 i =1 c 02 i =1

q ℓ can be computed more easily from ⃗


This ⃗ c ℓ using the following matrix vector product. The matrix M is
identical to equation 4.7b and matrix N equal to 5.10.

β 1
qℓ = c ℓ )⃗
N (⃗ cℓ − cℓ
M⃗ (6.9)
ρ 0 c 04 c 02

Using equation 6.5 we can write down the Verlet integration step by filling in equation 4.12c.

q ℓ = 2⃗
⃗ q ℓ−1 − ⃗ c ℓ−1 + ∆t 2 ⃗
q ℓ−2 + ∆t 2 S⃗ f (t ℓ−1 ) (6.10)

We now wish to rewrite this into an equation for ⃗ c ℓ , since those are the function values we are looking for. To

be able to do this we need to approximate ⃗ q . We will do this using a very similar approximation to section
5.3, but instead of the solution of the previous iteration step we will use the solution of the previous time step.

[u h (x, y, t ℓ )]2 ≈ u h (x, y, t ℓ−1 )u h (x, y, t ℓ ) ⇒ (6.11)


β 1
qℓ ≈
⃗ c ℓ−1 )⃗
N (⃗ cℓ − cℓ
M⃗ (6.12)
ρ 0 c 04 c 02

Using this result we can write down our Verlet integration by filling in our equations for ⃗ q into equation 6.10
and rewriting to ⃗c ℓ . For the initial ⃗
c 0 and ⃗
c 1 we will use the same equations 4.14a and 4.14b from the linear
wave equation.

à !−1 " #
β 1 2β 2 β 1
c ℓ−1 + ⃗
³ ´
ℓ ℓ−1

c = N (⃗
c )− M ∆t S⃗ 2
f (t ℓ−1 ) + c ℓ−1 )⃗
N (⃗ c ℓ−1 − 2 M⃗
c ℓ−1 − c ℓ−2 )⃗
N (⃗ c ℓ−2 + 2 M⃗c ℓ−2
ρ 0 c 04 c 02 ρ 0 c 04 c0 ρ 0 c 04 c0
(6.13)

6.4. Iteration
To reduce the influence of the approximation 6.11 we will use an iteration similar to section 5.3. The second
c ℓ,n denotes the nth iteration of the solution ⃗
index will be used to denote this iteration, so ⃗ c at time t ℓ . Using

this notation our new approximation for ⃗ q becomes:

β 1
q ℓ,n ≈
⃗ c ℓ,n−1 )⃗
N (⃗ c ℓ,n − c ℓ,n
M⃗ (6.14)
ρ 0 c 04 c 02
6.4. Iteration 19

c ℓ,n . The initial ⃗


Using this result we can again solve equation 6.10 to ⃗ c ℓ,0 is calculated using 6.13. As in section
5.3 we again apply a damping constant ω.
à !−1 " #
ℓ,0 β ℓ−1 1 2
³
ℓ−1 ⃗ ℓ−1
´ 2β ℓ−1 ℓ−1 2 ℓ−1 β ℓ−2 ℓ−2 1 ℓ−2

c = N (⃗
c )− 2 M ∆t S⃗ c + f (t ) + N (⃗
c c
)⃗ − 2 M⃗c − N (⃗
c c
)⃗ + 2 M⃗ c
ρ 0 c 04 c0 ρ 0 c 04 c0 ρ 0 c 04 c0
(6.15a)
à !−1 " #
ℓ,n β ℓ,n−1 1 2
³
ℓ−1 ⃗ ℓ−1
´ 2β ℓ−1 ℓ−1 2 ℓ−1 β ℓ−2 ℓ−2 1 ℓ−2

c t emp = N (⃗
c )− 2 M ∆t S⃗ c + f (t ) + N (⃗
c c
)⃗ − 2 M⃗ c − N (⃗
c c
)⃗ + 2 M⃗ c
ρ 0 c 04 c0 ρ 0 c 04 c0 ρ 0 c 04 c0
(6.15b)
c ℓ,n = ⃗
⃗ c tℓ,n
c ℓ,n−1 + ω(⃗ c ℓ,n−1 )
emp −⃗ (6.15c)

This iteration will continue until either a maximum number of iterations is reached or the difference between
c ℓ,n and ⃗
⃗ c ℓ,n−1 is below a certain minimum difference. When iteration is stopped we set ⃗ cℓ = ⃗
c ℓ,n and can
move to the next time step.
Thus our time Differentiation to the Westervelt equation consists of using equation 6.13 to compute the
next time step. Then iterating using equation 6.15 to refine the solution for this time step. Then we move to
the next time step and again iterate to refine the solution. This process is repeated until we have reached our
end time.
7
Implementation
This chapter will cover all information regarding the implementation of the previously discussed theory into
Python. We will first discuss how the mesh and its base functions were calculated and then go over and
element-wise approach to compute all the necessary matrices and vectors. This is then further improved into
a vectorized implementation. In the last section the implementation of the different boundary conditions is
discussed.

7.1. Mesh Generation


To create a two dimensional mesh we will be relying on GMSH. GMSH has an API package available that
allows you to generate a mesh directly in python. To generate the mesh the following input parameters are
used in my implementation.

• A list of ordered vertices that are defined by their x and y coordinate.

• A boolean list of equal size to the number of vertices. A "1" in the list on position i indicates that there
is a Neumann boundary condition between vertex i and i + 1. A "0" in the list indicates a Dirichlet
boundary condition.

• A float l c value that defines the target element size for the mesh.

The mesh is created by drawing a line from vertex through vertex in the order of the first list. Finally the path
is closed by going from the last vertex in the list to the first vertex. The space inside this line path is then used
to create the two dimensional mesh. The mesh is defined by these output variables.

• A coor matrix of size n_nod es × 2 with on each row the coordinates of the nodes.

• An elems matrix of size n_el ems × 3 with on each row the indexes of the three corner nodes of the
element.

• An i_bnd_dir list filled with the indices of the nodes on the Dirichlet boundary.

• An i_bnd_neu list filled with the indices of the nodes on the Neumann boundary.

By using these output variables we can compute all the necessary matrices and vectors for the FEM imple-
mentation.

7.2. Base Functions


To compute the matrices and vectors we need to compute the base functions on our mesh. In this project we
will use only first order base functions. For each node we define a two dimensional base function following
these two conditions:

• The base functions should be linear on each element.

• Each base functions should equal 1 in its corresponding node and should equal 0 in all other nodes.

20
7.3. Element-wise Computation 21

Since we want our base functions to be linear on each element we can describe our base function j on a
specific element as:
φj = a j x + b j y + c j (7.1)

Say we have an element e i , with its three corresponding nodes x⃗1 = (x 1 , y 1 ), x⃗2 = (x 2 , y 2 ) and x⃗3 = (x 3 , y 3 ). We

Figure 7.1: The element e i in the mesh.

can then find the value of the three non-zero base functions on this element by solving this matrix product.
    
x1 y1 1 a1 a2 a3 1 0 0
x 2 y2 1  b 1 b2 b 3  = 0 1 0 (7.2)
x3 y3 1 c1 c2 c3 0 0 1

From this we find that the base functions on the element e i equal:

y2 − y3 x3 − x2 x2 y 3 − x3 y 2
φ1 = x+ y+ (7.3a)
∆ ∆ ∆
y3 − y1 x1 − x3 x3 y 1 − x1 y 3
φ2 = x+ y+ (7.3b)
∆ ∆ ∆
y1 − y2 x2 − x1 x1 y 2 − x2 y 1
φ3 = x+ y+ (7.3c)
∆ ∆ ∆
with ∆ = x 1 y 2 + x 2 y 3 + x 3 y 1 − x 1 y 3 − x 2 y 1 − x 3 y 2 (7.3d)

φ1 , φ2 and φ3 are the base functions corresponding to the nodes x⃗1 , x⃗2 and x⃗3 respectively. All other base
functions are equal to zero on this element.

7.3. Element-wise Computation


The easiest way to compute the matrices S, M and N and the vector f is to use an element by element ap-
proach using the base function calculated in the previous section. By calculating them element by element
we can make use of the fact that there are only three non-zero base functions on each element. Thus the ele-
ment matrix is only a 3×3 matrix and the element is only 3×1. By looping over the element matrices for each
element and adding them at the correct indices we can construct the full S, M and N matrices. The same can
be done for the element vectors to construct the f vector. Since all of the matrices are sparse, we will be using
a sparse implementation for all the matrices in our computation.
To compute the element stiffness matrix S e i we can make use of the fact that the base functions are linear
on each element. From this it follows that the gradient is constant on the element, thus we can compute
the integral by simply multiplying the constant gradients by the area of the element. The area of a triangular
22 7. Implementation


element is equal to 2. The values of the gradient can trivially be found from equations 7.3.
Î Î Î
∇φ1 ∇φ1 d x d y ∇φ1 ∇φ2 d x d y ∇φ1 ∇φ3 d x d y

Î e i Îe i Îe i
S e i = Îe i ∇φ2 ∇φ1 d x d y Îe i ∇φ2 ∇φ2 d x d y

Îe i
∇φ2 ∇φ3 d x d y 
e i ∇φ3 ∇φ1 d x d y e i ∇φ3 ∇φ2 d x d y e i ∇φ3 ∇φ3 d x d y
(y 2 − y 3 ) + (x 3 − x 2 )2
2
 
(y 2 − y 3 )(y 3 − y 1 ) + (x 3 − x 2 )(x 1 − x 3 ) (y 2 − y 3 )(y 1 − y 2 ) + (x 3 − x 2 )(x 2 − x 1 )
1 
= (y 2 − y 3 )(y 3 − y 1 ) + (x 3 − x 2 )(x 1 − x 3 ) (y 3 − y 1 )2 + (x 1 − x 3 )2 (y 3 − y 1 )(y 1 − y 2 ) + (x 1 − x 3 )(x 2 − x 1 )
2∆
(y 2 − y 3 )(y 1 − y 2 ) + (x 3 − x 2 )(x 2 − x 1 ) (y 3 − y 1 )(y 1 − y 2 ) + (x 1 − x 3 )(x 2 − x 1 ) (y 1 − y 2 )2 + (x 2 − x 1 )2

To calculate the element mass matrix and element N matrix we can use this approximation from [7] (page 16,
formula (39)).
n!m!p!
Ï
p
φni φm
j φk d x d y ≈ |∆| (7.4)
ei (n + m + p + 2)!
Where φi , φ j and φk are non-zero first order base functions on the element e i . Using equation 7.4 we can
directly compute the element mass matrix by setting p = 0 and using the correct values for n and m.

φ φ dx dy φ φ dx dy φ φ dx dy
Î Î Î   
Îe i 1 1 Îe i 1 2 Îe i 1 3 2 1 1
|∆|
M e i = Îe i φ2 φ1 d x d y Îe i φ2 φ2 d x d y Îe i φ2 φ3 d x d y  = 1 2 1  (7.5)
24
ei φ3 φ1 d x d y ei φ3 φ2 d x d y ei φ3 φ3 d x d y 1 1 2

To compute the element N matrix we need to use equation 5.10. This equation gives us this element
matrix Ne i .
φ φ un d x d y φ φ un d x d y φ φ un d x d y
Î Î Î 
n
Îe i 1 1 n Îe i 1 2 n Îe i 1 3 n
c ) = Îe i φ2 φ1 u d x d y
Ne i (⃗  φ φ u dx dy
Îe i 2 2 n
φ φ u d x d y
Îe i 2 3 n (7.6)
n
e i φ3 φ1 u d x d y e i 3 φ2 u d x d y
φ e i φ3 φ3 u d x d y

To compute this element matrix we need to simplify u n . Since on element e i all base functions equal zero
except for the three base functions corresponding to the three nodes of that element, we can reduce u n to
c 1n φ1 + c 2n φ2 + c 3n φ3 . Here c 1n , c 2n and c 3n are equal to the values of ⃗
c n corresponding to the nodes x⃗1 , x⃗2 and
x⃗3 respectively. Using this we can compute the element matrix Ne i by summing over the following matrices.

c n ) = c 1n N1 + c 2n N2 + c 3n N3
Ne i (⃗ (7.7)

These three matrices can be computed using the quadrature approximation given in equation 7.4.

φ φ φ dx dy φ φ φ dx dy φ φ φ dx dy
Î Î Î   
Îe i 1 1 1 Îe i 1 1 2 Îe i 1 1 3 6 2 2
|∆|
N1 = Îe i φ1 φ2 φ1 d x d y Îe i φ1 φ2 φ2 d x d y Îe i φ1 φ2 φ3 d x d y  = 2 2 1 (7.8a)
120
e i φ1 φ3 φ1 d x d y e i φ1 φ3 φ2 d x d y e i φ1 φ3 φ3 d x d y 2 1 2
φ φ φ dx dy φ φ φ dx dy φ φ φ dx dy
Î Î Î   
Îe i 2 1 1 Îe i 2 1 2 Îe i 2 1 3 2 2 1
|∆|
N2 = Îe i φ2 φ2 φ1 d x d y Îe i φ2 φ2 φ2 d x d y Îe i φ2 φ2 φ3 d x d y  = 2 6 2 (7.8b)
120
e i φ2 φ3 φ1 d x d y e i φ2 φ3 φ2 d x d y e i φ2 φ3 φ3 d x d y 1 2 2
φ φ φ dx dy φ φ φ dx dy φ φ φ dx dy
Î Î Î   
Îe i 3 1 1 Îe i 3 1 2 Îe i 3 1 3 2 1 2
|∆|
N3 = Îe i φ3 φ2 φ1 d x d y Îe i φ3 φ2 φ2 d x d y Îe i φ3 φ2 φ3 d x d y  = 1 2 2 (7.8c)
120
φ φ
ei 3 3 1 φ d x d y φ φ
ei 3 3 2 φ d x d y φ
ei 3 3 3φ φ d x d y 2 2 6

Finally, we compute the element vector ⃗ f by first applying a Newton-Cotes rule and then approximating the
integral again using equation 7.4.

φ f (⃗ x 1 , t ) e i φ1 d x d y
Î Î
x1 , t ) d x d y f (⃗
    
Îe i 1 f (⃗
x1 , t )
|∆|
f e i (t ) = Îe i φ2 f (⃗ x 2 , t ) e i φ2 d x d y  ≈
Î
x 2 , t ) d x d y  ≈  f (⃗  f (⃗
x 2 , t ) (7.9)
6
φ φ
Î
ei 3 f x
(⃗ 3 , t ) d x d y f x
(⃗ 3 , t ) ei 3 d x d y f x
(⃗ 3 , t )

7.4. Vectorized Implementation


Though solving the finite element method through an element-wise implementation is the easiest way to
do it, it is also computationally quite slow. There are two main reasons for this. Firstly, looping over all ele-
ments takes a long time especially as the element size decreases and thus the number of elements increases.
7.4. Vectorized Implementation 23

Secondly, cumulatively building up a sparse matrix by going element matrix by element matrix is a computa-
tionally intensive operation.
In this section we will instead attempt to compute all the matrices and vector through a vectorized im-
plementation. In the vectorized implementation we can use the fast linear algebra in the python package
Numpy.This approach is based on [8]. The goal is to compute a list of data d at a and two list of indices i and
j in such a way that S i [k], j [k] = d at a[k] for all k. Duplicate combinations of i and j are allowed and will be
added together in the python sparse matrix implementation. This allows us to create the full sparse matrices
on initialization.

S = sparse . csc_matrix ( ( data , ( i , j ) ) , shape =(n_nodes , n_nodes ) )

Listing 7.1: Example of how the stiffness matrix is computed from the lists i , j and d at a.

In [8] it is shown how to compute the lists i , j and d at a to create the stiffness matrix. The list d at a
contains contains the values of the first element stiffness matrix from top left to bottom right followed by the
values of the second element stiffness matrix etc. This list is created in an efficient vectorized manner. The
lists i and j contain the correct indices corresponding to going over the element matrices one by one in this
manner. In these computations we will also use the list ar ea that contains the value of ∆ for each element.
The list ar ea is computed by taking a cross product.

ind_i = [ ]
ind_j = [ ]
for ind1 in range ( 3 ) :
for ind2 in range ( 3 ) :
ind_i . append ( ind1 )
ind_j . append ( ind2 )

i = elems [ : , ind_i ] . r a v e l ( "F" )


j = elems [ : , ind_j ] . r a v e l ( "F" )

Listing 7.2: Computation of the lists i and j in a similar manner to [8].

c1 = coor [ elems [ : , 0 ] , : ]
d21 = coor [ elems [ : , 1 ] , : ] − c1
d31 = coor [ elems [ : , 2 ] , : ] − c1
area = np . cross ( d21 , d31 )

Listing 7.3: Computation of the list ar ea.

a = np .sum( ( coor [ elems [ : , 1]] − coor [ elems [ : , 2 ] ] ) * * 2 , a x i s =1) / area / 2 .


b = np .sum( ( coor [ elems [ : , 2]] − coor [ elems [ : , 0 ] ] ) * * 2 , a x i s =1) / area / 2 .
c = np .sum( ( coor [ elems [ : , 1]] − coor [ elems [ : , 2 ] ] ) * ( coor [ elems [ : , 2 ] ] − coor [ elems
,→ [ : , 0 ] ] ) , a x i s =1) / area / 2.

data = numpy. concatenate ( ( a , c , − a − c , c , b , − b − c , − a − c , − b − c , a + b + 2


,→ * c ) , a x i s =None)

Listing 7.4: Computation of the list d at a for the stiffness matrix as was done in [8].

To efficiently compute the mass matrix we will use the same list of indices i and j . To get the list with the
data we will take the Kronecker product of the flattened indices of M e i and the ar ea list and divide the result
by 24. This directly gives us the correct d at a list to compute the mass matrix.

temp = np . abs ( area ) / 2 4.


m_ek = np . array ( [ [ 2 . 0 , 1 . 0 , 1 . 0 ] , [ 1 . 0 , 2 . 0 , 1 . 0 ] , [ 1 . 0 , 1 . 0 , 2 . 0 ] ] ) . r a v e l ( )
data = np . kron (m_ek, temp)

Listing 7.5: Computation of the list d at a for the mass matrix.


24 7. Implementation

The largest bottleneck in the computation time is the computation of the sparse N matrix, since this needs to
be done for each iteration in each time step. Therefore the goal was to make this as efficient as possible. The
goal is to calculate the index lists i and j beforehand together with a matrix Nd at a that contains all constant
values of N1 , N2 and N3 for each element. The final data list could then be computed by simply multiplying

c n and Nd at a .

data = c [ elems ] * N_data

Listing 7.6: Computation of the list d at a for the N matrix from the vector ⃗
c and Nd at a .

For this to work the matrix Nd at a needs to be 3 dimensional. The first dimension denotes the position in
Nk from top left to bottom right. The second dimension denotes which element Nk is calculated. The last
dimension denotes which of the three Nk from 7.8 is used. In total Nd at a is of size 9 × n el ems × 3. This matrix
is computed by taking the matrix product of the indices of the three Nk and the ar ea list.

temp = np . abs ( area ) / 120.


n_ek = np . array (
[ [ [ 6 . , 2. , 2.] ,
[2. , 2. , 1.] ,
[2. , 1. , 2.]] ,
[[2. , 2. , 1.] ,
[2. , 6. , 2.] ,
[1. , 2. , 2.]] ,
[[2. , 1. , 2.] ,
[1. , 2. , 2.] ,
[ 2 . , 2 . , 6 . ] ] ] ) . reshape ( ( 9 , 3) )
N_data = temp [ : , np . newaxis ] @ n_ek [ : , np . newaxis , : ]

Listing 7.7: Computation of the Nd at a . The np.newaxis makes sure that the dimensions match up with what was described.

The index lists i and j for the N matrix can be computed by concatenating the i and j that were computed in
Listing 7.2 three times.
For each of these vectorized calculations it has been verified that the result is equal to the matrix found
by using the element-wise approach. By implementing these vectorized ways of computing the matrices the
computation time was greatly decreased. Previously the calculation time of the sparse matrices was the main
bottleneck of the finite element method. Now this only takes up around three percent of the total compu-
tation time. The current bottleneck is the solving of the sparse linear system that needs to be done at every
iteration. This takes up around 95 percent of the computation time for a fine mesh.

7.5. Boundary Conditions


The boundary conditions are implemented in the same way for all three FEM implementations. By default
the finite element method applies Neumann zero boundary conditions on all boundaries. For the purposes of
this project we will only be using zero boundary conditions, so there is no implementation for non-zero Neu-
mann boundaries. To enforce Dirichlet boundaries we change all values for nodes on the Dirichlet boundary
to the prescribed values at that time step. This is done after each time and iteration step.
8
Results
In this chapter we will discuss the results of the finite element method compared to the one dimensional
analytical wave and the two dimensional circularly symmetric wave. It will then go over the results of the
non-linear diffusion finite element solution and also compare these to an analytical result. Finally we will
analyse the relation between the mesh size vs error and time step vs error.

8.1. One Dimensional Wave Example


To verify our two dimensional implementation we will first compare it to the the one dimensional result
from [4] and [3]. We will also use the analytical result found in 3.1 to verify our Finite Element result. The
analytical solution is for a semi-infinite domain, in our numerical implementation we will approximate this
by choosing a sufficiently large L. By doing this our solution will be valid until the displacement at x = 0
L
reaches the boundary at L. Thus our solution will be valid until around T v al i d = . Our boundary condition
c0
on the boundary at x = L does not influence the result for t < T v al i d . We will use a Neumann zero boundary,
since that does not require additional effort in the FEM implementation.
To simulate a one dimensional result in our two dimensional finite element method we will use a rectan-
gular domain. In the x-direction this domain will simulate the one dimensional result and in the y-direction
the solution should have the same value for all y. In the y-direction we will use Neumann zero boundaries
on both ends. To reduce the computation time we will not use a very wide rectangle in the y-direction. This
does not affect our results, since we expect all y-values to be identical. The mesh that was used can be seen
in figure 8.1.
As in [3] we will use the following time dependant boundary condition at x = 0.

t − Td 2
· µ ¶ ¸
£ ¤
h(t ) = P 0 sin 2π f 0 (t − Td ) exp − (8.1)
T w /2
We will use the constants in table 8.1 in our calculation. They are similar to what was used in [3].
Using these values we can make a plot of the time dependent boundary condition. This function is a sinus
that oscillates with a frequency of f 0 . A Gaussian envelop is placed over the sinus to only have a pulse of
about six periods. This boundary condition is chosen because of the rapid oscillation from low pressure to
high pressure. The pulse that this creates is also very similar to ones used in practical ultrasound imaging for
medical applications.

8.1.1. Linear Solution


For the linear wave equation we expect this boundary condition to induce a wave with the same shape that is
moving to the right with speed c 0 . Running the linear finite element method implementation with the given
values we get the following result. For visibility we just plot the x-dimension versus the pressure for all values.
The y-dimension is removed from the plot by plotting the x-location and pressure value of each node and
then drawing a line through all those points.
The finite element solution does what we expect. The boundary condition travels to the right with speed
c 0 and does not change in amplitude. The solution does not vary in the y-direction. If this was the case we

25
26 8. Results

L
Figure 8.1: Plot of the mesh with a significantly larger element size (l c = 0.03m) and larger L y = 10x so single elements are visible. Interior
nodes are denoted by a black dot. The nodes on the Neumann boundary are red and the nodes on the Dirichlet boundary are blue.

Figure 8.2: Plot of the Time dependant boundary condition using the parameters given in table 8.1.

would be seeing multiple different pressure values for the same x-value in figure 8.3. To better compare the
finite element solution to the analytical solution we zoom in on the wave and plot the analytical solution over
it.
Figure 8.4 shows that the finite element solution is almost identical to the analytical solution. The finite
element solution seems to have a slight shift to the right. To take a better look at this error we can look at the
following plot.
Figure 8.5 shows how the error changes over time. We can see here that the error increases with the time
as was also seen in [3]. The increase in error can also partially be caused by reflections due to the wave getting
closer to the right boundary.
8.1. One Dimensional Wave Example 27

Symbol Value Unit Name


kg
ρ0 1000 m3
material ambient density
m
c0 1500 s wave speed
β 10 coefficient of non-linearity
P0 106 Pa coefficient of nonlinearity
f0 105 Hz Single source frequency
6
Td f0 s Source envelope delay
3
Tw f0 s Source envelope width
12
Tend 2 · Td = f0 s Source end time
ρ 0 c 03
x sh βP 0 2π f 0 m Shock formation distance
Lx x sh + Tend · c 0 m Domain length
Lx
Ly 100 m Width in y-direction
c0
lc 36 f 0 m Mesh element size
lc
dt 4c 0 s Time step
ϵ 10−9 · P 0 Pa Tolerance for iteration
m i t er 50 Maximum number of iterations
ω 0.7 Damping in iteration

Table 8.1: Values for parameters used in finite element method for the one dimensional wave equation.

Figure 8.3: Plot of the finite element solution for four different time values.

8.1.2. Westervelt Equation


Due to the non-linear term in the Westervelt equation the wave speed for high pressure values is higher than
the wave speed for low pressure values. Thus for the non-linear solution we expect the slope of high to low
pressure to become steeper and the slope of low to high pressure to become gentler. When the faster high
pressure wave overtakes the slower low pressure part of the wave it creates a shock wave. We first plot the
finite element solution for different time values to see how it changes over time.
In figure 8.6 we see that the solution is initially similar to the linear solution. Then for larger time values
we see that the changes from high to low pressure indeed become steeper. This also results in an increase
of the amplitude for the low pressure and a decrease for the higher pressure. In the last time frame one can
see the creation of shock waves that distort the original shape of the wave. To better be able to see these
differences we will plot the solution side by side with the analytical solution in figure 8.7.
In figure 8.8 we see that the difference between the linear and Westervelt solution increases over time.
Also unlike in figure 8.5 the difference is no longer similar in shape to the original wave.
28 8. Results

Figure 8.4: Plot of the finite element solution and the analytical solution zoomed in on the wave.

Figure 8.5: Plot of the error between the fem solution and analytical solution for four different time values.

8.2. Circular Symmetric Two Dimensional Wave Example


We will now verify our two dimensional finite element implementation by comparing it to the analytical solu-
tion for a circular symmetric wave that was found in section 3.2. To numerically simulate the infinite domain
we will use a sufficiently large circular domain. In our finite element solution we can construct a mesh by its
vertices. Thus we choose to use a hexagonal mesh for this p problem. As in the previous section our solution
is only valid up until a maximum time of around T v al i d = 2c3R
0
, which is the distance from the centre to the
closest side of the hexagon. On all sides of the hexagon we will use Neumann zero boundary conditions.
As in section 3.2 we will use a two dimensional Gaussian function as our initial condition.

−r 2
· ¸
u(r, 0) = P 0 exp (8.2)
2σ2
For our parameters we will use values similar to what we used in the last section. All parameters that were
8.2. Circular Symmetric Two Dimensional Wave Example 29

Figure 8.6: Plot of the Westervelt finite element solution for four different time values.

Figure 8.7: Plot of the Westervelt finite element solution and the analytical solution zoomed in on the wave.

used can be found in table 8.2.


In figure 8.10 the initial condition is shown in two dimensions.

8.2.1. Linear Solution


For the linear wave equation we expect the result to be similar to a raindrop falling on a water surface. The
initial condition will cause a ripple that decreases in amplitude due to the wave having a larger area. As in the
previous section we will plot our solution in one dimension. Because of the circular symmetry of the problem
we will plot the radius versus the pressure.
In figure 8.11 the difference between the analytical solution and the finite element solution is so small
that the analytical solution is not visible below the finite element solution. The behaviour is as we expected.
The initial condition causes a circularly symmetric ripple that decreases in intensity as the time increases.
Figure 8.12 shows the difference with the analytical solution. As in the previous section the error does
30 8. Results

Figure 8.8: Plot of the difference between the fem solution and analytical solution for four different time values.

Figure 8.9: Plot of the mesh with a significantly larger element size (l c = 0.03m)so single elements are visible. Interior nodes are denoted
by a black dot. The nodes on the Neumann boundary are red.

seem to slightly increase with time. The error here is significantly smaller than in the one dimensional exam-
ple. In the plot we see that the error increases when the rate of change of the solution increases.

8.2.2. Westervelt Equation


In this section the difference due to the non-linear term in the Westervelt equation should be significantly
smaller due to the difference between the low and high pressure decreasing as time increases. The number of
oscillations is also lower for this example, which should also lower the difference between the Westervelt and
Linear solution.
The difference between the analytical and Westervelt solution is not discernable in these plots. Thus we
conclude that there is barely any influence from the non-linear term in this problem. In figure 8.14 we see
that the difference between the analytical and Westervelt solution is very similar to 8.12. By increasing the
8.3. Non-linear Diffusion 31

Symbol Value Unit Name


kg
ρ0 1000 m3
material ambient density
m
c0 1500 s wave speed
β 10 coefficient of non-linearity
P0 106 Pa coefficient of nonlinearity
t end 10−3 s End time for FEM
σ 0.1 m Source width
3
R c t
2 0 end m Domain radius
σ
lc 10 m Mesh element size
lc
dt 4c 0 s Time step
ϵ 10−9 · P 0 Pa Tolerance for iteration
m i t er 50 Maximum number of iterations
ω 0.7 Damping in iteration

Table 8.2: Values for parameters used in finite element method for the circular symmetric wave equation.

Figure 8.10: 2D Plot of the initial condition using the parameters given in table 8.2.

value of β the non-linear effects can be made more visible.

8.3. Non-linear Diffusion


To verify the solution found in chapter 5 we will compare it to a one dimensional reference solution from [9].
In one dimension equation 8.3 is a solution to the non-linear diffusion equation with α = −1 and f = 0.
32 8. Results

Figure 8.11: Plot of the finite element solution for four different time values.

Figure 8.12: Plot of the error between the fem solution and analytical solution for four different time values.

6


 u(x) = (8.3a)
(1 + x)2

 3
u(0) = 6
 u(1) = (8.3b)
2
As in section 8.1 we will use a rectangular domain to simulate a one dimensional wave. The mesh that was
used is almost identical to the mesh plotted in figure 8.1. The only difference is that both the left and right
side of the rectangle have Dirichlet boundary conditions. The parameters that were used for the Non-linear
Diffusion solution can be found in table .
In figure 8.15 the result of the finite element method is shown. The initial iteration step is a straight line
2
between the two boundary conditions. This is to be expected, since it is the trivial solution to ∂∂xu2 = 0. For
each iteration after the initial condition the solution is slowly moved to the correct analytical solution. In the
8.4. Mesh Size vs Error 33

Figure 8.13: Plot of the Westervelt finite element solution and the linear analytical solution for four different time values.

Figure 8.14: Plot of the difference between the fem solution and analytical solution for four different time values.

difference plot in figure 8.16 the decrease in the difference over the iterations can be seen.

8.4. Mesh Size vs Error


To evaluate the influence of the mesh size on the error we will compare the results of the finite element
implementation to both our analytical solutions. As an error norm we will be using the ℓ1 -norm on the
difference between the two solutions.

ϵ = max(|⃗
c i − u ana (⃗
x i , t )|) (8.4)
i

Where u ana is the analytical solution evaluated in the node corresponding to ⃗


c i . To compute the error we will
be using the ⃗
c solution from the last time step of the computation.
We will first look at the influence of the mesh size on the error for the two time dependant reference
34 8. Results

Symbol Value Name


α −1 coefficient of non-linearity
Lx 1.0 Domain length
Lx
Ly 10 = 0.10 Width in y-direction
lc 0.002 Mesh element size
ϵ 10−9 Tolerance for iteration
m i t er 50 Maximum number of iterations
ω 0.3 Damping in iteration

Table 8.3: Values for parameters used in finite element method for the Non-linear Diffusion equation.

Figure 8.15: Plot of the finite element solution and the analytical solution to the Non-linear diffusion equation. Iteration 0 denotes the
c0.
initial solution ⃗

solutions. For the calculations we will use the same parameters as were used in tables 8.1 and 8.2. We will
only change the value of l c for both problems. We will solve the problem with the values of l c in the tables
multiplied by a scaling of between 100 and 1. These scaling values are spaced on a logarithmic scale. After
solving the problem we compute the error and plot the l c versus error ϵ on a logarithmic scale to find the
relation between them. For the finite element method we expect this to be a relation of the form ϵ ∝ l c 2 .
As can be seen in the figure there were a lot of points that show weird behaviour for the resulting error
of larger mesh sizes, especially for the one dimensional problem. In the 1-dimensional case the solutions
would become inaccurate for larger mesh sizes due to the oscillations in the wave happening faster then the
distance between nodes in the mesh. This causes some strange behaviour in the solution that leads to a kind
of averaging of the wave over the interval. Due to this behaviour the error decreases even though the solution
is not accurate. For this reason we choose to eliminate a large number of data points for the one dimensional
problem. For the two dimensional problem this behaviour takes longer to take shape since the Gaussian
curve is easier to approximate using linear elements. For larger values of l c this effect again occurs, but it is
less present than for the one-dimensional case.
From these two fits we found a relation of ϵ ∝ l c 1.56 and ϵ ∝ l c 1.66 from the 1-dimensional and 2-dimensional
cases respectively. These two relations are similar, which is what we would expect. However both of them are
lower than the quadratic relation that we expected. This is especially the case for the 1-dimensional channel
problem. It would be good to better estimate the one dimensional error fit by having more data points for
lower l c values. Unfortunately this was not possible, due to an error in the GMSH API.
My best guess for the cause of this error is that in the one dimensional case the mesh is very long and
thin, which causes the triangular elements to become very stretched out, especially as the element size de-
creases. When lowering the l c value too much the elements become so stretched out that GMSH can no
8.4. Mesh Size vs Error 35

Figure 8.16: Plot of the difference between the finite element solution and the analytical solution to the Non-linear diffusion equation
c 0 . The difference on the Dirichlet boundary nodes is not
with a log scale on the y-axis. Iteration 0 again denotes the initial solution ⃗
included in the plots since the difference is always zero.

Figure 8.17: Plot of the lc versus the error on a logarithmic scale. The red markers were used to designate points that were not included
in fitting the line. The plot includes two linear fits for the relation between the error and the mesh size.

longer differentiate between the two elements and an error occurs in GMSH.
The same procedure was used to analyse the relationship between the error and the element size for the
non-linear diffusion. The parameters were kept equal to the ones given in table 8.3. The l c is again scaled by
values between 100 and 1 on a logarithmic scale. This resulting logarithmic plot of the error can be found in
figure 8.18.
For this problem all the data points seem to follow the linear fit, although there is some more inaccuracy
for the higher element sizes. This is probably because the non-linear diffusion problem does not have an
initial or boundary condition that is hard to approximate with linear elements. From the linear fit we find
a relation of ϵ ∝ l c 1.98 , which agrees much better with our expectation of ϵ ∝ l c 2 . This leads me to believe
that the different relations that we found for the time dependant problems are related to the Verlet Time
36 8. Results

Figure 8.18: Plot of the lc versus the error on a logarithmic scale. The plot includes a linear fit for the relation between the error and the
mesh size.

Integration.

8.5. Time Step vs Error


To investigate the influence of the time step size on the error we will be using a similar approach to the one
we used in the last section. We will be using the same error norm as equation 8.4. As previously we will be
using the parameters of tables 8.1 and 8.2. The only parameter that we will change is the size of the time step.
We will be solving both time dependant problems for twenty different time step values. The value of the time
step in the tables will be multiplied by logarithmically scaled values between 10 and 0.1. After calculating the
solution for each of these time values we will calculate the error on the last time step.

Figure 8.19: Plot of the time step versus the error on a logarithmic scale. For the solutions where the solution would become N aN , the
error has been plotted as the value 10250 .
8.5. Time Step vs Error 37

In figure 8.19 we see that the error explodes when the time step is too large. For the two dimensional
problem the implementation gives a solution which is incredibly large and thus the error is very large. For
the one dimensional channel the solution consists of N aN values. This is because the solution blows up
so much that the values pass the maximum float limit of python of 1.7976931348623157 × 10308 . When this
happens python returns "Not a Number"(N aN ). To still include these data points in the error plot they have
been plotted as the value 10250 . From this figure we can conclude that the convergence of the finite element
method depends on the time step used.
We will now plot only the values for which the solution converges and zoom in on the two error values for
the two different solutions.

Figure 8.20: Plot of the time step versus the error on a logarithmic scale. This plot includes only the values for which the solution
converges and has been split in two subplots for each solution.

The figure 8.20 shows that both solutions show the same relation between the time step and the error.
Unlike for the mesh size the logarithmic plot does not show a straight line. From this we can conclude that
the time step does not follow a relation of the form ϵ ∝ d t k to the error. The error decreases with the time step
until it plateaus, the error can then not decrease further unless decreasing the mesh size. This is because the
error caused by approximating the domain with a mesh can not be decreased by decreasing the time step.
9
Conclusion
In this thesis we found a way to compute the two dimensional Westervelt equation with the finite element
method. To do this we first had to solve the linear wave equation and the non-linear diffusion equation using
the finite element method. We found a way to iterate on each time step that allows us to approximate the
non-linearity in the Westervelt equation.
We were able to verify this finite element implementation by comparing it to the one dimensional work
of [3]. After which we also compared it to a two dimensional linear circularly symmetric solution. From this
we conclude that the finite element method can be used to solve the Westervelt equation in two dimensions.
The non-linear diffusion finite element solution was also verified by comparing it to the work done in [9]. We
have also shown that a faster vectorized implementation can be used instead of the element-by-element one.
The relation between the error and the mesh size was also analysed. For the time-dependant finite ele-
ment implementation the error was found to scale with around ϵ ∝ l c 1.7 . This value is below our expected
relation of ϵ ∝ l c 2 . For the non-linear diffusion equation the relation between the mesh size and error agrees
with our estimate, because it equals ϵ ∝ l c 1.98 .
When investigating the relation between the time step and the error we found that the convergence of the
finite element method depends on the time step used. Unlike the mesh size, the time step does not follow a
relation to the error of the form ϵ ∝ d t k . This is because the error stops decreasing when the time step gets
very small.

38
10
Discussion
In this research we focused on implementing the finite element method for two dimensional domains. All the
theory that was discussed in this thesis can be extended to three dimensional domains. This would make the
results more applicable to real life situations. The main work that would need to be done would be in chapter
7, where most of the calculations of the integrals would have to be changed.
The finite element implementation could be further improved by adding adaptive mesh refinement for
areas of large change in the solution values. This could greatly improve both the accuracy of the program
as well as the computation time. For example in the current implementation a large amount of computation
time is spend on the area of the domain the wave has not reached yet that is equal to zero. Another feature that
could be added is to add the option of non-zero Neumann boundary conditions to the code implementation.
For two dimensional finite element method it was verified that the results of the vectorized implementa-
tion gave equal results to the element-wise implementation. To quantify the improvement that this change
in implementation gave it would be good to do a more quantitative research of these changes on the compu-
tation time for different mesh sizes and time steps.
When looking at figure 8.4 we can see that the difference between the analytical and the numerical FEM
solution seem to be a slight shift to the right. This might be caused by one of the approximations we did when
applying the finite element method. It is also possible that the root of this shift is an error somewhere in our
theory or implementation that can be fixed. Further investigation would be required to figure this out. The
shift might be related to the way that the time dependent Dirichlet boundary is implemented, since it does
not seem to appear in figure 8.11.
In section 8.2 the differences between the analytical linear and finite element Westervelt solution are very
small. The value for the non-linearity constant that was used in this section β = 10 was the same one as used
in the section before it. In that section it did give very noticeable results. The reason that the non-linear
phenomena in this section were less noticeable is firstly because the wave oscillates less compared to the one
dimensional wave. The second reason is that the amplitude of the wave quickly decreases. It would be good
to increase the non-linearity constant in this section to better show the effects of the Westervelt equation on
the circularly symmetric problem.
When verifying the finite element implementation we mostly made use of linear reference solutions es-
pecially when calculating the errors. It would be good to further verify the non-linear finite element solutions
by comparing them to a non-linear reference solution. Unfortunately there are no analytical solutions to the
Westervelt Equation. Thus we would have to rely on a previously verified numerical solution from another
source to verify the implementation for non-linear problems. This would help to further proof that the theory
in this paper is correct.
The analysis of the mesh size vs error could be best improved by getting more data points for the 1-
dimensional problem. To do this the problem would need to be solved with smaller values of l c, which cur-
rently result in errors. By fixing the error one would be able to better approximate the relation by making a
better fit. The error could also be fixed by increasing the width of the channel, though this would also greatly
increase computation time. Another way to improve this section would be by getting more different reference
solutions to better confirm the relation between the error and mesh size.
Further research should be done into how the convergence of the finite element method relates to the
time step used. For this we would have to investigate the time step for which convergence stops for different

39
40 10. Discussion

mesh sizes and problems.


In this thesis we found that the relation between the mesh size and the error is below the expected
quadratic relation for the time dependant problems. For the non-linear diffusion equation we found the
correct relation between the two. In section 8.5 we found that the error stops decreasing when decreasing
the time step at a certain point. I would hypothesize that the error for the finite element method consists of
a summation of an error caused by the Verlet Integration and an error caused by the approximation of the
domain by the mesh. Thus when we plot the relation between the mesh size and the error with a sufficiently
small time step used to make the error of the Verlet Integration negligible. I expect that the relation for the
time dependant problems will also be closer to the expected ϵ ∝ l c 2 . Verifying this would take a lot of extra
computation time and was not possible to include in this thesis. For future research it would be interesting
to look further into this error relation.
Bibliography
[1] Lauterborn, W., Kurz, T. and Akhatov, I., 2007. Nonlinear Acoustics in Fluids in Handbook of Acoustics,
Chap. 8, p. 257-297, Springer.

[2] Hamilton, M. F. and Morfey, C.L., 1998. Model Equations in Nonlinear Acoustics edited by Hamilton, M. F.
and Blackstock, D. T., Chap. 3, p. 41-63, Academic Press.

[3] Zijta, M., 2017. Solving The Westervelt Equation With Losses Using First And Second Order Finite Element
Method, Delft University of Technology, Faculty of Applied Sciences & Faculty of Electrical Engineering,
Mathematics and Computer Science.

[4] Dirkse, B., 2014. Finite Element Method Appliet to the One-dimensionel Westervelt Equation, Delft Uni-
versity of Technology, Faculty of Applied Sciences & Faculty of Electrical Engineering, Mathematics and
Computer Science.

[5] Churchill, R.V., 1972. Operational Mathematics, 3rd edition, McGraw-Hill Book Company.

[6] Haberman, R., 2014. Applied Partial Differential Equations with Fourier Series and Boundary Value Prob-
lems, 5th edition, Pearson Education Limited.

[7] Segal, A., 2017. Finite element methods for the incompressible Navier-Stokes equations, Delft University of
Technology, Faculty of Applied Sciences & Faculty of Electrical Engineering, Mathematics and Computer
Science.

[8] Funken, S., Praetorius, D. and Wissgott, P., 2011. Efficient Implementation of Adaptive P1-FEM in Matlab
in Computational Methods in Applied Mathematics, Vol. 11., No. 4, pp. 460-490.

[9] Plaquevent-Jourdain, B., 2019. Méthodes d’analyse numérique pour la résolution d’équations différen-
tielles et aux dérivées partielles non-linéaires, Delft University of Technology, Faculty of Applied Sciences
& Faculty of Electrical Engineering, Mathematics and Computer Science.

41
A
Appendix
All code related to this project can be found in the GitLab repository at https://gitlab.com/leo.hendriks/
bep-fem/.

42

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy