Skip to content

Commit

Permalink
Updated xmsmesher notebooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Dolinar authored and wdolinar committed Jun 29, 2023
1 parent 0c17597 commit 8a6d467
Show file tree
Hide file tree
Showing 34 changed files with 13,225 additions and 49,787 deletions.
13,698 changes: 0 additions & 13,698 deletions examples/MeshSanDiego.html

This file was deleted.

Binary file removed examples/MeshSanDiego.zip
Binary file not shown.
219 changes: 219 additions & 0 deletions examples/MeshSanDiego/MeshSanDiego.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of Contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [Example - San Diego Meshing](#Example---San-Diego-Meshing)\n",
"- [Plot Initial Geometry](#Plot-Initial-Geometry)\n",
"- [Generate the Mesh](#Generate-the-Mesh)\n",
"- [Plot Mesh](#Plot-Mesh)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example - San Diego Meshing\n",
"\n",
"This example illustrates how run a more complicated meshing example for a real-world case. In this case, you use a polygon and other features defining the extents of San Diego Bay to generate a mesh that can be used for running a hydraulic model of the bay. An overview of the model is shown in the image below.\n",
"\n",
"A python-based class has been created for this example that contains two PolyInput objects that can be used to generate a 2D mesh."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from shapely.geometry import Polygon\n",
"\n",
"import meshing_tools\n",
"import xms.mesher as mesh"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot Initial Geometry"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For this example we'll use the polygon data held in the meshing_tools.py file. The code below retreives this polygon data."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"san_diego_example = meshing_tools.SanDiegoExample()\n",
"poly1 = san_diego_example.poly1\n",
"poly2 = san_diego_example.poly2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code shown below plots our polygon data using geoviews. The plot of this data is shown in the following image."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"basemap = gv.tile_sources.StamenTerrainRetina().options(width=900, height=900)\n",
"\n",
"polygons = gv.Polygons(\n",
" data=[\n",
" meshing_tools.polys_as_shapely(poly2), \n",
" meshing_tools.polys_as_shapely(poly1)\n",
" ], \n",
" crs=ccrs.UTM(zone=11),\n",
").options(fill_color=None,)\n",
"\n",
"points = gv.Points(\n",
" data=[poly1.outside_poly, poly2.outside_poly, poly2.inside_polys[-1]],\n",
" crs=ccrs.UTM(zone=11),\n",
").options(color='black', size=4)\n",
"\n",
"path = gv.Path(\n",
" data=[pd.DataFrame(data=poly2.inside_polys[-1], columns=['x', 'y', 'z'])], \n",
" crs=ccrs.UTM(zone=11), \n",
").options(line_color='black')\n",
"\n",
"basemap * polygons * points * path\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Initial Geometry](images/initial_geometry.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The MultiPolyMesherIo class holds all the options for generating meshes from polygon data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"mesh_io = mesh.meshing.MultiPolyMesherIo((poly1, poly2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate the Mesh"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Meshing was successful\n"
]
}
],
"source": [
"# Generate Mesh\n",
"succeded, errors = mesh.meshing.mesh_utils.generate_mesh(mesh_io=mesh_io)\n",
"if succeded:\n",
" print(\"Meshing was successful\")\n",
"else:\n",
" print(\"Meshing errors found:\")\n",
" for err in errors:\n",
" print(\"\\t{}\".format(err))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot Mesh\n",
"The mesh is converted to a pandas dataframe which is then used by geoviews for plotting. The image below shows the plot generated by the geoviews code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"verts,cells = meshing_tools.xmsmesh_to_dataframe(mesh_io.points, mesh_io.cells)\n",
"vert_points = gv.project(gv.Points(verts, vdims=['z'], crs=ccrs.UTM(zone=11)))\n",
"trimesh = gv.TriMesh((cells, vert_points))\n",
"\n",
"basemap * polygons * points * path * trimesh.edgepaths.options(line_width=1)\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![The generated mesh](images/mesh.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/MeshSanDiego/images/mesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8a6d467

Please sign in to comment.