- **Type–Safe Species Representation**: Strongly typed isotopes (`fourdst::atomic::Species`) generated from evaluated nuclear data (AME2020 / NUBASE2020).
- **Molar Abundance Core**: Stores absolute molar abundances and derives all secondary quantities (mass / number fractions, mean particle mass, electron abundance) on demand, with internal caching.
- **Canonical Composition Support**: Direct computation of canonical (X: Hydrogen, Y: Helium, Z: Metals) mass fractions via `getCanonicalComposition()`.
- **Convenience Construction**: Helper utilities for constructing compositions from a vector or set of mass fractions (`buildCompositionFromMassFractions`).
- **Deterministic Ordering**: Species are always stored and iterated lightest→heaviest (ordering defined by atomic mass) enabling uniform vector interfaces.
- **Clear Exception Hierarchy**: Explicit error signaling for invalid symbols, unregistered species, and inconsistent input data.
- **Meson + pkg-config Integration**: Simple build, install, and consumption in external projects.
---
# Installation
libcomposition can be installed either from source or as part of the `fourdst` project.
`libcomposition` uses the Meson build system. A C++23 compatible compiler is required.
### Build Steps
**Setup the build directory:**
The first step is to use meson to set up an out of source build. Note that this means that you can have multiple builds configured and cleanly separated!
```bash
meson setup builddir
```
**Compile the library:**
meson by default uses ninja to compile so it should be very fast; however, gcc is very slow when compiling the species database so that might take some time (clang tends to be very fast for this).
You can enable the generation of a `pkg-config` file during the setup step, which simplifies linking the library in other projects. By default this is true; it can be useful to disable this when using some build system orchestrator (such as meson-python).
The library surfaces errors through a focused hierarchy in `fourdst::composition::exceptions`:
| Exception Type | When It Occurs |
|----------------|----------------|
| `UnknownSymbolError` | A string symbol does not correspond to any known isotope in the compiled species database. |
| `UnregisteredSymbolError` | A valid species/symbol is used before being registered with a Composition instance. |
| `InvalidCompositionError` | Construction from mass fractions fails validation (sum deviates from unity beyond tolerance) or canonical (X+Y+Z) check fails. |
| `CompositionError` | Base class; may be thrown for generic composition-level issues (e.g. negative abundances via the documented `InvalidAbundanceError` contract). |
Recommended patterns:
- Validate externally provided symbol lists before calling bulk registration.
- Use species‑based overloads (strongly typed) where possible for slightly lower overhead (no symbol resolution).
- Wrap construction from mass fractions in a try/catch to surface normalization issues early.
---
# Linking and Integration
### Linking with pkg-config
If you installed `libcomposition` with the `pkg-config` option enabled, you can get the necessary compiler and linker flags easily: