Question #689434 on Yade changed: https://answers.launchpad.net/yade/+question/689434
Status: Open => Answered Vasileios Angelidakis proposed the following answer: Hi, To convert all the polyhedra into PBs, you have to define the generation of PBs inside the loop. You are currently creating only the last polyhedron. Then, for the newly created PBs, you have to assign the same orientation and position as the one of the polyhedral particles. Below I generate the PBs shifted by Vector3(lengthOfBase,0,0), so that you can compare the polyhedra (on the left) and the PBs (on the right). Also, I choose different "r=chosenR" for each body, depending on their individual dd values. I see some faces are still not rendered properly in the PBs, but this is only a visualisation issue. #Best Regards, #Vasileios ################################# from yade import polyhedra_utils,pack,plot,utils,qt import random import numpy as np #------------------------------------------- #Material n = PolyhedraMat(young=7.2e7,poisson=.2,density=2.5e3) O.materials.append(FrictMat(young=-1,poisson=-1,frictionAngle=radians(0.0),density=2500,label='frictionless')) #------------------------------------------- #Dimensions meanSize = 0.05 wallThickness = 0.5*meanSize distanceToCentre = 0.01 lengthOfBase = 5*meanSize heightOfBase = 12*meanSize #------------------------------------------- #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,R,0,-1,False) def dvalue(vecn1,pp1): dd1=1*(vecn1[0]*pp1[0]+vecn1[1]*pp1[1]+vecn1[2]*pp1[2]) return dd1 for s in sp: # Generate polyhedra color=Vector3(random.random(),random.random(),random.random()) b=polyhedra_utils.polyhedra(material=n,size=(2*distanceToCentre,distanceToCentre,distanceToCentre),color=color) b.state.pos = s[0] #s[0] stores center b.state.ori = Quaternion((random.random(),random.random(),random.random()),random.random()) #s[2] O.bodies.append(b) # Generate PBs aa=[] bb=[] cc=[] dd=[] vs=b.shape.v 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]]) aa.append(vects[0]) bb.append(vects[1]) cc.append(vects[2]) dd.append(dvalue2) id1=id1+1 chosenR=min(dd)/2 bbb=Body() bbb.aspherical=True wire=False highlight=True bbb.shape=PotentialBlock(k=0.0, r=chosenR, R=0.0, a=aa, b=bb, c=cc, d=np.array(dd)-chosenR, color=b.shape.color) utils._commonBodySetup(bbb, bbb.shape.volume, bbb.shape.inertia,material='frictionless', pos=bbb.shape.position, fixed=False) bbb.state.ori= b.state.ori bbb.state.pos = b.state.pos+Vector3(lengthOfBase,0,0) O.bodies.append(bbb) # Count number of bodies with b.shape=Polyhedra countPol=0 for b in O.bodies: if isinstance(b.shape,Polyhedra): countPol=countPol+1 print("number of Polyhedra = ", countPol) # Count number of bodies with b.shape=PotentialBlock countPBs=0 for b in O.bodies: if isinstance(b.shape,PotentialBlock): countPBs=countPBs+1 print("number of PotentialBlocks = ", countPBs) from yade import qt v=qt.View() v.ortho=True # I activate orthotropic projection, to make visual comparisons easier O.saveTmp() -- You received this question notification because your team yade-users is an answer contact for Yade. _______________________________________________ Mailing list: https://launchpad.net/~yade-users Post to : yade-users@lists.launchpad.net Unsubscribe : https://launchpad.net/~yade-users More help : https://help.launchpad.net/ListHelp