.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\basics\lab_basics.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_basics_lab_basics.py: .. _ref_lab_basics: Motor-CAD Lab model example script ================================== This example provides a Motor-CAD Lab model script. .. GENERATED FROM PYTHON SOURCE LINES 32-39 Set up example -------------- Setting up this example consists of performing imports, launching Motor-CAD, disabling all popup messages from Motor-CAD, and opening the file for the lab model. Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 39-50 .. code-block:: Python import os import matplotlib.pyplot as plt from scipy import io import ansys.motorcad.core as pymotorcad if "QT_API" in os.environ: os.environ["QT_API"] = "pyqt" .. GENERATED FROM PYTHON SOURCE LINES 51-53 Launch Motor-CAD ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python print("Starting initialization.") mcad = pymotorcad.MotorCAD() .. rst-class:: sphx-glr-script-out .. code-block:: none Starting initialization. .. GENERATED FROM PYTHON SOURCE LINES 58-60 Disable popup messages ~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python mcad.set_variable("MessageDisplayState", 2) .. GENERATED FROM PYTHON SOURCE LINES 64-68 Open relevant file ~~~~~~~~~~~~~~~~~~ Specify the working directory and open the relevant file for the lab model. .. GENERATED FROM PYTHON SOURCE LINES 68-76 .. code-block:: Python working_folder = os.getcwd() mcad.load_template("e8") mcad_name = "e8_mobility" mcad.save_to_file(os.path.join(working_folder, mcad_name + ".mot")) print("Initialization completed.") .. rst-class:: sphx-glr-script-out .. code-block:: none Initialization completed. .. GENERATED FROM PYTHON SOURCE LINES 77-80 Build model ----------- Set build options for the lab model. .. GENERATED FROM PYTHON SOURCE LINES 80-87 .. code-block:: Python mcad.set_variable("ModelType_MotorLAB", 1) mcad.set_variable("SatModelPoints_MotorLAB", 0) mcad.set_variable("LossModel_Lab", 0) mcad.set_variable("ModelBuildSpeed_MotorLAB", 10000) mcad.set_variable("MaxModelCurrent_MotorLAB", 480) mcad.set_variable("BuildSatModel_MotorLAB", True) .. GENERATED FROM PYTHON SOURCE LINES 88-89 Show the lab context. .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: Python mcad.set_motorlab_context() .. GENERATED FROM PYTHON SOURCE LINES 92-93 Build the model. .. GENERATED FROM PYTHON SOURCE LINES 93-96 .. code-block:: Python mcad.clear_model_build_lab() mcad.build_model_lab() .. GENERATED FROM PYTHON SOURCE LINES 97-98 Change operating modes. .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python mcad.set_variable("OperatingMode_Lab", 0) .. GENERATED FROM PYTHON SOURCE LINES 101-104 Calculate e-magnetic performance -------------------------------- Set e-magnetic calculation options. .. GENERATED FROM PYTHON SOURCE LINES 104-110 .. code-block:: Python mcad.set_variable("EmagneticCalcType_Lab", 0) mcad.set_variable("SpeedMax_MotorLAB", 10000) mcad.set_variable("Speedinc_MotorLAB", 250) mcad.set_variable("SpeedMin_MotorLAB", 500) mcad.set_variable("Imax_MotorLAB", 480) .. GENERATED FROM PYTHON SOURCE LINES 111-112 Calculate e-magnetic performance. .. GENERATED FROM PYTHON SOURCE LINES 112-118 .. code-block:: Python try: mcad.calculate_magnetic_lab() print("Magnetic calculation successfully completed.") except pymotorcad.MotorCADError: print("Magnetic calculation failed.") .. rst-class:: sphx-glr-script-out .. code-block:: none Magnetic calculation successfully completed. .. GENERATED FROM PYTHON SOURCE LINES 119-120 Retrieve results. .. GENERATED FROM PYTHON SOURCE LINES 120-125 .. code-block:: Python data = io.loadmat(os.path.join(working_folder, mcad_name, "Lab", "MotorLAB_elecdata.mat")) speed = data["Speed"] shaft_torque = data["Shaft_Torque"] shaft_power = data["Shaft_Power"] .. GENERATED FROM PYTHON SOURCE LINES 126-129 Plot results ------------ Plot torque/speed curve results. .. GENERATED FROM PYTHON SOURCE LINES 129-141 .. code-block:: Python plt.figure(1) plt.subplot(211) plt.plot(speed, shaft_torque) plt.xlabel("Speed") plt.ylabel("Shaft Torque") plt.subplot(212) plt.plot(speed, shaft_power) plt.xlabel("Speed") plt.ylabel("Shaft Power") plt.show(block=False) plt.savefig(os.path.join(working_folder, "../Maximum Torque VS Speed Curve.png")) .. image-sg:: /examples/basics/images/sphx_glr_lab_basics_001.png :alt: lab basics :srcset: /examples/basics/images/sphx_glr_lab_basics_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 142-145 Calculate operating point ------------------------- Set operating point calculation options. .. GENERATED FROM PYTHON SOURCE LINES 145-151 .. code-block:: Python mcad.set_variable("OpPointSpec_MotorLAB", 1) mcad.set_variable("StatorCurrentDemand_Lab", 480) mcad.set_variable("SpeedDemand_MotorLAB", 4000) mcad.set_variable("LabThermalCoupling", 0) mcad.set_variable("LabMagneticCoupling", 0) .. GENERATED FROM PYTHON SOURCE LINES 152-153 # Calculate operating point. .. GENERATED FROM PYTHON SOURCE LINES 153-155 .. code-block:: Python mcad.calculate_operating_point_lab() .. GENERATED FROM PYTHON SOURCE LINES 156-157 Retrieve results. .. GENERATED FROM PYTHON SOURCE LINES 157-163 .. code-block:: Python op_point_shaft_torque = mcad.get_variable("LabOpPoint_ShaftTorque") op_point_efficiency = mcad.get_variable("LabOpPoint_Efficiency") print("Operating Point Shaft Torque = ", op_point_shaft_torque) print("Operating Point Efficiency = ", op_point_efficiency) .. rst-class:: sphx-glr-script-out .. code-block:: none Operating Point Shaft Torque = 293.331897665637 Operating Point Efficiency = 96.9372201241536 .. GENERATED FROM PYTHON SOURCE LINES 164-167 Exit Motor-CAD -------------- Exit Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 167-169 .. code-block:: Python mcad.quit() print("Simulation completed.") .. rst-class:: sphx-glr-script-out .. code-block:: none Simulation completed. .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 4.627 seconds) .. _sphx_glr_download_examples_basics_lab_basics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: lab_basics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: lab_basics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: lab_basics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_