[SciPy-User] Trajectory Integration via scipy.integrate or PyDSTool?

Sara Gallian sara2411 at gmail.com
Mon May 14 16:47:10 EDT 2012


Thank you all for the suggestions! 

Indeed I know RK4 is not the best integrator for orbital-like problems, I just needed a "quick and dirty" solution to begin with (and show a few pictures :) ). I will definitely refine my little code later..

PyDSTool seems a really cool module, at any rate, but still I am a little confused. 
I have already set both paths in my .profile :

PYTHONPATH="/usr/local/PyDSTool:${PYTHONPATH}"
export PYTHONPATH

and 

PATH="/Library/Frameworks/EPD64.framework/Versions/Current/bin:${PATH}"
export PATH

but I receive an error when I try to import the module. 
I don't understand why.. 

Thank you very much for the patience!
Sara

On 14.05.2012, at 22:28, Rob Clewley wrote:

> Sara,
> 
> Your Hamiltonian system really requires a symplectic integrator or
> similar, as Lou mentions, that truly respects energy conservation. A
> regular ODE integrator will create numerical error in the total
> energy, as it is oblivious. In lieu of such a thing, at the very least
> you can make a correction at those detected events in your loop to
> restore the total energy.
> 
> Anyway, regarding your installation. You should change your PATH to
> point to whichever version of python you are using, i.e. the version
> that has numpy, scipy etc. installed through EPD. It looks like you
> are using a Mac, so if you've installed EPD you should point to that
> version of python with your PATH. /sw/ is not a valid directory with
> EPD. If EPD installs outside of the Mac Framework then you will need
> to change the path, but if it uses the Framework python then there is
> nothing to change.
> 
> Also, and I haven't given this much thought, but in the absence of a
> geometric integrator, you could possibly even solve the system more
> accurately as a differential-algebraic system (DAE), using the energy
> constant as the algebraic constraint. But there might be more
> mathematical problems with that approach that I'm not seeing (I'm not
> an expert). At least you could try setting such a thing with the Radau
> integrator in PyDSTool, and there are DAE examples provided.
> 
> Feel free to share your equations and code in more detail if you're
> still struggling. With small integration steps you might be fine using
> RK4 with the energy correction at boundaries.
> 
> -Rob
> 
> On Mon, May 14, 2012 at 2:12 PM, Sara Gallian <sara2411 at gmail.com> wrote:
>> Dear Lou,
>> I'm just moving a bunch of electrons in a static b field
>> dv/dt = q/m v x B
>> B depends on the position, in general
>> They move in this field, without interacting, till they bounce off a wall,
>> that specularly reflects them
>> Yes, the dynamic is conservative.
>> I could just write a RK4 and check the position at every ts, but I was
>> hoping to be able to use a better tool
>> Thanks
>> Sara
>> 
>> Sent from my iPhone
>> 
>> On 14.05.2012, at 20:03, Lou Pecora <lou_boog2000 at yahoo.com> wrote:
>> 
>> Hi, Sara,
>> 
>> Can you give more information?
>> 
>> Are the particles in a potential or is it free flight between hard wall
>> collisions?  Do the particles interact?  I assume the dynamics are
>> conservative (Hamiltonian). Is that correct?
>> 
>> -- Lou Pecora, my views are my own.
>> ________________________________
>> From: Rob Clewley <rob.clewley at gmail.com>
>> To: SciPy Users List <scipy-user at scipy.org>
>> Sent: Monday, May 14, 2012 1:22 PM
>> Subject: Re: [SciPy-User] Trajectory Integration via scipy.integrate or
>> PyDSTool?
>> 
>> Hi Sara,
>> 
>> I think you should use a tool that's appropriate for the task. With an
>> hour of work and help on this list or the PyDSTool forum at
>> http://sourceforge.net/projects/pydstool/forums/forum/472291 you
>> should be able to get your problem working quickly with PyDSTool. I
>> expect your problem is easy to solve in PyDSTool, and difficult to do
>> with odeint.
>> 
>> You can still use scipy's VODE in PyDSTool and you won't need any
>> fancy installation. Check out the file vode_event_test1.py in the
>> tests directory. Writing the vector field is simple, but in case you
>> have specific problems setting up yours then you should send me your
>> code on list so that I can help. I'd be interested to see what the
>> equations look like.
>> 
>> It's very simple to define a terminal event, just copy and adapt the
>> code in the file. You can write a loop so that whenever integration
>> has stopped because of an event, you reverse the velocity IC and
>> restart.
>> 
>> -Rob
>> 
>> On Mon, May 14, 2012 at 12:59 PM, Sara Gallian <sara2411 at gmail.com> wrote:
>>> Hi all,
>>> I'm trying to integrate particle trajectories in a finite domain, and I
>>> need to make them "reflect" at the boundaries (i.e. reverse the velocity
>>> perpendicular to the plane they collided with). I started by using
>>>  scipy.integrate.odeint , but since the integration steps are variable,
>>> simply checking the position and reversing the velocity won't work!
>>> Can anyone suggest the quickest way to obtain this? would Vode be able to
>>> handle this, or should I try to learn to use  PyDSTool?
>>> I'm running pretty late on a deadline, so any suggestion is more than
>>> appreciated :)
>>> Thanks!
>>> Sara
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>> 
>> 
>> 
>> --
>> Robert Clewley, Ph.D.
>> Assistant Professor
>> Neuroscience Institute and
>> Department of Mathematics and Statistics
>> Georgia State University
>> PO Box 5030
>> Atlanta, GA 30302, USA
>> 
>> tel: 404-413-6420 fax: 404-413-5446
>> http://www2.gsu.edu/~matrhc
>> http://neuroscience.gsu.edu/rclewley.html
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>> 
>> 
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>> 
>> 
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>> 
> 
> 
> 
> -- 
> Robert Clewley, Ph.D.
> Assistant Professor
> Neuroscience Institute and
> Department of Mathematics and Statistics
> Georgia State University
> PO Box 5030
> Atlanta, GA 30302, USA
> 
> tel: 404-413-6420 fax: 404-413-5446
> http://www2.gsu.edu/~matrhc
> http://neuroscience.gsu.edu/rclewley.html
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list