Griddata generates duplicate points while plotting CFD imported 3D data on an xy Plane
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi All,
I have multiple 3D snapshots of a tractor trailer exported from CFD. I am doing some other data analysis on them and then I want to visualise contour of this processed data. For start, I am just trying to plot CFD data directly using x,y,z cordinate and velocity values.
The problem I am mainly having is:
a. Contour does not capture the geometry boundaries properly and shape looks distorted. My x,y,z,u,v, and w are column vector. when I make mesh grid of x.y at z=0, I use griddata command to reshape my velocity vector into same n by n vector as mesh grid is.
b. When I am trying to reshape my velocity vector on the meshgrid using GRIDDATA() command, it gives warning of duplicate data points have been detected and averaged. I think this is the problem area. However I tried to use unique() command and it has removed some duplicate points, I dont know how these duplicate points exist in the data. But I am still getting same duplicate data point warning when I use Griddata command.
I have attached some matlab pictures of my results and a picture of CFD result which I am expecting to see.Please find the link below of one snapshot of data if someone wants to give a try.
below is the code I am using. I use for loop as later I will be using multiple files.
clear all; clc; close all;
%Read data Files%
dataName='saved_data'; % save a file in the directory to keep all data
save(dataName); %Save empty file
dinfo = dir('*.txt'); %Read directory for all text files
files={dinfo.name}; %save names of all text files in files to use in the loop
delimiterIn=' '; %How data is seperated
headerlinesIn=1; %is there any header
n=numel(files); % number of snapshots
for j=1:n
currentFile=files{1,j}; %load jth snapshot
raw_data=importdata(currentFile,delimiterIn,headerlinesIn); %read data in the snapshot
%and save it in raw data
end
%% Raw data%%
X=raw_data.data(:,2);
Y=raw_data.data(:,3);
Z=raw_data.data(:,4);
U=raw_data.data(:,11);
V=raw_data.data(:,12);
W=raw_data.data(:,13);
%% Scatter interpolant%%
[~, I, ~] = unique([X Y Z],'first','rows'); %here I noticed that there were some duplicate data points which I removed
X1 = X(I);
Y1 = Y(I);
Z1 = Z(I);
U1=U(I);
V1=V(I);
W1=W(I);
U2 = scatteredInterpolant(X1, Y1, Z1, U1); %this does not have any duplicate warning now
V2 = scatteredInterpolant(X1, Y1, Z1, V1);
W2 = scatteredInterpolant(X1, Y1, Z1, W1);
spacing=200;
x1=(linspace(min(X)/5,max(X)/4,spacing))';
y1=(linspace(min(Y),max(Y)/8,spacing))';
z1=(linspace(min(Z)/4,max(Z)/4,spacing))';
[xmesh, ymesh] = meshgrid(x1,y1,0:0);
%% Make velocity grid with U, V and W%%
u1=griddata(X1,Y1,U2.Values,xmesh,ymesh); % Again giving duplicate data point warning and removed however the size is still 20 by 200.
v1=griddata(X1,Y1,V2.Values,xmesh,ymesh);
w1=griddata(X1,Y1,W2.Values,xmesh,ymesh);
res_vel=sqrt(u1.^2+v1.^2+w1.^2);
%% Contourf Plot U,V data%%
h_fig1 = figure(1);
contourf(xmesh,ymesh,res_vel,0.0001:20)
colorbar()
caxis([-1, 27]);
To summarise, Any suggestion how to avoid duplicate data point warning while solving griddata command. Or any alternate to grid data?
secondly, if the problem is not with the grid data then any way of improving the quality of boundary captured and results. I noticed the velocity in the surrounding area is high but contour is showing small value.
I really appriciate any help as I am stuck here for long time.
Thanks
댓글 수: 0
답변 (2개)
Walter Roberson
2021년 9월 5일
[~, I, ~] = unique([X Y Z],'first','rows'); %here I noticed that there were some duplicate data points which I removed
No, that takes unique rows of X Y Z combinations, but scatteredInterpolant() and griddata() want unique X Y combinations. You should change to
[~, I, ~] = unique([X Y],'first','rows');
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Computational Fluid Dynamics (CFD)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!