\doxysection{utils.\+cpp}
\hypertarget{utils_8cpp_source}{}\label{utils_8cpp_source}\index{src/composition/lib/utils.cpp@{src/composition/lib/utils.cpp}}
\mbox{\hyperlink{utils_8cpp}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00001}00001\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{composition_8h}{fourdst/composition/composition.h}}"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00002}00002\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{exceptions__composition_8h}{fourdst/composition/exceptions/exceptions\_composition.h}}"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00003}00003\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{atomic_species_8h}{fourdst/atomic/atomicSpecies.h}}"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00004}00004\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{species_8h}{fourdst/atomic/species.h}}"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00005}00005\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{utils_8h}{fourdst/composition/utils.h}}"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00006}00006\ \textcolor{preprocessor}{\#include\ "{}fourdst/logging/logging.h"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00007}00007\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00008}00008\ \textcolor{preprocessor}{\#include\ <numeric>}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00009}00009\ \textcolor{preprocessor}{\#include\ <ranges>}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00010}00010\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00011}00011\ \textcolor{preprocessor}{\#include\ <set>}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00012}00012\ \textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00013}00013\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00014}00014\ \textcolor{preprocessor}{\#include\ "{}quill/LogMacros.h"{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00015}00015\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00016}00016\ \textcolor{keyword}{namespace\ }\{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00017}00017\ \ \ \ \ quill::Logger*\ getLogger()\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00018}00018\ \ \ \ \ \ \ \ \ \textcolor{keyword}{static}\ quill::Logger*\ logger\ =\ fourdst::logging::LogManager::getInstance().getLogger(\textcolor{stringliteral}{"{}log"{}});}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00019}00019\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ logger;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00020}00020\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00021}00021\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00022}00022\ \ \ \ \ \textcolor{keywordtype}{void}\ throw\_unknown\_symbol(\textcolor{keyword}{const}\ std::string\&\ symbol)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00023}00023\ \ \ \ \ \ \ \ \ LOG\_ERROR(getLogger(),\ \textcolor{stringliteral}{"{}Symbol\ \{\}\ is\ not\ a\ valid\ species\ symbol\ (not\ in\ the\ species\ database)"{}},\ symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00024}00024\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ \mbox{\hyperlink{classfourdst_1_1composition_1_1exceptions_1_1_unknown_symbol_error}{fourdst::composition::exceptions::UnknownSymbolError}}(\textcolor{stringliteral}{"{}Symbol\ "{}}\ +\ symbol\ +\ \textcolor{stringliteral}{"{}\ is\ not\ a\ valid\ species\ symbol\ (not\ in\ the\ species\ database)"{}});}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00025}00025\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00026}00026\ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00027}00027\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00028}00028\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{namespacefourdst_1_1composition}{fourdst::composition}}\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00029}\mbox{\hyperlink{namespacefourdst_1_1composition_a2cb98194b465f646973ceba38d0e7d95}{00029}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00030}00030\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::set<atomic::Species>\ \&species,}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00031}00031\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::vector<double>\ \&massFractions}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00032}00032\ \ \ \ \ )\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00033}00033\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{double}\ sum\ =\ std::accumulate(}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00034}00034\ \ \ \ \ \ \ \ \ \ \ \ \ massFractions.begin(),}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00035}00035\ \ \ \ \ \ \ \ \ \ \ \ \ massFractions.end(),}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00036}00036\ \ \ \ \ \ \ \ \ \ \ \ \ 0.0}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00037}00037\ \ \ \ \ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00038}00038\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00039}00039\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (std::abs(sum\ -\/\ 1.0)\ >\ 1e-\/10)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00040}00040\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ \mbox{\hyperlink{classfourdst_1_1composition_1_1exceptions_1_1_invalid_composition_error}{exceptions::InvalidCompositionError}}(}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00041}00041\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Mass\ fractions\ must\ sum\ to\ 1.0,\ got\ "{}}\ +\ \ std::to\_string(sum)}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00042}00042\ \ \ \ \ \ \ \ \ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00043}00043\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00044}00044\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00045}00045\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (species.size()\ !=\ massFractions.size())\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00046}00046\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ \mbox{\hyperlink{classfourdst_1_1composition_1_1exceptions_1_1_invalid_composition_error}{exceptions::InvalidCompositionError}}(}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00047}00047\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}The\ number\ of\ species\ and\ mass\ fractions\ must\ be\ equal.\ Got\ "{}}\ +}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00048}00048\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::to\_string(species.size())\ +\ \textcolor{stringliteral}{"{}\ species\ and\ "{}}\ +}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00049}00049\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::to\_string(massFractions.size())\ +\ \textcolor{stringliteral}{"{}\ mass\ fractions."{}}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00050}00050\ \ \ \ \ \ \ \ \ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00051}00051\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00052}00052\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00053}00053\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition}{composition}};}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00054}00054\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00055}00055\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [sp,\ xi]\ :\ std::views::zip(species,\ massFractions))\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00056}00056\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{namespacefourdst_1_1composition}{composition}}.registerSpecies(sp);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00057}00057\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{namespacefourdst_1_1composition}{composition}}.setMolarAbundance(sp,\ xi/sp.mass());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00058}00058\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00059}00059\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00060}00060\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition}{composition}};}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00061}00061\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00062}00062\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00063}\mbox{\hyperlink{namespacefourdst_1_1composition_a39d4f84dfa85ddda3b9feb5dda1afc1e}{00063}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(\textcolor{keyword}{const}\ std::vector<atomic::Species>\ \&species,\ \textcolor{keyword}{const}\ std::vector<double>\ \&massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00064}00064\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ speciesSet(species.begin(),\ species.end());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00065}00065\ \ \ \ \ \ \ \ \ std::vector<double>\ sortedMassFractions;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00066}00066\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00067}00067\ \ \ \ \ \ \ \ \ sortedMassFractions.resize(massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00068}00068\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [s,\ xi]\ :\ std::views::zip(species,\ massFractions))\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00069}00069\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ index\ =\ std::distance(speciesSet.begin(),\ speciesSet.find(s));}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00070}00070\ \ \ \ \ \ \ \ \ \ \ \ \ assert\ (index\ <\ sortedMassFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00071}00071\ \ \ \ \ \ \ \ \ \ \ \ \ sortedMassFractions[index]\ =\ xi;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00072}00072\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00073}00073\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00074}00074\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(speciesSet,\ sortedMassFractions);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00075}00075\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00076}00076\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00077}\mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{00077}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(\textcolor{keyword}{const}\ std::vector<std::string>\ \&symbols,\ \textcolor{keyword}{const}\ std::vector<double>\ \&massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00078}00078\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ species;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00079}00079\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ symbol\ :\ symbols)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00080}00080\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00081}00081\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00082}00082\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00083}00083\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00084}00084\ \ \ \ \ \ \ \ \ \ \ \ \ species.insert(result.value());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00085}00085\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00086}00086\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00087}00087\ \ \ \ \ \ \ \ \ std::vector<double>\ sortedMassFractions(massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00088}00088\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [symbol,\ xi]\ :\ std::views::zip(symbols,\ massFractions))\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00089}00089\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00090}00090\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00091}00091\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00092}00092\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00093}00093\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ index\ =\ std::distance(species.begin(),\ species.find(result.value()));}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00094}00094\ \ \ \ \ \ \ \ \ \ \ \ \ assert\ (index\ <\ sortedMassFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00095}00095\ \ \ \ \ \ \ \ \ \ \ \ \ sortedMassFractions[index]\ =\ xi;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00096}00096\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00097}00097\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(species,\ sortedMassFractions);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00098}00098\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00099}00099\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00100}\mbox{\hyperlink{namespacefourdst_1_1composition_ada2fea5f3ac5cff3ecd67541a0a094fc}{00100}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(\textcolor{keyword}{const}\ std::unordered\_map<atomic::Species,\ double>\&\ massFractionsMap)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00101}00101\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ species;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00102}00102\ \ \ \ \ \ \ \ \ std::vector<double>\ massFractions;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00103}00103\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00104}00104\ \ \ \ \ \ \ \ \ massFractions.reserve(massFractionsMap.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00105}00105\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00106}00106\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ \&sp:\ massFractionsMap\ |\ std::views::keys)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00107}00107\ \ \ \ \ \ \ \ \ \ \ \ \ species.insert(sp);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00108}00108\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00109}00109\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00110}00110\ \ \ \ \ \ \ \ \ massFractions.resize(massFractionsMap.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00111}00111\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [sp,\ xi]\ :\ massFractionsMap)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00112}00112\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ index\ =\ std::distance(species.begin(),\ species.find(sp));}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00113}00113\ \ \ \ \ \ \ \ \ \ \ \ \ assert\ (index\ <\ massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00114}00114\ \ \ \ \ \ \ \ \ \ \ \ \ massFractions[index]\ =\ xi;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00115}00115\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00116}00116\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00117}00117\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(species,\ massFractions);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00118}00118\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00119}00119\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00120}\mbox{\hyperlink{namespacefourdst_1_1composition_a8163289e584a05b4075c775279761e55}{00120}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(std::map<atomic::Species,\ double>\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00121}00121\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ species;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00122}00122\ \ \ \ \ \ \ \ \ std::vector<double>\ massFractionVector;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00123}00123\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00124}00124\ \ \ \ \ \ \ \ \ massFractionVector.reserve(massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00125}00125\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00126}00126\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [sp,\ xi]\ :\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00127}00127\ \ \ \ \ \ \ \ \ \ \ \ \ species.insert(sp);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00128}00128\ \ \ \ \ \ \ \ \ \ \ \ \ massFractionVector.push\_back(xi);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00129}00129\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00130}00130\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00131}00131\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(species,\ massFractionVector);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00132}00132\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00133}00133\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00134}\mbox{\hyperlink{namespacefourdst_1_1composition_abd0e185f7fd52130f36414faf2dc07d7}{00134}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(std::map<std::string,\ double>\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00135}00135\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ species;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00136}00136\ \ \ \ \ \ \ \ \ std::vector<double>\ massFractionVector;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00137}00137\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00138}00138\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00139}00139\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ \&symbol:\ massFractions\ |\ std::views::keys)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00140}00140\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00141}00141\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00142}00142\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00143}00143\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00144}00144\ \ \ \ \ \ \ \ \ \ \ \ \ species.insert(result.value());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00145}00145\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00146}00146\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00147}00147\ \ \ \ \ \ \ \ \ massFractionVector.resize(massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00148}00148\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00149}00149\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [symbol,\ xi]\ :\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00150}00150\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00151}00151\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00152}00152\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00153}00153\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00154}00154\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ index\ =\ std::distance(species.begin(),\ species.find(result.value()));}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00155}00155\ \ \ \ \ \ \ \ \ \ \ \ \ assert\ (index\ <\ massFractionVector.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00156}00156\ \ \ \ \ \ \ \ \ \ \ \ \ massFractionVector[index]\ =\ xi;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00157}00157\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00158}00158\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00159}00159\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00160}00160\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(species,\ massFractionVector);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00161}00161\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00162}00162\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00163}\mbox{\hyperlink{namespacefourdst_1_1composition_abf844ad6e10524bf99fc3bf6c9d68465}{00163}}\ \ \ \ \ \mbox{\hyperlink{classfourdst_1_1composition_1_1_composition}{Composition}}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(\textcolor{keyword}{const}\ std::unordered\_map<std::string,\ double>\&\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00164}00164\ \ \ \ \ \ \ \ \ std::set<atomic::Species>\ species;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00165}00165\ \ \ \ \ \ \ \ \ std::vector<double>\ massFractionVector;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00166}00166\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00167}00167\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ \&symbol:\ massFractions\ |\ std::views::keys)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00168}00168\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00169}00169\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00170}00170\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00171}00171\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00172}00172\ \ \ \ \ \ \ \ \ \ \ \ \ species.insert(result.value());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00173}00173\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00174}00174\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00175}00175\ \ \ \ \ \ \ \ \ massFractionVector.resize(massFractions.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00176}00176\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ [sp,\ xi]\ :\ massFractions)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00177}00177\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(sp);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00178}00178\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!result)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00179}00179\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ throw\_unknown\_symbol(sp);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00180}00180\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00181}00181\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ index\ =\ std::distance(species.begin(),\ species.find(result.value()));}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00182}00182\ \ \ \ \ \ \ \ \ \ \ \ \ assert\ (index\ <\ massFractionVector.size());}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00183}00183\ \ \ \ \ \ \ \ \ \ \ \ \ massFractionVector[index]\ =\ xi;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00184}00184\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00185}00185\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00186}00186\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1composition_aa90b1ef07d607c0c829bedccf381cf54}{buildCompositionFromMassFractions}}(species,\ massFractionVector);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00187}00187\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00188}00188\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00189}\mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{00189}}\ \ \ \ \ std::optional<fourdst::atomic::Species>\ \mbox{\hyperlink{namespacefourdst_1_1composition_adcc2e4ca25ab7b93983730fc78f4deea}{getSpecies}}(\textcolor{keyword}{const}\ std::string\&\ symbol)\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00190}00190\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{namespacefourdst_1_1atomic_a3f619cc8f8b2cd718a4082c6adb0de90}{fourdst::atomic::species}}.contains(symbol))\ \{}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00191}00191\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ std::nullopt;}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00192}00192\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00193}00193\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{namespacefourdst_1_1atomic_a3f619cc8f8b2cd718a4082c6adb0de90}{fourdst::atomic::species}}.at(symbol);}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00194}00194\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00195}00195\ }
\DoxyCodeLine{\Hypertarget{utils_8cpp_source_l00196}00196\ \}}

\end{DoxyCode}
