DEPARTMENT OF INFORMATICS

TECHNISCHE UNIVERSITÄT MÜNCHEN

Bachelor’s Thesis in Informatics

Visualization for Rational Approximations of Complex-valued Functions

Finn Capelle DEPARTMENT OF INFORMATICS

TECHNISCHE UNIVERSITÄT MÜNCHEN

Bachelor’s Thesis in Informatics

Visualization for Rational Approximations of Complex-valued Functions

Visualisierung für Rationale Approximationen von Komplexwertigen Funktionen

Author: Finn Capelle Supervisor: Prof. Martin Schulz Advisor: Dr. Martin Schreiber Submission Date: 14.08.2020 I confirm that this bachelor’s thesis in informatics is my own work and I have docu- mented all sources and material used.

Munich, 14.08.2020 Finn Capelle Acknowledgments

First and foremost I would like to thank my advisor Dr. Martin Schreiber for giving me the opportunity to write my bachelor thesis with him. His help and advice was always available and made this thesis possible in the first place.

Furthermore, I would like to thank Prof. Dr. Martin Schulz for enabling me to write this thesis at his chair. Abstract

Simulations often rely on numerical methods that consist of linear time differentials, which are hard to solve, and numerical solutions not always exist. They can be approximated using time-stepping methods, which often results in a lot of computation. When solving differential equations the solution function often contains an expo- nential integrator. This term can be approximated using REXI methods, which allows approximations for long time steps and parallelized solving. Each method has a high dimensional parameter space that makes comparing them challenging. This project was created to implement a user interface in which the parameters can be entered, and that displays the resulting error from the approximation. In the first part, the background of the thesis is discussed in more detail and the mathematical basics are explained. ODEs and PDEs will be roughly discussed as well as the theory behind rational approximations and the different REXI methods. The next section will go into more detail on how the is built up, the functionality and installation will be explained, and a small example provided.

iv Contents

Acknowledgments iii

Abstract iv

1 Introduction 1

2 ODE and PDE Basics 3 2.1 ODE Example ...... 3 2.2 PDE Example ...... 4 2.3 Solvers for differential equations ...... 7

3 REXI Methods 10 3.1 Problem Formulation ...... 10 3.2 TREXI ...... 11 3.3 CIREXI ...... 13 3.4 BREXI and ELREXI ...... 14 3.5 Difficulties in comparing the methods ...... 14

4 Software 15 4.1 Required Functionality ...... 15 4.2 Terminology ...... 15 4.3 ...... 16 4.3.1 Framework ...... 16 4.4 Architecture ...... 16 4.4.1 Class Diagram ...... 16 4.4.2 Dynamic Model ...... 18 4.4.3 Event Handling ...... 18 4.5 User Documentation ...... 19 4.5.1 Explanation of Functionality ...... 19 4.5.2 Installation and Example ...... 25 4.5.3 Third-party components ...... 31

5 Summary and Conclusion 32

v Contents

Bibliography 33

vi Figure 1.1 Mean sea level pressure and wind speed at 850 hPa for Europe; Wednesday 5 Aug, 12 UTC T+216 [20]

1 Introduction

Weather forecasts play a big role in our daily life. An estimated 80 percent of companies are weather dependent, most importantly agriculture, construction, and the insurance industry [16]. It was first tried by Lewis Fry Richardson in the 1920s to predict the weather for the next 6 hours. He had to calculate everything by hand and the results were described by himself as "a fairly correct deduction from a somewhat unnatural initial distribution". It was not until the 1960s with the advent of computers for the first realistic weather forecasts [19]. Today most predictions are done using numerical methods of the atmosphere and the ocean. Current weather observations are used as inputs that are relayed from radiosondes, weather satellites, and other observing systems [21]. These numerical methods often consist of linear differential equations, which are computationally expensive to solve, and analytical solutions not always exist. They

1 1 Introduction can be approximated using time-stepping methods, but for the approximations to be accurate, often small time-steps are required. This results in a lot of computation for long climate and weather predictions. Some of the time integration problems are solvable by rewriting them into the form

U(t) = eLtU(0). The exponential integrator part of this term can be approximated for long time steps using REXI methods. REXI approximations allow parallelized approximations, which results in a huge performance benefit. Four different REXI methods exist TREXI [15], CIREXI [30, 29], BREXI [9, 7], and ELREXI 1. Evaluating how these methods perform against each other is nearly impossible because of high dimensional parameter spaces. One way to simplify the comparison is a user interface where the error of the approximation is visualized and the parameters can be entered quickly.

1Developed by Pedro S. Peixoto but not yet published

2 2 ODE and PDE Basics

Differential equations can be split into two subclasses, Ordinary Differential Equations (ODE) and Partial Differential Equations (PDE). In both cases, an unknown function is given but ODEs contain differentials with respect to one independent variable, whereas PDEs contain differentials with respect to more than one independent variable [34].

2.1 ODE Example

This part is oriented towards these lecture notes [1]. An ODE typically consists of three parts

du(t) = λu(t) + N(u(t)) + f (t, u(t)), dt | {z } | {z } | {z } linear term nonlinear term forcing term where µ, λ ∈ C and N : C → C. The linear term accounts for purely non-chaotic linear behavior and the nonlinear term describes non-linear interactions for chaotic effects for example. The forcing term can be used for external effects for example. A simple example for an ODE is a radioactive decay rate given as

du(t) = −λu(t) . dt | {z } linear term u(t) is the amount of radioactive material and λ is a positive real valued constant depending on the radioactive material. The minus sign in-front of λ stands for the decreases in radioactive material over time.

3 2 ODE and PDE Basics

Figure 2.1 Nuclear Radiation Rate using equation 2.1 U(0) = 1000, λ = 1.23, t = [0; 10]

An analytical solution can be constructed for this ODE

du = λu dt du = dt λu Z u 1 Z t dη = (t − t0) dτ u0 λη t0 1 (ln u − ln u ) = t − t λ 0 0

u(t) ( − ) = eλ t t0 u0

λ(t−t0) u(t) = ±u0e

and assumed t0 = 0 the final solution is

u(t) = eλtu(0). (2.1) The result of the ODE is visualized in Figure 2.1.

2.2 PDE Example

The following example is oriented towards [14].

4 2 ODE and PDE Basics

Imagine a 1D rode made out of metal with a different heat distribution throughout. The goal is to find out how the heat distribution changes over time. This can be done using the heat equation

∂u ∂2u (x, t) = α (x, t). (2.2) ∂t ∂x2 The equation consists of two parts

∂u ∂u (x, t), (x, t), ∂x ∂t The left part describes how the temperature changes along the rod and the right part describes how the temperature changes at a certain point on the rod over time. α is known as the thermal diffusivity. It measures the rate of transfer of heat from the cold to the warm end. Consider that the rod has length l with insulated sides and a start temperature distribution f (x) degree C, for 0 < x < l. The task is to find u(x, t) at t > 0, when the ends of the rod are kept at 0◦C. To start, the initial condition (IC) and boundary condition (BC), have to be found and to make the solution simpler physical constants are made dimensionless. Please refer to [14] pages 3-4 for a detailed explanation.

PDE : ut = uxx (2.3) IC : u(x, 0) = f (x) (2.4) BC : u(0, t) = u(1, t) = 0 t > 0 (2.5) The solution that has to be found can then be written as,

u(x, t) = T(t)X(x) (2.6) 00 uxx = T(t)X (x) (2.7) 0 ut = T (t)X(x) (2.8) and the PDE becomes

T0(t) X00(x) = . (2.9) T(t) X(x) If t varies and x is held fixed the right hand side has to be constant and following the left hand side as well. This constant is set to −λ. T0(t) X00(x) = = −λ (2.10) T(t) X(x)

5 2 ODE and PDE Basics

Solving for X(x)

Using 2.10,

X00(x) + −λX(x) = 0, 0 < x < 1, (2.11) X(0) = X(1) = 0. (2.12)

2.11 is called the Sturm-Liouville problem, in which λ can take on 3 cases λ < 0, λ = 0, λ > 0. λ < 0 and λ = 0 can be discarded, for the explaination please refer to [14] pages 5-6. For λ > 0 2.11 is a harmonic equation √ √ X(x) = A cos( λx) + B sin( λx). √ The BC 2.5 implies that 0 = X(0) = A and B sin( λ) = 0. B can not be 0, because then u would also be 0, which would be the trivial solution, therefore √ sin( λ) = 0. √ 2 2 Thus, λ = πn where n ∈ N\{0}. The λn = π n values are the eigenvalues of the Sturm-Liouville problem and the corresponding solutions of 2.11 are called the eigenfunctions.

Xn(x) = bn sin(nπx) n = 1, 2, 3 (2.13)

Solving for T(t)

In the previous section it was shown, that λ = π2n2, so using 2.10

T0(t) = −π2n2T(t) (2.14) and with respect to n the solution is

−π2n2t Tn = cne (2.15) where cn is the constant from integration.

Full Solution

Combining the solutions for X 2.13 and for T 2.15 the final solution is

−π2n2t un(x, t) = cnbn sin(πnx)e . (2.16)

6 2 ODE and PDE Basics

Because, every un(x, t) is a solution for the PDE 2.3 the principle of superposition states that the infinite sum of these solutions is also a solution itself

∞ u(x, t) = ∑ un(x, t) (2.17) n=1

To satisfy the IC 2.4, possible values for cnbn have to be found, such that

∞ ∞ f (x) = un(x, 0) = ∑ un(x, 0) = ∑ cnbn sin(nπx). (2.18) n=1 n=1 This is called the Fourier Sine Series of f (x). To solve for cnbn the orthogonality property for the eigenfunctions sin(nπx) has to be used. For a detailed explanation please refer to [14] pages 7-8. The values are then given as

Z 1 cnbn = 2 sin(nπx) f (x)dx. (2.19) 0 In both examples, the time dependent parts of the solutions 2.1 2.16 rely on exponen- tial integrators.

λt −π2n2t u(t) = e u(0) un(x, t) = cnbn sin(πnx)e .

This again illustrates the usefulness of the REXI methods.

2.3 Solvers for differential equations

Different kinds of solvers to approximate solutions for time dependent ODEs and PDEs already exist for a long time. Mostly they rely on time stepping mechanisms.

Explicit and Implicit Time Stepping

Explicit and Implicit methods are used to obtain numerical approximations of solutions of time dependent ODEs and PDEs. Explicit methods calculate the state of the system in the future from the state of the system at the current time. Implicit methods find a solution by solving an equation containing both the current state and the future state of the system [10].

7 2 ODE and PDE Basics

Runge-Kutta Methods

The original Runge-Kutta method was developed by Carl Runge and Wilhelm Kutta and can be used to approximate solutions of ODEs. The method makes use of the Euler method, which is also used to approximate solutions of ODEs, for which the slope of the curve at the current point is used to approximate the next step. The Runge-Kutta method additionally makes use of the Simpson rule as well as more points for each time step iteration t → t+1 [26]. Today multiple variations of the original method exist [25].

Runge-Kutta stability

From 2.2 the stable areas for Runge-Kutta with different orders can be derived. No- ticeable is that higher order Runge-Kutta methods have larger stability regions which makes bigger time steps possible.

Stability plots are an important tool when comparing REXI methods, which is why they are supported by the software. To calculate the stability value for a given linear ODE a stability function r must be created, which is defined as the operator applied to the current time step, to approximate the next time step un+1 = r(tλ)un. The absolute value of r(tλ)un has to be smaller or equal to |un| for the approximation to be considered stable. This means, if the amplitude of the solution is not a amplified, the time integration is considered stable [2].

8 2 ODE and PDE Basics

Figure 2.2 Stability plots for Runge-Kutta with orders 1 (blue), 2 (red), 3 (green), 4 (pink) for complex input values [24]

9 3 REXI Methods

REXI is a derivation for Rational approximation of an EXponential Integrator. The goal is to approximate a rational number as the solution of an exponential integrator. Exponential integrators are a class of numerical methods to solve ODEs. They are based on the exact integration of the linear part of the initial value problem [11]. Initial value problems are a combination of an ordinary differential equation and its initial condition, which specifies the value of the function at a given point in the domain [17]. In this case, the goal is to approximate the linear part of the shallow-water equation (SWE).

3.1 Problem Formulation

The equations are based on [28]. The linear operator (L) of the SWE is written as,   0 −η0∂x −η0∂y L(U) :=  −g∂x 0 f  U −g∂y − f 0

where η0 describes a rest state with a mean water depth and is defined for perturba- tions of height η. The vector U is written as,

U := (η, u, v)T. For now all non-linear terms are neglected and f, the f-plane approximation, is considered constant. The time evolution of the SWE is given by,

Ut = L(U) where t describes the derivative in time and the system as itself is oscillatory. This means that L is hyperbolic with imaginary eigenvalues. These problems are solvable with the help of exponential integrators for arbitrary time step sizes

10 3 REXI Methods

U(t) = eLtU(0). The problem is that solving is typically quite expensive, and analytic solutions only exist for simplified systems of the f-plane SWE. But with the help of REXI methods, the exponential integrator can be approximated. In the program eix is approximated, what can be done using

N β eix ≈ ∑ n . (3.1) n=−N ix + αn x is a complex number, but this could also be replaced by Lt, for example, from the SWE. REXI methods try to find the best values for the α and β coefficients, which will be referred to as REXI Coefficients and are complex valued.

3.2 TREXI

This REXI method was developed by Terry Haut at el in 2015 and for a more detailed explanation, see [15]. The following equations are based on [28]. The first step is to approximate the solution space

M ix e ≈ ∑ bmψh(x + mh), m=−M with the ψh(x) given as:

 2  − 1 x ψ (x) := (4π) 2 exp − . h 4h2

M is controlling the interval of approximation ("Number Basis Functions" in the program) and h is related to the accuracy of integration ("Spacing Basis Functions" in the program) and describes a "horizontal" stretching of ψh(x). To compute bm, f (x) has to be rewritten in the Fourier space. For the exact calcula- tions please see [28] pages 3-4.

1 b = h exp(−imh) (3.2) m h exp(−h2) = exp(−imh) exp(h2) (3.3)

11 3 REXI Methods

The next step is to approximate the basis function ψh(x). For h = 1 a nearly optimal approximation be constructed with a sum of rational functions

K a ψ (x) ≈ l , 1 ∑ + ( + ) l=−K ix µ il

and a generalized approximation for arbitrary h is give as

K a ψ (x) ≈ l . (3.4) h ∑ x + ( + ) l=−K i h µ il

The coefficients al and µ can be precomputed and for simplicity they are assumed to be given. The last step is to combine the approximations 3.3 3.4

M K ha eix ≈ b l ∑ m ∑ + ( + ( + )) m=−M k=−K ix h µ i m k

and bm can be moved into ∑K

M K b ha eix ≈ m l . ∑ ∑ + ( + ( + )) m=−M k=−K ix h µ i m k From this equation the α coefficients can be deduced

M K αn := h ∑ ∑ h(µ + i(m + k)), m=−M k=−K and the β coefficients can be computed by using δ as the Kronecker delta

M K Re βn := h ∑ ∑ Re(bm)akδ(n, m + k) m=−M k=−K M K Im βn := h ∑ ∑ Im(bm)akδ(n, m + k). m=−M k=−K

Having the REXI coefficients the REXI approximation can be set up

1 N  βRe + iβIm   βRe − iβIm  eix ≈ ∑ n n − n n , 2 n=−N ix + αn ix − αn

which can be transformed into the general REXI approximation 3.1.

12 3 REXI Methods

3.3 CIREXI

The following equations are based on [27]. For a detailed explanation and the applica- tion with the SWE please refer to [30, 29]. For this method Cauchy contour integrals are used. They can be used to compute a ix value for a given function f (x), which is e in this case, around a point x0. To compute the value the contour integral has to be integrated

1 I f (z) f (x) = dz. 2πi z − x Γ To approximate the exponential integrator first a contour that encapsulates the value x, for which the function value should be approximated, has to be chosen. A circle can be used as the contour which can be parametrized using

Γ = {R exp(iθ) + µ|θ ∈ [0; 2π], µ ∈ C}. In this case R describes the radius of the circle and µ describes the shift of the center. This leads to z and the derivate dz

z = R exp(iθ) + µ dz = iR exp(iθ))dθ.

Now everything can be inserted into the Cauchy contour integral equation

2π 1 I ψ(R exp(iθ) + µ) ψ(x) = (iR exp(iθ))dθ 2πi R exp(iθ) + µ − x 0 2π 1 I ψ(R exp(iθ) + µ)(iR exp(iθ)) = dθ 2πi R exp(iθ) + µ − x 0

and the α and β coefficients can be deduced

α(θ) = −(R exp(iθ) + µ), β(θ) = −ψ(R exp(iθ) + µ)(iR exp(iθ)).

Now the Cauchy contour integral can be written as

13 3 REXI Methods

2π 1 I β(θ) dθ, 2πi x + α(θ) 0 and discretized which leads to the REXI approximation

1 N β n . (3.5) ∑ + N n=1 x αn

3.4 BREXI and ELREXI

In this context BREXI and ELREXI 1 will no further be explained and they will be treated as a blackbox. For more detailed information on BREXI please refer to [9, 7].

3.5 Difficulties in comparing the methods

Comparing the performance of different REXI methods to each other is difficult because of high dimensional parameter spaces, and not directly related parameters. It is known that TREXI works best for purely oscillatory problems, and CIREXI and BREXI for diffusive and oscillatory problems [3]. This makes it hard to derive the correct REXI method from the problem. CIREXI has five parameters the radius, center, and number of support points for the circle contour. A half-shift option, that relates to the position of the support points and different ψ functions needed to calculate the β coefficients. BREXI has two different parameters, the number of support points and the quadra- ture method to calculate the REXI coefficients. TREXI needs two parameters, the interval of approximation and the spacing of basis function which relates to the accuracy of integration. ELREXI has 4 parameters, the real radius, imaginary radius, and the number of support points for the ellipse contour. The ψ function has to be defined which is needed to calculate the β coefficients.

1Developed by Pedro S. Peixoto but not yet published

14 4 Software

4.1 Required Functionality

As shown in the previous part, 4 different REXI methods exist with different parameters. To make it easier to understand how the REXI methods work it is useful to visualize the most important parts. For each method, the α values and other values that depend on the respective method have to be plotted. Most importantly, a way to compare the error resulting from the approximation is needed. For that, an option to define multiple points for the approximation has to be given and a way to visualize the error. To promote usability, everything must be updated automatically when new input parameters exist, which results in a lot of communication between the different compo- nents.

4.2 Terminology

Name Description Figure The figure is the area on which the α values are drawn and other values that depend on the REXI method. The evaluation points are also drawn onto this area. Plot Area The plot area is the area from the Figure that is currently visible. Toolbar The toolbar is the area that provides buttons to work with the Plot Area and to save the current plots. REXI Menu The REXI menu handles the setup of the REXI method and the drawing of the values. Evaluation Menu The Evaluation menu handles the creating and drawing of the evaluation points as well as the error visualizations.

15 4 Software

4.3 Graphical User Interface

4.3.1 Framework In the beginning, some prerequisites were established for the GUI framework. Most importantly it should work together with python3 under . Second of all the framework must be supported for a long time. So an active community and at best a company behind the framework was important. Also, the integration of matplotlib or another equivalent plotting software was an important criterion. Because the software is going to be used at presentations and conferences a modern look and feel is preferred. By searching on the internet for GUI frameworks that work together with python3 and fulfill the requirements, 7 different options came up, Tkinter, wxPython, Kivy, PyQt, PySide, PyGUI, PyGTK, see [13, 12, 5, 6, 22, 8]. From further investigating the internet the choice was narrowed down to wxPython, Kivy, and PyQt.

• Kivy has great cross-platform capabilities and looks modern. But its primary focus is on mobile devices, which results in a lack of support for multiple windows.

• wxPython is written in python but wraps wxWidgets which are written in c++. The applications use native GUI elements of the respective . It is also backed up by a big community, which makes it likely to be around for many years.

• PyQt uses the c++ cross-platform , and is supported by Riverbank Computing. For non-commercial uses, it is free under the GNU GPL v3 license [33]. Because it is supported by a company it is likely to be around for many years. The community is very big and there are examples for nearly everything in the internet, which makes it very easy to start with.

In the end, the choice fell on PyQt. Besides the above mentioned advantages, it is also said to be more stable and flexible [18, 4].

4.4 Architecture

4.4.1 Class Diagram In order to get a better overview of the code, a UML class Diagram was created which displays the most important classes 4.1. The most important class is the GUI class, from here the whole program is started. The second most important class is the Store class, which is initialized in the GUI class. It contains all the objects and information that is needed throughout the different

16 4 Software

Figure 4.1 Class Diagram showing the most important classes with methods classes like references to REXI coefficients, the plot class, and the different windows to display the error. The Informal REXI Interface provides an interface with methods that each REXI method class should provide in order for the REXI Menu to work. This class/interface is also intended to make it easier in the future to add additional REXI methods. The Evaluation Menu class handles the creation of evaluation points and the error as well as the windows to display the error, stability, and order star. The Informal Evaluation Interface interface provides methods that each evaluation option, to create points, should have. This is also intended to make it easier to add new options in the future. The Graph class handles the Toolbar and Plot Area.

17 4 Software

Figure 4.2 Dynamic Model to display the users interaction with the system

4.4.2 Dynamic Model To gain a better understanding of how the user interacts with the system an activity diagram was created 4.2. The user starts the program and is presented with the REXI Menu in which he can choose the REXI method. He will choose one and has to enter the required parameters. Next, he has to pick the evaluation option in the Evaluation Menu and afterwards he has to enter the corresponding parameters. Then he chooses one of the windows to evaluate the method with the evaluation points defined in the previous step. If he decides he can open multiple windows, save the current figures, close the app or change the REXI method, REXI parameters, evaluation option and/or evaluation parameters.

4.4.3 Event Handling GUI applications, like this one, are mainly event-driven. User input triggers such events, but they can also be triggered when data from a server is received for example. In the program, a lot of different components exist that have to stay synchronized with each other. When the radius of the Cauchy contour gets updated, the Figure has to be updated, the error recomputed, and all secondary windows that either use the REXI coefficients or the error have to be updated. PyQt uses to communicate between objects. Signals are emitted by

18 4 Software

Figure 4.3 UML classes for the update signals as used in the program an event and slots can be any python callable and they are called when the connected signal is emitted [31]. PyQt offers the possibility to create custom signals by implementing a new object that inherits from QObjects. QObjects provide the functionality for communication between all objects in PyQt. Every QtWidget inherits from them for example. In this case, the functionality to connect signals is needed [23]. When creating a custom signal it is also possible to define what kind of information should be sent when the signal is emitted. In the program, there is a need for two different signals 4.3. The first one to emit if REXI coefficients are update and the second one to emit if the evaluation points change and/or the computed error changes.

4.5 User Documentation

In this section the functionality, installation, and usage will be demonstrated and an example for CIREXI, which includes the calculations, will be presented.

4.5.1 Explanation of Functionality The Toolbar contains all the functionality required to work with the Plot Area 4.4.

1. When selected, the evaluation drawings and the CIREXI contour can be grabbed, with the primary mouse button pressed, to move them around. With the sec- ondary mouse button pressed the Plot Area can be moved around.

2. When selected, the Plot Area can be moved around with the primary mouse button pressed.

3. When clicked, the Plot Area is zoomed in.

4. When clicked, the Plot Area is zoomed out.

5. When selected the cursor changes into a red pointer when it hovers over the Plot Area.

19 4 Software

Figure 4.4 Screenshot of the main screen with different functions and components surrounded

6. When clicked, the center of the Figure moves in the center of the Plot Area.

7. When clicked, the saving dialog opens. (Will be further explained in the example later.)

8. When clicked, all plots from the Figure are removed.

The Menu Bar to switch between the REXI Menu and Evaluation Menu.

9. When clicked, the REXI Menu will show in the area underneath.

10. When clicked, the Evaluation Menu will show in the area underneath.

20 4 Software

REXI Menu

The REXI Menu 4.5 is responsible for displaying all the REXI methods.

1. When clicked, a context menu opens to select a REXI method.

The next three sections are contained in a scroll area. 2. This section contains the functionality to enter the respective parameters for the REXI method and provides the functionality to plot the val- ues. 2.1. When clicked, the area minimizes/maxi- mizes. 2.2. This part changes when the REXI method changes. Here the options for the REXI method can be entered. 2.3. When clicked, the REXI coefficients are created and current values for the REXI method are plotted. 2.4. When selected, the coefficients are created and plotted automatically when a parame- ter changes.

3. This area is responsible for displaying the coef- ficients. 3.1. When clicked, the area minimizes/maxi- mizes. 3.2. This part displays the number of REXI Co- efficients and the gamma value if given. 3.3. When clicked, a window with a table con- taining the REXI coefficients opens or gets updated. 3.4. When checked, the coefficients table is up- Figure 4.5 dated automatically. When the window REXI menu with closes the box is unchecked automatically. components surrounded

21 4 Software

4. In this area the color values for the REXI plots can be chosen. 4.1. When clicked, the area minimizes/maxi- mizes. 4.2. When clicked, the primary color can be selected from the fold out menu. (con- tour for CIREXI, ELREXI and α values for BREXI, TREXI) 4.3. When clicked, the secondary color can be selected from the fold out menu. (α values for CIREXI, ELREXI and γ value for BREXI)

Evaluation Menu

The Evaluation Menu 4.6 to evaluate the different REXI methods. The next three sections are contained in a scroll area.

1. This section contains the functionality to create and plot the evaluation points. 1.1. When clicked, the area minimizes/maxi- mizes. 1.2. In this part the option to create evaluation points can be selected by clicking on them. 1.3. This area changes when a new option is selected for the evaluation points. In here, Figure 4.6 the corresponding parameters can be en- Evaluation menu with tered. components surrounded 1.4. When clicked, the current evaluation op- tion is plotted. 1.5. When selected, the evaluation points are plotted automatically when a parameter changes.

2. This area is responsible for displaying the error, stability and order star.

22 4 Software

2.1. When clicked, the area minimizes/maximizes. 2.2. This part displays the number of REXI Coefficients and the gamma value if given. 2.3. When clicked, the error windows, stability window, or order star window opens or updates. 2.4. When checked, the window is updated automatically. The box gets unchecked when the corresponding window closes.

3. In this area the color value for the evaluation points can be chosen. 3.1. When clicked, the area minimizes/maximizes. 3.2. When clicked, the color can be selected from the fold out menu.

Details on the coefficient table window and the error table window 4.7: (a) In this window, the α and β coefficients are displayed ordered in a list 4.7a.

(b) In this window, the error is displayed ordered in a table. The first error value corresponds to the evaluation point on the top left in the Figure, the last one to the evaluation point in the bottom right 4.7b.

(b) Error Table Window (a) Coefficients Table Window

Figure 4.7 Using CIREXI with 32 support points, a radius of 1, and the center at (0, 0). To calculate the error 300x300 points distributed in a 2x2 grid with the center at (0, 0) were used.

23 4 Software

(a) Error Plot Window (b) Error Map Window

(c) Stability Window (d) Order Star Window

Figure 4.8 Using CIREXI with 32 support points, a radius of 1, and the center at (0, 0). To calculate the error 300x300 points distributed in a 2x2 grid with the center at (0, 0) were used.

24 4 Software

Details on the error plot window, error map window, stability window, and order star window 4.8.

(a) In this window, the error is displayed on the y-axes reaching from 102 to 10−14 and on the x-axes are the evaluation points 4.8a. By clicking on the button on the top, the scaling changes from linear to logarithmic and back.

(b) In this window, the error is displayed in an error map. White fields mean that the error value is outside of the scale which is [10−18, 101] 4.8b.

(c) In this window, the stability values of the current evaluation points are displayed. Enclosed areas are areas of stability 4.8c.

A stable value can be determined with the help of one iteration un+1 = r(z)un. The function r(z) is the stability function and |r(z)un| has to be smaller or equal to |un| for the iteration to be considered stable [25]. In the case of one REXI approximation it is assumed that un = 1, which means the approximation is stable if |r(z)| ≤ 1. In the program the value of the REXI approximation is used as the value of the stability function r. A stability region is then given as,

S = {|r(z)| ≤ 1|z ∈ C}.

(d) In this window, the order star values of the current evaluation points are displayed 4.8d. Order Star plots show relative stability regions. To determine the relative stability for a given approximation, the approximation R(z) is divide by the actual solution f (z) [32]. In the program, the resulting value is displayed in three different colors,

R(z) R(z) R(z) > 1.1 red, 1.1 >= >= 1 yellow, 1 > blue f (z) f (z) f (z)

4.5.2 Installation and Example The software was tested and designed for Ubuntu 20.04 and macOS Catalina. To run the application matplotlib and PyQt have to be installed. Under Ubuntu this can be done by running: $ sudo apt-get install python3-pyqt5 $ sudo apt-get install python3-matplotlib After running theses commands and installing the libraries the application can be started by navigating into the folder with the gui.py file and typing

25 4 Software

Figure 4.9 Main Window with CIREXI Contour using 32 support points and the center at (0, 0).

$ python3 gui.py To gain a better understanding, a simple example using CIREXI approximating 2500 points, is created underneath. The result will be displayed in an error map and saved into a folder. As shown in 4.9 the following steps have to be taken,

1. All default parameters for CIREXI will be kept the same. By clicking on Plot Contour the values will be plotted and the coefficients created.

2. To change to the Evaluation Menu click on Evaluate in the Menu Bar.

As shown in 4.10 in the Evaluate Menu the following steps have to be taken,

1. The grid option will be chosen for this example in the Evaluation Menu.

2-3. 2.0 will be used for the horizontal and vertical length.

4-5. As the number of horizontal and vertical lines 50 is used.

26 4 Software

Figure 4.10 Main Window with CIREXI Contour using 32 support points and the center at (0, 0). The evaluation Grid uses 50x50 points distributed over an area of 2x2 with the center at (0, 0).

6. While entering the parameters the grid should be automatically updated. The error map window will be opened automatically as soon as the box gets checked.

In 4.11 the accuracy of the CIREXI method with the current parameters at different points throughout the area can be analyzed. White fields mean, that the error value is outside of the scale which is [10−18, 101]. In this case, it can be assumed with respect to the surrounding, that the error for the white points is smaller than 10−18. Noticeable is that the error is significantly larger compared to the surrounding when a point on top of one of the support points for the Cauchy contour integral is approximated. As the last step, the error map can be saved as a .png file by clicking on the disk in the Toolbar. The saving dialog should open automatically 4.12.

1. First the name has to be entered.

2. Next the location where to save the file has to be chosen.

3. The figure can be saved as a .png or .pdf file.

27 4 Software

Figure 4.11 Error map for 2500 points equally distributed in a 2x2 are with (0, 0) as the center using CIREXI with 32 support points, a radius of 1 and the center at 0, 0

Figure 4.12 Saving dialog for the example with CIREXI

4. By clicking on "Save" the figure gets saved. This process may take a while.

28 4 Software

A new folder with the given name was created under the location chosen for saving. In the folder is not only the error map stored but also the REXI plot. That is because every plot window that is open at the moment the saving dialog opens is saved.

Calculations done for the approximation

The first step is to parametrize the Cauchy contour. In the case above a circle with 32 support points, a radius of 1, and the center at (0, 0), is used. With

γ = R exp(iθ) + µ = exp(iθ), θ ∈ [0; 2π]

the support points for the circle contour can be constructed resulting in

Number Support Point Value 1 1 + 0i . . . . 8 0.1950903220161283 + 0.9807852804032304i 9 6.123233995736766e-17 + 1i) . . . . 32 0.9807852804032303 - 0.19509032201612872i

Now the REXI coefficients can be computed, where the α values are the negated support points.

αn = −(R exp(iθ) + µ) = −(exp(iθ))

= −γn The resulting α coefficients are

α coefficient number α value 1 -1 - 0j . . . . 8 -0.1950903220161283 - 0.9807852804032304i 9 -6.123233995736766e-17 - 1i . . . . 32 -0.9807852804032303 + 0.19509032201612872i

29 4 Software

Next the β coefficients have to be computed. For that ψ0 was used in the example x above which is given as e . With a radius R of 1 and the shift µ of 0, βn can be calculated with

−exp(R exp(iθ) + µ)i exp(iRθ) β = n N −exp(exp(iθ))i exp(iθ) = N −exp(γ )i exp(iθ) = n N Notice that β was already divided by N compared to the CIREXI discretization 3.5 1 where the term N was outside of the sum. This makes it possible to use the general REXI approximation 3.1. The resulting β coefficients are

β coefficient number β value 1 -0.08494630713934516 + 0i . . . . 8 0.02683139768577018 - 0.02688309380909196i 9 0.026295968275246766 - 0.016884447058379368i . . . . 32 -0.07702666970383326 + 0.031791915559810105i

Using the REXI approximation

N β eix ≈ ∑ n n=−N ix + αn the value for a given point can finally be approximated.

Point approximation real value absolute error 0.2+0.4i 1.12498643+0.47563663i 1.12498644+0.47563664i 8.004406−12 -0.2+0.4i 0.75410096+0.31882877i 0.75410096+0.31882877i 5.365855−12 -0.2-0.4i 0.75410096-0.31882877i 0.75410096-0.31882877i 5.365630−12 0.2-0.4i 1.12498643-0.47563663i 1.12498644-0.47563664i 8.004630−12

Table 4.1: CIREXI approximations for different, evenly spread, values inside the contour. Noticeable is that the error is smaller for values that have a negative real component.

30 4 Software

In table 4.1, 4 different CIREXI approximations can be seen. The points for the approximations are evenly spaced inside the contour and each value is located in one quadrant of the coordinate system. Noticeable is that approximations for values, which have a negative real component, performed better. But in general, the approxima- tions are strong and they even reach double precision, as long as the value for the approximation is inside the contour. It is furthermore noticeable that the approximation gets significantly better by in- creasing the number of support points. With 64 instead of 32 support points, the error falls from 10−12 to 10−16.

4.5.3 Third-party components A list of all third-party components with links to there official websites.

• PyQt5 - https://riverbankcomputing.com/software/pyqt

• matplotlib - https://matplotlib.org

• NumPy - https://numpy.org

31 5 Summary and Conclusion

Simulations, like weather and climate predictions, mostly rely on numerical methods, that contain differential equations. Solving differential equations is often computation- ally expensive, and solutions not always exist. Time dependent ordinary differential equations can be approximated with time- stepping methods like Runge-Kutta 2.3. The problem with these methods is that often only small time steps are possible for the iteration to be stable 2.2. Solutions for differential equations often contain an exponential integrator, like in these examples 2.1 2.16. This term can be approximated using,

N β eix ≈ ∑ n . n=−N ix + αn The presented REXI methods in chapter 3 try to find the most suitable values for α and β. The advantage of REXI methods is that large time steps are possible, and approximations can be done in parallel, which results in a huge performance benefit. But a high parameter space makes it complicated to compare the different methods and the correct method can not be derived from the problem 3.5. For this reason, a software, which is further described in chapter 4, was developed to facilitate the comparison. The software incorporates all REXI methods that exist today and visualizes the most important parts from them. Also, multiple complex valued points can be defined, and eix, where x is one point, can then approximated using one of the REXI methods. The error from this approximation can then be visualized in multiple ways, as well as the stability and order star values. The software created is well documented and can easily be extended due to the clear structure and the use of standard technologies.

Finally, it can be said that the different REXI methods can now be compared more efficient, due to the help of error, stability and order star plots. Thus, all goals of the project were achieved.

32 Bibliography

[1] Schreiber, ST 2020, Time integration basics: ODEs, lecture notes, Selected Topics in Algorithms and Scientific Computing (IN3400, IN3480), Chair of Computer Architecture and Parallel Systems Technical University of Munich. [2] Schreiber, ST 2020, Time integration: intermediate level, lecture notes, Selected Topics in Algorithms and Scientific Computing (IN3400, IN3480), Chair of Computer Architecture and Parallel Systems Technical University of Munich. [3] Schreiber, ST 2020, Rational approximation of exponential integrators, lecture notes, Selected Topics in Algorithms and Scientific Computing (IN3400, IN3480), Chair of Computer Architecture and Parallel Systems Technical University of Munich. [4] "Amigos-maker". PyQT vs wxPython: Which GUI module for your project? DEV, URL: https://dev.to/amigosmaker/pyqt-vs-wxpython-which-gui-module-for- your-project-3dfb. Date Accessed: 2020-04-02. 2019. [5] "IssueHunt". 13 Python GUI Libraries. Medium, URL: https://medium.com/ issuehunt/13-python-gui-libraries-a6196dfb694. Date Accessed: 2020-04-02. 2018. [6] J. Baker and S. Kenlon. 5 open source Python GUI frameworks. opensource, URL: https://opensource.com/resources/python/gui-frameworks. Date Accessed: 2020-04-02. 2019. [7] T. Bickart. “Direct solution method forA_{1}E +EA_{2}=-D.” In: IEEE Transactions on Automatic Control 22.3 (June 1977), pp. 467–468. issn: 1558-2523. doi: 10.1109/ TAC.1977.1101490. [8] D. Bolton. 7 Top Python GUI Frameworks. DICE, URL: https://insights.dice. com/2017/08/07/7-top-python-gui-frameworks/. Date Accessed: 2020-04-02. 2017. [9] J. C. Butcher. “On the implementation of implicit Runge-Kutta methods.” In: BIT Numerical Mathematics 16.3 (1976), pp. 237–240. issn: 1572-9125. doi: 10.1007/ BF01932265. [10] Explicit and Implicit Methods to Solve Differential Equations. Wikipedia The Free En- cyclopedia, URL: https://en.wikipedia.org/wiki/Explicit_and_implicit_ methods. Date Accessed: 2020-08-02.

33 Bibliography

[11] Exponential integrator. Wikipedia The Free Encyclopedia, URL: https : / / en . wikipedia.org/wiki/Exponential_integrator. Date Accessed: 2020-08-01. [12] H. Fatima. The 6 Best Python GUI Frameworks for Developers. resellerclub, URL: https://blog.resellerclub.com/the-6-best-python-gui-frameworks-for- developers/. Date Accessed: 2020-04-02. 2017. [13] Graphic User Interface FAQ. Python Software Foundation, URL: https://docs. python.org/3/faq/gui.html. Date Accessed: 2020-04-02. [14] M. J. Hancock. The 1-D Heat Equation, Linear Partial Differential Equations. URL: https : / / ocw . mit . edu / courses / mathematics / 18 - 303 - linear - partial - differential - equations - fall - 2006 / lecture - notes / heateqni . pdf. Date Accessed: 2020-08-05. 2006. [15] T. Haut, T. Babb, P. Martinsson, and B. Wingate. “A high-order time-parallel scheme for solving wave propagation problems via the direct construction of an approximate time-evolution operator.” In: IMA Journal of Numerical Analysis 36.2 (2016), pp. 688–716. doi: https://doi.org/10.1093/imanum/drv021. [16] In diesen Branchen spielen Wetterdaten eine besonders große Rolle. Verband Deutscher Wetterdienstleister, URL: https : / / www . wetterverband . de / news - presse / zahlen-fakten/in-diesen-branchen-spielen-wetterdaten-eine-besonders- grosse-rolle/. Date Accessed: 2020-08-04. [17] Initial value problem. Wikipedia The Free Encyclopedia, URL: https : / / en . wikipedia.org/wiki/Initial_value_problem. Date Accessed: 2020-08-01. [18] S. Kenlon. Qt versus Wx: How do two of the most popular Python frameworks compare? opensource, URL: https : / / opensource . com / article / 17 / 4 / pyqt - versus - wxpython. Date Accessed: 2020-04-02. 2017. [19] P. Lynch. “The origins of computer weather prediction and climate modeling.” In: Journal of Computational Physics 227.7 (2007), pp. 3431–3444. doi: 10.1016/j. jcp.2007.02.034. [20] Mean sea level pressure and wind speed at 850 hPa Forecast ECMWF. ECMWF, URL: https://www.ecmwf.int/en/forecasts/charts/catalogue/medium- mslp- wind850?facets=Component,Surface%3BType,Forecasts%3BParameters,Wind& time = 2020080600 , 0 , 2020080600 & projection = classical _ europe. Date Ac- cessed: 2020-08-05. [21] Numerical weather prediction. Wikipedia The Free Encyclopedia, URL: https : //en.wikipedia.org/wiki/Numerical_weather_prediction. Date Accessed: 2020-08-05.

34 Bibliography

[22] Python - GUI Programming (Tkinter). tutorialspoint, URL: https://www.tutorialspoint. com/python/python_gui_programming.htm. Date Accessed: 2020-07-20. [23] QObjects. The Qt Company, URL: https://doc.qt.io/qtforpython/PySide2/ QtCore/QObject.html#more. Date Accessed: 2020-07-28. [24] Runge-Kutta stability plot. MathWorks, URL: https : / / www . mathworks . com / matlabcentral/mlc-downloads/downloads/submissions/23972/versions/22/ previews/chebfun/examples/ode/html/Regions_02.png. Date Accessed: 2020- 08-06. [25] Runge–Kutta Methods. Wikipedia The Free Encyclopedia, URL: https : / / en . wikipedia.org/wiki/Runge-Kutta_methods. Date Accessed: 2020-08-06. [26] C. Runge. “Ueber die numerische Aufloesung von Differentialgleichungen.” In: (1895). doi: 10.1007/bf01446807. [27] M. Schreiber. Notes on Cauchy integration. GitHub, URL: https://github.com/ schreiberx / sweet / blob / master / doc / rexi / rexi _ with _ cauchy _ integral / notes_on_cauchy_integration.pdf. Date Accessed: 2020-07-27. 2017. [28] M. Schreiber. Understanding the Rational Approximation of the Exponential Integrator (REXI). GitHub, URL: https://github.com/schreiberx/sweet/blob/master/ doc/rexi/understanding_rexi/understanding_rexi.pdf. Date Accessed: 2020- 07-20. 2018. [29] M. Schreiber and R. Loft. “A Parallel Time-Integrator for Solving the Linearized Shallow Water Equations on the Rotating Sphere.” In: Numerical Linear Algebra with Applications 26.2 (2018). doi: doi.org/10.1002/nla.2220. [30] M. Schreiber, N. Schaeffer, and R. Loft. “Exponential Integrators with Parallel-in- Time Rational Approximations for the Shallow-Water Equations on the Rotating Sphere.” In: Parallel Computing 85 (2019), pp. 56–65. doi: 10.1016/j.parco.2019. 01.005. [31] Signal. The Qt Company, URL: https://doc.qt.io/qtforpython/PySide2/ QtCore/Signal.html. Date Accessed: 2020-07-28. [32] G. Wanner, E. Hairer, and S. P. Nørsett. “Order stars and stability theorems.” In: BIT Numerical Mathematics 18.4 (1978), pp. 475–489. doi: doi.org/10.1007/ BF01932026. [33] What is PyQt? Riverbank Computing, URL: hhttps://riverbankcomputing.com/ software/pyqt/intro. Date Accessed: 2020-04-02. [34] R. Winter. Classification of differential equations. Maths for Physicists and vice versa, URL: https://users.aber.ac.uk/ruw/teach/260/classification.php. Date Accessed: 2020-08-01. 2012.

35