How to extract velocity data from fluid simulation

Hello,

I was wondering if anyone knows how to grab the velocity information from a fluid simulation. I noticed that there are bvel.gz files being saved in the fluid cache, but I’m not sure how to use those to get the velocity vectors at the vertices of the mesh. I’m hoping to get them in a format I can export such as in a .txt or .csv file. I would be able to create a Python script for that, but I just need to figure out how to get to the data first. Any input would be appreciated.

Thanks!

Nevermind, I was able to do this after some trial and error and some googling. The .bvel and .bobj list the velocity and mesh information, respectively, in binary format. You’re supposed to read 12 bytes (bits? I’m forgetting the difference) at a time, which show the 3 components of velocity or location (each component is 4 bytes). The first 4 bytes in the file list the number of vertices. Create a loop which iterates that many times for the lines after the first. Each loop should pick up 12 bytes at a time. Here’s an example:

“bvel_file” is just the unzipped file from what Blender outputs. If you import gzip into your script you don’t even have to unzip each file, you can just read it directly.

vertNumBytes_vel = bvel_file.read(4) # Read the first number to get the number of vertices, in binary
vertNum_vel = struct.unpack(“<l”, vertNumBytes_vel)[0] # Convert the binary number into a readable number
frame_vel = # Empty list to append the information for each vertex

for i in range(0, vertNum_vel): # The loop starting from the first line after the one that lists the number of vertices
vxb = bvel_file.read(4) # Grab the three components written in binary (vxb, vyb, vzb)
vyb = bvel_file.read(4)
vzb = bvel_file.read(4)
vx = struct.unpack(“f”, vxb)[0] # “Unpack” the binary information into a readable number.
vy = struct.unpack(“f”, vyb)[0] # Include the “[0]”, otherwise you’ll grab a list with one item in it for some reason
vz = struct.unpack(“f”, vzb)[0]
frame_vel.append([round(vx, 4), round(vy, 4), round(vz, 4)]) # Append a short list of 3 components at that vertex to the list for that frame

So this loop will create a large list which contains the information for each vertex. So a list of smaller lists basically, where u, v, and w are the x, y, and z components of velocity.

E.g. [[u1, v1, w1], [u2, v2, w2], [u3, v3, w3], … etc.]

I hope this helps someone! Let me know if you have questions.