.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\internal_scripting\mechanical_force.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_internal_scripting_mechanical_force.py: .. _ref_internal_scripting_mechanical_force: Mechanical force ================ This example demonstrates internal scripting mechanical force functionality This will compute the operating conditions for some requested torque values and display the natural frequencies for the 0th and 8th modes. .. 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-42 .. code-block:: Python mc = pymotorcad.MotorCAD() .. GENERATED FROM PYTHON SOURCE LINES 43-45 Create internal script. This could also be saved in a separate file .. GENERATED FROM PYTHON SOURCE LINES 45-90 .. code-block:: Python import numpy as np # This function is called when "Run" is pressed def main(): pass class mechanical_forces: def initial(self): # %% # Disable pop-up messages mc.set_variable("MessageDisplayState", 2) # Called before calculation # For each operating point, set requested torque and speed # (using this mode requires that a Lab model has been built) # Note that if a lab model isn't available, MultiForceLoadPointDefinition # can be set to 1 (Current and Phase), and # LoadPoint_Current_Array and LoadPoint_PhaseAdvance_Array set # IM operating points are set with speed, current, and LoadPoint_Slip_Array NVH_Duty_Speed = np.concatenate((250, 6000, 9000), axis=None) NVH_Duty_Torque = np.concatenate((40, 20, 10), axis=None) mc.set_variable("NumLoadPoints", len(NVH_Duty_Speed)) for i in range(len(NVH_Duty_Speed)): mc.set_array_variable("LoadPoint_Speed_Array", i, float(NVH_Duty_Speed[i])) mc.set_array_variable("LoadPoint_Torque_Array", i, float(NVH_Duty_Torque[i])) # Set number of steps per cycle - for speed just use 30 in this example. 90 would be # a more usual minimum # If calculating for an induction machine (IM), use IMSingleLoadPointsPerCycle instead mc.set_variable("TorquePointsPerCycle", 30) def final(self): # Called after calculation # Example modal results o_Natural_Freq_Mode_0 = mc.get_magnetic_graph_point("NVH_NaturalFrequency", 0) o_Natural_Freq_Mode_8 = mc.get_magnetic_graph_point("NVH_NaturalFrequency", 8) mc.show_message(" Natural_Freq_Mode_0 " + str(o_Natural_Freq_Mode_0)) mc.show_message(" Natural_Freq_Mode_8 " + str(o_Natural_Freq_Mode_8)) mc.set_variable("MessageDisplayState", 0) .. GENERATED FROM PYTHON SOURCE LINES 91-94 Note ---- For further details, please see the E-NVH tutorial. .. GENERATED FROM PYTHON SOURCE LINES 96-99 PyMotorCAD Documentation Example -------------------------------------- (Used for the PyMotorCAD Documentation Examples only) .. GENERATED FROM PYTHON SOURCE LINES 99-105 .. code-block:: Python try: from setup_scripts.setup_script import run_mech_force_demo except ImportError: pass else: run_mech_force_demo(mc) .. rst-class:: sphx-glr-script-out .. code-block:: none 2:55:12 PM : Natural_Freq_Mode_0 (0, 6658.47007165279) 2:55:12 PM : Natural_Freq_Mode_8 (8, 8858.68125781642) .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 58.315 seconds) .. _sphx_glr_download_examples_internal_scripting_mechanical_force.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mechanical_force.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mechanical_force.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: mechanical_force.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_