problem with triangulation matlab

5 ビュー (過去 30 日間)
ran
ran 2024 年 6 月 13 日
コメント済み: Swastik Sarkar 2024 年 6 月 18 日
Hello, my friends; I am trying to interpret Fluent data for a wavy tunnel. The issue lies in the triangulation, as shown in the image. I am unsure how to resolve it and do not understand how to prevent the triangulation from occurring.
% Let the user choose the folder containing the text files
folder_path = uigetdir('Select the folder containing the text files');
% Check if the user canceled folder selection
if folder_path == 0
disp('Folder selection canceled. Exiting...');
return;
end
% Get a list of all the text files in the folder
file_list = dir(fullfile(folder_path, '*.txt'));
% Initialize cell arrays to store data for each variable
x_cell = cell(length(file_list), 1);
y_cell = cell(length(file_list), 1);
u_cell = cell(length(file_list), 1);
v_cell = cell(length(file_list), 1);
T_cell = cell(length(file_list), 1);
P_cell = cell(length(file_list), 1);
Tw_cell = cell(length(file_list), 1);
% rho_cell = cell(length(file_list), 1);
% k_cell = cell(length(file_list), 1);
% dissRate_cell = cell(length(file_list), 1);
% Visxosity_cell = cell(length(file_list), 1);
% Cp_cell = cell(length(file_list), 1);
% thermal_cell = cell(length(file_list), 1);
% Loop through each file and read its contents
for i = 1:length(file_list)
% Get the file name
file_name = fullfile(folder_path, file_list(i).name);
% Read the data from the file
data = readtable(file_name);
% Store the data in the cell arrays with the file name as the cell name
[~, file_name_only, ~] = fileparts(file_name);
x_cell{i} = struct('file_name', file_name_only, 'data', data.x_coordinate);
y_cell{i} = struct('file_name', file_name_only, 'data', data.y_coordinate);
u_cell{i} = struct('file_name', file_name_only, 'data', data.x_velocity);
v_cell{i} = struct('file_name', file_name_only, 'data', data.y_velocity);
T_cell{i} = struct('file_name', file_name_only, 'data', data.temperature);
P_cell{i} = struct('file_name', file_name_only, 'data', data.pressure);
Tw_cell{i} = struct('file_name', file_name_only, 'data', data.wall_temperature);
% rho_cell{i} = struct('file_name', file_name_only, 'data', data.density);
% k_cell{i} = struct('file_name', file_name_only, 'data', data.turb_kinetic_energy);
% dissRate_cell{i} = struct('file_name', file_name_only, 'data', data.turb_diss_rate);
% Visxosity_cell{i} = struct('file_name', file_name_only, 'data', data.viscosity_lam);
% Cp_cell{i} = struct('file_name', file_name_only, 'data', data.specific_heat_cp);
% thermal_cell{i} = struct('file_name', file_name_only, 'data', data.thermal_conductivity_lam);
end
%%
% Initialize structures to store wall coordinates and number of y coordinates
wall_coords_down = struct('x', {}, 'y', {});
wall_coords_yp = struct('x', {}, 'y', {});
num_y_coordinates = struct('file_name', {}, 'num_y', {});
y_coordinates_end_tunnel = struct('file_name', {}, 'num_y', {});
for i = 1:length(file_list)
% Find wall coordinates
xwall = x_cell{i}.data(Tw_cell{i}.data > 0);
ywall = y_cell{i}.data(Tw_cell{i}.data > 0);
% Find the largest wall X-coordinate (end of the tunnel)
largest_wall_X = max(xwall);
% Find the index of the largest wall X-coordinate
largest_wall_X_idx = find(xwall,1, 'last');
% Determine the distance between the largest wall X-coordinate and the preceding one
distance_between = max(gradient(sort(xwall)));
% Define the search range for X-coordinates
EndOfTunnel = find(largest_wall_X - 0.7 * distance_between < x_cell{i}.data & x_cell{i}.data <= largest_wall_X);
% Extract the corresponding y-coordinates
y_coordinates_end_tunnel(i).file_name = x_cell{i}.file_name;
y_coordinates_end_tunnel(i).num_y = y_cell{i}.data(EndOfTunnel);
% Store wall coordinates
wall_coords_up(i).x = xwall(ywall>(max(ywall)+min(ywall))/2);
wall_coords_up(i).y = ywall(ywall>(max(ywall)+min(ywall))/2);
wall_coords_down(i).x = xwall(ywall<(max(ywall)+min(ywall))/2);
wall_coords_down(i).y = ywall(ywall<(max(ywall)+min(ywall))/2);
% Count the number of y-coordinates
num_y_coordinates(i).file_name = x_cell{i}.file_name;
num_y_coordinates(i).num_y = length(y_coordinates_end_tunnel(i).num_y);
end
%%
% Initialize structures to store interpolated data
interp_u_cell = cell(length(file_list), 1);
interp_v_cell = cell(length(file_list), 1);
interp_T_cell = cell(length(file_list), 1);
interp_P_cell = cell(length(file_list), 1);
interp_Tw_cell = cell(length(file_list), 1);
interp_x_cell = cell(length(file_list), 1);
interp_y_cell = cell(length(file_list), 1);
for i = 1:length(file_list)
% Find wall coordinates
xwall = x_cell{i}.data(Tw_cell{i}.data > 0);
ywall = y_cell{i}.data(Tw_cell{i}.data > 0);
% Find the largest wall X-coordinate (end of the tunnel)
largest_wall_X = max(xwall);
% Calculate the distance between the maximum and minimum wall X-coordinates
distance_total = max(xwall) - min(xwall);
% Define the wavelength
wavelength = 28.8/1000; % m
% Calculate the number of sections based on the wavelength
num_sections = floor(distance_total / wavelength);
% Initialize structures to store interpolated data for each section
interp_u = cell(num_sections, 1);
interp_v = cell(num_sections, 1);
interp_T = cell(num_sections, 1);
interp_P = cell(num_sections, 1);
interp_Tw = cell(num_sections, 1);
interp_x= cell(num_sections, 1);
interp_y = cell(num_sections, 1);
interp_x_new= cell(num_sections, 1);
interp_y_new = cell(num_sections, 1);
% Initialize starting point for creating sections
current_x = largest_wall_X;
% Loop to create sections and interpolate data within each section
for j = 1:num_sections
% Find the end point of the current section
end_x = current_x - wavelength;
disp(end_x);disp(current_x);disp(wavelength);
% Find the indices of x coordinates within the current section
section_indices = find(x_cell{i}.data >= end_x-0.0001 & x_cell{i}.data <= current_x);
wall_length = length(xwall(xwall >= end_x & xwall <= current_x));
% Extract the x and y coordinates within the current section
section_x = x_cell{i}.data(section_indices);
disp(min(section_x));disp(max(section_x));
section_y = y_cell{i}.data(section_indices);
section_u = u_cell{i}.data(section_indices);
section_v = v_cell{i}.data(section_indices);
section_T = T_cell{i}.data(section_indices);
section_P = P_cell{i}.data(section_indices);
section_Tw = Tw_cell{i}.data(section_indices);
% Create linearly spaced vectors for interpolation
% interp_X = linspace(min(section_x), max(section_x), wall_length * 5);
% interp_Y = linspace(min(section_y), max(section_y), num_y_coordinates(i).num_y * 3);
% [interp_X_grid, interp_Y_grid] = meshgrid(interp_X, interp_Y);
Ylength = num_y_coordinates(i).num_y*3.5;
Ylength = 200;
interp_X = linspace(min(section_x), max(section_x), round(Ylength)*round(1.694444444));
interp_Y = linspace(min(section_y), max(section_y),round(Ylength));
% Construct meshgrid
[interp_x{j}, interp_y{j}] = meshgrid(interp_X, interp_Y);
F_u = scatteredInterpolant(section_x, section_y, section_u, 'natural', 'none');
% F_v = scatteredInterpolant(section_x, section_y, suection_v, 'natural', 'none');
% F_T = scatteredInterpolant(section_x, section_y, section_T, 'natural', 'none');
% F_P = scatteredInterpolant(section_x, section_y, section_P, 'natural', 'none');
%
%
% % Interpolate and re-normalize the data
%
interp_u{num_sections- j + 1} = smooth2a(F_u(interp_x{j}, interp_y{j}),8,8);
% interp_v{num_sections- j + 1} = smooth2a(F_v(interp_x{j}, interp_y{j}),8,8);
% interp_T{num_sections- j + 1} = smooth2a(F_T(interp_x{j}, interp_y{j}),8,8);
% interp_P{num_sections- j + 1} = smooth2a(F_P(interp_x{j}, interp_y{j}),8,8);
interp_x_new{num_sections- j + 1} = interp_x{j};
interp_y_new{num_sections- j + 1} = interp_y{j};
% Update current_x for the next section
current_x = end_x;
end
% Update cell arrays to contain the combined matrices
interp_u_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_u);
interp_v_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_v);
interp_T_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_T);
interp_P_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_P);
interp_x_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_x_new);
interp_y_cell{i} = struct('file_name', x_cell{i}.file_name, 'data', interp_y_new);
end
folder_path = uigetdir('Select the folder containing the text files');
% Define the file name without leading space characters
% Define the file name without leading space characters
filename = 'StaedyFlowM028Re8000.mat';
% Concatenate the folder path and file name to create the full path
full_path = fullfile(folder_path, filename);
% Save the structures to the file using MAT-file version 7.3
save(full_path, 'interp_u_cell', 'interp_v_cell', 'interp_T_cell', 'interp_P_cell', 'interp_Tw_cell', 'interp_x_cell', 'interp_y_cell', '-v7.3');
  1 件のコメント
Swastik Sarkar
Swastik Sarkar 2024 年 6 月 18 日
Hi @ran,
Could you please specify how we can use the file you have attached to plot the figure ?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCoordinate Systems についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by