How to use Matlab to process 3D CFD data?

49 vues (au cours des 30 derniers jours)
Xicheng Wang
Xicheng Wang le 3 Mar 2023
Modifié(e) : Precise Simulation le 9 Nov 2024 à 4:03
Hi everyone,
My question is about using Matlab to read and process 3D CFD data.
Typically, 3D CFD output of each coordinate and variable is stored in a column (Nx1, N is the total number of cells, e.g., can be seen in 'X_CFD').
% For creating data purpose
[x,y,z] = meshgrid([-3:0.25:3]);
V = x.*exp(-x.^2 -y.^2 -z.^2);
% Typical CFD output
X_CFD = x(:);
Y_CFD = y(:);
Z_CFD = z(:);
V_CFD = V(:);
Now, I know how to read this data file. However, to plot this field (e.g., iso-surface of V), I can only performe a 3D interpolation on a square mesh and then plot it. Please see below:
% Create square mesh for interpolation
[xq,yq,zq] = meshgrid([-2.9:0.25:2.9]);
Vq = griddata(X_CFD,Y_CFD,Z_CFD,V_CFD,xq,yq,zq);
figure
isosurface(xq,yq,zq,Vq,1e-4)
However, in real CFD problem, the mesh is usually non-square and performing interpolation on huge number of dataset is costly.
I'm wondering does Matlab provides some features that can plot above figure by just using those single column CFD data rather than performing 3D interpolation. I know it can be done by importing them into 'Tecplot' or 'ParaView'. But I'm quite faimilar with MATLAB and want use it to performe some further post-processing.
  1 commentaire
Precise Simulation
Precise Simulation le 9 Nov 2024 à 4:01
Modifié(e) : Precise Simulation le 9 Nov 2024 à 4:03
Hi, xicheng
You can also use the FEATool simulation GUI and MATLAB toolbox to import CFD data and perform advanced flow visualizations (it supports many CFD data formats such as from the OpenFOAM and SU2 solvers), for example as show here

Connectez-vous pour commenter.

Réponses (1)

Abhijeet
Abhijeet le 8 Mar 2023
Hi Xicheng,
MATLAB provides several features for processing and visualizing 3D CFD data without the need for interpolation. One tool for working with 3D CFD data in MATLAB is the PDE Toolbox, which allows you to import, manipulate, and visualize complex geometries and meshes. Here are the steps you can use the PDE Toolbox to visualize a 3D CFD dataset:
  1. Import the data into MATLAB using the appropriate function, depending on the file format.
  2. Create a PDE model object using the createpde function. You can create the object based on the specific geometry of your CFD simulation, or you can create a generic object and import the mesh data separately.
  3. Import the mesh data using the importGeometry function. This function reads in the mesh data and adds it to the PDE model object.
  4. Create a plot of the dataset using the pdeplot3D function. This function allows you to visualize the 3D geometry and mesh, as well as any solution data that you want to plot.
A sample code example for the above approach is attached for reference:
data = importdata('filename.txt');
model = createpde();
geometryFromMesh(model, 'meshdata');
pdeplot3D(model, 'ColorMapData', data, 'FaceAlpha', 0.5);
This should produce a 3D plot of your CFD dataset, with the color of each element in the mesh corresponding to the value of the solution data at that point.
Thanks

Catégories

En savoir plus sur Computational Fluid Dynamics (CFD) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by