Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 30 additions & 53 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,41 @@
# AGENTS.md
# FVdycoreCubed_GridComp: guide for agents

**Audience:** coding agents and developers working in the `FVdycoreCubed_GridComp` repository.
**Describes:** the MAPL3 line, branch `release/MAPL-v3`.
**Verified against:** `FVdycoreCubed_GridComp` @ `dadf5b5` (2026-11-06).
**Placement:** as in the GEOSgcm fixture (`components.yaml` @ `f50622d`).
Other fixtures (for example GEOSadas, GEOSldas) may place this repository
elsewhere; paths inside this repository do not change.
**Describes:** the MAPL3 line, branch `release/MAPL-v3`; verified against `FVdycoreCubed_GridComp` @ `4d7c4a3` (2026-11-10).
**Placement:** `src/Components/@GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSsuperdyn_GridComp/@FVdycoreCubed_GridComp` in the GEOSgcm fixture (`components.yaml`); other fixtures (GEOSfvdycore) may place it elsewhere. Paths below are relative to this repository.

## What this is
> **Built and ported on this line.** Superdyn builds this repository as its only subcomponent and adds `DYN` (`dyn.yaml`). `ADV` is compiled but Superdyn does not add it; the regression cases `adv-dyn` and `adv-sa` run it. The FV3 core `@fvdycore` is a separate nested repository; edit it only there. The Agcm that runs Superdyn is not compiled on this line, so `DYN` runs only in the regression cases.

The MAPL gridded-component wrapper of the GFDL FV3 cubed-sphere dynamical core,
at `src/Components/@GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSsuperdyn_GridComp/@FVdycoreCubed_GridComp`
in the GEOSgcm fixture (`components.yaml`, key `FVdycoreCubed_GridComp`). Parent:
`GEOS_SuperdynGridComp`. The core is the nested repository `@fvdycore`; edit it
only there.
## Rules for agents

> **Build status on this line:** built and ported to MAPL3. Superdyn's
> `CMakeLists.txt` builds it as the only `SUBCOMPONENT`; Superdyn adds `DYN`
> (config `dyn.yaml`) and runs the phases `run` and `run_add_incs`. `ADV` is
> compiled but not added by Superdyn; the regression case `adv-dyn` runs it.

## Documents

| Document | Content |
|---|---|
| [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) | Read first: `DYN`, `FV_StateMod`, state, tracers, `ADV`, configuration, build, regression, traps |
| [`docs/decisions.md`](docs/decisions.md) | Previous architectural decisions |
| `../../ARCHITECTURE.md` | Parent: Agcm and Superdyn |
| `regression/README.md` | CTest cases `adv-dyn`, `dyn-sa` |
- Read [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) (what `DYN` and `ADV` are and how they fit: grid, state, run phases, tracers, contracts, invariants) before changing phases, tracer handling, exports or configuration. Update it when the structure, a contract or an invariant changes; it describes only what changes rarely, so keep status and to-dos out of it.
- Note bugs and oddities; do not fix them unless asked. Record a bug or an open question as a GitHub issue, not in a document; a document may link to the issue.
- Do not edit the generated `*___.h` files; edit `DynCore_StateSpecs.rc` or `AdvCore_StateSpecs.rc`.
- When porting code to MAPL3, follow "Porting to MAPL3" in the `GEOSgcm_GridComp` `AGENTS.md` (`../../../AGENTS.md` in the fixture).
- Keep this file current: update it when status, a rule or a trap changes, and update its "verified against" commit.
- Cite files and routines, never line numbers. Label unchecked statements *Inferred:* or *Unverified:*.
- Error handling in code you write or touch uses the MAPL3 macros (`@MAPL/include/MAPL_ErrLog.h`): `_RC` on calls, `_STAT` on `allocate`, `_ASSERT(cond, msg)` with a message, and `_RETURN(_SUCCESS)` at every successful exit. Convert `RC=STATUS`/`VERIFY_`/`ASSERT_`/`RETURN_` in any routine you change. `_RC` expands to two statements (`rc=status);_VERIFY(status`), so it cannot end a one-line `if`; use a block `if`. Do not add decorative `!----` separator lines.

## Where things are
## Status and to-dos

| Want to change | Go to |
|---|---|
| Imports, exports, internal state | `DynCore_StateSpecs.rc` (`mapl_acg`); `AdvCore_StateSpecs.rc` |
| Run phases, tracer selection, tendencies | `DynCore_GridCompMod.F90` (`run`, `run_add_incs`, `add_incs`) |
| FV3 call, tracer packing, grid size | `FV_StateMod.F90` (`FV_Run`, `FV_Setup`) |
| Offline advection; shared tracer predicate | `AdvCore_GridCompMod.F90`; `fv_shared.F90` |
| Python gtFV3 core; regression; standalone scripts | `geos-gtfv3/`; `regression/`; `scripts/` |
- Superdyn accepts only `DYCORE: FV3`; its `FV3+ADV` and `DATMO` cases are commented out, but its block connecting `DYN`'s mass fluxes to `ADV` is still there, unreachable.
- Every regression case is `ADIABATIC: true` and cold-started (`COLDSTART: true`, `CASE_ID: 1`): the water-tracer packing in `FV_Run`, `add_incs` and restart reading are not exercised.
- `run` asserts that the import and export `TRADV` bundles share data (`MAPL_FieldBundleSameData`), because MAPL3 has no coupling for a service bundle yet.
- Not ported or not built: `Coldstart` as an entry point (it is called from `Initialize` instead), the `StandAlone_*.F90` drivers and several other tools (`CMakeLists.txt` lists what is built); `scripts/fv3.j` still writes MAPL2 `.rc` files for the unbuilt `StandAlone_FV3_Dycore.x`.

## Rules for changes
## Known traps

- Superdyn runs `DYN` phases `run` and `run_add_incs` and copies nothing; `DYN`
reads its own imports (`D_UV_DT`, `DTDT`, `DPEDT`, ...). `run` applies the
analysis/bias tendencies, `run_add_incs` the physics tendencies, both through
`add_incs`.
- Specs are edited in the `.rc` files, not by `MAPL_Add*Spec` calls.
- Keep the `ADV` imports (`MFX`, `MFY`, `CX`, `CY`, `PLE0`, `PLE1`) consistent
with `AdvCore_StateSpecs.rc` and the connections that fill them: the Superdyn
`FV3+ADV` connection block (live but unreachable) and `regression/adv-dyn/root.yaml`.
- `DYN` and `ADV` use one predicate, `field_is_cloud_water_species`
(`fv_shared.F90`), with opposite polarity.
- Tracers are not in the dycore restart; `DYN` borrows the `TRADV` fields.
- `DYN` and `ADV` share the module array `FV_Atm`.
- Files not in `CMakeLists.txt` are not compiled (architecture document,
section 2). `FV_PRECISION` is set by the fixture build.
- Error handling in code you write or touch uses the MAPL3 macros (`@MAPL/include/MAPL_ErrLog.h`): `_RC` on calls, `_STAT` on `allocate`, `_ASSERT(cond, msg)` with a message, and `_RETURN(_SUCCESS)` at every successful exit. Convert `RC=STATUS`/`VERIFY_`/`ASSERT_`/`RETURN_` in any routine you change. `_RC` expands to two statements (`rc=status);_VERIFY(status`), so it cannot end a one-line `if`; use a block `if`. Do not add decorative `!----` separator lines.
- **Five water species are required.** Unless `ADIABATIC`, `FV_Run` asserts that the tracers it receives include each of `Q`, `QLCN`, `QLLS`, `QICN` and `QILS` exactly once, and the packing then asserts that every tracer found a slot.
- **Tracers are found by name, but bundle fields have MAPL-generated names.** Use `get_short_name` (`standard_name`), never the field name.
- **`run` may return early.** If `RUN_DT` is longer than the parent step, `run` does nothing on most calls and leaves its exports unchanged, while `run_add_incs` adds tendencies on every call.
- **`ADV`'s behaviour depends on its own `DYCORE`.** With `FV3+ADV` it advects using the FV3 set-up of `DYN` (`adv-dyn`); with `DYCORE` unset it sets FV3 and its grid up itself (`adv-sa`); with `FV3` it does nothing (`AdvCore_Advection` is 0). Set it to match whether `DYN` is present and, when it is, to the same value as `DYN`'s.
- **The tracer split has two sides.** A change to `field_is_cloud_water_species` changes both what `DYN` keeps and what `ADV` advects.
- **`EXCLUDE_ADVECTION_TRACERS_LIST` must be a YAML sequence** (`[]` for none), read with `ESMF_HConfigAsStringSeq`; the adjusted bundle is built once, on the first `run`, and reused.
- **An unknown `EXCLUDE_ADVECTION_TRACERS` value** (other than `ALWAYS` or `PREDICTOR`) is meant to be ignored, but the code logs through an unassociated `logger` in `should_adjust_tracers`.
- **The Python core gets only seven tracers** (`q(:,:,:,1:7)` in `FV_Run`).
- **`FV_PRECISION` changes the build** (`R4`, `R4R8`, `R8`): FMS library, FV3 real kind and flags differ. CI runs the regression tests only on the R4 builds.

## Build and test

Built through Superdyn. Tests: CTest cases `adv-dyn` and `dyn-sa` (label
`REGRESSION`) and the CI builds in `.circleci/config.yml`. Executables:
`rs_scale.x`, `interp_restarts.x`; the `StandAlone_*.F90` drivers are not built.
- Built as part of a fixture (GEOSgcm, or GEOSfvdycore) through Superdyn; this repository has no standalone build. Executables: `rs_scale.x`, `interp_restarts.x`, and `fv3_driver.x` with `BUILD_GEOS_GTFV3_INTERFACE`.
- Regression tests (label `REGRESSION`): `regression/`, cases `adv-dyn`, `adv-sa`, `dyn-sa` (`cases.txt`); `regression/README.md` describes them. Each case directory has a `logging.yaml` (keep it in new cases). A case runs even when its baseline is missing; only the comparison is then skipped, and the comparison is done only for IntelLLVM (ifx) builds (`run_case.cmake`). `adv-sa` reads `adv-dyn`'s baseline exports as its input restart.
- Pull requests for this line target `release/MAPL-v3`, not `develop` (the MAPL2 line), and need a 0-diff label (`.github/workflows/enforce-labels.yml`). CI (`.circleci/config.yml`) builds the GEOSfvdycore fixture at `release/MAPL-v3` as R4 with ifx and gfortran (running the regression tests) and as R8 with ifx. Code owners: the FV3 gatekeepers, and the CMake team for `CMakeLists.txt` (`.github/CODEOWNERS`).
20 changes: 10 additions & 10 deletions DynCore_GridCompMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ subroutine run(gc, import, export, clock, rc)
! Add Analysis Tendencies
delpold = delp ! Old Pressure Thickness

call ADD_INCS(esmfgrid, self, import, dt, is_weighted=is_weighted)
call ADD_INCS(esmfgrid, self, import, dt, is_weighted=is_weighted, _RC)

if (DYN_DEBUG) call DEBUG_FV_STATE("ANA ADD_INCS", self)

Expand Down Expand Up @@ -2871,7 +2871,7 @@ subroutine run_add_incs(gc, import, export, clock, rc)

! Add Diabatic Forcing to State Variables
call MAPL_GridCompTimerStart(gc, "PHYS_ADD_INCS", _RC)
call ADD_INCS(esmfgrid, self, import, dt)
call ADD_INCS(esmfgrid, self, import, dt, _RC)
call MAPL_GridCompTimerStop(gc, "PHYS_ADD_INCS", _RC)

if (DYN_DEBUG) call DEBUG_FV_STATE('PHYSICS ADD_INCS', self)
Expand Down Expand Up @@ -3420,7 +3420,7 @@ subroutine add_incs(esmfgrid, self, import, dt, is_weighted, rc)
allocate(Q(is:ie, js:je, 1:km, nwat))
allocate(CVM(is:ie, js:je, 1:km))
Q(:, :, :, :) = 0.0
call PULL_Q(self, import, qqq, NXQ, in_field_name='Q', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='Q', _RC)
if (DYN_COLDSTART .and. overwrite_Q .and. (.not. ADIABATIC)) then
! USE Q computed by FV3
call getQ(Q(:, :, :, sphum), 'Q')
Expand All @@ -3444,29 +3444,29 @@ subroutine add_incs(esmfgrid, self, import, dt, is_weighted, rc)
end if
if (nwat >= 3) then
! Grab QLIQ from imports
call PULL_Q(self, import, qqq, NXQ, in_field_name='QLLS', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QLLS', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, liq_wat)) == size(qqq%content_r4)) Q(:, :, :, liq_wat) = Q(:, :, :, liq_wat) &
+ qqq%content_r4
elseif (associated(qqq%content)) then
if (size(Q(:, :, :, liq_wat)) == size(qqq%content)) Q(:, :, :, liq_wat) = Q(:, :, :, liq_wat) + qqq%content
end if
call PULL_Q(self, import, qqq, NXQ, in_field_name='QLCN', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QLCN', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, liq_wat)) == size(qqq%content_r4)) Q(:, :, :, liq_wat) = Q(:, :, :, liq_wat) &
+ qqq%content_r4
elseif (associated(qqq%content)) then
if (size(Q(:, :, :, liq_wat)) == size(qqq%content)) Q(:, :, :, liq_wat) = Q(:, :, :, liq_wat) + qqq%content
end if
! Grab QICE from imports
call PULL_Q(self, import, qqq, NXQ, in_field_name='QILS', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QILS', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, ice_wat)) == size(qqq%content_r4)) Q(:, :, :, ice_wat) = Q(:, :, :, ice_wat) &
+ qqq%content_r4
elseif (associated(qqq%content)) then
if (size(Q(:, :, :, ice_wat)) == size(qqq%content)) Q(:, :, :, ice_wat) = Q(:, :, :, ice_wat) + qqq%content
end if
call PULL_Q(self, import, qqq, NXQ, in_field_name='QICN', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QICN', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, ice_wat)) == size(qqq%content_r4)) Q(:, :, :, ice_wat) = Q(:, :, :, ice_wat) &
+ qqq%content_r4
Expand All @@ -3476,21 +3476,21 @@ subroutine add_incs(esmfgrid, self, import, dt, is_weighted, rc)
end if
if (nwat >= 6) then
! Grab RAIN from imports
call PULL_Q(self, import, qqq, NXQ, in_field_name='QRAIN', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QRAIN', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, rainwat)) == size(qqq%content_r4)) Q(:, :, :, rainwat) = qqq%content_r4
elseif (associated(qqq%content)) then
if (size(Q(:, :, :, rainwat)) == size(qqq%content)) Q(:, :, :, rainwat) = qqq%content
end if
! Grab SNOW from imports
call PULL_Q(self, import, qqq, NXQ, in_field_name='QSNOW', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QSNOW', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, snowwat)) == size(qqq%content_r4)) Q(:, :, :, snowwat) = qqq%content_r4
elseif (associated(qqq%content)) then
if (size(Q(:, :, :, snowwat)) == size(qqq%content)) Q(:, :, :, snowwat) = qqq%content
end if
! Grab GRAUPEL from imports
call PULL_Q(self, import, qqq, NXQ, in_field_name='QGRAUPEL', rc=rc)
call PULL_Q(self, import, qqq, NXQ, in_field_name='QGRAUPEL', _RC)
if ((qqq%is_r4) .and. (associated(qqq%content_r4))) then
if (size(Q(:, :, :, graupel)) == size(qqq%content_r4)) Q(:, :, :, graupel) = qqq%content_r4
elseif (associated(qqq%content)) then
Expand Down
Loading
Loading