How to export FEMesh?
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!