SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
comp.cpp
Go to the documentation of this file.
1#include "composition.h"
2#include "config.h"
3#include <string>
4
5int main(int argv, char* argc[]) {
6 std::string pathToConfigFile;
7 if (argv == 2) {
8 pathToConfigFile = argc[1];
9 } else {
10 pathToConfigFile = "config.json";
11 }
12 serif::config::Config::getInstance().loadConfig(pathToConfigFile);
14 std::vector<std::string> symbols = {"H-1", "He-4"};
15 comp.registerSymbol(symbols);
16 comp.setMassFraction("H-1", 0.7);
17 comp.setMassFraction("He-4", 0.3);
18 comp.finalize();
19 std::cout << "=== Mass Fraction Mode ===" << std::endl;
20 std::cout << "\tH-1 Mass Frac: " << comp.getMassFraction("H-1") << std::endl;
21 std::cout << "\tH-1 Number Frac: " << comp.getNumberFraction("H-1") << std::endl;
22 std::cout << "\tHe-4 Mass Frac: " << comp.getMassFraction("He-4") << std::endl;
23 std::cout << "\tHe-4 Number Frac: " << comp.getNumberFraction("He-4") << std::endl;
24
25 std::cout << "\tMass Frac Sum: " << comp.getMassFraction("H-1") + comp.getMassFraction("He-4") << std::endl;
26 std::cout << "\tNumber Frac Sum: " << comp.getNumberFraction("H-1") + comp.getNumberFraction("He-4") << std::endl;
27
29 comp2.registerSymbol(symbols, false);
30 comp2.setNumberFraction("H-1", comp.getNumberFraction("H-1"));
31 comp2.setNumberFraction("He-4", comp.getNumberFraction("He-4"));
32
33 comp2.finalize();
34 std::cout << "=== Number Fraction Mode ===" << std::endl;
35 std::cout << "\tH-1 Mass Frac: " << comp2.getMassFraction("H-1") << std::endl;
36 std::cout << "\tH-1 Number Frac: " << comp2.getNumberFraction("H-1") << std::endl;
37 std::cout << "\tHe-4 Mass Frac: " << comp2.getMassFraction("He-4") << std::endl;
38 std::cout << "\tHe-4 Number Frac: " << comp2.getNumberFraction("He-4") << std::endl;
39
40 std::cout << "\tMass Frac Sum: " << comp2.getMassFraction("H-1") + comp2.getMassFraction("He-4") << std::endl;
41 std::cout << "\tNumber Frac Sum: " << comp2.getNumberFraction("H-1") + comp2.getNumberFraction("He-4") << std::endl;
42
43
44 std::vector<std::string> symbols3 = {
45 "H-1",
46 "He-3",
47 "He-4",
48 "Li-6",
49 "Li-7",
50 "O-16",
51 "C-12",
52 "Fe-56",
53 "Ne-20",
54 "N-14",
55 "Mg-24",
56 "Si-28",
57 "S-32",
58 "Ca-40",
59 };
60 std::vector<double> mass_fractions = {
61 0.71243,
62 1e-5,
63 0.27,
64 1e-11,
65 1e-9,
66 0.009,
67 0.003,
68 0.0014,
69 0.0015,
70 0.001,
71 0.0006,
72 0.0006,
73 0.0004,
74 0.00006
75 };
76 serif::composition::Composition comp3(symbols3, mass_fractions, true);
77 std::cout << "=== Mass Fraction Mode ===" << std::endl;
78 double massFracSum = 0.0;
79 double numberFracSum = 0.0;
80 for (const auto& symbol : symbols3) {
81 std::cout << "\t" << symbol << " Mass Frac: " << comp3.getMassFraction(symbol) << std::endl;
82 std::cout << "\t" << symbol << " Number Frac: " << comp3.getNumberFraction(symbol) << std::endl;
83 massFracSum += comp3.getMassFraction(symbol);
84 numberFracSum += comp3.getNumberFraction(symbol);
85 }
86 std::cout << "\tMass Frac Sum: " << massFracSum << std::endl;
87 std::cout << "\tNumber Frac Sum: " << numberFracSum << std::endl;
88
89
90 return 0;
91}
Manages the composition of elements.
double getNumberFraction(const std::string &symbol) const
Gets the number fraction for a given symbol.
std::unordered_map< std::string, double > getMassFraction() const
Gets the mass fractions of all compositions.
void registerSymbol(const std::string &symbol, bool massFracMode=true)
Registers a new symbol.
bool finalize(bool norm=false)
Finalizes the composition.
double setNumberFraction(const std::string &symbol, const double &number_fraction)
Sets the number fraction for a given symbol.
int main()
Definition lookupTest.cpp:3