plotting streamlines from velocity components
60 views (last 30 days)
Show older comments
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 Comments
Wick
on 1 May 2018
Edited: Wick
on 1 May 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.
Accepted Answer
Wick
on 1 May 2018
Edited: Wick
on 1 May 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
More Answers (2)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!