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)
Aggregate context bundling all state needed for a single solver run.
| 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. |
Read the namelist filename from the first command-line argument.
Falls back to 'input.nml' when no argument is supplied.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(out) | :: | nml_file |
On return: path to the namelist file. |
Populate ctx and bring the solver to a ready-to-run state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Context to initialise. |
||
| type(config_t), | intent(in) | :: | cfg |
Configuration loaded via |
||
| character(len=*), | intent(in), | optional | :: | nml_file |
Optional namelist path stored in |
|
| logical, | intent(out), | optional | :: | is_ok | ||
| character(len=*), | intent(out), | optional | :: | message |
Execute the main time-marching loop until time_stop is reached.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context; |
Advance the main time loop by at most max_steps iterations.
| Type | Intent | Optional | 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 |
Write the final solution to the output file and print the performance table.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context (solution written from |
Print the end-of-run performance table once after a completed run.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context (read-only except for the once-only guard flag). |
Release all allocations held by ctx and finalise the logger.
Must be the last call in the lifecycle; ctx is invalid afterwards.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context to tear down. |
Write the current solution to a text file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context (solution written from |
||
| character(len=*), | intent(in) | :: | filename |
Output path to overwrite. |
||
| logical, | intent(out), | optional | :: | is_ok | ||
| character(len=*), | intent(out), | optional | :: | message |
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.
| Type | Intent | Optional | 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 γ. |
Copy the current solution into primitive-variable arrays.
| Type | Intent | Optional | 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 |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(in) | :: | ctx |
Solver context (read-only). |
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..
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(in) | :: | ctx |
Solver context (read-only). |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(in) | :: | ctx |
Solver context (read-only). |
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).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_run_context_t), | intent(in) | :: | ctx |
Solver context (read-only). |