Trying to get a contour plot from CFD ASCII data

4 views (last 30 days)
Hello everyone. I am trying to use MATLAB as a post processor to visualize my CFD simulation results. I use ANSYS Fluent as the solver and I exported ASCII data (on the node) of certain quantities (velocity, vorticity etc). Now, I am interested in getting a 2D filled contour so I am using the contourf function.
The problem is that I make use of the command griddata for interpolation and meshgrid to generate a rectangular mesh (b/w min and max x and y). But my problem domain inherently is not rectangular but something like this . So of course, griddata interpolates values into regions where there should be none at all. Does anyone know of any workaround for this? Ideally, I would want the meshgrid itself to be oriented exactly to my domain and not be rectangular so that whatever interpolation griddata does, it is only inside the actual domain.
I have attached the code below.
clc
clear
close all
files = dir('*dat');
for i = 1 : 10
fname = files(i+1).name;
A{i} = dlmread(fname,'',1,1);
A{i}(:,3) = 0; % set all z coordinates to absolute zero for consistency
end
x = A{1}(:,1);
y = A{1}(:,2);
n = 500; % number of grid points
xx = linspace(min(x),max(x),n);
yy = linspace(min(y),max(y),n);
[xi,yi] = meshgrid(xx,yy);
for i = 1:10
quantity = A{i}(:,5);
zi = griddata(x,y,quantity,xi,yi);
zi(zi == 0) = NaN;
contourf(xi,yi,zi,50,'Linestyle','none')
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
axis equal
xlabel('X');
ylabel('Y');
colormap('jet');
colorbar
pause(0.1);
end

Accepted Answer

Prashant Arora
Prashant Arora on 6 Mar 2017
Hi Digvijay,
You can include the boundaries of your domain as a vector (let's say function of x) and replace the values of meshgrid by NaNs. I am including a simple example below.
x = linspace(0,1,1000);
y = linspace(0,10,1000);
boundaryUp = 5 + sin(10*pi*x);
boundaryDown = 1 + sin(5*pi*x);
[X,Y] = meshgrid(x,y);
Y(Y > boundaryUp) = NaN;
Y(Y < boundaryDown) = NaN;
Z = 1 + X.*0 + Y.*0;
mesh(X,Y,Z);
  2 Comments
Digvijay Rawat
Digvijay Rawat on 9 Mar 2017
Thanks yaar. I did have this in mind but was too lazy to implement it so was hoping for an easy way out. Cheers!
Abdallah Ghazal
Abdallah Ghazal on 26 Oct 2020
Hi, I do the same kind of postprocessing of my CFD results in MATLAB. The problem I have is the long time it takes MATLAB to postprocess that data. I bieleve this is because the 'griddata' function is inside the for loop and I do have more than 100 iterations. I am wondering if there is any way to speed up the postprocessing. For your information, a simulation of 100 iterations takes about an hour of clock time. I would appreciate any assistance. Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!