How maxaragon/rte-rrtmgp-cpp works
Project Type and Purpose
• This is a high‑performance scientific computing library with both CPU and GPU implementations of Radiative Transfer for Energetics (RTE) coupled to the Rapid Radiative Transfer Model for GCM applications Parallel (RRTMGP), plus a Monte Carlo ray‑tracer.
• It provides a core C++ API, CUDA backends, legacy Fortran‑style kernels, Python bindings for post‑processing and test case runners (allsky, rfmip, rcemip), and a CMake‑based build & test infrastructure.
High‑Level Architecture
• Core Library Layer (src & include)
• RTE modules: Rte_lw, Rte_sw
• Optical property modules: Aerosol_optics, Cloud_optics, Gas_optics, Optical_props
• Flux solver modules: Fluxes, Source_functions, Gas_concs
• GPU Backends
• CUDA implementations of each core module (src_cuda & include_kernels_cuda)
• Separate “rt” backends for GPU ray‑tracer (src_cuda_rt & include_rt_kernels)
• CPU‑only legacy kernels (src_kernels/*.F90)
• Testing & Example Harness
• Test executable (src_test + include_test) → test_rte_rrtmgp
• Example directories with orchestration scripts: allsky/, rfmip/, rcemip/
• Python Wrappers & Utilities
• Cython interface (python/*.pyx + setup.py)
• Post‑processing scripts for visualization and camera setup
• Build & Configuration
• CMakeLists.txt at root and in subdirectories
• config/*.cmake for platform targets (Ubuntu, Mac, HPC clusters)
• External Data & Dependencies
• NetCDF and coefficient files (data/, rrtmgp-data/)
• Submodule for original RRTMGP data & code (rrtmgp/)
Component Interactions
• Build System (CMake) orchestrates compilation of:
• Core C++ library → CPU code
• CUDA library → GPU code + ray‑tracer
• Fortran kernels → legacy CPU performance paths
• Cython extension → Python importable module
• Test executable → linked to the above
• At runtime:
• test_rte_rrtmgp (and Python scripts) open NetCDF input → call core API
• Core API dispatches to CPU or GPU kernels (templated / macro‑based)
• Monte Carlo ray‑tracer uses its own RT API layer
• Outputs are NetCDF or visualizations consumed by Python
Architectural Patterns & Design Principles
• Layered modular design: interface headers (include/ & include_rt/) separate from implementation (src/ & src_cuda/).
• Strategy pattern via compile‐time dispatch: CPU vs GPU backends selected through CMake flags.
• Test‑driven integration: dedicated src_test harness linking to core modules.
• Plugin‑style example runners: allsky, rfmip, rcemip share the same engine with different inputs and plotting scripts.