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

19 views (last 30 days)
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={}; %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
%% Raw data%%,2);,3);,4);,11);,12);,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);
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);
[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.
%% Contourf Plot U,V data%%
h_fig1 = figure(1);
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.

Answers (2)

Walter Roberson
Walter Roberson on 5 Sep 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');
Muhammad Atif
Muhammad Atif on 5 Sep 2021
Edited: Muhammad Atif on 5 Sep 2021
I also tried X and Y only in scatter interpolant but still same result.
U2 = scatteredInterpolant(X1, Y1, U1);

Sign in to comment.

darova on 5 Sep 2021
Edited: darova on 5 Sep 2021
There is something wrong with the data
D = importdata('data.txt');
X =,2);
Y =,3);
Z =,4);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!