Trouble in running the example of Yade ball mill script

Asked by 010M

Hello, I am new Yade user also learner to python coding. I am trying run a ball mill script (mill.py) that is provided in Yade examples. but, I am getting error as below:
Running script mill.py
Traceback (most recent call last):
  File "/usr/bin/yade", line 343, in runScript
    execfile(script,globals())
  File "/usr/lib/python3/dist-packages/past/builtins/misc.py", line 87, in execfile
    exec_(code, myglobals, mylocals)
  File "mill.py", line 26, in <module>
    for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint = False):
  File "<__array_function__ internals>", line 5, in linspace
  File "/usr/lib/python3/dist-packages/numpy/core/function_base.py", line 120, in linspace
    num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer

Here is the script of mill.py

# encoding: utf-8
from yade import pack
from numpy import linspace
# geometry parameters
bumpNum=2
bumpHt,bumpTipAngle=0.07,60*pi/180
millRad,millDp=1,1 # radius and depth (cylinder length) of the mill
sphRad,sphRadFuzz=0.03,.8 # mean radius and relative fuzz of the radius (random, uniformly distributed between sphRad*(1-.5*sphRadFuzz)…sphRad*(1+.5*sphRadFuzz))
dTheta=pi/24 # circle division angle

###
### mill geometry (parameteric)
###
bumpPeri=2*bumpHt*tan(.5*bumpTipAngle) # length of a bump on the perimeter of the mill
bumpAngle=bumpPeri/millRad # angle of one bump from the axis of the mill
interBumpAngle=2*pi/bumpNum
bumpRad=millRad-bumpHt
pts=[]; thMin=0
for i in range(0,bumpNum):
 thMin+=interBumpAngle
 thMax=thMin+interBumpAngle-bumpAngle
 thTip=thMax+.5*bumpAngle
 # the circular parts spanning from thMin to thMax
 for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint = False):
  pts.append(Vector3(-.5*millDp,millRad*cos(th0),millRad*sin(th0)))
 # tip of the bump
 pts.append(Vector3(-.5*millDp,bumpRad*cos(thTip),bumpRad*sin(thTip)))
# close the curve
pts+=[pts[0]]
# make the second contour, just shifted by millDp; ppts contains both
ppts=[pts,[p+Vector3(millDp,0,0) for p in pts]]
mill=pack.sweptPolylines2gtsSurface(ppts,threshold=.01*min(dTheta*millRad,bumpHt))#,capStart=True,capEnd=True)
millIds=O.bodies.append(pack.gtsSurface2Facets(mill,color=(1,0,1))) # add triangles, save their ids
# make the caps less comfortably, but looking better as two triangle couples over the mill
mrs2=millRad*sqrt(2)
cap1,cap2=[Vector3(0,0,mrs2),Vector3(0,-mrs2,0),Vector3(0,0,-mrs2)],[Vector3(0,0,mrs2),Vector3(0,0,-mrs2),Vector3(0,mrs2,0)] # 2 triangles at every side
for xx in -.5*millDp,.5*millDp: millIds+=O.bodies.append([utils.facet([p+Vector3(xx,0,0) for p in cap1],color=(0,0,0)),utils.facet([p+Vector3(xx,0,0) for p in cap2],color=(0,0,0))])

# define domains for initial cloud of red and blue spheres
packHt=.8*millRad # size of the area
bboxes=[(Vector3(-.5*millDp,-.5*packHt,-.5*packHt),Vector3(.5*millDp,0,.5*packHt)),(Vector3(-.5*millDp,0,-.5*packHt),Vector3(.5*millDp,.5*packHt,.5*packHt))]
colors=(1,0,0),(0,0,1)
for i in (0,1): # red and blue spheres
 sp=pack.SpherePack(); bb=bboxes[i]; vol=(bb[1][0]-bb[0][0])*(bb[1][1]-bb[0][1])*(bb[1][2]-bb[0][2])
 sp.makeCloud(bb[0],bb[1],sphRad,sphRadFuzz,int(.25*vol/((4./3)*pi*sphRad**3)),False)
 O.bodies.append([utils.sphere(s[0],s[1],density=3000,color=colors[i]) for s in sp])
 print ("Numer of grains",len(O.bodies)-len(millIds))

O.dt=utils.PWaveTimeStep()

O.engines=[
 BexResetter(),
 BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingFacet2AABB(),MetaInteractingGeometry2AABB()]),
 InsertionSortCollider(),
 InteractionDispatchers(
  [ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
  [SimpleElasticRelationships()],
  [Law2_Dem3Dof_Elastic_Elastic()],
 ),
 GravityEngine(gravity=(0,0,-3e4)), # gravity artificially high, to make it faster going ;-)
 RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(1,0,0),angularVelocity=-120,subscribedBodies=millIds),
 SnapshotEngine(iterPeriod=30,fileBase='/tmp/mill-',viewNo=0,label='snapshooter'),
 NewtonsDampedLaw(damping=.3),
]

O.saveTmp()
from yade import qt
v=qt.View()
v.eyePosition=(3,.8,.96); v.upVector=(-.4,-.4,.8); v.viewDir=(-.9,-.25,-.3); v.axes=True; v.sceneRadius=1.9
O.run(10000); O.wait()
utils.encodeVideoFromFrames(snapshooter['savedSnapshots'],out='/tmp/mill.ogg',fps=30)

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
010M
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

> I am new Yade user

welcome :-)

Please read [1] and prvide information about your Yade version and Operating system version

> that is provided in Yade examples

Please provide also what exactly is "Yade examples" (recent git version, from source code of specific version, ...)

> I am getting error as below

looks like some Python 2/3 problem, with the specific versions we can give better answer.

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
010M (12345m) said :
#2

Hello Jan,
I am Harsha.
Thank you very much for your quick response.

here, I am providing the information of Yade and operating system version as follows:
Welcome to Yade 2022.01a
Using python version: 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]
TCP python prompt on localhost:9000, auth cookie `syecdu'
XMLRPC info provider on http://localhost:21000
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

OS: Ubuntu 22.04.1 LTS

The mill.py script as I posted, I just downloaded from here as follows: https://launchpad.net/yade

I would be happy to learn more about Yade.

Once again, thank you and team for support to develop DEM models.

Revision history for this message
Jan Stránský (honzik) said :
#3

> The mill.py script as I posted, I just downloaded from here as follows: https://launchpad.net/yade

what version, what link, ... ?
please try to be as much specific as possible in these cases.

It is not so important here, as I have tried recent version, and it seems that the code is simply outdated.
I have fixed the example in merge request [2]

To make it work, replace this line (as the error says)
 for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint = False):
with
 n=int(interBumpAngle/dTheta)
 for th0 in linspace(thMin,thMax,n,endpoint = False):

Cheers
Jan

[2] https://gitlab.com/yade-dev/trunk/-/merge_requests/899

Revision history for this message
010M (12345m) said :
#4

Hello Jan,
Your corrections are working well. Now, the problem is solved.

Thanks for the suggestions and providing corrections.