SudoDEM: Guide for Non-Spherical DEM
SudoDEM: Guide for Non-Spherical DEM
2
Contents
1 Introduction 5
1.1 Why SudoDEM . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Disclaimers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Requirements 7
2.1 Basic Linux Commands . . . . . . . . . . . . . . . . . . . . . 7
2.2 Python 2.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Package Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.1 Binary Installation . . . . . . . . . . . . . . . . . . . . 9
2.3.2 Non-root Compilation . . . . . . . . . . . . . . . . . . 10
3 Examples 17
3.1 Example 0: run a simulation . . . . . . . . . . . . . . . . . . . 17
3.2 Example 1: packing of super-ellipsoids . . . . . . . . . . . . . 20
3.3 Example 2: triaxial tests of super-ellipsoids . . . . . . . . . . . 28
3.4 Example 3: packing of GJKparticles . . . . . . . . . . . . . . 38
3.5 Example 4: packing of poly-superellipsoids . . . . . . . . . . . 46
3.6 Example 5: packing of superellipses . . . . . . . . . . . . . . . 50
4 Post-processing 55
4.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.2 Scene Visualization . . . . . . . . . . . . . . . . . . . . . . . . 56
4.2.1 SudoDEM3D . . . . . . . . . . . . . . . . . . . . . . . 56
4.2.2 SudoDEM2D . . . . . . . . . . . . . . . . . . . . . . . 60
3
CONTENTS A Quick Guide to SudoDEM
4
Chapter 1
Introduction
A sound name is the beginning to get things started. The word SudoDEM is
coined as a combination of ‘sudo’ and ‘DEM’. The prefix ‘sudo’ is a program
for Unix-like computer operating systems that allows users to run programs
as the superuser, i.e., ‘super user do’, which here means a powerful and flex-
ible DEM simulator. On the other hand, the pronunciation of ‘sudo’ sounds
like ‘pseudo’, implying that SudoDEM does and will consist of features dis-
tinguishing from the conventional DEM codes.
SudoDEM is specifically designed for modeling non-spherical particles us-
ing discrete element method (DEM), which inherits a basic framework of an
open-source DEM code, YADE1 . A profound modification was performed on
YADE for higher efficiency in modeling non-spherical particles. The project
is hosted on ResearchGate with a goal of developing a robust 2/3D DEM
code for convex particles, e.g., super-ellipsoids, poly-superellipsoids, cylin-
ders, cones, polyhedrons. In SudoDEM, some general optimization algo-
rithms e.g., Levenberg-Marquardt and Nelder-Mead simplex are adopted for
contact detection of superquadric particles. The popular Gilbert-Johnson-
Keerthi (GJK) algorithm used in computer graphic simulation is employed
for convex and non-convex (under construction) polytopes.
The project of SudoDEM is hosted on an individual website, and the
synchronous update can be also found on the Researchgate Page.
1
[Link]
5
CHAPTER 1. INTRODUCTION A Quick Guide to SudoDEM
(4) Zhao S., Zhang N., Zhou X., Zhang L. (2017). Particle shape effects on
fabric of granular random packing. Powder technology, 310, 175–186.
1.3 Disclaimers
BECAUSE THE CODE IS FREE OF CHARGE, THERE IS NO WAR-
RANTY ‘AS IS’; NOT EVEN FOR MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE.
6
Chapter 2
Requirements
• sudo apt-get install package 1 install a package to the system with root
permission.
7
CHAPTER 2. REQUIREMENTS A Quick Guide to SudoDEM
8
A Quick Guide to SudoDEM CHAPTER 2. REQUIREMENTS
26 d = d i c t ( ) # an empty d i c t
27 #t e s t e x p r e s s i o n
28 i f 1 >2:
29 p r i n t " 1 i s g r e a t e r than 2 , r e a l l y ? "
30 else :
31 i f 2 in [ 1 , 2 , 3 ] : # i f 2 i s in the l i s t [ 1 , 2 , 3 ]
32 #ok , l e t ' s s t a r t a f o r l o o p
33 f o r i in range (5) : # equal to f o r i in [ 0 , 1 , 2 , 3 , 4 ]
34 p r i n t i # you can s e e what ' s g o i n g on i n t h e f o r l o o p
35 # we append some data t o a l i s t c and a d i c t d
36 c . append ( math . c o s ( i ) ∗10 + 2 . 0 ∗ ∗ 5 ) # we append t h e v a l u e o f
10∗ c o s ( i ) + 2 . 0 ^ 5 t o t h e l i s t c . We u s e t h e math f u n c t i o n c o s
from t h e module math .
37 i f i not i n d . k e y s ( ) : # i f i i s not a key o r i n d e x o f t h e
dict d.
38 d[ i ] = str ( i )
39
40 #we can c a p s u l e our commands by a f u n c t i o n
41 d e f GoodJob ( input_number , keyword1 = 1 , keyword2 = True ) :
42 i f keyword2 : # t h a t i s i f keyword2 == True
43 p r i n t " t h e i n p u t number i s " , i n p u t
44 input_number += keyword1 # i . e . , t h e v a l u e o f input_number i s
updated t o input_number + keyword1
45 r e t u r n input_number # we can r e t u r n t h e v a l u e
46
47 # c a l l the f u n c t i o n
48 a = GoodJob ( 2 ) # a = 3 , with p r i n t i n f o ' t h e i n p u t number i s 3 '
49 b = GoodJob ( 3 , keyword1 = 5 , keyword2 = F a l s e ) # b = 8 , w i t h o u t
print info .
Ok, that is all you need to know prior to running a simulation. There are also
other further techniques you might be interested in, e.g., how to open/read-
/write/close a file, and how to write a Python script with the object-oriented
programming, which will be roughly introduced in the examples of this tu-
torial.
9
CHAPTER 2. REQUIREMENTS A Quick Guide to SudoDEM
Download the compiled package from the download page and unzip it to
anywhere (e.g., /home/xxx/). If you just get a package of the main program
which does not include the third-party libraries, then you need to download
the package "[Link]" for the third-party libraries and extract it into
the subfolder "lib". After that, make sure you get the following structure of
folders:
/home/xxx/SudoDEM/
bin/
sudodem3d
lib/
3rdlibs/
sudodem/
share/
Step 2: Set the environmental variable PATH
Append the path of the executable sudodem3d, i.e., ‘/home/xxx/Sudo-
DEM/bin’ to the environmental variable PATH by adding the following line
to the config file ‘/home/xxx/.bashrc’:
1 PATH=${PATH}:/home/xxx/SudoDEM/bin
INSTALL
LICENSE
[Link]
You may add subfolders, e.g.,‘3rdlib’, ‘build2d’, ‘build3d’, and ‘sudo-
deminstall’, inside the parent folder ‘SudoDEM’. Thus, the directory tree
10
A Quick Guide to SudoDEM CHAPTER 2. REQUIREMENTS
looks like
/home/xxx/SudoDEM
SudoDEM2D
SudoDEM3D
3rdlib
build2d
build3d
sudodeminstall
scripts
INSTALL
LICENSE
[Link]
The subfolder ‘3rdlib’ is for the third-party libraries. Note that the sub-
folder ‘3rdlib’ hosts the header files and the compiled dynamic libraries, while
for launching SudoDEM you need to copy all dynamic libraries ‘*.so.*’ files
into the install directory, e.g., ‘lib/3rdlibs/’. The compilation of the 2D and
3D versions will be done within the subfolders ‘build2d’ and ‘build3d’, re-
spectively. The compiled outputs (binary and library) will be installed in the
subfolder ‘sudodeminstall’.
/home/xxx/SudoDEM/3rdlib
boost-1_6_7
eigen3.3.5
libQGLViewer-2.6.3
minieigen
Four major libraries:
• Boost-1.67
Download the source from its official page ([Link]
users/history/version_1_67_0.html) or the github repo (https:
//[Link]/SwaySZ/boost-1_6_7).
11
CHAPTER 2. REQUIREMENTS A Quick Guide to SudoDEM
1 cd boost−1\_6\_7
2 ./[Link] −−prefix=$PWD/../boost167 −−with−
libraries=python,thread,filesystem,iostreams,regex,
serialization,system,date_time link=shared runtime−link=
shared −−without−icu
3 ./b2 −j3
4 ./b2 install
• MiniEigen
Download the source from the repo ([Link]
minieigen). Set the directory of your compiled boost in the file ‘CMake-
[Link]’:
1 s e t (BOOST_ROOT "/home/ swayzhao / s o f t w a r e /DEM/3 r d l i b / b o o s t 1 6 7
")
Then,
1 mkdir build
2 cd build
3 cmake ../
4 make
After compilation, you will get the shared library ‘[Link]’. Copy
it to the folder ‘lib/3rdlibs/py’.
• LibQGLViewer-2.6.3
Download the source from the repo ([Link]
libQGLViewer-2.6.3)
1 cd QGLViewer
2 qmake
3 make
• biuld-essential, cmake
• freeglut3-dev
12
A Quick Guide to SudoDEM CHAPTER 2. REQUIREMENTS
• zlib1g-dev (boost)
• python-dev (boost)
• pyqt4-dev-tools
• qt4-default
• python-numpy python-tk
• libbz2-dev
• python-xlib python-qt4
• ipython3.0 python-matplotlib
• libxi-dev
• libglib2.0-dev
• libxmu-dev
lib
pkg
py
Prior to compiling, you may need to edit the file ‘[Link]’, in
which you may change the installation directory, paths of library header
files, etc.
(a) The installation path is set by
13
CHAPTER 2. REQUIREMENTS A Quick Guide to SudoDEM
(c) For the QGLViewer, the paths for both header files and library are set
by the following two lines:
(d) Copy your system-installed numpy and pyqt4 to the path ’./lib/3rdlibs/py’.
You may also change the search path of numpy in the file [Link]
under the folder ‘cMake’:
1 cd build3d
2 cmake ../SudoDEM3D
3 make −j3
4 make install
1 PATH=${PATH}:/home/xxx/SudoDEM/sudodeminstall/
SudoDEM3D/bin
You are expected to get the following directory tree after installation:
14
A Quick Guide to SudoDEM CHAPTER 2. REQUIREMENTS
/home/xxx/SudoDEM/sudodeminstall
bin
lib
3rdlibs
*.so
py
[Link]
numpy
PyQt4
sudodem
share
Note: the installation procedure of SudoDEM will overwrite the above
directories except ‘3rdlibs’. You need to copy all the 3rd-party libraries com-
piled above (boost, libQGLViewer, minieigen) to ‘3rdlibs’. If you encounter
any problems about the 3rd-libraries, you may check the directory tree for
the binary package of SudoDEM.
IMPORTANT: Add rpath to all 3rd-party libraries under ‘3rdlibs’ by
executing the script ‘[Link]’ in the folder ‘scripts’.
1 cd 3rdlibs
2 cp /home/xxx/SudoDEM/scripts/[Link] .
3 chmod +x [Link]
4 ./[Link]
15
CHAPTER 2. REQUIREMENTS A Quick Guide to SudoDEM
16
Chapter 3
Examples
17
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
13 O. m a t e r i a l s . append ( wallmat1 )
14 # adding a m a t e r i a l t o t h e c o n t a i n e r ( m a t e r i a l s ) s o t h a t we can
e a s i l y a c c e s s i t by i t s l a b e l . See t h e d e f i n i t i o n o f a w a l l
below .
15
16 #c r e a t e a s p h e r i c a l p a r t i c l e
17 sp = s p h e r e ( ( 0 , 0 , 1 0 . 0 ) , 1 . 0 , m a t e r i a l = mat )
18 O. b o d i e s . append ( sp )
19 # c r e a t e t h e ground a s an i n f i n i t e p l a n e w a l l
20 ground = u t i l s . w a l l ( 0 , a x i s =2, s e n s e =1, m a t e r i a l = ' wallmat1 ' ) #
u t i l s . w a l l d e f i n e s a w a l l with normal p a r a l l e l t o one a x i s o f
t h e g l o b a l C a r t e s i a n c o o r d i n a t e system . The f i r s t argument (
h e r e = 0 ) s p e c i f i e s t h e l o c a t i o n o f t h e w a l l , and with t h e
keyword a x i s ( h e r e = 2 , a x i s has a v a l u e o f 0 , 1 , 2 f o r x , y ,
z a x i e s r e s p e c t i v e l y ) we know t h a t t h e normal o f t h e w a l l i s
a l o n g z a x i s with c e n t e r i n g a t z = 0 ( 0 , s p e c i f i e d by t h e
f i r s t argument ) ; t h e s e c o n d keyword s e n s e ( h e r e = 1 , s e n s e
can be −1, 0 , 1 f o r n e g a t i v e , both , and p o s i t i v e s i d e s
r e s p e c t i v e l y ) s p e c i f i e s that the p o s i t i v e s i d e ( i . e . , the
normal p o i n t s t o t h e p o s i t i v e d i r e c t i o n o f t h e a x i s ) o f t h e
w a l l i s a c t i v a t e d , a t which we w i l l compute t h e i n t e r a c t i o n
o f a p a r t i c l e and t h i s w a l l ; t h e l a s t keyword m a t e r i a l s
s p e c i f i e s a m a t e r i a l t o t h i s w a l l , and we a s s i g n a s t r i n g ( i .
e . , t h e l a b e l o f wallmat1 ) t o t h e keyword , and d i r e c t l y
a s s i g n i n g t h e o b j e c t o f t h e m a t e r i a l ( i . e . , wallmat1 r e t u r n e d
by RolFrictMat ) i s a l s o a c c e p t a b l e .
21 O. b o d i e s . append ( ground ) # add t h e ground t o t h e body c o n t a i n e r
22
23
24 # d e f i n e a f u n c t i o n i n v o k e d p e r i o d i c a l l y by a PyRunner
25 d e f record_data ( ) :
26 #open a f i l e
27 f o u t = open ( ' data . dat ' , ' a ' ) #c r e a t e / open a f i l e named ' data .
dat ' i n append mode
28 #we want t o r e c o r d t h e p o s i t i o n o f t h e s p h e r e
29 p = O. b o d i e s [ 0 ] # t h e s p h e r e has been appended i n t o t h e l i s t
O. b o d i e s , and we can u s e t h e c o r r e s p o n d i n g i n d e x t o a c c e s s i t
. We have added two b o d i e s i n t o t a l t o O. b o d i e s , and t h e
s p h e r e i s t h e f i r s t one , i . e . , t h e i n d e x i s 0 .
30 # p i s the o b j e c t of the sphere
31 # a s a body o b j e c t , p has s e v e r a l p r o p e r t i e s , e . g . , s t a t e ,
m a t e r i a l , which can be l i s t e d by p . d i c t ( ) i n t h e commandline .
32 pos = p . s t a t e . pos # g e t t h e p o s i t i o n o f t h e s p h e r e
33 p r i n t >>f o u t , O. i t e r , pos [ 0 ] , pos [ 1 ] , pos [ 2 ] # we p r i n t t h e
i t e r a t i o n number and t h e p o s i t i o n ( x , y , z ) i n t o t h e f i l e f o u t .
34 # then , c l o s e t h e f i l e and r e l e a s e r e s o u r c e
35 fout . close ()
36
37 # c r e a t e a Newton e n g i n e by which t h e p a r t i c l e s move under Newton
18
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
' s Law
38 newton=N e w t o n I n t e g r a t o r ( damping = 0 . 1 , g r a v i t y = ( 0 . , 0 . 0 , − 9 . 8 ) , l a b e l
=" newton " )
39 # we s e t a l o c a l damping o f 0 . 1 and g r a v i t a t i o n a l a c c e l e r a t i o n
−9.8 m/ s 2 a l o n g z a x i s .
40
41 # the engine c o n t a i n e r i s the k e r n e l part of a simulation
42 # During each time s t e p , each e n g i n e w i l l run one by one f o r
c o m p l e t i n g a DEM c y c l e .
43 O. e n g i n e s =[
44 F o r c e R e s e t t e r ( ) , # f i r s t , we need t o r e s e t t h e f o r c e c o n t a i n e r
t o s t o r e upcoming c o n t a c t f o r c e s
45 # next , we conduct t h e broad phase o f c o n t a c t d e t e c t i o n by
comparing a x i s −a l i g n e d bounding boxs (AABBs) t o r u l e out
t h o s e p a i r s t h a t a r e d e f i n i t e l y not c o n t a c t i n g .
46 I n s e r t i o n S o r t C o l l i d e r ( [ Bo1_Sphere_Aabb ( ) , Bo1_Wall_Aabb ( ) ] ,
v e r l e t D i s t =0.2∗0.01) ,
47 # then , we e x e c u t e t h e narrow phase o f c o n t a c t d e t e c t i o n
48 I n t e r a c t i o n L o o p ( # we w i l l l o o p a l l p o t e n t i a l l y c o n t a c t i n g
pairs of p a r t i c l e s
49 [ Ig2_Sphere_Sphere_ScGeom ( ) , Ig2_Wall_Sphere_ScGeom ( ) ] , # f o r
d i f f e r e n t p a r t i c l e shapes , we w i l l c a l l t h e c o r r e s p o n d i n g
f u n c t i o n s t o compute t h e c o n t a c t geometry , f o r example ,
Ig2_Sphere_Sphere_ScGeom ( ) i s used t o compute t h e c o n t a c t
geometry o f a s p h e r e −s p h e r e p a i r .
50 [ Ip2_RolFrictMat_RolFrictMat_RolFrictPhys ( ) ] , # we w i l l
compute t h e p h y s i c a l p r o p e r t i e s o f c o n t a c t , e . g . , c o n t a c t
s t i f f n e s s and c o e f f i c i e n t o f f r i c t i o n , a c c o r d i n g t o t h e
physical properties of contacting p a r t i c l e s .
51 [ R o l l i n g R e s i s t a n c e L a w ( u s e _ r o l l i n g _ r e s i s t a n c e=F a l s e ) ] # Next
, we compute c o n t a c t f o r c e s i n terms o f t h e c o n t a c t law with
t h e i n f o ( c o n t a c t g e o m e t r i c and p h y s i c a l p r o p e r t i e s ) computed
a t l a s t two s t e p s .
52 ),
53 newton , # f i n a l l y , we compute a c c e l e r a t i o n and v e l o c i t y o f
each p a r t i c l e and update t h e i r p o s i t i o n s .
54 #a t each time s t e p , we have a PyRunner f u n c t i o n h e l p t o hack
i n t o a DEM c y c l e and do whatever you want , e . g . , c h a n g i n g
p a r t i c l e s ' s t a t e s , and s a v i n g some data , o r j u s t s t o p p i n g t h e
program a f t e r a c e r t a i n r u n n i n g time .
55 PyRunner ( command= ' record_data ( ) ' , i t e r P e r i o d =10000 , l a b e l= '
r e c o r d ' , dead = F a l s e )
56 ]
57
58 # we need t o s e t a time s t e p
59 O. dt = 1 e−5
60
61 # c l e a n t h e f i l e data . dat and w r i t e a f i l e head
62 f o u t = open ( ' data . dat ' , 'w ' ) # we open t h e f i l e i n a w r i t e mode s o
19
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
t h a t t h e f i l e w i l l be c l e a n
63 p r i n t >>f o u t , ' i t e r , x , y , z ' # w r i t e a f i l e head
64 fout . c l o s e ( ) # c l o s e the f i l e
65
66 # run t h e s i m u l a t i o n
67 # you have two c h o i c e s :
68 # 1 . g i v e a command here , l i k e ,
69 # O. run ( )
70 # you can s e t how many i t e r a t i o n s t o run
71 O. run ( 1 6 0 0 0 0 0 )
72 # 2 . c l i k e t h e run button a t t h e GUI c o n t r o l e r
Run the simulation by typing the following command in a terminal:
1 sudodem3d [Link]
Then, open gnuplot and plot the data as shown in Fig. 3.1:
1 $> gnuplot
2 gnuplot> plot '[Link]' using ($1/10000):4; set xlabel 'iterations
[x10000]'; set ylabel 'position z [m]'
20
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
10
'[Link]' using ($1/10000):4
6
position z [m]
0
0 20 40 60 80 100 120 140 160
iterations [x10000]
21
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
2.0
1.5
2.0
1.0 1.5
1.0
0.8
0.8
0.2 0.2
Figure 3.2: Superellipsoids.
10 import math
11 import random a s rand
12 import numpy a s np
13
14 ########d e f i n e some p a r a m e t e r s#################
15 i s S p h e r e=F a l s e
16
17 num_x = 5
18 num_y = 5
19 num_z = 20
20 R = 0.1
21
22 #######d e f i n e some a u x i l i a r y f u n c t i o n s#########
23
24 #d e f i n e a l a t i c e g r i d
25 #R: d i s t a n c e between two n e i g h b o r i n g nodes
26 #num_x : number o f nodes a l o n g x a x i s
27 #num_y : number o f nodes a l o n g y a x i s
28 #num_z : number o f nodes a l o n g z a x i s
29 #r e t u r n a l i s t o f t h e p o s t i o n s o f a l l nodes
30 d e f G r i d I n i t i a l (R, num_x=10 ,num_y=10 ,num_z=20) :
31 pos = l i s t ( )
32 f o r i i n r a n g e (num_x) :
22
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
33 f o r j i n r a n g e (num_y) :
34 f o r k i n r a n g e (num_z) :
35 x = i ∗R∗ 2 . 0
36 y = j ∗R∗ 2 . 0
37 z = k∗R∗ 2 . 0
38 pos . append ( [ x , y , z ] )
39 r e t u r n pos
40
41 #g e n e r a t e a sample
42 d e f GenSample ( r , pos ) :
43 f o r p i n pos :
44 e p s i l o n 1 = rand . uniform ( 0 . 7 , 1 . 6 )
45 e p s i l o n 2 = rand . uniform ( 0 . 7 , 1 . 6 )
46 a = r
47 b = r ∗ rand . uniform ( 0 . 4 , 0 . 9 )#a s p e c t r a t i o
48 c = r ∗ rand . uniform ( 0 . 4 , 0 . 9 )
49
50 body = NewSuperquadrics2 ( a , b , c , e p s i l o n 1 , e p s i l o n 2 , p_mat , True ,
isSphere )
51 body . s t a t e . pos=p
52 O. b o d i e s . append ( body )
53
54 #########s e t u p a s i m u l a t i o n####################
55 # material for p a r t i c l e s
56 p_mat = SuperquadricsMat ( l a b e l="mat1" ,Kn=1e5 , Ks=7e4 , f r i c t i o n A n g l e
=math . atan ( 0 . 3 ) , d e n s i t y =2650 , betan =0, b e t a s =0)
57 # betan and b e t a s a r e c o e f f i c i e n t s o f v i s c o u s damping a t c o n t a c t ,
no v i s c o u s damping with 0 by d e f a u l t .
58 # material f o r the s i d e w a l l s
59 wall_mat = SuperquadricsMat ( l a b e l=" wallmat " ,Kn=1e6 , Ks=7e5 ,
f r i c t i o n A n g l e =0.0 , betan =0, b e t a s =0)
60 # m a t e r i a l f o r t h e bottom w a l l
61 wallmat_b = SuperquadricsMat ( l a b e l=" wallmat " ,Kn=1e6 , Ks=7e5 ,
f r i c t i o n A n g l e=math . atan ( 1 ) , betan =0, b e t a s =0)
62 # add m a t e r i a l s t o O. m a t e r i a l s
63 O. m a t e r i a l s . append (p_mat)
64 O. m a t e r i a l s . append ( wall_mat )
65 O. m a t e r i a l s . append ( wallmat_b )
66
67 # c r e a t e t h e box and add i t t o O. b o d i e s
68 O. b o d i e s . append ( u t i l s . w a l l (−R, a x i s =0, s e n s e =1, m a t e r i a l = wall_mat
) )#l e f t w a l l a l o n g x a x i s
69 O. b o d i e s . append ( u t i l s . w a l l ( 2 . 0 ∗R∗num_x−R, a x i s =0, s e n s e =−1,
m a t e r i a l = wall_mat ) )#r i g h t w a l l a l o n g x a x i s
70 O. b o d i e s . append ( u t i l s . w a l l (−R, a x i s =1, s e n s e =1, m a t e r i a l = wall_mat
) )#f r o n t w a l l a l o n g y a x i s
71 O. b o d i e s . append ( u t i l s . w a l l ( 2 . 0 ∗R∗num_y−R, a x i s =1, s e n s e =−1,
m a t e r i a l = wall_mat ) )#back w a l l a l o n g y a x i s
72 O. b o d i e s . append ( u t i l s . w a l l (−R, a x i s =2, s e n s e =1, m a t e r i a l =wallmat_b
23
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
) )#bottom w a l l a l o n g z a x i s
73
74 # create a l a t t i c e grid
75 pos = G r i d I n i t i a l (R, num_x=num_x, num_y=num_y, num_z=num_z) # g e t
p o s i t i o n s o f a l l nodes
76 # c r e a t e p a r t i c l e s a t each nodes
77 GenSample (R, pos )
78
79 # create engines
80 # d e f i n e a Newton e n g i n e
81 newton=N e w t o n I n t e g r a t o r ( damping = 0 . 1 , g r a v i t y = ( 0 . , 0 . , − 9 . 8 ) , l a b e l=
" newton " , i s S u p e r q u a d r i c s =1) # i s S u p e r q u a d r i c s : 1 f o r
superquadrics
82
83 O. e n g i n e s =[
84 F o r c e R e s e t t e r ( ) , I n s e r t i o n S o r t C o l l i d e r ( [ Bo1_Superquadrics_Aabb
( ) , Bo1_Wall_Aabb ( ) ] , v e r l e t D i s t = 0 . 2 ∗ 0 . 1 ) ,
85 InteractionLoop (
86 [ Ig2_Wall_Superquadrics_SuperquadricsGeom ( ) ,
Ig2_Superquadrics_Superquadrics_SuperquadricsGeom ( ) ] ,
87 [ Ip2_SuperquadricsMat_SuperquadricsMat_SuperquadricsPhys ( )
] , # c o l l i s i o n " physics "
88 [ SuperquadricsLaw ( ) ] # c o n t a c t law
89 ),
90 newton
91
92 ]
93 O. dt=5e−5
With a GUI controller, we can click ’show 3D’ button at the panel ’Sim-
ulation’ to display the simulating scene. On the ’Display’ panel, select the
render ’Gl1_Superquadrics’ to configure the resolution of solid or wireframe
particles, as shown in Fig. 3.3.
Figs. 3.4 - 3.6 show simulations of packing of superellipsoids at different
states for the presented example.
Several properties and methods for a shape Superquadrics are listed be-
low:
• Properties:
• rx , ry , rz : float, semi-major axis lengths in x, y, and z axies.
• 1 , 2 : float, shape parameters.
• isSphere: bool, particle is spherical or not.
• Methods:
• getVolume(): float, return particle’s volume.
24
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
4 'flags': 3,
5 'groupMask': 1,
6 'id': 100,
7 'iterBorn': 0,
25
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
We can see that the properties are printed in a dict form. Note that the value
enclosed by pointy brackets is another object (actually, instance of an object
with a specified memory address), which means that we can further access it
using the ".dict()" method. Again, the properties of the object State can be
accessed by:
1 O. b o d i e s [ 1 0 0 ] . s t a t e . d i c t ( )
4 'densityScaling': 1.0,
5 'inertia': Vector3(0.0045389863901528615,0.007287422614611933,
6 0.0067053718092146865),
7 'isDamped': True,
8 'mass': 3.225715855242557,
9 'refOri': Quaternion((1,0,0),0),
10 'refPos': Vector3(0,0,0),
26
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
11 'se3': (Vector3(0,0.8,3),
12 Quaternion((0.3970010520699211,0.5339678220536823,
13 −0.7465042060609055),2.1754719537556495)),
14 'vel': Vector3(0,0,0)}
For an object Shape, we list all properties which may vary for different child
classes.
1 O. b o d i e s [ 1 0 0 ] . shape . d i c t ( )
4 'eps1': 1.3975848801318045,
5 'eps2': 1.5376309088540607,
6 'highlight': False,
7 'isSphere': False,
8 'rx': 0.1,
9 'rxyz': Vector3(0.1,0.06469580193313924,0.07572423080016706),
10 'ry': 0.06469580193313924,
11 'rz': 0.07572423080016706,
12 'wire': False}
27
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
• Consolidation
1 t r i a x=CompressionEngine (
2 g o a l x = 1 . 0 e5 , # c o n f i n i n g s t r e s s 100 kPa
3 g o a l y = 1 . 0 e5 ,
28
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
4 g o a l z = 1 . 0 e5 ,
5 savedata_interval = 10000 ,
6 echo_interval = 2000 ,
7 continueFlag = False ,
8 max_vel = 1 0 0 . 0 ,
9 gain_alpha = 0 . 5 ,
10 f _ t h r e s h o l d = 0 . 0 1 , #1− f / g o a l
11 f m i n _ t h r e s h o l d = 0 . 0 1 , #t h e r a t i o o f d e v i a t o r i c s t r e s s
t o mean s t r e s s
12 unbf_tol = 0 . 0 1 , #unblanced f o r c e r a t i o
13 f i l e = ' r e c o r d −con '
14 )
29
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
1 X cc 0
σij = f l, σij = σij − pδij (3.5)
V c∈V i j
0
where σij is the stress tensor with an assembly, and σij is its cor-
responding deviatoric part; V is the total volume of the specimen;
f c and lc are the contact force and branch vector at contact c,
respectively, and δij is the Kronecker delta.
• unbf_tol γf : a target unbalanced force ratio defined as
fjc + fjb |
P P
|
Bi ∈V j∈Bi
γf = P (3.6)
2 |f c |
c∈V
• Compression
1 t r i a x=CompressionEngine (
2 z_servo = F a l s e ,
3 g o a l x = 1 . 0 e5 ,
4 g o a l y = 1 . 0 e5 ,
5 goalz = 0.01 ,
6 ramp_interval = 1 0 ,
7 ramp_chunks = 2 ,
8 savedata_interval = 1000 ,
9 echo_interval = 2000 ,
10 max_vel = 1 0 . 0 ,
11 gain_alpha = 0 . 5 ,
12 f i l e=' sheardata ' ,
13 target_strain = 0.4 ,
14 gain_alpha = 0 . 5
15 )
30
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
dˆ
I = ˙1 p (3.7)
σ0 /ρ
where ˙1 = d1 /dt is the major principal strain rate; dˆ and ρ are
the average diameter and material density of particles respectively;
σ0 is the confining stress.
31
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
45 gen_sample ( b o x s i z e [ 0 ] , b o x s i z e [ 1 ] , b o x s i z e [ 2 ] )
46
47 ####f u n c t i o n f o r s a v i n g data ( e . g . , s i m u l a t i o n s t a t e s h e r e )
48 def savedata () :
49 O. s a v e ( s t r (O. time )+ ' . xml . bz2 ' )
50
51 #########################################
52 ####t r i a x e n g i n e
53 #CAUTION: t h e CompressionEngine r e g a r d s t h e f i r s t s i x b o d i e s a s
c o n f i n i n g w a l l s by d e f a u l t . So t h e w a l l s s h o u l d be g e n e r a t e d
first .
54 t r i a x=CompressionEngine (
55 g o a l x = 1 . 0 e5 , # c o n f i n i n g s t r e s s 100 kPa
56 g o a l y = 1 . 0 e5 ,
57 g o a l z = 1 . 0 e5 ,
58 savedata_interval = 10000 ,
59 echo_interval = 2000 ,
60 continueFlag = False ,
61 max_vel = 1 0 . 0 ,
62 gain_alpha = 0 . 5 ,
63 f _ t h r e s h o l d = 0 . 0 1 , #1− f / g o a l
32
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
64 f m i n _ t h r e s h o l d = 0 . 0 1 , #t h e r a t i o o f d e v i a t o r i c s t r e s s t o mean
stress
65 unbf_tol = 0 . 0 1 , #unblanced f o r c e r a t i o
66 f i l e = ' r e c o r d −con ' ,
67 )
68
69 ############################
70
71
72
33
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
133 t r i a x . dead=True
134 calm_num = 0
Ss_z:6.1184e−05, e:0.992618
5 Iter 52000 Ubf 0.461741, Ss_x:1.2412, Ss_y:1.06812, Ss_z:1.10116,
e:0.854445
6 Iter 54000 Ubf 0.263699, Ss_x:1.75334, Ss_y:1.98567, Ss_z
:1.62181, e:0.757469
7 Iter 56000 Ubf 0.118329, Ss_x:3.06302, Ss_y:3.54818, Ss_z
:3.22986, e:0.679106
8 Iter 58000 Ubf 0.0110747, Ss_x:22.0177, Ss_y:21.3303, Ss_z
:21.3485, e:0.614824
9 Iter 60000 Ubf 0.000577066, Ss_x:91.4199, Ss_y:89.6039, Ss_z
:89.1057, e:0.58984
34
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
After consolidation (see the snapshot in Fig. 3.7), we obtain a state file
by
1 O. s a v e ( " f i n a l _ c o n . xml . bz2 " )
35
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
The compression ends up with an axial strain of 40%, and the final con-
figuration of particles is shown in Fig. 3.8.
The macroscopic mechanical response of a granular material during shear-
ing can be quantified by the stress tensor that is calculated from discrete
measurements with the following definition:
1 X cc
σij = f l (3.8)
V c∈V i j
36
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
where V is the total volume of the assembly, f c is the contact force at the
contact c, and lc is the branch vector joining the the centres of the two
contacting particles at contact c. The mean stress p and the deviatoric stress
q are defined as: r
1 3 0 0
p = σii , q = σ σ (3.9)
3 2 ij ij
0
where σij is the deviatoric part of stress tensor σij .
Given that the cubical specimens are confined by rigid walls, the axial
strain z and the volumetric strain v can be approximately calculated from
the positions of the boundary walls, i.e.,
Z H Z V
dh H0 dv V0
z = = − ln , v = x + y + z = = − ln (3.10)
H0 h H V0 v V
where H and V are the height and volume of the specimen during shearing,
respectively, and H0 and V0 are their initial values before shear. Positive
values of volumetric strain represent dilatancy.
The recorded data ’sheardata’ looks like below:
1 A x i a l S t r a i n V o l S t r a i n m ea n S tr e s s d e v i a t o r S t r e s s
2 0.000511000266 0.000490480823 106090.98 15931.56
3 0.003011001516 0.002450117535 131061.41 85718.91
37
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
Then we can plot the stress-strain variation and the loading path as shown
in Figs. 3.9 and 3.10.
1.50 15
1.25
Deviatoric stress ratio, q/p []
0.75
5
0.50
0.25 q/p
εv 0
0.00
0 10 20 30 40
Axial strain, [%]
Figure 3.9: Variation of deviatoric stress ratio q/p and volumetric strain v
with axial strain during shearing.
38
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
300
250
Deviatoric stress, q [kPa]
200
150
100
50
0
0 50 100 150 200 250 300
Mean stress, p [kPa]
• GJKSphere(radius,margin,mat)
• GJKPolyhedron(vertices,extent,margin,mat, rotate)
39
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
1 cube_v0 =
[[0 ,0 ,0] ,[1 ,0 ,0] ,[1 ,1 ,0] ,[0 ,1 ,0] ,[0 ,0 ,1] ,[1 ,0 ,1] ,[1 ,1 ,1] ,[0 ,1 ,1]]
2 cube_v = [ [ i ∗ 0 . 0 1 f o r i i n j ] f o r j i n cube_v0 ]
3
4 i s S p h e r e=F a l s e
5
6 num_x = 5
7 num_y = 5
8 num_z = 20
9 R = 0.01
40
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
41
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
Figure 3.12: Final packing of cones without random initial orientations (the
box not shown).
2 d e f GenSample ( r , pos ) :
3 f o r p i n pos :
4 body = GJKCone ( 0 . 0 0 5 , 0 . 0 1 , 0 . 0 5 ∗ 1 e −2,p_mat , F a l s e )
5 body . s t a t e . pos=p
6 O. b o d i e s . append ( body )
7 O. b o d i e s [ − 1 ] . shape . c o l o r =(rand . random ( ) , rand . random ( ) , rand .
42
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
random ( ) )
Fig. 3.12 shows final packing of cones without random initial orientations
(i.e., the argument rotate is False). It can be seen that particles still align in
the lattice grid due to no disturbance in the tangential direction.
Set the argument rotate to True as follows:
1 body = GJKCone ( 0 . 0 0 5 , 0 . 0 1 , 0 . 0 5 ∗ 1 e −2,p_mat , True )
Figure 3.13: Final packing of cones with random initial orientations (the box
not shown).
Rerun the simulation, and the initial particles have random orientations.
After free falling under gravity, it can be seen that the lattice alignment
corrupts, referring to Fig. 3.13
For cylindrical particles, the function GenSample is replaced as follows:
1 d e f GenSample ( r , pos ) :
2 f o r p i n pos :
3 body = GJKCylinder ( 0 . 0 0 5 , 0 . 0 1 , 0 . 0 5 ∗ 1 e −2,p_mat , F a l s e )
4 body . s t a t e . pos=p
5 O. b o d i e s . append ( body )
6 O. b o d i e s [ − 1 ] . shape . c o l o r =(rand . random ( ) , rand . random ( ) , rand .
random ( ) )
43
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
Figure 3.15: Final packing of cylinders with random initial orientations (the
box not shown).
after free falling. Again, we reset the argument rotate to True so that all
initial particles will have random orientations.
1 body = GJKCylinder ( 0 . 0 0 5 , 0 . 0 1 , 0 . 0 5 ∗ 1 e −2,p_mat , True )
44
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
Figure 3.17: Final packing of cuboids with random initial orientations (the
box not shown).
45
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
The column of particles collapses but not too much due to small gaps between
particles.
where rx+ , ry+ , rz+ and rx− , ry− , rz− are the principal elongation along positive and
negative directions of x, y, z axes, respectively; 1 , 2 control the squareness or
blockiness of particle surface, and their possible values are in (0, 2) for convex
shapes. Fig. 3.18 intuitively shows how 1 and 2 affect particle surface.
The module _superquadrics_utils provides two functions to generate a poly-
superellipsoid (see Sec. 5.1.2):
46
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
Figure 3.18: Poly-superellipsoids with rx+ = 1.0, rx− = 0.5, ry+ = 0.8, ry− =
0.9, rz+ = 0.4, rz− = 0.6 and (a) 1 = 0.4, 2 = 1.5, (b) 1 = 2 = 1.0, (c)
1 = 2 = 1.5.
47
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
26 def gettop () :
27 zmax=0
28 f o r b i n O. b o d i e s :
29 i f ( i s i n s t a n c e ( b . shape , P o l y S u p e r e l l i p s o i d ) ) :
30 i f ( b . s t a t e . pos [2] >=zmax ) :
31 zmax=b . s t a t e . pos [ 2 ]
32 r e t u r n zmax
33
34
35 d e f G e n p a r t i c l e s ( a , eps , ap , mat , b o x s i z e , num_s , num_t , bottom ) :
36 global t r i a l s
37 gap=max( a , a∗ap )
38 #p r i n t ( gap )
39 num=0
40 coor =[]
41 width=( b o x s i z e [ 0 ] − 2 . ∗ gap ) / 2 .
42 l e n g t h =( b o x s i z e [ 1 ] − 2 . ∗ gap ) / 2 .
43 h e i g h t =( b o x s i z e [ 2 ] − 2 . ∗ gap )
44 #i t e r a t i o n =0
45
46 w h i l e num<num_s and t r i a l s <num_t :
47 isOK=True
48 pos = [ 0 ] ∗ 3
49 pos [ 0 ] = random . uniform (−width , width )
50 pos [ 1 ] = random . uniform ( gap−l e n g t h , l e n g t h −gap )
51 pos [ 2 ] = random . uniform ( bottom+gap , bottom+gap+h e i g h t )
52
53 f o r i in range (0 , len ( coor ) ) :
54 d i s t a n c e=sum ( [ ( ( c o o r [ i ] [ j ]− pos [ j ] ) ∗ ∗ 2 . ) f o r j i n
range ( 0 , 3 ) ] )
55 i f ( d i s t a n c e <(4.∗ gap ∗ gap ) ) :
56
57 isOK=F a l s e
58 break
59
60 i f ( isOK==True ) :
61 c o o r . append ( pos )
62 num+=1
63 t r i a l s +=1
64 #p r i n t (num)
65 return coor
66
67
68 d e f Addlayer ( a , eps , ap , mat , b o x s i z e , num_s , num_t) :
69 bottom=g e t t o p ( )
70 c o o r=G e n p a r t i c l e s ( a , eps , ap , mat , b o x s i z e , num_s , num_t , bottom )
71 f o r b in coor :
72 #xyz = np . a r r a y ( [ 1 . 0 , 0 . 5 , 0 . 8 , 1 . 5 , 1 . 2 , 0 . 4 ] ) ∗ 0 . 1
73 xyz = np . a r r a y ( [ 1 . 0 , 0 . 5 , 0 . 8 , 1 . 5 , 0 . 2 , 0 . 4 ] ) ∗ 0 . 1
48
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
90
91 O. b o d i e s . append ( u t i l s . w a l l ( −0.5∗ w a l l b o x s i z e [ 0 ] , a x i s =0, s e n s e =1,
m a t e r i a l = wall_mat ) )#l e f t x
92 O. b o d i e s . append ( u t i l s . w a l l ( 0 . 5 ∗ w a l l b o x s i z e [ 0 ] , a x i s =0, s e n s e =−1,
m a t e r i a l = wall_mat ) )#r i g h t x
93 O. b o d i e s . append ( u t i l s . w a l l ( −0.5∗ b o x s i z e [ 1 ] , a x i s =1, s e n s e =1,
m a t e r i a l = wall_mat ) )#f r o n t y
94 O. b o d i e s . append ( u t i l s . w a l l ( 0 . 5 ∗ b o x s i z e [ 1 ] , a x i s =1, s e n s e =−1,
m a t e r i a l = wall_mat ) )#back y
95
96 O. b o d i e s . append ( u t i l s . w a l l ( 0 , a x i s =2, s e n s e =1, m a t e r i a l =wallmat_b )
)#bottom z
97 #O. b o d i e s . append ( u t i l s . w a l l ( b o x s i z e [ 0 ] , a x i s =2, s e n s e =−1, m a t e r i a l
= wallmat_b ) )#top z
98
99 newton=N e w t o n I n t e g r a t o r ( damping = 0 . 3 , g r a v i t y = ( 0 . , 0 . , − 9 . 8 ) , l a b e l=
" newton " , i s S u p e r q u a d r i c s =2)#i s S u p e r q u a d r i c s =2 f o r Poly−
superellipsoids
100
101 O. e n g i n e s =[
102 ForceResetter () ,
103 I n s e r t i o n S o r t C o l l i d e r ( [ Bo1_PolySuperellipsoid_Aabb ( ) ,
Bo1_Wall_Aabb ( ) ] , v e r l e t D i s t = 0 . 2 ∗ 0 . 1 ) ,
104 InteractionLoop (
105 [ Ig2_Wall_PolySuperellipsoid_PolySuperellipsoidGeom () ,
Ig2_PolySuperellipsoid_PolySuperellipsoid_PolySuperellipsoidGeom
() ] ,
49
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
106 [
Ip2_PolySuperellipsoidMat_PolySuperellipsoidMat_PolySuperellipsoidPhys
() ] , # c o l l i s i o n " physics "
107 [ PolySuperellipsoidLaw () ] # c o n t a c t law −− apply f o r c e s
108 ),
109 newton
110 ]
111 O. dt=5e−5
112 #adding p a r t i c l e s
113 Addlayer ( a , eps , ap , p_mat , b o x s i z e , num_s , num_t)#Note : t h e s e
p a r t i c l e s may i n t e r s e c t with each o t h e r when we g e n e r a t e them
.
114
115 #s e t t i n g t h e D i s p l a y p r o p e r t i e s . You can go t o t h e D i s p l a y p a n e l
t o s e t them d i r e c t l y .
116 sudodem . qt . G l 1 _ P o l y S u p e r e l l i p s o i d . w i r e=F a l s e
117 sudodem . qt . G l 1 _ P o l y S u p e r e l l i p s o i d . s l i c e s =10
118 sudodem . qt . Gl1_Wall . d i v=0 #h i d e t h e w a l l s
After running the script above, the user is expected to see a packing as shown
in Fig. 3.19.
50
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
14 num_s=100
15 num_t=8000
16 t r i a l s =0
17 boxsize =[50.0 ,10.0]
18
19 #############################
20 mat =S u p e r e l l i p s e M a t ( l a b e l="mat1" ,Kn=1e8 , Ks=7e7 , f r i c t i o n A n g l e=
math . atan ( 0 . 2 2 5 ) , d e n s i t y =2650)
21 O. m a t e r i a l s . append ( mat )
22
23 O. b o d i e s . append ( u t i l s . w a l l ( −0.5∗ b o x s i z e [ 1 ] , a x i s =1, s e n s e =1,
m a t e r i a l = ' mat1 ' ) )#ground
24 O. b o d i e s . append ( u t i l s . w a l l ( −0.5∗ b o x s i z e [ 0 ] , a x i s =0, s e n s e =1,
m a t e r i a l = ' mat1 ' ) )#l e f t
25 O. b o d i e s . append ( u t i l s . w a l l ( 0 . 5 ∗ b o x s i z e [ 0 ] , a x i s =0, s e n s e =−1,
m a t e r i a l = ' mat1 ' ) )#r i g h t
26
27 ###
28 def gettop () :
29 ymax=0
51
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
30 f o r b i n O. b o d i e s :
31 i f ( i s i n s t a n c e ( b . shape , S u p e r e l l i p s e ) ) :
32 i f ( b . s t a t e . pos [1] >=ymax ) :
33 ymax=b . s t a t e . pos [ 1 ]
34 r e t u r n ymax
35
36
37 d e f G e n p a r t i c l e s ( r , mat , b o x s i z e , num_s , num_t , bottom ) :
38 global t r i a l s
39 gap=r
40 #p r i n t ( gap )
41 num=0
42 coor =[]
43 width=( b o x s i z e [ 0 ] − 2 . ∗ gap ) / 2 .
44 h e i g h t =( b o x s i z e [ 1 ] − 2 . ∗ gap )
45 #i t e r a t i o n =0
46
47 w h i l e num<num_s and t r i a l s <num_t :
48 isOK=True
49 pos = [ 0 ] ∗ 2
50 pos [ 0 ] = random . uniform (−width , width )
51 pos [ 1 ] = random . uniform ( bottom+gap , bottom+gap+h e i g h t )
52
53 f o r i in range (0 , len ( coor ) ) :
54 d i s t a n c e=sum ( [ ( ( c o o r [ i ] [ j ]− pos [ j ] ) ∗ ∗ 2 . ) f o r j i n
range ( 0 , 2 ) ] )
55 i f ( d i s t a n c e <(4.∗ gap ∗ gap ) ) :
56
57 isOK=F a l s e
58 break
59
60 i f ( isOK==True ) :
61 c o o r . append ( pos )
62 num+=1
63 t r i a l s +=1
64 #p r i n t (num)
65 return coor
66
67
68 d e f Addlayer ( r , mat , b o x s i z e , num_s , num_t) :
69 bottom=g e t t o p ( )
70 c o o r=G e n p a r t i c l e s ( r , mat , b o x s i z e , num_s , num_t , bottom )
71 f o r b in coor :
72 r r = r ∗random . uniform ( 0 . 5 , 1 . 0 )
73 bb = N e w S u p e r e l l i p s e ( 1 . 5 ∗ r , r , 1 . 0 , mat , True , i s S p h e r e )
74 bb . s t a t e . pos=b
75 bb . s t a t e . v e l =[0 , −1]
76 O. b o d i e s . append ( bb )
77 i f l e n (O. b o d i e s ) − 3 > 2 0 0 0 :
52
A Quick Guide to SudoDEM CHAPTER 3. EXAMPLES
78 O. e n g i n e s [ − 1 ] . dead=True
79
80 O. dt = 1 e−3
81
After running the above script with sudodem2d, the user can get a packing
as shown in Fig. 3.20.
53
CHAPTER 3. EXAMPLES A Quick Guide to SudoDEM
54
Chapter 4
Post-processing
4.1 Data
It is preferable to save a series of states during a simulation, i.e., periodically
saving data using a PyRunner:
1 def savedata () :
2 g l o b a l saving_num
3 saving_num += 1
4 #p r i n t " t e s t i n g , no data saved "
5 O. s a v e ( ' s h e a r '+s t r ( saving_num )+ ' . xml . bz2 ' )
6
7 O. e n g i n e s = O. e n g i n e s + [ PyRunner ( command = ' s a v e d a t a ( ) ' ,
i t e r P e r i o d = 1000 ) ] # i f we l o a d t h e c o n s o l i d a t i o n data ,
then we do not need t h i s l i n e b e c a u s e t h e PyRunner c a l l i n g '
s a v e d a t a ( ) ' has been d e f i n e d .
The Python module utilspost provides plentiful examples of post-processing,
including some basic functions of stress-force-fabric computation and other
pre-processing functions for visualization (e.g., writing vtk files of particles
and 3D histograms of fabric). Based on this module, users can copy and mod-
ify for a self purpose or just call the module functions in a post-processing
script, e.g.,
1 import sudodem . u t i l s p o s t a s u t i l s p o s t
2 #t h e f o l l o w i n g f u n c t i o n s w i l l output t h e a v e r a g e f r i c t i o n
m o b i l i z a t i o n i n d e x o f each s t a t e t o a s i n g l e f i l e .
3 for i in [ ' 1.0 ' , ' 1.2 ' , ' 1.4 ' , ' 1.6 ' ] :
4 u t i l s p o s t . c a l c _ a v g F r i c M o b i l I n d e x ( i , steps_num )
The Python module _superquadrics_utils also provides some auxiliary
functions, e.g.,
• outputParticles(filename) : filename, the file name for writing; output
info of each particle, i.e., shape parameters rx , ry , rz , 1 , 2 , position
55
CHAPTER 4. POST-PROCESSING A Quick Guide to SudoDEM
Open Paraview, then import the vtk file "[Link]" and click the button
"Apply", so that the configuration of particles is visualized as shown in Fig.
4.2. It is noteworthy that the function outputVTK processes a particle sur-
face as a combination of many (determined by the argument slices, i.e., 15
herein) polygons, which would yield a large file (around 180 Mb in the pre-
sented example). The users may find ways to reduce the vtk file for a faster
visualization in Paraview. One possible way is to show only the particles
1
[Link]
2
[Link]/
56
A Quick Guide to SudoDEM CHAPTER 4. POST-PROCESSING
exposed in the view. Another possible way is to use the interface of built-in
Superquadric source in Paraview. Another alternative approach is rendering
the scene utilizing POV-Ray.
1 O. l o a d ( " s h e a r e n d . xml . bz2 " )
2 import sudodem . _ s u p e r q u a d r i c s _ u t i l s a s s u p e r u t i l s
3 s u p e r u t i l s . outputPOV ( " s h e a r e n d . pov " )
The users might revise the parameters of the camera in the POV file, i.e.,
"[Link]" here,
1 camera { // o r t h o g r a p h i c a n g l e 45
2 l o c a t i o n < 0 . 6 , 0 . 6 , 0 . 5 > ∗ 5 0 e−3
3 sky z
4 look_at <0 ,0 ,0.05 >∗10 e−3
5 r i g h t x∗ image_width / image_height
6 t r a n s l a t e < −0.04 ,0.01 , −0.1 >∗50 e−3
7 }
57
CHAPTER 4. POST-PROCESSING A Quick Guide to SudoDEM
1 povray [Link]
Image processing softwares, e.g., GIMP 3 , can be used to change image size or
make a gif animation, etc. Fig. 4.3 shows configuration of particles rendered
by POV-Ray and cropped using GIMP.
The module snapshot provides functions for visualizing poly-superellipsoids.
As an example, we load the state of final packing, and import the module
and call the outPov function as follows:
1 from sudodem import s n a p s h o t
2 s n a p s h o t . outPov ( " p a c k i n g p o l y s u p e r " , withbox=F a l s e )
58
A Quick Guide to SudoDEM CHAPTER 4. POST-PROCESSING
5 #end
6 #macro randomColor ( r , g , b )
7 t e x t u r e { pigment { c o l o r rgb<r , g , b> t r a n s m i t para_trans } f i n i s h {
phong para_phong }}
8 #end
9 #macro o c t a n t S u p e r ( ep1 , ep2 , rx , ry , rz , s i g n 1 , s i g n 2 , s i g n 3 )
10 s u p e r e l l i p s o i d { <ep1 , ep2>
11 #i f ( s i n g l e C o l o r = f a l s e )
12 randomColor ( rand ( Random_r ) , rand (Random_g) , rand (Random_b) )
13 #end
14 myremain ( s i g n 1 , s i g n 2 , s i g n 3 ) s c a l e <rx , ry , rz >}
15 #end
16 #macro p o l y S u p e r E l l i p s o i d ( ep1 , ep2 , a1 , a2 , b1 , b2 , c1 , c2 , t1 , t2 , t3 , r1 ,
r2 , r3 , r , g , b )
17 union {
18 o c t a n t S u p e r ( ep1 , ep2 , a2 , b2 , c2 , −1 , −1 , −1)
19 o c t a n t S u p e r ( ep1 , ep2 , a1 , b2 , c2 ,1 , −1 , −1)
20 o c t a n t S u p e r ( ep1 , ep2 , a2 , b1 , c2 , −1 ,1 , −1)
21 o c t a n t S u p e r ( ep1 , ep2 , a1 , b1 , c2 , 1 , 1 , − 1 )
22 o c t a n t S u p e r ( ep1 , ep2 , a2 , b2 , c1 , −1 , −1 ,1)
23 o c t a n t S u p e r ( ep1 , ep2 , a1 , b2 , c1 , 1 , − 1 , 1 )
24 o c t a n t S u p e r ( ep1 , ep2 , a2 , b1 , c1 , − 1 , 1 , 1 )
25 o c t a n t S u p e r ( ep1 , ep2 , a1 , b1 , c1 , 1 , 1 , 1 )
26 r o t a t e <r1 , r2 , r3>
27 t r a n s l a t e <t1 , t2 , t3>
28 #i f ( s i n g l e C o l o r = t r u e )
29 randomColor ( r , g , b )
30 #end
31 }
32 #end
33 p o l y S u p e r E l l i p s o i d ( 1 . 0 0 0 0 0 0 0 e +00 ,1.0000000 e +00 ,1.0000000 e −01 ,
59
CHAPTER 4. POST-PROCESSING A Quick Guide to SudoDEM
The users are not suggested to edit this file though. But the second file
[Link] includes some editable parameters as introduced above,
and looks like this:
1 // u s i n g t h e command : povray ∗ ∗ . pov +A0 . 0 1 +W1600 +H1200
2 #i n c l u d e " c o l o r s . i n c "
3 #d e c l a r e s i n g l e C o l o r = t r u e ;
4 #d e c l a r e Random_r = s e e d ( 1 4 3 2 ) ;
5 #d e c l a r e Random_g = s e e d ( 7 2 4 2 ) ;
6 #d e c l a r e Random_b = s e e d ( 9 9 1 2 ) ;
7 #d e c l a r e para_trans = 0 ;
8 #d e c l a r e para_phong = 1 . 0 ;
9 camera {
10 l o c a t i o n < 1.39244459003 , 0.950562440499 , 0.605226784362 >
11 sky z
12 r i g h t −x∗ image_width / image_height
13 look_at < 0 . 6 1 2 8 7 2 3 8 2 4 5 1 , 0 . 3 4 9 2 5 5 1 6 0 6 3 7 , 0 . 4 3 0 0 2 1 9 6 6 0 5 3 >
14 }
15 #i n c l u d e " p a c k i n g e l l i p s e s . i n c "
16 l i g h t _ s o u r c e { <4 ,8 ,5 >∗10 c o l o r rgb <1 ,1 ,1 >}
17 l i g h t _ s o u r c e {<12,−6>∗10 c o l o r rgb <1 ,1 ,1 >}
18 l i g h t _ s o u r c e { <0, 2 , 10> White }
19 background { rgb 1}
20 p l a n e { z , −5 pigment { c h e c k e r Green White }} // you may comment
out t h i s l i n e t o remove t h e p l a n e
you will get a nice figure with higher quality as Fig. 4.4.
4.2.2 SudoDEM2D
Module _superellipse_utils provides a function drawSVG (see Sec. 5.2.2) to
dump the particle profiles and contact forces chains to a SVG file.
1 from sudodem import _ s u p e r e l l i p s e _ u t i l s
2 O. l o a d ( " your data f i l e " )
3 drawSVG( " t e s t . svg " , d r a w _ f o r c e c h a i n=True ,
4 force_line_color =(1.0 ,0 ,0) ,
5 solo_color =(93.0/255 ,152.0/255 ,208.0/255) )
60
A Quick Guide to SudoDEM CHAPTER 4. POST-PROCESSING
The output file [Link] is editable by using a text editor and/or Inkscape
(recommended). Fig. 4.5 shows an exemplified snapshot of a packing of
elliptic particles with periodic boundary conditions. Refer to the keywords
of drawSVG for configuring the output figure.
61
CHAPTER 4. POST-PROCESSING A Quick Guide to SudoDEM
62
Chapter 5
5.1 SudoDEM3D
5.1.1 Basic classes
class State(inherits Serializable)
State of a body (spatial configuration, internal variables).
• angMom(=Vector3r::Zero())
Current angular momentum
• angVel(=Vector3r::Zero())
Current angular velocity
• blockedDOFs
Degress of freedom where linear/angular velocity will be always con-
stant (equal to zero, or to an user-defined value), regardless of applied
force/torque. String that may contain ‘xyzXYZ’ (translations and ro-
tations).
• dict() → dict
Return dictionary of attributes.
• inertia(=Vector3r::Zero())
Inertia of associated body, in local coordinate system.
• isDamped(=true)
Damping in Newtonintegrator can be deactivated for individual parti-
cles by setting this variable to FALSE. E.g. damping is inappropriate
for particles in free flight under gravity but it might still be applicable
to other particles in the same simulation.
63
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
• mass(=0)
Mass of this body
• ori
Current orientation.
• pos
Current position.
• refOri(=Quaternionr::Identity())
Reference orientation
• refPos(=Vector3r::Zero())
Reference position
• se3(=Se3r(Vector3r::Zero(), Quaternionr::Identity()))
Position and orientation as one object.
64
A Quick Guide to SudoDEM
CHAPTER 5. PYTHON CLASS REFERENCE
• getSurfArea(id, w, h)
Get the surface area of a super-ellipsoid by a given particle id with
resolution w and h (e.g., w=10,h=10). Larger w and h will yield more
accurate results.
• outputParticles(filename)
Output information including id, shape parameters, position and ori-
entation of all particles into a file.
• outputParticlesbyIds(filename, ids)
Output particles by a list of ids, referring to the last function. [Only
for superellipsoids]
65
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
• outputPOV(filename)
Output Superellipsoids (including spheres) into a POV file for post-
processing using POV-ray. [Only for superellipsoids and spheres]
• outputVTK(filename, slices)
Output Superellpisoids into a VTK file for post-processing using Par-
aview. [Only for superellipsoids]
66
A Quick Guide to SudoDEM
CHAPTER 5. PYTHON CLASS REFERENCE
• GJKPolyhedron(vertices,extent,margin,mat, rotate)
67
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
• outPov(fname,transmit=0,phong=1.0,singleColor=True,ids=[],scale=1.0,
withbox = True)
The user is referred to POV-Ray’s Doc for more details on the two
parameters (transmit and phong) and others that will be written to
the output file by this function.
68
A Quick Guide to SudoDEM
CHAPTER 5. PYTHON CLASS REFERENCE
5.2 SudoDEM2D
5.2.1 Basic classes
Class State
State of a body (spatial configuration, internal variables).
• angMom(=Vector2r::Zero())
Current angular momentum
• angVel(=Vector2r::Zero())
Current angular velocity
• blockedDOFs
Degress of freedom where linear/angular velocity will be always con-
stant (equal to zero, or to an user-defined value), regardless of applied
force/torque. String that may contain ‘xyZ’ (translations and rota-
tions).
• dict() → dict
Return dictionary of attributes.
• inertia(=Vector2r::Zero())
Inertia of associated body, in local coordinate system.
• isDamped(=true)
Damping in Newtonintegrator can be deactivated for individual parti-
cles by setting this variable to FALSE. E.g. damping is inappropriate
for particles in free flight under gravity but it might still be applicable
to other particles in the same simulation.
• mass(=0)
Mass of this body
• ori
Current orientation. The orientation and rotation of a particle is rep-
resented by a Rotation2d object (see Rotation2D in the Eigen library),
which has the following members and functions.
Class Rotation2d
69
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
• pos
Current position.
• refOri(=Rotation2D::Identity())
Reference orientation
• refPos(=Vector2r::Zero())
Reference position
• se2(=Se2r(Vector2r::Zero(), Rotation2d::Identity()))
Position and orientation as one object.
70
A Quick Guide to SudoDEM
CHAPTER 5. PYTHON CLASS REFERENCE
71
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
• getParticleVolume2D()
Compute the total volume (area for 2D) of particles in the scene.
• getMeanCN()
Get the mean coordination number of a packing
• changeParticleSize2D(alpha)
expand a particle by a given coefficient
• getVoidRatio2D(cellArea=1)
Compute 2D void ratio. Keyword cellArea is effective only for aperioidc
cell
• getStress2D(z_dim=1)
Compute overall stress of periodic cell
• getFabricTensorCN2D()
Fabric tensor of contact normal
• getFabricTensorPO2D()
Fabric tensor of particle orientation along the rx axis
• getStressAndTangent2D(z_dim=1,symmetry=true)
Compute overall stress of periodic cell using the same equation as func-
tion getStress. In addition, the tangent operator is calculated using the
equation: Sijkl = V c (kn ni lj nk ll + kt ti lj tk ll ) float volume: same as in
1
P
function getStress bool symmetry: make the tensors symmetric.
return: macroscopic stress tensor and tangent operator as py::tuple
72
A Quick Guide to SudoDEM
CHAPTER 5. PYTHON CLASS REFERENCE
73
CHAPTER 5. PYTHON CLASS REFERENCE
A Quick Guide to SudoDEM
74
Acknowledgments
The work was partially supported by the Hong Kong Scholars Program
(2018), the National Natural Science Foundation of China (by Project No.
51679207, 51909095), Research Grants Council of Hong Kong (by GRF Project
No. 16205418, TBRS Project No. T22-603/15N and CRF Project No.
C6012-15G). The following open-source tools but not limited to are acknowl-
edged: Ubuntu, YADE, Python, Boost, Eigen, Voro++, Paraview, Pov-Ray,
GIMP, InkScape, Veusz and LaTeX.
75
The shape parameters epsilon1 and epsilon2 are critical in defining the geometry of a NewSuperquadrics2 object. These parameters determine the ‘roundness’ of the superquadric by influencing its cross-sectional shape in the generated geometry. Variation in epsilon1 and epsilon2 results in different superquadric forms, from spheroid-like to more cube-like forms, thus impacting the object's interaction properties such as contact dynamics and packing behavior within simulations .
Using PolySuperellipsoidMat as a material property benefits simulations by providing tailored characteristics suitable for non-spherical particles, capturing complex contact interactions due to its customized material parameters, such as stiffness and friction. This material type influences simulations by better representing the nuances of particle shapes, impacting the effective area of contact, energy dissipation, and resultant force equations. Accurate material modeling with PolySuperellipsoidMat contributes to more realistic behavior and precision in simulations of complex granular material systems .
The GridInitial function calculates the positions of all nodes in a 3D grid by iterating over the specified ranges of num_x, num_y, and num_z dimensions. For each combination of i, j, and k, it computes the coordinates x, y, and z as multiples of R, the specified radius, doubled. Specifically, x = i * R * 2.0, y = j * R * 2.0, and z = k * R * 2.0. This methodical setup of node positions is crucial for laying out a spatial framework onto which simulation elements can be placed, ensuring that the grid remains uniform and consistent for further operations .
The isDamped parameter in particle states determines whether damping is applied, influencing the simulation's handling of motion and energy dissipation. If damping is active (isDamped=true), particle velocities are reduced over time to simulate friction-like effects, enhancing stability in long-term simulations. Deactivating damping (isDamped=false) is crucial for scenarios like free flight under gravity, where preserving kinetic energy is essential. This selective application of damping allows for more precise control over dynamic behaviors, adapting to the specific physical scenarios being simulated .
Materials for particles and side walls differ mainly in their stiffness (Kn and Ks values) and friction angles. For particles, the SuperquadricsMat has a stiffness of Kn=1e5 and Ks=7e4 with a friction angle calculated from the arctan of 0.3, while for side walls, wall_mat has a higher stiffness with Kn=1e6 and Ks=7e5 but a friction angle of 0. These differences affect the interaction dynamics in simulations, where higher wall stiffness may simulate rigid boundary constraints .
The NewtonIntegrator functions as a core component in the simulation process by managing the integration of motion equations. It applies specified parameters, such as damping (set at 0.3), and gravitational acceleration (set as (0, 0, -9.8)), to control the time step iteration. The isSuperquadrics parameter indicates compatibility with superquadrics, allowing for precise dynamics of these shapes. The integrator employs these settings to calculate the positions and velocities of particles time step by time step, ensuring accurate physical modeling of the simulation .
The InteractionLoop plays a pivotal role in managing collision physics by orchestrating the detection and response phases in particle simulations. It incorporates geometry interaction functors, like Ig2_Wall_GJKParticle_GJKParticleGeom, to identify when particles are in contact and applies collision physics laws (e.g., PolySuperellipsoidLaw) to resolve these interactions. This ensures that forces are appropriately calculated and applied, maintaining realistic physical behavior. The loop efficiently manages multiple interactions simultaneously, safeguarding against erratic behavior due to overlapping particles and ensuring the robustness of the simulation environment .
Quaternions, composed of components qw, qx, qy, qz, offer a significant advantage in particle orientation due to their ability to represent rotations transparently and avoid gimbal lock, a limitation of Euler angles. Their mathematical framework allows for smooth and continuous rotational manipulations, which is crucial for simulations involving complex 3D motions. Quaternions enable efficient interpolation between orientations (slerp), improving the accuracy and aesthetic smoothness of rotational transitions and interactions in simulations .
Setting appropriate time step values, like O.dt=5e-5, in particle simulations is crucial to balancing computational efficiency with accuracy. A smaller time step ensures that the simulation captures detailed dynamic interactions between particles, preventing instability and inaccuracies due to too rapid state changes. However, this comes at the cost of increased computational time. Conversely, a larger time step reduces computational load but risks missing critical interactions, especially in highly dynamic systems. Thus, selecting an optimal time step is a key factor in achieving reliable and meaningful simulation results .
The drawSVG function is important for post-processing because it facilitates the visualization of simulation data by generating an SVG file that depicts force chains and particle distributions. Configurable through parameters such as force_line_color, this SVG can be edited using tools like Inkscape, allowing researchers to analyze configurations visually. By providing such a visual representation, the function aids in better understanding complex interaction mechanisms and verifying the physical accuracy of the simulation results .