Coder Social home page Coder Social logo

microno95 / desolver Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 4.0 4.84 MB

A Python library for solving Initial Value Problems using various numerical integration methods.

License: Other

Python 100.00%
numerical-integrators pytorch numpy ordinary-differential-equations initial-value-problem python ode numerical-methods

desolver's Introduction

DESolver

Build Status Documentation Status codecov BCH compliance

This is a python package for solving Initial Value Problems using various numerical integrators. Many integration routines are included ranging from fixed step to symplectic to adaptive integrators.

Documentation

Documentation is now available at desolver docs! This will be updated with new examples as they are written, currently the examples show the use of pyaudi.

Latest Release

4.2.0 - Improved performance of implicit methods, added embedded implicit methods following Kroulíková (2017) for fully implicit adaptive integration.

4.1.0 - Initial release of implicit integration schemes that use a basic newton-raphson algorithm to solve for the intermediate states.

3.0.0 - PyAudi support has been finalised. It is now possible to do numerical integrations using gdual variables such as gdual_double, gdual_vdouble and gdual_real128 (only on select platforms, refer to pyaudi docs for more information). Install desolver with pyaudi support using pip install desolver[pyaudi]. Documentation has also been added and is available at desolver docs.

2.5.0 - Event detection has been added to the module. It is now possible to do numerical integration with terminal and non-terminal events.

2.2.0 - PyTorch backend is now implemented. It is now possible to numerically integrate a system of equations that use pytorch tensors and then compute gradients from these.

Use of PyTorch backend requires installation of PyTorch from here.

To Install:

Just type

pip install desolver

Implemented Integration Methods

Explicit Methods

Adaptive Methods
  1. Runge-Kutta 14(12) (Feagin, 2009)
  2. Runge-Kutta 10(8) (Feagin, 2009)
  3. Runge-Kutta 8(7) (Dormand & Prince, 1980)
  4. Runge-Kutta 4(5) with Cash-Karp Coefficients
  5. Adaptive Heun-Euler Method
Fixed Step Methods
  1. Symplectic BABs9o7H Method (Mads & Nielsen, 2015, BAB's9o7H)
  2. Symplectic ABAs5o6HA Method (Mads & Nielsen, 2015, ABAs5o6H)
  3. Runge-Kutta 5 - The 5th order integrator from RK45 with Cash-Karp Coefficients.
  4. Runge-Kutta 4 - The classic RK4 integrator
  5. Midpoint Method
  6. Heun's Method
  7. Euler's Method
  8. Euler-Trapezoidal Method

Implicit Methods [NEW]

Adaptive Methods
  1. Lobatto IIIC 4(2) (Kroulíková, 2017)
  2. Radau IIA 5(2) (Kroulíková, 2017)
Fixed Step Methods
  1. Backward Euler
  2. Implicit Midpoint
  3. Crank-Nicolson
  4. Lobatto IIIA 2
  5. Lobatto IIIB 2
  6. Lobatto IIIC 2
  7. Radau IA 3
  8. Radau IIA 3
  9. Lobatto IIIA 4
  10. Lobatto IIIB 4
  11. Gauss-Legendre 4
  12. Radau IA 5
  13. Radau IIA 6

Minimal Working Example

This example shows the integration of a harmonic oscillator using DESolver.

import desolver as de
import desolver.backend as D

def rhs(t, state, k, m, **kwargs):
    return D.array([[0.0, 1.0], [-k/m,  0.0]])@state

y_init = D.array([1., 0.])

a = de.OdeSystem(rhs, y0=y_init, dense_output=True, t=(0, 2*D.pi), dt=0.01, rtol=1e-9, atol=1e-9, constants=dict(k=1.0, m=1.0))

print(a)

a.integrate()

print(a)

print("If the integration was successful and correct, a[0].y and a[-1].y should be near identical.")
print("a[0].y  = {}".format(a[0].y))
print("a[-1].y = {}".format(a[-1].y))

print("Maximum difference from initial state after one oscillation cycle: {}".format(D.max(D.abs(a[0].y-a[-1].y))))

References

Feagin, T. (2009). High-Order Explicit Runge-Kutta Methods. Retrieved from https://sce.uhcl.edu/rungekutta/

Dormand, J. R. and Prince, P. J. (1980) A family of embedded Runge-Kutta formulae. Journal of Computational and Applied Mathematics, 6(1), 19-26. https://doi.org/10.1016/0771-050X(80)90013-3

Mads, K. and Nielsen, E. (2015). Efficient fourth order symplectic integrators for near-harmonic separable Hamiltonian systems. Retrieved from https://arxiv.org/abs/1501.04345

Kroulíková, T. (2017). RUNGE-KUTTA METHODS (Master's thesis, BRNO UNIVERSITY OF TECHNOLOGY, Brno, Czechia). Retrieved from https://www.vutbr.cz/www_base/zav_prace_soubor_verejne.php?file_id=174714

desolver's People

Contributors

microno95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

desolver's Issues

DESolver installation

i installed DESolver on a macbook pro (macos high sierra v10.13.3, 2.3 GHz Intel Core i7) with:
python3 -m pip install DESolver
and everything went ok but i tried:
octavioDarioMacBookPro:~ octavioDario$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import DESolver
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'DESolver'

then, as you told to me, i tried:
octavioDarioMacBookPro:~ octavioDario$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import desolver
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/desolver/init.py", line 1, in
from .differentialsystem import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/desolver/differentialsystem.py", line 35, in
import desolver.integrationschemes as ischemes
ModuleNotFoundError: No module named 'desolver.integrationschemes'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.