.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "samples\general\ParameterSweepSync.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_samples_general_ParameterSweepSync.py: Simple parametric sweep for SYNC machine ======================================== This is a simple example showing a two-dimensional parametric sweep for a wound field synchronous motor varying continuous stator skew and field current. .. GENERATED FROM PYTHON SOURCE LINES 29-104 .. rst-class:: sphx-glr-script-out .. code-block:: none Running skew: 0 Field current: 5 Sound power level [dB], electrical time order, space order: (68.715680802405, 2.0, 8) (65.6655425538224, 12.0, 0) (61.9602918417768, 10.0, -8) (53.5047465882269, 4.0, -8) (52.0632556454324, 6.0, 0) Running skew: 0 Field current: 10 Sound power level [dB], electrical time order, space order: (72.3252609534223, 2.0, 8) (65.1968444467469, 12.0, 0) (64.0221636292951, 10.0, -8) (58.0170169717154, 6.0, 0) (53.705080908458, 14.0, 8) Running skew: 7.5 Field current: 5 Sound power level [dB], electrical time order, space order: (68.0478860885667, 2.0, 8) (52.3488469520123, 6.0, 0) (51.3004475000929, 4.0, -8) (49.8667975623371, 10.0, -8) (49.3468712552461, 12.0, 0) Running skew: 7.5 Field current: 10 Sound power level [dB], electrical time order, space order: (71.6922106439609, 2.0, 8) (55.0628034540582, 6.0, 0) (52.1725027948218, 3.0, 8) (50.4051561671956, 1.0, 0) (50.3511636859912, 10.0, -8) | .. code-block:: Python import math import ansys.motorcad.core as pymotorcad # Open connection to Motor-CAD, and open e3 template (Sync machine) mc = pymotorcad.MotorCAD() mc.load_template("e3") # Alternatively, use the following # mc = pymotorcad.MotorCAD() # mc.load_from_file('filename.mot') # Ensure the transient calculation and force calculation are enabled mc.set_variable("TorqueCalculation", True) mc.set_variable("ElectromagneticForcesCalc_Load", True) # Make sure continuous stator skew is enabled mc.set_variable("SkewType", 1) # Set up the sweep parameters, in this case for sync machine field current and skew angle skew_angles = [0, 7.5] field_currents = [5, 10] # Run the sweep for skew_angle in skew_angles: for field_current in field_currents: # Set the parameter(s) to sweep mc.set_variable("StatorSkew", skew_angle) mc.set_variable("DCFieldCurrent", field_current) # Tell the user what step we are on: print("Running skew: " + str(skew_angle) + " Field current: " + str(field_current)) # Run the calculation mc.do_magnetic_calculation() # Find many steps have been run if mc.get_variable("MotorType_MotorLAB") == "IM": try: # Variable was renamed in 2024R1, try newer naming first numberOfCycles = mc.get_variable("IMSingleLoadNumberCycles_Rotating") except pymotorcad.MotorCADError: numberOfCycles = mc.get_variable("IMSingleLoadNumberCycles") else: numberOfCycles = mc.get_variable("TorqueNumberCycles") # Get the NVH data matrix nvh_data_raw = mc.get_magnetic_3d_graph("NVH_RadiatedPower_Level_OL", 1) # Find length of data available time_order_items = len(nvh_data_raw.y) space_order_items = len(nvh_data_raw.x) index_offset_space = math.floor(space_order_items / 2) # Iterate over data, storing as a list of tuples, so we can sort to find the biggest nvh_list = [] for raw_time_order in range(time_order_items): electrical_order = raw_time_order / numberOfCycles for raw_space_order in range(space_order_items): space_order = raw_space_order - index_offset_space # Store a tuple of sound power level, electrical time order, space order nvh_list.append( ( nvh_data_raw.data[raw_space_order][raw_time_order], electrical_order, space_order, ) ) # Sort the list on NVH, from highest to lowest, and show top 5 orders nvh_list.sort(reverse=True) print("Sound power level [dB], electrical time order, space order:") for i in range(min(5, len(nvh_list))): print(nvh_list[i]) print("") .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 46.705 seconds) .. _sphx_glr_download_samples_general_ParameterSweepSync.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ParameterSweepSync.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ParameterSweepSync.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ParameterSweepSync.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_