FloSewn / TQMesh

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

Problem with very narrow inside boundary #24

Closed danielsue closed 5 months ago

danielsue commented 5 months ago

Hi Flo,

Thanks for the nice tool. I got some problem when there is very narrow inside boundary included. My intension is to include a line constraint. Since the tool does not support it yet, I would like to add a thin inside boundary instead and then mesh the inside mesh and merge these two together. However, I got some weird result at the first step. Attached is the script I have modified from an example and the result is also attached.

frac2d-quad.para.txt

Screen Shot 2024-03-30 at 11 33 38 PM

Thanks,

Daniel

FloSewn commented 5 months ago

Hey Daniel,

thanks for your interest! I think your output results from the fact that TQMesh is not yet able to handle this type of grid. The local cell size is always measured using the smallest edge length in order to generate good elements as a rule. In your case, however, this leads to very small elements. You could still change the scaling parameters of vertices 4-6 to at least make the size distribution in the area of the line a little smoother - but this would result in a very large number of elements overall.

Are you trying to mimic the line constraint in order to locally refine the mesh along that line - or do you also need that line in order to access these vertices later on - similarly to vertices at boundary segments? If the former is the case, you could try to use fixed vertices (as for example in example 4), that you distribute along your line - with a small size and range parameter. Here is an example:

#===========================================================
#                         TQMESH     
#===========================================================

#-----------------------------------------------------------
#                     MESH DEFINITION
#-----------------------------------------------------------
Define mesh:
  Element size: 10 
  Element color: 1
  Meshing algorithm: Triangulation
  Number of quad refinements: 0
  Smooth quad layers: 0
  Number of smoothing iterations: 2

  # Output formats: COUT, TXT, VTU
  Output file format: VTU
  Output file prefix: ./frac2d-quad

  Define boundary vertices:
      0.00, -200.00  # v0
    100.00, -200.00  # v1
    100.00,    0.00  # v2
      0.00,    0.00  # v3
  End boundary vertices

  Define exterior boundary edges:
    0, 1,    2                 # Marker for bottom edge
    1, 2,    2                 # Marker for bottom edge
    2, 3,    2                 # Marker for bottom edge
    3, 0,    3                 # Marker for right edge
  End exterior boundary edges

  Define fixed vertices:
    50.0, -100.0,   0.1, 20.0
    52.0, -100.0,   0.1, 20.0
    54.0, -100.0,   0.1, 20.0
    56.0, -100.0,   0.1, 20.0
    58.0, -100.0,   0.1, 20.0
    60.0, -100.0,   0.1, 20.0
  End fixed vertices

End mesh

Greetings Flo

danielsue commented 5 months ago

Hi @FloSewn, thanks for your quick response. I am trying to mimic the line constraint in order to locally refine the mesh along that line. This line will be used as a fracture in the simulation domain. My objective is to generate anisotropic quadrilateral mesh along the fracture. The fracture is usually 10 to 100 meters in length but only 1cm in aperture. This is something like adding quad layers to the internal boundary as shown in 02_square_in_channel.para except the internal boundary is very narrow. Though the number of cells will be big, it is still way less compared to isotropic triangle mesh with a similar resolution. Thanks.

FloSewn commented 5 months ago

Ahh I see - so you actually do need some kind of a hole to model the fracture?

In that case, the element quality in your example could probably be enhanced by adjusting the mesh scale at some vertices, as for example here:

#===========================================================
#                         TQMESH
#===========================================================

#-----------------------------------------------------------
#                     MESH DEFINITION
#-----------------------------------------------------------
Define mesh:
  Element size: 10
  Element color: 1
  Meshing algorithm: Triangulation
  Number of quad refinements: 1
  Smooth quad layers: 0
  Number of smoothing iterations: 1

  # Output formats: COUT, TXT, VTU
  Output file format: VTU
  Output file prefix: ./frac2d-quad

  #---------------------------------------------------------
  #                        BOUNDARIES
  #---------------------------------------------------------
  Define boundary vertices:
     50.00,   -140.0000  
    100.00,   -140.0000 
    100.00,   -110.0000 
     50.00,   -110.0000  
    77.03125, -134.0878, 0.1, 0.1  # Adjust the last two values to change element size in the 
    77.04852, -134.0778, 0.1, 0.1  # vicinity of the vertices at the fracture
    68.49935, -119.4510, 0.1, 0.1  # The first value defines a local mesh scale
    68.48208, -119.4611, 0.1, 0.1  # The second value defines the local area within the scale is applied
  End boundary vertices

  Define exterior boundary edges:
    0, 1,    2                
    1, 2,    2                 
    2, 3,    2                 
    3, 0,    3                 
  End exterior boundary edges

  Define interior boundary edges:
    4, 7,    4                
    7, 6,    4                 
    6, 5,    4
    5, 4,    4
  End interior boundary edges

  #---------------------------------------------------------
  #                       QUAD-LAYERS
  #---------------------------------------------------------
  Add quad layers: 77.03125, -134.0878, 77.03125, -134.0878, 2, 0.1, 1.3

End mesh

I adjusted the size of your domain a little to speedup the meshing process. Here you can see the outcome:

Mesh

Regards, Flo

danielsue commented 5 months ago

Hi @FloSewn,

Your suggestion works. Is it possible to make the refinement at the vertices more aggressive? Though the specified local area is 0.1, the results shows the refined zone is much larger than this value. It would be great if the blue area at both ends of the fracture can be much smaller to reduce the number of cells. Thanks.

Daniel

FloSewn commented 5 months ago

Hi Daniel,

yes that's possible by simply reducing the range parameters a little. However, to get a better mesh quality, you should also slightly decrease the global element size. Otherwise the disparity between the element size will get too large near the small edge of the fracture and the meshing attempt might fail.

Here's an example with a much larger growth rate of elements:

#===========================================================
#                         TQMESH
#===========================================================

#-----------------------------------------------------------
#                     MESH DEFINITION
#-----------------------------------------------------------
Define mesh:
  Element size: 4
  Element color: 1
  Meshing algorithm: Triangulation
  Number of quad refinements: 1
  Smooth quad layers: 0
  Number of smoothing iterations: 1

  # Output formats: COUT, TXT, VTU
  Output file format: VTU
  Output file prefix: ./frac2d-quad

  #---------------------------------------------------------
  #                        BOUNDARIES
  #---------------------------------------------------------
  Define boundary vertices:
     50.00,   -140.0000
    100.00,   -140.0000
    100.00,   -110.0000
     50.00,   -110.0000
    77.03125, -134.0878, 0.1, 0.028 # Adjust the last two values to change element size in the
    77.04852, -134.0778, 0.1, 0.028 # vicinity of the vertices at the fracture
    68.49935, -119.4510, 0.1, 0.028 # The first value defines a local mesh scale
    68.48208, -119.4611, 0.1, 0.028 # The second value defines the local area within the scale is applied
  End boundary vertices

  Define exterior boundary edges:
    0, 1,    2
    1, 2,    2
    2, 3,    2
    3, 0,    3
  End exterior boundary edges

  Define interior boundary edges:
    4, 7,    4
    7, 6,    4
    6, 5,    4
    5, 4,    4
  End interior boundary edges

  #---------------------------------------------------------
  #                       QUAD-LAYERS
  #---------------------------------------------------------
  Add quad layers: 77.03125, -134.0878, 77.03125, -134.0878, 2, 0.1, 1.3

End mesh

And this is the outcome: Mesh

That's actually a very nice example - if you don't mind, I would add it to the other ones.

Greetings Flo

danielsue commented 5 months ago

Hi @FloSewn,

Thanks for you update. This looks nice and exactly what I would like to have. However, when I increase the domain to 100x200, there is something unexpected (shown below). The only thing I changed is the coordinates of outside boundary. Do you have any idea how to avoid this?

#===========================================================
#                         TQMESH
#===========================================================

#-----------------------------------------------------------
#                     MESH DEFINITION
#-----------------------------------------------------------
Define mesh:
  Element size: 10
  Element color: 1
  Meshing algorithm: Triangulation
  Number of quad refinements: 1
  Smooth quad layers: 0
  Number of smoothing iterations: 1

  # Output formats: COUT, TXT, VTU
  Output file format: VTU
  Output file prefix: ./frac2d-quad-b

  #---------------------------------------------------------
  #                        BOUNDARIES
  #---------------------------------------------------------
  Define boundary vertices:
     50.00,   -140.0000  
    100.00,   -140.0000 
    100.00,   -110.0000 
     50.00,   -110.0000  
    77.03125, -134.0878, 0.1, 0.1  # Adjust the last two values to change element size in the 
    77.04852, -134.0778, 0.1, 0.1  # vicinity of the vertices at the fracture
    68.49935, -119.4510, 0.1, 0.1  # The first value defines a local mesh scale
    68.48208, -119.4611, 0.1, 0.1  # The second value defines the local area within the scale is applied
  End boundary vertices

  Define exterior boundary edges:
    0, 1,    2                
    1, 2,    2                 
    2, 3,    2                 
    3, 0,    3                 
  End exterior boundary edges

  Define interior boundary edges:
    4, 7,    4                
    7, 6,    4                 
    6, 5,    4
    5, 4,    4
  End interior boundary edges

  #---------------------------------------------------------
  #                       QUAD-LAYERS
  #---------------------------------------------------------
  Add quad layers: 77.03125, -134.0878, 77.03125, -134.0878, 2, 0.1, 1.3

End mesh

frac2d-100x200-vs-50x30 Left: size 100x200, Right: size 50x30.

Thanks and regards,

Daniel

FloSewn commented 5 months ago

Hey Daniel,

that's unfortunate. It seems that the meshing approach fails, which might stem from the large gradients of the size function for this case. It should help to increase the range values a little bit - here I adjusted them slightly to a value of 0.035. In that way the size function will feature a smoother gradient near the fracture edges. Does this work for you?

#===========================================================
#                         TQMESH
#===========================================================

#-----------------------------------------------------------
#                     MESH DEFINITION
#-----------------------------------------------------------
Define mesh:
  Element size: 8
  Element color: 1
  Meshing algorithm: Triangulation
  Number of quad refinements: 1
  Smooth quad layers: 0
  Number of smoothing iterations: 1

  # Output formats: COUT, TXT, VTU
  Output file format: VTU
  Output file prefix: ./frac2d-quad

  #---------------------------------------------------------
  #                        BOUNDARIES
  #---------------------------------------------------------
  Define boundary vertices:
      0.00,   -200.0000
    100.00,   -200.0000
    100.00,      0.0000
      0.00,      0.0000
    77.03125, -134.0878, 0.1, 0.035 # Adjust the last two values to change element size in the
    77.04852, -134.0778, 0.1, 0.035 # vicinity of the vertices at the fracture
    68.49935, -119.4510, 0.1, 0.035 # The first value defines a local mesh scale
    68.48208, -119.4611, 0.1, 0.035 # The second value defines the local area within the scale is applied
  End boundary vertices

  Define exterior boundary edges:
    0, 1,    2
    1, 2,    2
    2, 3,    2
    3, 0,    3
  End exterior boundary edges

  Define interior boundary edges:
    4, 7,    4
    7, 6,    4
    6, 5,    4
    5, 4,    4
  End interior boundary edges

  #---------------------------------------------------------
  #                       QUAD-LAYERS
  #---------------------------------------------------------
  Add quad layers: 77.03125, -134.0878, 77.03125, -134.0878, 2, 0.1, 1.3

End mesh

That's probably something that should be improved for a future release.

Regards, Flo

danielsue commented 5 months ago

Thanks, Flo. It works after adjusting the parameter a bit. Regards, Daniel