.. 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 10-15 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 15-28 .. 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 29-32 Launch Motor-CAD ~~~~~~~~~~~~~~~~ Initialize ActiveX automation and launch Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. 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 36-39 Disable popup messages ~~~~~~~~~~~~~~~~~~~~~~ Disable all popup messages from Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python mcad.set_variable("MessageDisplayState", 2) .. GENERATED FROM PYTHON SOURCE LINES 42-46 Open relevant file ~~~~~~~~~~~~~~~~~~ Specify the working directory and open the relevant file for the thermal analysis. .. GENERATED FROM PYTHON SOURCE LINES 46-55 .. 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 56-60 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 60-65 .. code-block:: Python # Show thermal context # ----------------------- mcad.show_thermal_context() .. GENERATED FROM PYTHON SOURCE LINES 66-67 Display the **Scripting** tab. .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python mcad.display_screen("Scripting") .. GENERATED FROM PYTHON SOURCE LINES 70-71 Change the housing diameter. .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: Python mcad.set_variable("Housing_Dia", 250) .. GENERATED FROM PYTHON SOURCE LINES 74-75 Set the flow rate of the WJ fluid volume. .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: Python mcad.set_variable("WJ_Fluid_Volume_Flow_Rate", 0.002) .. GENERATED FROM PYTHON SOURCE LINES 78-79 Set the temperature of the WJ fluid inlet. .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: Python mcad.set_variable("WJ_Fluid_Inlet_Temperature", 25) .. GENERATED FROM PYTHON SOURCE LINES 82-83 Change the cooling fluid. .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: Python mcad.set_fluid("HousingWJFluid", "Dynalene HF-LO") .. GENERATED FROM PYTHON SOURCE LINES 86-87 Set the heat transfer correlation. .. GENERATED FROM PYTHON SOURCE LINES 87-105 .. 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 106-107 Save the file. .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: Python mcad.save_to_file(os.path.join(working_folder, "../MotorCAD_Thermal_Python.mot")) .. GENERATED FROM PYTHON SOURCE LINES 110-113 Calculate steady state ---------------------- Calculate the steady state. .. GENERATED FROM PYTHON SOURCE LINES 113-119 .. 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 120-121 Retrieve the magnet temperature. .. GENERATED FROM PYTHON SOURCE LINES 121-124 .. 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.171296913135 .. GENERATED FROM PYTHON SOURCE LINES 125-126 Retrieve the minimum, maximum, and average winding temperatures. .. GENERATED FROM PYTHON SOURCE LINES 126-133 .. 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.272225696292 Max = 144.596942536281 Average = 137.440314758973 .. GENERATED FROM PYTHON SOURCE LINES 134-137 Run simulation -------------- Run the transient simulation. .. GENERATED FROM PYTHON SOURCE LINES 137-145 .. 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 146-147 Get the transient results. .. GENERATED FROM PYTHON SOURCE LINES 147-159 .. 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 160-163 Plot results ------------ Plot results from the simulation. .. GENERATED FROM PYTHON SOURCE LINES 163-169 .. 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 170-173 Exit Motor-CAD -------------- Exit Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 173-174 .. code-block:: Python mcad.quit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 45.032 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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_