How to export 3D spheres (3D plot) generated in Matlab to ANSYS or Abaqus. ?
이전 댓글 표시
I want to export 3D spheres generated in Matlab to ANSYS or Abaqus. 3D spheres are randomly generated and I want to mesh the 3D spheres and analyse those. Can anyone help me to export the 3D sphere plot to any meshing software like Gmsh or Ansys or Abaqus?

댓글 수: 2
Anton Semechko
2018년 7월 5일
The spheres in your image, are they represented by level-sets of an implicit function?
Sadeep Thilakarathna
2018년 7월 6일
답변 (1개)
Anton Semechko
2018년 7월 6일
편집: Anton Semechko
2018년 7월 6일
The builtin 'ellipsoid' and 'sphere' functions produce bad quality meshes (in terms of element shapes and connectivity of the vertices). You can get much better quality meshes using functions from here.
Here are is an example:
% Unit sphere based on subdivision of an icosahedron; triangular mesh
TRa=SubdivideSphericalMesh(IcosahedronMesh,4);
% Unit sphere based on subdivision of a cube; quadrilateral mesh
TRb=SubdivideSphericalMesh(QuadCubeMesh,4);
% Visualize
figure('color','w')
subplot(1,3,1)
h=trimesh(TRa);
set(h,'EdgeColor','k','FaceColor',[0.9 0.9 0.9],'EdgeAlpha',0.5);
axis equal off vis3d
view([30 30])
zoom(1.5)
avp=GetAxesViewProps(gca);
ha=subplot(1,3,2);
h=patch(TRb);
set(h,'EdgeColor','k','FaceColor',[0.9 0.9 0.9],'EdgeAlpha',0.5);
axis equal off vis3d
MatchAxesView(avp,ha)
% Plot sphere generated with built-in 'sphere' function for comparison
ha=subplot(1,3,3);
[X,Y,Z]=sphere(20);
h=surf(X,Y,Z);
set(h,'EdgeColor','k','FaceColor',[0.9 0.9 0.9],'EdgeAlpha',0.5);
axis equal off vis3d
MatchAxesView(avp,ha)

1) When exporting the meshes, do you want the program to recognize the individual spheres or would it be OK if the their face-vertex connectivity lists were merged (so you would have a single mesh containing multiple disconnected spheres)?
2) What type of meshes will you be generating after exporting the spheres; hexahedral or tetrahedral?
댓글 수: 8
Sadeep Thilakarathna
2018년 7월 6일
Anton Semechko
2018년 7월 6일
편집: Anton Semechko
2018년 7월 10일
Below is an example of how you can export multiple spheres to a .msh file (Gmsh standard). Assuming you already got the functions for generating spheres from here, for this example to work, you will also need to get functions 'gmsh_mesh2d_write.m' and 'mesh_base_one.m' from here. Let me know if you run into any problems.
function sphere_mesh_export_demo
% Suppose you have N spheres. Let C and R be N-by-3 and N-by-1 arrays
% containing centroid coordinates and radii of the spheres, respectively.
% As an example, I will use N=10, R=linspace(0.1,0.3,N), and distribute
% spheres along the x-axis without them touching one another.
N=10;
R=1:N;
C=zeros(N,3); % initialize centroid coordinates
ds=min(R)/10; % separation between closest points on two adjacent spheres
for n=2:N
C(n,1)=C(n-1,1) + R(n-1) + R(n) + ds;
end
% Step 1: Get mesh of a unit sphere
n_sub=4; % number of icosahedron subdivisions
TRo=SubdivideSphericalMesh(IcosahedronMesh,n_sub); % mesh will have Nv=10*4^n_sub+2 vertices and Nf=2*Nv-4 faces
[Fo,Vo]=GetMeshData(TRo); % Fo is a Nf-by-3 array of faces and Vo is a Nv-by-3 array of vertex coordinates
% Step 2: Generate a composite mesh with spheres distributed accroding to C and R
Nv=size(Vo,1);
[F,V]=deal(cell(N,1));
for n=1:N
V{n}=bsxfun(@plus,R(n)*Vo,C(n,:)); % scale and translate TRo to get a sphere with radius R(n) and centroid C(n,:)
F{n}=Fo+(n-1)*Nv; % face-vertex connectivity of the n-th sphere
end
V=cell2mat(V); % compposite list of vertices
F=cell2mat(F); % composite list of faces
% Visualize result
figure('color','w')
h=patch('Faces',F,'Vertices',V);
set(h,'EdgeColor','none','FaceColor',0.75*[1 1 1],'FaceAlpha',0.5);
axis equal off
camlight('headlight')
lighting phong
material('dull')
%keyboard
% Step 3: Export mesh represented by F and V to a .msh file (Gmsh standard)
FileName='SphereMeshDemo.msh';
gmsh_mesh2d_write(FileName,...
3,...
size(V,1),...
V',...
3,...
size(F,1),...
F');
Sadeep Thilakarathna
2018년 7월 10일
Anton Semechko
2018년 7월 10일
OK. Let's export mesh to a .stl file. To do this, change code under step 3 to:
FileName='SphereMeshDemo.stl';
stlwrite(FileName,F,V)
Ignore that 'stlwrite' will say 'Wrote 3 faces'. It exports the mesh correctly (see snapshot below). If you want to correct this export status bug, change line (inside 'stlwrite') that reads:
fprintf('Wrote %d faces\n',size(faces, 2));
to
fprintf('Wrote %d faces\n',size(faces, 1));

Sadeep Thilakarathna
2018년 7월 12일
Anton Semechko
2018년 7월 12일
I was under the assumption that you were going to be using surface meshes as input to generate volumetric tet meshes in the program of your choice. If you want, you can also generate tet meshes directly in Matlab using 'iso2mesh' toolbox. 's2m' is name of the function you want to be using. Description of this function can be found here .
Sadeep Thilakarathna
2018년 7월 12일
Biltu Mahato
2018년 10월 17일
How did you assign material properties to .stl file? Abaqus doesn't let me assign material properties in Abaqus for .stl file imported from Matlab.
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

