How to import 2D finite element data from Matlab to Paraview?
14 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Maneet Kaur Bagga
on 8 May 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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!