feat: aggiunge salvataggio CSV soluzione FDM in results/fdm/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+9
-2
@@ -3,7 +3,7 @@ import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from fdm.solver import solve
|
||||
from fdm.solver import solve, save_csv
|
||||
from fdm.visualizer import visualize_fdm
|
||||
|
||||
|
||||
@@ -26,10 +26,11 @@ def 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-2): ").strip()
|
||||
choice = input("Select an option (0-3): ").strip()
|
||||
|
||||
if choice == "1":
|
||||
T, x_vals, t_vals = solve()
|
||||
@@ -42,6 +43,12 @@ def main_menu():
|
||||
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)
|
||||
|
||||
@@ -14,6 +14,7 @@ Returns T_matrix of shape (NX, NT).
|
||||
import sys
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import config
|
||||
@@ -85,3 +86,16 @@ def solve():
|
||||
T_matrix[:, n + 1] = T_cur
|
||||
|
||||
return T_matrix, x_vals, t_vals
|
||||
|
||||
|
||||
def save_csv(T_matrix, x_vals, t_vals, path: str) -> None:
|
||||
"""Save FDM solution to CSV with columns: x, t, T."""
|
||||
xs, ts = np.meshgrid(x_vals, t_vals, indexing="ij")
|
||||
df = pd.DataFrame({
|
||||
"x": xs.ravel(),
|
||||
"t": ts.ravel(),
|
||||
"T": T_matrix.ravel(),
|
||||
})
|
||||
os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True)
|
||||
df.to_csv(path, index=False)
|
||||
print(f"Salvato: {path} ({len(df)} righe)")
|
||||
|
||||
Reference in New Issue
Block a user