Mapping 3D velocity data onto a uniform grid

I am trying to map 3D velocity data from a non-uniform computational fluid dynamics (CFD) mesh grid onto a uniform Cartesian grid. The CFD data is generated using adaptive meshing, and therefore local grid density changes with every time step. However, I need results from each time step on the same Cartesian grid for input into another program.
I have created a uniform grid using meshgrid and then tried interp3 for mapping the data to the new grid. However, I haven't been successful in this approach because of difficulties interpolating from a non-uniform grid. Is there a more appropriate function that I could try?

댓글 수: 2

ANKUR KUMAR
ANKUR KUMAR 2018년 10월 4일
Provide us the code because random example of interp3 might confuse you.
dr23
dr23 2018년 10월 4일
%Input full x,y,z position and u,v,z velocity files %All x,y,z cells are not uniform in size
%%Small Sample of x data x = [0.0075246003;0.0059246002;0.0099246003;0.0051246001;0.0083246004;0.0095246003;0.011524601;0.0087246004;0.0095246003;0.0111246]; %Small Sample of y data y = [-0.018952699;-0.0061526997;-0.00055269962;-0.00095269958;-0.0109527;0.00064730041;-0.0029526997;-0.0081526994;-0.0077526996;-0.0041526995]; %Small Sample of z data z = [-0.0329438;-0.027343801;-0.040143799;-0.0465438;-0.0281438;-0.0473438;-0.0489437990;-0.0449438;-0.0473438;-0.0481438]; %Small Sample of velocity u data u = [0.097406045;-0.014577235;0.016985994;0.019886859;-0.044792913;0.0152714;0.0097842654;0.011417145;0.012931908;0.011697576]; %Small Sample of velocity v data v = [-0.043842282;-0.1308506;-0.042359531;-0.042068601;-0.18527155;-0.045896135;-0.042315964;-0.033556957;-0.032933142;-0.039122283]; %Small Sample of velocity w data w = [-0.08908686;0.091919765;0.16070224;0.18066588;0.16235189;0.18855327;0.19154422;0.15817995;0.1560359;0.18092647];
figure(1) quiver3(x,y,z,u,v,w)
V = [u v w];
[Xq,Yq,Zq] = meshgrid(0:0.001:0.025,0:0.001:0.025,0:0.001:0.025);
Vq = interp3(x,y,z,V,Xq,Yq,Zq);
I assume that I need something to deal with the non-uniform grid size of the original mesh before I interpolate.

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

 채택된 답변

jonas
jonas 2018년 10월 4일

0 개 추천

Try this
[Xq,Yq,Zq] = meshgrid(min(x):0.001:max(x),min(y):0.001:max(y),min(z):0.001:max(z));
Uq = griddata(x,y,z,u,Xq,Yq,Zq);
Vq = griddata(x,y,z,v,Xq,Yq,Zq);
Wq = griddata(x,y,z,w,Xq,Yq,Zq);
quiver3(Xq(:),Yq(:),Zq(:),Uq(:),Vq(:),Wq(:))

댓글 수: 4

dr23
dr23 2018년 10월 5일
Thanks, that helped. However, the data spreads out quite a bit when mapped to the new grid as shown in the attached images. I will need to find a way to keep the velocity data more accurate to its original location
Original:
New Grid:
jonas
jonas 2018년 10월 5일
편집: jonas 2018년 10월 5일
I dont know what spread out refers to in this context.
dr23
dr23 2018년 10월 8일
When mapped to the new grid, data are dispersed to points outside of the original fluid domain. Locations outside of the geometry now have non-zero velocities.
Oh I understand. The data is being interpolated. It's not too difficult to remove those points again. Let x,y,z be your original scattered data pts and X,Y,Z your new grid
%%3d boundary
tri = delaunayn([x y z]);
%%find points inside of 3d boundary
tn = tsearchn([x y z], tri, [X(:) Y(:) Z(:)]);
IsInside = ~isnan(tn)
You can then set the points outside of the original boundary to NaN, and you are golden. You can also have a look at this Q ( link )

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Computational Fluid Dynamics (CFD)에 대해 자세히 알아보기

태그

질문:

2018년 10월 4일

댓글:

2018년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by