dalesteam / dales

Dutch Atmospheric Large-Eddy Simulation model
GNU General Public License v3.0
50 stars 49 forks source link

dtmax < 0.1 leads to crash #79

Closed fjansson closed 1 year ago

fjansson commented 1 year ago

Specifying dtmax < 0.1 causes dt = 0 here: https://github.com/dalesteam/dales/blob/1d63af5d6fefbe2915be67e3be1e094f0634acb3/src/modstartup.f90#L424

Then dt = 0 leads to rk3coef = 0, which causes a division by 0. If that's not caught, the model crashes with the traditional segfault in thermodynamics. Note: dt is an integer number of milliseconds, rdt is a floating-point number of seconds. The time calculation is done in milliseconds (timee) which is then converted to floating point (rtimee).

Proposed fix In modstartup.f90, replace

 rdt = dtmax / 100.
 dt  = floor(rdt/tres) 

by

 rdt = dtmax / 100.
 dt  = max(floor(rdt/tres), 1) 

ensuring dt >= 1 i.e. 1 ms.

Bug found by Ho Yi Lydia Mak.