Example problem, or to create a function ?

Asked by Arthur Mercier

Hi,

I'm a beginner with Yade Software, I have Ubuntu 10.10 and Yade bzr2811.

I try to run the example Gravity Deposition of the tutorial but I have some problems.

The script is:
"from yade import pack, plot

O.bodies.append(utils.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))

sp=pack.SpherePack()

sp.makeCloud((0,0,0),(1,1,1),rMean=.05,rRelFuzz=.5)

sp.toSimulation()
O.engines=[
    ForceResetter(),
    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
    InteractionLoop(
        [Ig2_Sphere_Sphere_L3Geom(),Ig2_Facet_Sphere_L3Geom()],
        [Ip2_FrictMat_FrictMat_FrictPhys()],
        [Law2_L3Geom_FrictPhys_ElPerfPl()]
    ),
    GravityEngine(gravity=(0,0,-9.81)),
    NewtonIntegrator(damping=0.4),
    PyRunner(command='checkUnbalanced()',realPeriod=2),
    PyRunner(command='addPlotData()',iterPeriod=100)
    ]

O.dt=.5*utils.PWaveTimeStep()

O.trackEnergy=True

def checkUnbalanced():
if utils.unbalancedForce()<.05:
O.pause()
plot.saveDataTxt('bbb.txt.bz2')

def addPlotData():
plot.addData(i=O.iter,unbalanced=utils.unbalancedForce(),**O.energy)

plot.plots={'i':('unbalanced',None,O.energy.keys)}

plot.plot()
O.saveTmp()"

When I try to run it's written:
"Yade [18]: ---------------------------------------------------------------------------
NameError Traceback (most recent call last)

/home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
----> 1
      2
      3
      4
      5

NameError: name 'checkUnbalanced' is not defined

NameError: name 'addPlotData' is not defined
---------------------------------------------------------------------------
NameError Traceback (most recent call last)

/home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
----> 1
      2
      3
      4
      5 "
So my question is what is not good with the code ? And why to define the functions checkUnbalanced and addPlotData after the O.engines, why not before O.engines ?
How do I run a plot; 'cause when I write
"Yade [21]: import yade.plot; yade.plot.plot();
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)

/home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
----> 1
      2
      3
      4
      5

/home/arthur/yade/build/lib/yade-new/py/yade/plot.pyc in plot(noShow, subPlots)
    586 global currLineRefs
    587 figs=set([l.line.get_axes().get_figure() for l in currLineRefs])
--> 588 if not hasattr(list(figs)[0],'show') and not noShow:
    589 import warnings
    590 warnings.warn('plot.plot not showing figure (matplotlib using headless backend?)')

IndexError: list index out of range" ?

Thanks !

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anton Gladky (gladky-anton) said :
#1

Hi, could you, please, _attach_ the script instead of putting it into
the message?

Thanks.
Anton

On Tue, Apr 19, 2011 at 9:24 PM, Arthur Mercier
<email address hidden> wrote:
> New question #153493 on Yade:
> https://answers.launchpad.net/yade/+question/153493
>
> Hi,
>
> I'm a beginner with Yade Software, I have Ubuntu 10.10 and Yade bzr2811.
>
> I try to run the example Gravity Deposition of the tutorial but I have some problems.
>
> The script is:
> "from yade import pack, plot
>
> O.bodies.append(utils.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
>
> sp=pack.SpherePack()
>
> sp.makeCloud((0,0,0),(1,1,1),rMean=.05,rRelFuzz=.5)
>
> sp.toSimulation()
> O.engines=[
>    ForceResetter(),
>    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
>    InteractionLoop(
>        [Ig2_Sphere_Sphere_L3Geom(),Ig2_Facet_Sphere_L3Geom()],
>        [Ip2_FrictMat_FrictMat_FrictPhys()],
>        [Law2_L3Geom_FrictPhys_ElPerfPl()]
>    ),
>    GravityEngine(gravity=(0,0,-9.81)),
>    NewtonIntegrator(damping=0.4),
>    PyRunner(command='checkUnbalanced()',realPeriod=2),
>    PyRunner(command='addPlotData()',iterPeriod=100)
>    ]
>
> O.dt=.5*utils.PWaveTimeStep()
>
> O.trackEnergy=True
>
> def checkUnbalanced():
> if utils.unbalancedForce()<.05:
> O.pause()
> plot.saveDataTxt('bbb.txt.bz2')
>
> def addPlotData():
> plot.addData(i=O.iter,unbalanced=utils.unbalancedForce(),**O.energy)
>
> plot.plots={'i':('unbalanced',None,O.energy.keys)}
>
> plot.plot()
> O.saveTmp()"
>
> When I try to run it's written:
> "Yade [18]: ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
> ----> 1
>      2
>      3
>      4
>      5
>
> NameError: name 'checkUnbalanced' is not defined
>
> NameError: name 'addPlotData' is not defined
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
> ----> 1
>      2
>      3
>      4
>      5 "
> So my question is what is not good with the code ? And why to define the functions checkUnbalanced and addPlotData after the O.engines, why not before O.engines ?
> How do I run a plot; 'cause when I write
> "Yade [21]: import yade.plot; yade.plot.plot();
> ---------------------------------------------------------------------------
> IndexError                                Traceback (most recent call last)
>
> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
> ----> 1
>      2
>      3
>      4
>      5
>
> /home/arthur/yade/build/lib/yade-new/py/yade/plot.pyc in plot(noShow, subPlots)
>    586         global currLineRefs
>    587         figs=set([l.line.get_axes().get_figure() for l in currLineRefs])
> --> 588         if not hasattr(list(figs)[0],'show') and not noShow:
>    589                 import warnings
>    590                 warnings.warn('plot.plot not showing figure (matplotlib using headless backend?)')
>
> IndexError: list index out of range" ?
>
> Thanks !
>
>
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
Anton Gladky (gladky-anton) said :
#2

I think the problem in your code is in indention. It should look like this:

def addPlotData():
  plot.addData(i=O.iter,unbalanced=utils.unbalancedForce(),**O.energy)

and

def checkUnbalanced():
  if utils.unbalancedForce()<.05:
  O.pause()
  plot.saveDataTxt('bbb.txt.bz2')

On Tue, Apr 19, 2011 at 9:41 PM, Anton Gladky <email address hidden> wrote:
> Hi, could you, please, _attach_ the script instead of putting it into
> the message?
>
> Thanks.
> Anton
>
>
>
>
> On Tue, Apr 19, 2011 at 9:24 PM, Arthur Mercier
> <email address hidden> wrote:
>> New question #153493 on Yade:
>> https://answers.launchpad.net/yade/+question/153493
>>
>> Hi,
>>
>> I'm a beginner with Yade Software, I have Ubuntu 10.10 and Yade bzr2811.
>>
>> I try to run the example Gravity Deposition of the tutorial but I have some problems.
>>
>> The script is:
>> "from yade import pack, plot
>>
>> O.bodies.append(utils.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
>>
>> sp=pack.SpherePack()
>>
>> sp.makeCloud((0,0,0),(1,1,1),rMean=.05,rRelFuzz=.5)
>>
>> sp.toSimulation()
>> O.engines=[
>>    ForceResetter(),
>>    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
>>    InteractionLoop(
>>        [Ig2_Sphere_Sphere_L3Geom(),Ig2_Facet_Sphere_L3Geom()],
>>        [Ip2_FrictMat_FrictMat_FrictPhys()],
>>        [Law2_L3Geom_FrictPhys_ElPerfPl()]
>>    ),
>>    GravityEngine(gravity=(0,0,-9.81)),
>>    NewtonIntegrator(damping=0.4),
>>    PyRunner(command='checkUnbalanced()',realPeriod=2),
>>    PyRunner(command='addPlotData()',iterPeriod=100)
>>    ]
>>
>> O.dt=.5*utils.PWaveTimeStep()
>>
>> O.trackEnergy=True
>>
>> def checkUnbalanced():
>> if utils.unbalancedForce()<.05:
>> O.pause()
>> plot.saveDataTxt('bbb.txt.bz2')
>>
>> def addPlotData():
>> plot.addData(i=O.iter,unbalanced=utils.unbalancedForce(),**O.energy)
>>
>> plot.plots={'i':('unbalanced',None,O.energy.keys)}
>>
>> plot.plot()
>> O.saveTmp()"
>>
>> When I try to run it's written:
>> "Yade [18]: ---------------------------------------------------------------------------
>> NameError                                 Traceback (most recent call last)
>>
>> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
>> ----> 1
>>      2
>>      3
>>      4
>>      5
>>
>> NameError: name 'checkUnbalanced' is not defined
>>
>> NameError: name 'addPlotData' is not defined
>> ---------------------------------------------------------------------------
>> NameError                                 Traceback (most recent call last)
>>
>> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
>> ----> 1
>>      2
>>      3
>>      4
>>      5 "
>> So my question is what is not good with the code ? And why to define the functions checkUnbalanced and addPlotData after the O.engines, why not before O.engines ?
>> How do I run a plot; 'cause when I write
>> "Yade [21]: import yade.plot; yade.plot.plot();
>> ---------------------------------------------------------------------------
>> IndexError                                Traceback (most recent call last)
>>
>> /home/arthur/yade/build/lib/yade-new/py/yade/__init__.pyc in <module>()
>> ----> 1
>>      2
>>      3
>>      4
>>      5
>>
>> /home/arthur/yade/build/lib/yade-new/py/yade/plot.pyc in plot(noShow, subPlots)
>>    586         global currLineRefs
>>    587         figs=set([l.line.get_axes().get_figure() for l in currLineRefs])
>> --> 588         if not hasattr(list(figs)[0],'show') and not noShow:
>>    589                 import warnings
>>    590                 warnings.warn('plot.plot not showing figure (matplotlib using headless backend?)')
>>
>> IndexError: list index out of range" ?
>>
>> Thanks !
>>
>>
>>
>> --
>> You received this question notification because you are a member of
>> yade-users, which 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
Arthur Mercier (mercier-arthur) said :
#3

"Hi, could you, please, _attach_ the script instead of putting it into
the message?"

Here is the link of the script http://www.2shared.com/file/xrflYnqC/Tuto2.html (how can I attach the script otherwise ?).
Is it important to define the function before/after the O.engines ?

"I think the problem in your code is in indention"
It's true I didn't know that the indentation was important with Python, but it is. But I still have the problem, "NameError: name 'addPlotData' is not defined".

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

Strange, your script on Ubuntu 10.04 and with yade r2813 is working:

Welcome to Yade bzr2813
TCP python prompt on localhost:9000, auth cookie `scayed'
XMLRPC info provider on http://localhost:21000
Running script Tuto2.py
/home/gladk/dem/yade/cleanCompNew/build/lib/yade-cleanCompNew/py/yade/utils.py:280:
DeprecationWarning: Function utils.facetBox is deprecated, use
geom.facetBox instead.
  _deprecatedUtilsFunction('facetBox','geom.facetBox')
yade.plot: creating fake plot, since there are no y-data yet
/usr/lib/pymodules/python2.6/matplotlib/axes.py:4356: UserWarning: No
labeled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labeled objects found. "
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view, F10
both, F9 generator, F8 plot. ]]
Yade [1]: yade.plot: creating new line for gravWork
yade.plot: creating new line for kinetic
yade.plot: creating new line for elastPotential
yade.plot: creating new line for nonviscDamp
yade.plot:

Just one problem: utils.facetBox should be replaced by geom.facetBox.
But it is not critical.
Let us know, if you still has a problem.

You are right, there is no way to attach a file to answers, sorry for
wrong suggestion...
https://bugs.launchpad.net/launchpad/+bug/77123

Anton

Revision history for this message
Arthur Mercier (mercier-arthur) said :
#5

Still the problem, did I forget to import some things ? (such as "from yade import plot, pack, geom, utils").

Revision history for this message
Launchpad Janitor (janitor) said :
#6

This question was expired because it remained in the 'Open' state without activity for the last 15 days.