Export the positions of particles and their velocities in Rocky
Hello,
I want to do some post processing with Rocky data. I want to export the positions of the particles during the simulation and also their velocities to create gradients.
I found these codes in the manual.
This is the code for the positions:
study = app.GetStudy() particles = study.GetParticles() for particle in particles.IterParticles(time_step=10): print(particle.x, particle.y, particle.z) # Sample output: # (-5.833559188701166, 0.7380019118190704, 0.19294910836680973) # (-5.1383928383823845, 0.6290253809025952, -0.14368919420973403)
and this is the code for the velocities:
particles.GetGridFunction('Absolute Translational Velocity').GetArray(time_step=10) # Sample output: # array([ 2.56413788, 4.46129788, 3.96977314, 3.47665254 ])
The codes work when I run them in the python shell window.
But I want to save the data as csv files and not just display it. I would also like to have the data from each time step and not only from one. And this code should be part of the PrePost Scripts, so I need to save it in a separate py-file.
Thank you
Comments
-
I was able to solve it with
with open(output_file, 'w', newline='') as csvfile:
and
writer.writerow([x, y, z, velocity])
and also a for loop to save the data in the csv file.0