How to export relative velocity of spheres to Paraview

Asked by Chien-Cheng Hung on 2020-03-10

Hi all,

I am simulating direct shear experiments and I would like to visualize the relative velocity of all interacted spheres.
I've tried to record the interaction of bodies using VTKRecorder but it seems there is no relative velocity in this recorder.

So I am wondering how do I export the relative velocity of all interactive spheres to Paraview to visualize it?
Thanks!

Chien-Cheng

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2020-03-23
Last query:
2020-03-23
Last reply:
2020-03-11
Jan Stránský (honzik) said : #1

Hello Chien-Cheng,

> the relative velocity of all interacted spheres.

relative velocity with respect to what? relative velocity of interacting bodies for all interactions?

you can use export.VTKExporter [1]
###
vtk = export.VTKExporter()
vtk.exportSpheres(what=dict(velRelative="b.state.vel"))
vtk.exportInteractions(what=dict(velRelative="i.phys.normalForce"))
###
above, b.state.vel and i.phys.normalForce is only illustrative, needs to be replaced by actual formula for relative velocity
If you use older Yade version, the correct format might be list of tuples instead of dict: what=[("velRelative","b.state.vel")]

cheers
Jan

[1] https://yade-dem.org/doc/yade.export.html#yade.export.VTKExporter

Chien-Cheng Hung (chiencheng) said : #2

Hi Jan,

Thanks for your quick reply!

> relative velocity with respect to what? relative velocity of interacting bodies for all interactions?

Sorry I didn't describe clearly. But, yes, the relative velocity of interacting bodies for all interactions.
The relative velocity of the spheres that I want to obtain is described in ScGeom [1].

> above, b.state.vel and i.phys.normalForce is only illustrative, needs to be replaced by actual formula for relative velocity.

Can I get the formula for relative velocity [1] somewhere in Yade? Or I have to define one by myself?

Cheers,
Chien-Cheng

[1] https://yade-dem.org/doc/yade.wrapper.html?highlight=scgeom#yade.wrapper.ScGeom

Jan Stránský (honzik) said : #3

> Can I get the formula for relative velocity [1] somewhere in Yade? Or I have to define one by myself?

AFAIK you have to write it yourself..

you can write a function to it and call the function in exportInteractions / exportContactPoints, but as the commands are evaluated only locally, you have to "make the function global", e.g. using __builtin__ module (be very careful with this workaround not to overwrite some python basics, e.g. list etc.):
###
def relativeVelocity(interaction):
   i1,i2 = interaction.id1, interaction.id2
   b1,b2 = [O.bodies[i] for i in (i1,i2)]
   r1,r2 = [b.shape.radius for b in (b1,b2)]
   v1,v2 = [b.state.vel for b in (b1,b2)]
   ... # actual code comes here
   return relativeVelocity

import __builtin__ # or buitlins (2ithout underscores) in Python3
__builtin__.relativeVelocity = relativeVelocity

vtk.exportInteractions(what=..."relativeVelocity(i)"...) # now you can use relativeVelocity inside exportInteractions
###

cheers
Jan

Chien-Cheng Hung (chiencheng) said : #4

Hi Jan,

Thanks a lot!

> you can write a function to it and call the function in exportInteractions / exportContactPoints

Is it possible that instead of calling the function, I can make a list of data of relative velocity that is recognized in Paraview

Cheers,
Chien-Cheng

Best Jan Stránský (honzik) said : #5

> Is it possible that instead of calling the function, I can make a list of data of relative velocity that is recognized in Paraview

I am not sure i I got it correctly, but you can e.g. create a dict with (id1,id2) keys and read from it in exportInteractions, something like (not tested):
###
interactionsInfo = {}
for i in O.interactions:
   ... # some computations
   interactionsInfo[(i.id1,i.id2)] = someData
...
vtk.exportInteractions(what=dict(something="interactionsInfo[(i.id1,i.id2)]"))
# probably interactionsInfo would need the same builtin trick
###

cheers
Jan

Chien-Cheng Hung (chiencheng) said : #6

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