Skip to content

Commit

Permalink
Merge pull request #66 from nschloe/dmsh-adaptations
Browse files Browse the repository at this point in the history
Dmsh adaptations
  • Loading branch information
nschloe committed Apr 28, 2020
2 parents a2052a8 + 14a40f8 commit 3af10ba
Show file tree
Hide file tree
Showing 9 changed files with 755 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
- run: apt-get install -y git python3-pip python3-vtk7
- run: pip3 install -U pytest pytest-cov excode
- checkout
# install
# install; need a new pip
- run: pip3 install pip -U --force
- run: pip3 install -r test_requirements.txt
- run: pip3 install .[all]
# The tests
Expand Down
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ tag:
# git push --tags
curl -H "Authorization: token `cat $(HOME)/.github-access-token`" -d '{"tag_name": "v$(VERSION)"}' https://api.github.com/repos/nschloe/meshplex/releases

upload: setup.py
upload:
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
rm -f dist/*
python3 setup.py sdist
python3 setup.py bdist_wheel
# python3 setup.py sdist bdist_wheel
# https://stackoverflow.com/a/58756491/353337
python3 -m pep517.build --source --binary .
twine upload dist/*

publish: tag upload
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,4 @@ pytest
```

### License

meshplex is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
This software is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html).
7 changes: 6 additions & 1 deletion meshplex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@


def compute_tri_areas(ei_dot_ej):
return 0.5 * numpy.sqrt(
vol2 = 0.25 * (
ei_dot_ej[2] * ei_dot_ej[0]
+ ei_dot_ej[0] * ei_dot_ej[1]
+ ei_dot_ej[1] * ei_dot_ej[2]
)
# vol2 is the squared volume, but can be slightly negative if it comes to round-off
# errors. Corrrect those.
assert numpy.all(vol2 > -1.0e-14)
vol2[vol2 < 0] = 0.0
return numpy.sqrt(vol2)


def compute_ce_ratios(ei_dot_ej, tri_areas):
Expand Down
65 changes: 63 additions & 2 deletions meshplex/mesh_tri.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ def __repr__(self):
# self.update_values()
# return

@property
def euler_characteristic(self):
# number of vertices - number of edges + number of faces
if "edges" not in self.cells:
self.create_edges()
return (
self.node_coords.shape[0]
- self.edges["nodes"].shape[0]
+ self.cells["nodes"].shape[0]
)

@property
def genus(self):
# https://math.stackexchange.com/a/85164/36678
return 1 - self.euler_characteristic / 2

@property
def ce_ratios(self):
if self._ce_ratios is None:
Expand Down Expand Up @@ -171,8 +187,8 @@ def update_values(self):

if self.cell_volumes is not None or self.ce_ratios is not None:
self.cell_volumes = compute_tri_areas(self.ei_dot_ej)
self._ce_ratios = compute_ce_ratios(self.ei_dot_ej, self.cell_volumes)

self._ce_ratios = None
self._interior_edge_lengths = None
self._cell_circumcenters = None
self._interior_ce_ratios = None
Expand All @@ -185,6 +201,51 @@ def update_values(self):
self._cell_centroids = None
return

def remove_degenerate_cells(self, threshold):
is_okay = self.cell_volumes > threshold

self.cell_volumes = self.cell_volumes[is_okay]
self.cells["nodes"] = self.cells["nodes"][is_okay]
self.idx_hierarchy = self.idx_hierarchy[..., is_okay]

if "edges" in self.cells:
self.cells["edges"] = self.cells["edges"][is_okay]

if self._ce_ratios is not None:
self._ce_ratios = self._ce_ratios[is_okay]

if self.half_edge_coords is not None:
self.half_edge_coords = self.half_edge_coords[:, is_okay]

if self.ei_dot_ej is not None:
self.ei_dot_ej = self.ei_dot_ej[:, is_okay]

if self.ei_dot_ei is not None:
self.ei_dot_ei = self.ei_dot_ei[:, is_okay]

if self._cell_centroids is not None:
self._cell_centroids = self._cell_centroids[is_okay]

if self._cell_circumcenters is not None:
self._cell_circumcenters = self._cell_circumcenters[is_okay]

if self._cell_partitions is not None:
self._cell_partitions = self._cell_partitions[is_okay]

self._interior_edge_lengths = None
self._interior_ce_ratios = None
self._control_volumes = None
self._cv_centroids = None
self._cvc_cell_mask = None
self._surface_areas = None
self._signed_cell_areas = None
self._is_boundary_node = None
self.is_boundary_edge = None

self.create_edges()

return numpy.sum(~is_okay)

@property
def ce_ratios_per_interior_edge(self):
"""
Expand Down Expand Up @@ -757,7 +818,7 @@ def save(self, filename, *args, **kwargs):
"""Save the mesh to a file.
"""
_, file_extension = os.path.splitext(filename)
if file_extension in ".png":
if file_extension in [".png", ".svg"]:
import matplotlib.pyplot as plt

self.plot(*args, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshplex
version = 0.12.3
version = 0.13.0
author = Nico Schlömer
email = nico.schloemer@gmail.com
description = Fast tools for simplex meshes,
Expand All @@ -10,12 +10,12 @@ project_urls =
Issues=https://github.com/nschloe/meshplex/issues
long_description = file: README.md
long_description_content_type = text/markdown
license = MIT
license = GPLv3
platforms = any
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Science/Research
License :: OSI Approved :: MIT License
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Expand Down
4 changes: 0 additions & 4 deletions setup.py

This file was deleted.

0 comments on commit 3af10ba

Please sign in to comment.