Merge pull request #10 from poojanagrawal/standard_abundances
feat(Standard-Compositions): Imported standard metal fractions from MESA
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -74,6 +74,7 @@ subprojects/libconstants/
|
||||
subprojects/liblogging/
|
||||
subprojects/.wraplock
|
||||
subprojects/tomlplusplus-*/
|
||||
subprojects/CLI11-*/
|
||||
|
||||
qhull.wrap
|
||||
quill.wrap
|
||||
|
||||
2
Doxyfile
2
Doxyfile
@@ -48,7 +48,7 @@ PROJECT_NAME = fourdst::libcomposition
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = v2.3.1
|
||||
PROJECT_NUMBER = v2.4.0
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewers a
|
||||
|
||||
2
build-config/CLI11/meson.build
Normal file
2
build-config/CLI11/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
cli11_proj = subproject('cli11')
|
||||
cli11_dep = cli11_proj.get_variable('CLI11_dep')
|
||||
@@ -2,4 +2,5 @@ cmake = import('cmake')
|
||||
|
||||
subdir('fourdst')
|
||||
subdir('xxHash')
|
||||
subdir('CLI11')
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# *********************************************************************** #
|
||||
project('libcomposition', 'cpp', version: 'v2.3.1', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
|
||||
project('libcomposition', 'cpp', version: 'v2.4.0', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
|
||||
|
||||
# Add default visibility for all C++ targets
|
||||
add_project_arguments('-fvisibility=default', language: 'cpp')
|
||||
@@ -51,7 +51,6 @@ if get_option('pkg_config')
|
||||
description: 'Composition module for SERiF and related projects',
|
||||
version: meson.project_version(),
|
||||
libraries: [libcomposition],
|
||||
subdirs: ['fourdst'],
|
||||
filebase: 'fourdst_composition',
|
||||
install_dir: join_paths(get_option('libdir'), 'pkgconfig')
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,158 @@
|
||||
#pragma once
|
||||
|
||||
#include "fourdst/config/config.h"
|
||||
#include "fourdst/logging/logging.h"
|
||||
#include "fourdst/composition/composition.h"
|
||||
|
||||
#include "quill/Logger.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fourdst::composition::io {
|
||||
typedef std::vector<std::string> ParsedChemicalData;
|
||||
struct CompositionData {
|
||||
std::string comment_str;
|
||||
double he_abundance;
|
||||
bool requires_atomic_weight;
|
||||
std::vector<std::string> elements;
|
||||
std::vector<double> abundances;
|
||||
};
|
||||
struct IsotopicPercentage {
|
||||
std::string comment_str;
|
||||
std::vector<int> atomic_numbers;
|
||||
std::vector<std::string> elements;
|
||||
std::vector<int> mass_numbers;
|
||||
std::vector<double> percentages;
|
||||
};
|
||||
|
||||
enum class SolarCompositions {
|
||||
AG89,
|
||||
GN93,
|
||||
GS98,
|
||||
L03,
|
||||
AGS05,
|
||||
AGSS09,
|
||||
A09_Przybilla,
|
||||
MB22_photospheric,
|
||||
AAG21_photospheric,
|
||||
L09
|
||||
};
|
||||
|
||||
enum class IsotopicPercentages {
|
||||
L03,
|
||||
L09
|
||||
};
|
||||
|
||||
inline std::unordered_map<SolarCompositions, std::string> SolarCompositions_to_string_map = {
|
||||
{SolarCompositions::AG89, "AG89"},
|
||||
{SolarCompositions::GN93, "GN93"},
|
||||
{SolarCompositions::GS98, "GS98"},
|
||||
{SolarCompositions::L03, "L03"},
|
||||
{SolarCompositions::AGS05, "AGS05"},
|
||||
{SolarCompositions::AGSS09, "AGSS09"},
|
||||
{SolarCompositions::A09_Przybilla, "A09_Przybilla"},
|
||||
{SolarCompositions::MB22_photospheric, "MB22_photospheric"},
|
||||
{SolarCompositions::AAG21_photospheric, "AAG21_photospheric"},
|
||||
{SolarCompositions::L09, "L09"}
|
||||
};
|
||||
|
||||
inline std::unordered_map<IsotopicPercentages, std::string> IsotopicPercentages_to_string_map = {
|
||||
{IsotopicPercentages::L03, "L03_data"},
|
||||
{IsotopicPercentages::L09, "L09_data"}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ChemicalFileParser
|
||||
* @brief An abstract base class for chemical file parsers.
|
||||
*
|
||||
* This class defines the interface for parsing fortran code files that contain
|
||||
* nuclide fractions. Derived classes must implement the `parse`
|
||||
* method to handle specific file formats.
|
||||
*/
|
||||
class ChemicalFileParser {
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Parses a chemical file and returns the parsed data.
|
||||
*
|
||||
* This is a pure virtual function that must be implemented by derived
|
||||
* classes. It takes a filename as input and returns a `ParsedChemicalData`
|
||||
* struct containing the information extracted from the file.
|
||||
*
|
||||
* @param filename The path to the Chemical file to parse.
|
||||
* @return A `ParsedChemicalData` struct containing the parsed reaction data.
|
||||
*
|
||||
* @throws std::runtime_error If the file cannot be opened or a parsing
|
||||
* error occurs.
|
||||
*
|
||||
* @b Usage
|
||||
* @code
|
||||
* std::unique_ptr<ChemicalFileParser> parser = std::make_unique<SimpleReactionListFileParser>();
|
||||
* try {
|
||||
* ParsedChemicalData data = parser->parse("my_reactions.txt");
|
||||
* for (const auto& reaction_name : data.reactionPENames) {
|
||||
* // ... process reaction name
|
||||
const mfem::GridFunction& grav_potential_at_inf(FEM& fem, const Args& args, const mfem::GridFunction& rho, bool pho_warm) {
|
||||
|
||||
}
|
||||
* }
|
||||
* } catch (const std::runtime_error& e) {
|
||||
* // ... handle error
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
[[nodiscard]] CompositionData parse_compositon_data(const std::vector<char>& data,const std::string& scheme) const ;
|
||||
[[nodiscard]] IsotopicPercentage parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme) const ;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace fourdst::composition {
|
||||
/**
|
||||
* @brief Function to retrieve a standard solar composition record indexed by their canonical names including
|
||||
* - AG89
|
||||
* - GN93
|
||||
* - GS98
|
||||
* - L03
|
||||
* - AGS05
|
||||
* - AGS08
|
||||
* - A09_Pryzbilla
|
||||
* - MB22_photospheric
|
||||
* - AAG21_photospheric
|
||||
* - L09
|
||||
* Further, isotopic percentages can be selected as either
|
||||
* - L03
|
||||
* - L09
|
||||
*
|
||||
* These data have been extracted from chem_def.f90 from MESA <version>
|
||||
*
|
||||
* @note Composition names are case normalized; therefore, the inputs for metal fraction scheme and isotopic percentage scheme are case insensitive.
|
||||
*
|
||||
* @param metal_fraction_scheme The name of the metal fraction scheme to use. Must be one of the following: AG89, GN93, GS98, L03, AGS05, AGS08, A09_Pryzbilla, MB22_photospheric, AAG21_photospheric, L09
|
||||
* @param isotopic_percentage_scheme The name of the isotopic percentage scheme to use. Must be one of the following: L03, L09
|
||||
* @param initial_z <poojan_documenent_here>
|
||||
* @param initial_y <poojan document here>
|
||||
*/
|
||||
[[nodiscard]] Composition get_composition_record(const std::string& metal_fraction_scheme,
|
||||
const std::string& isotopic_percentage_scheme,
|
||||
double initial_z,
|
||||
double initial_y);
|
||||
|
||||
/**
|
||||
* @brief Overload of the string based version of this function which accepts the enums Solar
|
||||
* @param metal_fraction_scheme Enum corresponding to the standard solar composition to select
|
||||
* @param isotopic_percentage_scheme Enum corresponding to the isotopic percentages prescription to select
|
||||
* @param initial_z <poojan_document_here>
|
||||
* @param initial_y <poojan_document_here>
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] Composition get_composition_record(io::SolarCompositions metal_fraction_scheme,
|
||||
io::IsotopicPercentages isotopic_percentage_scheme,
|
||||
double initial_z,
|
||||
double initial_y);
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <numeric>
|
||||
|
||||
#include "fourdst/composition/utils/composition_hash.h"
|
||||
#include "fourdst/composition/utils.h"
|
||||
#include "../include/fourdst/composition/utils/utils.h"
|
||||
|
||||
#include "fourdst/composition/exceptions/exceptions_composition.h"
|
||||
|
||||
|
||||
396
src/composition/lib/io/standard_compositions.cpp
Normal file
396
src/composition/lib/io/standard_compositions.cpp
Normal file
@@ -0,0 +1,396 @@
|
||||
#include "fourdst/composition/io/standard_compositions.h"
|
||||
#include "fourdst/composition/io/StandardMetalFractionsBinary.h"
|
||||
|
||||
#include "fourdst/composition/composition.h"
|
||||
#include "fourdst/atomic/atomicSpecies.h"
|
||||
#include "fourdst/atomic/species.h"
|
||||
#include "../../include/fourdst/composition/utils/utils.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include <print>
|
||||
#include <ranges>
|
||||
#include <cctype>
|
||||
|
||||
namespace fourdst:: composition::io {
|
||||
namespace {
|
||||
inline void ltrim(std::string &s) {
|
||||
s.erase(
|
||||
s.begin(),
|
||||
std::ranges::find_if(s,
|
||||
[](const unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
inline void rtrim(std::string &s) {
|
||||
s.erase(
|
||||
std::find_if(
|
||||
s.rbegin(),
|
||||
s.rend(),
|
||||
[](const unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(),
|
||||
s.end()
|
||||
);
|
||||
}
|
||||
|
||||
inline void trim(std::string &s) {
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool to_bool(std::string s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(),
|
||||
[](unsigned char c){ return std::tolower(c); });
|
||||
|
||||
return s == "true";
|
||||
}
|
||||
|
||||
CompositionData ChemicalFileParser::parse_compositon_data(const std::vector<char>& data,const std::string& scheme) const {
|
||||
|
||||
// get file and metal_fraction_scheme
|
||||
// Load the file
|
||||
// find the metal_fraction_scheme
|
||||
// return abundances
|
||||
|
||||
// LOG_TRACE_L1(m_logger, "Parsing chemical abundance for: {}", scheme);
|
||||
|
||||
bool debug = false;
|
||||
if (debug){
|
||||
std::println("Parsing chemical abundance for: {}", scheme);
|
||||
}
|
||||
|
||||
std::istringstream stream(std::string(data.begin(), data.end()));
|
||||
|
||||
// add error message if something goes wrong
|
||||
|
||||
std::string line;
|
||||
int start_line = 0;
|
||||
int i = 0;
|
||||
|
||||
CompositionData comp;
|
||||
|
||||
while (std::getline(stream, line)) {
|
||||
|
||||
// find where the end of the scheme block is
|
||||
auto end_pos = std::ranges::search(line,std::format("END {}", scheme));
|
||||
|
||||
// exit if have reached the end of block
|
||||
if (!end_pos.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (start_line>0){
|
||||
const size_t colon_pos = line.find(':');
|
||||
line = line.substr(colon_pos+1);
|
||||
|
||||
line.erase(std::remove_if(line.begin(), line.end(),
|
||||
[](char c){ return c == '[' || c == ']'; }),
|
||||
line.end());
|
||||
|
||||
trim(line);
|
||||
std::string item;
|
||||
std::stringstream ss(line);
|
||||
double val;
|
||||
switch(i-start_line){
|
||||
case 1:
|
||||
comp.comment_str = line;
|
||||
break;
|
||||
case 2:
|
||||
comp.he_abundance = std::pow(10.0,std::stod(line));
|
||||
break;
|
||||
case 3:
|
||||
comp.requires_atomic_weight = to_bool(line);
|
||||
break;
|
||||
case 4:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
comp.elements.push_back(item);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
val = std::pow(10.0,std::stod(item));
|
||||
comp.abundances.push_back(val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// find where the start of the scheme block is
|
||||
auto start_pos = std::ranges::search(line, std::format("BEGIN {}", scheme));
|
||||
|
||||
if (!start_pos.empty()) {
|
||||
start_line = i;
|
||||
}
|
||||
i+=1;
|
||||
}
|
||||
|
||||
// if (start_pos==0):
|
||||
// raise error ("Scheme {} not found", scheme)
|
||||
|
||||
|
||||
if (debug){
|
||||
std::println("he_abundance: {}", comp.he_abundance);
|
||||
std::println("requires_atomic_weight: {}", comp.requires_atomic_weight);
|
||||
std::println("elements: {}",comp.elements);
|
||||
std::println("abundances: {}", comp.abundances);
|
||||
}
|
||||
|
||||
return comp;
|
||||
|
||||
}
|
||||
|
||||
IsotopicPercentage ChemicalFileParser::parse_isotopic_percentage(const std::vector<char>& data,const std::string& scheme) const {
|
||||
|
||||
// get file and iso_scheme
|
||||
// Load the file
|
||||
// find the iso_scheme
|
||||
// get iso_comp data
|
||||
// IsotopicPercentage object
|
||||
|
||||
bool debug = false;
|
||||
if (debug){
|
||||
std::println("Parsing Isotopic Percentage for: {}", scheme);
|
||||
}
|
||||
|
||||
std::istringstream stream(std::string(data.begin(), data.end()));
|
||||
|
||||
// add error message if something goes wrong
|
||||
ParsedChemicalData parsed;
|
||||
|
||||
std::string line;
|
||||
int start_line = 0;
|
||||
int i = 0;
|
||||
|
||||
IsotopicPercentage iso;
|
||||
|
||||
while (std::getline(stream, line)) {
|
||||
|
||||
// find where the end of the scheme block is
|
||||
auto end_pos = std::ranges::search(line,std::format("END {}", scheme));
|
||||
|
||||
// exit if have reached the end of block
|
||||
if (!end_pos.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (start_line>0){
|
||||
const size_t colon_pos = line.find(':');
|
||||
line = line.substr(colon_pos+1);
|
||||
|
||||
line.erase(std::remove_if(line.begin(), line.end(),
|
||||
[](char c){ return c == '[' || c == ']'; }),
|
||||
line.end());
|
||||
|
||||
trim(line);
|
||||
std::string item;
|
||||
std::stringstream ss(line);
|
||||
parsed.push_back(line);
|
||||
switch(i-start_line){
|
||||
case 1:
|
||||
iso.comment_str = line;
|
||||
break;
|
||||
case 2:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
iso.atomic_numbers.push_back(std::stoi(item));
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
iso.elements.push_back(item);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
iso.mass_numbers.push_back(std::stoi(item));
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
while(std::getline(ss, item, ',')) {
|
||||
iso.percentages.push_back(std::stod(item));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// find where the start of the scheme block is
|
||||
auto start_pos = std::ranges::search(line, std::format("BEGIN {}", scheme));
|
||||
|
||||
if (!start_pos.empty()) {
|
||||
start_line = i;
|
||||
}
|
||||
i+=1;
|
||||
}
|
||||
|
||||
if (debug){
|
||||
std::println("atomic_numbers: {}", iso.atomic_numbers);
|
||||
std::println("elements: {}",iso.elements);
|
||||
std::println("mass_numbers: {}", iso.mass_numbers);
|
||||
std::println("percentages: {}", iso.percentages);
|
||||
}
|
||||
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
namespace fourdst::composition {
|
||||
Composition get_composition_record(const std::string& metal_fraction_scheme,
|
||||
const std::string& isotopic_percentage_scheme,
|
||||
double initial_z, double initial_y) {
|
||||
|
||||
|
||||
std::vector<char> data;
|
||||
|
||||
io::ChemicalFileParser parser;
|
||||
io::CompositionData metals;
|
||||
|
||||
io::IsotopicPercentage isotopes;
|
||||
|
||||
data = std::ranges::to<std::vector<char>>(StandardMetalFractions);
|
||||
|
||||
metals = parser.parse_compositon_data(data,metal_fraction_scheme);
|
||||
isotopes = parser.parse_isotopic_percentage(data,isotopic_percentage_scheme);
|
||||
|
||||
std::string name;
|
||||
std::vector<atomic::Species> species;
|
||||
|
||||
|
||||
// construct name of the isotopes for all elements
|
||||
for (const auto [E,A] : std::ranges::views::zip(isotopes.elements, isotopes.mass_numbers)){
|
||||
if (std::ranges::contains(metals.elements,E ) || E == "H" || E == "He") {
|
||||
name = std::format("{}-{}",E,A);
|
||||
auto SpeciesObject = atomic::species.at(name);
|
||||
species.push_back(SpeciesObject);
|
||||
// std::println("Species: {} has mass: {}", SpeciesObject.name(), SpeciesObject.mass());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<double> massFracs;
|
||||
std::unordered_map<std::string, double> metal_fractions;
|
||||
|
||||
// hydrogen and helium are treated separately
|
||||
// H1
|
||||
massFracs.push_back(std::max(0.0, std::min(1.0, 1.0 - (initial_z + initial_y))));
|
||||
// H2
|
||||
massFracs.push_back(0.0);
|
||||
// He3
|
||||
// anders & grevesse 1989 solar mass fractions
|
||||
double xsol_he3,xsol_he4;
|
||||
xsol_he3 = 2.9291e-05;
|
||||
xsol_he4 = 2.7521e-01;
|
||||
massFracs.push_back(initial_y*xsol_he3/(xsol_he3 + xsol_he4));
|
||||
// He4
|
||||
massFracs.push_back(initial_y*xsol_he4/(xsol_he3 + xsol_he4));
|
||||
// Metals
|
||||
|
||||
double ztotal = 1.0-std::accumulate(massFracs.begin(), massFracs.end(), 0.0);
|
||||
|
||||
// multiply by atomic weight if needed
|
||||
|
||||
if (metals.requires_atomic_weight){
|
||||
// get isotope with max abundance for each metal
|
||||
// and store the corresponding mass number
|
||||
auto element_atomic_weight = [&isotopes]() {
|
||||
std::unordered_map<std::string, std::pair<double, int>> elem_info;
|
||||
|
||||
for (const auto& [iso, prcnt, a] : std::views::zip(isotopes.elements, isotopes.percentages, isotopes.mass_numbers)) {
|
||||
if (iso == "H" || iso == "He") {
|
||||
continue;
|
||||
}
|
||||
if (elem_info.contains(iso) && elem_info.at(iso).first <= prcnt) {
|
||||
elem_info[iso] = std::make_pair(prcnt, a);
|
||||
} else if (! elem_info.contains(iso)) {
|
||||
elem_info[iso] = std::make_pair(prcnt, a);
|
||||
}
|
||||
}
|
||||
return elem_info;
|
||||
}();
|
||||
|
||||
for (const auto [E,A] : std::ranges::views::zip(metals.elements, metals.abundances)) {
|
||||
// std::println("element: {}", E);
|
||||
auto name = std::format("{}-{}",E,element_atomic_weight.at(E).second);
|
||||
// std::println("{}", name);
|
||||
auto SpeciesObject = atomic::species.at(name);
|
||||
double weight = SpeciesObject.mass();
|
||||
metal_fractions.emplace(E,A*weight);
|
||||
// std::println("End");
|
||||
}
|
||||
} else {
|
||||
for (const auto [E,A] : std::ranges::views::zip(metals.elements, metals.abundances)) {
|
||||
metal_fractions.emplace(E,A);
|
||||
}
|
||||
}
|
||||
|
||||
double sum = [&metal_fractions]() {
|
||||
double accumulator = 0.0;
|
||||
for (const auto& frac : metal_fractions | std::views::values) {
|
||||
accumulator += frac;
|
||||
}
|
||||
return accumulator;
|
||||
}();
|
||||
|
||||
for (auto& frac : metal_fractions | std::views::values) {
|
||||
frac/=sum;
|
||||
}
|
||||
|
||||
double zsum = 0.0;
|
||||
|
||||
// get mass Fracs for each metal and scale it to required ztotal
|
||||
for (size_t i = 0; i < species.size();++i) {
|
||||
size_t Z = isotopes.atomic_numbers[i];
|
||||
if (Z<=2) continue;
|
||||
|
||||
if (metal_fractions.contains(isotopes.elements[i])) {
|
||||
double frac = 1e-2*isotopes.percentages[i]*species[i].mass();
|
||||
double frac_sum = 0.0;
|
||||
size_t j = i ;
|
||||
while (j<species.size() && isotopes.atomic_numbers[j] == Z) {
|
||||
frac_sum += 1e-2*isotopes.percentages[j]*species[j].mass();
|
||||
++j;
|
||||
}
|
||||
// extract zfrac for the corresponding Z symbol/ isotopes.elements
|
||||
double zfrac = metal_fractions.at(isotopes.elements[i]);
|
||||
auto temp = ztotal*zfrac*frac/frac_sum;
|
||||
massFracs.push_back(temp);
|
||||
zsum += temp;
|
||||
// std::println("isotope:{}",species[i].name());
|
||||
}
|
||||
}
|
||||
|
||||
// std::println("ztotal: {}, zsum:{}", ztotal, zsum);
|
||||
//Renormalize
|
||||
if (zsum > 0.0) {
|
||||
for (size_t i = 0; i < massFracs.size();++i) {
|
||||
if (isotopes.atomic_numbers[i]<=2) continue;
|
||||
massFracs[i] *= ztotal/zsum;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Composition comp = buildCompositionFromMassFractions(species, massFracs);
|
||||
return comp;
|
||||
|
||||
}
|
||||
|
||||
Composition get_composition_record(const io::SolarCompositions metal_fraction_scheme,
|
||||
const io::IsotopicPercentages isotopic_percentage_scheme,
|
||||
double initial_z,
|
||||
double initial_y) {
|
||||
return get_composition_record(
|
||||
io::SolarCompositions_to_string_map.at(metal_fraction_scheme),
|
||||
io::IsotopicPercentages_to_string_map.at(isotopic_percentage_scheme),
|
||||
initial_z,
|
||||
initial_y
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "fourdst/composition/exceptions/exceptions_composition.h"
|
||||
#include "fourdst/atomic/atomicSpecies.h"
|
||||
#include "fourdst/atomic/species.h"
|
||||
#include "fourdst/composition/utils.h"
|
||||
#include "../include/fourdst/composition/utils/utils.h"
|
||||
#include "fourdst/logging/logging.h"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
@@ -4,7 +4,9 @@ required_headers = [
|
||||
'fourdst/composition/composition.h',
|
||||
'fourdst/composition/utils.h',
|
||||
'fourdst/composition/composition_abstract.h',
|
||||
'fourdst/composition/exceptions/exceptions_composition.h'
|
||||
'fourdst/composition/exceptions/exceptions_composition.h',
|
||||
'fourdst/composition/io/standard_compositions.h',
|
||||
'fourdst/composition/io/StandardMetalFractionsBinary.h'
|
||||
]
|
||||
|
||||
foreach h : required_headers
|
||||
@@ -23,6 +25,7 @@ composition_sources = files(
|
||||
'lib/composition.cpp',
|
||||
'lib/utils.cpp',
|
||||
'lib/decorators/composition_masked.cpp',
|
||||
'lib/io/standard_compositions.cpp'
|
||||
)
|
||||
|
||||
|
||||
@@ -50,26 +53,48 @@ composition_dep = declare_dependency(
|
||||
# Make headers accessible
|
||||
composition_headers = files(
|
||||
'include/fourdst/composition/composition.h',
|
||||
'include/fourdst/composition/composition_abstract.h'
|
||||
'include/fourdst/composition/composition_abstract.h',
|
||||
)
|
||||
install_headers(composition_headers, subdir : 'fourdst/fourdst/composition')
|
||||
install_headers(composition_headers, subdir : 'fourdst/composition')
|
||||
|
||||
composition_headers_utils = files(
|
||||
'include/fourdst/composition/utils.h',
|
||||
'include/fourdst/composition/utils/utils.h',
|
||||
'include/fourdst/composition/utils/composition_hash.h'
|
||||
)
|
||||
install_headers(composition_headers_utils, subdir : 'fourdst/fourdst/composition/utils')
|
||||
install_headers(composition_headers_utils, subdir : 'fourdst/composition/utils')
|
||||
|
||||
composition_headers_io = files(
|
||||
'include/fourdst/composition/io/standard_compositions.h',
|
||||
'include/fourdst/composition/io/StandardMetalFractionsBinary.h'
|
||||
)
|
||||
|
||||
install_headers(composition_headers_io, subdir : 'fourdst/composition/io')
|
||||
|
||||
composition_headers_decorators = files(
|
||||
'include/fourdst/composition/decorators/composition_masked.h',
|
||||
'include/fourdst/composition/decorators/composition_decorator_abstract.h',
|
||||
)
|
||||
|
||||
install_headers(composition_headers_decorators, subdir : 'fourdst/composition/decorators')
|
||||
|
||||
composition_headers_atomic = files(
|
||||
'include/fourdst/atomic/atomicSpecies.h',
|
||||
'include/fourdst/atomic/elements.h',
|
||||
'include/fourdst/atomic/species.h',
|
||||
|
||||
)
|
||||
install_headers(composition_headers_atomic, subdir : 'fourdst/fourdst/atomic')
|
||||
install_headers(composition_headers_atomic, subdir : 'fourdst/atomic')
|
||||
|
||||
composition_exception_headers = files(
|
||||
'include/fourdst/composition/exceptions/exceptions_composition.h',
|
||||
)
|
||||
install_headers(composition_exception_headers, subdir : 'fourdst/fourdst/composition/exceptions')
|
||||
install_headers(composition_exception_headers, subdir : 'fourdst/composition/exceptions')
|
||||
|
||||
composition_iterator_headers = files(
|
||||
'include/fourdst/composition/iterators/composition_abstract_iterator.h',
|
||||
)
|
||||
|
||||
install_headers(composition_iterator_headers, subdir : 'fourdst/composition/iterators')
|
||||
|
||||
v = meson.project_version()
|
||||
|
||||
|
||||
10
subprojects/cli11.wrap
Normal file
10
subprojects/cli11.wrap
Normal file
@@ -0,0 +1,10 @@
|
||||
[wrap-file]
|
||||
directory = CLI11-2.6.1
|
||||
source_url = https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.6.1.tar.gz
|
||||
source_filename = CLI11-2.6.1.tar.gz
|
||||
source_hash = 377691f3fac2b340f12a2f79f523c780564578ba3d6eaf5238e9f35895d5ba95
|
||||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/cli11_2.6.1-1/CLI11-2.6.1.tar.gz
|
||||
wrapdb_version = 2.6.1-1
|
||||
|
||||
[provide]
|
||||
dependency_names = CLI11
|
||||
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/4D-STAR/libconfig.git
|
||||
revision = v2.0.2
|
||||
revision = v2.2.6
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/4D-STAR/libconstants.git
|
||||
revision = v1.1.1
|
||||
revision = v1.1.2
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/4D-STAR/liblogging.git
|
||||
revision = v1.1.1
|
||||
revision = v1.1.2
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include "fourdst/atomic/species.h"
|
||||
#include "fourdst/composition/composition.h"
|
||||
#include "fourdst/composition/exceptions/exceptions_composition.h"
|
||||
#include "fourdst/composition/utils.h"
|
||||
#include "fourdst/composition/utils/utils.h"
|
||||
#include "fourdst/composition/decorators/composition_masked.h"
|
||||
#include "fourdst/composition/io/standard_compositions.h"
|
||||
#include "fourdst/composition/utils/composition_hash.h"
|
||||
|
||||
#include "fourdst/config/config.h"
|
||||
@@ -482,4 +483,37 @@ TEST_F(compositionTest, iterationOrdering) {
|
||||
EXPECT_EQ(sp, speciesInOrder[count]);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(compositionTest, standardSolarCompositions) {
|
||||
using namespace fourdst::composition;
|
||||
|
||||
std::vector<io::SolarCompositions> comps = {
|
||||
io::SolarCompositions::AG89,
|
||||
io::SolarCompositions::GS98,
|
||||
io::SolarCompositions::L03,
|
||||
io::SolarCompositions::A09_Przybilla,
|
||||
io::SolarCompositions::AGS05,
|
||||
io::SolarCompositions::AGSS09,
|
||||
io::SolarCompositions::AAG21_photospheric,
|
||||
io::SolarCompositions::MB22_photospheric,
|
||||
io::SolarCompositions::L09
|
||||
};
|
||||
|
||||
std::vector<io::IsotopicPercentages> isos = {
|
||||
io::IsotopicPercentages::L03,
|
||||
io::IsotopicPercentages::L09
|
||||
};
|
||||
|
||||
|
||||
for (const auto comp : comps) {
|
||||
for (const auto iso: isos) {
|
||||
std::string string_comp = io::SolarCompositions_to_string_map.at(comp);
|
||||
std::string string_iso = io::IsotopicPercentages_to_string_map.at(iso);
|
||||
|
||||
EXPECT_NO_THROW((void)get_composition_record(comp, iso, 0.02, 0.28));
|
||||
EXPECT_NO_THROW((void)get_composition_record(string_comp, string_iso, 0.02, 0.28));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,3 +27,5 @@ foreach test_file : test_sources
|
||||
test_exe,
|
||||
env: ['MESON_SOURCE_ROOT=' + meson.project_source_root(), 'MESON_BUILD_ROOT=' + meson.project_build_root()])
|
||||
endforeach
|
||||
|
||||
subdir('sandbox')
|
||||
|
||||
1
tests/composition/sandbox/meson.build
Normal file
1
tests/composition/sandbox/meson.build
Normal file
@@ -0,0 +1 @@
|
||||
executable('sandbox', 'sandbox.cpp', dependencies: [species_weight_dep, composition_dep, config_dep, cli11_dep])
|
||||
47
tests/composition/sandbox/sandbox.cpp
Normal file
47
tests/composition/sandbox/sandbox.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "fourdst/composition/io/standard_compositions.h"
|
||||
#include "fourdst/composition/composition.h"
|
||||
#include "fourdst/atomic/species.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <unordered_map>
|
||||
#include <ranges>
|
||||
#include "CLI/CLI.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
|
||||
// @input: initial_z, initial_y, metal_fraction_scheme & isotopic_percentage_scheme
|
||||
// Options for metal_frac_scheme: ['AG89', 'GN93', 'GS98', 'L03', 'AGS05', 'AGSS09', 'A09_Przybilla', 'MB22_photospheric', 'AAG21_photospheric', 'L09']
|
||||
// Options for isotopic percentage scheme: ['L03_data', 'L09_data']
|
||||
|
||||
double initial_z;
|
||||
std::string metal_fraction_scheme;
|
||||
|
||||
auto keys = fourdst::composition::io::SolarCompositions_to_string_map | std::views::values | std::ranges::to<std::vector>();
|
||||
|
||||
CLI::App app("Example App To Load Solar Composition");
|
||||
app.add_option("-z,--initial_z", initial_z, "Initial Z")->required();
|
||||
app.add_option("-c,--metal-fraction-scheme", metal_fraction_scheme)->
|
||||
check(
|
||||
CLI::IsMember(
|
||||
keys,
|
||||
CLI::ignore_case)
|
||||
);
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
std::string isotopic_percentage_scheme;
|
||||
double initial_y;
|
||||
|
||||
// the following four should be user input
|
||||
// initial_y can be optional
|
||||
initial_y = 0.24 + 2*initial_z;
|
||||
isotopic_percentage_scheme = "L03_data";
|
||||
|
||||
fourdst::composition::Composition comp;
|
||||
comp = fourdst::composition::get_composition_record(metal_fraction_scheme, isotopic_percentage_scheme, initial_z, initial_y);
|
||||
std::cout << comp << std::endl;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user