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 Center および File ExchangeSTL (STereoLithography) についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by