Files
pinn/fdm/app.py
T
2026-05-13 21:24:26 +02:00

59 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fdm.solver import solve
from fdm.visualizer import visualize_fdm
def print_header():
print("=" * 38)
print(" Heat Equation — FDM Solver")
print(" ∂T/∂t = α ∂²T/∂x²")
print("=" * 38)
def main_menu():
print("\nInitializing solver...")
print("Ready.\n")
T, x_vals, t_vals = None, None, None
while True:
print("\n" + "-" * 30)
print(" MAIN MENU")
print("-" * 30)
print("1. Risolvi e salva risultati")
print("2. Heatmap T(x,t)")
print("3. Animazione T(x) nel tempo")
print("4. Grafico T(t) in punti fissi")
print("0. Esci")
print("-" * 30)
choice = input("Select an option (0-4): ").strip()
if choice == "1":
T, x_vals, t_vals = solve()
print(f"Soluzione completata. Shape T: {T.shape}")
print(f"T range: [{T.min():.2f}, {T.max():.2f}] °C")
elif choice in ("2", "3", "4"):
if T is None:
print("Eseguire prima l'opzione 1.")
else:
visualize_fdm(T, x_vals, t_vals)
print("Grafici salvati in animations/fdm/")
elif choice == "0":
print("Uscita.")
sys.exit(0)
else:
print("Scelta non valida.")
if __name__ == "__main__":
print_header()
main_menu()