84
NodePy Documentation Release 0.6.1 David Ketcheson September 06, 2016

NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

  • Upload
    lamphuc

  • View
    241

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy DocumentationRelease 0.6.1

David Ketcheson

September 06, 2016

Page 2: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all
Page 3: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

Contents

1 Overview 31.1 Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Classes of Numerical ODE Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Analysis of Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 Testing Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.5 NodePy Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 Modules Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351.7 Indices and tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Bibliography 73

Python Module Index 75

i

Page 4: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

ii

Page 5: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• Overview– Dependencies– Classes of Numerical ODE Solvers– Analysis of Methods– Testing Methods– NodePy Manual– Modules Reference– Indices and tables

Contents 1

Page 6: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

2 Contents

Page 7: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

CHAPTER 1

Overview

NodePy (Numerical ODEs in Python) is a Python package for designing, analyzing, and testing numerical methodsfor initial value ODEs. Its development was motivated by my own research in time integration methods for PDEs. Ifound that I was frequently repeating tasks that could be automated and integrated. Initially I developed a collection ofMATLAB scripts, but this became unwieldy due to the large number of files that were necessary and the more limitedcapability for code reuse.

NodePy represents an object-oriented approach, in which the basic object is a numerical ODE solver. The idea is todesign a laboratory for such methods in the same sense that MATLAB is a laboratory for matrices. Some distinctivedesign goals are:

• Plug-and-play: any method can be applied to any problem using the same syntax. Also, properties of differentkinds of methods are available through the same syntax. This makes it easy to compare different methods.

• Abstract representations: Generally, the most abstract (hence powerful) representaton of an object is usedwhenever possible. Thus, order conditions are generated using products on rooted trees (or other recursions)rather than being hard-coded.

• Numerical representation: The most precise representation possible is used for quantities such as coefficients:rational numbers (using SymPy’s Rational class) when available, floating-point numbers otherwise. Wherenecessary, method properties are determined by numerical calculations, using appropriate tolerances. Thus the“order” of a method with floating-point coefficients is determined by checking whether the order conditions aresatisfied to within a small value (near machine-epsilon). For efficiency reasons, coefficients are always convertedto floating-point for purposes of applying the method to a problem.

In general, user-friendliness of the interface and readability of the code are prioritized over performance.

NodePy includes capabilities for applying the methods to solve systems of ODEs. This is mainly intended for testingand comparison; for realistic problems of interest in most fields, time-stepping in Python will be too slow. One wayaround this is to wrap Fortran or C functions representing the right-hand-side of the ODE, and we are looking intothis.

Note: The user guide is currently quite incomplete, and in general is not expected to keep pace with all NodePydevelopment. However, NodePy includes substantial inline documentation within the various modules, and you areencouraged to look there.

1.1 Dependencies

• Python 2.7

• Numpy, Matplotlib

3

Page 8: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• SymPy (note: NodePy is now compatible with SymPy 0.7.1)

• Optional: networkx (for some Runge-Kutta stage dependency graphing)

1.2 Classes of Numerical ODE Solvers

NodePy includes classes for the following types of methods:

• Runge-Kutta Methods

– Implicit

– Explicit

– Embedded pairs

– Low-storage methods

– Extrapolation methods

– Integral deferred correction methods

– Strong stability preserving methods

– Runge-Kutta-Chebyshev methods

• Linear Multistep Methods

• Two-step Runge-Kutta Methods

Arbitrary methods in these classes can be instantiated by specifying their coefficients.

1.3 Analysis of Methods

NodePy includes functions for analyzing many properties, including:

• Stability:

– Absolute stability (e.g., plot the region of absolute stability)

– Strong stability preservation

• Accuracy

– Order of accuracy

– Error coefficients

– Relative accuracy efficiency

– Generation of Python and MATLAB code for order conditions

1.4 Testing Methods

NodePy includes implementation of the actual time-stepping algorithms for the various classes of methods. A widerange of initial value ODEs can be loaded, including the DETEST suite of problems. Arbitrary initial value problemscan be instantiated and solved simply by calling a method with the initial value problem as argument. For methodswith error estimates, adaptive time-stepping can be used based on a specified error tolerance. NodePy also includesautomated functions for convergence testing.

4 Chapter 1. Overview

Page 9: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

In the future, NodePy may also support solving semi-discretizations of initial boundary value PDEs.

1.5 NodePy Manual

1.5.1 Quick Start Guide

Obtaining NodePy

It is possible to install NodePy via pip, but the pip version is often outdated and the development version is recom-mended instead. The current development version of NodePy can be obtained via Git:

git clone git://github.com/ketch/nodepy.git

Installing NodePy

After downloading, simply add the directory containing the nodepy directory to your Python path. For instance, ifyour nodepy directory is /user/home/python/nodepy, the appropriate bash command is:

$ export PYTHONPATH=/user/home/python/

You will probably want to add this command to your .bash_profile file to avoid retyping it.

NodePy Documentation

NodePy documentation can be found at http://numerics.kaust.edu.sa/nodepy

The documentation is also included in the nodepy/doc directory, and can be built from your local install, if you haveSphinx.

Examples

NodePy comes with some canned examples that can be run to confirm your installation and to demonstrate capabilitiesof NodePy. These can be found in the directory nodepy/examples. Additional examples can be found in the UserGuide .

1.5.2 Classes of ODE solvers

The basic object in NodePy is an ODE solver. Several types of solvers are supported, including linear multistepmethods, Runge-Kutta methods, and Two-step Runge-Kutta methods. For each class, individual methods may beinstantiated by specifying their coefficients. Many convenience functions are also provided for loading commonmethods or common families of methods. The Runge-Kutta method class also supports some special low-storage RKmethod classes, integral deferred correction methods, and extrapolation methods.

1.5. NodePy Manual 5

Page 10: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Contents

• Runge-Kutta methods– Accuracy– Classical (linear) stability– Nonlinear stability– Reducibility of Runge-Kutta methods– Composing Runge-Kutta methods

• Embedded Runge-Kutta Pairs• Low-Storage Runge-Kutta methods

– 2S/3S methods– 2S/3S embedded pairs– 2R/3R methods

Runge-Kutta methods

A Runge-Kutta method is a one-step method that computes the next time step solution as follows:

\begin{align*} y_i = & u^{n} + \Delta t \sum_{j=1}^{s} + a_{ij} f(y_j)) & (1\le j \le s) \\ u^{n+1} = &u^{n} + \Delta t \sum_{j=1}^{s} b_j f(y_j). \end{align*}

The simplest way to load a Runge-Kutta method is using the loadRKM function:

>> from nodepy import runge_kutta_method as rk>> import numpy as np>> rk44=rk.loadRKM('RK44')Classical RK4

0.000 |0.500 | 0.5000.500 | 0.000 0.5001.000 | 0.000 0.000 1.000

_______|________________________________| 0.167 0.333 0.333 0.167

Many well-known methods are available through the loadRKM() function. Additionally, several classes of methodsare available through the following functions:

• Optimal strong stability preserving methods: SSPRK2(s), SSPRK3(s), SSPIRK2(), etc.

• Integral deferred correction methods: DC(s)

• Extrapolation methods: extrap(s)

• Runge-Kutta Chebyshev methods: RKC1(s), RKC2(s)

See the documentation of these functions for more details.

More generally, any Runge-Kutta method may be instantiated by providing its Butcher coefficients, 𝐴 and 𝑏:

>> A=np.array([[0,0],[0.5,0]])>> b=np.array([0,1.])>> rk22=rk.RungeKuttaMethod(A,b)

Note that, because NumPy arrays are indexed from zero, the Butcher coefficient 𝑎21, for instance, corresponds tomy_rk.a[1,0]. The abscissas 𝑐 are automatically set to the row sums of 𝐴 (this implies that every stage has has stageorder at least equal to 1). Alternatively, a method may be specified in Shu-Osher form, by coefficient arrays 𝛼, 𝛽:

6 Chapter 1. Overview

Page 11: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>> rk22=rk.RungeKuttaMethod(alpha=alpha,beta=beta)

A separate subclass is provided for explicit Runge-Kutta methods: ExplicitRungeKuttaMethod. If a method is explicit,it is important to instantiate it as an ExplicitRungeKuttaMethod and not simply a RungeKuttaMethod, since the latterclass has significantly less functionality in NodePy. Most significantly, time stepping is currently implemented forexplicit methods, but not for implicit methods.

Examples:

>>> from nodepy.runge_kutta_method import *

• Load a method:

>>> ssp104=loadRKM('SSP104')

• Check its order of accuracy:

>>> ssp104.order()4

• Find its radius of absolute monotonicity:

>>> ssp104.absolute_monotonicity_radius()5.999999999949068

• Load a dictionary with many methods:

>>> RK=loadRKM()>>> sorted(RK.keys())['BE', 'BS5', 'BuRK65', 'CMR6', 'DP5', 'FE', 'Fehlberg45', 'GL2', 'GL3', 'Heun33', 'Lambert65', 'LobattoIIIA2', 'LobattoIIIA3', 'LobattoIIIC2', 'LobattoIIIC3', 'LobattoIIIC4', 'MTE22', 'Merson43', 'Mid22', 'NSSP32', 'NSSP33', 'PD8', 'RK44', 'RadauIIA2', 'RadauIIA3', 'SDIRK23', 'SDIRK34', 'SDIRK54', 'SSP104', 'SSP22', 'SSP22star', 'SSP33', 'SSP53', 'SSP54', 'SSP63', 'SSP75', 'SSP85', 'SSP95']

>>> print(RK['Mid22'])Midpoint Runge-Kutta

0 |1/2 | 1/2_____|__________

| 0 1

• Many methods are naturally implemented in some Shu-Osher form different from the Butcher form:

>>> ssp42 = SSPRK2(4)>>> ssp42.print_shu_osher()SSPRK(4,2)

| |1/3 | 1 | 1/32/3 | 1 | 1/31 | 1 | 1/3_____|_____________________|_____________________

| 1/4 3/4 | 1/4

References:

1. [butcher2003]

2. [hairer1993]

1.5. NodePy Manual 7

Page 12: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Accuracy

The principal measure of accuracy of a Runge-Kutta method is its order of accuracy. By comparing the Runge-Kuttasolution with the Taylor series for the exact solution, it can be shown that the local truncation error for small enoughstep size ℎ is approximately

Error ≈ 𝐶ℎ𝑝,

where 𝐶 is a constant independent of ℎ. Thus the expected asymptotic rate of convergence for small step sizes is 𝑝.This error corresponds to the lowest-order terms that do not match those of the exact solution Taylor series. Typically,a higher order accurate method will provide greater accuracy than a lower order method even for practical step sizes.

In order to compare two methods with the same order of accuracy more detailed information about the accuracy of amethod may be obtained by considering the relative size of the constant 𝐶. This can be measured in various ways andis referred to as the principal error norm.

For example:

>> rk22.order()2>> rk44.order()4>> rk44.principal_error_norm()0.014504582343198208>> ssp104=rk.loadRKM('SSP104')>> ssp104.principal_error_norm()0.002211223747053554

Since the SSP(10,4) method has smaller principal error norm, we expect that it will provide better accuracy than theclassical 4-stage Runge-Kutta method for a given step size. Of course, the SSP method has 10 stages, so it requiresmore work per step. In order to determine which method is more efficient, we need to compare the relative accuracyfor a fixed amount of work:

>> rk.relative_accuracy_efficiency(rk44,ssp104)1.7161905294239843

This indicates that, for a desired level of error, the SSP(10,4) method will require about 72% more work.

RungeKuttaMethod.principal_error_norm(tol=1e-13, mode=’float’)The 2-norm of the vector of leading order error coefficients.

RungeKuttaMethod.error_metrics()Returns several measures of the accuracy of the Runge-Kutta method. In order, they are:

•𝐴𝑞+1: 2-norm of the vector of leading order error coefficients

•𝐴𝑞+1𝑚𝑎𝑥: Max-norm of the vector of leading order error coefficients

•𝐴𝑞+2 : 2-norm of the vector of next order error coefficients

•𝐴𝑞+2𝑚𝑎𝑥: Max-norm of the vector of next order error coefficients

•𝐷: The largest (in magnitude) coefficient in the Butcher array

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.error_metrics()(sqrt(1745)/2880, 1/120, sqrt(8531)/5760, 1/144, 1)

Reference: [kennedy2000]

8 Chapter 1. Overview

Page 13: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

RungeKuttaMethod.stage_order(tol=1e-14)The stage order of a Runge-Kutta method is the minimum, over all stages, of the order of accuracy of that stage.It can be shown to be equal to the largest integer k such that the simplifying assumptions 𝐵(𝑥𝑖) and 𝐶(𝑥𝑖) are satisfied for 1𝑙𝑒𝑥𝑖𝑙𝑒𝑘.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.stage_order()1>>> gl2 = rk.loadRKM('GL2')>>> gl2.stage_order()2

References:

1. Dekker and Verwer

2. [butcher2003]

Classical (linear) stability

RungeKuttaMethod.stability_function(stage=None, mode=’exact’, formula=’lts’,use_butcher=False)

The stability function of a Runge-Kutta method is𝑝ℎ𝑖(𝑧) = 𝑝(𝑧)/𝑞(𝑧), where

$$p(z)=\det(I - z A + z e b^T)$$

$$q(z)=\det(I - z A)$$

The function can also be computed via the formula

$$‘\phi(z) = 1 + b^T (I-zA)^{-1} e$$

where 𝑒 is a column vector with all entries equal to one.

This function constructs the numerator and denominator of the stability function of a Runge-Kutta method.

For methods with rational coefficients, mode=’exact’ computes the stability function using rational arithmetic.Alternatively, you can set mode=’float’ to force computation using floating point, in case the exact computationis too slow.

For explicit methods, the denominator is simply 1 and there are three options for computing the numerator (thisis the ‘formula’ option). These only affect the speed, and only matter if the computation is symbolic. They are:

•‘lts’: SymPy’s lower_triangular_solve

•‘det’: ratio of determinants

•‘pow’: power series

For implicit methods, only the ‘det’ (determinant) formula is supported. If mode=’float’ is selected, the formulaautomatically switches to ‘det’.

The user can also select whether to compute the function based on Butcher or Shu-Osher coefficients by setting𝑢𝑠𝑒𝑏𝑢𝑡𝑐ℎ𝑒𝑟.

1.5. NodePy Manual 9

Page 14: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Output:

• p – Numpy poly representing the numerator

• q – Numpy poly representing the denominator

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> p,q = rk4.stability_function()>>> print(p)

4 3 20.04167 x + 0.1667 x + 0.5 x + 1 x + 1

>>> dc = rk.DC(3)>>> dc.stability_function(mode='exact')(poly1d([1/3888, 1/648, 1/24, 1/6, 1/2, 1, 1], dtype=object), poly1d([1], dtype=object))

>>> dc.stability_function(mode='float')(poly1d([ 2.57201646e-04, 1.54320988e-03, 4.16666667e-02,

1.66666667e-01, 5.00000000e-01, 1.00000000e+00,1.00000000e+00]), poly1d([ 1.]))

>>> ssp3 = rk.SSPIRK3(4)>>> ssp3.stability_function()(poly1d([-67/300 + 13*sqrt(15)/225, -sqrt(15)/25 + 1/6, -sqrt(15)/5 + 9/10,

-1 + 2*sqrt(15)/5, 1], dtype=object), poly1d([-2*sqrt(15)/25 + 31/100, -7/5 + 9*sqrt(15)/25, -3*sqrt(15)/5 + 12/5,-2 + 2*sqrt(15)/5, 1], dtype=object))

>>> ssp3.stability_function(mode='float')(poly1d([ 4.39037781e-04, 1.17473328e-02, 1.25403331e-01,

5.49193338e-01, 1.00000000e+00]), poly1d([ 1.61332303e-04, -5.72599537e-03, 7.62099923e-02,-4.50806662e-01, 1.00000000e+00]))

>>> ssp2 = rk.SSPIRK2(1)>>> ssp2.stability_function()(poly1d([1/2, 1], dtype=object), poly1d([-1/2, 1], dtype=object))

RungeKuttaMethod.plot_stability_region(N=200, color=’r’, filled=True, bounds=None,plotroots=False, alpha=1.0, scalefac=1.0,to_file=False, longtitle=True, fignum=None)

The region of absolute stability of a Runge-Kutta method, is the set

{𝑧 ∈ 𝐶 : |𝜑(𝑧)| ≤ 1}

where 𝜑(𝑧) is the stability function of the method.

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

Example::

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

10 Chapter 1. Overview

Page 15: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Nonlinear stability

RungeKuttaMethod.absolute_monotonicity_radius(acc=1e-10, rmax=200, tol=3e-16)Returns the radius of absolute monotonicity (also referred to as the radius of contractivity or the strong stabilitypreserving coefficient of a Runge-Kutta method.

RungeKuttaMethod.circle_contractivity_radius(acc=1e-13, rmax=1000)Returns the radius of circle contractivity of a Runge-Kutta method.

Example:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.circle_contractivity_radius()1.000...

Reducibility of Runge-Kutta methods

Two kinds of reducibility (DJ-reducibility and HS-reducibility) have been identified in the literature. NodePy containsfunctions for detecting both and transforming a reducible method to an equivalent irreducible method. Of course,reducibility is dealt with relative to some numerical tolerance, since the method coefficients are floating point numbers.

RungeKuttaMethod._dj_reducible_stages(tol=1e-13)Determine whether the method is DJ-reducible.

A method is DJ-reducible if it contains any stage that does not influence the output.

Returns a list of unnecessary stages. If the method is DJ-irreducible, returns an empty list.

This routine may not work correctly for RK pairs, as it doesn’t check bhat.

RungeKuttaMethod.dj_reduce(tol=1e-13)Remove all DJ-reducible stages.

A method is DJ-reducible if it contains any stage that does not influence the output.

Examples:

Construct a reducible method:>>> from nodepy import rk>>> A=np.array([[0,0],[1,0]])>>> b=np.array([1,0])>>> rkm = rk.ExplicitRungeKuttaMethod(A,b)

Check that it is reducible:>>> rkm._dj_reducible_stages()[1]

Reduce it:>>> print(rkm.dj_reduce())Runge-Kutta Method<BLANKLINE>0 |___|___

| 1

RungeKuttaMethod._hs_reducible_stages(tol=1e-13)Determine whether the method is HS-reducible. A Runge-Kutta method is HS-reducible if two rows of A areequal.

1.5. NodePy Manual 11

Page 16: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

If the method is HS-reducible, returns True and a pair of equal stages. If not, returns False and the minimumpairwise difference (in the maximum norm) between rows of A.

Examples:

Construct a reducible method:>>> from nodepy import rk>>> A=np.array([[1,0],[1,0]])>>> b=np.array([0.5,0.5])>>> rkm = rk.ExplicitRungeKuttaMethod(A,b)

Check that it is reducible:>>> rkm._hs_reducible_stages()(True, [0, 1])

Composing Runge-Kutta methods

Butcher has developed an elegant theory of the group structure of Runge-Kutta methods. The Runge-Kutta methodsform a group under the operation of composition. The multiplication operator has been overloaded so that multiplyingtwo Runge-Kutta methods gives the method corresponding to their composition, with equal timesteps.

It is also possible to compose methods with non-equal timesteps using the compose() function.

Embedded Runge-Kutta Pairs

class nodepy.runge_kutta_method.ExplicitRungeKuttaPair(A=None, b=None, bhat=None,alpha=None, beta=None, al-phahat=None, betahat=None,name=’Runge-Kutta Pair’,shortname=’RKM’, descrip-tion=’‘, order=(None, None))

Class for embedded Runge-Kutta pairs. These consist of two methods with identical coefficients 𝑎𝑖𝑗 but differentcoefficients 𝑏𝑗 such that the methods have different orders of accuracy. Typically the higher order accuratemethod is used to advance the solution, while the lower order method is used to obtain an error estimate.

An embedded Runge-Kutta Pair takes the form:

\begin{align*} y_i = & u^{n} + \Delta t \sum_{j=1}^{s} + a_{ij} f(y_j)) & (1\le j \le s) \\ u^{n+1} = & u^{n}+ \Delta t \sum_{j=1}^{s} b_j f(y_j) \\ \hat{u}^{n+1} = & u^{n} + \Delta t \sum_{j=1}^{s} \hat{b}_j f(y_j).\end{align*}

That is, both methods use the same intermediate stages 𝑦𝑖, but different weights. Typically the weightsℎ𝑎𝑡𝑏𝑗 are chosen so thatℎ𝑎𝑡𝑢𝑛+1 is accurate of order one less than the order of 𝑢𝑛+1. Then their difference can be used as an errorestimate.

The class also admits Shu-Osher representations:

\begin{align*} y_i = & v_i u^{n} + \sum_{j=1}^s \alpha_{ij} y_j + \Delta t \sum_{j=1}^{s} + \beta_{ij}f(y_j)) & (1\le j \le s+1) \\ u^{n+1} = & y_{s+1} \hat{u}^{n+1} = & \hat{v}_{s+1} u^{n} + \sum_{j=1}^s\hat{\alpha}_{s+1,j} + \Delta t \sum_{j=1}^{s} \hat{\beta}_{s+1,j} f(y_j). \end{align*}

In NodePy, if rkp is a Runge-Kutta pair, the principal (usually higher-order) method is the one used if accuracyor stability properties are queried. Properties of the embedded (usually lower-order) method can be accessed viarkp.embedded_method.

When solving an IVP with an embedded pair, one can specify a desired error tolerance. The step size will beadjusted automatically to achieve approximately this tolerance.

12 Chapter 1. Overview

Page 17: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

In addition to the ordinary Runge-Kutta initialization, here the embedded coefficients �̂�𝑗 are set as well.

Low-Storage Runge-Kutta methods

Typically, implementation of a Runge-Kutta method requires 𝑠×𝑁 memory locations, where 𝑠 is the number of stagesof the method and 𝑁 is the number of unknowns. Certain classes of Runge-Kutta methods can be implemented usingsubstantially less memory, by taking advantage of special relations among the coefficients. Three main classes havebeen developed in the literature:

• 2N (Williamson) methods

• 2R (van der Houwen/Wray) methods

• 2S methods

Each of these classes requires only 2×𝑁 memory locations. Additional methods have been developed that use morethan two memory locations per unknown but still provide a substantial savings over traditional methods. These arereferred to as, e.g., 3S, 3R, 4R, and so forth. For a review of low-storage methods, see [ketcheson2010] .

In NodePy, low-storage methods are a subclass of explicit Runge-Kutta methods (and/or explicit Runge-Kutta pairs).In addition to the usual properties, they possess arrays of low-storage coefficients. They override the generic RKimplementation of time-stepping and use special memory-efficient implementations instead. It should be noted that,although these low-storage algorithms are implemented, due to Python language restrictions an extra intermediatecopy of the solution array will be created. Thus the implementation in NodePy is not really minimum-storage.

At the moment, the following classes are implemented:

• 2S : Methods using two registers (under Ketcheson’s assumption)

• 2S* [Methods using two registers, one of which retains the previous] step solution

• 3S* [Methods using three registers, one of which retains the previous] step solution

• 2S embedded pairs

• 3S* embedded pairs

• 2R embedded pairs

• 3R embedded pairs

Examples:

>>> from nodepy import lsrk, ivp>>> myrk = lsrk.load_2R('DDAS47')>>> print(myrk)DDAS4()7[2R]2R Method of Tselios \& Simos (2007)0.000 |0.336 | 0.3360.286 | 0.094 0.1920.745 | 0.094 0.150 0.5010.639 | 0.094 0.150 0.285 0.1100.724 | 0.094 0.150 0.285 -0.122 0.3170.911 | 0.094 0.150 0.285 -0.122 0.061 0.444

_______|_________________________________________________| 0.094 0.150 0.285 -0.122 0.061 0.346 0.187

>>> rk58 = lsrk.load_2R('RK58[3R]C')>>> rk58.name'RK5(4)8[3R+]C'>>> rk58.order()

1.5. NodePy Manual 13

Page 18: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

5>>> problem = ivp.load_ivp('vdp')>>> t,u = rk58(problem)>>> u[-1]array([-1.40278844, 1.23080499])>>> import nodepy>>> rk2S = lsrk.load_LSRK("{}/method_coefficients/58-2S_acc.txt".format(nodepy.__path__[0]),has_emb=True)>>> rk2S.order()5>>> rk2S.embedded_method.order()4>>> rk3S = lsrk.load_LSRK(nodepy.__path__[0]+'/method_coefficients/58-3Sstar_acc.txt',lstype='3S*')>>> rk3S.principal_error_norm()0.00035742076...

2S/3S methods

class nodepy.low_storage_rk.TwoSRungeKuttaMethod(betavec, gamma, delta, lstype,name=’Low-storage Runge-KuttaMethod’, description=’‘, short-name=’LSRK2S’, order=None)

Class for low-storage Runge-Kutta methods that use Ketcheson’s assumption (2S, 2S*, and 3S* methods).

This class cannot be used for embedded pairs. Use the class TwoSRungeKuttaPair instead.

The low-storage coefficient arrays 𝑒𝑡𝑎, 𝛾, 𝛿 follow the notation of [ketcheson2010] .

The argument lstype must be one of the following values:

•2S

•2S*

•3S*

Initializes the low-storage method by storing the low-storage coefficients and computing the Butcher coeffi-cients.

2S/3S embedded pairs

class nodepy.low_storage_rk.TwoSRungeKuttaPair(betavec, gamma, delta, lstype, bhat=None,name=’Low-storage Runge-Kutta Pair’,description=’‘, shortname=’LSRK2S’,order=None)

Class for low-storage embedded Runge-Kutta pairs that use Ketcheson’s assumption (2S, 2S*, and 3S* meth-ods).

This class is only for embedded pairs. Use the class TwoSRungeKuttaMethod for single 2S/3S methods.

The low-storage coefficient arrays 𝑒𝑡𝑎, 𝛾, 𝛿 follow the notation of [ketcheson2010] .

The argument lstype must be one of the following values:

•2S

•2S*

•2S_pair

•3S*

14 Chapter 1. Overview

Page 19: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

•3S*_pair

The 2S/2S*/3S* classes do not need an extra register for the error estimate, while the 2S_pair/3S_pair methodsdo.

Initializes the low-storage pair by storing the low-storage coefficients and computing the Butcher coefficients.

2R/3R methods

class nodepy.low_storage_rk.TwoRRungeKuttaMethod(a, b, bhat=None, regs=2, name=‘2RRunge-Kutta Method’, description=’‘,shortname=’LSRK2R’, order=None)

Class for 2R/3R/4R low-storage Runge-Kutta pairs.

These were developed by van der Houwen, Wray, and Kennedy et. al. Only 2R and 3R methods have beenimplemented so far.

References:

• [kennedy2000]

• [ketcheson2010]

Initializes the 2R method by storing the low-storage coefficients and computing the Butcher array.

The coefficients should be specified as follows:

•For all methods, the weights 𝑏 are used to fill in the appropriate entries in 𝐴.

•For 2R methods, a is a vector of length 𝑠− 1 containing the first subdiagonal of 𝐴

•For 3R methods, a is a 2 × 𝑠 − 1 array whose first row contains the first subdiagonal of 𝐴 and whosesecond row contains the second subdiagonal of 𝐴.

Contents

• Linear Multistep methods– Instantiation

* Adams-Bashforth Methods* Adams-Moulton Methods* Backward-difference formulas* Optimal Explicit SSP methods

– Stability* Characteristic Polynomials* Plotting The Stability Region

Linear Multistep methods

A linear multistep method computes the next solution value from the values at several previous steps:

𝛼𝑘𝑦𝑛+𝑘 + 𝛼𝑘−1𝑦𝑛+𝑘−1 + ...+ 𝛼0𝑦𝑛 = ℎ(𝛽𝑘𝑓𝑛+𝑘 + ...+ 𝛽0𝑓𝑛)

Note that different conventions for numbering the coefficients exist; the above form is used in NodePy. Methods areautomatically normalized so that𝑎𝑙𝑝ℎ𝑎𝑘 = 1.

Examples:

1.5. NodePy Manual 15

Page 20: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> import nodepy.linear_multistep_method as lm>>> ab3=lm.Adams_Bashforth(3)>>> ab3.order()3>>> bdf2=lm.backward_difference_formula(2)>>> bdf2.order()2>>> bdf2.is_zero_stable()True>>> bdf7=lm.backward_difference_formula(7)>>> bdf7.is_zero_stable()False>>> bdf3=lm.backward_difference_formula(3)>>> bdf3.A_alpha_stability()86>>> ssp32=lm.elm_ssp2(3)>>> ssp32.order()2>>> ssp32.ssp_coefficient()1/2>>> ssp32.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

Instantiation

The follwing functions return linear multistep methods of some common types:

• Adams-Bashforth methods: Adams_Bashforth(k)

• Adams-Moulton methods: Adams_Moulton(k)

• backward_difference_formula(k)

• Optimal explicit SSP methods (elm_ssp2(k))

In each case, the argument 𝑘 specifies the number of steps in the method. Note that it is possible to generate methodsfor arbitrary 𝑘, but currently for large 𝑘 there are large errors in the coefficients due to roundoff errors. This begins tobe significant at 7 steps. However, members of these families with many steps do not have good properties.

More generally, a linear multistep method can be instantiated by specifying its coefficients𝑎𝑙𝑝ℎ𝑎,𝑏𝑒𝑡𝑎:

>> from nodepy import linear_multistep_method as lmm>> my_lmm=lmm.LinearMultistepMethod(alpha,beta)

Adams-Bashforth Methodslinear_multistep_method.Adams_Bashforth(k)

Construct the k-step, Adams-Bashforth method. The methods are explicit and have order k. They have the form:

𝑦𝑛+1 = 𝑦𝑛 + ℎ∑︀𝑘−1

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equations (1.5) and (1.7) from [hairer1993] III.1, along with the binomial expansion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> ab3=lm.Adams_Bashforth(3)

16 Chapter 1. Overview

Page 21: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> ab3.order()3

References:#. [hairer1993]_

Adams-Moulton Methodslinear_multistep_method.Adams_Moulton(k)

Construct the k-step, Adams-Moulton method. The methods are implicit and have order k+1. They have theform:

𝑦𝑛+1 = 𝑦𝑛 + ℎ∑︀𝑘

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equation (1.9) and the equation in Exercise 3 from Hairer & Wanner III.1, along withthe binomial expansion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> am3=lm.Adams_Moulton(3)>>> am3.order()4

References: [hairer1993]

Backward-difference formulaslinear_multistep_method.backward_difference_formula(k)

Construct the k-step backward differentiation method. The methods are implicit and have order k. They havethe form:∑︀𝑘

𝑗=0 𝛼𝑗𝑦𝑛+𝑘−𝑗+1 = ℎ𝛽𝑗𝑓(𝑦𝑛+1)

They are generated using equation (1.22’) from Hairer & Wanner III.1, along with the binomial expan-sion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> bdf4=lm.backward_difference_formula(4)>>> bdf4.A_alpha_stability()73

References: #.[hairer1993]_ pp. 364-365

Optimal Explicit SSP methodslinear_multistep_method.elm_ssp2(k)

Returns the optimal SSP k-step linear multistep method of order 2.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> lm10=lm.elm_ssp2(10)>>> lm10.ssp_coefficient()8/9

1.5. NodePy Manual 17

Page 22: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Stability

Characteristic PolynomialsLinearMultistepMethod.characteristic_polynomials()

Returns the characteristic polynomials (also known as generating polynomials) of a linear multistep method.They are:

𝜌(𝑧) =∑︀𝑘

𝑗=0 𝛼𝑘𝑧𝑘

𝜎(𝑧) =∑︀𝑘

𝑗=0 𝛽𝑘𝑧𝑘

Examples:

>>> from nodepy import lm>>> ab5 = lm.Adams_Bashforth(5)>>> rho,sigma = ab5.characteristic_polynomials()>>> print(rho)

5 41 x - 1 x

>>> print(sigma)4 3 2

2.64 x - 3.853 x + 3.633 x - 1.769 x + 0.3486

References:

1. [hairer1993] p. 370, eq. 2.4

Plotting The Stability RegionLinearMultistepMethod.plot_stability_region(N=100, bounds=None, color=’r’,

filled=True, alpha=1.0, to_file=False,longtitle=False)

The region of absolute stability of a linear multistep method is the set

{𝑧 ∈ 𝐶 : 𝜌(𝜁)− 𝑧𝜎(𝑧𝑒𝑡𝑎) satisfies the root condition}

where 𝜌(𝑧𝑒𝑡𝑎) and 𝜎(𝑧𝑒𝑡𝑎) are the characteristic functions of the method.

Also plots the boundary locus, which is given by the set of points z:

{𝑧|𝑧 = 𝜌(exp(𝑖𝜃))/𝜎(exp(𝑖𝜃)), 0 ≤ 𝜃 ≤ 2 * 𝜋}

Here 𝜌 and 𝜎 are the characteristic polynomials of the method.

References: [leveque2007] section 7.6.1

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

Two-step Runge-Kutta methods

Two-step Runge-Kutta methods are a class of multi-stage multistep methods that use two steps and (potentially) severalstages.

18 Chapter 1. Overview

Page 23: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

class nodepy.twostep_runge_kutta_method.TwoStepRungeKuttaMethod(d, theta, A, b,Ahat=None,bhat=None,type=’General’,name=’Two-stepRunge-KuttaMethod’)

General class for Two-step Runge-Kutta Methods The representation uses the form and partly the notation of[Jackiewicz1995], equation (1.3).

Initialize a 2-step Runge-Kutta method.

1.5.3 Testing Methods: Solving Initial Value Problems

In addition to directly analyzing solver properties, NodePy also facilitates the testing of solvers through applicationto problems of interest. Furthermore, NodePy includes routines for automatically running sets of tests to compare thepractical convergence or efficiency of various solvers for given problem(s).

Contents

• Testing Methods: Solving Initial Value Problems– Initial Value Problems

* Instantiation– Solving Initial Value Problems

* Convergence Testing* Performance testing with automatic step-size control

Initial Value Problems

The principal objects in NodePy are ODE solvers. The object upon which a solver acts is an initial value problem.Mathematically, an initial value problem (IVP) consists of one or more ordinary differential equations and an initialcondition:

\begin{align*} u’(t) & = F(u) & u(0) & = u_0. \end{align*}

In NodePy, an initial value problem is an object with the following properties:

• rhs(): The right-hand-side function; i.e. F where 𝑢(𝑡)′ = 𝐹 (𝑢).

• u0: The initial condition.

• T: The (default) final time of solution.

Optionally an IVP may possess the following:

• exact(): a function that takes one argument (t) and returns the exact solution (Should we make this afunction of u0 as well?)

• dt0: The default initial timestep when a variable step size integrator is used.

• Any other problem-specific parameters.

The module ivp contains functions for loading a variety of initial value problems. For instance, the van der Poloscillator problem can be loaded as follows:

1.5. NodePy Manual 19

Page 24: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>> from NodePy import ivp>> myivp = ivp.load_ivp('vdp')

Instantiation

ivp.detest(testkey)Load problems from the non-stiff DETEST problem set. The set consists of six groups of problems, as follows:

•A1-A5 – Scalar problems

•B1-B5 – Small systems (2-3 equations)

•C1-C5 – Moderate size systems (10-50 equations)

•D1-D5 – Orbit equations with varying eccentricities

•E1-E5 – Second order equations

•F1-F5 – Problems with discontinuities

•SB1-SB3 – Periodic Orbit problem from Shampine Baca paper pg.11,13

Note: Although this set of problems was not intended to become a standard, and although there are certaindangers in accepting any particular set of problems as a universal standard, it is nevertheless sometimes usefulto try a new method on this test set due to the availability of published results for many existing methods.

Reference: [enright1987]

Solving Initial Value Problems

Any ODE solver object in NodePy can be used to solve an initial value problem simply by calling the solver with aninitial value problem object as argument:

>> t,u = rk44(my_ivp)

ODESolver.__call__(ivp, t0=0, N=5000, dt=None, errtol=None, controllertype=’P’, x=None, diagnos-tics=False, use_butcher=False, max_steps=7500)

Calling an ODESolver numerically integrates the ODE u’(t) = f(t,u(t)) with initial value u(0)=u0 from time t0up to time T using the solver.

The timestep can be controlled in any of three ways:

1.By specifying N, the total number of steps to take. Then dt = (T-t0)/N.

2.By specifying dt directly.

3.For methods with an error estimate (e.g., RK pairs), by specifying an error tolerance. Then the step size isadjusted using a PI-controller to achieve the requested tolerance. In this case, dt should also be specifiedand determines the value of the initial timestep.

The argument x is used to pass any additional arguments required for the RHS function f.

Input:

• ivp – An IVP instance (the initial value problem to be solved)

• t0 – The initial time from which to integrate

• N – The # of steps to take (using a fixed step size)

20 Chapter 1. Overview

Page 25: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• dt – The step size to use

• errtol – The local error tolerance to be observed (using adaptive stepping). This requires that themethod have an error estimator, such as an embedded Runge-Kutta method.

• controllerType – The type of adaptive step size control to be used; available options are ‘P’ and ‘PI’.See [hairer1993b] for details.

• diagnostics – if True, return the number of rejected steps and a list of step sizes used, in addition tothe solution values and times.

Output:

• t – A list of solution times

• u – A list of solution values

If ivp.T is a scalar, the solution is integrated to that time and all output step values are returned. If ivp.T is alist/array, the solution is integrated to T[-1] and the solution is returned for the times specified in T.

TODO:

•Implement an option to not keep all output (for efficiency).

•Option to keep error estimate history

Convergence Testing

convergence.ctest(methods, ivp, grids=[20, 40, 80, 160, 320, 640], verbosity=0, parallel=False)Runs a convergence test, integrating a single initial value problem using a sequence of fixed step sizes and a setof methods. Creates a plot of the resulting errors versus step size for each method.

Inputs:

• methods – a list of ODEsolver instances

• ivp – an IVP instance

• grids – a list of grid sizes for integration. optional; defaults to [20,40,80,160,320,640]

• parallel – to exploit possible parallelization (optional)

Example:

>>> import nodepy.runge_kutta_method as rk>>> from nodepy.ivp import load_ivp>>> rk44=rk.loadRKM('RK44')>>> myivp=load_ivp('nlsin')>>> work, err=ctest(rk44,myivp)

TODO:

• Option to plot versus f-evals or dt

Performance testing with automatic step-size control

convergence.ptest(methods, ivps, tols=[0.1, 0.01, 0.0001, 1e-06], verbosity=0, parallel=False)Runs a performance test, integrating a set of problems with a set of methods using a sequence of error tolerances.Creates a plot of the error achieved versus the amount of work done (number of function evaluations) for eachmethod.

Input:

1.5. NodePy Manual 21

Page 26: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• methods – a list of ODEsolver instances Note that all methods must have error estimators.

• ivps – a list of IVP instances

• tols – a specified list of error tolerances (optional)

• parallel – to exploit possible parallelization (optional)

Example:

>>> import nodepy.runge_kutta_method as rk>>> from nodepy.ivp import load_ivp>>> bs5=rk.loadRKM('BS5')>>> myivp=load_ivp('nlsin')>>> work,err=ptest(bs5,myivp)

1.5.4 Analyzing Stability Properties

Plotting the region of absolute stability

Region of absolute stability for the optimal SSP 10-stage, 4th order Runge-Kutta method:

from nodepy.runge_kutta_method import *ssp104=loadRKM('SSP104')ssp104.plot_stability_region(bounds=[-15,1,-10,10])

14 12 10 8 6 4 2 010

5

0

5

10Absolute Stability Region for SSPRK(10,4)

22 Chapter 1. Overview

Page 27: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

RungeKuttaMethod.plot_stability_region(N=200, color=’r’, filled=True, bounds=None,plotroots=False, alpha=1.0, scalefac=1.0,to_file=False, longtitle=True, fignum=None)

The region of absolute stability of a Runge-Kutta method, is the set

{𝑧 ∈ 𝐶 : |𝜑(𝑧)| ≤ 1}

where 𝜑(𝑧) is the stability function of the method.

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

Example::

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

Region of absolute stability for the 3-step Adams-Moulton method:

from nodepy.linear_multistep_method import *am3=Adams_Moulton(3)am3.plot_stability_region()

1.5. NodePy Manual 23

Page 28: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

3 2 1 0

2

1

0

1

2

Stability region

LinearMultistepMethod.plot_stability_region(N=100, bounds=None, color=’r’,filled=True, alpha=1.0, to_file=False,longtitle=False)

The region of absolute stability of a linear multistep method is the set

{𝑧 ∈ 𝐶 : 𝜌(𝜁)− 𝑧𝜎(𝑧𝑒𝑡𝑎) satisfies the root condition}

where 𝜌(𝑧𝑒𝑡𝑎) and 𝜎(𝑧𝑒𝑡𝑎) are the characteristic functions of the method.

Also plots the boundary locus, which is given by the set of points z:

{𝑧|𝑧 = 𝜌(exp(𝑖𝜃))/𝜎(exp(𝑖𝜃)), 0 ≤ 𝜃 ≤ 2 * 𝜋}

Here 𝜌 and 𝜎 are the characteristic polynomials of the method.

References: [leveque2007] section 7.6.1

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

24 Chapter 1. Overview

Page 29: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Plotting the order star

Order star for the optimal SSP 10-stage, 4th order Runge-Kutta method:

from nodepy.runge_kutta_method import *ssp104=loadRKM('SSP104')ssp104.plot_order_star()

4 2 0 2 4

4

2

0

2

4

Order star for SSPRK(10,4)

RungeKuttaMethod.plot_stability_region(N=200, color=’r’, filled=True, bounds=None,plotroots=False, alpha=1.0, scalefac=1.0,to_file=False, longtitle=True, fignum=None)

The region of absolute stability of a Runge-Kutta method, is the set

{𝑧 ∈ 𝐶 : |𝜑(𝑧)| ≤ 1}

where 𝜑(𝑧) is the stability function of the method.

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

Example::

1.5. NodePy Manual 25

Page 30: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

1.5.5 Rooted Trees

class nodepy.rooted_trees.RootedTree(strg)A rooted tree is a directed acyclic graph with one node, which has no incoming edges, designated as the root.Rooted trees are useful for analyzing the order conditions of multistage numerical ODE solvers, such as Runge-Kutta methods and other general linear methods.

The trees are represented as strings, using one of the notations introduced by Butcher (the third column of Table300(I) of Butcher’s text). The character ‘T’ is used in place of $\tau$ to represent a vertex, and braces ‘{ }’ areused instead of brackets ‘[ ]’ to indicate that everything inside the braces is joined to a single parent node. Thusthe first four trees are:

‘T’, ‘{T}’, ‘{T^2}’, {{T}}’

These can be generated using the function list_trees(), which returns a list of all trees of a given order:

>>> from nodepy import *>>> for p in range(4): print(rt.list_trees(p))['']['T']

26 Chapter 1. Overview

Page 31: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

['{T}']['{{T}}', '{T^2}']

Note that the tree of order 0 is indicated by an empty string.

If the tree contains an edge from vertex A to vertex B, vertex B is said to be a child of vertex A. A vertex withno children is referred to as a leaf.

Warning: One important convention is assumed in the code; namely, that at each level, leaves are listedfirst (before any other subtrees), and if there are $n$ leaves, we write ‘T^n’.

Note: Currently, powers cannot be used for subtrees; thus

‘{{T}{T}}’

is valid, while

‘{{T}^2}’

is not. This restriction may be lifted in the future.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}{T}}')>>> tree.order()9>>> tree.density()144>>> tree.symmetry()2

Topologically equivalent trees are considered equal:

>>> tree2=RootedTree('{T^2{T}{T{T}}}')>>> tree2==treeTrue

We can generate Python code to evaluate the elementary weight corresponding to a given tree for a given classof methods:

>>> rk.elementary_weight_str(tree)'dot(b,dot(A,c)*dot(A,c*dot(A,c))*c**2)'

References:

1. [butcher2003]

2. [hairer1993]

TODO: - Check validity of strg more extensively

• Accept any leaf ordering, but convert it to our convention

• convention for ordering of subtrees?

1.5. NodePy Manual 27

Page 32: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Plotting trees

A single tree can be plotted using the plot method of the RootedTree class. For convenience, the methodplot_all_trees() plots the whole forest of rooted trees of a given order.

RootedTree.plot(nrows=1, ncols=1, iplot=1, ttitle=’‘)Plots the rooted tree.

INPUT: (optional)

• nrows, ncols – number of rows and columns of subplots in the figure

• iplot – index of the subplot in which to plot this tree

These are only necessary if plotting more than one tree in a single figure using subplot.

OUTPUT: None.

The plot is created recursively by plotting the root, parsing the subtrees, plotting the subtrees’ roots, and calling_plot_subtree on each child

from nodepy.rooted_trees import *tree=RootedTree('{T^2{T{T}}{T}}')tree.plot()

from nodepy.rooted_trees import *plot_all_trees(5)

28 Chapter 1. Overview

Page 33: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

{{T^3}} {{{T^2}}} {{{{T}}}}

{{T{T}}} {T{T^2}} {T{{T}}}

{T^2{T}} {{T}{T}} {T^4}

Functions on rooted trees

RootedTree.order()The order of a rooted tree, denoted $r(t)$, is the number of vertices in the tree.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.order()7

RootedTree.density()The density of a rooted tree, denoted by $\gamma(t)$, is the product of the orders of the subtrees.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.density()56

Reference:

•[butcher2003] p. 127, eq. 301(c)

1.5. NodePy Manual 29

Page 34: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

RootedTree.symmetry()The symmetry $\sigma(t)$ of a rooted tree is...

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.symmetry()2

Reference:

•[butcher2003] p. 127, eq. 301(b)

Computing products on trees

RootedTree.Gprod(alpha, beta, alphaargs=[], betaargs=[])Returns the product of two functions on a given tree.

INPUT:

alpha, beta – two functions on rooted trees that return symbolic or numeric values

alphaargs – a string containing any additional arguments that must be passed to function alpha

betaargs – a string containing any additional arguments that must be passed to function beta

OUTPUT: (alpha*beta)(self) i.e., the function that is the product (in G) of the functions alpha and beta. Notethat this product is not commutative.

The product is given by

$(\alpha*\beta)(‘’)=\beta(‘’)$

$(\alpha*\beta)(t) = \lambda(\alpha,t)(\beta) + \alpha(t)\beta(‘’)$

Note: Gprod can be used to compute products of more than two functions by passing Gprod itself in as beta,and providing the remaining functions to be multiplied as betaargs.

Examples:

>>> from nodepy import rt>>> tree = rt.RootedTree('{T{T}}')>>> tree.Gprod(rt.Emap,Dmap)1/2

Reference: [butcher2003] p. 276, Thm. 386A

RootedTree.lamda(alpha, extraargs=[])Computes Butcher’s functional lambda on a given tree for the function alpha. This is used to compute theproduct of two functions on trees.

INPUT:

•alpha – a function on rooted trees

•extraargs – a list containing any additional arguments that must be passed to alpha

OUTPUT:

• tprod – a list of trees [t1, t2, ...]

30 Chapter 1. Overview

Page 35: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• fprod – a list of numbers [a1, a2, ...]

The meaning of the output is that $\lambda(\alpha,t)(\beta)=a1*\beta(t1)+a2*\beta(t2)+...$

Examples:

>>> from nodepy import rt>>> tree = rt.RootedTree('{T{T}}')>>> tree.lamda(rt.Emap)(['T', '{T}', '{{T}}', '{T}', '{T^2}', '{T{T}}'], [1/2, 1, 1, 1/2, 1, 1])

Reference: [butcher2003] pp. 275-276

Using rooted trees to generate order conditions

1.5.6 What’s new in Version 0.6.1

Released May 14, 2015

• Two algorithms for computing optimal downwind perturbations of Runge-Kutta methods. One relies on CVXPYfor solving linear programs.

• The Numipedia project has been moved to its own repository: https://github.com/ketch/numipedia

• Many new doctests; >80% test coverage.

• Many improvements to the two-step RK module, including stability region plots for arbitrary methods.

• Three-step RK methods removed from master (because most of the module was not working).

• Pretty-printing of linear multistep methods.

• New methods: - Several very-high-order RK methods - Some singly diagonally-implicit RK methods - Nystromand Milne-Simpson families of multistep methods

• load_ivp() works similarly to load_RKM() (returns a dictionary).

• Improved computation of maximum linearly stable step sizes for semi-discretizations.

• Many bug fixes.

1.5.7 What’s new in Version 0.6

Version 0.6 is a relatively small update, which includes the following:

• Computation of optimal perturbations (splittings) of Runge-Kutta methods

• Additive linear multistep methods

• More accurate calculation of imaginary stability intervals

• Rational coefficients for more of the built-in RK methods

• Faster computation of stability polynomials

• More general deferred correction methods

• Fixed major bug in deferred correction method construction

• Continuous integration via Travis-CI

• Added information on citing nodepy

1.5. NodePy Manual 31

Page 36: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• Corrections to the documentation

• Updates for compatitibility with sympy 0.7.6

• Fixed bug involving non-existence of alphahat attribute

• minor bug fixes

1.5.8 What’s new in Version 0.5

Released: Nov. 4, 2013

Version 0.5 is a relatively small update, which includes the following:

• More Runge-Kutta methods available in rk.loadRKM(), including the 8(7) Prince-Dormand pair

• Lots of functionality and improvements for studying internal stability of RK methods

• Shu-Osher arrays used to construct an RK method are now stored and (by default) used for timestepping

• Ability to compute the effective order of a RK method

• More accurate computation of stability region intervals

• Use exact arithmetic (sympy) in many more functions

• Generation of Fortran code for order conditions

• Refactoring of how embedded Runge-Kutta pairs and low-storage methods are represented internally

• Plotting functions return a figure handle

• Better pretty-printing of RK methods with exact coefficients

• Updates for compatibility with sympy 0.7.3

• Improved reducibility for RK pairs

• More initial value problems

• Several bug fixes

• Automated testing with Travis

1.5.9 What’s new in Version 0.4

Released: Aug. 28, 2012

Version 0.4 of NodePy inclues numerous bug fixes and new features. The most significant new feature is the useof exact arithmetic for construction and analysis of many methods, using SymPy. Because exact arithmetic can beslow, NodePy automatically switches to floating point arithmetic for some operations, such as numerical integrationof initial value problems. If you find operations that seem excessively slow let me know. You can always revert tofloating-point representation of a method by using method.__num__().

Other new features and fixes include:

• Improvements to linear multistep methods:

– Stability region plotting

– Zero-stability

– 𝐴(𝛼)-stability angles

• Automatic selection of plotting region for stability region plots

32 Chapter 1. Overview

Page 37: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• Code base now hosted on Github (github.com/ketch/nodepy)

• Documentation corrections

• Use MathJax (instead of jsMath) in docs

• Much greater docstring coverage

• Many more examples in docs (can be run as doctests)

– For example, 95 doctests covering 25 items in runge_kutta_method.py

• Extrapolation methods based on GBS (midpoint method) – thanks to Umair bin Waheed

• Construction of simple linear finite difference matrices

• Analysis of the potential for parallelism in Runge-Kutta methods

– Number of sequentially-dependent stages

– Plotting of stage dependency graph

• Automatic reduction of reducible Runge-Kutta methods

• A heuristic method for possibly-optimal splittings of Runge-Kutta methods into upwind/downwind parts

• Fix bugs in computation of stability intervals

• Fix bugs in stability region plotting

• New examples in nodepy/examples/

• Spectral difference matrices for linear advection – thanks to Matteo Parsani

1.5.10 Planned Future Development

Development of NodePy is based on research needs. The following is a list of capabilities or features that wouldnaturally fit into the package but have not yet been implemented.

Multistep methods

• Time-stepping for multistep methods

• Selection of startup method

• Variable step size multistep methods

• Properties of particular multistep + startup method combinations

• Adaptive step size and order selection

Runge-Kutta Methods

• Time stepping for implicit methods

• Interpolants (dense output)

• Adaptive order (extrapolation and deferred correction)

1.5. NodePy Manual 33

Page 38: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

PDEs

Many common semi-discretizations of PDEs will be implemented as 𝑖𝑣𝑝 objects. Initially this will be imple-mented purely in Python and limited to simple 1D PDEs (e.g. advection, diffusion), since time-stepping for multi-dimensional or nonlinear PDEs will be too slow in Python. Eventually we plan to support wrapped Fortran and Csemi-discretizations.

Miscellaneous

• Additional classes of multi-stage, multistep methods.

• Analysis of geometric integrators.

• Partitioned rooted trees, additive and partitioned RK methods.

• Unit tests.

• An automatically-generated encyclopedia of solvers.

1.5.11 About NodePy

NodePy is an open-source, free project. If you find NodePy useful, please let me know via a short e-mail([email protected]).

NodePy is primarily developed by David Ketcheson. The following people have also contributed code to NodePy(listed in alphabetical order):

• Robert Bradshaw: initial implementation of exact representation and analysis of methods

• Matteo Parsani: spectral difference matrices

• Umair bin Waheed: Implementation of GBS extrapolation methods and their embedded pairs

Citing

If you use NodePy in work that is published, please cite

David I. Ketcheson, NodePy Software <version number>

Contributing

Contributions to the package are most welcome. If you have used NodePy for research, chances are that others wouldfind your code useful. Feel free to either e-mail a patch or fork and issue a pull request on Github.

License

NodePy is distributed under the terms of the modified Berkeley Software Distribution (BSD) license. The license is inthe file nodepy/LICENSE.txt and reprinted below.

See http://www.opensource.org/licenses/bsd-license.php for more details.

Copyright (c) 2008-2010 David I. Ketcheson. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that thefollowing conditions are met:

34 Chapter 1. Overview

Page 39: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• Redistributions of source code must retain the above copyright notice, this list of conditions and the followingdisclaimer.

• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the follow-ing disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANYEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIESOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENTSHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, IN-CIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITEDTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSI-NESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CON-TRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANYWAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAM-AGE.

Funding

NodePy development has been supported by:

• A U.S. Dept. of Energy Computational Science Graduate Fellowship

• Grants from King Abdullah University of Science & Technology

1.5.12 Bibliography

Books

Journal Articles

1.6 Modules Reference

1.6.1 runge_kutta_method

Examples:

>>> from nodepy.runge_kutta_method import *

• Load a method:

>>> ssp104=loadRKM('SSP104')

• Check its order of accuracy:

>>> ssp104.order()4

• Find its radius of absolute monotonicity:

>>> ssp104.absolute_monotonicity_radius()5.999999999949068

• Load a dictionary with many methods:

1.6. Modules Reference 35

Page 40: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> RK=loadRKM()>>> sorted(RK.keys())['BE', 'BS5', 'BuRK65', 'CMR6', 'DP5', 'FE', 'Fehlberg45', 'GL2', 'GL3', 'Heun33', 'Lambert65', 'LobattoIIIA2', 'LobattoIIIA3', 'LobattoIIIC2', 'LobattoIIIC3', 'LobattoIIIC4', 'MTE22', 'Merson43', 'Mid22', 'NSSP32', 'NSSP33', 'PD8', 'RK44', 'RadauIIA2', 'RadauIIA3', 'SDIRK23', 'SDIRK34', 'SDIRK54', 'SSP104', 'SSP22', 'SSP22star', 'SSP33', 'SSP53', 'SSP54', 'SSP63', 'SSP75', 'SSP85', 'SSP95']

>>> print(RK['Mid22'])Midpoint Runge-Kutta

0 |1/2 | 1/2_____|__________

| 0 1

• Many methods are naturally implemented in some Shu-Osher form different from the Butcher form:

>>> ssp42 = SSPRK2(4)>>> ssp42.print_shu_osher()SSPRK(4,2)

| |1/3 | 1 | 1/32/3 | 1 | 1/31 | 1 | 1/3_____|_____________________|_____________________

| 1/4 3/4 | 1/4

References:

1. [butcher2003]

2. [hairer1993]

class nodepy.runge_kutta_method.RungeKuttaMethod(A=None, b=None, alpha=None,beta=None, name=’Runge-KuttaMethod’, shortname=’RKM’, descrip-tion=’‘, mode=’exact’, order=None)

General class for implicit and explicit Runge-Kutta Methods. The method is defined by its Butcher array(𝐴, 𝑏, 𝑐). It is assumed everywhere that 𝑐𝑖 =

∑︀𝑗 𝐴𝑖𝑗 .

A Runge-Kutta Method is initialized by providing either:

1. Butcher arrays 𝐴 and 𝑏 with valid and consistent dimensions; or

2. Shu-Osher arrays 𝛼 and 𝛽 with valid and consistent dimensions

but not both.

The Butcher arrays are used as the primary representation of the method. If Shu-Osher arrays are providedinstead, the Butcher arrays are computed by shu_osher_to_butcher().

Initialize a Runge-Kutta method. For explicit methods, the class ExplicitRungeKuttaMethod should be usedinstead.

TODO: make A a property and update c when it is changed

Now that we store (alpha,beta) as auxiliary data, maybe it’s okay to specify both (𝐴, 𝑏) and (𝛼, 𝛽).

pOrder of the method. This can be imposed and cached, which is advantageous to avoid issues with roundofferror and slow computation of the order conditions.

latex()A laTeX representation of the Butcher arrays.

36 Chapter 1. Overview

Page 41: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

Example:

>>> from nodepy import rk>>> merson = rk.loadRKM('Merson43')>>> print(merson.latex())

Inconsistent literal block quoting.

begin{align} begin{array}{c|ccccc}

Unexpected indentation.

& & & & & \

Block quote ends without a blank line; unexpected unindent.

frac{1}{3} & frac{1}{3} & & & & \ frac{1}{3} & frac{1}{6} & frac{1}{6} & & & \ frac{1}{2} &frac{1}{8} & & frac{3}{8} & & \ 1 & frac{1}{2} & & - frac{3}{2} & 2 & \ hline

Unexpected indentation.

& frac{1}{6} & & & frac{2}{3} & frac{1}{6}\ & frac{1}{10} & & frac{3}{10} & frac{2}{5}& frac{1}{5}

Block quote ends without a blank line; unexpected unindent.

end{array} end{align}

print_shu_osher()Pretty-prints the Shu-Osher arrays in the form:

| |c | \alpha | \beta______________________

| amp1 | bmp1

where amp1, bmp1 represent the last rows of 𝛼, 𝛽.

dj_reduce(tol=1e-13)Remove all DJ-reducible stages.

A method is DJ-reducible if it contains any stage that does not influence the output.

Examples:

Construct a reducible method:>>> from nodepy import rk>>> A=np.array([[0,0],[1,0]])>>> b=np.array([1,0])>>> rkm = rk.ExplicitRungeKuttaMethod(A,b)

Check that it is reducible:>>> rkm._dj_reducible_stages()[1]

Reduce it:>>> print(rkm.dj_reduce())Runge-Kutta Method<BLANKLINE>0 |

___|___| 1

1.6. Modules Reference 37

Page 42: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

error_coefficient(tree, mode=’exact’)Returns the coefficient in the Runge-Kutta method’s error expansion multiplying a single elementary dif-ferential, corresponding to a given tree.

Examples:

Construct an RK method and some rooted trees:>>> from nodepy import rk, rt>>> rk4 = rk.loadRKM('RK44')>>> tree4 = rt.list_trees(4)[0]>>> tree5 = rt.list_trees(5)[0]

The method has order 4, so this gives zero:>>> rk4.error_coefficient(tree4)0

This is non-zero, as the method doesn'tsatisfy fifth-order conditions:>>> rk4.error_coefficient(tree5)-1/720

error_coeffs(p)Returns the coefficients in the Runge-Kutta method’s error expansion multiplying all elementary differen-tials of the given order.

error_metrics()Returns several measures of the accuracy of the Runge-Kutta method. In order, they are:

•𝐴𝑞+1: 2-norm of the vector of leading order error coefficients

•𝐴𝑞+1𝑚𝑎𝑥: Max-norm of the vector of leading order error coefficients

•𝐴𝑞+2 : 2-norm of the vector of next order error coefficients

•𝐴𝑞+2𝑚𝑎𝑥: Max-norm of the vector of next order error coefficients

•𝐷: The largest (in magnitude) coefficient in the Butcher array

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.error_metrics()(sqrt(1745)/2880, 1/120, sqrt(8531)/5760, 1/144, 1)

Reference: [kennedy2000]

principal_error_norm(tol=1e-13, mode=’float’)The 2-norm of the vector of leading order error coefficients.

order(tol=1e-14, mode=’float’, extremely_high_order=False)The order of a Runge-Kutta method.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.order()4

38 Chapter 1. Overview

Page 43: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> rk4.order(mode='exact')4

mode == ‘float’: (default) Check that conditions hold approximately, to within tolerance 𝑡𝑜𝑙. Appropri-ate when coefficients are floating-point, or for faster checking of high-order methods.

mode == ‘exact’: Check that conditions hold exactly. Appropriate when coefficients are specified asrational or algebraic numbers, but may be very slow for high order methods.

order_condition_residuals(p)Generates and evaluates code to test whether a method satisfies the order conditions of order p (only).

effective_order(tol=1e-14)Returns the effective order of a Runge-Kutta method. This may be higher than the classical order.

Example: >>> from nodepy import rk >>> RK4 = rk.loadRKM(‘RK44’) >>> RK4.effective_order() 4

effective_order_condition_residuals(q)Generates and evaluates code to test whether a method satisfies the effective order q conditions (only).

Similar to order_condition_residuals(self,p), but at the moment works only for q <= 4. (enough to findExplicit SSPRK)

stage_order(tol=1e-14)The stage order of a Runge-Kutta method is the minimum, over all stages, of the order of accuracy of thatstage. It can be shown to be equal to the largest integer k such that the simplifying assumptions 𝐵(𝑥𝑖) and 𝐶(𝑥𝑖) are satisfied for 1𝑙𝑒𝑥𝑖𝑙𝑒𝑘.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.stage_order()1>>> gl2 = rk.loadRKM('GL2')>>> gl2.stage_order()2

References:

1. Dekker and Verwer

2. [butcher2003]

stability_function_unexpanded()Compute the stability function expression but don’t simplify it. This can be useful for performance reasons.

Example:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.stability_function_unexpanded()z*(z/2 + 1)/3 + z*(z*(z/2 + 1)/2 + 1)/3 + z*(z*(z*(z/2 + 1)/2 + 1) + 1)/6 + z/6 + 1>>> rk4.stability_function_unexpanded().simplify()z**4/24 + z**3/6 + z**2/2 + z + 1

1.6. Modules Reference 39

Page 44: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

stability_function(stage=None, mode=’exact’, formula=’lts’, use_butcher=False)The stability function of a Runge-Kutta method is𝑝ℎ𝑖(𝑧) = 𝑝(𝑧)/𝑞(𝑧), where

$$p(z)=\det(I - z A + z e b^T)$$

$$q(z)=\det(I - z A)$$

The function can also be computed via the formula

$$‘\phi(z) = 1 + b^T (I-zA)^{-1} e$$

where 𝑒 is a column vector with all entries equal to one.

This function constructs the numerator and denominator of the stability function of a Runge-Kutta method.

For methods with rational coefficients, mode=’exact’ computes the stability function using rational arith-metic. Alternatively, you can set mode=’float’ to force computation using floating point, in case the exactcomputation is too slow.

For explicit methods, the denominator is simply 1 and there are three options for computing the numerator(this is the ‘formula’ option). These only affect the speed, and only matter if the computation is symbolic.They are:

•‘lts’: SymPy’s lower_triangular_solve

•‘det’: ratio of determinants

•‘pow’: power series

For implicit methods, only the ‘det’ (determinant) formula is supported. If mode=’float’ is selected, theformula automatically switches to ‘det’.

The user can also select whether to compute the function based on Butcher or Shu-Osher coefficients bysetting 𝑢𝑠𝑒𝑏𝑢𝑡𝑐ℎ𝑒𝑟.

Output:

• p – Numpy poly representing the numerator

• q – Numpy poly representing the denominator

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> p,q = rk4.stability_function()>>> print(p)

4 3 20.04167 x + 0.1667 x + 0.5 x + 1 x + 1

>>> dc = rk.DC(3)>>> dc.stability_function(mode='exact')(poly1d([1/3888, 1/648, 1/24, 1/6, 1/2, 1, 1], dtype=object), poly1d([1], dtype=object))

>>> dc.stability_function(mode='float')(poly1d([ 2.57201646e-04, 1.54320988e-03, 4.16666667e-02,

1.66666667e-01, 5.00000000e-01, 1.00000000e+00,1.00000000e+00]), poly1d([ 1.]))

>>> ssp3 = rk.SSPIRK3(4)>>> ssp3.stability_function()(poly1d([-67/300 + 13*sqrt(15)/225, -sqrt(15)/25 + 1/6, -sqrt(15)/5 + 9/10,

-1 + 2*sqrt(15)/5, 1], dtype=object), poly1d([-2*sqrt(15)/25 + 31/100, -7/5 + 9*sqrt(15)/25, -3*sqrt(15)/5 + 12/5,-2 + 2*sqrt(15)/5, 1], dtype=object))

40 Chapter 1. Overview

Page 45: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> ssp3.stability_function(mode='float')(poly1d([ 4.39037781e-04, 1.17473328e-02, 1.25403331e-01,

5.49193338e-01, 1.00000000e+00]), poly1d([ 1.61332303e-04, -5.72599537e-03, 7.62099923e-02,-4.50806662e-01, 1.00000000e+00]))

>>> ssp2 = rk.SSPIRK2(1)>>> ssp2.stability_function()(poly1d([1/2, 1], dtype=object), poly1d([-1/2, 1], dtype=object))

plot_stability_function(bounds=[-20, 1])Plot the value of the stability function along the negative real axis.

Example:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_stability_function()

plot_stability_region(N=200, color=’r’, filled=True, bounds=None, plotroots=False, al-pha=1.0, scalefac=1.0, to_file=False, longtitle=True, fignum=None)

The region of absolute stability of a Runge-Kutta method, is the set

{𝑧 ∈ 𝐶 : |𝜑(𝑧)| ≤ 1}

where 𝜑(𝑧) is the stability function of the method.

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

Example::

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

plot_order_star(N=200, bounds=[-5, 5, -5, 5], plotroots=False, color=(‘w’, ‘b’), filled=True,fignum=None)

The order star of a Runge-Kutta method is the set

$$ \{ z \in C : | \phi(z)/\exp(z) | \le 1 \} $$

where 𝜑(𝑧) is the stability function of the method.

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, order star is filled in (solid); otherwise it is outlined

Example::

1.6. Modules Reference 41

Page 46: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.plot_order_star()<matplotlib.figure.Figure object at 0x...>

circle_contractivity_radius(acc=1e-13, rmax=1000)Returns the radius of circle contractivity of a Runge-Kutta method.

Example:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.circle_contractivity_radius()1.000...

absolute_monotonicity_radius(acc=1e-10, rmax=200, tol=3e-16)Returns the radius of absolute monotonicity (also referred to as the radius of contractivity or the strongstability preserving coefficient of a Runge-Kutta method.

linear_monotonicity_radius(acc=1e-10, tol=1e-15, tol2=1e-08)Computes Horvath’s monotonicity radius of the stability function.

TODO: clean this up.

optimal_shu_osher_form()Gives a Shu-Osher form in which the SSP coefficient is evident (i.e., in which𝑎𝑙𝑝ℎ𝑎𝑖𝑗 ,𝑏𝑒𝑡𝑎𝑖𝑗𝑔𝑒0 and𝑎𝑙𝑝ℎ𝑎𝑖𝑗/𝑏𝑒𝑡𝑎𝑖𝑗 = 𝑐 for every𝑏𝑒𝑡𝑎𝑖𝑗𝑛𝑒0).

Input:

• A RungeKuttaMethod

Output:

• alpha, beta – Shu-Osher arrays

The ‘optimal’ Shu-Osher arrays are given by

$$\alpha= K(I+cA)^{-1}$$ $$\beta = c \alpha$$

where K=[ A b^T].

Example:

>>> from nodepy import rk>>> rk2 = rk.loadRKM('MTE22')>>> rk2.optimal_shu_osher_form()(array([[0, 0, 0],

[1.00000000000000, 0, 0],[0.625000000060027, 0.374999999939973, 0]], dtype=object), array([[0, 0, 0],[0.666666666666667, 0, 0],[4.00177668780088e-11, 0.750000000000000, 0]], dtype=object))

References:

1. [higueras2005]

42 Chapter 1. Overview

Page 47: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

canonical_shu_osher_form(r)Returns d,P where P is the matrix 𝑃 = 𝑟(𝐼 + 𝑟𝐾)−1𝐾 and d is the vector 𝑑 = (𝐼 + 𝑟𝐾)−1𝑒 = (𝐼 −𝑃 )𝑒.

Note that this can be computed for any value of 𝑟, including values for which 𝑑, 𝑃 may have negativeentries.

lp_perturb(r, tol=None)Find a perturbation via linear programming.

Use linear programming to determine if there exists a perturbation of this method with radius of absolutemonotonicity at least 𝑟.

The linear program to be solved is begin{align}

Unexpected indentation.

(I-2alpha^{down}_r)alpha_r + alpha^{down}_r & = (alpha^{up}_r ) ge 0 \ (I-2alpha^{down}_r)v_r & = gamma_r ge 0.

Block quote ends without a blank line; unexpected unindent.

end{align}

This function requires cvxpy.

ssplit(r, P_signs=None, delta=None)Sympy exact version of split()

If P_signs is passed, use that as the sign pattern of the P matrix. This is useful if r is symbolic (since thenin general the signs of elemnts of P are unknown).

resplit(r, tol=1e-15, max_iter=5)

is_splittable(r, tol=1e-15)

optimal_perturbed_splitting(acc=1e-12, rmax=50.01, tol=1e-13, algorithm=’split’)Return the optimal downwind splitting of the method along with the optimal downwind SSP coefficient.

The default algorithm (split with iteration) is not provably correct. The LP algorithm is. See the paper(Higueras & Ketcheson) for more details.

Example:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> r, d, alpha, alphatilde = rk4.optimal_perturbed_splitting(algorithm='split')>>> print(r)0.68501606...

propagation_matrix(L, dt)Returns the solution propagation matrix for the linear autonomous system with RHS equal to the matrixL, i.e. it returns the matrix G such that when the Runge-Kutta method is applied to the system 𝑢′(𝑡) = 𝐿𝑢with stepsize dt, the numerical solution is given by 𝑢𝑛+1 = 𝐺𝑢𝑛.

Input:

• self – a Runge-Kutta method

• L – the RHS of the ODE system

• dt – the timestep

1.6. Modules Reference 43

Page 48: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

The formula for 𝐺 is (if 𝐿 is a scalar): 𝐺 = 1 + 𝑏𝑇𝐿(𝐼 −𝐴𝐿)−1𝑒

where 𝐴 and 𝑏 are the Butcher arrays and 𝑒 is the vector of ones. If 𝐿 is a matrix, all quantities above arereplaced by their Kronecker product with the identity matrix of size 𝑚, where 𝑚 is the number of stagesof the Runge-Kutta method.

is_explicit()

is_zero_stable()

is_FSAL()True if method is “First Same As Last”.

nodepy.runge_kutta_method.sign_split(M)Given a matrix M, return two matrices. The first contains the positive entries of M; the second contains thenegative entries of M, multiplied by -1.

nodepy.runge_kutta_method.redistribute_gamma(gamma, alpha_up, alpha_down)

class nodepy.runge_kutta_method.ExplicitRungeKuttaMethod(A=None, b=None, al-pha=None, beta=None,name=’Runge-KuttaMethod’, short-name=’RKM’, descrip-tion=’‘, mode=’exact’,order=None)

Class for explicit Runge-Kutta methods. Mostly identical to RungeKuttaMethod, but also includes time-steppingand a few other functions.

Initialize a Runge-Kutta method. For explicit methods, the class ExplicitRungeKuttaMethod should be usedinstead.

TODO: make A a property and update c when it is changed

Now that we store (alpha,beta) as auxiliary data, maybe it’s okay to specify both (𝐴, 𝑏) and (𝛼, 𝛽).

imaginary_stability_interval(mode=’exact’, eps=1e-14)Length of imaginary axis half-interval contained in the method’s region of absolute stability.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.imaginary_stability_interval()2.8284271247461...

real_stability_interval(mode=’exact’, eps=1e-14)Length of negative real axis interval contained in the method’s region of absolute stability.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> I = rk4.real_stability_interval()>>> print("{:.10f}".format(I))2.7852935634

linear_absolute_monotonicity_radius(acc=1e-10, rmax=50, tol=3e-16)Returns the radius of absolute monotonicity of the stability function of a Runge-Kutta method.

TODO: implement this functionality for implicit methods.

is_explicit()

44 Chapter 1. Overview

Page 49: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

work_per_step()Number of function evaluations required for one step.

num_seq_dep_stages()Number of sequentially dependent stages.

Number of sequential function evaluations that must be made.

Examples:

Extrapolation methods are parallelizable:>>> from nodepy import rk>>> ex4 = rk.extrap(4)>>> len(ex4)7>>> ex4.num_seq_dep_stages()4

So are deferred correction methods:>>> dc4 = rk.DC(4)>>> len(dc4)17>>> dc4.num_seq_dep_stages()8

Unless `\theta` is non-zero:>>> rk.DC(4,theta=1).num_seq_dep_stages()20

internal_stability_polynomials(stage=None, mode=’exact’, formula=’lts’,use_butcher=False)

The internal stability polynomials of a Runge-Kutta method depend on the implementation and must there-fore be constructed base on the Shu-Osher form used for the implementation. By default the Shu-Oshercoefficients are used. The Butcher coefficients are used if use_butcher=True or if Shu-Osher coefficientsare not defined.

The formula for the polynomials is: Modified Shu-Osher form: (𝑎𝑙𝑝ℎ𝑎𝑠𝑡𝑎𝑟𝑚𝑝1 + 𝑧𝑏𝑒𝑡𝑎𝑠𝑡𝑎𝑟𝑚𝑝1)(𝐼 −𝑎𝑙𝑝ℎ𝑎𝑠𝑡𝑎𝑟 − 𝑧𝑏𝑒𝑡𝑎𝑠𝑡𝑎𝑟)−1 Butcher array: 𝑧𝑏𝑇 (𝐼 − 𝑧𝐴)−1

Note that in the first stage no perturbation is introduced because for an explicit method the first stage isequal to the solution at the current time level. Therefore, the first internal polynomial is set to zero.

For symbolic computation, this routine has been significantly modified for efficiency relative toparticular classes of methods. Two formulas are implemented, one based on SymPy’s Ma-trix.lower_triangular_solve() and the other using a power series for the inverse. Different choices of thesetwo are more efficient for different classes of methods (this only matters for methods with very manystages).

Options

• use_butcher

Output:

• numpy array of internal stability polynomials

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> theta = rk4.internal_stability_polynomials()>>> for p in theta:

1.6. Modules Reference 45

Page 50: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

... print(p)3 2

0.08333 x + 0.1667 x + 0.3333 x2

0.1667 x + 0.3333 x

0.1667 x

internal_stability_plot(bounds=None, N=200, use_butcher=False, formula=’lts’, levels=[1,100, 500, 1000, 1500, 10000])

Plot internal stability regions.

Plots the $epsilon$-internal-stability region contours.

By default the Shu-Osher coefficients are used. The Butcher coefficients are used if use_butcher=True orif Shu-Osher coefficients are not defined.

Examples:

>>> from nodepy import rk>>> rk4 = rk.loadRKM('RK44')>>> rk4.internal_stability_plot()

maximum_internal_amplification(N=200, use_butcher=False, formula=’lts’)The maximum amount by which any stage error is amplified, assuming the step size is taken so that themethod is absolutely stable:

max𝑧∈𝑆,𝑗 |𝜃𝑗(𝑧)|

where 𝑆 = {𝑧 ∈ 𝐶 : |𝑅(𝑧)| ≤ 1.

Here 𝑅(𝑧) is the stability function and 𝜃𝑗(𝑧) are the internal stability functions.

By default the Shu-Osher coefficients are used. The Butcher coefficients are used if use_butcher=True orif Shu-Osher coefficients are not defined.

Examples:

>>> from nodepy import rk>>> ssp2 = rk.SSPRK2(6)>>> ssp2.maximum_internal_amplification()(1.0974050096180772, 0.83333333333333337)>>> ssp2.maximum_internal_amplification(use_butcher=True)(2.0370511185806568, 0.0)

class nodepy.runge_kutta_method.ContinuousRungeKuttaMethod(A=None, b=None, al-pha=None, beta=None,b_dense=None,name=’ContinuousRunge-Kutta Method’,shortname=’CRKM’,description=’‘,mode=’exact’, or-der=None)

46 Chapter 1. Overview

Page 51: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

class nodepy.runge_kutta_method.ContinuousExplicitRungeKuttaMethod(A=None,b=None,alpha=None,beta=None,b_dense=None,name=’ContinuousRunge-KuttaMethod’,short-name=’CRKM’,descrip-tion=’‘,mode=’exact’,order=None)

class nodepy.runge_kutta_method.ExplicitRungeKuttaPair(A=None, b=None, bhat=None,alpha=None, beta=None, al-phahat=None, betahat=None,name=’Runge-Kutta Pair’,shortname=’RKM’, descrip-tion=’‘, order=(None, None))

Class for embedded Runge-Kutta pairs. These consist of two methods with identical coefficients 𝑎𝑖𝑗 but differentcoefficients 𝑏𝑗 such that the methods have different orders of accuracy. Typically the higher order accuratemethod is used to advance the solution, while the lower order method is used to obtain an error estimate.

An embedded Runge-Kutta Pair takes the form:

\begin{align*} y_i = & u^{n} + \Delta t \sum_{j=1}^{s} + a_{ij} f(y_j)) & (1\le j \le s) \\ u^{n+1} = & u^{n}+ \Delta t \sum_{j=1}^{s} b_j f(y_j) \\ \hat{u}^{n+1} = & u^{n} + \Delta t \sum_{j=1}^{s} \hat{b}_j f(y_j).\end{align*}

That is, both methods use the same intermediate stages 𝑦𝑖, but different weights. Typically the weightsℎ𝑎𝑡𝑏𝑗 are chosen so thatℎ𝑎𝑡𝑢𝑛+1 is accurate of order one less than the order of 𝑢𝑛+1. Then their difference can be used as an errorestimate.

The class also admits Shu-Osher representations:

\begin{align*} y_i = & v_i u^{n} + \sum_{j=1}^s \alpha_{ij} y_j + \Delta t \sum_{j=1}^{s} + \beta_{ij}f(y_j)) & (1\le j \le s+1) \\ u^{n+1} = & y_{s+1} \hat{u}^{n+1} = & \hat{v}_{s+1} u^{n} + \sum_{j=1}^s\hat{\alpha}_{s+1,j} + \Delta t \sum_{j=1}^{s} \hat{\beta}_{s+1,j} f(y_j). \end{align*}

In NodePy, if rkp is a Runge-Kutta pair, the principal (usually higher-order) method is the one used if accuracyor stability properties are queried. Properties of the embedded (usually lower-order) method can be accessed viarkp.embedded_method.

When solving an IVP with an embedded pair, one can specify a desired error tolerance. The step size will beadjusted automatically to achieve approximately this tolerance.

In addition to the ordinary Runge-Kutta initialization, here the embedded coefficients �̂�𝑗 are set as well.

main_methodReturn the main method of the pair (usually the higher-order one).

embedded_methodAlways recompute the embedded method on the fly. This may be inefficient.

error_metrics(q=None, p=None)Return full set of error metrics for an embedded RK pair. See [kennedy2000] p. 181

Example:

1.6. Modules Reference 47

Page 52: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rk>>> bs5 = rk.loadRKM('BS5')>>> bs5.error_metrics()main method has order 5embedded method has order 4(43*sqrt(83011)/558835200, 43/3386880, sqrt(29695176594765489880490334265)/810521680634265600, 1451/15966720, sqrt(870269901055795)/277898765760, 10147/131580855, sqrt(51577359825120524319571156056057595)/219308015066060340, 26201089/40912704, sqrt(5250600078722255566247933273951710555)/2193080150660603400, 305343067/400035328, 482048/414219, 5987277*sqrt(72241974756542598745)/243675572295622600, 5987277/36366848)

is_FSAL()

plot_stability_region(N=200, color=’r’, filled=True, bounds=None, plotroots=False, al-pha=1.0, scalefac=1.0, to_file=False, longtitle=True, fignum=None)

Plot the absolute stability region of an RK pair. By default, the region of the main method is filled in redand the region of the embedded method is outlined in black.

Example:

>>> from nodepy import rk>>> bs5 = rk.loadRKM('BS5')>>> bs5.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

nodepy.runge_kutta_method.elementary_weight(tree)Constructs Butcher’s elementary weights for a Runge-Kutta method

Currently doesn’t work right; note that two of the 5th-order weights appear identical. The _str version belowworks correctly and produces NumPy code. But it would be nice to have this version working so that we couldsymbolically simplify the expressions.

In order to do things correctly, we need a symbolic system that includes support for either:

•Two different types of multiplication; or

•Full tensor expressions

The latter is now available in Sympy, and I’ve started a test implementation. The main issue now is that thingslike

AxA**2

don’t get parentheses when they really mean

(AxA)**2.

It’s not really a bug since Ax(A**2) does show parentheses, but it will make it harder to parse into code.

Examples:

>>> from nodepy import rk, rt>>> tree = rt.list_trees(2)[0]>>> tree'{T}'>>> rk.elementary_weight(tree)b*c

References: [butcher2003]

nodepy.runge_kutta_method.elementary_weight_str(tree, style=’python’)Constructs Butcher’s elementary weights for a Runge-Kutta method as strings suitable for numpy execution.

Examples:

48 Chapter 1. Overview

Page 53: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rk, rt>>> tree = rt.list_trees(5)[0]>>> rk.elementary_weight_str(tree)'dot(b,dot(A,c**3))'

>>> rk.elementary_weight_str(tree,style='matlab')"b'*((A*c.^3))">>> rk.elementary_weight_str(rt.RootedTree('{T^10}'))'dot(b,c**10)'>>> rk.elementary_weight_str(rt.RootedTree('{{T^11}T}'))'dot(b,dot(A,c**11))'

nodepy.runge_kutta_method.RKeta(tree)

nodepy.runge_kutta_method.RKeta_str(tree)Computes eta(t) for Runge-Kutta methods

nodepy.runge_kutta_method.discrete_adjoint(meth)Returns the discrete adjoint of a Runge-Kutta method

nodepy.runge_kutta_method.is_absolutely_monotonic_poly(r, tol, p)Returns 1 if the polynomial p is absolutely monotonic at z=-r.

nodepy.runge_kutta_method.shu_osher_change_alpha_ij(alpha, beta, i, j, val)

Input:

• alpha, beta: Shu-Osher arrays

• i,j: indices

• val – real number

Output: Shu-Osher arrays alph, bet with alph[i,j]=alpha[i,j]+val.

nodepy.runge_kutta_method.shu_osher_zero_alpha_ij(alpha, beta, i, j)

Input: Shu-Osher arrays alpha, beta indices i,j

Output: Shu-Osher arrays alph, bet with alph[i,j]=0.

nodepy.runge_kutta_method.shu_osher_zero_beta_ij(alpha, beta, i, j)

Input:

• Shu-Osher arrays alpha, beta

• indices i,j

Output:

• Shu-Osher arrays alph, bet with bet[i,j]=0.

nodepy.runge_kutta_method.shu_osher_to_butcher(alpha, beta)Accepts a Shu-Osher representation of an explicit Runge-Kutta and returns the Butcher coefficients

\begin{align*} A = & (I-\alpha_0)^{-1} \beta_0 \\ b = & \beta_1 + \alpha_1 \end{align*}

References:

1. [gottlieb2009]

nodepy.runge_kutta_method.loadRKM(which=’All’)Load a set of standard Runge-Kutta methods for testing. The following methods are included:

Explicit:

1.6. Modules Reference 49

Page 54: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

‘FE’: Forward Euler ‘RK44’: Classical 4-stage 4th-order ‘Merson43’ Merson 4(3) pair from Hairer and Wannerbook pg. 167 ‘MTE22’: Minimal truncation error 2-stage 2nd-order ‘Heun33’: Third-order method of Heun‘SSP22’: Trapezoidal rule 2nd-order ‘DP5’: Dormand-Prince 5th-order ‘CMR6’: Calvo et al.’s 6(5) method‘PD8’: Prince-Dormand 8th-order and 7th-order pair ‘Fehlberg45’: 5th-order part of Fehlberg’s pair ‘Lam-bert65’:

Implicit:

‘BE’: Backward Euler ‘GL2’: 2-stage Gauss-Legendre ‘GL3’: 3-stage Gauss-Legendre

Also various Lobatto and Radau methods.

nodepy.runge_kutta_method.RK22_family(gamma)Construct a 2-stage second order Runge-Kutta method

Input: gamma – family parameter Output: An ExplicitRungeKuttaMethod Examples:

>>> from nodepy import rk>>> print(rk.RK22_family(-1))Runge-Kutta Method

0 |-1/2 | -1/2______|____________

| 2 -1

nodepy.runge_kutta_method.RK44_family(w)Construct a 4-stage fourth order Runge-Kutta method

Input: w – family parameter Output: An ExplicitRungeKuttaMethod

Examples:

>>> from nodepy import rk>>> print(rk.RK44_family(1))Runge-Kutta Method

0 |1/2 | 1/21/2 | 1/3 1/61 | -2 3______|________________________

| 1/6 -1/3 1 1/6

nodepy.runge_kutta_method.SSPRK2(m)Construct the optimal m-stage, second order SSP Explicit Runge-Kutta method (m>=2).

Input: m – number of stages Output: A ExplicitRungeKuttaMethod

Examples:

Load the 4-stage method:>>> SSP42=SSPRK2(4)>>> print(SSP42)SSPRK(4,2)<BLANKLINE>0 |1/3 | 1/32/3 | 1/3 1/31 | 1/3 1/3 1/3_____|____________________

| 1/4 1/4 1/4 1/4

50 Chapter 1. Overview

Page 55: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> SSP42.absolute_monotonicity_radius()2.999999999974534

References:

1. [ketcheson2008]

nodepy.runge_kutta_method.SSPRK3(m)Construct the optimal m-stage third order SSP Runge-Kutta method (m=n**2, n>=2)

Input: m – number of stages Output: A RungeKuttaMethod

Examples:

Load the 4-stage method:>>> SSP43=SSPRK3(4)>>> print(SSP43)SSPRK43<BLANKLINE>0 |1/2 | 1/21 | 1/2 1/21/2 | 1/6 1/6 1/6_____|____________________

| 1/6 1/6 1/6 1/2

>>> SSP43.absolute_monotonicity_radius()1.9999999999527063

References:

1. [ketcheson2008]

nodepy.runge_kutta_method.SSPRKm(m)Construct the optimal m-stage, linearly mth order SSP Explicit Runge-Kutta method (m>=2).

Input: m – number of stages Output: A ExplicitRungeKuttaMethod

Examples:

Load the 4-stage method:>>> SSP44=SSPRKm(4)>>> print(SSP44)SSPRK44<BLANKLINE>0 |1 | 12 | 1 13 | 1 1 1______|________________________

| 5/8 7/24 1/24 1/24

>>> SSP44.absolute_monotonicity_radius()0.9999999999308784

References:

1. [gottlieb2001]

1.6. Modules Reference 51

Page 56: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.runge_kutta_method.SSPIRK1(m)Construct the m-stage, first order unconditionally SSP Implicit Runge-Kutta method with smallest coefficient ofz^2 (in the stability polynomial)

Input: m – number of stages Output: A RungeKuttaMethod

Examples:

Load the 4-stage method:>>> ISSP41=SSPIRK1(4)>>> print(ISSP41)SSPIRK41<BLANKLINE>1/4 | 1/41/2 | 1/4 1/43/4 | 1/4 1/4 1/41 | 1/4 1/4 1/4 1/4_____|____________________

| 1/4 1/4 1/4 1/4

nodepy.runge_kutta_method.SSPIRK2(m)Construct the optimal m-stage, second order SSP Implicit Runge-Kutta method (m>=2).

Input: m – number of stages Output: A RungeKuttaMethod

Examples:

Load the 4-stage method:>>> ISSP42=SSPIRK2(4)>>> print(ISSP42)SSPIRK42<BLANKLINE>1/8 | 1/83/8 | 1/4 1/85/8 | 1/4 1/4 1/87/8 | 1/4 1/4 1/4 1/8_____|____________________

| 1/4 1/4 1/4 1/4

>>> ISSP42.absolute_monotonicity_radius()7.999999999992724

References:

1. [ketcheson2009]

nodepy.runge_kutta_method.SSPIRK3(m)Construct the optimal m-stage, third order SSP Implicit Runge-Kutta method (m>=2).

Input: m – number of stages Output: A RungeKuttaMethod

Examples:

Load the 4-stage method:>>> ISSP43=SSPIRK3(4)>>> print(ISSP43)SSPIRK43<BLANKLINE>-sqrt(15)/10 + 1/2 | -sqrt(15)/10 + 1/2-sqrt(15)/30 + 1/2 | sqrt(15)/15 -sqrt(15)/10 + 1/2sqrt(15)/30 + 1/2 | sqrt(15)/15 sqrt(15)/15 -sqrt(15)/10 + 1/2

52 Chapter 1. Overview

Page 57: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

sqrt(15)/10 + 1/2 | sqrt(15)/15 sqrt(15)/15 sqrt(15)/15 -sqrt(15)/10 + 1/2____________________|________________________________________________________________________________

| 1/4 1/4 1/4 1/4

>>> x=ISSP43.absolute_monotonicity_radius()>>> print("{:.5f}".format(x))6.87298

References:

1. [ketcheson2009]

nodepy.runge_kutta_method.RKC1(m, epsilon=0)Construct the m-stage, first order explicit Runge-Kutta-Chebyshev methods of Verwer (m>=1).

‘epsilon’ is a damping parameter used to avoid tangency of the stability region boundary to the negative realaxis.

Input: m – number of stages Output: A ExplicitRungeKuttaMethod

Examples:

Load the 4-stage method:>>> RKC41=RKC1(4)>>> print(RKC41)Runge-Kutta-Chebyshev (4,1)<BLANKLINE>0 |1/16 | 1/161/4 | 1/8 1/89/16 | 3/16 1/4 1/8______|________________________

| 1/4 3/8 1/4 1/8

References:

1. [verwer2004]

nodepy.runge_kutta_method.RKC2(m, epsilon=0)Construct the m-stage, second order Explicit Runge-Kutta-Chebyshev methods of Verwer (m>=2).

Inputs: m – number of stages epsilon – damping factor

Output: A ExplicitRungeKuttaMethod

Examples:

Load the 4-stage method:>>> RKC42=RKC2(4)>>> print(RKC42)Runge-Kutta-Chebyshev (4,2)<BLANKLINE>0 |1/5 | 1/51/5 | 1/10 1/108/15 | -8/45 32/135 64/135________|________________________________

| -51/64 3/8 1 27/64

References:

1.6. Modules Reference 53

Page 58: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

1. [verwer2004]

nodepy.runge_kutta_method.dcweights(x)Takes a set of abscissae x and an index i, and returns the quadrature weights for the interval [x_i,x_{i+1}]. Usedin construction of deferred correction methods.

nodepy.runge_kutta_method.DC_pair(s, theta=0.0, grid=’eq’)Spectral deferred correction embedded pairs. See also the help for DC(). Examples:

>>> from nodepy import rk>>> DC2 = rk.DC_pair(2)>>> print(DC2)Picard 3(2)

0 |1/2 | 1/21 | 1/2 1/21/2 | 5/24 1/3 -1/241 | 1/6 2/3 1/6_______|___________________________________

| 1/6 0 0 2/3 1/6| 1/6 2/3 1/6

nodepy.runge_kutta_method.DC(s, theta=0, grid=’eq’, num_corr=None)Spectral deferred correction methods. For now, based on explicit Euler and equispaced points. For theta=0, thisis Picard iteration.

Input: s – number of grid points & number of correction iterations

Output: A ExplicitRungeKuttaMethod

Note that the number of stages is NOT equal to s. The order is equal to s+1.

Examples:

>>> from nodepy import rk>>> dc3 = rk.DC(3)>>> dc3.order()4>>> dc3.principal_error_norm()0.0069444...>>> dc3_cheb = rk.DC(3,grid='cheb')>>> dc3_cheb.order()4>>> dc3_cheb.principal_error_norm()0.0066478...

References:

1.[dutt2000]

2.[gottlieb2009]

nodepy.runge_kutta_method.extrap(p, base=’euler’, seq=’harmonic’, embedded=False, shu-osher=False)

Construct extrapolation methods. For now, based on explicit Euler, but allowing arbitrary sequences.

Input: p – number of grid points & number of extrapolation iterations base – the base method to be used(‘euler’ or ‘midpoint’) seq – extrapolation sequence

Output: A ExplicitRungeKuttaMethod

Examples:

54 Chapter 1. Overview

Page 59: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rk>>> ex3 = rk.extrap(3)>>> print(ex3)Ex-Euler 3

0 |1/2 | 1/21/3 | 1/32/3 | 1/3 1/3_____|____________________

| 0 -2 3/2 3/2

>>> ex3.num_seq_dep_stages()3>>> ex3.principal_error_norm()0.04606423319938055>>> ex3.principal_error_norm(mode='exact')sqrt(11)/72

>>> ex4 = rk.extrap(2,'midpoint')>>> print(ex4)Ex-Midpoint 2

0 |1/2 | 1/21/4 | 1/41/2 | 1/23/4 | 1/4 1/2

______|______________________________| 0 -1/3 2/3 0 2/3

>>> ex4.order()4

References:

1.[Hairer] chapter II.9

nodepy.runge_kutta_method.extrap_pair(p, base=’euler’)Returns an embedded RK pair. If the base method is Euler, the prinicpal method has order p and the embeddedmethod has order p-1. If the base method is midpoint, the orders are $2p, 2(p-1)$.

Examples:

>>> from nodepy import rk>>> ex32 = rk.extrap_pair(3,base='Euler')>>> ex32.order()3>>> ex32.embedded_method.order()2>>> ex42 = rk.extrap_pair(2,base='midpoint')>>> ex42.order()4>>> ex42.embedded_method.order()2

nodepy.runge_kutta_method.runge_kutta_order_conditions(p, ind=’all’)This is the current method of producing the code on-the-fly to test order conditions for RK methods. May bedeprecated soon.

1.6. Modules Reference 55

Page 60: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.runge_kutta_method.RKOCstr2code(ocstr)Converts output of runge_kutta_order_conditions() to numpy-executable code.

nodepy.runge_kutta_method.compose(RK1, RK2, h1=1, h2=1)The method obtained by applying RK2, followed by RK1, each with half the timestep.

Output:

The methodc_2 | A_2 0

1+c_1 | b_2 A_1_____________

| b_2 b_1

but with everything divided by two.The b_2 matrix block consists of m_1 (row) copies of b_2.

Examples:

What method is obtained by two successive FE steps?>>> from nodepy import rk>>> fe=rk.loadRKM('FE')>>> print(fe*fe)Runge-Kutta Method<BLANKLINE>0 |0.500 | 0.500_______|______________

| 0.500 0.500

TODO: Generalize this for any number of inputs

nodepy.runge_kutta_method.python_to_fortran(code)

nodepy.runge_kutta_method.python_to_matlab(code)Convert python code string (order condition) to matlab code string Doesn’t really work yet. We need to do moreparsing.

nodepy.runge_kutta_method.relative_accuracy_efficiency(rk1, rk2, mode=’float’,tol=1e-14)

Compute the accuracy efficiency of method rk1 relative to that of rk2, for two methods with the same order ofaccuracy.

The relative accuracy efficiency is

𝜂 = 𝑠2𝑠1

(︁𝐴2

𝐴1

)︁1/𝑝+1

where 𝑠1, 𝑠2 are the number of stages of the two methods and 𝐴1, 𝐴2 are their principal error norms.

If the result is >1, method 1 is more efficient.

Examples:

Compare Fehlberg's method with Dormand-Prince>>> from nodepy import rk>>> dp5 = rk.loadRKM('DP5')>>> f45 = rk.loadRKM('Fehlberg45')>>> rk.relative_accuracy_efficiency(dp5,f45) # doctest: +ELLIPSIS1.22229116499...

56 Chapter 1. Overview

Page 61: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.runge_kutta_method.accuracy_efficiency(rk1, parallel=False, mode=’float’,tol=1e-14, p=None)

Compute the accuracy efficiency of method rk1.

The accuracy efficiency is

𝜂 = 1𝑠1

(︁1𝐴1

)︁1/𝑝+1

where 𝑠1 are the number of stages of the the method and 𝐴1 is its principal error norms.

Examples:

Accuracy efficiency of Dormand-Prince>>> from nodepy import rk>>> dp5 = rk.loadRKM('DP5')>>> rk.accuracy_efficiency(dp5) # doctest: +ELLIPSIS0.5264921944121...

nodepy.runge_kutta_method.linearly_stable_step_size(rk, L, acc=1e-07, tol=1e-14,plot=1)

Determine the maximum linearly stable step size for Runge-Kutta method rk applied to the IVP 𝑢′ = 𝐿𝑢, bycomputing the eigenvalues of 𝐿 and determining the values of the stability function of rk at the eigenvalues.

Note that this analysis is not generally appropriate if L is non-normal.

Examples:

>>> from nodepy import rk, semidisc

4th-order Runge-Kutta scheme:>>> rk44=rk.loadRKM('RK44')

Centered differences on a grid with spacing 1/100:>>> L1=semidisc.centered_diffusion_matrix(100)>>> L2=semidisc.centered_advection_diffusion_matrix(1.,1./500,100)

>>> print("{:.5f}".format(rk.linearly_stable_step_size(rk44,L1,plot=0)))0.00007>>> print("{:.5f}".format(rk.linearly_stable_step_size(rk44,L2,plot=0)))0.02423

>>> sd = semidisc.load_semidisc('spectral difference advection',order=1)>>> print("{:.5f}".format(rk.linearly_stable_step_size(rk44,sd.L,plot=0)))0.01393

1.6.2 rooted_trees

class nodepy.rooted_trees.RootedTree(strg)A rooted tree is a directed acyclic graph with one node, which has no incoming edges, designated as the root.Rooted trees are useful for analyzing the order conditions of multistage numerical ODE solvers, such as Runge-Kutta methods and other general linear methods.

The trees are represented as strings, using one of the notations introduced by Butcher (the third column of Table300(I) of Butcher’s text). The character ‘T’ is used in place of $\tau$ to represent a vertex, and braces ‘{ }’ areused instead of brackets ‘[ ]’ to indicate that everything inside the braces is joined to a single parent node. Thusthe first four trees are:

‘T’, ‘{T}’, ‘{T^2}’, {{T}}’

These can be generated using the function list_trees(), which returns a list of all trees of a given order:

1.6. Modules Reference 57

Page 62: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import *>>> for p in range(4): print(rt.list_trees(p))['']['T']['{T}']['{{T}}', '{T^2}']

Note that the tree of order 0 is indicated by an empty string.

If the tree contains an edge from vertex A to vertex B, vertex B is said to be a child of vertex A. A vertex withno children is referred to as a leaf.

Warning: One important convention is assumed in the code; namely, that at each level, leaves are listedfirst (before any other subtrees), and if there are $n$ leaves, we write ‘T^n’.

Note: Currently, powers cannot be used for subtrees; thus

‘{{T}{T}}’

is valid, while

‘{{T}^2}’

is not. This restriction may be lifted in the future.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}{T}}')>>> tree.order()9>>> tree.density()144>>> tree.symmetry()2

Topologically equivalent trees are considered equal:

>>> tree2=RootedTree('{T^2{T}{T{T}}}')>>> tree2==treeTrue

We can generate Python code to evaluate the elementary weight corresponding to a given tree for a given classof methods:

>>> rk.elementary_weight_str(tree)'dot(b,dot(A,c)*dot(A,c*dot(A,c))*c**2)'

References:

1. [butcher2003]

2. [hairer1993]

TODO: - Check validity of strg more extensively

• Accept any leaf ordering, but convert it to our convention

• convention for ordering of subtrees?

58 Chapter 1. Overview

Page 63: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

order()The order of a rooted tree, denoted $r(t)$, is the number of vertices in the tree.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.order()7

density()The density of a rooted tree, denoted by $\gamma(t)$, is the product of the orders of the subtrees.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.density()56

Reference:

•[butcher2003] p. 127, eq. 301(c)

symmetry()The symmetry $\sigma(t)$ of a rooted tree is...

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> tree.symmetry()2

Reference:

•[butcher2003] p. 127, eq. 301(b)

Dmap()Butcher’s function $D(t)$. Represents differentiation. Defined by $D(t)$=0 except for D(‘T’)=1.

Reference:

1. [butcher1997]

lamda(alpha, extraargs=[])Computes Butcher’s functional lambda on a given tree for the function alpha. This is used to compute theproduct of two functions on trees.

INPUT:

•alpha – a function on rooted trees

•extraargs – a list containing any additional arguments that must be passed to alpha

OUTPUT:

• tprod – a list of trees [t1, t2, ...]

• fprod – a list of numbers [a1, a2, ...]

The meaning of the output is that $\lambda(\alpha,t)(\beta)=a1*\beta(t1)+a2*\beta(t2)+...$

Examples:

1.6. Modules Reference 59

Page 64: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import rt>>> tree = rt.RootedTree('{T{T}}')>>> tree.lamda(rt.Emap)(['T', '{T}', '{{T}}', '{T}', '{T^2}', '{T{T}}'], [1/2, 1, 1, 1/2, 1, 1])

Reference: [butcher2003] pp. 275-276

lamda_str(alpha, extraargs=[])Alternate version of lamda above, but returns a string. Hopefully we can get rid of this (and the other strfunctions) when SAGE can handle noncommutative symbolic algebra.

Gprod(alpha, beta, alphaargs=[], betaargs=[])Returns the product of two functions on a given tree.

INPUT:

alpha, beta – two functions on rooted trees that return symbolic or numeric values

alphaargs – a string containing any additional arguments that must be passed to function alpha

betaargs – a string containing any additional arguments that must be passed to function beta

OUTPUT: (alpha*beta)(self) i.e., the function that is the product (in G) of the functions alpha and beta.Note that this product is not commutative.

The product is given by

$(\alpha*\beta)(‘’)=\beta(‘’)$

$(\alpha*\beta)(t) = \lambda(\alpha,t)(\beta) + \alpha(t)\beta(‘’)$

Note: Gprod can be used to compute products of more than two functions by passing Gprod itself in asbeta, and providing the remaining functions to be multiplied as betaargs.

Examples:

>>> from nodepy import rt>>> tree = rt.RootedTree('{T{T}}')>>> tree.Gprod(rt.Emap,Dmap)1/2

Reference: [butcher2003] p. 276, Thm. 386A

Gprod_str(alpha, beta, alphaargs=[], betaargs=[])Alternate version of Gprod, but operates on strings. Hopefully can be eliminated later in favor of symbolicmanipulation.

plot(nrows=1, ncols=1, iplot=1, ttitle=’‘)Plots the rooted tree.

INPUT: (optional)

• nrows, ncols – number of rows and columns of subplots in the figure

• iplot – index of the subplot in which to plot this tree

These are only necessary if plotting more than one tree in a single figure using subplot.

OUTPUT: None.

The plot is created recursively by plotting the root, parsing the subtrees, plotting the subtrees’ roots, andcalling _plot_subtree on each child

60 Chapter 1. Overview

Page 65: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

list_equivalent_trees()Returns a list of all strings (subject to our assumptions) equivalent to a given tree

INPUT: self – any rooted tree

OUTPUT:

treelist – a list of all the ‘legal’ tree strings that produce the same tree.

The list of equivalent trees is obtained by taking all permutations of the (non-leaf) subtrees. This routineis used to test equality of trees.

nodepy.rooted_trees.plot_all_trees(p, title=’str’)Plots all rooted trees of order p.

Example:

Plot all trees of order 4:

>>> from nodepy import rt>>> rt.plot_all_trees(4)<matplotlib.figure.Figure object at ...>

nodepy.rooted_trees.list_trees(p, ind=’all’)Returns rooted trees of order p.

INPUT:

•p – order of trees desired

•ind – if given, returns a single tree corresponding to this index. Not very useful since the orderingisn’t obvious.

OUTPUT: list of all trees of order p (or just one, if ind is provided).

Generates the rooted trees using Albrecht’s ‘Recursion 3’.

Examples:

Produce column of Butcher’s Table 302(I):

>>> for i in range(1,11):... forest=list_trees(i)... print(len(forest))112492048115286719

Warning: This code is complete only up to order 10. We need to extend it by adding more subloops forp>10.

TODO: Implement Butcher’s formula (Theorem 302B) for the number of trees and determine to what or-der this is valid.

Reference: [albrecht1996]

1.6. Modules Reference 61

Page 66: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.rooted_trees.Dprod(tree, alpha)Evaluate (alpha*D)(t). Note that this is not equal to (D*alpha)(t). This function is necessary (rather than justusing Gprod) in order to avoid infinite recursions.

Examples:

>>> from nodepy import rt>>> tree = rt.RootedTree('{T{T}}')>>> Dprod(tree,Emap)1/2

nodepy.rooted_trees.Dprod_str(tree, alpha)

nodepy.rooted_trees.Dmap(tree)Butcher’s function D(t). Represents differentiation. Defined by D(t)=0 except for D(‘T’)=1.

nodepy.rooted_trees.Dmap_str(tree)

nodepy.rooted_trees.Gprod(tree, alpha, beta, alphaargs=’‘, betaargs=[])Returns the product of two functions on a given tree. See Butcher p. 276, Thm. 386A

nodepy.rooted_trees.Gprod_str(tree, alpha, beta, alphaargs=’‘, betaargs=[])

nodepy.rooted_trees.Emap(tree, a=1)Butcher’s function E^a(t). Gives the B-series for the exact solution advanced ‘a’ steps in time.

Examples:

>>> from nodepy import rooted_trees as rt>>> tree=rt.RootedTree('{T^2{T{T}}}')>>> rt.Emap(tree)1/56>>> rt.Emap(tree,a=2)16/7

Reference:

[butcher1997]

nodepy.rooted_trees.Emap_str(tree, a=1)

nodepy.rooted_trees.recursiveVectors(p, ind=’all’)Generate recursive vectors using Albrecht’s ‘recursion 1’. These are essentially the order conditions for Runge-Kutta methods, excluding those that correspond to bushy trees. More specifically, these are the vectors that mustbe orthogonal to the vector of weights b.

Note that the individual order conditions obtained from this algorithm are different from those obtained usingButcher’s approach. But as a set of conditions up to some order they are, of course, equivalent.

Follows [albrecht1996] p. 1718

Warning: This code is complete only up to order 12. We need to extend it by adding more subloops forp>12.

Example

Count number of conditions for order 12:

>>> from nodepy import rt>>> v = rt.recursiveVectors(12)>>> print(len(v))4769

62 Chapter 1. Overview

Page 67: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.rooted_trees.py2tex(codestr)Convert a python code string to LaTex

1.6.3 linear_multistep_method

Examples:

>>> import nodepy.linear_multistep_method as lm>>> ab3=lm.Adams_Bashforth(3)>>> ab3.order()3>>> bdf2=lm.backward_difference_formula(2)>>> bdf2.order()2>>> bdf2.is_zero_stable()True>>> bdf7=lm.backward_difference_formula(7)>>> bdf7.is_zero_stable()False>>> bdf3=lm.backward_difference_formula(3)>>> bdf3.A_alpha_stability()86>>> ssp32=lm.elm_ssp2(3)>>> ssp32.order()2>>> ssp32.ssp_coefficient()1/2>>> ssp32.plot_stability_region()<matplotlib.figure.Figure object at 0x...>

class nodepy.linear_multistep_method.LinearMultistepMethod(alpha, beta,name=’Linear multi-step method’, short-name=’LMM’, descrip-tion=’‘)

Implementation of linear multistep methods in the form:

𝛼𝑘𝑦𝑛+𝑘 + 𝛼𝑘−1𝑦𝑛+𝑘−1 + ...+ 𝛼0𝑦𝑛 = ℎ(𝛽𝑘𝑓𝑛+𝑘 + ...+ 𝛽0𝑓𝑛)

Methods are automatically normalized so that alpha_k=1.

Notes: Representation follows Hairer & Wanner p. 368, NOT Butcher.

References:

1. [hairer1993] Chapter III

2. [butcher2003]

characteristic_polynomials()Returns the characteristic polynomials (also known as generating polynomials) of a linear multistepmethod. They are:

𝜌(𝑧) =∑︀𝑘

𝑗=0 𝛼𝑘𝑧𝑘

𝜎(𝑧) =∑︀𝑘

𝑗=0 𝛽𝑘𝑧𝑘

Examples:

1.6. Modules Reference 63

Page 68: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> from nodepy import lm>>> ab5 = lm.Adams_Bashforth(5)>>> rho,sigma = ab5.characteristic_polynomials()>>> print(rho)

5 41 x - 1 x

>>> print(sigma)4 3 2

2.64 x - 3.853 x + 3.633 x - 1.769 x + 0.3486

References:

1. [hairer1993] p. 370, eq. 2.4

order(tol=1e-10)Return the order of the local truncation error of a linear multistep method.

Examples:

>>> from nodepy import lm>>> am3=lm.Adams_Moulton(3)>>> am3.order()4

absolute_monotonicity_radius()

p

latex()Print a LaTeX representation of a linear multistep formula.

Example:

>>> from nodepy import lm>>> print(lm.Adams_Bashforth(2).latex())\begin{align} y_{n + 2} - y_{n + 1} = \frac{3}{2}h f(y_{n + 1}) - \frac{1}{2}h f(y_{n})\end{align}

ssp_coefficient()Return the SSP coefficient of the method.

The SSP coefficient is given by

min0≤𝑗<𝑘 −𝛼𝑘/𝑏𝑒𝑡𝑎𝑘

if 𝛼𝑗 < 0 and 𝛽𝑗 > 0 for all 𝑗, and is equal to zero otherwise.

Examples:

>>> from nodepy import lm>>> ssp32=lm.elm_ssp2(3)>>> ssp32.ssp_coefficient()1/2

>>> bdf2=lm.backward_difference_formula(2)>>> bdf2.ssp_coefficient()0

plot_stability_region(N=100, bounds=None, color=’r’, filled=True, alpha=1.0, to_file=False,longtitle=False)

The region of absolute stability of a linear multistep method is the set

64 Chapter 1. Overview

Page 69: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

{𝑧 ∈ 𝐶 : 𝜌(𝜁)− 𝑧𝜎(𝑧𝑒𝑡𝑎) satisfies the root condition}

where 𝜌(𝑧𝑒𝑡𝑎) and 𝜎(𝑧𝑒𝑡𝑎) are the characteristic functions of the method.

Also plots the boundary locus, which is given by the set of points z:

{𝑧|𝑧 = 𝜌(exp(𝑖𝜃))/𝜎(exp(𝑖𝜃)), 0 ≤ 𝜃 ≤ 2 * 𝜋}

Here 𝜌 and 𝜎 are the characteristic polynomials of the method.

References: [leveque2007] section 7.6.1

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

plot_boundary_locus(N=1000)Plot the boundary locus, which is given by the set of points

{𝑧|𝑧 = 𝜌(exp(𝑖𝜃))/𝜎(exp(𝑖𝜃)), 0 ≤ 𝜃 ≤ 2 * 𝜋}

where 𝜌 and 𝜎 are the characteristic polynomials of the method.

References: [leveque2007] section 7.6.1

A_alpha_stability(N=1000, tol=1e-14)Angle of 𝐴(𝛼)-stability.

The result is given in degrees. The result is only accurate to about 1 degree, so we round down.

Examples:

>>> from nodepy import lm>>> bdf5 = lm.backward_difference_formula(5)>>> bdf5.A_alpha_stability()51

is_explicit()

is_zero_stable(tol=1e-13)True if the method is zero-stable.

Examples:

>>> from nodepy import lm>>> bdf5=lm.backward_difference_formula(5)>>> bdf5.is_zero_stable()True

class nodepy.linear_multistep_method.AdditiveLinearMultistepMethod(alpha, beta,gamma,name=’Additivelinearmultistepmethod’)

Method for solving equations of the form

𝑦′(𝑡) = 𝑓(𝑦) + 𝑔(𝑦)

The method takes the form

1.6. Modules Reference 65

Page 70: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

𝛼𝑘𝑦𝑛+𝑘 + 𝛼𝑘−1𝑦𝑛+𝑘−1 + ...+ 𝛼0𝑦𝑛 = ℎ(𝛽𝑘𝑓𝑛+𝑘 + ...+ 𝛽0𝑓𝑛 + 𝛾𝑘𝑓𝑛+𝑘 + ...+ 𝛾0𝑓𝑛)

Methods are automatically normalized so that alpha_k=1.

The usual reference for these is Ascher, Ruuth, and Whetton. But we follow a different notation (as just de-scribed).

order(tol=1e-10)Return the order of the local truncation error of an additive linear multistep method. The output is theminimum of the order of the component methods.

plot_imex_stability_region(N=100, color=’r’, filled=True, alpha=1.0, fignum=None)

Input: (all optional)

• N – Number of gridpoints to use in each direction

• bounds – limits of plotting region

• color – color to use for this plot

• filled – if true, stability region is filled in (solid); otherwise it is outlined

stiff_damping_factor(epsilon=1e-07)Return the magnitude of the largest root at z=-inf. This routine just computes a numerical approximationto the true value (with absolute accuracy epsilon).

nodepy.linear_multistep_method.Adams_Bashforth(k)Construct the k-step, Adams-Bashforth method. The methods are explicit and have order k. They have the form:

𝑦𝑛+1 = 𝑦𝑛 + ℎ∑︀𝑘−1

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equations (1.5) and (1.7) from [hairer1993] III.1, along with the binomial expansion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> ab3=lm.Adams_Bashforth(3)>>> ab3.order()3

References:#. [hairer1993]_

nodepy.linear_multistep_method.Nystrom(k)Construct the k-step explicit Nystrom linear multistep method. The methods are explicit and have order k. Theyhave the form:

𝑦𝑛+1 = 𝑦𝑛−1 + ℎ∑︀𝑘−1

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equations (1.13) and (1.7) from [hairer1993] III.1, along with the binomial expansionand the relation in exercise 4 on p. 367.

Note that the term “Nystrom method” is also commonly used to refer to a class of methods for second-orderODEs; those are NOT the methods generated by this function.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> nys3=lm.Nystrom(6)>>> nys3.order()6

References:#. [hairer1993]_

66 Chapter 1. Overview

Page 71: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

nodepy.linear_multistep_method.Adams_Moulton(k)Construct the k-step, Adams-Moulton method. The methods are implicit and have order k+1. They have theform:

𝑦𝑛+1 = 𝑦𝑛 + ℎ∑︀𝑘

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equation (1.9) and the equation in Exercise 3 from Hairer & Wanner III.1, along withthe binomial expansion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> am3=lm.Adams_Moulton(3)>>> am3.order()4

References: [hairer1993]

nodepy.linear_multistep_method.Milne_Simpson(k)Construct the k-step, Milne-Simpson method. The methods are implicit and (for k>=3) have order k+1. Theyhave the form:

𝑦𝑛+1 = 𝑦𝑛−1 + ℎ∑︀𝑘

𝑗=0 𝛽𝑗𝑓(𝑦𝑛 − 𝑘 + 𝑗 + 1)

They are generated using equation (1.15), the equation in Exercise 3, and the relation in exercise 4, all fromHairer & Wanner III.1, along with the binomial expansion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> ms3=lm.Milne_Simpson(3)>>> ms3.order()4

References: [hairer1993]

nodepy.linear_multistep_method.backward_difference_formula(k)Construct the k-step backward differentiation method. The methods are implicit and have order k. They havethe form:∑︀𝑘

𝑗=0 𝛼𝑗𝑦𝑛+𝑘−𝑗+1 = ℎ𝛽𝑗𝑓(𝑦𝑛+1)

They are generated using equation (1.22’) from Hairer & Wanner III.1, along with the binomial expan-sion.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> bdf4=lm.backward_difference_formula(4)>>> bdf4.A_alpha_stability()73

References: #.[hairer1993]_ pp. 364-365

nodepy.linear_multistep_method.elm_ssp2(k)Returns the optimal SSP k-step linear multistep method of order 2.

Examples:

1.6. Modules Reference 67

Page 72: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

>>> import nodepy.linear_multistep_method as lm>>> lm10=lm.elm_ssp2(10)>>> lm10.ssp_coefficient()8/9

nodepy.linear_multistep_method.sand_cc(s)

Construct Sand’s circle-contractive method of order 𝑝 = 2(𝑠+ 1) that uses 2𝑠 + 1 steps.

Examples:

>>> import nodepy.linear_multistep_method as lm>>> cc4 = lm.sand_cc(4)>>> cc4.order()10>>> cc4.ssp_coefficient()1/8

References:

1. [sand1986]

nodepy.linear_multistep_method.arw2(gam, c)Returns the second order IMEX additive multistep method based on the parametrization in Section 3.2 of Ascher,Ruuth, & Spiteri. The parameters are gam and c. Known methods are obtained with the following values:

(1/2,0): CNAB (1/2,1/8): MCNAB (0,1): CNLF (1,0): SBDF

Examples:

>>> from nodepy import lm>>> import sympy>>> CNLF = lm.arw2(0,sympy.Rational(1))>>> CNLF.order()2>>> CNLF.method1.ssp_coefficient()1>>> CNLF.method2.ssp_coefficient()0>>> print(CNLF.stiff_damping_factor())0.999...

nodepy.linear_multistep_method.loadLMM(which=’All’)Load a set of standard linear multistep methods for testing.

Examples:

>>> from nodepy import lm>>> ebdf5 = lm.loadLMM('eBDF5')>>> ebdf5.is_zero_stable()True

1.6.4 low_storage_rk

Typically, implementation of a Runge-Kutta method requires 𝑠×𝑁 memory locations, where 𝑠 is the number of stagesof the method and 𝑁 is the number of unknowns. Certain classes of Runge-Kutta methods can be implemented usingsubstantially less memory, by taking advantage of special relations among the coefficients. Three main classes havebeen developed in the literature:

68 Chapter 1. Overview

Page 73: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

• 2N (Williamson) methods

• 2R (van der Houwen/Wray) methods

• 2S methods

Each of these classes requires only 2×𝑁 memory locations. Additional methods have been developed that use morethan two memory locations per unknown but still provide a substantial savings over traditional methods. These arereferred to as, e.g., 3S, 3R, 4R, and so forth. For a review of low-storage methods, see [ketcheson2010] .

In NodePy, low-storage methods are a subclass of explicit Runge-Kutta methods (and/or explicit Runge-Kutta pairs).In addition to the usual properties, they possess arrays of low-storage coefficients. They override the generic RKimplementation of time-stepping and use special memory-efficient implementations instead. It should be noted that,although these low-storage algorithms are implemented, due to Python language restrictions an extra intermediatecopy of the solution array will be created. Thus the implementation in NodePy is not really minimum-storage.

At the moment, the following classes are implemented:

• 2S : Methods using two registers (under Ketcheson’s assumption)

• 2S* [Methods using two registers, one of which retains the previous] step solution

• 3S* [Methods using three registers, one of which retains the previous] step solution

• 2S embedded pairs

• 3S* embedded pairs

• 2R embedded pairs

• 3R embedded pairs

Examples:

>>> from nodepy import lsrk, ivp>>> myrk = lsrk.load_2R('DDAS47')>>> print(myrk)DDAS4()7[2R]2R Method of Tselios \& Simos (2007)0.000 |0.336 | 0.3360.286 | 0.094 0.1920.745 | 0.094 0.150 0.5010.639 | 0.094 0.150 0.285 0.1100.724 | 0.094 0.150 0.285 -0.122 0.3170.911 | 0.094 0.150 0.285 -0.122 0.061 0.444

_______|_________________________________________________| 0.094 0.150 0.285 -0.122 0.061 0.346 0.187

>>> rk58 = lsrk.load_2R('RK58[3R]C')>>> rk58.name'RK5(4)8[3R+]C'>>> rk58.order()5>>> problem = ivp.load_ivp('vdp')>>> t,u = rk58(problem)>>> u[-1]array([-1.40278844, 1.23080499])>>> import nodepy>>> rk2S = lsrk.load_LSRK("{}/method_coefficients/58-2S_acc.txt".format(nodepy.__path__[0]),has_emb=True)>>> rk2S.order()5>>> rk2S.embedded_method.order()

1.6. Modules Reference 69

Page 74: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

4>>> rk3S = lsrk.load_LSRK(nodepy.__path__[0]+'/method_coefficients/58-3Sstar_acc.txt',lstype='3S*')>>> rk3S.principal_error_norm()0.00035742076...

class nodepy.low_storage_rk.TwoRRungeKuttaMethod(a, b, bhat=None, regs=2, name=‘2RRunge-Kutta Method’, description=’‘,shortname=’LSRK2R’, order=None)

Class for 2R/3R/4R low-storage Runge-Kutta pairs.

These were developed by van der Houwen, Wray, and Kennedy et. al. Only 2R and 3R methods have beenimplemented so far.

References:

• [kennedy2000]

• [ketcheson2010]

Initializes the 2R method by storing the low-storage coefficients and computing the Butcher array.

The coefficients should be specified as follows:

•For all methods, the weights 𝑏 are used to fill in the appropriate entries in 𝐴.

•For 2R methods, a is a vector of length 𝑠− 1 containing the first subdiagonal of 𝐴

•For 3R methods, a is a 2 × 𝑠 − 1 array whose first row contains the first subdiagonal of 𝐴 and whosesecond row contains the second subdiagonal of 𝐴.

class nodepy.low_storage_rk.TwoSRungeKuttaMethod(betavec, gamma, delta, lstype,name=’Low-storage Runge-KuttaMethod’, description=’‘, short-name=’LSRK2S’, order=None)

Class for low-storage Runge-Kutta methods that use Ketcheson’s assumption (2S, 2S*, and 3S* methods).

This class cannot be used for embedded pairs. Use the class TwoSRungeKuttaPair instead.

The low-storage coefficient arrays 𝑒𝑡𝑎, 𝛾, 𝛿 follow the notation of [ketcheson2010] .

The argument lstype must be one of the following values:

•2S

•2S*

•3S*

Initializes the low-storage method by storing the low-storage coefficients and computing the Butcher coeffi-cients.

class nodepy.low_storage_rk.TwoSRungeKuttaPair(betavec, gamma, delta, lstype, bhat=None,name=’Low-storage Runge-Kutta Pair’,description=’‘, shortname=’LSRK2S’,order=None)

Class for low-storage embedded Runge-Kutta pairs that use Ketcheson’s assumption (2S, 2S*, and 3S* meth-ods).

This class is only for embedded pairs. Use the class TwoSRungeKuttaMethod for single 2S/3S methods.

The low-storage coefficient arrays 𝑒𝑡𝑎, 𝛾, 𝛿 follow the notation of [ketcheson2010] .

The argument lstype must be one of the following values:

•2S

70 Chapter 1. Overview

Page 75: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

•2S*

•2S_pair

•3S*

•3S*_pair

The 2S/2S*/3S* classes do not need an extra register for the error estimate, while the 2S_pair/3S_pair methodsdo.

Initializes the low-storage pair by storing the low-storage coefficients and computing the Butcher coefficients.

nodepy.low_storage_rk.load_LSRK(file, lstype=‘2S’, has_emb=False)Load low storage methods of the types 2S/2S*/3S*/2S_pair/3S_pair from a file containing the low-storagecoefficient arrays. If has_emb=True, the method has an embedded method that requires an extra register.

The use of both _pair and has_emb seems redundant; this should be corrected in the future.

nodepy.low_storage_rk.load_LSRK_RKOPT(file, lstype=‘2S’, has_emb=False)Load low storage methods of the types 2S/2S*/3S*/2S_pair/3S_pair from a file containing the low-storagecoefficient arrays. Such a file is usually written by RK-opt (see https://github.com/ketch/RK-opt).

nodepy.low_storage_rk.load_2R(name)Loads 2R low-storage methods from the literature.

1.7 Indices and tables

• genindex

• modindex

• search

1.7. Indices and tables 71

Page 76: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

72 Chapter 1. Overview

Page 77: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

Bibliography

[butcher2003] J.C. Butcher, Numerical Methods for Ordinary Differential Equations

[hairer1993] Hairer & Wanner, Solving Ordinary Differential Equations I: Nonstiff Problems

[hairer1993b] Hairer & Wanner, Solving Ordinary Differential Equations II: Stiff Problems

[leveque2007] R.J. LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations

[albrecht1996] Albrecht, The Runge-Kutta Theory in a Nutshell, (1996) p. 1727

[butcher1997] J.C. Butcher & S. Tracogna, “Order Conditions for Two-Step Runge-Kutta methods”, APNUM 24 pp.351-364 (1997)

[dutt2000] 1. Dutt & L. Greengard & V. Rokhlin, Spectral deferred correction methods for ordinary differentialequations, BIT 40:241-266 (2000)

[enright1987] W.H. Enright & J.D. Pryce, Two FORTRAN Packages for Assessing Initial Value Methods, ACM Trans.on Mathematical Software 13(1):1-27 (1987)

[gottlieb2009] Gottlieb, Ketcheson, & Shu, High Order Strong Stability Preserving Time Discretizations, J. Sci. Com-put. 38(3):251 (2009)

[higueras2005] 1. Higueras, Representations of Runge-Kutta methods and strong stability preserving methods,SINUM 43 pp. 924-948 (2005)

[kennedy2000] C.A. Kennedy & M.H. Carpenter & R.M. Lewis, Low-storage, explicit Runge-Kutta schemes for thecompressible Navier-Stokes equations, APNUM 35:177-219 (2000)

[ketcheson2010] D.I. Ketcheson Runge–Kutta Methods with Minimum Storage Implementations, J. Comput. Phys.229:1763-1773 (2010)

[ketcheson2009c] D.I. Ketcheson & Sigal Gottlieb & Colin B. Macdonald Strong Stability Preserving Two-stepRunge–Kutta Methods

[kraaijevanger1991] JFBM Kraaijevanger, Contractivity of Runge-Kutta Methods, BIT 1991

[ketcheson2008] D.I. Ketcheson, Highly efficient strong stability preserving Runge-Kutta methods with low-storageimplementations, SISC 30(4):2113 (2008)

[ketcheson2009] D.I. Ketcheson, C.B. Macdonald, and S. Gottlieb, Optimal implicit strong stability preservingRunge-Kutta methods, APNUM 59(2):373 (2009)

73

Page 78: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

74 Bibliography

Page 79: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

Python Module Index

nnodepy.linear_multistep_method, 63nodepy.low_storage_rk, 68nodepy.rooted_trees, 57nodepy.runge_kutta_method, 35

75

Page 80: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

76 Python Module Index

Page 81: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

Index

Symbols__call__() (nodepy.ode_solver.ODESolver method), 20

AA_alpha_stability() (nodepy.linear_multistep_method.LinearMultistepMethod

method), 65absolute_monotonicity_radius()

(nodepy.linear_multistep_method.LinearMultistepMethodmethod), 64

absolute_monotonicity_radius()(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 42

accuracy_efficiency() (in modulenodepy.runge_kutta_method), 56

Adams_Bashforth() (in modulenodepy.linear_multistep_method), 66

Adams_Moulton() (in modulenodepy.linear_multistep_method), 66

AdditiveLinearMultistepMethod (class innodepy.linear_multistep_method), 65

arw2() (in module nodepy.linear_multistep_method), 68

Bbackward_difference_formula() (in module

nodepy.linear_multistep_method), 67

Ccanonical_shu_osher_form()

(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 43

characteristic_polynomials()(nodepy.linear_multistep_method.LinearMultistepMethodmethod), 63

circle_contractivity_radius()(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 42

compose() (in module nodepy.runge_kutta_method), 56ContinuousExplicitRungeKuttaMethod (class in

nodepy.runge_kutta_method), 46

ContinuousRungeKuttaMethod (class innodepy.runge_kutta_method), 46

ctest() (nodepy.convergence method), 21

DDC() (in module nodepy.runge_kutta_method), 54DC_pair() (in module nodepy.runge_kutta_method), 54dcweights() (in module nodepy.runge_kutta_method), 54density() (nodepy.rooted_trees.RootedTree method), 59detest() (nodepy.ivp method), 20discrete_adjoint() (in module

nodepy.runge_kutta_method), 49dj_reduce() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 37Dmap() (in module nodepy.rooted_trees), 62Dmap() (nodepy.rooted_trees.RootedTree method), 59Dmap_str() (in module nodepy.rooted_trees), 62Dprod() (in module nodepy.rooted_trees), 61Dprod_str() (in module nodepy.rooted_trees), 62

Eeffective_order() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 39effective_order_condition_residuals()

(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 39

elementary_weight() (in modulenodepy.runge_kutta_method), 48

elementary_weight_str() (in modulenodepy.runge_kutta_method), 48

elm_ssp2() (in module nodepy.linear_multistep_method),67

Emap() (in module nodepy.rooted_trees), 62Emap_str() (in module nodepy.rooted_trees), 62embedded_method (nodepy.runge_kutta_method.ExplicitRungeKuttaPair

attribute), 47error_coefficient() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 38error_coeffs() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 38

77

Page 82: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

error_metrics() (nodepy.runge_kutta_method.ExplicitRungeKuttaPairmethod), 47

error_metrics() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 38

ExplicitRungeKuttaMethod (class innodepy.runge_kutta_method), 44

ExplicitRungeKuttaPair (class innodepy.runge_kutta_method), 47

extrap() (in module nodepy.runge_kutta_method), 54extrap_pair() (in module nodepy.runge_kutta_method),

55

GGprod() (in module nodepy.rooted_trees), 62Gprod() (nodepy.rooted_trees.RootedTree method), 60Gprod_str() (in module nodepy.rooted_trees), 62Gprod_str() (nodepy.rooted_trees.RootedTree method),

60

Iimaginary_stability_interval()

(nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 44

internal_stability_plot() (nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 46

internal_stability_polynomials()(nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 45

is_absolutely_monotonic_poly() (in modulenodepy.runge_kutta_method), 49

is_explicit() (nodepy.linear_multistep_method.LinearMultistepMethodmethod), 65

is_explicit() (nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 44

is_explicit() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 44

is_FSAL() (nodepy.runge_kutta_method.ExplicitRungeKuttaPairmethod), 48

is_FSAL() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 44

is_splittable() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 43

is_zero_stable() (nodepy.linear_multistep_method.LinearMultistepMethodmethod), 65

is_zero_stable() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 44

Llamda() (nodepy.rooted_trees.RootedTree method), 59lamda_str() (nodepy.rooted_trees.RootedTree method),

60latex() (nodepy.linear_multistep_method.LinearMultistepMethod

method), 64

latex() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 36

linear_absolute_monotonicity_radius()(nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 44

linear_monotonicity_radius()(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 42

linearly_stable_step_size() (in modulenodepy.runge_kutta_method), 57

LinearMultistepMethod (class innodepy.linear_multistep_method), 63

list_equivalent_trees() (nodepy.rooted_trees.RootedTreemethod), 60

list_trees() (in module nodepy.rooted_trees), 61load_2R() (in module nodepy.low_storage_rk), 71load_LSRK() (in module nodepy.low_storage_rk), 71load_LSRK_RKOPT() (in module

nodepy.low_storage_rk), 71loadLMM() (in module

nodepy.linear_multistep_method), 68loadRKM() (in module nodepy.runge_kutta_method), 49lp_perturb() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 43

Mmain_method (nodepy.runge_kutta_method.ExplicitRungeKuttaPair

attribute), 47maximum_internal_amplification()

(nodepy.runge_kutta_method.ExplicitRungeKuttaMethodmethod), 46

Milne_Simpson() (in modulenodepy.linear_multistep_method), 67

Nnodepy.linear_multistep_method (module), 63nodepy.low_storage_rk (module), 68nodepy.rooted_trees (module), 57nodepy.runge_kutta_method (module), 35num_seq_dep_stages() (nodepy.runge_kutta_method.ExplicitRungeKuttaMethod

method), 45Nystrom() (in module nodepy.linear_multistep_method),

66

Ooptimal_perturbed_splitting()

(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 43

optimal_shu_osher_form()(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 42

order() (nodepy.linear_multistep_method.AdditiveLinearMultistepMethodmethod), 66

78 Index

Page 83: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

order() (nodepy.linear_multistep_method.LinearMultistepMethodmethod), 64

order() (nodepy.rooted_trees.RootedTree method), 58order() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 38order_condition_residuals()

(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 39

Pp (nodepy.linear_multistep_method.LinearMultistepMethod

attribute), 64p (nodepy.runge_kutta_method.RungeKuttaMethod at-

tribute), 36plot() (nodepy.rooted_trees.RootedTree method), 60plot_all_trees() (in module nodepy.rooted_trees), 61plot_boundary_locus() (nodepy.linear_multistep_method.LinearMultistepMethod

method), 65plot_imex_stability_region()

(nodepy.linear_multistep_method.AdditiveLinearMultistepMethodmethod), 66

plot_order_star() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 41

plot_stability_function() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 41

plot_stability_region() (nodepy.linear_multistep_method.LinearMultistepMethodmethod), 64

plot_stability_region() (nodepy.runge_kutta_method.ExplicitRungeKuttaPairmethod), 48

plot_stability_region() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 41

principal_error_norm() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 38

print_shu_osher() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 37

propagation_matrix() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 43

ptest() (nodepy.convergence method), 21py2tex() (in module nodepy.rooted_trees), 62python_to_fortran() (in module

nodepy.runge_kutta_method), 56python_to_matlab() (in module

nodepy.runge_kutta_method), 56

Rreal_stability_interval() (nodepy.runge_kutta_method.ExplicitRungeKuttaMethod

method), 44recursiveVectors() (in module nodepy.rooted_trees), 62redistribute_gamma() (in module

nodepy.runge_kutta_method), 44relative_accuracy_efficiency() (in module

nodepy.runge_kutta_method), 56resplit() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 43

RK22_family() (in module nodepy.runge_kutta_method),50

RK44_family() (in module nodepy.runge_kutta_method),50

RKC1() (in module nodepy.runge_kutta_method), 53RKC2() (in module nodepy.runge_kutta_method), 53RKeta() (in module nodepy.runge_kutta_method), 49RKeta_str() (in module nodepy.runge_kutta_method), 49RKOCstr2code() (in module

nodepy.runge_kutta_method), 55RootedTree (class in nodepy.rooted_trees), 57runge_kutta_order_conditions() (in module

nodepy.runge_kutta_method), 55RungeKuttaMethod (class in

nodepy.runge_kutta_method), 36

Ssand_cc() (in module nodepy.linear_multistep_method),

68shu_osher_change_alpha_ij() (in module

nodepy.runge_kutta_method), 49shu_osher_to_butcher() (in module

nodepy.runge_kutta_method), 49shu_osher_zero_alpha_ij() (in module

nodepy.runge_kutta_method), 49shu_osher_zero_beta_ij() (in module

nodepy.runge_kutta_method), 49sign_split() (in module nodepy.runge_kutta_method), 44ssp_coefficient() (nodepy.linear_multistep_method.LinearMultistepMethod

method), 64SSPIRK1() (in module nodepy.runge_kutta_method), 52SSPIRK2() (in module nodepy.runge_kutta_method), 52SSPIRK3() (in module nodepy.runge_kutta_method), 52ssplit() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 43SSPRK2() (in module nodepy.runge_kutta_method), 50SSPRK3() (in module nodepy.runge_kutta_method), 51SSPRKm() (in module nodepy.runge_kutta_method), 51stability_function() (nodepy.runge_kutta_method.RungeKuttaMethod

method), 39stability_function_unexpanded()

(nodepy.runge_kutta_method.RungeKuttaMethodmethod), 39

stage_order() (nodepy.runge_kutta_method.RungeKuttaMethodmethod), 39

stiff_damping_factor() (nodepy.linear_multistep_method.AdditiveLinearMultistepMethodmethod), 66

symmetry() (nodepy.rooted_trees.RootedTree method),59

TTwoRRungeKuttaMethod (class in

nodepy.low_storage_rk), 70

Index 79

Page 84: NodePy Documentation - Read the Docs · NodePy Documentation, Release 0.6.1 RungeKuttaMethod.stage_order(tol=1e-14) The stage order of a Runge-Kutta method is the minimum, over all

NodePy Documentation, Release 0.6.1

TwoSRungeKuttaMethod (class innodepy.low_storage_rk), 70

TwoSRungeKuttaPair (class in nodepy.low_storage_rk),70

TwoStepRungeKuttaMethod (class innodepy.twostep_runge_kutta_method), 18

Wwork_per_step() (nodepy.runge_kutta_method.ExplicitRungeKuttaMethod

method), 44

80 Index