CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Special Topics > Visualization & Post-Processing

Plotting contours in Matlab

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree9Likes
  • 9 Post By daenerys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 23, 2015, 11:08
Default Plotting contours in Matlab
  #1
New Member
 
Lily
Join Date: Aug 2014
Posts: 27
Rep Power: 8
daenerys is on a distinguished road
Hi all,

I'm trying to visualize plots and contours in matlab, same type of plots Ansys Fluent can do automatically.

Lets say I want to plot the static pressure contour. I exported a data file from Fluent after solving the field.
I got an ascii file with 4 columns in it:
column 1 - node numbers
column 2 - x coordinate
column 3 - y coordinate
column 4 - static pressure value

I wrote the following matlab code, but it's not working.

clc
close all
clear all

data=importdata('static_pressure');
index=data.data(:,1);
x=data.data(:,2);
y=data.data(:,3);
p=data.data(:,4);
interval=20;
xplot=x(1:interval:end);
yplot=y(1:interval:end);
pplot=p(1:interval:end);
[xi,yi]=meshgrid(xplot,yplot);
zi=griddata(x,y,p,xi,yi);

figure(1)
hcb=colorbar;
colorTitleHandle = get(hcb,'Title');
titleString = '[Pa]';
set(colorTitleHandle ,'String',titleString);
caxis ([0.5,1.8]);
title('Static Pressure Distribution');
xlabel('X coordinate');
ylabel('Y coordinate');
contourf(x,y,p,10000, 'edgecolor', 'none');


I get the following error:
Error using ==> contourf at 65
Z must be size 2x2 or greater.

Error in ==> load at 20
contourf(x,y,p,10000, 'edgecolor', 'none');


Any help would be appreciated. Thx.

Last edited by daenerys; March 19, 2015 at 12:18.
daenerys is offline   Reply With Quote

Old   March 19, 2015, 12:16
Default
  #2
New Member
 
Lily
Join Date: Aug 2014
Posts: 27
Rep Power: 8
daenerys is on a distinguished road
Hi everybody,

I managed to get it to work, so for future reference here is my code:

clc
close alll
clear all

%read data
data=importdata('static_pressure');
x=data.data(:,2);
y=data.data(:,3);
p=data.data(:,4);
%enforce y==0 where y<1e-9 (to avoid NaN at centerline)
y(y<1e-9)=0;
%make rectangular grid
Nx = 1000;
Ny = Nx;
xx = linspace(min(x),max(x),Nx);
yy = linspace(min(y),max(y),Ny);
[xi,yi]=meshgrid(xx,yy);
%interpolate results on rectangular grid
zi=griddata(x,y,p,xi,yi);
%mirror
xi = [ xi(end:-1:2,: ); xi];
yi = [-yi(end:-1:2,: ); yi];
zi = [ zi(end:-1:2,: ); zi];

%plot
figure()
hcb=colorbar;
colorTitleHandle = get(hcb,'Title');
titleString = '[Pa]';
set(colorTitleHandle ,'String',titleString);
title('Pressure Distribution');
xlabel('X coordinate');
ylabel('Y coordinate');
contourf(xi,yi,zi,100, 'edgecolor', 'none');
axis([0 0.0508 -0.015 0.015]);


Enjoy!
mozkan26, Shayan, MSF and 6 others like this.
daenerys is offline   Reply With Quote

Old   October 26, 2020, 13:58
Default
  #3
Senior Member
 
Join Date: Jul 2019
Posts: 125
Rep Power: 3
Bodo1993 is on a distinguished road
Hi, I use the file 'surfaces' to extract 2D surfaces of the phase fraction from OpenFOAM transient results. I postprocess the data using MATLAB to plot contours of the phase fraction and make videos. I am wondering if I have to use the interpolation function 'griddata' to do so. The problem with 'griddata' is that it takes time to do the interpolation, e.g. a simulation with 100 time steps may take more than an hour to generate the video. Any suggestions?
Bodo1993 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2D Geometry - Plotting Contours For Specific Regions Only Naz1405 FLUENT 4 June 12, 2014 11:19
How to plot FLUENT contours on MATLAB Thiago Combustion FLUENT 1 October 10, 2013 15:13
[General] Plotting contours on a triangular 3D mesh nikosb ParaView 1 March 2, 2013 10:40
Contours of 2D plotting therockyy FLOW-3D 4 December 22, 2012 16:04
About velocity angle when plotting a contours wateraction FLUENT 0 July 25, 2010 00:24


All times are GMT -4. The time now is 06:39.