.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/03-tips-n-tricks/03-using_inline_functions_and_Query.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_examples_gallery_examples_03-tips-n-tricks_03-using_inline_functions_and_Query.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_03-tips-n-tricks_03-using_inline_functions_and_Query.py: .. _ref_how_to_use_query: Using Inline Functions (Query) ------------------------------ This example shows you how to use the inline functions in PyMAPDL. Inline functions like ``UX`` have been implemented in PyMAPDL as methods on the ``mapdl.inline_functions.Query`` object. In this example we set up a simple simulation and use ``Query`` to demonstrate some of its functionality. First, get an instance of :class:`ansys.mapdl.core.inline_functions.Query` below, using the ``mapdl`` property ``queries``. .. GENERATED FROM PYTHON SOURCE LINES 19-29 .. code-block:: default from ansys.mapdl.core import launch_mapdl mapdl = launch_mapdl() # clear at the start and enter the preprocessing routine mapdl.clear() mapdl.prep7() q = mapdl.queries .. GENERATED FROM PYTHON SOURCE LINES 30-37 Setup Mesh ~~~~~~~~~~ - Assign element type ``SOLID5`` to element type 1 - Create a cuboid ``mapdl.block`` 10 x 20 x 30 in dimension - Set element size to 2 - Mesh the block - Plot the elements created .. GENERATED FROM PYTHON SOURCE LINES 37-44 .. code-block:: default mapdl.et(1, "SOLID5") mapdl.block(0, 10, 0, 20, 0, 30) mapdl.esize(2) mapdl.vmesh("ALL") mapdl.eplot() .. image-sg:: /examples/gallery_examples/03-tips-n-tricks/images/sphx_glr_03-using_inline_functions_and_Query_001.png :alt: 03 using inline functions and Query :srcset: /examples/gallery_examples/03-tips-n-tricks/images/sphx_glr_03-using_inline_functions_and_Query_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-54 Setup Boundary Conditions ~~~~~~~~~~~~~~~~~~~~~~~~~ - Assign an Elastic modulus in the x-direction to material 1 of 21e9 - And a poisson's ratio of 0.3 - Select all nodes at the ``z = 30`` end of the block - Remove all degrees of freedom for all nodes in the selection - Select all nodes at the ``z = 0`` end - Apply a x-direction force of 10000 to all of these - Finish preprocessing .. GENERATED FROM PYTHON SOURCE LINES 54-65 .. code-block:: default mapdl.mp("EX", 1, 210e9) mapdl.mp("PRXY", 1, 0.3) mapdl.nsel("S", "LOC", "Z", 30) mapdl.d("ALL", "UX") mapdl.d("ALL", "UY") mapdl.d("ALL", "UZ") mapdl.nsel("S", "LOC", "Z", 0) mapdl.f("ALL", "FX", 10000) mapdl.finish() .. rst-class:: sphx-glr-script-out .. code-block:: none ***** ROUTINE COMPLETED ***** CP = 0.000 .. GENERATED FROM PYTHON SOURCE LINES 66-73 Setup Boundary Conditions ~~~~~~~~~~~~~~~~~~~~~~~~~ - Enter solution (``mapdl.slashsolu`` also works) - Set the analysis type to ``STATIC`` - Select all nodes - Solve the model - Finish solution .. GENERATED FROM PYTHON SOURCE LINES 73-80 .. code-block:: default mapdl.run("/SOLU") mapdl.antype("STATIC") mapdl.allsel() mapdl.solve() mapdl.finish(mute=True) .. GENERATED FROM PYTHON SOURCE LINES 81-87 Post-Processing ~~~~~~~~~~~~~~~ - Get the result from the ``mapdl`` instance - Plot the equivalent stress results - Show the edges so that we can see the element boundaries - Use the "plasma" colormap because it is perceptually uniform .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. code-block:: default result = mapdl.result result.plot_principal_nodal_stress(0, "SEQV", show_edges=True, cmap="plasma") .. image-sg:: /examples/gallery_examples/03-tips-n-tricks/images/sphx_glr_03-using_inline_functions_and_Query_002.png :alt: 03 using inline functions and Query :srcset: /examples/gallery_examples/03-tips-n-tricks/images/sphx_glr_03-using_inline_functions_and_Query_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 92-97 Using ``Query`` ~~~~~~~~~~~~~~~ - Use ``Query`` to get the nodes nearest to (5, 0, 0) and (5, 10, 0) - Use the ``Query`` instance to examine the x, y, and z displacement. - Print the results in a formatted string. .. GENERATED FROM PYTHON SOURCE LINES 97-118 .. code-block:: default node1 = q.node(5.0, 0.0, 0.0) node2 = q.node(5.0, 10.0, 0.0) for node in [node1, node2]: x_displacement = q.ux(node) y_displacement = q.uy(node) z_displacement = q.uz(node) message = f""" ************************ Displacement at Node {node}: ************************ X | {x_displacement} Y | {y_displacement} Z | {z_displacement} """ print(message) .. rst-class:: sphx-glr-script-out .. code-block:: none ************************ Displacement at Node 28: ************************ X | 1.757716378392647e-05 Y | 3.0362575468963493e-09 Z | -7.982690758480564e-07 ************************ Displacement at Node 49: ************************ X | 1.7612417675184542e-05 Y | 1.2385898428775669e-19 Z | 8.070989838529134e-07 .. GENERATED FROM PYTHON SOURCE LINES 119-122 Stop mapdl ~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 122-123 .. code-block:: default mapdl.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.221 seconds) .. _sphx_glr_download_examples_gallery_examples_03-tips-n-tricks_03-using_inline_functions_and_Query.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-using_inline_functions_and_Query.py <03-using_inline_functions_and_Query.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-using_inline_functions_and_Query.ipynb <03-using_inline_functions_and_Query.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_