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 | |||
|---|---|---|---|---|---|---|---|
| real(kind=wp), | public | :: | t | = | 0.0_wp | ||
| real(kind=wp), | public | :: | t_comp | = | 0.0_wp | ||
| integer, | public | :: | iter | = | 0 | ||
| logical, | public | :: | run_complete | = | .false. | ||
| 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 | :: | print_freq | = | 50 | ||
| character(len=512), | public | :: | nml_file | = | 'input.nml' | ||
| procedure(stepper_iface), | public, | pointer, nopass | :: | stepper | => | null() | |
| logical, | public | :: | timers_started | = | .false. | ||
| logical, | public | :: | performance_reported | = | .false. |
| procedure, public :: observe => hook_noop | |
| procedure, public :: raw_dt => ctx1d_raw_dt | |
| procedure, public :: set_dt => ctx1d_set_dt | |
| procedure, public :: step => ctx1d_step | |
| procedure, public :: write_checkpoint_now => ctx1d_checkpoint | |
| procedure, public :: log_iteration_line => ctx1d_log_line | |
| procedure, public :: begin_work => ctx1d_begin_work | |
| procedure, public :: write_snapshot_now => ctx1d_snapshot | |
| procedure, public :: finish_work => ctx1d_finish_work | |
| procedure, public :: progress_residual => ctx1d_progress_residual |
1D raw_dt hook: recompute state % dt from the CFL condition when
CFL-driven, then return the stored dt (Q2c; body lifted verbatim from
the pre-engine run_solver_steps loop).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D progress_residual hook: state residual norm for progress ticks.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
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. |
Parse the worker's CLI: --cortex-socket=URI plus a positional namelist path. Either may be absent. or empty.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(out) | :: | nml_file |
On return: namelist path (defaults to 'input.nml'). |
||
| character(len=*), | intent(out) | :: | cortex_uri |
On return: namelist path (defaults to 'input.nml'). On return: URI string if --cortex-socket was given, |
||
| logical, | intent(out) | :: | attached |
On return: .true. iff --cortex-socket was given. |
Dispatch one parsed CLI token onto the worker-CLI state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | arg |
The argument buffer as filled by |
||
| integer, | intent(in) | :: | arg_len |
The argument's reported TRUE length (may exceed |
||
| character(len=*), | intent(inout) | :: | nml_file |
Updated in place with a positional namelist path. |
||
| character(len=*), | intent(inout) | :: | cortex_uri |
Updated in place with a positional namelist path.
Updated in place with a |
||
| logical, | intent(inout) | :: | attached |
Set |
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; |
||
| procedure(progress_callback_i), | optional | :: | on_progress | |||
| integer, | intent(in), | optional | :: | every_steps | ||
| real(kind=wp), | intent(in), | optional | :: | every_seconds |
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 | ||
| procedure(progress_callback_i), | optional | :: | on_progress | |||
| integer, | intent(in), | optional | :: | every_steps | ||
| real(kind=wp), | intent(in), | optional | :: | every_seconds |
1D set_dt hook: store the engine's clipped dt.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx | |||
| real(kind=wp), | intent(in) | :: | dt |
1D step hook: advance one step, wrapped in the per-iteration timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D write_checkpoint_now hook: write the checkpoint and own the
failure policy.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D log_iteration_line hook: one iteration summary line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D begin_work hook: start total wall-time accounting only when real
work is about to begin, so a zero-step polling call does not consume
elapsed time.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D write_snapshot_now hook: live snapshot side channel.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
1D finish_work hook: stop the total timer once the run finishes.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
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 |
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 | ||
|---|---|---|---|---|---|---|
| class(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) in
'(4ES20.12)' format. 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 | ||
|---|---|---|---|---|---|---|
| class(solver_run_context_t), | intent(inout) | :: | ctx |
Solver context (gather_buf is updated; all other fields are 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). |