uodate len(O.bodies) after erasing particles

Asked by azim

Dear all
I deleted some particles in my simulation. Particles and their interactions are erased without a problem.
But the length of O.bodies is the same as before deletion. I did that with looping over bodies and also with looping over len(O.bodies) but neither of them solve my problem.
Thanks in advance.

Here is my script:

# -*- coding: utf-8 -*-
from yade import pack
num_spheres=1000
compFricDegree = 30
targetPorosity = 0.43
finalFricDegree = 30
rate=-0.02
damp=0.2
stabilityThreshold=0.01
young=5e6
mn,mx=Vector3(0,0,0),Vector3(1,1,1)
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)
sp=pack.SpherePack()

clumps=False
if clumps:
 volume = (mx[0]-mn[0])*(mx[1]-mn[1])*(mx[2]-mn[2])
 mean_rad = pow(0.09*volume/num_spheres,0.3333)
 c1=pack.SpherePack([((-0.2*mean_rad,0,0),0.5*mean_rad),((0.2*mean_rad,0,0),0.5*mean_rad)])
 sp.makeClumpCloud(mn,mx,[c1],periodic=False)
 sp.toSimulation(material='spheres')
 O.bodies.updateClumpProperties()
else:
 sp.makeCloud(mn,mx,-1,0.3333,num_spheres,False, 0.95,seed=1)
 O.bodies.append([sphere(center,rad,material='spheres') for center,rad in sp])
triax=TriaxialStressController(
 maxMultiplier=1.0+2e4/young,
 finalMaxMultiplier=1.0+2e3/young,
 thickness = 0,
 stressMask = 7,
 internalCompaction=True,
)

newton=NewtonIntegrator(damping=damp)

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()]
 ),
 GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
 triax,
 newton
]
triax.goal1=triax.goal2=triax.goal3=-10000

while 1:
  O.run(1000, True)
  unb=unbalancedForce()
  print 'unbalanced force:',unb,' mean stress: ',triax.meanStress
  if unb<stabilityThreshold and abs(-10000-triax.meanStress)/10000<0.001:
    break

######### 1 loop over O.bodies
triax.internalCompaction=False
for b in O.bodies:
 if b.id>5:
  if b.state.pos[0]<.5:
   O.bodies.erase(b.id)

######### 2 loop over len(O.bodies)
#triax.internalCompaction=False
#for b in range(len(O.bodies)):
# if O.bodies[b].id in range(6):
# continue
# else:
# if O.bodies[b].state.pos[0]<.5:
# O.bodies.erase(O.bodies[b].id)

Question information

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

Hi Azim,

> but neither of them solve my problem

please specify your problem, I did not find any in your description..

Unchanged length of O.bodies is an implementation choice, see e.g. [1]

cheers
Jan

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

Revision history for this message
azim (mirzavand) said :
#2

Hi Jan

thanks for your reply.

>>please specify your problem, I did not find any in your description..

I want to update len(O.bodies) after erasing some of particles.
Their existence as a None/nullptr will be a problem for me in next parts of my simulation.
If you believe that it is optional and every future problems with or without updating has a solution,or, updating len(O.bodies ) will cause problem in performance {you said in [1]}, then we can skip updating, otherwise, I need to update len(O.bodies).
I read [1] and all other related questions before asking these question. they did not answer me.
thanks again Dear Jan
Azim

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

> Their existence as a None/nullptr will be a problem for me in next parts of my simulation.

again, please be more specific, I am pretty sure that there would be a solution

Jan

Revision history for this message
azim (mirzavand) said :
#4

Hi Jan
Hi Jan
for being more specific I need to open new thread. it is an other problem.
before closing current thread:
 I need to be sure about erasing.
would you please check the porosities after erasing in my script. I don't understand the changes
i tried:
for i in range(1,1000):

Revision history for this message
azim (mirzavand) said :
#5

sorry for the stupid mistake I made.

Hi Jan
for being more specific I need to open new thread. it is an other problem.
for closing current thread:
 I need to be sure about erasing.
1) would you please check the porosities after erasing in my script. I don't understand the changes
I tried:
for i in range(1,1000):
     print porosity()
     print triax.porosity
     O.run(1,1)
I appended above lines to the end of my script after erasing. I don't know to what origin it is calculating porosities???
and triax.porosity goes in negative range!!! would it be the effect of nullPtrs??
thanks
Azim

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

Hi Azim,

In general, updating len(O.bodies) after erasing bodies / on request is possible, but you would need to modify the C++ source. The change would most likely break functionality at maaany other places of Yade, so there would be large amount of work / testing to make it work.

More appropriate solution is to fix the parts of code, which were written/tested without the option of erasing bodies in mind (like in this case probably).

I can reproduce the problem with porosities. Probably it is the effect of null pointers, although after a short glance at the code I don't see the problem.. please report a bug

cheers
Jan

Revision history for this message
azim (mirzavand) said :
#7

Hi Jan
thank you.
I will report a bug.
you solved my problem in this case, but I don't know how it is marked as solved by Azim (me), how can I fix it?
thanks
Azim

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

> how can I fix it?

no idea :-)
Jan