FloSewn / TQMesh

A simple two-dimensional mesh generator with triangular and quadrilateral elements in C++
MIT License
60 stars 16 forks source link

Fixed Vertexes in Quad Mesh #25

Closed BimwerxNZ closed 7 months ago

BimwerxNZ commented 7 months ago

Hi, first of all, excellent work and thank you so much for sharing this. I've tried a few mesh parameters and found that with quad meshes, when adding a fixed vertex, that it does not maintain that point after 'tri2quad_modification'.

I'm using cpp to create some test cases, and created a custom class to hold a list of domains to mesh. The general workflow is as follow:

  1. MeshGenerator generator{};
  2. UserSizeFunction f_1 = [factMSize](const Vec2d& p) { return factMSize; };
  3. Domain domain_1{ f_1 };
  4. Boundary& bdry_ext_1 = domain_1.add_exterior_boundary(); // using bdry_ext_1.set_shape_from_coordinates(meshDomains[0].ext_coords, meshDomains[0].ext_markers);
  5. Then I add the fixed vertexes in a loop using: domain_1.add_fixed_vertex(meshDomains[0].int_Points[i_p0].x, meshDomains[0].int_Points[i_p0].y, 0.01, 0.5);
  6. Followed by interior boundaries as follow: Boundary& bdry_int_1 = domain_1.add_interior_boundary(); (with coordinates using bdry_int_1.set_shape_from_coordinates)
  7. Now I create the mesh: Mesh& baseMesh = generator.new_mesh(domain_1);
  8. Next I add the quad layers using: generator.quad_layer_generation(baseMesh)
  9. Followed by: generator.triangulation(baseMesh).generate_elements();
  10. Then: generator.tri2quad_modification(baseMesh).modify();
  11. Then: generator.quad_refinement(baseMesh).refine();
  12. And finally the smoothing using: generator.mixed_smoothing(baseMesh)...

I am doing this for each domain, then I merge the meshes - not sure of this is where the issue resides?

The resulting mesh consists of quads, and boundary quad layers are working as expected. The only issue is that the fixed vertexes seem to do nothing. Am I missing something perhaps?

Happy to share full code, it's just quite a lot to post directly in this post.

Thanks again!

BimwerxNZ commented 7 months ago

I realized the issue was with the scaling and range values of vertexes

FloSewn commented 7 months ago

Hey there,

thanks for your kind words and your interest! It seems that your problem has been solved.

Anyway, here is the explanation of the parameters:

The scaling (or size) is the actual mesh size that is applied to the underlying size function, which will be regarded during the meshing process. The range parameter defines the circular area around the vertex, where this local mesh size is applied to.

To compute the size function at a location (x,y), we consider three values: 1) The mesh size that stems from the size function which is provided by the user 2) The length of boundary edges in the vicinity of our location (x,y) 3) Nearby vertices (with scale and range parameters $s$ and $r$), for whose we calculate the mesh scale by $h = s \cdot exp(-\frac{\Delta x^2}{r^2})$, where $\Delta x$ is the distance vector between our location (x,y) and the vertex.

We then take the smallest of these three scales. In this way the mesh size is automatically adjusted in the vicinity of small edges, without distorting the elements too much.

I'm glad if TQMesh is helpful for you - please let me know if you find any bugs or missing features.

Regards, Flo