.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_quadtree_hanging.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_plot_quadtree_hanging.py: QuadTree: Hanging Nodes ======================= You can give the refine method a function, which is evaluated on every cell of the TreeMesh. Occasionally it is useful to initially refine to a constant level (e.g. 3 in this 32x32 mesh). This means the function is first evaluated on an 8x8 mesh (2^3). .. GENERATED FROM PYTHON SOURCE LINES 13-46 .. image-sg:: /examples/images/sphx_glr_plot_quadtree_hanging_001.png :alt: plot quadtree hanging :srcset: /examples/images/sphx_glr_plot_quadtree_hanging_001.png :class: sphx-glr-single-img .. code-block:: Python import discretize import matplotlib.pyplot as plt def run(plotIt=True): M = discretize.TreeMesh([8, 8]) def refine(cell): xyz = cell.center dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5 if dist < 0.25: return 3 return 2 M.refine(refine) if plotIt: M.plot_grid(nodes=True, centers=True, faces_x=True) plt.legend( ( "Nodes", "Hanging Nodes", "Cell Centers", "X faces", "Hanging X faces", "Grid", ) ) if __name__ == "__main__": run() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.119 seconds) .. _sphx_glr_download_examples_plot_quadtree_hanging.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_quadtree_hanging.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_quadtree_hanging.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_quadtree_hanging.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_