How to import 2D finite element data from Matlab to Paraview?

14 visualizaciones (últimos 30 días)
Dimitrios Kalliontzis
Dimitrios Kalliontzis el 5 de Feb. de 2021
Respondida: Maneet Kaur Bagga el 8 de Mayo de 2024
Hello everyone!
I have 2D finite element data that are generated in matlab and I am trying to use this code for post-processing in Paraview:
https://www.mathworks.com/matlabcentral/fileexchange/47814-vtkwrite-exports-various-2d-3d-data-to-paraview-in-vtk-file-format.
I have the following matrices:
1) CRD(# of nodes, 2) which gives the 2D coordinates of the nodes,
2) Nodes(# of nodes per element,# of elements) which provides the connectivity between the nodes,
3) U(# of nodes, 2) which gives the x & y velocities per node, and
4) P(# of nodes, 1) which gives the pressure on a node.
However, I am not quite sure how can I put all these in the appropriate form so that they are compatible with the code. I went through several trials but it seems that the data are not saved properly. I would appreciate your help!

Respuestas (1)

Maneet Kaur Bagga
Maneet Kaur Bagga el 8 de Mayo de 2024
Hi,
As per my understanding you want to export the 2D finite element data from MATLAB to Paraview using the given "VTK Export Script". One of the possible workaround for this could be as follows:
Given the "CRD" is 2D and VTK expects 3D coordinates, append a coloumn of zeros to make the matrix 3D, MATLAB uses 1-based indexing, while VTK uses 0-based indexing therefore it should be followed accordingly:
CRD_3D = [CRD, zeros(size(CRD, 1), 1)]; % Append zeros to make it 3D
Nodes_adjusted = Nodes - 1; % Adjust for 0-based indexing if needed
Assuming the element type to be "triangle" or "quadrilateral", you can export the mesh with scalar (pressure) and vector (velocity) data as:
% Exporting 2D finite element data to VTK format
vtkwrite('finiteElementData.vtk', 'structured_grid', CRD_3D, ...
'scalars', 'Pressure', P, 'vectors', 'Velocity', U(:,1), U(:,2), zeros(size(U, 1), 1));
After the generation of the ".vtk" file, Open Paraview > File Open and select you ".vtk" file.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by