Skip to content

Commit 3bacc8a

Browse files
authored
Add adaptive CFL and CFL checks.
2 parents 706e882 + 4eb0b66 commit 3bacc8a

8 files changed

Lines changed: 864 additions & 56 deletions

config.m

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@
8989
error('Unknown geometry type: %s. Supported types: cylinder, ellipse, rectangle, airfoil, multi', geometry_type);
9090
end
9191

92+
% Time-based simulation control (alternative to num_time_steps)
93+
config.simulation.use_end_time = false; % If true, use end_time instead of num_time_steps
94+
config.simulation.end_time = 20; % Simulation end time (when use_end_time = true)
95+
config.simulation.end_time_ci = 0.2; % Reduced end time for CI/testing
96+
97+
% Adaptive time step control
98+
config.adaptive_dt.enable = false; % Enable adaptive time step reduction
99+
config.adaptive_dt.cfl_threshold = 0.5; % Convective CFL threshold for time step reduction (lowered for stability)
100+
config.adaptive_dt.cfl_viscous_threshold = 0.5; % Viscous CFL threshold (nu*dt/h^2 < threshold)
101+
config.adaptive_dt.reduction_factor = 0.2; % Factor to reduce time step by (dt_new = dt * factor)
102+
config.adaptive_dt.min_factor = 0.001; % Minimum time step as fraction of original (dt_min = dt_0 * min_factor)
103+
config.adaptive_dt.max_reductions = 10; % Maximum number of consecutive reductions allowed
104+
config.adaptive_dt.nan_check_enable = true; % Enable NaN checking after time step reduction (stops simulation if found)
105+
92106
%% RBF-FD Algorithm Parameters
93107
% Main stencil sizes
94108
config.rbf.stencil_size_main = 35;
@@ -138,11 +152,16 @@
138152

139153
%% Logging and Debug Parameters
140154
% Master debug switch - set to true to enable all debug features
141-
debug_master = false; % Master switch for all debug features
155+
debug_master = false; % Master switch for all debug features
156+
157+
% Local CFL diagnostics
158+
config.logging.cfl_check_frequency = 1; % Run local CFL check every N steps
159+
config.logging.cfl_local_enable = true; % Enable per-node CFL checks
160+
config.logging.cfl_percentiles = [90 99]; % Percentiles to report
142161

143162
% Individual debug settings (controlled by master switch unless overridden)
144163
config.logging.enable = debug_master; % Enable debug logging
145-
config.logging.step_frequency = 3; % Print diagnostics every N steps
164+
config.logging.step_frequency = 1; % Print diagnostics every N steps
146165
config.logging.trace_substeps = debug_master; % Print substep diagnostics inside fractional step
147166
config.logging.snapshot_on_nan = debug_master; % Save snapshot if NaN detected
148167
config.logging.snapshot_dir = 'debug'; % Directory to save debug snapshots
@@ -164,11 +183,16 @@
164183
% Stability thresholds
165184
config.logging.cfl_warning_threshold = 0.8; % Warn if CFL > this value
166185
config.logging.cfl_critical_threshold = 1.5; % Critical CFL threshold
167-
config.logging.velocity_explosion_threshold = 100; % Velocity magnitude explosion threshold
168-
config.logging.pressure_explosion_threshold = 1000; % Pressure explosion threshold
186+
config.logging.cfl_stop_threshold = 0.9; % Stop simulation if CFL > this value (always active)
187+
config.logging.velocity_explosion_threshold = 100; % Velocity magnitude explosion threshold
188+
config.logging.pressure_explosion_threshold = 1000; % Pressure explosion threshold
169189
config.logging.divergence_warning_threshold = 10; % Mass conservation warning
170190
config.logging.divergence_critical_threshold = 100; % Mass conservation critical
171191
config.logging.condition_number_threshold = 1e12; % Matrix conditioning threshold
192+
config.logging.immediate_nan_check = true; % Check for NaNs immediately after each time step
193+
config.logging.comprehensive_instability_check = true; % Check for all types of instability (not just NaNs)
194+
config.logging.periodic_health_check = false; % Periodic health checks during simulation
195+
config.logging.health_check_frequency = 10; % Health check every N steps
172196

173197
% Environment override for enabling logging
174198
dbg_env = getenv('DEBUG');

debug/snapshot_step_00021.mat

-15.5 MB
Binary file not shown.

debug/snapshot_step_00026.mat

-22.9 MB
Binary file not shown.

0 commit comments

Comments
 (0)