← Back to team overview

yade-users team mailing list archive

Re: [Question #677402]: Count number of fragments

 

Question #677402 on Yade changed:
https://answers.launchpad.net/yade/+question/677402

    Status: Answered => Open

Luis Barbosa is still having a problem:
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()

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.