|
| 1 | +# ClimaCore.jl — Repo-Specific Guide |
| 2 | + |
| 3 | +## Package overview |
| 4 | + |
| 5 | +ClimaCore.jl provides the dynamical core infrastructure for [CliMA](https://clima.caltech.edu/)'s Earth System Model. It supplies flexible and composable discretization tools — spectral element and finite difference operators, field abstractions, data layouts, and GPU-portable kernels — that downstream packages (ClimaAtmos.jl, ClimaLand.jl, ClimaCoupler.jl) build on to solve the governing equations of their component models. |
| 6 | + |
| 7 | +## Directory map |
| 8 | + |
| 9 | +| Layer | Directory | Description | |
| 10 | +|:---|:---|:---| |
| 11 | +| Core module | `src/ClimaCore.jl` | Top-level module, re-exports all sub-modules | |
| 12 | +| DataLayouts | `src/DataLayouts/` | Low-level array-of-structs / struct-of-arrays data storage backends | |
| 13 | +| Geometry | `src/Geometry/` | Coordinate types, axis tensors, covariant/contravariant transforms | |
| 14 | +| Domains | `src/Domains/` | Abstract domain definitions (intervals, rectangles, spheres) | |
| 15 | +| Meshes | `src/Meshes/` | Mesh generation: interval, rectangle, cubed-sphere | |
| 16 | +| Topologies | `src/Topologies/` | Distributed topologies, DSS (direct stiffness summation) connectivity | |
| 17 | +| Quadratures | `src/Quadratures/` | Gauss–Legendre and Gauss–Lobatto quadrature rules | |
| 18 | +| Grids | `src/Grids/` | Spectral element and finite-difference grid types | |
| 19 | +| Spaces | `src/Spaces/` | Function spaces built on grids (spectral element, finite-difference, extruded) | |
| 20 | +| Fields | `src/Fields/` | `Field` type — the primary user-facing data container on a space | |
| 21 | +| Operators | `src/Operators/` | Spectral element and finite-difference differential operators | |
| 22 | +| MatrixFields | `src/MatrixFields/` | Banded matrix fields for implicit vertical solvers | |
| 23 | +| Hypsography | `src/Hypsography/` | Terrain-following coordinate transforms | |
| 24 | +| Limiters | `src/Limiters/` | Flux limiters for transport | |
| 25 | +| Remapping | `src/Remapping/` | Interpolation and remapping between spaces | |
| 26 | +| InputOutput | `src/InputOutput/` | HDF5-based checkpointing and restart I/O | |
| 27 | +| CommonGrids | `src/CommonGrids/` | Pre-built convenience grid constructors | |
| 28 | +| CommonSpaces | `src/CommonSpaces/` | Pre-built convenience space constructors | |
| 29 | +| Utilities | `src/Utilities/` | Internal utilities (PlusHalf indexing, AutoBroadcaster, etc.) | |
| 30 | +| DebugOnly | `src/DebugOnly/` | Debug-mode-only utilities | |
| 31 | +| CUDA ext | `ext/ClimaCoreCUDAExt.jl`, `ext/cuda/` | CUDA GPU extension (loaded via Pkg extensions) | |
| 32 | +| Krylov ext | `ext/KrylovExt.jl` | Krylov.jl integration for iterative solvers | |
| 33 | +| Lib: Plots | `lib/ClimaCorePlots/` | Plots.jl recipes for ClimaCore fields | |
| 34 | +| Lib: Makie | `lib/ClimaCoreMakie/` | Makie.jl recipes for ClimaCore fields | |
| 35 | +| Lib: VTK | `lib/ClimaCoreVTK/` | VTK output for visualization | |
| 36 | +| Lib: TempestRemap | `lib/ClimaCoreTempestRemap/` | TempestRemap bindings for conservative remapping | |
| 37 | +| Lib: Spectra | `lib/ClimaCoreSpectra/` | Spectral analysis of fields on the sphere | |
| 38 | + |
| 39 | +## Key abstractions |
| 40 | + |
| 41 | +1. **`Field`** (`src/Fields/`) — the primary data type. A field wraps data on a space and supports broadcast, reductions, and operator application. |
| 42 | +2. **`Space`** (`src/Spaces/`) — represents a discretized function space (spectral element, finite-difference, or extruded hybrid). Constructed from a grid and a quadrature rule. |
| 43 | +3. **Operators** (`src/Operators/`) — lazy differential operators (gradient, divergence, curl, interpolation, restriction) that compose via Julia's broadcast system. |
| 44 | +4. **`DataLayout`** (`src/DataLayouts/`) — the storage backends (IJFH, VIJFH, VF, etc.) that determine memory layout for CPU vs GPU performance. |
| 45 | +5. **`MatrixFields`** (`src/MatrixFields/`) — banded-matrix field algebra used for implicit vertical solvers and Jacobian construction. |
| 46 | + |
| 47 | +## Test groups |
| 48 | + |
| 49 | +Tests are defined in `test/runtests.jl` using the `UnitTest` / `tabulated_tests` framework: |
| 50 | + |
| 51 | +| Group | What it covers | |
| 52 | +|:---|:---| |
| 53 | +| CPU unit tests | 104 tests covering DataLayouts, Geometry, Meshes, Topologies, Quadratures, Spaces, Fields, Operators (spectral element + finite-difference), MatrixFields, Hypsography, Limiters, Remapping, InputOutput, Aqua, deprecations | |
| 54 | +| GPU tests (`:gpu_only`) | 9 tests: CUDA kernels, compiler stress regression, DataLayout GPU ops, spectral element CUDA, finite-difference CUDA, extruded sphere/3dbox CUDA, field map-reduce CUDA | |
| 55 | +| Buildkite CI | Runs the unit tests on an HPC cluster with CUDA, defined in `.buildkite/pipeline.yml` | |
| 56 | +| Lib CI workflows | Separate GitHub Actions per companion package: ClimaCoreMakie, ClimaCorePlots, ClimaCoreSpectra, ClimaCoreTempestRemap, ClimaCoreVTK | |
| 57 | + |
| 58 | +## Repo-specific conventions |
| 59 | + |
| 60 | +- **Module-per-directory**: each `src/` subdirectory is its own Julia sub-module, re-exported from `ClimaCore.jl`. |
| 61 | +- **`lib/` companion packages**: visualization and remapping packages live as independent Julia packages under `lib/`, each with its own `Project.toml`. They have separate CI workflows. |
| 62 | +- **`ext/` CUDA pattern**: GPU support uses Julia's package extension mechanism (`ext/ClimaCoreCUDAExt.jl`). CPU fallbacks are always provided. |
| 63 | +- **Coding style**: `TitleCase` for types, `snake_case` for objects/functions, spaces after commas. Formatting follows [YASGuide](https://github.com/jrevels/YASGuide) loosely, enforced via `JuliaFormatter` (v1.0.62) in CI. |
| 64 | +- **ColPrac**: the project follows the [ColPrac guide](https://github.com/SciML/ColPrac) for collaborative practices. |
| 65 | +- **Tabulated test runner**: tests use the custom `UnitTest` struct and `run_unit_tests!` / `tabulate_tests` helpers from `test/tabulated_tests.jl`, with leak detection enabled. |
| 66 | + |
| 67 | +## Self-correction |
| 68 | + |
| 69 | +If this guide is discovered to be stale or missing a pattern, update it. |
0 commit comments