plotting streamlines from velocity components

조회 수: 73 (최근 30일)
Michael Wales
Michael Wales 2018년 4월 30일
답변: Syed Fazuruddin 2020년 4월 1일
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
Michael Wales
Michael Wales 2018년 5월 1일
@Chad, my problem is that MATLAB wants U,V,W to be 3x3 matrices. My velocity components (Vx,Vx,Vz) are a single column each. I can combine them to get a 3x1 matrix, but not a 3x3 .
Wick
Wick 2018년 5월 1일
편집: Wick 2018년 5월 1일
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.

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

채택된 답변

Wick
Wick 2018년 5월 1일
편집: Wick 2018년 5월 1일
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
  댓글 수: 1
Michael Wales
Michael Wales 2018년 5월 1일
@Chad...thank you very much, it works great.

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

추가 답변 (2개)

Michael Wales
Michael Wales 2018년 5월 1일
Here is my data and code for the quiver plot:
figure (202) plot3(x,y,z,'ok'); hold on;
quiver3(x,y,z, Vx,Vy,Vz);
- -
You are correct, I only have one (u,v,w) for every (x,y,z) value

Syed Fazuruddin
Syed Fazuruddin 2020년 4월 1일
How to draw a wavy wall of a square in matlab

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by