CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > CFX

Matlab contour plots

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 12, 2007, 09:11
Default Matlab contour plots
  #1
Chris
Guest
 
Posts: n/a
Hi everyone;-)

I have a problem getting matlab to plot the velocity contour which I can see in CFX POST. I tried exporting x,y,z and the velocity vector (.csv) at a giving plane but I can't seem to get the same contour plot in matlab (when using the "contour" command).

Does anyone know how to do this?

Thanks in advance

Regards Chris
  Reply With Quote

Old   January 12, 2007, 11:44
Default Re: Matlab contour plots
  #2
Robin
Guest
 
Posts: n/a
Check that you are using the same range, number of contours and a similar color map. Did you plot Hybrid or Conservative values and export the same?

-Robin
  Reply With Quote

Old   January 12, 2007, 12:46
Default Re: Matlab contour plots
  #3
Chris
Guest
 
Posts: n/a
Hi Robin,

Thanks for your answers but my problem is more Matlab related. I exported hybrid values but my problem is when I plot the values in matlab using the "contour" command I get a totally scattered image... Nothing that even resembes the contour found in POST Viewer!

Do you know some commands in matlab that are useful when using it as a visulization tool?

thanks anyways;-)

  Reply With Quote

Old   January 12, 2007, 14:25
Default Re: Matlab contour plots
  #4
Robin
Guest
 
Posts: n/a
Sorry, been too long since I used Matlab.
  Reply With Quote

Old   January 12, 2007, 15:27
Default Re: Matlab contour plots
  #5
Chris
Guest
 
Posts: n/a
OK no prob.

thanks anyways....
  Reply With Quote

Old   January 15, 2007, 05:03
Default Re: Matlab contour plots
  #6
Oli
Guest
 
Posts: n/a
Hi,

I'm a relatively experienced MATLAB user; contour or contourf will work fine, as long as you are inputting the correct data in the arrays.

Can you given an example of your MATLAB code, perhaps with a picture of the results you are getting?

Oli
  Reply With Quote

Old   January 15, 2007, 09:58
Default Re: Matlab contour plots
  #7
Chris
Guest
 
Posts: n/a
Hi Oli

I get this error:

??? Attempted to access x(:,0); index must be a positive integer or logical.

Error in ==> specgraph.contourgroup.schema>LdoDirtyAction at 256 refresh(h);

??? Error occurred while evaluating listener callback.

when I use this code in Matlab:

clear all; close all; clc;

% Importing data from CFX

filename={'..\CSV\proeve\VelocityPlane1_60lMin379e 3Elements'} extension='.csv'; for i=1:length(filename)

file=char(strcat(filename(i),extension));

csv=importdata(file)

Data=csv.data

Header=csv.colheaders

Text=csv.textdata

[rows, cols]=size(Data);

%function call for plot format

index=Data(:,1);

x=Data(:,2);

y=Data(:,3);

z=Data(:,4);

u=Data(:,5);

% [y,index]=sort(y); % x=x(index); % z=z(index); % u=u(index);

D=[y z u];

contourf(y,z,u)

end

The csv file comes directly from CFX and the data is imported correctly. The plane I want to make the contour in is the y,z-plane and jeg would like to see the velocity(u) as the contours...

Hope you can help me!
  Reply With Quote

Old   January 16, 2007, 10:35
Default Re: Matlab contour plots
  #8
Oli
Guest
 
Posts: n/a
Chris,

The specific error message you get is because you are trying to reference column 0 in the x array, which does not exist.

However, I think there are a few problems with your code, although I think it would be easier if I just posted some code I got to work. I don't have MATLAB available right now, but I'll have a look over it tonight.

Can I just ask so that I can clarify: are you outputting data from a plane in CFX? If so, doesn't the csv file just have 4 columns (x, y, z and U)? Your code suggests you have 5 columns.

Will post again soon,

Oli

  Reply With Quote

Old   January 16, 2007, 16:34
Default Re: Matlab contour plots
  #9
chris
Guest
 
Posts: n/a
Hi Oli

The five columns are due to a column containing the node number! It's like an index number (1,2,3,4,5...) - the .csv data is exported as follows:

Node Number(:,1) X(:,2) Y(:,3) Z(:,4) Velocity(:,5)

Hope this helps..

I am not sure that I understand the part you wrote about reference to column 0 in the x array, but I will try looking at it.. Regards Chris

  Reply With Quote

Old   January 17, 2007, 03:30
Default Re: Matlab contour plots
  #10
Oli
Guest
 
Posts: n/a
Chris,

I underestimated the amount of work on at the moment, so I can't run any code myself. However, I can give you a few tips and direct you to some resources you might find useful. Please note that I don't have a copy of MATLAB on me so this is from memory!

1) First of all, the error message:

??? Attempted to access x(:,0); index must be a positive integer or logical.

...occurs because 0 is not a positive integer or logical number. All arrays in MATLAB start at number 1, so x(:,1) would be fine, as long as x is dimensioned that way.

2) The reading of the csv file can be done much less laboriously using the function 'csvread'. Either look in the help, or type 'help csvread' at the command line. Also, the curly brackets around filename are unnecessary: try filename='thisisthefile.csv' then data=csvread(filename) or even data=csvread('thisisthefile.csv'). To add directory information, use square brackets: directory='C:\Work\etc\' then filename=[directory 'thisisthefile.csv'].

3) The reason why contourf doesn't work is that you are only inputting one-dimensional arrays into it. Again, look in the help file or type 'help contour'. Basically, x and y need to define a *structured* (by that I mean 'monotonic') grid, much like the one supplied by the function 'meshgrid' (look it up). Unfortunately, the CFX data is not in this format as it is unstructured, so you need to impose this data upon a structured grid produced by meshgrid using something like the function 'griddata'.

4) Finally, you don't need any 'for' loops for this function. Actually, you very rarely need 'for' loops in MATLAB, and should try to avoid them wherever possible. Your code should just be:

a. START: clear all, close all etc. etc. b. READ THE CSV FILE: use 'csvread' c. DEFINE THE CONTOUR GRID: use 'meshgrid' d. SUPERIMPOSE YOUR DATA ONTO THE CONTOUR GRID: use 'griddata' e. PLOT THE DATA: use 'contourf' with the x and y values from meshgrid, and the variable values from griddata. f. END

No for loops required!!

I recommend these sources for more information:

1) The MATLAB help file is usually very good - I use it often. Search for the page that has a list of functions on and make that one of your favourites.

2) Failing that, try the online help: http://www.mathworks.com/support/pro...tml?product=ML

3) Failing that, there is a very active message board: http://www.mathworks.com/matlabcentral/

MATLAB is a really great language for visualisation - stick with it, even if it has a rather steep learning curve to being with. You wont regret it!

Oli
  Reply With Quote

Old   January 22, 2007, 04:43
Default Re: Matlab contour plots
  #11
Chris
Guest
 
Posts: n/a
Hi Oli,

Thanks for your detailed answer â€" really nice to get something concrete to go on…ïŠ

I have been working all weekend tying to get a decent contour plot but I still have some problems though…

The problem is that the contour isn't displayed nicely (it is jagged on the boundaries) and takes quit a while for matlab to calculate.

I think the problem is that the matrices produced by meshgrid are not equally spaced. This means that a lot of interpolated points from "meshgrid" are coinciding and resulting in a jagged outer edge.

I tried fixing this by interpolating the interpolated values from "meshgrid" onto an equally spaced matrix using "linspace" and "interp2" unfortunately I get an error message saying I should use "meshgrid" to create 'X' and 'Y' matrices in the "interp2" function â€" but I did this all ready….

This is the code I am using:

clear all; close all; clc;

% Importing data from CFX

% Hybrid values

Hybrid=importdata('../CSV/ContourTest/T_Turbulent_Hybrid.csv');

index_Hybrid=Hybrid(:,1);

xH=Hybrid(:,2);

yH=Hybrid(:,3);

zH=Hybrid(:,4);

uH=Hybrid(:,5);

[YIH ZIH] = meshgrid(yH,zH); UIH = griddata(yH,zH,uH,YIH,ZIH,'cubic');

yiH=linspace(min(yH),max(yH),100); %equally spaced vectors ziH=linspace(min(zH),max(zH),50);

[YiH ZiH]=meshgrid(yiH,ziH); UiH=interp2(YIH,ZIH,UIH,YiH,ZiH); % This doesn't work!! Any ideas?

figure contourf(YiH,ZiH,UiH,'LineStyle','none') axis equal hold on scatter(YIH(,ZIH(,30,UIH(,'filled','MarkerEd geColor','k') % to see interpolated points hold off

Error message Error using ==> interp2 X and Y must be monotonic vectors or matrices produced by MESHGRID.

Do you have any idea why I can't use the "interp2" function here?

Thanks in advance

Regards Chris
  Reply With Quote

Old   July 31, 2017, 14:23
Default
  #12
Member
 
AHMAD
Join Date: Oct 2013
Posts: 35
Rep Power: 12
afikr is on a distinguished road
Hello guys,

Have you guys managed to find a solution to this problem.


I am stuck on the same problem.


What I did:

I extracted data from a sliced plane.

Then I changed it to a radial theta coordinate.

Next, I created a finer structured grid using meshgrid function,

Use griddata function to interpolate.

I have tried all types of interpolation , linear, nearest, cubic and natural. But my contour does not look like it shoud. (See image attached).

any help is much appreciated. Thanks
Attached Images
File Type: jpg 1.jpg (95.3 KB, 29 views)
File Type: jpg 2.jpg (68.7 KB, 32 views)
afikr is offline   Reply With Quote

Old   October 26, 2020, 13:25
Default
  #13
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
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

Old   October 26, 2020, 17:04
Default
  #14
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,655
Rep Power: 143
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
My suggestion is you try an appropriate forum. Your question is on OpenFOAM and matlab, and this is the CFX forum.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   October 26, 2020, 17:15
Default
  #15
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
Dear ghorrocks,
Thank you for the suggestion. Kindly, the problem in principle is the same.
My question was more for MATLAB than the CFD tool. I will move it to the proper forum.
Bodo1993 is offline   Reply With Quote

Old   October 28, 2020, 04:16
Default
  #16
Member
 
AHMAD
Join Date: Oct 2013
Posts: 35
Rep Power: 12
afikr is on a distinguished road
Quote:
Originally Posted by Bodo1993 View Post
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?
How many grid points on that plane are we talking about? I think griddata works fine if you have appropriate grid size.
afikr is offline   Reply With Quote

Old   October 28, 2020, 10:55
Default
  #17
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
Quote:
Originally Posted by afikr View Post
How many grid points on that plane are we talking about? I think griddata works fine if you have appropriate grid size.
Thanks for the reply. I realized that the grid size that I use in MATLAB for meshgrid is orders higher than the one I use in the CFD software. I am wondering if I should use the same grid size in MATLAB as the CFD software or is it advisable to have a finer one to reduce the interpolation errors?
Bodo1993 is offline   Reply With Quote

Old   October 29, 2020, 05:32
Default
  #18
Member
 
AHMAD
Join Date: Oct 2013
Posts: 35
Rep Power: 12
afikr is on a distinguished road
Quote:
Originally Posted by Bodo1993 View Post
Thanks for the reply. I realized that the grid size that I use in MATLAB for meshgrid is orders higher than the one I use in the CFD software. I am wondering if I should use the same grid size in MATLAB as the CFD software or is it advisable to have a finer one to reduce the interpolation errors?
I think you don't need to have a finer grid size since your only wanted to create a video from the surface contour plots. Interpolation error is relevant if you intend to calculate some average values across the surface of interest. So I think you can experiment with several grid sizes and compare the CFD result with the one interpolated in Matlab. See if the interpolated result in Matlab manage to capture important details that have been resolved by the CFD solver.
afikr 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
CFX Contour Plots Troubleshooting derz CFX 7 November 21, 2010 11:08
vector plots and contour plots do not match swati_mohanty FLUENT 1 August 26, 2010 06:53
How to change contour plots Pedro Romero FLUENT 4 November 19, 2009 01:14
drawing of contour plots chinthakindi Main CFD Forum 1 April 27, 2004 05:33
Local surface contour line plots Nandu FLUENT 0 November 10, 2003 00:26


All times are GMT -4. The time now is 00:26.