This page was generated from
docs\source\examples/shape_functions_Q9.ipynb.
Plotting the shape functions of the Q9 quadrilateral#
We use Richard Shewchuk’s two-dimensional quality mesh generator to triangulate the master cell of the Q9 quadrilateral, then we plot the shape functions with Matplotlib.
[8]:
import matplotlib.pyplot as plt
import triangle as tr
from sigmaepsilon.mesh.cells import Q9
# get the coordinates of the master cell
mc = Q9.Geometry.master_coordinates()
# triangulate the master cell and plot with the `triangle` library
data = dict(vertices=mc)
triangulation = tr.triangulate(data, 'qa0.02')
tr.compare(plt, data, triangulation)
plt.show()
[9]:
from sigmaepsilon.mesh.plotting import triplot_mpl_data
from sigmaepsilon.mesh import triangulate
# get the triangulation as a `matplotlib` triangulation object
*_, triobj = triangulate(points=triangulation["vertices"], triangles=triangulation["triangles"])
# evaluate shape functions at the vertices of the triangulation
values = Q9.Geometry.shape_function_values(triangulation["vertices"])
# plot the values
fig, ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = plt.subplots(3, 3, figsize=(9, 6))
for i, ax in enumerate([ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8, ax9]):
_ = triplot_mpl_data(triobj, fig=fig, ax=ax, data=values[:, i], nlevels=10)