Vtp/vtu files in DEM/PIC simulations

Hi,
In DEM and PIC simulations, we generally write particle’s information in vtp/vtu files. The information is written in binary format. However, these files can be processed with ParaView.
I would like to read those files and count the number of particles at a particular time instant. Is that possible via a program?

How can I compile codes at visualization_tools/Paraview and use the executable to read the information in vtp/vtu files?

Thank you.

MFiX can write either Binary or ASCII format data into VTP file. If you want to directly see the particle data (including number of particles), you can output particle data into ASCII format and can open with any text reader.

Try:
PRINT_DES_DATA = .T.
VTP_DIR = ‘vtp’
spx_dt(1) = 0.005
spx_dt(2) = 0.005
spx_dt(3) = 0.005
spx_dt(4) = 0.005
spx_dt(5) = 100.0
spx_dt(6) = 100.0
spx_dt(7) = 100.0
spx_dt(8) = 100.0
spx_dt(9) = 100.0
spx_dt(10) = 1.0
spx_dt(11) = 1.0

1 Like

Hi Xi,
Thank you for your reply. We use
PRINT_DES_DATA = .True. - to write discrete particle data
VTP_DIR = ’ ’ - set the directory to store vtp files

In vtp_mod, there is no keyword to change the encoding from raw to ascii
Line 1020 in vtp_mod.f ( WRITE(BUFFER,*)’ AppendedData encoding=“raw”’ )
Therefore, I think the above mentioned two keywords did not write the data in ascii format.

Thanks

If you already have the VTP files written out, you can read them using VTK (the underlying library that Paraview uses). I prefer to use the Python wrapped version of VTK, which is what the GUI uses to read and show the VTP and VTU files (and the particle count)

Relevant code:

import vtk
import glob
import os
import sys

fdir = 'path/to/dir/with/vtps/'

# check directory
if not os.path.exists(fdir):
    print('Error: Path does not exist:', fdir)
    sys.exit()

# create reader
points = vtk.vtkXMLPolyDataReader()

# loop over all vtp files
for fname in sorted(glob.glob(os.path.join(fdir, '*.vtp'))):
    print('Reading:', fname)
    points.SetFileName(fname)
    points.Update()

    # print the arrays
    data = points.GetOutput()
    point_data = data.GetPointData()

    # loop over all data arrays
    for i in range(point_data.GetNumberOfArrays()):
        array = point_data.GetArray(i)
        print(i, point_data.GetArrayName(i), '\t',
              'Points:', array.GetNumberOfTuples(),
              'Components:', array.GetNumberOfComponents(),
              )

Justin,
Thank you very much.
I have VTP files. I will use this python code to get the number of particles.
In one of the gas-solid flows, I considered two solid-phase particles. I will make changes to the code if I have get the count of each solid phase particles.
Thank you.