checkpoint Module

Checkpoints are Fortran unformatted (stream) binary files that capture everything needed to resume a run exactly:

  • A magic integer (42) and version (1) for format identification.
  • Scalars: iter, t, n_pt, neq, dt.
  • The conserved-variable array ub(neq, n_pt).
  • An optional BDF2 previous-step array bdf2_ub_prev(neq, n_pt), preceded by a presence flag (integer 1 = present, 0 = absent).

File naming: <base>_NNNNNN.bin where NNNNNN is the zero-padded iteration number. A companion text file latest_checkpoint (written alongside) records the path of the most recent checkpoint so that restart drivers need not track the iteration themselves.

Typical usage in the driver: @code use checkpoint, only: write_checkpoint, read_checkpoint ! --- writing --- call write_checkpoint(state, cfg%checkpoint_file, t, iter) ! --- reading --- call read_checkpoint(state, cfg%restart_file, t, iter) @endcode



Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: CKPT_MAGIC = 42
integer, private, parameter :: CKPT_VERSION = 1

Functions

private function resolve_latest(fname, is_ok, message) result(actual)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fname
logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message

Return Value character(len=512)


Subroutines

public subroutine write_checkpoint(state, base, t, iter, is_ok, message)

Write a checkpoint file for the current solver state.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state

Current solver state (must have ub allocated).

character(len=*), intent(in) :: base

Base name (e.g. 'checkpoint'); file = base_NNNNNN.bin.

real(kind=wp), intent(in) :: t

Current simulation time [s].

integer, intent(in) :: iter

Current iteration number.

logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message

public subroutine read_checkpoint(state, fname, t, iter, is_ok, message)

Read a checkpoint file and restore solver state.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state

Solver state with ub already allocated (from setup_solver).

character(len=*), intent(in) :: fname

Path to the checkpoint file (or 'latest_checkpoint').

real(kind=wp), intent(out) :: t

Restored simulation time [s].

integer, intent(out) :: iter

Restored iteration count.

logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message

private subroutine update_latest(fname, is_ok, message)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fname
logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message