Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small triangles in mesh generated #259

Open
Girishchandra-Yendargaye opened this issue May 20, 2022 · 9 comments
Open

Small triangles in mesh generated #259

Girishchandra-Yendargaye opened this issue May 20, 2022 · 9 comments

Comments

@Girishchandra-Yendargaye

Can we remove small triangles generated.

@Girishchandra-Yendargaye Girishchandra-Yendargaye changed the title small tringles in mesh generated Small triangles in mesh generated May 20, 2022
@stoiver
Copy link
Member

stoiver commented May 20, 2022

@Girishchandra-Yendargaye, you are right that it is important to try to create meshes without unnecessarily small triangles.

We use the triangle package http://www.cs.cmu.edu/~quake/triangle.html to create meshes via the anuga.create_domain_from_regions

The mesh is setup by defining a boundary polygon, breaklines and interior regions. If the segments of these polygons and polylines are too small, or if vertices from one polygon or polyline is too close to another then the resulting triangulation will include very small triangles. The Triangle procedure will maintain the vertices in these defining structures.

The best strategy is to identify the location of the smallest triangles and try to change the defining polygons or polylines in those locations to avoid the creation of the small triangles.

Typical situations are when the boundary polygon are created manually, two vertices may be created very close, indeed so close that the two vertices cannot be visually separated. When working with building polygons, created via some third party process, often there are extra very close vertices created.

So it is worth investigating your polygon definitions to ensure no small segments.

Another problem, often with building polygons, is when the vertex of one building polygon is very close to another building vertex.

So it is sensible to test the minimum distance between any pair of vertices that define the geometry of the mesh to avoid as much as possible the subsequent creation of small triangles.

Another subtle situation is when the vertex v1 of one structure is very close to the segment [v2, v3] of a structure. This involves a more expensive test, of distance between a line segment and a point. Counter intuitively, this problem can often be resolved by breaking the segment, with a new vertex so [v2, v3] becomes [v2, v4], [v4, v3] and replacing the old vertex v1 with the new vertex v4.

Creating a good mesh is probably one of the most time consuming components of the setup of an anuga model.

@Girishchandra-Yendargaye
Copy link
Author

Girishchandra-Yendargaye commented May 23, 2022

@stoiver Thank you for your quick reply..Ok we will try to identify the location of smallest triangles and test the minimum distance between any pair of vertices...Is there any api for finding such triangles.

@stoiver
Copy link
Member

stoiver commented May 25, 2022

@Girishchandra-Yendargaye at least you should check out some of the basic statistics of the domain using

domain.print_statistics()

If you use anuga.create_domain_from_regions then there are possibilities for regions to intersect strangely. For instance

bounding_polygon = [[0.0, 0.0],
  [20.0, 0.0],
  [20.0, 10.0],
  [0.0, 10.0],
  [0.0, 5.0],
  [0.0, 4.99]]

boundary_tags={'bottom': [0],
   'right': [1],
   'top': [2],
   'left1': [3],
   'left2': [4],
   'left3': [5]}

domain = anuga.create_domain_from_regions(bounding_polygon,
   boundary_tags,
   maximum_triangle_area = 0.2)

dplotter2 = anuga.Domain_plotter(domain)
plt.triplot(dplotter2.triang, linewidth = 0.4)
plt.show()

This produces

Figure_1

domain.print_statistics()
Mesh statistics:
  Number of triangles = 1619
  Extent [m]:
    x in [0.00000e+00, 2.00000e+01]
    y in [0.00000e+00, 1.00000e+01]
  Areas [m^2]:
    A in [9.52560e-05, 1.99783e-01]
    number of distinct areas: 1619
    Histogram:
      [9.52560e-05, 2.00640e-02[: 41
      [2.00640e-02, 4.00328e-02[: 5
      [4.00328e-02, 6.00016e-02[: 3
      [6.00016e-02, 7.99704e-02[: 22
      [7.99704e-02, 9.99392e-02[: 300
      [9.99392e-02, 1.19908e-01[: 411
      [1.19908e-01, 1.39877e-01[: 329
      [1.39877e-01, 1.59846e-01[: 260
      [1.59846e-01, 1.79814e-01[: 151
      [1.79814e-01, 1.99783e-01]: 97
    Percentiles (10 percent):
      161 triangles in [9.52560e-05, 8.91894e-02]
      161 triangles in [8.91894e-02, 9.74869e-02]
      161 triangles in [9.74869e-02, 1.05187e-01]
      161 triangles in [1.05187e-01, 1.13139e-01]
      161 triangles in [1.13139e-01, 1.20900e-01]
      161 triangles in [1.20900e-01, 1.30077e-01]
      161 triangles in [1.30077e-01, 1.41101e-01]
      161 triangles in [1.41101e-01, 1.53672e-01]
      161 triangles in [1.53672e-01, 1.67574e-01]
      161 triangles in [1.67574e-01, 1.97480e-01]
      9 triangles in [1.97480e-01, 1.99783e-01]
  Boundary:
    Number of boundary segments == 105
    Boundary tags == ['bottom', 'right', 'top', 'left1', 'left2', 'left3']

So we can see via either the plot or the statistics that there are some very small triangles.

Then that should lead you to look at the boundary polygon points for strange positioning.

With breaklines and riverwalls we do have a procedure to try to pin down problems. The procedure is
anuga.utilities.spatialInputUtil.add_intersections_to_domain_features

@Girishchandra-Yendargaye
Copy link
Author

Girishchandra-Yendargaye commented May 25, 2022

@stoiver Yes we are already doing this but for 20 million of triangle we are trying to find exact location of such triangles...ok we will try once again this way if no other option

@stoiver
Copy link
Member

stoiver commented May 25, 2022

@Girishchandra-Yendargaye probably should have asked earlier, how do you create your domain? Via create_domain_from_regions?

domain.areas

Points to the triangle areas.

domain centroid_coordinates

the centroids of the triangles.

They are numpy arrays and so you can argsort to find the smallest areas and then find the corresponding location via the coordinates.

@Girishchandra-Yendargaye
Copy link
Author

@stoiver we call create_domain_from_file for generating domain from Mesh.
ok this way it will help us to locate...thank you !

@stoiver
Copy link
Member

stoiver commented May 26, 2022

@Girishchandra-Yendargaye, how do you create the mesh file in the first place?

@Girishchandra-Yendargaye
Copy link
Author

@stoiver We use .. anuga.create_mesh_from_regions(bounding_polygon,
boundary_tags=dict0,
maximum_triangle_area=default_res,
filename=meshname,
interior_regions=interior_regions, #interior_regions
use_cache=cache,
verbose=True)

@stoiver
Copy link
Member

stoiver commented May 27, 2022

@Girishchandra-Yendargaye,

First anuga.create_domain_from_regions is just a wrapper around anuga.create_mesh_from_regions.

In the call to anuga.create_mesh_from_regions I would suggest changing the value of default_res so that you can work with a much smaller triangulation. Problems with the bounding_polygon and the interior_regions should show up even with a much smaller mesh. Actually a coarse meshing process will highlight problem areas, and then you can try to fix up the bounding_polygon and the interior_regions which should then lead to better triangulation when you restore the value of default_res.

Typical problems are very small segments in the individual definitions of the bounding_polygon and the interior_regions. Then there is the problem of these polygons perhaps have self intersections or at least approximate self intersections and then the problem of the boundary_polygon and the interior_regions intersecting or almost intersecting.

The procedure
anuga.utilities.spatialInputUtil.add_intersections_to_domain_features can help with fixing some of these problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants