Files
pinn/fdm/app.py
T
2026-05-15 15:26:59 +02:00

63 lines
1.5 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, save_csv
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")
print("2. Visualizza")
print("3. Salva CSV")
print("0. Esci")
print("-" * 30)
choice = input("Select an option (0-3): ").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 == "2":
if T is None:
print("Eseguire prima l'opzione 1.")
else:
visualize_fdm(T, x_vals, t_vals)
elif choice == "3":
if T is None:
print("Eseguire prima l'opzione 1.")
else:
save_csv(T, x_vals, t_vals, "results/fdm/fdm_solution.csv")
elif choice == "0":
print("Uscita.")
sys.exit(0)
else:
print("Scelta non valida.")
if __name__ == "__main__":
print_header()
main_menu()