Skip to content

Commit

Permalink
Performance-focused rewrite of the ConvexPolyhedron class (#188)
Browse files Browse the repository at this point in the history
* Updated documentation for ConvexPolyhedron rewrite

* Updated __init__ and shape creation helpers

* Updated centroid getter and setter

* Updated volume getter, setter, and _rescale function

* Improved _find_equations method

* Added equations property

* Updated faces property to work with optional sorting

* Added normals property

* Updated sort_faces

* Updated neighbors property

* Added simplices property and updated _surface_triangulation

* Added _find_triangle_array_area helper

* Add faster surface area getter, setter, and calculation

* Added get_face_area method

* Added face_centroids property and _get_face_centroids

* Updated inertia_tensor property + _compute and diagonalize methods

Compute_inertia_tensor needed to be updated because the previous algorithm does not work if the tetrahedral decomposition of the shape includes tetrahedra with negative volumes. This new method, implemented based on an algorithm published by A. M. Messner in 1980 is significantly faster and provides slightly more accurate results. Because of this, the relevant pytest has been updated to better check the method.

* Added get_dihedral

* Added more stringent pytests for centroid and centroid setter

The centroid methods are core functionality to this class, and prior to this commit was not being tested. This fixes that, with a two-part test that checks for initial and repeated setting behavior. The monte carlo centroid compute has also been updated to test more samples on CircleCI. Test sampling has been tuned to account for the tighter tolerances

* Added in-depth tests for surface area and volume setters

* Added circleci checker function to speed up local pytest runs

* Added Truncated Icosahedron to bad_shapes for test MOI

This shape is individually responsible for ~25% of the total runtime of the test. The test passes (even at high precisions) but it has been marked bad due to the poor performance

* Added pytest for test_face_centroids and fixes for shape creation with Fast=True

* Set fast flag to properly default to False

* Fix typo in _consume_hull

* Fixed documentation for Polyhedron class

The Polyhedron example bases the input off of a ConvexPolyhedron object. Because of this, the ordering of faces can be different. Documentation has been updated to match

* Docstring fixes

* Added tests for simplex equations, face equations, and normals

* Combined pytest marks to clean up testing code

* Update Credits.rst

* Added test for heavily degenerate input vertices

Also checks appropriate warning behavior for such a case

* Changed [test] to [tests]

* Updated ConvexPolyhedron to properly handle nonconvex inputs.

* Removed use of Fast flag from class

* Removed fast flag from credits

* Updated ci flags for pytest

* Fixed D202 in convex_polyhedron

* Added ci check to MI test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

* Updated tests

* Updated docstring for _calculate_signed_volume

* Removed degenerate cube test

* Removed remaining circleci files

* Update changelog

* Clarified language on faces breaking change

* Cleaned up convex hull handling

* Update coxeter/shapes/convex_polyhedron.py

Co-authored-by: Domagoj Fijan <[email protected]>

* Removed unnecessary call to principal_moments

* Fixed pytest fixture call

* Fixed bug in _find_coplanar_simplices

* Removed copy of inherited method get_dihedral

---------

Co-authored-by: Brandon Butler <[email protected]>
Co-authored-by: Vyas Ramasubramani <[email protected]>
Co-authored-by: Bradley Dice <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Domagoj Fijan <[email protected]>
  • Loading branch information
6 people authored Jan 19, 2024
1 parent b380519 commit 00e012e
Show file tree
Hide file tree
Showing 7 changed files with 801 additions and 110 deletions.
15 changes: 15 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ Added
~~~~~

- New `edge_lengths` method.
- ``combine_simplices``, ``find_simplex_equations``, ``_find_face_centroids``,
``find_coplanar_simplices``, ``_find_face_centroids``, and ``calculate_signed_volume``
methods for the ConvexPolyhedron class.
- ``simplices``, ``equations``, and ``face_centroids`` properties for the
ConvexPolyhedron class.
- Additional pytests for surface area, volume, centroid, moment of inertia, and equations properties.

Changed
~~~~~~~

- Pre-commit now uses ruff instead of flake8, pydocstyle, pyupgrade and isort.
- CI now uses GitHub Actions.
- Docs ported to furo theme.
- Reimplemented ``find_equations``, ``_volume``, ``surface_area``, ``centroid``,
``_compute_inertia_tensor``, ``rescale``, and ``get_face_area`` methods for convex
polyhedra using NumPy vectorized operations and polyhedron simplices.
- [breaking] ``ConvexPolyhedron._surface_triangulation`` now returns sorted simplices,
rather than running polytri. This can change the order of vertices and/or triangles.
- [breaking] ``faces`` may return faces in a different order than previously. Faces are still sorted with ``sort_faces``, and will still be ordered such that curl and divergence theorems work properly.
- ``volume``, ``surface_area``, and ``centroid`` properties now return stored values, rather than computing the quantity at each call.
- ``rescale`` now computes the centroid to ensure the correct value is available when ``centroid`` is called.
- Optimized pytest configurations for more efficient use of local and remote resources.

v0.7.0 - 2023-09-18
-------------------
Expand Down
9 changes: 9 additions & 0 deletions Credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ Jen Bradley
* Added shape family for prisms and antiprisms.
* Added shape family for equilateral pyramids and dipyramids.
* Added edges, edge_vectors, edge_lengths, and num_edges methods.
* Reimplemented ``find_equations``, ``_volume``, ``surface_area``, ``centroid``,
``_compute_inertia_tensor``, ``rescale``, and ``get_face_area`` methods for convex
polyhedra using NumPy vectorized operations and polyhedron simplices.
* Added the ``combine_simplices``, ``find_simplex_equations``, ``_find_face_centroids``,
``find_coplanar_simplices``, ``_find_face_centroids``, and ``calculate_signed_volume``
methods to the ConvexPolyhedron class.
* Added ``simplices``, ``equations``, and ``face_centroids`` properties to the
ConvexPolyhedron class.
* Optimized pytest configurations for more efficient use of local and remote resources.

Domagoj Fijan

Expand Down
Loading

0 comments on commit 00e012e

Please sign in to comment.