Skip to content

Commit

Permalink
Merge pull request #162 from nschloe/abstol
Browse files Browse the repository at this point in the history
tests: absolute tolerance
  • Loading branch information
nschloe authored Oct 4, 2021
2 parents de90660 + 3ac4898 commit d1ff1c6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 24 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Run pre-commit
uses: pre-commit/[email protected]

build:
linux:
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-python@v2
Expand All @@ -43,3 +43,20 @@ jobs:
pip install tox
CC="clang" tox -- --cov pygalmesh --cov-report xml --cov-report term
- uses: codecov/codecov-action@v1

macos:
runs-on: macos-latest
steps:
- uses: actions/setup-python@v2
with:
python-version: "3.x"
- uses: actions/checkout@v2
with:
lfs: true
- name: Install system dependencies
run: |
brew install cgal eigen
- name: Test with tox
run: |
pip install tox
CC="clang" tox -- --cov pygalmesh --cov-report xml --cov-report term
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pygalmesh
version = 0.10.3
version = 0.10.4
author = Nico Schlömer
author_email = [email protected]
description = Python frontend to CGAL's mesh generation capabilities
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"src/pybind11.cpp",
]
),
include_dirs=[os.environ.get("EIGEN_INCLUDE_DIR", "/usr/include/eigen3/")],
include_dirs=[
os.environ.get("EIGEN_INCLUDE_DIR", "/usr/include/eigen3/"),
# macos/brew:
"/usr/local/include/eigen3",
],
# no CGAL libraries necessary from CGAL 5.0 onwards
libraries=["gmp", "mpfr"],
)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_from_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_from_array():

tol = min(h)
ref = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
assert abs(max(mesh.points[:, 0]) - ref[0]) < tol
assert abs(min(mesh.points[:, 0]) - ref[1]) < tol
assert abs(max(mesh.points[:, 1]) - ref[2]) < tol
assert abs(min(mesh.points[:, 1]) - ref[3]) < tol
assert abs(max(mesh.points[:, 2]) - ref[4]) < tol
assert abs(min(mesh.points[:, 2]) - ref[5]) < tol
assert abs(max(mesh.points[:, 0]) - ref[0]) < (1.0 + ref[0]) * tol
assert abs(min(mesh.points[:, 0]) - ref[1]) < (1.0 + ref[1]) * tol
assert abs(max(mesh.points[:, 1]) - ref[2]) < (1.0 + ref[2]) * tol
assert abs(min(mesh.points[:, 1]) - ref[3]) < (1.0 + ref[3]) * tol
assert abs(max(mesh.points[:, 2]) - ref[4]) < (1.0 + ref[4]) * tol
assert abs(min(mesh.points[:, 2]) - ref[5]) < (1.0 + ref[5]) * tol

vol = sum(helpers.compute_volumes(mesh.points, mesh.get_cells_type("tetra")))
ref = 1.0 / 6.0 * np.pi
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_inr():
(min(mesh.points[:, 2]), -3.98639357e-03),
]
for val, ref in vals_refs:
assert abs(val - ref) < 6.0e-2 * abs(ref), f"{val:.8e} != {ref:.8e}"
assert abs(val - ref) < 1.0e-3 * (1.0 + abs(ref)), f"{val:.8e} != {ref:.8e}"

vol = sum(helpers.compute_volumes(mesh.points, mesh.get_cells_type("tetra")))
ref = 6.95558790e02
Expand Down
2 changes: 1 addition & 1 deletion tests/test_remesh_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_remesh_surface():
(min(mesh.points[:, 2]), -3.01316000e-01),
]
for val, ref in vals_refs:
assert abs(val - ref) < 1.0e-3 * abs(ref), f"{val:.8e} != {ref:.8e}"
assert abs(val - ref) < 1.0e-3 * (1.0 + abs(ref)), f"{val:.8e} != {ref:.8e}"

triangle_areas = helpers.compute_triangle_areas(
mesh.points, mesh.get_cells_type("triangle")
Expand Down
12 changes: 6 additions & 6 deletions tests/test_surface_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def test_sphere():
)

tol = 1.0e-2
assert abs(max(mesh.points[:, 0]) - radius) < tol
assert abs(min(mesh.points[:, 0]) + radius) < tol
assert abs(max(mesh.points[:, 1]) - radius) < tol
assert abs(min(mesh.points[:, 1]) + radius) < tol
assert abs(max(mesh.points[:, 2]) - radius) < tol
assert abs(min(mesh.points[:, 2]) + radius) < tol
assert abs(max(mesh.points[:, 0]) - radius) < (1.0 + radius) * tol
assert abs(min(mesh.points[:, 0]) + radius) < (1.0 + radius) * tol
assert abs(max(mesh.points[:, 1]) - radius) < (1.0 + radius) * tol
assert abs(min(mesh.points[:, 1]) + radius) < (1.0 + radius) * tol
assert abs(max(mesh.points[:, 2]) - radius) < (1.0 + radius) * tol
assert abs(min(mesh.points[:, 2]) + radius) < (1.0 + radius) * tol

areas = helpers.compute_triangle_areas(mesh.points, mesh.get_cells_type("triangle"))
surface_area = sum(areas)
Expand Down
18 changes: 11 additions & 7 deletions tests/test_volume_from_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def test_volume_from_surface():
mesh = meshio.read(out_filename)

tol = 2.0e-2
assert abs(max(mesh.points[:, 0]) - 0.357612477657) < tol
assert abs(min(mesh.points[:, 0]) + 0.358747130015) < tol
assert abs(max(mesh.points[:, 1]) - 0.496137874959) < tol
assert abs(min(mesh.points[:, 1]) + 0.495301051456) < tol
assert abs(max(mesh.points[:, 2]) - 0.298780230629) < tol
assert abs(min(mesh.points[:, 2]) + 0.300472866512) < tol
vals_refs = [
(max(mesh.points[:, 0]), +0.357612477657),
(min(mesh.points[:, 0]), -0.358747130015),
(max(mesh.points[:, 1]), +0.496137874959),
(min(mesh.points[:, 1]), -0.495301051456),
(max(mesh.points[:, 2]), +0.298780230629),
(min(mesh.points[:, 2]), -0.300472866512),
]
for val, ref in vals_refs:
assert abs(val - ref) < (1.0 + ref) * tol, f"{val:.15e} != {ref:.15e}"

vol = sum(helpers.compute_volumes(mesh.points, mesh.get_cells_type("tetra")))
assert abs(vol - 0.044164693065) < tol
assert abs(vol - 0.044164693065) < (1.0 + vol) * tol

0 comments on commit d1ff1c6

Please sign in to comment.