feat(GraphEngine): More robust reaction type selection at network construction
Added new ways to select exactly what types of reactions (strong, beta+, beta-, electron capture, positron capture, or any combination thereof) can be turned on at network construction time. There are a few quality of life masks added as well such as weak which addes all weak type reactions, and all which adds weak + strong reactions. The default is to just add strong reactions for now.
This commit is contained in:
@@ -119,6 +119,13 @@ namespace gridfire {
|
||||
BuildDepthType buildDepth = NetworkBuildDepth::Full
|
||||
);
|
||||
|
||||
explicit GraphEngine(
|
||||
const fourdst::composition::Composition &composition,
|
||||
const partition::PartitionFunction& partitionFunction,
|
||||
BuildDepthType buildDepth,
|
||||
NetworkConstructionFlags reactionTypes
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Constructs a GraphEngine from a set of reactions.
|
||||
*
|
||||
|
||||
@@ -11,6 +11,76 @@
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
|
||||
enum class NetworkConstructionFlags : uint32_t {
|
||||
NONE = 0,
|
||||
|
||||
STRONG = 1 << 0, // 1
|
||||
|
||||
BETA_MINUS = 1 << 1, // 2
|
||||
BETA_PLUS = 1 << 2, // 4
|
||||
ELECTRON_CAPTURE = 1 << 3, // 8
|
||||
POSITRON_CAPTURE = 1 << 4, // 16
|
||||
|
||||
WEAK = BETA_MINUS | BETA_PLUS | ELECTRON_CAPTURE | POSITRON_CAPTURE,
|
||||
DEFAULT = STRONG,
|
||||
ALL = STRONG | WEAK
|
||||
};
|
||||
|
||||
constexpr auto to_underlying(NetworkConstructionFlags f) noexcept {
|
||||
return static_cast<std::underlying_type_t<NetworkConstructionFlags>>(f);
|
||||
}
|
||||
|
||||
inline NetworkConstructionFlags operator|(const NetworkConstructionFlags lhs, const NetworkConstructionFlags rhs) {
|
||||
return static_cast<NetworkConstructionFlags>(to_underlying(lhs) | to_underlying(rhs));
|
||||
}
|
||||
|
||||
inline NetworkConstructionFlags operator&(const NetworkConstructionFlags lhs, const NetworkConstructionFlags rhs) {
|
||||
return static_cast<NetworkConstructionFlags>(to_underlying(lhs) & to_underlying(rhs));
|
||||
}
|
||||
|
||||
inline bool has_flag(const NetworkConstructionFlags flags, const NetworkConstructionFlags flag_to_check) {
|
||||
return (flags & flag_to_check) != NetworkConstructionFlags::NONE;
|
||||
}
|
||||
|
||||
inline std::string NetworkConstructionFlagsToString(NetworkConstructionFlags flags) {
|
||||
std::stringstream ss;
|
||||
constexpr std::array<NetworkConstructionFlags, 5> bases_flags_array = {
|
||||
NetworkConstructionFlags::STRONG,
|
||||
NetworkConstructionFlags::BETA_MINUS,
|
||||
NetworkConstructionFlags::BETA_PLUS,
|
||||
NetworkConstructionFlags::ELECTRON_CAPTURE,
|
||||
NetworkConstructionFlags::POSITRON_CAPTURE
|
||||
};
|
||||
|
||||
const std::unordered_map<NetworkConstructionFlags, std::string> bases_string_map = {
|
||||
{NetworkConstructionFlags::STRONG, "Strong"},
|
||||
{NetworkConstructionFlags::BETA_MINUS, "BetaMinus"},
|
||||
{NetworkConstructionFlags::BETA_PLUS, "BetaPlus"},
|
||||
{NetworkConstructionFlags::ELECTRON_CAPTURE, "ElectronCapture"},
|
||||
{NetworkConstructionFlags::POSITRON_CAPTURE, "PositronCapture"}
|
||||
};
|
||||
|
||||
size_t i = 0;
|
||||
for (const auto& flagType : bases_flags_array) {
|
||||
if (has_flag(flags, flagType)) {
|
||||
ss << bases_string_map.at(flagType);
|
||||
if (i < bases_flags_array.size() - 1) {
|
||||
ss << ", ";
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
std::string result = ss.str();
|
||||
if (result.empty()) {
|
||||
return "No reactions";
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Builds a nuclear reaction network from the Reaclib library based on an initial composition.
|
||||
*
|
||||
@@ -26,7 +96,7 @@ namespace gridfire {
|
||||
* @param weakInterpolator Interpolator to build weak rates from. Must be constructed and owned by the caller.
|
||||
* @param maxLayers Variant specifying either a predefined NetworkBuildDepth or a custom integer depth;
|
||||
* negative depth (Full) collects all reactions, zero is invalid.
|
||||
* @param reverse If true, collects reverse reactions (decays or back-reactions); if false, uses forward reactions.
|
||||
* @param ReactionTypes
|
||||
* @pre composition must have at least one species with positive mass fraction.
|
||||
* @pre Resolved integer depth from maxLayers must not be zero.
|
||||
* @post Returned network includes only reactions satisfying the depth and reverse criteria.
|
||||
@@ -35,8 +105,8 @@ namespace gridfire {
|
||||
*/
|
||||
reaction::ReactionSet build_nuclear_network(
|
||||
const fourdst::composition::Composition &composition,
|
||||
const rates::weak::WeakRateInterpolator &weakInterpolator,
|
||||
const std::optional<rates::weak::WeakRateInterpolator> &weakInterpolator,
|
||||
BuildDepthType maxLayers = NetworkBuildDepth::Full,
|
||||
bool reverse = false
|
||||
NetworkConstructionFlags ReactionTypes = NetworkConstructionFlags::DEFAULT
|
||||
);
|
||||
}
|
||||
|
||||
@@ -779,6 +779,8 @@ namespace gridfire::reaction {
|
||||
|
||||
void add_reaction(std::unique_ptr<Reaction>&& reaction);
|
||||
|
||||
void extend(const ReactionSet& other);
|
||||
|
||||
/**
|
||||
* @brief Removes a reaction from the set.
|
||||
* @param reaction The Reaction to remove.
|
||||
|
||||
Reference in New Issue
Block a user