diff --git a/AGENTS.md b/AGENTS.md index 39483007..ffb4228b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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`). diff --git a/DynCore_GridCompMod.F90 b/DynCore_GridCompMod.F90 index 2a5371cf..a4599ed9 100644 --- a/DynCore_GridCompMod.F90 +++ b/DynCore_GridCompMod.F90 @@ -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) @@ -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) @@ -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') @@ -3444,14 +3444,14 @@ 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 @@ -3459,14 +3459,14 @@ subroutine add_incs(esmfgrid, self, import, dt, is_weighted, rc) 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 @@ -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 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 84095205..ff5d0c71 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1,429 +1,69 @@ -# FVdycoreCubed_GridComp: MAPL wrapper of the FV3 dynamical core +# FVdycoreCubed_GridComp architecture -**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. +A map of the repository: what lives where, how the pieces fit, and what must not break. Paths are relative to the repository root. It names modules and routines rather than linking to lines; use them to search the code. It describes only things that change rarely; status, rules for changes, known traps and to-dos are in [`AGENTS.md`](../AGENTS.md). -> **Build status on this line:** built and ported to MAPL3. -> `GEOSsuperdyn_GridComp/CMakeLists.txt` lists `FVdycoreCubed_GridComp` as the -> only entry of `alldirs` (`GEOSdatmodyn_GridComp` is commented out: "not yet -> ported to MAPL3") and builds it as a `SUBCOMPONENT` of the library -> `GEOS_SuperdynGridComp`. Superdyn adds `DYN` (config file `dyn.yaml`) and -> runs it with the phases `run` and `run_add_incs`. `ADV` is compiled into this -> repository's library but Superdyn does not add it (section 7). +## Bird's-eye view -Paths are relative to the `FVdycoreCubed_GridComp` repository root. Parent -composite: `GEOSagcm_GridComp/ARCHITECTURE.md` (`../../../ARCHITECTURE.md` in -the fixture), section on Superdyn. Repository overview one level up: -`GEOSgcm_GridComp/docs/ARCHITECTURE.md` (`../../../../docs/ARCHITECTURE.md` in the fixture). +This repository wraps the GFDL FV3 cubed-sphere dynamical core as MAPL components. In GEOS its main component is `DYN`, the child of Superdyn (`GEOS_SuperdynGridComp`, in `GEOSgcm_GridComp`); the Agcm runs Superdyn twice per step, once to advance the resolved flow (with analysis increments) and once to add the physics tendencies. The core itself is the nested repository `@fvdycore`; this repository holds the MAPL layer (`DYN`), the bridge to the core's data structures (`FV_StateMod`), an offline tracer-advection component (`ADV`), restart tools and an optional Python core. -"Agcm" is `GEOS_AgcmGridComp`; "Superdyn" is `GEOS_SuperdynGridComp`. A -`(file, routine)` citation means the statement was checked there; *Inferred:* -and *Unverified:* mark weaker statements. +The defining design choice: the dynamics state lives in MAPL's internal state, which `FV_StateMod` copies into the FV3 core before each step and back after it, while the tracers stay with the components that own them and are lent to the core through the `TRADV` service. -## 0. Differences from the MAPL2 line +## Codemap -- Specs are in `DynCore_StateSpecs.rc` and `AdvCore_StateSpecs.rc` (`mapl_acg`), not `MAPL_Add*Spec` calls; `DUDT`, `DVDT` are the vector import `D_UV_DT`. -- Entry points are phases `run` and `run_add_incs`; Superdyn copies no tendencies into `DYN`. -- Grid size and layout come from the config `geometry:` section, not `AGCM_IM`, `NX` and similar keys. -- `DYN` and `ADV` share one tracer predicate (`fv_shared.F90`). -- Intermittent replay, `TRADVEX`, the standalone executables and many regridding helper sources are gone; regression cases `adv-dyn`, `dyn-sa` exist. +- `DynCore_GridCompMod.F90`, `DynCore_StateSpecs.rc`: `DYN`. `SetServices`, `Initialize`, phases `run` and `run_add_incs`, `Finalize`; `add_incs` applies tendencies; `Coldstart` builds an idealized state; tracer handling (`should_adjust_tracers`, `get_adjusted_tracer_bundle`, `PULL_Q`). +- `FV_StateMod.F90`: the bridge to FV3. `FV_Setup`, `FV_InitState`, `FV_Run`, `FV_Finalize`, `State_To_FV`, `FV_To_State`; the module array `FV_Atm` (the FV3 state). +- `AdvCore_GridCompMod.F90`, `AdvCore_StateSpecs.rc`: `ADV`, offline tracer advection from `DYN`'s mass fluxes (`offline_tracer_advection` in `@fvdycore`). +- `fv_shared.F90`: helpers both components use: `field_is_cloud_water_species`, `get_short_name`, `is_name_in_list`. +- `@fvdycore/`: the FV3 core (GFDL_atmos_cubed_sphere, branch `geos/release/MAPL-v3`), a separate nested repository built into this library. +- `geos-gtfv3/`: optional bridge to a Python FV3 core (built with `BUILD_GEOS_GTFV3_INTERFACE`), and its standalone driver `fv3_driver.x`. +- `rs_scale.F90`, `rs_scaleMod.F90`, `interp_restarts.F90` (with the grid and regridding helpers `AppGridCreate.F90`, `CubeHalo.F90`, `GetWeights*.F90`, `fv_regrid*.F90`): the restart tools `rs_scale.x` and `interp_restarts.x`. +- `sw.f90`, `jw.f90`, `testcases_3_4_5_6_stand_alone.f90`: idealized initial states for `Coldstart`. +- `regression/`: standalone regression cases. `scripts/`: the MAPL2-era `fv3_setup` and `fv3.j`. -## 1. Purpose and placement +## How it is put together -This repository is the MAPL gridded-component layer around the GFDL FV3 -cubed-sphere dynamical core. The core itself is the nested repository -`@fvdycore` (section 9), built into the same library (`CMakeLists.txt`, -`SUBCOMPONENTS fvdycore`). +- **Placement.** Superdyn adds `DYN` with configuration `dyn.yaml` when `DYCORE` is `FV3` (any other value stops). It runs `DYN` phase `run` from its own `run` and phase `run_add_incs` from its own `run_add_incs`, and re-exports `DYN`'s state and `TRADV`. Each component also has an external `SetServices` wrapper (`fvdycorecubed_setservices_`, `advcore_setservices_`) for loading by name from `libFVdycoreCubed_GridComp`. +- **Grid.** `DYN` takes its cubed-sphere grid and levels from its configuration (`geometry:` with `esmf_geom: class: CubedSphere`, `im_world`, `nx_face`, `ny_face`, and `vertical_grid: num_levels`): `MAPL_GridCompSetGeometry` builds the ESMF grid and `FV_Setup` sizes FV3 from the same keys. One level means shallow-water dynamics. +- **State.** The internal state (`AK`, `BK`, D-grid `U`, `V`, `PT`, `PE`, `PKZ`, and non-hydrostatic `W`, `DZ`) holds FV3's prognostic state: `FV_InitState` points the bridge's `STATE%VARS` at it, `State_To_FV` copies it into `FV_Atm` before each step and `FV_To_State` copies it back. The MAPL internal restart is therefore the dycore restart. +- **`run`.** Returns unless its own alarm `Time2Run` (`RUN_DT`) rings. Otherwise it lends the tracers (below), applies the analysis or bias increments `D_UV_DT`, `DTDT`, `DPEDT` through `add_incs` (not with `FV3_STANDALONE`, after the `ReplayShutOff` alarm rings, with `ADIABATIC`, or without `DO_ADD_INCS`), calls `FV_Run`, and fills the exports, including the mass fluxes and Courant numbers `MFX`, `MFY`, `CX`, `CY` and the edge pressures `PLE0`, `PLE1` that `ADV` uses. +- **`run_add_incs`.** On every call (except for shallow-water dynamics): adds the physics tendencies through `add_incs` (winds converted from the A grid to the D grid, `PE`, `PT` and `PKZ` updated; tracers untouched), then recomputes the dependent exports. +- **`FV_Run`.** Packs the tracers into `FV_Atm%q`, copies the state in (`State_To_FV`), runs `fv_dynamics` (or the Python core), unpacks the tracers and copies the state back (`FV_To_State`). Water species are packed by name: liquid, ice and cloud fraction are each the sum of their convective and large-scale parts, with the convective part carried as an extra tracer and the large-scale part recovered after the step. +- **Tracers.** `TRADV` is a service `DYN` provides: each owner subscribes the tracers it wants advected, and `DYN` finds them in the bundle, by name through `standard_name` (`get_short_name`). `DYN` keeps no tracers of its own and frees its pointers after each phase. +- **`ADV`.** With `DYCORE: FV3+ADV`, `DYN` keeps only the cloud and water species (`field_is_cloud_water_species`), and `ADV`, which also provides `TRADV`, advects the rest with `DYN`'s mass fluxes. When `ADV`'s configuration has no `DYCORE`, it sets up FV3 and its grid itself, and its mass-flux imports come from elsewhere (a data component in `adv-sa`); with `DYCORE: FV3` it does nothing. Superdyn does not add `ADV` on this line. -In the GEOSgcm fixture the repository is at -`src/Components/@GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSsuperdyn_GridComp/@FVdycoreCubed_GridComp` -(`components.yaml`, key `FVdycoreCubed_GridComp`). Superdyn imports `SetServices` -from the Fortran module `FVdycoreCubed_GridComp` (the `DYN` component) and adds -`DYN` with `MAPL_GridCompAddChild(gc, "DYN", FV3_SetServices, "dyn.yaml")` when -`DYCORE:` (default `FV3`) is `FV3`; any other value fails -(`GEOS_SuperdynGridComp.F90`, `SetServices`, the `select case (trim(dycore))`). The `use` of -`AdvCore_GridCompMod` and the `FV3+ADV` and `DATMO` cases are commented out. +## Contracts -Each component has an external-procedure wrapper for loading from a shared -object: `FVdycoreCubed_SetServices` and `AdvCore_SetServices` (end of the -respective files); the regression cases name them in YAML -(`fvdycorecubed_setservices_`, `advcore_setservices_`, in -`libFVdycoreCubed_GridComp`). +### Imports of `DYN` -## 2. Directory and file map +- From the Agcm (MAPL2 code, not compiled on this line): analysis or bias increments `D_UV_DT` (a vector), `DTDT`, `DPEDT`, and the `DQ*ANA` and `DOXANA` moisture and ozone increments (diagnostics only); the surface geopotential `PHIS` and the variance of the filtered topography `VARFLT`. `DWDT` is declared but not applied. +- Through `TRADV`: every advected tracer, from the components that own it (Moist, Chemistry, ...). -| Path | Content | -|---|---| -| `DynCore_GridCompMod.F90` | `DYN` component, about 5000 lines. Only `SetServices` is public | -| `DynCore_StateSpecs.rc`, `AdvCore_StateSpecs.rc` | Import, export and internal specs of `DYN` and `ADV` (`mapl_acg`) | -| `FV_StateMod.F90` | `FV_Setup`, `FV_InitState`, `FV_Run`, `FV_Finalize`, `State_To_FV`, `FV_To_State`; module-level array `FV_Atm` | -| `AdvCore_GridCompMod.F90` | `ADV` component | -| `fv_shared.F90` | Tracer-name helpers used by `DYN` and `ADV` | -| `rs_scale*.F90`, `interp_restarts.F90` | Restart tools built here (section 10) | -| `AppGridCreate.F90`, `CubeHalo.F90`, `GetWeights*.F90`, `fv_regrid*.F90`, `fv_regridding_utils.F90` | Grid creation and regridding helpers | -| `sw.f90`, `jw.f90`, `testcases_3_4_5_6_stand_alone.f90` | Idealized cases used by `Coldstart` | -| `GEOS_FV3_Utilities.F90` | Utility module (`a2d2c`) | -| `regression/` | CTest cases (section 12) | -| `.circleci/config.yml`, `.github/` | CI, `CODEOWNERS`, workflows | +### Exports of `DYN` -Not listed in `CMakeLists.txt` (not built): `c2c_rst.F90`, `c2l_CFIO_offline.F90`, -`CreateTopography.F90`, `dyn_interp_rst.F90`, `moist_interp_rst.F90`, -`ESMF_GenerateCSGridDescription.F90`, the four `StandAlone_*.F90`, `.cppdefs`, -`FVdycore_arch.mk`. *Inferred:* legacy or manually built tools. +- The dynamics state that Physics imports through Superdyn: `UV`, `T`, `PLE`, `ZLE`, `PREF`, `DELP`, `OMEGA`, `PS`, `AK`, `BK`, ...; pre-dynamics (`*_DYN_IN`) and tendency diagnostics; energetics. +- For `ADV`: `MFX`, `MFY`, `CX`, `CY`, `PLE0`, `PLE1` (`R8`). -## 3. The DYN component +### Services -### 3.1 How it is called +- `DYN` provides `TRADV` (advection); `ADV` provides `TRADV` too. Neither subscribes to any service. -Superdyn runs `DYN` as a child (`GEOS_SuperdynGridComp.F90`): +## Invariants -| Phase | Routine | Called by | Does | -|---|---|---|---| -| `run` | `run` | Superdyn `run`: `MAPL_GridCompRunChild(gc, "DYN", phase_name="run")` | Applies the analysis/bias tendencies, advances the FV3 state one dynamics step, fills exports | -| `run_add_incs` | `run_add_incs` | Superdyn `run_add_incs` | Adds the physics tendencies to the FV3 state, recomputes exports | +- Tracers are never in the dycore restart; their owners keep them. +- `DYN` and `ADV` share one FV3 state (`FV_Atm` is module data in `FV_StateMod`), and one definition of which tracers stay in the core (`field_is_cloud_water_species`, used with opposite polarity). +- Physics tendencies reach the dynamics state only in `run_add_incs`; analysis increments only in `run`. +- `run` works only when `Time2Run` rings; `run_add_incs` works on every call. -Superdyn `run` runs `ADV` only if its module variable `ADV` is not -1; it is -initialized to -1 and never assigned (`GEOS_SuperdynGridComp.F90`, module -variable `ADV` and `run`). Superdyn registers no imports and copies no tendencies into `DYN`: -`DYN` declares its own imports (3.2) and relies on connections to fill them. -`GEOS_AgcmGridComp.F90` (in `GEOSgcm_GridComp`, `GEOSagcm_GridComp/`) still calls -the Superdyn child with `ESMF_GridCompRun(..., PHASE=1)` in `Run`, the MAPL2 -interface, and fills `DUDT`, `DVDT`, `DPEDT` with the `DO_UPDATE_ANA3D` calls -in `Run`. *Unverified:* what fills the `DYN` imports `D_UV_DT`, `DTDT`, -`DPEDT`, `DQ*ANA`, `DOXANA`, `PHIS`, `VARFLT` in the full GCM. In `adv-dyn`, -connections from data components fill `PHIS`, `VARFLT` and the six `DQ*ANA` -(`regression/adv-dyn/root.yaml`). +## Cross-cutting concerns -### 3.2 SetServices +- **Generated specs:** `DYN` and `ADV` declare their specs in `*_StateSpecs.rc` (ACG). `TRADV` and `ADV`'s `TEST_TRACER*` diagnostics are added in `SetServices`. +- **Precision:** `FV_PRECISION` (`R4`, `R4R8`, `R8`), set by the fixture build, chooses the FMS library and the FV3 real kind; the internal state is `R8`. +- **Configuration:** resource keys are read from the component's configuration (`dyn.yaml` under Superdyn); the main ones are `DYCORE`, `AdvCore_Advection`, `RUN_DT`, `FV3_CONFIG`, `ADIABATIC`, `COLDSTART` and `CASE_*`, `FV3_STANDALONE`, `DO_ADD_INCS`, `ANA_IS_WEIGHTED`, `REPLAY_SHUTOFF`, `EXCLUDE_ADVECTION_TRACERS[_LIST]`, `RUN_GTFV3`. +- **Testing:** each regression case runs `DYN`, `ADV` or both for one hour (two or three steps) under a configurable Root, with data components that own the tracers (and, for `adv-sa`, provide the mass fluxes), and compares the checkpoints exactly against a stored baseline. -(`DynCore_GridCompMod.F90`, `SetServices`) +## Where to go next -- Specs come from `DynCore_StateSpecs.rc` through the generated includes - `DynCore_Import___.h`, `DynCore_Export___.h`, `DynCore_Internal___.h` - (`mapl_acg` in `CMakeLists.txt`). -- Imports (13 specs): `D_UV_DT` (vector wind tendency), `DWDT`, `DTDT`, `DPEDT`, - `DQVANA`, `DQLANA`, `DQIANA`, `DQRANA`, `DQSANA`, `DQGANA`, `DOXANA`, `PHIS`, - `VARFLT`. Only `VARFLT` sets `RESTART` (`SKIP`). -- `TRADV`: added in code as an export spec with `itemtype=MAPL_STATEITEM_SERVICE`; - a service item appears in both the import and the export state (source - comment). Section 6. -- Exports (206 rows in `DynCore_StateSpecs.rc`): `CX`, `CY`, `MFX`, `MFY` (R8), - `PLE0`, `PLE1` (inputs of `ADV`), the state (`UV` vector, `T`, `Q`, `W`, - `ZLE`, ...), grid and vertical coordinates, the `*_DYN_IN` set, tendency and - energetics diagnostics. -- Internal state (section 5); private state `DynState` named `DYN_STATE`. -- Registers `Initialize`, `run`, `run_add_incs`, `Finalize`; the `Coldstart` - entry point is commented out. `MAPL_GridCompSetGeometry` builds the grid from - the config (section 8). Reads `FV3_STANDALONE:`, `DEBUG_DYN:`, `DEBUG_ADV:`, - `DEBUG_TQ_ERRORS:`. - -### 3.3 Initialize - -(`DynCore_GridCompMod.F90`, `Initialize`) - -1. `DynSetup` (alias for `FV_Setup`, section 4), timed `DYN_SETUP`. -2. Reads `DO_ADD_INCS:` and `COLDSTART:`. A nonzero `COLDSTART` calls `Coldstart` - (idealized state from `CASE_*`, `T0:`, `IM:`, `JM:`). -3. `DynInit` (alias for `FV_InitState`): connects `STATE%VARS` to the MAPL - internal-state arrays, creates the alarm "Time2Run" at `RUN_DT:` and a - six-hour dry-mass alarm, sets `FV_Atm%phis`, `varflt`, `ak`, `bk`, calls - `State_To_FV`, and under `RUN_GTFV3` `geos_gtfv3_interface_f_init`. -4. Fills the exports `PREF`, `UV` (if present), `T`, `DXC`, `DYC`, `AREA`. -5. Creates the sticky alarm "ReplayShutOff" (`REPLAY_SHUTOFF:`, default -3600; - the absolute value in seconds is the ring interval). - -There is no explicit `MAPL_GenericInitialize` call. *Inferred:* the framework -handles the internal-state restart. - -### 3.4 run (phase `run`) - -(`DynCore_GridCompMod.F90`, `run`) - -1. Returns at once if the "Time2Run" alarm is not ringing (the dycore step may - be longer than the parent's, `RUN_DT:`). -2. Gets `TRADV` from the import and export state and asserts the two bundles - hold the same data (`MAPL_FieldBundleSameData`; a source comment says there - is no coupling mechanism yet). If `EXCLUDE_ADVECTION_TRACERS` asks for it - (`should_adjust_tracers`), the export bundle is replaced by an adjusted - bundle `xTRADV` (section 6); `PULL_Q` points `STATE%VARS%tracer(:)` at the - bundle fields. -3. The "WMP REPLAY/ANA" section runs when `FV3_STANDALONE` is false and the - `ReplayShutOff` alarm is not ringing. Intermittent-replay code is not in this - file (a comment: "we are not doing this anymore, right?"). If `DO_ADD_INCS` - (default true) and not `ADIABATIC`, the imports `D_UV_DT`, `DPEDT`, `DTDT` - are applied with `add_incs` (`ANA_IS_WEIGHTED:`, default `NO`, must be `YES` - or `NO`, selects mass-weighted temperature tendencies). `DQVANA` etc. rebuild - the pre-increment moisture state (`QVOLD = QV - DQVANA`) for diagnostics; - `add_incs` does not change the tracers. -4. Fills the `*_DYN_IN` exports. -5. Calls `DynRun` (alias for `FV_Run`, section 4) with `PLE0` the edge pressure - before the step. -6. Fills the exports (`PLE0`, `PLE1`, `CX`, `CY`, `MFX`, `MFY`, `UV`, `T`, `Q`, - `PLE`, diagnostics), the mass fluxes from `fillMassFluxes` or, for - `AdvCore_Advection == 2`, `computeMassFluxes`; then `free_tracers`. - -### 3.5 run_add_incs (phase `run_add_incs`) - -(`DynCore_GridCompMod.F90`, `run_add_incs`) - -- Skipped if `SW_DYNAMICS`. Only `run` checks the Time2Run alarm. -- `PULL_Q`, then (if `DO_ADD_INCS` and not `ADIABATIC`) `add_incs` adds the - physics tendencies (timer `PHYS_ADD_INCS`): `D_UV_DT` is converted from the A - grid to the native D grid with `Agrid_To_Native` (`wind_increment_limiter = - 800.d0/86400.d0`, section 16); `PE` is advanced by `DT*DPEDT`; `PT` is - re-weighted by old and new `DP` and `cp/cvm`; `getPKZ` recomputes `PKZ`. The - tracers are not changed. The use of `DWDT` in `add_incs` is commented out. -- Recomputes the dependent exports (`U_DGRID`, `ZLE`, `PLE`, `PKE`, `KEPHY`, - `PEPHY`, `TEPHY`, ...), then frees the tracer pointers. - -### 3.6 Finalize - -`DynFinalize` (alias for `FV_Finalize`: `fv_end`, and the gtFV3 finalize under -`RUN_GTFV3`). - -## 4. FV_StateMod: the bridge to the FV3 core - -(`FV_StateMod.F90`) - -`FV_Atm(:)` is a module-level `save` array of the FV3 type `fv_atmos_type` -(`@fvdycore`, `fv_arrays_mod`). `AdvCore_GridCompMod` uses the same array -(`use FV_StateMod, only: FV_Atm`), so `DYN` and `ADV` share one FV3 state. - -**`FV_Setup`** (called from `Initialize`): `fms_init`, `fv_init1`; takes the -grid size and layout from the component's config (`MAPL_GridCompGet` with -`hconfig`, `num_levels`; `setup_fv_dimensions_and_topology` reads -`geometry: esmf_geom:` `im_world`, `nx_face`, `ny_face`; `npz==1` selects -`SW_DYNAMICS`); reads `AGCM.STRETCH_FACTOR`, `FIXED_LATS`, `RUN_DT:`, -`DYCORE:` and sets `AdvCore_Advection` (0 for -`FV3`, 1 for `FV3+ADV`), which the resource `AdvCore_Advection:` may override -(2 selects time-centered mass fluxes); reads `ADIABATIC:`, `FV_OFF:`, -`fix_mass:` (default 1), `FV3_CONFIG:` (default `STOCK`; a string containing -`MONOTONIC` or `MERRA-2` selects hydrostatic, monotonic schemes) and -resolution-dependent defaults; then `fv_init2`. - -**`FV_Run`** (called every dynamics step, first time with extra set-up): - -1. First call, and only when not `ADIABATIC`: counts the water tracers - (`Q`, `QLCN`, `QLLS`, `QICN`, `QILS` must be present: asserts - `nwat_tracers == 5`; then `CLLS`, `CLCN`, `QRAIN`, `QSNOW`, `QGRAUPEL` are - counted too) and, if `flagstruct%nwat` is 0, sets it to 1 (3 if - non-hydrostatic; 6 when `nwat_tracers >= 10`) and `STATE%VARS%nwat`. -2. Sets `FV_Atm%phis` and `varflt` from the imports; packs the tracers into - `FV_Atm%q` (section 6). -3. `State_To_FV` copies the MAPL arrays into the FV3 state; dry mass fixed to - `PSDRY:`, mass check/fix under `MASSALARM`; first non-hydrostatic call: - `Make_NH`, `na_init`, `adiabatic_init`. -4. `fv_dynamics` (or `geos_gtfv3_interface_f` when `run_gtfv3 /= 0`, section 11). -5. Fills the Rayleigh-friction tendencies (`DUDT_RAY`, ...); `fv_subgrid_z` when - `fv_sg_adj > 0`; unpacks the tracers back; `FV_To_State`. - -If `ADIABATIC:` is nonzero the tracers are passed through in order. - -## 5. State and restarts - -Internal state of `DYN` (`DynCore_StateSpecs.rc`, `category: INTERNAL`): - -| Name | Notes | -|---|---| -| `AK`, `BK` | Vertical-only, edge; `RESTART` required; `ADD2EXPORT` true | -| `U`, `V`, `PT`, `PE`, `PKZ` | D-grid winds, scaled potential temperature (K Pa^-kappa), edge pressure, `pk` exponent; R8; `RESTART` required. `PE` is also exported as `PLE` | -| `DZ`, `W` | Non-hydrostatic; R8; no `RESTART` entry | - -`FV_InitState` wires the FV3 state arrays to these MAPL arrays -(`FV_StateMod.F90`), so once a restart is read the FV3 core sees the values. -The regression cases enable the internal checkpoint in the component YAML -(`mapl: misc: checkpoint: internal: true`). The dycore state holds no tracers: -the components that own them keep them, and `DYN` borrows pointers through -`TRADV`. `free_tracers` only deallocates and nullifies the FV tracer pointers -(a comment there says "Comment out to output tracer to checkpoint file"). -`COLDSTART:` builds an idealized state instead of reading a restart; both -regression cases use it (`COLDSTART: true`, `CASE_ID: 1`). - -## 6. Tracers: the `TRADV` bundle - -`TRADV` is the dycore's bundle of all advected tracers, a service item in both -the import and export state of `DYN` (3.2). It is filled by connecting `TRADV` -of the owning component to `TRADV` of `DYN` (`regression/*/root.yaml`: -`DataMoist`, and for `adv-dyn` also `DataTracers` and `ADV`). Superdyn -re-exports `TRADV` from `DYN` (`MAPL_GridCompReexport`). - -Selection in `DYN` (`run`, `should_adjust_tracers`, `get_adjusted_tracer_bundle`): - -- `EXCLUDE_ADVECTION_TRACERS:` (default `ALWAYS`; `PREDICTOR` uses the clock - alarm `PredictorAlarm`; other values are ignored) decides whether the bundle - is adjusted. `EXCLUDE_ADVECTION_TRACERS_LIST` is a YAML sequence in the - component config (`ESMF_HConfigAsStringSeq`; `[]` in the regression cases). -- When `AdvCore_Advection >= 1`, every tracer for which - `field_is_cloud_water_species` (`fv_shared.F90`) is false is excluded. It is - true for `Q`, `QLCN`, `QLLS`, `QICN`, `QILS`, `CLCN`, `CLLS`, `NCPL`, `NCPI`, - `QRAIN`, `QSNOW`, `QGRAUPEL`. Names come from the field `standard_name` - (`get_short_name`). -- The remaining fields go into a saved module bundle `bundle_adv` (`xTRADV`), - and `PULL_Q` points `STATE%VARS%tracer(:)` at them. - -Packing in `FV_Run` (`FV_StateMod.F90`): `QLCN`/`QLLS` are summed into the -liquid slot, `QICN`/`QILS` into ice, `CLCN`/`CLLS` into cloud fraction; the -convective parts are carried as extra tracers (`idx_qlcn`, `idx_qicn`, -`idx_clcn`); `QRAIN`, `QSNOW`, `QGRAUPEL` have their own slots; other tracers -take the next free index; the final count must equal `ncnst` (asserted). After -`fv_dynamics` the large-scale part is total minus convective, bounded below by -zero. - -With `DYCORE: FV3` every tracer in `TRADV` (minus the exclude list) is advected -inside `fv_dynamics`; with `FV3+ADV` only the species above stay there and `ADV` -handles the rest (section 7). - -## 7. The ADV component - -(`AdvCore_GridCompMod.F90`, `AdvCore_StateSpecs.rc`) - -Offline tracer advection driven by the mass fluxes of `DYN`. In -`GEOS_SuperdynGridComp.F90` the `ADV` `MAPL_GridCompAddChild` in `SetServices` is commented -out, but the `if (adjustl(DYCORE) == "FV3+ADV")` block that connects `MFX`, -`MFY`, `CX`, `CY`, `PLE0`, `PLE1` to `ADV` (in `SetServices`) is live and unreachable, -since any `DYCORE` other than `FV3` hits `_FAIL`. `ADV` is added by the -regression case `adv-dyn` (`root.yaml`, child `ADV` with `adv.yaml`). - -- Imports (R8): `MFX`, `MFY`, `CX`, `CY`, `PLE0`, `PLE1`; `TRADV` is a service - item as in `DYN`. Exports: `AREA` and 38 `TEST_TRACER*` diagnostics - (`ntracers = 38`). -- `SetServices` registers `Initialize`, phase `run`, `Finalize`; reads `RUN_DT:`, - `DYCORE:` and `AdvCore_Advection:` (`FV3` sets 0; `FV3+ADV` and any other - value 1). If `DYCORE` is neither, the dycore is "not running" and - `Initialize` calls `fv_setup` and `MAPL_GridCompSetGeometry` itself. -- `run` (only if `AdvCore_Advection > 0`) copies the imports, builds `xTRADV` - with its own `get_adjusted_tracer_bundle`, reads `ADV_QSPLIT:` (default 0), - `ADV_CORE_REPORT_TRACER_MASS:`, calls `offline_tracer_advection(...)` and sets - values below `tiny` to zero. - -`DYN` and `ADV` each have a function `get_adjusted_tracer_bundle`; both use -`field_is_cloud_water_species`, with opposite polarity (`DYN` excludes tracers -for which it is false, `ADV` those for which it is true). The species list is -defined once, in `fv_shared.F90`. - -## 8. Configuration - -Resource keys are read with `MAPL_GridCompGetResource` from the component's -configuration; in the regression cases that is its YAML file -(`regression/adv-dyn/dyn.yaml`, `regression/dyn-sa/dyn-sa.yaml`). - -- Top-level keys: `DYCORE:`, `AdvCore_Advection:`; `RUN_DT:`; `FV3_CONFIG:`, - `ADIABATIC:`, `FV_OFF:`, `ADJUST_SPLITS:`, `RUN_GTFV3:`, `fix_mass:`; - `COLDSTART:`, `CASE_ID:`, `CASE_TRACERS:`; `FV3_STANDALONE:`; `DO_ADD_INCS:`, - `ANA_IS_WEIGHTED:`, `REPLAY_SHUTOFF:`; `EXCLUDE_ADVECTION_TRACERS[_LIST]:`. -- `geometry:` with `esmf_geom:` (`class: CubedSphere`, `im_world`, `nx_face`, - `ny_face`) and `vertical_grid:` (`num_levels`, `field_edge: PLE`, - `field_center: PE`). `FV_Setup` reads these - (`setup_fv_dimensions_and_topology`); `DYN` does not call `MAPL_GridCreate`. -- `mapl:` with `setServices` (`sharedObj: libFVdycoreCubed_GridComp`, - `userRoutine: fvdycorecubed_setservices_`) and `misc` (checkpoint options). - -Superdyn names the config file `dyn.yaml`; *Unverified:* the file used in the -full GCM was not found in the fixture. - -## 9. `@fvdycore` - -`@fvdycore` is the nested repository holding the GFDL atmospheric cubed-sphere -core with GEOS modifications (`components.yaml`, key `fvdycore`, branch `geos/release/MAPL-v3`, develop `geos/develop`). -Its `CMakeLists.txt` builds a library `fvdycore` from `model/`, `tools/` and -`geos_utils/`, added here as a sub-component. It is not part of this repository -(`.gitignore` ignores `/@fvdycore`) and is not documented here; see -`@fvdycore/README.md` (`../@fvdycore/README.md` in the fixture) (the upstream GFDL README). - -## 10. Executables and tools - -Built by `CMakeLists.txt`: `rs_scale.x` (inserts a dry mass into restarts), -`interp_restarts.x` (interpolates FV and moist restarts to a cubed sphere, with -optional new vertical levels), and `fv3_driver.x` (`geos-gtfv3/driver/`, only -with `BUILD_GEOS_GTFV3_INTERFACE`). The four `StandAlone_*.F90` sources remain -but have no `ecbuild_add_executable`; the standalone use of `DYN` is the -regression case `dyn-sa`. - -## 11. `geos-gtfv3/` - -An optional bridge to a Python implementation of the FV3 core (the -NDSL/Pace "GeosDycoreWrapper", imported in `geos_gtfv3.py`). It is built only -when `BUILD_GEOS_GTFV3_INTERFACE` is on (default off; `CMakeLists.txt`), which -defines `RUN_GTFV3`, runs `geos-gtfv3/geos_gtfv3_interface.py` with `cffi` under -`mpirun -np 1` to produce `libgeos_gtfv3_interface_py.so`, and compiles -`geos_gtfv3_interface.f90` and `geos_gtfv3_interface.c`. Files: -`geos_gtfv3_interface.f90` (Fortran bindings `geos_gtfv3_interface_f_init`, `_f`, -`_f_finalize`), the `.c` C shim, `geos_gtfv3.py` (`geos_gtfv3_init`, -`geos_gtfv3`, `geos_gtfv3_finalize`, class `GEOSGTFV3`), further Python files -(`f_py_conversion.py`, `geos_gtfv3_debug.py`, `cuda_profiler.py`), `driver/` (a -standalone driver, with `driver/setenv/pyenv.sh`) and `README.md` -(`GTFV3_BACKEND`, default `gt:gpu`; `GTFV3_NAMELIST`, default `input.nml`). - -At run time the resource `RUN_GTFV3:` selects the Python core in `FV_Run` -instead of `fv_dynamics`. The Fortran path passes only the first seven -tracers to Python (`q(:,:,:,1:7)`, `nq_tot=7`). - -## 12. Regression tests and CI - -`regression/CMakeLists.txt` reads `regression/cases.txt` (`adv-dyn`, `dyn-sa`) -and calls `esma_add_regression_tests(NAME fv3 ...)`. Each case is a CTest with -label `REGRESSION`. `regression/run_case.cmake` runs `GEOS.x` on 6 ranks and -compares checkpoints against a baseline only when the compiler is `IntelLLVM` -(`regression/README.md`: `ctest -L REGRESSION`). - -| Case | Content | -|---|---| -| `dyn-sa` | Children `DYNsa` (`dyn-sa.yaml`: `FV3_STANDALONE: true`, `COLDSTART: true`, `DYCORE: FV3`, `ADIABATIC: true`, 12 cells per face edge, 91 levels) and `DataMoist`; `TRADV` connected | -| `adv-dyn` | Children `DYN` (`DYCORE: FV3+ADV`), `ADV`, and data components for moist (`DataMoist`), extra tracers (`DataTracers`), `PHIS`/`VARFLT` (`DataPhisVarflt`) and `DQ*ANA` (`DataAna`); `MFX`, `MFY`, `CX`, `CY`, `PLE0`, `PLE1` connected from `DYN` to `ADV` | - -The README says each case has a `cmpchk.py`; none is in the repository. -CI (`.circleci/config.yml`): `build-GEOSfvdycore-as-R4-on-` (`ifx`, -`gfortran`; fixture branch `release/MAPL-v3`; `ctest -L REGRESSION`) and -`build-GEOSfvdycore-as-R8-on-ifx`. - -## 13. `scripts/` - -`scripts/CMakeLists.txt` installs `fv3_setup` (tcsh, interactive), `fv3.j` and -`.FV3_VERSION`. `fv3.j` writes MAPL2-format `CAP.rc`, `AGCM.rc`, `HISTORY.rc` -and runs `StandAlone_FV3_Dycore.x`, which is not built here (section 10). - -## 14. Build - -`CMakeLists.txt` builds one library `FVdycoreCubed_GridComp` (`esma_add_library`, -`SUBCOMPONENTS fvdycore`; `TYPE SHARED` unless `BUILD_GEOS_GTFV3_INTERFACE`), the -executables of section 10, `scripts` and `regression`. `mapl_acg` runs on -`DynCore_StateSpecs.rc` (`IMPORT_SPECS EXPORT_SPECS INTERNAL_SPECS`) and -`AdvCore_StateSpecs.rc` (`IMPORT_SPECS EXPORT_SPECS GET_POINTERS -DECLARE_POINTERS`). Dependencies: `MAPL`, `GFTL_SHARED::gftl-shared-v2`, -`GMAO_hermes` (`m_set_eta`, `m_topo_remap`), `GEOS_Shared`, `esmf`, OpenMP. -`FV_PRECISION` (`R4`, `R4R8`, `R8`; set in the fixture, default `R4R8`) -selects the FMS library (`fms_r4`, `fms_r8`) and the flags `SINGLE_FV -OVERLOAD_R4` or `FREAL8`. Other options: -`BUILD_GEOS_GTFV3_INTERFACE`, `CRAY_POINTER`. - -## 15. Known traps - -- `FV_Run` asserts exactly five water tracers when not `ADIABATIC` and requires - `Q`, `QLCN`, `QLLS`, `QICN`, `QILS` in `TRADV`. -- Only `run` checks the Time2Run alarm: when it is not ringing `run` returns - early and does not refresh the exports, while `run_add_incs` runs on every - call. *Inferred:* `RUN_DT:` is meant to be a multiple of the parent step. -- `run` asserts the import and export `TRADV` bundles share data. - -## 16. Observations (noted, not fixed) - -- `run` reads `CONSV:` and `FILL:` into `LCONSV` and `LFILL`, which are not used - afterwards. `FV_Setup` sets the FV3 flags itself. -- The module header comment (MAPL2-era) says the component "supports only a 1D - latitude-based decomposition" and mentions PILGRIM; the comment block above - `SetServices` still lists the imports `DUDT`, `DVDT`. -- The body of `FV_DA_Incs` is commented out. In `a2d3d` (`FV_StateMod.F90`) the - code using the optional argument `wind_increment_limiter` is commented out, - so the value `800.d0/86400.d0` passed by `add_incs` has no effect; no other use - was found. -- The export `PID` is set to 0 ("WMP need to get from MAPL gid"). -- The gtFV3 path passes only seven tracers (section 11) while `FV_Atm%q` holds - all packed tracers. -- `setup_fv_dimensions_and_topology` sets `npy = 6*npx`, so its `else` branch is - never taken (a `TODO` in the source asks about it). -- `FV3_STANDALONE` is read in `SetServices` and not used there; `run` and - `Coldstart` read it again. +- [`AGENTS.md`](../AGENTS.md): rules, status on this line, to-dos, known traps, build and test. +- Superdyn and the Agcm: `GEOSagcm_GridComp/AGENTS.md` and `GEOSagcm_GridComp/docs/ARCHITECTURE.md` in `GEOSgcm_GridComp` (`../../AGENTS.md` and `../../docs/ARCHITECTURE.md` in the fixture). +- `regression/README.md`: the regression cases. +- `@fvdycore/README.md`: the FV3 core (upstream GFDL). diff --git a/docs/decisions.md b/docs/decisions.md deleted file mode 100644 index 8530110b..00000000 --- a/docs/decisions.md +++ /dev/null @@ -1,84 +0,0 @@ -# FVdycoreCubed_GridComp: previous architectural decisions - -**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. - -Only what is easy to see in the code now. Entries grow over time. Context: -[`ARCHITECTURE.md`](ARCHITECTURE.md). - -### Dycore state aliases the MAPL internal state -- Pattern: `FV_InitState` points the FV3 state arrays at the MAPL internal-state arrays - (`AK`, `BK`, `U`, `V`, `PT`, `PE`, `PKZ`, `DZ`, `W`) so a MAPL restart fills the dycore - directly (`FV_StateMod.F90`, `FV_InitState`; `DynCore_GridCompMod.F90`, `SetServices`). [Verified] -- Likely reason: reuse MAPL restart and checkpoint handling instead of the FV3 own I/O. [Inferred] -- Question for maintainers: what is the role of the FV3 native restart I/O (`fv_io`) in the GEOS configuration? - -### Tracers are borrowed, not owned -- Pattern: the dycore restart holds no tracers; `DYN` imports the `TRADV` bundle and points - its tracer pointers at the bundle fields, then `FV_Run` packs and unpacks them around - `fv_dynamics` (`DynCore_GridCompMod.F90`, `run`, `PULL_Q`; `FV_StateMod.F90`, `FV_Run`). [Verified] -- Likely reason: tracers belong to the components that produce them and carry their own restarts. [Inferred] -- Question for maintainers: is the `free_tracers` comment ("Comment out to output tracer to - checkpoint file") a supported option? - -### Two Run phases: dynamics, then physics increments -- Pattern: phase `run` applies the analysis/bias tendencies found in the imports - and advances the state; phase `run_add_incs` adds the physics tendencies to the dycore state - through the same `add_incs`, instead of the physics changing the state itself - (`DynCore_GridCompMod.F90`, `SetServices`, `run`, `run_add_incs`). [Verified] -- Likely reason: physics runs between the two phases on the dynamics state, and the dycore - holds the prognostic variables on its native D-grid winds and edge pressure. [Inferred] -- Question for maintainers: on this line Superdyn runs the two phases but copies nothing - (`GEOS_SuperdynGridComp.F90`, `run`, `run_add_incs`); which connection fills `D_UV_DT`, - `DTDT`, `DPEDT` in the full GCM? - -### Offline tracer advection as a sibling component -- Pattern: with `DYCORE: FV3+ADV`, tracers outside a fixed water/cloud list are advected by - the separate component `ADV` using the mass fluxes and Courant numbers exported by `DYN` - (`MFX`, `MFY`, `CX`, `CY`, `PLE0`, `PLE1`) (`AdvCore_GridCompMod.F90`, `run`; - `regression/adv-dyn/root.yaml`; the Superdyn `FV3+ADV` branch is commented out on this line). [Verified] -- Likely reason: advect many chemistry/aerosol tracers with a different split or time step than - the core, without the cost of carrying them through `fv_dynamics`. [Inferred] -- Question for maintainers: what is the role of the time-centered mass flux option - (`AdvCore_Advection: 2`, `computeMassFluxes`)? - -### Water tracers packed by name -- Pattern: `FV_Run` packs `QLCN`/`QLLS`, `QICN`/`QILS`, `CLCN`/`CLLS` into the FV3 liquid, ice and - cloud-fraction slots, carries the convective parts as extra tracers, and recovers the - large-scale part afterwards (`FV_StateMod.F90`, `FV_Run`). [Verified] -- Likely reason: the FV3 core knows a fixed set of water species while GEOS moist physics - keeps convective and large-scale parts separate. [Inferred] -- Question for maintainers: is the requirement of exactly five water tracers (`nwat_tracers == 5`) - expected to stay? - -### Component wrapper in this repository, core in a separate one -- Pattern: the MAPL layer lives here and the GFDL-derived core in the nested repository `@fvdycore`; - the core is built into this repository's library (`CMakeLists.txt`, `SUBCOMPONENTS fvdycore`). [Verified] -- Likely reason: track the upstream GFDL code separately from the GEOS interface. [Inferred] -- Question for maintainers: which changes belong in `@fvdycore` and which in `FV_StateMod.F90`? - -### Optional Python core -- Pattern: a build option (`BUILD_GEOS_GTFV3_INTERFACE`) and a runtime resource (`RUN_GTFV3:`) - replace `fv_dynamics` by a call into a Python implementation through a C shim - (`geos-gtfv3/`; `FV_StateMod.F90`, `FV_Run`). [Verified] -- Likely reason: run the dycore on GPUs while the rest of the model stays in Fortran. [Inferred] -- Question for maintainers: what is the role of the first-seven-tracers limit of the Python path? - -### Tracer bundle as a MAPL3 service item -- Pattern: `DYN` and `ADV` declare `TRADV` as `MAPL_STATEITEM_SERVICE`, which puts the bundle in - both the import and the export state, and `run` asserts the two share data - (`DynCore_GridCompMod.F90`, `SetServices`, `run`). [Verified] -- Likely reason: the source comment says the component is the provider and there is no coupling - mechanism yet to copy the bundle. [Verified: comment in `run`] -- Question for maintainers: is the same-data assertion meant to stay once a coupling mechanism exists? - -### Tracer selection predicate shared by DYN and ADV -- Pattern: both components decide which tracers stay in the dycore with one function, - `field_is_cloud_water_species` in `fv_shared.F90`, with opposite polarity - (`DynCore_GridCompMod.F90`, `AdvCore_GridCompMod.F90`, `get_adjusted_tracer_bundle`). [Verified] -- Likely reason: keep the two selections consistent. [Inferred] -- Question for maintainers: should `FV_StateMod.F90` (the `nwat_tracers` count) use the same predicate? diff --git a/regression/README.md b/regression/README.md index 99626c3d..64317b7e 100644 --- a/regression/README.md +++ b/regression/README.md @@ -1,59 +1,56 @@ # FVdycoreCubed Regression Tests -This directory contains CTest-based regression cases for -`@FVdycoreCubed_GridComp`. +This directory contains CTest-based regression cases for `@FVdycoreCubed_GridComp`. ## Test Harness Overview - Test case names are listed in `cases.txt`. -- `CMakeLists.txt` registers each case as a CTest and assigns label `REGRESSION`. -- `run_case.cmake` creates a temporary run directory, copies the selected case - files, and runs `GEOS.x` with MPI. -- The harness currently runs each case with 6 MPI ranks (`num_procs = 6`). -- If the run fails, `run_case.cmake` emits `PET0.ESMF_LogFile` (when present) - and exits with a CTest failure. +- `CMakeLists.txt` registers each case as a CTest with label `REGRESSION` (`esma_add_regression_tests` in `@cmake`, `NAME fv3`, `DATA_PATH FVdycoreCubed_GridComp`). +- Regression data is read from `$LOCAL_REGRESSION_DATA_DIR/FVdycoreCubed_GridComp/`, or from `/regression-data/FVdycoreCubed_GridComp/` when `LOCAL_REGRESSION_DATA_DIR` is not set at configure time. The test `fv3/sync_data`, which every case requires, syncs that directory from S3 when ctest runs. +- `run_case.cmake` creates a temporary run directory, copies the case files and any input restarts (`checkpoints/