solver_runtime_2d Module

Mirrors solver_runtime (1D) for the coexisting euler_2d solver: a run context bundling state + time/iteration bookkeeping, a bounded advance-N step loop extracted 1:1 from run_euler_2d's original time loop, a global L2 residual reduction (resid_glob, the 2D analogue of the 1D state % resid_glob), and a result-write wrapper. euler_driver_2d and (phase P2) the dim-aware solver_session both drive this runtime, so the CLI and the attached IPC worker observe the SAME numerical run.

Bit-for-bit contract: init_run_context_2d + run_solver_steps_2d + write_solution_file_2d reproduce the pre-P1 run_euler_2d behaviour — same setup order, same log lines, same checkpoint/print cadence. Time accumulation is Kahan-compensated since Q2b (authorized behavior change, spec 2026-07-10-q2-2d-machinery-alignment-design.md §6), matching the 1D runtime. The only other additions are the per-step residual reduction (pure observation, no state change) and the polling boundary. There are deliberately NO snapshot files here (spec 2026-07-03 §2.3).



Derived Types

type, public, extends(run_loop_ctx_t) ::  solver_run_context_2d_t

Aggregate context for one 2D solver run (2D analogue of solver_run_context_t). Populated by init_run_context_2d; callers set nml_file BEFORE init (it feeds the config: loaded log line). t, t_comp, iter, and run_complete are inherited from run_loop_ctx_t (Q2c) under their historical names.

Components

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_2d_t), public :: state
real(kind=wp), public :: resid_glob = 0.0_wp

Global L2 residual norm of the last-substage residual, reduced across ranks each step (2D analogue of the 1D state % resid_glob; exposed through the P2 session as the ADVANCE/GET_PROGRESS residual field).

character(len=512), public :: nml_file = 'input.nml'
procedure(stepper_2d_iface), public, pointer, nopass :: stepper => null()

Type-Bound Procedures

procedure, public :: begin_work => hook_noop
procedure, public :: write_snapshot_now => hook_noop
procedure, public :: finish_work => hook_noop
procedure, public :: progress_residual => hook_zero

(it is referenced inside the on_progress argument list).

procedure, public :: raw_dt => ctx2d_raw_dt
procedure, public :: set_dt => ctx2d_set_dt
procedure, public :: step => ctx2d_step
procedure, public :: write_checkpoint_now => ctx2d_checkpoint
procedure, public :: log_iteration_line => ctx2d_log_line
procedure, public :: observe => ctx2d_observe

Functions

private function ctx2d_raw_dt(ctx) result(dt)

2D raw_dt hook: recompute and store state % dt from the adaptive CFL condition, then return it (Q2c; body lifted verbatim from the pre-engine run_solver_steps_2d loop).

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

Return Value real(kind=wp)

public pure function global_point_count_2d(ctx) result(n)

Whole-domain point count (FVM cells / FDM nodes), identical on all ranks.

Arguments

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

Return Value integer


Subroutines

public subroutine init_run_context_2d(ctx, cfg, status, message)

Bring a 2D run context to ready-to-step state.

Read more…

Arguments

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

Context to initialise (ctx % nml_file read for logging).

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

Validated 2D configuration.

integer, intent(out) :: status

0 on success, 1 on failure (logger already finalised).

character(len=*), intent(out) :: message

Human-readable error when status /= 0.

public subroutine run_solver_steps_2d(ctx, max_steps, steps_taken, finished, status, message)

Advance the 2D time loop by at most max_steps iterations.

Read more…

Arguments

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

private subroutine ctx2d_set_dt(ctx, dt)

2D set_dt hook: store the engine's time_stop-clipped dt.

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx
real(kind=wp), intent(in) :: dt

private subroutine ctx2d_step(ctx)

2D step hook: advance one step via the bound integrator.

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

private subroutine ctx2d_checkpoint(ctx)

2D write_checkpoint_now hook: write the checkpoint and own the failure policy.

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

private subroutine ctx2d_log_line(ctx)

2D log_iteration_line hook: one iteration summary line.

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

private subroutine ctx2d_observe(ctx)

2D observe hook: reduce the global L2 residual norm (collective, observation only — no state change).

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

private subroutine compute_resid_glob_2d(ctx)

Reduce the global L2 norm of the last-substage residual into ctx % resid_glob (2D analogue of the 1D compute_resid_glob): resid_glob = sqrt( par_sum(sum resid^2) / (nx_g*ny_g * neq2d) ) The denominator uses GLOBAL counts so the norm is decomposition- independent (np=1 == np=2 up to summation reordering, ~1e-13). Collective: every rank must call. Dummy widened type -> class (Q2c): called from the ctx2d_observe hook, whose own dummy is class(solver_run_context_2d_t) per the abstract run_loop_ctx_t interface, so the actual argument here is polymorphic and the callee must accept it as such.

Arguments

Type IntentOptional Attributes Name
class(solver_run_context_2d_t), intent(inout) :: ctx

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

Gather to root and write the standard 6-column x y rho u v p result (plus any tec/plt/vtk formats the config requests). Collective.

Arguments

Type IntentOptional Attributes Name
type(solver_run_context_2d_t), intent(inout) :: ctx
character(len=*), intent(in) :: filename
logical, intent(out) :: is_ok
character(len=*), intent(out) :: message

public subroutine teardown_run_context_2d(ctx)

Release runtime handles and finalise the logger. The state's allocatable arrays are released by intrinsic assignment when the owner resets the context (ctx = solver_run_context_2d_t()), mirroring the 1D session.

Arguments

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