Possible use of uninitialised data in final call to diagnostics

Issue #247 new
David Dickinson created an issue

We call our diagnostics routines after exiting the main time advance loop. In a nonlinear simulation we might choose to exit this main loop whilst not initialised to the init%full level, meaning not all arrays may be allocated. This can lead to problems in the diagnostics calls.

For a concrete example

  1. Call timeadv --> sets reset = true as the cfl limit is violated
  2. Enter reset_time_step → sets the init level to override_timestep
  3. We determine the new time step. If this is less than dt_min we set exit = .true. and immediately return to the main loop
  4. As exit is true we exit the main loop
  5. We call diagnostics

Several diagnostics will want to use arrays which are not allocated at the override_timestep level. For example diagnostics_fluxes wants to form g_work = gnew * vpa**2 * 2 * aj0, but vpa is deallocated when going from full to override_timestep so is not available for this diagnostic.

There are several solutions:

  1. Don’t call the final diagnostics if exit is true. This is sensible here but for other exit reasons (e.g. out of time) we probably do want to call the diagnostics.
  2. Make sure reset_time_step always ends with setting the init_level to full (or at least something close to full). This leaves things in an expected state but can correspond to a large amount of work (e.g. initialising the response matrices) which isn’t used.
  3. Restructure the initialisation to avoid this, for example vpa is actually independent of dt whilst vpar isn't. These arrays are currently initialised in the same routine and hence this routine must be called after we override the time step. Splitting the initialisation would avoid this. Of course this only addresses the specific issue raised here.

None of these solutions are ideal.

Comments (1)

  1. Log in to comment