Skip to content

Generalize kill-zone/tracer limits; size streamfunction zones adaptively#16

Open
hdrake wants to merge 1 commit into
TRACMASS:mainfrom
hdrake:generalize-killzone-tracer-limits
Open

Generalize kill-zone/tracer limits; size streamfunction zones adaptively#16
hdrake wants to merge 1 commit into
TRACMASS:mainfrom
hdrake:generalize-killzone-tracer-limits

Conversation

@hdrake

@hdrake hdrake commented Jun 22, 2026

Copy link
Copy Markdown

Summary

The streamfunction flux arrays and their per-zone loops were hard-coded to a fixed 21 kill zones, and the geographical kill-zone (10) and tracer (10) capacities were scattered as bare literals across many files (including the per-project kill_zones.F90). This generalizes those limits into named constants and sizes the streamfunction allocation to the zones a run actually uses.

This is the first of two planned changes; a follow-up will reduce the online streamfunction memory footprint (the 0:ntracmax flux dimension) using the maxlbas machinery introduced here.

Changes

  • Named capacity constants in mod_precdef: MAXGEOZONES, MAXTRACERS, and MAXZONES = 1 + MAXTRACERS + MAXGEOZONES, used to dimension the kill-zone and tracer configuration arrays.
  • Adaptive maxlbas: the actual number of streamfunction zones is computed from the run — namelist geographic zones + subdomain wall zones + tracer kill zones — and finalized in init_subdomain once exitType and all zones are known. The offline flux arrays and the compute_stream loop now size to maxlbas instead of a fixed 21.
  • Derive from SIZE(): runtime loop bounds and the subdomain "last 4" wall slots are derived from SIZE() of the arrays, removing hard-coded slot numbers (7–10) and 1,10 loops in mod_subdomain, kill_zones.F90 (×5), mod_diffusion, and mod_init.
  • Well-defined defaults: ienw/iene/jens/jenn are initialized to 0 so "undefined slot" is well-defined.

Bug fixes

  • Latent out-of-bounds when the configured zone count differs from 21.
  • Under-allocation when an exitType=2 run uses a subdomain (which promotes exitType to 3 and adds geographic walls) — now correct because maxlbas is finalized in init_subdomain after the promotion.

Behavior

Unchanged for valid configs. The streamfunction output (psi_*.csv) now contains the actual number of zone blocks instead of always 21 (e.g. 2 for a single kill-zone, 9–11 for subdomains). Verified byte-identical to the previous output for the real (non-empty) zones; the dropped trailing zones were always zero.

Testing

  • Clean build (Theoretical project, gfortran -fbounds-check), no warnings.
  • Regression: single kill-zone → maxlbas=2, psi_* byte-identical to baseline for real zones.
  • Subdomain box → maxlbas=11; full-width subdomain (E/W walls skipped) → maxlbas=9; both run clean under bounds-checking.
  • The change is size-preserving by construction (MAXGEOZONES=MAXTRACERS=10, MAXZONES=21).
  • Note: the tracer-array changes compile clean and are size-preserving, but were not exercised by a tracer-enabled run (the Theoretical project ships no tracer fields).

🤖 Generated with Claude Code


Addresses #19.

The streamfunction flux arrays and their per-zone loops were hard-coded to
a fixed 21 kill zones, and the kill-zone (10) and tracer (10) capacities
were scattered as bare literals across many files (including per-project
kill_zones.F90). This generalizes those limits and sizes the streamfunction
allocation to the zones a run actually uses.

- Add named capacity constants in mod_precdef: MAXGEOZONES, MAXTRACERS, and
  MAXZONES = 1 + MAXTRACERS + MAXGEOZONES, used to dimension the kill-zone
  and tracer configuration arrays.
- Compute maxlbas (the actual streamfunction zone count) from the run:
  namelist geographic zones + subdomain wall zones + tracer kill zones,
  finalised in init_subdomain once exitType and all zones are known. The
  flux arrays (offline) and the compute_stream loop now size to maxlbas
  instead of a fixed 21.
- Derive runtime loop bounds and the subdomain "last 4" wall slots from
  SIZE() of the arrays, removing the hard-coded slot numbers (7-10) in
  mod_subdomain and the 1,10 loops in kill_zones.F90 (x5), mod_diffusion,
  and mod_init.
- Initialise ienw/iene/jens/jenn to 0 so undefined slots are well-defined.

Fixes a latent out-of-bounds when the configured zone count differs from
21, and an under-allocation when an exitType=2 run uses a subdomain (which
promotes exitType to 3 and adds geographic walls). Behaviour is otherwise
unchanged: streamfunction output now contains the actual number of zone
blocks, verified byte-identical to the previous output for the real zones.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@hdrake

hdrake commented Jun 22, 2026

Copy link
Copy Markdown
Author

Indirectly addresses #5 by making the dimensions of the output more intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant