Python module for generating dual meshes
Project description
DualMesh
Python module for generating dual meshes.
Requirements
- meshio >= 3.2.6
- numpy >= 1.16.3
Installation
Copy dual_mesh.py from the repository to where you wish to use it.
Example
We can go through the example of using dual_mesh.py module.
First, we import all the needed modules
# For opening a mesh file
import meshio
# For generating a dual mesh
import dual_mesh as dm
# For plotting both the mesh and dual mesh
import matplotlib.pyplot as plt
We load the mesh for which we want a dual mesh
msh = meshio.read("example.msh")
We get the dual mesh object using dual_mesh.py
dual_msh = dm.get_dual(msh, order=True)
We use matplotlib to plot the original mesh
fig, ax = plt.subplots()
ax.triplot(msh.points[:, 0], msh.points[:, 1], msh.cells["triangle"])
We loop over the polygons (cells) in the dual mesh and we plot them
for cell in dual_msh.cells["polygon"]:
# We get the coordinates of the current polygon.
# We repeat one of the points, so that when plotted, we get a complete polygon
cell_points = dual_msh.points[cell + [cell[0]]]
# We plot the points of the current polygon
ax.plot(cell_points[:, 0], cell_points[:, 1], ":", color="black")
And finally we add the legend and save the resulting figure
# We add a legend to the figure
fig.legend([ax.lines[0], ax.lines[-1]], ["Mesh", "Dual mesh"])
# We save the resulting figure
fig.savefig("example.png")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dualmesh-0.13.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
dualmesh-0.13.1-py3-none-any.whl
(14.9 kB
view hashes)
Close
Hashes for dualmesh-0.13.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0aa8f8dd68151a9d5de004c94f81d505457e99ac47368afc272a8ad476e85b9 |
|
MD5 | 5d5caf3b15d211f931218379cdf471d6 |
|
BLAKE2b-256 | ac99124b56c5254f5cedc703a18186be3d4032084803ab8650f6904d9b47fe9a |