Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ uv run mlflow ui
# https://kni.dk/mlflow-ana-p3/
```

## Hyperparameter Optimization

Optimize `corner_smoothing` using [Optuna](https://optuna.org/) + Hydra:

```bash
# Minimize L2 error vs FV reference (default objective)
uv run python main.py -m +experiment/optimization=corner_smoothing \
'solver.corner_smoothing=interval(0.02,0.35)' Re=1000 N=30

# Minimize vortex error vs Botella & Peyret reference
uv run python main.py -m +experiment/optimization=corner_smoothing \
'solver.corner_smoothing=interval(0.02,0.35)' Re=1000 N=30 \
optuna.objective=botella_vortex

# Customize trials and parallelism
uv run python main.py -m +experiment/optimization=corner_smoothing \
'solver.corner_smoothing=interval(0.02,0.35)' Re=1000 N=30 \
hydra.sweeper.n_trials=20 hydra.sweeper.n_jobs=8
```

View results in MLflow under `Optuna-CornerSmoothing-{objective}`. See [docs/optuna_optimization.md](docs/optuna_optimization.md) for details.

## References

- [High-Re solutions for incompressible flow (Ghia et al.)](https://www.sciencedirect.com/science/article/pii/0021999182900584)
Expand Down
2 changes: 1 addition & 1 deletion conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ N: 32

# Solver control
tolerance: 1.0e-6
max_iterations: 500000
max_iterations: 10000000

# Experiment naming
experiment_name: LDC-Dev
Expand Down
6 changes: 2 additions & 4 deletions conf/experiment/benchmarking/timings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defaults:

# MLflow experiment
experiment_name: LDC-Benchmarking
sweep_name: multigrid-comparison-Re${Re}
sweep_name: Benchmarking

# Benchmarking parameters
Re: 100
Expand All @@ -21,6 +21,4 @@ hydra:
# Sweep over spectral solver variants
# sg: Single Grid (no multigrid)
# fsg: Full Single Grid
# vmg: V-cycle MultiGrid
# fmg: Full MultiGrid
solver: spectral/sg,spectral/fsg,spectral/vmg,spectral/fmg
solver: spectral/sg,spectral/fsg
26 changes: 0 additions & 26 deletions conf/experiment/fv_validation.yaml

This file was deleted.

57 changes: 57 additions & 0 deletions conf/experiment/optimization/corner_smoothing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# @package _global_
#
# Optuna optimization of corner_smoothing parameter
#
# Supported objectives (override with optuna.objective=...):
# - fv_l2_error: Minimize L2 error vs FV reference (default)
# - botella_vortex: Minimize vortex metric error vs Botella & Peyret
#
# Note: Multi-objective optimization is not supported by hydra-optuna-sweeper 1.x
#
# Usage:
# # FV L2 error (default)
# uv run python main.py -m +experiment/optimization=corner_smoothing \
# 'solver.corner_smoothing=interval(0.02,0.35)'
#
# # Botella vortex metrics
# uv run python main.py -m +experiment/optimization=corner_smoothing \
# 'solver.corner_smoothing=interval(0.02,0.35)' optuna.objective=botella_vortex
#
# # Custom Re/N
# uv run python main.py -m +experiment/optimization=corner_smoothing \
# 'solver.corner_smoothing=interval(0.02,0.35)' Re=1000 N=32

defaults:
- override /solver: spectral/fsg
- override /hydra/sweeper: optuna_corner

# Experiment name (dynamically includes objective type)
experiment_name: Optuna-CornerSmoothing
sweep_name: corner-smoothing-${optuna.objective}
# Grid and physics
N: 30
Re: 1000

# Solver settings (strict convergence)
# Note: Early NaN/Inf detection exits diverging runs quickly
tolerance: 1.0e-6
max_iterations: 500000

# Validation against non-regularized FV (true LDC solution)
validation:
reference_dir: data/validation/fv

# Optimization settings
# Override objective with: optuna.objective=botella_vortex
optuna:
objective: fv_l2_error # Options: fv_l2_error, botella_vortex

# Optuna sweeper settings
hydra:
sweeper:
study_name: corner_smoothing_${optuna.objective}_Re${Re}_N${N}
n_trials: 15
n_jobs: 5
params:
N: 30, 40, 50
solver.corner_smoothing: interval(0.01, 0.10)
21 changes: 0 additions & 21 deletions conf/experiment/validation/convergence/fv-regu-1000.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions conf/experiment/validation/convergence/fv-regu-400.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions conf/experiment/validation/convergence/spectral.yaml

This file was deleted.

9 changes: 5 additions & 4 deletions conf/experiment/validation/ghia/fv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ defaults:
- override /solver: fv

# MLflow experiment
experiment_name: LDC-Validation
sweep_name: ghia-Re${Re}
experiment_name: LDC-GHIA-PLOTS

sweep_name: ghia-plots

hydra:
sweeper:
params:
# Sweep over FV grid sizes
N: 64
Re: 100
N: 128
Re: 1000
12 changes: 8 additions & 4 deletions conf/experiment/validation/ghia/spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ defaults:
- override /solver: spectral/sg

# MLflow experiment
experiment_name: LDC-Validation
sweep_name: ghia-HPC
experiment_name: LDC-GHIA-PLOTS
sweep_name: ghia-plots

solver:
corner_treatment: smoothing
corner_smoothing: 0.15 # smoothing width (fraction of domain) for smoothing method

# Validation parameters

Expand All @@ -16,5 +20,5 @@ hydra:
params:
# Sweep over spectral solver types
solver: spectral/fsg #,spectral/vmg #, spectral/vmg
Re: 400, 1000
N: 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 46, 50, 56, 60, 64, 68, 74, 82, 86, 90
Re: 1000
N: 16, 20, 32
17 changes: 0 additions & 17 deletions conf/experiment/validation/hpc-fv.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ defaults:
- override /validation: fv-regu

# MLflow experiment
experiment_name: LDC-Convergence
sweep_name: regu-Re400
experiment_name: LDC-Saad-Regu
sweep_name: regu-Re1000

# Use Saad/polynomial corner treatment for regularized problem
solver:
Expand All @@ -17,5 +17,5 @@ solver:
hydra:
sweeper:
params:
Re: 400
N: 12, 14, 16, 18, 24, 32, 40, 48, 56, 64
Re: 1000
N: 16, 32, 64, 128
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# @package _global_
# Convergence test - Spectral solver with Saad regularization at Re=1000
# Convergence test - Spectral solver with Saad regularization at Re=400
# Sweep over N values with polynomial corner treatment

defaults:
- override /solver: spectral/fsg
- override /validation: fv-regu
- override /validation: fv

# MLflow experiment
experiment_name: LDC-Convergence
sweep_name: regu-Re1000-b
experiment_name: LDC-Saad
sweep_name: Re1000

# Use Saad/polynomial corner treatment for regularized problem
solver:
corner_treatment: saad
corner_smoothing: 0.15 # smoothing width (fraction of domain) for smoothing method

hydra:
sweeper:
params:
Re: 1000
N: 26, 28, 32, 36, 40, 44, 48, 64, 80, 96, 112, 128
N: 16, 32, 64, 128
28 changes: 28 additions & 0 deletions conf/hydra/sweeper/optuna_corner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @package hydra.sweeper
#
# Optuna Sweeper Configuration for corner_smoothing optimization
# Usage: python main.py -m hydra/sweeper=optuna_corner
#
# For parallel execution, set n_jobs > 1 (requires storage to be set)
# Example: hydra.sweeper.n_jobs=4 hydra.sweeper.storage="sqlite:///optuna.db"

_target_: hydra_plugins.hydra_optuna_sweeper.optuna_sweeper.OptunaSweeper

defaults:
- sampler: tpe

# Optimization direction (minimize L2 error)
direction: minimize

# Study configuration
study_name: corner_smoothing_optimization
storage: null # Set to "sqlite:///optuna.db" for parallel execution

# Number of trials and parallel jobs
n_trials: 15
n_jobs: 1 # Set > 1 for parallel trials (requires storage)

# Required fields
search_space: null
custom_search_space: null
params: null
2 changes: 1 addition & 1 deletion conf/solver/spectral/fsg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name: spectral_fsg

# FSG Multigrid settings
multigrid: fsg
n_levels: 3
n_levels: 2
coarse_tolerance_factor: 1.0
prolongation_method: fft
restriction_method: fft
2 changes: 1 addition & 1 deletion conf/solver/spectral/sg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ max_iterations: ${max_iterations}

# Spectral-specific parameters
basis_type: chebyshev # "chebyshev" or "legendre"
CFL: 2.0
CFL: 1.5
beta_squared: 5.0 # artificial compressibility parameter

# Corner singularity treatment
Expand Down
14 changes: 14 additions & 0 deletions data/validation/botella/botella_Re1000_vortex.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Botella & Peyret (1998) - Benchmark spectral solution for lid-driven cavity
# Reference: J. Comp. Phys. 179, 439-468 (2002)
# Primary and secondary vortex characteristics at Re=1000 with regularized lid velocity
# N=160 polynomial order (highest resolution benchmark)
#
# Primary vortex (PV): |psi| = magnitude of streamfunction at vortex center
# BL (bottom-left): secondary vortex in bottom-left corner
# BR (bottom-right): secondary vortex in bottom-right corner
#
# Note: psi values are absolute magnitudes (|ψ|), omega values are absolute magnitudes (|ω|)
# Sign conventions vary between papers; we compare magnitudes.
#
Re,psi_primary,omega_primary,x_primary,y_primary,psi_BL,omega_BL,x_BL,y_BL,psi_BR,omega_BR,x_BR,y_BR
1000,0.1189366,2.067753,0.4692,0.5652,2.3072e-4,1.109789,0.1360,0.1118,1.7297e-3,1.112030,0.8640,0.1118
11 changes: 11 additions & 0 deletions data/validation/botella/botella_Re100_vortex.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Botella & Peyret (1998) - Benchmark spectral solution for lid-driven cavity
# Reference: J. Comp. Phys. 179, 439-468 (2002) - Table II
# Primary and secondary vortex characteristics at Re=100 with regularized lid velocity
# N=128 polynomial order
#
# Primary vortex (PV): global minimum of streamfunction
# BR (bottom-right): secondary vortex in bottom-right corner
# BL (bottom-left): secondary vortex in bottom-left corner (very weak at Re=100)
#
Re,psi_min,psi_min_x,psi_min_y,omega_center,psi_BR,psi_BR_x,psi_BR_y,psi_BL,psi_BL_x,psi_BL_y
100,-0.1034339,0.6188,0.7344,3.166577,1.4235e-8,0.9453,0.0625,0.0,0.0,0.0
11 changes: 11 additions & 0 deletions data/validation/botella/botella_Re400_vortex.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Botella & Peyret (1998) - Benchmark spectral solution for lid-driven cavity
# Reference: J. Comp. Phys. 179, 439-468 (2002) - Table V
# Primary and secondary vortex characteristics at Re=400 with regularized lid velocity
# N=128 polynomial order
#
# Primary vortex (PV): global minimum of streamfunction
# BR (bottom-right): secondary vortex in bottom-right corner
# BL (bottom-left): secondary vortex in bottom-left corner
#
Re,psi_min,psi_min_x,psi_min_y,omega_center,psi_BR,psi_BR_x,psi_BR_y,psi_BL,psi_BL_x,psi_BL_y
400,-0.1139600,0.5547,0.6055,2.295353,6.4157e-7,0.8906,0.1250,5.1567e-6,0.0508,0.0469
Loading
Loading