.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\basics\thermal_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_thermal_basics.py: .. _ref_thermal_basics: Motor-CAD thermal example script ================================ This example provides a Motor-CAD thermal script. .. GENERATED FROM PYTHON SOURCE LINES 32-37 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 thermal analysis. .. GENERATED FROM PYTHON SOURCE LINES 37-50 .. code-block:: Python # Perform required imports # ~~~~~~~~~~~~~~~~~~~~~~~~ # Import the required packages. import os import matplotlib.pyplot as plt import ansys.motorcad.core as pymotorcad if "QT_API" in os.environ: os.environ["QT_API"] = "pyqt" .. GENERATED FROM PYTHON SOURCE LINES 51-54 Launch Motor-CAD ~~~~~~~~~~~~~~~~ Initialize ActiveX automation and launch Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 54-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-61 Disable popup messages ~~~~~~~~~~~~~~~~~~~~~~ Disable all popup messages from Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 61-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 thermal analysis. .. GENERATED FROM PYTHON SOURCE LINES 68-77 .. 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)) mcad.load_from_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 78-82 Create analysis --------------- Creating the analysis consists of showing the thermal context, displaying the **Scripting** tab, setting parameters, and saving the file. .. GENERATED FROM PYTHON SOURCE LINES 82-87 .. code-block:: Python # Show thermal context # ----------------------- mcad.show_thermal_context() .. GENERATED FROM PYTHON SOURCE LINES 88-89 Display the **Scripting** tab. .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: Python mcad.display_screen("Scripting") .. GENERATED FROM PYTHON SOURCE LINES 92-93 Change the housing diameter. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python mcad.set_variable("Housing_Dia", 250) .. GENERATED FROM PYTHON SOURCE LINES 96-97 Set the flow rate of the WJ fluid volume. .. GENERATED FROM PYTHON SOURCE LINES 97-99 .. code-block:: Python mcad.set_variable("WJ_Fluid_Volume_Flow_Rate", 0.002) .. GENERATED FROM PYTHON SOURCE LINES 100-101 Set the temperature of the WJ fluid inlet. .. GENERATED FROM PYTHON SOURCE LINES 101-103 .. code-block:: Python mcad.set_variable("WJ_Fluid_Inlet_Temperature", 25) .. GENERATED FROM PYTHON SOURCE LINES 104-105 Change the cooling fluid. .. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: Python mcad.set_fluid("HousingWJFluid", "Dynalene HF-LO") .. GENERATED FROM PYTHON SOURCE LINES 108-109 Set the heat transfer correlation. .. GENERATED FROM PYTHON SOURCE LINES 109-127 .. code-block:: Python mcad.set_variable("Calc/Input_h[WJ]_Rear_Housing", 1) mcad.set_array_variable("HousingWJ_CalcInputH_A", 0, 1) wj_fluid_k = mcad.get_variable("WJ_Fluid_Thermal_Conductivity") wj_fluid_rho = mcad.get_variable("WJ_Fluid_Density") wj_fluid_mu = mcad.get_variable("WJ_Fluid_Dynamic_Viscosity") wj_fluid_u_a = mcad.get_array_variable("HousingWJ_Velocity_A", 0) wj_fluid_u_r = mcad.get_variable("WJ_Channel_Fluid_Velocity_[Rear]") h_A = 0.005 * wj_fluid_k * wj_fluid_rho * wj_fluid_u_a / wj_fluid_mu h_R = 0.005 * wj_fluid_k * wj_fluid_rho * wj_fluid_u_r / wj_fluid_mu print("h_A = ", h_A) print("h_R = ", h_R) mcad.set_array_variable("HousingWJ_InputH_A", 0, h_A) mcad.set_variable("Input_Value_h[WJ]_Rear_Housing", h_R) .. rst-class:: sphx-glr-script-out .. code-block:: none h_A = 178.49062082139457 h_R = 0.0 .. GENERATED FROM PYTHON SOURCE LINES 128-129 Save the file. .. GENERATED FROM PYTHON SOURCE LINES 129-131 .. code-block:: Python mcad.save_to_file(os.path.join(working_folder, "../MotorCAD_Thermal_Python.mot")) .. GENERATED FROM PYTHON SOURCE LINES 132-135 Calculate steady state ---------------------- Calculate the steady state. .. GENERATED FROM PYTHON SOURCE LINES 135-141 .. code-block:: Python try: mcad.do_steady_state_analysis() print("Thermal calculation successfully completed.") except pymotorcad.MotorCADError: print("Thermal calculation failed.") .. rst-class:: sphx-glr-script-out .. code-block:: none Thermal calculation successfully completed. .. GENERATED FROM PYTHON SOURCE LINES 142-143 Retrieve the magnet temperature. .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: Python node_temperature = mcad.get_node_temperature(13) print("Node Temp = ", node_temperature) .. rst-class:: sphx-glr-script-out .. code-block:: none Node Temp = 128.102528138655 .. GENERATED FROM PYTHON SOURCE LINES 147-148 Retrieve the minimum, maximum, and average winding temperatures. .. GENERATED FROM PYTHON SOURCE LINES 148-155 .. code-block:: Python winding_temperature_min = mcad.get_variable("T_[Winding_Min]") winding_temperature_max = mcad.get_variable("T_[Winding_Max]") winding_temperature_average = mcad.get_variable("T_[Winding_Average]") print("Min = ", winding_temperature_min) print("Max = ", winding_temperature_max) print("Average = ", winding_temperature_average) .. rst-class:: sphx-glr-script-out .. code-block:: none Min = 116.279266918815 Max = 144.588223250193 Average = 137.132751906985 .. GENERATED FROM PYTHON SOURCE LINES 156-159 Run simulation -------------- Run the transient simulation. .. GENERATED FROM PYTHON SOURCE LINES 159-167 .. code-block:: Python mcad.set_variable("Transient_Calculation_Type", 0) mcad.set_variable("Transient_Time_Period", 60) try: mcad.do_transient_analysis() except pymotorcad.MotorCADError: print("Thermal calculation failed.") .. GENERATED FROM PYTHON SOURCE LINES 168-169 Get the transient results. .. GENERATED FROM PYTHON SOURCE LINES 169-181 .. code-block:: Python num_time_steps = 51 winding_temp_average_transient = [] time = [] for timeStep in range(num_time_steps): try: (x, y) = mcad.get_temperature_graph_point("Winding (Avg)", timeStep) time.append(x) winding_temp_average_transient.append(y) except pymotorcad.MotorCADError: print("Export failed.") .. GENERATED FROM PYTHON SOURCE LINES 182-185 Plot results ------------ Plot results from the simulation. .. GENERATED FROM PYTHON SOURCE LINES 185-191 .. code-block:: Python plt.figure(1) plt.plot(time, winding_temp_average_transient) plt.xlabel("Time") plt.ylabel("WindingTemp_Average_Transient") plt.show() .. image-sg:: /examples/basics/images/sphx_glr_thermal_basics_001.png :alt: thermal basics :srcset: /examples/basics/images/sphx_glr_thermal_basics_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 192-195 Exit Motor-CAD -------------- Exit Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 195-196 .. code-block:: Python mcad.quit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 59.735 seconds) .. _sphx_glr_download_examples_basics_thermal_basics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: thermal_basics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: thermal_basics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: thermal_basics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_