[Yt-svn] yt-commit r457 - trunk/yt/lagos

britton at wrangler.dreamhost.com britton at wrangler.dreamhost.com
Fri May 9 15:28:01 PDT 2008


Author: britton
Date: Fri May  9 15:28:00 2008
New Revision: 457
URL: http://yt.spacepope.org/changeset/457

Log:
Calculation of gravitational potential stops when grav. potential exceeds 
kinetic energy, since all we care about is whether or not it is bound.  This 
speeds things up considerably.

9 May, 2008

Britton Smith


Modified:
   trunk/yt/lagos/DerivedQuantities.py

Modified: trunk/yt/lagos/DerivedQuantities.py
==============================================================================
--- trunk/yt/lagos/DerivedQuantities.py	(original)
+++ trunk/yt/lagos/DerivedQuantities.py	Fri May  9 15:28:00 2008
@@ -168,16 +168,17 @@
     total_cells = len(data['x'])
     cells_done = 0
     potential = 0.0
-    pb = get_pbar("Calculating gravitational potential ", (na.array(range(total_cells)).sum())) # Progress bar
+    pb = get_pbar("Calculating gravitational potential ", (0.5*(total_cells**2 - total_cells)))
     for q in xrange(total_cells-1):
         pot = data['CellMass'][(q+1):total_cells] / \
             (((data['x'][(q+1):total_cells]-data['x'][q])**2 + \
                   (data['y'][(q+1):total_cells]-data['y'][q])**2 + \
                   (data['z'][(q+1):total_cells]-data['z'][q])**2)**(0.5))
-        potential += 2 * data['CellMass'][q] * pot.sum()
+        potential += 2 * G * data['CellMass'][q] * pot.sum()
         cells_done += (total_cells - q - 1)
         pb.update(cells_done)
-    potential *= G
+        if (potential > kinetic):
+            break
     pb.finish()
 
     return (kinetic < potential),1.0



More information about the yt-svn mailing list