MATLAB读取TECPLOT笛卡尔网格三维流场数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB读取TECPLOT笛卡尔网格三维流场数据相关的知识,希望对你有一定的参考价值。

tecplot按照网格点逐点输出数据到文件,一个点的坐标及其相关数据写成一行,更具数据文件头可以知道,一行含七个数据,分别是x,y,z,u,v,w,rho。

1、matlab读取tecplot文件,将数据存贮到三维数组中,并保存变量到mat文件以供调用

% read data from tecplot file 
% save the data as the three dimension arrays
function [x,y,z,u,v,w,rho]=tecplot2mat(filename,num_head)
%% tecplot data file read
fid = fopen(strcat(filename,‘.dat‘));
data = textscan(fid,‘%f %f %f %f %f %f %f‘,‘headerlines‘,num_head);
data = cell2mat(data);
fclose(fid);

%% reshape data
% get discrete points
xi = sort(unique(data(:,1)));
yi = sort(unique(data(:,2)));
zi = sort(unique(data(:,3)));

% number of the discrete points
num_x = length(xi);
num_y = length(yi);
num_z = length(zi);

% initialize the three demonsions array
x = zeros(num_x,num_y,num_z);
y = zeros(num_x,num_y,num_z);
z = zeros(num_x,num_y,num_z);
u = zeros(num_x,num_y,num_z);
v = zeros(num_x,num_y,num_z);
w = zeros(num_x,num_y,num_z);
rho = zeros(num_x,num_y,num_z);

% assignment the array according to the data
for n = 1:size(data,1)
%     % if we don‘t know the relationship between the number and the index,we
%     % must find the index according to the number
%     index_x = find(data(n,1) == xi);
%     index_y = find(data(n,2) == yi);
%     index_z = find(data(n,3) == zi);
    % if we know the relationship between the number and the index, we can
    % directly access the index
    index_x = data(n,1) + 1;
    index_y = data(n,2) + 1;
    index_z = data(n,3) + 1;
    % access the data
    x(index_x,index_y,index_z) = data(n,1);
    y(index_x,index_y,index_z) = data(n,2);
    z(index_x,index_y,index_z) = data(n,3);
    u(index_x,index_y,index_z) = data(n,4);
    v(index_x,index_y,index_z) = data(n,5);
    w(index_x,index_y,index_z) = data(n,6);
    rho(index_x,index_y,index_z) = data(n,7);
end

fprintf(‘reshape the data\n‘);

%% data save to mat
eval([‘save ‘,filename,‘ x y z u v w rho;‘]);

fprintf(‘save the data\n‘);
end

2、测试函数

clc;clear;
close all;

file_info = dir(‘*.dat‘);
file_num = length(file_info);
num_head = 3;
for i = 1:file_num
    [~,~,~,~,~,~,~]=tecplot2mat(file_info(i).name,num_head);
end

 

以上是关于MATLAB读取TECPLOT笛卡尔网格三维流场数据的主要内容,如果未能解决你的问题,请参考以下文章

如何用TECPLOT画温度云图,求高手指教

三维重建基于切片的三维重建MATLAB仿真

MATLAB绘图—三维网格绘图(mesh)

哪位大哥有FLUENT中三维既有自转又有公转的滑移网格或者动网格的例子,跪求!

tecplot云图怎么显示截面多相流颗粒粒径分布或者相含率

matlab三维隐函数网格图