How to plot streamlines in matlab ???

Hi everybody, I m new. I ve this question like title. I have to plot streamlines with circular cylinder, from PIV data of velocity. For each data I ve one value of X Y U V (2D model), a matrix with n rows x 4 columns. From this matrix, that represents the average values of velocity, I ve just elaborated a quiver plot with the cylinder but I need of your help to understand how can I use streamline function in matlab or if is necessary to write the strem function like fluid mechanics theory. In annex the matrix
Thanks

6 Comments

So, you already have a series of (x,y) values which compose the different stream lines? Why not just plot them?
if I plot X ed Y I obtain a straight line that don t follow the velocity data evolution. That s why I m in trouble. If I use meshgrid function in matlab I obtain a square grid but the strealine are also straigth lines
Oh, so your data is velocity (U,V) values at certain (x,y) coordinates, and you want to plot arrows for those velocity vectors?
I ve just plotted arrows for my data. Now I need to plot streamlines that represent the evolution of the arrows substantially that and the aim is to underline the vortex shedding. Look this other annex that is a screen shot of the streamline for a similar work.
How are you identifying which points connect to form a streamline?
this is my problem Bob; I tried in different ways to buil the grid first and after to plot the U and V values on meshgrid X and Y, but the result is always a square grid. I Know how to not consider the cylinder (NaN values for U and V in the coordinates X and Y of its position respect the grid) but at this point I m not sure of my grid. Have you confidence with stream function?

Sign in to comment.

Answers (3)

Bob Thompson
Bob Thompson on 25 Feb 2019
Try using the quiver function. It's not perfect streamlines, but it should give you an idea of what the velocity field looks like, which should essentially achieve the same affect. This should still plot in a 'square' because I suspect that is what is available for your (x,y) data, so that will be the bounds of your 2D plot area. Based on the image you attached you should be getting a grid that is roughly rectangular anyway, as it is a cross section of your flow perpendicular to the cylinder you are flowing around.
data = xlsread('Cartel1.xlsx');
quiver(data(:,1),data(:,2),data(:,3),data(:,4));
ANTONIO LEUZZI
ANTONIO LEUZZI on 26 Feb 2019
Sorry Bob but I think that you don t Know or you aren t understanding my problem!!! If you read with attention my previously messages I ve write that I ve already plotted quiver data!!!!!!!!! My problem is HOW TO PLOT STREAMLINE WITH MY VELOCITY DATA??? HOW TO CREATE A GRID OF POINT ??? Are you understandong now?

12 Comments

No, I am evidently not understanding what you're asking for.
Let's start at the basics to make sure we are on the same page.
You have a set of [x,y,u,v] data that makes up a velocity field.
You want to plot streamlines.
Do you know that streamline is a built in function?
Yes Bob I studied it and I know that streamline dericìved by stream function and that stream function has got an equation for two both components of velocity (U and V), but my trouble is how to write it in a code. Look for my earlier Excel annex. There are all data cleared of anomalous data. How can I eventually write the stream function by myself , without streamline of Mat? This is my question. Or if I follow the stream2D of Mat hoe is necessary meshgrid of data?? Because if I meshgrid my data onbtain a square grid also and a straigth line and I don t Know how I m in mistake or what I dont understand of this part of Fluid Mechanics!!!!
I'm going to go through this step by step to make sure I am understanding, if I am not, feel free to correct me.
I know that streamline dericìved by stream function and that stream function has got an equation for two both components of velocity (U and V), but my trouble is how to write it in a code.
You have read the documentation and you understand that the streamline function calculates the streamline values for U and V directions using the stream function, but you are not sure how to write a) the stream function in code, b) the streamline command in code?
The streamline function in Matlab actually just generates a line based on the data field that you feed it. I have not looked in greater detail, but I believe this is more a process of generating a series of points with interpolation than it is spceifically using a fluid dynamics stream function.
To respond to problem (a), I do not know the stream function equations off the top of my head, but I also don't know that they are necessary in this situation. If you are looking to write the code to generate streamlines without using the streamline() command then the basic pseudo code I came up with is this:
data = xlsread('Cartel1.xlsx');
ns = 15; % Number of streamlines
streams = zeros(max(data(:,1))*10,2,ns); % Preallocate streamline array size
% (xlocation,ylocation,streamline number)
streams(1,1,:) = 0;
streams(1,2,:) = [min(data(:,2)):(max(data(:,2))-min(data(:,2)))/(ns-1):max(data(:,2))];
c = 1;
for i = 0.1:0.1:max(data(:,1)); % values from x = 0 to max x value
c = c + 1; % Array index counter
streams(c,1,:) = i; % Set new x values
for j = 1:ns; % Loop through each stream y value
streams(c,2,j) = streams(c-1,2,j)+interp2(data(:,1),data(:,2),data(:,4),i,steams(c-1,2,j));
end
end
To respond to problem (b), this is actually quite easy, because you already have the x,y,u,v data necessary to create the streamlines, you just need to decide what the starting points are.
streamline(data(:,1),data(:,2),data(:,3),data(:,4),[zeros(1,100)],[min(data(:,2)):(max(data(:,2))-min(data(:,2)))/99:max(data(:,2))]);
% Should plot 100 streamlines starting on left edge
How can I eventually write the stream function by myself , without streamline of Mat?
See above for beginnings of a code. I do wonder why you feel a need to write this yourself though. Is there a specific problem with the built in streamline command?
Or if I follow the stream2D of Mat hoe is necessary meshgrid of data??
I'm assuming you're getting this idea from the examples found in the streamline documentation. It is not necessary for you to generate a mesh grid because you already have the x,y data in your excel document. The examples shown use meshgrid() because they are generating a generic sample set of data so other poeple can recreate their example.
Because if I meshgrid my data onbtain a square grid
You should be getting a square gird because you are looking at a 2D plot, and those are almost always presented as square grids.
Hi Bob and thanks for all. I ve launched the code and appears this message Error using zeros
Size inputs must be integers, wich refers to the string streams = zeros(max(data(:,1))*10,2,ns);
Double check that ns, and max(data(:,1))*10 are both integers. If they are not, fiddle around with the sizing until they become integers. The code I posted is probably not going to do exactly what you want it to do right off the bat, so you're going to have to do some editting to make it your own.
This is the error!!!!!
"Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 128)
F = makegriddedinterp({X, Y}, V, method,extrap);
Error in Streamline_testA (line 374)
streams(c,2,j) = streams(c-1,2,j)+interp2(avg_ordered(:,1),avg_ordered(:,2),avg_ordered(:,4),i,streams(c-1,2,j));"
Are x and y only increasing? If not sort your data.
data = sortrows(data,[1,2]); % Sort in ascending order with first priority to column 1 and second priority to column 2
@Bob Nbob: When a comment is posted as an answer, you can copy it into the section for commants. Usually this is marked by "[MOVED from section for answers]". You can do this without editor-powers also, but only admins and editors can delete the pseudo-answer afterwards. Here the pseudo-answer got several comments already and moving them is tedious.
the grid vector must contain unique point!!!!!!!!!!!!!!!!!!!! new error
wich refers to loop for!!!
@ANTONIO LEUZZI: Uppercase means shouting in an internet forum. With bold type also and a bunch of exclamation marks your message looks excited. Calm down.
Post the current code and a copy of the complete error message.
There wasn t absolutely my intention to shout but I ve highlighted ineffectiveness for resolving thsi problem despite Bob's help!!!!! I m sorry for this misunderstood and thanks for your suggest

Sign in to comment.

ANTONIO LEUZZI
ANTONIO LEUZZI on 28 Mar 2019
Hei guys. Unfortunately I ve not complete this part of code yet. I would still need of your help. I will try to be clearest possible. Than, I ve PIV measurements that consist of X,Y,U,V data, or rather each value has got an X displacement and a Y dispalcement at wich corrispond U velocity component (of dispalcement) and V velocity component (of displacement) respectively. So I ve a matrix of this value. My ask is hoe to plot streamlines with the presence of a cylinder? I ve attached the code with the data. In this code you can find first part in wich the data were arranged and in wich were erased spikes values. After that there s a second part in wich I ve computed main velocity, for U and V, plotted velocity profiles, for U and V and computed Reynolds Shear Stress. I attached even an Excel file with the matrix of data. I know the stream function in matlab bu I think that in my case would need another way to plot the stremlines.
untitled.jpg
This image is the velocity displacement with a quiver function. Streamlines follow easily the row wise. As you can see from the Excel file, Y length is 166.0957 that is the legth of the regitred PIV image; also for X length. But the process of the data in PIV were made for each Y value constant corrispond all X values and so U values and V values. Than streamlines follow X data posted on the same ordinate.
I don t try to extract them. Please help me. ANd thanks for your help

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 25 Feb 2019

Answered:

on 28 Mar 2019

Community Treasure Hunt

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

Start Hunting!