← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2895: Simplify utils.psd()

 

------------------------------------------------------------
revno: 2895
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: yade
timestamp: Thu 2011-07-21 11:10:30 +0200
message:
  Simplify utils.psd()
modified:
  py/utils.py


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'py/utils.py'
--- py/utils.py	2011-07-20 15:30:57 +0000
+++ py/utils.py	2011-07-21 09:10:30 +0000
@@ -766,11 +766,11 @@
 	saveVars('table',loadNow=True,**dictParams)
 	return len(tagsParams)
 	
-def psd(bins=5, result="number", mask=-1):
+def psd(bins=5, mass=True, mask=-1):
 	"""Calculates particle size distribution.
 	
 	:param int bins: number of bins
-	:param string result: how will be PSD calculated ("number", "mass", "volume")
+	:param bool mass: if true, the mass-PSD will be calculated
 	:param int mask: :yref:`Body.mask` for the body
 	:return:
 		* binsSizes: list of bin's sizes
@@ -792,7 +792,6 @@
 	deltaBinD = (maxD-minD)/bins
 	binsMass = numpy.zeros(bins)
 	binsNumbers = numpy.zeros(bins)
-	binsVolumes = numpy.zeros(bins)
 	
 		
 	for b in O.bodies:
@@ -801,28 +800,21 @@
 			
 			basketId = int(math.floor( (d-minD) / deltaBinD ) )
 			if (d == maxD): basketId = bins-1												 #If the diametr equals the maximal diameter, put the particle into the last bin
-			binsMass[basketId] = binsMass[basketId] + b.state.mass		#Put masses in the bin 
-			binsVolumes[basketId] = binsVolumes[basketId] + 4.0/3.0*math.pi*math.pow(b.shape.radius, 3)					 #Put volumes in the bin 
-			binsNumbers[basketId] = binsNumbers[basketId] + 1				 #Put numbers in the bin 
+			binsMass[basketId] = binsMass[basketId] + b.state.mass		#Put masses into the bin 
+			binsNumbers[basketId] = binsNumbers[basketId] + 1					#Put numbers into the bin 
 			
 	binsProc = numpy.zeros(bins+1)
 	binsSumCum = numpy.zeros(bins+1)
 	
 	i=1
 	for size in binsSizes[:-1]:
-		if (result=="number"):
-			binsSumCum[i]+=binsSumCum[i-1]+binsNumbers[i-1]
-		elif (result=="mass"):
-			binsSumCum[i]+=binsSumCum[i-1]+binsMass[i-1]
-		elif (result=="volume"):
-			binsSumCum[i]+=binsSumCum[i-1]+binsVolumes[i-1]
+		if (mass): binsSumCum[i]+=binsSumCum[i-1]+binsMass[i-1]		#Calculate mass
+		else: binsSumCum[i]+=binsSumCum[i-1]+binsNumbers[i-1]			#Calculate number of particles
 		i+=1
 	
-	
 	if (binsSumCum[len(binsSumCum)-1] > 0):
 		i=0
 		for l in binsSumCum:
 			binsProc[i] = binsSumCum[i]/binsSumCum[len(binsSumCum)-1]
 			i+=1
- 
 	return binsSizes, binsProc, binsSumCum