can we set a mask for a particular particle

Asked by ytang

Hi All,

I want to use this command : yade.export.text(filename, mask=-1) to export the particle position and radius. the explanation for this command is: mask (int) – export only spheres with the corresponding mask.

here is the MWE:

import numpy as np
from yade import pack, plot, export, utils
import math
O.bodies.append(geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(1,1,1),rMean=.07,rRelFuzz=.5)
sp.toSimulation()
O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 PyRunner(command='checkUnbalanced()',realPeriod=2),
 PyRunner(command='subbox()',iterPeriod=1000),
 #PyRunner(command='displacement()',iterPeriod=30000),
 #VTKRecorder(fileName='3d-vtk-',recorders=['all','bstresses'],iterPeriod=1000),
 PyRunner(command='get_po()',iterPeriod=1000),
 NewtonIntegrator(gravity=(0,0,-9.81),damping=0.4),

]
O.dt=.5*PWaveTimeStep()
print(len(O.bodies))
def checkUnbalanced():
 if unbalancedForce()<.001:
  O.pause()
#plot.plots={'i':('unbalanced')}
#plot.plot()
x0 = 0.5
y0 = 0.5
z0 = 0.5
######################## sub-region and coloring#########################################
ball_list1 =[]
def subbox():
 global ball_list1
 aaa = 0.0
 for b in O.bodies:
  brp = math.sqrt((b.state.pos[0]-x0)**2 + (b.state.pos[1]-y0)**2)
  if brp >= 0.2:
   if brp <= 0.4:
    if (b.state.pos[2]-z0 >= -0.5) and (b.state.pos[2]-z0 <= 0.0):
     if isinstance(b.shape,Sphere):
      b.shape.color =Vector3(255,255,255) # white
      m = b.id
      ball_list1.append(m)
for i in ball_list1:
 for b in O.bodies[i]:
  b.mask = 1
def get_po():
 export.text(filename = "state1.txt",mask = 1)

but it seems this command just export all particle' information. not just ball_list1.

Is there anyone can give me some suggestions.

best,
yong

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

1) mask=1 is the default value (so setting it to 1 would have no effect)
2) in the MWE, ball_list1 is empty..
3) have a look at source code [1]. A sphere is exported if: (mask<0) or ((mask & b.mask) > 0)

cheers
Jan

[1] https://gitlab.com/yade-dev/trunk/blob/master/py/export.py#L55

Revision history for this message
ytang (ytang116) said :
#2

Hi Jan,

1) you mean mask = 1 is the default value, I'm a little bit confused. Because in [1] the mask = 1, in [2] , mask = -1.

if mask = 1 is the default value.

so for this command: A sphere is exported if: (mask<0) or ((mask & b.mask) > 0)

mask < 0 is false.

& is the bitwise operation.

here is the definition of bitwise.
x & y
Does a "bitwise and". Each bit of the output is 1 if the corresponding bit of x AND of y is 1, otherwise, it's 0.

the binary expression for 1 is 00000001, if we want the output to be 1,
the only choice is to set b.mask is also 00000001. so I need to set b.mask = 1???
Is my understanding right?

best,
yong

References:
[1] https://yade-dem.org/doc/yade.utils.html?highlight=yade%20utils%20sphere#yade.utils.sphere
[2] https://yade-dem.org/doc/yade.export.html?highlight=export%20text#yade.export.text

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

Hello,

I meant that default is b.mask=1[1].
Setting it again to 1 in a for loop has no effect in your script.

> the binary expression for 1 is 00000001, if we want the output to be 1, the only choice is to set b.mask is also 00000001. so I need to set b.mask = 1??? Is my understanding right?

this I do not understand.. perhaps a short test could make it clear:
###
from yade import export
s1 = sphere((1,0,0),1,mask=1) # 1 = 0b01
s2 = sphere((2,0,0),1,mask=2) # 2 = 0b10
s3 = sphere((3,0,0),1,mask=3) # 3 = 0b11
O.bodies.append((s1,s2,s3))
export.text("maskDefault.txt")
export.text("mask1.txt",mask=1)
export.text("mask2.txt",mask=2)
export.text("mask3.txt",mask=3)
###

> but it seems this command just export all particle' information. not just ball_list1.

back to OP, all particles are exported just because you used export.text(...,mask=1) and b.mask of all bodies is 1 (by default).

Also note that apart from exporting, more importantly the b.mask value determines which particles may interact and which not (!!)

cheers
Jan

[1] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.Body.groupMask

Revision history for this message
Janek Kozicki (cosurgi) said :
#4

Just a quick note: we had a bug regarding Body mask when ENABLE_MPI=OFF compilation option was used. The bug was introduced on 2018-08-15 and was removed 5 days ago. For details see https://gitlab.com/yade-dev/trunk/merge_requests/285 and https://gitlab.com/yade-dev/trunk/commit/d53bf315dc5ca33dce5208196be1f56f38f189cb

Revision history for this message
Janek Kozicki (cosurgi) said :
#5

Sorry, the links were badly formatted, here it is again:
[1] is the merge requst
[2] is the actual fix.

[1] https://gitlab.com/yade-dev/trunk/merge_requests/285

[2] https://gitlab.com/yade-dev/trunk/commit/d53bf315dc5ca33dce5208196be1f56f38f189cb

Revision history for this message
ytang (ytang116) said :
#6

Thanks Jan Stránský, that solved my question.