Legendre vs Chebyshev Basis Comparison Plots#

Compare the two spectral basis implementations side-by-side.

Setup#

from utils import get_project_root, LDCPlotter, GhiaValidator, plot_validation

# Configuration
Re = 100
N = 25  # Grid size (number of nodes)
Re_str = f"Re{int(Re)}"

project_root = get_project_root()
data_dir = project_root / "data" / "Spectral-Solver"
fig_dir = project_root / "figures" / "Spectral-Solver"
fig_dir.mkdir(parents=True, exist_ok=True)

# File paths
chebyshev_path = data_dir / "Chebyshev" / f"LDC_N{N}_{Re_str}.h5"

if not chebyshev_path.exists():
    raise FileNotFoundError(f"Chebyshev solution not found: {chebyshev_path}")

# Load Chebyshev solution (Legendre diverged with current settings)
plotter_cheb = LDCPlotter(chebyshev_path)
validator_cheb = GhiaValidator(chebyshev_path, Re=Re, method_label="Chebyshev")

print(f"Loaded solutions for Re={Re}:")
print(f"  Chebyshev: {chebyshev_path.name}")
Loaded solutions for Re=100:
  Chebyshev: LDC_N25_Re100.h5

Ghia Validation#

Ghia benchmark validation for Chebyshev spectral solver

plot_validation(
    validator_cheb, output_path=fig_dir / f"comparison_ghia_validation_{Re_str}.pdf"
)
print("  ✓ Ghia validation saved")
Ghia Benchmark Validation (Re = 100), U velocity (vertical centerline), V velocity (horizontal centerline)
Validation plot saved to: /home/runner/work/02689-AdvancedNumericalAlgorithmP3/02689-AdvancedNumericalAlgorithmP3/figures/Spectral-Solver/comparison_ghia_validation_Re100.pdf
  ✓ Ghia validation saved

Convergence History#

Chebyshev convergence behavior

fig_dir_cheb = fig_dir / "Chebyshev"
fig_dir_cheb.mkdir(parents=True, exist_ok=True)

plotter_cheb.plot_convergence(output_path=fig_dir_cheb / f"convergence_{Re_str}.pdf")
print("  ✓ Chebyshev convergence saved")
Convergence History (Re = 100)
Convergence plot saved to: /home/runner/work/02689-AdvancedNumericalAlgorithmP3/02689-AdvancedNumericalAlgorithmP3/figures/Spectral-Solver/Chebyshev/convergence_Re100.pdf
  ✓ Chebyshev convergence saved

Chebyshev Field Plots#

Solution fields and streamlines

plotter_cheb.plot_fields(output_path=fig_dir_cheb / f"fields_{Re_str}.pdf")
print("  ✓ Chebyshev fields saved")

plotter_cheb.plot_streamlines(output_path=fig_dir_cheb / f"streamlines_{Re_str}.pdf")
print("  ✓ Chebyshev streamlines saved")
  • Solution Fields (Re = 100), Pressure, U velocity, V velocity
  • Velocity Magnitude with Streamlines (Re = 100)
Fields plot saved to: /home/runner/work/02689-AdvancedNumericalAlgorithmP3/02689-AdvancedNumericalAlgorithmP3/figures/Spectral-Solver/Chebyshev/fields_Re100.pdf
  ✓ Chebyshev fields saved
Streamlines plot saved to: /home/runner/work/02689-AdvancedNumericalAlgorithmP3/02689-AdvancedNumericalAlgorithmP3/figures/Spectral-Solver/Chebyshev/streamlines_Re100.pdf
  ✓ Chebyshev streamlines saved

Total running time of the script: (0 minutes 2.912 seconds)

Gallery generated by Sphinx-Gallery