← Back to team overview

yade-dev team mailing list archive

[yade-dev] fragments distribution for cohesive laws

 

Hi guys,

I tried to write some python code to analyse the distribution of fragments
produced during one of my simulation. Since it can interest some of you, I
wanted to share the first draft. As indicated in the file, I use it with
CohesiveFrictionalPM, but it can be easily adapted to every cohesive contact
laws. This is really basic stuff due to my still very poor coding knowledge,
but I think this kind of feature should be included into the sources.
Obviously, any improvement/advice on the code is welcome.

In its current form, the script produces a text file where each fragment
(cohesive block) is identified with its X,Y,Z dimensions, as well as the
number of particles involved and the corresponding volume. I have attached
an example of the results (picture+text file) obtained for a slope stability
simulation involving a wedge formed by two discontinuity planes.

If you think this could be useful in YADE, maybe we could include a function
in yade.utils with few more lines to plot the corresponding distribution
curve.

Cheers

  Luc

Attachment: WedgeIdentification.png
Description: PNG image

Attachment: wedgeFragmentDistribution.spheres
Description: Binary data

# -*- coding: utf-8 -*-
# encoding: utf-8

## THSI SCRIPT PRODUCES A TEXT FILE GIVING THE DISTRIBUTION SIZE OF FRAGMENTS (VALID FOR COHESIVE CONTACT LAWS, WRITTEN HERE FOR CFpm WHERE isCohesive INDICATES IF AN INTERACTION IS COHESIVE OR NOT)

### load simulation
O.load('wedge.xml')


######################################################################################
nbFragments=0
fragments=particles=[] # fragments not used here because some pb. The idea was to stock ID depending on the fragment to which they belong (see line 63 for pb)
color=[0.,0.,0.]
a=b=0
colorInc=1.0

## initialize if some bodies are non dynamic (isDynamic is used to determine if particles have already been checked)
for o in O.bodies :
    o.isDynamic=True
    o.shape.color=color

### to clean the file (other way?)
outFile=open('fragmentDistribution.spheres','w')
outFile.close()

outFile=open('fragmentDistribution.spheres','a')
outFile.write('# Id_nbPart_X_Y_Z_V' + '\n')

for o in O.bodies :
  if o.shape.name=='Sphere' and o.isDynamic==True :
      del particles[:]

      ## color setting (EXPERIMENTAL-> probably something cleaner to do here)
      if color[a]>=1 :
	  a+=1
	  if a>2 : 
	      b+=1
	      color=[0.,0.,0.]
	      a=b
	      if b>2 : 
		  color=[0.,0.,0.]
		  a=0
		  b=0
      color[a]=color[a]+colorInc

      nbFragments+=1
      print 'fragment ID=', nbFragments, ' | color=', color 
      particles.append(o.id)
      o.isDynamic=False #marked
      o.shape.color=color
      for c in particles :
	  for i in O.interactions.withBody(c) :
	      if i.phys.isCohesive :
		    if i.id1==c and O.bodies[i.id2].isDynamic==True :
			particles.append(i.id2)
			O.bodies[i.id2].isDynamic=False
			O.bodies[i.id2].shape.color=color
		    elif i.id2==c and O.bodies[i.id1].isDynamic==True :
			particles.append(i.id1)
			O.bodies[i.id1].isDynamic=False
			O.bodies[i.id1].shape.color=color

      #fragments.append(particles) # does not work since del particles[:] seems to delete fragments components too
      xmin=ymin=zmin=1000
      xmax=ymax=zmax=0
      nbParticles=X=Y=Z=V=0
      for p in particles :
	  nbParticles+=1
	  V+=1.333*3.14*pow(O.bodies[p].shape.radius,3)
	  if O.bodies[p].state.pos[0]<xmin :
	      xmin=O.bodies[p].state.pos[0]-O.bodies[p].shape.radius
	  if O.bodies[p].state.pos[0]>xmax :
	      xmax=O.bodies[p].state.pos[0]+O.bodies[p].shape.radius
	  if O.bodies[p].state.pos[1]<ymin :
	      ymin=O.bodies[p].state.pos[1]-O.bodies[p].shape.radius
	  if O.bodies[p].state.pos[1]>ymax :
	      ymax=O.bodies[p].state.pos[1]+O.bodies[p].shape.radius
	  if O.bodies[p].state.pos[2]<zmin :
	      zmin=O.bodies[p].state.pos[2]-O.bodies[p].shape.radius
	  if O.bodies[p].state.pos[2]>zmax :
	      zmax=O.bodies[p].state.pos[2]+O.bodies[p].shape.radius
      X=xmax-xmin
      Y=ymax-ymin
      Z=zmax-zmin
      outFile.write('%g\t%g\t%g\t%g\t%g\t%g\n'%(nbFragments,nbParticles,X,Y,Z,V))


print 'nbFragments=', nbFragments
outFile.close()

################################################################################
## graphical interface
from yade import qt
qt.Controller()
v=qt.View()
renderer=qt.Renderer()
renderer.bgColor=(0.5,0.5,0.5)