Search code examples
matlabcontourparaview

Plotting contour for irregular xy data with holes


I am stuck with this problem for the last two days and haven't found a solution so far. I have a data in the following format:

x1, y1, val1
..  ..  ..
..  ..  ..
xn, yn, valn

The values val1, ..., valn are the field quantities I obtain after simulation on a geometry as below.

enter image description here

Only the grey region is the domain of interest whereas the one in blue/dark blue is not (including the inverted L shaped blue region in the interior). Thus the x and y coordinates of the data are scattered/irregular and with large gaps due to the hole in my original geometry. Is there a way to get a filled contour plot for this data? Trying the following in Matlab gives me triangulation with triangles outside the original polygon. Also, it fills the holes which is not what I want.

x = data(:,1);
y = data(:,2);
z = data(:,3);

%
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
xi = dt.Points(:,1) ;
yi = dt.Points(:,2) ;
F = scatteredInterpolant(x,y,z);
zI = F(xi,yi) ;
trisurf(tri,xi,yi,zI) 

Another possibility was to import the data in ParaView and do filtering as Table-to-Points--> Delaunay Triangulation 2D. But this has the same problems as Matlab. The holes are not analytical to mask the unwanted interpolated regions with NaNs by using some mathematical expression.


Solution

  • Paraview seems to have the solution for this. Although I did not use finite elements to solve the pde, I could generate a finite element mesh inside GMsh for my geometry with holes. I then import both my CSV data file and the GMsh mesh file (in .vtk format) in ParaView. Resampling my field data with Dataset filter with the results of the Delaunay2D as the input gives me the contour only on the original geometry.