14. Solving ordinary differential equations#
We are developing a library for solving nonlinear ordinary differential equations, and learn the numerical analysis behind the methods. First we build an abstraction of nonlinear functions, and implement solvers for nonlinear equations. On this basis we can simply define time-stepping algorithms. We apply it to mechanical systems of masses connected by springs and constraints. 3D visualization in Jupyter notebooks is provided by pythreejs.
The chapter covers:
A little bit of theory: existence, uniqueness, and stability of solutions
Some simple time-stepping methods: the explicit and implicit Euler and the Crank-Nicolson methods, their convergence and stability, stiff ODEs
Implementing time-stepping methods: function algebra, Newton’s method, explicit and implicit time-steppers in C++
Automatic Differentiation: numerical and automatic differentiation
Runge-Kutta methods: explicit and implicit Runge-Kutta methods of arbitrary order
Automatic step-size control: embedded methods, and automatic step-size control for non-stiff and stiff problems
Mechanical Systems: energy conservation, the Newmark, Störmer-Verlet, and generalized-\(\alpha\) methods, systems with constraints
14.1. Getting the code#
Fork that github repo ASC-ODE, and clone it via
git clone https://github.com/my_fork_on_github/ASC-ODE.git
It contains the basic linear algebra package nanoblas as a git submodule. Populate it using
cd ASC-ODE
git submodule update --init
You are welcome to replace nanoblas by your preferred linear algebra package.
ASC-ODE has the following dependency which must be installed:
pybind11
The LAPACK interface of nanoblas is not needed for ASC-ODE. It is switched off by default,
and can be enabled by cmake -DNANOBLAS_USE_LAPACK=ON ...
Then you can use cmake to build ASC-ODE:
mkdir build
cd build
cmake ..
make
The Runge-Kutta methods and the mechanical systems are provided in the branches RungeKutta and Newmark.
The corresponding sections explain how to merge them into your fork.