How to import geometry with holes to use with PDE toolbox?

So there are two main options for creating geometry for a PDE model: geometryFromMesh and importGeometry.
The geometry I have is essentially a hollow sphere (i.e. a solid sphere with a smaller spherical cutout inside). I have created an STL file and attempted to use importGeometry. However, I get the error "Assemblies of more than one geometric model are not currently supported"
Now I am looking into using geometryFromMesh. I have two questions: 1. Is this even possible? 2. If so, then how might I create a mesh that has holes in it?
This is the geometry I'm trying to use.

Answers (1)

You could try something like the following series of commands:
[az,el,r] = meshgrid(linspace(0,2*pi-0.01),linspace(-pi,pi-0.01),linspace(0.25,1));
[x,y,z] = sph2cart(az,el,r);
shp = alphaShape(x(:),y(:),z(:),0.05);
[elements,nodes] = boundaryFacets(shp);
nodes = nodes';
elements = elements';
model = createpde();
geometryFromMesh(model,nodes,elements);
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5)
Don't forget to mesh your resulting geometry by using generateMesh.
Alan Weiss
MATLAB mathematical toolbox documentation

5 Comments

Thanks for the answer. Your code does work; however, if I do something similar from importing an STL file, I keep getting this error:
Failed to create geometry, the input does not form a closed volume.
This may be due to missing faces or gaps in the input.
The thing is, I'm sure my geometry is actually closed since I drew these in Autodesk Inventor and exported to STL. I have also tried using Meshlab to make the surfaces "watertight"/closed and still the issue persists.
Another issue I sometimes encounter is Maltab crashing, saying an "internal issue" has occured. This occurs when attempting to generate the mesh.
I am sorry, but there are limitations in the current STL import. We are certainly working on improving our 3-D geometry handling. However, at present, the geometry creation commands I gave are the only way I know to create a hollow sphere.
Then again, I don't know all the details of our 3-D STL geometry reconstruction, so it is possible that some other way might work. If the commands I gave are unsatisfactory, then perhaps you can try contacting technical support.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Thanks Alan,
Would be awesome to see improvement in 3D geometry handling. Right now, I'm not even using a hollow sphere; it's actually a completely solid object.
I can consistently get MATLAB to crash now when using generateMesh.
When I plot using pdegplot, everything looks fine. Checking the FEMesh also seems ok. However for some reason using your version of the code works.
Here is the code I use:
% Make a big sphere
[x,y,z]=sphere(24);
shp = alphaShape(x(:),y(:),z(:), 10);
[faces,vertices] = boundaryFacets(shp);
vertices = vertices.*10e-4;
% Make a small sphere
[x,y,z]=sphere(24);
shp = alphaShape(x(:),y(:),z(:), 10);
[f,v] = boundaryFacets(shp);
v = v.*10e-5;
% Combine the two spheres
fnew = [faces; f + length(vertices)];
vnew = [vertices; v];
faces = fnew;
vertices = vnew;
model = createpde();
gd = geometryFromMesh(model, vertices', faces');
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5);
% the geometry seems plots alright and has 2 faces
% however the next step crashes
generateMesh(model);
I can also consistently get it to crash with STL files that I have sculpted in Meshmixer--and these are not even large STL files.
I am very sorry that you are having such trouble with geometry creation. But really, you are trying to push the current 3-D geometry beyond what it can do. It is not designed for subdomains, nor for holes or multiple regions. My code is sort of fortuitously workable, but I don't really know why.
If you can afford to wait until the next release in March, then things might be somewhat better, but I cannot promise or even describe anything that is coming up. Sorry.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Asked:

on 18 Jan 2017

Commented:

on 2 Feb 2017

Community Treasure Hunt

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

Start Hunting!