Exception occured: std::bad_alloc

Asked by Yor1

Hello everybody !

I try to simulate a simple shear test.
I simulate the simple shear test with 400000 iterations.
The problem is when the simulation is between 1000 and 1100 iterations i obtained this error message:

"FATAL /home/hamdi/YADE/sources/trunk/core/ThreadRunner.cpp:30 run: Exception occured:
std::bad_alloc"

I don't undersatand the origin of the error.

Best regards!
Jabrane

P.S this is my script

# -*- coding: utf-8 -*-
O=Omega()

from yade import ymport, utils, plot

################## parameters definition
PACKING='X1Y1Z1_1k'
DAMPING=0.5
dtCOEFF=0.5
normalSTRESS=5e5
normalVEL=normalSTRESS/1e8 # 0.001 for 100kPa // optimized for normalVEL=normalSTRESS/1e8?
shearVEL=1*normalVEL # try different values to ensure quasi-static conditions
intR=1.263 #1.263 for X1Y1Z1_5k
DENS=3000
YOUNG=50e9
FRICT=18
ALPHA=0.3
TENS=45e5
COH=45e6
iterMAX=400000
OUT='shearTest_'+PACKING+'_K10_D3000_Y50e9A03F18T45e5C45e6_500kPa_shearVel1'

###################### Import of the sphere assembly
### material definition
def sphereMat(): return JCFpmMat(type=1,density=DENS,young=YOUNG,poisson = ALPHA,frictionAngle=radians(FRICT),tensileStrength=TENS,cohesion=COH)
def wallMat(): return JCFpmMat(type=0,density=DENS,young=YOUNG,frictionAngle=radians(0))
## copy spheres from the packing into the scene
O.bodies.append(ymport.text(PACKING+'.spheres',scale=1.,shift=Vector3(0,0,0),material=sphereMat))

## preprocessing to get dimensions
dim=utils.aabbExtrema()
xinf=dim[0][0]
xsup=dim[1][0]
X=xsup-xinf
yinf=dim[0][1]
ysup=dim[1][1]
Y=ysup-yinf
zinf=dim[0][2]
zsup=dim[1][2]
Z=zsup-zinf
## initial surface
S0=X*Z

## spheres factory
R=0
Rmax=0
numSpheres=0.
for o in O.bodies:
 if isinstance(o.shape,Sphere):
   o.shape.color=(0.7,0.5,0.3)
   numSpheres+=1
   R+=o.shape.radius
   if o.shape.radius>Rmax:
     Rmax=o.shape.radius
Rmean=R/numSpheres

###################### creation of shear box
thickness=Y/100
oversizeFactor=1.3

### loading platens
O.bodies.append(utils.box(center=(xinf+X/2.,yinf-thickness+Rmean/10.,zinf+Z/2.),extents=(oversizeFactor*X/2,thickness,oversizeFactor*Z/2),material=wallMat,fixed=True))
bottomPlate=O.bodies[-1]
O.bodies.append(utils.box(center=(xinf+X/2.,ysup+thickness-Rmean/10.,zinf+Z/2.),extents=(oversizeFactor*X/2,thickness,oversizeFactor*Z/2),material=wallMat,fixed=True))
topPlate=O.bodies[-1]

O.engines=[

 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(aabbEnlargeFactor=intR,label='aabb'),Bo1_Box_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(interactionDetectionFactor=intR,label='ss2d3dg'),Ig2_Box_Sphere_ScGeom()],
  [Ip2_JCFpmMat_JCFpmMat_JCFpmPhys(cohesiveTresholdIteration=1,label='interactionPhys')],
  [Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM(recordCracks=True,Key=OUT,label='interactionLaw')]
 ),

 GlobalStiffnessTimeStepper(defaultDt=0.1*PWaveTimeStep(),timestepSafetyCoefficient=dtCOEFF),
 TranslationEngine(ids=[topPlate.id],translationAxis=(0.,-1.,0.),velocity=0.,label='yTranslation'),
 PyRunner(iterPeriod=1,initRun=True,command='servoController()',label='servo'),
 NewtonIntegrator(damping=DAMPING,gravity=(0,0,0),label='damper'),
 PyRunner(iterPeriod=100,initRun=True,command='dataCollector()'),
]

###################### Engines definition ( servoController() and dataCollector() )
shearing=False
sigmaN=0
tau=0
Fs1=0
Fs2=0
Xdispl=0
px0=0
Ydispl=0
py0=topPlate.state.pos[1]
prevTranslation=0
n=0

def servoController():
    global px0, py0, sigmaN, n, Fn1, Fn2, shearing, butee, piston1, piston2
    Fn1=abs(O.forces.f(topPlate.id)[1])
    Fn2=abs(O.forces.f(bottomPlate.id)[1])
    sigmaN=Fn1/(S0-2*Xdispl*Z) # necessary?
    #print yTranslation.velocity, sigmaN
    if shearing==False:
      if yTranslation.velocity<normalVEL:
 yTranslation.velocity+=normalVEL/1000
      if sigmaN>(0.9*normalSTRESS):
 yTranslation.velocity=normalVEL*((normalSTRESS-sigmaN)/normalSTRESS)
    if shearing==False and abs((normalSTRESS-sigmaN)/normalSTRESS)<0.001 and unbalancedForce()<0.01:
      yTranslation.velocity=0
      n+=1
      if n>1000 and abs((sigmaN-normalSTRESS)/normalSTRESS)<0.001:
 print 'stress on joint plane = ', utils.forcesOnPlane((X/2,Y/2,Z/2),(0,1,0))/S0

 ### add top box
    O.bodies.append(utils.box(center=(xinf-thickness+Rmean/10,3*(ysup/4)+2*Rmean,zsup/2),extents=(thickness,Y/4,oversizeFactor*Z/2),material=wallMat,fixed=True))
    butee=O.bodies[-1]
    O.bodies.append(utils.box(center=(xsup+thickness-Rmean/10,3*(ysup/4)+2*Rmean,zsup/2),extents=(thickness,Y/4,oversizeFactor*Z/2),material=wallMat,fixed=True))
    O.bodies.append(utils.box(center=(xsup/2,3*(ysup/4)+2*Rmean,zinf-thickness+Rmean/10),extents=(oversizeFactor*X/2,Y/4,thickness),material=wallMat,fixed=True,wire=True))
    O.bodies.append(utils.box(center=(xsup/2,3*(ysup/4)+2*Rmean,zsup+thickness-Rmean/10),extents=(oversizeFactor*X/2,Y/4,thickness),material=wallMat,fixed=True,wire=True))
 ### add bottom box
    O.bodies.append(utils.box(center=(xsup+thickness-Rmean/10,(ysup/4)-2*Rmean,zsup/2),extents=(thickness,Y/4,oversizeFactor*Z/2),material=wallMat,fixed=True))
    piston1=O.bodies[-1]
    O.bodies.append(utils.box(center=(xinf-thickness+Rmean/10,(ysup/4)-2*Rmean,zsup/2),extents=(thickness,Y/4,oversizeFactor*Z/2),material=wallMat,fixed=True))
    piston2=O.bodies[-1]
    O.bodies.append(utils.box(center=(xsup/2,(ysup/4)-2*Rmean,zinf-thickness+Rmean/10),extents=(oversizeFactor*X/2,Y/4,thickness),material=wallMat,fixed=True,wire=True))
    O.bodies.append(utils.box(center=(xsup/2,(ysup/4)-2*Rmean,zsup+thickness-Rmean/10),extents=(oversizeFactor*X/2,Y/4,thickness),material=wallMat,fixed=True,wire=True))
 ### add engine and initialisation
    O.engines=O.engines[:6]+ [TranslationEngine(ids=[piston1.id,piston2.id],translationAxis=(-1.,0.,0.),velocity=0.)]+O.engines[6:]
    px0=piston1.state.pos[0]
    py0=topPlate.state.pos[1]
    shearing=True
    #print 'shearing! || iteration=', O.iter
    if shearing==True:
      #yTranslation.velocity=0. # if you want a constant normal diaplacement control
      yTranslation.velocity=50*normalVEL*((normalSTRESS-sigmaN)/normalSTRESS) # not good enough because not general (coeff needs to be adjusted)
      if O.engines[6].velocity<shearVEL:
 O.engines[6].velocity+=(shearVEL/1000)

def dataCollector():
    global Xdispl, Ydispl, tau, Fs1, Fs2
    if shearing:
      Fs1=abs(O.forces.f(butee.id)[0])
      Fs2=abs(O.forces.f(piston1.id)[0])
      Xdispl=abs(piston1.state.pos[0]-px0)
    tau=Fs1/(S0-2*Xdispl*Z)
    Ydispl=abs(topPlate.state.pos[1]-py0)
    numberOfCohesiveBonds=0
    for i in O.interactions:
      if i.phys.isCohesive:
 numberOfCohesiveBonds+=1
    yade.plot.addData({'t':O.time,'i':O.iter,'Xdispl':Xdispl,'sigmaN':sigmaN,'Fn1':Fn1,'Fn2':Fn2,'tau':tau,'Fs1':Fs1,'Fs2':Fs2,'Ydispl':Ydispl,'unbF':utils.unbalancedForce(),'Ek':utils.kineticEnergy(),'bonds':numberOfCohesiveBonds})
   plot.saveDataTxt(OUT)

plot.plots={'i':('sigmaN','tau')}

from yade import qt
qt.Controller()
qt.View()
v=qt.Renderer()
v.dispScale=(1,1,1)

O.step();

ss2d3dg.interactionDetectionFactor=-1.
aabb.aabbEnlargeFactor=-1.

O.run(iterMAX)

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Yor1
Solved:
Last query:
Last reply:
Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#1

Hi,
Can you compile&run a debug build and post more information here?
Bruno

Revision history for this message
Yor1 (jabrane-hamdi) said :
#2

Hello Bruno,

I think that is a problem of memory.
In the engines i think tha "PyRunner(iterPeriod=1,initRun=True,command='servoController()',label='servo')" take a lot of memory and after 1000 iterations i don't have memory.
In order to preserve memory for the simulation, i think that the solution is iterPeriod must be important for example iterPeriod=100 or iterPeriod=1000.

Best regards.
Jabrane.

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#3

There should not be any memory cost for this function.

Why is there an indentation before "O" in:
### add top box
    O.bodies.append(utils.box(center=(xinf-thickness+Rmean/10,3*(ysup/4)+2*Rmean,zsup/2)

It could be a problem.

Revision history for this message
Yor1 (jabrane-hamdi) said :
#4

Hi Bruno,

We have the indentation before "O" because this line is included
in the recorder servoController().

Best regards.
Jabrane.

Revision history for this message
Anton Gladky (gladky-anton) said :
#5

You are adding bodies at each call of servoController()?
Could you please check the number of bodies during the
simulation?

Anton

2016-06-21 18:37 GMT+02:00 Yor1 <email address hidden>:
> Question #295520 on Yade changed:
> https://answers.launchpad.net/yade/+question/295520
>
> Yor1 posted a new comment:
> Hi Bruno,
>
> We have the indentation before "O" because this line is included
> in the recorder servoController().
>
> Best regards.
> Jabrane.
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Chareyre (bruno-chareyre-9) said :
#6

Bingo! :)

On 21 June 2016 at 22:13, Anton Gladky <<email address hidden>
> wrote:

> Question #295520 on Yade changed:
> https://answers.launchpad.net/yade/+question/295520
>
> Anton Gladky proposed the following answer:
> You are adding bodies at each call of servoController()?
> Could you please check the number of bodies during the
> simulation?
>
> Anton
>
>
> 2016-06-21 18:37 GMT+02:00 Yor1 <email address hidden>:
> > Question #295520 on Yade changed:
> > https://answers.launchpad.net/yade/+question/295520
> >
> > Yor1 posted a new comment:
> > Hi Bruno,
> >
> > We have the indentation before "O" because this line is included
> > in the recorder servoController().
> >
> > Best regards.
> > Jabrane.
> >
> > --
> > You received this question notification because your team yade-users is
> > an answer contact for Yade.
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~yade-users
> > Post to : <email address hidden>
> > Unsubscribe : https://launchpad.net/~yade-users
> > More help : https://help.launchpad.net/ListHelp
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>
>

Revision history for this message
Yor1 (jabrane-hamdi) said :
#7

Dear Bruno and Anton,

The origin of the problem is that the boxes are contituted many times in the recorder servoController().
So i moved the lines in which the boxes is contituted out of the recorder and i works.
That solve my problem.

Best regards.
Jabrane.

Revision history for this message
badugama (badugama) said :
#8

I'm new to YADE and Ubuntu and, I was looking to develop a script for simple shear test. I tried the above script but got a different telling ,

yTranslation.velocity+=normalVEL/1000

IndentationError: unindent does not match any outer indentation level

Can anyone tell me why i am getting an such a error ?

Revision history for this message
Jérôme Duriez (jduriez) said :
#9

Hi,

The YADE terminal interface conforms Python language syntax rules (because YADE terminal is python, we could say). One of such rules is that indentation (how many spaces / tabulations appear at the beginning of a line) does matter, with function definitions, or "if" blocks being defined by indentation.

Here, the correct indentation of the above script has been lost during copy/paste, leading to an erroneous python (or YADE) script.
You just have to correct it, which gives you a nice opportunity to familiarize yourself with python/YADE ;-) .

Revision history for this message
badugama (badugama) said :
#10

Thanks Jerome,

Thanks to your comment, I could avoid that error and some more errors like that. but now I am getting en error

IOError: [Errno 2] No such file or directory: 'X1Y1Z1_1k.spheres'

Can you tell me , where I should look at ??

Revision history for this message
Yor1 (jabrane-hamdi) said :
#11

Hello Badugama,

 'X1Y1Z1_1k.spheres' is file which contains the positions and radii of particles of the sample.
You can constitute your sample and you name it 'xxxx.spheres' for example and you modify X1Y1Z1_1k.spheres
by 'xxxx.spheres' in the script.
Remark : you have to create your particles file in the same directory of your script.

Best regards.
Jabrane.