dengwirda / jigsaw

JIGSAW is a Delaunay-based unstructured mesh generator for two- and three-dimensional geometries.
Other
144 stars 36 forks source link

How can I compile it with my code as header-only?(don't need to linked to the library) #49

Closed gwt829 closed 1 year ago

gwt829 commented 2 years ago

Dear developer: Jigsaw is a very excellent mesh generation library! I use it to generate meshes before finite element calculation. I am not a programmer, but a mechanics researcher. I often use MATLAB language instead of C++ language in my work. I'm just a C++ beginner. Although there is a MATLAB version of jigsaw-matlab, generating a large number of nodes and units (millions) will spend a lot of time on file i/o, so I want to compile jigsaw into mex function. How can I get it? I use VS2017 and MATLAB R2021a.

dengwirda commented 2 years ago

@gwt829 thanks for your interest in jigsaw! One way to approach this could be to write a MATLAB mex function that loads the jigsaw API (jigsaw.dll on Windows). This should allow you to call from MATLAB to jigsaw without any file I/O. The interface to jigsaw's API is a set of C structs + function calls defined in jigsaw/inc/. Creating such a mex interface may require a little work though, and it could be worthwhile first exploring whether I/O time is definitely an issue for your workflows first. I/O is typically not a dominant part of the overall runtime --- for meshes of 10's of millions of cells I/O time may be a minute or two, based on my experience.

gwt829 commented 2 years ago

Thank you for your answer. I have solved this problem. The reason why I want to avoid file i/o is that a model is composed of a large number of small geometry rather than a large one, so the mesh generation of a model may involve thousands of file i/o operations. In addition, I want to ask:

  1. Can only surface meshes (triangles) of 3D geometry be generated instead of volume meshes (tetrahedrons)?

  2. Whether to consider adding quadrilateral mesh generation of the plane?

I read your doctoral thesis. My idea is that when inserting new points at the current end, it is no longer through the off-center method, but based on the cross field of geometry. The new points inserted in this way form a right triangle with the front edge and finally form a high-quality boundary-aligned quadrilateral by merging the triangles. I wrote a MATLAB program, but robustness is a problem. I want to implement it in C++, but it's very difficult for me.

dengwirda commented 2 years ago

@gwt829, to answer your questions:

  1. Yes, both surface and volume meshing is supported, though the surface meshing case is perhaps more mature. Setting opts.mesh_dims = k defines the topological dimension of the mesh to generate, so k = 2 will give a surface mesh and k = 3 will give a volume mesh (k = 1 will mesh just the sharp curves in the geometry as edges).
  2. There's not genuine support for quad meshing at present, and I'd say that adding this would be quite involved. I agree that the cross-field ideas are very interesting, both for the quadrilateral and hexahedral cases, and I know that gmsh has pursued a strategy similar to what you outline.