Visualize CFD data in a 2D mesh

조회 수: 9 (최근 30일)
António Rebelo
António Rebelo 2023년 10월 20일
댓글: Fabio Freschi 2023년 10월 23일
I have a N-by-M 2D mesh with already assigned values of the quantity for each one of the N*M cells (i = 1, 2, 3, ..., N*M).
I have the nodes coordinates but I can't find a way to "plot" each quantity as a color in the respective i cell.
I have tried to use 'pcolor' and 'surf' but the vectors x and y that define the mesh coordinates are always 1 unit too big...
Do you know how I could solve this problem?
Thank you!
  댓글 수: 3
António Rebelo
António Rebelo 2023년 10월 21일
편집: António Rebelo 2023년 10월 21일
Yes, I have (N+1) different y coordinates and (M+1) different x coordinates. The value of is calculated at the center of each cell.
Fortunately I managed to fix the problem by using the function imagesc.
It does exactly what I want by using the values of and the two vectors that contain the x and y coordinates of the cell midpoints.
Thank you a lot for the help!
Walter Roberson
Walter Roberson 2023년 10월 21일
image and imagesc() ignores the coordinate vectors, except for the first and last coordinate in the vector. You cannot use imagesc() for the case where the nodes are not equally spaced.
Also note that the coordinates you pass to image() or imagesc() are treated as the coordinates of the center of the pixel. If you want to use the coordinates as the coordinates of the edge then you need to make an adjustment to the coordinates

댓글을 달려면 로그인하십시오.

채택된 답변

Fabio Freschi
Fabio Freschi 2023년 10월 21일
I assume you have the connectivity of your cells, if not you can create it with delaunay. Then use the low level funciton patch. Note that patch works also with four-node elements.
% dummy data
x = linspace(-1,1,30);
y = linspace(0,3,100);
[X,Y] = meshgrid(x,y);
% points coordinates
P = [X(:) Y(:)];
% create triangulation
T = delaunay(P);
% scalar function
phi = P(:,1).^2+P(:,2).^2;
% plot
figure
patch('Faces',T,'Vertices',P,'FaceVertexCData',phi,...
'EdgeColor','none','FaceColor','interp');
  댓글 수: 6
António Rebelo
António Rebelo 2023년 10월 23일
@Fabio Freschi In this case the mesh is made up by rectangles (not all the same size). 'delaunay' does not work,right? How do I assemble the connectivity matrix for rectangular cells?
Fabio Freschi
Fabio Freschi 2023년 10월 23일
In theory, you can use triangles as weel, but it would be easier to have the connectivity of rectangles. In some way you should have the connectivity available, in any case you can create it on the fly
% dummy data
npx = 30;
npy = 100;
x = linspace(-1,1,npx);
y = linspace(0,3,npy);
[X,Y] = meshgrid(x,y);
% points coordinates
P = [X(:) Y(:)];
% create connectivity
nod = reshape(1:npx*npy,npy,npx).';
nElm = (npx-1)*(npy-1);
T = zeros(nElm,4);
T(:,1) = reshape(nod(1:npx-1,1:npy-1),nElm,1);
T(:,2) = reshape(nod(2:npx,1:npy-1),nElm,1);
T(:,3) = reshape(nod(2:npx,2:npy),nElm,1);
T(:,4) = reshape(nod(1:npx-1,2:npy),nElm,1);
% barycenters
B = (P(T(:,1),:)+P(T(:,2),:)+P(T(:,3),:)+P(T(:,4),:))/4;
% scalar function evaluated at barycenters
phi = B(:,1).^2+B(:,2).^2;
% plot
figure
patch('Faces',T,'Vertices',P,'FaceVertexCData',phi,...
'EdgeColor','k','FaceColor','flat');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by