PINN: allinea output a results/pinn/ e centralizza parametri in config

- visualizer.py: sostituisce animations/ con results/pinn/TIMESTAMP/,
  nomi fissi (heatmap.html, animation.html, comparison.html) come FDM
- config.py: aggiunge sezioni architettura, sampling, Adam, L-BFGS, loss weights
- model.py: costruisce HeatPINN dinamicamente da HIDDEN_SIZE/N_HIDDEN_LAYERS;
  heat_pinn_loss legge pesi W_PDE/W_IC/W_BC da config
- engine.py: tutti i parametri di training letti da config

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 14:14:11 +02:00
parent 4f050e80df
commit fbb0458f69
4 changed files with 62 additions and 32 deletions
+10 -17
View File
@@ -1,15 +1,17 @@
import os
from datetime import datetime
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import config
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ANIMATIONS_DIR = os.path.join(BASE_DIR, 'animations')
def visualize_heat_field(T_pred, x_vals, t_vals, T_fdm):
os.makedirs(ANIMATIONS_DIR, exist_ok=True)
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
out_dir = os.path.join(BASE_DIR, 'results', 'pinn', timestamp)
os.makedirs(out_dir, exist_ok=True)
# Downsample T_fdm from shape (NX_fdm, NT_fdm) to match PINN grid
nx_pred = len(x_vals)
@@ -44,9 +46,9 @@ def visualize_heat_field(T_pred, x_vals, t_vals, T_fdm):
fig_map.update_yaxes(title_text='t', row=1, col=1)
fig_map.update_layout(title_text='Heat Equation PINN vs FDM', height=450)
map_path = _next_path('heatmap', '.html')
map_path = os.path.join(out_dir, 'heatmap.html')
fig_map.write_html(map_path)
print(f"Heatmap saved → {map_path}")
print(f"Heatmap saved {map_path}")
# --- Animated profile T(x) evolving in time ---
n_frames = len(t_vals)
@@ -92,9 +94,9 @@ def visualize_heat_field(T_pred, x_vals, t_vals, T_fdm):
frames=frames,
)
anim_path = _next_path('heat_animation', '.html')
anim_path = os.path.join(out_dir, 'animation.html')
fig_anim.write_html(anim_path)
print(f"Animation saved → {anim_path}")
print(f"Animation saved {anim_path}")
# --- Time-series comparison at fixed spatial points ---
# Spatial indices for x=0, x=L/2, x=L
@@ -141,15 +143,6 @@ def visualize_heat_field(T_pred, x_vals, t_vals, T_fdm):
height=500,
)
comparison_path = _next_path('comparison', '.html')
comparison_path = os.path.join(out_dir, 'comparison.html')
fig_ts.write_html(comparison_path)
print(f"Time-series saved → {comparison_path}")
def _next_path(prefix, ext):
i = 1
while True:
path = os.path.join(ANIMATIONS_DIR, f'{prefix}_{i:03d}{ext}')
if not os.path.exists(path):
return path
i += 1
print(f"Comparison saved {comparison_path}")