# About periodic simple shear example in the yade documentation

Asked by Lei Hang on 2020-07-05

Dear all,

The script of periodic simple shear is as following:
https://gitlab.com/yade-dev/trunk/blob/master/doc/sphinx/tutorial/04-periodic-simple-shear.py

My questions:
1.Does the “if 0” in line 82 mean the following script (for b in O.bodies: b.state.blockedDOFs='XYZ' b.state.angVel=(0,0,0)) will never be executed? If we change it to "if 1", the following script will be always executed?

2.In line 85(b.state.blockedDOFs='XYZ'),it blocks X,Y,Z rotations of spheres. Why in line 87 (b.state.angVel=(0,0,0)) still set the angle velocity to be 0? Isn't it blocking X,Y,Z rotations of spheres equivalent to the angle velocity being 0?

3.What's the meaning of "if stress[2,2]!=0 else 0" in line 112?

4.The former content of the script ( b.state.blockedDOFs='XYZ', b.state.angVel=(0,0,0)) blocks the rotation of the particles. Does the rotation of the particles equal to 0? Why it still set "Gl1_Sphere.stripes=True" to show rotation of particles?

Many thanks in advance!

## Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
 Revision history for this message Jan Stránský (honzik) said on 2020-07-05: #1

Hello,

> 1...

yes

> 2.... Why in line 87 (b.state.angVel=(0,0,0)) still set the angle velocity to be 0? Isn't it blocking X,Y,Z rotations of spheres equivalent to the angle velocity being 0?

setting state.blockedDOFs does NOT modify state.vel or state.angVel.
It blocks the degree of freedom from being influenced by interactions and the value of state.vel or state.angVel are actually preserved (with current value).

> 3.What's the meaning of "if stress[2,2]!=0 else 0" in line 112?

this is "python inline if-else" 
tanPhi = (stress[0,2]/stress[2,2]) if stress[2,2] != 0 else 0
could be rewritten as
###
if stress[2,2] != 0:
tanPhi=(stress[0,2]/stress[2,2])
else:
tanPhi = 0
###
Why it used here:
- it is shorter
- the longer way could not be used in plot.addData function

> 4....

see point 2

cheers
Jan

 Revision history for this message Lei Hang (h-stone) said on 2020-07-05: #2

Thank you for your quick answers!

Some questions still confuse me. The script of periodic simple shear is as following：
https://gitlab.com/yade-dev/trunk/blob/master/doc/sphinx/tutorial/04-periodic-simple-shear.py

1. Why it add"!" behind the "stress[2,2]"? （If it means factorial, non-negative factorial is greater than or equal to one）

2.In my opinion, the script in line 116 (b.shape.color=scalarOnColorScale(b.state.rot().norm(),0,pi/2.)) means the color of the variable will change according to the value of the variable compared to 0 and pi/2. But I can't relate it to the specification(yade._utils.scalarOnColorScale((float)x[, (float)xmin=0[, (float)xmax=1]]) → Vector3). What's the meaning of "((float)x[, (float)xmin=0[, (float)xmax=1]]) "

Many thanks!!!

 Revision history for this message  Jan Stránský (honzik) said on 2020-07-05: #3

> 1. Why it add"!" behind the "stress[2,2]"? （If it means factorial, non-negative factorial is greater than or equal to one)

"!=" is Python operator for inequality 
stress[2,2]!=0
means stress[2,2] is not equal to zero. Compare to
stress[2,2]==0
which means stress[2,2] is zero

> 2 ... b.shape.color=scalarOnColorScale(b.state.rot().norm(),0,pi/2.)) means the color of the variable will change according to the value of the variable compared to 0 and pi/2.

yes, the color of body 'b' will change according to the value of b.state.rot().norm() relative to the color scale from 0 to pi/2

> 2 ... But I can't relate it to the specification

yade._utils.scalarOnColorScale((float)x[, (float)xmin=0[, (float)xmax=1]]) → Vector3

components:
(float)x ... first parameter, named x (which is not much important), of type float (real number)
[ ... means optional argument
(float)xmin=0 ... second parameter, named xmin, of type float, with default value 0 (if you do not specify it)
[ ... another optional argument
(float)xmax=1 ... third parameter, named xmax, of type float, with default value 1 (if you do not specify it)
→ Vector3 ... the function returns Vector3 instance

In this specific example:
x = b.state.rot().norm()
xmin = 0
xmax = pi/2

cheers
Jan

 Revision history for this message Lei Hang (h-stone) said on 2020-07-05: #4

Thanks Jan Stránský, that solved my question.

To post a message you must log in.