thermique.py

Created by teivaetienne

Created on March 27, 2025

4.39 KB


# Thermal Calculation Script for NumWorks

print("=== Thermal Calculation Script ===")
print("Select a calculation:")
print("1. Conduction Flux")
print("2. Conduction Resistance")
print("3. Convection Flux")
print("4. Convection Resistance")
print("5. Radiation Flux")
print("6. Composite Wall Resistance")
print("7. Composite Wall Flux")
print("8. Temperature Profile")
print("9. Total Flux (Convection + Radiation)")
print("0. Exit")
print("")

while True:
    choice = input("Enter your choice (0-9): ")
    
    if choice == "1":
        # Conduction Flux: phi = lambda * (delta_T / e)
        lambda_ = float(input("Enter thermal conductivity (W/m.K): "))
        delta_T = float(input("Enter temperature difference (K or °C): "))
        e = float(input("Enter thickness (m): "))
        phi = lambda_ * delta_T / e
        print("Conduction flux: {:.4f} W/m2".format(phi))
    
    elif choice == "2":
        # Conduction Resistance: R = e / lambda
        e = float(input("Enter thickness (m): "))
        lambda_ = float(input("Enter thermal conductivity (W/m.K): "))
        R = e / lambda_
        print("Conduction resistance: {:.4f} m2.K/W".format(R))
    
    elif choice == "3":
        # Convection Flux: phi_conv = h * (T_surface - T_infty)
        h = float(input("Enter convection coefficient (W/m2.K): "))
        T_surface = float(input("Enter surface temperature (K or °C): "))
        T_infty = float(input("Enter ambient temperature (K or °C): "))
        phi = h * (T_surface - T_infty)
        print("Convection flux: {:.4f} W/m2".format(phi))
    
    elif choice == "4":
        # Convection Resistance: R_conv = 1 / h
        h = float(input("Enter convection coefficient (W/m2.K): "))
        R = 1 / h
        print("Convection resistance: {:.4f} m2.K/W".format(R))
    
    elif choice == "5":
        # Radiation Flux: phi_rad = epsilon * sigma * (T_surface^4 - T_env^4)
        epsilon = float(input("Enter emissivity (0-1): "))
        T_surface = float(input("Enter surface temperature (K): "))
        T_env = float(input("Enter environment temperature (K): "))
        sigma = 5.67e-8
        phi = epsilon * sigma * (T_surface**4 - T_env**4)
        print("Radiation flux: {:.4f} W/m2".format(phi))
    
    elif choice == "6":
        # Composite Wall Resistance: R_total = sum(e_i / lambda_i)
        n = int(input("Enter number of layers: "))
        R_total = 0
        for i in range(n):
            e = float(input("Layer {}: Enter thickness (m): ".format(i+1)))
            lambda_ = float(input("Layer {}: Enter thermal conductivity (W/m.K): ".format(i+1)))
            R_total += e / lambda_
        print("Total composite resistance: {:.4f} m2.K/W".format(R_total))
    
    elif choice == "7":
        # Composite Wall Flux: phi = delta_T / R_total
        delta_T = float(input("Enter total temperature difference (K or °C): "))
        R_total = float(input("Enter total composite resistance (m2.K/W): "))
        phi = delta_T / R_total
        print("Composite wall flux: {:.4f} W/m2".format(phi))
    
    elif choice == "8":
        # Temperature Profile: T(x) = T_int - (delta_T / e) * x
        T_int = float(input("Enter interior temperature (K or °C): "))
        delta_T = float(input("Enter total temperature difference (K or °C): "))
        e = float(input("Enter wall thickness (m): "))
        x = float(input("Enter distance from interior surface (m): "))
        T_x = T_int - (delta_T / e) * x
        print("Temperature at x = {:.4f} m: {:.4f}".format(x, T_x))
    
    elif choice == "9":
        # Total Flux (Convection + Radiation): phi_total = h*(T_surface - T_infty) + epsilon * sigma * (T_surface^4 - T_env^4)
        h = float(input("Enter convection coefficient (W/m2.K): "))
        T_surface = float(input("Enter surface temperature (K): "))
        T_infty = float(input("Enter ambient temperature (K): "))
        epsilon = float(input("Enter emissivity (0-1): "))
        T_env = float(input("Enter environment temperature (K): "))
        sigma = 5.67e-8
        phi_conv = h * (T_surface - T_infty)
        phi_rad = epsilon * sigma * (T_surface**4 - T_env**4)
        phi_total = phi_conv + phi_rad
        print("Total flux (convection + radiation): {:.4f} W/m2".format(phi_total))
    
    elif choice == "0":
        print("Exiting.")
        break
    
    else:
        print("Invalid choice. Please choose between 0 and 9.")
    
    print("\n---\n")  # Séparateur entre les opérations

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.