I am trying plot streamlines using the streamlinefunction. The number of streamlines i'm getting streamlines are way too less. I am attaching the code and the data file containing the velocity components and their co-ordinates. please help me in resolving the issue.
MATLAB: Plotting streamlines in matlab.
streamlines
Related Solutions
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
You need to be careful about pre and post collision velocities, and the boundary checks:
t=0;dt=0.5;x1=1;y1=0;v1x=0;v1y=0;m1=1;% centers = [x1, y1];
x2=-8;y2=0;v2x=2;v2y=0;m2=1;% centers2 = [x2, y2];
% t=0, plot position of particles
subplot (3, 1, 1)plot ([-10, 10], [-10, 10], 'w')% obj1 = viscircles(centers,1)
% obj2 = viscircles (centers2, 1)
r1 = rectangle ('Position', [x1,y1,1,1], 'FaceColor', 'r', 'Curvature', [1,1]);r2 = rectangle ('Position', [x2,y2,1,1], 'FaceColor', 'b', 'Curvature', [1,1]);axis ([-10 10 -10 10]);subplot (3, 1, 2)plot (t, x1)plot (t, x2)xlabel ('Time')ylabel ('Position-X')subplot (3, 1, 3)plot (t, y1)plot (t, y2)xlabel ('Time')ylabel ('Position-Y')xx1 = [ ];xx2 = [ ];yy1 = [ ];yy2 = [ ];% Start moving :)
while t < 100 % Update "old" values
v1xold = v1x; v2xold = v2x; v1yold = v1y; v2yold = v2y; if 1 < sqrt((x2-x1)^2+(y2-y1)^2) x1 = x1 + (v1x * dt); x2 = x2 + (v2x * dt); y1 = y1 + (v1y * dt); y2 = y2 + (v2y * dt); xx1 = [xx1, x1]; xx2 = [xx2, x2]; yy1 = [yy1, y1]; yy2 = [yy2, y2]; else % Use "old" values on RHS
v1x = ((m1-m2)/(m1+m2))*v1xold + ((2*m2)/(m1+m2)) * v2xold; v1y = ((m1-m2)/(m1+m2))*v1yold + ((2*m2)/(m1+m2)) * v2yold; v2x = ((m2-m1)/(m1+m2))*v2xold + ((2*m1)/(m1+m2)) * v1xold; v2y = ((m2-m1)/(m1+m2))*v2yold + ((2*m1)/(m1+m2)) * v1yold; x1 = x1 + (v1x * dt); x2 = x2 + (v2x * dt); y1 = y1 + (v1y * dt); y2 = y2 + (v2y * dt); xx1 = [xx1, x1]; xx2 = [xx2, x2]; yy1 = [yy1, y1]; yy2 = [yy2, y2]; end % At Boundary - Turn Direction
if x1+dt*v1x>9 v1x= -v1x; end if x2+dt*v2x>9 v2x=-v2x; end if x1+dt*v1x<-10 v1x=abs(v1x); end if x2+dt*v2x<-10 v2x=abs(v2x); end if y1+dt*v1y>9 v1y=-v1y; end if y2+dt*v2y>9 v2y=-v2y; end if y1+dt*v1y<-10 v1y=abs(v1y); end if y2+dt*v2y<-10 v2y=abs(v2y); end %update the position of the rectangles
set(r1,'Position', [x1,y1,1,1]); set(r2,'Position', [x2,y2,1,1]); subplot (3, 1, 2) plot (t, x1,'ro',t,x2,'bs') axis([0 100 -10 10]) xlabel ('Time') ylabel ('Position-X') subplot (3, 1, 3) plot (t, y1,'ro',t,y2,'bs') axis([0 100 -10 10]) xlabel ('Time') ylabel ('Position-Y') drawnow t= t+ dt; end
Related Question
- Streamline plot not complete
- How to draw 3D bar graph of Z for specified value of X and Y.
- I’m trying to take the grid points x and y and the velocities Vx and Vy to plot the streamlines using streamline starting at x = −4 and 21 and y locations between -4 and 4.
- How to transform this 2D animation into 3D
Best Answer