How to give each clump a new material and a new color?

Asked by Kalyan Khanal

Hi,

I have different clumps like:

###script

sp=pack.SpherePack()

c1=pack.SpherePack([((0,0,0),.08/1000)])
c2=pack.SpherePack([((0,0,0),.2/1000)])
c3=pack.SpherePack([((0,0,0),.3/1000),((0.4/1000,0,0),.3/1000)])
c4=pack.SpherePack([((0,0,0),.6/1000),((-0.8/1000,0,0),.3/1000),((0.8/1000,0,0),.3/1000)])
c5=pack.SpherePack([((0,0,0),0.001),((0.0015,0,0),0.001),((0.0015/2,0.0015,0),0.001)])
#c6=pack.SpherePack([((0,0,0),0.0024),((0.003,0,0),0.0024),((0,0.003,0),0.0024),((0.003,0.003,0),0.0024)])
sp=pack.SpherePack()
print 'Generated # of clumps:',sp.makeClumpCloud((0,0,0),(0.06,0.02,0.06),[c1,c2,c3,c4,c5],num=num_particles,periodic=False,seed=1)
sp.toSimulation(material='sphereMat',color=(255,153,0))

######################

Here, instead of giving one material and one color to all clump particles, How can I give different color and different material to each clump? foe eg: I want to give something like

for clump c1: material =x, color=(255,1,1)
for clump c2: material =Y, color=(255, 0,0) and so on.
I need to do this for at least two different clump type.

I am new to python code so, I want to know what is the script for it.

Any reference and script is much appreciated.

Kind regards,
Kalyan Khanal

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Kalyan Khanal
Solved:
Last query:
Last reply:
Revision history for this message
Kalyan Khanal (kalyan-khanal) said :
#1

#### show how to use makeClumpTemplate():

#dyad:
relRadList1 = [1,1]
relPosList1 = [[1,0,0],[-1,0,0]]

#peanut:
relRadList2 = [.5,1,.5]
relPosList2 = [[1,0,0],[0,0,0],[-1,0,0]]

#stick:
relRadList3 = [1,1,1,1,1]
relPosList3 = [[0,1,0],[0,2,0],[0,3,0],[0,4,0],[0,5,0]]

templates= []
templates.append(clumpTemplate(relRadii=relRadList1,relPositions=relPosList1))
templates.append(clumpTemplate(relRadii=relRadList2,relPositions=relPosList2))
templates.append(clumpTemplate(relRadii=relRadList3,relPositions=relPosList3))

#### show how to use replaceByClumps():

#replace by 50% dyads, 30% peanuts and 10% sticks:
O.bodies.replaceByClumps(templates,[.5,.3,.1])

How can I give different material to different clumps like for dyad=materialx, peanut=materialY and so on?

Revision history for this message
Jan Stránský (honzik) said :
#2

Hello,
it should not be difficult.. Coupld you please post a complete working minimal example such that we can try it?
thanks
Jan

Revision history for this message
Kalyan Khanal (kalyan-khanal) said :
#3

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

'''This example shows usage of clumpTemplate(), replaceByClumps() and getRoundness().'''

#define material for all bodies:
id_Mat=O.materials.append(FrictMat(young=1e7,poisson=0.3,density=1000,frictionAngle=1))
Mat=O.materials[id_Mat]

#define engines:
O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 NewtonIntegrator(damping=0.7,gravity=[0,0,-10])
]

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

#create a box:
id_box = O.bodies.append(box((0,0,0),(2,2,.1),fixed=True,material=Mat))

#create assembly of spheres:
sp=pack.SpherePack()
sp.makeCloud(minCorner=(-1.5,-1.5,.1),maxCorner=(1.5,1.5,2),rMean=.2,rRelFuzz=.5,num=100,periodic=False)
O.bodies.append([sphere(c,r,material=Mat) for c,r in sp])

print len(sp),' particles generated.'
print 'Roundness coefficient without clumps is: ',O.bodies.getRoundness()

#### show how to use makeClumpTemplate():

#dyad:
relRadList1 = [1,1]
relPosList1 = [[1,0,0],[-1,0,0]]

#peanut:
relRadList2 = [.5,1,.5]
relPosList2 = [[1,0,0],[0,0,0],[-1,0,0]]

#stick:
relRadList3 = [1,1,1,1,1]
relPosList3 = [[0,1,0],[0,2,0],[0,3,0],[0,4,0],[0,5,0]]

templates= []
templates.append(clumpTemplate(relRadii=relRadList1,relPositions=relPosList1))
templates.append(clumpTemplate(relRadii=relRadList2,relPositions=relPosList2))
templates.append(clumpTemplate(relRadii=relRadList3,relPositions=relPosList3))

#### show how to use replaceByClumps():

#replace by 50% dyads, 30% peanuts and 10% sticks:
O.bodies.replaceByClumps(templates,[.5,.3,.1])

#### show how to use getRoundness():

#create a list of all standalone spheres:
standaloneList = []
for b in O.bodies:
 if b.isStandalone:
  standaloneList.append(b.id)

print 'Roundness coefficient for spheres and clumps is: ',O.bodies.getRoundness()
print 'Roundness coefficient just for clumps is: ',O.bodies.getRoundness(standaloneList)

O.dt=1e-6

This is an example of replace by clumps in yade.

since there are three different clumps but same material, how can I make each clump a different material.

I tried the following but does not work but does not work:

from yade import pack

l = 0.06
b = 0.02
h = 0.06
vol = l*b*h
mn,mx=Vector3(0,0,0),Vector3(l,b,h)

O.materials.append(CohFrictMat(young=2e8,poisson=0.3,frictionAngle=radians(30),density=2650,label='spheres'))
O.materials.append(CohFrictMat(young=1e9,poisson=0.3,frictionAngle=radians(30),density=1000,label='fibres'))

sp=pack.SpherePack()
sp.makeCloud(mn,mx,-1,0.3333,100,False, 0.95)
O.bodies.append([sphere(center,rad,material='spheres',color=(255,0,0)) for center,rad in sp])

#dyad:
relRadList1 = [1,1]
relPosList1 = [[1,0,0],[-1,0,0]]

#peanut:
relRadList2 = [.5,1,.5]
relPosList2 = [[1,0,0],[0,0,0],[-1,0,0]]

templates= []
templates.append(clumpTemplate(relRadii=relRadList1,relPositions=relPosList1))
templates.append(clumpTemplate(relRadii=relRadList2,relPositions=relPosList2))

O.bodies.replaceByClumps(templates,[0.31,.31])
sp.toSimulation()

#for fibres
fibresp=pack.SpherePack()
fibresp.makeCloud(mn,mx,-1,0.3333,10,False, 0.95)
O.bodies.append([sphere(center,rad,material='spheres',color=(255,0,0)) for center,rad in fibresp])

#stick:
relRadList3 = [1,1,1,1,1]
relPosList3 = [[0,1,0],[0,2,0],[0,3,0],[0,4,0],[0,5,0]]

templatesf= []
templates.append(clumpTemplate(relRadii=relRadList3,relPositions=relPosList3))

O.bodies.replaceByClumps(templates,[.1])
fibresp.toSimulation()

I get error for length and I cannot assign different materials. I want to give dyad and peanut shape sphere material and stick with fibre material and also want to change their colours respectively.

I don't know the coding very well so I think a small algorithm could fix this, I am trying but I am lost it seems.

Revision history for this message
Klaus Thoeni (klaus.thoeni) said :
#4

Hi,

this should be easy as replaceByClumps actually returns a list:

clumpList = O.bodies.replaceByClumps(templates,[.5,.3,.1])

You can use the list (variable "clumpList" above) to modify the properties.

HTH
Klaus

Revision history for this message
Kalyan Khanal (kalyan-khanal) said :
#5

I am trying with what you've said. Thanks anyway :)