About periodic simple shear
Hello, I am a new user for yade. When I study the yade documentation about periodic simple shear, I don't understand the meaning of "if 0:..., else:...". The detailed code is following:
from yade import pack,plot
# the "if 0:" block will be never executed, therefore the "else:" block will be
# to use cloud instead of regular packing, change to "if 1:" or something similar
if 0:
# create cloud of spheres and insert them into the simulation
# we give corners, mean radius, radius variation
sp=pack.
sp.makeCloud(
# insert the packing into the simulation
sp.toSimulation
else:
# in this case, add dense packing
O.bodies.append(
pack.regularHex
,!1))
)
Please help me understand the grammar of "if 0:..., else:...". Thanks a lot!
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:
Related bugs
Related FAQ:
None Link to a FAQ
Revision history for this message
|
#1 |
Hello,
> I am a new user for yade
welcome :-)
next time please provide also a link to the script
This pattern is to easy switch between two different scenarios
Suppose:
###
if 0:
createLooseP
else:
createDenseP
###
As it is, with "if 0:", is equivalent to (as the "if 0:" block is never executed and therefore "else" is always executed):
createDensePack
If you change it to
###
if 1:
createLooseP
else:
createDenseP
###
then it is equivalent to (as "if 1" is always executed and therefore "else" is never executed):
createLoosePack
This way you can choose one scenario or the other just by altering 0/1 after the "if" keyword.
HTH
cheers
Jan
Revision history for this message
|
#2 |
Thanks for your quick help Jan! But I still don't understand (as the "if 0:" block is never executed and therefore "else" is always executed). The "if 0:" block is never executed, why we add the "if 0:"block? why we not just write the content of "else:" block? The same in "if 1:..., else:..."block, why we not just write the content of "if 1:"?
Thank you for your help!
Revision history for this message
|
#3 |
Because you can easily choose one scenario or the other just by replacing 0 with 1 or vice versa.
The value "0" or "1" is not hardcoded, it is there to enable quick and easy selection.
If you know your final script needs just the "else" scenario, then just write that one.
But in the case of the chosen script, you can choose loose packing or you can choose densePacking.
If you let "if 0:", then you are using loose packing
If you change it to "if 1:", then you are using dense packing.
Then if you change it back to "if 0:", you use loose packing.
Then ...
everything by changing just one symbol. That is the meaning of it.
You could modify it e.g. in a more readable (but more verbose at the same time) code:
###
useLoosePacking = True
useDensePacking = False
# check that exactly one value is set to True
assert useLoosePacking or useDensePacking is True # at least one is True
assert useLoosePacking and useDensePacking is False # not both are True
#
if useLoosePacking:
createLooseP
elif useDensePacking:
createDenseP
###
cheers
Jan
Revision history for this message
|
#4 |
Thanks Jan Stránský, that solved my question.
Revision history for this message
|
#5 |
Hello,
When I study the yade script about periodic simple shear test, I don't understand some places. The periodic simple shear script link is following:
https:/
I want to ask several questions:
1.What is the meaning of "O.cell.
2."pack.
3.What is the meaning of "O.cell.
4.What is the meaning of "O.cell.trsf[0,2]" in the "checkDistorsion" part? What do the numbers in the "trsf" mean?
5.In "plot.addData(
Thank you very much for your kindly help!
Revision history for this message
|
#6 |
Hello,
first of all, I am not sure if periodic simulations are a good very first starting point to learn Yade..
The previous scripts are OK?
> 1.What is the meaning of "O.cell.
it assign Matrix3(2,0,0, 0,2,0, 0,0,2) object to O.cell [1] as its hSize [2] attribute
> What is the meaning of the numbers in the Matrix?
"Base cell vectors (columns of the matrix)" [2].
In this case, diagonal terms are "normal size" (i.e. 2x2x2), zero non-diagonal terms means no skew and no rotation
(non-diagonal terms control skew and/or rotation)
> 2."pack.
color of resulting particles
(in ideal case, the documentation should tell that **kw are keywords passed to utils.sphere function. You are welcome to improve the documentation! :-)
> 3.What is the meaning of "O.cell.
you assign Matrix3(-.1,0,0, 0,-.1,0, 0,0,-.1) object to O.cell [1] as its hSize [3] attribute.
The components are components of velocity gradient (in matrix form).
In this case, only diagonal negative terms it is isotropic compaction.
> What is the meaning of the numbers in the Matrix?
components of velocity gradient [4]
The indexing of the components is very similar to those of deformation gradient (O.cell.trsf), see below.
> In the "Checkstress()" part, it changes to "O.cell.
now it is changed to shear:
diagonal terms are zero = no change of size
non-diagonal terms are non-zero = some shear or rotation (in this case only one, xz, non-diagonal term is non-zero = shear in xz plane).
> 4.What is the meaning of "O.cell.trsf[0,2]" in the "checkDistorsion" part? What do the numbers in the "trsf" mean?
trsf is deformation gradient [5] of the cell
trsf[0,2] means its xz shear part (see below)
> stress=
> 5.In "plot.addData(
stress here is matrix form of Cauchy stress tensor [6]. Indices are 0=x, 1=y, 2=z
stress[2,2] means stress_zz, i.e. normal z component
stress[0,2] means stress_xz, i.e. shear xz component
The indices corresponds to those of hSize, velGrad and trsf (where it is related to strain/strain-rate counterpart)
cheers
Jan
[1] https:/
[2] https:/
[3] https:/
[4] https:/
[5] https:/
[6] https:/
Revision history for this message
|
#7 |
Thank you for your answer! I have some other questions.
1. What is the meaning of the numbers(2,3,4,5) in "hsize[
2.
"> In the "Checkstress()" part, it changes to "O.cell.
now it is changed to shear:
diagonal terms are zero = no change of size
non-diagonal terms are non-zero = some shear or rotation (in this case only one, xz, non-diagonal term is non-zero = shear in xz plane)."
Here, how to determine it shears in xz? Why is it shearing rather than rotating? Why is it in the xz plane rather than in other planes?
Revision history for this message
|
#8 |
Hello,
> O.cell [1]
> hSize [2]
> "Base cell vectors (columns of the matrix)" [2].
> O.cell [1]
> hSize [3]
> components of velocity gradient [4]
> trsf is deformation gradient [5]
> stress here is matrix form of Cauchy stress tensor [6].
This is the standard approach on this forum to "cite" references summarized at the end of the message (or at the end of a previous message in the thread)
Full links in the text looks messy and also this way you can easily reference one link at multiple places (like O.cell here)
> Does "hsize" mean the size of cell?
no, see [2] :-), where it states that hSize is "Base cell vectors (columns of the matrix)". I.e. vectors of the edges of the cell.
> Does "diagonal terms" mean the size of cell?
In case of diagonal matrix, the diagonal terms represent size. In general case not.
> O.cell.
> Here, how to determine it shears in xz?
> Why is it in the xz plane rather than in other planes?
because the only non-zero term is at index (0,2), corresponding to xz (0=x,2=z) shear component, which is shear in xz plane.
> Why is it shearing rather than rotating?
just because it is..
see e.g. [7], section "2D Transformations" (or google "2x2 matrix mapping scale skew rotation"). It is for 2D, which easier to understand and does not differ from 3D much.
velGrad is "roughly" (in "small strain sense") time derivative of deformation gradient (see [4] for full definition and relation).
cheers
Jan
Revision history for this message
|
#9 |
Thanks Jan Stránský, that solved my question.
Revision history for this message
|
#10 |
Hello
Excuse me. I find I don't understand the non-zero term is at index(0,2) in the answer. How to associate the non-zero term with the index? Thanks so much!
"> O.cell.
> Here, how to determine it shears in xz?
> Why is it in the xz plane rather than in other planes?
because the only non-zero term is at index (0,2), corresponding to xz (0=x,2=z) shear component, which is shear in xz plane."
Revision history for this message
|
#11 |
If the O.cell.
Revision history for this message
|
#12 |
> How to associate the non-zero term with the index?
The Matrix3 is (xx, xy, xz, yx, yy, yz, zx, zy, zz), "one row" of the form:
xx xy xz
yx yy yz
zx zy zz
> If the O.cell.
you have no shear here.
the first (the only non-zero) element is xx = normal x direction, so this correspond to stretching (enlargement) along x axis.
cheers
Jan
Revision history for this message
|
#14 |
Thanks Jan Stránský, that solved my question.
Revision history for this message
|
#15 |
Hi Jan Stránský!
I'm hoping to hi-jack this question thread and expand upon the amazing discussion you and Lei Hang have had above. Seriously, the above conversation was an amazing review of the opensource code.
To start off my questions, why does the code first simulate a constant isotropic compression of O.cell.
Does this step ultimately cause the periodic boundary condition to be flush with the particle regularHexa pack? Because without it, the periodic boundary condition seems to simulate a regularHexa pack within the representative volume element but it is suspended inside of it at iteration 0.
I am asking because I am interested in a periodic simple shear simulation as well ... I just cannot connect the dots on why this step is logical. Is isotropic compression necessary prior to the simple shear of O.cell.
Another question I have is about the section:
plot.addData(
# color particles based on rotation amount
The outputted data takes on the form (via columns):
# exz i sxz szz tanPhi
Based on the conversation above, I recognize that sxz = shear stress in the xz plane and szz = normal stress in the zz direction.
I am confused about exz, i, and tanPhi:
To my understanding, exz represents the current transformation matrix of the cell at the given iteration step. Would this definition be analogous to the cell strain or deformation at a given time step?
I am fairly lost on what the data column 'i' could represent - so no guesses there.
Finally, I am curious about tanPhi. For my simulations I have the particle rotations blocked via:
b.state.
Why is a change in angle being outputted when the rotational DOFs are being blocked? Does tanPhi represent something else here?
Thanks for all of the help Jan. Your assistance has and always is, greatly appreciated.
Cheers,
Kieran
Revision history for this message
|
#16 |
Hello,
> why does the code first simulate a constant isotropic compression of O.cell.
> Is isotropic compression necessary prior to the simple shear of O.cell.
Because the author decided it :-)
Probably because it corresponds to simulated real situation.
Definitely it is not necessary.
> Does this step ultimately cause the periodic boundary condition to be flush with the particle regularHexa pack? Because without it, the periodic boundary condition seems to simulate a regularHexa pack within the representative volume element but it is suspended inside of it at iteration 0.
Sorry, here I am lost...
Could you please reword the question and idea behind?
> exz ... Would this definition be analogous to the cell strain or deformation at a given time step?
In this very specific case yes, exz=O.cell.
BUT, in general, be careful with mapping O.cell.trsf to strain (!)
> I am fairly lost on what the data column 'i' could represent
do you mean i=O.iter?
If yes, then "i" is iteration number
> Finally, I am curious about tanPhi.
> Why is a change in angle being outputted when the rotational DOFs are being blocked? Does tanPhi represent something else here?
Even you have rotational DOFs of particle blocked, the cell as a whole deforms (after all you apply some shear).
Anyway, here,
tanPhi=
so it is not a geometric angle, but some stress measure.
To me it seems like reformulated cohesion-less (c=0) Mohr-Coulomb condition
shear stress = normal stress * tan(phi)
tan(phi) = shear stress / normal stress
so you basically output tangent of friction angle.
cheers
Jan
Revision history for this message
|
#17 |
Hi Jan,
Thank you for the explanations! Let's see how I can reword my question above.
> Does this step ultimately cause the periodic boundary condition to be flush with the particle regularHexa pack? Because without it, the periodic boundary condition seems to simulate a regularHexa pack within the representative volume element but it is suspended inside of it at iteration 0.
During the compression portion of the simulation, I observe how the representative volume element (RVE) shrinks inward to the particle clump / regularHexa pack. Once this is complete, or the limitMeanStress is reached, the xz-plane shear begins. So back to when I asked above if this step is necessary for the PBC to be flush with the clump, I really was asking if we need to isotopically compress the RVE in order to shear the cube.
It sounds like it doesn't need to occur - which is promising to hear. I was also able to start the RVE shear simulation by setting the limitMeanStress=0 so it starts right away.
Revision history for this message
|
#18 |
The compression stage is not necessary, of course.
It depends on what you want to simulate. The original script probably simulated some experiment with prestress and one outcome is tanPhi = shear stress / normal stress (which is meaningless for zero normal stress).
If you need to model only shear, then model only shear.
For some cohesive materials, also pre-tension + shear could be applied :-)
It is really up to you.
cheers
Jan