Update app.py
Browse files1234567891011121314151617181920212223242526272829303132import streamlit as stimport os# 1. Affichage de l'image PetroOXY optimisée en haut de pagest.image("PetroOXY.jpg", use_container_width=True)# 2. Intégration de l'introduction (Principe de fonctionnement)try:with open("intropetrooxy.txt", "r", encoding="utf-8") as f:intro_text = f.read()st.markdown(intro_text)except FileNotFoundError:st.warning("Le fichier 'intropetrooxy.txt' est introuvable dans l'onglet Files.")# En-tête visuelle pour séparer l'introduction de la zone de simulationst.write("---")st.subheader("💻 Zone de Simulation & Calculs")# =====================================================================# VOS INPUTS ET CALCULS SONT ICI# =====================================================================# En-tête visuelle pour séparer les résultats de la conclusionst.write("---")# 3. Intégration de la conclusion et des perspectivestry:with open("conclupetrooxy.txt", "r", encoding="utf-8") as f:conclusion_text = f.read()st.markdown(conclusion_text)except FileNotFoundError:st.warning("Le fichier 'conclupetrooxy.txt' est introuvable dans l'onglet Files.")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181import streamlit as stimport numpy as npimport matplotlib.pyplot as pltimport mathimport ioimport sys# =====================================================================# 1. FONCTIONS GRAPHIQUES ET OUTILS (VOTRE CODE ENTRÉE)# =====================================================================def idiese(nbd):for i in range(nbd):print("#", end="")print()def TRACE1D(x, y1, y2, label_x, label_y1, label_y2, title):fig, ax1 = plt.subplots(figsize=(8, 5))x_log = np.where(x <= 0, 1e-3, x)ax1.set_xscale('log')ax1.set_xlabel(label_x)# Axe principal (Gauche) : Pressionax1.plot(x_log, y1, color='red', label=label_y1)ax1.set_ylabel(label_y1, color='red')ax1.tick_params(axis='y', labelcolor='red')# Axe secondaire (Droite) : Concentrationax2 = ax1.twinx()ax2.plot(x_log, y2, 'o', color='blue', label=label_y2)ax2.set_ylabel(label_y2, color='blue')ax2.tick_params(axis='y', labelcolor='blue')plt.title(title)fig.tight_layout()return figdef TRACE2D(x, y1, y2, label_x, label_y1, label_y2, title):fig, ax1 = plt.subplots(figsize=(8, 5))x_log = np.where(x <= 0, 1e-3, x)ax1.set_xscale('log')ax1.set_xlabel(label_x)# AXE Y1 : TEMPÉRATURE (À gauche)ax1.set_ylabel(label_y1, color='blue')ax1.plot(x_log, y1, color='blue')ax1.tick_params(axis='y', labelcolor='blue')ax1.set_ylim(0, 180)# AXE Y2 : PRESSION (À droite)ax2 = ax1.twinx()ax2.set_ylabel(label_y2, color='red')ax2.plot(x_log, y2, color='red')ax2.tick_params(axis='y', labelcolor='red')ax2.set_ylim(7e5, 10.5e5)plt.title(title)fig.tight_layout()return figdef executer_simulation():stdout_capture = io.StringIO()sys.stdout = stdout_capturetry:print("00 - IMPORT DES BIBLIOTHEQUES TERMINÉ")print("01 - PARAMETRES DE DIMENSIONNEMENT ET VARIABLES UTILES")un = 1.E+00 ; zero = 0.E+00 ; mill = 1.000E+03rgp = 8.314 ; Tref = 273.15 ; Tamb = 25.E+00MmolRH = 167E+00 ; MmolO2 = 32.E+00Venc = 0.18070 ; Vech = 0.00500 ; Pini = 700.Dtsec = 500. ; Pexpo = 1.E+09 ; Ea = 90000Tset = 160.E+00 ; roRH = 780.E+00 ; Solub = 2.8E-03niter = 500 ; niterd = 100print("02 - MASSE MOLAIRE FUEL SATURE ET NBE DE MOLES")MassRH = roRH * VechMmolRHs = (MmolRH + Solub * MmolO2) / (un + Solub)nmolRH = MassRH / MmolRHsTsetK = Tref + Tsetk_app = Pexpo * math.exp(-Ea/rgp/TsetK) / millTcou = np.zeros(niter)TcouK = np.zeros(niter)Tps = np.zeros(niter)Pres = np.zeros(niter)Cfuel = np.zeros(niter)print("03 - MONTEE EN TEMPERATURE : EVOLUTION P et T ")VencSI = Venc / mill ; VechSI = Vech / millVolg = (VencSI - VechSI)nO2g = mill * Pini * Volg / rgp / (Tamb + Tref)Pas_montee = Dtsec / float(niterd - 1)ezt = Tset - Tambfor i in range(niterd):Tps[i] = float(i) * Pas_monteezz = math.exp(-4 * Tps[i] / Dtsec)Tcou[i] = Tamb + ezt * (un - zz)TcouK[i] = Tcou[i] + TrefPres[i] = nO2g * rgp * TcouK[i] / VolgCfuel[i] = nmolRH / Vechprint("04 - RACCORDEMENT / TRANSITOIRE ET INSTANT DE FIN D'ESSAI")TK = TcouK[niterd-1]Pmax = Pres[niterd-1]Pend = 0.9 * PmaxdeltaP = Pmax - PendCfuel0 = Cfuel[niterd-1]Xi = Cfuel0 * rgp * TK * (Vech / Volg)ezp = Xi / (Xi - deltaP)trmax = math.log(ezp) / k_appprint(f"DUREE DE L'ESSAI CALCULÉE : {trmax/3600:.4f} heures")print("05 - DETERMINATION T, P, C_RH EN PHASE DE THERMO-OXYDATION")ntest = niter - niterdPas_test = trmax / float(ntest - 1)ii = 1for i in range(niterd, niter):timeloc = float(ii) * Pas_testTps[i] = Tps[niterd-1] + timelocTcou[i] = Tcou[niterd-1]termExp = math.exp(-k_app * timeloc)ezP = un - termExpPres[i] = Pmax - Xi * ezPCfuel[i] = Cfuel[niterd-1] * termExpii += 1print("06 - ENREGISTREMENT DES FIGURES")fig1 = TRACE2D(Tps, Tcou, Pres, "Temps (s)", "TEMPERATURE (°C)", "PRESSION (Pa)", "EVOLUTION TEMPORELLE T & P")fig2 = TRACE1D(Tps, Pres, Cfuel, "Temps (s)", "PRESSION (Pa)", "Concentration (mol/l)", "EVOLUTION TEMPORELLE P ET Cfuel")finally:sys.stdout = sys.__stdout__texte_deroule = stdout_capture.getvalue()return texte_deroule, fig1, fig2# =====================================================================# 2. INTERFACE UTILISATEUR STREAMLIT# =====================================================================# Affichage sécurisé de l'imagest.image("PetroOXY.jpg", use_container_width=True)# Affichage de l'introductiontry:with open("intropetrooxy.txt", "r", encoding="utf-8") as f:intro_text = f.read()st.markdown(intro_text)except FileNotFoundError:st.warning("Le fichier 'intropetrooxy.txt' est manquant dans les fichiers sources.")st.write("---")st.subheader("💻 Exécution du code numérique")# Bouton d'action pour lancer la simulationif st.button("🚀 Lancer la simulation PetroOXY"):with st.spinner("Calcul des équations cinétiques en cours..."):# Exécution du moteur physiquelog_texte, figure1, figure2 = executer_simulation()st.success("Simulation terminée avec succès !")# Affichage des deux graphiques côte à côte ou l'un sous l'autrest.pyplot(figure1)st.pyplot(figure2)# Optionnel : Affichage des lignes de log de la consolewith st.expander("📄 Voir le rapport détaillé d'exécution"):st.code(log_texte)st.write("---")# Affichage de la conclusiontry:with open("conclupetrooxy.txt", "r", encoding="utf-8") as f:conclusion_text = f.read()st.markdown(conclusion_text)except FileNotFoundError:st.warning("Le fichier 'conclupetrooxy.txt' est manquant dans les fichiers sources.")
app.py+161-12