.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/object_hierarchy_example.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_auto_examples_object_hierarchy_example.py: Object Hierarchy Demo ===================== The geometry of the simulation is built like a tree graph. There is a root ( or roots) at the top, a host object, and then child objects can be added to the host, and those children can have children and so on. The top level is considered to be at depth = 0. The grandchild of a root object would be at depth = 2. Objects at the lowest depth are placed into the mesh first. Objects are inserted in the order their parents were added when they are at the same depth. Then they are inserted in the order *they* were added when these objects have the same parent at the same depth. .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. code-block:: Python import PySALESetup as pss import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 21-24 In this example we create two identical circles and give them an offset to demonstrate how this works. .. GENERATED FROM PYTHON SOURCE LINES 24-48 .. code-block:: Python top_circle = pss.PySALEObject.generate_ellipse((0,0), 100, 100, rotation=0., material=1) top_circle.add_child(pss.PySALEObject.generate_ellipse((0,0), 70, 70, rotation=0., material=2)) top_circle.add_child(pss.PySALEObject.generate_ellipse((50,50), 70, 70, rotation=0., material=3)) for child in top_circle.children: child.add_child( pss.PySALEObject.generate_ellipse(child.polygon.centroid, major=10, minor=10, rotation=0., material=4) ) for child in top_circle.children: for child2 in child.children: child2.add_child(pss.PySALEObject.generate_ellipse( child2.polygon.centroid, major=5, minor=5, rotation=0, material=5)) .. GENERATED FROM PYTHON SOURCE LINES 49-51 Finally lets plot this situation. .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: Python fig, ax = top_circle.plot() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_object_hierarchy_example_001.png :alt: object hierarchy example :srcset: /auto_examples/images/sphx_glr_object_hierarchy_example_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-58 Create our mesh and fill in the objects. See how the mesh is populated. .. GENERATED FROM PYTHON SOURCE LINES 58-65 .. code-block:: Python mesh = pss.PySALEMesh.from_dimensions((200, 200), cell_size=1., origin=(-100., -100.)) mesh.project_polygons_onto_mesh([top_circle]) fig2, ax2 = mesh.plot_materials() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_object_hierarchy_example_002.png :alt: Materials :srcset: /auto_examples/images/sphx_glr_object_hierarchy_example_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.451 seconds) .. _sphx_glr_download_auto_examples_object_hierarchy_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: object_hierarchy_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: object_hierarchy_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: object_hierarchy_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_