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
Yade [3]: math.sqrt(2) # use a function from that module
Out[3]: 1.4142135623730951
Yade [4]: import math as m # use the module under a different name
Yade [5]: m.cos(m.pi)
Out[5]: -1.0
Yade [6]: from math import * # import everything so that it can be used without module name
Yade [7]: cos(pi)
Out[7]: -1.0
Variables:
Yade [8]: a=1; b,c=2,3 # multiple commands separated with ;, multiple assignment
Yade [9]: a+b+c
Out[9]: 6
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
Yade [11]: a[0] # first element has index 0
Out[11]: 1
Yade [12]: a[-1] # negative counts from the end