plotting streamlines from velocity components
53 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Michael Wales
le 30 Avr 2018
Réponse apportée : Syed Fazuruddin
le 1 Avr 2020
I am having trouble creating streamlines in MATLAB. I have: (1) x,y,z coordinates and (2) velocity components (Vx, Vy, Vz).
I have no trouble plotting the quiver (arrow) plot, but I cannot figure out the streamlines.
Any help would be greatly appreciated.
Thanks,
-Mike
3 commentaires
Wick
le 1 Mai 2018
Modifié(e) : Wick
le 1 Mai 2018
So your X and and Y are not plaid (as if created by meshgrid).
Are you fields continuous, differentiable, and functions? That is, for every (x,y,z) value, do you only have one (u,v,w)? If so, your best bet is to create a 3D plaid grid using ndgrid covering the (x,y,z) domain of interest. Then use some sort of interpolation to fill in the velocities for every point. The function 'scatteredInterpolant' is probably your friend here. The you can use commands like mesh, surf, slice, streamlines, and others that expect 2- or 3D rectangular data to work with.
Edit: I'm not sure my comment addressed your concern. Can you upload a .mat file with some values I can try to work with? I can then write you some code that will manipulate it properly.
Réponse acceptée
Wick
le 1 Mai 2018
Modifié(e) : Wick
le 1 Mai 2018
Michael,
I've got some code below that plots slices and streamlines for your data but the data itself is odd. It looks like you've got an impeller blowing into a tank but the velocity vector that's coming out of it is normal to the impeller. However, that's what the quiver arrows show so the streamlines follow the arrows. So at least, you can now look at your streamlines as you work on the velocities (if necessary.
Good luck!
clearvars
load 'velocity components.mat'
mag_V = sqrt(Vx.^2 + Vy.^2 + Vz.^2);
% Filtering out zero velocity walls.
index = mag_V > 0.1;
xx = x(index);
yy = y(index);
zz = z(index);
Vxx = Vx(index);
Vyy = Vy(index);
Vzz = Vz(index);
FVx = scatteredInterpolant(xx,yy,zz,Vxx,'linear','none');
FVy = scatteredInterpolant(xx,yy,zz,Vyy,'linear','none');
FVz = scatteredInterpolant(xx,yy,zz,Vzz,'linear','none');
% This is a very ugly grid for your problem but it works.
% A cylindrical grid would probably be more resource efficient
elements = 40; % how many subdivisions per dimensions.
% Mind you, this is 3D. Total memory gets large fast
[X3, Y3, Z3] = meshgrid(linspace(min(x),max(x),elements),...
linspace(min(y),max(y),elements),...
linspace(min(z),max(z),elements));
V3x = FVx(X3,Y3,Z3);
V3y = FVy(X3,Y3,Z3);
V3z = FVz(X3,Y3,Z3);
mag_V3 = sqrt(V3x.^2 + V3y.^2 + V3z.^2); % velocity vector magnitude
starting_x = zeros(5,5); % starting points for streamlines
[starting_y, starting_z] = meshgrid(linspace(-0.005,.005,5), ...
linspace(-0.005,.005,5));
figure(1)
clf
plot3(x,y,z,'.k','MarkerSize',4);
hold on
quiver3(x,y,z, Vx,Vy,Vz);
h = slice(X3,Y3,Z3,mag_V3,[],0,-0.02:.02:0);
set(h,'EdgeColor','w','FaceAlpha',0.75');
h = streamline(X3,Y3,Z3,V3x,V3y,V3z,starting_x,starting_y,starting_z);
set(h,'LineColor','r','LineWidth',4);
axis equal
grid on
hold off
Plus de réponses (2)
Voir également
Catégories
En savoir plus sur Vector Fields dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!