Search code examples
fortranvtkparaviewparticlespost-processing

Fortran ouput particle data to .vtu file for paraview


I am trying to write a Fortran subroutine to output (randomly positioned) particle data to a .vtu file for post-processing in Paraview. The program produces a file which is formatted as follows:

<?xml version="1.0"?>
<VTKFile type= "UnstructuredGrid"  version= "0.1"  byte_order= "BigEndian">                         
 <UnstructuredGrid>                                                                                 
  <Piece NumberOfPoints="6664" NumberOfCells="0">                                                   
   <PointData Scalars="Pressure" Vectors="Velocity">                                                
    <DataArray type="Float32" Name="Pressures" format="ascii">                                      
    ...    
    </DataArray>                                                                                    
    <DataArray type="Float32" Name="Density" format="ascii">                                        
    ...    
    </DataArray>                                                                                    
    <DataArray type="Float32" Name="Mass" format="ascii">                                           
    ...
    </DataArray>                                                                                    
    <DataArray type="Float32" Name="Scalarplot" format="ascii">                                     
    ...
    </DataArray>                                                                                    
    <DataArray type="Float32" Name="Velocity" NumberOfComponents="3" format="ascii">                
    ... ... ...
    </DataArray>                                                                                    
   </PointData>                                                                                     
   <Points> 
    <DataArray type="Float32" NumberOfComponents="3" format="ascii"> 
    ... ... ...
    </DataArray>                                                                                    
   </Points>                                                                                        
   <Cells>                                                                                          
    <DataArray type="Int32" Name="connectivity" format="ascii">                                     
    ...
    </DataArray>                                                                                    
    <DataArray type="Int32" Name="offsets" format="ascii">                                          
    ...  
    </DataArray>                                                                                    
    <DataArray type="Int32" Name="types" format="ascii">                                            
    ...       
    </DataArray>
   </Cells>
  </Piece>
 </UnstructuredGrid>
</VTKFile>

The code is based on the subroutine in the SPHYSICS program and the file format documentation.

Paraview loads the file but I cannot visualise the particles using their coordinates or any of the field variables. Could this be due to a problem with the .vtu file?

The scalarplot value is set to 1 for each particle and is probably unnecessary. I just included it in case I wanted the particles to be coloured differently at some point (probably should be a Float).

Does this have to contain Cell data? The connectivity and offesets have just been set to the particle/point number and the types have just been set to "1" for each particle/point. Could this be leading to the problem?


Solution

  • It turns out that there is nothing wrong with the format of the output above. The problem was with the format specifiers used on the "..." components. Some of these were specified using "*" which must have produced an inconsistent / incompatible output file. By specifying these specifically (e.g. "//TRIM(no_dim)//"(4X, E15.8))" for the coordinates), the file worked with Paraview. For those who are interested a .pvd file should also be written (which is file which points to the .pvu files) in order to produce an animation in Paraview.