• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    Fortran
  • Created about 13 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy access in Python to a large collection of ODE solvers

What is Odespy?

Odespy (ODE Software in Python) offers a unified interface to a large collection of software for solving systems of ordinary differential equations (ODEs). There is also some support for Differential Algebraic Equations (DAEs).

You can pronounce Odespy by first saying the acronym ODE, for ordinary differential equations, in English (or in another language!) and then adding "spy" as in the English word spy.

How do I install Odespy?

Pip

Odespy requires Python version 2.7. The simplest procedure for installing Odespy is to use pip:

Terminal> sudo pip install -e git+https://github.com/hplgit/odespy.git#egg=odespy

Clone/fork repo

Alternatively, you can check out this repo and run setup.py:

Terminal> git clone [email protected]:hplgit/odespy.git
Terminal> cd odespy
Terminal> sudo python setup.py install

Turning off Fortran compilation

If you face problems with compiling the Fortran parts of Odespy, or if you do not have a Fortran compiler, you can install without any Fortran code:

Terminal> sudo python setup.py install --no-fortran

Problems with compiled Fortran modules and Anaconda

Problems with the compiled Fortran libraries appear on different systems. If you use Anaconda Python, successfully build the Fortran modules, but get error messages like cannot find extension module _rkf, the problem may be related to GFortran 1.4. You may try

Terminal> cd /path/to/anaconda/lib/
Terminal> mv libgfortran.so.3.0.0 libgfortran.so.3.0.0.bak
Terminal> ln -sf /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0 \
          libgfortran.so.3.0.0

See also this link.

Problems with compiled Fortran modules on Windows

There have been various problems with compiling Odespy on Windows, usually related to the Fortran compiler. One recommended technique is to rely on Anaconda on Windows, install the ming32 compiler, and then run

Terminal> python setup.py install build --compiler=ming32

This may give problems of the type

File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\gnu.py",
line 333, in get_libraries
raise NotImplementedError("Only MS compiler supported with gfortran on win64")
NotImplementedError: Only MS compiler supported with gfortran on win64

A remedy is to edit the gnu.py file and comment out the NotImplementedError:

else:
    #raise NotImplementedError("Only MS compiler supported with gfortran on win64")
    pass

Install Pre-compiled Version with Conda

If you are using Anaconda or Miniconda and a build has been published for your system, then you can install a pre-compiled version of Odespy. Install using conda with the following command:

Terminal> conda install -c https://conda.binstar.org/rothnic odespy

If a pre-compiled package is not available for your system, and you go through the effort of installing the compilation tools, you can build and upload a conda package as follows from the command line:

# Set environment variable in windows to build for python 2
# Use 34 instead of 27, to compile for python 3
set CONDA_PY=27

# Build the package
conda build odespy

# Upload the package
binstar upload <PATH to the build file>\odespy-<version>-<dependency versions>.tar.bz2

Notice. You may have to add/modify the conda build scripts to support your platform type. This has only been tested for Windows so far.

Contents of Odespy

Odespy features the following collection of numerical methods and implementations:

  • Pure Python implementations of classical explicit schemes such as the Forward Euler method (also called Euler); Runge-Kutta methods of 2nd, 3rd, and 4th order; Heun's method; Adams-Bashforth methods of 2nd, 3rd, and 4th order; Adams-Bashforth-Moulton methods of 2nd and 3rd order.
  • Pure Python implementations of classical implicit schemes such as Backward Euler; 2-step backward scheme; the theta rule; the Midpoint (or Trapezoidal) method.
  • Pure Python implementations of adaptive explicit Runge-Kutta methods of type Runge-Kutta-Fehlberg of order (4,5), Dormand-Prince of order (4,5), Cash-Karp of order (4,5), Bogacki-Shampine of order (2,3).
  • Wrappers for all FORTRAN solvers in ODEPACK.
  • Wrappers for the wrappers of FORTRAN solvers in scipy: vode and zvode (adaptive Adams or BDF from vode.f); dopri5 (adaptive Dormand-Prince method of order (4,5)); dop853 (adaptive Dormand-Prince method of order 8(5,3)); odeint (adaptive Adams or BDF, basically the same as vode, but in the implementation lsoda from ODEPACK).
  • Wrapper for the Runge-Kutta-Chebyshev formulas of order 2 as offered by the well-known FORTRAN code rkc.f.
  • Wrapper for the Runge-Kutta-Fehlberg method of order (4,5) as provided by the well-known FORTRAN code rkf45.f.
  • Wrapper for the Radau5 method as provided by the well-known FORTRAN code radau5.f. There have been some unidentified problems with running this solver (segmentation fault).
  • Wrapper for some solvers in the odelab.

The ODE problem can always be specified in Python, but for wrappers of FORTRAN codes one can also implement the problem in FORTRAN and avoid callback to Python.

Warning: Potential problems with FORTRAN codes. Some users have faced problems with some of the FORTRAN-based solvers (typically segmentation fault errors), mostly radau5, but also rkf45. It seems that Odespy's Python interface to radau5 is broken.

How do I use Odespy?

Here is an example on the Odespy syntax

def f(u, t):
    """2x2 system for a van der Pool oscillator."""
    return [u[1], 3.*(1. - u[0]*u[0])*u[1] - u[0]]

import odespy, numpy
solver = odespy.Vode(f, rtol=0.0, atol=1e-6,
                     adams_or_bdf='adams', order=10)
solver.set_initial_condition([2.0, 0.0])
t_points = numpy.linspace(0, 30, 150)
u, t = solver.solve(t_points)

u0 = u[:,0]
from matplotlib.pyplot import *
plot(t, u0)
show()

An incomplete tutorial is under development and explains much more of the syntax and provides many examples.

I have used Odespy in a publication - how do I cite it?

Please cite this GitHub repository:

H. P. Langtangen and L. Wang. Odespy software package. URL: https://github.com/hplgit/odespy. 2015

BibTeX entry:

@misc{odespy,
  title = {{Odespy} Software Package},
  author = {H. P. Langtangen and L. Wang},
  url = {https://github.com/hplgit/odespy},
  key = {odespy},
  note = {\url{https://github.com/hplgit/odespy}},
  year = {2015},
}

Publish entry:

* misc
** {Odespy} Software Package
   key:       odespy
   author:    H. P. Langtangen, L. Wang
   url:       https://github.com/hplgit/odespy
   status:    published
   sortkey:   Odespy
   year:      2015
   note:      \url{https://github.com/hplgit/odespy}
   entrytype: misc

More Repositories

1

fenics-tutorial

Source files and published documents for the FEniCS tutorial.
TeX
352
star
2

doconce

Lightweight markup language - document once, include anywhere
R
312
star
3

num-methods-for-PDEs

Lecture material on numerical methods for partial differential equations.
Python
246
star
4

scipro-primer

Software and additional material for the book "A Primer on Scientific Programming with Python"
HTML
187
star
5

fdm-book

Resources for "The Craft of Finite Difference Computing with Partial Differential Equations" by H. P. Langtangen
Python
162
star
6

prog4comp

Resources for the book "Programming for Computations" by S. Linge and H. P. Langtangen
Python
120
star
7

fem-book

Dockerfile
107
star
8

web4sciapps

Examples on using web frameworks for making scientific applications.
66
star
9

scitools

Additional scientific computing functionality in Python - extensions to NumPy/SciPy++
Python
64
star
10

pysketcher

Python-based drawing tool for making sketches of mechanics problems.
Python
57
star
11

INF5620

Course material from 2013 for the course INF5620 Numerical Solution of Partial Differential Equations
Python
41
star
12

MAlley-slide-templates

Templates for Michael Alley's assertion-evidence design of slides.
JavaScript
40
star
13

bumpy

Quick tutorial of scientific computing with Python using a real physics application.
36
star
14

hplgit.github.com

HPL's public site at github.com
HTML
27
star
15

preprocess

C/C++ preprocessor-like tool for a range of languages (i.e., #ifdef, #ifndef, #if-else, #include, etc. for Python, LaTeX, Bash, JavaScript, "whatever").
Python
24
star
16

parampool

Set and retrieve parameters for simulation models using diverse interfaces (command line, web GUI, file)
Python
23
star
17

scaling-book

Resources for the book "Scaling of Differential Equations".
Python
17
star
18

virtual-classroom

Scripts for automating GitHub classrooms.
Python
16
star
19

decay-book

Resources for the book "Finite Difference Computing with Exponential Decay Models" by H. P. Langtangen
Python
13
star
20

bioinf-py

Illustrating Python via examples from bioinformatics
Python
13
star
21

setup4book-doconce

Flexible setup for writing a book as assembly of chapters written in DocOnce markup.
Python
13
star
22

vagrantbox

Tutorial for Vagrant boxes and related technologies such as virtualenv.
12
star
23

primer.html

HTML versions of chapters from the "primer" book.
11
star
24

quiztools

Tools for automating the definition of a quiz at web sites such as Kahoot, Google forms, JotForm.
Python
10
star
25

physical-quantities

The PhysicalQuantity class made independent of K. Hinsen's ScientificPython package.
Python
9
star
26

ppde

Examples on solving PDEs in parallel, with tools like petsc4py.
Python
8
star
27

fenics-mixed

Tutorial on how to combine FEniCS applications in Python with software written in other languages.
JavaScript
6
star
28

MC_cython

Illustrating Cython and other tools for connecting Python and C, using Monte Carlo simulation as example
5
star
29

cse-physics

Paper on the Computing in Science Education project and its impact on physics education.
2
star
30

drink.py

Recipe for the "drink.py" cocktail.
Python
2
star
31

scalar-vector-fields

Python tools for computing with and plotting scalar and vector fields.
2
star
32

uio-thesis

LaTeX setup for a PhD thesis at the University of Oslo.
TeX
1
star
33

configparam

Python
1
star
34

pyhpc

Exploration of high-performance computing tools for Python
Python
1
star
35

animate

Documentation of how to make animations from individual plot frames.
Shell
1
star
36

SpectralDNS-paper

TeX
1
star
37

drug-book

The drug modeling book by Aslak Tveito and Glenn T. Lines translated to DocOnce.
TeX
1
star
38

disease-modeling

A basic introduction to disease modeling.
1
star