import numpy as np import pandas as pd # Constants V = 0.5 # Balloon volume in m³ R = 285 # Specific gas constant for air in J/(kg·K) Cv = 715 # Specific heat capacity of air in J/(kg·K) P_initial = 5 * 1e5 # Initial pressure in Pa (5 bar) T_initial = 293.15 # Initial temperature in K (20°C) n = 500 # Total simulation duration in seconds dt = 20 # Time step in seconds A = 3 # Balloon surface area in m² h = 3 # Heat loss coefficient in W/m²/K T_ext = 300 # External temperature in K # Functions to calculate tau, mair, and Tair as a function of pressure (in bar) def tau(x): return 0.0019 * x**3 - 0.0485 * x**2 + 0.5328 * x + 1.2794 def mair(x): return -0.0006 * x + 0.0149 def Tair(x): return 0.1135 * x**3 - 2.2814 * x**2 + 17.361 * x + 16.564 # Initialization P = P_initial T = T_initial m = (P * V) / (R * T) # Initial mass of air in the balloon W_cumule = 0 # Initial cumulative work # List to store results results = [] # Simulation loop for t in range(0, n + dt, dt): x = P / 1e5 # Convert pressure to bar current_mair = mair(x) current_Tair = Tair(x) + 273.15 # Convert to Kelvin current_tau = tau(x) # Mass of air injected during dt m_injected = current_mair * dt # Heat losses Q_pertes = h * A * (T - T_ext) * dt # Thermal balance to calculate final temperature T_final = (m * Cv * T + m_injected * Cv * current_Tair - Q_pertes) / ((m + m_injected) * Cv) # Update mass and temperature m += m_injected T = T_final # Update pressure using the ideal gas law P = (m * R * T) / V # Update cumulative work W_cumule += current_tau * dt # Store results results.append({ "Time (s)": t, "Pressure (Pa)": P, "Temperature (K)": T, "Mass (kg)": m, "Power (tau)": current_tau, "Flow rate (mair)": current_mair, "Injected air temperature (Tair)": current_Tair, "Cumulative work (J)": W_cumule, "Heat losses (J)": Q_pertes }) # Create a DataFrame and export to TSV df = pd.DataFrame(results) df.to_csv("thermal_loss_filling_simulation.tsv", sep="\t", index=False) print("Simulation complete. Results exported to 'thermal_loss_filling_simulation.tsv'.")