Display problems with "rectangle" function

4 Ansichten (letzte 30 Tage)
Enrico Bussetti
Enrico Bussetti am 8 Apr. 2020
Kommentiert: Edoardo Cipriano am 14 Jul. 2020
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

Akzeptierte Antwort

Edoardo Cipriano
Edoardo Cipriano am 13 Jul. 2020
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 Kommentare
Enrico Bussetti
Enrico Bussetti am 14 Jul. 2020
Thank you! Solo per sapere, stai seguendo CFD al Poli?
Edoardo Cipriano
Edoardo Cipriano am 14 Jul. 2020
yes

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by