├── .gitignore ├── .nojekyll ├── 2DO ├── README.do.txt ├── README.md ├── README.sh ├── bld.bat ├── build.sh ├── clean.sh ├── doc ├── README ├── api │ ├── .buildinfo │ ├── README │ ├── RungeKutta.html │ ├── _images │ │ ├── gaussian1_Fehlberg_41.png │ │ ├── gaussian1_RK2_41.png │ │ ├── logistic1.png │ │ ├── osc1a.png │ │ └── osc2.png │ ├── _modules │ │ ├── index.html │ │ └── odespy │ │ │ ├── RungeKutta.html │ │ │ ├── odepack.html │ │ │ ├── problems.html │ │ │ ├── problems_pde.html │ │ │ ├── radau5.html │ │ │ ├── rkc.html │ │ │ ├── rkf45.html │ │ │ ├── runtests.html │ │ │ └── solvers.html │ ├── _sources │ │ ├── RungeKutta.txt │ │ ├── index.txt │ │ ├── odepack.txt │ │ ├── odespy.txt │ │ ├── problems.txt │ │ ├── problems_pde.txt │ │ ├── radau5.txt │ │ ├── rkc.txt │ │ ├── rkf45.txt │ │ ├── runtests.txt │ │ ├── solvers.txt │ │ └── version.txt │ ├── _static │ │ ├── ajax-loader.gif │ │ ├── basic.css │ │ ├── comment-bright.png │ │ ├── comment-close.png │ │ ├── comment.png │ │ ├── dialog-note.png │ │ ├── dialog-seealso.png │ │ ├── dialog-topic.png │ │ ├── dialog-warning.png │ │ ├── doctools.js │ │ ├── down-pressed.png │ │ ├── down.png │ │ ├── epub.css │ │ ├── file.png │ │ ├── footerbg.png │ │ ├── headerbg.png │ │ ├── ie6.css │ │ ├── jquery.js │ │ ├── middlebg.png │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── pyramid.css │ │ ├── searchtools.js │ │ ├── transparent.gif │ │ ├── underscore.js │ │ ├── up-pressed.png │ │ ├── up.png │ │ └── websupport.js │ ├── genindex.html │ ├── index.html │ ├── np-modindex.html │ ├── objects.inv │ ├── odepack.html │ ├── odespy.html │ ├── problems.html │ ├── problems_pde.html │ ├── py-modindex.html │ ├── radau5.html │ ├── rkc.html │ ├── rkf45.html │ ├── runtests.html │ ├── search.html │ ├── searchindex.js │ ├── solvers.html │ └── version.html ├── pub │ └── tutorial │ │ ├── .nojekyll │ │ ├── README │ │ ├── fig-odespy │ │ ├── gaussian1_Fehlberg_41.pdf │ │ ├── gaussian1_Fehlberg_41.png │ │ ├── gaussian1_RK2_41.pdf │ │ ├── gaussian1_RK2_41.png │ │ ├── gaussian3_41.pdf │ │ ├── gaussian3_41.png │ │ ├── gaussian3_41_Em10.pdf │ │ ├── gaussian3_41_Em10.png │ │ ├── gaussian3e_41.pdf │ │ ├── gaussian3e_41.png │ │ ├── logistic1.pdf │ │ ├── logistic1.png │ │ ├── osc1a.pdf │ │ ├── osc1a.png │ │ ├── osc1b.pdf │ │ ├── osc1b.png │ │ ├── osc2.pdf │ │ ├── osc2.png │ │ ├── osc_EC_30.pdf │ │ ├── osc_EC_30.png │ │ ├── sode1.pdf │ │ └── sode1.png │ │ ├── html │ │ ├── .buildinfo │ │ ├── _images │ │ │ ├── exos1a.png │ │ │ ├── exos1b.png │ │ │ ├── exos2.png │ │ │ ├── exsos1.png │ │ │ ├── gaussian1_Fehlberg_41.png │ │ │ ├── gaussian1_RK2_41.png │ │ │ ├── gaussian3_41.png │ │ │ ├── gaussian3_41_Em10.png │ │ │ ├── gaussian3e_41.png │ │ │ ├── logistic1.png │ │ │ ├── osc1a.png │ │ │ ├── osc2.png │ │ │ ├── osc_EC_30.png │ │ │ └── sode1.png │ │ ├── _sources │ │ │ ├── index.txt │ │ │ └── main_odespy.txt │ │ ├── _static │ │ │ ├── ajax-loader.gif │ │ │ ├── basic.css │ │ │ ├── cbc_banner.png │ │ │ ├── cbc_logo.png │ │ │ ├── comment-bright.png │ │ │ ├── comment-close.png │ │ │ ├── comment.png │ │ │ ├── default.css │ │ │ ├── dialog-note.png │ │ │ ├── dialog-seealso.png │ │ │ ├── dialog-topic.png │ │ │ ├── dialog-warning.png │ │ │ ├── doctools.js │ │ │ ├── down-pressed.png │ │ │ ├── down.png │ │ │ ├── epub.css │ │ │ ├── file.png │ │ │ ├── footerbg.png │ │ │ ├── headerbg.png │ │ │ ├── ie6.css │ │ │ ├── jquery.js │ │ │ ├── middlebg.png │ │ │ ├── minus.png │ │ │ ├── plus.png │ │ │ ├── pygments.css │ │ │ ├── pyramid.css │ │ │ ├── searchtools.js │ │ │ ├── sidebar.js │ │ │ ├── transparent.gif │ │ │ ├── underscore.js │ │ │ ├── up-pressed.png │ │ │ ├── up.png │ │ │ └── websupport.js │ │ ├── genindex.html │ │ ├── index.html │ │ ├── main_odespy.html │ │ ├── objects.inv │ │ ├── search.html │ │ └── searchindex.js │ │ ├── odespy-solarized.html │ │ ├── odespy.html │ │ └── odespy.pdf ├── src │ ├── api │ │ ├── README │ │ ├── clean.sh │ │ ├── cpapi.sh │ │ └── make.py │ └── tutorial │ │ ├── .dict4spell.txt │ │ ├── clean.sh │ │ ├── cptut.sh │ │ ├── fig-odespy │ │ ├── gaussian1_Fehlberg_41.pdf │ │ ├── gaussian1_Fehlberg_41.png │ │ ├── gaussian1_RK2_41.pdf │ │ ├── gaussian1_RK2_41.png │ │ ├── gaussian3_41.pdf │ │ ├── gaussian3_41.png │ │ ├── gaussian3_41_Em10.pdf │ │ ├── gaussian3_41_Em10.png │ │ ├── gaussian3e_41.pdf │ │ ├── gaussian3e_41.png │ │ ├── logistic1.pdf │ │ ├── logistic1.png │ │ ├── osc1a.pdf │ │ ├── osc1a.png │ │ ├── osc1b.pdf │ │ ├── osc1b.png │ │ ├── osc2.pdf │ │ ├── osc2.png │ │ ├── osc_EC_30.pdf │ │ ├── osc_EC_30.png │ │ ├── sode1.pdf │ │ └── sode1.png │ │ ├── main_odespy.do.txt │ │ ├── make.sh │ │ ├── odespy.do.txt │ │ └── src-odespy │ │ ├── SIR1.py │ │ ├── SIR2.py │ │ ├── SIRV1.py │ │ ├── SIRV2.py │ │ ├── SIRV3.py │ │ ├── SIRV4.py │ │ ├── complex1.py │ │ ├── complex2.py │ │ ├── decay1.py │ │ ├── decay2.py │ │ ├── decay3.py │ │ ├── diskarray.py │ │ ├── duffing1.py │ │ ├── exfh1.py │ │ ├── expt2.py │ │ ├── gaussian1.py │ │ ├── gaussian2.py │ │ ├── gaussian3.py │ │ ├── gaussian4.py │ │ ├── growth1.py │ │ ├── growth2.py │ │ ├── growth3.py │ │ ├── growth4.py │ │ ├── inverse1.py │ │ ├── inverse2.py │ │ ├── logistic1.py │ │ ├── logistic10.py │ │ ├── logistic2.py │ │ ├── logistic3.py │ │ ├── logistic4.py │ │ ├── logistic5.py │ │ ├── logistic6.py │ │ ├── logistic7.py │ │ ├── logistic8.py │ │ ├── logistic9.py │ │ ├── matplotlib2scitools.sh │ │ ├── motivation1.py │ │ ├── motivation2.py │ │ ├── osc1a.py │ │ ├── osc1b.py │ │ ├── osc2.py │ │ ├── osc3.py │ │ ├── osc4.py │ │ ├── osc_EC.py │ │ ├── pde_diffusion.py │ │ ├── scitools2matplotlib.sh │ │ └── sode1.py ├── web-old │ └── index.html └── web │ ├── images │ ├── body-bg.png │ ├── highlight-bg.jpg │ ├── hr.png │ ├── octocat-icon.png │ ├── tar-gz-icon.png │ └── zip-icon.png │ ├── index.html │ ├── javascripts │ └── main.js │ ├── params.json │ └── stylesheets │ ├── print.css │ ├── pygment_trac.css │ └── stylesheet.css ├── meta.yaml ├── odespy ├── PyDSTool.py ├── RungeKutta.py ├── __init__.py ├── demos │ ├── demo_AdaptiveResidual.py │ ├── demo_Lsodar_1.py │ ├── demo_Lsodar_2.py │ ├── demo_Lsodar_2_fortran.py │ ├── demo_Lsode_Lsoda_1.py │ ├── demo_Lsode_Lsoda_1_fortran.py │ ├── demo_Lsode_Lsoda_2.py │ ├── demo_Lsode_Lsoda_2_fortran.py │ ├── demo_Lsode_Lsoda_3.py │ ├── demo_Lsode_Lsoda_3_fortran.py │ ├── demo_Lsodes.py │ ├── demo_Lsodes_fortran.py │ ├── demo_Lsodi_1.py │ ├── demo_Lsodi_1_fortran.py │ ├── demo_Lsodi_2.py │ ├── demo_Lsodis_1.py │ ├── demo_Lsodis_2.py │ ├── demo_Lsoibt_1.py │ ├── demo_Lsoibt_2.py │ ├── demo_MyRungeKutta.py │ ├── demo_RKC_1.py │ ├── demo_RKC_1_fortran.py │ ├── demo_RKC_2.py │ ├── demo_RKC_2_fortran.py │ ├── demo_Radau5_1.py │ ├── demo_Radau5_2.py │ ├── demo_Radau5_2_fortran.py │ ├── demo_Radau5_3.py │ ├── demo_Radau5_3_fortran.py │ ├── demo_Radau5_4.py │ ├── demo_Radau5_4_fortran.py │ ├── demo_Radau5_5.py │ ├── demo_Radau5_5_fortran.py │ ├── demo_basics_complex_Pi.py │ ├── demo_basics_exponential.py │ ├── demo_basics_sine.py │ ├── demo_basics_van_der_pol.py │ └── demo_odelab.py ├── odepack.py ├── odepack │ ├── odepack.pyf │ ├── opkda1.f │ ├── opkda2.f │ ├── opkdmain.f │ └── solve_odepack.f ├── problems.py ├── problems_pde.py ├── radau5.py ├── radau5 │ ├── LICENSE.txt │ ├── advance_radau5.f │ ├── radau11_spec.pdf │ ├── radau5.f │ ├── radau5.pyf │ └── radaua.f ├── rkc.py ├── rkc │ ├── rkc.f │ ├── rkc.pyf │ └── solve_rkc.f ├── rkf45.py ├── rkf45 │ ├── advance_rkf45.f │ ├── rkf45.f │ ├── rkf45.pyf │ └── rkf45_associate.f ├── runtests.py ├── setup.py ├── solvers.py ├── tests │ ├── joblib_ex.py │ ├── test_ThetaRule.py │ └── test_basics.py └── version.py ├── sandbox ├── examples │ ├── 2D_mass_spring_animation.m │ ├── Baseball_trajectory.m │ ├── Baseball_trajectory.pdf │ ├── elastic_pendulum.py │ ├── mechanic │ │ ├── decsol.f │ │ ├── dr_iso.f │ │ ├── dr_isosp.f │ │ ├── dr_phem56.f │ │ ├── hem5.f │ │ ├── hem5.ps │ │ ├── lapack.f │ │ ├── linsp.f │ │ ├── phem56.f │ │ └── phem56.ps │ ├── odedemo2.m │ ├── pendulum2_as_DAE.txt │ ├── pendulum_as_DAE.m │ ├── pendulum_with_moving_top │ │ ├── .DS_Store │ │ ├── cartpendulum.m │ │ └── notes.pdf │ ├── rotateface.m │ ├── springmass2.m │ └── twodof.m ├── liwei │ └── master-thesis │ │ ├── ode_thesis.pdf │ │ ├── ode_thesis.tex │ │ ├── odespy_slides.odp │ │ └── odespy_slides.pdf └── potential_packages │ ├── Assimulo-2.0 │ ├── CHANGELOG │ ├── INSTALL │ ├── PKG-INFO │ ├── README │ ├── assimulo │ │ ├── __init__.py │ │ ├── constants.pxi │ │ ├── examples │ │ │ ├── __init__.py │ │ │ ├── cvode_basic.py │ │ │ ├── cvode_gyro.py │ │ │ ├── cvode_with_disc.py │ │ │ ├── cvode_with_initial_sensitivity.py │ │ │ ├── cvode_with_jac.py │ │ │ ├── cvode_with_jac_spgmr.py │ │ │ ├── cvode_with_parameters.py │ │ │ ├── euler_basic.py │ │ │ ├── ida_with_disc.py │ │ │ ├── ida_with_initial_sensitivity.py │ │ │ ├── ida_with_jac.py │ │ │ ├── ida_with_parameters.py │ │ │ ├── radau5dae_vanderpol.py │ │ │ ├── radau5ode_vanderpol.py │ │ │ ├── rungekutta34_basic.py │ │ │ └── rungekutta4_basic.py │ │ ├── exception.py │ │ ├── explicit_ode.c │ │ ├── explicit_ode.pxd │ │ ├── explicit_ode.pyx │ │ ├── implicit_ode.c │ │ ├── implicit_ode.pxd │ │ ├── implicit_ode.pyx │ │ ├── kinsol.py │ │ ├── lib │ │ │ ├── __init__.py │ │ │ ├── kinpinv.c │ │ │ ├── kinpinv.h │ │ │ ├── kinslug.h │ │ │ ├── kinsol_jmod.c │ │ │ ├── kinsol_jmod.h │ │ │ ├── kinsol_jmod_impl.h │ │ │ ├── kinsol_jmod_impl_wSLU.h │ │ │ ├── kinsol_jmod_wSLU.h │ │ │ ├── radau_core.py │ │ │ ├── reg_routines.h │ │ │ ├── sundials_callbacks.pxi │ │ │ ├── sundials_constants.pxi │ │ │ ├── sundials_includes.pxd │ │ │ ├── sundials_kinsol_core.pxi │ │ │ ├── sundials_kinsol_core.pyx │ │ │ ├── sundials_kinsol_core_wSLU.pxd │ │ │ ├── sundials_kinsol_core_wSLU.pyx │ │ │ └── sundials_kinsol_includes.pxi │ │ ├── ode.c │ │ ├── ode.pxd │ │ ├── ode.pyx │ │ ├── problem.c │ │ ├── problem.pyx │ │ ├── problem_algebraic.py │ │ ├── solvers │ │ │ ├── __init__.py │ │ │ ├── euler.c │ │ │ ├── euler.pyx │ │ │ ├── radau5.py │ │ │ ├── runge_kutta.py │ │ │ ├── sundials.c │ │ │ └── sundials.pyx │ │ └── tests │ │ │ ├── __init__.py │ │ │ ├── solvers │ │ │ ├── __init__.py │ │ │ ├── test_euler.py │ │ │ ├── test_radau5.py │ │ │ ├── test_rungekutta.py │ │ │ └── test_sundials.py │ │ │ ├── test_KINSOL.py │ │ │ ├── test_examples.py │ │ │ ├── test_explicit_ode.py │ │ │ ├── test_implicit_ode.py │ │ │ └── test_ode.py │ └── setup.py │ ├── dmv10 │ ├── dmv10.f │ └── dr_dmv10.f │ ├── gnimatlab │ ├── Contents.m │ ├── coeff_comp.m │ ├── coeff_irk2.m │ ├── coeff_lmm2.m │ ├── gni_comp.m │ ├── gni_irk2.m │ ├── gni_lmm2.m │ ├── gnievents.m │ ├── gniget.m │ ├── gniset.m │ ├── henon.m │ ├── kepler.m │ ├── phaseplot.m │ ├── rattwo.m │ ├── sphereplot.m │ ├── stverl.m │ └── twobodysphere.m │ ├── rock │ ├── examples │ │ ├── dr_bruss2d_rock.f │ │ ├── dr_burgersm_rock.f │ │ └── dr_finag_rock.f │ ├── rock2.f │ └── rock4.f │ └── sdirk │ ├── dc_decsol.f │ ├── decsol.f │ └── sdirk4.f └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.pyc 3 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/.nojekyll -------------------------------------------------------------------------------- /README.sh: -------------------------------------------------------------------------------- 1 | # Compile README.do.txt to GitHub-extended Markdown using DocOnce 2 | doconce format pandoc README --github_md 3 | -------------------------------------------------------------------------------- /bld.bat: -------------------------------------------------------------------------------- 1 | python setup.py build --compiler=mingw32 2 | if errorlevel 1 exit 1 3 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | python setup.py build 2 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -rf build 3 | find . \( -name '*.pyc' -o -name '*~' \) -exec rm -rf {} \; 4 | -------------------------------------------------------------------------------- /doc/README: -------------------------------------------------------------------------------- 1 | Directory for documentation. 2 | 3 | src: source code for documentation. 4 | 5 | All other directories are automatically generated from the corresponding 6 | directories under src/ and contain the official versions of the 7 | documentation. 8 | -------------------------------------------------------------------------------- /doc/api/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: b8d2014b3430607e1550c904ff3d933d 4 | tags: fbb0d17656682115ca4d033fb2f83ba1 5 | -------------------------------------------------------------------------------- /doc/api/README: -------------------------------------------------------------------------------- 1 | This directory contains the API documentation for the package. 2 | The documentation is automatically generated by ../src/api/make.py. 3 | -------------------------------------------------------------------------------- /doc/api/_images/gaussian1_Fehlberg_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_images/gaussian1_Fehlberg_41.png -------------------------------------------------------------------------------- /doc/api/_images/gaussian1_RK2_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_images/gaussian1_RK2_41.png -------------------------------------------------------------------------------- /doc/api/_images/logistic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_images/logistic1.png -------------------------------------------------------------------------------- /doc/api/_images/osc1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_images/osc1a.png -------------------------------------------------------------------------------- /doc/api/_images/osc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_images/osc2.png -------------------------------------------------------------------------------- /doc/api/_sources/RungeKutta.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.RungeKutta` 3 | ======================== 4 | 5 | .. automodule:: odespy.RungeKutta 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/index.txt: -------------------------------------------------------------------------------- 1 | .. Odespy API documentation master file, created by 2 | sphinx-quickstart on Thu Apr 26 09:34:46 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Odespy API 7 | ====================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | odespy 15 | rkc 16 | version 17 | odepack 18 | problems_pde 19 | solvers 20 | problems 21 | rkf45 22 | runtests 23 | RungeKutta 24 | radau5 25 | 26 | 27 | 28 | Indices and tables 29 | ================== 30 | 31 | * :ref:`genindex` 32 | * :ref:`modindex` 33 | * :ref:`search` 34 | 35 | -------------------------------------------------------------------------------- /doc/api/_sources/odepack.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.odepack` 3 | ===================== 4 | 5 | .. automodule:: odespy.odepack 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/odespy.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy` 3 | ============= 4 | 5 | .. automodule:: odespy 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/problems.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.problems` 3 | ====================== 4 | 5 | .. automodule:: odespy.problems 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/problems_pde.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.problems_pde` 3 | ========================== 4 | 5 | .. automodule:: odespy.problems_pde 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/radau5.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.radau5` 3 | ==================== 4 | 5 | .. automodule:: odespy.radau5 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/rkc.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.rkc` 3 | ================= 4 | 5 | .. automodule:: odespy.rkc 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/rkf45.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.rkf45` 3 | =================== 4 | 5 | .. automodule:: odespy.rkf45 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/runtests.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.runtests` 3 | ====================== 4 | 5 | .. automodule:: odespy.runtests 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/solvers.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.solvers` 3 | ===================== 4 | 5 | .. automodule:: odespy.solvers 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_sources/version.txt: -------------------------------------------------------------------------------- 1 | 2 | :mod:`odespy.version` 3 | ===================== 4 | 5 | .. automodule:: odespy.version 6 | :members: 7 | :undoc-members: 8 | :special-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /doc/api/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/ajax-loader.gif -------------------------------------------------------------------------------- /doc/api/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/comment-bright.png -------------------------------------------------------------------------------- /doc/api/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/comment-close.png -------------------------------------------------------------------------------- /doc/api/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/comment.png -------------------------------------------------------------------------------- /doc/api/_static/dialog-note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/dialog-note.png -------------------------------------------------------------------------------- /doc/api/_static/dialog-seealso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/dialog-seealso.png -------------------------------------------------------------------------------- /doc/api/_static/dialog-topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/dialog-topic.png -------------------------------------------------------------------------------- /doc/api/_static/dialog-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/dialog-warning.png -------------------------------------------------------------------------------- /doc/api/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/down-pressed.png -------------------------------------------------------------------------------- /doc/api/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/down.png -------------------------------------------------------------------------------- /doc/api/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/file.png -------------------------------------------------------------------------------- /doc/api/_static/footerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/footerbg.png -------------------------------------------------------------------------------- /doc/api/_static/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/headerbg.png -------------------------------------------------------------------------------- /doc/api/_static/ie6.css: -------------------------------------------------------------------------------- 1 | * html img, 2 | * html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", 3 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", 4 | this.src = "_static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), 5 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", 6 | this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) 7 | );} 8 | -------------------------------------------------------------------------------- /doc/api/_static/middlebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/middlebg.png -------------------------------------------------------------------------------- /doc/api/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/minus.png -------------------------------------------------------------------------------- /doc/api/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/plus.png -------------------------------------------------------------------------------- /doc/api/_static/transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/transparent.gif -------------------------------------------------------------------------------- /doc/api/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/up-pressed.png -------------------------------------------------------------------------------- /doc/api/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/_static/up.png -------------------------------------------------------------------------------- /doc/api/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/api/objects.inv -------------------------------------------------------------------------------- /doc/pub/tutorial/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/.nojekyll -------------------------------------------------------------------------------- /doc/pub/tutorial/README: -------------------------------------------------------------------------------- 1 | This directory contains published versions of the tutorial for the odespy 2 | package. 3 | 4 | * html: sphinx version 5 | * odespy.pdf: classic LaTeX version 6 | * odespy.html: HTML bootstrap 7 | * odespy-solarized.html: HTML w/solarized colors 8 | 9 | The files are automatically generated by ../src/odespy/make.sh. 10 | -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian1_Fehlberg_41.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian1_Fehlberg_41.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian1_Fehlberg_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian1_Fehlberg_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian1_RK2_41.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian1_RK2_41.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian1_RK2_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian1_RK2_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3_41.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3_41.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3_41_Em10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3_41_Em10.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3_41_Em10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3_41_Em10.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3e_41.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3e_41.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/gaussian3e_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/gaussian3e_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/logistic1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/logistic1.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/logistic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/logistic1.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc1a.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc1a.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc1a.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc1b.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc1b.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc1b.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc2.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc2.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc_EC_30.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc_EC_30.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/osc_EC_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/osc_EC_30.png -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/sode1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/sode1.pdf -------------------------------------------------------------------------------- /doc/pub/tutorial/fig-odespy/sode1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/fig-odespy/sode1.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 12abf71e4135ce40f5edc02b03cdfd5a 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/exos1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/exos1a.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/exos1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/exos1b.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/exos2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/exos2.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/exsos1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/exsos1.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/gaussian1_Fehlberg_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/gaussian1_Fehlberg_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/gaussian1_RK2_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/gaussian1_RK2_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/gaussian3_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/gaussian3_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/gaussian3_41_Em10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/gaussian3_41_Em10.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/gaussian3e_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/gaussian3e_41.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/logistic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/logistic1.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/osc1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/osc1a.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/osc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/osc2.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/osc_EC_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/osc_EC_30.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_images/sode1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_images/sode1.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_sources/index.txt: -------------------------------------------------------------------------------- 1 | 2 | .. Master file automatically created by doconce sphinx_dir 3 | 4 | A Tutorial for the Odespy Interface to ODE Solvers 5 | ================================================== 6 | 7 | Contents: 8 | 9 | .. toctree:: 10 | :maxdepth: 3 11 | 12 | main_odespy 13 | 14 | 15 | Indices and tables 16 | ================== 17 | 18 | * :ref:`genindex` 19 | * :ref:`modindex` 20 | * :ref:`search` 21 | -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/cbc_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/cbc_banner.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/cbc_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/cbc_logo.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/comment-bright.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/comment-close.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/comment.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/dialog-note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/dialog-note.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/dialog-seealso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/dialog-seealso.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/dialog-topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/dialog-topic.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/dialog-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/dialog-warning.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/down-pressed.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/down.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/file.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/footerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/footerbg.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/headerbg.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/ie6.css: -------------------------------------------------------------------------------- 1 | * html img, 2 | * html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", 3 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", 4 | this.src = "_static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), 5 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", 6 | this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) 7 | );} 8 | -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/middlebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/middlebg.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/minus.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/plus.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/transparent.gif -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/up-pressed.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/_static/up.png -------------------------------------------------------------------------------- /doc/pub/tutorial/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/html/objects.inv -------------------------------------------------------------------------------- /doc/pub/tutorial/odespy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/pub/tutorial/odespy.pdf -------------------------------------------------------------------------------- /doc/src/api/README: -------------------------------------------------------------------------------- 1 | Run 2 | 3 | python make.py 4 | 5 | to generate new documentation. If it is ok, copy it to the destination 6 | by 7 | 8 | sh cpapi.sh 9 | 10 | clean.sh cleans up the files in this directory. 11 | 12 | Note: The doc string in __init__.py must be copied from the tutorial 13 | when the tutorial is updated. 14 | 15 | -------------------------------------------------------------------------------- /doc/src/api/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -rf api *~ tmp.out -------------------------------------------------------------------------------- /doc/src/api/cpapi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copy the Sphinx API doc 3 | 4 | dest=../../api 5 | rm -rf $dest 6 | cp -r api/_build/html $dest 7 | 8 | cat > $dest/README < $dest/README <= 6 and t <= 15 else 0 19 | #p = lambda t: 0.1 20 | 21 | solver = odespy.Euler(f, f_args=(beta, nu, p)) 22 | solver.set_initial_condition([S0, I0, 0, 0]) 23 | dt = 0.5 # t counts days 24 | T = 60 25 | N = int(T/dt) 26 | t = np.linspace(0, T, N+1) 27 | u, t = solver.solve(t) 28 | S, I, R, V = u[:,0], u[:,1], u[:,2], u[:,3] 29 | 30 | from matplotlib.pyplot import * 31 | plot(t, S, 'r-', 32 | t, I, 'b-', 33 | t, R, 'g-', 34 | t, V, 'y-') 35 | legend(['S', 'I', 'R', 'V']) 36 | savefig('tmppng'); savefig('tmp.pdf') 37 | show() 38 | 39 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/SIRV2.py: -------------------------------------------------------------------------------- 1 | """As SIRV1.py, but animating the effect of varying p.""" 2 | 3 | def f(u, t, beta, nu, p): 4 | S, I, R, V = u 5 | return [-beta*S*I - p(t)*S, 6 | beta*S*I - nu*I, 7 | nu*I, 8 | p(t)*S] 9 | 10 | import odespy 11 | import numpy as np 12 | import sys, time 13 | import matplotlib.pyplot as plt 14 | 15 | def simulate(beta, nu, p, S0, I0, frame_counter=0, mpl_lines=None): 16 | solver = odespy.Euler(f, f_args=(beta, nu, p)) 17 | solver.set_initial_condition([S0, I0, 0, 0]) 18 | dt = 0.5 # t counts days 19 | T = 60 20 | N = int(T/dt) 21 | t = np.linspace(0, T, N+1) 22 | u, t = solver.solve(t) 23 | S, I, R, V = u[:,0], u[:,1], u[:,2], u[:,3] 24 | 25 | if mpl_lines is None: 26 | mpl_lines = plt.plot(t, S, 'r-', 27 | t, I, 'b-', 28 | t, R, 'g-', 29 | t, V, 'y-') 30 | else: 31 | for line, func in zip(mpl_lines, [S, I, R, V]): 32 | line.set_ydata(func) 33 | plt.draw() 34 | plt.legend(['S', 'I', 'R', 'V']) 35 | plt.title('beta=%.4f, nu=%.1f, p=%.2f' % (beta, nu, p(T))) 36 | plt.savefig('tmp_%04d.png' % frame_counter) 37 | frame_counter += 1 38 | time.sleep(1) 39 | return frame_counter, mpl_lines 40 | 41 | # beta = 0.0005; nu = 0.1; I0 = 1; p = 0.1 42 | I0 = 1 43 | S0 = 1500. 44 | beta = 0.0005 45 | nu = 0.1 46 | p = 0.1 47 | mpl_lines = None 48 | frame_counter = 0 49 | plt.ion() # key 50 | p_list = np.logspace(0.000001, 0.3, 12) 51 | for p in p_list: 52 | frame_counter, mpl_lines = \ 53 | simulate(beta, nu, lambda t: np.log10(p) if t > 8 else 0, 54 | S0, I0, frame_counter, mpl_lines) 55 | #plt.show() 56 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/SIRV3.py: -------------------------------------------------------------------------------- 1 | """As SIRV1.py, but computing max I(t) as a function of vaccination period.""" 2 | 3 | def f(u, t, beta, nu, p): 4 | S, I, R, V = u 5 | return [-beta*S*I - p(t)*S, 6 | beta*S*I - nu*I, 7 | nu*I, 8 | p(t)*S] 9 | 10 | import odespy 11 | import numpy as np 12 | import sys, time 13 | 14 | def simulate(beta, nu, p0, S0, I0, V_T): 15 | p = lambda t: p0 if 6 <= t <= 6+V_T else 0 16 | solver = odespy.Euler(f, f_args=(beta, nu, p)) 17 | solver.set_initial_condition([S0, I0, 0, 0]) 18 | dt = 0.5 # t counts days 19 | T = 60 20 | N = int(T/dt) 21 | t = np.linspace(0, T, N+1) 22 | u, t = solver.solve(t) 23 | I = u[:,1] 24 | return I.max() 25 | 26 | I0 = 1 27 | S0 = 1500. 28 | beta = 0.0005 29 | nu = 0.1 30 | p0 = 0.1 31 | V_Ts = np.linspace(0, 30, 31) 32 | I_max = np.array([simulate(beta, nu, p0, S0, I0, V_T) for V_T in V_Ts]) 33 | 34 | tol = 5 # tolerance for comparing I_max[i] with final I_max[-1] 35 | i = 0 36 | print I_max 37 | while I_max[i] - I_max[-1] > tol: 38 | i += 1 39 | print 'No use in letting V_T > %d' % (V_Ts[i]) 40 | 41 | import matplotlib.pyplot as plt 42 | plt.plot(V_Ts, I_max, 'b-') 43 | plt.legend(['max I(t)']) 44 | #plt.title('max I(t) as function of vaccination period') 45 | plt.savefig('tmp.png'); plt.savefig('tmp.pdf') 46 | plt.show() 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/SIRV4.py: -------------------------------------------------------------------------------- 1 | """As SIRV1.py, but seasonal change in beta.""" 2 | 3 | def f(u, t, beta, nu, p, mu, rho): 4 | S, I, R, V = u 5 | return [-beta(t)*S*I - p(t)*S + mu*R + rho*V, 6 | beta(t)*S*I - nu*I, 7 | nu*I - mu*R, 8 | p(t)*S - rho*V] 9 | 10 | import odespy 11 | import numpy as np 12 | import sys 13 | 14 | I0 = 1 15 | S0 = 1500. 16 | period = 360 17 | beta = lambda t: 0.0003*np.sin(np.pi/period*t)**6 18 | nu = 1./10 19 | mu = 1./100 20 | rho = 1./150 21 | p = lambda t: 0.01*np.sin(np.pi/period*(t-50))**6 22 | p = lambda t: 0.0 23 | 24 | solver = odespy.Euler(f, f_args=(beta, nu, p, mu, rho)) 25 | solver.set_initial_condition([S0, I0, 0, 0]) 26 | dt = 0.5 # t counts days 27 | T = 1400 28 | N = int(T/dt) 29 | t = np.linspace(0, T, N+1) 30 | u, t = solver.solve(t) 31 | S, I, R, V = u[:,0], u[:,1], u[:,2], u[:,3] 32 | 33 | from matplotlib.pyplot import * 34 | plot(t, S, 'r-', 35 | t, I, 'b-', 36 | t, R, 'g-', 37 | t, V, 'y-') 38 | legend(['S', 'I', 'R', 'V']) 39 | savefig('tmppng'); savefig('tmp.pdf') 40 | show() 41 | 42 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/complex1.py: -------------------------------------------------------------------------------- 1 | def f(u, t): 2 | return 1j*w*u 3 | 4 | import odespy, numpy 5 | 6 | w = 2*numpy.pi 7 | solver = odespy.RK4(f, complex_valued=True) 8 | solver.set_initial_condition(1+0j) 9 | u, t = solver.solve(numpy.linspace(0, 6, 101)) 10 | 11 | from matplotlib.pyplot import * 12 | plot(t, u.real) 13 | show() 14 | 15 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/complex2.py: -------------------------------------------------------------------------------- 1 | """As complex1.py, but comparison of zvode and RK4.""" 2 | 3 | def f(u, t): 4 | return 1j*w*u 5 | 6 | import odespy, numpy, time 7 | 8 | w = 2*numpy.pi 9 | n = 600 # no of periods 10 | r = 40 # resolution of each period 11 | tp = numpy.linspace(0, n, n*r+1) 12 | 13 | solvers = [odespy.Vode(f, complex_valued=True, 14 | atol=1E-7, rtol=1E-6, 15 | adams_or_bdf='adams'), 16 | odespy.RK4(f, complex_valued=True), 17 | odespy.RKFehlberg(f, complex_valued=True, 18 | atol=1E-7, rtol=1E-6)] 19 | cpu = [] 20 | for solver in solvers: 21 | solver.set_initial_condition(1+0j) 22 | t0 = time.clock() 23 | solver.solve(tp) 24 | t1 = time.clock() 25 | cpu.append(t1-t0) 26 | 27 | # Compare solutions at the end point: 28 | exact = numpy.exp(1j*w*tp).real[-1] 29 | min_cpu = min(cpu); cpu = [c/min_cpu for c in cpu] # normalize 30 | print 'Exact: u(%g)=%g' % (tp[-1], exact) 31 | for solver, cpu_time in zip(solvers, cpu): 32 | print '%-15s u(%g)=%.6f (error: %10.2E, cpu: %.1f)' % \ 33 | (solver.__class__.__name__, 34 | solver.t[-1], solver.u[-1].real, 35 | exact - solver.u[-1].real, cpu_time) 36 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/decay1.py: -------------------------------------------------------------------------------- 1 | """Simple example of decay ODE integrated until asymptotic value is reached.""" 2 | c = -0.1 3 | A = 1.5 4 | 5 | def f(u, t): 6 | return c*u 7 | 8 | import odespy 9 | solver = odespy.RK4(f) 10 | solver.set_initial_condition(A) 11 | 12 | import numpy 13 | # Make sure integration interval [0, T] is large enough 14 | N = 50 15 | T = 150 16 | time_points = numpy.linspace(0, T, N+1) 17 | 18 | tol = 0.001 # tolerance for terminating the simulation 19 | 20 | def terminate(u, t, step_no): 21 | # Most recent solution is in u[step_no] at time t[step_no] 22 | if abs(u[step_no]) <= tol: 23 | return True 24 | else: 25 | return False 26 | 27 | u, t = solver.solve(time_points, terminate) 28 | 29 | print "Solve u'=%g*u, u(0)=%g, for t in [%g, %g] and u>%g" % \ 30 | (c, A, time_points[0], time_points[-1], tol) 31 | print 'Final u(t=%g)=%g after %d steps' % (t[-1], u[-1], len(u)-1) 32 | 33 | from matplotlib.pyplot import * 34 | print plot 35 | plot(t, u) 36 | show() 37 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/decay2.py: -------------------------------------------------------------------------------- 1 | """As exde1.py, but y and x as names instead of u and t.""" 2 | 3 | def myrhs(y, x): 4 | return -y 5 | 6 | import odespy 7 | solver = odespy.RK4(myrhs) 8 | solver.set_initial_condition(1) 9 | 10 | import numpy 11 | # Make sure integration interval [0, L] is large enough 12 | N = 50 13 | L = 10 14 | x_points = numpy.linspace(0, L, N+1) 15 | 16 | def terminate(y, x, stepnumber): 17 | tol = 0.001 18 | return True if abs(y[stepnumber]) < tol else False 19 | 20 | y, x = solver.solve(x_points, terminate) 21 | 22 | print 'Final y(x=%g)=%g' % (x[-1], y[-1]) 23 | 24 | from matplotlib.pyplot import * 25 | plot(x, y) 26 | show() 27 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/decay3.py: -------------------------------------------------------------------------------- 1 | """As exde1.py, but no terminate function and AdaptiveResidual as solver.""" 2 | c = -1 3 | A = 1 4 | 5 | def f(u, t): 6 | return c*u 7 | 8 | import odespy 9 | solver = odespy.AdaptiveResidual(f, solver='Euler', atol=1E-3) 10 | solver.set_initial_condition(A) 11 | 12 | import numpy 13 | # Make sure integration interval [0, T] is large enough 14 | N = 20 15 | T = 4 16 | time_points = numpy.linspace(0, T, N+1) 17 | 18 | u, t = solver.solve(time_points) 19 | 20 | print 'Final u(t=%g)=%g after %d steps' % (t[-1], u[-1], len(u)-1) 21 | 22 | from matplotlib.pyplot import * 23 | plot(t, u) 24 | show() 25 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/diskarray.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | class DiskArray: 3 | def __init__(self, size, in_memory=3): 4 | if isinstance(size, int): 5 | stored_size = tuple(size) 6 | self.idxmap = np.zeros(size, dtype=np.int) 7 | elif isinstance(size, (tuple,list)): 8 | stored_size = list(size) 9 | stored_size[0] = in_memory 10 | self.idxmap = np.zeros(size[0], dtype=np.int) 11 | self.array = np.zeros(stored_size) 12 | self.stored = self.array.size 13 | # shelve 14 | 15 | def _next(self, idx): 16 | idx = tuple(idx) # can be a slice! 17 | idx0 = idx[0] 18 | if idx0 < self.stored-1: 19 | return idx0 + 1 20 | elif: 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/duffing1.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy 2 | from numpy import sin, cos, pi, sqrt 3 | 4 | c = 1 5 | Theta = pi/4 6 | 7 | def f(u, t): 8 | x, dxdt = u 9 | return [dxdt, cos(t)**3 - sin(t) - x - dxdt - x**3] 10 | 11 | def u_exact(t): 12 | return cos(t) 13 | 14 | solver = odespy.RK4(f) 15 | solver.set_initial_condition([1, 0]) 16 | N_P = 120 # no of periods 17 | T = 2*pi*N_P 18 | Ns_per_period = [40, 80, 160, 320] 19 | for N_per_period in Ns_per_period: 20 | N = N_per_period*N_P 21 | time_points = numpy.linspace(0, T, N+1) 22 | u, t = solver.solve(time_points) 23 | 24 | x = u[:,0] 25 | v = u[:,1] 26 | error = u_exact(t) - x 27 | dt = t[1] - t[0] 28 | print N_per_period, numpy.abs(error).max(), numpy.abs(error).max()/dt**4 29 | 30 | import sys 31 | sys.exit(0) 32 | from matplotlib.pyplot import * 33 | i = -10*N_per_period # start index for the last 10 periods 34 | plot(t[i:], error[i:], 'r-') 35 | savefig('tmppng'); savefig('tmp.pdf') 36 | show() 37 | 38 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/exfh1.py: -------------------------------------------------------------------------------- 1 | """The FitzHugh-Nagumo model from biology.""" 2 | 3 | def f(u, t, s=10, a=0.12, c1=0.175, c2=0.03, b=0.011, d=0.55): 4 | v, w = u 5 | fv = s*c1*v*(v - a)*(1 - v) - s*c2*w 6 | fw = s*b*(v - d*w) 7 | return [fv, fw] 8 | 9 | def jac(u, t, s=10, a=0.12, c1=0.175, c2=0.03, b=0.011, d=0.55): 10 | v, w = u 11 | return [[(1+a)*2*v*c1 - a*c1 - 3*v**2*c1, c2], 12 | [b, -b*d]] 13 | 14 | 15 | v0 = 0.1 16 | w0 = 0.0 17 | T = 50 18 | 19 | import odespy, numpy as np, scitools.std as st 20 | a = 0.12 # stable 21 | a = -0.12 # unstable 22 | solver = odespy.ForwardEuler(f, jac=jac, f_kwargs={'a': a}) 23 | solver.set_initial_condition([v0, w0]) 24 | time_points = np.linspace(0, T, 401) 25 | #time_points = np.linspace(0, T, 21) 26 | u, t = solver.solve(time_points) 27 | v = u[:,0] 28 | w = u[:,1] 29 | st.plot(t, v, 'r-', 30 | t, w, 'b-', 31 | legend=('v', 'w')) 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/expt2.py: -------------------------------------------------------------------------------- 1 | """Gaussian function for testing adaptivity.""" 2 | 3 | from odespy.problems import Logistic 4 | from numpy import exp, linspace 5 | 6 | import odespy 7 | problem = Logistic(a=2, R=1, U0=0.0001) 8 | solver = odespy.RKFehlberg 9 | #solver = odespy.lsoda_scipy 10 | #solver = odespy.Lsoda 11 | solver = odespy.RK4 12 | solver = solver(problem.f, verbose=2, first_step=1.100, 13 | u_exact=problem.u_exact, atol=1E-6, rtol=1E-6) 14 | solver.set_initial_condition(problem.u_exact(0)) 15 | 16 | T = 10 17 | dt = 0.5 18 | N = round(int(T/float(dt))) 19 | time_points = linspace(0, T, N+1) 20 | u, t = solver.solve(time_points) 21 | print u 22 | 23 | from matplotlib.pyplot import * 24 | plot(t, u, 'r-o', 25 | t, problem.u_exact(t), 'x') 26 | try: 27 | hold('on') 28 | plot(solver.t_all, solver.u_all, 'o') 29 | except: 30 | pass 31 | show() 32 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/gaussian1.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np, matplotlib.pyplot as plt 2 | 3 | center_point = 3 4 | s = 0.5 5 | 6 | problem = odespy.problems.Gaussian1(c=center_point, s=s) 7 | 8 | npoints = 41 9 | tp = np.linspace(0, 2*center_point, npoints) 10 | 11 | method = odespy.RK2 12 | solver = method(problem.f) 13 | solver.set_initial_condition(problem.U0) 14 | 15 | u, t = solver.solve(tp) 16 | 17 | method = solver.__class__.__name__ 18 | print '%.4f %s' % (u.max(), method) 19 | 20 | if solver.has_u_t_all(): 21 | plt.plot(solver.t_all, solver.u_all, 'bo', 22 | tp, problem.u_exact(tp)) 23 | print '%s used %d steps (%d specified)' % \ 24 | (method, len(solver.u_all), len(tp)) 25 | else: 26 | plt.plot(tp, solver.u, tp, problem.u_exact(tp)) 27 | plt.legend([method, 'exact']) 28 | plt.savefig('tmppng'); plt.savefig('tmp.pdf') 29 | plt.show() 30 | 31 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/gaussian2.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np, matplotlib.pyplot as plt 2 | 3 | center_point = 3 4 | s = 0.5 5 | 6 | problem = odespy.problems.Gaussian1(c=center_point, s=s) 7 | 8 | npoints = 41 9 | tp = np.linspace(0, 2*center_point, npoints) 10 | 11 | rtol = 1E-12 12 | atol = rtol 13 | min_step = 0.000001 14 | 15 | solver = odespy.Fehlberg(problem.f, atol=atol, rtol=rtol, 16 | min_step=min_step) 17 | solver.set_initial_condition(problem.U0) 18 | 19 | u, t = solver.solve(tp) 20 | 21 | method = solver.__class__.__name__ 22 | print '%.8f %s' % (u.max(), method) 23 | 24 | if solver.has_u_t_all(): 25 | plt.plot(solver.t_all, solver.u_all, 'bo', 26 | tp, problem.u_exact(tp), 'g-') 27 | print '%s used %d steps (%d specified)' % \ 28 | (method, len(solver.u_all), len(tp)) 29 | else: 30 | plt.plot(tp, solver.u, tp, problem.u_exact(tp)) 31 | plt.legend([method, 'exact']) 32 | plt.savefig('tmppng'); plt.savefig('tmp.pdf') 33 | plt.show() 34 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/gaussian3.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np, matplotlib.pyplot as plt 2 | 3 | def run(problem, tp, solver): 4 | method = solver.__class__.__name__ 5 | 6 | solver.set_initial_condition(problem.U0) 7 | 8 | u, t = solver.solve(tp) 9 | solver.u_max = u.max() 10 | print '%.4f %s' % (solver.u_max, method) 11 | 12 | if solver.has_u_t_all(): 13 | plt.plot(solver.t_all, solver.u_all) 14 | print '%s used %d steps (%d specified)' % \ 15 | (method, len(solver.u_all), len(tp)) 16 | else: 17 | plt.plot(solver.t, solver.u) 18 | legend.append(method) 19 | plt.hold('on') 20 | 21 | rtol = 1E-6 22 | atol = rtol 23 | s = 0.5 24 | npoints = 41 25 | center_point = 3 26 | problem = odespy.problems.Gaussian1(c=center_point, s=s) 27 | tp = np.linspace(0, 2*center_point, npoints) 28 | min_step = 0.0001 29 | 30 | methods = ['DormandPrince', 'BogackiShampine', 31 | 'RKFehlberg', 'Vode', 'RKF45', 'Lsoda'] 32 | solvers = [eval('odespy.' + method)( 33 | problem.f, atol=atol, rtol=rtol, 34 | min_step=min_step) 35 | for method in methods] 36 | # Run Vode with implicit BDF method of order 5 37 | solvers[1].set(adams_or_bdf='bdf', order=5, jac=problem.jac) 38 | 39 | legend = [] 40 | for solver in solvers: 41 | run(problem, tp, solver) 42 | 43 | plt.plot(tp, problem.u_exact(tp)) 44 | legend.append('exact') 45 | plt.legend(legend) 46 | plt.savefig('tmp1.png') 47 | 48 | # Plot errors 49 | plt.figure() 50 | exact = problem.u_exact(tp) 51 | for solver in solvers: 52 | plt.plot(tp, exact - solver.u) 53 | plt.hold('on') 54 | plt.legend(legend) 55 | plt.savefig('tmp2.png') 56 | plt.show() 57 | 58 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/gaussian4.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np 2 | 3 | center_points = [2, 3, 4, 5] 4 | s = 0.5 5 | npoints = 41 6 | min_step = 0.0001 7 | 8 | results = [] 9 | for center_point in center_points: 10 | problem = odespy.problems.Gaussian1(c=center_point, s=s) 11 | tp = np.linspace(0, 2*center_point, npoints) 12 | for tol in (1E-4, 1E-6, 1E-10, 1E-12): 13 | atol = rtol = tol 14 | # Build list of solvers 15 | adaptive = ['RKFehlberg', 'Fehlberg', 'DormandPrince', 16 | 'CashKarp', 'BogackiShampine', 'Lsoda',] # 'AdaptiveResidual'] 17 | solvers = [(eval('odespy.' + method) 18 | (problem.f, atol=atol, rtol=rtol, min_step=min_step), 19 | method) 20 | for method in adaptive] 21 | stiff_nonstiff = ['Vode', 'Lsode'] 22 | solvers += [(eval('odespy.' + method) 23 | (problem.f, atol=atol, rtol=rtol, min_step=min_step, 24 | adams_or_bdf='adams'), method+'_adams') 25 | for method in stiff_nonstiff] 26 | solvers += [(eval('odespy.' + method) 27 | (problem.f, atol=atol, rtol=rtol, min_step=min_step, 28 | adams_or_bdf='bdf'), method+'_bdf') 29 | for method in stiff_nonstiff] 30 | 31 | for solver, method in solvers: 32 | 33 | solver.set_initial_condition(problem.U0) 34 | 35 | u, t = solver.solve(tp) 36 | u_max = u.max() 37 | solver.u_max = u_max # store key result 38 | 39 | print '%s: u_max=%g c/s=%g %s' % \ 40 | (method, solver.u_max, center_point/s, str(solver)) 41 | 42 | results.append((method, center_point, tol, u_max)) 43 | 44 | # Make results2[method][center_point][tol] = u_max 45 | from collections import OrderedDict 46 | results2 = OrderedDict() 47 | for method, center_point, tol, u_max in results: 48 | if method not in results2: 49 | results2[method] = {} 50 | if center_point not in results2[method]: 51 | results2[method][center_point] = {} 52 | if tol not in results2[method][center_point]: 53 | results2[method][center_point][tol] = {} 54 | results2[method][center_point][tol] = u_max 55 | 56 | print '\n\n=======================================================' 57 | for method in results2: 58 | for center_point in results2[method]: 59 | for tol in results2[method][center_point]: 60 | print '%s, c=%g, tol=%E, u_max=%.6f' % \ 61 | (method, center_point, tol, 62 | results2[method][center_point][tol]) 63 | # print '\n' 64 | # print '\n\n' 65 | 66 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/growth1.py: -------------------------------------------------------------------------------- 1 | """Simple example of exponential growth ODE.""" 2 | c = 0.1 3 | A = 1.5 4 | 5 | def f(u, t): 6 | return c*u 7 | 8 | import odespy 9 | solver = odespy.RK4(f) 10 | solver.set_initial_condition(A) 11 | 12 | import numpy 13 | N = 30 # no of time steps 14 | time_points = numpy.linspace(0, 40, N+1) 15 | u, t = solver.solve(time_points) 16 | 17 | from matplotlib.pyplot import * 18 | plot(t, u) 19 | show() 20 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/growth2.py: -------------------------------------------------------------------------------- 1 | """ 2 | As expgr1.py, but class for right-hand side function and 3 | comparison with exact solution. 4 | """ 5 | 6 | class ExponentialGrowth: 7 | def __init__(self, c=1, A=1): 8 | self.c, self.A = c, A 9 | 10 | def __call__(self, u, t): 11 | return self.c*u 12 | 13 | f = ExponentialGrowth(c=0.1, A=1.5) 14 | 15 | import odespy 16 | solver = odespy.RK4(f) 17 | solver.set_initial_condition(f.A) 18 | 19 | import numpy 20 | N = 30 # no of time steps 21 | time_points = numpy.linspace(0, 40, N+1) 22 | u, t = solver.solve(time_points) 23 | 24 | u_exact = f.A*numpy.exp(f.c*t) 25 | error = numpy.abs(u_exact - u).max() 26 | print 'Max deviation of numerical solution:', error 27 | 28 | from matplotlib.pyplot import * 29 | plot(t, u, 'r-', t, u_exact, 'bo') 30 | legend(['RK4, N=%d' % N, 'exact']) 31 | show() 32 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/growth3.py: -------------------------------------------------------------------------------- 1 | """As exgr1.py, but c as argument in f.""" 2 | c = 0.1 3 | A = 1.5 4 | import odespy 5 | 6 | # f has extra positional argument 7 | def f(u, t, c): 8 | return c*u 9 | 10 | solver = odespy.RK4(f, f_args=[c]) 11 | 12 | # Alternative: f has extra keyword argument 13 | def f(u, t, c=1): 14 | return c*u 15 | 16 | solver = odespy.RK4(f, f_kwargs={'c': c}) 17 | solver.set_initial_condition(A) 18 | 19 | import numpy 20 | N = 30 21 | time_points = numpy.linspace(0, 40, N+1) 22 | u, t = solver.solve(time_points) 23 | 24 | from matplotlib.pyplot import * 25 | plot(t, u) 26 | show() 27 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/growth4.py: -------------------------------------------------------------------------------- 1 | """As exgr1.py, but several consequtive calls to solve.""" 2 | c = 0.1 3 | A = 1.5 4 | 5 | def f(u, t): 6 | return c*u 7 | 8 | import odespy, numpy 9 | from matplotlib.pyplot import * 10 | 11 | solver = odespy.RK4(f) 12 | 13 | # Split time domain into subdomains and 14 | # integrate the ODE in each subdomain 15 | T = [0, 3, 6, 10, 20, 40] 16 | 17 | N_tot = 30 # no of time intervals in total 18 | dt = float(T[-1])/N_tot # time step, kept fixed 19 | u = []; t = [] # collectors for u and t 20 | 21 | for i in range(len(T)-1): 22 | T_interval = T[i+1] - T[i] 23 | N = int(round(T_interval/dt)) 24 | time_points = numpy.linspace(T[i], T[i+1], N+1) 25 | 26 | solver.set_initial_condition(A) # at time_points[0] 27 | print 'Solving in [%s, %s] with %d intervals' % \ 28 | (T[i], T[i+1], N) 29 | ui, ti = solver.solve(time_points) 30 | A = ui[-1] # newest u is next initial condition 31 | 32 | plot(ti, ui) 33 | hold('on') 34 | 35 | u.append(ui); t.append(ti) 36 | 37 | # Can concatenate all the elements of u and t, if desired 38 | u = numpy.concatenate(u); t = numpy.concatenate(t) 39 | #plot(t, u, 'bo') # same curve 40 | show() 41 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/inverse1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find the inverse of a function f(x). 3 | Common solver: solve y = f(x) wrt x. 4 | Here we differentiate to find x'(y) = 1/f'(x). x(0)=q where f(q)=0. 5 | Solving the ODE for x(y) constructs the inverse of f. 6 | """ 7 | 8 | def rhs(x, y, f, h=1E-4): 9 | dfdx = (f(x+h) - f(x))/h 10 | return 1./dfdx 11 | 12 | from numpy import sqrt, linspace 13 | 14 | def f(x): 15 | return sqrt(x) 16 | #return 2*x 17 | 18 | import odespy 19 | solver = odespy.RungeKutta2(rhs, f_args=[f], f_kwargs={'h': 1E-3}) 20 | solver.set_initial_condition(0) 21 | y_points = linspace(0, 4, 41) 22 | x, y = solver.solve(y_points) 23 | from matplotlib.pyplot import * 24 | g_e = lambda y: y**2 # exact inverse function 25 | y_ = linspace(0, 4, 11) 26 | plot(y, x, 'r-', 27 | x, f(x), 'b-', 28 | y_, g_e(y_), 'go') 29 | legend(['computed inverse', 'original f(x)', 'exact inverse']) 30 | savefig('tmppng'); savefig('tmp.pdf') 31 | show() 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/inverse2.py: -------------------------------------------------------------------------------- 1 | """As inverse1.py, but wrapped in a reusable class.""" 2 | import numpy as np 3 | import odespy 4 | 5 | class Inverse: 6 | """ 7 | Compute the inverse function of some given function f(x). 8 | Method: solve an ODE for the inverse function. 9 | """ 10 | def __init__(self, f, x0, I=[0,1], h=1E-4, resolution=400): 11 | self.f, self.I, self.h, self.x0 = f, I, h, x0 12 | self.resolution = resolution 13 | 14 | # Check that f(x0)=I[0] 15 | froot = abs(f(x0)-I[0]) 16 | if froot > 1E-3: 17 | raise ValueError( 18 | 'abs(f(x0)-%s)=%s - not a root of f(x)=I[0]' % \ 19 | (I[0], froot)) 20 | 21 | def _rhs(self, x, y): 22 | dfdx = (self.f(x + self.h) - self.f(x))/self.h 23 | return 1./dfdx 24 | 25 | def discrete(self): 26 | """Solve dx/dxy = 1/f'(x), x(I[0])=x0.""" 27 | self.y = np.linspace(self.I[0], self.I[1], self.resolution+1) 28 | solver = odespy.RungeKutta4(self._rhs) 29 | solver.set_initial_condition(self.x0) 30 | self.x, self.y = solver.solve(self.y) 31 | return self.x, self.y 32 | 33 | def continuous(self): 34 | if not hasattr(self, 'x') and hasattr(self, 'y'): 35 | self.discrete() 36 | from scitools.numpyutils import wrap2callable 37 | self.g = wrap2callable((self.y, self.x)) 38 | return self.g 39 | 40 | def verify(self): 41 | """Check that g(f(x)) = x.""" 42 | x = np.linspace(self.I[0], self.I[1], self.resolution+1) 43 | x2 = self.g(self.f(x)) 44 | return np.abs(x - x2).max() 45 | 46 | def _test(): 47 | 48 | def f(x): 49 | return np.sqrt(x) 50 | 51 | inverse = Inverse(f, x0=0, I=[0, 4], resolution=10) 52 | x, y = inverse.discrete() 53 | g = inverse.continuous() 54 | print 'max error:', inverse.verify() 55 | 56 | from matplotlib.pyplot import plot, legend, savefig, show 57 | g_e = lambda y: y**2 # exact inverse function 58 | y_ = np.linspace(0, 4, 11) 59 | plot(y, x, 'r-', 60 | x, f(x), 'b-', 61 | y_, g_e(y_), 'go') 62 | legend(['computed inverse', 'original f(x)', 'exact inverse']) 63 | savefig('tmppng'); savefig('tmp.pdf') 64 | show() 65 | 66 | if __name__ == '__main__': 67 | _test() 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic1.py: -------------------------------------------------------------------------------- 1 | def f(u, t): 2 | return a*u*(1 - u/R) 3 | 4 | a = 2 5 | R = 1E+5 6 | A = 1 7 | 8 | import odespy 9 | solver = odespy.RK4(f) 10 | solver.set_initial_condition(A) 11 | 12 | from numpy import linspace, exp 13 | T = 10 # end of simulation 14 | N = 30 # no of time steps 15 | time_points = linspace(0, T, N+1) 16 | u, t = solver.solve(time_points) 17 | 18 | def u_exact(t): 19 | return R*A*exp(a*t)/(R + A*(exp(a*t) - 1)) 20 | 21 | from matplotlib.pyplot import * 22 | 23 | plot(t, u, 'r-', 24 | t, u_exact(t), 'bo') 25 | savefig('tmppng'); savefig('tmp.pdf') 26 | show() 27 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic10.py: -------------------------------------------------------------------------------- 1 | a = 2 2 | R = 1E+5 3 | A = 1 4 | 5 | f_f77_str = """ 6 | subroutine f_f77(neq, t, u, udot) 7 | Cf2py intent(hide) neq 8 | Cf2py intent(out) udot 9 | integer neq 10 | double precision t, u, udot 11 | dimension u(neq), udot(neq) 12 | udot(1) = %.3f*u(1)*(1 - u(1)/%.1f) 13 | return 14 | end 15 | """ % (a, R) 16 | print f_f77_str 17 | #import sys; sys.exit(1) 18 | 19 | import odespy 20 | f_f77 = odespy.compile_f77(f_f77_str) 21 | solver = odespy.Lsode(f=None, f_f77=f_f77) 22 | 23 | solver.set_initial_condition(A) 24 | 25 | from numpy import linspace 26 | T = 10 # end of simulation 27 | N = 30 # no of time steps 28 | time_points = linspace(0, T, N+1) 29 | u, t = solver.solve(time_points) 30 | 31 | from matplotlib.pyplot import * 32 | 33 | plot(t, u, 'r-') 34 | savefig('tmppng'); savefig('tmp.pdf') 35 | show() 36 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic2.py: -------------------------------------------------------------------------------- 1 | from numpy import linspace, exp 2 | 3 | class Logistic: 4 | def __init__(self, a, R, A): 5 | self.a = a 6 | self.R = R 7 | self.A = A 8 | 9 | def f(self, u, t): 10 | a, R = self.a, self.R # short form 11 | return a*u*(1 - u/R) 12 | 13 | def u_exact(self, t): 14 | a, R, A = self.a, self.R, self.A # short form 15 | return R*A*exp(a*t)/(R + A*(exp(a*t) - 1)) 16 | 17 | import odespy 18 | problem = Logistic(a=2, R=1E+5, A=1) 19 | solver = odespy.RK4(problem.f) 20 | solver.set_initial_condition(problem.A) 21 | 22 | T = 10 # end of simulation 23 | N = 30 # no of time steps 24 | time_points = linspace(0, T, N+1) 25 | u, t = solver.solve(time_points) 26 | 27 | from matplotlib.pyplot import * 28 | 29 | plot(t, u, 'r-', 30 | t, problem.u_exact(t), 'bo') 31 | savefig('tmppng'); savefig('tmp.pdf') 32 | show() 33 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic3.py: -------------------------------------------------------------------------------- 1 | from numpy import linspace 2 | 3 | def f(u, t, a=1, R=1): 4 | return a*u*(1 - u/R) 5 | 6 | A = 1 7 | 8 | import odespy 9 | solver = odespy.RK4(f, f_kwargs=dict(a=2, R=1E+5)) 10 | solver.set_initial_condition(A) 11 | 12 | T = 10 # end of simulation 13 | N = 30 # no of time steps 14 | time_points = linspace(0, T, N+1) 15 | u, t = solver.solve(time_points) 16 | 17 | from matplotlib.pyplot import * 18 | plot(t, u, 'r-') 19 | savefig('tmppng'); savefig('tmp.pdf') 20 | show() 21 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic4.py: -------------------------------------------------------------------------------- 1 | def f(u, t, a=1, R=1): 2 | return a*u*(1 - u/R) 3 | 4 | A = 1 5 | 6 | import odespy, numpy 7 | from matplotlib.pyplot import plot, hold, show, axis 8 | 9 | solver = odespy.RK4(f, f_kwargs=dict(a=2, R=1E+5)) 10 | 11 | # Split time domain into subdomains and 12 | # integrate the ODE in each subdomain 13 | T = [0, 1, 4, 8, 12] # subdomain boundaries 14 | 15 | N_tot = 30 # total no of time steps 16 | dt = float(T[-1])/N_tot # time step, kept fixed 17 | u = []; t = [] # collectors for u and t in each domain 18 | 19 | for i in range(len(T)-1): 20 | T_interval = T[i+1] - T[i] 21 | N = int(round(T_interval/dt)) 22 | time_points = numpy.linspace(T[i], T[i+1], N+1) 23 | 24 | solver.set_initial_condition(A) # at time_points[0] 25 | print 'Solving in [%s, %s] with %d intervals' % \ 26 | (T[i], T[i+1], N) 27 | ui, ti = solver.solve(time_points) 28 | A = ui[-1] # newest ui value is next initial condition 29 | 30 | plot(ti, ui) 31 | hold('on') 32 | 33 | u.append(ui); t.append(ti) 34 | 35 | axis([0, T[-1], -0.1E+5, 1.1E+5]) 36 | # Can concatenate all the elements of u and t, if desired 37 | u = numpy.concatenate(u); t = numpy.concatenate(t) 38 | savefig('tmppng'); savefig('tmp.pdf') 39 | show() 40 | #plot(t, u, 'bo') # same curve, but only one piece 41 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic5.py: -------------------------------------------------------------------------------- 1 | def f(u, t): 2 | return a*u*(1 - u/R) 3 | 4 | a = 2 5 | R = 1E+5 6 | A = 1 7 | 8 | import odespy, numpy 9 | solver = odespy.RK4(f) 10 | solver.set_initial_condition(A) 11 | 12 | T = 20 # end of simulation 13 | dt = 0.25 14 | N = int(round(T/dt)) 15 | time_points = numpy.linspace(0, T, N+1) 16 | 17 | tol = 100 # tolerance for termination criterion 18 | 19 | def terminate(u, t, step_no): 20 | """u[step_no] holds (the most recent) solution at t[step_no].""" 21 | return abs(u[step_no] - R) < tol 22 | 23 | u, t = solver.solve(time_points, terminate) 24 | print 'Final u(t=%g)=%g' % (t[-1], u[-1]) 25 | 26 | from matplotlib.pyplot import * 27 | plot(t, u, 'r-') 28 | savefig('tmppng'); savefig('tmp.pdf') 29 | show() 30 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic6.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import odespy 4 | 5 | class Logistic: 6 | def __init__(self, a, R, A, T): 7 | """ 8 | a` is (initial growth rate), `R` the carrying capacity, 9 | `A` the initial amount of u, and `T` is some (very) total 10 | simulation time when `u` is very close to the asymptotic 11 | value `R`. 12 | """ 13 | self.a, self.R, self.A = a, R, A 14 | self.tol = 0.01*R # tolerance for termination criterion 15 | 16 | def f(self, u, t): 17 | """Right-hand side of the ODE.""" 18 | a, R = self.a, self.R # short form 19 | return a*u*(1 - u/R) 20 | 21 | def terminate(self, u, t, step_no): 22 | """u[step_no] holds solution at t[step_no].""" 23 | return abs(u[step_no] - self.R) < self.tol 24 | 25 | def u_exact(self, t): 26 | a, R, A = self.a, self.R, self.A # short form 27 | return R*A*np.exp(a*t)/(R + A*(np.exp(a*t) - 1)) 28 | 29 | 30 | class Solver: 31 | def __init__(self, problem, dt, method='RK4'): 32 | self.problem = problem 33 | self.dt = dt 34 | self.method_class = eval('odespy.' + method) 35 | self.N = int(round(T/dt)) 36 | 37 | def solve(self): 38 | self.solver = self.method_class(self.problem.f) 39 | self.solver.set_initial_condition(self.problem.A) 40 | time_points = np.linspace(0, self.problem.T, self.N+1) 41 | self.u, self.t = self.solver.solve( 42 | time_points, self.problem.terminate) 43 | print 'Final u(t=%g)=%g' % (t[-1], u[-1]) 44 | 45 | def plot(self): 46 | plt.plot(self.t, self.u, 'r-', 47 | self.t, self.u_exact(self.t), 'bo') 48 | plt.legend(['numerical', 'exact']) 49 | plt.savefig('tmp.png'); plt.savefig('tmp.pdf') 50 | plt.show() 51 | 52 | def main(): 53 | problem = Logistic(a=2, R=1E+5, A=1, T=20) 54 | solver = Solver(problem, dt=0.25, method='RK4') 55 | solver.solve() 56 | solver.plot() 57 | 58 | if __name__ == '__main__': 59 | main() 60 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic7.py: -------------------------------------------------------------------------------- 1 | def f(y, x): 2 | return a*y*(1 - y/R) 3 | 4 | a = 2; R = 1E+5; A = 1 5 | 6 | import odespy, numpy 7 | solver = odespy.RK4(f) 8 | solver.set_initial_condition(A) 9 | 10 | L = 10 # end of x domain 11 | N = 30 # no of time steps 12 | x_points = numpy.linspace(0, L, N+1) 13 | y, x = solver.solve(x_points) 14 | 15 | from matplotlib.pyplot import * 16 | plot(x, y, 'r-') 17 | xlabel('x'); ylabel('y') 18 | show() 19 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic8.py: -------------------------------------------------------------------------------- 1 | def f(u, t, a=1, R=1): 2 | return a*u*(1 - u/R) 3 | 4 | A = 1 5 | 6 | import odespy 7 | solver = odespy.CashKarp(f, f_kwargs=dict(a=2, R=1E+5), 8 | first_step=9., verbose=1) 9 | solver.set_initial_condition(A) 10 | 11 | from numpy import linspace 12 | T = 10 # end of simulation 13 | N = 3 # no of time steps 14 | time_points = linspace(0, T, N+1) 15 | u, t = solver.solve(time_points) 16 | 17 | from matplotlib.pyplot import * 18 | plot(solver.t_all, solver.u_all, 'r-o') 19 | savefig('tmppng'); savefig('tmp.pdf') 20 | show() 21 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/logistic9.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np, matplotlib.pyplot as plt 2 | 3 | def run(problem, tp, solver): 4 | method = solver.__class__.__name__ 5 | 6 | solver.set_initial_condition(problem.U0) 7 | 8 | u, t = solver.solve(tp) 9 | solver.u_max = u.max() 10 | print '%.4f %s' % (solver.u_max, method) 11 | 12 | if solver.has_u_t_all(): 13 | plt.plot(solver.t_all, solver.u_all) 14 | print '%s used %d steps (%d specified)' % \ 15 | (method, len(solver.u_all), len(tp)) 16 | else: 17 | plt.plot(solver.t, solver.u) 18 | legend.append(method) 19 | plt.hold('on') 20 | 21 | rtol = 1E-6 22 | atol = rtol 23 | npoints = 41 24 | problem = odespy.problems.Logistic(a=2, R=1E+5, A=1) 25 | L = 10 26 | N = 30 27 | tp = np.linspace(0, L, N+1) 28 | min_step = 0.0001 29 | 30 | methods = ['DormandPrince', 'BogackiShampine', 31 | 'RKFehlberg', 'Vode', 'RKF45', 'Lsoda'] 32 | solvers = [eval('odespy.' + method)( 33 | problem.f, atol=atol, rtol=rtol, 34 | min_step=min_step) 35 | for method in methods] 36 | solvers[1].set(adams_or_bdf='bdf', order=4) # Vode 37 | 38 | legend = [] 39 | for solver in solvers: 40 | run(problem, tp, solver) 41 | 42 | plt.plot(tp, problem.u_exact(tp)) 43 | legend.append('exact') 44 | plt.legend(legend) 45 | plt.savefig('tmp1.png') 46 | plt.show() 47 | 48 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/matplotlib2scitools.sh: -------------------------------------------------------------------------------- 1 | scitools replace 'from scitools.std import *' 'from matplotlib.pyplot import *' *.py 2 | scitools replace 'import scitools.std as mpl' 'import matplotlib.pyplot as mpl' *.py 3 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/motivation1.py: -------------------------------------------------------------------------------- 1 | def f(u, t): 2 | return [u[1], 3.*(1. - u[0]*u[0])*u[1] - u[0]] 3 | 4 | u0 = [2.0, 0.0] 5 | import odespy, numpy 6 | 7 | for method in odespy.Lsode, odespy.DormandPrince, odespy.Vode: 8 | 9 | solver = method(f, rtol=0.0, atol=1e-6, 10 | adams_or_bdf='adams', order=10) 11 | solver.set_initial_condition(u0) 12 | t_points = numpy.linspace(0, 30, 150) 13 | u, t = solver.solve(t_points) 14 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/motivation2.py: -------------------------------------------------------------------------------- 1 | def f(u, t): 2 | return [u[1], 3.*(1. - u[0]*u[0])*u[1] - u[0]] 3 | 4 | u0 = [2.0, 0.0] 5 | import odespy, numpy, matplotlib.pyplot as plt 6 | 7 | for method in odespy.Lsode, odespy.DormandPrince, odespy.Vode: 8 | solver = method(f, rtol=0.0, atol=1e-6, 9 | adams_or_bdf='adams', order=10) 10 | solver.set_initial_condition(u0) 11 | t_points = numpy.linspace(0, 30, 150) 12 | u, t = solver.solve(t_points) 13 | 14 | plt.plot(t, u[:,0]) 15 | plt.hold('on') 16 | plt.show() 17 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/osc1a.py: -------------------------------------------------------------------------------- 1 | """Oscillating pendulum.""" 2 | 3 | import odespy, numpy 4 | from math import sin, pi, sqrt 5 | 6 | c = 1 7 | Theta = pi/4 8 | 9 | def f(u, t): 10 | theta, omega = u 11 | return [omega, -c*sin(theta)] 12 | 13 | solver = odespy.Heun(f) 14 | solver.set_initial_condition([Theta, 0]) 15 | freq = sqrt(c) # frequency of oscillations when Theta is small 16 | period = 2*pi/freq # the period of the oscillations 17 | T = 10*period # final time 18 | N_per_period = 20 # resolution of one period 19 | N = N_per_period*period 20 | time_points = numpy.linspace(0, T, N+1) 21 | 22 | u, t = solver.solve(time_points) 23 | 24 | theta = u[:,0] 25 | omega = u[:,1] 26 | 27 | from matplotlib.pyplot import * 28 | plot(t, theta, 'r-') 29 | savefig('tmppng'); savefig('tmp.pdf') 30 | show() 31 | 32 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/osc1b.py: -------------------------------------------------------------------------------- 1 | """Oscillating pendulum.""" 2 | 3 | import odespy, numpy 4 | from math import sin, pi, sqrt 5 | 6 | c = 1 7 | Theta = pi/4 8 | 9 | def f(u, t): 10 | theta, omega = u 11 | return [omega, -c*sin(theta)] 12 | 13 | solver = odespy.RK4(f) 14 | solver.set_initial_condition([Theta, 0]) 15 | freq = sqrt(c) # frequency of oscillations when Theta is small 16 | period = 2*pi/freq # the period of the oscillations 17 | T = 10*period # final time 18 | N_per_period = 20 # resolution of one period 19 | N = N_per_period*period 20 | time_points = numpy.linspace(0, T, N+1) 21 | 22 | u, t = solver.solve(time_points) 23 | 24 | theta = u[:,0] 25 | omega = u[:,1] 26 | 27 | from matplotlib.pyplot import * 28 | plot(t, theta, 'r-') 29 | savefig('tmppng'); savefig('tmp.pdf') 30 | show() 31 | 32 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/osc2.py: -------------------------------------------------------------------------------- 1 | """As osc1.py, but testing several solvers and setting sin(theta) to theta.""" 2 | 3 | from math import pi, sqrt 4 | 5 | class Problem: 6 | def __init__(self, c, Theta): 7 | self.c, self.Theta = float(c), float(Theta) 8 | 9 | self.freq = sqrt(c) 10 | self.period = 2*pi/self.freq 11 | 12 | def f(self, u, t): 13 | theta, omega = u; c = self.c 14 | return [omega, -c*theta] 15 | 16 | problem = Problem(c=1, Theta=pi/4) 17 | 18 | import odespy 19 | solvers = [ 20 | odespy.ThetaRule(problem.f, theta=0), # Forward Euler 21 | odespy.ThetaRule(problem.f, theta=0.5), # Midpoint method 22 | odespy.ThetaRule(problem.f, theta=1), # Backward Euler 23 | odespy.RK4(problem.f), 24 | odespy.MidpointIter(problem.f, max_iter=2, eps_iter=0.01), 25 | odespy.LeapfrogFiltered(problem.f), 26 | ] 27 | 28 | N_per_period = 20 29 | T = 3*problem.period # final time 30 | import numpy 31 | import matplotlib.pyplot as plt 32 | legends = [] 33 | 34 | for solver in solvers: 35 | solver_name = str(solver) # short description of solver 36 | print solver_name 37 | 38 | solver.set_initial_condition([problem.Theta, 0]) 39 | N = N_per_period*problem.period 40 | time_points = numpy.linspace(0, T, N+1) 41 | 42 | u, t = solver.solve(time_points) 43 | 44 | theta = u[:,0] 45 | legends.append(solver_name) 46 | plt.plot(t, theta) 47 | plt.hold('on') 48 | plt.legend(legends) 49 | plotfile = __file__[:-3] 50 | plt.savefig(plotfile + '.png'); plt.savefig(plotfile + '.pdf') 51 | plt.show() 52 | 53 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/osc3.py: -------------------------------------------------------------------------------- 1 | """As osc2.py, but testing several solvers.""" 2 | 3 | from math import pi, sqrt 4 | 5 | class Problem: 6 | def __init__(self, c, Theta): 7 | self.c, self.Theta = float(c), float(Theta) 8 | 9 | self.freq = sqrt(c) 10 | self.period = 2*pi/self.freq 11 | 12 | def __call__(self, u, t): 13 | theta, omega = u; c = self.c 14 | return [omega, -c*theta] 15 | 16 | problem = Problem(c=1, Theta=pi/4) 17 | 18 | import odespy 19 | solvers = [ 20 | odespy.ThetaRule(problem, theta=0), # Forward Euler 21 | odespy.ThetaRule(problem, theta=0.5), # Midpoint 22 | odespy.ThetaRule(problem, theta=1), # Backward Euler 23 | odespy.RK4(problem), 24 | odespy.RK2(problem), 25 | odespy.MidpointIter(problem, max_iter=5, eps_iter=0.01), 26 | odespy.Leapfrog(problem), 27 | odespy.LeapfrogFiltered(problem), 28 | ] 29 | 30 | theta_exact = lambda t: problem.Theta*numpy.cos(sqrt(problem.c)*t) 31 | 32 | import sys 33 | try: 34 | num_periods = int(sys.argv[1]) 35 | except IndexError: 36 | num_periods = 8 # default 37 | 38 | T = num_periods*problem.period # final time 39 | results = {} 40 | resolutions = [10, 20, 40, 80, 160] # intervals per period 41 | import numpy 42 | 43 | for solver in solvers: 44 | solver_name = str(solver) 45 | results[solver_name] = {'dt': [], 'error': []} 46 | 47 | solver.set_initial_condition([problem.Theta, 0]) 48 | 49 | for N_per_period in resolutions: 50 | N = N_per_period*num_periods 51 | time_points = numpy.linspace(0, T, N+1) 52 | 53 | u, t = solver.solve(time_points) 54 | 55 | theta = u[:,0] 56 | error = numpy.abs(theta_exact(t) - theta) 57 | error_L2 = sqrt(numpy.sum(error**2)/N) 58 | if not numpy.isnan(error_L2): # drop nan (overflow) 59 | results[solver_name]['dt'].append(t[1] - t[0]) 60 | results[solver_name]['error'].append(error_L2) 61 | 62 | # Print 63 | for solver in results: 64 | print '%-20s %s' % (solver, ' '.join(['%.1E' % e 65 | for e in results[solver]['error']])) 66 | 67 | from math import log 68 | print '\n\nConvergence results for %d periods' % num_periods 69 | for solver_name in results: 70 | r_h = results[solver_name]['dt'] 71 | r_E = results[solver_name]['error'] 72 | rates = [log(r_E[i]/r_E[i-1])/log(r_h[i]/r_h[i-1]) for i 73 | in range(1, len(r_h))] 74 | # Reformat rates with 1 decimal for rate 75 | rates = ', '.join(['%.1f' % rate for rate in rates]) 76 | print '%-20s r: %s E_min=%.1E' % \ 77 | (solver_name, rates, min(results[solver_name]['error'])) 78 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/osc_EC.py: -------------------------------------------------------------------------------- 1 | import odespy 2 | from numpy import * 3 | from matplotlib.pyplot import * 4 | 5 | def f(u, t): 6 | omega, theta = u 7 | return [-c*sin(theta), omega] 8 | 9 | c = 1 10 | Theta0_degrees = 30 11 | 12 | solver = odespy.EulerCromer(f) 13 | Theta0 = Theta0_degrees*pi/180 14 | solver.set_initial_condition([0, Theta0]) 15 | # Solve for num_periods periods using formulas for small theta 16 | freq = sqrt(c) # frequency of oscillations 17 | period = 2*pi/freq # one period 18 | N = 40 # intervals per period 19 | dt = period/N # time step 20 | num_periods = 10 21 | T = num_periods*period # total simulation time 22 | 23 | time_points = linspace(0, T, num_periods*N+1) 24 | u, t = solver.solve(time_points) 25 | 26 | # Extract components and plot theta 27 | theta = u[:,1] 28 | omega = u[:,0] 29 | theta_linear = lambda t: Theta0*cos(sqrt(c)*t) 30 | plot(t, theta, t, theta_linear(t)) 31 | legend(['Euler-Cromer', 'Linearized problem'], loc='lower left') 32 | title('Error in linearized term: %8.2g' % abs(Theta0-sin(Theta0))) 33 | savefig('tmp.pdf'); savefig('tmp.png') 34 | show() 35 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/scitools2matplotlib.sh: -------------------------------------------------------------------------------- 1 | scitools replace 'from matplotlib.pyplot import *' 'from scitools.std import *' *.py 2 | scitools replace 'import matplotlib.pyplot as mpl' 'import scitools.std as mpl' *.py 3 | -------------------------------------------------------------------------------- /doc/src/tutorial/src-odespy/sode1.py: -------------------------------------------------------------------------------- 1 | """Stochastic oscillator driven by white noise.""" 2 | 3 | 4 | class WhiteNoiseOscillator: 5 | def __init__(self, b, c, sigma=1): 6 | self.b, self.c, self.sigma = b, c, sigma 7 | 8 | def connect_solver(self, solver): 9 | """Solver is needed for time step number and size.""" 10 | self.solver = solver 11 | 12 | def f(self, u, t): 13 | if not hasattr(self, 'N'): # is self.N not yet computed? 14 | # Compute N(t) for all time intervals 15 | import numpy 16 | numpy.random.seed(12) 17 | t = self.solver.t 18 | dW = numpy.random.normal(loc=0, scale=1, size=len(t)-1) 19 | dt = t[1:] - t[:-1] 20 | self.N = self.sigma*dW/numpy.sqrt(dt) 21 | 22 | x, v = u 23 | N = self.N[self.solver.n] 24 | return [v, N -self.b*v -self.c*x] 25 | 26 | from numpy import pi, linspace 27 | from matplotlib.pyplot import * 28 | import odespy 29 | 30 | problem = WhiteNoiseOscillator(b=0.1, c=pi**2, sigma=1) 31 | solvers = [odespy.Heun(problem.f), odespy.RK4(problem.f), 32 | odespy.ForwardEuler(problem.f)] 33 | for solver in solvers: 34 | f.connect_solver(solver) 35 | solver.set_initial_condition([0,0]) # start from rest 36 | T = 60 # with c=pi**2, the period is 1 37 | u, t = solver.solve(linspace(0, T, 10001)) 38 | 39 | x = u[:,0] 40 | plot(t, x) 41 | hold(True) 42 | 43 | legend([str(s) for s in solvers]) 44 | savefig('tmppng'); savefig('tmp.pdf') 45 | show() 46 | 47 | -------------------------------------------------------------------------------- /doc/web/images/body-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/body-bg.png -------------------------------------------------------------------------------- /doc/web/images/highlight-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/highlight-bg.jpg -------------------------------------------------------------------------------- /doc/web/images/hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/hr.png -------------------------------------------------------------------------------- /doc/web/images/octocat-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/octocat-icon.png -------------------------------------------------------------------------------- /doc/web/images/tar-gz-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/tar-gz-icon.png -------------------------------------------------------------------------------- /doc/web/images/zip-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/doc/web/images/zip-icon.png -------------------------------------------------------------------------------- /doc/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | Odespy by hplgit 14 | 15 | 16 | 17 |
18 |
19 | 20 |
21 |

Odespy

22 |

ODE Solvers in Python

23 |
24 | 25 |
26 | Download .zip 27 | Download .tar.gz 28 | View on GitHub 29 |
30 | 31 |
32 | 33 |
34 | 35 | The Odespy package provides easy access to a large collection of ODE solvers through a simple Python interface. 36 | 37 |
38 |

39 |

Documentation

40 | 41 |

42 |

    43 |

  1. Tutorial: Sphinx, LaTeX/PDF 44 |

  2. API documentation 45 | 49 |
50 | 51 |

Authors

52 |

53 | Liwei Wang (ruojiao77@yahoo.com)
54 | Hans Petter Langtangen (hpl@simula.no)
55 |

56 | 57 |

Contact

58 |

Hans Petter Langtangen (hpl@simula.no)

59 |
60 | 61 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | -------------------------------------------------------------------------------- /doc/web/javascripts/main.js: -------------------------------------------------------------------------------- 1 | console.log('This would be the main JS file.'); 2 | -------------------------------------------------------------------------------- /doc/web/params.json: -------------------------------------------------------------------------------- 1 | {"name":"Num-methods-for-pdes","tagline":"Lecture material on numerical methods for partial differential equations.","body":"### Welcome to GitHub Pages.\r\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:\r\n\r\n```\r\n$ cd your_repo_root/repo_name\r\n$ git fetch origin\r\n$ git checkout gh-pages\r\n```\r\n\r\nIf you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.\r\n\r\n### Designer Templates\r\nWe've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.\r\n\r\n### Rather Drive Stick?\r\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\r\n\r\n### Authors and Contributors\r\nYou can @mention a GitHub username to generate a link to their profile. The resulting `` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} -------------------------------------------------------------------------------- /meta.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | name: odespy 3 | version: "0.3.0" 4 | 5 | source: 6 | git_url: https://github.com/hplgit/odespy 7 | 8 | requirements: 9 | build: 10 | - python 11 | - numpy 12 | - setuptools 13 | 14 | run: 15 | - python 16 | - numpy 17 | 18 | about: 19 | home: https://github.com/hplgit/odespy 20 | summary: 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).' 21 | 22 | build: 23 | script_env: 24 | - CONDA_PY 25 | -------------------------------------------------------------------------------- /odespy/demos/demo_AdaptiveResidual.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | This example intends to show users how to use AdaptivevResidual, i.e. 5 | to integrate with calculated residual as error-check criteria for 6 | a specified solver. 7 | 8 | Currently, only scalar ODE problem can be used with AdaptiveResidual. 9 | 10 | """ 11 | 12 | from odespy import * 13 | import numpy as np 14 | import scitools.std as st 15 | 16 | f = lambda u,t: -u 17 | u0, t0, tn, n_points = 1., 0., 5., 10 18 | atol, rtol = 1e-1, 1e-1 19 | time_points = np.linspace(t0, tn, n_points) 20 | 21 | for solver in ('RKFehlberg', 'RungeKutta2'): 22 | m = AdaptiveResidual(f, solver=solver, atol=atol, rtol=rtol) 23 | m.set_initial_condition(u0) 24 | u,t = m.solve(time_points, print_info=True) 25 | st.plot(t, u, '-', legend=solver, hold='on') 26 | 27 | st.plot(time_points, np.exp(-time_points),'*', 28 | legend='Exact', hold='on', 29 | title='AdaptiveResidual with rtol=atol=0.1') 30 | 31 | -------------------------------------------------------------------------------- /odespy/demos/demo_Lsodar_1.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Van Der Pol oscillator 5 | u''=100*(1-u*u)*u'-u, with supplied full jacobian matrix 6 | With one root function: g = u 7 | 8 | This example is the typical usage of Lsodar with 9 | user-supplied functions composed in Python. 10 | """ 11 | 12 | from odespy import * 13 | #import scitools.basics,easyviz as st 14 | import scitools.std as st 15 | import numpy as np 16 | 17 | def f(u,t): 18 | u00, u11 = u 19 | udot = [u11,100.*(1 - u00*u00)*u11 - u00] 20 | return udot 21 | 22 | def jac(u,t): 23 | u00, u11 = u 24 | return [[0.,1.], 25 | [-200.*u00*u11 - 1.,100.*(1. - u00*u00)]] 26 | 27 | def g(u,t): 28 | u00, u11 = u 29 | return u00 30 | 31 | import sys 32 | try: 33 | n_points = int(sys.argv[1]) # Read from input 34 | except: 35 | n_points = 20 # default number of time-steps 36 | 37 | t0, tn, u0 = 0., 200., [2.,0.] 38 | time_points = np.linspace(t0, tn, n_points) 39 | atol, rtol = 1e-4, 1e-4 40 | 41 | 42 | st.figure() 43 | method = Lsodar 44 | 45 | # Test case 1: Lsodar, with f, g & jac 46 | m = method(f, rtol=rtol, atol=atol, jac=jac, g=g) 47 | m.set_initial_condition(u0) 48 | u,t = m.solve(time_points) 49 | st.plot(t, u[:,0], title="Lsodar with Python functions", 50 | legend="with f, g & jac", hold="on") 51 | 52 | # Test case 2: Lsodar, with f & g 53 | m = method(f, rtol=rtol, atol=atol, g=g) 54 | m.set_initial_condition(u0) 55 | u,t = m.solve(time_points) 56 | st.plot(t, u[:,0], '*', title="Lsodar with Python functions", 57 | legend="with f & g", hold="on") 58 | 59 | -------------------------------------------------------------------------------- /odespy/demos/demo_Lsodar_2.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Test for dlsodar(), from demo in ODEPACK 5 | u' = ((2*log(u) + 8)/t - 5)*u, u(0)=1 6 | With two root functions: 7 | g1 = du/dt = ((2*log(u) + 8)/t - 5)*u, root = 2.5 8 | g2 = log(u)-2.2491, root = 2.47 and 2.53 9 | Exact solution is u(t) = exp(-t**2 + 5*t - 4) 10 | 11 | This example is the typical usage of Lsodar with 12 | user-supplied functions composed in Python. 13 | """ 14 | 15 | from odespy import * 16 | #import scitools.basics,easyviz as st 17 | import scitools.std as st 18 | import numpy as np 19 | 20 | def f(u,t): 21 | return ((2.*np.log(u)+8.)/t-5.)*u 22 | 23 | def u_solution(t): 24 | return np.exp(-t ** 2 + 5 * t - 4) 25 | 26 | def g(u,t): 27 | return [((2.*np.log(u) + 8.)/t - 5.)*u,\ 28 | np.log(u) - 2.2491] 29 | 30 | import sys 31 | try: 32 | n_points = int(sys.argv[1]) # Read from input 33 | except: 34 | n_points = 200 # default number of time-steps 35 | 36 | t0, tn, u0 = 1., 6., 1.0 37 | time_points = np.linspace(t0, tn, n_points) 38 | atol, rtol = 1e-8, 1e-8 39 | 40 | 41 | st.figure() 42 | method = Lsodar 43 | 44 | # Test case: Lsodar, with f & g 45 | m = method(f, rtol=rtol, atol=atol, g=g) 46 | m.set_initial_condition(u0) 47 | u,t = m.solve(time_points) 48 | st.plot(t, u, 'o', 49 | title="Lsodar with Python functions", 50 | legend="with f & g", hold="on") 51 | 52 | # Exact solution: u(t) = exp(-t**2+5*t-4) 53 | st.plot(t, u_solution(time_points), '-', 54 | title="Lsodar with Python functions", 55 | legend="Exact solution", hold="on") 56 | -------------------------------------------------------------------------------- /odespy/demos/demo_Lsodar_2_fortran.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Same example as in demo_Lsodar_2.py 5 | u' = ((2*log(u) + 8)/t - 5)*u, u(0)=1 6 | With two root functions: 7 | g1 = du/dt = ((2*log(u) + 8)/t - 5)*u, root = 2.5 8 | g2 = log(u)-2.2491, root = 2.47 and 2.53 9 | Exact solution is u(t) = exp(-t**2 + 5*t - 4) 10 | 11 | This example is the typical usage of Lsodar with 12 | user-supplied functions composed in Python. 13 | """ 14 | 15 | from odespy import * 16 | import scitools.std as st 17 | import numpy as np 18 | import os 19 | 20 | def u_solution(t): 21 | return np.exp(-t ** 2 + 5 * t - 4) 22 | 23 | f_str = """ 24 | subroutine f_f77(neq, t, u, udot) 25 | Cf2py intent(hide) neq 26 | Cf2py intent(out) udot 27 | integer neq 28 | double precision t, u, udot 29 | dimension u(neq), udot(neq) 30 | udot(1) = ((2.0d0*log(u(1)) + 8.0d0)/t - 5.0d0)*u(1) 31 | return 32 | end 33 | """ 34 | 35 | g_str = """ 36 | subroutine g_f77(neq, t, u, ng, groot) 37 | Cf2py intent(hide) neq 38 | Cf2py optional, intent(hide) ng 39 | Cf2py intent(in) t, u 40 | Cf2py intent(out) groot 41 | integer neq, ng 42 | double precision t, u, groot 43 | dimension u(neq), groot(ng) 44 | groot(1) = ((2.0d0*log(u(1)) + 8.0d0)/t - 5.0d0)*u(1) 45 | groot(2) = log(u(1)) - 2.2491d0 46 | return 47 | end 48 | """ 49 | 50 | import sys 51 | try: 52 | n_points = int(sys.argv[1]) # Read from input 53 | except: 54 | n_points = 200 # default number of time-steps 55 | 56 | t0, tn, u0 = 1., 6., 1.0 57 | time_points = np.linspace(t0, tn, n_points) 58 | atol, rtol, ng = 1e-8, 1e-8, 2 59 | ng = 2 # number of constraint functions in g 60 | 61 | # Compile these Fortran subroutines 62 | from numpy import f2py 63 | f2py.compile(f_str+'\n'+g_str, modulename='callback', verbose=False) 64 | import callback 65 | f_f77, g_f77 = callback.f_f77, callback.g_f77 66 | 67 | st.figure() 68 | method = Lsodar 69 | # Test case: Lsodar, with f & g 70 | m = method(None, f_f77=f_f77, rtol=rtol, atol=atol, g_f77=g_f77, ng=ng) 71 | m.set_initial_condition(u0) 72 | u,t = m.solve(time_points) 73 | st.plot(t, u, 'o', 74 | title="Lsodar with Fortran subroutines", 75 | legend="with f & g", hold="on") 76 | 77 | # Exact solution: u(t) = exp(-t**2+5*t-4) 78 | st.plot(t, u_solution(time_points), '-', 79 | title="Lsodar with Fortran subroutines", 80 | legend="Exact solution", hold="on") 81 | 82 | os.remove('callback.so') 83 | -------------------------------------------------------------------------------- /odespy/demos/demo_Lsode_Lsoda_1.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Van Der Pol oscillator 5 | u''=3*(1-u*u)*u'-u, with supplied full jacobian matrix 6 | 7 | This example is the typical usage of Lsode/Lsoda with 8 | user-supplied functions composed in Python. 9 | """ 10 | 11 | from odespy import * 12 | #import scitools.basics,easyviz as st 13 | import scitools.std as st 14 | import numpy as np 15 | 16 | def f(u,t): 17 | u00,u11 = u 18 | udot = [u11,3.*(1 - u00*u00)*u11 - u00] 19 | return udot 20 | 21 | def jac(u,t): 22 | u00,u11 = u 23 | return [[0.,1.], 24 | [-6.*u00*u11 - 1.,3.*(1. - u00*u00)]] 25 | 26 | import sys 27 | try: 28 | n_points = int(sys.argv[1]) # Read from input 29 | except: 30 | n_points = 10 # default number of time-steps 31 | 32 | 33 | t0, tn, u0 = 0., 10., [2.,0.] 34 | time_points = np.linspace(t0, tn, n_points) 35 | atol, rtol = 1e-4, 1e-4 36 | 37 | 38 | st.figure() 39 | method = Lsode 40 | 41 | # Test case 1: Lsode, with f & jac 42 | m = method(f, rtol=rtol, atol=atol, jac=jac) 43 | m.set_initial_condition(u0) 44 | u,t = m.solve(time_points) 45 | st.plot(t, u[:,0], title="Lsode with Python functions", 46 | legend="with f & jac", hold="on") 47 | 48 | # Test case 2: Lsode, with f 49 | m = method(f, rtol=rtol, atol=atol) 50 | m.set_initial_condition(u0) 51 | u,t = m.solve(time_points) 52 | st.plot(t, u[:,0], '*', title="Lsode with Python functions", 53 | legend="with f", hold="on") 54 | 55 | method = Lsoda 56 | st.figure() 57 | # Test case 3: Lsoda, with f & jac 58 | m = method(f, rtol=rtol, atol=atol, jac=jac) 59 | m.set_initial_condition(u0) 60 | u,t = m.solve(time_points) 61 | st.plot(t, u[:,0], title="Lsoda with Python functions", 62 | legend="with f & jac", hold="on") 63 | 64 | # Test case 4: Lsoda, with f 65 | m = method(f, rtol=rtol, atol=atol) 66 | m.set_initial_condition(u0) 67 | u,t = m.solve(time_points) 68 | st.plot(t, u[:,0], '*', title="Lsoda with Python functions", 69 | legend="with f", hold="on") 70 | 71 | 72 | st.figure() 73 | # Test case 5: Switch to Lsodar 74 | m.switch_to(Lsodar) 75 | u,t = m.solve(time_points) 76 | st.plot(t, u[:,0], '-', title="Lsodar with Python functions", 77 | legend="Switch from Lsoda", hold="on") 78 | 79 | # Test case 6: Supplement jac 80 | m.set(jac=jac, iter_method=None) 81 | u,t = m.solve(time_points) 82 | st.plot(t, u[:,0], 'o', title="Lsodar with Python functions", 83 | legend="Supplement jac", hold="on") 84 | -------------------------------------------------------------------------------- /odespy/demos/demo_Lsodi_1.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Chemical kinetics, from opkdmain.f in ODEPACK 5 | du1/dt = -0.04*u1+1e4*u2*u3 6 | du2/dt = 0.04*u1-1e4*u2*u3-3e7*u2*u2 7 | 0 = u1+u2+u3-1 8 | 9 | This example is the typical usage of Lsodi with 10 | user-supplied functions composed in Python. 11 | """ 12 | from odespy import * 13 | import scitools.std as st 14 | import numpy as np 15 | 16 | def res(u, t, s, ires): 17 | r = np.zeros(3,float) 18 | r[0] = -.04*u[0] + 1e4*u[1]*u[2] - s[0] 19 | r[1] = .04*u[0] - 1e4*u[1]*u[2] - 3e7*u[1]*u[1] - s[1] 20 | r[2] = sum(u) - 1 21 | return r,ires 22 | 23 | def adda(u, t, p): 24 | p[0][0] += 1. 25 | p[1][1] += 1. 26 | return p 27 | 28 | def jac(u, t, s): 29 | return np.asarray(((-.04, 1e4*u[2], 1e4*u[1]), 30 | (.04, -1e4*u[2] - 6e7*u[1], -1e4*u[1]), 31 | (1.,1.,1.))) 32 | 33 | import sys 34 | try: 35 | n_points = int(sys.argv[1]) # Read from input 36 | except: 37 | n_points = 10 # default number of time-steps 38 | 39 | t0, tn, u0 = 0., 4., [1.,0.,0.] 40 | time_points = np.linspace(t0, tn, n_points) 41 | ydoti = [-.04,.04,0.] # initial value of du/dt 42 | atol, rtol = [1e-6,1e-8,1e-6], 1e-4 43 | 44 | st.figure() 45 | method = Lsodi 46 | exact_final = [9.055142e-1, 2.240418e-5, 9.446344e-2] 47 | 48 | # Test case 1: Lsodi, with res, adda, ydoti & jac 49 | m = method(res=res, rtol=rtol, atol=atol, ydoti=ydoti, 50 | adda_lsodi=adda, jac_lsodi=jac) 51 | m.set_initial_condition(u0) 52 | u,t = m.solve(time_points) 53 | st.plot(t, u[:,0], 'b-', title="Lsodi with Python functions", 54 | legend="with res, adda, ydoti & jac", hold="on") 55 | print 'Max error for test case 1 is %g' % max(u[-1] - exact_final) 56 | 57 | # Test case 2: Lsodi, with res, ydoti & adda 58 | m = method(res=res, rtol=rtol, atol=atol, ydoti=ydoti, 59 | adda_lsodi=adda) 60 | m.set_initial_condition(u0) 61 | u,t = m.solve(time_points) 62 | st.plot(t, u[:,0], 'r*', title="Lsodi with Python functions", 63 | legend="with res, adda & ydoti", hold="on") 64 | print 'Max error for test case 1 is %g' % max(u[-1] - exact_final) 65 | 66 | 67 | -------------------------------------------------------------------------------- /odespy/demos/demo_MyRungeKutta.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | This example intends to show users how to apply MyRungeKutta to define 5 | own RungKutta solvers. 6 | """ 7 | from odespy import * 8 | #import scitools.basics,easyviz as st 9 | import scitools.std as st 10 | import numpy as np 11 | 12 | # arrays to test user-defined Runge-Kutta methods 13 | bt = dict( 14 | FehlBerg = dict( 15 | table = np.array(\ 16 | [[0., 0., 0., 0., 0., 0., 0.], 17 | [.25, .25, 0., 0., 0., 0., 0.], 18 | [.375, .09375, .28125, 0., 0., 0., 0.], 19 | [.92307692, .87938097, -3.27719618, 3.32089213, 0., 0., 0.], 20 | [1., 2.03240741,-8., 7.17348928,-.20589669, 0., 0.], 21 | [.5, -.2962963, 2., -1.38167641, .45297271, -.275, 0.], 22 | [0., .11574074, 0., .54892788, .53533138, -.2, 0.], 23 | [0., .11851852, 0., .51898635, .50613149, -.18, .03636364]]), 24 | order = (4,5)), 25 | RungeKutta3 = dict( 26 | table = np.array(\ 27 | [[0., 0., 0., 0.], 28 | [.5, .5, 0., 0.], 29 | [1., -1., 2., 0.], 30 | [0., .16666667, .66666667, .16666667]]), 31 | order = 3)) 32 | 33 | # Test for user-defined methods: 34 | # Sample ODE problem: u = e**-t, T = [0.,.25,.5,.75,.1], 35 | def f(u,t): 36 | return -u 37 | u0, t0, tn, n_points = 1., 0., 1., 5 38 | time_points = np.linspace(t0, tn, n_points) 39 | 40 | orders = [] # list for calculated orders 41 | for m in bt.keys(): 42 | # user-defined method, without order suplied 43 | method = MyRungeKutta(f, butcher_tableau=bt[m]['table']) 44 | orders += [method.get_order()] 45 | method.set_initial_condition(u0) 46 | u,t = method.solve(time_points) 47 | error = abs((u[-1] - np.exp(-1.))/np.exp(-1.)) 48 | print 'Error is %g with solver %s' % (error, m) 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /odespy/demos/demo_RKC_1.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | This example shows how to use RKC. It solves a system of ODEs that 5 | arise from semi-discretization of the reaction-diffusion equation 6 | 7 | U = U + (1 - U)*U**2 for t >= 0, 0 <= x <= 10 8 | t xx 9 | 10 | Dirichlet boundary conditions specify U(0,t) and U(10,t) for all t >= 0 11 | and the initial values U(x,0) are specified. 12 | 13 | These values are taken from an analytical solution that is evaluated in 14 | sol(x,t) so that the numerical solution can be compared to a known solution. 15 | 16 | In this test example, F is provide as a Python function. This lead to 17 | unavoidable efficiency cost to call-back F from extension module. For users 18 | who are familiar with Fortran language, there is a better way to provide F 19 | in Fortran language instead of Python. See demo_RKC_1_fortran.py. 20 | 21 | """ 22 | 23 | 24 | from odespy import * 25 | import scitools.std as st 26 | import numpy as np 27 | 28 | def f(u, t, udot=None): 29 | n = u.size 30 | if udot is None: 31 | udot = np.zeros(n) 32 | 33 | sol0 = 1.0/(1.0 + np.exp(np.sqrt(.5)*(0. - np.sqrt(.5)*t))) 34 | udot[0] = (sol0 - 2.*u[0] + u[1])/.01 + (1. - u[0])*u[0]**2 35 | for i in range(1,n): 36 | udot[i] = (u[i - 1] - 2.*u[i] + u[i + 1])/.01 + (1. - u[i])*u[i]**2 37 | sol10 = 1.0/(1.0 + np.exp(np.sqrt(.5)*(10. - np.sqrt(.5)*t))) 38 | udot[-1] = (u[-2] - 2.*u[-1] + sol10)/.01 + (1. - u[-1])*u[-1]**2 39 | return udot 40 | 41 | import sys 42 | try: 43 | n_points = int(sys.argv[1]) # Read from input 44 | except: 45 | n_points = 20 # default number of time-steps 46 | 47 | t0, tn = 0., 15. 48 | n = 9 # no of points in x grid 49 | x = np.linspace(0, 10, n) 50 | dx = x[1] - x[0] 51 | u0 = [1.0/(1.0 + np.exp(np.sqrt(.5)*dx)) for i in range(1,n+1)] 52 | time_points = np.linspace(t0, tn, n_points) 53 | 54 | 55 | 56 | atol, rtol = 1e-4, 1e-4 57 | st.figure() 58 | 59 | # Needs to debug RKFehlberg for this particular example, 60 | # replace 99 by a variable 61 | raise Exception('Reimplement this test for variable grid size and debug RKFehlberg then.') 62 | m = RKFehlberg(f, rtol=rtol, atol=atol) 63 | m.set_initial_condition(u0) 64 | u,t = m.solve(time_points) 65 | st.plot(t, u[:,0], 'o', title="Python function f", 66 | legend="RKFehlberg", hold="on") 67 | sys.exit(1) 68 | 69 | # Test case 1: RKC 70 | m = RKC(f, rtol=rtol, atol=atol) 71 | m.set_initial_condition(u0) 72 | u,t = m.solve(time_points) 73 | st.plot(t, u[:,0], title="Python function f", 74 | legend="RKC", hold="on") 75 | 76 | # Test case 2: Lsode 77 | m = m.switch_to(Lsode) 78 | u,t = m.solve(time_points) 79 | st.plot(t, u[:,0], '*', title="Python function f", 80 | legend="Lsode", hold="on") 81 | 82 | # Test case 3: RKFehlberg 83 | 84 | m = m.switch_to(RKFehlberg) 85 | u,t = m.solve(time_points) 86 | st.plot(t, u[:,0], 'o', title="Python function f", 87 | legend="RKFehlberg", hold="on") 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /odespy/demos/demo_Radau5_1.py: -------------------------------------------------------------------------------- 1 | from odespy import * 2 | import scitools.std as st 3 | 4 | def f(u,t): 5 | udot = np.zeros(8, float) 6 | udot[0] = -1.71*u[0] + .43*u[1] + 8.32*u[2] + .0007 7 | udot[1] = 1.71*u[0] - 8.75*u[1] 8 | udot[2] = -10.03*u[2] + .43*u[3] + .035*u[4] 9 | udot[3] = 8.32*u[1] + 1.71*u[2] - 1.12*u[3] 10 | udot[4] = -1.745*u[4] + .43*u[5] + .43*u[6] 11 | udot[5] = -280.*u[5]*u[7] + .69*u[3] + 1.71*u[4] - \ 12 | .43*u[5] + .69*u[6] 13 | udot[6] = 280.*u[5]*u[7] - 1.81*u[6] 14 | udot[7] = -udot[6] 15 | return udot 16 | 17 | def jac(u,t): 18 | dfu = [[-1.71,.43,8.32,0.,0.,0.,0.,0.], 19 | [1.71,-8.75,0.,0.,0.,0.,0.,0.], 20 | [0.,0.,-10.03,.43,.035,0.,0.,0.], 21 | [0.,8.32,1.71,-1.12,0.,0.,0.,0.], 22 | [0.,0.,0.,0.,-1.745,.43,.43,0.], 23 | [0.,0.,0.,.69,1.71,-.43-280.*u[7],.69,-280.*u[5]], 24 | [0.,0.,0.,0.,0.,280.*u[7],-1.81,280.*u[5]], 25 | [0.,0.,0.,0.,0.,-280.*u[7],1.81,-280.*u[5]]] 26 | return dfu 27 | 28 | u0 = np.zeros(8, float) 29 | u0[0], u0[-1] = 1., .0057 30 | time_points = np.linspace(0., 10., 20) 31 | 32 | print "HIRES, chemical reaction, mildly stiff" 33 | st.figure() 34 | 35 | # Loop for all possible solvers 36 | for solver in ['Vode', 'Radau5Explicit']: 37 | method = eval(solver)(f, jac=jac) 38 | method.set_initial_condition(u0) 39 | u,t = method.solve(time_points) 40 | st.plot(t, u[:,0], hold="on", legend=solver, axis=[0.,10.,0.,1.]) 41 | print 'Succeed when solver is %s' % solver 42 | -------------------------------------------------------------------------------- /odespy/demos/demo_Radau5_2.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Van Der Pol oscillator 5 | u''=3*(1-u*u)*u'-u, with supplied full jacobian matrix 6 | 7 | This example is the typical usage of Lsode/Lsoda with 8 | user-supplied functions composed in Python. 9 | """ 10 | 11 | from odespy import * 12 | import scitools.std as st 13 | import numpy as np 14 | 15 | def f(u,t): 16 | u00,u11 = u 17 | udot = [u11,3.*(1 - u00*u00)*u11 - u00] 18 | return udot 19 | 20 | def jac(u,t): 21 | u00,u11 = u 22 | return [[0.,1.], 23 | [-6.*u00*u11 - 1.,3.*(1. - u00*u00)]] 24 | 25 | import sys 26 | try: 27 | n_points = int(sys.argv[1]) # Read from input 28 | except: 29 | n_points = 10 # default number of time-steps 30 | 31 | 32 | t0, tn, u0 = 0., 10., [2.,0.] 33 | time_points = np.linspace(t0, tn, n_points) 34 | atol, rtol = 1e-4, 1e-4 35 | 36 | 37 | st.figure() 38 | method = Radau5Explicit 39 | 40 | # Test case 1: Radau5, with f & jac 41 | m = method(f, rtol=rtol, atol=atol, jac=jac) 42 | m.set_initial_condition(u0) 43 | u,t = m.solve(time_points) 44 | st.plot(t, u[:,0], title= "Van der Pol oscillator, with Radau5 & Lsoda", 45 | legend="Radau5 with f & jac", hold="on") 46 | 47 | # Test case 2: Radau5, with f 48 | m = method(f, rtol=rtol, atol=atol) 49 | m.set_initial_condition(u0) 50 | u,t = m.solve(time_points) 51 | st.plot(t, u[:,0], '*', legend="Radau5 with f", hold="on") 52 | 53 | method = Lsoda 54 | # Test case 3: Lsoda, with f & jac 55 | m = method(f, rtol=rtol, atol=atol, jac=jac) 56 | m.set_initial_condition(u0) 57 | u,t = m.solve(time_points) 58 | st.plot(t, u[:,0], legend="Lsoda with f & jac", hold="on") 59 | 60 | # Test case 4: Lsoda, with f 61 | m = method(f, rtol=rtol, atol=atol) 62 | m.set_initial_condition(u0) 63 | u,t = m.solve(time_points) 64 | st.plot(t, u[:,0], '*', legend="Lsoda with f", hold="on") 65 | 66 | 67 | -------------------------------------------------------------------------------- /odespy/demos/demo_Radau5_3.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | u'= A*y, With supplied banded jacobian matrix 5 | 6 | This example is the typical usage of Lsode/Lsoda with 7 | user-supplied functions composed in Python. 8 | """ 9 | 10 | from odespy import * 11 | import scitools.std as st 12 | import numpy as np 13 | 14 | def f(u,t): 15 | udot = np.zeros(25,float) 16 | for j in range(5): 17 | for i in range(5): 18 | k = i+j*5 19 | udot[k] = -2.*u[k] + u[k - 1]*(i>0) + u[k - 5]*(j>0) 20 | return (np.asarray(udot)) 21 | 22 | def jac_banded(u,t,ml,mu): 23 | pd = np.zeros(6*25,float).reshape(6,25) 24 | pd[0,:], pd[1,:], pd[5,:], pd[1,4:24] = -2., 1., 1., 0. 25 | return pd 26 | 27 | import sys 28 | try: 29 | n_points = int(sys.argv[1]) # Read from input 30 | except: 31 | n_points = 10 # default number of time-steps 32 | 33 | 34 | t0, tn, u0 = 0., 4., [1]+24*[0] 35 | ml, mu = 5, 0 36 | time_points = np.linspace(t0, tn, n_points) 37 | atol, rtol = 1e-2, 1e-2 38 | 39 | 40 | st.figure() 41 | method = Radau5Explicit 42 | 43 | # Test case 1: Radau5, with f, ml, mu & jac_banded 44 | m = method(f, rtol=rtol, atol=atol, 45 | ml=ml, mu=mu, jac_banded=jac_banded) 46 | m.set_initial_condition(u0) 47 | u,t = m.solve(time_points) 48 | st.plot(t, u[:,0], title= "Radau5 & Lsoda", 49 | legend="Radau5 with f, ml, mu & jac", hold="on") 50 | 51 | # Test case 2: Radau5, with f, ml, mu 52 | m = method(f, rtol=rtol, atol=atol, ml=ml, mu=mu) 53 | m.set_initial_condition(u0) 54 | u,t = m.solve(time_points) 55 | st.plot(t, u[:,0], '*', 56 | legend="Radau5 with f & ml,mu", hold="on") 57 | 58 | # Test case 3: Radau5, with f 59 | m = method(f, rtol=rtol, atol=atol) 60 | m.set_initial_condition(u0) 61 | u,t = m.solve(time_points) 62 | st.plot(t, u[:,0], 'o', 63 | legend="with f", hold="on") 64 | 65 | method = Lsoda 66 | st.figure() 67 | # Test case 4: Lsoda, with f, ml, mu & jac_banded 68 | m = method(f, rtol=rtol, atol=atol, 69 | ml=ml, mu=mu, jac_banded=jac_banded) 70 | m.set_initial_condition(u0) 71 | u,t = m.solve(time_points) 72 | st.plot(t, u[:,0], 73 | legend="Lsoda with f, ml, mu & jac", hold="on") 74 | 75 | # Test case 5: Lsoda, with f, ml, mu 76 | m = method(f, rtol=rtol, atol=atol, 77 | ml=ml, mu=mu) 78 | m.set_initial_condition(u0) 79 | u,t = m.solve(time_points) 80 | st.plot(t, u[:,0], '*', 81 | legend="Lsoda with f & jac", hold="on") 82 | 83 | # Test case 6: Lsoda, with f 84 | m = method(f, rtol=rtol, atol=atol) 85 | m.set_initial_condition(u0) 86 | u,t = m.solve(time_points) 87 | st.plot(t, u[:,0], 'o', 88 | legend="Lsoda with f", hold="on") 89 | 90 | -------------------------------------------------------------------------------- /odespy/demos/demo_Radau5_4.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | """ 4 | Chemical kinetics, from opkdmain.f in ODEPACK 5 | du1/dt = -0.04*u1+1e4*u2*u3 6 | du2/dt = 0.04*u1-1e4*u2*u3-3e7*u2*u2 7 | 0 = u1+u2+u3-1 8 | 9 | This example is the typical usage of DAE with 10 | user-supplied functions composed in Python. 11 | """ 12 | from odespy import * 13 | import scitools.std as st 14 | import numpy as np 15 | 16 | def f(u, t): 17 | udot = np.zeros(3, float) 18 | udot[0] = -.04*u[0] + 1e4*u[1]*u[2] 19 | udot[1] = .04*u[0] - 1e4*u[1]*u[2] - 3e7*u[1]*u[1] 20 | udot[2] = sum(u) - 1 21 | return udot 22 | 23 | def mas(): 24 | m = [[1, 0, 0], 25 | [0, 1, 0], 26 | [0, 0, 0]] 27 | return m 28 | 29 | def jac(u, t): 30 | return np.asarray(((-.04, 1e4*u[2], 1e4*u[1]), 31 | (.04, -1e4*u[2] - 6e7*u[1], -1e4*u[1]), 32 | (1.,1.,1.))) 33 | 34 | import sys 35 | try: 36 | n_points = int(sys.argv[1]) # Read from input 37 | except: 38 | n_points = 10 # default number of time-steps 39 | 40 | t0, tn, u0 = 0., 4., [1.,0.,0.] 41 | time_points = np.linspace(t0, tn, n_points) 42 | atol, rtol = [1e-6,1e-8,1e-6], 1e-4 43 | 44 | st.figure() 45 | method = Radau5Implicit 46 | exact_final = [9.055142e-1, 2.240418e-5, 9.446344e-2] 47 | 48 | # Test case 1: Radau5, with f, mas & jac 49 | m = method(f=f, mas=mas, rtol=rtol, atol=atol, jac=jac) 50 | m.set_initial_condition(u0) 51 | u,t = m.solve(time_points) 52 | st.plot(t, u[:,0], 'b-', title="Radau5 with Python functions", 53 | legend="with f, mas & jac", hold="on") 54 | print 'Max error for test case 1 is %g' % max(u[-1] - exact_final) 55 | 56 | # Test case 2: Radau5, with f, mas 57 | m = method(f=f, mas=mas, rtol=rtol, atol=atol) 58 | m.set_initial_condition(u0) 59 | u,t = m.solve(time_points) 60 | st.plot(t, u[:,0], 'r*', title="Radau5 with Python functions", 61 | legend="with f, mas", hold="on") 62 | print 'Max error for test case 1 is %g' % max(u[-1] - exact_final) 63 | 64 | 65 | -------------------------------------------------------------------------------- /odespy/demos/demo_basics_complex_Pi.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | # Scalar ODE with complex value 3 | # u' = 1/(t - 10 + 1j) 4 | 5 | from odespy import * 6 | 7 | solver_no = 1 # number of solvers in figure 8 | 9 | complex_solvers = ['AdamsBashMoulton2', 'AdamsBashMoulton3', 'AdamsBashforth2', 10 | 'AdamsBashforth3', 'AdamsBashforth4', 'AdaptiveResidual', 11 | 'Backward2Step', 'BackwardEuler', 'Euler', 12 | 'Heun', 'Leapfrog', 'LeapfrogFiltered', 13 | 'MidpointImplicit', 'MidpointIter', 'RK3', 14 | 'RK2', 'RK4', 'RKFehlberg', 15 | 'ThetaRule', 'Trapezoidal'] 16 | fail_solvers = [name for name in list_available_solvers() if name not in complex_solvers] 17 | 18 | f = lambda u, t: 1./(t - 10. + 1j) 19 | u0, time_points = 0, np.linspace(0., 20., 200) 20 | 21 | print """ Scalar ODE with complex value 22 | u' = 1./(t - 10 + 1j) """ 23 | 24 | succeed_no = 0 25 | for solver in complex_solvers: 26 | try: 27 | method = eval(solver)(f, atol=1e-6) 28 | method.set_initial_condition(u0) 29 | u,t = method.solve(time_points) 30 | success = np.allclose(u[-1].imag, -2*np.arctan(10)) 31 | print solver, 'Succeed' if success else 'Fail' 32 | except: 33 | print 'Failed when solver is %s' % solver 34 | -------------------------------------------------------------------------------- /odespy/demos/demo_basics_exponential.py: -------------------------------------------------------------------------------- 1 | # Author: Liwei Wang 2 | 3 | # Scalar ODE: Exponential 4 | # u' = - u, u = exp(-t) 5 | 6 | from odespy import * 7 | import numpy as np 8 | import scitools.std as st 9 | 10 | solver_no = 0 # number of solvers in figure 11 | st.figure() 12 | 13 | exceptions=['Lsodi', 'Lsodis', 'Lsoibt', 'MyRungeKutta', 14 | 'MySolver', 'Lsodes', 'EulerCromer'] 15 | solvers = [solver for solver in list_available_solvers() if solver not in exceptions] 16 | 17 | f=lambda u,t:-u 18 | u0, time_points = 1., np.linspace(0., 10., 100) 19 | 20 | print """Scalar ODE: Exponential u = exp(-t), u' = -u""" 21 | 22 | # Loop for all possible solvers 23 | for solver in solvers: 24 | try: 25 | method = eval(solver)(f, atol=1e-6) 26 | method.set_initial_condition(u0) 27 | u,t = method.solve(time_points) 28 | if solver_no % 8 == 0: 29 | # More than 8 solvers in current figure? 30 | st.figure() # Initialize new figure. 31 | st.plot(t, u, hold="on", legend=solver, axis=[0., 10., 0., 1.5]) 32 | solver_no += 1 33 | print 'Succeed when solver is %s' % solver 34 | except: 35 | print 'Failed when solver is %s' % solver 36 | -------------------------------------------------------------------------------- /odespy/demos/demo_basics_sine.py: -------------------------------------------------------------------------------- 1 | # Nonstiff ODE: Sine 2 | # u'' = - u, u = sin(t) 3 | 4 | from odespy import * 5 | import scitools.std as st 6 | 7 | solver_no = 1 # number of solvers in figure 8 | st.figure() 9 | 10 | exceptions=['Lsodi', 'Lsodes', 'Lsodis', 'Lsoibt', 'MyRungeKutta', 11 | 'MySolver', 'AdaptiveResidual'] 12 | solvers = [solver for solver in list_available_solvers() if solver not in exceptions] 13 | 14 | f = lambda (u00,u11),t: [u11, -u00] 15 | jac = lambda (u00,u11),t: \ 16 | [[0., 1.], [- 1., 0.]] 17 | 18 | u0, time_points = [0., 1.], np.linspace(0., 10., 100) 19 | 20 | print """Nonstiff ODE: Sine u = sin(t), u'' = -u""" 21 | 22 | # Loop for all possible solvers 23 | for solver in solvers: 24 | try: 25 | method = eval(solver)(f) 26 | method.set_initial_condition(u0) 27 | u,t = method.solve(time_points) 28 | if solver_no == 8: # More than 8 solvers in current figure? 29 | st.figure() # Initialize new figure. 30 | solver_no = 1 31 | st.plot(t, u[:,0], hold="on", legend=solver, axis=[0., 10., -1.5, 1.5]) 32 | solver_no += 1 33 | print 'Succeed when solver is %s' % solver 34 | except: 35 | print 'Failed when solver is %s' % solver 36 | 37 | -------------------------------------------------------------------------------- /odespy/demos/demo_basics_van_der_pol.py: -------------------------------------------------------------------------------- 1 | # Stiff ODE: Van der Pol oscillator 2 | # u'' = 3*(1 - u**2)*u' - u 3 | from odespy import * 4 | import scitools.std as st 5 | 6 | solver_no = 1 # number of solvers in figure 7 | st.figure() 8 | 9 | exceptions=['RKC', 'Lsodes', 'Leapfrog', 'Lsodi', 'Lsodis', 'Lsoibt', 10 | 'MyRungeKutta', 'MySolver', 'AdaptiveResidual', 'EulerCromer'] 11 | solvers = [solver for solver in list_available_solvers() if solver not in exceptions] 12 | 13 | f = lambda (u00,u11),t: [u11, 3.*(1 - u00**2)*u11 - u00] 14 | jac = lambda (u00,u11),t: \ 15 | [[0., 1.], [-6.*u00*u11 - 1., 3.*(1. - u00**2)]] 16 | 17 | u0, time_points = [2., 0.], np.linspace(0., 10., 100) 18 | 19 | print """Van der Pol oscillator problem: 20 | u'' = 3*(1 - u**2)*u' - u""" 21 | 22 | # Loop for all possible solvers 23 | for solver in solvers: 24 | try: 25 | method = eval(solver)(f) 26 | method.set_initial_condition(u0) 27 | u,t = method.solve(time_points) 28 | if solver_no == 8: # More than 8 solvers in current figure? 29 | st.figure() # Initialize new figure. 30 | solver_no = 1 31 | st.plot(t, u[:,0], hold="on", legend=solver, axis=[0.,10.,-4.,4.]) 32 | solver_no += 1 33 | print 'Succeed when solver is %s' % solver 34 | except: 35 | print 'Failed when solver is %s' % solver 36 | -------------------------------------------------------------------------------- /odespy/demos/demo_odelab.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy, matplotlib.pyplot as plt 2 | 3 | # Run through all scheme classes in with a simple ODE u'=-u, u(0)=1 4 | # and see which classes that work 5 | 6 | problem = odespy.problems.Exponential(a=-1, b=0) 7 | 8 | scheme = 'ExplicitEuler' 9 | test = odespy.odelab(problem.f, odelab_solver=scheme) 10 | schemes = test.odelab_schemes # all scheme classes 11 | 12 | failures = [] 13 | for scheme in schemes: 14 | print scheme, 15 | solver = odespy.odelab(problem.f, odelab_solver=scheme, 16 | atol=1E-2, rtol=1E-2) 17 | solver.set_initial_condition(1.0) 18 | try: 19 | u, t = solver.solve(numpy.linspace(0, 3, 221)) 20 | print 'summary:', len(u), u[-1], numpy.exp(-t[-1]) - u[-1] 21 | except: 22 | failures.append(scheme) 23 | 24 | print '\nFailed classes:\n', ' '.join(failures) 25 | print '\nAll solver classes:\n', ' '.join(schemes) 26 | print '\nWorking classes:\n', ' '.join([scheme for scheme in schemes if scheme not in failures]) 27 | print '\nDocumented working classes:\n', ' '.join(odespy.odelab.solvers) 28 | 29 | -------------------------------------------------------------------------------- /odespy/radau5/LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/odespy/radau5/LICENSE.txt -------------------------------------------------------------------------------- /odespy/radau5/advance_radau5.f: -------------------------------------------------------------------------------- 1 | subroutine advance_radau5( 2 | & n, fcn, x, y, xend, h, rtol, atol, itol, 3 | & jac, ijac, mljac, mujac, mas, imas, mlmas, mumas, work, 4 | & lwork, iwork, liwork, idid) 5 | external fcn, jac, mas 6 | integer n, itol, ijac, mljac, mujac, imas, mlmas, mumas, lwork, 7 | & iwork_in, liwork, idid 8 | double precision x, y, xend, h, rtol, atol, work_in 9 | dimension y(n), rtol(*), atol(*), work(lwork), iwork(liwork) 10 | 11 | integer iout 12 | call radau5(n, fcn, x, y, xend, h, rtol, atol, itol, jac, ijac, 13 | & mljac, mujac, mas, imas, mlmas, mumas, solout, iout, work, 14 | & lwork, iwork, liwork, rpar, ipar, idid) 15 | return 16 | end 17 | 18 | subroutine advance_radau5_liwei( 19 | & n, fcn, x, y, xend, h, rtol, atol, itol, 20 | & jac, ijac, mljac, mujac, mas, imas, mlmas, mumas, work_in, 21 | & lwork, iwork_in, liwork, idid) 22 | external fcn, jac, mas 23 | integer n, itol, ijac, mljac, mujac, imas, mlmas, mumas, lwork, 24 | & iwork_in, liwork, idid 25 | double precision x, y, xend, h, rtol, atol, work_in 26 | dimension y(n), rtol(*), atol(*) 27 | dimension work_in(lwork), iwork_in(liwork) 28 | 29 | double precision, allocatable :: work(:) 30 | integer, allocatable :: iwork(:) 31 | integer i, iout 32 | 33 | allocate(iwork(liwork)) 34 | allocate(work(lwork)) 35 | do 10 i = 1, 9 36 | 10 iwork(i) = iwork_in(i) 37 | do 20 i = 1, 20 38 | 20 work(i) = work_in(i) 39 | iout = 0 40 | call radau5(n, fcn, x, y, xend, h, rtol, atol, itol, jac, ijac, 41 | & mljac, mujac, mas, imas, mlmas, mumas, solout, iout, work, 42 | & lwork, iwork, liwork, rpar, ipar, idid) 43 | 44 | 45 | C n -- neq, fcn -- f, x--t, y--u0, xend--tend, h -- first_step, 46 | C rtol -- rtol, atol--atol, itol--itol, jac--jac, ijac -- ijac, 47 | C mljac -- ml, mujac -- mu, mas, imas, mlmas, mumas, 48 | C work(2) -- safety, work(7) -- max_step, 49 | C iwork(2) -- nsteps,lwork -- lrw, iwork >= 3*neq + 20, 50 | C liwork -- liw, idid -- istate, 51 | C dummy inputs: rpar, ipar, solout, iout=0 52 | C ouput: x, y, h, idid, iwork(14-20) 53 | return 54 | end 55 | 56 | 57 | -------------------------------------------------------------------------------- /odespy/radau5/radau11_spec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/odespy/radau5/radau11_spec.pdf -------------------------------------------------------------------------------- /odespy/rkc/rkc.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | ! Note: the context of this file is case sensitive. 3 | 4 | python module solve__user__routines 5 | interface solve_user_interface 6 | subroutine termin(yrr,trr,n,nt,neq,valid) 7 | double precision dimension(nt,neq), depend(nt,neq) :: yrr 8 | double precision dimension(nt), depend(nt) :: trr 9 | integer :: n 10 | integer intent(out) :: valid 11 | integer :: nt 12 | integer :: neq 13 | end subroutine termin 14 | subroutine f(neq,t,y,ydot) 15 | integer intent(hide) :: neq 16 | double precision dimension(neq) :: y 17 | double precision :: t 18 | double precision dimension(*), intent(out) :: ydot 19 | end subroutine f 20 | function spcrad(neq,t,y) 21 | integer intent(hide) :: neq 22 | double precision dimension(neq), intent(in) :: y 23 | double precision intent(in) :: t 24 | double precision intent(out):: spcrad 25 | end function spcrad 26 | end interface solve_user_interface 27 | end python module solve__user__routines 28 | python module _rkc ! in 29 | interface ! in :_rkc 30 | subroutine solve(spcrad,neq,f,yin,yout,trr,nt,rtol,atol,info,idid,termin,itermin,nstop) ! in :_rkc:solve_rkc.f 31 | use solve__user__routines 32 | external spcrad 33 | integer optional,check(len(yin)>=neq),depend(yin) :: neq=len(yin) 34 | external f 35 | double precision dimension(neq), intent(in) :: yin 36 | double precision dimension(nt,neq),intent(out) :: yout 37 | double precision dimension(nt), intent(in) :: trr 38 | integer optional,depend(trr) :: nt=len(trr) 39 | double precision :: rtol 40 | double precision dimension(*), intent(in) :: atol 41 | integer dimension(4) :: info 42 | integer intent(out) :: idid 43 | external termin 44 | integer :: itermin 45 | integer intent(out) :: nstop 46 | integer :: nfe 47 | integer :: nsteps 48 | integer :: naccpt 49 | integer :: nrejct 50 | integer :: nfesig 51 | integer :: maxm 52 | common /rkcdid/ nfe,nsteps,naccpt,nrejct,nfesig,maxm 53 | end subroutine solve 54 | end interface 55 | end python module _rkc 56 | 57 | ! This file was auto-generated with f2py (version:1). 58 | ! See http://cens.ioc.ee/projects/f2py2e/ 59 | -------------------------------------------------------------------------------- /odespy/rkf45/advance_rkf45.f: -------------------------------------------------------------------------------- 1 | subroutine advance(f,neqn,y,t,tout,relerr,abserr,iflag) 2 | Cf2py intent(in,hide) neqn 3 | Cf2py intent(in) t,tout,relerr,abserr 4 | Cf2py intente(out) iflag 5 | Cf2py intent(in,out) y 6 | integer neqn,iflag 7 | double precision y(neqn),t,tout,relerr,abserr 8 | external f 9 | 10 | integer iwork(5) 11 | double precision work(3+6*neqn) 12 | logical finished 13 | integer triedcounter 14 | character*80 msg 15 | 16 | triedcounter = 0 17 | finished = .false. 18 | iflag = 1 19 | msg = '' 20 | do while (.not. finished) 21 | call rkf45(f,neqn,y,t,tout,relerr,abserr,iflag,work,iwork) 22 | triedcounter = triedcounter + 1 23 | c succeed 24 | if (iflag .lt. 3) go to 300 25 | c Tried more than two times. Return with failure. 26 | if (triedcounter .gt. 2) go to 300 27 | c Tried again when iflag = 3 or 4. 28 | if (iflag .lt. 5) go to 500 29 | c Invalid inputs 30 | if (iflag .eq. 8) then 31 | msg = 'Invalid input parameters' 32 | go to 300 33 | end if 34 | c One-step integrator is altered as suggestion. 35 | if (iflag .eq. 7) then 36 | msg = 'One-step integrator is altered as suggestion' 37 | iflag = -1 38 | go to 400 39 | end if 40 | c Too much accuracy requirement. 41 | if (iflag .eq. 6) then 42 | msg = 'Too much accuracy requirement.' 43 | go to 300 44 | end if 45 | c atol should be positive to continue. 46 | msg = 'atol should be positive to continue.' 47 | 48 | 300 finished = .true. 49 | 400 if (iflag .gt. 2) write (*,*) msg 50 | 500 continue 51 | end do 52 | return 53 | end 54 | -------------------------------------------------------------------------------- /odespy/rkf45/rkf45.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | ! Note: the context of this file is case sensitive. 3 | 4 | python module advance__user__routines 5 | interface advance_user_interface 6 | subroutine f(neqn,t,y,ydot) 7 | integer optional,depend(y) :: neqn=len(y) 8 | double precision dimension(neqn),intent(in) :: y 9 | double precision intent(in):: t 10 | double precision dimension(*), intent(out) :: ydot 11 | end subroutine f 12 | end interface advance_user_interface 13 | end python module advance__user__routines 14 | python module _rkf45 ! in 15 | interface ! in :_rkf45 16 | subroutine advance(f,neqn,y,t,tout,relerr,abserr,iflag) ! in :_rkf45:advance_rkf45.f 17 | use advance__user__routines 18 | external f 19 | integer optional,check(len(y)>=neqn),depend(y) :: neqn=len(y) 20 | double precision dimension(neqn), intent(in,out) :: y 21 | double precision intent(in) :: t 22 | double precision intent(in) :: tout 23 | double precision intent(in) :: relerr 24 | double precision intent(in) :: abserr 25 | integer intent(out) :: iflag 26 | end subroutine advance 27 | end interface 28 | end python module _rkf45 29 | 30 | ! This file was auto-generated with f2py (version:1). 31 | ! See http://cens.ioc.ee/projects/f2py2e/ 32 | -------------------------------------------------------------------------------- /odespy/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | fortran = True # compile Fortran libraries? 4 | 5 | from os.path import join 6 | import sys 7 | 8 | def configuration(parent_package='', top_path=None): 9 | 10 | from numpy.distutils.misc_util import Configuration 11 | from numpy.distutils.system_info import get_info 12 | config = Configuration('odespy', parent_package, top_path) 13 | 14 | if fortran: 15 | config.add_library('_odepack', 16 | sources=[join('odepack','solve_odepack.f'), 17 | join('odepack','opkd*.f')]) 18 | 19 | config.add_library('_rkc', 20 | sources=[join('rkc','solve_rkc.f'), 21 | join('rkc','rkc.f')]) 22 | config.add_library('_rkf45', 23 | sources=[join('rkf45','advance_rkf45.f'), 24 | join('rkf45','rkf45.f'), 25 | join('rkf45','rkf45_associate.f')]) 26 | 27 | config.add_library('_radau5', 28 | sources=[join('radau5','advance_radau5.f'), 29 | join('radau5','radau5.f'), 30 | join('radau5','radaua.f'),]) 31 | 32 | 33 | # Extensions: 34 | config.add_extension('_odepack', 35 | sources=[join('odepack','odepack.pyf')], 36 | libraries=['_odepack']) 37 | config.add_extension('_rkc', 38 | sources=[join('rkc','rkc.pyf')], 39 | libraries=['_rkc']) 40 | config.add_extension('_rkf45', 41 | sources=[join('rkf45','rkf45.pyf')], 42 | libraries=['_rkf45']) 43 | config.add_extension('_radau5', 44 | sources=[join('radau5','radau5.pyf')], 45 | libraries=['_radau5']) 46 | 47 | config.add_data_dir('tests') 48 | return config 49 | 50 | if __name__ == '__main__': 51 | from numpy.distutils.core import setup 52 | setup(**configuration(top_path='').todict()) 53 | 54 | -------------------------------------------------------------------------------- /odespy/tests/joblib_ex.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dear Gael, 3 | 4 | I've been playing around with joblib lately. Amazing piece of software! 5 | 6 | One of the most obvious applications, I thought, would be to 7 | build very large data structures and have joblib managing the storage 8 | of them for me so that I can pretend they are in memory and work 9 | conveniently with them. 10 | 11 | As I didn't see any direct support for this, I reasoned as follows. 12 | The dump and load functions demand that I store one single 13 | data structure in one file and keep track of the filename. That's 14 | not suitable for large data as they have to be in memory and the 15 | filename is beyond my interest. 16 | 17 | I therefore though of making the retrieve function below, with synonym 18 | save, such that I for each piece of the data I can call save, joblib will 19 | save the piece for me, and at any time I get a memory mapped (?) array 20 | back and attach it in, e.g., a big dictionary that holds numerous such 21 | views to arrays. 22 | 23 | The amazing thing is that I can store the data in joblib and start 24 | many interactive sessions or programs manipulating the data without 25 | any need to recompute (i.e., restore pieces). All my big data are just 26 | there!! Totally amazing :-) 27 | 28 | Is this the right way to use joblib? Or is the same functionality available 29 | in better ways? 30 | """ 31 | 32 | from joblib import Memory 33 | memory = Memory(cachedir='tmp', verbose=0) 34 | 35 | @memory.cache(ignore=['data']) 36 | def retrieve(name, data=None): 37 | print 'joblib save of', name 38 | return data 39 | 40 | save = retrieve 41 | 42 | def create_big_data(n): 43 | """ 44 | Create many pieces of a big data structure, one by one (here 2). 45 | Make joblib save the pieces. 46 | """ 47 | import numpy 48 | big1 = numpy.linspace(0, 1, n+1) 49 | big2 = numpy.linspace(1, 2, n+1) 50 | 51 | save('a', big1) 52 | save('b', big2) 53 | 54 | def retrieve_big_data(): 55 | """ 56 | Grab references to the pieces of a big data structure, all pieces 57 | stored by joblib, and collect them in some appropriate data 58 | structure, here a dict. 59 | """ 60 | a = retrieve('a') 61 | b = retrieve('b') 62 | data = {'arrays': {'a': a, 'b': b}} 63 | return data 64 | 65 | def compute(data): 66 | data['arrays']['b'][-10:] = 0.1 67 | return data 68 | 69 | if __name__ == '__main__': 70 | create_big_data(1000) # create pieces and store in joblib 71 | data = retrieve_big_data() 72 | data = compute(data) 73 | print data['arrays']['b'][-12:] 74 | 75 | # Try to do different things with b and see if retrieve is ever 76 | # called. 77 | -------------------------------------------------------------------------------- /odespy/version.py: -------------------------------------------------------------------------------- 1 | short_version = '0.3.0' 2 | version = short_version 3 | full_version = short_version 4 | -------------------------------------------------------------------------------- /sandbox/examples/2D_mass_spring_animation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/examples/2D_mass_spring_animation.m -------------------------------------------------------------------------------- /sandbox/examples/Baseball_trajectory.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/examples/Baseball_trajectory.pdf -------------------------------------------------------------------------------- /sandbox/examples/elastic_pendulum.py: -------------------------------------------------------------------------------- 1 | import odespy, numpy as np, scitools.std as st 2 | k = 150. 3 | #k = 50000. 4 | # k instability because large k means small s, even simulation 5 | # around equilibrium is problematic with k=50,000, there is 6 | # round-off in s and in final force when k/m*s*ny balances g 7 | L0 = 9.81 # unstretched length of pendulum 8 | g = 9.81 9 | m = 1.0 10 | theta0 = 60.0 # degrees 11 | theta0 = theta0*np.pi/180 12 | # Equilibruim length 13 | L = L0 + m*g/k 14 | # Initial condition: theta degrees from equilibrium 15 | x0 = L*np.sin(theta0) 16 | # cos(theta0) = (L0-L)/y0 17 | y0 = L0 - L*np.cos(theta0) 18 | 19 | # Unknowns: vx, x, vy, y 20 | # Equations: vx' = ..., x' = vx, vy' = ..., y' = vy 21 | 22 | def f(u, t, m, k, L0): 23 | g = 9.81 24 | vx, x, vy, y = u 25 | # mv' = -k*s*n + m*g*j, n: normal vector along the pendulum 26 | L = np.sqrt(x**2 + (y-L0)**2) 27 | s = L - L0 28 | nx = x/L 29 | ny = (y-L0)/L 30 | #print 't=%g vx=%5.2f vy=%5.2f x=%5.2f, y=%5.2f, Fx=%5.2f, Fy=%5.2f' % (t, vx, vy, x, y, -k/m*s*nx, -k/m*s*ny - g) 31 | #print 'k=%g, s=%5.2g, ny=%5.2f, k/m*s*ny=%g, k*s*ny/m=%g' % (k,s,ny,k/m*s*ny,k*s*ny/m) 32 | return [-k/m*s*nx, vx, 33 | -k/m*s*ny - g, vy] 34 | 35 | solver = odespy.EulerCromer(f, f_args=(m, k, L0)) 36 | solver.set_initial_condition([0, x0, 0, y0]) 37 | # First test: vertical pendulum doing harmonic vertical motion, first 38 | # at rest, then slightly out of equilibrium 39 | # k and m should balance 40 | 41 | # For large k, this is theta'' + g/L0*sin(theta) = 0, so L0=g 42 | # implies theta'' + theta = 0 equation with theta0*cos(t) as solution 43 | P = 2*np.pi 44 | N = 60 45 | dt = P/N 46 | num_periods = 6 47 | T = num_periods*P 48 | time_points = np.linspace(0, T, num_periods*N+1) 49 | u, t = solver.solve(time_points) 50 | x = u[:,1] 51 | y = u[:,3] 52 | theta = np.arctan(x/(L0-y)) 53 | theta_exact = lambda t: theta0*np.cos(t) 54 | theta_e = theta_exact(t) 55 | if abs(theta0) < 1E-14: 56 | st.figure() 57 | st.plot(t, y, title='y motion') 58 | st.figure() 59 | # Control perfect aspect ratio of the axis so the motion is geometrically true 60 | st.plot(x, y, 'b-', title='xy motion', daspect=[1,1,1], daspectmode='manual', 61 | axis=[x.min(), x.max(), L0-L-x.max(), L0-L+x.max()]) 62 | st.figure() 63 | st.plot(t, theta, t, theta_e, legend=('EC', 'exact'), title='theta motion') 64 | # Difference in final value for N=60 65 | #diff_exact = 0.0014700112828 66 | #diff_EC = abs(x[-1] - x_e[-1]) 67 | #tol = 1E-14 68 | #assert abs(diff_exact - diff_EC) < tol, \ 69 | # 'diff_exact=%g, diff_EulerCromer=%g' % (diff_exact, diff_EC) 70 | raw_input() 71 | -------------------------------------------------------------------------------- /sandbox/examples/odedemo2.m: -------------------------------------------------------------------------------- 1 | function odedemo2() 2 | % Ball Falling in honey 3 | % -Andy Ruina, Jan 24, 2008 4 | 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | % VARIABLES (Assume consistent units) 7 | % +y = displacement up 8 | % v = dy/dt 9 | % z = [y v], z is the 'state vector' 10 | % 11 | 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | % CONSTANTS 14 | g = 10 ; % gravity constant 15 | c = .1 ; % drag constant (force per unit velocity) 16 | m = .1; % mass 17 | 18 | % INTIAL CONDITIONS 19 | y0 = 0 ; % initial height 20 | v0 = 20 ; % initial velocity 21 | z0 = [y0 v0]; % z is the list of state variables 22 | % z is the state vector. 23 | 24 | tspan =[0 5]; %time interval of integration 25 | 26 | error = 1e-4; 27 | % Set error tolerance and use 'event detection' 28 | options = odeset('abstol', error, 'reltol',error,... 29 | 'events', @stopevent) ; 30 | 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | % Ask Matlab to SOLEVE odes in function 'rhs' 33 | [t zarray] = ode45(@rhs,tspan, z0, options,m,c,g); 34 | % The parameters m,c and g are passed to both 35 | % the 'rhs' function and the 'stopevent' function 36 | % Each row of zarray is the state z at one time. 37 | 38 | %UNPACK the zarray (the solution) into sensible variables 39 | y = zarray(:,1); % y is the first column of z 40 | v = zarray(:,2); % v is the second column of z 41 | 42 | plot (t,y, t, v) 43 | title('Andy''s plot of ball in honey') 44 | xlabel('time'); ylabel('y and v') 45 | axis([0 inf -inf inf]) %inf self scales plot 46 | 47 | end % end of main function odedemo2 48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 49 | 50 | 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 52 | % THE DIFFERENTIAL EQUATION 'The Right Hand Side' 53 | function zdot = rhs(t,z,m,c,g) 54 | %UNPACK state vector z into sensible variables 55 | y = z(1); % y is the first element of z 56 | v = z(2); % v is the second element of z 57 | 58 | %The equations 59 | ydot = v; % kinematic relation between y and v 60 | vdot = -g -c*v/m; % F = m a 61 | 62 | % Pack the rate of change of y, v into a rate of change 63 | % of state: 64 | zdot = [ydot vdot]'; % Has to be a column vector 65 | end % end of rhs 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 67 | 68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 | function [value, isterminal, dir] = stopevent(t,z,m,c,g) 70 | % Have to assign numbers to value, isterminal, dir 71 | %UNPACK z into sensible variables 72 | y = z(1); % y is the first element of z 73 | v = z(2); % v is the second element of z 74 | value = y - (-5); % stop integrating when y = -5 75 | isterminal = 1; % 1 means stop 76 | dir = -1; % -1 for decreasing, +1 for increasing, 77 | % 0 for any which way. 78 | end % end of stopevent 79 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 80 | -------------------------------------------------------------------------------- /sandbox/examples/pendulum2_as_DAE.txt: -------------------------------------------------------------------------------- 1 | http://apmonitor.com/wiki/index.php/Apps/PendulumMotion 2 | http://sundials.2283335.n4.nabble.com/pendulum-example-td3240916.html 3 | -------------------------------------------------------------------------------- /sandbox/examples/pendulum_as_DAE.m: -------------------------------------------------------------------------------- 1 | function simp_pend 2 | clc 3 | close all 4 | %%% Simple pendulum as a DAE 5 | %%% 21 April 2009 %%%% 6 | %%% Pranav Bhounsule %%%% 7 | 8 | l = 1; m = 1; I = m*l^2/12; g=10; 9 | T = 5; steps = 300; 10 | Tol = 1e-6; 11 | 12 | th0 = 1; 13 | thdot0 = 0; 14 | 15 | x0 = (l/2)*cos(th0); 16 | y0 = (l/2)*sin(th0); 17 | 18 | xdot0 = -(l/2)*sin(th0)*thdot0; 19 | ydot0 = (l/2)*cos(th0)*thdot0; 20 | 21 | z0 = [x0 xdot0 y0 ydot0 th0 thdot0]'; 22 | tspan = linspace(0,T,steps); 23 | 24 | options=odeset('abstol',Tol,'reltol',Tol); 25 | 26 | [t,z] = ode45(@f,[tspan],z0,options,l,m,I,g); 27 | 28 | 29 | pendanimate(t,z,l) 30 | 31 | function zdot = f(t,z,l,m,I,g) 32 | 33 | x = z(1); 34 | xdot = z(2); 35 | y = z(3); 36 | ydot = z(4); 37 | th = z(5); 38 | thdot = z(6); 39 | 40 | A = [m 0 0 -1 0; 41 | 0 m 0 0 -1; 42 | 0 0 I -(l/2)*sin(th) (l/2)*cos(th); 43 | -1 0 -(l/2)*sin(th) 0 0; 44 | 0 -1 (l/2)*cos(th) 0 0]; 45 | b = [ m*g; 46 | 0; 47 | 0; 48 | (l/2)*cos(th)*thdot^2; 49 | (l/2)*sin(th)*thdot^2]; 50 | 51 | X = A \ b; 52 | xddot = X(1); 53 | yddot = X(2); 54 | thddot = X(3); 55 | 56 | zdot = [xdot xddot ydot yddot thdot thddot]'; 57 | 58 | function pendanimate(t,z,l) 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | 61 | clf 62 | 63 | moviescaling = 1; % slow down factor 64 | n=length(t); dur=t(end); 65 | delay =floor(moviescaling*1000*dur/n); %delay per frame in .001 secs 66 | 67 | bar1ref = [0 1; 0 0]; 68 | 69 | r = l/2; 70 | axis('equal') 71 | d = 0.2*r; 72 | axis([-2*r-d 2*r+d -2*r-d 2*r+d]); 73 | 74 | bar1pic=line('xdata',bar1ref(1,:),'ydata',bar1ref(2,:), ... 75 | 'linewidth', 3, 'erase','xor','color','red'); 76 | 77 | hinge=line('xdata',0,'ydata',0, 'marker','.','markersize',[30], ... 78 | 'color','black','erase', 'xor'); 79 | 80 | for i=1:n 81 | for j=1:100, log(1:delay*10); end %delay for graphics. 82 | %the number in this expression 83 | %is machine dependent. 84 | %The LOG is just something 85 | %to keep the machine busy. 86 | 87 | theta = -pi/2; 88 | R=[cos(theta) -sin(theta) ; sin(theta) cos(theta)]; 89 | x = z(i,1); y = z(i,3); th = z(i,5); 90 | 91 | bar1 = R*[x-r*cos(th) x+r*cos(th); y-r*sin(th) y+r*sin(th)]; 92 | set(bar1pic,'xdata',bar1(1,:),'ydata',bar1(2,:)); 93 | 94 | drawnow 95 | if i==1 96 | pause(1) 97 | end 98 | end 99 | -------------------------------------------------------------------------------- /sandbox/examples/pendulum_with_moving_top/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/examples/pendulum_with_moving_top/.DS_Store -------------------------------------------------------------------------------- /sandbox/examples/pendulum_with_moving_top/notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/examples/pendulum_with_moving_top/notes.pdf -------------------------------------------------------------------------------- /sandbox/examples/rotateface.m: -------------------------------------------------------------------------------- 1 | % Drawing and rotation of drawing 2 | s=linspace(0, 2*pi, 20); % 21 points from zero to 2*pi 3 | 4 | % parametric description of a circle 5 | circ = [cos(s); -sin(s)]; %first row is x, second is y 6 | 7 | % The body parts are mostly obtained by stretching the x and/or 8 | % y components (multiplication) or displacing them (addition) 9 | head = [3*circ(1,:); 4*circ(2,:)]; 10 | mouth= [circ(1,1:10); circ(2,1:10)-1.8]; %half a circle 11 | nose = [[0 .5 0]; [-.5 -1.5 -1.5]]; % three points, an open triangle 12 | lefteye = [ circ(1,:)*.7-1 ; circ(2,:)/3+.3 ]; 13 | righteye = [ circ(1,:)*.7+1 ; circ(2,:)/3+.3 ]; 14 | 15 | % The matrices above are put side to side into a big two 16 | % row matrix called pict. The top row is x components of 17 | % points in the picture, the bottom row is y components. 18 | % Between each matrix is the 19 | % column vector [nan nan]' which is the two numbers 20 | % "Not a Number" in a column. When plotting, MATLAB 21 | % skips [nan nan]'. Thus this is a trick to keep the 22 | % pieces of the picture from connecting to each other. 23 | refpict = [ head [nan nan]' ... 24 | mouth [nan nan]' ... 25 | nose [nan nan]' ... 26 | lefteye [nan nan]' ... 27 | righteye [nan nan]'] ; 28 | 29 | refpict(2,:) = refpict(2,:) -10; % offset 30 | 31 | hold off; 32 | plot(refpict(1,:),refpict(2,:)) 33 | axis('equal') 34 | 35 | hold on 36 | theta = pi/4; 37 | R = [ cos(theta) -sin(theta); 38 | sin(theta) cos(theta) ]; 39 | pict = R*refpict; 40 | plot(pict(1,:),pict(2,:)); 41 | axis('equal') 42 | 43 | 44 | 45 | 46 | disp(['End at: ' datestr(now)]) -------------------------------------------------------------------------------- /sandbox/examples/springmass2.m: -------------------------------------------------------------------------------- 1 | function springmass2 () 2 | %Spring-mass with forcing 3 | % mx'' + cx' + kx = F_0 sin (omega t) 4 | m=2; k = 5; c= 0.2; 5 | F0 = 5; 6 | omega = sqrt(k/m); %force at resonant frequency 7 | 8 | tspan=[0 20*pi]; 9 | x0 = 0; v0=0; % initial conditions 10 | z0 = [x0 v0]; 11 | 12 | 13 | [t z_soln] =ode45(@W,tspan, z0,[],m,k,c,omega,F0); 14 | 15 | %unpack z_soln, matrix where each row i is the 16 | %value of z at time t(i) 17 | x = z_soln(:,1); % first column of z_soln 18 | v = z_soln(:,2); % second column 19 | 20 | figure(1) 21 | plot (t, x); 22 | xlabel('t = time') 23 | ylabel('x = position') 24 | title('Andy''s plot') 25 | grid on 26 | figure(2) 27 | plot(x,v); 28 | axis('equal') 29 | xlabel('x = position') 30 | ylabel('v = velocity') 31 | title('Phase plot') 32 | grid on 33 | 34 | end 35 | 36 | % Here is the differential equation 37 | function zdot=W(t,z,m,k,c,omega,F0) 38 | %unpack z, list of values of z at time t 39 | x = z(1); 40 | v = z(2); 41 | 42 | xdot = v; 43 | vdot = -(k/m)*x - (c/m)*v + F0*sin(omega*t); 44 | 45 | zdot = [xdot vdot]'; 46 | end -------------------------------------------------------------------------------- /sandbox/examples/twodof.m: -------------------------------------------------------------------------------- 1 | function twodof 2 | %TWO MASSES IN A LINE WITH A SPRING BETWEEN THEM 3 | %AND A SPRING FROM EACH TO THE WALL (3 SPRINGS) 4 | m1 = 1; m2 = 2; 5 | k1 = 1; k2 = 1; k3 = 1; 6 | M = [m1 0 ; 0 m2]; 7 | %NOTE SIGNS 8 | K = [ (k1 + k2) -k2 ; 9 | -k2 (k2 + k3) ]; 10 | 11 | tspan = linspace(0,10, 1001); 12 | xzero = [1 -1]'; % INITIAL DISPLACEMENT 13 | vzero = [0 0 ]'; 14 | zzero = [xzero; vzero]; 15 | 16 | [t zmat] = ode45(@rhs, tspan, zzero,[],M, K); 17 | 18 | x = zmat(:,[1 2]); 19 | v = zmat(:,[3 4]); 20 | 21 | plot(t,x(:,1), t, x(:,2)) 22 | xlabel('time'); ylabel('position(s)') 23 | title('Motion of the two masses') 24 | disp(['It is now ' datestr(now) ' , try again?']) 25 | end 26 | 27 | 28 | function zdot = rhs(t,z,M,K) 29 | x=z([1 2]); 30 | v=z([3 4]); 31 | xdot = v; 32 | 33 | vdot = M^(-1)* (-K) *x; 34 | 35 | zdot = [xdot; vdot]; 36 | end -------------------------------------------------------------------------------- /sandbox/liwei/master-thesis/ode_thesis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/liwei/master-thesis/ode_thesis.pdf -------------------------------------------------------------------------------- /sandbox/liwei/master-thesis/ode_thesis.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/liwei/master-thesis/ode_thesis.tex -------------------------------------------------------------------------------- /sandbox/liwei/master-thesis/odespy_slides.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/liwei/master-thesis/odespy_slides.odp -------------------------------------------------------------------------------- /sandbox/liwei/master-thesis/odespy_slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/liwei/master-thesis/odespy_slides.pdf -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/INSTALL: -------------------------------------------------------------------------------- 1 | ======== 2 | ASSIMULO 3 | ======== 4 | 5 | INSTALL 6 | ======= 7 | 8 | *REQUIREMENTS 9 | -Python-2.6 / 2.7 (with headers) 10 | -Numpy, Scipy, Pylab 11 | -Sundials-2.4.0 12 | -Cython 13 | 14 | Installation is performed using the command: 15 | 16 | 'python setup.py install --sundials-home=/path/to/sundials' 17 | 18 | The argument --sundials-home should point to where Sundials have been 19 | installed. Assimulo is then installed under Python dist-packages. 20 | To test the installation, browse to the tests folder and do a 'nosetests'. 21 | (The testing needs additionally the python-nose package) 22 | 23 | For more information regarding Assimulo and the installation procedure, 24 | please visit: http://www.jmodelica.org/assimulo 25 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: Assimulo 3 | Version: 2.0 4 | Summary: A package for solving ordinary differential equations and differential algebraic equations. 5 | Home-page: http://www.jmodelica.org/assimulo 6 | Author: C. Andersson, C. Führer, J. Åkesson, M. Gäfvert 7 | Author-email: chria@maths.lth.se 8 | License: GPL 9 | Download-URL: http://www.jmodelica.org/assimulo 10 | Description: 11 | Assimulo is a Cython / Python based simulation package that allows for 12 | simulation of both ordinary differential equations (ODEs), f(t,y), and 13 | differential algebraic equations (DAEs), f(t,y,yd). It combines a 14 | variety of different solvers written in C and Python via a common 15 | high-level interface. 16 | 17 | Assimulo currently supports Explicit Euler, adaptive Runge-Kutta of 18 | order 4 and Runge-Kutta of order 4. It also wraps the popular SUNDIALS 19 | (https://computation.llnl.gov/casc/sundials/main.html) solvers CVode 20 | (for ODEs) and IDA (for DAEs). A Python version of Ernst Hairer's code 21 | (http://www.unige.ch/~hairer/software.html) Radau5 is also available. 22 | 23 | Documentation and installation instructions can be found at: 24 | http://www.jmodelica.org/assimulo . 25 | 26 | For questions and comments, visit: 27 | http://www.jmodelica.org/forums/jmodelicaorg-users/assimulo 28 | 29 | The package requires Numpy, Scipy and Matplotlib and additionally for 30 | compiling from source, Cython 0.15 and Sundials 2.4. 31 | 32 | Platform: Linux 33 | Platform: Windows 34 | Platform: MacOS X 35 | Classifier: Programming Language :: Python 36 | Classifier: Programming Language :: Cython 37 | Classifier: Programming Language :: C 38 | Classifier: Operating System :: MacOS :: MacOS X 39 | Classifier: Operating System :: Microsoft :: Windows 40 | Classifier: Operating System :: Unix 41 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/README: -------------------------------------------------------------------------------- 1 | ======== 2 | ASSIMULO 3 | ======== 4 | 5 | README 6 | ======= 7 | 8 | Assimulo is a Python based simulation package that allows for simulation of both 9 | ordinary differential equations of the form f(t,y), (explicit problems) and 10 | differential algebraic equations of the form f(t,y,yd), (implicit problems). 11 | Assimulo currently supports Explicit Euler, adaptive Runge-Kutta of order 4 12 | and Runge-Kutta of order 4. It also wraps the popular SUNDIALS 13 | (https://computation.llnl.gov/casc/sundials/main.html) solvers CVode 14 | (for explicit problems) and IDA (for implicit problems). A Python version of 15 | Ernst Hairer's code (http://www.unige.ch/~hairer/software.html) Radau5 is also available. 16 | CVode and IDA supports discontinuous systems of the form f(t,y,sw) and f(t,y,yd,sw) with 17 | event(root)-functions defined as g(t,y,sw) and g(t,y,yd,sw) where 18 | sw should be fixed during the integration. 19 | 20 | The package comes with a Problem specifications class and subclasses corresponding 21 | to the different problem, Implicit_Problem and Explicit_Problem. To define and 22 | solve a problem, first import the solver of choice and the appropriate 23 | (Implicit/Explicit)_Problem class. Then define your function, f and initial conditions 24 | which pass to the problem class constructor. Then create your solver, set the attributes 25 | (method, absolute/relative tolerance etc.) and use the simulate method to simulate. 26 | 27 | For more information about Assimulo, documentation tutorial etc, visit 28 | http://www.jmodelica.org/assimulo 29 | 30 | 31 | INSTALL 32 | See the INSTALL file or the installation page on http://www.jmodelica.org/assimulo. 33 | 34 | CONTACT 35 | Trac-site: https://trac.jmodelica.org/assimulo/wiki 36 | Homepage: http://www.jmodelica.org/assimulo 37 | Email: chria@maths.lth.se 38 | 39 | The package is currently under development and any input is appreciated. 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | def testattr(**kwargs): 19 | """Add attributes to a test function/method/class. 20 | 21 | This function is needed to be able to add 22 | @attr(slow = True) 23 | for functions. 24 | 25 | """ 26 | def wrap(func): 27 | func.__dict__.update(kwargs) 28 | return func 29 | return wrap 30 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/constants.pxi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2010 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | """ 18 | This file contains the constants used in Assimulo. 19 | """ 20 | 21 | #Return flags 22 | """ 23 | DEF ID_OK = 0 24 | DEF ID_DISCARD = 1 25 | DEF ID_EVENT = 2 26 | DEF ID_COMPLETE = 3 27 | DEF ID_FAIL = -1 28 | """ 29 | 30 | #Verbosity levels 31 | DEF DEBUG = 10 32 | DEF INFO = 20 33 | DEF WARNING = 30 34 | DEF ERROR = 40 35 | DEF CRITICAL = 50 36 | 37 | #Backward compability 38 | QUIET = CRITICAL 39 | WHISPER = ERROR 40 | NORMAL = WARNING 41 | LOUD = INFO 42 | SCREAM = DEBUG 43 | 44 | 45 | DEF ID_OK = 0 46 | DEF ID_DISCARD = 1 47 | DEF ID_EVENT = 2 48 | DEF ID_COMPLETE = 3 49 | DEF ID_FAIL = -1 50 | 51 | ID_PY_OK = 0 52 | ID_PY_DISCARD = 1 53 | ID_PY_EVENT = 2 54 | ID_PY_COMPLETE = 3 55 | ID_PY_FAIL = -1 56 | 57 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | __all__ = ["cvode_gyro", "cvode_basic", "cvode_with_disc", "cvode_with_initial_sensitivity", 19 | "cvode_with_jac", "cvode_with_jac_spgmr", "cvode_with_parameters", "euler_basic", 20 | "rungekutta4_basic", "rungekutta34_basic", "ida_with_disc", "ida_with_initial_sensitivity", 21 | "ida_with_jac", "ida_with_parameters", "radau5ode_vanderpol","radau5dae_vanderpol"] 22 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/cvode_basic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | #import pylab as P 20 | import nose 21 | from assimulo.solvers.sundials import CVode 22 | from assimulo.problem import Explicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | global exp_mod, exp_sim 26 | 27 | #Define the rhs 28 | def f(t,y): 29 | ydot = -y[0] 30 | return N.array([ydot]) 31 | 32 | #Define an Assimulo problem 33 | exp_mod = Explicit_Problem(f, y0=4) 34 | exp_mod.name = 'Simple CVode Example' 35 | 36 | #Define an explicit solver 37 | exp_sim = CVode(exp_mod) #Create a CVode solver 38 | 39 | #Sets the parameters 40 | exp_sim.iter = 'Newton' #Default 'FixedPoint' 41 | exp_sim.discr = 'BDF' #Default 'Adams' 42 | exp_sim.atol = [1e-4] #Default 1e-6 43 | exp_sim.rtol = 1e-4 #Default 1e-6 44 | 45 | #Simulate 46 | t1, y1 = exp_sim.simulate(5,100) #Simulate 5 seconds 47 | t2, y2 = exp_sim.simulate(7) #Simulate 2 seconds more 48 | 49 | #Basic test 50 | nose.tools.assert_almost_equal(y2[-1], 0.00347746, 5) 51 | 52 | #Plot 53 | #if with_plots: 54 | # P.plot(t1, y1, color="b") 55 | # P.plot(t2, y2, color="b") 56 | # P.show() 57 | 58 | if __name__=='__main__': 59 | run_example() 60 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/cvode_gyro.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from assimulo.problem import Explicit_Problem 19 | from assimulo.solvers.sundials import CVode 20 | from scipy import * 21 | import nose 22 | import pylab as P 23 | 24 | def run_example(with_plots=True): 25 | 26 | def curl(v): 27 | return array([[0,v[2],-v[1]],[-v[2],0,v[0]],[v[1],-v[0],0]]) 28 | 29 | #Defines the rhs 30 | def f(t,u): 31 | """ 32 | Simulations for the Gyro (Heavy Top) example in Celledoni/Safstrom: 33 | Journal of Physics A, Vol 39, 5463-5478, 2006 34 | """ 35 | I1=1000. 36 | I2=5000. 37 | I3=6000. 38 | u0=[0,0,1.] 39 | pi=u[0:3] 40 | Q=(u[3:12]).reshape((3,3)) 41 | Qu0=dot(Q,u0) 42 | f=array([Qu0[1],-Qu0[0],0.]) 43 | f=0 44 | omega=array([pi[0]/I1,pi[1]/I2,pi[2]/I3]) 45 | pid=dot(curl(omega),pi)+f 46 | Qd=dot(curl(omega),Q) 47 | return hstack([pid,Qd.reshape((9,))]) 48 | 49 | def energi(state): 50 | energi=[] 51 | for st in state: 52 | Q=(st[3:12]).reshape((3,3)) 53 | pi=st[0:3] 54 | u0=[0,0,1.] 55 | Qu0=dot(Q,u0) 56 | V=Qu0[2] # potential energy 57 | T=0.5*(pi[0]**2/1000.+pi[1]**2/5000.+pi[2]**2/6000.) 58 | energi.append([T]) 59 | return energi 60 | 61 | #Initial conditions 62 | y0=hstack([[1000.*10,5000.*10,6000*10],eye(3).reshape((9,))]) 63 | 64 | #Create an Assimulo explicit problem 65 | gyro_mod = Explicit_Problem(f,y0) 66 | 67 | #Create an Assimulo explicit solver (CVode) 68 | gyro_sim=CVode(gyro_mod) 69 | 70 | #Sets the parameters 71 | gyro_sim.discr='BDF' 72 | gyro_sim.iter='Newton' 73 | gyro_sim.maxord=2 #Sets the maxorder 74 | gyro_sim.atol=1.e-10 75 | gyro_sim.rtol=1.e-10 76 | 77 | #Simulate 78 | t, y = gyro_sim.simulate(0.1) 79 | 80 | #Basic tests 81 | nose.tools.assert_almost_equal(y[-1][0],692.800241862) 82 | nose.tools.assert_almost_equal(y[-1][8],7.08468221e-1) 83 | 84 | #Plot 85 | if with_plots: 86 | P.plot(t,y) 87 | P.show() 88 | 89 | if __name__=='__main__': 90 | run_example() 91 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/cvode_with_jac.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.sundials import CVode 22 | from assimulo.problem import Explicit_Problem 23 | 24 | 25 | def run_example(with_plots=True): 26 | global t,y 27 | 28 | #Defines the rhs 29 | def f(t,y): 30 | yd_0 = y[1] 31 | yd_1 = -9.82 32 | #print y, yd_0, yd_1 33 | return N.array([yd_0,yd_1]) 34 | 35 | #Defines the jacobian 36 | def jac(t,y): 37 | j = N.array([[0,1.],[0,0]]) 38 | return j 39 | 40 | #Defines an Assimulo explicit problem 41 | y0 = [1.0,0.0] #Initial conditions 42 | 43 | exp_mod = Explicit_Problem(f,y0) 44 | 45 | exp_mod.jac = jac #Sets the jacobian 46 | exp_mod.name = 'Example using Jacobian' 47 | 48 | 49 | exp_sim = CVode(exp_mod) #Create a CVode solver 50 | 51 | #Set the parameters 52 | exp_sim.iter = 'Newton' #Default 'FixedPoint' 53 | exp_sim.discr = 'BDF' #Default 'Adams' 54 | exp_sim.atol = 1e-5 #Default 1e-6 55 | exp_sim.rtol = 1e-5 #Default 1e-6 56 | 57 | #Simulate 58 | t, y = exp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points 59 | 60 | #Basic tests 61 | nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4) 62 | nose.tools.assert_almost_equal(y[-1][1],-49.100000000) 63 | 64 | #Plot 65 | if with_plots: 66 | P.plot(t,y,linestyle="dashed",marker="o") #Plot the solution 67 | P.show() 68 | 69 | 70 | if __name__=='__main__': 71 | run_example() 72 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/cvode_with_jac_spgmr.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.sundials import CVode 22 | from assimulo.problem import Explicit_Problem 23 | 24 | 25 | def run_example(with_plots=True): 26 | 27 | #Defines the rhs 28 | def f(t,y): 29 | yd_0 = y[1] 30 | yd_1 = -9.82 31 | 32 | return N.array([yd_0,yd_1]) 33 | 34 | #Defines the jacobian*vector product 35 | def jacv(t,y,fy,v): 36 | j = N.array([[0,1.],[0,0]]) 37 | return N.dot(j,v) 38 | 39 | y0 = [1.0,0.0] #Initial conditions 40 | 41 | #Defines an Assimulo explicit problem 42 | exp_mod = Explicit_Problem(f,y0) 43 | 44 | exp_mod.jacv = jacv #Sets the jacobian 45 | exp_mod.name = 'Example using the Jacobian Vector product' 46 | 47 | exp_sim = CVode(exp_mod) #Create a CVode solver 48 | 49 | #Set the parameters 50 | exp_sim.iter = 'Newton' #Default 'FixedPoint' 51 | exp_sim.discr = 'BDF' #Default 'Adams' 52 | exp_sim.atol = 1e-5 #Default 1e-6 53 | exp_sim.rtol = 1e-5 #Default 1e-6 54 | exp_sim.linear_solver = 'SPGMR' #Change linear solver 55 | #exp_sim.options["usejac"] = False 56 | 57 | #Simulate 58 | t, y = exp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points 59 | 60 | #Basic tests 61 | nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4) 62 | nose.tools.assert_almost_equal(y[-1][1],-49.100000000) 63 | 64 | #Plot 65 | if with_plots: 66 | P.plot(t,y) 67 | P.show() 68 | 69 | if __name__=='__main__': 70 | run_example() 71 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/euler_basic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.euler import * 22 | from assimulo.problem import Explicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | 26 | #Defines the rhs 27 | def f(t,y): 28 | ydot = -y[0] 29 | return N.array([ydot]) 30 | 31 | #Define an Assimulo problem 32 | exp_mod = Explicit_Problem(f, 4.0) 33 | exp_mod.name = 'Simple Explicit Example' 34 | 35 | #Explicit Euler 36 | exp_sim = ExplicitEuler(exp_mod) #Create a explicit Euler solver 37 | exp_sim.options["continuous_output"] = True 38 | 39 | #Simulate 40 | t1, y1 = exp_sim.simulate(3) #Simulate 3 seconds 41 | t2, y2 = exp_sim.simulate(5,100) #Simulate 2 second more 42 | 43 | #Basic test 44 | nose.tools.assert_almost_equal(y2[-1], 0.02628193) 45 | 46 | #Plot 47 | if with_plots: 48 | P.plot(t1, y1, color="b") 49 | P.plot(t2, y2, color="b") 50 | P.show() 51 | 52 | if __name__=='__main__': 53 | run_example() 54 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/radau5dae_vanderpol.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.radau5 import * 22 | from assimulo.problem import Implicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | 26 | #Define the residual 27 | def f(t,y,yd): 28 | eps = 1.e-6 29 | my = 1./eps 30 | yd_0 = y[1] 31 | yd_1 = my*((1.-y[0]**2)*y[1]-y[0]) 32 | 33 | res_0 = yd[0]-yd_0 34 | res_1 = yd[1]-yd_1 35 | 36 | return N.array([res_0,res_1]) 37 | 38 | y0 = [2.0,-0.6] #Initial conditions 39 | yd0 = [-.6,-200000.] 40 | 41 | #Define an Assimulo problem 42 | imp_mod = Implicit_Problem(f,y0,yd0) 43 | imp_mod.name = 'Van der Pol (implicit)' 44 | 45 | #Define an explicit solver 46 | imp_sim = Radau5DAE(imp_mod) #Create a Radau5 solver 47 | 48 | #Sets the parameters 49 | imp_sim.atol = 1e-4 #Default 1e-6 50 | imp_sim.rtol = 1e-4 #Default 1e-6 51 | imp_sim.inith = 1.e-4 #Initial step-size 52 | 53 | #Simulate 54 | t, y, yd = imp_sim.simulate(2.) #Simulate 2 seconds 55 | 56 | #Plot 57 | if with_plots: 58 | P.plot(t,y[:,0], marker='o') 59 | P.show() 60 | 61 | #Basic test 62 | x1 = y[:,0] 63 | assert N.abs(x1[-1]-1.706168035) < 1e-3 #For test purpose 64 | 65 | if __name__=='__main__': 66 | run_example() 67 | 68 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/radau5ode_vanderpol.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.radau5 import * 22 | from assimulo.problem import Explicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | 26 | #Define the rhs 27 | def f(t,y): 28 | eps = 1.e-6 29 | my = 1./eps 30 | yd_0 = y[1] 31 | yd_1 = my*((1.-y[0]**2)*y[1]-y[0]) 32 | 33 | return N.array([yd_0,yd_1]) 34 | 35 | y0 = [2.0,-0.6] #Initial conditions 36 | 37 | #Define an Assimulo problem 38 | exp_mod = Explicit_Problem(f,y0) 39 | exp_mod.name = 'Van der Pol (explicit)' 40 | 41 | #Define an explicit solver 42 | exp_sim = Radau5ODE(exp_mod) #Create a Radau5 solver 43 | 44 | #Sets the parameters 45 | exp_sim.atol = 1e-4 #Default 1e-6 46 | exp_sim.rtol = 1e-4 #Default 1e-6 47 | exp_sim.inith = 1.e-4 #Initial step-size 48 | 49 | #Simulate 50 | t, y = exp_sim.simulate(2.) #Simulate 2 seconds 51 | 52 | #Plot 53 | if with_plots: 54 | P.plot(t,y[:,0], marker='o') 55 | P.show() 56 | 57 | #Basic test 58 | x1 = y[:,0] 59 | assert N.abs(x1[-1]-1.706168035) < 1e-3 #For test purpose 60 | 61 | if __name__=='__main__': 62 | run_example() 63 | 64 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/rungekutta34_basic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.runge_kutta import * 22 | from assimulo.problem import Explicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | 26 | #Defines the rhs 27 | def f(t,y): 28 | ydot = -y[0] 29 | return N.array([ydot]) 30 | 31 | #Define an Assimulo problem 32 | exp_mod = Explicit_Problem(f, 4.0) 33 | exp_mod.name = 'Simple Explicit Example' 34 | 35 | exp_sim = RungeKutta34(exp_mod) #Create a RungeKutta34 solver 36 | exp_sim.inith = 0.1 #Sets the initial step, default = 0.01 37 | 38 | #Simulate 39 | t, y = exp_sim.simulate(5) #Simulate 5 seconds 40 | 41 | #Basic test 42 | nose.tools.assert_almost_equal(y[-1],0.02695199,5) 43 | 44 | #Plot 45 | if with_plots: 46 | P.plot(t,y) 47 | P.show() 48 | 49 | if __name__=='__main__': 50 | run_example() 51 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/examples/rungekutta4_basic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import numpy as N 19 | import pylab as P 20 | import nose 21 | from assimulo.solvers.runge_kutta import * 22 | from assimulo.problem import Explicit_Problem 23 | 24 | def run_example(with_plots=True): 25 | 26 | #Defines the rhs 27 | def f(t,y): 28 | ydot = -y[0] 29 | return N.array([ydot]) 30 | 31 | #Define an Assimulo problem 32 | exp_mod = Explicit_Problem(f, 4.0) 33 | exp_mod.name = 'Simple Explicit Example' 34 | 35 | exp_sim = RungeKutta4(exp_mod) #Create a RungeKutta4 solver 36 | 37 | #Simulate 38 | t, y = exp_sim.simulate(5, 100) #Simulate 5 seconds 39 | 40 | #Basic test 41 | nose.tools.assert_almost_equal(y[-1],0.02695179) 42 | 43 | #Plot 44 | if with_plots: 45 | P.plot(t,y) 46 | P.show() 47 | 48 | if __name__=='__main__': 49 | run_example() 50 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/exception.py: -------------------------------------------------------------------------------- 1 | 2 | class AssimuloException(Exception): 3 | pass 4 | 5 | class TerminateSimulation(AssimuloException): 6 | pass 7 | 8 | class DiscardValue(AssimuloException): 9 | pass 10 | 11 | class Explicit_ODE_Exception(AssimuloException): 12 | pass 13 | 14 | class ODE_Exception(AssimuloException): 15 | pass 16 | 17 | class Implicit_ODE_Exception(AssimuloException): 18 | pass 19 | 20 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/explicit_ode.pxd: -------------------------------------------------------------------------------- 1 | 2 | from ode cimport ODE 3 | import numpy as N 4 | cimport numpy as N 5 | 6 | 7 | cdef class Explicit_ODE(ODE): 8 | 9 | cpdef _simulate(self, double t0, double tfinal,N.ndarray output_list,int ONE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT, int STEP_EVENT) 10 | 11 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/implicit_ode.pxd: -------------------------------------------------------------------------------- 1 | 2 | from ode cimport ODE 3 | import numpy as N 4 | cimport numpy as N 5 | 6 | 7 | cdef class Implicit_ODE(ODE): 8 | 9 | cpdef _simulate(self, double t0, double tfinal,N.ndarray output_list,int ONE_STEP, int INTERPOLATE_OUTPUT,int TIME_EVENT, int STEP_EVENT) 10 | 11 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/__init__.py -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinpinv.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinpinv.c -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinpinv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinpinv.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinslug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinslug.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod.c -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_impl.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_impl.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_impl_wSLU.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_impl_wSLU.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_wSLU.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/kinsol_jmod_wSLU.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/lib/reg_routines.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/lib/reg_routines.h -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/ode.pxd: -------------------------------------------------------------------------------- 1 | import numpy as N 2 | cimport numpy as N 3 | 4 | cdef class ODE: 5 | cdef public dict options, solver_options, problem_info 6 | cdef public dict supports, statistics 7 | 8 | cdef public list event_data 9 | 10 | cdef public object problem 11 | 12 | cdef public double t, t0 13 | cdef public N.ndarray y,yd, p 14 | cdef public N.ndarray y0, yd0, p0, sw0 15 | 16 | #cdef public list t,y,yd,p,sw_cur 17 | cdef public list t_sol, y_sol, yd_sol, p_sol, sw 18 | 19 | cpdef log_message(self, message, int level) 20 | cpdef log_event(self, double time, object event_info, int level) 21 | cpdef simulate(self, double tfinal, int ncp=*, object ncp_list=*) 22 | cpdef get_options(self) 23 | cpdef get_supports(self) 24 | cpdef get_statistics(self) 25 | cpdef get_event_data(self) 26 | cpdef print_event_data(self) 27 | cpdef finalize(self) 28 | cpdef initialize(self) 29 | cdef _reset_solution_variables(self) 30 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/solvers/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | __all__ = ["euler","radau5","sundials","runge_kutta"] 19 | 20 | from euler import ExplicitEuler 21 | from radau5 import Radau5ODE, Radau5DAE 22 | from sundials import IDA, CVode 23 | from runge_kutta import RungeKutta34, RungeKutta4 24 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hplgit/odespy/c1200a6d1a36ba539766a8bbfb9104740cfb74c7/sandbox/potential_packages/Assimulo-2.0/assimulo/tests/__init__.py -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/tests/solvers/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/tests/test_explicit_ode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import nose 19 | from assimulo import testattr 20 | from assimulo.explicit_ode import * 21 | from assimulo.problem import Explicit_Problem 22 | from assimulo.exception import * 23 | 24 | class Test_Explicit_ODE: 25 | pass 26 | 27 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/tests/test_implicit_ode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import nose 19 | from assimulo import testattr 20 | from assimulo.implicit_ode import * 21 | from assimulo.problem import Implicit_Problem 22 | from assimulo.exception import * 23 | 24 | class Test_Implicit_ODE: 25 | pass 26 | -------------------------------------------------------------------------------- /sandbox/potential_packages/Assimulo-2.0/assimulo/tests/test_ode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Copyright (C) 2011 Modelon AB 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3 of the License. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import nose 19 | from assimulo import testattr 20 | from assimulo.ode import * 21 | from assimulo.problem import Explicit_Problem 22 | from assimulo.exception import * 23 | 24 | class Test_ODE: 25 | 26 | def setUp(self): 27 | self.problem = Explicit_Problem(y0=4.0) 28 | self.simulator = ODE(self.problem) 29 | 30 | @testattr(stddist = True) 31 | def test_init(self): 32 | """ 33 | This tests the functionality of the method __init__. 34 | """ 35 | assert self.simulator.verbosity == NORMAL 36 | assert self.simulator.continuous_output == False 37 | 38 | @testattr(stddist = True) 39 | def test_verbosity(self): 40 | """ 41 | This tests the functionality of the property verbosity. 42 | """ 43 | nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, 'Test') 44 | nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, [1, 31]) 45 | nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, [1]) 46 | 47 | self.simulator.verbosity=1 48 | assert self.simulator.verbosity==1 49 | assert self.simulator.options["verbosity"] == 1 50 | self.simulator.verbosity=4 51 | assert self.simulator.verbosity==4 52 | assert self.simulator.options["verbosity"] == 4 53 | 54 | @testattr(stddist = True) 55 | def test_continuous_output(self): 56 | """ 57 | This tests the functionality of the property continuous_output. 58 | """ 59 | assert self.simulator.continuous_output == False #Test the default value 60 | 61 | self.simulator.continuous_output = True 62 | assert self.simulator.continuous_output == True 63 | assert self.simulator.options["continuous_output"] == True 64 | -------------------------------------------------------------------------------- /sandbox/potential_packages/dmv10/dr_dmv10.f: -------------------------------------------------------------------------------- 1 | C * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | C --- DRIVER FOR DMV10 FOR THE MOTION OF A RIGID BODY 3 | C * * * * * * * * * * * * * * * * * * * * * * * * * * * 4 | include 'dmv10.f' 5 | IMPLICIT DOUBLE PRECISION (A-H,O-Z) 6 | DIMENSION Q(4),AM(3),RPAR(20),IPAR(20) 7 | REAL TIME0,TIME1 8 | EXTERNAL POTENP 9 | C --- INITIAL VALUES 10 | C ANGULAR MOMENTUM 11 | AM(1)=1.8D0 12 | AM(2)=0.4D0 13 | AM(3)=-0.9D0 14 | C QUATERNION 15 | Q(1)=1.0D0 16 | Q(2)=0.0D0 17 | Q(3)=0.0D0 18 | Q(4)=0.0D0 19 | C --- MOMENTS OF INERTIA 20 | AI1=0.6D0 21 | AI2=0.8D0 22 | AI3=1.0D0 23 | RPAR(11)=AI1 24 | RPAR(12)=AI2 25 | RPAR(13)=AI3 26 | C --- 27 | H=0.01 28 | XEND=10.0D0 29 | NSTEP=XEND/H 30 | H=XEND/NSTEP 31 | WRITE (6,*) 'XEND=',XEND,' H=',H,' NSTEP=',NSTEP 32 | C --- 33 | DO I=1,10 34 | RPAR(I)=0.0D0 35 | IPAR(I)=0 36 | END DO 37 | C 38 | WRITE (6,*) '--- INITIAL CONDITION' 39 | WRITE (6,*) ' AM ',AM(1),AM(2),AM(3) 40 | WRITE (6,*) ' QQ ',Q(1),Q(2),Q(3),Q(4) 41 | CALL HAMIL(Q,AM,HAM0,RPAR,IPAR) 42 | CALL CPU_TIME(TIME0) 43 | C --- 44 | CALL DMV10 (AM,Q,POTENP,H,NSTEP,RPAR,IPAR) 45 | C --- 46 | CALL CPU_TIME(TIME1) 47 | CALL HAMIL(Q,AM,HAM1,RPAR,IPAR) 48 | WRITE (6,*) '--- SOLUTION AT ENDPOINT' 49 | WRITE (6,*) ' AM ',AM(1),AM(2),AM(3) 50 | WRITE (6,*) ' QQ ',Q(1),Q(2),Q(3),Q(4) 51 | WRITE (6,*) 'ERR HAM=',(HAM1-HAM0)/HAM0,' TIME=',TIME1-TIME0 52 | STOP 53 | END 54 | C 55 | SUBROUTINE HAMIL (Q,AM,HAM,RPAR,IPAR) 56 | IMPLICIT REAL*8 (A-H,O-Z) 57 | DIMENSION Q(4),AM(3) 58 | DIMENSION IPAR(*),RPAR(*) 59 | CALL POTEN(Q,POT,RPAR,IPAR) 60 | HAM=AM(1)**2/RPAR(11)+AM(2)**2/RPAR(12)+AM(3)**2/RPAR(13) 61 | HAM=HAM/2.0D0+POT 62 | RETURN 63 | END 64 | c 65 | SUBROUTINE POTEN(Q,POT,RPAR,IPAR) 66 | IMPLICIT REAL*8 (A-H,O-Z) 67 | DIMENSION Q(4) 68 | DIMENSION IPAR(*),RPAR(*) 69 | POT=Q(1)**2-Q(2)**2-Q(3)**2+Q(4)**2 70 | POT=0.0D0 71 | RETURN 72 | END 73 | c 74 | SUBROUTINE POTENP(Q,POTP,RPAR,IPAR) 75 | IMPLICIT REAL*8 (A-H,O-Z) 76 | DIMENSION Q(4),POTP(3) 77 | DIMENSION IPAR(*),RPAR(*) 78 | POTP(1)=-2*(Q(1)*Q(2)+Q(3)*Q(4)) 79 | POTP(2)=-2*(Q(1)*Q(3)-Q(2)*Q(4)) 80 | POTP(1)=0.0d0 81 | POTP(2)=0.0d0 82 | POTP(3)=0.0d0 83 | RETURN 84 | END 85 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/Contents.m: -------------------------------------------------------------------------------- 1 | % GniMatlab -- Geometric Numerical Integration codes for Matlab. 2 | % 3 | % GNI Integrators. 4 | % gni_irk2 - Implicit Runge-Kutta methods. 5 | % gni_lmm2 - Symmetric multistep methods. 6 | % gni_comp - Generic composition methods. 7 | % 8 | % GNI Option handling. 9 | % gniset - Create/alter GNI OPTIONS structure. 10 | % gniget - Get GNI OPTIONS parameters. 11 | % 12 | % Examples of GNI problem files. 13 | % henon - Henon-Heiles problem. 14 | % kepler - Kepler problem. 15 | % twobodysphere - Two-body problem on a sphere. 16 | % 17 | % Examples of custom output functions. 18 | % phaseplot - Two-dimensional plot in phase space. 19 | % sphereplot - Three-dimensional plot on a sphere. 20 | 21 | % Copyright (c) 2002 by Ernst Hairer & Martin Hairer. 22 | 23 | 24 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/coeff_lmm2.m: -------------------------------------------------------------------------------- 1 | function [A,B,C] = coeff_lmm2(method) 2 | switch method 3 | case '801', 4 | A = [1;0;1;0.5]; 5 | B = [17671;-23622;61449;-25258]/12096; 6 | case '802', 7 | A = [1;2;3;1.75]; 8 | B = [192481;6582;816783;-78406]/120960; 9 | case '803', 10 | A = [1;1;1;0.5]; 11 | B = [13207;-8934;42873;-16906]/8640; 12 | otherwise 13 | error(['The required method "' method '" is not implemented']); 14 | end 15 | C = [672;-168;32;-3]/840; 16 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/gnievents.m: -------------------------------------------------------------------------------- 1 | function [teout,ieout,qeout,peout,stop] = gnievents(odefile,E0,E1,P0,P1,Q0,Q1,T,direction,terminal,varargin) 2 | H=T(2) - T(1); 3 | H2=H*H; 4 | DIFF=(Q1-Q0)/H; 5 | 6 | P0DIF=P0-DIFF; 7 | P1DIF=P1-DIFF; 8 | 9 | teout = []; 10 | ieout = []; 11 | qeout = []; 12 | peout = []; 13 | stop = logical(0); 14 | LeftSave = []; 15 | RightSave = []; 16 | TSave = []; 17 | 18 | LeftCur = E0; 19 | RightCur = E1; 20 | TCur = T; 21 | StateCur = ((E0.*E1) <= 0) & (E1 ~= 0) & (direction .* (E1-E0) >= 0); 22 | 23 | Level = 0; 24 | 25 | while (max(StateCur) == 1) 26 | Time = (TCur(2)+TCur(1))/2; 27 | 28 | XM0=Time-T(1); 29 | XM1=Time-T(2); 30 | POLQ=Q0+XM0*(DIFF+XM1*(P1DIF*XM0+P0DIF*XM1)/H2); 31 | POLP=DIFF+(XM0*(2*XM1+XM0)*P1DIF+XM1*(2*XM0+XM1)*P0DIF)/H2; 32 | CurVal = feval(odefile,Time,[POLQ;POLP],'events',varargin{:}); 33 | 34 | StateR = (CurVal.*RightCur) <= 0; 35 | StateL = (CurVal.*LeftCur) <= 0; 36 | stopit = logical((TCur(1) == Time) | (TCur(2) == Time)); 37 | if (StateR == StateCur) 38 | LeftCur = CurVal; 39 | TCur(1) = Time; 40 | elseif (StateL == StateCur) 41 | RightCur = CurVal; 42 | TCur(2) = Time; 43 | else 44 | Level = Level+1; 45 | LeftSave = [LeftSave,CurVal]; 46 | RightSave = [RightSave,RightCur]; 47 | TSave = [TSave,[Time;TCur(2)]]; 48 | 49 | RightCur = CurVal; 50 | TCur(2) = Time; 51 | StateCur = StateL; 52 | end 53 | if stopit 54 | indices = (find(StateCur)); 55 | teout = [teout;Time*ones(size(indices))']; 56 | ieout = [ieout;indices]; 57 | qeout = [qeout;ones(size(indices))'*POLQ']; 58 | peout = [peout;ones(size(indices))'*POLP']; 59 | if (max(terminal(indices)) == 1) 60 | stop = logical(1); 61 | break; 62 | end 63 | if (Level > 0) 64 | TCur = TSave(:,Level); 65 | LeftCur = LeftSave(:,Level); 66 | RightCur = RightSave(:,Level); 67 | StateCur = ((LeftCur.*RightCur) <= 0) & (direction .* (RightCur - LeftCur) >= 0); 68 | Level = Level-1; 69 | 70 | TSave = TSave(:,1:Level); 71 | LeftSave = LeftSave(:,1:Level); 72 | RightSave = RightSave(:,1:Level); 73 | else 74 | break; 75 | end 76 | end 77 | end 78 | 79 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/gniget.m: -------------------------------------------------------------------------------- 1 | function o = gniget(options,name,default) 2 | %GNIGET Get GNI OPTIONS parameters. 3 | % VAL = GNIGET(OPTIONS,'NAME') extracts the value of the named property 4 | % from the options structure OPTIONS. The syntax is the same as for ODEGET. 5 | % 6 | % See also GNISET, GNI_IRK2, GNI_COMP, GNI_LMM2. 7 | 8 | if nargin < 2 9 | error('Not enough input arguments.'); 10 | end 11 | 12 | if ~isempty(options) & ~isa(options,'struct') 13 | error('First argument must be an options structure created with GNISET.'); 14 | end 15 | 16 | if isempty(options) 17 | if nargin == 3 18 | o = default; 19 | else 20 | o = []; 21 | end 22 | return; 23 | end 24 | 25 | Names = [ 26 | 'OutputFcn ' 27 | 'OutputSel ' 28 | 'OutputSteps ' 29 | 'Events ' 30 | 'Stats ' 31 | 'Vectorized ' 32 | 'Jacobian ' 33 | 'StepSize ' 34 | 'NumSteps ' 35 | 'MaxIter ' 36 | 'PartialFlow ' 37 | 'Method ' 38 | ]; 39 | [m,n] = size(Names); 40 | names = lower(Names); 41 | 42 | lowName = lower(name); 43 | j = strmatch(lowName,names); 44 | if isempty(j) % if no matches 45 | error(sprintf(['Unrecognized property name ''%s''. ' ... 46 | 'See GNISET for possibilities.'], name)); 47 | elseif length(j) > 1 % if more than one match 48 | % Check for any exact matches (in case any names are subsets of others) 49 | k = strmatch(lowName,names,'exact'); 50 | if length(k) == 1 51 | j = k; 52 | else 53 | msg = sprintf('Ambiguous property name ''%s'' ', name); 54 | msg = [msg '(' deblank(Names(j(1),:))]; 55 | for k = j(2:length(j))' 56 | msg = [msg ', ' deblank(Names(k,:))]; 57 | end 58 | msg = sprintf('%s).', msg); 59 | error(msg); 60 | end 61 | end 62 | 63 | eval(['o = options.' Names(j,:) ';']); 64 | 65 | if (nargin == 3) & isempty(o) 66 | o = default; 67 | end 68 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/henon.m: -------------------------------------------------------------------------------- 1 | function [out,out2,out3] = henon(t,q,flag) 2 | % Example GNI problem file for solving the Henon-Heiles problem. 3 | % Use it as follows: 4 | % 5 | % [T,Q,P,TE,QE,PE] = gni_meth('henon'); 6 | % plot3(QE(:,2),PE(:,1),PE(:,2),'o'); 7 | % 8 | % With gni_meth replaced by either gni_irk2, gni_lmm2, or gni_comp. 9 | if (nargin < 3) | isempty(flag) 10 | out(1,:)=-q(1,:).*(1+2*q(2,:)); 11 | out(2,:)=-q(2,:).*(1-q(2,:)) - q(1,:).^2; 12 | else 13 | switch flag 14 | case 'init', 15 | out = [0 1000]; 16 | out2 = [0.18 0.18 0.18 0.18]; 17 | out3 = gniset('StepSize',0.2,'Vectorized','on',... 18 | 'Events','on','OutputSteps',-1,'OutputFcn','phaseplot'); 19 | case 'events', 20 | out = [q(1)]; 21 | out2 = [0]; 22 | out3 = [0]; 23 | end 24 | end 25 | 26 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/kepler.m: -------------------------------------------------------------------------------- 1 | function [out,out2,out3] = kepler(t,q,flag,varargin) 2 | % Example GNI problem file for solving the 2D Kepler problem. 3 | % Use it as follows: 4 | % 5 | % gni_meth('kepler',[],[],[],0.7); 6 | % 7 | % With gni_meth replaced by either gni_irk2, gni_lmm2, or gni_comp 8 | % to draw the solution with eccentricity 0.7. 9 | if (nargin < 3) | isempty(flag) 10 | rad=q(1,:).*q(1,:)+q(2,:).*q(2,:); 11 | rad=rad.*sqrt(rad); 12 | out(1,:)=-q(1,:)./rad; 13 | out(2,:)=-q(2,:)./rad; 14 | else 15 | switch flag 16 | case 'init', 17 | if (nargin < 4) 18 | ecc = 0.5; 19 | else 20 | ecc = varargin{1}; 21 | end 22 | if (ecc < 0) | (ecc >= 1) 23 | error('The eccentricity must lie between 0 and 1'); 24 | end 25 | out = [0 2*pi]; 26 | out2 = [1-ecc,0,0,sqrt((1+ecc)/(1-ecc))]; 27 | out3 = gniset('NumSteps',50,'Vectorized','on','Events','off',... 28 | 'OutputSteps',-1,'OutputFcn','phaseplot'); 29 | end 30 | end 31 | 32 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/rattwo.m: -------------------------------------------------------------------------------- 1 | function [outP,outQ] = rattwo(t,P,Q,ode,ha,hb,hc,first,last,flags,varargin) 2 | if isempty(flags) 3 | F = feval(ode,t,Q,varargin{:}); 4 | EP = P - ha*F; 5 | EQ = Q + hb*EP; 6 | 7 | EE1 = EQ(1:3)'*EQ(1:3); 8 | EQ1 = EQ(1:3)'*Q(1:3); 9 | EE2 = EQ(4:6)'*EQ(4:6); 10 | EQ2 = EQ(4:6)'*Q(4:6); 11 | 12 | BET1 = 1 - EE1; 13 | ALAM1 = -BET1/(hb*(EQ1+sqrt(BET1+EQ1^2))); 14 | BET2 = 1 - EE2; 15 | ALAM2 = -BET2/(hb*(EQ2+sqrt(BET2+EQ2^2))); 16 | 17 | outP = EP - [ALAM1*Q(1:3);ALAM2*Q(4:6)]; 18 | outQ = Q + hb*outP; 19 | 20 | if (last) 21 | F = feval(ode,t,outQ,varargin{:}); 22 | outP = outP - hc*F; 23 | AMU1 = sum(outP(1:3).*outQ(1:3)); 24 | AMU2 = sum(outP(4:6).*outQ(4:6)); 25 | outP = outP - [AMU1*outQ(1:3);AMU2*outQ(4:6)]; 26 | end 27 | return; 28 | else switch flags 29 | case 'init', 30 | case 'done', 31 | end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/stverl.m: -------------------------------------------------------------------------------- 1 | function [outP,outQ] = stverl(t,P,Q,ode,ha,hb,hc,first,last,flags,varargin) 2 | global EP; 3 | global EQ; 4 | 5 | if isempty(flags) 6 | if (first) 7 | EQ = EQ + ha*P; 8 | outQ = Q + EQ; 9 | EQ = EQ + (Q - outQ); 10 | Q = outQ; 11 | end 12 | F = feval(ode,t,Q,varargin{:}); 13 | 14 | EP = EP + hb*F; 15 | outP = P + EP; 16 | EP = EP + (P - outP); 17 | 18 | EQ = EQ + hc*outP; 19 | outQ = Q + EQ; 20 | EQ = EQ + (Q - outQ); 21 | return; 22 | else switch flags 23 | case 'init', 24 | EQ = 0; 25 | EP = 0; 26 | case 'done', 27 | end 28 | end 29 | 30 | -------------------------------------------------------------------------------- /sandbox/potential_packages/gnimatlab/twobodysphere.m: -------------------------------------------------------------------------------- 1 | function [out,out2,out3] = twobodysphere(t,q,flag) 2 | % Example GNI problem file for solving the two-body problem 3 | % constrained to the sphere of radius one. 4 | % Use it as follows: 5 | % 6 | % gni_comp('twobodysphere'); 7 | % 8 | % Only gni_comp works, since this problem uses a special basic 9 | % method and is therefore not written in the standard way. This problem 10 | % also uses the custom output function SPHEREPLOT. 11 | if (nargin < 3) | isempty(flag) 12 | prod = q(1:3)'*q(4:6); 13 | out = -q([4:6,1:3])/(1-prod^2)^(3/2); 14 | else 15 | switch flag 16 | case 'init', 17 | out = [0 10]; 18 | 19 | phi = [1.3 -2.1]; 20 | theta = [2.1 -1.1]; 21 | out2([1 4]) = cos(phi).*sin(theta); 22 | out2([2 5]) = sin(phi).*sin(theta); 23 | out2([3 6]) = cos(theta); 24 | 25 | dphi = [1.2 0.1]; 26 | dtheta = [0.1 -0.5]; 27 | out2([7 10]) = -dphi.*sin(phi).*sin(theta) + dtheta.*cos(phi).*cos(theta); 28 | out2([8 11]) = dphi.*cos(phi).*sin(theta) + dtheta.*sin(phi).*cos(theta); 29 | out2([9 12]) = -dtheta.*sin(theta); 30 | 31 | out3 = gniset('StepSize',0.02,'Vectorized','off','Events','off',... 32 | 'PartialFlow','rattwo','OutputFcn','sphereplot',... 33 | 'OutputSteps',5,'OutputSel',[1:6]); 34 | end 35 | end 36 | 37 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from os.path import join 4 | 5 | def configuration(parent_package='',top_path=None): 6 | 7 | from numpy.distutils.misc_util import Configuration 8 | 9 | config = Configuration(None, parent_package, top_path) 10 | config.set_options(ignore_setup_xxx_py=True, 11 | assume_default_configuration=True, 12 | delegate_options_to_subpackages=True, 13 | quiet=True) 14 | 15 | config.add_subpackage('odespy') 16 | config.get_version(join('odespy', 'version.py')) 17 | 18 | return config 19 | 20 | if __name__ == '__main__': 21 | from odespy.version import full_version 22 | import sys 23 | fortran = True 24 | if '--no-fortran' in sys.argv: 25 | sys.argv.remove('--no-fortran') # intefers with distutils sys.argv use 26 | fortran = False 27 | 28 | name = 'odespy' 29 | download_url = 'https://github.com/hplgit/odespy' 30 | url = 'http://hplgit.github.io/odespy/doc/web/index.html' 31 | author = 'Liwei Wang and Hans Petter Langtangen' 32 | author_email = 'hpl@simula.no' 33 | license = 'GPL' 34 | version = full_version 35 | 36 | if fortran: 37 | from numpy.distutils.core import setup 38 | #setup(**configuration(top_path='').todict()) 39 | setup( 40 | name=name, 41 | version=version, 42 | url=url, 43 | download_url=download_url, 44 | license=license, 45 | author=author, 46 | author_email=author_email, 47 | configuration=configuration) 48 | else: 49 | # Run plain distutils 50 | from distutils.core import setup 51 | setup( 52 | name=name, 53 | version=version, 54 | url=url, 55 | download_url=download_url, 56 | license=license, 57 | author=author, 58 | author_email=author_email, 59 | description='', 60 | packages=['odespy'], 61 | ) 62 | --------------------------------------------------------------------------------