Exporting fields in legacy VTK format with Octave/MATLAB

March 2021, Cremona, Italy


Hi folks!
This page deals with importing a mesh written in the SU2 format (created with GMSH) into Octave/MATLAB, then associating some fields to it, and finally exporting it in a legacy VTK format for visualizing in ParaView. I thought of putting the scripts here, in case they can be of some use to anyone.
The meshes will be made of triangles or quads. The scripts read such meshes, and locate for every element its neighboring points (you need such info for CFD solvers). The boundary elements are assigned a label "inlet", "outlet", "walls" or "sym". The script recognizes such labels and assigns an ID to the neighboring values according to that label (see the very beginning of the scripts).
Finally, the script associates to the mesh some simple scalar fields, such as a sin(x)+sin(y), and writes a legacy VTK file, with unstructured data format, containing the grid and the field (with "cell data" attribute).

Triangle mesh

So, you need to download these files: the Octave/MATLAB script, and the grid, put them in the same folder, and run the Octave script.
Octave/MATLAB script: read_tria_mesh_su2.m
Grid of triangular elements: simple_1.su2

The script will create a VTK file called "output.vtk", and once you open it in ParaView, you should see:

Quad mesh

Again, download the script and the meshes, run the script and then open the resulting file "output.vtk" with ParaView.
Octave/MATLAB script: read_quad_mesh_su2.m
Grid of quad elements (finer): cyl_mesh_finer.su2
Grid of quad elements (coarser): cyl_mesh.su2

This is what you should see:


And... that's it!

Back to Homepage