solver_runtime Module

Solver execution lifecycle and I/O orchestration.

This module centralises the solver lifecycle behind the thin app/euler_1d.f90 program: CLI parsing, config loading, solver-state initialisation, adaptive-dt time loop, checkpoint/restart, live snapshots, iteration logging, and performance reporting.

Typical call sequence:

  call resolve_cli_namelist(ctx % nml_file)
  call read_config(ctx % nml_file, cfg)
  call initialize_runtime(ctx, cfg, ctx % nml_file)
  call run_solver(ctx)
  call finalize_runtime(ctx)
  call teardown_runtime(ctx)


Derived Types

type, public ::  solver_run_context_t

Aggregate context bundling all state needed for a single solver run.

Read more…

Components

Type Visibility Attributes Name Initial
type(solver_state_t), public :: state
type(timer_t), public :: t_total
type(timer_t), public :: t_io
type(timer_t), public :: t_iter
integer, public :: iter = 0
integer, public :: print_freq = 50
real(kind=wp), public :: t = 0.0_wp
real(kind=wp), public :: t_comp = 0.0_wp
character(len=512), public :: nml_file = 'input.nml'
procedure(stepper_iface), public, pointer, nopass :: stepper => null()
logical, public :: timers_started = .false.
logical, public :: run_complete = .false.
logical, public :: performance_reported = .false.

Subroutines

public subroutine resolve_cli_namelist(nml_file)

Read the namelist filename from the first command-line argument. Falls back to 'input.nml' when no argument is supplied.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(out) :: nml_file

On return: path to the namelist file.

public subroutine initialize_runtime(ctx, cfg, nml_file, is_ok, message)

Populate ctx and bring the solver to a ready-to-run state.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Context to initialise.

type(config_t), intent(in) :: cfg

Configuration loaded via read_config.

character(len=*), intent(in), optional :: nml_file

Optional namelist path stored in ctx % nml_file.

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

public subroutine run_solver(ctx)

Execute the main time-marching loop until time_stop is reached.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Solver context; ctx % t and ctx % iter are updated in place.

public subroutine run_solver_steps(ctx, max_steps, steps_taken, finished, is_ok, message)

Advance the main time loop by at most max_steps iterations.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx
integer, intent(in) :: max_steps
integer, intent(out) :: steps_taken
logical, intent(out) :: finished
logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message

public subroutine finalize_runtime(ctx)

Write the final solution to the output file and print the performance table.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Solver context (solution written from ctx % state % ub).

public subroutine report_performance_summary(ctx)

Print the end-of-run performance table once after a completed run.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Solver context (read-only except for the once-only guard flag).

public subroutine teardown_runtime(ctx)

Release all allocations held by ctx and finalise the logger. Must be the last call in the lifecycle; ctx is invalid afterwards.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Solver context to tear down.

public subroutine write_solution_file(ctx, filename, is_ok, message)

Write the current solution to a text file.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(inout) :: ctx

Solver context (solution written from ctx % state % ub).

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

Output path to overwrite.

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

private subroutine write_cell_row(io_unit, x, ub_col, gam)

Write a single row of primitive variables to io_unit in '(4ES20.12)' format. Shared by finalize_runtime and write_snapshot to avoid duplicating the conserved-to-primitive conversion.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: io_unit

Fortran I/O unit (already open for writing).

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

Cell-centre coordinate. [m]

real(kind=wp), intent(in) :: ub_col(3)
real(kind=wp), intent(in) :: gam

Ratio of specific heats γ.

public subroutine copy_current_solution(ctx, x, rho, u, p, is_ok, message)

Copy the current solution into primitive-variable arrays.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(in) :: ctx

Solver context (read-only).

real(kind=wp), intent(out) :: x(:)
real(kind=wp), intent(out) :: rho(:)
real(kind=wp), intent(out) :: u(:)
real(kind=wp), intent(out) :: p(:)
logical, intent(out), optional :: is_ok
character(len=*), intent(out), optional :: message

private subroutine log_iteration(ctx)

Log one iteration summary line (time, residual, per-iteration and elapsed wall time). The lightweight iter_s and elapsed_s fields are always populated. Called every ctx % print_freq iterations and once unconditionally after the loop.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(in) :: ctx

Solver context (read-only).

private subroutine log_performance_summary(ctx)

Print the wall-clock performance table after the run completes. Reports total time, I/O time, and the three hot-path timers (compute_resid, flux precompute, face loop) plus overall throughput. Only called when ctx % state % cfg % do_timing is .true..

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(in) :: ctx

Solver context (read-only).

private subroutine write_snapshot(ctx)

Write a live snapshot of the current solution to snapshot_file. The file is overwritten on each call. A header comment records the current iteration and time; subsequent rows are (x, ρ, u, p) via write_cell_row. Open/write failures are logged as warnings rather than fatal errors so that a snapshot glitch does not abort the run. This file path is retained for compatibility with legacy file-watching tooling; new integrations should prefer the polling session/API surface.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(in) :: ctx

Solver context (read-only).

private subroutine log_effective_config(ctx)

Log the effective (post-promotion) configuration at startup. Reads from the authoritative copy ctx % state % cfg, which may differ from the original namelist values when BC promotions have been applied (e.g. smooth_wave → periodic, woodward_colella → reflecting).

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_t), intent(in) :: ctx

Solver context (read-only).