How wrf-model/wrf works
1. This repository is the full WRF-ARW modeling system: a large Fortran-centered atmospheric model with optional chemistry, hydrology, data assimilation, and adjoint/tangent-linear capabilities. The codebase is organized as a set of cooperating model subsystems rather than a single application.
2. The main runtime entry points are in main/. The key drivers are wrf.F, real_em.F, ideal_em.F, ndown_em.F, convert_em.F, and the NMM variants. These launch different model workflows: real-data forecasts, idealized tests, nested-domain transfer, and conversion/preprocessing paths.
3. The core forecast execution path flows through frame/, share/, dyn_em/, and phys/. frame/ provides model infrastructure such as time stepping, domain management, comms, I/O plumbing, and error handling; share/ holds common utilities and mediation layers; dyn_em/ implements the ARW dynamical core; phys/ contains the physics parameterizations that are called each timestep.
4. The model state and many compile-time interfaces are generated from the Registry/ definitions. This is a major architectural boundary: the Registry drives structure layout, I/O metadata, and many generated headers and interfaces under inc/, share/, and related build outputs. This means a lot of the data model is code-generated rather than hand-written.
5. Build and configuration are handled by both legacy and modern systems. Top-level Makefile, configure, compile, and clean coexist with CMakeLists.txt and cmake/. Platform-specific compiler settings live in arch/, while .ci/ and .github/workflows/ define automated build/test matrices.
6. I/O is abstracted into pluggable backend implementations under external/. There are backends for NetCDF, parallel NetCDF, ADIOS2, PIO, ESMF, HDF5/PHDF5, GRIB1/2, and IOAPI-related support. This lets the same model state be written to restart, boundary, and diagnostic files through different storage stacks without changing the core model logic.
7. The run/ directory is not code; it is the runtime data bundle. It contains lookup tables, aerosol/radiation coefficients, land-surface tables, ozone and greenhouse gas data, and other static inputs required by physics and chemistry packages. These files are read by the model at startup and during physics calculations.
8. The physics subsystem in phys/ is broad and modular. It includes boundary layer, microphysics, cumulus, radiation, surface layer, land surface, fire, aerosol, lightning, and diagnostics packages. The model selects among these at runtime based on namelist configuration, so the physics layer is a set of interchangeable components attached to the dynamical core.
9. Chemistry is a substantial subsystem in chem/. It contains chemistry drivers, aerosol and gas-phase modules, photolysis, deposition, emissions, and many mechanism-specific implementations. chem/KPP/ is especially important: it holds the KPP mechanism generator, mechanism definitions, and generated include files for dozens of chemical schemes. Chemistry data flow is driven by mechanism selection and couples into the physics/dynamics timestep.
10. WRF-Hydro is integrated as a separate but coupled model family under hydro/. It includes routing, groundwater, reservoir, nudging, I/O, orchestration, and coupling layers. This subsystem has its own configuration and templates, but it exchanges forcing and state with the atmospheric model through coupling interfaces.
11. Data assimilation lives under var/ and is effectively a second major application inside the repository. It contains WRFDA components for observation processing, forward operators, background-error generation, minimization, radiance handling, analysis increments, verification, and VARBC. The flow is typically observations + background + error statistics in, analysis increments / updated initial conditions out, with separate tooling for running and generating background-error fields.
12. The adjoint and tangent-linear model is isolated in wrftladj/. It mirrors key forecast modules with _tl and _ad variants, plus adjoint-specific infrastructure. This boundary exists because the adjoint workflow needs a differentiable version of the forecast physics/dynamics for sensitivity and optimization tasks.
13. Testing and examples are split across several layers. test/ contains named model cases with namelists and inputs; tools/ contains validation, registry/code-generation utilities, and regression helpers; .sane/ and .ci/ define scripted build and HPC regression workflows. This makes the repo support both developer-level unit/regression checks and full model-case integration runs.
14. The repository’s main integration boundaries are therefore: configuration/build system; generated state definition via Registry; forecast runtime core; pluggable I/O backends; optional physics/chemistry/hydro modules; and separate DA/adjoin/validation toolchains. An architecture diagram should show the core forecast model in the center, with these optional subsystems attaching through well-defined interfaces and shared state.
Main entry points: Registry Registry · share Shared mediation · main Main drivers · phys Physics
Components 18
Build & config
Build systems, platform settings, and CI automation.
- Makefile · Legacy build entry point for compiling the model stack.
Makefile - CMake · Modern build configuration and platform detection.
CMakeLists.txt - Arch config · Compiler and machine-specific build settings.
arch - CI scripts · Repository automation for builds, tests, and workflows.
.github/workflows
Forecast core
Main atmospheric model runtime and shared infrastructure.
- Main drivers · Top-level executables for real, idealized, nesting, and conversion workflows.
main - Shared mediation · Common startup, domain mediation, namelist, and restart plumbing.
share - Frame core · Time stepping, domain management, comms, I/O plumbing, and error handling.
frame - ARW dynamics · The atmospheric dynamical core and integration routines.
dyn_em
I/O backends
Pluggable file-format and parallel I/O implementations.
- I/O backends · NetCDF, PNetCDF, ADIOS2, PIO, ESMF, HDF5, GRIB, and related adapters.
external
Optional subsystems
Physics, chemistry, hydrology, and specialized model families.
Analysis tools
Data assimilation, adjoint/tangent-linear, and validation tooling.
- Registry · Model state definitions and generated interfaces that shape the data model.
Registry - WRFDA · Observation processing, minimization, background-error, radiance, and analysis tools.
var - TL/Adjoint · Tangent-linear and adjoint forecast components for sensitivity and optimization.
wrftladj - Tools · Registry/code-generation, regression, and repository helper utilities.
tools - Test cases · Named integration cases and namelist/input bundles for exercising the model.
test
Runtime data
Static tables and lookup files used at run time.
- Run data · Lookup tables, coefficients, and other runtime files consumed by physics and chemistry.
run
Connections 25
- Makefile → Main drivers: builds · Legacy build compiles the executables and shared objects.
- CMake → Main drivers: builds · CMake builds the same runtime entry points.
- Arch config → Makefile: configures · Platform-specific compiler settings feed legacy builds.
- Arch config → CMake: configures · Architecture settings also inform the CMake path.
- CI scripts → Makefile: checks · CI runs make-based compilation and regression workflows.
- CI scripts → CMake: checks · CI runs CMake-based build and test matrices.
- Main drivers → Shared mediation: boots · Drivers initialize the shared mediation layer and runtime state.
- Shared mediation → Frame core: uses · Shared routines delegate to the frame infrastructure.
- Frame core → ARW dynamics: steps · Frame integration calls into the dynamical core each timestep.
- ARW dynamics → Physics: calls · Dynamics invokes selected physics packages during integration.
- Physics → Run data: reads · Physics packages consume static tables and coefficient files.
- Chemistry → Run data: reads · Chemistry mechanisms and photolysis use external lookup data.
- Main drivers → Registry: generated from · Executables depend on generated state, I/O metadata, and interfaces.
- Registry → Shared mediation: generates · Registry definitions feed shared headers and interfaces.
- Registry → Physics: defines state · Physics accesses state layout and metadata derived from Registry.
- Registry → Chemistry: defines state · Chemical species and interfaces are driven by Registry definitions.
- I/O backends → Shared mediation: implements I/O · Backend adapters provide the storage layer used by shared I/O code.
- I/O backends → Frame core: supports · Frame I/O plumbing routes through selectable backend implementations.
- WRFDA → Registry: reuses · Assimilation state and generated interfaces track the model data model.
- WRFDA → Shared mediation: couples to · DA workflows use shared model mediation, I/O, and state transfer.
- TL/Adjoint → ARW dynamics: mirrors · Adjoint/TL modules mirror key forecast dynamics.
- TL/Adjoint → Physics: mirrors · Adjoint/TL physics modules mirror selected parameterizations.
- WRF-Hydro → Shared mediation: couples to · Hydrology exchanges forcing and state through shared coupling interfaces.
- Tools → Registry: generates · Developer tools generate allocs, args, streams, and state descriptors.
- Test cases → Main drivers: exercise · Integration cases run the main model entry points.