scipy_dae - solving differential algebraic equations (DAE's) and implicit differential equations (IDE's) in Python
Python implementation of solvers for differential algebraic equations (DAE's) and implicit differential equations (IDE's) that should be added to scipy one day.
Currently, two different methods are implemented.
- Implicit Radau IIA methods of order 2s - 1 with arbitrary number of odd stages.
- Implicit backward differentiation formula (BDF) of variable order with quasi-constant step-size and stability/ accuracy enhancement using numerical differentiation formula (NDF).
More information about both methods are given in the specific class documentation.
The Kármán vortex street solved by a finite element discretization of the weak form of the incompressible Navier-Stokes equations using FEniCS and the three stage Radau IIA method.
The Robertson problem of semi-stable chemical reaction is a simple system of differential algebraic equations of index 1. It demonstrates the basic usage of the package.
import numpy as np
import matplotlib.pyplot as plt
from scipy_dae.integrate import solve_dae
def F(t, y, yp):
"""Define implicit system of differential algebraic equations."""
y1, y2, y3 = y
y1p, y2p, y3p = yp
F = np.zeros(3, dtype=np.common_type(y, yp))
F[0] = y1p - (-0.04 * y1 + 1e4 * y2 * y3)
F[1] = y2p - (0.04 * y1 - 1e4 * y2 * y3 - 3e7 * y2**2)
F[2] = y1 + y2 + y3 - 1 # algebraic equation
return F
# time span
t0 = 0
t1 = 1e7
t_span = (t0, t1)
t_eval = np.logspace(-6, 7, num=1000)
# initial conditions
y0 = np.array([1, 0, 0], dtype=float)
yp0 = np.array([-0.04, 0.04, 0], dtype=float)
# solver options
method = "Radau"
# method = "BDF" # alternative solver
atol = rtol = 1e-6
# solve DAE system
sol = solve_dae(F, t_span, y0, yp0, atol=atol, rtol=rtol, method=method, t_eval=t_eval)
t = sol.t
y = sol.y
# visualization
fig, ax = plt.subplots()
ax.plot(t, y[0], label="y1")
ax.plot(t, y[1] * 1e4, label="y2 * 1e4")
ax.plot(t, y[2], label="y3")
ax.set_xlabel("t")
ax.set_xscale("log")
ax.legend()
ax.grid()
plt.show()
More examples are given in the examples directory, which includes
- ordinary differential equations (ODE's)
- differential algebraic equations (DAE's)
- implicit differential equations (IDE's)
In order to investigate the work precision of the implemented solvers, we use different DAE examples with differentiation index 1, 2 and 3 as well as IDE examples.
Brenan's index 1 problem is described by the system of differential algebraic equations
For the consistent initial conditions
This problem is solved for
Clearly, the family of Radau IIA methods outplay the BDF/NDF methods for low tolerances. For medium to high tolerances, both methods are appropriate.
The knife edge index 2 problem is a simple mechanical example with nonholonomic constraint. It is described by the system of differential algebraic equations
Since the implemented solvers are designed for index 1 DAE's we have to perform some sort of index reduction. Therefore, we transform the semi-explicit form into a general form as proposed by Gear. The resulting index 1 system is given as
For the initial conditions
with the Lagrange multiplier
This problem is solved for
Arevalo's index 3 problem describes the motion of a particle on a circular track. It is described by the system of differential algebraic equations
Since the implemented solvers are designed for index 1 DAE's we have to perform some sort of index reduction. Therefore, we use the stabilized index 1 formulation of Hiller and Anantharaman. The resulting index 1 system is given as
The analytical solution to this problem is given by
with the Lagrange multipliers
This problem is solved for
A simple example of an implicit differential equations is called Weissinger's equation
It has the analytical solution
Starting at
In a final example, an nonlinear index 1 DAE is investigated as proposed by Kvaernø. The system is given by
It has the analytical solution
Starting at
An editable developer mode can be installed via
python -m pip install -e .[dev]
The tests can be started using
python -m pytest --cov