3D particle (n-body) celestial motion animation

Hello. I have c++ application where I am performing n-body gravitational motion simulations. I would like to generate x,y,z cartesian coordinates at discrete time values that can imported into Paraview for 3d viewing and animation of the particle trajectories together as a system of particles. I generate ascii data trajectory files currently with 1 file per particle. In a given txt file, each row of numeric values represents the x,y,z coordinates at a discrete periodic time value for that particle.

The following is an example result of two masses moving apart from the origin, where each row is the x,y,z coordinates at a different time value. Currently, I am not writing the time values to the trajectory files, but I could if that would benefit a workflow of importing and interpreting the data as temporal trajectories.

Mass1.txt:
0,0,0
1,1,1
2,2,2

Mass2.txt
0,0,0
-1,-1,-1
-2,-2,-2

I’ve spent a few hours google searching for answers and playing around with the Paraview interface and haven’t been able to determine a solution. If you know how to help me and can offer advice, I would appreciate your assistance.

My end goal as imagined would be to write my trajectory data to a file format readily consumed by a Paraview import process, and be able to interact with (rotate, zoom and pan around with the mouse) a rendering perspective of the particle positions statically at any time in their trajectory, as well as generate renderings of their motion across time as I interact with the pose/perspecive in the 3d environment.

Thank you

Welcome to the ParaView community, Troy!

What you want to do isn’t too hard in ParaView. First, you want to name your files sequentially, which you have already done. Note that if you have more than a few files, you’ll want to pad the file index with 0s so that ParaView sorts them correctly, e.g.

Mass001.txt
Mass002.txt

Mass050.txt

Next, you can load these files into ParaView as a series. Browse to the directory that has these file and you should be able to select Mass…txt. This will load the whole series of files as a time series. By default, ParaView will open these files with a delimited text file reader. Since you don’t have headers in these files, uncheck the Have Headers property in the Properties panel, like so:

image

Next, we need to convert these positions into something ParaView can display in the 3D view. Use the Table to Points filter to turn these XYZ data columns into 3D points. Set the X Column property to “Field 0”, the Y Column property to “Field 1”, and the Z Column property to “Field 2”, like so

image

Finally, let’s show these points in the render view. Click anywhere in the view with the bluish gray background to make it active. Now change the representation type to “3D Glyphs”
image

You should see arrows at the point locations. To change to spheres, find the Glyph Type property and change it to “Spheres”. You should see the following.

Let us know if you need any clarification or help!

I note that @cory.quammen’s solution assumes that each .txt file has all the data at a particular time step. This is how ParaView assumes data is lain out: one file per time step (at least for simple files like delimited text files).

However, @troywigton’s description sounds like each file has all the timesteps for a single mass, which is not what ParaView is expecting. The easiest solution would be to change the way you write out your text files. In the example you started this post with, you have two files for particles that go through 3 time steps. You would change that to have 3 files like this:

Mass_t001.csv:

0,0,0
0,0,0

Mass_t002.csv:

1,1,1
-1,-1,-1

Mass_t003.csv:

2,2,2
-2,-2,-2

(Note, I changed the filenames to have a .csv extension. ParaView doesn’t really care about the difference between txt and csv, but csv is the more typical extension for a delimited text file using commas for delimiters.)

Loading data from text files that have data for all timesteps is not directly supported by ParaView. This was asked previously — Use a time column of a CSV as timestep — but did not have a good solution.

Here is a solution that might work. First, add a time value column to your data. (You said in your initial description that you could do that.) Second, concatenate all of your files together. If that is not easy when generating, you can do it in *nix/mac with a simple cat command (e.g. cat Mass*.txt > Mass_all.csv). Third, load this file into ParaView and use the Table to Points filter as described by @cory.quammen. This will give you a point for all mass for all time. Finally, use the Threshold filter to extract the masses at the timestep you want. If you want to animate over time, use the animation view panel (ViewAnimation View) to add a track to animate the threshold value.

Thank you for your help. Here is the result after following your advice.

Here is the data format. One row per object. One file per time.
image