2025-07-24 09:35:52 -04:00
\chapter { libcomposition\+ : A Modern C++ Library for Chemical Compositions}
\hypertarget { index} { } \label { index} \index { libcomposition: A Modern C++ Library for Chemical Compositions@{ libcomposition: A Modern C++ Library for Chemical Compositions} }
\hypertarget { index_ intro_ sec} { } \doxysection { \texorpdfstring { Introduction} { Introduction} } \label { index_ intro_ sec}
2025-11-08 10:00:16 -05:00
{ \ttfamily libcomposition} is a modern, C++23 library, for the creation, manipulation, and analysis of astrophysical chemical compositions. It provides a robust and type‑ safe interface for assembling a set of isotopes together with their molar abundances and for deriving commonly used bulk properties (mass fractions, number fractions, canonical X/\+ Y/Z, mean particle mass, and electron abundance). { \ttfamily libcomposition} is designed to be tighly integrated into SERiF and related projects such as Grid\+ Fire.\hypertarget { index_ autotoc_ md10} { } \doxysubsubsection { \texorpdfstring { Key Features} { Key Features} } \label { index_ autotoc_ md10}
2025-07-24 09:35:52 -04:00
\begin { DoxyItemize}
2025-11-27 17:47:38 -05:00
\item { \bfseries { Type– \+ Safe Species Representation} } \+ : Strongly typed isotopes ({ \ttfamily \doxylink { structfourdst_ 1_ 1atomic_ 1_ 1Species} { fourdst\+ ::atomic\+ ::\+ Species} } ) generated from evaluated nuclear data (AME2020 / NUBASE2020).
2025-11-08 10:00:16 -05:00
\item { \bfseries { 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.
\item { \bfseries { Canonical Composition Support} } \+ : Direct computation of canonical (X\+ : Hydrogen, Y\+ : Helium, Z\+ : Metals) mass fractions via { \ttfamily get\+ Canonical\+ Composition()} .
\item { \bfseries { Convenience Construction} } \+ : Helper utilities for constructing compositions from a vector or set of mass fractions ({ \ttfamily build\+ Composition\+ From\+ Mass\+ Fractions} ).
\item { \bfseries { Deterministic Ordering} } \+ : Species are always stored and iterated lightest→heaviest (ordering defined by atomic mass) enabling uniform vector interfaces.
\item { \bfseries { Clear Exception Hierarchy} } \+ : Explicit error signaling for invalid symbols, unregistered species, and inconsistent input data.
\item { \bfseries { Meson + pkg-\/ config Integration} } \+ : Simple build, install, and consumption in external projects.
2025-07-24 09:35:52 -04:00
\end { DoxyItemize}
\DoxyHorRuler { 0}
\hypertarget { index_ install_ sec} { } \doxysection { \texorpdfstring { Installation} { Installation} } \label { index_ install_ sec}
2025-11-08 06:42:51 -05:00
{ \ttfamily libcomposition} uses the Meson build system. A C++23 compatible compiler is required.\hypertarget { index_ autotoc_ md12} { } \doxysubsubsection { \texorpdfstring { Build Steps} { Build Steps} } \label { index_ autotoc_ md12}
2025-07-24 09:35:52 -04:00
{ \bfseries { Setup the build directory\+ :} }
2025-11-08 10:00:16 -05:00
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!
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
\DoxyCodeLine { meson\ setup\ builddir}
\end { DoxyCode}
{ \bfseries { Compile the library\+ :} }
2025-11-08 10:00:16 -05:00
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).
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
\DoxyCodeLine { meson\ compile\ -\/ C\ builddir}
\end { DoxyCode}
{ \bfseries { Install the library\+ :} }
This will also install a pkg-\/ config file!
\begin { DoxyCode} { 0}
\DoxyCodeLine { sudo\ meson\ install\ -\/ C\ builddir}
\end { DoxyCode}
2025-11-08 06:42:51 -05:00
\hypertarget { index_ autotoc_ md13} { } \doxysubsubsection { \texorpdfstring { Build Options} { Build Options} } \label { index_ autotoc_ md13}
2025-11-08 10:00:16 -05:00
You can enable the generation of a { \ttfamily 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).
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
\DoxyCodeLine { \# \ Enable\ pkg-\/ config\ file\ generation}
\DoxyCodeLine { meson\ setup\ builddir\ -\/ Dpkg-\/ config=true}
\end { DoxyCode}
\DoxyHorRuler { 0}
\hypertarget { index_ usage_ sec} { } \doxysection { \texorpdfstring { Usage} { Usage} } \label { index_ usage_ sec}
2025-11-27 17:47:38 -05:00
Below are focused examples illustrating the current API. All examples assume headers are available via pkg-\/ config or your include path.\hypertarget { index_ autotoc_ md15} { } \doxyparagraph { \texorpdfstring { 1. Constructing a Composition from Symbols} { 1. Constructing a Composition from Symbols} } \label { index_ autotoc_ md15}
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ <iostream>} }
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { composition_ 8h} { fourdst/composition/composition.h} } "{ } } }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { keywordtype} { int} \ main()\ \{ }
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition} { fourdst::composition} } ;}
\DoxyCodeLine { }
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Register\ symbols\ upon\ construction\ (no\ molar\ abundances\ yet\ -\/ >\ default\ 0.0)} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ comp(\{ \textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ \textcolor { stringliteral} { "{ } He-\/ 4"{ } } ,\ \textcolor { stringliteral} { "{ } C-\/ 12"{ } } \} );}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { }
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Set\ molar\ abundances\ (absolute\ counts;\ they\ need\ not\ sum\ to\ 1.0)} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a262d7133035d4e6f45daa81827abf5e7} { setMolarAbundance} } (\textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ 10.0);}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ comp.setMolarAbundance(\textcolor { stringliteral} { "{ } He-\/ 4"{ } } ,\ 3.0);}
\DoxyCodeLine { \ \ \ \ comp.setMolarAbundance(\textcolor { stringliteral} { "{ } C-\/ 12"{ } } ,\ 0.25);}
\DoxyCodeLine { }
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Query\ derived\ properties} }
\DoxyCodeLine { \ \ \ \ \textcolor { keywordtype} { double} \ x\_ h1\ =\ comp.getMassFraction(\textcolor { stringliteral} { "{ } H-\/ 1"{ } } );}
\DoxyCodeLine { \ \ \ \ \textcolor { keywordtype} { double} \ y\_ he4\ =\ comp.getNumberFraction(\textcolor { stringliteral} { "{ } He-\/ 4"{ } } );}
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { auto} \ canon\ =\ comp.getCanonicalComposition();\ \textcolor { comment} { //\ X,\ Y,\ Z\ mass\ fractions} }
\DoxyCodeLine { }
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ \textcolor { stringliteral} { "{ } H-\/ 1\ mass\ fraction:\ "{ } } \ <<\ x\_ h1\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ \textcolor { stringliteral} { "{ } He-\/ 4\ number\ fraction:\ "{ } } \ <<\ y\_ he4\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ canon\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;\ \textcolor { comment} { //\ <CanonicalComposition:\ X=...,\ Y=...,\ Z=...>} }
\DoxyCodeLine { \} }
2025-07-24 09:35:52 -04:00
\end { DoxyCode}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md16} { } \doxyparagraph { \texorpdfstring { 2. Constructing from Strongly Typed Species} { 2. Constructing from Strongly Typed Species} } \label { index_ autotoc_ md16}
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ <iostream>} }
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { composition_ 8h} { fourdst/composition/composition.h} } "{ } } }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { species_ 8h} { fourdst/atomic/species.h} } "{ } } }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
\DoxyCodeLine { \textcolor { keywordtype} { int} \ main()\ \{ }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition} { fourdst::composition} } ;}
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1atomic} { fourdst::atomic} } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Build\ directly\ from\ species\ constants} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ comp(std::vector<Species>\{ H\_ 1,\ He\_ 4,\ O\_ 16\} );}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a262d7133035d4e6f45daa81827abf5e7} { setMolarAbundance} } (H\_ 1,\ 5.0);}
\DoxyCodeLine { \ \ \ \ comp.setMolarAbundance(He\_ 4,\ 2.5);}
\DoxyCodeLine { \ \ \ \ comp.setMolarAbundance(O\_ 16,\ 0.1);}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ \textcolor { stringliteral} { "{ } Mean\ particle\ mass:\ "{ } } \ <<\ comp.getMeanParticleMass()\ <<\ \textcolor { stringliteral} { "{ } \ g/mol\( \backslash \) n"{ } } ;}
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ \textcolor { stringliteral} { "{ } Electron\ abundance\ (Ye):\ "{ } } \ <<\ comp.getElectronAbundance()\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \} }
\end { DoxyCode}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md17} { } \doxyparagraph { \texorpdfstring { 3. Building from Mass Fractions (\+ Helper Utility)} { 3. Building from Mass Fractions (Helper Utility)} } \label { index_ autotoc_ md17}
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ <iostream>} }
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { utils_ 8h} { fourdst/composition/utils.h} } "{ } } }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { keywordtype} { int} \ main()\ \{ }
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition} { fourdst::composition} } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ std::vector<std::string>\ symbols\ =\ \{ \textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ \textcolor { stringliteral} { "{ } He-\/ 4"{ } } ,\ \textcolor { stringliteral} { "{ } C-\/ 12"{ } } \} ;}
\DoxyCodeLine { \ \ \ \ std::vector<double>\ mf\ \ \ \ \ \ \ =\ \{ 0.70,\ 0.28,\ 0.02\} ;\ \textcolor { comment} { //\ Must\ sum\ to\ \string ~1\ within\ tolerance} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ comp\ =\ \mbox { \hyperlink { namespacefourdst_ 1_ 1composition_ aa90b1ef07d607c0c829bedccf381cf54} { buildCompositionFromMassFractions} } (symbols,\ mf);}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { auto} \ canon\ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ aac5b214a3d1278e127422224cb9cee50} { getCanonicalComposition} } ();}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ canon\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \} }
\end { DoxyCode}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md18} { } \doxyparagraph { \texorpdfstring { 4. Iterating and Sorted Vector Interfaces} { 4. Iterating and Sorted Vector Interfaces} } \label { index_ autotoc_ md18}
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ <iostream>} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { composition_ 8h} { fourdst/composition/composition.h} } "{ } } }
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { keywordtype} { int} \ main()\ \{ }
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition} { fourdst::composition} } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ comp(\{ \textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ \textcolor { stringliteral} { "{ } C-\/ 12"{ } } ,\ \textcolor { stringliteral} { "{ } He-\/ 4"{ } } \} );\ \textcolor { comment} { //\ Internally\ sorted\ by\ mass\ (H\ <\ He\ <\ C)} }
\DoxyCodeLine { \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a262d7133035d4e6f45daa81827abf5e7} { setMolarAbundance} } (\{ \textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ \textcolor { stringliteral} { "{ } He-\/ 4"{ } } ,\ \textcolor { stringliteral} { "{ } C-\/ 12"{ } } \} ,\ \{ 10.0,\ 3.0,\ 0.25\} );}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Ordered\ iteration\ (lightest\ -\/ >\ heaviest)} }
\DoxyCodeLine { \ \ \ \ \textcolor { keywordflow} { for} \ (\textcolor { keyword} { const} \ \textcolor { keyword} { auto} \ \& [sp,\ y] \ :\ comp)\ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ std::cout\ <<\ sp\ <<\ \textcolor { stringliteral} { "{ } :\ molar\ =\ "{ } } \ <<\ y\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
\DoxyCodeLine { \ \ \ \ \} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Vector\ access\ (index\ corresponds\ to\ ordering\ by\ atomic\ mass)} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { auto} \ molarVec\ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ abcb391f5fca2b636127e48e681e4c3ee} { getMolarAbundanceVector} } ();}
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { auto} \ massVec\ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ af4f44aaf8b7e0d63872a70b5e2131369} { getMassFractionVector} } ();}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { keywordtype} { size\_ t} \ idx\_ he4\ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a0d94f62402bb90b5d12679faeaa8c5d7} { getSpeciesIndex} } (\textcolor { stringliteral} { "{ } He-\/ 4"{ } } );}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ std::cout\ <<\ \textcolor { stringliteral} { "{ } He-\/ 4\ index:\ "{ } } \ <<\ idx\_ he4\ <<\ \textcolor { stringliteral} { "{ } ,\ molar\ abundance\ at\ index:\ "{ } } \ <<\ molarVec[idx\_ he4]\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \} }
\end { DoxyCode}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md19} { } \doxyparagraph { \texorpdfstring { 5. Accessing Specific Derived Quantities} { 5. Accessing Specific Derived Quantities} } \label { index_ autotoc_ md19}
2025-07-24 09:35:52 -04:00
2025-11-08 10:00:16 -05:00
\begin { DoxyCode} { 0}
\DoxyCodeLine { \textcolor { comment} { //\ Assume\ 'comp'\ is\ already\ populated.} }
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \textcolor { keywordtype} { double} \ mf\_ c12\ \ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a9ea2b673341fdc67afeb0f0517a54c8c} { getMassFraction} } (\textcolor { stringliteral} { "{ } C-\/ 12"{ } } );}
\DoxyCodeLine { \textcolor { keywordtype} { double} \ nf\_ c12\ \ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a34f71d4d8f0297c576fd62fabd490305} { getNumberFraction} } (\textcolor { stringliteral} { "{ } C-\/ 12"{ } } );}
\DoxyCodeLine { \textcolor { keywordtype} { double} \ mol\_ c12\ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ add67a92d73e3a57a2bbdb52bc9ca3bfe} { getMolarAbundance} } (\textcolor { stringliteral} { "{ } C-\/ 12"{ } } );}
\DoxyCodeLine { \textcolor { keywordtype} { double} \ meanA\ \ \ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ afbbb5e51ad5ae5c0fa6bc0094195aecd} { getMeanParticleMass} } ();}
\DoxyCodeLine { \textcolor { keywordtype} { double} \ Ye\ \ \ \ \ \ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a90fc71d1fe03017ee4c7a1cac69d24fb} { getElectronAbundance} } ();}
\DoxyCodeLine { \textcolor { keyword} { auto} \ \ \ canon\ \ \ \ =\ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ aac5b214a3d1278e127422224cb9cee50} { getCanonicalComposition} } ();}
2025-11-08 10:00:16 -05:00
\end { DoxyCode}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md20} { } \doxyparagraph { \texorpdfstring { 6. Exception Handling Examples} { 6. Exception Handling Examples} } \label { index_ autotoc_ md20}
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ <iostream>} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { composition_ 8h} { fourdst/composition/composition.h} } "{ } } }
\DoxyCodeLine { \textcolor { preprocessor} { \# include\ "{ } \mbox { \hyperlink { exceptions_ _ composition_ 8h} { fourdst/composition/exceptions/exceptions\_ composition.h} } "{ } } }
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \textcolor { keywordtype} { int} \ main()\ \{ }
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition} { fourdst::composition} } ;}
\DoxyCodeLine { \ \ \ \ \textcolor { keyword} { using\ namespace\ } \mbox { \hyperlink { namespacefourdst_ 1_ 1composition_ 1_ 1exceptions} { fourdst::composition::exceptions} } ;}
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ comp;}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { }
\DoxyCodeLine { \ \ \ \ \textcolor { keywordflow} { try} \ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ \textcolor { comment} { //\ Unknown\ symbol\ (not\ in\ species\ database)} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a3ab4dcda0bfd1a35b169bcc57fe66725} { registerSymbol} } (\textcolor { stringliteral} { "{ } Xx-\/ 999"{ } } );}
\DoxyCodeLine { \ \ \ \ \} \ \textcolor { keywordflow} { catch} \ (\textcolor { keyword} { const} \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1UnknownSymbolError} { UnknownSymbolError} } \ \& e)\ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor { stringliteral} { "{ } Caught\ UnknownSymbolError:\ "{ } } \ <<\ e.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1SpeciesError_ af0c63f7e05d0c65157b960c654d09b67} { what} } ()\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \} }
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a3ab4dcda0bfd1a35b169bcc57fe66725} { registerSymbol} } (\textcolor { stringliteral} { "{ } H-\/ 1"{ } } );}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { keywordflow} { try} \ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ \textcolor { comment} { //\ Unregistered\ symbol\ used\ in\ a\ setter} }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a262d7133035d4e6f45daa81827abf5e7} { setMolarAbundance} } (\textcolor { stringliteral} { "{ } He-\/ 4"{ } } ,\ 1.0);\ \textcolor { comment} { //\ He-\/ 4\ not\ registered\ yet} }
\DoxyCodeLine { \ \ \ \ \} \ \textcolor { keywordflow} { catch} \ (\textcolor { keyword} { const} \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1UnregisteredSymbolError} { UnregisteredSymbolError} } \ \& e)\ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor { stringliteral} { "{ } Caught\ UnregisteredSymbolError:\ "{ } } \ <<\ e.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1CompositionError_ ae44ceddb19da8a8cda7ee150b6826d08} { what} } ()\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a3ab4dcda0bfd1a35b169bcc57fe66725} { registerSymbol} } (\textcolor { stringliteral} { "{ } He-\/ 4"{ } } );}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \ \ \ \ \textcolor { keywordflow} { try} \ \{ }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \ \ \ \ comp.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition_ a262d7133035d4e6f45daa81827abf5e7} { setMolarAbundance} } (\textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ -\/ 3.0);}
\DoxyCodeLine { \ \ \ \ \} \ \textcolor { keywordflow} { catch} \ (\textcolor { keyword} { const} \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1InvalidCompositionError} { InvalidCompositionError} } \ \& e)\ \{ \ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor { stringliteral} { "{ } Caught\ InvalidCompositionError:\ "{ } } \ <<\ e.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1CompositionError_ ae44ceddb19da8a8cda7ee150b6826d08} { what} } ()\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \ \ \ \ \} }
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \ \ \ \ \textcolor { comment} { //\ Mass\ fraction\ construction\ validation} }
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \ \ \ \ \textcolor { keywordflow} { try} \ \{ }
2025-11-27 17:47:38 -05:00
\DoxyCodeLine { \ \ \ \ \ \ \ \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { Composition} } \ bad\ =\ \mbox { \hyperlink { namespacefourdst_ 1_ 1composition_ aa90b1ef07d607c0c829bedccf381cf54} { buildCompositionFromMassFractions} } (\{ \textcolor { stringliteral} { "{ } H-\/ 1"{ } } ,\ \textcolor { stringliteral} { "{ } He-\/ 4"{ } } \} ,\ \{ 0.6,\ 0.5\} );\ \textcolor { comment} { //\ sums\ to\ 1.1} }
\DoxyCodeLine { \ \ \ \ \} \ \textcolor { keywordflow} { catch} \ (\textcolor { keyword} { const} \ \mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1InvalidCompositionError} { InvalidCompositionError} } \ \& e)\ \{ }
\DoxyCodeLine { \ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor { stringliteral} { "{ } Caught\ InvalidCompositionError:\ "{ } } \ <<\ e.\mbox { \hyperlink { classfourdst_ 1_ 1composition_ 1_ 1exceptions_ 1_ 1CompositionError_ ae44ceddb19da8a8cda7ee150b6826d08} { what} } ()\ <<\ \textcolor { stringliteral} { "{ } \( \backslash \) n"{ } } ;}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { \ \ \ \ \} }
\DoxyCodeLine { \} }
\end { DoxyCode}
2025-11-08 10:00:16 -05:00
\DoxyHorRuler { 0}
\hypertarget { index_ exceptions_ sec} { } \doxysection { \texorpdfstring { Possible Exception States} { Possible Exception States} } \label { index_ exceptions_ sec}
The library surfaces errors through a focused hierarchy in { \ttfamily \doxylink { namespacefourdst_ 1_ 1composition_ 1_ 1exceptions} { fourdst\+ ::composition\+ ::exceptions} } \+ :
\tabulinesep =1mm
\begin { longtabu} spread 0pt [c]{ *{ 2} { |X[-1]} |}
\hline
\PBS \centering \cellcolor { \tableheadbgcolor } \textbf { Exception Type } & \PBS \centering \cellcolor { \tableheadbgcolor } \textbf { When It Occurs } \\ \cline { 1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS \centering \cellcolor { \tableheadbgcolor } \textbf { Exception Type } & \PBS \centering \cellcolor { \tableheadbgcolor } \textbf { When It Occurs } \\ \cline { 1-2}
\endhead
{ \ttfamily Unknown\+ Symbol\+ Error} & A string symbol does not correspond to any known isotope in the compiled species database. \\ \cline { 1-2}
{ \ttfamily Unregistered\+ Symbol\+ Error} & A valid species/symbol is used before being registered with a Composition instance. \\ \cline { 1-2}
{ \ttfamily Invalid\+ Composition\+ Error} & Construction from mass fractions fails validation (sum deviates from unity beyond tolerance) or canonical (X+\+ Y+Z) check fails. \\ \cline { 1-2}
{ \ttfamily Composition\+ Error} & Base class; may be thrown for generic composition-\/ level issues (e.\+ g. negative abundances via the documented { \ttfamily Invalid\+ Abundance\+ Error} contract). \\ \cline { 1-2}
\end { longtabu}
Recommended patterns\+ :
\begin { DoxyItemize}
\item Validate externally provided symbol lists before calling bulk registration.
\item Use species‑ based overloads (strongly typed) where possible for slightly lower overhead (no symbol resolution).
\item Wrap construction from mass fractions in a try/catch to surface normalization issues early.
\end { DoxyItemize}
\DoxyHorRuler { 0}
\hypertarget { index_ api_ sec} { } \doxysection { \texorpdfstring { Linking and Integration} { Linking and Integration} } \label { index_ api_ sec}
2025-11-27 17:47:38 -05:00
\hypertarget { index_ autotoc_ md23} { } \doxysubsubsection { \texorpdfstring { Linking with pkg-\/ config} { Linking with pkg-config} } \label { index_ autotoc_ md23}
2025-11-08 10:00:16 -05:00
If you installed { \ttfamily libcomposition} with the { \ttfamily pkg-\/ config} option enabled, you can get the necessary compiler and linker flags easily\+ :
2025-07-24 09:35:52 -04:00
\begin { DoxyCode} { 0}
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \# \ Get\ compiler\ flags\ (include\ paths)}
\DoxyCodeLine { pkg-\/ config\ -\/ -\/ cflags\ fourdst\_ composition}
2025-07-24 09:35:52 -04:00
\DoxyCodeLine { }
2025-11-08 10:00:16 -05:00
\DoxyCodeLine { \# \ Get\ linker\ flags\ (library\ paths\ and\ names)}
\DoxyCodeLine { pkg-\/ config\ -\/ -\/ libs\ fourdst\_ composition}
\end { DoxyCode}
{ \bfseries { Example compilation command\+ :} }
\begin { DoxyCode} { 0}
\DoxyCodeLine { g++\ my\_ app.cpp\ \$ (pkg-\/ config\ -\/ -\/ cflags\ -\/ -\/ libs\ fourdst\_ composition)\ -\/ o\ my\_ app}
2025-07-24 09:35:52 -04:00
\end { DoxyCode}
\DoxyHorRuler { 0}
2025-11-08 10:00:16 -05:00
\hypertarget { index_ api_ ref_ sec} { } \doxysection { \texorpdfstring { API Reference} { API Reference} } \label { index_ api_ ref_ sec}
For a complete list of all classes, methods, and functions, see the { \bfseries { Namespaces} } and { \bfseries { Classes} } sections of this generated documentation.
2025-07-24 09:35:52 -04:00
\begin { DoxyItemize}
2025-11-08 10:00:16 -05:00
\item Namespace overview\+ : { \ttfamily \doxylink { namespacefourdst_ 1_ 1composition} { fourdst\+ ::composition} } , { \ttfamily \doxylink { namespacefourdst_ 1_ 1atomic} { fourdst\+ ::atomic} }
2025-11-27 17:47:38 -05:00
\item Core classes\+ : { \ttfamily \doxylink { classfourdst_ 1_ 1composition_ 1_ 1Composition} { fourdst\+ ::composition\+ ::\+ Composition} } , { \ttfamily \doxylink { classfourdst_ 1_ 1composition_ 1_ 1CompositionAbstract} { fourdst\+ ::composition\+ ::\+ Composition\+ Abstract} }
2025-11-08 10:00:16 -05:00
\item Helper utilities\+ : { \ttfamily build\+ Composition\+ From\+ Mass\+ Fractions}
\item Exception hierarchy\+ : { \ttfamily \doxylink { namespacefourdst_ 1_ 1composition_ 1_ 1exceptions} { fourdst\+ ::composition\+ ::exceptions} }
2025-07-24 09:35:52 -04:00
\end { DoxyItemize}
\DoxyHorRuler { 0}
2025-11-08 10:00:16 -05:00
\hypertarget { index_ test_ sec} { } \doxysection { \texorpdfstring { Testing Overview} { Testing Overview} } \label { index_ test_ sec}
The test suite (Google\+ Test) exercises\+ :
\begin { DoxyItemize}
\item Species database integrity (selected property spot checks).
\item Registration and abundance setting (symbols vs species overloads).
\item Mass fraction utility construction and validation tolerances.
\item Canonical composition correctness (X + Y + Z ≈ 1.\+ 0).
\item Vector interface ordering and index lookup consistency.
\item Exception pathways for unknown/unregistered symbols and invalid compositions.
\end { DoxyItemize}
Use tolerances (e.\+ g. 1e-\/ 12– 1e-\/ 14) when comparing floating‑ point derived quantities in custom tests.