Display problems with "rectangle" function

조회 수: 4 (최근 30일)
Enrico Bussetti
Enrico Bussetti 2020년 4월 8일
댓글: Edoardo Cipriano 2020년 7월 14일
I'm using the rectangle function to display an obstacle in the mesh of my CFD code.
The problem is that if my mesh is too coarse (I mean something like 0.025x0.025 as the size of the cells) i get some display issues, like this:
As you can see the borders of the rectangle are not straight lines. Here's a zoom-in:
The preoblem disappears as soon as I refine the grid.
Here's the code for the plot in the figure above
position = [c1,c2,c3,c4]; % No problem with this two lines, I checked
color = [0.85 0.85 0.85];
figure
subplot(211);
surface(X,Y,kappa_1.*ca'.*cb'); % This is the surface plot of the reaction rate in the back. This should also be correct
axis([0 Lx 0 Ly]); title('reaction rate [mol/m3/s]'); xlabel('x'); ylabel('y');
colorbar; shading interp;
rectangle( 'Position', position, 'FaceColor', color); % This part of the code is responsible for the rectangle
I cannot figure out the cause of this issue. If someone could help me I would be very grateful.
Thanks

채택된 답변

Edoardo Cipriano
Edoardo Cipriano 2020년 7월 13일
I solved writing the data in a .tec file to visualize them using paraview. This is an example of code where x, y are the vectors of the discretized lengths of the domain
[X,Y] = meshgrid(x,y);
and the other variables are the fields to visualize,
Note that the rectangle can be also directly built in paraview.
% --------------------------------------------------------------------------------------
% [Post-Proc] Write tecplot file with Results
% --------------------------------------------------------------------------------------
function writeTecplot(nameFile,x,y,X,Y,uu,vv,pp,ca,cb,cc,cd)
res = fopen(nameFile, 'w');
fprintf(res,'Title = Solution\n');
fprintf(res,'Variables = "x", "y", "u", "v", "p", "CA", "CB", "CC", "CD"\n');
fprintf(res,['Zone I = ',num2str(length(y)),', J = ',num2str(length(x)),' F = POINT\n']);
for i=1:length(x)
for j=1:length(y)
fprintf(res,'%f %f %f %f %f %f %f %f %f\n',...
X(j,i),Y(j,i),uu(i,j),vv(i,j),pp(i,j),ca(i,j),cb(i,j),cc(i,j),cd(i,j));
end
end
fclose(res);
end
% --------------------------------------------------------------------------------------
% [Post-Proc] Write tecplot file with Obstacle/Rectangle
% --------------------------------------------------------------------------------------
function writeObstacle(position)
xObst = [position(1) position(1)+position(3)];
yObst = [position(2) position(2)+position(4)];
obs = fopen('Obstacle.tec', 'w');
fprintf(obs,'Title = Obstacle\n');
fprintf(obs,'Variables = "x", "y"\n');
fprintf(obs,['Zone I = ',num2str(length(xObst)),', J = ',num2str(length(yObst)),' F = POINT\n']);
for i=1:length(xObst)
for j=1:length(yObst)
fprintf(obs,'%f %f\n',xObst(i),yObst(j));
end
end
fclose(obs);
end
  댓글 수: 2
Enrico Bussetti
Enrico Bussetti 2020년 7월 14일
Thank you! Solo per sapere, stai seguendo CFD al Poli?
Edoardo Cipriano
Edoardo Cipriano 2020년 7월 14일
yes

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Volume Data에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by