How to make VTK file of relative particle rotation angle from state1 to state2

Asked by Leonard

Hi,

I'd like to ask that is it possible to output VTK file of relative particle rotation angle from state1 to state2 by importing samples (or txt files).

The motivation is: I carried out triaxial compression test and I have saved samples at many strain levels (e.g., at axial strain 1%, 2% ...). I would like to invesitgate the relative particle rotation angle between any of two states I am interested in, and visualise it in paraview.

If it is possible, I would like to ask that (1) how to calculate the relative rotation angle of a sphere between two states? (2) how to write these information into VTK so that it can be visualised in paraview?

Thanks
Leonard

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 :
#1

Hello,

> (1) how to calculate the relative rotation angle of a sphere between two states?

see [1]:
###
   relOri = state1.ori.conjugate()*state2.ori
   axis,angle = relOri.toAxisAngle()
###
Works only for "small rotations".
There is a possibility, that the particle may be "rolled" and the "rolled" 2*pi rounds are not counted (orientation is equal).
See [1] and links therein for possible solutions.

> (2) how to write these information into VTK so that it can be visualised in paraview?

use VTKExporter [2]

Cheers
Jan

[1] https://answers.launchpad.net/yade/+question/692057
[2] https://yade-dem.org/doc/yade.export.html#yade.export.VTKExporter

Revision history for this message
Leonard (z2521899293) said :
#2

Hi Jan,

Thanks for your reply.

I got the solution for each individual question. But I am not clear how to combine the two.

If I understood correctly, for using VTKExporter, it is something like:

vtkExporter.exportSpheres(ids='all',what=[('id',"b.id"),('ori','b.state.ori'),('radius',"b.shape.radius")])

It seems that the above code can only save the variables at one state. i.e. not some value calculated from two states, such as the relative rotation angle between state1 and state2.

What I have in my mind is: storing the rotation angle (calculated by axis,angle = relOri.toAxisAngle()) into a VTK file. Something like:

step1: from the sample at state1 --> output a txt file (lets name it txt1) which has b.ori for each particle.
step2: from the sample at state2 --> output a txt file (txt2) which has b.ori for each particle.
step3: calculating relOri = state1.ori.conjugate()*state2.ori and axis,angle = relOri.toAxisAngle() by using txt1 and txt2, then I have the angle for each particle.
step4: store that angle into a VTK file which can be visualised in paraview

Do you have any ideas?

Thanks!

Leonard

Revision history for this message
Karol Brzezinski (kbrzezinski) said :
#3

Hi Leonard,

I think that you can use 'rot()' method of body state or Jan's proposal in VTKExporter.

######## MVE
from yade import export
exporter = export.VTKExporter('tmp-')
s = O.bodies.append(sphere((0,0,0),1))

#set current state as reference
setRefSe3()
# set angular velocity
O.bodies[s].state.angVel = (0,0,1)

# rotate
O.run(1000,wait = True)

# export
exporter.exportSpheres(ids='all',what=dict(rotation_method_1 = 'b.state.rot()',rotation_method_2 = '(b.state.refOri.conjugate()*b.state.ori).toRotationVector() '))
######

Cheers,
Karol

Revision history for this message
Jan Stránský (honzik) said :
#4

a MWE for a case where you have the computed values
###
from yade import export
import builtins # to store "data" and access them from a string command

spheres = [
    sphere((0,0,0),1),
    sphere((3,0,0),1),
    sphere((6,0,0),1),
]
O.bodies.append(spheres)

data = [ # e.g. angle
    1,
    2,
    3,
]
builtins.data = data # make data "global", visible in export module

vtk = export.VTKExporter("test-angle")
vtk.exportSpheres(what=dict(angle="data[b.id]"))
###

Cheers
Jan

Revision history for this message
Leonard (z2521899293) said :
#5

Hi Jan and Karol,

Thanks for your MWEs.

Because I use an old version of Yade (2018.02b), consequently executing the MWE gives error: ValueError: too many values to unpack[1]. Thereby, I need to adapt the MWE to my old verison.

I successfully adapted Karol's MWE:
# exporter.exportSpheres(ids='all',what=dict(rotation_method_1 = 'b.state.rot()',rotation_method_2 = '(b.state.refOri.conjugate()*b.state.ori).toRotationVector() '))
###### change to
exporter.exportSpheres(ids='all',what=[('rotation_method_1','b.state.rot()'),('rotation_method_2','(b.state.refOri.conjugate()*b.state.ori).toRotationVector()')])

But I didn't make it for Jan's MWE. What I tried is:
from yade import export
import builtins # to store "data" and access them from a string command

spheres = [
    sphere((0,0,0),1),
    sphere((3,0,0),1),
    sphere((6,0,0),1),
]
O.bodies.append(spheres)

data = [ # e.g. angle
    1,
    2,
    3,
]
builtins.data = data # make data "global", visible in export module

vtk = export.VTKExporter("test-angle")
# vtk.exportSpheres(what=dict(angle="data[b.id]")) ## change it to
vtk.exportSpheres(ids='all',what=[('ids','b.id'),('pos','b.state.pos'),('angle','data[b.id]')])

It returns the following error:
Traceback (most recent call last):
  File "/usr/bin/yade", line 182, in runScript
    execfile(script,globals())
  File "Jan_MWE.py", line 22, in <module>
    vtk.exportSpheres(ids='all',what=[('ids','b.id'),('pos','b.state.pos'),('angle','data[b.id]')])
  File "/usr/lib/x86_64-linux-gnu/yade/py/yade/export.py", line 431, in exportSpheres
    test = eval(command) # ... eval one example to see what type (float, Vector3, Matrix3) the result is ...
  File "<string>", line 1, in <module>
NameError: name 'data' is not defined

Could you please give some instructions?

Thanks
Leonard

[1]https://answers.launchpad.net/yade/+question/695966

Revision history for this message
Jan Stránský (honzik) said :
#6

What python version do you use?

Revision history for this message
Leonard (z2521899293) said :
#7

Hi Jan,

It is python 2.7.17. Obtained by:

In [1]: import sys; print(sys.version)
2.7.17 (default, Nov 28 2022, 18:51:39)
[GCC 7.5.0]

Thanks
Leonard

Revision history for this message
Jérôme Duriez (jduriez) said :
#8

With Python 2 and Yade 2018, and considering how fast Yade is evolving, did you consider updating your system ? (sorry for the comment if that's impossible for you)

Revision history for this message
Best Jan Stránský (honzik) said :
#9

For python 2, change the "builtin" approach from

### python 3
import builtins
builtins.data = data
###

to

### both python 3 and python 2
__builtins__.data = data # note: no import
###

Cheers
Jan

Revision history for this message
Leonard (z2521899293) said :
#10

Hi,

Yes, that is a good idea and I am moving to the latest version of Yade.
Just because lots of project data have been obtained in the old version, I would like to try whether it is possible to make use of them.

Thanks,
Leonard

Revision history for this message
Leonard (z2521899293) said :
#11

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