edoddridge / aronnax

An idealised isopycnal model that can be run either with n+1/2 layers, or with n layers and variable bathymetry.
http://aronnax.readthedocs.io/en/latest/
MIT License
24 stars 6 forks source link

Style for invalid value checking #11

Open axch opened 7 years ago

axch commented 7 years ago

Self-checking for infinities as well as NaN seems like a reasonable sanity precaution to take, and maintain in the production system.

edoddridge commented 7 years ago

I agree. I'd put this fairly low down the priority list though - I've not had a simulation in which the model was able to carry around infinities without producing NaN values very quickly. The way that these bad values propagate quickly from one variable to the others is the reason why the code only checks for NaNs in the h field. https://github.com/edoddridge/MIM/blob/master/MIM.f90#L760

It is also highly likely that there is a more efficient way of testing for bad values than the one currently implemented. This subroutine is from my very early days with Fortran.

axch commented 7 years ago

There is a second question here, prompted by the observation that the code that writes out the average value dumps checks the h array for NaNs (again), rather than hav. The question is, where do we want to be on the spectrum between catching invalid values early vs spending little effort on validity checks?

Reasonable choices include:

edoddridge commented 7 years ago

The options described above could be tagged to the debug_level parameter: as the debug_level is increased, the model becomes stricter about checking for invalid values. This would obviate any speed concerns associated with regularly checking arrays, while still providing the ability to detect the first NaN, if the user desires that behaviour.