Rel. to Uniaxial test

Asked by Swapnil

Hi Jan and others :)

Following the uniax.py script on github, I am attempting the uniaxial test. As a beginner, I am trying the same script first.

(1) Creating a table from which the parameters are read and used:

readParamsFromTable(noTableOk=True,young=24e9,poisson=0.2,sigmaT=3.5e6,frictionAngle=atan(0.8),epsCrackOnset=1e-4,relDuctility=30,intRadius=1.5,dtSafety=0.8,damping=0.4,strainRateCompression=0.5,setSpeeds=True,doModes=3,specimenLength=0.15,sphereRadius=3.5e-3,isoPrestress=0)

(2) Creating a new material "Concreteid":

concreteId=O.materials.append(CpmMat(young=young,frictionAngle=frictionAngle,poisson=poisson,density=4800,sigmaT=sigmaT,relDuctility=relDuctility,epsCrackOnset=epsCrackOnset,isoPrestress=isoPrestress))

(3) Packing spheres in a hyperboloid:
sp=SpherePack()

sp=pack.randomDensePack(pack.inHyperboloid((0,0,-.5*specimenLength),(0,0,.5*specimenLength),.25*specimenLength,.17*specimenLength),spheresInCell=2000,radius=sphereRadius,memoizeDb='/tmp/triaxPackCache.sqlite',returnSpherePack=True)

sp.toSimulation(material=concreteId)

(4) bb=uniaxialTestFeatures() (I think this calls all the uniaxial test function)

(5) negIds,posIds,axis,crossSectionArea=bb[`negIds´],bb[`posIds´],bb[`axis´],bb[`area´] --> Upon typing this command in the terminal, it says "Invalid Syntax".

Can somebody help and explain what this command actually means, does and why is there a syntax error shown here ? Have no idea what I can do..

I am completely new in Yade and hence reading the documentation as well as trying simple tests. Will certainly have more questions :D

thanks :)

Question information

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

Hello,

5) this is Python related. bb is a Python dict. It has string keys. so it should be bb['negIds'] or bb["negIds"], not bb[`negIds´] (some not valid quotation marks)

concerning what it means, you can have a look at docs [1] or source code [2]. It takes all particles and determines which are "boundary", what crosssection the specimen has etc.

cheers
Jan

[1] http://yade-dem.org/doc/yade.utils.html#yade.utils.uniaxialTestFeatures
[2] https://github.com/yade/trunk/blob/master/py/utils.py#L537

Revision history for this message
Swapnil (swapspace) said :
#2

Hi Jan, thanks for the response.

I am trying a simpler case for the uniaxial test. Following things up with the following code:

from yade import pack,plot
pred=pack.inCylinder((0,0,0),(0,0,0.2),0.05) (Packing in a cylinder)
sp=pack.randomDensePack(pred,radius=0.008) (Packing spheres in the above cylinder)
O.bodies.append(sp) (Adds the spheres to the cylinder geometry)
yade.qt.Controller() (Pressed F12 and it displays the packed geometry)

Moving towards uniaxial testing:

bb=uniaxialTestFeatures()

negIds,posIds,axis,crossSectionArea=bb['negIds'],bb['posIds'],bb['axis'],bb['area'] --> this time the command worked unlike the last time when I got an error. Still no idea what the reason might have been

O.dt=0.005*PWavetimeStep() (Time step control for the simulation)

Next, we go for the Interaction of spheres inside:

O.engines=[ForceResetter(),InsertionSortCollider([Bo1_Sphere_Aabb()]),InteractionLoop([Ig2_Sphere_Sphere_ScGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_ScGeom_FrictPhys_CundallStrack()]),NewtonIntegrator(),UniaxialStrainer(strainRate=-0.00005,axis=axis,asymmetry=0,posIds=posIds,negIds=negIds,crossSectionArea=crossSectionArea,blockDisplacements=False,blockRotations=False,setSpeeds=False,label='strainer'),PyRunner(virtPeriod=1e-6/0.5,realPeriod=1,command='addPlotData()',label='plotDataCollector',initRun=True)] --> Here I want to understand the PyRunner (........) command. Can you describe this.

Next is the plotting of data:

plot.plots={'eps':('sigma')}

def addPlotData():
     ....: yade.plot.addData(t=O.time,i=O.iter,eps=-strainer.strain,sigma=-strainer.avgStress)
     ....: O.step()
--> When I execute the above, it shows "addPlotData" is not defined.

the sim ulation runs and I can see the straining of the sample. Upon pressing F8 to see the plot of sigma against the epsilon (stress-strain) I see nothing (no plots). What am I doing wrong or what changes can I make to execute this task in a better way?

I hope I could make everything clear...

Thanks :)

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

Hello,

> negIds,posIds,axis,crossSectionArea=bb['negIds'],bb['posIds'],bb['axis'],bb['area'] --> this time the command worked unlike the last time when I got an error. Still no idea what the reason might have been

as I wrote and as the error said, the reason was invalid Python syntax, i.e. `´ symbols. ' and " are used for strings, see Python docs for more info

PyRunner [1] is used to run a Python code periodically, in your case executing function plotAddData. You can choose a period of executing the function, chose one:
iterPeriod ... runs the code every given time step
virtPeriod ... runs the code every given virtual time (e.g. every 1 ms)
realPeriod ... runs the code every real period, e.g. every 10 s

> When I execute the above, it shows "addPlotData" is not defined.

How do you run the code? using a script, or copying the code to yade terminal?
anyway, do not call O.step() inside a function you call by PyRunner.

cheers
Jan

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

Revision history for this message
Swapnil (swapspace) said :
#4

Jan, I can now understand the PyRunner better. Thanks :)

However, with the addPlotData(), I still have doubts.

I am typing the code in the yade terminal.

I tried the following:

in first line: def addPlotData():
     ....: yade.plot.addData(t=O.time,i=O.iter,eps=-strainer.strain,sigma=-strainer.avgStress)
     .....

in new line:
O.step()

Upon pressing enter it says:

NameError Traceback (most recent call last)
/usr/bin/yade in <module>()

NameError: name 'addPlotData' is not defined

How do we correct this one in order to execute the process and come up with the desired stress-strain plot?

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

Hello,
writing the code to a script [1] and running it by
yade nameOfTheScript.py
should solve it [2]
Alternatively you can use a (not preferable) workaround with globals() [3] or __builtin__ [4].
cheers
Jan

[1] https://yade-dem.org/doc/tutorial-hands-on.html#starting-yade
[2] https://answers.launchpad.net/yade/+question/293179
[3] https://answers.launchpad.net/yade/+question/239546
[4] https://answers.launchpad.net/yade/+question/260135

Revision history for this message
Swapnil (swapspace) said :
#6

Hi Jan,

I created a script named "script1.py" and pasted the above code there. Saved it in a folder.

Upon typing the command "yade script1.py" in the terminal, it says "Invalid Syntax"

what could be wrong here?

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

well, as the error says, the syntax in the file is invalid :-) the error also specifies the problem position.
please post here the code or put the file to the internet and send here the link.
cheers
Jan

Revision history for this message
Swapnil (swapspace) said :
#8

Here is the script Jan:

from yade import pack,plot
pred=pack.inCylinder((0,0,0),(0,0,0.2),0.05)
sp=pack.randomDensePack(pred,radius=0.008)
O.bodies.append(sp)
bb=uniaxialTestFeatures()
negIds,posIds,crossSectionArea=bb['negIds'],bb['posIds'],bb['axis'],bb['area']
O.dt=0.005*PWaveTimeStep()
O.engines=[ForceResetter(),InsertionSortCollider([Bo1_Sphere_Aabb()]),InteractionLoop([Ig2_Sphere_Sphere_ScGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_ScGeom_FrictPhys_CundallStrack()]),NewtonIntegrator(),UniaxialStrainer(strainRate=-0.00005,axis=axis,asymmetry=0,posIds=posIds,negIds=negIds,crossSectionArea=crossSectionArea,blockDisplacements=False,blockRotations=False,setSpeeds=False,label='strainer'),PyRunner(virtPeriod=1e-6/0.5,realPeriod=1,command='addPlotData()',label='plotDataCollector',initRun=True)]
plot.plots={'eps':('sigma')}

def addPlotData():
yade.plot.addData(t=O.time,i=O.iter,eps=-strainer.strain,sigma=-strainer.avgStress)

O.run(10,True)
-------
saved as file script1.py. I am typing "yade script1.py" in the terminal and I get the following error:

File "<ipython-input-1-0669567f7eda>", line 1
    yade script1.py
               ^
SyntaxError: invalid syntax

---

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

Hello,

read [1]
You can start yade simply by "yade", opening yade prompt and allowing you to type commands
Or you can pass a script name as an command line argument.
so instead of

yade
yade script1.py # this one already inside yade

just run (see [1] for details)

yade script1.py

cheers
Jan

[1] https://yade-dem.org/doc/tutorial-hands-on.html

Revision history for this message
Swapnil (swapspace) said :
#10

Thanks Jan, I did as you instructed. The simulation runs but I see nothing.

Here is the content on the terminal:
---------

zg@ZG-Yade ~ $ yade script1.py
Welcome to Yade 1.20.0
TCP python prompt on localhost:9001, auth cookie `ascedk'
XMLRPC info provider on http://localhost:21001
Running script script1.py
Traceback (most recent call last):
  File "/usr/bin/yade", line 182, in runScript
    execfile(script,globals())
IOError: [Errno 2] No such file or directory: 'script1.py'
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view (use h-key for showing help), F10 both, F9 generator, F8 plot. ]]
[0;34mYade [[1;34m1[0;34m]: [0mERROR /build/yade-KKgSmd/yade-1.20.0/pkg/common/InsertionSortCollider.cpp:244 action: verletDist is set to 0 because no spheres were found. It will result in suboptimal performances, consider setting a positive verletDist in your script.
WARN /build/yade-KKgSmd/yade-1.20.0/pkg/dem/Shop_01.cpp:457 PWaveTimeStep: PWaveTimeStep has not found any suitable spherical body to calculate dt. dt is set to 1.0
-----------------------
Not able to figure out the snag.

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

Hello,
take care of errors:

> IOError: [Errno 2] No such file or directory: 'script1.py'

i.e. the script.py is not in terminals' current directory. Where did you save it?
Jan

Revision history for this message
Swapnil (swapspace) said :
#12

I have a desktop folder "Home"(File manager). In that I created a folder "scriptf" and it is saved therein.

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

Ok, than in terminal you need to change directory (cd) [1]

cd scriptf

and then

yade script1.py

cheers
Jan

[1] https://yade-dem.org/doc/tutorial-hands-on.html

Revision history for this message
Swapnil (swapspace) said :
#14

Thanks Jan, I tried this. As follows:

zg@ZG-Yade ~ $ cd scriptf
zg@ZG-Yade ~/scriptf $ yade script1.py
Welcome to Yade 1.20.0
TCP python prompt on localhost:9001, auth cookie `uskyea'
XMLRPC info provider on http://localhost:21001
Running script script1.py
Traceback (most recent call last):
  File "/usr/bin/yade", line 182, in runScript
    execfile(script,globals())
  File "script1.py", line 12
    yade.plot.addData(t=O.time,i=O.iter,eps=-strainer.strain,sigma=-strainer.avgStress)
       ^
IndentationError: expected an indented block
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view (use h-key for showing help), F10 both, F9 generator, F8 plot. ]]
[0;34mYade [[1;34m1[0;34m]: [0m
-------
I do not see anything in the simulation window as well. What mistake am I making?

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

Hello,
again, just read the errors :-) it says that there is IndentationError at line 12 (yade.plot...) in file "script1.py" and that an indented block is expected.
So just make the line 12 indented (e.g. 2 spaces in the beginning of the line) to get rid of this error.
cheers
Jan

PS: If you are going to use yade seriously, you will need to know Python basics. Yade tutorial scripts and other example scripts could be enough, but consider to read some Python tutorial.
PPS: after fixing this error, you will get a different error ;-)

Revision history for this message
Swapnil (swapspace) said :
#16

Haha, yeah Jan. You are right. Silly me. Got to dive deeper into Python. I now put the indentation and it finally works. Although there is a packing error but I guess that is due to the dimensions I assigned.

I am trying to view the plot by pressing F8 but nothing is happening.

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

Hello,
errors thrown by Python are (usually) relatively easy to read. It also tells you what kind of error it is and where the problematic code is located.
In your case, it has nothing to do with yade packing. "ValueError: too many values to unpack" is a 'typical' Python error, where you try to assign uncompatible number of variables. Try e.g.

a,b,c = 1,2,3
a,b,c = 1,2,3,4

Concerning F8, according to your screenshots, you are experiencing [1], where there is a link to workaround. As you have it now, F keys does not work..
Using a script, you can write
import yade.plot; yade.plot.plot()
which is just what F8 would do

cheers
Jan

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

Revision history for this message
Swapnil (swapspace) said :
#18

I tried adding the following to the original script itself:
import yade.plot
yade.plot.plot()

It does not seem to work.

I tried understanding the workaround as well (https://bugs.launchpad.net/yade/+bug/1604266/comments/11). As suggested here the default popping up of the Qt controller appears to be the problem. But there is not any command in the script for Qt controller. Not sure what to do there.

Anyway, I am not able to get the plot :D

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

Concerning the bug, you need to delete/comment a line in yade executable
to get its name, run 'which yade' to terminal (should be something like /usr/bin/yade)
then do in terminal
sudo gedit /usr/bin/yade
comment the line "if (gui<>'none'): yade.qt.Controller();" and save the file

concerning plot, first you need to define what to plot by
plot.plots = {...}
and also have some data in plot.data (usually filled by plot.addData function). Have a look at [1]
cheers
Jan

PS: if you find a new question is too far away from the original topic (e.g. here plotting, while the original question was uniaxial test), please open a new question

[1] https://yade-dem.org/doc/user.html#plotting-variables

Revision history for this message
Swapnil (swapspace) said :
#20

Jan, if we look at the script above, it is defined there.
----
plot.plots={'eps':('sigma')}
def addPlotData():
  yade.plot.addData(t=O.time,i=O.iter,eps=-strainer.strain,sigma=-strainer.avgStress)
------
Do I need to add something else?

PS: Sorry, should have posted this question separately but I guess Iĺl soon have a similar one in a new task ;-)

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

it should be enough
Jan

Revision history for this message
Swapnil (swapspace) said :
#22

Yeah, but it does not work.

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

Always specify your problem, what it does, what you expect it should do and does not etc. "it does not work" has no informative value. Furthermore, with a specific problem, please post the code (ideally MWE [1]) you use.

if you put at the and of the script
plot.plot()
does it what you expect?

cheers
Jan

[1] https://yade-dem.org/wiki/Howtoask

Revision history for this message
Swapnil (swapspace) said :
#24

Thanks Jan, the script works with plot.plot() :-)

Can you help with this problem?

Provide an answer of your own, or ask Swapnil for more information if necessary.

To post a message you must log in.