Hands-on¶
Shell basics¶
Directory tree¶
Directory tree is hierarchical way to organize files in operating systems. A typical (reduced) tree in linux looks like this:
/ Root
├──boot System startup
├──bin Low-level programs
├──lib Low-level libraries
├──dev Hardware access
├──sbin Administration programs
├──proc System information
├──var Files modified by system services
├──root Root (administrator) home directory
├──etc Configuration files
├──media External drives
├──tmp Temporary files
├──usr Everything for normal operation (usr = UNIX system resources)
│ ├──bin User programs
│ ├──sbin Administration programs
│ ├──include Header files for c/c++
│ ├──lib Libraries
│ ├──local Locally installed software
│ └──doc Documentation
└──home Contains the user's home directories
├──user Home directory for user
└──user1 Home directory for user1
Note that there is a single root /
; all other disks (such as USB sticks) attach to some point in the tree (e.g. in /media
).
Starting yade¶
If yade is installed on the machine, it can be (roughly speaking) run as any other program; without any arguments, it runs in the “dialog mode”, where a command-line is presented:
user@machine:~$ yade
Welcome to Yade 2019.01a
TCP python prompt on localhost:9002, auth cookie `adcusk'
XMLRPC info provider on http://localhost:21002
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view, F10 both, F9 generator, F8 plot. ]]
Yade [1]: #### hit ^D to exit
Do you really want to exit ([y]/n)?
Yade: normal exit.
The command-line is in fact python
, enriched with some yade-specific features. (Pure python interpreter can be run with python
or ipython
commands).
Instead of typing commands on-by-one on the command line, they can be be written in a file (with the .py extension) and given as argument to Yade:
user@machine:~$ yade simulation.py
For a complete help, see man yade
Exercises
- Open the terminal, navigate to your home directory
- Create a new empty file and save it in
~/first.py
- Change directory to
/tmp
; delete the file~/first.py
- Run program
xeyes
- Look at the help of Yade.
- Look at the manual page of Yade
- Run Yade, exit and run it again.
Python basics¶
We assume the reader is familar with Python tutorial and only briefly review some of the basic capabilities. The following will run in pure-python interpreter (python
or ipython
), but also inside Yade, which is a super-set of Python.
Numerical operations and modules:
Yade [1]: (1+3*4)**2 # usual rules for operator precedence, ** is exponentiation Out[1]: 169 Yade [2]: import math # gain access to "module" of functions --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [3]: math.sqrt(2) # use a function from that module --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-3-2df21407a367> in <module>() ----> 1 math.sqrt(2) # use a function from that module NameError: name 'math' is not defined Yade [4]: import math as m # use the module under a different name --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [5]: m.cos(m.pi) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-5-14c4d6f16c07> in <module>() ----> 1 m.cos(m.pi) NameError: name 'm' is not defined Yade [6]: from math import * # import everything so that it can be used without module name --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [7]: cos(pi) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-7-a971a9dfc2c9> in <module>() ----> 1 cos(pi) NameError: name 'cos' is not defined
Variables:
Yade [8]: a=1; b,c=2,3 # multiple commands separated with ;, multiple assignment --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [9]: a+b+c --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-ce778f4f86b8> in <module>() ----> 1 a+b+c NameError: name 'a' is not defined
Sequences¶
Lists¶
Lists are variable-length sequences, which can be modified; they are written with braces [...]
, and their elements are accessed with numerical indices:
Yade [10]: a=[1,2,3] # list of numbers --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [11]: a[0] # first element has index 0 --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-11-80b78b5dce4b> in <module>() ----> 1 a[0] # first element has index 0 NameError: name 'a' is not defined Yade [12]: a[-1] # negative counts from the end --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-12-ac777dcadb50> in <module>() ----> 1 a[-1] # negative counts from the end NameError: name 'a' is not defined Yade [13]: a[3] # error --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-13-fbb6c185e4c3> in <module>() ----> 1 a[3] # error NameError: name 'a' is not defined Yade [14]: len(a) # number of elements --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-14-7baf271bbd30> in <module>() ----> 1 len(a) # number of elements NameError: name 'a' is not defined Yade [15]: a[1:] # from second element to the end --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-15-b735c2bc32f5> in <module>() ----> 1 a[1:] # from second element to the end NameError: name 'a' is not defined Yade [16]: a+=[4,5] # extend the list --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [17]: a+=[6]; a.append(7) # extend with single value, both have the same effect --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [18]: 9 in a # test presence of an element --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-18-136c2e44fc80> in <module>() ----> 1 9 in a # test presence of an element NameError: name 'a' is not defined
Lists can be created in various ways:
Yade [19]: range(10) Out[19]: range(0, 10) Yade [20]: range(10)[-1] Out[20]: 9
List of squares of even number smaller than 20, i.e. \(\left\{a^2\;\forall a\in \{0,\cdots,19\} \;\middle|\; 2 \| a\right\}\) (note the similarity):
Yade [21]: [a**2 for a in range(20) if a%2==0]
Out[21]: [0, 4, 16, 36, 64, 100, 144, 196, 256, 324]
Tuples¶
Tuples are constant sequences:
Yade [22]: b=(1,2,3) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [23]: b[0] --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-23-54af0eb47770> in <module>() ----> 1 b[0] NameError: name 'b' is not defined Yade [24]: b[0]=4 # error --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module
Dictionaries¶
Mapping from keys to values:
Yade [25]: ende={'one':'ein' , 'two':'zwei' , 'three':'drei'} --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [26]: de={1:'ein' , 2:'zwei' , 3:'drei'}; en={1:'one' , 2:'two' , 3:'three'} --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [27]: ende['one'] ## access values --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-27-f15db300064b> in <module>() ----> 1 ende['one'] ## access values NameError: name 'ende' is not defined Yade [28]: de[1], en[2] --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-28-63a7b204c051> in <module>() ----> 1 de[1], en[2] NameError: name 'de' is not defined
Functions, conditionals¶
Yade [29]: 4==5 Out[29]: False Yade [30]: a=3.1 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [31]: if a<10: ....: b=-2 # conditional statement ....: else: ....: b=3 ....: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [32]: c=0 if a<1 else 1 # trenary conditional expression --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [33]: b,c --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-33-6d26c4665011> in <module>() ----> 1 b,c NameError: name 'b' is not defined Yade [34]: def square(x): return x**2 # define a new function ....: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [35]: square(2) # and call that function --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-35-71ff7dc6a0ab> in <module>() ----> 1 square(2) # and call that function NameError: name 'square' is not defined
Exercises
Read the following code and say what wil be the values of
a
andb
:a=range(5) b=[(aa**2 if aa%2==0 else -aa**2) for aa in a]
Yade basics¶
Yade objects are constructed in the following manner (this process is also called “instantiation”, since we create concrete instances of abstract classes: one individual sphere is an instance of the abstract Sphere, like Socrates is an instance of “man”):
Yade [36]: Sphere # try also Sphere? --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-36-406ed7fe2682> in <module>() ----> 1 Sphere # try also Sphere? NameError: name 'Sphere' is not defined Yade [37]: s=Sphere() # create a Sphere, without specifying any attributes --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [38]: s.radius # 'nan' is a special value meaning "not a number" (i.e. not defined) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-38-a84b252d48ac> in <module>() ----> 1 s.radius # 'nan' is a special value meaning "not a number" (i.e. not defined) NameError: name 's' is not defined Yade [39]: s.radius=2 # set radius of an existing object --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [40]: s.radius --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-40-b0184777f7f7> in <module>() ----> 1 s.radius NameError: name 's' is not defined Yade [41]: ss=Sphere(radius=3) # create Sphere, giving radius directly --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [42]: s.radius, ss.radius # also try typing s.<tab> to see defined attributes --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-42-9b548a74d27f> in <module>() ----> 1 s.radius, ss.radius # also try typing s.<tab> to see defined attributes NameError: name 's' is not defined
Particles¶
Particles are the “data” component of simulation; they are the objects that will undergo some processes, though do not define those processes yet.
Singles¶
There is a number of pre-defined functions to create particles of certain type; in order to create a sphere, one has to (see the source of utils.sphere for instance):
- Create Body
- Set Body.shape to be an instance of Sphere with some given radius
- Set Body.material (last-defined material is used, otherwise a default material is created)
- Set position and orientation in Body.state, compute mass and moment of inertia based on Material and Shape
In order to avoid such tasks, shorthand functions are defined in the utils module; to mention a few of them, they are utils.sphere, utils.facet, utils.wall.
Yade [43]: s=utils.sphere((0,0,0),radius=1) # create sphere particle centered at (0,0,0) with radius=1 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [44]: s.shape # s.shape describes the geometry of the particle --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-44-104ff9880aca> in <module>() ----> 1 s.shape # s.shape describes the geometry of the particle NameError: name 's' is not defined Yade [45]: s.shape.radius # we already know the Sphere class --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-45-0ce9c4a05591> in <module>() ----> 1 s.shape.radius # we already know the Sphere class NameError: name 's' is not defined Yade [46]: s.state.mass, s.state.inertia # inertia is computed from density and geometry --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-46-769bda160c16> in <module>() ----> 1 s.state.mass, s.state.inertia # inertia is computed from density and geometry NameError: name 's' is not defined Yade [47]: s.state.pos # position is the one we prescribed --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-47-255b0133f234> in <module>() ----> 1 s.state.pos # position is the one we prescribed NameError: name 's' is not defined Yade [48]: s2=utils.sphere((-2,0,0),radius=1,fixed=True) # explanation below --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module
In the last example, the particle was fixed in space by the fixed=True
parameter to utils.sphere; such a particle will not move, creating a primitive boundary condition.
A particle object is not yet part of the simulation; in order to do so, a special function O.bodies.append (also see Omega::bodies and Scene) is called:
Yade [49]: O.bodies.append(s) # adds particle s to the simulation; returns id of the particle(s) added
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-49-a6b941d5e765> in <module>()
----> 1 O.bodies.append(s) # adds particle s to the simulation; returns id of the particle(s) added
NameError: name 's' is not defined
Packs¶
There are functions to generate a specific arrangement of particles in the pack module; for instance, cloud (random loose packing) of spheres can be generated with the pack.SpherePack class:
Yade [50]: from yade import pack --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [51]: sp=pack.SpherePack() # create an empty cloud; SpherePack contains only geometrical information --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [52]: sp.makeCloud((1,1,1),(2,2,2),rMean=.2) # put spheres with defined radius inside box given by corners (1,1,1) and (2,2,2) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-52-24fd91cde142> in <module>() ----> 1 sp.makeCloud((1,1,1),(2,2,2),rMean=.2) # put spheres with defined radius inside box given by corners (1,1,1) and (2,2,2) NameError: name 'sp' is not defined Yade [53]: for c,r in sp: print(c,r) # print center and radius of all particles (SpherePack is a sequence which can be iterated over) ....: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [54]: sp.toSimulation() # create particles and add them to the simulation --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-54-5bd4db1bc17d> in <module>() ----> 1 sp.toSimulation() # create particles and add them to the simulation NameError: name 'sp' is not defined
Boundaries¶
utils.facet (triangle Facet) and utils.wall (infinite axes-aligned plane Wall) geometries are typically used to define boundaries. For instance, a “floor” for the simulation can be created like this:
Yade [55]: O.bodies.append(utils.wall(-1,axis=2))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-55-0fefbfba03d8> in <module>()
----> 1 O.bodies.append(utils.wall(-1,axis=2))
NameError: name 'utils' is not defined
There are other conveinence functions (like utils.facetBox for creating closed or open rectangular box, or family of ymport functions)
Look inside¶
The simulation can be inspected in several ways. All data can be accessed from python directly:
Yade [56]: len(O.bodies) Out[56]: 0 Yade [57]: O.bodies[10].shape.radius # radius of body #10 (will give error if not sphere, since only spheres have radius defined) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-57-1be8745d9b66> in <module>() ----> 1 O.bodies[10].shape.radius # radius of body #10 (will give error if not sphere, since only spheres have radius defined) IndexError: Body id out of range. Yade [58]: O.bodies[12].state.pos # position of body #12 --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-58-4bda6cc74763> in <module>() ----> 1 O.bodies[12].state.pos # position of body #12 IndexError: Body id out of range.
Besides that, Yade says this at startup (the line preceding the command-line):
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view, F10 both, F9 generator, F8 plot. ]]
- Controller
- Pressing
F12
brings up a window for controlling the simulation. Although typically no human intervention is done in large simulations (which run “headless”, without any graphical interaction), it can be handy in small examples. There are basic information on the simulation (will be used later). - 3d view
- The 3d view can be opened with F11 (or by clicking on button in the Controller – see below). There is a number of keyboard shortcuts to manipulate it (press
h
to get basic help), and it can be moved, rotated and zoomed using mouse. Display-related settings can be set in the “Display” tab of the controller (such as whether particles are drawn). - Inspector
- Inspector is opened by clicking on the appropriate button in the Controller. It shows (and updates) internal data of the current simulation. In particular, one can have a look at engines, particles (Bodies) and interactions (Interactions). Clicking at each of the attribute names links to the appropriate section in the documentation.
Exercises
What is this code going to do?
Yade [59]: O.bodies.append([utils.sphere((2*i,0,0),1) for i in range(1,20)]) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-59-db9855b362b2> in <module>() ----> 1 O.bodies.append([utils.sphere((2*i,0,0),1) for i in range(1,20)]) <ipython-input-59-db9855b362b2> in <listcomp>(.0) ----> 1 O.bodies.append([utils.sphere((2*i,0,0),1) for i in range(1,20)]) NameError: name 'utils' is not defined
Create a simple simulation with cloud of spheres enclosed in the box
(0,0,0)
and(1,1,1)
with mean radius .1. (hint: pack.SpherePack.makeCloud)Enclose the cloud created above in box with corners
(0,0,0)
and(1,1,1)
; keep the top of the box open. (hint: utils.facetBox; typeutils.facetBox?
orutils.facetBox??
to get help on the command line)Open the 3D view, try zooming in/out; position axes so that \(z\) is upwards, \(y\) goes to the right and \(x\) towards you.
Engines¶
Engines define processes undertaken by particles. As we know from the theoretical introduction, the sequence of engines is called simulation loop. Let us define a simple interaction loop:
Yade [60]: O.engines=[ # newlines and indentations are not important until the brace is closed ....: ForceResetter(), ....: InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Wall_Aabb()]), ....: InteractionLoop( # dtto for the parenthesis here ....: [Ig2_Sphere_Sphere_ScGeom(),Ig2_Wall_Sphere_ScGeom()], ....: [Ip2_FrictMat_FrictMat_FrictPhys()], ....: [Law2_ScGeom_FrictPhys_CundallStrack()] ....: ), ....: NewtonIntegrator(damping=.2,label='newtonCustomLabel') # define a label newtonCustomLabel under which we can access this engine easily ....: ] ....: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [61]: O.engines Out[61]: [] Yade [62]: O.engines[-1]==newtonCustomLabel # is it the same object? --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-62-fe0482e87a80> in <module>() ----> 1 O.engines[-1]==newtonCustomLabel # is it the same object? IndexError: list index out of range Yade [63]: newtonCustomLabel.damping --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-63-0dbcb17339e8> in <module>() ----> 1 newtonCustomLabel.damping NameError: name 'newtonCustomLabel' is not defined
Instead of typing everything into the command-line, one can describe simulation in a file (script) and then run yade with that file as an argument. We will therefore no longer show the command-line unless necessary; instead, only the script part will be shown. Like this:
O.engines=[ # newlines and indentations are not important until the brace is closed
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Wall_Aabb()]),
InteractionLoop( # dtto for the parenthesis here
[Ig2_Sphere_Sphere_ScGeom(),Ig2_Wall_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_ScGeom_FrictPhys_CundallStrack()]
),
GravityEngine(gravity=(0,0,-9.81)), # 9.81 is the gravity acceleration, and we say that
NewtonIntegrator(damping=.2,label='newtonCustomLabel') # define a label under which we can access this engine easily
]
Besides engines being run, it is likewise important to define how often they will run. Some engines can run only sometimes (we will see this later), while most of them will run always; the time between two successive runs of engines is timestep (\(\Dt\)). There is a mathematical limit on the timestep value, called critical timestep, which is computed from properties of particles. Since there is a function for that, we can just set timestep using utils.PWaveTimeStep:
O.dt=utils.PWaveTimeStep()
Each time when the simulation loop finishes, time O.time
is advanced by the timestep O.dt
:
Yade [64]: O.dt=0.01 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /usr/lib/python3.8/codeop.py in __call__(self, source, filename, symbol) 134 135 def __call__(self, source, filename, symbol): --> 136 codeob = compile(source, filename, symbol, self.flags, 1) 137 for feature in _features: 138 if codeob.co_flags & feature.compiler_flag: TypeError: required field "type_ignores" missing from Module Yade [65]: O.time Out[65]: 0.0 Yade [66]: O.step() Yade [67]: O.time Out[67]: 1e-08
For experimenting with a single simulations, it is handy to save it to memory; this can be achieved, once everything is defined, with:
O.saveTmp()
Exercises
- Define engines as in the above example, run the Inspector and click through the engines to see their sequence.
- Write a simple script which will
- define particles as in the previous exercise (cloud of spheres inside a box open from the top)
- define a simple simulation loop, as the one given above
- set \(\Dt\) equal to the critical P-Wave \(\Dt\)
- save the initial simulation state to memory
- Run the previously-defined simulation multiple times, while changing the value of timestep (use the ⟳ button to reload the initial configuration).
- Reload the simulation, open the 3d view, open the Inspector, select a particle in the 3d view (shift-click). Then run the simulation and watch how forces on that particle change; pause the simulation somewhere in the middle, look at interactions of this particle.
- At which point can we say that the deposition is done, so that the simulation can be stopped?
See also
The Bouncing sphere example shows a basic simulation.