Skip to content

adam_realm_object ​

ADAM, realm class definition — common per-realm state and orchestrator contract.

A realm is the unit the forest_object orchestrator tends. The name is the crasi of two aspects this type entails simultaneously:

  1. A physical-numerical model: the PDE system, numerics configuration, time integrator, boundary conditions, etc. (math layer).
  2. A spatial region modelization: the grid, the AMR Morton tree, the field data, the communication maps (where layer).

A realm has both laws (1) and borders (2). Neither name equation_object (math-only) nor subdomain_object (region-only) captured both aspects — hence realm_object, evoking a bounded territory governed by its own rules.

Consumer apps (PRISM, NASTO, CHASE, ...) extend realm_object to define their specific PDE family (prism_common_object extends realm_object, etc.). Each extended type adds app-private data and overrides the orchestrator contract TBPs.

The orchestrator contract is the set of TBPs carrying the _forest suffix. These are the methods forest_object may call on a realm; grep "_forest" across the codebase reveals the entire orchestrator contract surface. Three architectural rules govern these TBPs:

  • O1 — signature uses only ADAM-lib-visible types (intrinsic kinds plus class(realm_object), grid_object, etc.). Apps override the implementation; signatures are sacred.
  • O2 — app-specific dispatch (which integrator, which physics) lives in self%'s components, not in orchestrator-supplied arguments.
  • O3 — q is never public on realm_object. Halo exchange between realms goes through realm-side TBPs that operate on q internally; the orchestrator schedules but never touches q.

Source: src/lib/common/adam_realm_object.F90

Dependencies

Contents ​

Derived Types ​

realm_object ​

Realm system class definition, common data to all backends and applications.

@NOTE: the orchestrator contract methods carrying the _forest suffix are the surface forest_object may call on a realm. Default implementations here error-stop with a "not overridden" message; each consumer app must override.

Inheritance

Components

NameTypeAttributesDescription
iotype(io_object)IO handler.
amrtype(amr_object)AMR marker handler.
slicestype(slices_object)Slices handler.
flailtype(flail_object)FLAIL, the elliptic solver library (issue #84).
wenotype(weno_object)WENO reconstructor.
with_wenologicalRead [weno] and initialize weno (the app clears it when unused, #80 P5).
with_fdvlogicalRead [fdv] and bind the FD/FV operators (cleared when unused, #80 P5).
ibtype(ib_object)Immersed boundary.
tstype(stepper_object)Time integrator on SELAH (stepper_object, #132).
selah_layoutinteger(kind=I4P)Layout of the fields ts integrates (the FNL apps set LAYOUT_V_LAST, their (b, i, j, k, v) device fields).
selah_partitionsinteger(kind=I4P)The variables (first, last) of the two partitions of a splitting scheme (PRISM's Yoshida: B then D); 0 for none.
adamtype(adam_object)ADAM, grid + tree + field + maps orchestrator.
fdv_schemecharacter(len=:)allocatableFDV scheme, fd/fv.
fdv_orderinteger(kind=I4P)Order of finite difference/volume schemes, general order.
fdv_half_stencilinteger(kind=I4P)Half stencil length of finite difference/volume schemes.
fdv_half_stencilsinteger(kind=I4P)Half stencil length of fdv schemes for each derivative up to 6.
ngcinteger(kind=I4P)pointerNumber of ghost cells.
niinteger(kind=I4P)pointerNumber of cells in i direction.
njinteger(kind=I4P)pointerNumber of cells in j direction.
nkinteger(kind=I4P)pointerNumber of cells in k direction.
nbinteger(kind=I4P)pointerTotal blocks number for MPI.
blocks_numberinteger(kind=I4P)pointerActual blocks number.
nvinteger(kind=I4P)pointerNumber of variables in q vector. 1-based position of this realm in the forest's realm(:) array, or 0 in the N=1 single-realm legacy path (where the program driver calls realm%initialize_forest directly, bypassing the forest orchestrator).
realm_indexinteger(kind=I4P)
realms_numberinteger(kind=I4P)Realms in the forest (set by initialize_forest, #80 P3). Inter-realm seam coupling — currently-published stage buffer key.
stage_activeinteger(kind=I4P)A copy of the forest's flux register (its faces and lookup, the accumulators unused), refreshed by the forest each time it builds the register (init, regrid). A realm can accumulate one residual evaluation's seam fluxes into it for a diagnostic without touching the forest's step accumulators (FLUME's D_flux, issue #68 A2).
flux_register_copytype(flux_register_object)Procedure pointer TBPs for FDV operators (set at initialization by backend).
compute_block_total_variationprocedure(compute_block_total_variation_interface)pass(self), pointerCompute TV.
compute_curlprocedure(compute_curl_interface)pass(self), pointerCompute curl.
compute_curl_extendedprocedure(compute_curl_interface)pass(self), pointerCompute curl on extended support.
compute_derivative1procedure(compute_derivative1_interface)pass(self), pointerCompute deriv1.
compute_derivative2procedure(compute_derivative2_interface)pass(self), pointerCompute deriv2.
compute_derivative4procedure(compute_derivative4_interface)pass(self), pointerCompute deriv4.
compute_divergenceprocedure(compute_divergence_interface)pass(self), pointerCompute dive.
compute_gradientprocedure(compute_gradient_interface)pass(self), pointerCompute grad.
compute_gradient_extendedprocedure(compute_gradient_interface)pass(self), pointerCompute gradient on extended support.
compute_laplacianprocedure(compute_laplacian_interface)pass(self), pointerCompute laplac.

Type-Bound Procedures

NameAttributesDescription
initializepass(self)Initialize common data.
load_fdv_from_filepass(self)Load FDV config from file.
initialize_process_contextpass(self)Process-global MPI (+ device) init; forest calls it ONCE first.
initialize_forestpass(self), non_overridableInvoked by forest%initialize per realm: the template.
initialize_app_forestpass(self)Template hook: parse, build, backend, before the state.
restart_state_forestpass(self)Template hook: the state from the restart files.
initial_amr_iterations_forestpass(self)Template hook: initial state + regrid passes.
set_initial_state_forestpass(self)Template hook: the initial condition, from scratch.
amr_update_initial_forestpass(self)Template hook: one initial regrid.
rebalance_initial_forestpass(self)Template hook: the static rebalance of the initial grid.
reset_time_forestpass(self)Template hook: time and step counter to zero.
post_initial_state_forestpass(self)Template hook: everything after the initial state.
compute_local_dt_forestpass(self)Invoked by forest%compute_global_dt during the min reduction.
advance_one_step_forestpass(self)Invoked by forest%evolve_one_step per realm per timestep.
stages_per_step_forestpass(self)Number of integrator stages this realm exposes per step.
coupling_descriptor_forestpass(self)Report (scheme_time, rk_scheme, nv) for β admissibility.
open_step_forestpass(self)Per-step prologue (multi-realm path).
begin_stage_forestpass(self)Begin one integrator stage on this realm (multi-realm path).
end_stage_forestpass(self)End the stage: residuals + assignment (multi-realm path).
close_step_forestpass(self)Per-step epilogue (multi-realm path).
post_step_forestpass(self)Invoked by forest%post_step per realm per timestep.
runtime_amr_forestpass(self)Whether this realm regrids during the run (#74).
regrid_forestpass(self)Invoked by forest%regrid per realm per timestep (#74).
regrid_begin_forestpass(self)Multi-realm regrid, phase 1: is it a regrid step (#110).
regrid_mark_forestpass(self)Phase 2: mark one sweep, marks on the tree (#110).
regrid_apply_forestpass(self)Phase 3: adapt to the (balanced) tree marks (#110).
regrid_end_forestpass(self)Phase 4: refresh the grid-dependent state (#110).
is_done_forestpass(self)Invoked by forest%is_done during the termination reduction.
finalize_forestpass(self)Invoked by forest%finalize per realm at shutdown.
finalize_mpi_forestpass(self)Process-global MPI finalize; forest calls it ONCE after all.
fill_seam_from_peer_forestpass(self)Receive-side roundtrip: copy peer's interior into self's ghosts.
pack_seam_cells_forestpass(self)Pack own cells of the cross-rank seam send rows.
unpack_seam_cells_forestpass(self)Unpack the cross-rank seam receive rows into own ghosts.
after_topology_build_forestpass(self)Backend hook invoked once after the forest builds the seam maps.
apply_reflux_to_stage_forestpass(self)Apply Berger-Colella reflux to self's stage buffer.
close_block_xh5fnopassClose XH5F file block.
close_file_xh5fnopassClose XH5F file.
open_block_xh5fpass(self)Open block file XH5F.
open_file_xh5fpass(self)Open file XH5F.
save_q_xh5fpass(self)Save in XH5F (XDMF/HDF5) format.
compute_curl_fd_extendedpass(self)Compute curl of vector field, finite difference, even for half gcs.
compute_gradient_fd_extendedpass(self)Compute gradient of scalar field, finite difference, even for half gcs. private FDV operators
compute_block_total_variation_fdpass(self)Return the max of block total variation for a given var.
compute_curl_fdpass(self)Compute curl of vector field, finite difference.
compute_curl_fvpass(self)Compute curl of vector field, finite volume.
compute_curl_fv_extendedpass(self)Compute curl of vector field, finite volume, even for half gcs.
compute_derivative1_fdpass(self)Compute derivative1 of scalar field, finite difference.
compute_derivative1_fvpass(self)Compute derivative1 of scalar field, finite volume.
compute_derivative2_fdpass(self)Compute derivative2 of scalar field, finite difference.
compute_derivative2_fvpass(self)Compute derivative2 of scalar field, finite volume.
compute_derivative4_fdpass(self)Compute derivative4 of scalar field, finite difference.
compute_divergence_fdpass(self)Compute divergence of vector field, finite difference.
compute_divergence_fvpass(self)Compute divergence of vector field, finite volume.
compute_gradient_fdpass(self)Compute gradient of scalar field, finite difference.
compute_gradient_fvpass(self)Compute gradient of scalar field, finite volume.
compute_gradient_fv_extendedpass(self)Compute gradient of scalar field, finite volume, even for half gcs.
compute_laplacian_fdpass(self)Compute laplacian of scalar field, finite difference.
compute_laplacian_fvpass(self)Compute laplacian of scalar field, finite volume.

realm_pointer ​

A pointer to one realm of the forest. The forest and every routine that receives the sibling realms take an array of these, type(realm_pointer) :: realm(:), never a polymorphic array class(realm_object) :: realm(:): indexing a polymorphic array dummy is miscompiled by nvfortran 25.11 and 26.9, which may address element is with the stride of the declared type instead of the dynamic one (issue #96, first worked around in 0062a237). The driver (adam_run_library%run_forest) allocates each realm as a scalar of its own through its pointer (allocate(realm(i)%ptr, mold=prototype)), so no polymorphic array exists at all.

Components

NameTypeAttributesDescription
ptrclass(realm_object)pointerThe realm.

Interfaces ​

compute_block_total_variation_interface ​

compute_curl_interface ​

compute_derivative1_interface ​

compute_derivative2_interface ​

compute_derivative4_interface ​

compute_divergence_interface ​

compute_gradient_interface ​

compute_laplacian_interface ​

Subroutines ​

initialize ​

Initialize common data: MPI, ADAM, grid, field and data replica pointers.

[weno] and [fdv] are read on demand (issue #80 P5): before calling this, the application says whether its configuration uses the WENO coefficients (self%with_weno) and the realm's FD/FV operators (self%with_fdv), both .true. by default. A component not wanted is not initialized and its section is not read, so an input that carries it anyway reports its keys unread.

fortran
subroutine initialize(self, filename, memory_avail, nv, fields_number, verbose, L0)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inouttargetThe equation.
filenamecharacter(len=*)inInput parameters file name.
memory_availreal(kind=R8P)invalueMemory available for single MPI process.
nvinteger(kind=I4P)inoptionalNumber of field variables.
fields_numberinteger(kind=I4P)inoptionalBlock-sized fields allocated per block (default 170).
verboselogicalinoptionalTrigger verbose output.
L0real(kind=R8P)inoptionalAdimensionalization parameter.

Call graph

load_fdv_from_file ​

Load FDV config from file.

fortran
subroutine load_fdv_from_file(self, file_parameters)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe equation.
file_parameterstype(file_ini)inSimulation parameters ini file handler.

Call graph

initialize_forest ​

Initialize this realm, the library template (issue #80 P3): the sequence every application shares, its steps delegated to the *_forest hooks below.

fortran
 call self%initialize_app_forest(filename, realms_number) ! parse, build the library and app objects, the backend
 if (self%io%restart) then
    call self%restart_state_forest                        ! the state from the restart files
 else
    do i=1, self%initial_amr_iterations_forest()          ! the initial state, then a regrid on it, n times
       call self%set_initial_state_forest
       call self%amr_update_initial_forest
    enddo
    call self%rebalance_initial_forest                    ! [amr].(balance_static)
    call self%set_initial_state_forest                    ! the initial state on the final grid
    call self%adam%make_comm_local_maps_ghost_bc          ! the maps of the final grid
    call self%reset_time_forest
 endif
 call self%post_initial_state_forest                     ! device push, ghosts, t0 diagnostics, history files

Invoked by forest%initialize once per realm at startup, before the time loop; MPI and the device are up already (initialize_process_context). The forest sets self%realm_index = is BEFORE invoking it, so the hooks can read their forest position for per-realm IO filenames, log prefixes, etc. The template is non-overridable: an application implements the hooks, whose defaults error-stop, except restart_state_forest, which refuses [IO].(restart) = .true..

fortran
subroutine initialize_forest(self, filename, realms_number)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
filenamecharacter(len=*)inInput parameters file name.
realms_numberinteger(kind=I4P)inoptionalRealm count in the forest.

Call graph

initialize_app_forest ​

Template hook: everything before the initial state (parse the input, build the library and app objects, set up the backend); realms_number divides the memory budget in a forest. Default error-stops.

fortran
subroutine initialize_app_forest(self, filename, realms_number)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
filenamecharacter(len=*)inInput parameters file name.
realms_numberinteger(kind=I4P)inoptionalRealm count in the forest.

Call graph

restart_state_forest ​

Template hook: the state from the restart files (time and step counter included). Default refuses the restart.

fortran
subroutine restart_state_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

set_initial_state_forest ​

Template hook: the initial condition on the current grid (and what derives from it). Default error-stops.

fortran
subroutine set_initial_state_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

amr_update_initial_forest ​

Template hook: one regrid of the initial grid on the current state. Default error-stops.

fortran
subroutine amr_update_initial_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

rebalance_initial_forest ​

Template hook: the static rebalance of the initial grid, [amr].(balance_static) (default .true.: every application decides what it does with it). Default error-stops.

fortran
subroutine rebalance_initial_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

reset_time_forest ​

Template hook: the time and the step counter of a run from scratch to zero. Default error-stops.

fortran
subroutine reset_time_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

post_initial_state_forest ​

Template hook: everything after the initial state, restart or not (device push, ghost update, t0 diagnostics, history files, the AMR lock). Default error-stops.

fortran
subroutine post_initial_state_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

compute_local_dt_forest ​

Compute this realm's local stability-limited dt (no MPI reduction).

Invoked by forest%compute_global_dt during the min reduction across all realms in the forest. The reduction itself is the orchestrator's job; this method computes only the value local to self.

Default implementation error-stops: every consumer app MUST override this method (the CFL criterion and umax are app-specific). PRISM's override lives on prism_cpu_object/prism_fnl_object.

fortran
subroutine compute_local_dt_forest(self, dt_local)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.
dt_localreal(kind=R8P)outLocal stability-limited dt.

Call graph

advance_one_step_forest ​

Advance this realm by one full timestep of size dt.

Invoked by forest%evolve_one_step once per realm per timestep when the forest contains a single realm (N=1 fast path). For N>1 the forest drives the stage loop itself via open_step_forest, begin_stage_forest, end_stage_forest, close_step_forest, and this TBP is NOT invoked — see forest_object%evolve_one_step for the multi-realm path.

The orchestrator owns global dt selection (compute_global_dt) and the termination check; this method owns the integration itself — RK substages, BC application, intra-realm ghost exchange, divergence cleaning — i.e. everything that turns q at time t into q at time t + dt.

Default implementation error-stops: every consumer app MUST override this method (the integrator catalog and the substage layout are app-specific). PRISM's override lives on prism_cpu_object and prism_fnl_object as a thin wrapper around the legacy integrate / integrate_dev dispatch.

fortran
subroutine advance_one_step_forest(self, dt)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
dtreal(kind=R8P)inTimestep size.

Call graph

coupling_descriptor_forest ​

Report this realm's coupling descriptor for β admissibility.

Returns the identity of the realm's ODE solver + physics layout. Two realms may share a seam with CADENCE_STAGE_COINCIDENT only if all three values match between them; otherwise the forest rejects the manifest. Spatial operator (scheme_space) and grid resolution are NOT in the descriptor — those are precisely the dimensions β allows to differ between realms.

Default implementation returns empty strings and sentinel nv = -1: a realm that does not override this TBP cannot participate in β. App-side overrides (e.g. prism_common_object) report numerics%scheme_time, ts%scheme, physics%nv.

fortran
subroutine coupling_descriptor_forest(self, scheme_time, rk_scheme, nv)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.
scheme_timecharacter(len=:)outallocatableTime-integration family tag ("runge_kutta", "leapfrog", ...).
rk_schemecharacter(len=:)outallocatableWithin-family scheme tag ("runge-kutta-ssp-54", ...).
nvinteger(kind=I4P)outNumber of conserved variables on this realm.

Call graph

open_step_forest ​

Per-step prologue on the multi-realm path: pre-stage-loop setup.

Invoked once per realm per timestep, BEFORE the forest's stage loop starts. Body owns whatever the integrator does once per step before its first stage: external-field prelude, integrator-private state initialization (for SELAH realms: ts%begin_step), time bookkeeping (it increment, dt capping for time_max), progress prints.

Default implementation error-stops: every multi-realm participant MUST override this. N=1 apps can leave it.

fortran
subroutine open_step_forest(self, dt)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
dtreal(kind=R8P)inTimestep size from the forest.

Call graph

begin_stage_forest ​

Open one integrator stage on this realm — multi-realm path.

Invoked once per (realm, stage) by the forest, with k iterating from 1 to K_total. Body publishes the realm's stage-k buffer to peers: it runs whatever integrator-private work is needed BEFORE residuals (for SELAH realms: ts%begin_stage(k) building the stage state from self%q and the prior stages), and assigns self%stage_active = k so peer-realm reads pick up the right buffer. Crucially it does NOT touch ghost cells from peer realms; peer realms may not yet have opened their own stage-k buffer when this fires.

The forest invokes begin_stage_forest on EVERY realm before proceeding to the seam fill and end_stage_forest, so by the time residuals evaluate, every peer realm has its stage-k buffer populated and the inter-realm ghost exchange returns coherent values.

Default implementation error-stops: every multi-realm participant MUST override this.

fortran
subroutine begin_stage_forest(self, k, K_total, dt, realm)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
kinteger(kind=I4P)inStage index (1..K_total).
K_totalinteger(kind=I4P)inForest-wide stage count for this step.
dtreal(kind=R8P)inTimestep size from the forest.
realmtype(realm_pointer)inouttarget, optionalSibling realms (contract parity).

Call graph

end_stage_forest ​

Close one integrator stage on this realm — multi-realm path.

Invoked once per (realm, stage) by the forest AFTER its Phase 2 inter-realm seam fill has populated the seam ghost cells. The body runs the integrator's per-stage work that needs valid peer ghosts: residual computation and stage assignment in a single sweep (for SELAH realms: compute_residuals + ts%set_rhs). The read-after- overwrite race that originally required a three-phase split is eliminated by the upstream seam fill, which decouples peer state reads from the in-place overwrite of the stage buffer's interior.

flux_register is an optional dummy used by FV residuals (compute_residuals_fv_centered) to accumulate seam-face flux contributions for Phase-A Berger–Colella reflux. Backends that don't implement FV reflux (e.g. FNL's FD-centered path) ignore it.

Default implementation error-stops: every multi-realm participant MUST override this. realm accepted on contract for parity but is not needed: peer state is read via the seam fill, not here.

fortran
subroutine end_stage_forest(self, k, K_total, dt, realm, flux_register)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
kinteger(kind=I4P)inStage index (1..K_total).
K_totalinteger(kind=I4P)inForest-wide stage count for this step.
dtreal(kind=R8P)inTimestep size from the forest.
realmtype(realm_pointer)inouttarget, optionalSibling realms (parity only).
flux_registerclass(flux_register_object)inoutoptionalForest's flux register for FV reflux.

Call graph

close_step_forest ​

Per-step epilogue on the multi-realm path: post-stage-loop finalization.

Invoked once per realm per timestep, AFTER the forest's stage loop completes. Body owns whatever the integrator does once per step at the end: assembly of the committed state from stage buffers (for SELAH realms: ts%finish_step), BC update, divergence cleaning, coil current refresh, residual save, time advance. Should also clear self%stage_active = 0 so any inter-step fill_seam_from_peer_forest query reads from the committed state rather than a stale stage buffer.

Default implementation error-stops: every multi-realm participant MUST override this.

fortran
subroutine close_step_forest(self, dt)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
dtreal(kind=R8P)inTimestep size from the forest.

Call graph

post_step_forest ​

Run this realm's per-timestep post-step work: diagnostics, IO, AMR.

Invoked by forest%post_step once per realm per timestep, after the advance. The orchestrator owns cadence decisions (when to save state, when to refine the mesh, etc.) and conveys them via the optional do_* flags; this method executes the work that those flags enable. Cadence flags absent ⇒ caller wants the default cadence (today: do everything every step, since save_*_data routines internally respect the realm's own it_save settings).

Default implementation error-stops: every consumer app MUST override this method (the diagnostic catalog and IO layout are app-specific). PRISM's override lives on prism_cpu_object and prism_fnl_object.

Optional realm(:): forest realm array threaded for inter-realm halo refresh inside save_simulation_data (which calls update_ghost). FNL backend forwards it through; CPU backend ignores it.

fortran
subroutine post_step_forest(self, dt, t, it, do_save_state, do_save_residuals, do_save_restart, do_amr, realm)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
dtreal(kind=R8P)inTimestep size just advanced.
treal(kind=R8P)inSimulation time after the advance.
itinteger(kind=I4P)inIteration index after the advance.
do_save_statelogicalinoptionalSave state output this step.
do_save_residualslogicalinoptionalSave residuals output this step.
do_save_restartlogicalinoptionalSave restart dump this step.
do_amrlogicalinoptionalRun AMR update this step.
realmtype(realm_pointer)inouttarget, optionalSibling realms for inter-realm halo refresh.

Call graph

is_done_forest ​

Decide whether this realm's local termination criterion is met.

Invoked by forest%is_done during the termination reduction across all realms in the forest. The reduction itself (typically a logical AND or OR depending on coupling semantics) is the orchestrator's job; this method computes only the predicate local to self.

Default implementation error-stops: every consumer app MUST override this method (the termination criterion mixes iteration count, simulated time, and app-specific physics signals). PRISM's override lives on prism_cpu_object/prism_fnl_object.

fortran
subroutine is_done_forest(self, done)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.
donelogicaloutTrue if this realm is done evolving.

Call graph

finalize_forest ​

Shut this realm down: final state dump, final diagnostics, close output files, finalize the realm's MPI handler.

Invoked by forest%finalize once per realm at shutdown, after the time loop exits. Mirror of initialize_forest: every IO file opened in initialize_forest is closed here; every per-realm resource the orchestrator did not acquire is released here.

Default implementation error-stops: every consumer app MUST override this method (the close-order and final-dump catalog are app-specific). PRISM's override lives on prism_cpu_object/prism_fnl_object.

fortran
subroutine finalize_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.

Call graph

initialize_process_context ​

Initialize the process-global MPI handler (and the device, on the device backends).

MPI and the device context are process-global: the forest calls this ONCE, on a single realm, before any realm is initialized (issue #80 P3, the mirror of finalize_mpi_forest); a realm never initializes them itself. The default initializes the CPU mpih singleton; the FNL backends override it to initialize mpih_fnl (device binding, the ranks sharing a device) first. mpih%initialize is once-only, so a test driver that called it already is harmless.

fortran
subroutine initialize_process_context(self, verbose)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm (carries no MPI state; dispatch picks the backend).
verboselogicalinoptionalTrigger verbose output.

Call graph

finalize_mpi_forest ​

Finalize the process-global MPI handler.

MPI_FINALIZE is process-global and must run EXACTLY ONCE, after every realm has completed all MPI-using teardown. The forest therefore calls this on a SINGLE realm after the per-realm finalize_forest loop — not inside finalize_forest (which runs per realm; doing the finalize there tore MPI down while later realms still had IO/ghost work pending — the next realm's update_ghost would hit MPI_Type_f2c on a finalized communicator). The default targets the CPU mpih singleton; the FNL backend overrides to finalize mpih_fnl.

fortran
subroutine finalize_mpi_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm (carries no MPI state; dispatch picks the backend handler).

Call graph

fill_seam_from_peer_forest ​

Fill THIS realm's seam ghost cells for peer slot p_idx from peer's interior. Default: error_stops; every multi-realm participant MUST override (the receiver is the dispatch target).

fortran
subroutine fill_seam_from_peer_forest(self, peer, p_idx)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inout
peerclass(realm_object)intarget
p_idxinteger(kind=I4P)in

Call graph

pack_seam_cells_forest ​

Pack this realm's cells of the cross-rank seam send rows of peer slot p_idx (maps%seam_mpi_send_cell), from the active buffer (stage_active rule of fill_seam_from_peer_forest), nv values per row in row order. Default: error_stops; every multi-realm participant MUST override.

fortran
subroutine pack_seam_cells_forest(self, p_idx, buf)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.
p_idxinteger(kind=I4P)inPeer slot (the realm that owns the ghosts).
bufreal(kind=R8P)outPacked values, nv * rows.

Call graph

unpack_seam_cells_forest ​

Unpack buf into this realm's seam ghosts of the cross-rank receive rows of peer slot p_idx (maps%seam_mpi_recv_cell), on the active buffer, nv values per row in row order. Default: error_stops; every multi-realm participant MUST override.

fortran
subroutine unpack_seam_cells_forest(self, p_idx, buf)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
p_idxinteger(kind=I4P)inPeer slot (the realm that owns the cells).
bufreal(kind=R8P)inPacked values, nv * rows.

Call graph

after_topology_build_forest ​

Backend hook invoked by forest%populate_inter_realm_topology AFTER all host-side seam maps have been built. CPU default is a no-op (host maps are the production state). GPU backends override to propagate the freshly-built host seam maps to device-resident copies (e.g. via maps_fnl%copy_cpu_gpu).

fortran
subroutine after_topology_build_forest(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inout

Call graph

regrid_forest ​

Regrid this realm if its cadence asks for it now (issue #74, runtime AMR).

Invoked by forest%regrid once per realm after post_step_forest, on committed q (no stage active). The realm marks its blocks, calls adam%amr_update and refreshes its grid-dependent state; regridded tells the forest whether the tree changed, so it rebuilds what it owns (the flux register). Default: never regrid.

fortran
subroutine regrid_forest(self, regridded)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
regriddedlogicaloutTrue if the tree changed.

Call graph

regrid_begin_forest ​

Start a multi-realm regrid of this realm: active if its cadence asks for a regrid now (issue #110).

fortran
subroutine regrid_begin_forest(self, active)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
activelogicaloutThis realm marks its blocks at this step.

Call graph

regrid_mark_forest ​

Mark the blocks of this realm for sweep sweep and gather the marks on its replicated tree (issue #110).

marked is false when the realm does not mark in this sweep (no regrid step, or more sweeps than its [amr] iters); the forest then clears its tree marks before balancing the seams.

fortran
subroutine regrid_mark_forest(self, sweep, marked)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
sweepinteger(kind=I4P)inSweep of the regrid, from 1.
markedlogicaloutThe realm marked its blocks.

Call graph

regrid_apply_forest ​

Adapt this realm to the marks on its replicated tree, as the forest balanced them (issue #110).

fortran
subroutine regrid_apply_forest(self, changed)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
changedlogicaloutThe tree changed.

Call graph

regrid_end_forest ​

End a multi-realm regrid of this realm: refresh the state of the new grid, regridded if any sweep changed it.

fortran
subroutine regrid_end_forest(self, regridded)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
regriddedlogicaloutThe tree changed in some sweep.

Call graph

apply_reflux_to_stage_forest ​

Apply the Berger-Colella reflux correction to THIS realm's stage-stage buffer for every flux-register face where self is the coarse side.

Invoked by forest_object%evolve_one_step once per realm per stage, AFTER flux_register%reduce_fine_sums has globalised the fine-side accumulators. The realm filters the register's face array by face%coarse_realm == self%realm_index, picks up its OWN integrator- specific stage weight (self%ts%stage_weight(stage)), and writes the correction delta into its OWN stage buffer (the stepper's registers).

Architectural role: this TBP keeps the per-realm reflux write integrator-private. The forest never names a stepper register or a stage weight: those live realm-side (ts), so a realm can change its integrator without touching the orchestrator.

The realm's 1-based forest position is read from self%realm_index, which the forest writes once at initialize-time; no per-call plumbing of is through the dispatch is needed.

Default implementation error-stops: every multi-realm participant that uses FV reflux MUST override this. Multi-realm participants that DO NOT accumulate flux contributions (e.g. an FD-only realm) should override with a no-op body.

fortran
subroutine apply_reflux_to_stage_forest(self, stage, dt, flux_register)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe realm.
stageinteger(kind=I4P)inIntegrator stage 1..K_total.
dtreal(kind=R8P)inTime step.
flux_registerclass(flux_register_object)inForest's flux register (read-only).

Call graph

close_block_xh5f ​

Close XH5F file block.

fortran
subroutine close_block_xh5f(xh5f)

Arguments

NameTypeIntentAttributesDescription
xh5ftype(xh5f_file_object)inoutXH5F file handler.

Call graph

close_file_xh5f ​

Close XH5F file.

fortran
subroutine close_file_xh5f(xh5f)

Arguments

NameTypeIntentAttributesDescription
xh5ftype(xh5f_file_object)inoutXH5F file handler.

Call graph

open_block_xh5f ​

Open XH5F file block; length_scale multiplies the written block origin and spacing (output units of an application, e.g. FLUME [reference] output_units). The origin is the corner of the first stored cell: ngc_saved cells below the block's first interior cell, ngc_saved the ghost layers the caller writes (default all, ngc; 0 for the interior only, e.g. the restart snapshot, issue #109).

fortran
subroutine open_block_xh5f(self, xh5f, b, nijk, t, time, length_scale, ngc_saved)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe equation.
xh5ftype(xh5f_file_object)inoutXH5F file handler.
binteger(kind=I4P)inBlock index.
nijkinteger(kind=I8P)inBlocks dimensions.
tinteger(kind=I4P)inoptionalTime iteration.
timereal(kind=R8P)inoptionalTime.
length_scalereal(kind=R8P)inoptionalScale of the written origin and spacing.
ngc_savedinteger(kind=I4P)inoptionalGhost layers written (default ngc).

Call graph

open_file_xh5f ​

Open XH5F file.

fortran
subroutine open_file_xh5f(self, basename, xh5f, directory)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe equation.
basenamecharacter(len=*)inBase name of output files.
xh5ftype(xh5f_file_object)outXH5F file handler.
directorycharacter(len=*)inoptionalDirectory name of output files.

Call graph

save_q_xh5f ​

Save ADAM in XH5F format.

fortran
subroutine save_q_xh5f(self, basename, q, q_name, directory, with_ghost, with_cell_morton, t, time)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inoutThe equation.
basenamecharacter(len=*)inBase name of output files.
qreal(kind=R8P)inQ-vector variables [nv,ni,nj,nk,nb].
q_namecharacter(len=*)inoptionalQ-vector variables names [nv].
directorycharacter(len=*)inoptionalDirectory name of output files.
with_ghostlogicalinoptionalFlag to save ghost cells.
with_cell_mortonlogicalinoptionalFlag to save Morton code also in cells.
tinteger(kind=I4P)inoptionalTime iteration.
timereal(kind=R8P)inoptionalTime.

Call graph

compute_block_total_variation_fd ​

Return the max of block total variation for a given var.

fortran
subroutine compute_block_total_variation_fd(self, hs, dxyz, ivar, q, tot_var_field, total_variation)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dxyzreal(kind=R8P)inSpace steps.
ivarinteger(kind=I4P)inIndex of first component of vec field.
qreal(kind=R8P)inField variables.
tot_var_fieldreal(kind=R8P)inoutTotal variation field on blocks.
total_variationreal(kind=R8P)outMax total variation on given block.

Call graph

compute_curl_fd ​

Compute curl of vector fields, div(q(ivar:ivar+2), using finite difference schemes.

fortran
subroutine compute_curl_fd(self, hs, ivar, q, curl)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
curlreal(kind=R8P)inoutCurl.

Call graph

compute_curl_fd_extended ​

Compute curl of vector fields, div(q(ivar:ivar+2), using finite difference schemes.

fortran
subroutine compute_curl_fd_extended(self, hs, ivar, q, curl)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
curlreal(kind=R8P)inoutCurl.

Call graph

compute_curl_fv ​

Compute curl of vector fields, div(q(ivar:ivar+2), using finite volume schemes.

fortran
subroutine compute_curl_fv(self, hs, ivar, q, curl)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
curlreal(kind=R8P)inoutCurl.

Call graph

compute_curl_fv_extended ​

Compute curl of vector fields, div(q(ivar:ivar+2), using finite volume schemes.

fortran
subroutine compute_curl_fv_extended(self, hs, ivar, q, curl)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
curlreal(kind=R8P)inoutCurl.

Call graph

compute_derivative1_fd ​

Compute derivative1 of scalar fields, dq(ivar)/ds, using finite difference schemes.

fortran
subroutine compute_derivative1_fd(self, hs, dir, ivar, q, dq_ds)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dirinteger(kind=I4P)inDirection, 1=X, 2=Y, 3=Z.
ivarinteger(kind=I4P)inStart index of (vec.) variable of q.
qreal(kind=R8P)inField variables.
dq_dsreal(kind=R8P)inoutDerivative1, dq/ds.

Call graph

compute_derivative1_fv ​

Compute derivative1 of scalar fields, dq(ivar)/ds, using finite volume schemes.

fortran
subroutine compute_derivative1_fv(self, hs, dir, ivar, q, dq_ds)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dirinteger(kind=I4P)inDirection, 1=X, 2=Y, 3=Z.
ivarinteger(kind=I4P)inStart index of (vec.) variable of q.
qreal(kind=R8P)inField variables.
dq_dsreal(kind=R8P)inoutDerivative1, dq/ds.

Call graph

compute_derivative2_fd ​

Compute derivative2 of scalar fields, d2q(ivar)/ds2, using finite difference schemes.

fortran
subroutine compute_derivative2_fd(self, hs, dir, ivar, q, d2q_ds2)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dirinteger(kind=I4P)inDirection, 1=X, 2=Y, 3=Z.
ivarinteger(kind=I4P)inStart index of vec variable of q.
qreal(kind=R8P)inField variables.
d2q_ds2real(kind=R8P)inoutDerivative2, d2q/ds2.

Call graph

compute_derivative2_fv ​

Compute derivative2 of scalar fields, d2q(ivar)/ds2, using finite volume schemes.

fortran
subroutine compute_derivative2_fv(self, hs, dir, ivar, q, d2q_ds2)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dirinteger(kind=I4P)inDirection, 1=X, 2=Y, 3=Z.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
d2q_ds2real(kind=R8P)inoutDerivative2, d2q/ds2.

compute_derivative4_fd ​

Compute derivative2 of scalar fields, d4q(ivar)/ds4, using finite difference schemes.

fortran
subroutine compute_derivative4_fd(self, hs, dir, ivar, q, d4q_ds4)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
dirinteger(kind=I4P)inDirection, 1=X, 2=Y, 3=Z.
ivarinteger(kind=I4P)inStart index of variable of q.
qreal(kind=R8P)inField variables.
d4q_ds4real(kind=R8P)inoutDerivative4, d4q/ds4.

Call graph

compute_divergence_fd ​

Compute divergence of vector fields, div(q(ivar:ivar+2), using finite difference schemes.

fortran
subroutine compute_divergence_fd(self, hs, ivar, q, divergence)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of field of q.
qreal(kind=R8P)inField variables.
divergencereal(kind=R8P)inoutDivergence.

Call graph

compute_divergence_fv ​

Compute divergence of vector fields, div(q(ivar:ivar+2), using finite volume schemes.

fortran
subroutine compute_divergence_fv(self, hs, ivar, q, divergence)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inStart index of field of q.
qreal(kind=R8P)inField variables.
divergencereal(kind=R8P)inoutDivergence.

Call graph

compute_gradient_fd ​

Compute gradient of scalar variable q(ivar), finite difference schemes.

fortran
subroutine compute_gradient_fd(self, hs, ivar, q, gradient)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
gradientreal(kind=R8P)inoutGradient.

Call graph

compute_gradient_fd_extended ​

Compute gradient of scalar variable q(ivar), finite difference schemes.

fortran
subroutine compute_gradient_fd_extended(self, hs, ivar, q, gradient)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
gradientreal(kind=R8P)inoutGradient.

Call graph

compute_gradient_fv ​

Compute gradient of scalar variable q(ivar), finite volume schemes.

fortran
subroutine compute_gradient_fv(self, hs, ivar, q, gradient)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
gradientreal(kind=R8P)inoutGradient.

Call graph

compute_gradient_fv_extended ​

Compute gradient of scalar variable q(ivar), finite volume schemes.

fortran
subroutine compute_gradient_fv_extended(self, hs, ivar, q, gradient)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
gradientreal(kind=R8P)inoutGradient.

Call graph

compute_laplacian_fd ​

Compute laplacian of scalar variable q(ivar), finite difference schemes.

fortran
subroutine compute_laplacian_fd(self, hs, ivar, q, laplacian)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
laplacianreal(kind=R8P)inoutGradient.

Call graph

compute_laplacian_fv ​

Compute laplacian of scalar variable q(ivar), finite volume schemes.

fortran
subroutine compute_laplacian_fv(self, hs, ivar, q, laplacian)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe equation.
hsinteger(kind=I4P)inFDV half stencil length.
ivarinteger(kind=I4P)inIndex of scalar variable of q.
qreal(kind=R8P)inField variables.
laplacianreal(kind=R8P)inoutGradient.

Functions ​

initial_amr_iterations_forest ​

Template hook: the passes of initial state + regrid before the final initial state. Default error-stops.

Returns: integer(kind=I4P)

fortran
function initial_amr_iterations_forest(self) result(n)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.

Call graph

stages_per_step_forest ​

Return the number of integrator stages this realm exposes per step.

Integrator-agnostic: K is the number of inter-realm seam-coherence boundaries the realm wants visible to the forest: K = ts%stages() for the SSP schemes the staged path admits (FLUME and PRISM refuse the others here). A realm that does all its work atomically and needs one peer-sync per step would report K = 1.

Invoked by forest%evolve_one_step on the multi-realm path to size the stage loop. Under α (end-of-step seam coupling) realms may report different K values: the orchestrator iterates k = 1..max(K_realm) and gates each per-stage TBP on k <= K_realm(is). Under β (stage-coincident) admissibility requires equal K on both endpoints of every β seam (enforced at init).

Default implementation error-stops: every realm that participates in a multi-realm forest MUST override this. Apps that only ever run as N=1 may leave it (the N=1 fast path doesn't call this).

Returns: integer(kind=I4P)

fortran
function stages_per_step_forest(self) result(K)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.

Call graph

runtime_amr_forest ​

Return whether this realm regrids during the time loop (issue #74, runtime AMR).

The forest asks it before every regrid: with a realm that regrids, a multi-realm forest fills its seams before the realms mark and balances their marks across the seams (issue #110). Default: no runtime regridding, the behaviour of every app before #74; an app that regrids overrides it.

Returns: logical

fortran
function runtime_amr_forest(self) result(yes)

Arguments

NameTypeIntentAttributesDescription
selfclass(realm_object)inThe realm.

Call graph