How to export FEMesh?

조회 수: 8 (최근 30일)
Fabian Günther
Fabian Günther 2021년 8월 23일
편집: Wan Ji 2021년 8월 23일
Dear Matlab Community,
how can I export a FEMesh created in Matlab?
Alternatively, it would also help me to just regularise the imported stl-file and then export it again as a stl-file.
Here is my code so far:
meshSize=0.05;
meshGrowthRate=1.1;
meshOrder='quadratic';
% import any unordered stl-file
model = createpde(1);
importGeometry(model,'geometry.stl');
% generation of a regular FE mesh
mesh=generateMesh(model,'Hmax',meshSize,'Hmin',meshSize,'Hgrad',meshGrowthRate,'GeometricOrder',meshOrder);
pdeplot3D(model)
I am very grateful for any help.
Best regards,
FG

채택된 답변

Wan Ji
Wan Ji 2021년 8월 23일
The mesh is now the field of model
you can get mesh by
Mesh = model.Mesh;
% nodes are obtained by
Nodes = Mesh.Nodes; % d-by-n matrix where d is the number of dimension
% elements are obtained by
Elements = Mesh.Elements; % s-by-m matrix where s is the number of nodes of one element
  댓글 수: 7
Wan Ji
Wan Ji 2021년 8월 23일
편집: Wan Ji 2021년 8월 23일
Or just have a little modification on the function
function toinp(MeshIn, fileName, ElementType)
Mesh.Elements = MeshIn.Elements';
Mesh.Nodes = MeshIn.Nodes';
if(~strncmpi(fileName(end:-1:1),'pni.',4))
fileName = [fileName,'.inp'];
end
while(exist(fileName,'file'))
s = input('File name already exists, are you sure to overwrite it (1 for yes and 0 for no)?');
switch s
case {'yes', 1}
break;
otherwise
fileName = input('Please input a new file name:','s');
end
end
if(~strncmpi(fileName(end:-1:1),'pni.',4))
fprintf('File name not with suffix ''.inp'', program will add it\n')
fileName = [fileName,'.inp'];
end
fid = fopen(fileName,'wt');
fprintf(fid,'*HEADING\n');
fprintf(fid,'%s\n**\n',fileName);
fprintf(fid,'*Node\n');
for i = 1:1:size(Mesh.Nodes,1)
ndim = size(Mesh.Nodes,2);
fprintf(fid, ['%d',repmat(',%f', 1, ndim),'\n'], i, Mesh.Nodes(i,:));
end
switch lower(ElementType)
case{'c2d3','c2d4','c2d6','c2d8'}
eType = ElementType;
eType(2:3) = 'ps';
otherwise
eType = ElementType;
end
fprintf(fid,'*Element, Type=%s\n', upper(eType));
for i = 1:1:size(Mesh.Elements,1)
nenode = size(Mesh.Elements,2);
fprintf(fid,['%d',repmat(',%d', 1, nenode),'\n'], i, Mesh.Elements(i,:));
end
fclose(fid);
fprintf('Output Inp File Successfully!\n')
end
Then use
Mesh = model.Mesh;
toinp(Mesh, 'myinp.inp', 'c3d10')
It is OK now
Fabian Günther
Fabian Günther 2021년 8월 23일
Thanks alot man!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by