contact forces in VTKrecorder

Asked by Eleni Gerolymatou on 2021-03-13

I'm sorry if this is trivial, but I have been fighting with it for a while. I need to export all spheres and contact interactions (forces and torques) in an assembly. I am using Yade daily from 2020-12-08 and VTKRecorder(fileName='3d-vtk-',recorders=['all'],iterPeriod=100). I cannot seem to find in interactions the forces and torques as vectors and the particles involved in each contact. How can I access this information?

Question information

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

Hello,
for this kind of questions, please always provide a MWE [1]
E.g. for the code below, I can load "3d-vtk-intrs.1.vtp" and color them by "forceN".
For "fancy" VTK exporting, you can try export.VTKExporter [2].
cheers
Jan

###
O.bodies.append([
    sphere((0,0,0),2),
    sphere((1,0,0),2),
    sphere((0,1,0),2),
])
O.step()
vtk = VTKRecorder(fileName='3d-vtk-',recorders=['all'],iterPeriod=1)
vtk()
###

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

(I failed to answer to the correct adress and now my answer is in yade-users list, sorry - duplicating here)

Hi Eleni!

Don't yo get some "*.intrs.N.vtp" file together with the *.spheres.N.vtu's and others?

Do you want to export for visualization or for acquiring data? It is a bit unusual to look for "particles involved in each contact" in some vtk.

Cheers

Bruno

Eleni Gerolymatou (elenig) said : #3

Thanks for the quick reply Jan and sorry for the lack of an MWE, I missed the instructions.
I am only partly interested in the visualization and was hoping to avoid using the exporter and the recorder, but of course that is fine. What I need is a list of the contacts with contact force and torque vectors and the contacting particles. Am I right that recorder cannot provide this and I should use exporter instead? Where can I find what 'dictionary' includes?

As a workaround I found that
namefor='force')+'.txt'
a=open(namefor,'w')
for b in O.interactions:
 a.write(str(b.id1)+' '+str(b.id2)+' '+str(b.phys.normalForce[0])+' '+str(b.phys.normalForce[1])+' '+str(b.phys.normalForce[2])+' '+str(b.phys.shearForce[0])+' '+str(b.phys.shearForce[1])+' '+str(b.phys.shearForce[2])+' '+str(b.phys.moment_bending[0])+' '+str(b.phys.moment_bending[1])+' '+str(b.phys.moment_bending[2])+' '+str(b.phys.moment_twist[0])+' '+str(b.phys.moment_twist[1])+' '+str(b.phys.moment_twist[1])+'+\n')
a.close()

works, but maybe this is not optimal?

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

The VTK* stuff exports data to the VTK format suitable for visualizing in Paraview. So all the data are there, but if you want to do something other with them, it might not be the best choice of data format.

> Am I right that recorder cannot provide this and I should use exporter instead?

It seems like that

> Where can I find what 'dictionary' includes?

what is 'dictionary'?

> As a workaround I found that
> ...
> works, but maybe this is not optimal?

I think it is fine, especially if it works.
I would write it differently, but time spent on rewriting may easily make the approach not optimal :-D

cheers
Jan

PS: how I would write it. I haven't tested it and also would work only with newer Python versions
#
def interaction2line(i):
    fnx,fny,fnz = i.phys.normalForce # similarly for other vector quantities
    line = f"{i.id1} {i.id2} {fnx} {fny} {fnz}\n"
    # f"..." is "f-string", you can use "old-style" % or .format() replacement
    return line
lines = [iteraction2line(i) for i in O.interactions]
with open("force.txt","w") as f: # no need to close it if you use 'with'
    f.write("some heading, describing columns\n")
    f.writelines(lines)
###

I suspect you have definitely no reason to use any vtk-related export. Let you explain what you need.
B

Eleni Gerolymatou (elenig) said : #6

Ideally I would like to export all the contact information both as txt and to visualize in Paraview, but visualization is secondary to me. I will go with Jan's solution and only use exporter at larger intervals for viewing. Thanks a lot!

Eleni Gerolymatou (elenig) said : #7

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