Architecture

This page maps the physics onto the C++ code: the top-level class, the module objects it owns, and the flow of control.

Entry point

src/model_main/model_main.cpp contains main. It takes the model folder as the single argument, constructs an agb::AGBStarModel, and calls calcModel(). The special argument --selftest instead runs the Henyey structure-solver validation (Jacobian AD-vs-FD, Newton solve, eigenvalue solve, grey bootstrap) and exits.

The top-level model object

agb::AGBStarModel (src/agb_model/) owns one instance of each physics module and orchestrates the iteration. The members, in construction order (which is also the dependency order), are:

Member

Class

Role

config

agb::ModelConfig

Parsed config.toml; owns all parameters.

spectral_grid

agb::SpectralGrid

Wavenumber/wavelength grids and interpolation.

atmosphere

agb::Atmosphere

The persistent structure (radius, \(T_\mathrm{gas}\), \(T_\mathrm{dust}\), \(\rho\), \(p\), \(v\)), number densities, and all opacity arrays; the equation of state; structure I/O.

chemistry

agb::FastChemChemistry

Equilibrium gas-phase composition (FastChem).

dust_species

agb::DustSpeciesagb::GailSedlmayrDust

Dust nucleation/growth (moment method) and dust opacity (Mie).

transport_coeff

agb::TransportCoefficients

Gas opacities (lines, CIA, H⁻/H₂⁻, Rayleigh).

radiative_transfer

agb::RadiativeTransfer

Spherical VEF moment radiative transfer; owns the agb::RadiationField per shell.

temperature_correction

agb::TemperatureCorrection

Unsöld–Lucy and full-linearisation correctors.

hydrodynamics

agb::Hydrodynamics

Wind structure, sonic point, mass-loss rate; optional agb::StructureSolver (Henyey).

The modules communicate almost entirely through the shared agb::Atmosphere object (temperatures, density, number densities, opacities) and through the agb::RadiationField (mean intensity, flux, flux-mean extinction). This keeps the interfaces narrow.

Control flow

main
└─ AGBStarModel::calcModel                         (outer / global loop)
   ├─ chemistryHydroIteration                      (inner loop)
   │  ├─ chemistryDustIteration
   │  │  ├─ FastChemChemistry::calcChemicalComposition
   │  │  ├─ Atmosphere::equationOfState
   │  │  └─ GailSedlmayrDust::calcDistribution      (carbon-depleting RK4 sweep)
   │  ├─ radiativeTransfer
   │  │  ├─ dust  + gas opacities  (per shell)
   │  │  └─ RadiativeTransfer::solveRadiativeTransfer  (VEF moment method)
   │  ├─ Hydrodynamics::setDustState
   │  ├─ Hydrodynamics::calcWindVelocity            (Melia Φ / shooting / Henyey)
   │  └─ Atmosphere::equationOfState
   ├─ temperatureIteration                          (one RE correction step)
   │  ├─ RadiativeTransfer::solveRadiativeTransfer
   │  ├─ TemperatureCorrection::calculate           (Unsöld–Lucy)   ── or ──
   │  ├─ TemperatureCorrection::linearisedCorrection (full linearisation)
   │  ├─ adaptive damping / Anderson / cap
   │  └─ convergence tests (flux, energy balance, settling)
   └─ applyMovableGrid                              (optional, every N iters)

After the outer loop converges (or hits nb_temperature_iter), the spectrum, structure, dust and hydro outputs are written.

Persistent iteration state

agb::AGBStarModel carries the state that must survive across outer iterations: the temperature-iteration counter, the two-phase corrector latch (linearisation_active, linearisation_ready_count), the per-layer relaxation factors and previous corrections (relaxation_gas/dust, prev_delta_b_gas/dust), and the Anderson history (anderson_x_*, anderson_f_*). All of this is reset at the start of calcModel() and (the per-node parts) when the movable grid fires.

Third-party libraries

See Installation and building for versions. FastChem (chemistry), LX-MIE (dust Mie theory), Eigen + CppAD (Henyey linear algebra and autodiff), and toml++ (config parsing) are fetched and built by CMake.