From: Eric A. <Ay...@ma...> - 2005-06-22 23:15:22
|
I've been using Python (occasionally with vpython) for an undergrad- level computational physics course, and have had excellent results with an RK4 routine. Here's a sample program: http:// phys.csuchico.edu/ayars/250/code/spring-pendulum.shtml (Ignore the "error processing directive" messages on the webpage -- the page is not up to date at the moment but the code shown is good.) As you suggest, I solve all variables at once: in this example I use the array y[] as a container. I've found that for displaying things on-screen in vpython, a python- based RK4 routine is not the speed-limiting factor. If you need to go with a c routine, though, you might consider writing your own and then using SWIG (http://www.swig.org/) as a way of making a python wrapper for it. I'm new to SWIG (as of this week, actually) but it is working very well for me so far. Hope this helps. -EA ----------------------------------------------------------------- Dr. Eric Ayars Assistant Professor of Physics California State University, Chico ay...@ma... On Jun 22, 2005, at 10:53 AM, Gary wrote: > I've been wondering if there would be a programming, accuracy, or > performance benefit to using a fancy ode solver with vpython rather > than the canonical v = v + F/m * dt especially as the number of > objects grows. My thinking was that I could call the solver once > per "frame" (say, 1/30 sec), solve for all of the variables all at > once, and perhaps have better accuracy, and perhaps get more > objects into the simulation. > > I began to experiment with scipy's odeint, and got some demos > working. I ran across some instabilites that I tracked down, but > before going any further I thought I'd ask: > > Does this seem worth the effort? > > Is there something I haven't considered that dooms this idea? > > Has someone already done this? > > The instablilty I found is related to in the way odeint (LSODA??) > manages the independent variable. I'd like to look at other > solvers. Any suggestions? In particular I'd like to look at a 4th > order Runge-Kutta solver, but the only RK4s that I've found are > written in python. Does anyone know where there's a python-wrapped > C or Fortran RK solver? > > Thanks, > Gary > > |