.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\01-Modeling-Setup\HFSS_CoordinateSystem.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_01-Modeling-Setup_HFSS_CoordinateSystem.py: General: coordinate system creation ----------------------------------- This example shows how you can use PyAEDT to create and modify coordinate systems in the modeler. .. GENERATED FROM PYTHON SOURCE LINES 7-10 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: default import os import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 16-20 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 20-23 .. code-block:: default non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 24-27 Launch AEDT in graphical mode ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Launch AEDT 2023 R2 in graphical mode. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: default d = pyaedt.launch_desktop(specified_version="2023.2", non_graphical=non_graphical, new_desktop_session=True) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! .. GENERATED FROM PYTHON SOURCE LINES 31-34 Insert HFSS design ~~~~~~~~~~~~~~~~~~ Insert an HFSS design with the default name. .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: default hfss = pyaedt.Hfss(projectname=pyaedt.generate_unique_project_name(folder_name="CoordSysDemo")) .. rst-class:: sphx-glr-script-out .. code-block:: none Returning found desktop with PID 1580! .. GENERATED FROM PYTHON SOURCE LINES 38-43 Create coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~ The coordinate system is centered on the global origin and has the axis aligned to the global coordinate system. The new coordinate system is saved in the object ``cs1``. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: default cs1 = hfss.modeler.create_coordinate_system() .. GENERATED FROM PYTHON SOURCE LINES 47-51 Modify coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~ The ``cs1`` object exposes properties and methods to manipulate the coordinate system. The origin can be changed. .. GENERATED FROM PYTHON SOURCE LINES 51-63 .. code-block:: default cs1["OriginX"] = 10 cs1.props["OriginY"] = 10 cs1.props["OriginZ"] = 10 # Pointing vectors can be changed ypoint = [0, -1, 0] cs1.props["YAxisXvec"] = ypoint[0] cs1.props["YAxisYvec"] = ypoint[1] cs1.props["YAxisZvec"] = ypoint[2] .. GENERATED FROM PYTHON SOURCE LINES 64-67 Rename coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~ Rename the coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: default cs1.rename("newCS") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 71-76 Change coordinate system mode ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use the ``change_cs_mode`` method to change the mode. Options are ``0`` for axis/position, ``1`` for Euler angle ZXZ, and ``2`` for Euler angle ZYZ. Here ``1`` sets Euler angle ZXZ as the mode. .. GENERATED FROM PYTHON SOURCE LINES 76-84 .. code-block:: default cs1.change_cs_mode(1) # In the new mode, these properties can be edited cs1.props["Phi"] = "10deg" cs1.props["Theta"] = "22deg" cs1.props["Psi"] = "30deg" .. GENERATED FROM PYTHON SOURCE LINES 85-88 Delete coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~ Delete the coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 88-91 .. code-block:: default cs1.delete() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 92-96 Create coordinate system by defining axes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a coordinate system by defining the axes. During creation, you can specify all coordinate system properties. .. GENERATED FROM PYTHON SOURCE LINES 96-101 .. code-block:: default cs2 = hfss.modeler.create_coordinate_system( name="CS2", origin=[1, 2, 3.5], mode="axis", x_pointing=[1, 0, 1], y_pointing=[0, -1, 0] ) .. GENERATED FROM PYTHON SOURCE LINES 102-105 Create coordinate system by defining Euler angles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a coordinate system by defining Euler angles. .. GENERATED FROM PYTHON SOURCE LINES 105-108 .. code-block:: default cs3 = hfss.modeler.create_coordinate_system(name="CS3", origin=[2, 2, 2], mode="zyz", phi=10, theta=20, psi=30) .. GENERATED FROM PYTHON SOURCE LINES 109-114 Create coordinate system by defining view ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a coordinate system by defining the view. Options are ``"iso"``, ``"XY"``, ``"XZ"``, and ``"XY"``. Here ``"iso"`` is specified. The axes are set automatically. .. GENERATED FROM PYTHON SOURCE LINES 114-117 .. code-block:: default cs4 = hfss.modeler.create_coordinate_system(name="CS4", origin=[1, 0, 0], reference_cs="CS3", mode="view", view="iso") .. GENERATED FROM PYTHON SOURCE LINES 118-123 Create coordinate system by defining axis and angle rotation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a coordinate system by defining the axis and angle rotation. When you specify the axis and angle rotation, this data is automatically translated to Euler angles. .. GENERATED FROM PYTHON SOURCE LINES 123-126 .. code-block:: default cs5 = hfss.modeler.create_coordinate_system(name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123) .. GENERATED FROM PYTHON SOURCE LINES 127-133 Create face coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Face coordinate systems are bound to an object face. First create a box and then define the face coordinate system on one of its faces. To create the reference face for the face coordinate system, you must specify starting and ending points for the axis. .. GENERATED FROM PYTHON SOURCE LINES 133-140 .. code-block:: default box = hfss.modeler.create_box([0, 0, 0], [2, 2, 2]) face = box.faces[0] fcs1 = hfss.modeler.create_face_coordinate_system( face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1" ) .. GENERATED FROM PYTHON SOURCE LINES 141-145 Create face coordinate system centered on face ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a face coordinate system centered on the face with the X axis pointing to the edge vertex. .. GENERATED FROM PYTHON SOURCE LINES 145-150 .. code-block:: default fcs2 = hfss.modeler.create_face_coordinate_system( face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2" ) .. GENERATED FROM PYTHON SOURCE LINES 151-155 Swap X and Y axes of face coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Swap the X axis and Y axis of the face coordinate system. The X axis is the pointing ``axis_position`` by default. You can optionally select the Y axis. .. GENERATED FROM PYTHON SOURCE LINES 155-161 .. code-block:: default fcs3 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0], axis="Y") # Axis can also be changed after coordinate system creation fcs3.props["WhichAxis"] = "X" .. GENERATED FROM PYTHON SOURCE LINES 162-167 Apply a rotation around Z axis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Apply a rotation around the Z axis. The Z axis of a face coordinate system is always orthogonal to the face. A rotation can be applied at definition. Rotation is expressed in degrees. .. GENERATED FROM PYTHON SOURCE LINES 167-173 .. code-block:: default fcs4 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[1], rotation=10.3) # Rotation can also be changed after coordinate system creation fcs4.props["ZRotationAngle"] = "3deg" .. GENERATED FROM PYTHON SOURCE LINES 174-178 Apply offset to X and Y axes of face coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Apply an offset to the X axis and Y axis of a face coordinate system. The offset is in respect to the face coordinate system itself. .. GENERATED FROM PYTHON SOURCE LINES 178-187 .. code-block:: default fcs5 = hfss.modeler.create_face_coordinate_system( face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3] ) # The offset can also be changed after the coordinate system is created. fcs5.props["XOffset"] = "0.2mm" fcs5.props["YOffset"] = "0.1mm" .. GENERATED FROM PYTHON SOURCE LINES 188-192 Create coordinate system relative to face coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a coordinate system relative to a face coordinate system. Coordinate systems and face coordinate systems interact with each other. .. GENERATED FROM PYTHON SOURCE LINES 192-199 .. code-block:: default face = box.faces[1] fcs6 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0]) cs_fcs = hfss.modeler.create_coordinate_system( name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso" ) .. GENERATED FROM PYTHON SOURCE LINES 200-203 Get all coordinate systems ~~~~~~~~~~~~~~~~~~~~~~~~~~ Get all coordinate systems. .. GENERATED FROM PYTHON SOURCE LINES 203-208 .. code-block:: default css = hfss.modeler.coordinate_systems names = [i.name for i in css] print(names) .. rst-class:: sphx-glr-script-out .. code-block:: none ['CS_FCS', 'Face_CS_S4M4KF', 'Face_CS_1LA3BG', 'Face_CS_5URKGT', 'Face_CS_QHEKY7', 'FCS2', 'FCS1', 'CS5', 'CS4', 'CS3', 'CS2'] .. GENERATED FROM PYTHON SOURCE LINES 209-212 Select coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~ Select an existing coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 212-217 .. code-block:: default css = hfss.modeler.coordinate_systems cs_selected = css[0] cs_selected.delete() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 218-222 Get point coordinate under another coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get a point coordinate under another coordinate system. A point coordinate can be translated in respect to any coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 222-229 .. code-block:: default hfss.modeler.create_box([-10, -10, -10], [20, 20, 20], "Box1") p = hfss.modeler["Box1"].faces[0].vertices[0].position print("Global: ", p) p2 = hfss.modeler.global_to_cs(p, "CS5") print("CS5 :", p2) .. rst-class:: sphx-glr-script-out .. code-block:: none Global: [-10.0, -10.0, 10.0] CS5 : [-10.0, 13.8330960296045, 2.940315329304] .. GENERATED FROM PYTHON SOURCE LINES 230-235 Close AEDT ~~~~~~~~~~ After the simulaton completes, you can close AEDT or release it using the :func:`pyaedt.Desktop.release_desktop` method. All methods provide for saving the project before closing. .. GENERATED FROM PYTHON SOURCE LINES 235-237 .. code-block:: default d.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 32.618 seconds) .. _sphx_glr_download_examples_01-Modeling-Setup_HFSS_CoordinateSystem.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: HFSS_CoordinateSystem.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: HFSS_CoordinateSystem.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_