Question #677402 on Yade changed:
https://answers.launchpad.net/yade/+question/677402
Status: Open => Answered
Jan Stránský proposed the following answer:
Hello,
1) there was wrong indentation in your code, should be:
######################################Using functions provided by
Jan#################################################
def addBodyToAggreg(body,aggreg): # auxiliary function, add body [yade.Body
instance] and all its neighbors into aggreg (python set instance)
if body.id in aggreg: # do nothing if b is already in aggreg ...
return
aggreg.add(body.id) # ... otherwise add it to aggreg
intrs = body.intrs()
for i in intrs: # and add also all its neighbors ...
if not isinstance(i.phys,JCFpmPhys): # ... but only that connected with
JCFpmPhys interactions
continue
if i.phys.breakOccurred: # ... but only not yet broken
continue
i2 = i.id1 if i.id2==body.id else i.id2 # choose the other body of
interaction
b2 = O.bodies[i2]
addBodyToAggreg(b2,aggreg) # and add it and all its neighbors to aggreg
def aggregs(): # actual function to detect standalone aggregates
ids = set(b.id for b in O.bodies if isinstance(b.shape,Sphere)) # first make
a set of all spheres ids
ret = []
while len(ids)>0: # while there are still some particles not assigned to any
aggregate ...
i = ids.pop() # ... choose one random ...
b = O.bodies[i]
a = set() # ... create new aggregate (set of sphere ids)
addBodyToAggreg(b,a) # ... and add the sphere together with all its
neigbors to aggregate
for bid in a: # delete all used ids from ids
ids.discard(bid)
ret.append(a)
return ret
#################
2) as the comment says, addBodyToAggreg is an auxiliary function, so
just do not call it standalone :-)
cheers
Jan
--
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 : [email protected]
Unsubscribe : https://launchpad.net/~yade-users
More help : https://help.launchpad.net/ListHelp