.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\advanced\force_extraction.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_advanced_force_extraction.py: .. _ref_force_extraction: Motor-CAD force extraction example script ========================================= todo: expand this... .. GENERATED FROM PYTHON SOURCE LINES 34-35 Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python import ansys.motorcad.core as pymotorcad .. GENERATED FROM PYTHON SOURCE LINES 38-39 Launch Motor-CAD .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python mc = pymotorcad.MotorCAD() .. GENERATED FROM PYTHON SOURCE LINES 42-43 Disable pop-up messages .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python mc.set_variable("MessageDisplayState", 2) .. GENERATED FROM PYTHON SOURCE LINES 47-49 Load a baseline model - in this case a template. For users, this would normally be a baseline model .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python mc.load_template("e9") .. GENERATED FROM PYTHON SOURCE LINES 52-53 Set up the point we want to extract .. GENERATED FROM PYTHON SOURCE LINES 53-60 .. code-block:: Python required_space_order = 8 # Space order required, positive or negative required_electrical_time_order = 2 # Electrical time order required, should be 0 or positive operating_point = ( 1 # Which speed point to extract data for (between 1 and the number of calculations run) ) rotor_slice = 1 # Which rotor slice (if more than one) that we want results from .. GENERATED FROM PYTHON SOURCE LINES 61-62 Run the calculation (Assume that it has already been set up as required) .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python mc.do_multi_force_calculation() .. GENERATED FROM PYTHON SOURCE LINES 65-66 How many cycles have been run .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python electrical_cycles = mc.get_variable("TorqueNumberCycles") .. GENERATED FROM PYTHON SOURCE LINES 69-70 Extract max space order that exists in the calculation .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python mech_force_space_order_max = mc.get_variable("ForceMaxOrder_Space_Stator_OL") .. GENERATED FROM PYTHON SOURCE LINES 73-77 Get the indexes to use in querying the force: required_time_order should always be 0 or positive. This is the order of the number of cycles run, which will be the same as electrical order if electrical_cycles = 1 .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: Python required_time_order = required_electrical_time_order * electrical_cycles .. GENERATED FROM PYTHON SOURCE LINES 80-81 Results stored with negative space orders at the end, so apply offset .. GENERATED FROM PYTHON SOURCE LINES 81-84 .. code-block:: Python if required_space_order < 0: required_space_order = required_space_order + 2 * mech_force_space_order_max .. GENERATED FROM PYTHON SOURCE LINES 85-87 Find the force density using GetMagnetic3DGraphPoint: Note the use of _Th1 for the 1st operating point in the name. .. GENERATED FROM PYTHON SOURCE LINES 87-94 .. code-block:: Python _, force_density_result = mc.get_magnetic_3d_graph_point( "Fr_Density_Stator_FFT_Amplitude_OL" + "_Th" + str(operating_point), rotor_slice, required_space_order, required_time_order, ) .. GENERATED FROM PYTHON SOURCE LINES 95-97 Apply 2x factor due to FFT symmetry, unless 0th time order (mean) This is equivalent to showing results with 'Positive time only' .. GENERATED FROM PYTHON SOURCE LINES 97-100 .. code-block:: Python if required_time_order > 0: force_density_result = force_density_result * 2 .. GENERATED FROM PYTHON SOURCE LINES 101-103 Results ------- .. GENERATED FROM PYTHON SOURCE LINES 103-104 .. code-block:: Python print("Force density: " + str(force_density_result)) .. rst-class:: sphx-glr-script-out .. code-block:: none Force density: 122696.3686592 .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 29.503 seconds) .. _sphx_glr_download_examples_advanced_force_extraction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: force_extraction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: force_extraction.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: force_extraction.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_