VTKExporter -> exportFacets command

Asked by drasszkusz on 2021-03-10

Hi all!

I have a question about VTKExporter exportFacet command. The main goal is to export specified facets and forces, stresses, etc acting on them. I could export facets to vtk and open in paraview, but without the forces, stresses, etc. Here is the MWE:

vtk = export.VTKExporter(vtksave+'file-')
def vtkexporter():

Also a PyRunner is running in engines:


It works fine, but I have problem when i need to specify the what [1] command:

vtk.exportFacets(ids=facetid, what=dict(velocity='b.state.vel'))

The manual refers to see exportSpheres() [2], but its not very helpfull, cause I'm getting this error:
/home/dem/Yade/install/lib/x86_64-linux-gnu/yade-2020-04-23.git-6c442b0/py/yade/export.pyc in exportFacets(self, ids, what, comment, numLabel)
    489 outFile.write("\nCELL_DATA %d"%(nBodies))
    490 # see exportSpheres for explanation of this code block
--> 491 for name,command in what:
    492 test = eval(command)
    493 if isinstance(test,Matrix3):

ValueError: too many values to unpack

So what are the exact expressions that I have to use to save everything (coordnumber, forceLen, forceVec, stressLen, stressVec, torqueLen, torqueVec) like VTKRecorder do?

Thank you for your help!

[1] https://yade-dem.org/doc/yade.export.html?highlight=exportfacets#yade.export.VTKExporter.exportFacets
[2] https://yade-dem.org/doc/yade.export.html?highlight=vtkexporter#yade.export.VTKExporter.exportSpheres

Question information

English Edit question
Yade Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Jan Stránský (honzik) said : #1


it seems you are using and older version of Yade (you should have included the information [3] :-)
Previously, "what" parameter used to be a list/tuple of 2-length key-value tuples. It was changed to dict, as dict is more natural for the data structure [4].

vtk.exportFacets(..., what=[('velocity','b.state.vel')])
or for more quantities:
vtk.exportFacets(..., what=[('vel','b.state.vel'),('pos','b.state.pos'),('dspl','b.state.displ()')])


[3] https://www.yade-dem.org/wiki/Howtoask
[4] https://gitlab.com/yade-dev/trunk/-/commit/763208677a8043f99a2fb4ebe225608c2c8ff910

drasszkusz (drasszkusz) said : #2

Hi Jan!

Thank you for your answer! It works now. :)
Sorry, I forgot [3], I'm using Yade installed from source code 10 months ago.
Could you help me in how to export coordnumber, forceLen, forceVec, stressLen, stressVec, torqueLen, torqueVec using 'what' subcommand?

Thank you!

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

E.g. this way. Basically the code you would write in python to get the values, just it is a string and uses 'b' as the current body:

For further help, please provide a MWE [3] with a few facets, a few spheres (may be everything fixed = not moving for the sake of simplicity).
With information what the quantities are (lenForce = force magnitude? stress = forceMagnitude/area? stressLen = ???)


drasszkusz (drasszkusz) said : #4

Thank you Jan, I updated Yade and it works as dict now :) Here is an MWE for those who will have the same problem in the future:
def vtkexporter():
   vtk.exportFacets(ids=facetid, what=dict(vel='b.state.vel',pos='b.state.pos',dspl='b.state.displ()',coordnumber='len(b.intrs())',forceLen='O.forces.f(b.id).norm()',forceVec='O.forces.f(b.id)',stress='O.forces.f(b.id).norm()/b.shape.area'))

About lenForce, stress, stressLen, etc , I'm still figuring them out. According to [5], stressLen is the sum of normal and shear stresses and the norm of the summed value. So yes, Len is the magnitude. I don't know if stress='O.forces.f(b.id).norm()/b.shape.area' cause it is being retrieved from another file's algorithm with the following commands in[5]:

const Vector3r& stress = bodyStates[b->getId()].normStress;
const Vector3r& shear = bodyStates[b->getId()].shearStress;

I'm still searching that how are they calculated.


[5] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/VTKRecorder.cpp

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

Concerning stress, I see a few possible definitions (in the context of facets):
- force magnitude divided by are (result is scalar)
- force vector divided by area (result is vector)
- some stress tensor, just now I have no idea what would it be / how would it be computed..
So it depends on what you want to export :-)
Anyway, having the force, the rest should be easy

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

Concerning [5], the bodyStates is computed at [6] and IMO it is meant mainly for spherical (or some "volume") particles, not very suitable for facets (IMO!).

[6] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/VTKRecorder.cpp#L689

drasszkusz (drasszkusz) said : #7

Yeah, that's why i'm not 100% sure about these things. Anyway thank you for all your help! I will be okay from now on.