Export VTK files to txt files

Asked by Yor1

Hello Yade users,

I want to obtain the data saved in the sphere's vtk files (velocity, forces, stress field in the spheres) as a text file (.txt).
So i want to know if it is possible to export the vtk files to text files.

Best regards.
Jabrane.

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jérôme Duriez (jduriez) said :
#1

Hi,

I do not know how to convert directly vtk files into text files, but you have a straightforward method using just Python commands in order to directly export YADE variables into text files.

I guess you know how to access the relevant variables in YADE (e.g. b.state.vel for the velocity), and googling input/output Python commands will tell you how to create an external text file from these variables.

Jerome

Revision history for this message
Hicham BENNIOU (benniou-hicham-deactivatedaccount) said :
#2

Hi,

Jérôme is right, you can export all the relevant variables directly from Python by writing them into a text file.

If you still need to write your vtk files in "clear", take a look here, this should be a good start [1]

[1] : http://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python

Hicham

Revision history for this message
Yor1 (jabrane-hamdi) said :
#3

Hello Jérôme and Hicham,

Thank you for your response.
So i have to export my results in txt files directly.

In this case, i want to export my variables in txt files every 10000 iterations like my vtk files, is it possible ?

Best regards.
Jabrane.

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

Hi Jabrane,

using PyRunner:

##############
def saveMyDate():
   ... # code creating a file and writing your desired data into it

O.engines = [
   ...
   PyRunner(iterPeriod=10000,command='saveMyData()'),
]
##############

cheers
Jan

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#5

Not sure it will answer the real question but for the sake of completeness, a quick remark: the vtk files are already text files.
I think the .vtu have some kind of binary encoding but all the vtk I've seen from yade are readable ASCII files.
Bruno

Revision history for this message
Yor1 (jabrane-hamdi) said :
#6

Hello Jan and Bruno,

Finally i use these lines in the recorder to obtain the text files peridically :

if (O.iter%1000==302):
      f = open(str(O.iter)+'_data_spheres', 'w')
      for b in O.bodies:
 if (type(b.shape)==Sphere):
   f.write('{} {} {} {} {} {} {} {} {} {} {} {}\n'.format(b.state.pos[0],b.state.pos[1],b.state.pos[2],b.state.vel[0]*0.1*utils.PWaveTimeStep(),b.state.vel[1]*0.1*utils.PWaveTimeStep(),b.state.vel[2]*0.1*utils.PWaveTimeStep(),b.state.vel[0],b.state.vel[1],b.state.vel[2],s[b.id][0,0],s[b.id][1,1],s[b.id][2,2]))
      print f

I use this condition "if (O.iter%1000==302)" because my vtk files are enumerated like this : 40302, 41302, 42302 etc ...

Best regards.
Jabrane

Can you help with this problem?

Provide an answer of your own, or ask Yor1 for more information if necessary.

To post a message you must log in.