feat(GridFire): added weak electron screening

This commit is contained in:
2025-07-01 11:40:03 -04:00
parent 40b28477ed
commit 0c16e81e98
26 changed files with 1408 additions and 444 deletions

View File

@@ -1,3 +1,77 @@
//
// Created by Emily Boudreaux on 6/30/25.
//
#include "gridfire/io/network_file.h"
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <stdexcept>
#include "quill/LogMacros.h"
namespace gridfire::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);
}
}
SimpleReactionListFileParser::SimpleReactionListFileParser() {}
ParsedNetworkData SimpleReactionListFileParser::parse(const std::string& filename) const {
LOG_TRACE_L1(m_logger, "Parsing simple reaction list file: {}", filename);
std::ifstream file(filename);
if (!file.is_open()) {
LOG_ERROR(m_logger, "Failed to open file: {}", filename);
m_logger -> flush_log();
throw std::runtime_error("Could not open file: " + filename);
}
ParsedNetworkData parsed;
std::string line;
int line_number = 0;
while (std::getline(file, line)) {
line_number++;
LOG_TRACE_L3(m_logger, "Parsing reaction list file {}, line {}: {}", filename, line_number, line);
const size_t comment_pos = line.find('#');
if (comment_pos != std::string::npos) {
line = line.substr(0, comment_pos);
}
trim(line);
if (line.empty()) {
continue; // Skip empty lines
}
parsed.reactionPENames.push_back(line);
}
LOG_TRACE_L1(m_logger, "Parsed {} reactions from file: {}", parsed.reactionPENames.size(), filename);
return parsed;
}
}