Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Speeding Up Realtime Visualization

  • To: mathgroup at
  • Subject: [mg84367] Re: Re: Speeding Up Realtime Visualization
  • From: Will <secandum.oculi at>
  • Date: Thu, 20 Dec 2007 00:11:34 -0500 (EST)

Since I haven't mentioned this before, I'm trying to make a two species reaction diffusion simulator by approximating the associated PDE using finite difference integration. These 'rough' simulators, e.g., are typically very fast. I'm going for something with this speed.

In my code, I've compiled a function which performs the 'next-time-interval' finite difference calculation. Using the Timing function, I found this calculation takes essentially no time. Mathematica usually says 0. sec. However, when I perform this calculation across the entire 100x100 grid, i.e. ~99^2 calcuations, it takes 0.45 sec. 

I originally computed the entire grid using For loops, which required ~0.5-0.6 sec. Figuring that Mathematica doesn't like procedural programming, I tried implementing a Threading technique to apply the finite difference calculation across the grid, which takes 0.45. Of course, this is way to slow for a 'fast' simulator.

Again, I can speed things up by lowering my grid size, or keeping the grid size and increasing the spatial interval in the integrator, but I'll be losing significant quality.

I still think the sluggishness has something to do with the way I'm setting up my matrices, which are used to read/write during the finite difference calculation. I figure I'm forgetting something huge

Ok, here's my code:
a=0.082;(*u diffusion*)
b=0.041;(*v diffusion*)
f=0.035;(*u feed/rxn rate*)
k=0.0625;(*v death rate*)
dtf=dt f;
e=a dt/(ds)^2;
g=b dt/(ds)^2;

uP=Table[1,{i,1,length},{j,1,length}];(*previous u state*)
uC=Table[0,{i,1,length},{j,1,length}];(*current u state*)
vP=Table[0,{i,1,length},{j,1,length}];(*previous v state*)
vC=Table[0,{i,1,length},{j,1,length}];(*current v state*)
c=2;p=1;(*for double buffer*)
u={uP,uC};(*u[[1]] is previous, u[[2]] is current*)
v={vP,vC};(*v[[1]] is previous, v[[2]] is current*)

(*initial conditions, small square of altered conc values*)
Do[v[[1,i,j]]= Sin[0.1i-0.5length]Cos[0.1j-0.5length]^2,{i,1,length},{j,1,length}];

(*finite difference/rxn diffusion calculation*)


(*Rxn Diffusion*)
If[p==1,c=1;p=2,c=2;p=1] ;  (*c/p inverter*)

Then I Dynamically visualize either ugrid or vgrid using ArrayPlot or Graphics[Raster[]] , which seem take take the same time.

Any ideas?


  • Prev by Date: RE: Button Question
  • Next by Date: Re: express a quadratic, in the form (x+a)^2 + b
  • Previous by thread: Re: Re: Speeding Up Realtime Visualization
  • Next by thread: Re: Speeding Up Realtime Visualization