{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Copy-pasted from https://github.com/hannorein/rebound/blob/master/ipython_examples/CloseEncounters.ipynb\n", "\n", "import rebound\n", "import numpy as np\n", "def setupSimulation():\n", " sim = rebound.Simulation()\n", " sim.integrator = \"ias15\" # IAS15 is the default integrator, so we don't need this line\n", " sim.add(m=1.)\n", " sim.add(m=1e-3,a=1.)\n", " sim.add(m=5e-3,a=1.25)\n", " sim.move_to_com()\n", " return sim" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "sim = setupSimulation()\n", "sim.integrate(100.*2.*np.pi)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n" ] } ], "source": [ "for o in sim.calculate_orbits():\n", " print(o)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Two particles had a close encounter (d" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "fig = plt.figure(figsize=(10,5))\n", "ax = plt.subplot(111)\n", "ax.set_xlabel(\"time [orbits]\")\n", "ax.set_xlim([0,sim.t/(2.*np.pi)])\n", "ax.set_ylabel(\"distance\")\n", "plt.plot(times/(2.*np.pi), distances);\n", "plt.plot([0.0,12],[0.2,0.2]); # Plot our close encounter criteria;" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Two particles had a close encounter (d\n", " uniform vec3 focus;\n", " uniform vec3 aef;\n", " uniform vec3 omegaOmegainc;\n", " attribute float lintwopi;\n", " varying float lin;\n", " uniform mat4 mvp;\n", " const float M_PI = 3.14159265359;\n", " void main() {\n", " float a = aef.x;\n", " float e = aef.y;\n", " float f = aef.z+lintwopi;\n", " lin = lintwopi/(M_PI*2.);\n", " if (e>1.){\n", " float theta_max = acos(-1./e);\n", " f = 0.0001-theta_max+1.9998*lin*theta_max;\n", " lin = sqrt(min(0.5,lin));\n", " }\n", " float omega = omegaOmegainc.x;\n", " float Omega = omegaOmegainc.y;\n", " float inc = omegaOmegainc.z;\n", " float r = a*(1.-e*e)/(1. + e*cos(f));\n", " float cO = cos(Omega);\n", " float sO = sin(Omega);\n", " float co = cos(omega);\n", " float so = sin(omega);\n", " float cf = cos(f);\n", " float sf = sin(f);\n", " float ci = cos(inc);\n", " float si = sin(inc);\n", " vec3 pos = vec3(r*(cO*(co*cf-so*sf) - sO*(so*cf+co*sf)*ci),r*(sO*(co*cf-so*sf) + cO*(so*cf+co*sf)*ci),+ r*(so*cf+co*sf)*si);\n", " gl_Position = mvp*(vec4(focus+pos, 1.0));\n", " }\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d0fe0b16b4104ec29c03ce535e7483bb" } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sim = rebound.Simulation()\n", "sim.getWidget()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "for i in range(10):\n", " sim.add(m=1e-3,a=0.4+0.1*i,inc=0.03*i,omega=5.*i) # Jupiter mass planets on close orbits\n", "sim.move_to_com() # Move to the centre of mass frame" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/brian/anaconda/lib/python2.7/site-packages/rebound/simulation.py:518: RuntimeWarning: At least 10 predictor corrector loops in IAS15 did not converge. This is typically an indication of the timestep being too large.\n", " warnings.warn(msg[1:], RuntimeWarning)\n" ] } ], "source": [ "sim.integrate(500)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2c2d6726e0ab4cf8a26eca9272d9d2c5" } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sim.getWidget(size=(400,200),orbits=False)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "471d49cfcfc24278adf51e20076689ff" } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "widget_1 = sim.getWidget(orientation=(0,0,0,1),scale=2)\n", "widget_2 = sim.getWidget(orientation=(0,1,0,1),scale=2,size=(50,200))\n", "widget_3 = sim.getWidget(orientation=(1,0,0,1),scale=2,size=(200,50))\n", "from ipywidgets import HBox, VBox\n", "VBox((widget_3,HBox((widget_1, widget_2))))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 0 }