Revision: 3627
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3627&view=rev
Author:   fer_perez
Date:     2007-07-29 01:03:12 -0700 (Sun, 29 Jul 2007)

Log Message:
-----------
Small optimization.

Modified Paths:
--------------
    trunk/py4science/examples/schrodinger/schrod_fdtd.py

Modified: trunk/py4science/examples/schrodinger/schrod_fdtd.py
===================================================================
--- trunk/py4science/examples/schrodinger/schrod_fdtd.py        2007-07-29 
06:50:34 UTC (rev 3626)
+++ trunk/py4science/examples/schrodinger/schrod_fdtd.py        2007-07-29 
08:03:12 UTC (rev 3627)
@@ -237,22 +237,26 @@
 IDX2 = range(2,N)                              #  psi [ k + 1 ]
 IDX3 = range(0,N-2)                            #  psi [ k - 1 ]
 
-for t in range(0,T+1):
+for t in range(T+1):
+    # Precompute a couple of indexing constants, this speeds up the computation
+    psi_rPR = psi_r[PR]
+    psi_iPR = psi_i[PR]
+
     #  Apply the update equations.
     psi_i[FU,IDX1] = psi_i[PA,IDX1] + \
-                      c1*(psi_r[PR,IDX2] - 2*psi_r[PR,IDX1] +
-                          psi_r[PR,IDX3])
-    psi_i[FU]    = psi_i[FU] - c2V*psi_r[PR]
+                      c1*(psi_rPR[IDX2] - 2*psi_rPR[IDX1] +
+                          psi_rPR[IDX3])
+    psi_i[FU] -= c2V*psi_r[PR]
     
     psi_r[FU,IDX1] = psi_r[PA,IDX1] - \
-                      c1*(psi_i[PR,IDX2] - 2*psi_i[PR,IDX1] +
-                          psi_i[PR,IDX3])
-    psi_r[FU]    = psi_r[FU] + c2V*psi_i[PR]
+                      c1*(psi_iPR[IDX2] - 2*psi_iPR[IDX1] +
+                          psi_iPR[IDX3])
+    psi_r[FU] += c2V*psi_i[PR]
 
     #  Increment the time steps.  PR -> PA and FU -> PR
-    psi_r[PA] = psi_r[PR]
+    psi_r[PA] = psi_rPR
     psi_r[PR] = psi_r[FU]
-    psi_i[PA] = psi_i[PR]
+    psi_i[PA] = psi_iPR
     psi_i[PR] = psi_i[FU]
 
     #  Only plot after a few iterations to make the simulation run faster.


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to