Azzera filtri
Azzera filtri

Griddata generates duplicate points while plotting CFD imported 3D data on an xy Plane

9 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Walter Roberson
Walter Roberson il 5 Set 2021
[~, 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 Commenti
Muhammad Atif
Muhammad Atif il 5 Set 2021
Hi Walter,
Thank you so much for your quick reply here and thank you for highlighting the problem. I tried your suggestion and the duplicate point warning is over now but there is no improvement in the picture quality. I tried different levels of contour(0:1:20/0:0.1:20/0:0.1:100 etc). but nothing has improved. Is there something I am missing. Last time when I was trying on 2D data, I had this issue when I was only using resultant of x-velocity and y-velocity but later I added w-velocity and it worked fine. But here I tried all combination but no success. I have attached my recent picture of contour.
I highly appriciate your help.
Thanks
Muhammad Atif
Muhammad Atif il 5 Set 2021
Modificato: Muhammad Atif il 5 Set 2021
I also tried X and Y only in scatter interpolant but still same result.
U2 = scatteredInterpolant(X1, Y1, U1);

Accedi per commentare.


darova
darova il 5 Set 2021
Modificato: darova il 5 Set 2021
There is something wrong with the data
D = importdata('data.txt');
X = D.data(:,2);
Y = D.data(:,3);
Z = D.data(:,4);
plot3(X,Y,Z,'.')
  6 Commenti

Accedi per commentare.

Categorie

Scopri di più su Computational Fluid Dynamics (CFD) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by