Curl Function to Plot CFD output: Data - [x y x Ux Uy Uz]

Hi,
I have a data set consisting of coordinates, x y z, and magnitudes of velocity Ux Uy Uz in a (26683 x 6) data set. This data has been produced by taking a cut through a 3D CFD simulation I have produced, so that the y coordinate is constant throughout the slice.
I have no experience with the curl function and would appreciate it if anyone could give me a hand with the code I'd have to write to plot angular velocity in a 2D plot, with shading and quiver on.
Thanks

 Accepted Answer

So each columne of the 26683x6 matrix represents one of the coordinates or components?
Are x/y/z monotonic? If so, you should be able to reshape() each of the channels ino a three-d matrix and call curl directly. If they are not, you will need to generate monotonic coordinates (with meshgrid() or ndgrid() and interpolate to these values with TriScatteredInterp(). From here call curl directly.
More per comments:
Matrix was your 26683x6 matrix. I was assuming it was of the form [x y z u v w] or similar. Thus you extract the columns of it to figure out how to mesh the data.
So in the above you would have something like:
[xx yy zz] = meshgrid(0:238,120,0:148) %uses increments of 1, this could be refined.
Now create the interpolant object for each vector component:
Fu = TriScatteredInterp(Matrix(:,1),Matrix(:,2),Matrix(:,3), Matrix(:,4)); %u component
Then to get the results for curl, calculate the vector components with the corresponding interpolant on the above meshgrid output:
uu = Fu(xx,yy,zz); %interpolate to our grid
Then call curl after doing this:
curl(xx,yy,zz,uu,vv,ww)

14 Comments

Yes, basically column 1 represents x coordinates, column 2 y coordinates, column 3 z coordinates... etc In this case I think x/y/z are not monotonic. How would I apply meshgrid to this data set so I can interp? Sorry, very new to Matlab! Thanks for your reply.
Welcome.
It really depends, you could meshgrid the min to the max or, if you know values you want, you could meshgrid those. I don't know the range of your data, but for the purpose of ease, let's say x goes from 1-50, is constant, 5, and z ranges from something to something and you want 50 levels. You could have:
[xx yy zz] = meshgrid(1:50,5,linspace(min(Matrix(:,3)),max(matrix(:,3)),50)
then run the interpolant on these.
How is 'Matrix' defined in that line of code? My x values go from 0 to 238.03, y values are constant at 120, and z varies across the 26683 points but its maximum is 148.75. And after interpolation do I curl(xx,yy,zz)? Appreciate the help Sean :)
you're welcome, see the edit.
Sorry to bother you even more! I've tried adding your code to my function. So far it just plots a quiver plot for the velocity. My matrix is just called 'data' so I've changed that. Here is my code so far:
function wrap_OF_U_components2(fn,step_sz)
close all
data=import_U_componens_file(fn)
x=data.data(:,1);
y=data.data(:,2);
z=data.data(:,3);
Ux=data.data(:,4);
Uy=data.data(:,5);
Uz=data.data(:,6);
%plots velocity vectors
figure(1)
quiver(x,z,Ux,Uy);
axis equal
axis tight
&plots curl angular velocity
[xx yy zz]=meshgrid(0:238,120,0:148)
Fu=TriScatteredInterp(data(:,1),data(:,3),data(:,3),data(:,4));
uu=Fu(xx,yy,zz);
curl(xx,yy,zz,uu,vv,ww)
I've tried running it as it is, but I get an error 'Index exceeds matrix dimensions', also I imagine it'll will say vv, ww are undefined? Thanks a lot for your help again!
The index exceeeds matrix dimensions error means you are rying to reference somethign with an index that doesn't exist. I'm guess it's data(:,etc) in TriScatteredInterp since your struct looks like it's named data.data. Why not just use the column vectors that were extracted in the first part?
Fu=TriScatteredInterp(x,y,z,Ux);
uu=Fu(xx,yy,zz);
Fv=TriScatteredInterp(x,y,z,Uv);
vv=Fv(xx,yy,zz);
Fw=TriScatteredInterp(x,y,z,Uz);
ww=Fw(xx,yy,zz);
curl(...
Yes that makes more sense! Thanks. However I just tried running it again and it says:
'Error using curl (line 55)
U,V must all be size 2x2 or greater.
Error in wrap_OF_U_components2 (line 28)
curl(xx,yy,zz,uu,vv,ww)'
Feels like it's close! I assume U,V are the variables defined by uu, vv in this example?
It's having issues since y is a singular dimension. It needs at least two indices per dimension to be able to calculate the curl. I had overlooked this earlier. To account for it, forget y all together in the call to curl and just calculate the u and w components. You don't have enough information for a v-component.
curl(squeeze(xx),squeeze(zz),squeeze(uu),squeeze(ww))
One more question! That all seemed to work out, but how would I plot pcolor and quiver for this particular case? I've tried:
cav = curl(squeeze(xx),squeeze(yy),squeeze(uu),squeeze(ww))
pcolor(uu,ww,cav); shading interp
hold on; quiver(xx,zz,uu,ww)
However this produced a fairly strange plot, so I'm assuming it's wrong!
What do you mean by strange? Can you post a screen shot?
Also, I would giess you want"
pcolor(squeeze(xx),squeeze(zz),cav)
Brilliant! That gave me a good plot. To produce quiver on the plot would I use:
quiver(squeeze(xx),squeeze(yy),squeeze(uu),squeeze(ww)) ?
I think quiver expects column vectors:
quiver(xx(:),yy(:),uu(:),ww(:))
Thank you so much for all your help Sean!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!