How to efficiently convert polyhedrons to potential blocks in batches?

Asked by weijie

Dear all,

I have created many different polyhedrons of different sizes in makeCloud, how can I convert them in batch without error?

In my MWS below, I found that only one polyhedron was converted, and the shape of this polyhedron was wrong.

Thanks in advance.
Jie

Below is my script:
########################
from yade import polyhedra_utils,pack,plot,utils,export,qt
import numpy as np
import math
import random
import os
#-------------------------------------------
#Material
n = PolyhedraMat(young=7.2e7,poisson=.2,density=2.5e3)
powderDensity = 2500
O.materials.append(FrictMat(young=-1,poisson=-1,frictionAngle=radians(0.0),density=powderDensity,label='frictionless'))
#-------------------------------------------
#Dimensions

meanSize = 0.05
wallThickness = 0.5*meanSize
distanceToCentre = 0.01
lengthOfBase = 0.250
heightOfBase = 0.600

#-------------------------------------------
#Make Cloud

sp=pack.SpherePack()
mn,mx=Vector3(-0.5*(lengthOfBase-wallThickness),0.5*meanSize,-0.5*(lengthOfBase-wallThickness)),Vector3(0.5*(lengthOfBase-wallThickness),0.5*heightOfBase,0.5*(lengthOfBase-wallThickness))
R=sqrt(3.0)*distanceToCentre
sp.makeCloud(mn,mx,psdSizes=[distanceToCentre,2*distanceToCentre],psdCumm=(0.1,1),num=500)

for center,radius in sp:
    b=Body()
    b.mask=1
    color=Vector3(random.random(),random.random(),random.random())
    b=polyhedra_utils.polyhedra(material=n,size=(2*radius,radius,radius),color=color)
    b.state.pos =center #s[0] stores center
    b.state.ori = Quaternion((random.random(),random.random(),random.random()),random.random()) #s[2]
    O.bodies.append(b)

def dvalue(vecn1,pp1):
 dd1=1*(vecn1[0]*pp1[0]+vecn1[1]*pp1[1]+vecn1[2]*pp1[2])
 return dd1

for b in O.bodies:
 aa=[]
 bb=[]
 cc=[]
 dd=[]
 if not isinstance(b.shape,Polyhedra): # skip non-polyhedra bodies
  continue
 vs = [b.state.ori*v for v in b.shape.v] # vertices in global coords
 face2=b.shape.GetSurfaces()

 id1=0
 while id1<len(face2):
  face11=face2[id1]
  if len(face11)>2:
   vec1=vs[face11[2]]-vs[face11[1]]; vec1.normalize()
   vec2=vs[face11[0]]-vs[face11[1]]; vec2.normalize() #Normalize this object in-place.
   vects=vec1.cross(vec2); vects.normalize()
   dvalue2=dvalue(vects,vs[face11[0]]) # Some dvalue2 values return equal to 0. Check this part of your script once more.
   dv=dvalue2
   #dv=dvalue2-chosenR
   aa.append(vects[0])
   bb.append(vects[1])
   cc.append(vects[2])
   dd.append(dv)
  id1=id1+1

print(dd)
r=min(np.array(dd)/2)
print(r)
bbb=Body()
bbb.aspherical=True
wire=False
color=[125,2,1]
highlight=True
bbb.shape=PotentialBlock(k=0.0, r=r, R=0.0, a=aa, b=bb, c=cc, d=np.array(dd)-r)
utils._commonBodySetup(bbb, bbb.shape.volume, bbb.shape.inertia,material='frictionless', pos=bbb.shape.position, fixed=False)
bbb.state.ori=bbb.shape.orientation
bbb.state.pos = [0,0.5,0]
O.bodies.append(bbb)

from yade import qt
v=qt.View()
O.saveTmp()

Question information

Language:
English Edit question
Status:
Invalid
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Vasileios Angelidakis
Solved:
Last query:
Last reply:
Revision history for this message
Vasileios Angelidakis (vsangelidakis) said :
#1

Hi Jie,

Hope you don't mind; I reject this question as duplicate to [1].
I will answer under the original question, to keep continuity for future readers.

Best Regards,
Vasileios

[1] https://answers.launchpad.net/yade/+question/689434