Count number of fragments

Asked by Luis Barbosa on 2019-01-08

Hi,
I am trying to implement these functions [1], to count the number of aggregates formed after compression of one single (and larger) aggregate.

But it is not working, the error is:

TypeError Traceback (most recent call last)
/usr/bin/yadedaily in <module>()

TypeError: addBodyToAggreg() takes exactly 2 arguments (0 given)

The problem seems to be in body,aggreg.

Somebody who worked with this code could help me understand?
Thanks,
Luis

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

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Luis Barbosa
Solved:
2019-01-09
Last query:
2019-01-09
Last reply:
2019-01-09
Jérôme Duriez (jduriez) said : #1

Hi,

According to the error, you most probably typed somewhere just "addBodyToAggreg()", ie without any argument, whereas this function defined by Jan in #5 of [1] requires two arguments to be given...

Without the code *you* used (in a Minimal Working fashion :-) ), I guess it is impossible to say more.

Jérôme

Luis Barbosa (luis-pires-b) said : #2

Hi Jerome, I've tried this, but it still not working.
Perhaps - def addBodyToAggreg(body,aggreg) - has to be used as an external function?
I tried this, but my python complains that this is not a module to be called.

Follow my script:

#!/usr/bin/python
# -*- coding: utf-8 -*-

#Forca normal lei de contato coesao e atrito
from yade import plot
from yade import pack
from yade import utils
from yade import bodiesHandling
from yade import export
#from add import addBodyToAggreg
import math
import random
##################################Material##########################################

O.materials.append(JCFpmMat(type=1,young=70e5,poisson=0.3,frictionAngle=radians(30),density=1500,tensileStrength=1e5,cohesion=1e5,jointNormalStiffness=1e5,jointShearStiffness=1e5,jointCohesion=1e5,jointFrictionAngle=radians(30),jointDilationAngle=0.0,label='spheres'))

O.materials.append(JCFpmMat(type=1,young=70e5,poisson=0.3,frictionAngle=radians(10),density=2000,tensileStrength=0,cohesion=0,jointNormalStiffness=0,jointShearStiffness=0,jointCohesion=0,jointFrictionAngle=radians(0),jointDilationAngle=0.0,label='plates'))

##################################Aggregate##########################################
size=1
if size==1:
 rag=0.055 #aumento de 12.61 x 0.00238
 print "class 1"
rad,gap= 0.01,0#0.003783,0
r=rag
print "diametro agregado", rag*2
# Spheres
ag=O.bodies.append(
# pack.regularHexa(
 pack.randomDensePack(
  (pack.inSphere((0,0,r),r)),radius=rad,color=(0,1,0),rRelFuzz=0,material='spheres') # head
)

######################################Planes#################################################
p1=O.bodies.append(utils.geom.facetBox((0,0,0),(0.05,-0.05,0),wallMask=1,material='plates'))
p2=O.bodies.append(utils.geom.facetBox((0,0,r),(0.05,-0.05,r),wallMask=32,material='plates'))# os r's se somam

######################################Engines#################################################
O.engines=[
  ForceResetter(),

 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
  [Ip2_JCFpmMat_JCFpmMat_JCFpmPhys(cohesiveTresholdIteration=1)],
  [Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM(smoothJoint=False, Key="Wei", recordCracks=True)]
 ),

  TranslationEngine(ids=p2,translationAxis=[0,0,-1],velocity=0.05),
  GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=500,timestepSafetyCoefficient=0.5),
  NewtonIntegrator(damping=0.1,gravity=[0,0,-9.81]),

   PyRunner(command='addBodyToAggreg()',iterPeriod=100,initRun=True),
   PyRunner(command='aggregs()',iterPeriod=100,initRun=True),

]

######################################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 CohFrictPhys 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

 aggs = aggregs()
 for a in aggs:
  print a

from yade import qt
qt.View()
qt.Controller()

Robert Caulk (rcaulk) said : #3

Jerome's educated guess was correct. You are calling this function without arguments:

PyRunner(command='addBodyToAggreg()',iterPeriod=100,initRun=True)

Jan Stránský (honzik) said : #4

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

Luis Barbosa (luis-pires-b) said : #5

Thank you Jan