Merge branch 'main' into feature/pointwisePolytrope
This commit is contained in:
33
src/composition/meson.build
Normal file
33
src/composition/meson.build
Normal file
@@ -0,0 +1,33 @@
|
||||
# Define the library
|
||||
composition_sources = files(
|
||||
'private/composition.cpp',
|
||||
)
|
||||
|
||||
composition_headers = files(
|
||||
'public/composition.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
probe_dep,
|
||||
config_dep,
|
||||
quill_dep,
|
||||
species_weight_dep
|
||||
]
|
||||
|
||||
# Define the libcomposition library so it can be linked against by other parts of the build system
|
||||
libcomposition = static_library('composition',
|
||||
composition_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
dependencies: dependencies,
|
||||
install : true)
|
||||
|
||||
composition_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libcomposition,
|
||||
dependencies: dependencies,
|
||||
sources: composition_sources,
|
||||
)
|
||||
|
||||
# Make headers accessible
|
||||
install_headers(composition_headers, subdir : '4DSSE/composition')
|
||||
536
src/composition/private/composition.cpp
Normal file
536
src/composition/private/composition.cpp
Normal file
@@ -0,0 +1,536 @@
|
||||
#include "composition.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atomicSpecies.h"
|
||||
|
||||
using namespace composition;
|
||||
|
||||
CompositionEntry::CompositionEntry() : m_symbol("H-1"), m_isotope(chemSpecies::species.at("H-1")), m_initialized(false) {}
|
||||
|
||||
CompositionEntry::CompositionEntry(const std::string& symbol, bool massFracMode) : m_symbol(symbol), m_isotope(chemSpecies::species.at(symbol)), m_massFracMode(massFracMode) {
|
||||
setSpecies(symbol);
|
||||
}
|
||||
|
||||
CompositionEntry::CompositionEntry(const CompositionEntry& entry) :
|
||||
m_symbol(entry.m_symbol),
|
||||
m_isotope(entry.m_isotope),
|
||||
m_massFracMode(entry.m_massFracMode),
|
||||
m_massFraction(entry.m_massFraction),
|
||||
m_numberFraction(entry.m_numberFraction),
|
||||
m_relAbundance(entry.m_relAbundance),
|
||||
m_initialized(entry.m_initialized) {}
|
||||
|
||||
void CompositionEntry::setSpecies(const std::string& symbol) {
|
||||
if (m_initialized) {
|
||||
throw std::runtime_error("Composition entry is already initialized.");
|
||||
}
|
||||
if (chemSpecies::species.count(symbol) == 0) {
|
||||
throw std::runtime_error("Invalid symbol.");
|
||||
}
|
||||
m_symbol = symbol;
|
||||
m_isotope = chemSpecies::species.at(symbol);
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
std::string CompositionEntry::symbol() const {
|
||||
return m_symbol;
|
||||
}
|
||||
|
||||
double CompositionEntry::mass_fraction() const {
|
||||
if (!m_massFracMode) {
|
||||
throw std::runtime_error("Composition entry is in number fraction mode.");
|
||||
}
|
||||
return m_massFraction;
|
||||
}
|
||||
|
||||
double CompositionEntry::mass_fraction(double meanMolarMass) const {
|
||||
if (m_massFracMode) {
|
||||
return m_massFraction;
|
||||
}
|
||||
return m_relAbundance / meanMolarMass;
|
||||
}
|
||||
|
||||
|
||||
double CompositionEntry::number_fraction() const {
|
||||
if (m_massFracMode) {
|
||||
throw std::runtime_error("Composition entry is in mass fraction mode.");
|
||||
}
|
||||
return m_numberFraction;
|
||||
}
|
||||
|
||||
double CompositionEntry::number_fraction(double totalMoles) const {
|
||||
if (m_massFracMode) {
|
||||
return m_relAbundance / totalMoles;
|
||||
}
|
||||
return m_numberFraction;
|
||||
}
|
||||
|
||||
double CompositionEntry::rel_abundance() const {
|
||||
return m_relAbundance;
|
||||
}
|
||||
|
||||
chemSpecies::Species CompositionEntry::isotope() const {
|
||||
return m_isotope;
|
||||
}
|
||||
|
||||
void CompositionEntry::setMassFraction(double mass_fraction) {
|
||||
if (!m_massFracMode) {
|
||||
throw std::runtime_error("Composition entry is in number fraction mode.");
|
||||
}
|
||||
m_massFraction = mass_fraction;
|
||||
m_relAbundance = m_massFraction / m_isotope.mass();
|
||||
}
|
||||
|
||||
void CompositionEntry::setNumberFraction(double number_fraction) {
|
||||
if (m_massFracMode) {
|
||||
throw std::runtime_error("Composition entry is in mass fraction mode.");
|
||||
}
|
||||
m_numberFraction = number_fraction;
|
||||
m_relAbundance = m_numberFraction * m_isotope.mass();
|
||||
}
|
||||
|
||||
bool CompositionEntry::setMassFracMode(double meanParticleMass) {
|
||||
if (m_massFracMode) {
|
||||
return false;
|
||||
}
|
||||
m_massFracMode = true;
|
||||
m_massFraction = m_relAbundance / meanParticleMass;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompositionEntry::setNumberFracMode(double specificNumberDensity) {
|
||||
if (!m_massFracMode) {
|
||||
return false;
|
||||
}
|
||||
m_massFracMode = false;
|
||||
m_numberFraction = m_relAbundance / specificNumberDensity;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompositionEntry::getMassFracMode() const {
|
||||
return m_massFracMode;
|
||||
}
|
||||
|
||||
Composition::Composition(const std::vector<std::string>& symbols) {
|
||||
for (const auto& symbol : symbols) {
|
||||
registerSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
Composition::Composition(const std::set<std::string>& symbols) {
|
||||
for (const auto& symbol : symbols) {
|
||||
registerSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
Composition::Composition(const std::vector<std::string>& symbols, const std::vector<double>& fractions, bool massFracMode) : m_massFracMode(massFracMode) {
|
||||
if (symbols.size() != fractions.size()) {
|
||||
LOG_ERROR(m_logger, "The number of symbols and fractions must be equal.");
|
||||
throw std::runtime_error("The number of symbols and fractions must be equal.");
|
||||
}
|
||||
|
||||
validateComposition(fractions);
|
||||
|
||||
for (const auto &symbol : symbols) {
|
||||
registerSymbol(symbol);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < symbols.size(); ++i) {
|
||||
if (m_massFracMode) {
|
||||
setMassFraction(symbols[i], fractions[i]);
|
||||
} else {
|
||||
setNumberFraction(symbols[i], fractions[i]);
|
||||
}
|
||||
}
|
||||
finalize();
|
||||
}
|
||||
|
||||
void Composition::registerSymbol(const std::string& symbol, bool massFracMode) {
|
||||
if (!isValidSymbol(symbol)) {
|
||||
LOG_ERROR(m_logger, "Invalid symbol: {}", symbol);
|
||||
throw std::runtime_error("Invalid symbol.");
|
||||
}
|
||||
|
||||
// If no symbols have been registered allow mode to be set
|
||||
if (m_registeredSymbols.size() == 0) {
|
||||
m_massFracMode = massFracMode;
|
||||
} else {
|
||||
if (m_massFracMode != massFracMode) {
|
||||
LOG_ERROR(m_logger, "Composition is in mass fraction mode. Cannot register symbol in number fraction mode.");
|
||||
throw std::runtime_error("Composition is in mass fraction mode. Cannot register symbol in number fraction mode.");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_registeredSymbols.find(symbol) != m_registeredSymbols.end()) {
|
||||
LOG_WARNING(m_logger, "Symbol {} is already registered.", symbol);
|
||||
return;
|
||||
}
|
||||
|
||||
m_registeredSymbols.insert(symbol);
|
||||
CompositionEntry entry(symbol, m_massFracMode);
|
||||
m_compositions[symbol] = entry;
|
||||
LOG_INFO(m_logger, "Registered symbol: {}", symbol);
|
||||
}
|
||||
|
||||
void Composition::registerSymbol(const std::vector<std::string>& symbols, bool massFracMode) {
|
||||
for (const auto& symbol : symbols) {
|
||||
registerSymbol(symbol, massFracMode);
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> Composition::getRegisteredSymbols() const {
|
||||
return m_registeredSymbols;
|
||||
}
|
||||
|
||||
void Composition::validateComposition(const std::vector<double>& fractions) const {
|
||||
if (!isValidComposition(fractions)) {
|
||||
LOG_ERROR(m_logger, "Invalid composition.");
|
||||
throw std::runtime_error("Invalid composition.");
|
||||
}
|
||||
}
|
||||
|
||||
bool Composition::isValidComposition(const std::vector<double>& fractions) const {
|
||||
double sum = 0.0;
|
||||
for (const auto& fraction : fractions) {
|
||||
sum += fraction;
|
||||
}
|
||||
if (sum < 0.999999 || sum > 1.000001) {
|
||||
LOG_ERROR(m_logger, "The sum of fractions must be equal to 1.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Composition::isValidSymbol(const std::string& symbol) const {
|
||||
return chemSpecies::species.count(symbol) > 0;
|
||||
}
|
||||
|
||||
double Composition::setMassFraction(const std::string& symbol, const double& mass_fraction) {
|
||||
if (m_registeredSymbols.find(symbol) == m_registeredSymbols.end()) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not registered.", symbol);
|
||||
throw std::runtime_error("Symbol is not registered.");
|
||||
}
|
||||
|
||||
if (!m_massFracMode) {
|
||||
LOG_ERROR(m_logger, "Composition is in number fraction mode.");
|
||||
throw std::runtime_error("Composition is in number fraction mode.");
|
||||
}
|
||||
|
||||
if (mass_fraction < 0.0 || mass_fraction > 1.0) {
|
||||
LOG_ERROR(m_logger, "Mass fraction must be between 0 and 1 for symbol {}. Currently it is {}.", symbol, mass_fraction);
|
||||
throw std::runtime_error("Mass fraction must be between 0 and 1.");
|
||||
}
|
||||
|
||||
m_finalized = false;
|
||||
double old_mass_fraction = m_compositions.at(symbol).mass_fraction();
|
||||
m_compositions.at(symbol).setMassFraction(mass_fraction);
|
||||
|
||||
return old_mass_fraction;
|
||||
}
|
||||
|
||||
std::vector<double> Composition::setMassFraction(const std::vector<std::string>& symbols, const std::vector<double>& mass_fractions) {
|
||||
if (symbols.size() != mass_fractions.size()) {
|
||||
LOG_ERROR(m_logger, "The number of symbols and mass fractions must be equal.");
|
||||
throw std::runtime_error("The number of symbols and mass fractions must be equal.");
|
||||
}
|
||||
|
||||
std::vector<double> old_mass_fractions;
|
||||
old_mass_fractions.reserve(symbols.size());
|
||||
for (size_t i = 0; i < symbols.size(); ++i) {
|
||||
old_mass_fractions.push_back(setMassFraction(symbols[i], mass_fractions[i]));
|
||||
}
|
||||
return old_mass_fractions;
|
||||
}
|
||||
|
||||
double Composition::setNumberFraction(const std::string& symbol, const double& number_fraction) {
|
||||
if (m_registeredSymbols.find(symbol) == m_registeredSymbols.end()) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not registered.", symbol);
|
||||
throw std::runtime_error("Symbol is not registered.");
|
||||
}
|
||||
|
||||
if (m_massFracMode) {
|
||||
LOG_ERROR(m_logger, "Composition is in mass fraction mode.");
|
||||
throw std::runtime_error("Composition is in mass fraction mode.");
|
||||
}
|
||||
|
||||
if (number_fraction < 0.0 || number_fraction > 1.0) {
|
||||
LOG_ERROR(m_logger, "Number fraction must be between 0 and 1 for symbol {}. Currently it is {}.", symbol, number_fraction);
|
||||
throw std::runtime_error("Number fraction must be between 0 and 1.");
|
||||
}
|
||||
|
||||
m_finalized = false;
|
||||
double old_number_fraction = m_compositions.at(symbol).number_fraction();
|
||||
m_compositions.at(symbol).setNumberFraction(number_fraction);
|
||||
|
||||
return old_number_fraction;
|
||||
}
|
||||
|
||||
std::vector<double> Composition::setNumberFraction(const std::vector<std::string>& symbols, const std::vector<double>& number_fractions) {
|
||||
if (symbols.size() != number_fractions.size()) {
|
||||
LOG_ERROR(m_logger, "The number of symbols and number fractions must be equal.");
|
||||
throw std::runtime_error("The number of symbols and number fractions must be equal.");
|
||||
}
|
||||
|
||||
std::vector<double> old_number_fractions;
|
||||
old_number_fractions.reserve(symbols.size());
|
||||
for (size_t i = 0; i < symbols.size(); ++i) {
|
||||
old_number_fractions.push_back(setNumberFraction(symbols[i], number_fractions[i]));
|
||||
}
|
||||
return old_number_fractions;
|
||||
}
|
||||
|
||||
bool Composition::finalize(bool norm) {
|
||||
bool finalized = false;
|
||||
if (m_massFracMode) {
|
||||
finalized = finalizeMassFracMode(norm);
|
||||
} else {
|
||||
finalized = finalizeNumberFracMode(norm);
|
||||
}
|
||||
if (finalized) {
|
||||
m_finalized = true;
|
||||
}
|
||||
return finalized;
|
||||
}
|
||||
|
||||
bool Composition::finalizeMassFracMode(bool norm) {
|
||||
std::vector<double> mass_fractions;
|
||||
mass_fractions.reserve(m_compositions.size());
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
mass_fractions.push_back(entry.mass_fraction());
|
||||
}
|
||||
if (norm) {
|
||||
double sum = 0.0;
|
||||
for (const auto& mass_fraction : mass_fractions) {
|
||||
sum += mass_fraction;
|
||||
}
|
||||
for (int i = 0; i < mass_fractions.size(); ++i) {
|
||||
mass_fractions[i] /= sum;
|
||||
}
|
||||
for (auto& [symbol, entry] : m_compositions) {
|
||||
setMassFraction(symbol, entry.mass_fraction() / sum);
|
||||
}
|
||||
}
|
||||
try {
|
||||
validateComposition(mass_fractions);
|
||||
} catch (const std::runtime_error& e) {
|
||||
double massSum = 0.0;
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
massSum += entry.mass_fraction();
|
||||
}
|
||||
LOG_ERROR(m_logger, "Composition is invalid (Total mass {}).", massSum);
|
||||
m_finalized = false;
|
||||
return false;
|
||||
}
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
m_specificNumberDensity += entry.rel_abundance();
|
||||
}
|
||||
m_meanParticleMass = 1.0/m_specificNumberDensity;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Composition::finalizeNumberFracMode(bool norm) {
|
||||
std::vector<double> number_fractions;
|
||||
number_fractions.reserve(m_compositions.size());
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
number_fractions.push_back(entry.number_fraction());
|
||||
}
|
||||
if (norm) {
|
||||
double sum = 0.0;
|
||||
for (const auto& number_fraction : number_fractions) {
|
||||
sum += number_fraction;
|
||||
}
|
||||
for (auto& [symbol, entry] : m_compositions) {
|
||||
setNumberFraction(symbol, entry.number_fraction() / sum);
|
||||
}
|
||||
}
|
||||
try {
|
||||
validateComposition(number_fractions);
|
||||
} catch (const std::runtime_error& e) {
|
||||
double numberSum = 0.0;
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
numberSum += entry.number_fraction();
|
||||
}
|
||||
LOG_ERROR(m_logger, "Composition is invalid (Total number {}).", numberSum);
|
||||
m_finalized = false;
|
||||
return false;
|
||||
}
|
||||
for (const auto& [_, entry] : m_compositions) {
|
||||
m_meanParticleMass += entry.rel_abundance();
|
||||
}
|
||||
m_specificNumberDensity = 1.0/m_meanParticleMass;
|
||||
return true;
|
||||
}
|
||||
|
||||
Composition Composition::mix(const Composition& other, double fraction) const {
|
||||
if (!m_finalized || !other.m_finalized) {
|
||||
LOG_ERROR(m_logger, "Compositions have not both been finalized.");
|
||||
throw std::runtime_error("Compositions have not been finalized (Consider running .finalize()).");
|
||||
}
|
||||
|
||||
if (fraction < 0.0 || fraction > 1.0) {
|
||||
LOG_ERROR(m_logger, "Fraction must be between 0 and 1.");
|
||||
throw std::runtime_error("Fraction must be between 0 and 1.");
|
||||
}
|
||||
|
||||
std::set<std::string> mixedSymbols = other.getRegisteredSymbols();
|
||||
// Get the union of the two sets
|
||||
mixedSymbols.insert(m_registeredSymbols.begin(), m_registeredSymbols.end());
|
||||
|
||||
Composition mixedComposition(mixedSymbols);
|
||||
for (const auto& symbol : mixedSymbols) {
|
||||
double thisMassFrac, otherMassFrac = 0.0;
|
||||
|
||||
thisMassFrac = hasSymbol(symbol) ? getMassFraction(symbol) : 0.0;
|
||||
otherMassFrac = other.hasSymbol(symbol) ? other.getMassFraction(symbol) : 0.0;
|
||||
|
||||
double massFraction = fraction * thisMassFrac + otherMassFrac * (1-fraction);
|
||||
mixedComposition.setMassFraction(symbol, massFraction);
|
||||
}
|
||||
mixedComposition.finalize();
|
||||
return mixedComposition;
|
||||
}
|
||||
|
||||
double Composition::getMassFraction(const std::string& symbol) const {
|
||||
if (!m_finalized) {
|
||||
LOG_ERROR(m_logger, "Composition has not been finalized.");
|
||||
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()).");
|
||||
}
|
||||
if (m_compositions.count(symbol) == 0) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not in the composition.", symbol);
|
||||
throw std::runtime_error("Symbol is not in the composition.");
|
||||
}
|
||||
if (m_massFracMode) {
|
||||
return m_compositions.at(symbol).mass_fraction();
|
||||
} else {
|
||||
return m_compositions.at(symbol).mass_fraction(m_meanParticleMass);
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> Composition::getMassFraction() const {
|
||||
std::unordered_map<std::string, double> mass_fractions;
|
||||
for (const auto& [symbol, entry] : m_compositions) {
|
||||
mass_fractions[symbol] = getMassFraction(symbol);
|
||||
}
|
||||
return mass_fractions;
|
||||
}
|
||||
|
||||
|
||||
double Composition::getNumberFraction(const std::string& symbol) const {
|
||||
if (!m_finalized) {
|
||||
LOG_ERROR(m_logger, "Composition has not been finalized.");
|
||||
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()).");
|
||||
}
|
||||
if (m_compositions.count(symbol) == 0) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not in the composition.", symbol);
|
||||
throw std::runtime_error("Symbol is not in the composition.");
|
||||
}
|
||||
if (!m_massFracMode) {
|
||||
return m_compositions.at(symbol).number_fraction();
|
||||
} else {
|
||||
return m_compositions.at(symbol).number_fraction(m_specificNumberDensity);
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> Composition::getNumberFraction() const {
|
||||
std::unordered_map<std::string, double> number_fractions;
|
||||
for (const auto& [symbol, entry] : m_compositions) {
|
||||
number_fractions[symbol] = getNumberFraction(symbol);
|
||||
}
|
||||
return number_fractions;
|
||||
}
|
||||
|
||||
std::pair<CompositionEntry, GlobalComposition> Composition::getComposition(const std::string& symbol) const {
|
||||
if (!m_finalized) {
|
||||
LOG_ERROR(m_logger, "Composition has not been finalized.");
|
||||
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()).");
|
||||
}
|
||||
if (m_compositions.count(symbol) == 0) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not in the composition.", symbol);
|
||||
throw std::runtime_error("Symbol is not in the composition.");
|
||||
}
|
||||
return {m_compositions.at(symbol), {m_specificNumberDensity, m_meanParticleMass}};
|
||||
}
|
||||
|
||||
std::pair<std::unordered_map<std::string, CompositionEntry>, GlobalComposition> Composition::getComposition() const {
|
||||
if (!m_finalized) {
|
||||
LOG_ERROR(m_logger, "Composition has not been finalized.");
|
||||
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()).");
|
||||
}
|
||||
return {m_compositions, {m_specificNumberDensity, m_meanParticleMass}};
|
||||
}
|
||||
|
||||
Composition Composition::subset(const std::vector<std::string>& symbols, std::string method) const {
|
||||
std::array<std::string, 2> methods = {"norm", "none"};
|
||||
|
||||
if (std::find(methods.begin(), methods.end(), method) == methods.end()) {
|
||||
std::string errorMessage = "Invalid method: " + method + ". Valid methods are 'norm' and 'none'.";
|
||||
LOG_ERROR(m_logger, "Invalid method: {}. Valid methods are norm and none.", method);
|
||||
throw std::runtime_error(errorMessage);
|
||||
}
|
||||
|
||||
Composition subsetComposition;
|
||||
for (const auto& symbol : symbols) {
|
||||
if (m_compositions.count(symbol) == 0) {
|
||||
LOG_ERROR(m_logger, "Symbol {} is not in the composition.", symbol);
|
||||
throw std::runtime_error("Symbol is not in the composition.");
|
||||
} else {
|
||||
subsetComposition.registerSymbol(symbol);
|
||||
}
|
||||
subsetComposition.setMassFraction(symbol, m_compositions.at(symbol).mass_fraction());
|
||||
}
|
||||
if (method == "norm") {
|
||||
bool isNorm = subsetComposition.finalize(true);
|
||||
if (!isNorm) {
|
||||
LOG_ERROR(m_logger, "Subset composition is invalid.");
|
||||
throw std::runtime_error("Subset composition is invalid.");
|
||||
}
|
||||
}
|
||||
return subsetComposition;
|
||||
}
|
||||
|
||||
void Composition::setCompositionMode(bool massFracMode) {
|
||||
if (!m_finalized) {
|
||||
LOG_ERROR(m_logger, "Composition has not been finalized. Mode cannot be set unless composition is finalized.");
|
||||
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()). The mode cannot be set unless the composition is finalized.");
|
||||
}
|
||||
|
||||
bool okay = true;
|
||||
for (auto& [_, entry] : m_compositions) {
|
||||
if (massFracMode) {
|
||||
okay = entry.setMassFracMode(m_meanParticleMass);
|
||||
} else {
|
||||
okay = entry.setNumberFracMode(m_specificNumberDensity);
|
||||
}
|
||||
if (!okay) {
|
||||
LOG_ERROR(m_logger, "Composition mode could not be set.");
|
||||
throw std::runtime_error("Composition mode could not be set due to an unknown error.");
|
||||
}
|
||||
}
|
||||
m_massFracMode = massFracMode;
|
||||
}
|
||||
|
||||
bool Composition::hasSymbol(const std::string& symbol) const {
|
||||
return m_compositions.count(symbol) > 0;
|
||||
}
|
||||
|
||||
/// OVERLOADS
|
||||
|
||||
Composition Composition::operator+(const Composition& other) const {
|
||||
return mix(other, 0.5);
|
||||
}
|
||||
|
||||
std::ostream& composition::operator<<(std::ostream& os, const Composition& composition) {
|
||||
os << "Composition: \n";
|
||||
for (const auto& [symbol, entry] : composition.m_compositions) {
|
||||
os << entry << "\n";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
456
src/composition/public/composition.h
Normal file
456
src/composition/public/composition.h
Normal file
@@ -0,0 +1,456 @@
|
||||
#ifndef COMPOSITION_H
|
||||
#define COMPOSITION_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "probe.h"
|
||||
#include "config.h"
|
||||
|
||||
#include "atomicSpecies.h"
|
||||
|
||||
namespace composition{
|
||||
/**
|
||||
* @brief Represents the global composition of a system. This tends to be used after finalize and is primarily for internal use.
|
||||
*/
|
||||
struct GlobalComposition {
|
||||
double specificNumberDensity; ///< The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species).
|
||||
double meanParticleMass; ///< The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species).
|
||||
|
||||
// Overload the output stream operator for GlobalComposition
|
||||
friend std::ostream& operator<<(std::ostream& os, const GlobalComposition& comp) {
|
||||
os << "Global Composition: \n";
|
||||
os << "\tSpecific Number Density: " << comp.specificNumberDensity << "\n";
|
||||
os << "\tMean Particle Mass: " << comp.meanParticleMass << "\n";
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an entry in the composition with a symbol and mass fraction.
|
||||
*/
|
||||
struct CompositionEntry {
|
||||
std::string m_symbol; ///< The chemical symbol of the species.
|
||||
chemSpecies::Species m_isotope; ///< The isotope of the species.
|
||||
bool m_massFracMode = true; ///< The mode of the composition entry. True if mass fraction, false if number fraction.
|
||||
|
||||
double m_massFraction = 0.0; ///< The mass fraction of the species.
|
||||
double m_numberFraction = 0.0; ///< The number fraction of the species.
|
||||
double m_relAbundance = 0.0; ///< The relative abundance of the species for converting between mass and number fractions.
|
||||
|
||||
bool m_initialized = false; ///< True if the composition entry has been initialized.
|
||||
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
*/
|
||||
CompositionEntry();
|
||||
|
||||
/**
|
||||
* @brief Constructs a CompositionEntry with the given symbol and mode.
|
||||
* @param symbol The chemical symbol of the species.
|
||||
* @param massFracMode True if mass fraction mode, false if number fraction mode.
|
||||
* @example
|
||||
* @code
|
||||
* CompositionEntry entry("H", true);
|
||||
* @endcode
|
||||
*/
|
||||
CompositionEntry(const std::string& symbol, bool massFracMode=true);
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
* @param entry The CompositionEntry to copy.
|
||||
*/
|
||||
CompositionEntry(const CompositionEntry& entry);
|
||||
|
||||
/**
|
||||
* @brief Sets the species for the composition entry.
|
||||
* @param symbol The chemical symbol of the species.
|
||||
*/
|
||||
void setSpecies(const std::string& symbol);
|
||||
|
||||
/**
|
||||
* @brief Gets the chemical symbol of the species.
|
||||
* @return The chemical symbol of the species.
|
||||
*/
|
||||
std::string symbol() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the mass fraction of the species.
|
||||
* @return The mass fraction of the species.
|
||||
*/
|
||||
double mass_fraction() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the mass fraction of the species given the mean molar mass.
|
||||
* @param meanMolarMass The mean molar mass.
|
||||
* @return The mass fraction of the species.
|
||||
*/
|
||||
double mass_fraction(double meanMolarMass) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the number fraction of the species.
|
||||
* @return The number fraction of the species.
|
||||
*/
|
||||
double number_fraction() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the number fraction of the species given the total moles.
|
||||
* @param totalMoles The total moles.
|
||||
* @return The number fraction of the species.
|
||||
*/
|
||||
double number_fraction(double totalMoles) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the relative abundance of the species.
|
||||
* @return The relative abundance of the species.
|
||||
*/
|
||||
double rel_abundance() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the isotope of the species.
|
||||
* @return The isotope of the species.
|
||||
*/
|
||||
chemSpecies::Species isotope() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the mode of the composition entry.
|
||||
* @return True if mass fraction mode, false if number fraction mode.
|
||||
*/
|
||||
bool getMassFracMode() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the mass fraction of the species.
|
||||
* @param mass_fraction The mass fraction to set.
|
||||
*/
|
||||
void setMassFraction(double mass_fraction);
|
||||
|
||||
/**
|
||||
* @brief Sets the number fraction of the species.
|
||||
* @param number_fraction The number fraction to set.
|
||||
*/
|
||||
void setNumberFraction(double number_fraction);
|
||||
|
||||
/**
|
||||
* @brief Sets the mode to mass fraction mode.
|
||||
* @param meanMolarMass The mean molar mass.
|
||||
* @return True if the mode was successfully set, false otherwise.
|
||||
*/
|
||||
bool setMassFracMode(double meanMolarMass);
|
||||
|
||||
/**
|
||||
* @brief Sets the mode to number fraction mode.
|
||||
* @param totalMoles The total moles.
|
||||
* @return True if the mode was successfully set, false otherwise.
|
||||
*/
|
||||
bool setNumberFracMode(double totalMoles);
|
||||
|
||||
/**
|
||||
* @brief Overloaded output stream operator for CompositionEntry.
|
||||
* @param os The output stream.
|
||||
* @param entry The CompositionEntry to output.
|
||||
* @return The output stream.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const CompositionEntry& entry) {
|
||||
os << "<" << entry.m_symbol << " : m_frac = " << entry.mass_fraction() << ">";
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Manages the composition of elements.
|
||||
* @details The composition is a collection of elements with their respective mass fractions.
|
||||
* The general purpose of this class is to provide a standardized interface for managing the composition of
|
||||
* any part of 4DSSE. There are a few rules when using this class.
|
||||
* - Only species in the atomicSpecies.h database can be used. There are 1000s (All species from AME2020) in there so it should not be a problem.
|
||||
* - Before a mass fraction can be set with a particular instance of Composition, the symbol must be registered. (i.e. register He-3 before setting its mass fraction)
|
||||
* - Before any composition information can be retrived (e.g. getComposition), the composition must be finalized (call to .finalize()). This checks if the total mass fraction sums to approximatly 1 (within 1 part in 10^8)
|
||||
* - Any changes made to the composition after finalization will "unfinalize" the composition. This means that the composition must be finalized again before any information can be retrived.
|
||||
* - The mass fraction of any individual species must be no more than 1 and no less than 0.
|
||||
* - The only exception to the finalize rule is if the compositon was constructed with symbols and mass fractions at instantiation time. In this case, the composition is automatically finalized.
|
||||
* however, this means that the composition passed to the constructor must be valid.
|
||||
*
|
||||
* @example Constructing a finalized composition with symbols and mass fractions:
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "He"};
|
||||
* std::vector<double> mass_fractions = {0.7, 0.3};
|
||||
* Composition comp(symbols, mass_fractions);
|
||||
* @endcode
|
||||
* @example Constructing a composition with symbols and finalizing it later:
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "He"};
|
||||
* Composition comp(symbols);
|
||||
* comp.setComposition("H", 0.7);
|
||||
* comp.setComposition("He", 0.3);
|
||||
* comp.finalize();
|
||||
* @endcode
|
||||
*/
|
||||
class Composition {
|
||||
private:
|
||||
Config& m_config = Config::getInstance();
|
||||
Probe::LogManager& m_logManager = Probe::LogManager::getInstance();
|
||||
quill::Logger* m_logger = m_logManager.getLogger("log");
|
||||
|
||||
bool m_finalized = false; ///< True if the composition is finalized.
|
||||
double m_specificNumberDensity = 0.0; ///< The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species).
|
||||
double m_meanParticleMass = 0.0; ///< The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species).
|
||||
bool m_massFracMode = true; ///< True if mass fraction mode, false if number fraction mode.
|
||||
|
||||
std::set<std::string> m_registeredSymbols; ///< The registered symbols.
|
||||
std::unordered_map<std::string, CompositionEntry> m_compositions; ///< The compositions.
|
||||
|
||||
/**
|
||||
* @brief Checks if the given symbol is valid.
|
||||
* @details A symbol is valid if it is in the atomic species database (species in atomicSpecies.h). These include all the isotopes from AME2020.
|
||||
* @param symbol The symbol to check.
|
||||
* @return True if the symbol is valid, false otherwise.
|
||||
*/
|
||||
bool isValidSymbol(const std::string& symbol) const;
|
||||
|
||||
/**
|
||||
* @brief Checks if the given mass fractions are valid.
|
||||
* @param mass_fractions The mass fractions to check.
|
||||
* @return True if the mass fractions are valid, false otherwise.
|
||||
*/
|
||||
bool isValidComposition(const std::vector<double>& fractions) const;
|
||||
|
||||
/**
|
||||
* @brief Validates the given mass fractions.
|
||||
* @param mass_fractions The mass fractions to validate.
|
||||
* @throws std::invalid_argument if the mass fractions are invalid.
|
||||
*/
|
||||
void validateComposition(const std::vector<double>& fractions) const;
|
||||
|
||||
/**
|
||||
* @brief Finalizes the composition in mass fraction mode.
|
||||
* @param norm If true, the composition will be normalized to sum to 1.
|
||||
* @return True if the composition is successfully finalized, false otherwise.
|
||||
*/
|
||||
bool finalizeMassFracMode(bool norm);
|
||||
|
||||
/**
|
||||
* @brief Finalizes the composition in number fraction mode.
|
||||
* @param norm If true, the composition will be normalized to sum to 1.
|
||||
* @return True if the composition is successfully finalized, false otherwise.
|
||||
*/
|
||||
bool finalizeNumberFracMode(bool norm);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
*/
|
||||
Composition() = default;
|
||||
|
||||
/**
|
||||
* @brief Default destructor.
|
||||
*/
|
||||
~Composition() = default;
|
||||
|
||||
/**
|
||||
* @brief Finalizes the composition.
|
||||
* @param norm If true, the composition will be normalized to sum to 1 [Default False]
|
||||
* @return True if the composition is successfully finalized, false otherwise.
|
||||
*/
|
||||
bool finalize(bool norm=false);
|
||||
|
||||
/**
|
||||
* @brief Constructs a Composition with the given symbols.
|
||||
* @param symbols The symbols to initialize the composition with.
|
||||
* @example
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "O"};
|
||||
* Composition comp(symbols);
|
||||
* @endcode
|
||||
*/
|
||||
Composition(const std::vector<std::string>& symbols);
|
||||
|
||||
/**
|
||||
* @brief Constructs a Composition with the given symbols as a set.
|
||||
* @param symbols The symbols to initialize the composition with.
|
||||
* @example
|
||||
* @code
|
||||
* std::set<std::string> symbols = {"H", "O"};
|
||||
* Composition comp(symbols);
|
||||
* @endcode
|
||||
*/
|
||||
Composition(const std::set<std::string>& symbols);
|
||||
|
||||
/**
|
||||
* @brief Constructs a Composition with the given symbols and mass fractions.
|
||||
* @param symbols The symbols to initialize the composition with.
|
||||
* @param mass_fractions The mass fractions corresponding to the symbols.
|
||||
* @param massFracMode True if mass fraction mode, false if number fraction mode.
|
||||
* @example
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "O"};
|
||||
* std::vector<double> mass_fractions = {0.1, 0.9};
|
||||
* Composition comp(symbols, mass_fractions);
|
||||
* @endcode
|
||||
*/
|
||||
Composition(const std::vector<std::string>& symbols, const std::vector<double>& mass_fractions, bool massFracMode=true);
|
||||
|
||||
/**
|
||||
* @brief Registers a new symbol.
|
||||
* @param symbol The symbol to register.
|
||||
* @param massFracMode True if mass fraction mode, false if number fraction mode.
|
||||
* @example
|
||||
* @code
|
||||
* Composition comp;
|
||||
* comp.registerSymbol("H");
|
||||
* @endcode
|
||||
*/
|
||||
void registerSymbol(const std::string& symbol, bool massFracMode=true);
|
||||
|
||||
/**
|
||||
* @brief Registers multiple new symbols.
|
||||
* @param symbols The symbols to register.
|
||||
* @param massFracMode True if mass fraction mode, false if number fraction mode.
|
||||
* @example
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "O"};
|
||||
* Composition comp;
|
||||
* comp.registerSymbol(symbols);
|
||||
* @endcode
|
||||
*/
|
||||
void registerSymbol(const std::vector<std::string>& symbols, bool massFracMode=true);
|
||||
|
||||
/**
|
||||
* @brief Gets the registered symbols.
|
||||
* @return A set of registered symbols.
|
||||
*/
|
||||
std::set<std::string> getRegisteredSymbols() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the mass fraction for a given symbol.
|
||||
* @param symbol The symbol to set the mass fraction for.
|
||||
* @param mass_fraction The mass fraction to set.
|
||||
* @return The mass fraction that was set.
|
||||
* @example
|
||||
* @code
|
||||
* Composition comp;
|
||||
* comp.setMassFraction("H", 0.1);
|
||||
* @endcode
|
||||
*/
|
||||
double setMassFraction(const std::string& symbol, const double& mass_fraction);
|
||||
|
||||
/**
|
||||
* @brief Sets the mass fraction for multiple symbols.
|
||||
* @param symbols The symbols to set the mass fraction for.
|
||||
* @param mass_fractions The mass fractions corresponding to the symbols.
|
||||
* @return A vector of mass fractions that were set.
|
||||
* @example
|
||||
* @code
|
||||
* std::vector<std::string> symbols = {"H", "O"};
|
||||
* std::vector<double> mass_fractions = {0.1, 0.9};
|
||||
* Composition comp;
|
||||
* comp.setMassFraction(symbols, mass_fractions);
|
||||
* @endcode
|
||||
*/
|
||||
std::vector<double> setMassFraction(const std::vector<std::string>& symbols, const std::vector<double>& mass_fractions);
|
||||
|
||||
/**
|
||||
* @brief Sets the number fraction for a given symbol.
|
||||
* @param symbol The symbol to set the number fraction for.
|
||||
* @param number_fraction The number fraction to set.
|
||||
* @return The number fraction that was set.
|
||||
*/
|
||||
double setNumberFraction(const std::string& symbol, const double& number_fraction);
|
||||
|
||||
/**
|
||||
* @brief Sets the number fraction for multiple symbols.
|
||||
* @param symbols The symbols to set the number fraction for.
|
||||
* @param number_fractions The number fractions corresponding to the symbols.
|
||||
* @return A vector of number fractions that were set.
|
||||
*/
|
||||
std::vector<double> setNumberFraction(const std::vector<std::string>& symbols, const std::vector<double>& number_fractions);
|
||||
|
||||
/**
|
||||
* @brief Mix two compositions together with a given fraction.
|
||||
* @param other The other composition to mix with.
|
||||
* @param fraction The fraction of the other composition to mix with. This is the fraction of the other composition wrt. to the current. i.e. fraction=1 would mean that 50% of the new composition is from the other and 50% from the current).
|
||||
*/
|
||||
Composition mix(const Composition& other, double fraction) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the mass fractions of all compositions.
|
||||
* @return An unordered map of compositions with their mass fractions.
|
||||
*/
|
||||
std::unordered_map<std::string, double> getMassFraction() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the mass fraction for a given symbol.
|
||||
* @param symbol The symbol to get the mass fraction for.
|
||||
* @return The mass fraction for the given symbol.
|
||||
*/
|
||||
double getMassFraction(const std::string& symbol) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the number fraction for a given symbol.
|
||||
* @param symbol The symbol to get the number fraction for.
|
||||
* @return The number fraction for the given symbol.
|
||||
*/
|
||||
double getNumberFraction(const std::string& symbol) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the number fractions of all compositions.
|
||||
* @return An unordered map of compositions with their number fractions.
|
||||
*/
|
||||
std::unordered_map<std::string, double> getNumberFraction() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the composition entry and global composition for a given symbol.
|
||||
* @param symbol The symbol to get the composition for.
|
||||
* @return A pair containing the CompositionEntry and GlobalComposition for the given symbol.
|
||||
*/
|
||||
std::pair<CompositionEntry, GlobalComposition> getComposition(const std::string& symbol) const;
|
||||
|
||||
/**
|
||||
* @brief Gets all composition entries and the global composition.
|
||||
* @return A pair containing an unordered map of CompositionEntries and the GlobalComposition.
|
||||
*/
|
||||
std::pair<std::unordered_map<std::string, CompositionEntry>, GlobalComposition> getComposition() const;
|
||||
|
||||
/**
|
||||
* @brief Gets a subset of the composition.
|
||||
* @param symbols The symbols to include in the subset.
|
||||
* @param method The method to use for the subset (default is "norm").
|
||||
* @return A Composition object containing the subset.
|
||||
*/
|
||||
Composition subset(const std::vector<std::string>& symbols, std::string method="norm") const;
|
||||
|
||||
/**
|
||||
* @brief Check if a symbol is registered.
|
||||
* @param symbol The symbol to check.
|
||||
* @return True if the symbol is registered, false otherwise.
|
||||
*/
|
||||
bool hasSymbol(const std::string& symbol) const;
|
||||
|
||||
/**
|
||||
* @brief Sets the composition mode.
|
||||
* @param massFracMode True if mass fraction mode, false if number fraction mode.
|
||||
*/
|
||||
void setCompositionMode(bool massFracMode);
|
||||
|
||||
/**
|
||||
* @brief Overloaded output stream operator for Composition.
|
||||
* @param os The output stream.
|
||||
* @param composition The Composition to output.
|
||||
* @return The output stream.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const Composition& composition);
|
||||
|
||||
// Overload the + operator to call mix with a fraction of 0.5
|
||||
/**
|
||||
* @brief Overloads the + operator to mix two compositions together with a fraction of 0.5.
|
||||
* @param other The other composition to mix with.
|
||||
* @return The mixed composition.
|
||||
*/
|
||||
Composition operator+(const Composition& other) const;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif // COMPOSITION_H
|
||||
@@ -46,7 +46,7 @@ bool Config::loadConfig(const std::string& configFile) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
loaded = true;
|
||||
m_loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -61,3 +61,45 @@ void Config::addToCache(const std::string &key, const YAML::Node &node) {
|
||||
void Config::registerUnknownKey(const std::string &key) {
|
||||
unknownKeys.push_back(key);
|
||||
}
|
||||
|
||||
bool Config::has(const std::string &key) {
|
||||
if (!m_loaded) {
|
||||
throw std::runtime_error("Error! Config file not loaded");
|
||||
}
|
||||
if (isKeyInCache(key)) { return true; }
|
||||
|
||||
YAML::Node node = YAML::Clone(yamlRoot);
|
||||
std::istringstream keyStream(key);
|
||||
std::string subKey;
|
||||
while (std::getline(keyStream, subKey, ':')) {
|
||||
if (!node[subKey]) {
|
||||
registerUnknownKey(key);
|
||||
return false;
|
||||
}
|
||||
node = node[subKey]; // go deeper
|
||||
}
|
||||
|
||||
// Key exists and is of the requested type
|
||||
addToCache(key, node);
|
||||
return true;
|
||||
}
|
||||
|
||||
void recurse_keys(const YAML::Node& node, std::vector<std::string>& keyList, const std::string& path = "") {
|
||||
if (node.IsMap()) {
|
||||
for (const auto& it : node) {
|
||||
std::string key = it.first.as<std::string>();
|
||||
std::string new_path = path.empty() ? key : path + ":" + key;
|
||||
recurse_keys(it.second, keyList, new_path);
|
||||
}
|
||||
} else {
|
||||
keyList.push_back(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::string> Config::keys() const {
|
||||
std::vector<std::string> keyList;
|
||||
YAML::Node node = YAML::Clone(yamlRoot);
|
||||
recurse_keys(node, keyList);
|
||||
return keyList;
|
||||
}
|
||||
@@ -23,15 +23,19 @@
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <stdexcept>
|
||||
|
||||
// Required for YAML parsing
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
// -- Forward Def of Resource manager to let it act as a friend of Config --
|
||||
class ResourceManager;
|
||||
|
||||
/**
|
||||
* @class Config
|
||||
* @brief Singleton class to manage configuration settings loaded from a YAML file.
|
||||
@@ -96,6 +100,21 @@ private:
|
||||
*/
|
||||
void registerUnknownKey(const std::string &key);
|
||||
|
||||
bool m_loaded = false;
|
||||
|
||||
// Only friends can access get without a default value
|
||||
template <typename T>
|
||||
T get(const std::string &key) {
|
||||
if (!m_loaded) {
|
||||
throw std::runtime_error("Error! Config file not loaded");
|
||||
}
|
||||
if (has(key)) {
|
||||
return getFromCache<T>(key, T());
|
||||
} else {
|
||||
throw std::runtime_error("Error! Key not found in config file");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Get the singleton instance of the Config class.
|
||||
@@ -138,7 +157,7 @@ public:
|
||||
*/
|
||||
template <typename T>
|
||||
T get(const std::string &key, T defaultValue) {
|
||||
if (!loaded) {
|
||||
if (!m_loaded) {
|
||||
throw std::runtime_error("Configuration file not loaded! This should be done at the very start of whatever main function you are using (and only done once!)");
|
||||
}
|
||||
// --- Check if the key has already been checked for existence
|
||||
@@ -176,6 +195,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the key exists in the given config file
|
||||
* @param key Key to check;
|
||||
* @return boolean true or false
|
||||
*/
|
||||
bool has(const std::string &key);
|
||||
|
||||
/**
|
||||
* @brief Get all keys defined in the configuration file.
|
||||
* @return Vector of all keys in the configuration file.
|
||||
*/
|
||||
std::vector<std::string> keys() const;
|
||||
|
||||
/**
|
||||
* @brief Print the configuration file path and the YAML root node.
|
||||
* @param os Output stream.
|
||||
@@ -183,6 +215,10 @@ public:
|
||||
* @return Output stream.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const Config& config) {
|
||||
if (!config.m_loaded) {
|
||||
os << "Config file not loaded" << std::endl;
|
||||
return os;
|
||||
}
|
||||
if (!config.debug) {
|
||||
os << "Config file: " << config.configFilePath << std::endl;
|
||||
} else{
|
||||
@@ -195,6 +231,8 @@ public:
|
||||
|
||||
// Setup gTest class as a friend
|
||||
friend class configTestPrivateAccessor;
|
||||
// -- Resource Manager is a friend of config so it can create a seperate instance
|
||||
friend class ResourceManager;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,23 +1,34 @@
|
||||
# Define the library
|
||||
eos_sources = files(
|
||||
'private/helm.cpp',
|
||||
'private/eosIO.cpp'
|
||||
)
|
||||
|
||||
eos_headers = files(
|
||||
'public/helm.h'
|
||||
'public/helm.h',
|
||||
'public/eosIO.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
const_dep,
|
||||
quill_dep,
|
||||
probe_dep,
|
||||
config_dep,
|
||||
mfem_dep,
|
||||
macros_dep,
|
||||
]
|
||||
# Define the libconst library so it can be linked against by other parts of the build system
|
||||
libeos = static_library('eos',
|
||||
eos_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
dependencies: [const_dep, quill_dep, probe_dep, config_dep, mfem_dep],
|
||||
dependencies: dependencies,
|
||||
install : true)
|
||||
|
||||
eos_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libeos,
|
||||
dependencies: dependencies
|
||||
)
|
||||
# Make headers accessible
|
||||
install_headers(eos_headers, subdir : '4DSSE/eos')
|
||||
36
src/eos/private/eosIO.cpp
Normal file
36
src/eos/private/eosIO.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <string>
|
||||
|
||||
#include "eosIO.h"
|
||||
#include "helm.h"
|
||||
#include "debug.h"
|
||||
|
||||
EosIO::EosIO(const std::string filename) : m_filename(filename) {
|
||||
load();
|
||||
}
|
||||
|
||||
std::string EosIO::getFormat() const {
|
||||
return m_format;
|
||||
}
|
||||
|
||||
|
||||
EOSTable& EosIO::getTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
void EosIO::load() {
|
||||
// Load the EOS table from the file
|
||||
// For now, just set the format to HELM
|
||||
|
||||
m_format = "helm";
|
||||
if (m_format == "helm") {
|
||||
loadHelm();
|
||||
}
|
||||
}
|
||||
|
||||
void EosIO::loadHelm() {
|
||||
// Load the HELM table from the file
|
||||
auto helmTabptr = helmholtz::read_helm_table(m_filename);
|
||||
m_table = std::move(helmTabptr);
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
@@ -121,21 +122,22 @@ namespace helmholtz {
|
||||
}
|
||||
|
||||
// this function reads in the HELM table and stores in the above arrays
|
||||
HELMTable read_helm_table(const std::string filename) {
|
||||
std::unique_ptr<HELMTable> read_helm_table(const std::string filename) {
|
||||
Config& config = Config::getInstance();
|
||||
std::string logFile = config.get<std::string>("EOS:Helm:LogFile", "log");
|
||||
Probe::LogManager& logManager = Probe::LogManager::getInstance();
|
||||
quill::Logger* logger = logManager.getLogger(logFile);
|
||||
LOG_INFO(logger, "read_helm_table : Reading HELM table from file {}", filename);
|
||||
|
||||
HELMTable table;
|
||||
// Make a unique pointer to the HELMTable
|
||||
std::unique_ptr<HELMTable> table = std::make_unique<HELMTable>();
|
||||
string data;
|
||||
int i, j;
|
||||
|
||||
//set T and Rho (d) arrays
|
||||
for (j=0; j<table.jmax; j++) { table.t[j] = pow(10, tlo + tstp*j); }
|
||||
for (j=0; j<table->jmax; j++) { table->t[j] = pow(10, tlo + tstp*j); }
|
||||
|
||||
for (i=0; i<table.imax; i++) { table.d[i] = pow(10, dlo + dstp*i); }
|
||||
for (i=0; i<table->imax; i++) { table->d[i] = pow(10, dlo + dstp*i); }
|
||||
|
||||
ifstream helm_table(filename);
|
||||
if (!helm_table) {
|
||||
@@ -144,83 +146,83 @@ namespace helmholtz {
|
||||
throw std::runtime_error("Error (" + std::to_string(errorCode) + ") opening file " + filename);
|
||||
}
|
||||
//read the Helmholtz free energy and its derivatives
|
||||
for (j=0; j<table.jmax; j++) {
|
||||
for (i=0; i<table.imax; i++){
|
||||
for (j=0; j<table->jmax; j++) {
|
||||
for (i=0; i<table->imax; i++){
|
||||
getline(helm_table, data);
|
||||
stringstream id(data);
|
||||
id >> table.f[i][j];
|
||||
id >> table.fd[i][j];
|
||||
id >> table.ft[i][j];
|
||||
id >> table.fdd[i][j];
|
||||
id >> table.ftt[i][j];
|
||||
id >> table.fdt[i][j];
|
||||
id >> table.fddt[i][j];
|
||||
id >> table.fdtt[i][j];
|
||||
id >> table.fddtt[i][j];
|
||||
id >> table->f[i][j];
|
||||
id >> table->fd[i][j];
|
||||
id >> table->ft[i][j];
|
||||
id >> table->fdd[i][j];
|
||||
id >> table->ftt[i][j];
|
||||
id >> table->fdt[i][j];
|
||||
id >> table->fddt[i][j];
|
||||
id >> table->fdtt[i][j];
|
||||
id >> table->fddtt[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
//read the pressure derivative with density
|
||||
for (j=0; j<table.jmax; j++) {
|
||||
for (i=0; i<table.imax; i++){
|
||||
for (j=0; j<table->jmax; j++) {
|
||||
for (i=0; i<table->imax; i++){
|
||||
getline(helm_table, data);
|
||||
stringstream id(data);
|
||||
id >> table.dpdf[i][j];
|
||||
id >> table.dpdfd[i][j];
|
||||
id >> table.dpdft[i][j];
|
||||
id >> table.dpdfdt[i][j];
|
||||
id >> table->dpdf[i][j];
|
||||
id >> table->dpdfd[i][j];
|
||||
id >> table->dpdft[i][j];
|
||||
id >> table->dpdfdt[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
//read the electron chemical potential
|
||||
for (j=0; j<table.jmax; j++) {
|
||||
for (i=0; i<table.imax; i++){
|
||||
for (j=0; j<table->jmax; j++) {
|
||||
for (i=0; i<table->imax; i++){
|
||||
getline(helm_table, data);
|
||||
stringstream id(data);
|
||||
id >> table.ef[i][j];
|
||||
id >> table.efd[i][j];
|
||||
id >> table.eft[i][j];
|
||||
id >> table.efdt[i][j];
|
||||
id >> table->ef[i][j];
|
||||
id >> table->efd[i][j];
|
||||
id >> table->eft[i][j];
|
||||
id >> table->efdt[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
//read the number density
|
||||
for (j=0; j<table.jmax; j++) {
|
||||
for (i=0; i<table.imax; i++){
|
||||
for (j=0; j<table->jmax; j++) {
|
||||
for (i=0; i<table->imax; i++){
|
||||
getline(helm_table, data);
|
||||
stringstream id(data);
|
||||
id >> table.xf[i][j];
|
||||
id >> table.xfd[i][j];
|
||||
id >> table.xft[i][j];
|
||||
id >> table.xfdt[i][j];
|
||||
id >> table->xf[i][j];
|
||||
id >> table->xfd[i][j];
|
||||
id >> table->xft[i][j];
|
||||
id >> table->xfdt[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
helm_table.close(); //done reading
|
||||
|
||||
// construct the temperature and density deltas and their inverses
|
||||
for (j=0; j<table.jmax; j++) {
|
||||
double dth = table.t[j+1] - table.t[j];
|
||||
for (j=0; j<table->jmax; j++) {
|
||||
double dth = table->t[j+1] - table->t[j];
|
||||
double dt2 = dth * dth;
|
||||
double dti = 1.0/dth;
|
||||
double dt2i = 1.0/dt2;
|
||||
table.dt_sav[j] = dth;
|
||||
table.dt2_sav[j] = dt2;
|
||||
table.dti_sav[j] = dti;
|
||||
table.dt2i_sav[j] = dt2i;
|
||||
table->dt_sav[j] = dth;
|
||||
table->dt2_sav[j] = dt2;
|
||||
table->dti_sav[j] = dti;
|
||||
table->dt2i_sav[j] = dt2i;
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<table.imax; i++) {
|
||||
double dd = table.d[i+1] - table.d[i];
|
||||
for (i=0; i<table->imax; i++) {
|
||||
double dd = table->d[i+1] - table->d[i];
|
||||
double dd2 = dd * dd;
|
||||
double ddi = 1.0/dd;
|
||||
table.dd_sav[i] = dd;
|
||||
table.dd2_sav[i] = dd2;
|
||||
table.ddi_sav[i] = ddi;
|
||||
table->dd_sav[i] = dd;
|
||||
table->dd2_sav[i] = dd2;
|
||||
table->ddi_sav[i] = ddi;
|
||||
}
|
||||
|
||||
table.loaded = true;
|
||||
table->loaded = true;
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
70
src/eos/public/eosIO.h
Normal file
70
src/eos/public/eosIO.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef EOSIO_H
|
||||
#define EOSIO_H
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <memory>
|
||||
|
||||
// EOS table format includes
|
||||
#include "helm.h"
|
||||
|
||||
using EOSTable = std::variant<
|
||||
std::unique_ptr<helmholtz::HELMTable>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @class EosIO
|
||||
* @brief Handles the input/output operations for EOS tables.
|
||||
*
|
||||
* The EosIO class is responsible for loading and managing EOS tables from files.
|
||||
* It supports different formats, currently only HELM format.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* EosIO eosIO("path/to/file");
|
||||
* std::string format = eosIO.getFormat();
|
||||
* EOSTable& table = eosIO.getTable();
|
||||
* @endcode
|
||||
*/
|
||||
class EosIO {
|
||||
private:
|
||||
std::string m_filename; ///< The filename of the EOS table.
|
||||
bool m_loaded = false; ///< Flag indicating if the table is loaded.
|
||||
std::string m_format; ///< The format of the EOS table.
|
||||
EOSTable m_table; ///< The EOS table data.
|
||||
|
||||
/**
|
||||
* @brief Loads the EOS table from the file.
|
||||
*/
|
||||
void load();
|
||||
|
||||
/**
|
||||
* @brief Loads the HELM format EOS table.
|
||||
*/
|
||||
void loadHelm();
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs an EosIO object with the given filename.
|
||||
* @param filename The filename of the EOS table.
|
||||
*/
|
||||
EosIO(const std::string filename);
|
||||
|
||||
/**
|
||||
* @brief Default destructor.
|
||||
*/
|
||||
~EosIO() = default;
|
||||
|
||||
/**
|
||||
* @brief Gets the format of the EOS table.
|
||||
* @return The format of the EOS table as a string.
|
||||
*/
|
||||
std::string getFormat() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the EOS table.
|
||||
* @return A reference to the EOS table.
|
||||
*/
|
||||
EOSTable& getTable();
|
||||
};
|
||||
|
||||
#endif // EOSIO_H
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <string>
|
||||
#include <format>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/**
|
||||
* @brief 2D array template alias.
|
||||
* @tparam T Type of the array elements.
|
||||
@@ -139,6 +141,118 @@ namespace helmholtz
|
||||
heap_deallocate_contiguous_2D_memory(xfdt);
|
||||
}
|
||||
|
||||
// // Delete copy constructor and copy assignment operator to prevent accidental shallow copies
|
||||
// HELMTable(const HELMTable&) = delete;
|
||||
// HELMTable& operator=(const HELMTable&) = delete;
|
||||
|
||||
// // Move constructor
|
||||
// HELMTable(HELMTable&& other) noexcept
|
||||
// : loaded(other.loaded),
|
||||
// f(other.f), fd(other.fd), ft(other.ft), fdd(other.fdd), ftt(other.ftt), fdt(other.fdt),
|
||||
// fddt(other.fddt), fdtt(other.fdtt), fddtt(other.fddtt),
|
||||
// dpdf(other.dpdf), dpdfd(other.dpdfd), dpdft(other.dpdft), dpdfdt(other.dpdfdt),
|
||||
// ef(other.ef), efd(other.efd), eft(other.eft), efdt(other.efdt),
|
||||
// xf(other.xf), xfd(other.xfd), xft(other.xft), xfdt(other.xfdt)
|
||||
// {
|
||||
// other.f = nullptr;
|
||||
// other.fd = nullptr;
|
||||
// other.ft = nullptr;
|
||||
// other.fdd = nullptr;
|
||||
// other.ftt = nullptr;
|
||||
// other.fdt = nullptr;
|
||||
// other.fddt = nullptr;
|
||||
// other.fdtt = nullptr;
|
||||
// other.fddtt = nullptr;
|
||||
// other.dpdf = nullptr;
|
||||
// other.dpdfd = nullptr;
|
||||
// other.dpdft = nullptr;
|
||||
// other.dpdfdt = nullptr;
|
||||
// other.ef = nullptr;
|
||||
// other.efd = nullptr;
|
||||
// other.eft = nullptr;
|
||||
// other.efdt = nullptr;
|
||||
// other.xf = nullptr;
|
||||
// other.xfd = nullptr;
|
||||
// other.xft = nullptr;
|
||||
// other.xfdt = nullptr;
|
||||
// }
|
||||
|
||||
// // Move assignment operator
|
||||
// HELMTable& operator=(HELMTable&& other) noexcept {
|
||||
// if (this != &other) {
|
||||
// // Deallocate current memory
|
||||
// heap_deallocate_contiguous_2D_memory(f);
|
||||
// heap_deallocate_contiguous_2D_memory(fd);
|
||||
// heap_deallocate_contiguous_2D_memory(ft);
|
||||
// heap_deallocate_contiguous_2D_memory(fdd);
|
||||
// heap_deallocate_contiguous_2D_memory(ftt);
|
||||
// heap_deallocate_contiguous_2D_memory(fdt);
|
||||
// heap_deallocate_contiguous_2D_memory(fddt);
|
||||
// heap_deallocate_contiguous_2D_memory(fdtt);
|
||||
// heap_deallocate_contiguous_2D_memory(fddtt);
|
||||
// heap_deallocate_contiguous_2D_memory(dpdf);
|
||||
// heap_deallocate_contiguous_2D_memory(dpdfd);
|
||||
// heap_deallocate_contiguous_2D_memory(dpdft);
|
||||
// heap_deallocate_contiguous_2D_memory(dpdfdt);
|
||||
// heap_deallocate_contiguous_2D_memory(ef);
|
||||
// heap_deallocate_contiguous_2D_memory(efd);
|
||||
// heap_deallocate_contiguous_2D_memory(eft);
|
||||
// heap_deallocate_contiguous_2D_memory(efdt);
|
||||
// heap_deallocate_contiguous_2D_memory(xf);
|
||||
// heap_deallocate_contiguous_2D_memory(xfd);
|
||||
// heap_deallocate_contiguous_2D_memory(xft);
|
||||
// heap_deallocate_contiguous_2D_memory(xfdt);
|
||||
|
||||
// // Transfer ownership of resources
|
||||
// loaded = other.loaded;
|
||||
// f = other.f;
|
||||
// fd = other.fd;
|
||||
// ft = other.ft;
|
||||
// fdd = other.fdd;
|
||||
// ftt = other.ftt;
|
||||
// fdt = other.fdt;
|
||||
// fddt = other.fddt;
|
||||
// fdtt = other.fdtt;
|
||||
// fddtt = other.fddtt;
|
||||
// dpdf = other.dpdf;
|
||||
// dpdfd = other.dpdfd;
|
||||
// dpdft = other.dpdft;
|
||||
// dpdfdt = other.dpdfdt;
|
||||
// ef = other.ef;
|
||||
// efd = other.efd;
|
||||
// eft = other.eft;
|
||||
// efdt = other.efdt;
|
||||
// xf = other.xf;
|
||||
// xfd = other.xfd;
|
||||
// xft = other.xft;
|
||||
// xfdt = other.xfdt;
|
||||
|
||||
// // Null out the other object's pointers
|
||||
// other.f = nullptr;
|
||||
// other.fd = nullptr;
|
||||
// other.ft = nullptr;
|
||||
// other.fdd = nullptr;
|
||||
// other.ftt = nullptr;
|
||||
// other.fdt = nullptr;
|
||||
// other.fddt = nullptr;
|
||||
// other.fdtt = nullptr;
|
||||
// other.fddtt = nullptr;
|
||||
// other.dpdf = nullptr;
|
||||
// other.dpdfd = nullptr;
|
||||
// other.dpdft = nullptr;
|
||||
// other.dpdfdt = nullptr;
|
||||
// other.ef = nullptr;
|
||||
// other.efd = nullptr;
|
||||
// other.eft = nullptr;
|
||||
// other.efdt = nullptr;
|
||||
// other.xf = nullptr;
|
||||
// other.xfd = nullptr;
|
||||
// other.xft = nullptr;
|
||||
// other.xfdt = nullptr;
|
||||
// }
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const helmholtz::HELMTable& table) {
|
||||
if (!table.loaded) {
|
||||
os << "HELMTable not loaded\n";
|
||||
@@ -371,7 +485,7 @@ namespace helmholtz
|
||||
* @param filename Path to the file containing the table.
|
||||
* @return HELMTable structure containing the table data.
|
||||
*/
|
||||
HELMTable read_helm_table(const std::string filename);
|
||||
std::unique_ptr<HELMTable> read_helm_table(const std::string filename);
|
||||
|
||||
/**
|
||||
* @brief Calculate the Helmholtz EOS components.
|
||||
|
||||
@@ -6,18 +6,22 @@ meshIO_sources = files(
|
||||
meshIO_headers = files(
|
||||
'public/meshIO.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
mfem_dep
|
||||
]
|
||||
# Define the libmeshIO library so it can be linked against by other parts of the build system
|
||||
libmeshIO = static_library('meshIO',
|
||||
meshIO_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
dependencies: [mfem_dep],
|
||||
dependencies: dependencies,
|
||||
install : true)
|
||||
|
||||
meshio_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libmeshIO,
|
||||
sources: meshIO_sources,
|
||||
dependencies: [mfem_dep]
|
||||
)
|
||||
dependencies: dependencies
|
||||
)
|
||||
|
||||
# Make headers accessible
|
||||
install_headers(meshIO_headers, subdir : '4DSSE/meshIO')
|
||||
@@ -1,12 +1,24 @@
|
||||
# Build resources first so that all the embedded resources are available to the other targets
|
||||
subdir('resources')
|
||||
# Build the main source code in the correct order
|
||||
# Unless you know what you are doing, do not change the order of the subdirectories
|
||||
# as there are dependencies which exist between them.
|
||||
|
||||
# Build the main source code
|
||||
# Utility Libraries
|
||||
subdir('misc')
|
||||
subdir('config')
|
||||
subdir('dobj')
|
||||
subdir('const')
|
||||
subdir('opatIO')
|
||||
subdir('meshIO')
|
||||
subdir('probe')
|
||||
subdir('dobj')
|
||||
|
||||
# Physically Informed Libraries
|
||||
subdir('const')
|
||||
subdir('composition')
|
||||
|
||||
# Asset Libraries
|
||||
subdir('eos')
|
||||
subdir('meshIO')
|
||||
|
||||
# Resouce Manager Libraries
|
||||
subdir('resource')
|
||||
|
||||
# Physics Libraries
|
||||
subdir('network')
|
||||
subdir('poly')
|
||||
|
||||
36
src/misc/macros/debug.h
Normal file
36
src/misc/macros/debug.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file debug.h
|
||||
* @brief Defines a macro for triggering a breakpoint in different compilers and platforms.
|
||||
*
|
||||
* This file provides a macro `BREAKPOINT()` that triggers a breakpoint
|
||||
* in the debugger, depending on the compiler and platform being used.
|
||||
*
|
||||
* Usage:
|
||||
* @code
|
||||
* BREAKPOINT(); // Triggers a breakpoint in the debugger
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__ // GCC and Clang
|
||||
/**
|
||||
* @brief Triggers a breakpoint in GCC and Clang.
|
||||
*/
|
||||
#define BREAKPOINT() __builtin_debugtrap()
|
||||
#elif defined(_MSC_VER) // MSVC
|
||||
/**
|
||||
* @brief Triggers a breakpoint in MSVC.
|
||||
*/
|
||||
#define BREAKPOINT() __debugbreak()
|
||||
#elif defined(__APPLE__) && defined(__MACH__) // macOS with Clang and LLDB
|
||||
#include <signal.h>
|
||||
/**
|
||||
* @brief Triggers a breakpoint in macOS with Clang and LLDB.
|
||||
*/
|
||||
#define BREAKPOINT() raise(SIGTRAP)
|
||||
#else
|
||||
#include <csignal>
|
||||
/**
|
||||
* @brief Triggers a breakpoint in other platforms.
|
||||
*/
|
||||
#define BREAKPOINT() std::raise(SIGTRAP)
|
||||
#endif
|
||||
21
src/misc/macros/meson.build
Normal file
21
src/misc/macros/meson.build
Normal file
@@ -0,0 +1,21 @@
|
||||
# ***********************************************************************
|
||||
#
|
||||
# Copyright (C) 2025 -- The 4D-STAR Collaboration
|
||||
# File Author: Emily Boudreaux
|
||||
# Last Modified: March 19, 2025
|
||||
#
|
||||
# 4DSSE is free software; you can use it and/or modify
|
||||
# it under the terms and restrictions the GNU General Library Public
|
||||
# License version 3 (GPLv3) as published by the Free Software Foundation.
|
||||
#
|
||||
# 4DSSE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public License
|
||||
# along with this software; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# *********************************************************************** #
|
||||
macros_dep = declare_dependency(include_directories: include_directories('.'))
|
||||
16
src/misc/macros/warning_control.h
Normal file
16
src/misc/macros/warning_control.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef WARNING_CONTROL_H
|
||||
#define WARNING_CONTROL_H
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define DEPRECATION_WARNING_OFF _Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
||||
#define DEPRECATION_WARNING_ON _Pragma("GCC diagnostic pop")
|
||||
#elif defined(_MSC_VER)
|
||||
#define DEPRECATION_WARNING_OFF __pragma(warning(push)) __pragma(warning(disable: 4996))
|
||||
#define DEPRECATION_WARNING_ON __pragma(warning(pop))
|
||||
#else
|
||||
#define DEPRECATION_WARNING_OFF
|
||||
#define DEPRECATION_WARNING_ON
|
||||
#endif
|
||||
|
||||
#endif // WARNING_CONTROL_H
|
||||
2
src/misc/meson.build
Normal file
2
src/misc/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
# IMPORTANT: DO NOT MAKE MISC DEPEND ON ANY OTHER MODULE AS IT IS THE FIRST MODULE TO BE BUILT
|
||||
subdir('macros')
|
||||
36
src/network/meson.build
Normal file
36
src/network/meson.build
Normal file
@@ -0,0 +1,36 @@
|
||||
# Define the library
|
||||
network_sources = files(
|
||||
'private/network.cpp',
|
||||
'private/approx8.cpp'
|
||||
)
|
||||
|
||||
network_headers = files(
|
||||
'public/network.h',
|
||||
'public/approx8.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
boost_dep,
|
||||
const_dep,
|
||||
quill_dep,
|
||||
mfem_dep,
|
||||
config_dep,
|
||||
probe_dep
|
||||
]
|
||||
|
||||
# Define the libnetwork library so it can be linked against by other parts of the build system
|
||||
libnetwork = static_library('network',
|
||||
network_sources,
|
||||
include_directories: include_directories('public'),
|
||||
dependencies: dependencies,
|
||||
install : true)
|
||||
|
||||
network_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libnetwork,
|
||||
sources: network_sources,
|
||||
dependencies: dependencies,
|
||||
)
|
||||
|
||||
# Make headers accessible
|
||||
install_headers(network_headers, subdir : '4DSSE/network')
|
||||
523
src/network/private/approx8.cpp
Normal file
523
src/network/private/approx8.cpp
Normal file
@@ -0,0 +1,523 @@
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <array>
|
||||
|
||||
#include <boost/numeric/odeint.hpp>
|
||||
|
||||
#include "const.h"
|
||||
#include "config.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
#include "approx8.h"
|
||||
#include "network.h"
|
||||
|
||||
/* Nuclear reaction network in cgs units based on Frank Timmes' "aprox8".
|
||||
At this time it does neither screening nor neutrino losses. It includes
|
||||
the following 8 isotopes:
|
||||
|
||||
h1
|
||||
he3
|
||||
he4
|
||||
c12
|
||||
n14
|
||||
o16
|
||||
ne20
|
||||
mg24
|
||||
|
||||
and the following nuclear reactions:
|
||||
|
||||
---pp chain---
|
||||
p(p,e+)d
|
||||
d(p,g)he3
|
||||
he3(he3,2p)he4
|
||||
|
||||
---CNO cycle---
|
||||
c12(p,g)n13 - n13 -> c13 + p -> n14
|
||||
n14(p,g)o15 - o15 + p -> c12 + he4
|
||||
n14(a,g)f18 - proceeds to ne20
|
||||
n15(p,a)c12 - / these two n15 reactions are \ CNO I
|
||||
n15(p,g)o16 - \ used to calculate a fraction / CNO II
|
||||
o16(p,g)f17 - f17 + e -> o17 and then o17 + p -> n14 + he4
|
||||
|
||||
---alpha captures---
|
||||
c12(a,g)o16
|
||||
triple alpha
|
||||
o16(a,g)ne20
|
||||
ne20(a,g)mg24
|
||||
c12(c12,a)ne20
|
||||
c12(o16,a)mg24
|
||||
|
||||
At present the rates are all evaluated using a fitting function.
|
||||
The coefficients to the fit are from reaclib.jinaweb.org .
|
||||
|
||||
*/
|
||||
|
||||
namespace nnApprox8{
|
||||
|
||||
// using namespace std;
|
||||
using namespace boost::numeric::odeint;
|
||||
|
||||
//helper functions
|
||||
// a function to multilpy two arrays and then sum the resulting elements: sum(a*b)
|
||||
double sum_product( const vec7 &a, const vec7 &b){
|
||||
if (a.size() != b.size()) {
|
||||
throw std::runtime_error("Error: array size mismatch in sum_product");
|
||||
}
|
||||
|
||||
double sum=0;
|
||||
for (size_t i=0; i < a.size(); i++) {
|
||||
sum += a[i] * b[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// the fit to the nuclear reaction rates is of the form:
|
||||
// exp( a0 + a1/T9 + a2/T9^(1/3) + a3*T9^(1/3) + a4*T9 + a5*T9^(5/3) + log(T9) )
|
||||
// this function returns an array of the T9 terms in that order, where T9 is the temperatures in GigaKelvin
|
||||
vec7 get_T9_array(const double &T) {
|
||||
vec7 arr;
|
||||
double T9=1e-9*T;
|
||||
double T913=pow(T9,1./3.);
|
||||
|
||||
arr[0]=1;
|
||||
arr[1]=1/T9;
|
||||
arr[2]=1/T913;
|
||||
arr[3]=T913;
|
||||
arr[4]=T9;
|
||||
arr[5]=pow(T9,5./3.);
|
||||
arr[6]=log(T9);
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
// this function uses the two preceding functions to evaluate the rate given the T9 array and the coefficients
|
||||
double rate_fit(const vec7 &T9, const vec7 &coef){
|
||||
return exp(sum_product(T9,coef));
|
||||
}
|
||||
|
||||
// p + p -> d; this, like some of the other rates, this is a composite of multiple fits
|
||||
double pp_rate(const vec7 &T9) {
|
||||
vec7 a1 = {-34.78630, 0,-3.511930, 3.100860, -0.1983140, 1.262510e-2, -1.025170};
|
||||
vec7 a2 = { -4.364990e+1,-2.460640e-3,-2.750700,-4.248770e-1,1.598700e-2,-6.908750e-4,-2.076250e-1};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2);
|
||||
}
|
||||
|
||||
// p + d -> he3
|
||||
double dp_rate(const vec7 &T9) {
|
||||
vec7 a1 = {7.528980, 0, -3.720800, 0.8717820, 0, 0,-0.6666670};
|
||||
vec7 a2 = {8.935250, 0, -3.720800, 0.1986540, 0, 0, 0.3333330};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2);
|
||||
}
|
||||
|
||||
// he3 + he3 -> he4 + 2p
|
||||
double he3he3_rate(const vec7 &T9){
|
||||
vec7 a = {2.477880e+01,0,-12.27700,-0.1036990,-6.499670e-02,1.681910e-02,-6.666670e-01};
|
||||
return rate_fit(T9,a);
|
||||
}
|
||||
|
||||
// he3(he3,2p)he4
|
||||
double he3he4_rate(const vec7 &T9){
|
||||
vec7 a1 = {1.560990e+01,0.000000e+00,-1.282710e+01,-3.082250e-02,-6.546850e-01,8.963310e-02,-6.666670e-01};
|
||||
vec7 a2 = {1.770750e+01,0.000000e+00,-1.282710e+01,-3.812600e+00,9.422850e-02,-3.010180e-03,1.333330e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2);
|
||||
}
|
||||
|
||||
// he4 + he4 + he4 -> c12
|
||||
double triple_alpha_rate(const vec7 &T9){
|
||||
vec7 a1 = {-9.710520e-01,0.000000e+00,-3.706000e+01,2.934930e+01,-1.155070e+02,-1.000000e+01,-1.333330e+00};
|
||||
vec7 a2 = {-1.178840e+01,-1.024460e+00,-2.357000e+01,2.048860e+01,-1.298820e+01,-2.000000e+01,-2.166670e+00};
|
||||
vec7 a3 = {-2.435050e+01,-4.126560e+00,-1.349000e+01,2.142590e+01,-1.347690e+00,8.798160e-02,-1.316530e+01};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3);
|
||||
}
|
||||
|
||||
// c12 + p -> n13
|
||||
double c12p_rate(const vec7 &T9){
|
||||
vec7 a1={1.714820e+01,0.000000e+00,-1.369200e+01,-2.308810e-01,4.443620e+00,-3.158980e+00,-6.666670e-01};
|
||||
vec7 a2={1.754280e+01,-3.778490e+00,-5.107350e+00,-2.241110e+00,1.488830e-01,0.000000e+00,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2);
|
||||
}
|
||||
|
||||
// c12 + he4 -> o16
|
||||
double c12a_rate(const vec7 &T9){
|
||||
vec7 a1={6.965260e+01,-1.392540e+00,5.891280e+01,-1.482730e+02,9.083240e+00,-5.410410e-01,7.035540e+01};
|
||||
vec7 a2={2.546340e+02,-1.840970e+00,1.034110e+02,-4.205670e+02,6.408740e+01,-1.246240e+01,1.373030e+02};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2);
|
||||
}
|
||||
|
||||
// n14(p,g)o15 - o15 + p -> c12 + he4
|
||||
double n14p_rate(const vec7 &T9){
|
||||
vec7 a1={1.701000e+01,0.000000e+00,-1.519300e+01,-1.619540e-01,-7.521230e+00,-9.875650e-01,-6.666670e-01};
|
||||
vec7 a2={2.011690e+01,0.000000e+00,-1.519300e+01,-4.639750e+00,9.734580e+00,-9.550510e+00,3.333330e-01};
|
||||
vec7 a3={7.654440e+00,-2.998000e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a4={6.735780e+00,-4.891000e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,6.820000e-02};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3) + rate_fit(T9,a4);
|
||||
}
|
||||
|
||||
// n14(a,g)f18 assumed to go on to ne20
|
||||
double n14a_rate(const vec7 &T9){
|
||||
vec7 a1={2.153390e+01,0.000000e+00,-3.625040e+01,0.000000e+00,0.000000e+00,-5.000000e+00,-6.666670e-01};
|
||||
vec7 a2={1.968380e-01,-5.160340e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a3={1.389950e+01,-1.096560e+01,-5.622700e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3);
|
||||
}
|
||||
|
||||
// n15(p,a)c12 (CNO I)
|
||||
double n15pa_rate(const vec7 &T9){
|
||||
vec7 a1 = {2.747640e+01,0.000000e+00,-1.525300e+01,1.593180e+00,2.447900e+00,-2.197080e+00,-6.666670e-01};
|
||||
vec7 a2 = {-4.873470e+00,-2.021170e+00,0.000000e+00,3.084970e+01,-8.504330e+00,-1.544260e+00,-1.500000e+00};
|
||||
vec7 a3 = {2.089720e+01,-7.406000e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a4 = {-6.575220e+00,-1.163800e+00,0.000000e+00,2.271050e+01,-2.907070e+00,2.057540e-01,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3) + rate_fit(T9,a4);
|
||||
}
|
||||
|
||||
// n15(p,g)o16 (CNO II)
|
||||
double n15pg_rate(const vec7 &T9){
|
||||
vec7 a1 = {2.001760e+01,0.000000e+00,-1.524000e+01,3.349260e-01,4.590880e+00,-4.784680e+00,-6.666670e-01};
|
||||
vec7 a2 = {6.590560e+00,-2.923150e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a3 = {1.454440e+01,-1.022950e+01,0.000000e+00,0.000000e+00,4.590370e-02,0.000000e+00,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3);
|
||||
}
|
||||
|
||||
double n15pg_frac(const vec7 &T9){
|
||||
double f1=n15pg_rate(T9);
|
||||
double f2=n15pa_rate(T9);
|
||||
return f1/(f1+f2);
|
||||
}
|
||||
|
||||
// o16(p,g)f17 then f17 -> o17(p,a)n14
|
||||
double o16p_rate(const vec7 &T9){
|
||||
vec7 a={1.909040e+01,0.000000e+00,-1.669600e+01,-1.162520e+00,2.677030e-01,-3.384110e-02,-6.666670e-01};
|
||||
return rate_fit(T9,a);
|
||||
}
|
||||
|
||||
// o16(a,g)ne20
|
||||
double o16a_rate(const vec7 &T9){
|
||||
vec7 a1={2.390300e+01,0.000000e+00,-3.972620e+01,-2.107990e-01,4.428790e-01,-7.977530e-02,-6.666670e-01};
|
||||
vec7 a2={3.885710e+00,-1.035850e+01,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a3={9.508480e+00,-1.276430e+01,0.000000e+00,-3.659250e+00,7.142240e-01,-1.075080e-03,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3);
|
||||
}
|
||||
|
||||
// ne20(a,g)mg24
|
||||
double ne20a_rate(const vec7 &T9){
|
||||
vec7 a1={2.450580e+01,0.000000e+00,-4.625250e+01,5.589010e+00,7.618430e+00,-3.683000e+00,-6.666670e-01};
|
||||
vec7 a2={-3.870550e+01,-2.506050e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a3={1.983070e+00,-9.220260e+00,0.000000e+00,0.000000e+00,0.000000e+00,0.000000e+00,-1.500000e+00};
|
||||
vec7 a4={-8.798270e+00,-1.278090e+01,0.000000e+00,1.692290e+01,-2.573250e+00,2.089970e-01,-1.500000e+00};
|
||||
return rate_fit(T9,a1) + rate_fit(T9,a2) + rate_fit(T9,a3) + rate_fit(T9,a4);
|
||||
}
|
||||
|
||||
// c12(c12,a)ne20
|
||||
double c12c12_rate(const vec7 &T9){
|
||||
vec7 a={6.128630e+01,0.000000e+00,-8.416500e+01,-1.566270e+00,-7.360840e-02,-7.279700e-02,-6.666670e-01};
|
||||
return rate_fit(T9,a);
|
||||
}
|
||||
|
||||
// c12(o16,a)mg24
|
||||
double c12o16_rate(const vec7 &T9){
|
||||
vec7 a={4.853410e+01,3.720400e-01,-1.334130e+02,5.015720e+01,-3.159870e+00,1.782510e-02,-2.370270e+01};
|
||||
return rate_fit(T9,a);
|
||||
}
|
||||
|
||||
|
||||
// for Boost ODE solvers either a struct or a class is required
|
||||
|
||||
// a Jacobian matrix for implicit solvers
|
||||
|
||||
void Jacobian::operator() ( const vector_type &y, matrix_type &J, double /* t */, vector_type &dfdt ) {
|
||||
Constants& constants = Constants::getInstance();
|
||||
const double avo = constants.get("N_a").value;
|
||||
const double clight = constants.get("c").value;
|
||||
// EOS
|
||||
vec7 T9=get_T9_array(y[Net::itemp]);
|
||||
|
||||
// evaluate rates once per call
|
||||
double rpp=pp_rate(T9);
|
||||
double r33=he3he3_rate(T9);
|
||||
double r34=he3he4_rate(T9);
|
||||
double r3a=triple_alpha_rate(T9);
|
||||
double rc12p=c12p_rate(T9);
|
||||
double rc12a=c12a_rate(T9);
|
||||
double rn14p=n14p_rate(T9);
|
||||
double rn14a=n14a_rate(T9);
|
||||
double ro16p=o16p_rate(T9);
|
||||
double ro16a=o16a_rate(T9);
|
||||
double rne20a=ne20a_rate(T9);
|
||||
double r1212=c12c12_rate(T9);
|
||||
double r1216=c12o16_rate(T9);
|
||||
|
||||
double pfrac=n15pg_frac(T9);
|
||||
double afrac=1-pfrac;
|
||||
|
||||
double yh1 = y[Net::ih1];
|
||||
double yhe3 = y[Net::ihe3];
|
||||
double yhe4 = y[Net::ihe4];
|
||||
double yc12 = y[Net::ic12];
|
||||
double yn14 = y[Net::in14];
|
||||
double yo16 = y[Net::io16];
|
||||
double yne20 = y[Net::ine20];
|
||||
|
||||
// zero all elements to begin
|
||||
for (int i=0; i < Net::nvar; i++) {
|
||||
for (int j=0; j < Net::nvar; j++) {
|
||||
J(i,j)=0.0;
|
||||
}
|
||||
}
|
||||
|
||||
// h1 jacobian elements
|
||||
J(Net::ih1,Net::ih1) = -3*yh1*rpp - 2*yc12*rc12p -2*yn14*rn14p -2*yo16*ro16p;
|
||||
J(Net::ih1,Net::ihe3) = 2*yhe3*r33 - yhe4*r34;
|
||||
J(Net::ih1,Net::ihe4) = -yhe3*r34;
|
||||
J(Net::ih1,Net::ic12) = -2*yh1*rc12p;
|
||||
J(Net::ih1,Net::in14) = -2*yh1*rn14p;
|
||||
J(Net::ih1,Net::io16) = -2*yh1*ro16p;
|
||||
|
||||
// he3 jacobian elements
|
||||
J(Net::ihe3,Net::ih1) = yh1*rpp;
|
||||
J(Net::ihe3,Net::ihe3) = -2*yhe3*r33 - yhe4*r34;
|
||||
J(Net::ihe3,Net::ihe4) = -yhe3*r34;
|
||||
|
||||
// he4 jacobian elements
|
||||
J(Net::ihe4,Net::ih1) = yn14*afrac*rn14p + yo16*ro16p;
|
||||
J(Net::ihe4,Net::ihe3) = yhe3*r33 - yhe4*r34;
|
||||
J(Net::ihe4,Net::ihe4) = yhe3*r34 - 1.5*yhe4*yhe4*r3a - yc12*rc12a - 1.5*yn14*rn14a - yo16*ro16a - yne20*rne20a;
|
||||
J(Net::ihe4,Net::ic12) = -yhe4*rc12a + yc12*r1212 + yo16*r1216;
|
||||
J(Net::ihe4,Net::in14) = yh1*afrac*rn14p - 1.5*yhe4*rn14a;
|
||||
J(Net::ihe4,Net::io16) = yh1*ro16p - yhe4*ro16a + yc12*r1216;
|
||||
J(Net::ihe4,Net::ine20) = -yhe4*rne20a;
|
||||
|
||||
// c12 jacobian elements
|
||||
J(Net::ic12,Net::ih1) = -yc12*rc12p + yn14*afrac*rn14p;
|
||||
J(Net::ic12,Net::ihe4) = 0.5*yhe4*yhe4*r3a - yhe4*rc12a;
|
||||
J(Net::ic12,Net::ic12) = -yh1*rc12p - yhe4*rc12a - yo16*r1216 - 2*yc12*r1212;
|
||||
J(Net::ic12,Net::in14) = yh1*yn14*afrac*rn14p;
|
||||
J(Net::ic12,Net::io16) = -yc12*r1216;
|
||||
|
||||
// n14 jacobian elements
|
||||
J(Net::in14,Net::ih1) = yc12*rc12p - yn14*rn14p + yo16*ro16p;
|
||||
J(Net::in14,Net::ihe4) = -yn14*rn14a;
|
||||
J(Net::in14,Net::ic12) = yh1*rc12p;
|
||||
J(Net::in14,Net::in14) = -yh1*rn14p - yhe4*rn14a;
|
||||
J(Net::in14,Net::io16) = yo16*ro16p;
|
||||
|
||||
// o16 jacobian elements
|
||||
J(Net::io16,Net::ih1) = yn14*pfrac*rn14p - yo16*ro16p;
|
||||
J(Net::io16,Net::ihe4) = yc12*rc12a - yo16*ro16a;
|
||||
J(Net::io16,Net::ic12) = yhe4*rc12a - yo16*r1216;
|
||||
J(Net::io16,Net::in14) = yh1*pfrac*rn14p;
|
||||
J(Net::io16,Net::io16) = yh1*ro16p - yc12*r1216 -yhe4*ro16a;
|
||||
|
||||
// ne20 jacobian elements
|
||||
J(Net::ine20,Net::ihe4) = yn14*rn14a + yo16*ro16a - yne20*rne20a;
|
||||
J(Net::ine20,Net::ic12) = yc12*r1212;
|
||||
J(Net::ine20,Net::in14) = yhe4*rn14a;
|
||||
J(Net::ine20,Net::io16) = yo16*ro16a;
|
||||
J(Net::ine20,Net::ine20) = -yhe4*rne20a;
|
||||
|
||||
// mg24 jacobian elements
|
||||
J(Net::img24,Net::ihe4) = yne20*rne20a;
|
||||
J(Net::img24,Net::ic12) = yo16*r1216;
|
||||
J(Net::img24,Net::io16) = yc12*r1216;
|
||||
J(Net::img24,Net::ine20) = yhe4*rne20a;
|
||||
|
||||
// energy accountings
|
||||
for (int j=0; j<Net::niso; j++) {
|
||||
for (int i=0; i<Net::niso; i++) {
|
||||
J(Net::iener,j) += J(i,j)*Net::mion[i];
|
||||
}
|
||||
J(Net::iener,j) *= -avo*clight*clight;
|
||||
}
|
||||
}
|
||||
|
||||
void ODE::operator() ( const vector_type &y, vector_type &dydt, double /* t */) {
|
||||
Constants& constants = Constants::getInstance();
|
||||
const double avo = constants.get("N_a").value;
|
||||
const double clight = constants.get("c").value;
|
||||
|
||||
// EOS
|
||||
double T=y[Net::itemp];
|
||||
double den=y[Net::iden];
|
||||
vec7 T9=get_T9_array(T);
|
||||
|
||||
// rates
|
||||
double rpp=den*pp_rate(T9);
|
||||
double r33=den*he3he3_rate(T9);
|
||||
double r34=den*he3he4_rate(T9);
|
||||
double r3a=den*den*triple_alpha_rate(T9);
|
||||
double rc12p=den*c12p_rate(T9);
|
||||
double rc12a=den*c12a_rate(T9);
|
||||
double rn14p=den*n14p_rate(T9);
|
||||
double rn14a=n14a_rate(T9);
|
||||
double ro16p=den*o16p_rate(T9);
|
||||
double ro16a=den*o16a_rate(T9);
|
||||
double rne20a=den*ne20a_rate(T9);
|
||||
double r1212=den*c12c12_rate(T9);
|
||||
double r1216=den*c12o16_rate(T9);
|
||||
|
||||
double pfrac=n15pg_frac(T9);
|
||||
double afrac=1-pfrac;
|
||||
|
||||
double yh1 = y[Net:: ih1];
|
||||
double yhe3 = y[Net:: ihe3];
|
||||
double yhe4 = y[Net:: ihe4];
|
||||
double yc12 = y[Net:: ic12];
|
||||
double yn14 = y[Net:: in14];
|
||||
double yo16 = y[Net:: io16];
|
||||
double yne20 = y[Net::ine20];
|
||||
|
||||
dydt[Net::ih1] = -1.5*yh1*yh1*rpp;
|
||||
dydt[Net::ih1] += yhe3*yhe3*r33;
|
||||
dydt[Net::ih1] += -yhe3*yhe4*r34;
|
||||
dydt[Net::ih1] += -2*yh1*yc12*rc12p;
|
||||
dydt[Net::ih1] += -2*yh1*yn14*rn14p;
|
||||
dydt[Net::ih1] += -2*yh1*yo16*ro16p;
|
||||
|
||||
dydt[Net::ihe3] = 0.5*yh1*yh1*rpp;
|
||||
dydt[Net::ihe3] += -yhe3*yhe3*r33;
|
||||
dydt[Net::ihe3] += -yhe3*yhe4*r34;
|
||||
|
||||
dydt[Net::ihe4] = 0.5*yhe3*yhe3*r33;
|
||||
dydt[Net::ihe4] += yhe3*yhe4*r34;
|
||||
dydt[Net::ihe4] += -yhe4*yc12*rc12a;
|
||||
dydt[Net::ihe4] += yh1*yn14*afrac*rn14p;
|
||||
dydt[Net::ihe4] += yh1*yo16*ro16p;
|
||||
dydt[Net::ihe4] += -0.5*yhe4*yhe4*yhe4*r3a;
|
||||
dydt[Net::ihe4] += -yhe4*yo16*ro16a;
|
||||
dydt[Net::ihe4] += 0.5*yc12*yc12*r1212;
|
||||
dydt[Net::ihe4] += yc12*yo16*r1216;
|
||||
dydt[Net::ihe4] += -yhe4*yne20*rne20a;
|
||||
|
||||
dydt[Net::ic12] = (1./6.)*yhe4*yhe4*yhe4*r3a;
|
||||
dydt[Net::ic12] += -yhe4*yc12*rc12a;
|
||||
dydt[Net::ic12] += -yh1*yc12*rc12p;
|
||||
dydt[Net::ic12] += yh1*yn14*afrac*rn14p;
|
||||
dydt[Net::ic12] += -yc12*yc12*r1212;
|
||||
dydt[Net::ic12] += -yc12*yo16*r1216;
|
||||
|
||||
dydt[Net::in14] = yh1*yc12*rc12p;
|
||||
dydt[Net::in14] += -yh1*yn14*rn14p;
|
||||
dydt[Net::in14] += yh1*yo16*ro16p;
|
||||
dydt[Net::in14] += -yhe4*yn14*rn14a;
|
||||
|
||||
dydt[Net::io16] = yhe4*yc12*rc12a;
|
||||
dydt[Net::io16] += yh1*yn14*pfrac*rn14p;
|
||||
dydt[Net::io16] += -yh1*yo16*ro16p;
|
||||
dydt[Net::io16] += -yc12*yo16*r1216;
|
||||
dydt[Net::io16] += -yhe4*yo16*ro16a;
|
||||
|
||||
dydt[Net::ine20] = 0.5*yc12*yc12*r1212;
|
||||
dydt[Net::ine20] += yhe4*yn14*rn14a;
|
||||
dydt[Net::ine20] += yhe4*yo16*ro16a;
|
||||
dydt[Net::ine20] += -yhe4*yne20*rne20a;
|
||||
|
||||
dydt[Net::img24] = yc12*yo16*r1216;
|
||||
dydt[Net::img24] += yhe4*yne20*rne20a;
|
||||
|
||||
dydt[Net::itemp] = 0.;
|
||||
dydt[Net::iden] = 0.;
|
||||
|
||||
// energy accounting
|
||||
double enuc = 0.;
|
||||
for (int i=0; i<Net::niso; i++) {
|
||||
enuc += Net::mion[i]*dydt[i];
|
||||
}
|
||||
dydt[Net::iener] = -enuc*avo*clight*clight;
|
||||
}
|
||||
|
||||
nuclearNetwork::NetOut Approx8Network::evaluate(const nuclearNetwork::NetIn &netIn) {
|
||||
m_y = convert_netIn(netIn);
|
||||
m_tmax = netIn.tmax;
|
||||
m_dt0 = netIn.dt0;
|
||||
|
||||
const double stiff_abs_tol = m_config.get<double>("Network:Approx8:Stiff:AbsTol", 1.0e-6);
|
||||
const double stiff_rel_tol = m_config.get<double>("Network:Approx8:Stiff:RelTol", 1.0e-6);
|
||||
const double nonstiff_abs_tol = m_config.get<double>("Network:Approx8:NonStiff:AbsTol", 1.0e-6);
|
||||
const double nonstiff_rel_tol = m_config.get<double>("Network:Approx8:NonStiff:RelTol", 1.0e-6);
|
||||
|
||||
int num_steps = -1;
|
||||
|
||||
if (m_stiff) {
|
||||
LOG_DEBUG(m_logger, "Using stiff solver for Approx8Network");
|
||||
num_steps = integrate_const(
|
||||
make_dense_output<rosenbrock4<double>>(stiff_abs_tol, stiff_rel_tol),
|
||||
std::make_pair(ODE(), Jacobian()),
|
||||
m_y,
|
||||
0.0,
|
||||
m_tmax,
|
||||
m_dt0
|
||||
);
|
||||
|
||||
} else {
|
||||
LOG_DEBUG(m_logger, "Using non stiff solver for Approx8Network");
|
||||
num_steps = integrate_const (
|
||||
make_dense_output<runge_kutta_dopri5<vector_type>>(nonstiff_abs_tol, nonstiff_rel_tol),
|
||||
ODE(),
|
||||
m_y,
|
||||
0.0,
|
||||
m_tmax,
|
||||
m_dt0
|
||||
);
|
||||
}
|
||||
|
||||
double ysum = 0.0;
|
||||
for (int i = 0; i < Net::niso; i++) {
|
||||
m_y[i] *= Net::aion[i];
|
||||
ysum += m_y[i];
|
||||
}
|
||||
for (int i = 0; i < Net::niso; i++) {
|
||||
m_y[i] /= ysum;
|
||||
}
|
||||
|
||||
nuclearNetwork::NetOut netOut;
|
||||
std::vector<double> outComposition;
|
||||
outComposition.reserve(Net::nvar);
|
||||
|
||||
for (int i = 0; i < Net::niso; i++) {
|
||||
outComposition.push_back(m_y[i]);
|
||||
}
|
||||
netOut.energy = m_y[Net::iener];
|
||||
netOut.composition = outComposition;
|
||||
netOut.num_steps = num_steps;
|
||||
|
||||
return netOut;
|
||||
}
|
||||
|
||||
void Approx8Network::setStiff(bool stiff) {
|
||||
m_stiff = stiff;
|
||||
}
|
||||
|
||||
vector_type Approx8Network::convert_netIn(const nuclearNetwork::NetIn &netIn) {
|
||||
if (netIn.composition.size() != Net::niso) {
|
||||
LOG_ERROR(m_logger, "Error: composition size mismatch in convert_netIn");
|
||||
throw std::runtime_error("Error: composition size mismatch in convert_netIn");
|
||||
}
|
||||
|
||||
vector_type y(Net::nvar, 0.0);
|
||||
y[Net::ih1] = netIn.composition[0];
|
||||
y[Net::ihe3] = netIn.composition[1];
|
||||
y[Net::ihe4] = netIn.composition[2];
|
||||
y[Net::ic12] = netIn.composition[3];
|
||||
y[Net::in14] = netIn.composition[4];
|
||||
y[Net::io16] = netIn.composition[5];
|
||||
y[Net::ine20] = netIn.composition[6];
|
||||
y[Net::img24] = netIn.composition[7];
|
||||
y[Net::itemp] = netIn.temperature;
|
||||
y[Net::iden] = netIn.density;
|
||||
y[Net::iener] = netIn.energy;
|
||||
|
||||
double ysum = 0.0;
|
||||
for (int i = 0; i < Net::niso; i++) {
|
||||
y[i] /= Net::aion[i];
|
||||
ysum += y[i];
|
||||
}
|
||||
for (int i = 0; i < Net::niso; i++) {
|
||||
y[i] /= ysum;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// main program
|
||||
|
||||
16
src/network/private/network.cpp
Normal file
16
src/network/private/network.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "network.h"
|
||||
#include "probe.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
namespace nuclearNetwork {
|
||||
Network::Network() :
|
||||
m_config(Config::getInstance()),
|
||||
m_logManager(Probe::LogManager::getInstance()),
|
||||
m_logger(m_logManager.getLogger("log")) {
|
||||
}
|
||||
nuclearNetwork::NetOut nuclearNetwork::Network::evaluate(const NetIn &netIn) {
|
||||
// You can throw an exception here or log a warning if it should never be used.
|
||||
LOG_ERROR(m_logger, "nuclearNetwork::Network::evaluate() is not implemented");
|
||||
throw std::runtime_error("nuclearNetwork::Network::evaluate() is not implemented");
|
||||
}
|
||||
}
|
||||
314
src/network/public/approx8.h
Normal file
314
src/network/public/approx8.h
Normal file
@@ -0,0 +1,314 @@
|
||||
#ifndef APPROX8_H
|
||||
#define APPROX8_H
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <boost/numeric/odeint.hpp>
|
||||
|
||||
#include "network.h"
|
||||
|
||||
/**
|
||||
* @file approx8.h
|
||||
* @brief Header file for the Approx8 nuclear reaction network.
|
||||
*
|
||||
* This file contains the definitions and declarations for the Approx8 nuclear reaction network.
|
||||
* The network is based on Frank Timmes' "aprox8" and includes 8 isotopes and various nuclear reactions.
|
||||
* The rates are evaluated using a fitting function with coefficients from reaclib.jinaweb.org.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef vector_type
|
||||
* @brief Alias for a vector of doubles using Boost uBLAS.
|
||||
*/
|
||||
typedef boost::numeric::ublas::vector< double > vector_type;
|
||||
|
||||
/**
|
||||
* @typedef matrix_type
|
||||
* @brief Alias for a matrix of doubles using Boost uBLAS.
|
||||
*/
|
||||
typedef boost::numeric::ublas::matrix< double > matrix_type;
|
||||
|
||||
/**
|
||||
* @typedef vec7
|
||||
* @brief Alias for a std::array of 7 doubles.
|
||||
*/
|
||||
typedef std::array<double,7> vec7;
|
||||
|
||||
namespace nnApprox8{
|
||||
|
||||
using namespace boost::numeric::odeint;
|
||||
|
||||
/**
|
||||
* @struct Net
|
||||
* @brief Contains constants and arrays related to the nuclear network.
|
||||
*/
|
||||
struct Net{
|
||||
const static int ih1=0;
|
||||
const static int ihe3=1;
|
||||
const static int ihe4=2;
|
||||
const static int ic12=3;
|
||||
const static int in14=4;
|
||||
const static int io16=5;
|
||||
const static int ine20=6;
|
||||
const static int img24=7;
|
||||
|
||||
const static int itemp=img24+1;
|
||||
const static int iden =itemp+1;
|
||||
const static int iener=iden+1;
|
||||
|
||||
const static int niso=img24+1; // number of isotopes
|
||||
const static int nvar=iener+1; // number of variables
|
||||
|
||||
static constexpr std::array<int,niso> aion = {
|
||||
1,
|
||||
3,
|
||||
4,
|
||||
12,
|
||||
14,
|
||||
16,
|
||||
20,
|
||||
24
|
||||
};
|
||||
|
||||
static constexpr std::array<double,niso> mion = {
|
||||
1.67262164e-24,
|
||||
5.00641157e-24,
|
||||
6.64465545e-24,
|
||||
1.99209977e-23,
|
||||
2.32462686e-23,
|
||||
2.65528858e-23,
|
||||
3.31891077e-23,
|
||||
3.98171594e-23
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Multiplies two arrays and sums the resulting elements.
|
||||
* @param a First array.
|
||||
* @param b Second array.
|
||||
* @return Sum of the product of the arrays.
|
||||
* @example
|
||||
* @code
|
||||
* vec7 a = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
|
||||
* vec7 b = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
|
||||
* double result = sum_product(a, b);
|
||||
* @endcode
|
||||
*/
|
||||
double sum_product( const vec7 &a, const vec7 &b);
|
||||
|
||||
/**
|
||||
* @brief Returns an array of T9 terms for the nuclear reaction rate fit.
|
||||
* @param T Temperature in GigaKelvin.
|
||||
* @return Array of T9 terms.
|
||||
* @example
|
||||
* @code
|
||||
* double T = 1.5;
|
||||
* vec7 T9_array = get_T9_array(T);
|
||||
* @endcode
|
||||
*/
|
||||
vec7 get_T9_array(const double &T);
|
||||
|
||||
/**
|
||||
* @brief Evaluates the nuclear reaction rate given the T9 array and coefficients.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @param coef Array of coefficients.
|
||||
* @return Evaluated rate.
|
||||
* @example
|
||||
* @code
|
||||
* vec7 T9 = get_T9_array(1.5);
|
||||
* vec7 coef = {1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001};
|
||||
* double rate = rate_fit(T9, coef);
|
||||
* @endcode
|
||||
*/
|
||||
double rate_fit(const vec7 &T9, const vec7 &coef);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction p + p -> d.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double pp_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction p + d -> he3.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double dp_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction he3 + he3 -> he4 + 2p.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double he3he3_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction he3(he3,2p)he4.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double he3he4_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction he4 + he4 + he4 -> c12.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double triple_alpha_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction c12 + p -> n13.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double c12p_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction c12 + he4 -> o16.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double c12a_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction n14(p,g)o15 - o15 + p -> c12 + he4.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double n14p_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction n14(a,g)f18 assumed to go on to ne20.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double n14a_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction n15(p,a)c12 (CNO I).
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double n15pa_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction n15(p,g)o16 (CNO II).
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double n15pg_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the fraction for the reaction n15(p,g)o16.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Fraction of the reaction.
|
||||
*/
|
||||
double n15pg_frac(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction o16(p,g)f17 then f17 -> o17(p,a)n14.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double o16p_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction o16(a,g)ne20.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double o16a_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction ne20(a,g)mg24.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double ne20a_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction c12(c12,a)ne20.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double c12c12_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @brief Calculates the rate for the reaction c12(o16,a)mg24.
|
||||
* @param T9 Array of T9 terms.
|
||||
* @return Rate of the reaction.
|
||||
*/
|
||||
double c12o16_rate(const vec7 &T9);
|
||||
|
||||
/**
|
||||
* @struct Jacobian
|
||||
* @brief Functor to calculate the Jacobian matrix for implicit solvers.
|
||||
*/
|
||||
struct Jacobian {
|
||||
/**
|
||||
* @brief Calculates the Jacobian matrix.
|
||||
* @param y State vector.
|
||||
* @param J Jacobian matrix.
|
||||
* @param t Time.
|
||||
* @param dfdt Derivative of the state vector.
|
||||
*/
|
||||
void operator() ( const vector_type &y, matrix_type &J, double /* t */, vector_type &dfdt );
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct ODE
|
||||
* @brief Functor to calculate the derivatives for the ODE solver.
|
||||
*/
|
||||
struct ODE {
|
||||
/**
|
||||
* @brief Calculates the derivatives of the state vector.
|
||||
* @param y State vector.
|
||||
* @param dydt Derivative of the state vector.
|
||||
* @param t Time.
|
||||
*/
|
||||
void operator() ( const vector_type &y, vector_type &dydt, double /* t */);
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Approx8Network
|
||||
* @brief Class for the Approx8 nuclear reaction network.
|
||||
*/
|
||||
class Approx8Network : public nuclearNetwork::Network {
|
||||
public:
|
||||
/**
|
||||
* @brief Evaluates the nuclear network.
|
||||
* @param netIn Input parameters for the network.
|
||||
* @return Output results from the network.
|
||||
*/
|
||||
virtual nuclearNetwork::NetOut evaluate(const nuclearNetwork::NetIn &netIn);
|
||||
|
||||
/**
|
||||
* @brief Sets whether the solver should use a stiff method.
|
||||
* @param stiff Boolean indicating if a stiff method should be used.
|
||||
*/
|
||||
void setStiff(bool stiff);
|
||||
|
||||
/**
|
||||
* @brief Checks if the solver is using a stiff method.
|
||||
* @return Boolean indicating if a stiff method is being used.
|
||||
*/
|
||||
bool isStiff() { return m_stiff; }
|
||||
private:
|
||||
vector_type m_y;
|
||||
double m_tmax;
|
||||
double m_dt0;
|
||||
bool m_stiff = false;
|
||||
|
||||
/**
|
||||
* @brief Converts the input parameters to the internal state vector.
|
||||
* @param netIn Input parameters for the network.
|
||||
* @return Internal state vector.
|
||||
*/
|
||||
vector_type convert_netIn(const nuclearNetwork::NetIn &netIn);
|
||||
};
|
||||
|
||||
} // namespace nnApprox8
|
||||
|
||||
#endif
|
||||
93
src/network/public/network.h
Normal file
93
src/network/public/network.h
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "probe.h"
|
||||
#include "config.h"
|
||||
#include "quill/Logger.h"
|
||||
|
||||
namespace nuclearNetwork {
|
||||
|
||||
/**
|
||||
* @struct NetIn
|
||||
* @brief Input structure for the network evaluation.
|
||||
*
|
||||
* This structure holds the input parameters required for the network evaluation.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* nuclearNetwork::NetIn netIn;
|
||||
* netIn.composition = {1.0, 0.0, 0.0};
|
||||
* netIn.tmax = 1.0e6;
|
||||
* netIn.dt0 = 1.0e-3;
|
||||
* netIn.temperature = 1.0e8;
|
||||
* netIn.density = 1.0e5;
|
||||
* netIn.energy = 1.0e12;
|
||||
* @endcode
|
||||
*/
|
||||
struct NetIn {
|
||||
std::vector<double> composition; ///< Composition of the network
|
||||
double tmax; ///< Maximum time
|
||||
double dt0; ///< Initial time step
|
||||
double temperature; ///< Temperature in Kelvin
|
||||
double density; ///< Density in g/cm^3
|
||||
double energy; ///< Energy in ergs
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct NetOut
|
||||
* @brief Output structure for the network evaluation.
|
||||
*
|
||||
* This structure holds the output results from the network evaluation.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* nuclearNetwork::NetOut netOut = network.evaluate(netIn);
|
||||
* std::vector<double> composition = netOut.composition;
|
||||
* int steps = netOut.num_steps;
|
||||
* double energy = netOut.energy;
|
||||
* @endcode
|
||||
*/
|
||||
struct NetOut {
|
||||
std::vector<double> composition; ///< Composition of the network after evaluation
|
||||
int num_steps; ///< Number of steps taken in the evaluation
|
||||
double energy; ///< Energy in ergs after evaluation
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Network
|
||||
* @brief Class for network evaluation.
|
||||
*
|
||||
* This class provides methods to evaluate the network based on the input parameters.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* nuclearNetwork::Network network;
|
||||
* nuclearNetwork::NetIn netIn;
|
||||
* // Set netIn parameters...
|
||||
* nuclearNetwork::NetOut netOut = network.evaluate(netIn);
|
||||
* @endcode
|
||||
*/
|
||||
class Network {
|
||||
public:
|
||||
Network();
|
||||
virtual ~Network() = default;
|
||||
|
||||
/**
|
||||
* @brief Evaluate the network based on the input parameters.
|
||||
*
|
||||
* @param netIn Input parameters for the network evaluation.
|
||||
* @return NetOut Output results from the network evaluation.
|
||||
*/
|
||||
virtual NetOut evaluate(const NetIn &netIn);
|
||||
|
||||
protected:
|
||||
Config& m_config; ///< Configuration instance
|
||||
Probe::LogManager& m_logManager; ///< Log manager instance
|
||||
quill::Logger* m_logger; ///< Logger instance
|
||||
};
|
||||
|
||||
} // namespace nuclearNetwork
|
||||
|
||||
#endif // NETWORK_H
|
||||
@@ -1,20 +0,0 @@
|
||||
# Define the library
|
||||
opatIO_sources = files(
|
||||
'private/opatIO.cpp',
|
||||
)
|
||||
|
||||
opatIO_headers = files(
|
||||
'public/opatIO.h'
|
||||
)
|
||||
|
||||
# Define the libopatIO library so it can be linked against by other parts of the build system
|
||||
libopatIO = library('opatIO',
|
||||
opatIO_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
dependencies: [picosha2_dep],
|
||||
install : true,
|
||||
)
|
||||
|
||||
# Make headers accessible
|
||||
install_headers(opatIO_headers, subdir : '4DSSE/opatIO')
|
||||
@@ -1,520 +0,0 @@
|
||||
/* ***********************************************************************
|
||||
//
|
||||
// Copyright (C) 2025 -- The 4D-STAR Collaboration
|
||||
// File Author: Emily Boudreaux
|
||||
// Last Modified: March 07, 2025
|
||||
//
|
||||
// 4DSSE is free software; you can use it and/or modify
|
||||
// it under the terms and restrictions the GNU General Library Public
|
||||
// License version 3 (GPLv3) as published by the Free Software Foundation.
|
||||
//
|
||||
// 4DSSE is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public License
|
||||
// along with this software; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// *********************************************************************** */
|
||||
#include "opatIO.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <deque>
|
||||
#include <cstdint>
|
||||
#include "picosha2.h"
|
||||
|
||||
// Function to check system endianness
|
||||
bool is_big_endian() {
|
||||
uint16_t test = 0x1;
|
||||
return reinterpret_cast<uint8_t*>(&test)[0] == 0;
|
||||
}
|
||||
|
||||
// Generic function to swap bytes for any type
|
||||
template <typename T>
|
||||
T swap_bytes(T value) {
|
||||
static_assert(std::is_trivially_copyable<T>::value, "swap_bytes only supports trivial types.");
|
||||
T result;
|
||||
uint8_t* src = reinterpret_cast<uint8_t*>(&value);
|
||||
uint8_t* dest = reinterpret_cast<uint8_t*>(&result);
|
||||
for (size_t i = 0; i < sizeof(T); i++) {
|
||||
dest[i] = src[sizeof(T) - 1 - i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
OpatIO::OpatIO() {}
|
||||
|
||||
OpatIO::OpatIO(std::string filename) : filename(filename) {
|
||||
load();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
OpatIO::~OpatIO() {
|
||||
unload();
|
||||
}
|
||||
|
||||
// Load the OPAT file
|
||||
void OpatIO::load() {
|
||||
if (loaded) return;
|
||||
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Could not open file: " + filename);
|
||||
}
|
||||
|
||||
readHeader(file);
|
||||
readTableIndex(file);
|
||||
|
||||
loaded = true;
|
||||
file.close();
|
||||
}
|
||||
|
||||
// // Unload the OPAT file
|
||||
void OpatIO::unload() {
|
||||
if (!loaded) return;
|
||||
|
||||
tableIndex.clear();
|
||||
while (!tableQueue.empty()) {
|
||||
tableQueue.pop_front();
|
||||
}
|
||||
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
// Read the header from the file
|
||||
void OpatIO::readHeader(std::ifstream &file) {
|
||||
file.read(reinterpret_cast<char*>(&header), sizeof(Header));
|
||||
if (file.gcount() != sizeof(Header)) {
|
||||
throw std::runtime_error("Error reading header from file");
|
||||
}
|
||||
|
||||
if (is_big_endian()) {
|
||||
header.version = swap_bytes(header.version);
|
||||
header.numTables = swap_bytes(header.numTables);
|
||||
header.indexOffset = swap_bytes(header.indexOffset);
|
||||
header.numIndex = swap_bytes(header.numIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Read the table index from the file
|
||||
void OpatIO::readTableIndex(std::ifstream &file) {
|
||||
file.seekg(header.indexOffset, std::ios::beg);
|
||||
tableIndex.resize(header.numTables);
|
||||
long unsigned int indexReadBytes;
|
||||
for (uint32_t i = 0; i < header.numTables; i++) {
|
||||
indexReadBytes = 0;
|
||||
// Read the index vector in based on numIndex
|
||||
tableIndex.at(i).index.resize(header.numIndex);
|
||||
file.read(reinterpret_cast<char*>(tableIndex.at(i).index.data()), header.numIndex * sizeof(double));
|
||||
indexReadBytes += static_cast<int>(file.gcount());
|
||||
|
||||
// Read the start and end position of the table in
|
||||
file.read(reinterpret_cast<char*>(&tableIndex.at(i).byteStart), sizeof(uint64_t));
|
||||
indexReadBytes += static_cast<int>(file.gcount());
|
||||
file.read(reinterpret_cast<char*>(&tableIndex.at(i).byteEnd), sizeof(uint64_t));
|
||||
indexReadBytes += static_cast<int>(file.gcount());
|
||||
|
||||
// Read the checksum in
|
||||
file.read(tableIndex.at(i).sha256, 32);
|
||||
indexReadBytes += static_cast<int>(file.gcount());
|
||||
|
||||
// validate that the size of read data is correct
|
||||
if (indexReadBytes != header.numIndex * sizeof(double) + 32 + 2 * sizeof(uint64_t)) {
|
||||
throw std::runtime_error("Error reading table index from file");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTableIDToIndex();
|
||||
}
|
||||
|
||||
void OpatIO::buildTableIDToIndex(){
|
||||
tableIDToIndex.clear();
|
||||
int tableID = 0;
|
||||
std::vector<double> ind;
|
||||
ind.resize(header.numIndex);
|
||||
for (const auto &table : tableIndex) {
|
||||
ind.clear();
|
||||
for (const auto &index : table.index) {
|
||||
ind.push_back(index);
|
||||
}
|
||||
tableIDToIndex.emplace(tableID, ind);
|
||||
tableID++;
|
||||
}
|
||||
LookupEpsilon();
|
||||
}
|
||||
|
||||
void OpatIO::LookupEpsilon() {
|
||||
/*
|
||||
Get 10% of the minimum spacing between index values
|
||||
in the tableIDToIndex map. This can be used
|
||||
to set the comparison distance when doing a reverse
|
||||
lookup (index -> tableID)
|
||||
*/
|
||||
indexEpsilon.resize(header.numIndex);
|
||||
|
||||
double epsilon;
|
||||
for (int i = 0; i < static_cast<int>(header.numIndex); i++) {
|
||||
epsilon = std::numeric_limits<double>::max();
|
||||
for (int j = 1; j < static_cast<int>(header.numTables); j++) {
|
||||
epsilon = std::min(epsilon, std::fabs(tableIDToIndex.at(j).at(i) - tableIDToIndex.at(j-1).at(i)));
|
||||
}
|
||||
indexEpsilon.at(i) = epsilon * 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
int OpatIO::lookupTableID(std::vector<double> index) {
|
||||
std::vector<bool> IndexOkay;
|
||||
IndexOkay.resize(header.numIndex);
|
||||
int tableID = 0;
|
||||
for (const auto &tableMap : tableIDToIndex){
|
||||
// Loop through all index values and check if they are within epsilon for that index
|
||||
std::fill(IndexOkay.begin(), IndexOkay.end(), false);
|
||||
for (long unsigned int i = 0; i < index.size(); i++) {
|
||||
IndexOkay.at(i) = std::fabs(tableMap.second.at(i) - index.at(i)) < indexEpsilon.at(i);
|
||||
}
|
||||
// If all index values are within epsilon, return the table ID
|
||||
if (std::all_of(IndexOkay.begin(), IndexOkay.end(), [](bool i){return i;})) {
|
||||
return tableID;
|
||||
}
|
||||
tableID++;
|
||||
}
|
||||
// If no table is found, return -1 (sentinal value)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get a table from the queue
|
||||
OPATTable OpatIO::getTableFromQueue(int tableID) {
|
||||
for (const auto &table : tableQueue) {
|
||||
if (table.first == tableID) {
|
||||
return table.second;
|
||||
}
|
||||
}
|
||||
throw std::out_of_range("Table not found!");
|
||||
}
|
||||
|
||||
// Add a table to the queue
|
||||
void OpatIO::addTableToQueue(int tableID, OPATTable table) {
|
||||
if (static_cast<int>(tableQueue.size()) >= maxQDepth) {
|
||||
removeTableFromQueue();
|
||||
}
|
||||
std::pair<int, OPATTable> IDTablePair = {tableID, table};
|
||||
tableQueue.push_back(IDTablePair);
|
||||
}
|
||||
|
||||
// Remove a table from the queue
|
||||
void OpatIO::removeTableFromQueue() {
|
||||
if (!tableQueue.empty()) {
|
||||
tableQueue.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
// Flush the queue
|
||||
void OpatIO::flushQueue() {
|
||||
while (!tableQueue.empty()) {
|
||||
tableQueue.pop_back();
|
||||
tableQueue.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the OPAT version
|
||||
uint16_t OpatIO::getOPATVersion() {
|
||||
return header.version;
|
||||
}
|
||||
|
||||
// Get a table for given X and Z
|
||||
OPATTable OpatIO::getTable(std::vector<double> index) {
|
||||
int tableID = lookupTableID(index);
|
||||
if (tableID == -1) {
|
||||
throw std::out_of_range("Index Not found!");
|
||||
}
|
||||
try {
|
||||
return getTableFromQueue(tableID);
|
||||
}
|
||||
catch(const std::out_of_range &e) {
|
||||
return getTable(tableID);
|
||||
}
|
||||
}
|
||||
|
||||
OPATTable OpatIO::getTable(int tableID) {
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Could not open file: " + filename);
|
||||
}
|
||||
|
||||
uint64_t byteStart = tableIndex[tableID].byteStart;
|
||||
|
||||
file.seekg(byteStart, std::ios::beg);
|
||||
|
||||
OPATTable table;
|
||||
|
||||
// Step 1: Read N_R and N_T
|
||||
file.read(reinterpret_cast<char*>(&table.N_R), sizeof(uint32_t));
|
||||
file.read(reinterpret_cast<char*>(&table.N_T), sizeof(uint32_t));
|
||||
|
||||
|
||||
// Resize vectors to hold the correct number of elements
|
||||
table.logR.resize(table.N_R);
|
||||
table.logT.resize(table.N_T);
|
||||
table.logKappa.resize(table.N_R, std::vector<double>(table.N_T));
|
||||
|
||||
// Step 2: Read logR values
|
||||
file.read(reinterpret_cast<char*>(table.logR.data()), table.N_R * sizeof(double));
|
||||
|
||||
// Step 3: Read logT values
|
||||
file.read(reinterpret_cast<char*>(table.logT.data()), table.N_T * sizeof(double));
|
||||
|
||||
// Step 4: Read logKappa values (flattened row-major order)
|
||||
for (size_t i = 0; i < table.N_R; ++i) {
|
||||
|
||||
file.read(reinterpret_cast<char*>(table.logKappa[i].data()), table.N_T * sizeof(double));
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
throw std::runtime_error("Error reading table from file: " + filename);
|
||||
}
|
||||
|
||||
addTableToQueue(tableID, table);
|
||||
file.close();
|
||||
return table;
|
||||
}
|
||||
|
||||
// Set the maximum queue depth
|
||||
void OpatIO::setMaxQDepth(int depth) {
|
||||
maxQDepth = depth;
|
||||
}
|
||||
|
||||
int OpatIO::getMaxQDepth() {
|
||||
return maxQDepth;
|
||||
}
|
||||
|
||||
// Set the filename
|
||||
void OpatIO::setFilename(std::string filename) {
|
||||
if (loaded) {
|
||||
throw std::runtime_error("Cannot set filename while file is loaded");
|
||||
}
|
||||
this->filename = filename;
|
||||
}
|
||||
|
||||
// Check if the file is loaded
|
||||
bool OpatIO::isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
// Print the header
|
||||
void OpatIO::printHeader() {
|
||||
std::cout << "Version: " << header.version << std::endl;
|
||||
std::cout << "Number of Tables: " << header.numTables << std::endl;
|
||||
std::cout << "Header Size: " << header.headerSize << std::endl;
|
||||
std::cout << "Index Offset: " << header.indexOffset << std::endl;
|
||||
std::cout << "Creation Date: " << header.creationDate << std::endl;
|
||||
std::cout << "Source Info: " << header.sourceInfo << std::endl;
|
||||
std::cout << "Comment: " << header.comment << std::endl;
|
||||
std::cout << "Number of Indices: " << header.numIndex << std::endl;
|
||||
}
|
||||
|
||||
// Print the table index
|
||||
void OpatIO::printTableIndex() {
|
||||
if (tableIndex.empty()) {
|
||||
std::cout << "No table indexes found." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Print table header
|
||||
std::cout << std::left << std::setw(10);
|
||||
for (int i = 0; i < header.numIndex; i++) {
|
||||
std::cout << "Index " << i << std::setw(10);
|
||||
}
|
||||
std::cout << std::setw(15) << "Byte Start"
|
||||
<< std::setw(15) << "Byte End"
|
||||
<< "Checksum (SHA-256)" << std::endl;
|
||||
|
||||
std::cout << std::string(80, '=') << std::endl; // Separator line
|
||||
|
||||
// Print each entry in the table
|
||||
for (const auto &index : tableIndex) {
|
||||
std::cout << std::fixed << std::setprecision(4) << std::setw(10);
|
||||
for (int i = 0; i < header.numIndex; i++) {
|
||||
std::cout << index.index[i] << std::setw(10);
|
||||
}
|
||||
std::cout << std::setw(5) << index.byteStart
|
||||
<< std::setw(15) << index.byteEnd
|
||||
<< std::hex; // Switch to hex mode for checksum
|
||||
|
||||
for (int i = 0; i < 8; ++i) { // Print first 8 bytes of SHA-256 for brevity
|
||||
std::cout << std::setw(2) << std::setfill('0') << (int)index.sha256[i];
|
||||
}
|
||||
|
||||
std::cout << "..." << std::dec << std::setfill(' ') << std::endl; // Reset formatting
|
||||
}
|
||||
}
|
||||
|
||||
void OpatIO::printTable(OPATTable table, uint32_t truncateDigits) {
|
||||
int printTo;
|
||||
bool truncate = false;
|
||||
if (table.N_R > truncateDigits) {
|
||||
printTo = truncateDigits;
|
||||
truncate = true;
|
||||
} else {
|
||||
printTo = table.N_R-1;
|
||||
}
|
||||
std::cout << "LogR (size: " << table.logR.size() << "): [";
|
||||
for (int i = 0; i < printTo; ++i) {
|
||||
std::cout << table.logR.at(i) << ", ";
|
||||
}
|
||||
if (truncate) {
|
||||
std::cout << "..., ";
|
||||
for (int i = truncateDigits; i > 1; --i) {
|
||||
std::cout << table.logR.at(table.logR.size() - i) << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << table.logR.back() << "]" << std::endl;
|
||||
|
||||
if (table.N_T > truncateDigits) {
|
||||
printTo = truncateDigits;
|
||||
truncate = true;
|
||||
} else {
|
||||
printTo = table.N_T-1;
|
||||
}
|
||||
std::cout << "LogT (size: " << table.logT.size() << "): [";
|
||||
for (int i = 0; i < printTo; ++i) {
|
||||
std::cout << table.logT.at(i) << ", ";
|
||||
}
|
||||
if (truncate) {
|
||||
std::cout << "..., ";
|
||||
for (int i = truncateDigits; i > 1; --i) {
|
||||
std::cout << table.logT.at(table.logT.size() - i) << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << table.logT.back() << "]" << std::endl;
|
||||
|
||||
bool truncateRow = false;
|
||||
bool truncateCol = false;
|
||||
int printToRow, printToCol;
|
||||
if (table.N_T > truncateDigits) {
|
||||
printToRow = truncateDigits;
|
||||
truncateRow = true;
|
||||
} else {
|
||||
printToRow = table.N_T-1;
|
||||
}
|
||||
if (table.N_R > truncateDigits) {
|
||||
printToCol = truncateDigits;
|
||||
truncateCol = true;
|
||||
} else {
|
||||
printToCol = table.N_R-1;
|
||||
}
|
||||
|
||||
std::cout << "LogKappa (size: " << table.N_R << " x " << table.N_T << "): \n[";
|
||||
for (int rowIndex = 0; rowIndex < printToRow; rowIndex++) {
|
||||
std::cout << "[";
|
||||
for (int colIndex = 0; colIndex < printToCol; colIndex++) {
|
||||
std::cout << table.logKappa.at(rowIndex).at(colIndex) << ", ";
|
||||
}
|
||||
if (truncateRow) {
|
||||
std::cout << "..., ";
|
||||
for (int i = truncateDigits; i > 1; i--) {
|
||||
std::cout << table.logKappa.at(rowIndex).at(table.logKappa.at(rowIndex).size() - i) << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << table.logKappa.at(rowIndex).back() << "],\n";
|
||||
}
|
||||
if (truncateCol) {
|
||||
std::cout << ".\n.\n.\n";
|
||||
for (int rowIndex = truncateDigits; rowIndex > 1; rowIndex--) {
|
||||
std::cout << "[";
|
||||
for (int colIndex = 0; colIndex < printToCol; colIndex++) {
|
||||
std::cout << table.logKappa.at(rowIndex).at(colIndex) << ", ";
|
||||
}
|
||||
if (truncateRow) {
|
||||
std::cout << "..., ";
|
||||
for (int i = truncateDigits; i > 1; i--) {
|
||||
std::cout << table.logKappa.at(rowIndex).at(table.logKappa.at(rowIndex).size() - i) << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << table.logKappa.at(rowIndex).back() << "],\n";
|
||||
}
|
||||
std::cout << "[";
|
||||
for (int colIndex = 0; colIndex < printToCol; colIndex++) {
|
||||
std::cout << table.logKappa.back().at(colIndex) << ", ";
|
||||
}
|
||||
if (truncateRow) {
|
||||
std::cout << "..., ";
|
||||
for (int i = truncateDigits; i > 1; i--) {
|
||||
std::cout << table.logKappa.back().at(table.logKappa.back().size() - i) << ", ";
|
||||
}
|
||||
}
|
||||
std::cout << table.logKappa.back().back() << "]";
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
}
|
||||
|
||||
void OpatIO::printTable(std::vector<double> index, uint32_t truncateDigits) {
|
||||
int tableID = lookupTableID(index);
|
||||
OPATTable table = getTable(tableID);
|
||||
printTable(table, truncateDigits);
|
||||
}
|
||||
|
||||
// Get the table index
|
||||
std::vector<TableIndex> OpatIO::getTableIndex() {
|
||||
return tableIndex;
|
||||
}
|
||||
|
||||
// Get the header
|
||||
Header OpatIO::getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
// Get the size of the index vector used
|
||||
uint16_t OpatIO::getNumIndex() {
|
||||
return header.numIndex;
|
||||
}
|
||||
|
||||
TableIndex OpatIO::getTableIndex(std::vector<double> index) {
|
||||
int tableID = lookupTableID(index);
|
||||
return tableIndex.at(tableID);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> OpatIO::computeChecksum(int tableID) {
|
||||
OPATTable table = getTable(tableID);
|
||||
std::vector<std::vector<double>> logKappa = table.logKappa;
|
||||
std::vector<double> flatData(logKappa.size() * logKappa.size());
|
||||
size_t offset = 0;
|
||||
for (const auto& row : logKappa) {
|
||||
for (const auto& val : row) {
|
||||
flatData[offset++] = val;
|
||||
}
|
||||
}
|
||||
std::vector<unsigned char> flatDataBytes(flatData.size() * sizeof(double));
|
||||
std::memcpy(flatDataBytes.data(), flatData.data(), flatDataBytes.size());
|
||||
std::vector<unsigned char> hash(picosha2::k_digest_size);
|
||||
picosha2::hash256(flatDataBytes.begin(), flatDataBytes.end(), hash.begin(), hash.end());
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> OpatIO::computeChecksum(std::vector<double> index) {
|
||||
int tableID = lookupTableID(index);
|
||||
return computeChecksum(tableID);
|
||||
}
|
||||
|
||||
bool OpatIO::validateAll() {
|
||||
for (const auto &table : tableIDToIndex) {
|
||||
std::vector<unsigned char> hash = computeChecksum(table.first);
|
||||
std::vector<unsigned char> storedHash(tableIndex.at(table.first).sha256, tableIndex.at(table.first).sha256 + 32);
|
||||
if (hash != storedHash) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,290 +0,0 @@
|
||||
/* ***********************************************************************
|
||||
//
|
||||
// Copyright (C) 2025 -- The 4D-STAR Collaboration
|
||||
// File Author: Emily Boudreaux
|
||||
// Last Modified: March 07, 2025
|
||||
//
|
||||
// 4DSSE is free software; you can use it and/or modify
|
||||
// it under the terms and restrictions the GNU General Library Public
|
||||
// License version 3 (GPLv3) as published by the Free Software Foundation.
|
||||
//
|
||||
// 4DSSE is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public License
|
||||
// along with this software; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// *********************************************************************** */
|
||||
#ifndef OPATIO_H
|
||||
#define OPATIO_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Structure to hold the header information of an OPAT file.
|
||||
*/
|
||||
#pragma pack(1)
|
||||
struct Header {
|
||||
char magic[4]; ///< Magic number to identify the file type
|
||||
uint16_t version; ///< Version of the OPAT file format
|
||||
uint32_t numTables; ///< Number of tables in the file
|
||||
uint32_t headerSize; ///< Size of the header
|
||||
uint64_t indexOffset; ///< Offset to the index section
|
||||
char creationDate[16]; ///< Creation date of the file
|
||||
char sourceInfo[64]; ///< Source information
|
||||
char comment[128]; ///< Comment section
|
||||
uint16_t numIndex; ///< Size of index vector per table
|
||||
char reserved[24]; ///< Reserved for future use
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
/**
|
||||
* @brief Structure to hold the index information of a table in an OPAT file.
|
||||
*/
|
||||
struct TableIndex {
|
||||
std::vector<double> index; ///< Index vector for associated table
|
||||
uint64_t byteStart; ///< Byte start position of the table
|
||||
uint64_t byteEnd; ///< Byte end position of the table
|
||||
char sha256[32]; ///< SHA-256 hash of the table data
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure to hold the data of an OPAT table.
|
||||
*/
|
||||
struct OPATTable {
|
||||
uint32_t N_R; ///< Number of R values
|
||||
uint32_t N_T; ///< Number of T values
|
||||
std::vector<double> logR; ///< Logarithm of R values
|
||||
std::vector<double> logT; ///< Logarithm of T values
|
||||
std::vector<std::vector<double>> logKappa; ///< Logarithm of Kappa values
|
||||
};
|
||||
|
||||
class opatIOTest; // Friend for gtest
|
||||
|
||||
/**
|
||||
* @brief Class to manage the input/output operations for OPAT files.
|
||||
*/
|
||||
class OpatIO {
|
||||
private:
|
||||
Header header; ///< Header information of the OPAT file
|
||||
std::vector<TableIndex> tableIndex; ///< Index information of the tables
|
||||
std::deque<std::pair<int, OPATTable>> tableQueue; ///< Queue to manage table caching
|
||||
std::map<int, std::vector<double>> tableIDToIndex; ///< Map to store table ID to indexing
|
||||
std::vector<double> indexEpsilon; ///< Epsilon values for each index
|
||||
int maxQDepth = 20; ///< Maximum depth of the table queue
|
||||
std::string filename; ///< Filename of the OPAT file
|
||||
bool loaded = false; ///< Flag to indicate if the file is loaded
|
||||
|
||||
/**
|
||||
* @brief Read the header from the file.
|
||||
* @param file The input file stream.
|
||||
*/
|
||||
void readHeader(std::ifstream &file);
|
||||
|
||||
/**
|
||||
* @brief Read the table index from the file.
|
||||
* @param file The input file stream.
|
||||
*/
|
||||
void readTableIndex(std::ifstream &file);
|
||||
|
||||
/**
|
||||
* @brief Get a table from the queue.
|
||||
* @param tableID The ID of the table.
|
||||
* @return The OPAT table.
|
||||
*/
|
||||
OPATTable getTableFromQueue(int tableID);
|
||||
|
||||
/**
|
||||
* @brief Add a table to the queue.
|
||||
* @param tableID The ID of the table.
|
||||
* @param table The OPAT table.
|
||||
*/
|
||||
void addTableToQueue(int tableID, OPATTable table);
|
||||
|
||||
/**
|
||||
* @brief Remove a table from the queue.
|
||||
*/
|
||||
void removeTableFromQueue();
|
||||
|
||||
/**
|
||||
* @brief Flush the table queue.
|
||||
*/
|
||||
void flushQueue();
|
||||
|
||||
/**
|
||||
* @brief Get a table by its ID.
|
||||
* @param tableID The ID of the table.
|
||||
* @return The OPAT table.
|
||||
*/
|
||||
OPATTable getTable(int tableID);
|
||||
|
||||
/**
|
||||
* @brief Print a table.
|
||||
* @param table The OPAT table.
|
||||
* @param truncateDigits Number of digits to truncate.
|
||||
*/
|
||||
void printTable(OPATTable table, uint32_t truncateDigits=5);
|
||||
|
||||
/**
|
||||
* @brief Lookup epsilon values for Index.
|
||||
*/
|
||||
void LookupEpsilon();
|
||||
|
||||
/**
|
||||
* @brief Build the table ID to Index mapping.
|
||||
*/
|
||||
void buildTableIDToIndex();
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
*/
|
||||
OpatIO();
|
||||
|
||||
/**
|
||||
* @brief Constructor with filename.
|
||||
* @param filename The name of the OPAT file.
|
||||
*/
|
||||
OpatIO(std::string filename);
|
||||
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
~OpatIO();
|
||||
|
||||
/**
|
||||
* @brief Get a table by index vector
|
||||
* @param index The index vector associated with the table to retrieve.
|
||||
* @throw std::out_of_range if the index is not found.
|
||||
* @return The OPAT table.
|
||||
*/
|
||||
OPATTable getTable(std::vector<double> index);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum depth of the table queue.
|
||||
* @param depth The maximum depth.
|
||||
*/
|
||||
void setMaxQDepth(int depth);
|
||||
|
||||
/**
|
||||
* @brief Get the maximum depth of the table queue.
|
||||
* @return The maximum depth.
|
||||
*/
|
||||
int getMaxQDepth();
|
||||
|
||||
/**
|
||||
* @brief Set the filename of the OPAT file.
|
||||
* @param filename The name of the file.
|
||||
*/
|
||||
void setFilename(std::string filename);
|
||||
|
||||
/**
|
||||
* @brief Load the OPAT file.
|
||||
*/
|
||||
void load();
|
||||
|
||||
/**
|
||||
* @brief Unload the OPAT file.
|
||||
*/
|
||||
void unload();
|
||||
|
||||
/**
|
||||
* @brief Check if the file is loaded.
|
||||
* @return True if the file is loaded, false otherwise.
|
||||
*/
|
||||
bool isLoaded();
|
||||
|
||||
/**
|
||||
* @brief Print the header information.
|
||||
*/
|
||||
void printHeader();
|
||||
|
||||
/**
|
||||
* @brief Print the table index.
|
||||
*/
|
||||
void printTableIndex();
|
||||
|
||||
/**
|
||||
* @brief Print a table by X and Z values.
|
||||
* @param index The index vector associated with the table to print.
|
||||
* @param truncateDigits Number of digits to truncate.
|
||||
*/
|
||||
void printTable(std::vector<double> index, uint32_t truncateDigits=5);
|
||||
|
||||
/**
|
||||
* @brief Get the table index.
|
||||
* @return A vector of TableIndex structures.
|
||||
*/
|
||||
std::vector<TableIndex> getTableIndex();
|
||||
|
||||
/**
|
||||
* @brief Get the header information.
|
||||
* @return The Header structure.
|
||||
*/
|
||||
Header getHeader();
|
||||
|
||||
/**
|
||||
* @brief Lookup the table ID by X and Z values.
|
||||
* @param index The index vector associated with the table to lookup.
|
||||
* @return The table ID if index is found, otherwise -1.
|
||||
*/
|
||||
int lookupTableID(std::vector<double> index);
|
||||
|
||||
/**
|
||||
* @brief Lookup the closest table ID by X and Z values.
|
||||
* @param index The index vector associated with the table to lookup.
|
||||
* @return The closest table ID.
|
||||
*/
|
||||
int lookupClosestTableID(std::vector<double> index);
|
||||
|
||||
/**
|
||||
* @brief Get the version of the OPAT file format.
|
||||
* @return The version of the OPAT file format.
|
||||
*/
|
||||
uint16_t getOPATVersion();
|
||||
|
||||
/**
|
||||
* @brief Get size of the index vector per table in the OPAT file.
|
||||
* @return The size of the index vector per table.
|
||||
*/
|
||||
uint16_t getNumIndex();
|
||||
|
||||
/**
|
||||
* @brief Get the index vector for a given table ID.
|
||||
* @param index The index vector associated with the table to retrieve.
|
||||
* @return The full TableIndex entry for the table
|
||||
*/
|
||||
TableIndex getTableIndex(std::vector<double> index);
|
||||
|
||||
/**
|
||||
* @brief Get the checksum (sha256) for a given table ID.
|
||||
* @param tableID The ID of the table.
|
||||
* @return The checksum vector for the table.
|
||||
*/
|
||||
std::vector<unsigned char> computeChecksum(int tableID);
|
||||
|
||||
/**
|
||||
* @brief Get the checksum (sha256) for a given index vector.
|
||||
* @param index The index vector associated with the table to retrieve.
|
||||
* @return The checksum vector for the table.
|
||||
*/
|
||||
std::vector<unsigned char> computeChecksum(std::vector<double> index);
|
||||
|
||||
/**
|
||||
* @brief Validate the checksum of all tables.
|
||||
* @return True if all checksum are valid, false otherwise.
|
||||
*/
|
||||
bool validateAll();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -27,16 +27,23 @@ probe_headers = files(
|
||||
'public/probe.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
config_dep,
|
||||
mfem_dep,
|
||||
quill_dep
|
||||
]
|
||||
|
||||
# Define the liblogger library so it can be linked against by other parts of the build system
|
||||
libprobe = static_library('probe',
|
||||
probe_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
install : true,
|
||||
dependencies: [config_dep, mfem_dep, quill_dep, macros_dep]
|
||||
dependencies: dependencies
|
||||
)
|
||||
|
||||
probe_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libprobe,
|
||||
dependencies: dependencies
|
||||
)
|
||||
40
src/resource/meson.build
Normal file
40
src/resource/meson.build
Normal file
@@ -0,0 +1,40 @@
|
||||
# Define the library
|
||||
resourceManager_sources = files(
|
||||
'private/resourceManager.cpp',
|
||||
'private/resourceManagerTypes.cpp'
|
||||
)
|
||||
|
||||
resourceManager_headers = files(
|
||||
'public/resourceManager.h',
|
||||
'public/resourceManagerTypes.h'
|
||||
)
|
||||
|
||||
dependencies = [
|
||||
yaml_cpp_dep,
|
||||
opatio_dep,
|
||||
eos_dep,
|
||||
quill_dep,
|
||||
config_dep,
|
||||
probe_dep,
|
||||
mfem_dep,
|
||||
macros_dep,
|
||||
meshio_dep
|
||||
]
|
||||
|
||||
libResourceHeader_dep = declare_dependency(include_directories: include_directories('public'))
|
||||
# Define the libresourceManager library so it can be linked against by other parts of the build system
|
||||
libresourceManager = static_library('resourceManager',
|
||||
resourceManager_sources,
|
||||
include_directories: include_directories('public'),
|
||||
cpp_args: ['-fvisibility=default'],
|
||||
dependencies: dependencies,
|
||||
install : true)
|
||||
|
||||
resourceManager_dep = declare_dependency(
|
||||
include_directories: include_directories('public'),
|
||||
link_with: libresourceManager,
|
||||
dependencies: dependencies
|
||||
)
|
||||
|
||||
# Make headers accessible
|
||||
install_headers(resourceManager_headers, subdir : '4DSSE/resource')
|
||||
68
src/resource/private/resourceManager.cpp
Normal file
68
src/resource/private/resourceManager.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
#include "resourceManager.h"
|
||||
#include "resourceManagerTypes.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
ResourceManager::ResourceManager() {
|
||||
std::string defaultDataDir = TOSTRING(DATA_DIR);
|
||||
m_dataDir = m_config.get<std::string>("Data:Dir", defaultDataDir);
|
||||
// -- Get the index file path using filesytem to make it a system safe path
|
||||
std::string indexFilePath = m_dataDir + "/index.yaml";
|
||||
std::filesystem::path indexFile(indexFilePath);
|
||||
|
||||
m_resourceConfig.loadConfig(indexFile.string());
|
||||
std::vector<std::string> assets = m_resourceConfig.keys();
|
||||
for (auto key : assets ) {
|
||||
load(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> ResourceManager::getAvaliableResources() {
|
||||
std::vector<std::string> resources;
|
||||
resources = m_resourceConfig.keys();
|
||||
return resources;
|
||||
}
|
||||
|
||||
const Resource& ResourceManager::getResource(const std::string &name) const {
|
||||
auto it = m_resources.find(name);
|
||||
if (it != m_resources.end()) {
|
||||
return it->second;
|
||||
}
|
||||
throw std::runtime_error("Resource " + name + " not found");
|
||||
}
|
||||
|
||||
|
||||
bool ResourceManager::loadResource(std::string& name) {
|
||||
return load(name);
|
||||
}
|
||||
|
||||
bool ResourceManager::load(const std::string& name) {
|
||||
const std::string resourcePath = m_dataDir + "/" + m_resourceConfig.get<std::string>(name);
|
||||
std::filesystem::path resourceFile(resourcePath);
|
||||
if (!std::filesystem::exists(resourceFile)) {
|
||||
LOG_ERROR(m_logger, "Resource file not found: {}", resourceFile.string());
|
||||
return false;
|
||||
}
|
||||
LOG_INFO(m_logger, "Loading resource: {}", resourceFile.string());
|
||||
if (m_resources.find(name) != m_resources.end()) {
|
||||
LOG_INFO(m_logger, "Resource already loaded: {}", name);
|
||||
return true;
|
||||
}
|
||||
Resource resource = createResource(name, resourcePath);
|
||||
m_resources[name] = std::move(resource);
|
||||
// -- Check if the resource is already in the map
|
||||
return true;
|
||||
}
|
||||
|
||||
41
src/resource/private/resourceManagerTypes.cpp
Normal file
41
src/resource/private/resourceManagerTypes.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <string>
|
||||
|
||||
#include "resourceManagerTypes.h"
|
||||
#include "opatIO.h"
|
||||
#include "meshIO.h"
|
||||
#include "eosIO.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
std::string getFirstSegment(const std::string& input) {
|
||||
size_t pos = input.find(':');
|
||||
if (pos == std::string::npos) {
|
||||
// No colon found, return the entire string
|
||||
return input;
|
||||
} else {
|
||||
// Return substring from start to the position of the first colon
|
||||
return input.substr(0, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Resource createResource(const std::string& type, const std::string& path) {
|
||||
static const std::unordered_map<std::string, std::function<Resource(const std::string&)>> factoryMap = {
|
||||
{"opac", [](const std::string& p) { return Resource(
|
||||
std::make_unique<OpatIO>(p));
|
||||
}},
|
||||
{"mesh", [](const std::string& p) { return Resource(
|
||||
std::make_unique<MeshIO>(p));
|
||||
}},
|
||||
{"eos", [](const std::string& p) { return Resource(
|
||||
std::make_unique<EosIO>(p));
|
||||
}}
|
||||
// Add more mappings as needed
|
||||
};
|
||||
auto it = factoryMap.find(getFirstSegment(type));
|
||||
if (it != factoryMap.end()) {
|
||||
return it->second(path);
|
||||
} else {
|
||||
throw std::invalid_argument("Unknown resource type: " + type);
|
||||
}
|
||||
}
|
||||
115
src/resource/public/resourceManager.h
Normal file
115
src/resource/public/resourceManager.h
Normal file
@@ -0,0 +1,115 @@
|
||||
#ifndef RESOURCE_MANAGER_H
|
||||
#define RESOURCE_MANAGER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "resourceManagerTypes.h"
|
||||
#include "config.h"
|
||||
#include "probe.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
/**
|
||||
* @class ResourceManager
|
||||
* @brief Manages resources within the application.
|
||||
*
|
||||
* The ResourceManager class is responsible for loading, storing, and providing access to resources.
|
||||
* It follows the Singleton design pattern to ensure only one instance of the manager exists.
|
||||
*/
|
||||
class ResourceManager {
|
||||
private:
|
||||
/**
|
||||
* @brief Private constructor to prevent instantiation.
|
||||
*/
|
||||
ResourceManager();
|
||||
|
||||
/**
|
||||
* @brief Deleted copy constructor to prevent copying.
|
||||
*/
|
||||
ResourceManager(const ResourceManager&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Deleted assignment operator to prevent assignment.
|
||||
*/
|
||||
ResourceManager& operator=(const ResourceManager&) = delete;
|
||||
|
||||
Config& m_config = Config::getInstance();
|
||||
Probe::LogManager& m_logManager = Probe::LogManager::getInstance();
|
||||
quill::Logger* m_logger = m_logManager.getLogger("log");
|
||||
|
||||
Config m_resourceConfig;
|
||||
std::string m_dataDir;
|
||||
std::unordered_map<std::string, Resource> m_resources;
|
||||
|
||||
/**
|
||||
* @brief Loads a resource by name.
|
||||
* @param name The name of the resource to load.
|
||||
* @return True if the resource was loaded successfully, false otherwise.
|
||||
*/
|
||||
bool load(const std::string& name);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Gets the singleton instance of the ResourceManager.
|
||||
* @return The singleton instance of the ResourceManager.
|
||||
*/
|
||||
static ResourceManager& getInstance() {
|
||||
static ResourceManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a list of available resources.
|
||||
* @return A vector of strings containing the names of available resources.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* ResourceManager& manager = ResourceManager::getInstance();
|
||||
* std::vector<std::string> resources = manager.getAvaliableResources();
|
||||
* @endcode
|
||||
*/
|
||||
std::vector<std::string> getAvaliableResources();
|
||||
|
||||
/**
|
||||
* @brief Gets a resource by name.
|
||||
* @param name The name of the resource to retrieve.
|
||||
* @return A constant reference to the requested resource.
|
||||
* @throws std::runtime_error if the resource is not found.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* ResourceManager& manager = ResourceManager::getInstance();
|
||||
* const Resource& resource = manager.getResource("exampleResource");
|
||||
* @endcode
|
||||
*/
|
||||
const Resource& getResource(const std::string &name) const;
|
||||
|
||||
/**
|
||||
* @brief Loads a resource by name.
|
||||
* @param name The name of the resource to load.
|
||||
* @return True if the resource was loaded successfully, false otherwise.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* ResourceManager& manager = ResourceManager::getInstance();
|
||||
* bool success = manager.loadResource("exampleResource");
|
||||
* @endcode
|
||||
*/
|
||||
bool loadResource(std::string& name);
|
||||
|
||||
/**
|
||||
* @brief Loads all resources.
|
||||
* @return An unordered map with resource names as keys and load success as values.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* ResourceManager& manager = ResourceManager::getInstance();
|
||||
* std::unordered_map<std::string, bool> results = manager.loadAllResources();
|
||||
* @endcode
|
||||
*/
|
||||
std::unordered_map<std::string, bool> loadAllResources();
|
||||
};
|
||||
|
||||
#endif // RESOURCE_MANAGER_H
|
||||
71
src/resource/public/resourceManagerTypes.h
Normal file
71
src/resource/public/resourceManagerTypes.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef RESOURCE_MANAGER_TYPES_H
|
||||
#define RESOURCE_MANAGER_TYPES_H
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
#include "opatIO.h"
|
||||
#include "helm.h"
|
||||
#include "meshIO.h"
|
||||
#include "eosIO.h"
|
||||
|
||||
/**
|
||||
* @file resourceManagerTypes.h
|
||||
* @brief Defines types and functions for managing resources.
|
||||
*
|
||||
* This file provides type definitions and functions for handling different
|
||||
* types of resources in a unified manner.
|
||||
*/
|
||||
|
||||
// -- Valid resource types
|
||||
/**
|
||||
* @brief A variant type that can hold different types of resources.
|
||||
*
|
||||
* The Resource type is a std::variant that can hold a unique pointer to
|
||||
* an OpatIO, MeshIO, or EosIO object.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* Resource resource = std::make_unique<OpatIO>(...);
|
||||
* @endcode
|
||||
*/
|
||||
using Resource = std::variant<
|
||||
std::unique_ptr<OpatIO>,
|
||||
std::unique_ptr<MeshIO>,
|
||||
std::unique_ptr<EosIO>>;
|
||||
|
||||
/**
|
||||
* @brief Extracts the first segment of a given string.
|
||||
*
|
||||
* This function takes a string input and returns the first segment
|
||||
* separated by a delimiter (default is '/').
|
||||
*
|
||||
* @param input The input string to be processed.
|
||||
* @return The first segment of the input string.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* std::string segment = getFirstSegment("path/to/resource");
|
||||
* // segment == "path"
|
||||
* @endcode
|
||||
*/
|
||||
std::string getFirstSegment(const std::string& input);
|
||||
|
||||
/**
|
||||
* @brief Creates a resource based on the specified type and path.
|
||||
*
|
||||
* This function creates a resource object based on the provided type
|
||||
* and initializes it using the given path.
|
||||
*
|
||||
* @param type The type of the resource to be created (e.g., "OpatIO", "MeshIO", "EosIO").
|
||||
* @param path The path to initialize the resource with.
|
||||
* @return A Resource object initialized with the specified type and path.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* Resource resource = createResource("OpatIO", "path/to/opat");
|
||||
* @endcode
|
||||
*/
|
||||
Resource createResource(const std::string& type, const std::string& path);
|
||||
|
||||
#endif // RESOURCE_MANAGER_TYPES_H
|
||||
@@ -1,469 +0,0 @@
|
||||
CODATA 2022 + astrophysical constants
|
||||
Most quantities have been converted to CGS
|
||||
Generated on Feb 10, 2025
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Reference:
|
||||
|
||||
Mohr, P. , Tiesinga, E. , Newell, D. and Taylor, B. (2024), Codata Internationally Recommended 2022 Values of the Fundamental Physical Constants,
|
||||
Codata Internationally Recommended 2022 Values of the Fundamental Physical Constants,
|
||||
[online], https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=958002, https://physics.nist.gov/constants (Accessed February 10, 2025)
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Symbol Name Value Unit Uncertainty Source
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
wienK Wien displacement law constant 2.89776850e-01 K cm 5.10000000e-07 CODATA2022
|
||||
au1Hyper atomic unit of 1st hyperpolarizablity 3.20636151e-53 C^3 m^3 J^-2 2.80000000e-60 CODATA2022
|
||||
au2Hyper atomic unit of 2nd hyperpolarizablity 6.23538080e-65 C^4 m^4 J^-3 1.10000000e-71 CODATA2022
|
||||
auEDip atomic unit of electric dipole moment 8.47835309e-30 C m 7.30000000e-37 CODATA2022
|
||||
auEPol atomic unit of electric polarizablity 1.64877727e-41 C^2 m^2 J^-1 1.60000000e-49 CODATA2022
|
||||
auEQuad atomic unit of electric quadrupole moment 4.48655124e-40 C m^2 3.90000000e-47 CODATA2022
|
||||
auMDip atomic unit of magn. dipole moment 1.85480190e-23 J T^-1 1.60000000e-30 CODATA2022
|
||||
auMFlux atomic unit of magn. flux density 2.35051757e+09 G 7.10000000e-01 CODATA2022
|
||||
muD deuteron magn. moment 4.33073482e-27 J T^-1 3.80000000e-34 CODATA2022
|
||||
muD_Bhor deuteron magn. moment to Bohr magneton ratio 4.66975457e-04 5.00000000e-12 CODATA2022
|
||||
muD_Nuc deuteron magn. moment to nuclear magneton ratio 8.57438233e-01 9.20000000e-09 CODATA2022
|
||||
muD_e deuteron-electron magn. moment ratio -4.66434555e-04 5.00000000e-12 CODATA2022
|
||||
muD_p deuteron-proton magn. moment ratio 3.07012208e-01 4.50000000e-09 CODATA2022
|
||||
muD_n deuteron-neutron magn. moment ratio -4.48206520e-01 1.10000000e-07 CODATA2022
|
||||
rgE electron gyromagn. ratio 1.76085963e+11 s^-1 T^-1 5.30000000e+01 CODATA2022
|
||||
rgE_2pi electron gyromagn. ratio over 2 pi 2.80249532e+04 MHz T^-1 2.40000000e-03 CODATA2022
|
||||
muE electron magn. moment -9.28476412e-24 J T^-1 8.00000000e-31 CODATA2022
|
||||
muE_Bhor electron magn. moment to Bohr magneton ratio -1.00115965e+00 3.80000000e-12 CODATA2022
|
||||
muE_Nuc electron magn. moment to nuclear magneton ratio -1.83828197e+03 8.50000000e-07 CODATA2022
|
||||
muE_anom electron magn. moment anomaly 1.15965219e-03 3.80000000e-12 CODATA2022
|
||||
muE_muP_shield electron to shielded proton magn. moment ratio -6.58227596e+02 7.10000000e-06 CODATA2022
|
||||
muE_muH_shield electron to shielded helion magn. moment ratio 8.64058255e+02 1.00000000e-05 CODATA2022
|
||||
muE_D electron-deuteron magn. moment ratio -2.14392349e+03 2.30000000e-05 CODATA2022
|
||||
muE_mu electron-muon magn. moment ratio 2.06766989e+02 5.40000000e-06 CODATA2022
|
||||
muE_n electron-neutron magn. moment ratio 9.60920500e+02 2.30000000e-04 CODATA2022
|
||||
muE_p electron-proton magn. moment ratio -6.58210686e+02 6.60000000e-06 CODATA2022
|
||||
mu0 magn. constant 1.25663706e-06 N A^-2 0.00000000e+00 CODATA2022
|
||||
phi0 magn. flux quantum 2.06783385e-15 Wb 0.00000000e+00 CODATA2022
|
||||
muMu muon magn. moment -4.49044799e-26 J T^-1 4.00000000e-33 CODATA2022
|
||||
muMu_Bhor muon magn. moment to Bohr magneton ratio -4.84197045e-03 1.30000000e-10 CODATA2022
|
||||
muMu_Nuc muon magn. moment to nuclear magneton ratio -8.89059698e+00 2.30000000e-07 CODATA2022
|
||||
muMu_p muon-proton magn. moment ratio -3.18334512e+00 8.90000000e-08 CODATA2022
|
||||
rgN neutron gyromagn. ratio 1.83247171e+08 s^-1 T^-1 4.30000000e+01 CODATA2022
|
||||
rgN_2pi neutron gyromagn. ratio over 2 pi 2.91646950e+01 MHz T^-1 7.30000000e-06 CODATA2022
|
||||
muN neutron magn. moment -9.66236450e-27 J T^-1 2.40000000e-33 CODATA2022
|
||||
muN_Bhor neutron magn. moment to Bohr magneton ratio -1.04187563e-03 2.50000000e-10 CODATA2022
|
||||
muN_Nuc neutron magn. moment to nuclear magneton ratio -1.91304273e+00 4.50000000e-07 CODATA2022
|
||||
muN_p_shield neutron to shielded proton magn. moment ratio -6.84996940e-01 1.60000000e-07 CODATA2022
|
||||
muN_e neutron-electron magn. moment ratio 1.04066882e-03 2.50000000e-10 CODATA2022
|
||||
muN_p neutron-proton magn. moment ratio -6.84979340e-01 1.60000000e-07 CODATA2022
|
||||
rgP proton gyromagn. ratio 2.67522187e+08 s^-1 T^-1 1.10000000e-01 CODATA2022
|
||||
rgP_2pi proton gyromagn. ratio over 2 pi 4.25774813e+01 MHz T^-1 3.70000000e-06 CODATA2022
|
||||
muP proton magn. moment 1.41060671e-26 J T^-1 1.20000000e-33 CODATA2022
|
||||
muP_Bhor proton magn. moment to Bohr magneton ratio 1.52103221e-03 1.50000000e-11 CODATA2022
|
||||
muP_Nuc proton magn. moment to nuclear magneton ratio 2.79284735e+00 2.80000000e-08 CODATA2022
|
||||
muP_shield proton magn. shielding correction 2.56890000e-05 1.10000000e-08 CODATA2022
|
||||
muP_n proton-neutron magn. moment ratio -1.45989805e+00 3.40000000e-07 CODATA2022
|
||||
rgH shielded helion gyromagn. ratio 2.03789457e+08 s^-1 T^-1 2.40000000e+00 CODATA2022
|
||||
rgH_2pi shielded helion gyromagn. ratio over 2 pi 3.24341015e+01 MHz T^-1 2.80000000e-06 CODATA2022
|
||||
muH_shield shielded helion magn. moment -1.07455302e-26 J T^-1 9.30000000e-34 CODATA2022
|
||||
muH_shield_Bhor shielded helion magn. moment to Bohr magneton rati -1.15867147e-03 1.40000000e-11 CODATA2022
|
||||
muH_shield_Nuc shielded helion magn. moment to nuclear magneton r -2.12749772e+00 2.50000000e-08 CODATA2022
|
||||
muH_shield_p shielded helion to proton magn. moment ratio -7.61766562e-01 1.20000000e-08 CODATA2022
|
||||
muH_shield_p_shield shielded helion to shielded proton magn. moment ra -7.61786131e-01 3.30000000e-09 CODATA2022
|
||||
muP_shield shielded proton magn. moment 1.41057047e-26 J T^-1 1.20000000e-33 CODATA2022
|
||||
muP_shield_Bhor shielded proton magn. moment to Bohr magneton rati 1.52099313e-03 1.60000000e-11 CODATA2022
|
||||
muP_shield_Nuc shielded proton magn. moment to nuclear magneton r 2.79277560e+00 3.00000000e-08 CODATA2022
|
||||
aSi_220 {220} lattice spacing of silicon 1.92015571e-08 cm 3.20000000e-16 CODATA2022
|
||||
aSi lattice spacing of silicon 1.92015576e-08 cm 5.00000000e-16 CODATA2022
|
||||
mAlpha_e alpha particle-electron mass ratio 7.29429954e+03 2.40000000e-07 CODATA2022
|
||||
mAlpha alpha particle mass 6.64465734e-24 g 2.00000000e-33 CODATA2022
|
||||
EAlpha alpha particle mass energy equivalent 5.97192019e-03 erg 1.80000000e-12 CODATA2022
|
||||
EAlpha_MeV alpha particle mass energy equivalent in MeV 5.97192019e-03 erg 1.76239430e-12 CODATA2022
|
||||
mAlpha_u alpha particle mass in u 6.64465734e-24 g 1.04613961e-34 CODATA2022
|
||||
MAlpha alpha particle molar mass 4.00150618e+00 g / mol 1.20000000e-09 CODATA2022
|
||||
mAlpha_p alpha particle-proton mass ratio 3.97259969e+00 2.20000000e-10 CODATA2022
|
||||
angstromStar Angstrom star 1.00001495e-08 cm 9.00000000e-15 CODATA2022
|
||||
mU atomic mass constant 1.66053907e-24 g 5.00000000e-34 CODATA2022
|
||||
mU_E atomic mass constant energy equivalent 1.49241809e-03 erg 4.50000000e-13 CODATA2022
|
||||
mU_E_MeV atomic mass constant energy equivalent in MeV 1.49241809e-03 erg 4.48609458e-13 CODATA2022
|
||||
mU_eV atomic mass unit-electron volt relationship 1.49241809e-03 erg 4.48609458e-13 CODATA2022
|
||||
mU_hartree atomic mass unit-hartree relationship 3.42317769e+07 E_h 1.00000000e-02 CODATA2022
|
||||
mU_Hz atomic mass unit-hertz relationship 2.25234272e+23 1 / s 6.80000000e+13 CODATA2022
|
||||
mU_invm atomic mass unit-inverse meter relationship 7.51300661e+12 1 / cm 2.30000000e+03 CODATA2022
|
||||
mU_J atomic mass unit-joule relationship 1.49241809e-03 erg 4.50000000e-13 CODATA2022
|
||||
mU_K atomic mass unit-kelvin relationship 1.08095402e+13 K 3.30000000e+03 CODATA2022
|
||||
mU_kg atomic mass unit-kilogram relationship 1.66053907e-24 g 5.00000000e-34 CODATA2022
|
||||
au1Hyper atomic unit of 1st hyperpolarizability 3.20636131e-53 C^3 m^3 J^-2 1.50000000e-62 CODATA2022
|
||||
au2Hyper atomic unit of 2nd hyperpolarizability 6.23537999e-65 C^4 m^4 J^-3 3.80000000e-74 CODATA2022
|
||||
auAct atomic unit of action 1.05457182e-27 erg s 0.00000000e+00 CODATA2022
|
||||
auC atomic unit of charge 1.60217663e-19 C 0.00000000e+00 CODATA2022
|
||||
auCrho atomic unit of charge density 1.08120238e+12 C m^-3 4.90000000e+02 CODATA2022
|
||||
auI atomic unit of current 6.62361824e-03 A 1.30000000e-14 CODATA2022
|
||||
auMu atomic unit of electric dipole mom. 8.47835363e-30 C m 1.30000000e-39 CODATA2022
|
||||
auE atomic unit of electric field 5.14220675e+11 V m^-1 7.80000000e+01 CODATA2022
|
||||
auEFG atomic unit of electric field gradient 9.71736243e+21 V m^-2 2.90000000e+12 CODATA2022
|
||||
auPol atomic unit of electric polarizability 1.64877727e-41 C^2 m^2 J^-1 5.00000000e-51 CODATA2022
|
||||
auV atomic unit of electric potential 2.72113862e+01 V 5.30000000e-11 CODATA2022
|
||||
auQuad atomic unit of electric quadrupole mom. 4.48655152e-40 C m^2 1.40000000e-49 CODATA2022
|
||||
Eh atomic unit of energy 4.35974472e-11 erg 8.50000000e-23 CODATA2022
|
||||
auF atomic unit of force 8.23872350e-03 dyn 1.20000000e-12 CODATA2022
|
||||
auL atomic unit of length 5.29177211e-09 cm 8.00000000e-19 CODATA2022
|
||||
auM atomic unit of mag. dipole mom. 1.85480202e-23 J T^-1 5.60000000e-33 CODATA2022
|
||||
auB atomic unit of mag. flux density 2.35051757e+09 G 7.10000000e-01 CODATA2022
|
||||
auChi atomic unit of magnetizability 7.89103660e-29 J T^-2 4.80000000e-38 CODATA2022
|
||||
amu atomic unit of mass 9.10938370e-28 g 2.80000000e-37 CODATA2022
|
||||
aup atomic unit of momentum 1.99285191e-19 dyn s 3.00000000e-29 CODATA2022
|
||||
auEps atomic unit of permittivity 1.11265006e-10 F m^-1 1.70000000e-20 CODATA2022
|
||||
aut atomic unit of time 2.41888433e-17 s 4.70000000e-29 CODATA2022
|
||||
auv atomic unit of velocity 2.18769126e+08 cm / s 3.30000000e-02 CODATA2022
|
||||
N_a Avogadro constant 6.02214076e+23 1 / mol 0.00000000e+00 CODATA2022
|
||||
mu_B Bohr magneton 9.27401008e-24 J T^-1 2.80000000e-33 CODATA2022
|
||||
mu_B_eV_T Bohr magneton in eV/T 5.78838181e-05 eV T^-1 1.70000000e-14 CODATA2022
|
||||
mu_B_Hz_T Bohr magneton in Hz/T 1.39962449e+10 Hz T^-1 4.20000000e+00 CODATA2022
|
||||
mu_B__mT Bohr magneton in inverse meters per tesla 4.66864481e+01 m^-1 T^-1 2.90000000e-07 CODATA2022
|
||||
muB_K_T Bohr magneton in K/T 6.71713816e-01 K T^-1 2.00000000e-10 CODATA2022
|
||||
rBhor Bohr radius 5.29177211e-09 cm 8.00000000e-19 CODATA2022
|
||||
kB Boltzmann constant 1.38064900e-16 erg / K 0.00000000e+00 CODATA2022
|
||||
kB_eV_K Boltzmann constant in eV/K 1.38064900e-16 erg / K 0.00000000e+00 CODATA2022
|
||||
kB_Hz_K Boltzmann constant in Hz/K 2.08366191e+10 1 / (K s) 0.00000000e+00 CODATA2022
|
||||
kB__MK Boltzmann constant in inverse meters per kelvin 6.95034570e-01 1 / (K cm) 4.00000000e-07 CODATA2022
|
||||
Z0 characteristic impedance of vacuum 3.76730314e+02 ohm 5.61366546e-08 CODATA2022
|
||||
re classical electron radius 2.81794033e-13 cm 1.30000000e-22 CODATA2022
|
||||
lambda_compt Compton wavelength 2.42631024e-10 cm 7.30000000e-20 CODATA2022
|
||||
lambda_compt_2pi Compton wavelength over 2 pi 3.86159268e-11 cm 1.80000000e-20 CODATA2022
|
||||
G0 conductance quantum 7.74809173e-05 S 0.00000000e+00 CODATA2022
|
||||
K_J-90 conventional value of Josephson constant 4.83597900e+14 Hz V^-1 0.00000000e+00 CODATA2022
|
||||
R_K-90 conventional value of von Klitzing constant 2.58128070e+04 ohm 0.00000000e+00 CODATA2022
|
||||
xu(CuKa1) Cu x unit 1.00207697e-11 cm 2.80000000e-18 CODATA2022
|
||||
muD_e deuteron-electron mag. mom. ratio -4.66434555e-04 1.20000000e-12 CODATA2022
|
||||
mD_e deuteron-electron mass ratio 3.67048297e+03 1.30000000e-07 CODATA2022
|
||||
g_D deuteron g factor 8.57438234e-01 2.20000000e-09 CODATA2022
|
||||
muD deuteron mag. mom. 4.33073509e-27 J T^-1 1.10000000e-35 CODATA2022
|
||||
muD_Bhor deuteron mag. mom. to Bohr magneton ratio 4.66975457e-04 1.20000000e-12 CODATA2022
|
||||
muD_Nuc deuteron mag. mom. to nuclear magneton ratio 8.57438234e-01 2.20000000e-09 CODATA2022
|
||||
mD deuteron mass 3.34358377e-24 g 1.00000000e-33 CODATA2022
|
||||
mD_E deuteron mass energy equivalent 3.00506323e-03 erg 9.10000000e-13 CODATA2022
|
||||
mD_E_MeV deuteron mass energy equivalent in MeV 3.00506323e-03 erg 9.13240681e-13 CODATA2022
|
||||
mD_u deuteron mass in u 3.34358377e-24 g 6.64215627e-35 CODATA2022
|
||||
MD deuteron molar mass 2.01355321e+00 g / mol 6.10000000e-10 CODATA2022
|
||||
muD_n deuteron-neutron mag. mom. ratio -4.48206530e-01 1.10000000e-07 CODATA2022
|
||||
muD_p deuteron-proton mag. mom. ratio 3.07012209e-01 7.90000000e-10 CODATA2022
|
||||
mD_p deuteron-proton mass ratio 1.99900750e+00 1.10000000e-10 CODATA2022
|
||||
RrmsD deuteron rms charge radius 2.12799000e-13 cm 7.40000000e-17 CODATA2022
|
||||
eps_0 electric constant 8.85418781e-12 F m^-1 1.30000000e-21 CODATA2022
|
||||
qE_m electron charge to mass quotient -1.75882001e+11 C kg^-1 5.30000000e+01 CODATA2022
|
||||
muE_D electron-deuteron mag. mom. ratio -2.14392349e+03 5.60000000e-06 CODATA2022
|
||||
mE_D electron-deuteron mass ratio 2.72443711e-04 9.60000000e-15 CODATA2022
|
||||
g_e electron g factor -2.00231930e+00 3.50000000e-13 CODATA2022
|
||||
rg_e electron gyromag. ratio 1.76085963e+11 s^-1 T^-1 5.30000000e+01 CODATA2022
|
||||
rg_e_2pi electron gyromag. ratio over 2 pi 2.80249516e+04 MHz T^-1 1.70000000e-04 CODATA2022
|
||||
muE electron mag. mom. -9.28476470e-24 J T^-1 2.80000000e-33 CODATA2022
|
||||
muE_anom electron mag. mom. anomaly 1.15965218e-03 1.80000000e-13 CODATA2022
|
||||
muE_Bhor electron mag. mom. to Bohr magneton ratio -1.00115965e+00 1.80000000e-13 CODATA2022
|
||||
muE_Nuc electron mag. mom. to nuclear magneton ratio -1.83828197e+03 1.10000000e-07 CODATA2022
|
||||
mE electron mass 9.10938370e-28 g 2.80000000e-37 CODATA2022
|
||||
mE_E electron mass energy equivalent 8.18710578e-07 erg 2.50000000e-16 CODATA2022
|
||||
mE_MeV electron mass energy equivalent in MeV 8.18710578e-07 erg 2.40326495e-16 CODATA2022
|
||||
mE_u electron mass in u 9.10938370e-28 g 2.65686251e-38 CODATA2022
|
||||
ME electron molar mass 5.48579909e-04 g / mol 1.70000000e-13 CODATA2022
|
||||
muE_mu electron-muon mag. mom. ratio 2.06766988e+02 4.60000000e-06 CODATA2022
|
||||
mE_mu electron-muon mass ratio 4.83633169e-03 1.10000000e-10 CODATA2022
|
||||
muE_n electron-neutron mag. mom. ratio 9.60920500e+02 2.30000000e-04 CODATA2022
|
||||
mE_n electron-neutron mass ratio 5.43867344e-04 2.60000000e-13 CODATA2022
|
||||
muE_p electron-proton mag. mom. ratio -6.58210688e+02 2.00000000e-07 CODATA2022
|
||||
mE_p electron-proton mass ratio 5.44617021e-04 3.30000000e-14 CODATA2022
|
||||
mE_tau electron-tau mass ratio 2.87585000e-04 1.90000000e-08 CODATA2022
|
||||
mE_alpha electron to alpha particle mass ratio 1.37093355e-04 4.50000000e-15 CODATA2022
|
||||
muE_H_shield electron to shielded helion mag. mom. ratio 8.64058257e+02 1.00000000e-05 CODATA2022
|
||||
muE_p_shield electron to shielded proton mag. mom. ratio -6.58227597e+02 7.20000000e-06 CODATA2022
|
||||
eV electron volt 1.60217663e-12 erg 0.00000000e+00 CODATA2022
|
||||
eV_amu electron volt-atomic mass unit relationship 1.78266192e-33 g 5.31372501e-43 CODATA2022
|
||||
eV_hartree electron volt-hartree relationship 3.67493222e-02 E_h 7.10000000e-14 CODATA2022
|
||||
eV_Hz electron volt-hertz relationship 2.41798924e+14 1 / s 0.00000000e+00 CODATA2022
|
||||
eV_invm electron volt-inverse meter relationship 8.06554394e+03 1 / cm 0.00000000e+00 CODATA2022
|
||||
eV_J electron volt-joule relationship 1.60217663e-12 erg 0.00000000e+00 CODATA2022
|
||||
eV_K electron volt-kelvin relationship 1.16045181e+04 K 0.00000000e+00 CODATA2022
|
||||
eV_kg electron volt-kilogram relationship 1.78266192e-33 g 0.00000000e+00 CODATA2022
|
||||
e elementary charge 1.60217663e-19 C 0.00000000e+00 CODATA2022
|
||||
e_h elementary charge over h 2.41798926e+14 A J^-1 1.50000000e+06 CODATA2022
|
||||
F Faraday constant 9.64853321e+04 C mol^-1 0.00000000e+00 CODATA2022
|
||||
F_conv Faraday constant for conventional electric current 9.64853251e+04 C_90 mol^-1 1.20000000e-03 CODATA2022
|
||||
G_F Fermi coupling constant 4.54379566e+00 s4 / (g2 cm4) 2.33738613e-06 CODATA2022
|
||||
alpha fine-structure constant 7.29735257e-03 1.10000000e-12 CODATA2022
|
||||
c1 first radiation constant 3.74177185e-05 St erg 0.00000000e+00 CODATA2022
|
||||
c1L first radiation constant for spectral radiance 1.19104297e-05 St erg / rad2 0.00000000e+00 CODATA2022
|
||||
Eh_amu hartree-atomic mass unit relationship 4.85087021e-32 g 1.46127438e-41 CODATA2022
|
||||
Eh_eV hartree-electron volt relationship 4.35974472e-11 erg 8.49153616e-23 CODATA2022
|
||||
Eh Hartree energy 4.35974472e-11 erg 8.50000000e-23 CODATA2022
|
||||
Eh_E_eV Hartree energy in eV 4.35974472e-11 erg 8.49153616e-23 CODATA2022
|
||||
Eh_Hz hartree-hertz relationship 6.57968392e+15 1 / s 1.30000000e+04 CODATA2022
|
||||
Eh_invm hartree-inverse meter relationship 2.19474631e+05 1 / cm 4.30000000e-07 CODATA2022
|
||||
Eh_J hartree-joule relationship 4.35974472e-11 erg 8.50000000e-23 CODATA2022
|
||||
Eh_K hartree-kelvin relationship 3.15775025e+05 K 6.10000000e-07 CODATA2022
|
||||
Eh_kg hartree-kilogram relationship 4.85087021e-32 g 9.40000000e-44 CODATA2022
|
||||
mH_e helion-electron mass ratio 5.49588528e+03 2.40000000e-07 CODATA2022
|
||||
mH helion mass 5.00641278e-24 g 1.50000000e-33 CODATA2022
|
||||
mH_E helion mass energy equivalent 4.49953941e-03 erg 1.40000000e-12 CODATA2022
|
||||
mH_E_eV helion mass energy equivalent in MeV 4.49953941e-03 erg 1.36185014e-12 CODATA2022
|
||||
mH_u helion mass in u 5.00641278e-24 g 1.61072289e-34 CODATA2022
|
||||
MH helion molar mass 3.01493225e+00 g / mol 9.10000000e-10 CODATA2022
|
||||
mH_p helion-proton mass ratio 2.99315267e+00 1.30000000e-10 CODATA2022
|
||||
Hz_amu hertz-atomic mass unit relationship 7.37249732e-48 g 2.15870079e-57 CODATA2022
|
||||
Hz_eV hertz-electron volt relationship 6.62607015e-27 erg 0.00000000e+00 CODATA2022
|
||||
Hz_Eh hertz-hartree relationship 1.51982985e-16 E_h 2.90000000e-28 CODATA2022
|
||||
Hz_invm hertz-inverse meter relationship 3.33564095e-11 1 / cm 0.00000000e+00 CODATA2022
|
||||
Hz_J hertz-joule relationship 6.62607015e-27 erg 0.00000000e+00 CODATA2022
|
||||
Hz_K hertz-kelvin relationship 4.79924307e-11 K 0.00000000e+00 CODATA2022
|
||||
Hz_kg hertz-kilogram relationship 7.37249732e-48 g 0.00000000e+00 CODATA2022
|
||||
invalpha inverse fine-structure constant 1.37035999e+02 2.10000000e-08 CODATA2022
|
||||
invm_amu inverse meter-atomic mass unit relationship 2.21021909e-39 g 6.64215627e-49 CODATA2022
|
||||
invm_eV inverse meter-electron volt relationship 1.98644586e-18 erg 0.00000000e+00 CODATA2022
|
||||
invm_Eh inverse meter-hartree relationship 4.55633525e-08 E_h 8.80000000e-20 CODATA2022
|
||||
invm_Hz inverse meter-hertz relationship 2.99792458e+08 1 / s 0.00000000e+00 CODATA2022
|
||||
invm_J inverse meter-joule relationship 1.98644586e-18 erg 0.00000000e+00 CODATA2022
|
||||
invm_K inverse meter-kelvin relationship 1.43877688e-02 K 0.00000000e+00 CODATA2022
|
||||
invm_kg inverse meter-kilogram relationship 2.21021909e-39 g 0.00000000e+00 CODATA2022
|
||||
invG0 inverse of conductance quantum 1.29064037e+04 ohm 0.00000000e+00 CODATA2022
|
||||
K_J Josephson constant 4.83597848e+14 Hz V^-1 0.00000000e+00 CODATA2022
|
||||
J_amu joule-atomic mass unit relationship 1.11265006e-14 g 3.32107813e-24 CODATA2022
|
||||
J_eV joule-electron volt relationship 1.00000000e+07 erg 0.00000000e+00 CODATA2022
|
||||
J_Eh joule-hartree relationship 2.29371228e+17 E_h 4.50000000e+05 CODATA2022
|
||||
J_Hz joule-hertz relationship 1.50919018e+33 1 / s 0.00000000e+00 CODATA2022
|
||||
J_invm joule-inverse meter relationship 5.03411657e+22 1 / cm 0.00000000e+00 CODATA2022
|
||||
J_K joule-kelvin relationship 7.24297052e+22 K 0.00000000e+00 CODATA2022
|
||||
J_kg joule-kilogram relationship 1.11265006e-14 g 0.00000000e+00 CODATA2022
|
||||
K_amu kelvin-atomic mass unit relationship 1.53617919e-37 g 4.64950939e-47 CODATA2022
|
||||
K_eV kelvin-electron volt relationship 1.38064900e-16 erg 0.00000000e+00 CODATA2022
|
||||
K_Eh kelvin-hartree relationship 3.16681156e-06 E_h 6.10000000e-18 CODATA2022
|
||||
K_Hz kelvin-hertz relationship 2.08366191e+10 1 / s 0.00000000e+00 CODATA2022
|
||||
K_invm kelvin-inverse meter relationship 6.95034800e-01 1 / cm 0.00000000e+00 CODATA2022
|
||||
K_J kelvin-joule relationship 1.38064900e-16 erg 0.00000000e+00 CODATA2022
|
||||
K_kg kelvin-kilogram relationship 1.53617919e-37 g 0.00000000e+00 CODATA2022
|
||||
kg_amu kilogram-atomic mass unit relationship 1.00000000e+03 g 2.98897032e-07 CODATA2022
|
||||
kg_eV kilogram-electron volt relationship 8.98755179e+23 erg 0.00000000e+00 CODATA2022
|
||||
kg_Eh kilogram-hartree relationship 2.06148579e+34 E_h 4.00000000e+22 CODATA2022
|
||||
kg_Hz kilogram-hertz relationship 1.35639249e+50 1 / s 0.00000000e+00 CODATA2022
|
||||
kg_invm kilogram-inverse meter relationship 4.52443833e+39 1 / cm 0.00000000e+00 CODATA2022
|
||||
kg_J kilogram-joule relationship 8.98755179e+23 erg 0.00000000e+00 CODATA2022
|
||||
kg_K kilogram-kelvin relationship 6.50965726e+39 K 0.00000000e+00 CODATA2022
|
||||
aSi lattice parameter of silicon 5.43102051e-08 cm 8.90000000e-16 CODATA2022
|
||||
n0 Loschmidt constant (273.15 K, 101.325 kPa) 2.68678011e+19 1 / cm3 0.00000000e+00 CODATA2022
|
||||
mu0 mag. constant 1.25663706e-06 N A^-2 1.90000000e-16 CODATA2022
|
||||
Phi0 mag. flux quantum 2.06783385e-15 Wb 0.00000000e+00 CODATA2022
|
||||
R molar gas constant 8.31446262e+07 erg / (K mol) 0.00000000e+00 CODATA2022
|
||||
Mu molar mass constant 1.00000000e+00 g / mol 3.00000000e-10 CODATA2022
|
||||
MC12 molar mass of carbon-12 1.20000000e+01 g / mol 3.60000000e-09 CODATA2022
|
||||
h_mol molar Planck constant 3.99031271e-03 St g / mol 0.00000000e+00 CODATA2022
|
||||
ch_mol molar Planck constant times c 1.19626566e+08 cm erg / mol 5.40000000e-02 CODATA2022
|
||||
v_mol_ideal_100kPa molar volume of ideal gas (273.15 K, 100 kPa) 2.27109546e+04 cm3 / mol 0.00000000e+00 CODATA2022
|
||||
v_mol_ideal_101.325kPa molar volume of ideal gas (273.15 K, 101.325 kPa) 2.24139695e+04 cm3 / mol 0.00000000e+00 CODATA2022
|
||||
vSI_mol molar volume of silicon 1.20588320e+01 cm3 / mol 6.00000000e-07 CODATA2022
|
||||
xu Mo x unit 1.00209952e-11 cm 5.30000000e-18 CODATA2022
|
||||
lambda_compt_mu muon Compton wavelength 1.17344411e-12 cm 2.60000000e-20 CODATA2022
|
||||
lambda_compt_mu_2pi muon Compton wavelength over 2 pi 1.86759431e-13 cm 4.20000000e-21 CODATA2022
|
||||
mMu_e muon-electron mass ratio 2.06768283e+02 4.60000000e-06 CODATA2022
|
||||
g_mu muon g factor -2.00233184e+00 1.30000000e-09 CODATA2022
|
||||
muMu muon mag. mom. -4.49044830e-26 J T^-1 1.00000000e-33 CODATA2022
|
||||
muMu_anom muon mag. mom. anomaly 1.16592089e-03 6.30000000e-10 CODATA2022
|
||||
muMu_Bhor muon mag. mom. to Bohr magneton ratio -4.84197047e-03 1.10000000e-10 CODATA2022
|
||||
muMu_Nuc muon mag. mom. to nuclear magneton ratio -8.89059703e+00 2.00000000e-07 CODATA2022
|
||||
mMu muon mass 1.88353163e-25 g 4.20000000e-33 CODATA2022
|
||||
mMu_E muon mass energy equivalent 1.69283380e-04 erg 3.80000000e-12 CODATA2022
|
||||
mMu_E_MeV muon mass energy equivalent in MeV 1.69283380e-04 erg 3.68500626e-12 CODATA2022
|
||||
mMu_E_u muon mass in u 1.88353163e-25 g 4.15134767e-33 CODATA2022
|
||||
MMu muon molar mass 1.13428926e-01 g / mol 2.50000000e-09 CODATA2022
|
||||
mMu_n muon-neutron mass ratio 1.12454517e-01 2.50000000e-09 CODATA2022
|
||||
muMu_p muon-proton mag. mom. ratio -3.18334514e+00 7.10000000e-08 CODATA2022
|
||||
mMu_p muon-proton mass ratio 1.12609526e-01 2.50000000e-09 CODATA2022
|
||||
mMu_tau muon-tau mass ratio 5.94635000e-02 4.00000000e-06 CODATA2022
|
||||
1 natural unit of action 1.05457182e-27 erg s 0.00000000e+00 CODATA2022
|
||||
1_eV_s natural unit of action in eV s 1.05457182e-27 erg s 0.00000000e+00 CODATA2022
|
||||
E natural unit of energy 8.18710578e-07 erg 2.50000000e-16 CODATA2022
|
||||
E_MeV natural unit of energy in MeV 8.18710578e-07 erg 2.40326495e-16 CODATA2022
|
||||
L natural unit of length 3.86159268e-11 cm 1.20000000e-20 CODATA2022
|
||||
M natural unit of mass 9.10938370e-28 g 2.80000000e-37 CODATA2022
|
||||
p natural unit of momentum 2.73092449e-17 dyn s 3.40000000e-25 CODATA2022
|
||||
p_MeV_c natural unit of momentum in MeV/c 5.10998946e-01 MeV/c 3.10000000e-09 CODATA2022
|
||||
t natural unit of time 1.28808867e-21 s 3.90000000e-31 CODATA2022
|
||||
v natural unit of velocity 2.99792458e+10 cm / s 0.00000000e+00 CODATA2022
|
||||
lambda_compt_n neutron Compton wavelength 1.31959091e-13 cm 7.50000000e-23 CODATA2022
|
||||
lambda_compt_n_2pi neutron Compton wavelength over 2 pi 2.10019415e-14 cm 1.40000000e-23 CODATA2022
|
||||
muN_e neutron-electron mag. mom. ratio 1.04066882e-03 2.50000000e-10 CODATA2022
|
||||
mN_e neutron-electron mass ratio 1.83868366e+03 8.90000000e-07 CODATA2022
|
||||
g_n neutron g factor -3.82608545e+00 9.00000000e-07 CODATA2022
|
||||
rg_n neutron gyromag. ratio 1.83247171e+08 s^-1 T^-1 4.30000000e+01 CODATA2022
|
||||
rg_n_2pi neutron gyromag. ratio over 2 pi 2.91646933e+01 MHz T^-1 6.90000000e-06 CODATA2022
|
||||
muN neutron mag. mom. -9.66236510e-27 J T^-1 2.30000000e-33 CODATA2022
|
||||
muN_Bhor neutron mag. mom. to Bohr magneton ratio -1.04187563e-03 2.50000000e-10 CODATA2022
|
||||
muN_Nuc neutron mag. mom. to nuclear magneton ratio -1.91304273e+00 4.50000000e-07 CODATA2022
|
||||
mN neutron mass 1.67492750e-24 g 9.50000000e-34 CODATA2022
|
||||
mN_E neutron mass energy equivalent 1.50534976e-03 erg 8.60000000e-13 CODATA2022
|
||||
mN_E_MeV neutron mass energy equivalent in MeV 1.50534976e-03 erg 8.65175382e-13 CODATA2022
|
||||
mN_u neutron mass in u 1.67492750e-24 g 8.13664143e-34 CODATA2022
|
||||
MN neutron molar mass 1.00866492e+00 g / mol 5.70000000e-10 CODATA2022
|
||||
mN_mu neutron-muon mass ratio 8.89248406e+00 2.00000000e-07 CODATA2022
|
||||
muN_p neutron-proton mag. mom. ratio -6.84979340e-01 1.60000000e-07 CODATA2022
|
||||
mN_p neutron-proton mass ratio 1.00137842e+00 4.90000000e-10 CODATA2022
|
||||
mN_tau neutron-tau mass ratio 5.28779000e-01 3.60000000e-05 CODATA2022
|
||||
muN_p_shield neutron to shielded proton mag. mom. ratio -6.84996940e-01 1.60000000e-07 CODATA2022
|
||||
G Newtonian constant of gravitation 6.67430000e-08 cm3 / (g s2) 1.50000000e-12 CODATA2022
|
||||
G_hbar_c Newtonian constant of gravitation over h-bar c 6.70883000e-39 (GeV/c^2)^-2 1.50000000e-43 CODATA2022
|
||||
mu_N nuclear magneton 5.05078375e-27 J T^-1 1.50000000e-36 CODATA2022
|
||||
mu_N_eV_T nuclear magneton in eV/T 3.15245126e-08 eV T^-1 9.60000000e-18 CODATA2022
|
||||
mu_N_invm_T nuclear magneton in inverse meters per tesla 2.54262343e-02 m^-1 T^-1 1.60000000e-10 CODATA2022
|
||||
mu_N_K_T nuclear magneton in K/T 3.65826778e-04 K T^-1 1.10000000e-13 CODATA2022
|
||||
mu_N_MHz_T nuclear magneton in MHz/T 7.62259323e+00 MHz T^-1 2.30000000e-09 CODATA2022
|
||||
h Planck constant 6.62607015e-27 erg s 0.00000000e+00 CODATA2022
|
||||
h_eV_s Planck constant in eV s 6.62607009e-27 erg s 4.00544159e-35 CODATA2022
|
||||
hbar Planck constant over 2 pi 1.05457180e-27 erg s 1.30000000e-35 CODATA2022
|
||||
hbar_eV_s Planck constant over 2 pi in eV s 1.05457181e-27 erg s 6.40870654e-36 CODATA2022
|
||||
chbar_MeV Planck constant over 2 pi times c in MeV fm 3.16152675e-17 cm erg 1.92261196e-25 CODATA2022
|
||||
planck_length Planck length 1.61625500e-33 cm 1.80000000e-38 CODATA2022
|
||||
planck_mass Planck mass 2.17643400e-05 g 2.40000000e-10 CODATA2022
|
||||
planck_mass_E_GeV Planck mass energy equivalent in GeV 1.95608143e+16 erg 2.24304729e+11 CODATA2022
|
||||
planck_temp Planck temperature 1.41678400e+32 K 1.60000000e+27 CODATA2022
|
||||
plank_time Planck time 5.39124700e-44 s 6.00000000e-49 CODATA2022
|
||||
qP_mP proton charge to mass quotient 9.57883316e+07 C kg^-1 2.90000000e-02 CODATA2022
|
||||
lambda_compt_p proton Compton wavelength 1.32140986e-13 cm 4.00000000e-23 CODATA2022
|
||||
lambda_compt_p_2pi proton Compton wavelength over 2 pi 2.10308910e-14 cm 9.70000000e-24 CODATA2022
|
||||
mP_e proton-electron mass ratio 1.83615267e+03 1.10000000e-07 CODATA2022
|
||||
g_p proton g factor 5.58569469e+00 1.60000000e-09 CODATA2022
|
||||
rg_p proton gyromag. ratio 2.67522187e+08 s^-1 T^-1 1.10000000e-01 CODATA2022
|
||||
rg_p_2pi proton gyromag. ratio over 2 pi 4.25774789e+01 MHz T^-1 2.90000000e-07 CODATA2022
|
||||
muP proton mag. mom. 1.41060680e-26 J T^-1 6.00000000e-36 CODATA2022
|
||||
muP_Bhor proton mag. mom. to Bohr magneton ratio 1.52103220e-03 4.60000000e-13 CODATA2022
|
||||
muP_Nuc proton mag. mom. to nuclear magneton ratio 2.79284734e+00 8.20000000e-10 CODATA2022
|
||||
muP_shield proton mag. shielding correction 2.56890000e-05 1.10000000e-08 CODATA2022
|
||||
mP proton mass 1.67262192e-24 g 5.10000000e-34 CODATA2022
|
||||
mP_E proton mass energy equivalent 1.50327762e-03 erg 4.60000000e-13 CODATA2022
|
||||
mP_E_MeV proton mass energy equivalent in MeV 1.50327762e-03 erg 4.64631224e-13 CODATA2022
|
||||
mP_u proton mass in u 1.67262192e-24 g 8.80085705e-35 CODATA2022
|
||||
MP proton molar mass 1.00727647e+00 g / mol 3.10000000e-10 CODATA2022
|
||||
mP_mu proton-muon mass ratio 8.88024337e+00 2.00000000e-07 CODATA2022
|
||||
muP_n proton-neutron mag. mom. ratio -1.45989805e+00 3.40000000e-07 CODATA2022
|
||||
mP_n proton-neutron mass ratio 9.98623478e-01 4.90000000e-10 CODATA2022
|
||||
RrmsP proton rms charge radius 8.41400000e-14 cm 1.90000000e-16 CODATA2022
|
||||
mP_tau proton-tau mass ratio 5.28051000e-01 3.60000000e-05 CODATA2022
|
||||
kappa quantum of circulation 3.63694755e+00 cm2 / s 1.10000000e-09 CODATA2022
|
||||
2kappa quantum of circulation times 2 7.27389510e+00 cm2 / s 2.20000000e-09 CODATA2022
|
||||
Rinf Rydberg constant 1.09737316e+05 1 / cm 2.10000000e-07 CODATA2022
|
||||
cRinf_Hz Rydberg constant times c in Hz 3.28984196e+15 1 / s 6.40000000e+03 CODATA2022
|
||||
hcRinf_eV Rydberg constant times hc in eV 2.17987236e-11 erg 4.16565925e-23 CODATA2022
|
||||
hcRinf_J Rydberg constant times hc in J 2.17987236e-11 erg 4.20000000e-23 CODATA2022
|
||||
S0_R_100kPa Sackur-Tetrode constant (1 K, 100 kPa) -1.15170754e+00 4.50000000e-10 CODATA2022
|
||||
S0_R_101.325kPa Sackur-Tetrode constant (1 K, 101.325 kPa) -1.16487052e+00 4.50000000e-10 CODATA2022
|
||||
c2 second radiation constant 1.43877688e+00 K cm 0.00000000e+00 CODATA2022
|
||||
rg_h_shield shielded helion gyromag. ratio 2.03789457e+08 s^-1 T^-1 2.40000000e+00 CODATA2022
|
||||
rg_h_shield_2pi shielded helion gyromag. ratio over 2 pi 3.24340997e+01 MHz T^-1 4.30000000e-07 CODATA2022
|
||||
muH_shield shielded helion mag. mom. -1.07455309e-26 J T^-1 1.30000000e-34 CODATA2022
|
||||
muH_shield_Bhor shielded helion mag. mom. to Bohr magneton ratio -1.15867147e-03 1.40000000e-11 CODATA2022
|
||||
muH_shield_Nuc shielded helion mag. mom. to nuclear magneton rati -2.12749772e+00 2.50000000e-08 CODATA2022
|
||||
muH_shield_p shielded helion to proton mag. mom. ratio -7.61766562e-01 8.90000000e-09 CODATA2022
|
||||
muH_shield_p_shield shielded helion to shielded proton mag. mom. ratio -7.61786131e-01 3.30000000e-09 CODATA2022
|
||||
rg_p_shield shielded proton gyromag. ratio 2.67515315e+08 s^-1 T^-1 2.90000000e+00 CODATA2022
|
||||
rg_p_shield_2pi shielded proton gyromag. ratio over 2 pi 4.25763851e+01 MHz T^-1 5.30000000e-07 CODATA2022
|
||||
muP_shield shielded proton mag. mom. 1.41057056e-26 J T^-1 1.50000000e-34 CODATA2022
|
||||
muP_shield_Bhor shielded proton mag. mom. to Bohr magneton ratio 1.52099313e-03 1.70000000e-11 CODATA2022
|
||||
muP_shield_Nuc shielded proton mag. mom. to nuclear magneton rati 2.79277560e+00 3.00000000e-08 CODATA2022
|
||||
c speed of light in vacuum 2.99792458e+10 cm / s 0.00000000e+00 CODATA2022
|
||||
g standard acceleration of gravity 9.80665000e+02 cm / s2 0.00000000e+00 CODATA2022
|
||||
atm standard atmosphere 1.01325000e+06 P / s 0.00000000e+00 CODATA2022
|
||||
sigma Stefan-Boltzmann constant 5.67037442e-05 g / (s3 K4) 0.00000000e+00 CODATA2022
|
||||
lambda_compt_tau tau Compton wavelength 6.97771000e-14 cm 4.70000000e-18 CODATA2022
|
||||
lambda_compt_tau_2pi tau Compton wavelength over 2 pi 1.11056000e-14 cm 1.00000000e-18 CODATA2022
|
||||
mTau_e tau-electron mass ratio 3.47723000e+03 2.30000000e-01 CODATA2022
|
||||
mTau tau mass 3.16754000e-24 g 2.10000000e-28 CODATA2022
|
||||
mTau_E tau mass energy equivalent 2.84684000e-03 erg 1.90000000e-07 CODATA2022
|
||||
mTau_E_MeV tau mass energy equivalent in MeV 2.84677949e-03 erg 2.56348261e-07 CODATA2022
|
||||
mTau_u tau mass in u 3.16754469e-24 g 2.15870079e-28 CODATA2022
|
||||
MTau tau molar mass 1.90754000e+00 g / mol 1.30000000e-04 CODATA2022
|
||||
mTau_mu tau-muon mass ratio 1.68170000e+01 1.10000000e-03 CODATA2022
|
||||
mTau_n tau-neutron mass ratio 1.89115000e+00 1.30000000e-04 CODATA2022
|
||||
mTau_p tau-proton mass ratio 1.89376000e+00 1.30000000e-04 CODATA2022
|
||||
sigma_T Thomson cross section 6.65245873e-25 cm2 6.00000000e-34 CODATA2022
|
||||
muPsi_e triton-electron mag. mom. ratio -1.62051442e-03 2.10000000e-11 CODATA2022
|
||||
mPsi_e triton-electron mass ratio 5.49692154e+03 2.70000000e-07 CODATA2022
|
||||
g_psi triton g factor 5.95792493e+00 1.20000000e-08 CODATA2022
|
||||
muPsi triton mag. mom. 1.50460952e-26 J T^-1 3.00000000e-35 CODATA2022
|
||||
muPsi_Bhor triton mag. mom. to Bohr magneton ratio 1.62239367e-03 3.20000000e-12 CODATA2022
|
||||
muPsi_Nuc triton mag. mom. to nuclear magneton ratio 2.97896247e+00 5.90000000e-09 CODATA2022
|
||||
mPsi triton mass 5.00735674e-24 g 1.50000000e-33 CODATA2022
|
||||
mPsi_E triton mass energy equivalent 4.50038781e-03 erg 1.40000000e-12 CODATA2022
|
||||
mPsi_E_MeV triton mass energy equivalent in MeV 4.50038781e-03 erg 1.36185014e-12 CODATA2022
|
||||
mPsi_u triton mass in u 5.00735674e-24 g 1.99264688e-34 CODATA2022
|
||||
MPsi triton molar mass 3.01550072e+00 g / mol 9.20000000e-10 CODATA2022
|
||||
muPsi_n triton-neutron mag. mom. ratio -1.55718553e+00 3.70000000e-07 CODATA2022
|
||||
muPsi_p triton-proton mag. mom. ratio 1.06663991e+00 1.00000000e-08 CODATA2022
|
||||
mPsi_p triton-proton mass ratio 2.99371703e+00 1.50000000e-10 CODATA2022
|
||||
u unified atomic mass unit 1.66053907e-24 g 5.00000000e-34 CODATA2022
|
||||
R_K von Klitzing constant 2.58128075e+04 ohm 0.00000000e+00 CODATA2022
|
||||
theta_W weak mixing angle 2.22900000e-01 3.00000000e-04 CODATA2022
|
||||
b_freq Wien frequency displacement law constant 5.87892576e+10 1 / (K s) 0.00000000e+00 CODATA2022
|
||||
b_lambda Wien wavelength displacement law constant 2.89777196e-01 K cm 0.00000000e+00 CODATA2022
|
||||
auMom_um atomic unit of mom.um 1.99285188e-19 dyn s 2.40000000e-27 CODATA2022
|
||||
mE_h electron-helion mass ratio 1.81954307e-04 7.90000000e-15 CODATA2022
|
||||
mE_psi electron-triton mass ratio 1.81920006e-04 9.00000000e-15 CODATA2022
|
||||
g_h helion g factor -4.25525061e+00 5.00000000e-08 CODATA2022
|
||||
muH helion mag. mom. -1.07461753e-26 J T^-1 1.30000000e-34 CODATA2022
|
||||
muH_Bhor helion mag. mom. to Bohr magneton ratio -1.15874096e-03 1.40000000e-11 CODATA2022
|
||||
muH_Nuc helion mag. mom. to nuclear magneton ratio -2.12762531e+00 2.50000000e-08 CODATA2022
|
||||
n0 Loschmidt constant (273.15 K, 100 kPa) 2.65164580e+19 1 / cm3 0.00000000e+00 CODATA2022
|
||||
p_um natural unit of mom.um 2.73092449e-17 dyn s 3.40000000e-25 CODATA2022
|
||||
p_um_MeV_c natural unit of mom.um in MeV/c 5.10998946e-01 MeV/c 3.10000000e-09 CODATA2022
|
||||
mN-mP neutron-proton mass difference 2.30557435e-27 g 8.20000000e-34 CODATA2022
|
||||
mN-mP_E neutron-proton mass difference energy equivalent 2.07214689e-06 erg 7.40000000e-13 CODATA2022
|
||||
mN-mP_E_MeV neutron-proton mass difference energy equivalent i 2.07214689e-06 erg 7.37001252e-13 CODATA2022
|
||||
mN-mP_u neutron-proton mass difference in u 2.30557435e-27 g 8.13664143e-34 CODATA2022
|
||||
stp standard-state pressure 1.00000000e+06 P / s 0.00000000e+00 CODATA2022
|
||||
mAlpha alpha particle relative atomic mass 4.00150618e+00 6.30000000e-11 CODATA2022
|
||||
muB_invm_T Bohr magneton in inverse meter per tesla 4.66864478e+01 m^-1 T^-1 1.40000000e-08 CODATA2022
|
||||
kB_invm Boltzmann constant in inverse meter per kelvin 6.95034800e-01 1 / (K cm) 0.00000000e+00 CODATA2022
|
||||
ampere-90 conventional value of ampere-90 1.00000009e+00 A 0.00000000e+00 CODATA2022
|
||||
coulomb-90 conventional value of coulomb-90 1.00000009e+00 C 0.00000000e+00 CODATA2022
|
||||
farad-90 conventional value of farad-90 9.99999982e-01 F 0.00000000e+00 CODATA2022
|
||||
henry-90 conventional value of henry-90 1.00000002e+00 H 0.00000000e+00 CODATA2022
|
||||
ohm-90 conventional value of ohm-90 1.00000002e+00 ohm 0.00000000e+00 CODATA2022
|
||||
volt-90 conventional value of volt-90 1.00000011e+00 V 0.00000000e+00 CODATA2022
|
||||
watt-90 conventional value of watt-90 1.00000020e+07 erg / s 0.00000000e+00 CODATA2022
|
||||
mD_amu_rel deuteron relative atomic mass 2.01355321e+00 4.00000000e-11 CODATA2022
|
||||
rg_e_MHz_T electron gyromag. ratio in MHz/T 2.80249514e+04 MHz T^-1 8.50000000e-06 CODATA2022
|
||||
mE_amu_rel electron relative atomic mass 5.48579909e-04 1.60000000e-14 CODATA2022
|
||||
e_hbar elementary charge over h-bar 1.51926745e+15 A J^-1 0.00000000e+00 CODATA2022
|
||||
mH_amu_rel helion relative atomic mass 3.01493225e+00 9.70000000e-11 CODATA2022
|
||||
h_shield_shift helion shielding shift 5.99674300e-05 1.00000000e-10 CODATA2022
|
||||
F_hyperfine_Cs-133 hyperfine transition frequency of Cs-133 9.19263177e+09 1 / s 0.00000000e+00 CODATA2022
|
||||
aSi_220_ideal lattice spacing of ideal Si (220) 1.92015572e-08 cm 3.20000000e-16 CODATA2022
|
||||
eta luminous efficacy 6.83000000e-05 s3 rad2 cd/(g cm2) 0.00000000e+00 CODATA2022
|
||||
rg_n_MHz_T neutron gyromag. ratio in MHz/T 2.91646931e+01 MHz T^-1 6.90000000e-06 CODATA2022
|
||||
mN_amu_rel neutron relative atomic mass 1.00866492e+00 4.90000000e-10 CODATA2022
|
||||
mu_N_invm nuclear magneton in inverse meter per tesla 2.54262341e-02 m^-1 T^-1 7.80000000e-12 CODATA2022
|
||||
h_eV_Hz Planck constant in eV/Hz 6.62607015e-27 erg s 0.00000000e+00 CODATA2022
|
||||
rg_p_MHz_T proton gyromag. ratio in MHz/T 4.25774785e+01 MHz T^-1 1.80000000e-08 CODATA2022
|
||||
mP_amu_rel proton relative atomic mass 1.00727647e+00 5.30000000e-11 CODATA2022
|
||||
lambda_compt_bar reduced Compton wavelength 3.86159268e-11 cm 1.20000000e-20 CODATA2022
|
||||
lambda_compt_mu_bar reduced muon Compton wavelength 1.86759431e-13 cm 4.20000000e-21 CODATA2022
|
||||
lambda_compt_n_bar reduced neutron Compton wavelength 2.10019416e-14 cm 1.20000000e-23 CODATA2022
|
||||
hbar reduced Planck constant 1.05457182e-27 erg s 0.00000000e+00 CODATA2022
|
||||
hbar_eV_s reduced Planck constant in eV s 1.05457182e-27 erg s 0.00000000e+00 CODATA2022
|
||||
chbar_MeV reduced Planck constant times c in MeV fm 3.16152677e-17 cm erg 0.00000000e+00 CODATA2022
|
||||
lambda_compt_p_bar reduced proton Compton wavelength 2.10308910e-14 cm 6.40000000e-24 CODATA2022
|
||||
lambda_compt_tau_bar reduced tau Compton wavelength 1.11053800e-14 cm 7.50000000e-19 CODATA2022
|
||||
rg_h_shield_MHz_T shielded helion gyromag. ratio in MHz/T 3.24340994e+01 MHz T^-1 3.80000000e-07 CODATA2022
|
||||
rg_p_shield_MHz_T shielded proton gyromag. ratio in MHz/T 4.25763847e+01 MHz T^-1 4.60000000e-07 CODATA2022
|
||||
d_shield-p_shield_HD shielding difference of d and p in HD 2.02000000e-08 2.00000000e-11 CODATA2022
|
||||
t_shield-p_shield_HT shielding difference of t and p in HT 2.41400000e-08 2.00000000e-11 CODATA2022
|
||||
tau_E tau energy equivalent 2.84684357e-03 erg 1.92261196e-07 CODATA2022
|
||||
psi_amu_rel triton relative atomic mass 3.01550072e+00 1.20000000e-10 CODATA2022
|
||||
muPsi_p triton to proton mag. mom. ratio 1.06663992e+00 2.10000000e-09 CODATA2022
|
||||
epsilon0 vacuum electric permittivity 8.85418781e-12 F m^-1 1.30000000e-21 CODATA2022
|
||||
mu0 vacuum mag. permeability 1.25663706e-06 N A^-2 1.90000000e-16 CODATA2022
|
||||
mWZ W to Z mass ratio 8.81530000e-01 1.70000000e-04 CODATA2022
|
||||
au Astronomical Unit 1.49597871e+13 cm 0.00000000e+00 IAU 2012 Resolution B2
|
||||
pc Parsec 3.08567758e+18 cm 0.00000000e+00 Derived from au + IAU 2015 Resolution B 2 note [4]
|
||||
kpc Kiloparsec 3.08567758e+21 cm 0.00000000e+00 Derived from au + IAU 2015 Resolution B 2 note [4]
|
||||
L_bol0 Luminosity for absolute bolometric magnitude 0 3.01280000e+35 erg / s 0.00000000e+00 IAU 2015 Resolution B 2
|
||||
L_sun Nominal solar luminosity 3.82800000e+33 erg / s 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
GM_sun Nominal solar mass parameter 1.32712440e+26 cm3 / s2 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
M_sun Solar mass 1.98840987e+33 g 4.46880543e+28 IAU 2015 Resolution B 3 + CODATA 2018
|
||||
R_sun Nominal solar radius 6.95700000e+10 cm 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
GM_jup Nominal Jupiter mass parameter 1.26686530e+23 cm3 / s2 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
M_jup Jupiter mass 1.89812460e+30 g 4.26589589e+25 IAU 2015 Resolution B 3 + CODATA 2018
|
||||
R_jup Nominal Jupiter equatorial radius 7.14920000e+09 cm 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
GM_earth Nominal Earth mass parameter 3.98600400e+20 cm3 / s2 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
M_earth Earth mass 5.97216787e+27 g 1.34220095e+23 IAU 2015 Resolution B 3 + CODATA 2018
|
||||
R_earth Nominal Earth equatorial radius 6.37810000e+08 cm 0.00000000e+00 IAU 2015 Resolution B 3
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <input_file> <output_file>"
|
||||
exit 1
|
||||
fi
|
||||
input_file="$1"
|
||||
output_file="$2"
|
||||
printf 'const char embeddedConstants[] = R"(' > "$output_file"
|
||||
cat "$input_file" >> "$output_file"
|
||||
printf ')";\n' >> "$output_file"
|
||||
@@ -1,17 +0,0 @@
|
||||
data_file = files('const.dat')
|
||||
command_file = files('format.sh')
|
||||
output_file = meson.current_build_dir() + '/embedded_constants.h'
|
||||
|
||||
embedded_constants_h = custom_target('embed_constants',
|
||||
input: data_file,
|
||||
output: 'embedded_constants.h',
|
||||
command: ['sh', '-c', command_file[0].full_path()+' @INPUT@ ' + output_file, '@INPUT@', '@OUTPUT@']
|
||||
)
|
||||
|
||||
# Ensure the generated header is included
|
||||
const_data_header = include_directories('.')
|
||||
|
||||
const_data_dep = declare_dependency(
|
||||
include_directories: const_data_header,
|
||||
sources: embedded_constants_h
|
||||
)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user