MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_amr_state.fpp.f90 File Reference

Contains module m_amr_state. More...

Go to the source code of this file.

Data Types

type  m_amr_state::t_level
 One refined level: its own grid and metadata (host-only). Fields live in the flat stores amr_cons_st/amr_stor_st, indexed by amr_loc_of. More...

Modules

module  m_amr_state
 Module-scope AMR state (block pool, flat field store, wave buffers) and the leaf helpers every AMR module needs.

Functions/Subroutines

subroutine m_amr_state::s_build_level_coords (pcb, pcb_lb, lo, nfine, fcb, fcc, fdx)
 Fill fcb/fcc/fdx by subdividing parent cells (s_amr_subdivide_cb); pcb_lb is lbound(pcb, 1). Only 0..nfine is filled.
pure subroutine m_amr_state::s_amr_region_box (k, rlo, rhi)
 Block k's region box in global coarse cells; collapsed dimensions read 0:0.
pure subroutine m_amr_state::s_amr_patch_box (k, plo, phi)
 Block k's padded coarse patch box [plo, phi] (region +/- amr_cpat_mar; collapsed dims 0:0).
pure integer function m_amr_state::f_amr_prolong_reach ()
 How many parent cells inside a child's footprint the ghost prolongation reads: 1 for limited linear, 2 for the quartic.
pure integer function m_amr_state::f_amr_cpat_mar ()
 Coarse-patch margin amr_cpat_mar: the coarse cells a buff_size fine ghost layer spans plus the prolongation reach.
pure subroutine m_amr_state::s_amr_patch_core (k, clo, chi)
 Core [clo, chi] of the patch box that the ghost fill never reads, so the fill waves ship only the shell around it.
impure subroutine m_amr_state::s_amr_build_block_coords (k, gcb, glb, fcb, fcc, fdx, d)
 Fine cell coordinates of block k in dimension d, rebuilt from the global coarse boundaries gcb by replaying k's ancestor chain from replicated metadata, so any rank can reproduce them. Do not bisect amr_slots(parent)x_cb instead: the parent's slot exists only on its owner, which a level>=2 block's owner need not be.
impure subroutine m_amr_state::s_amr_build_global_cb (pad)
 Assemble the global coarse cell-boundary arrays over (-1-pad : G+pad): each rank writes its own cells' boundaries into a sentinel-filled array and an elementwise MAX allreduce recovers the global one. A larger-pad rebuild gives a consistent superset.
pure logical function m_amr_state::f_amr_boxes_overlap (alo, ahi, blo, bhi)
 Do two coarse-index boxes [alo:ahi] and [blo:bhi] overlap? Collapsed dims never disqualify.
pure integer function m_amr_state::f_amr_parent_block (k)
 Index of the level-(level(k)-1) block that block k refines, or 0 for level 1 (parent is the L0 grid). Regions are in L0 cell indices at every level; proper nesting guarantees one overlapping parent.
impure subroutine m_amr_state::s_amr_fine_slice (slot, d, dlo, dhi, buf, dir)
 Pack (dir=+1) / unpack (dir=-1) the fine cells of slot's q_cons over [dlo:dhi] in dim d (interior transverse, all sys_size) in a fixed order, so a packer and unpacker with matching extents align cell-for-cell. On GPU only this near-seam slab moves device<->host.
pure subroutine m_amr_state::s_amr_phys_to_cells (pmin, pmax, pad_cells, blo, bhi)
 Convert a physical-space bbox to a global coarse-index bbox padded by pad_cells (uniform spacing; the axisymmetric half axis cell only shrinks dy(0), so the floor stays conservative).
impure subroutine m_amr_state::s_amr_check_lag_clear ()
 Rank-local per-stage guard: the local bubbles' padded bbox must stay clear of the current block (initial overlap, or drift beyond the regrid margin).
pure elemental real(wp) function m_amr_state::minmod (a, b)
 minmod slope limiter: 0 if a,b differ in sign, else the smaller-magnitude argument.
pure real(wp) function m_amr_state::f_amr_lin (u0, xm, xp, ym, yp, zm, zp, xix, xiy, xiz)
 Minmod-limited linear value at fine offset (xix, xiy, xiz) in coarse cell u0, from its face neighbours (m, p) per direction; pass u0 for both neighbours of a direction without a slope.
pure logical function m_amr_state::f_amr_cons_ok (fi, fj, fk, loc)
 Admissible fine cell: positive density and (except model 4) positive internal energy; a NaN state is inadmissible.
pure real(wp) function m_amr_state::f_amr_quartic_half (q, xi)
 Average over one half (xi < 0 left, > 0 right; |xi| = 1/4) of the middle of five cell averages q: the conservative quartic, or MC-limited linear where either half leaves the range of the three nearest averages. That range is widened only where the three second differences share a sign (smooth data): by the smallest of them, c, at a local extremum of the averages, and where they are monotone by c/4 times the ratio of the smallest to the largest, never across zero. A smooth extremum in the next cell needs c/8 (without it the fill is second order there) and has a ratio near one; at the foot of a steep front c is as large as q(0) and the ratio is small; at an under- or overshoot beside a front the differences change sign and the quartic's slope is the front's, not the cell's. Both halves are tested so the two children share one reconstruction (their mean stays q(0)).
impure subroutine m_amr_state::s_amr_scr_init ()
 Allocate the pooled q_prim/rhs advance scratch (idempotent). The lockstep driver associates it for every block, so it must exist on every rank, including one that never allocates a slot. rhs gets the igr widening.
impure subroutine m_amr_state::s_amr_size_int (a, n)
 Grow-on-demand sizing for append-only tables and pools: a grow preserves the entries already appended.
impure subroutine m_amr_state::s_amr_size_int3 (a, n)
impure subroutine m_amr_state::s_amr_size_rows (a, r, n)
 s_amr_size_int for a table of n columns of r ints.
impure subroutine m_amr_state::s_amr_size_real (a, n, dev)
 Wire pools, preserving on grow. dev keeps the pool device-resident across (re)allocation: the old image is deleted from the device before it is freed and the new one created after; contents never survive a wave, so nothing is copied.

Variables

type(t_level), dimension(:), allocatable m_amr_state::amr_slots
 Fixed pool of refined-block slots; the working slot amr_cur selects which one per-block routines operate on.
integer, dimension(:), allocatable m_amr_state::amr_loc_of
 Dense local index for live slots: amr_slots is sparse over 1:amr_max_blocks, the field store is dense. Freed indices are recycled through amr_loc_free.
integer, dimension(:), allocatable m_amr_state::amr_loc_free
 stack of recycled local indices
integer m_amr_state::amr_loc_n = 0
 high-water mark of local indices handed out
integer m_amr_state::amr_loc_nfree = 0
 depth of the recycle stack
real(stp), dimension(:,:,:,:,:), allocatable m_amr_state::amr_cons_st
 Flat per-block field store (x, y, z, var, local slot) so one kernel can run over every live block; all slots share the mbuf extents. Sized by s_amr_st_reserve.
real(stp), dimension(:,:,:,:,:), allocatable m_amr_state::amr_stor_st
real(stp), dimension(:,:,:,:,:), allocatable m_amr_state::amr_ibp
 Moving bodies: the primitive state of the RHS pass of each block whose IB correction waits for the bodies to move (s_amr_fine_stage_ib), one column per such block, in the store's (x, y, z, var) layout.
integer, dimension(:), allocatable m_amr_state::amr_ibp_blk
 the block of each amr_ibp column
integer m_amr_state::amr_ibp_n = 0
 columns in use this stage
integer m_amr_state::amr_st_cap = 0
 local slots the store is sized for; grows only (s_amr_compact_store keeps the index space dense)
type(scalar_field), dimension(:), allocatable m_amr_state::amr_cons_br
 Copy bridge to the shared solver, whose routines take type(scalar_field) and serve the monolithic path too (a pointer view into the flat store is not attachable on OpenMP offload): load from the store, call, store back, in both directions since the dummies are intent(inout). Not GPU_DECLARE'd: a declare binds the present-table entry to the descriptor that move_alloc then swaps out (CCE find_in_present_table failed); allocate via move_alloc + GPU_ENTER_DATA instead (CCE lib-4425 otherwise).
integer, dimension(amr_bat_max) m_amr_state::amr_bat_loc = 0
 Batched advance: the bridge spans amr_br_batch blocks along the last active dimension, member i at offset (i-1)*amr_bat_w with its own ghost shell, so no block's stencil reaches another's interior. amr_bat_loc = members' flat-store columns (device-resident).
type(scalar_field), dimension(:), allocatable m_amr_state::amr_scr_prim
 Pooled advance scratch shared by every fine block (the fused advance leaves no cross-block lifetime); same pattern as amr_cg.
type(scalar_field), dimension(:), allocatable m_amr_state::amr_scr_rhs
type(scalar_field), dimension(:), allocatable m_amr_state::amr_scr_prim_blk
 block-frame prim scratch for the batched per-member IB correction (ib only); the slab prim stacks members along amr_bat_sd
integer m_amr_state::amr_br_batch = 1
 Blocks per batched s_compute_rhs call (amr_bat_max once initialized); bounded to avoid exhausting device memory.
integer, dimension(3) m_amr_state::amr_maxc
 max coarse block cells per dim: (m_glb+1)/2 etc.; 1 for collapsed dims
integer, dimension(3) m_amr_state::max_f
 Per-slot sizing: max fine cells per dim and the buffered array bounds. amr_slot_live(k): slot k's field arrays are allocated (lazy, owned-only).
integer, dimension(3) m_amr_state::mbuf_lo
integer, dimension(3) m_amr_state::mbuf_hi
logical, dimension(:), allocatable m_amr_state::amr_slot_live
integer, dimension(:,:), allocatable m_amr_state::amr_seam_pairs
 cached same-level seam list (xb, yb, seam-dim) so s_amr_fine_fine_post iterates O(#seams); rebuilt when amr_seam_pairs_dirty is set or the block count changes
integer m_amr_state::amr_num_seam_pairs
integer m_amr_state::amr_seam_pairs_nblk
logical m_amr_state::amr_seam_pairs_dirty
integer m_amr_state::amr_tag_narrow = 0
 Tag base of the clusterer's narrow-node reductions, above the per-box tag space [1..amr_max_blocks]; checked against MPI_TAG_UB at init.
integer, parameter m_amr_state::amr_band_reflux = 0
 Keyed wave tags: amr_tag_base + band*65536 + gen*4096 + seq, checked against MPI_TAG_UB. gen (mod 16) bumps per wave entry on every rank; seq is the message's index in the pair's canonically ordered transfer list (block id, dim, lo before hi), so matching is independent of posting order.
integer, parameter m_amr_state::amr_band_freg = 1
integer, parameter m_amr_state::amr_band_parent_fill = 2
integer, parameter m_amr_state::amr_band_stage_fill = 3
integer, parameter m_amr_state::amr_band_migrate = 4
integer, parameter m_amr_state::amr_band_seam = 5
integer, parameter m_amr_state::amr_band_restrict_l1 = 6
integer, parameter m_amr_state::amr_band_restrict_parent = 7
integer, parameter m_amr_state::amr_n_bands = 8
integer m_amr_state::amr_tag_base = 0
integer, dimension(0:amr_n_bands - 1) m_amr_state::amr_tag_gen = 0
integer, dimension(:,:), allocatable m_amr_state::amr_tsq
 (0:np-1, dir) in-wave per-peer seq counters; touched-reset
integer, dimension(:,:), allocatable m_amr_state::amr_tsq_tch
 touched peers per dir, so the reset is O(active peers), not O(P)
integer, dimension(2) m_amr_state::amr_n_tsq = 0
integer, dimension(:,:), allocatable m_amr_state::amr_ovl_gather
 cached per-block P2P overlap-rank lists, rebuilt with the seam list: amr_ovl_gather(:,k) = ranks whose owned coarse range meets block k's padded patch box; amr_ovl_scatter(:,k) = ranks whose coarse interior meets k's region box. Rank-ascending and not owner-excluded, so iterating gives the same MPI order as a 0..num_procs-1 scan. (max-overlap, amr_max_blocks); sized in s_amr_build_seam_pairs
integer, dimension(:,:), allocatable m_amr_state::amr_ovl_scatter
integer, dimension(:), allocatable m_amr_state::amr_my_blk
 Block indices this rank owns, ascending (the paired MPI_SENDRECVs depend on the order); built in s_amr_assign_block_owners.
integer m_amr_state::amr_n_my = 0
integer, dimension(:), allocatable m_amr_state::amr_l1r_blk
 Level-1 blocks this rank receives restriction for (not its own, overlapping its interior), rebuilt once per mesh epoch. Keyed on amr_mesh_epoch, not amr_myblk_dirty (owner writes only). Ownership here is amr_block_owner(k) == proc_rank, not the multi-owner amr_rank_owns_block.
integer, dimension(:), allocatable m_amr_state::amr_l1p_blk
 padded variant (region +/- amr_cpat_mar vs my coarse range): stage-fill gather
integer m_amr_state::amr_n_l1p = 0
integer m_amr_state::amr_n_l1r = 0
integer, dimension(:), allocatable m_amr_state::amr_fch_blk
 foreign children of my owned parents (level >= 2, powner == me, cowner /= me)
integer m_amr_state::amr_n_fch = 0
integer, dimension(:), allocatable m_amr_state::amr_own_blk
 blocks this rank intersects (amr_owns_all, the multi-owner notion, all levels)
integer m_amr_state::amr_n_own = 0
integer, dimension(:), allocatable m_amr_state::amr_parent_blk
 cached f_amr_parent_block (0 for level <= 1), avoiding an O(global blocks) scan per block per stage
integer, dimension(:), allocatable m_amr_state::amr_child_ptr
 children of p = amr_child_idx(amr_child_ptr(p-1)+1 : amr_child_ptr(p)), ascending
integer, dimension(:), allocatable m_amr_state::amr_child_idx
 (amr_child_ptr(0) = 0)
integer(8) m_amr_state::amr_l1r_epoch = -1_8
integer m_amr_state::amr_l1r_nblk = -1
 second key half, matching s_amr_reg_prepare's (epoch, num_blocks) pair
logical m_amr_state::amr_myblk_dirty = .true.
 Set wherever amr_block_owner is written (assigner, inheritance, restart/migration), so lists built from it never go stale.
integer, dimension(:), allocatable m_amr_state::amr_ovl_gather_n
integer, dimension(:), allocatable m_amr_state::amr_ovl_scatter_n
 per-block list lengths
real(wp), dimension(:), allocatable m_amr_state::amr_fw_sq
 Wire pools of the pooled waves (m_amr_wave lays them out; contents never survive a wave). The fill and restrict waves share amr_fw_sq/rq; the seam wave is posted before the fills and drained after, so it has its own pair. The zero-copy reflux waves list their blocks in amr_fw_rblk.
real(wp), dimension(:), allocatable m_amr_state::amr_fw_rq
real(wp), dimension(:), allocatable m_amr_state::amr_sw_sq
real(wp), dimension(:), allocatable m_amr_state::amr_sw_rq
real(wp), dimension(:), allocatable m_amr_state::amr_rf_sq
real(wp), dimension(:), allocatable m_amr_state::amr_rf_rq
 device-resident pools of the packed reflux-faces wave
integer, dimension(:), allocatable m_amr_state::amr_fw_rblk
logical m_amr_state::amr_fw_dev = .false.
 Device-resident wire pools: with rdma_mpi MPI sends/receives them by device address, and the step-path kernels find them present, so slices do not cross PCIe per wave.
integer m_amr_state::amr_sw_nsame = 0
 seam pairs both of whose blocks this rank owns: exchanged by one batched kernel at drain, no wire
integer, dimension(:), allocatable m_amr_state::amr_sw_plx
integer, dimension(:), allocatable m_amr_state::amr_sw_ply
integer, dimension(:), allocatable m_amr_state::amr_sw_pd
integer, dimension(:), allocatable m_amr_state::amr_sw_pxhi
integer, dimension(:,:), allocatable m_amr_state::amr_sw_pfm
integer, dimension(:,:), allocatable m_amr_state::amr_fx_pl
 Fused exchange packs (amr_device_pack): one row per wave transfer (slab corner (1:3), extents (4:6), payload offset in the wire pool (7); the child pack also has source store slot (8) and the child's patch frame (9:11)) plus the exclusive element prefix, so one kernel walks a family's transfers. Rebuilt per wave.
integer, dimension(:), allocatable m_amr_state::amr_fx_pre
integer(kind=8), dimension(:,:), allocatable m_amr_state::amr_fine_cut
 (0:num_procs-1, 1:amr_max_level) SFC Morton-key upper bound per rank, one independent cost-weighted cut per level (owner = cut search, f_amr_owner); O(P) storage. Per level because same-level boxes have distinct Morton keys, which the binary search needs.
integer, dimension(3) m_amr_state::amr_maxc_fit = 1
 Regrid box size cap per dim (fixed for the run, identical on all ranks; 1 in collapsed dims): a box of at most min-over-ranks of (local extent + 1)/2 cells intersects every rank in at most (its extent + 1)/2 cells, so the per-rank scratch constraint 2*(isect cells) - 1 <= local extent holds by construction. Equals amr_maxc at np=1.
integer m_amr_state::sw_m
 Swap contract (s_amr_swap_to_fine / s_amr_restore_coarse): the fine advance swaps these coarse globals to the block's values and restores after: m/n/p, idwint/idwbuff, the nine coordinate arrays (sw_x_cb..sw_dz), acoustic_source; WENO/hypoelastic/IGR spacing coefficients are recomputed instead. Any new module-level state derived from m/n/p/idwint/idwbuff/coords that a kernel reads on the fine grid must be swapped here or refreshed per fine call, including its device copy (a stale device copy reads out of range under CCE OpenACC; cv_int is refreshed by a per-call GPU_UPDATE in s_compute_rhs). amr_swap_depth makes the swap re-entrant and guards an unpaired restore. Saved coarse-level global state for swap/restore.
integer m_amr_state::sw_n
integer m_amr_state::sw_p
type(int_bounds_info), dimension(3) m_amr_state::sw_idwint
type(int_bounds_info), dimension(3) m_amr_state::sw_idwbuff
logical m_amr_state::sw_acoustic_source
real(wp), dimension(:,:,:), allocatable m_amr_state::sw_jac
 IGR sigma-state bounce: the fine solve reuses jac/jac_old at fine indices, so the coarse contents (jac_old is the Jacobi warm start) are saved here across the fine advance.
real(wp), dimension(:,:,:), allocatable m_amr_state::sw_jac_old
integer m_amr_state::amr_swap_depth = 0
 Swap nesting depth: only the outermost swap saves the coarse state and only its restore puts it back; inner swaps re-install, inner restores are no-ops.
real(wp), dimension(:), allocatable m_amr_state::amr_gxcb
 Global coarse cell-boundary arrays (-1:X_glb), assembled once at init; the fine-distribution owner rebuilds whole-block fine coordinates from them.
real(wp), dimension(:), allocatable m_amr_state::amr_gycb
real(wp), dimension(:), allocatable m_amr_state::amr_gzcb
real(wp), dimension(:), allocatable m_amr_state::sw_x_cb
real(wp), dimension(:), allocatable m_amr_state::sw_x_cc
real(wp), dimension(:), allocatable m_amr_state::sw_dx
real(wp), dimension(:), allocatable m_amr_state::sw_y_cb
real(wp), dimension(:), allocatable m_amr_state::sw_y_cc
real(wp), dimension(:), allocatable m_amr_state::sw_dy
real(wp), dimension(:), allocatable m_amr_state::sw_z_cb
real(wp), dimension(:), allocatable m_amr_state::sw_z_cc
real(wp), dimension(:), allocatable m_amr_state::sw_dz
logical m_amr_state::amr_xchg_coarse_ghosts = .false.
 True (identically on all ranks) iff some rank's fine ghost fill reads its coarse ghost cells: the solver populates only prim ghosts, so the cons ghosts must be halo-exchanged first. Never true at np=1.
integer m_amr_state::amr_xchg_bad = 0
 local accumulator behind amr_xchg_coarse_ghosts; s_amr_reduce_xchg_flag does one allreduce per scan
integer, dimension(:,:), allocatable m_amr_state::amr_slab_tab
 Per-block gathered coarse patch: the owner may not hold the coarse cells its block refines, so before each prolongation/ghost fill the patch region_lo-amr_cpat_mar : region_hi+amr_cpat_mar is gathered point-to-point into amr_cg (stp scalar_fields, block-local frame: cell 0 = global coarse cell amr_cpat_off(d)). Messages carry wp cast to stp, so at np=1 the patch equals the local coarse read bitwise. Sized to the largest block. amr_slab_tab: device-resident slab table for the shell/ghost kernels, rows lo(1:3),hi(1:3),soff,scnt over <= 6 slabs, refreshed by one GPU_UPDATE per launch.
integer m_amr_state::amr_slab_n = 0
 rows queued in amr_slab_tab (s_amr_slab_add)
integer m_amr_state::amr_cg_np = 1
 patches amr_cg holds, stacked along dim 3 (s_amr_cg_reserve)
integer m_amr_state::amr_cg_nuse = 0
 patches the level-1 pool gather filled (s_amr_l1_pool_gather)
integer, dimension(:), allocatable m_amr_state::amr_cg_pz
 dim-3 offset of each owned level-1 box's patch in the pool
type(scalar_field), dimension(:), allocatable m_amr_state::amr_cg
integer m_amr_state::amr_cpat_mar = 0
 coarse-cell stencil reach (f_amr_cpat_mar)
integer, dimension(3) m_amr_state::amr_cpat_hi = 0
 amr_cg upper local bounds per dim (0 in collapsed dims)
integer, dimension(3) m_amr_state::amr_cpat_off = 0
 global coarse index of amr_cg local cell 0 (region_lo - amr_cpat_mar)
integer m_amr_state::amr_wcur = 1
 consume cursor into the open fill wave's receive transfers (box-major)
real(stp), dimension(:), allocatable m_amr_state::amr_pc
 Subcycling patch cache: the pooled level-1 patches (amr_cg, amr_cg_nuse patches) at the step start (time level 0) then the step end (1), each flat with g1 fastest, then g2, g3, variable.

Detailed Description

Contains module m_amr_state.

Definition in file m_amr_state.fpp.f90.