Is there a way to import 2D meshes (nodes and triangles) into PDE model objects?

I am using the PDE toolbox to calculate coupled structural and acoustical problems. For 3D geometries it is possible to import a tetraeder mesh into the model by using the Matlab function
geometryFromMesh
I could not find a similar function for 2D geometry and the properties
model.Mesh.Nodes
and
model.Mesh.Elements
are read-only. I need such a function because I want to do the meshing outside the PDE toolbox. Is there a way to import my own 2D-mesh into the PDE model objects?
Regards Benjamin

 Akzeptierte Antwort

Alan Weiss
Alan Weiss am 27 Jun. 2017
There is currently no functionality for creating geometry from a 2-D mesh. Sorry.
You might be able to use legacy functions to solve a PDE using a [p,e,t] mesh. You'll have to figure out how to specify coefficients and boundary conditions. For example, use a boundary matrix (very difficult) as sketched in the legacy assemb function reference page. Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

9 Kommentare

Thank's for the quick answer. I found an unsupported way of importing the 2D mesh by using
assoc = pde.FEMeshAssociation(t, e);
model.Mesh = pde.FEMesh(p, t, Hmax, Hmin, geomorder,assoc)
pde.FEMesh(nodes,tet,Hmax,Hmin, geomOrder,assoc);
where p, e, t are the mesh in the format used in the legacy workflow. Hmax and Hmin are the maximum and minimum lengths of the triangles' edges. This is more a hack than a solution but it seems to work.
Wow, I had no idea that functionality existed.
Alan Weiss
MATLAB mathematical toolbox documentation
I found it by looking at the original code in the toolbox function generateMesh. I was lucky to find that the source code can be viewed. Here is an example of what I wanted to do:
Thank you so much, it was really helpful! I wish I found this earlier.
Hi Benjamin, I need fine mesh on one of the boundary of a rectangular domain and not in the whole rectangle.How can I do that ? How did you able to change the source code of generateMesh. Any help would be appreciated.
Hi, So this is what I do, First create a structured triangular mesh in another software (Patran-Nastran), Then I convert it to matlab’s mesh format (p,e,t).
The code is as follows.
if true
% code
bdffile=mesh8.txt' % cantaleaver
[nodeData,elemData] = elemnodeDatatria6(bdffile);
p=(nodeData(:,2:3))' ;
t=[(elemData(:,2:7)) ,ones(size(elemData,1),1)]';
figure(201)
plot(p(1,:),p(2,:),'.')
hold on
[k,v] = boundary(p',0);
plot(p(1,k(:)),p(2,k(:)),'o')
hold on
xb=p(1,k(:)) ;
yb=p(2,k(:));
dl=xb(3)-xb(1)
Hmax=dl
Hmin=dl
R = [3,6,0,0,2,2,2,2,0.5,-0.5,-0.5,-.05,.05, 0.5]'; % Cantaleaver
gm = [R];
for i=1:size(R,2)
str{i} = ( sprintf('R%d',i) );
end
sf=[];
for i=1:size(R,2)
sf=char([str{i},'+',sf]);
end
sf=sf(1:end-1);
delete(model.Geometry)
model.Geometry = [];
ns = char(str);
ns = ns';
g= decsg(gm,sf,ns);
geometryFromEdges(model,g);
figure
pdegplot(model,'EdgeLabels','on');
order='quadratic';
xmax=max(xb);
xmin=min(xb) ;
ymax=max(yb);
ymin=min(yb) ;
nx=(xmax-xmin)/abs(p(1,2)-p(1,1));
ny=(ymax-ymin)/abs(p(1,2)-p(1,1));
edge2=k(1:nx+1);
edge4=k(nx+1:nx+ny/2-1);
edge5=k(nx+ny/2-1:nx+ny/2+3);
edge6=k(nx+ny/2+3:nx+ny+1 );
edge3=k(nx+ny+1:2*nx+ny+1 );
edge1=k(2*nx+ny+1:2*nx+2*ny+1 );
E2s=(p(1,edge2(1:end-1))-p(1,edge2(1)))/(p(1,edge2(end))-p(1,edge2(1)));
E2e=(p(1,edge2(2:end))-p(1,edge2(1)))/(p(1,edge2(end))-p(1,edge2(1)));
E4s=(p(2,edge4(1:end-1))-p(2,edge4(1)))/(p(2,edge4(end))-p(2,edge4(1)));
E4e=(p(2,edge4(2:end))-p(2,edge4(1)))/ (p(2,edge4(end))-p(2,edge4(1)));
E5s=(p(2,edge5(1:end-1))-p(2,edge5(1)))/(p(2,edge5(end))-p(2,edge5(1)));
E5e=(p(2,edge5(2:end))-p(2,edge5(1)))/ (p(2,edge5(end))-p(2,edge5(1)));
E6s=(p(2,edge6(1:end-1))-p(2,edge6(1)))/(p(2,edge6(end))-p(2,edge6(1)));
E6e=(p(2,edge6(2:end))-p(2,edge6(1)))/ (p(2,edge6(end))-p(2,edge6(1)));
E3s=(p(1,edge3(1:end-1))-p(1,edge3(1)))/(p(1,edge3(end))-p(1,edge3(1)));
E3e=(p(1,edge3(2:end))-p(1,edge3(1)))/(p(1,edge3(end))-p(1,edge3(1)));
E1s=(p(2,edge1(1:end-1))-p(2,edge1(1)))/(p(2,edge1(end))-p(2,edge1(1)));
E1e=(p(2,edge1(2:end))-p(2,edge1(1)))/ (p(2,edge1(end))-p(2,edge1(1))) ;
e(1,:)=[edge1(1:end-1)',edge2(1:end-1)',edge3(1:end-1)',edge4(1:end-1)',edge5(1:end-1)',edge6(1:end-1)'];
e(2,:)=[edge1(2:end)' ,edge2(2:end)' ,edge3(2:end)' ,edge4(2:end)' ,edge5(2:end)' ,edge6(2:end)'];
e(3,:)=[E1s,E2s,E3s,E4s,E5s,E6s];
e(4,:)=[E1e,E2e,E3e,E4e,E5e,E6e];
e(5,:)=[1*ones( size(E1s)),2*ones(size(E2s)),3*ones(size(E3s)),4*ones(size(E4s)),5*ones(size(E5s)),6*ones(size(E6s))];
e(6,:)=ones(size(e(5,:)));
e(7,:)=zeros(size(e(5,:)));
whos t;
t=double(t);
assoc = pde.FEMeshAssociation(t, e);
model.Mesh = pde.FEMesh(p, t(1:6,:), Hmax, Hmin, order,assoc);
pde.FEMesh(p,t(1:6,:) ,Hmax,Hmin, order,assoc);
figure(200)
pdemesh( model,'NodeLabels','on')
axis equal
end
This is an example, for your type of geometry or another meshing it might differ.
Thank you
Thank you very much.
Hi Kaveh I was trying to run your code in matlab but got error saying 'Undefined function or variable 'elemnodeDatatria6'.How can I avoid it. Appreciate your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by