.. 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 12-13 Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 13-15 .. code-block:: Python import ansys.motorcad.core as pymotorcad .. GENERATED FROM PYTHON SOURCE LINES 16-17 Launch Motor-CAD .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: Python mc = pymotorcad.MotorCAD() .. GENERATED FROM PYTHON SOURCE LINES 20-21 Disable pop-up messages .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python mc.set_variable("MessageDisplayState", 2) .. GENERATED FROM PYTHON SOURCE LINES 25-27 Load a baseline model - in this case a template. For users, this would normally be a baseline model .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python mc.load_template("e9") .. GENERATED FROM PYTHON SOURCE LINES 30-31 Set up the point we want to extract .. GENERATED FROM PYTHON SOURCE LINES 31-38 .. 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 39-40 Run the calculation (Assume that it has already been set up as required) .. GENERATED FROM PYTHON SOURCE LINES 40-42 .. code-block:: Python mc.do_multi_force_calculation() .. GENERATED FROM PYTHON SOURCE LINES 43-44 How many cycles have been run .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: Python electrical_cycles = mc.get_variable("TorqueNumberCycles") .. GENERATED FROM PYTHON SOURCE LINES 47-48 Extract max space order that exists in the calculation .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python mech_force_space_order_max = mc.get_variable("ForceMaxOrder_Space_Stator_OL") .. GENERATED FROM PYTHON SOURCE LINES 51-55 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 55-57 .. code-block:: Python required_time_order = required_electrical_time_order * electrical_cycles .. GENERATED FROM PYTHON SOURCE LINES 58-59 Results stored with negative space orders at the end, so apply offset .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. 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 63-65 Find the force density using GetMagnetic3DGraphPoint: Note the use of _Th1 for the 1st operating point in the name. .. GENERATED FROM PYTHON SOURCE LINES 65-72 .. 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 73-75 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 75-78 .. code-block:: Python if required_time_order > 0: force_density_result = force_density_result * 2 .. GENERATED FROM PYTHON SOURCE LINES 79-81 Results ------- .. GENERATED FROM PYTHON SOURCE LINES 81-82 .. code-block:: Python print("Force density: " + str(force_density_result)) .. rst-class:: sphx-glr-script-out .. code-block:: none Force density: 123612.9127435388 .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 58.329 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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_