PDE meshing (generateMesh) failing after solid operations

Hey there,
I'm trying to develop an algorithm to define, edit and solve finite elements problems using constructive solid geometry. The libs I'm using work well, but when it comes to generate the mesh, some complex geometries return the "Meshing failed for Hmax..." error whatever the Hmax, Hmin values are.
After some tests, It seems it is the very solid operation which makes the meshing fail, even if the operation is somehow "simplifying" the model, or if it leaves the model exactly the same way. An example:
Original model: Successful mesh generation
Modified (intersection with a cube to obtain a half): failed generation
How could I avoid this? For me, since the non-modified models are of the same complexity, it does not seem a "too complex geometry" problem.
Any workaround appreciated.
Thank you

10 Comments

Can you explain more how you are generating the mesh?
Sure!
The model I am working with is loaded from a STL file through "stlread". Then, I use "mesh_boolean" from the gptoolbox to perform the solid operation (union, intersect, difference), which outputs a new set of faces (connectivity list) and points. Using this script requires a previous MEX compilation, including CGAL, gmp, libigl and Eigen.
After that, I use the script "triangulation" to generate a triangulation struct from faces and points, which is the required variable type to feed the "stlwrite" function. When the new stl is saved, it is instantly re-loaded using "importGeometry", from the PDE Toolbox. Finally, "generateMesh" is used, also from the PDE Toolbox, to generate the pde model mesh.
Thank you
% Let V2, F2, V1, F1 be the points and faces of the two selected STL's.
% Intersect solids
[semiV,semiF] = mesh_boolean(V2,F2,V1,F1, 'intersect');
% Write the altered STL model
triangulation_fish = triangulation(semiF,semiV);
stlwrite(triangulation_fish,'fish.stl');
% Create PDE Model and load the STL
mymodel = createpde;
importGeometry(mymodel,'fish.stl');
% pdegplot(mymodel,'CellLabels','on')
generateMesh(mymodel,'Hmax',0.1);
pdeplot3D(mymodel);
Can't you use another mesh generator? I didn't even know that 3d mesh can be generated using MATLAB
It is specially important that the model editing, mesh generation and problem solving are fully automatic, because this method is aimed to be inserted into an upper optimization-simulation algorithm.
Do you know a mesh software able to be launched and configured just from Matlab? A feedback would be needed, in order to tell Matlab the process is running/over.
There's an external tool called the FEATool which solves arbitrary PDE's, it has gmsh (my preferred mesh generated) built in and is fully scriptable so should be embeddable inside any existing optimisation codes.
May I ask you how you perform solid operations (like boolean ones) with geometry in MATLAB?
i am actually facing a similar problem, I try to add some Vertex to the solid so to be able to extract results at that point and then the Meshing operation fails as you say.
Thanks!
Sure!
I used raw C++ functions compiled by MATLAB using the mex command. The function is called "mesh_boolean".
You will need:
  • Alecjacobson's gptoolbox .- It contains the MATLAB mesh_boolean function call you want to use. Also you can find useful documentation on how to compile the souce files.
  • libigl .- It contains the source files needed for you compilation (the actual mesh_boolean fuction writen in C++).
  • Eigen .- The classic linear algebra C++ lib. It is used by almost any other math - related library.
Theoretically, libigl just needs Eigen, although I used CGAL and Boost too (and their dependencies) because I think this function needs them specifically. Check the documentation carefully to be aware of the libs you need to use.
The last step would be to compile the libraries source files, and then compile the mesh_boolean function directly from MATLAB. In case you are not familiar with C++, to compile your libs:
  • Download Cmake .- It is a software which reads a txt input file called "Cmakelists" to arrange some compilation options and then generates a solution. (.sln). Let us say it saves us a headache due to the many libs we would need to include and configure to compile by ourselves.
  • Download Visual Studio .- It contains an easy-to-use compiler. Just open your previously generated .sln and BUILD your libs.
And you are done! Anyway, as I have already said, the gptoolbox documentation is pretty helpful and it is a good starting point.
Cheers!

Sign in to comment.

 Accepted Answer

I figured it out a coupe weeks ago. There is a script called tetgen.m, from the gptoolbox, which uses an external program, also called Tetgen, to generate the meshes.

1 Comment

Hi there, Could you please let me know how you used gptoolbox? Did you directly input the model geometry object? I can only see that tetgen() requires a triangle mesh and then triangle() requires a .poly or .node file.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!