Reading *.msh files (3D) in Matlab.

조회 수: 184 (최근 30일)
Sanwar Ahmad
Sanwar Ahmad 2019년 10월 1일
편집: ALI 2024년 5월 1일
I have created this 3D geometry and the mesh in Gmsh, now I need to get the number of nodes, elements, faces from the mesh in Matlab. How can I do that?
I can send you the *.geo and the *.msh files.
Thanks in advance.
Sanwar

채택된 답변

ADSW121365
ADSW121365 2020년 3월 6일
If you're using gmsh, you can use its inbuilt exporter to export a .m file to read into MATLAB.
This loads in a structure array called msh.
Assuming a 3D linear tetrahedral mesh:
%Uses pre-created mesh from gmsh
%Run mesh file name without .m:
Single_coil
nodes = msh.POS';
elements = msh.TETS;
groupsID = elements(:,5);
%If you have multiple domains, this will contain domain IDs
% (assuming you haven't checked 'export all elements', else it will be a column of zeros.
elements = elements(:,1:4);
elements =elements';
geom2 = geometryFromMesh(model,nodes,elements,groupsID); %Import to PDE Toolbox
%If you have subdomains, this will identify their geometries even for a coherent mesh:
%In my example, my actual mesh is just a solid 3D box, however by giving the group IDs
% it is able to identify internal cells, faces etc
%% Plotting:
figure(1); pdeplot3D(model,'FaceAlpha',0.5) %Mesh Plot
figure(2); pdegplot(model,'CellLabels','on','FaceAlpha',0.5) %Geometry
figure(3); pdegplot(model,'FaceLabels','on','FaceAlpha',0.5) %Geometry
%% Finding specific elements/nodes:
%Given this setup, the labels in figures 2 and 3 will allow you to identify faces,
%cells or areas using the usual functions mentioned above.
C_e = findElements(model.Mesh,'region','cell',1); %Coil
C_n = findNodes(model.Mesh,'region','cell',1);
  댓글 수: 13
廷臣 沈
廷臣 沈 2023년 10월 22일
Try ticking this option here. It will appear after you choose to save.
Jutamas Taweesint
Jutamas Taweesint 2024년 4월 14일
편집: Jutamas Taweesint 2024년 4월 14일
Hi, I run the code and it's error.
How should I do?
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2019년 11월 5일
findElements and findNodes can be used to calculate the number of elements and nodes in a mesh respectievely.
You can find the documentation for both the functions in the following links
  댓글 수: 3
Harshit Ks
Harshit Ks 2020년 9월 23일
@Sanwar Ahmad
Hi, I am stuck on the same problem as in your original question.
Can you share the codes to read .msh files?
Thanks.
Sanwar Ahmad
Sanwar Ahmad 2020년 9월 24일
@Harshit Ks, follow the link and download gmsh_size_read.m and any related .m files. You may have to change it based on the Gmsh version you are using, that's what I did.
Have fun.

댓글을 달려면 로그인하십시오.


ALI
ALI 2024년 5월 1일
편집: ALI 2024년 5월 1일
hi can i solve overset meshes in matlab please?
if you have any code please share

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by