Skip to content

Commit 0bb73b5

Browse files
author
keith roberts
authored
simple mesh generator (#10)
* 2D mesh generator based on DistMesh algorithm which calls CGAL Delaunay triangulation.
1 parent 71a12b8 commit 0bb73b5

23 files changed

+1032
-103
lines changed

.circleci/config.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ jobs:
1515
- image: circleci/python:3
1616
steps:
1717
- checkout
18-
- run: pip install . --user
19-
- run: pip install -U pytest pytest-cov --user
18+
- run: sudo apt install -y cmake python-pybind11
19+
- run: sudo apt-get install libmpfr-dev
20+
- run: sudo apt-get install libboost-all-dev
21+
- run: git clone https://github.com/CGAL/cgal.git && cd cgal/ && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && sudo make install
22+
- run: pip install -e .
23+
- run: pip install -U pytest pytest-cov
2024
- run:
2125
command: pytest --cov oceanmesh
2226
- run: bash <(curl -s https://codecov.io/bash)

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
__pycache__
21
*.nc
2+
*.pyc
3+
*.swp
4+
*.prof
5+
dist/
6+
build/
7+
.coverage
8+
.cache/
9+
*.egg-info/
10+
.pytest_cache/
11+
*.segy
12+
*.vtk
13+
*.hdf5
14+
*.msh
15+
*.so

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
3+
project(oceanmesh)
4+
5+
##############################################################################
6+
7+
# Add custom CMake modules
8+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
9+
10+
# Some screen output
11+
message(STATUS "OS detected: ${CMAKE_SYSTEM_NAME}")
12+
message(STATUS "CXX Compiler detected: ${CMAKE_CXX_COMPILER_ID}")
13+
message(STATUS "CMake additional search path for libraries: ${CMAKE_LIBRARY_PATH}")
14+
15+
# CGAL and its components
16+
find_package(CGAL)
17+
message(STATUS "CGAL version: ${CGAL_VERSION}")
18+
19+
if( CGAL_VERSION VERSION_LESS 5.0)
20+
message(FATAL_ERROR "This project requires at least CGAL 5.0 library and will not be compiled.")
21+
endif()
22+
23+
24+
# include helper file
25+
include( ${CGAL_USE_FILE})
26+
27+
set (SRC "oceanmesh/cpp")
28+
29+
include_directories (${SRC})
30+
31+
find_package(pybind11)
32+
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
33+
34+
#add_subdirectory(pybind11)
35+
pybind11_add_module(delaunay_class ${SOURCES} "${SRC}/delaunay_class.cpp")
File renamed without changes.

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include oceanmesh/cpp/*.cpp
2+
include tests/*
3+
4+
include README.md LICENSE.txt
5+
global-include CMakeLists.txt

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ default:
66
clean:
77
@find . | grep -E "(__pycache__|\.pyc|\.pyo$\)" | xargs rm -rf
88
@rm -rf build/*
9-
@rm -rf pyOceanMesh.egg-info/
9+
@rm -rf oceanmesh.egg-info/
1010
@rm -rf dist/
1111

1212
format:
13-
isort -rc pyOceanMesh/ tests/*.py
14-
black pyOceanMesh/ tests/*.py
13+
isort -rc oceanmesh/ tests/*.py
14+
black oceanmesh/ tests/*.py
1515
blacken-docs README.md

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,89 @@
11
oceanmesh: Automatic coastal ocean mesh generation
22
=====================================================
3+
:ocean: :cyclone:
34

45
[![CircleCI](https://circleci.com/gh/circleci/circleci-docs.svg?style=svg)](https://circleci.com/gh/CHLNDDEV/oceanmesh)
56
[![CodeCov](https://codecov.io/gh/CHLNDDEV/oceanmesh/branch/master/graph/badge.svg)](https://codecov.io/gh/CHLNDDEV/oceanmesh)
67

78

89

9-
Coastal ocean mesh generation from ESRI Shapefiles and digitial elevation models.
10+
Coastal ocean mesh generation from ESRI Shapefiles and digitial elevation models.
1011

1112

1213
Functionality
1314
=============
1415

15-
* WIP
16+
* A toolkit for the development of meshes and their auxiliary files that are used in the simulation of coastal ocean circulation. The software integrates mesh generation with geophysical datasets such as topobathymetric rasters/digital elevation models and shapefiles representing coastal features. It provides some necessary pre- and post-processing tools to inevitably perform a succesful numerical simulations with the developed model.
17+
* Automatically deal with arbitrarily complex shoreline vector datasets that represent complex coastal boundaries and incorporate the data in an automatic-sense into the mesh generation process.
18+
* A variety of commonly used mesh size functions to distribute element sizes that can easily be controlled via a simple scripting application interface.
19+
* Mesh checking and clean-up methods to avoid simulation problems.
20+
21+
Questions?
22+
============
23+
24+
Besides posting issues with the code on Github, you can also ask questions via our Slack channel [here](https://join.slack.com/t/oceanmesh2d/shared_invite/zt-hcu2nag7-NUBw52cxxlYupLrc1hqvhw).
25+
26+
Otherwise please reach out to either Dr. William Pringle (wpringle@nd.edu) or Dr. Keith Roberts (krober@usp.br) with questions or concerns!
27+
28+
Installation
29+
============
30+
31+
For installation, oceanmesh needs [CGAL](https://www.cgal.org/) and
32+
[pybind11](https://github.com/pybind/pybind11):
33+
34+
sudo apt install libcgal-dev python3-pybind11
35+
36+
After that, clone the repo and oceanmesh can be updated/installed using pip.
37+
38+
pip install -U -e .
39+
40+
:warning:
41+
42+
**WARNING: THIS PROGRAM IS IN ACTIVE DEVELOPMENT. INSTALLATION IS ONLY RECOMMENDED FOR DEVELOPERS AT THIS TIME. WHEN A STABLE API IS REACHED, THE PROGRAM WILL BE AVAILABLE VIA pypi**
1643

1744
Examples
1845
==========
1946

20-
* WIP
47+
Build a simple mesh around New York witha minimum element size of 1 km expanding linear from the shoreline to a maximum size of 5 km.
48+
49+
50+
**Here we use the GSHHS shoreline [here](http://www.soest.hawaii.edu/pwessel/gshhg/gshhg-shp-2.3.7.zip) and the Python package `meshio` to write the mesh to a VTK file for visualization in ParaView.**
51+
52+
![NewYorkMesh](https://user-images.githubusercontent.com/18619644/94013474-8196b400-fd80-11ea-8471-21fa8853f264.png)
53+
54+
```
55+
import meshio
56+
57+
from oceanmesh import (
58+
Shoreline,
59+
distance_sizing_function,
60+
signed_distance_function,
61+
generate_mesh,
62+
)
63+
64+
65+
fname = "datasets/gshhg-shp-2.3.7/GSHHS_shp/f/GSHHS_f_L1.shp"
66+
67+
bbox, h0 = (-75.000, -70.001, 40.0001, 41.9000), 1e3
68+
69+
shore = Shoreline(fname, bbox, h0)
70+
71+
cell_size = distance_sizing_function(shore, max_size=5e3/ 111e3)
72+
73+
domain = signed_distance_function(shore)
74+
75+
points, cells = generate_mesh(
76+
domain=domain, cell_size=cell_size, h0=1e3 / 111e3
77+
)
78+
79+
meshio.write_points_cells(
80+
"simple_new_york.vtk",
81+
points,
82+
[("triangle", cells)],
83+
file_format="vtk",
84+
)
85+
~
86+
```
2187

2288
Testing
2389
============
@@ -32,4 +98,3 @@ License
3298
=======
3399

34100
This software is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html)
35-

oceanmesh/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
from oceanmesh.edgefx import distance_sizing_function
2+
from oceanmesh.edges import draw_edges, get_poly_edges
13
from oceanmesh.geodata import DEM, Geodata, Shoreline
24
from oceanmesh.grid import Grid
3-
from oceanmesh.edgefx import distance_sizing_function
4-
from oceanmesh.signed_distance_function import signed_distance_function
5-
from oceanmesh.edges import get_poly_edges, draw_edges
5+
from oceanmesh.signed_distance_function import signed_distance_function, Domain
6+
7+
from .cpp.delaunay_class import DelaunayTriangulation
8+
from .fix_mesh import fix_mesh, simp_vol
69
from .inpoly import inpoly
10+
from .mesh_generator import generate_mesh
711

812
__all__ = [
913
"SizeFunction",
1014
"Grid",
1115
"Geodata",
1216
"DEM",
17+
"Domain",
1318
"Shoreline",
1419
"distance_sizing_function",
1520
"signed_distance_function",
1621
"get_poly_edges",
1722
"draw_edges",
1823
"inpoly",
24+
"DelaunayTriangulation",
25+
"generate_mesh",
26+
"fix_mesh",
27+
"simp_vol",
1928
]

oceanmesh/cpp/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)