** Spring 2021**

**
Introduction to Finite Differences
and **

Finite Elements in the Geosciences

**
**

- Valerie Maupin, Contact: valerie.maupin@geo.uio.no
- Clint Conrad, Contact: c.p.conrad@geo.uio.no

- Computing with Python: Programming for Computations – Python. A Gentle Introduction to Numerical Simulations with Python 3.6 by Svein Linge and Hans Petter Langtangen (2020). This book is available for free from Springer and introduces scientific programming using Python. We will refer to this book ast LL20.
- Finite Differences: Finite Difference Computing with PDEs – A Modern Software Approach by Hans Petter Langtangen and Svein Linge (2017). This book is available for free from Springer. We will follow chapters 1-4 (pages 1-351), and we will refer to this book as LL17.
- Finite Elements: Introduction to Numerical Methods for Variational Problems by Hans Petter Langtangen and Kent-Andre Mardal (2019). This book is available from Springer. We will follow chapters 1-7 (pages 1-280), and we will refer to this book as LM19.

- Python: Introduction to Scientific Programming with Python by Joakim Sundnes (2020). This book is available for free from Springer and is a useful reference for scientific programming using Python. We will refer to this book as S20.
- Geoscience Applications: Introduction to Numerical Geodynamic Modelling by Taras Gerya (2019). This book is available from Cambridge University press and from the UiO library, and provides useful examples of geoscience problems solved using finite differences and finite elements. We refer to this book ast G19.

- Monday January 18, 14.15: Class Organization and Introduction Homework: To catch up to speed on programming in Python, we will read the first several chapters of S20 and/or LL20. Please tell us which book you find more useful for this introduction.
- Friday January 29, 10.15: Basics of Python Programming Summary: We decided to proceed using LL20, starting with Chapter 6. The earlier chapters of LL20 and the entirety of S20 are useful references for implementing Python code, and it would be useful to read them and implement some of the examples. We do not plan to go through these chapters in detail, unless we need to learn something specific from them. Homework: For next time, read LL20 Chapter 6: Computing Integrals and Testing Code. Carefully and write your own Python codes to implement the examples in this chapter. For a specific exercise, compute the integral of the sine function from 0 to pi (as in exercise 6.4a on page 169) using your own code to implement the trapezoidal and midpoint methods. Make your own version of the table on page 145, showing how the solution changes as you increase n. For a bonus application, try implementing the monte carlo method to solve this integral. Be prepared to share your code, and to demonstrate how it works, with the group (e.g., using share screen on Zoom). Read Ahead: Next time, we will continue with LL20 Chapters 7 and 8. It would be a good idea to familiarize yourself with these chapters in advance of our next meeting.
- Monday February 8, 14.15: Numerical Integration Summary: We talked about methods for numerical integration (LL20 Chapter 6), using trapezoid rule and the midpoint method. We discussed the monte carlo method, and generally talked about programming techniques. Homework: For next time, read LL20 Sections 8.1-8.3. These sections give an introduction to writing code to solve ordinary differential equations, with applications to exponential problems. Please write code to implement the problems discussed in these sections. Exercises 8.1-8.3 on pages 273-274 will help with this.
- Monday February 22, 14.15: Differential Equations: Exponential Problems Summary: We went through LL20, sections 8.1 to 8.3 and discussed some examples from the exercises assigned. Homework: For next time, read sections 8.4 and 8.5 of LL20 (osciallating problems), and do exercises 8.9 and 8.11.
- Monday March 1, 14.15: Differential Equations: Oscillating Problems Summary: We went through LL20, sections 8.4 to 8.5. We reviewed the differences between the Forward Euler method and more advanced finite difference methods such as Euler-Cromer (first order) or Runge-Kutta (second or even fourth order) methods. We tested our codes to see how the solution is affect by changing resolution. Homework: For next time, read chapter 9 of LL20 (partial differential equations) and prepare a coding solution for exercise 9.2b.
- Monday March 8, 14.15: Intro to Partial Differential Equations Summary: We went through LL20, chapter 9. We reviewed the diffusion equation, and how it is implemented in finite-differences. We payed special attention to the boundary conditions, including how they are implemented in the finite difference solution. We discussed the temporal resolution (time step size) that is necessary to obtain a stable solution, for a given spatial resolution. Homework: For next time, we begin the LL17 book, which goes into more detail about finite difference methods. We start with Chapter 1 (vibrational problems), sections 1.1 to 1.7. The book goes into more detail than we need about some of the methods. Thus, you can pass through the following subsections relatively quickly: 1.3.2-1.3.5, 1.4.6, 1.5.6, 1.74. We will not assign an exercise this week, so we can focus on the methods. However, it would be good to familiarize yourself with some of the codes associated with this chapter, and try to get some of them to work. Here is the website that provides some code for this book: [LL17 codes] Note that the relevant code for this chapter can be found using the "vib" link.
- Monday March 15, 14.15: Vibrational Ordinary Differential Equations Summary: We went through LL17, chapter 1. We discussed the stability or instability of finite difference solutions to the vibrational ODE, how we can determine if a solution is stable, and the conditions that make a solution unstable. We discussed the different solution schemes (e.g., Centered Finite Difference, Forward Euler, Backward Euler, Crank-Nicolson, Runge-Kutta, Forward-Backward Euler-Cromer) and their implementation. Homework: For next time, we continue with the LL17 book, moving into solutions to the wave equation in Chapter 2. In particular, we will discuss sections 2.1 to 2.4 in detail, but we will omit sections 2.2.3, 2.2.4, 2.3.4, and 2.4.4. To practice implementation, let's do exercises 2.1 and 2.4 (in section 2.5). Also, let's read sections 2.6.1 to 2.6.3 (about reflecting boundary conditions), section 2.7 (about variable wave velocity), and section 2.11 (about FD methods in 2D and 3D).
- Monday March 22, 14.15: Finite Difference Solutions to the Wave Equation Summary: We went through LL17, chapter 2. We discussed using a stencil to implement a finite difference solution to the wave equation in 1 dimension (and also in 2 dimensions). The discussed the importance of the Courant condition, which specifies the relationship between spatial and temporal resolutions, and leads to an unstable solution if it is violated. We implented standing waves using a finite difference scheme, and discussed implementation of boundary conditions. Homework: For next time, we will finish our reading of the LL17 book, looking at the diffusion equation (Chapter 3) and advection (Chapter 4). For Chapter 3, let's read sections 3.1 and 3.2, as well as 3.5.1 to 3.3.5 (heterogeneous media) and 3.6.1-3.6.2 (two dimensions). For Chapter 4, we will read sections 4.1.1 to 4.1.4.
- Friday March 26, 9.15: Finite Difference Solutions to the Diffusion Equation Summary: We went through LL17, sections 3.1-3.2, 3.5, 3.6, and 4.1. In doing so we discussed the diffusion equation and in particular the difference between the explicity solution (which we used before for the wave equation) and the implicity solution. The implicity solution is useful for the diffusion equation because it allows for longer timesteps for a given spatial resolution (larger F parameter). However, the implicit solution requires inversion of a generally sparse or banded matrix, and there are efficient ways to do this. The advection equation (section 4.1) is most readily solved with a simple upwind differences scheme. Homework: For next time, we start with finite elements using the LM19 book. Let's read chapter 1, and chapter 2 sections 2.1-2.4, as well as a quick look at section 2.5. We have a three-part exercise: (a) Write your own numerical integration program (as we did early in the semester) to reproduce the example in section 2.2.3 and plot the result (you should get something similar to figure 2.2). (b) Now apply this same numerical integration method to approximate the function y=exp(x^2) using a linear function in the span [0,2]. (c) Finally, find the analytical expressions for the 3 Lagrange polynomials of order 2 for an element with points at [0., 0.5, 1.0], and plot them.
- Easter Break

- Monday April 12, 14.15: Function Approximation by Global Functions Summary: We will cover LM19, chapters 1 and 2.
- Monday April 19, 14.15: Function Approximation by Finite Elements Summary: We will cover LM19, chapter 3 (sections 3.1, 3.2, 3.5 and the beginning of 3.6).
- Monday April 26, 14.15: Variational Formulations with Finite Elements Summary: We will cover LM19, sections 4.1 (approximating differential equations) and 5.1 (computing with finite elements) and 6.1 (time-dependence).
- Week of May 3: No class (Tectonics Field Trip)
- Monday May 10, 14.15: Discussion of Individual Projects
- Monday May 31 (tentative), 14.15: Project Presentations (project writeups will be due a few days before)