Unable to generate a proper contour plot
6 ビュー (過去 30 日間)
古いコメントを表示
Greetings everyone,
I am trying to generate a contour plot of mach number. I have provided the code below as well as my output(PLOT.PNG). The output is not what I want. I want it to be completely filled with colours of mach number. I have attached the necessary files obtained from ANSYS FLUENT(ZIP file).
Any help is appreciated!
clc; clearvars; close all; % clear my workspace
% import the data
pname = '[insert directory here]';
fname = 'interior.dat'; % data from ANSYS FLUENT
prof_name = 'boundary_data.dat';
% reference variables
%ur = 127.54; % in m/s
%pr = 272609; % in Pa
Lr = 0.03989;%.3422e-3; % in m
% reading the file
a = importdata(strcat(pname,fname));
b = importdata(strcat(pname,prof_name));
% collecting variables
x = a.data(:,2); y = a.data(:,3); M = a.data(:,4);
% profile
xp = b.data(:,2) ; yp = b.data(:,3);
%%
% creating a matrix data or a structured data
xu = unique(round(x,4)); yu = unique(round(y,4)); % for better memory
[xm,ym] = meshgrid(xu,yu);
%% interpolate
Mm = griddata(x,y,M,xm,ym);
%um = griddata(x,y,u,xm,ym);
%vm = griddata(x,y,v,xm,ym);
%pm = griddata(x,y,p,xm,ym);
%% set undefined values outside the fluid domain
in = inpolygon(xm,ym,xp,yp);
xm(~in) = NaN; ym(~in) = NaN; Mm(~in) = NaN;
%% plot
%subplot(2,2,1)
%contourf(xm, ym, Mm, 'LineColor', 'none');
pcolor(xm,ym,Mm);shading interp; hold on;
plot(xp,yp,'.k'); hold off; axis equal;
clb = colorbar;
title(clb,'M');
xlabel('x/D');ylabel('y/D');
set(clb,'TickDir','out');
set(gca,'TickDir','out','layer' , 'top');
2 件のコメント
Umeshraja
2024 年 10 月 11 日
Hello @Bamelari Jovani, it seems that the zip file is either corrupted or possibly empty, as I'm unable to extract it.
回答 (1 件)
Umeshraja
2024 年 10 月 11 日
The lines highlighted below are indeed attempting to mask areas outside the fluid domain to prevent plotting data where it doesn't physically exist. However, this approach can sometimes cause problems, especially if the boundary isn't well-defined.
in = inpolygon(xm,ym,xp,yp);
xm(~in) = 0; ym(~in) = 0; Mm(~in) = 0;
Removing these lines result in contour plot completely filled with colours representing mach number as shown below.
Hope it helps!
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!