docs(docs): asdded and cleaned up docs
This commit is contained in:
@@ -9,6 +9,27 @@
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
/**
|
||||
* @brief Builds a nuclear reaction network from the Reaclib library based on an initial composition.
|
||||
*
|
||||
* Constructs a layered reaction network by collecting reactions up to the specified depth
|
||||
* from the Reaclib dataset. Starting species are those with non-zero mass fractions in the input
|
||||
* composition. Layers expand by including products of collected reactions until the depth limit.
|
||||
* Optionally selects reverse reactions instead of forward.
|
||||
*
|
||||
* See implementation in construction.cpp for details on the layering algorithm, logging, and performance.
|
||||
*
|
||||
* @param composition Mapping of isotopic species to their mass fractions; species with positive
|
||||
* mass fraction seed the network.
|
||||
* @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.
|
||||
* @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.
|
||||
* @return A LogicalReactionSet encapsulating the collected reactions for graph-based engines.
|
||||
* @throws std::logic_error If the resolved network depth is zero (no reactions can be collected).
|
||||
*/
|
||||
reaction::LogicalReactionSet build_reaclib_nuclear_network(
|
||||
const fourdst::composition::Composition &composition,
|
||||
BuildDepthType maxLayers = NetworkBuildDepth::Full,
|
||||
|
||||
@@ -13,25 +13,70 @@
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
/**
|
||||
* @brief Primes absent species in the network to their equilibrium abundances.
|
||||
*
|
||||
* Executes a network priming algorithm that iteratively rebuilds the reaction network,
|
||||
* calculates equilibrium mass fractions for species with zero initial abundance,
|
||||
* and applies mass transfers based on reaction flows.
|
||||
*
|
||||
* Refer to priming.cpp for implementation details on logging, algorithmic steps, and error handling.
|
||||
*
|
||||
* @param netIn Input network data containing initial composition, temperature, and density.
|
||||
* @param engine DynamicEngine used to build and evaluate the reaction network.
|
||||
* @pre netIn.composition defines species and their mass fractions; engine is constructed with a valid network.
|
||||
* @post engine.networkReactions restored to its initial state; returned report contains primedComposition,
|
||||
* massFractionChanges for each species, success flag, and status code.
|
||||
* @return PrimingReport encapsulating the results of the priming operation.
|
||||
*/
|
||||
PrimingReport primeNetwork(
|
||||
const NetIn&,
|
||||
DynamicEngine& engine
|
||||
);
|
||||
|
||||
PrimingReport primeNetwork(
|
||||
const NetIn&,
|
||||
DynamicEngine& engine
|
||||
);
|
||||
/**
|
||||
* @brief Computes the destruction rate constant for a specific species.
|
||||
*
|
||||
* Calculates the sum of molar reaction flows for all reactions where the species
|
||||
* is a reactant (negative stoichiometry) after scaling its abundance to unity.
|
||||
*
|
||||
* @param engine Engine providing the current set of network reactions and flow calculations.
|
||||
* @param species The atomic species whose destruction rate is computed.
|
||||
* @param Y Vector of molar abundances for all species in the engine.
|
||||
* @param T9 Temperature in units of 10^9 K.
|
||||
* @param rho Density of the medium.
|
||||
* @pre Y.size() matches engine.getNetworkReactions().size() mapping species order.
|
||||
* @post Returned rate constant is non-negative.
|
||||
* @return Sum of absolute stoichiometry-weighted destruction flows for the species.
|
||||
*/
|
||||
double calculateDestructionRateConstant(
|
||||
const DynamicEngine& engine,
|
||||
const fourdst::atomic::Species& species,
|
||||
const std::vector<double>& Y,
|
||||
double T9,
|
||||
double rho
|
||||
);
|
||||
|
||||
double calculateDestructionRateConstant(
|
||||
const DynamicEngine& engine,
|
||||
const fourdst::atomic::Species& species,
|
||||
const std::vector<double>& Y,
|
||||
double T9,
|
||||
double rho
|
||||
);
|
||||
|
||||
double calculateCreationRate(
|
||||
const DynamicEngine& engine,
|
||||
const fourdst::atomic::Species& species,
|
||||
const std::vector<double>& Y,
|
||||
double T9,
|
||||
double rho
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @brief Computes the creation rate for a specific species.
|
||||
*
|
||||
* Sums molar reaction flows for all reactions where the species
|
||||
* appears as a product (positive stoichiometry).
|
||||
*
|
||||
* @param engine Engine providing the current set of network reactions and flow calculations.
|
||||
* @param species The atomic species whose creation rate is computed.
|
||||
* @param Y Vector of molar abundances for all species in the engine.
|
||||
* @param T9 Temperature in units of 10^9 K.
|
||||
* @param rho Density of the medium.
|
||||
* @pre Y.size() matches engine.getNetworkReactions().size() mapping species order.
|
||||
* @post Returned creation rate is non-negative.
|
||||
* @return Sum of stoichiometry-weighted creation flows for the species.
|
||||
*/
|
||||
double calculateCreationRate(
|
||||
const DynamicEngine& engine,
|
||||
const fourdst::atomic::Species& species,
|
||||
const std::vector<double>& Y,
|
||||
double T9,
|
||||
double rho
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,21 @@
|
||||
#include <variant>
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
/**
|
||||
* @enum NetworkBuildDepth
|
||||
* @brief Specifies supported depths for building the reaction network.
|
||||
*
|
||||
* Values:
|
||||
* - Full: Build the complete network (infinite depth).
|
||||
* - Shallow: Build only direct reactions (depth = 1).
|
||||
* - SecondOrder: Include reactions up to second order (depth = 2).
|
||||
* - ThirdOrder: Include reactions up to third order (depth = 3).
|
||||
* - FourthOrder: Include reactions up to fourth order (depth = 4).
|
||||
* - FifthOrder: Include reactions up to fifth order (depth = 5).
|
||||
*
|
||||
* @note For custom build depths, see BuildDepthType.
|
||||
*/
|
||||
enum class NetworkBuildDepth {
|
||||
Full = -1,
|
||||
Shallow = 1,
|
||||
@@ -12,5 +27,13 @@ namespace gridfire {
|
||||
FifthOrder = 5
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef BuildDepthType
|
||||
* @brief Variant specifying either a predefined NetworkBuildDepth or a custom integer depth.
|
||||
*
|
||||
* @pre If using the integer alternative, the value must be >= 0 or -1 to indicate a full build.
|
||||
* @post The network builder will interpret and apply the specified depth to control reaction expansion.
|
||||
*/
|
||||
using BuildDepthType = std::variant<NetworkBuildDepth, int>;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,31 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <ranges>
|
||||
// Required for PrimingReport fields and streaming
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include "fourdst/composition/composition.h"
|
||||
#include "fourdst/composition/atomicSpecies.h"
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
/**
|
||||
* @enum PrimingReportStatus
|
||||
* @brief Enumerates outcome codes for a network priming operation.
|
||||
*
|
||||
* These status codes indicate the reason for success or failure of the priming process:
|
||||
* - FULL_SUCCESS: Priming completed successfully with all species processed.
|
||||
* - NO_SPECIES_TO_PRIME: There were no species eligible for priming.
|
||||
* - MAX_ITERATIONS_REACHED: The algorithm reached its iteration limit without converging.
|
||||
* - FAILED_TO_FINALIZE_COMPOSITION: Unable to build a valid Composition object at end.
|
||||
* - FAILED_TO_FIND_CREATION_CHANNEL: No reaction path found to create the priming species.
|
||||
* - FAILED_TO_FIND_PRIMING_REACTIONS: No reactions containing the priming species were found.
|
||||
* - BASE_NETWORK_TOO_SHALLOW: The provided base network depth was insufficient for priming.
|
||||
*
|
||||
* @see PrimingReport for data associated with each status.
|
||||
*/
|
||||
enum class PrimingReportStatus {
|
||||
FULL_SUCCESS = 0,
|
||||
NO_SPECIES_TO_PRIME = 1,
|
||||
@@ -15,6 +38,12 @@ namespace gridfire {
|
||||
BASE_NETWORK_TOO_SHALLOW = 6
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Mapping from PrimingReportStatus codes to human-readable strings.
|
||||
*
|
||||
* Used when formatting or logging the priming status. No preconditions.
|
||||
* The map contains entries for all PrimingReportStatus values.
|
||||
*/
|
||||
inline std::map<PrimingReportStatus, std::string> PrimingReportStatusStrings = {
|
||||
{PrimingReportStatus::FULL_SUCCESS, "Full Success"},
|
||||
{PrimingReportStatus::NO_SPECIES_TO_PRIME, "No Species to Prime"},
|
||||
@@ -25,12 +54,38 @@ namespace gridfire {
|
||||
{PrimingReportStatus::BASE_NETWORK_TOO_SHALLOW, "Base Network Too Shallow"}
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct PrimingReport
|
||||
* @brief Captures the result of a network priming operation.
|
||||
*
|
||||
* Contains the finalized composition, the changes in mass fractions for species,
|
||||
* a success flag, and a detailed status code.
|
||||
*
|
||||
* @pre A priming algorithm must be executed before constructing a valid report.
|
||||
* @post All fields reflect the outcome of the priming run.
|
||||
*/
|
||||
struct PrimingReport {
|
||||
/** Finalized composition after priming. */
|
||||
fourdst::composition::Composition primedComposition;
|
||||
std::vector<std::pair<fourdst::atomic::Species, double>> massFractionChanges; ///< Species and their destruction/creation rates
|
||||
/**
|
||||
* List of pairs (species, rate change) representing destruction (<0)
|
||||
* or creation (>0) rates of species during priming.
|
||||
*/
|
||||
std::vector<std::pair<fourdst::atomic::Species, double>> massFractionChanges;
|
||||
/** True if priming completed without error. */
|
||||
bool success;
|
||||
/** Detailed status code indicating the result. */
|
||||
PrimingReportStatus status;
|
||||
|
||||
/**
|
||||
* @brief Serialize the report to a stream.
|
||||
*
|
||||
* Formats the success flag and status string into the output stream.
|
||||
* @param os Output stream to write to.
|
||||
* @param report Report to serialize.
|
||||
* @return Reference to the modified output stream.
|
||||
* @post The stream contains a textual representation of the report.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const PrimingReport& report) {
|
||||
std::stringstream ss;
|
||||
const std::string successStr = report.success ? "true" : "false";
|
||||
@@ -39,4 +94,5 @@ namespace gridfire {
|
||||
return os << ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -16,9 +16,39 @@
|
||||
|
||||
namespace gridfire {
|
||||
|
||||
/**
|
||||
* @class NetworkPrimingEngineView
|
||||
* @brief Provides a view of a DynamicEngine filtered to reactions involving a specified priming species.
|
||||
*
|
||||
* This view constructs a subset of the network reactions from the base engine that
|
||||
* contain the given priming species and delegates all engine operations to the underlying engine.
|
||||
*
|
||||
* See implementation in engine_priming.cpp for details on reaction set construction.
|
||||
*
|
||||
* @note Throws std::runtime_error if no priming reactions are found for the species.
|
||||
*/
|
||||
class NetworkPrimingEngineView final : public DefinedEngineView {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the view by looking up the priming species by symbol.
|
||||
*
|
||||
* @param primingSymbol Symbol string of the species to prime.
|
||||
* @param baseEngine Reference to the base DynamicEngine to wrap.
|
||||
* @pre primingSymbol must correspond to a valid species in atomic::species registry.
|
||||
* @post The view will contain only reactions that involve the priming species.
|
||||
* @throws std::out_of_range If primingSymbol is not found in the species registry.
|
||||
* @throws std::runtime_error If no reactions contain the priming species.
|
||||
*/
|
||||
NetworkPrimingEngineView(const std::string& primingSymbol, DynamicEngine& baseEngine);
|
||||
/**
|
||||
* @brief Constructs the view using an existing Species object.
|
||||
*
|
||||
* @param primingSpecies The species object to prime.
|
||||
* @param baseEngine Reference to the base DynamicEngine to wrap.
|
||||
* @pre primingSpecies must be valid and present in the network of baseEngine.
|
||||
* @post The view will contain only reactions that involve the priming species.
|
||||
* @throws std::runtime_error If no reactions contain the priming species.
|
||||
*/
|
||||
NetworkPrimingEngineView(const fourdst::atomic::Species& primingSpecies, DynamicEngine& baseEngine);
|
||||
|
||||
|
||||
@@ -26,6 +56,16 @@ namespace gridfire {
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
fourdst::atomic::Species m_primingSpecies; ///< The priming species, if specified.
|
||||
private:
|
||||
/**
|
||||
* @brief Constructs the set of reaction names that involve the priming species.
|
||||
*
|
||||
* @param primingSpecies Species for which to collect priming reactions.
|
||||
* @param baseEngine Base engine containing the full network of reactions.
|
||||
* @pre baseEngine.getNetworkReactions() returns a valid iterable set of reactions.
|
||||
* @post Returns a vector of unique reaction name strings containing the priming species.
|
||||
* @return Vector of reaction name strings containing the priming species.
|
||||
* @throws std::runtime_error If no reactions involve the priming species.
|
||||
*/
|
||||
std::vector<std::string> constructPrimingReactionSet(
|
||||
const fourdst::atomic::Species& primingSpecies,
|
||||
const DynamicEngine& baseEngine
|
||||
|
||||
@@ -13,21 +13,92 @@
|
||||
|
||||
|
||||
namespace gridfire::partition {
|
||||
class CompositePartitionFunction final : public PartitionFunction {
|
||||
public:
|
||||
explicit CompositePartitionFunction(const std::vector<BasePartitionType>& partitionFunctions);
|
||||
CompositePartitionFunction(const CompositePartitionFunction& other);
|
||||
[[nodiscard]] double evaluate(int z, int a, double T9) const override;
|
||||
[[nodiscard]] double evaluateDerivative(int z, int a, double T9) const override;
|
||||
[[nodiscard]] bool supports(int z, int a) const override;
|
||||
[[nodiscard]] std::string type() const override;
|
||||
[[nodiscard]] std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<CompositePartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
std::vector<std::unique_ptr<PartitionFunction>> m_partitionFunctions; ///< Set of partition functions to use in the composite partition function.
|
||||
private:
|
||||
std::unique_ptr<PartitionFunction> selectPartitionFunction(const BasePartitionType type) const;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @class CompositePartitionFunction
|
||||
* @brief Combines multiple PartitionFunction instances into a single composite strategy.
|
||||
*
|
||||
* Maintains an ordered list of sub-functions and delegates evaluation and derivative calls
|
||||
* to the first function that supports the requested isotope.
|
||||
*
|
||||
* See partition_composite.cpp for details on sub-function selection and error logging.
|
||||
*
|
||||
* @throws std::runtime_error If no sub-function supports a given (z,a,T9) in evaluate or evaluateDerivative.
|
||||
*/
|
||||
class CompositePartitionFunction final : public PartitionFunction {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a composite function from specified types.
|
||||
*
|
||||
* Instantiates sub-functions according to the order of types provided.
|
||||
* @param partitionFunctions List of BasePartitionType identifiers for sub-functions.
|
||||
* @pre partitionFunctions must not be empty.
|
||||
* @post m_partitionFunctions contains instances matching each type.
|
||||
+ */
|
||||
explicit CompositePartitionFunction(const std::vector<BasePartitionType>& partitionFunctions);
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
*
|
||||
* Creates deep clones of the sub-functions in another composite.
|
||||
* @param other Existing composite to copy from.
|
||||
* @post m_partitionFunctions contains clones of other's sub-functions.
|
||||
+ */
|
||||
CompositePartitionFunction(const CompositePartitionFunction& other);
|
||||
/**
|
||||
* @brief Evaluate the composite partition function.
|
||||
*
|
||||
* Calls evaluate on the first sub-function supporting the isotope.
|
||||
* @param z Atomic number (>=1).
|
||||
* @param a Mass number (>=z).
|
||||
* @param T9 Temperature in 10^9 K.
|
||||
* @return Partition function value from supporting sub-function.
|
||||
* @throws std::runtime_error If no sub-function supports (z,a,T9).
|
||||
+ */
|
||||
[[nodiscard]] double evaluate(int z, int a, double T9) const override;
|
||||
/**
|
||||
* @brief Evaluate temperature derivative of the composite function.
|
||||
*
|
||||
* Delegates to the first supporting sub-function's derivative.
|
||||
* @param z Atomic number.
|
||||
* @param a Mass number.
|
||||
* @param T9 Temperature in 10^9 K.
|
||||
* @return d/dT9 of the partition function.
|
||||
* @throws std::runtime_error If no sub-function supports (z,a,T9).
|
||||
+ */
|
||||
[[nodiscard]] double evaluateDerivative(int z, int a, double T9) const override;
|
||||
/**
|
||||
* @brief Check support across all sub-functions.
|
||||
*
|
||||
* @param z Atomic number.
|
||||
* @param a Mass number.
|
||||
* @return true if any sub-function supports (z,a); false otherwise.
|
||||
+ */
|
||||
[[nodiscard]] bool supports(int z, int a) const override;
|
||||
/**
|
||||
* @brief Get composite type identifier.
|
||||
*
|
||||
* Concatenates the type() strings of all sub-functions.
|
||||
* @return A string like "CompositePartitionFunction(func1, func2, ...)".
|
||||
+ */
|
||||
[[nodiscard]] std::string type() const override;
|
||||
/**
|
||||
* @brief Clone this composite partition function.
|
||||
*
|
||||
* @return Unique pointer to a deep copy of this object.
|
||||
+ */
|
||||
[[nodiscard]] std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<CompositePartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
std::vector<std::unique_ptr<PartitionFunction>> m_partitionFunctions; ///< Set of partition functions to use in the composite partition function.
|
||||
private:
|
||||
/**
|
||||
* @brief Instantiate a sub-function by its type.
|
||||
*
|
||||
* @param type Enumeration value selecting the desired function implementation.
|
||||
* @return Unique pointer to a new PartitionFunction instance of the given type.
|
||||
* @throws std::runtime_error If the given type is not recognized.
|
||||
+ */
|
||||
std::unique_ptr<PartitionFunction> selectPartitionFunction(const BasePartitionType type) const;
|
||||
};
|
||||
}
|
||||
@@ -4,13 +4,75 @@
|
||||
#include <memory>
|
||||
|
||||
namespace gridfire::partition {
|
||||
|
||||
/**
|
||||
* @class PartitionFunction
|
||||
* @brief Abstract interface for evaluating nuclear partition functions.
|
||||
*
|
||||
* Provides methods to compute the partition function and its temperature derivative
|
||||
* for a given isotope, to query if the function supports that isotope, and to
|
||||
* clone the function object. Concrete implementations must provide temperature-
|
||||
* dependent statistical models.
|
||||
*/
|
||||
class PartitionFunction {
|
||||
public:
|
||||
/**
|
||||
* @brief Virtual destructor.
|
||||
*
|
||||
* Ensures proper cleanup in derived classes.
|
||||
*/
|
||||
virtual ~PartitionFunction() = default;
|
||||
|
||||
/**
|
||||
* @brief Evaluate the partition function for a given isotope.
|
||||
*
|
||||
* @param z Proton number (atomic number) of the isotope; must be >= 1.
|
||||
* @param a Mass number of the isotope; must be >= z.
|
||||
* @param T9 Temperature in units of 10^9 K; must be > 0.
|
||||
* @return Partition function value (dimensionless) at the specified temperature.
|
||||
* @pre Derived implementation supports (z, a) and T9 > 0.
|
||||
* @post No side effects; pure function.
|
||||
*/
|
||||
[[nodiscard]] virtual double evaluate(int z, int a, double T9) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Evaluate the temperature derivative of the partition function.
|
||||
*
|
||||
* Computes d/dT (partition function) at the given parameters.
|
||||
*
|
||||
* @param z Proton number (atomic number) of the isotope; must be >= 1.
|
||||
* @param a Mass number of the isotope; must be >= z.
|
||||
* @param T9 Temperature in units of 10^9 K; must be > 0.
|
||||
* @return Temperature derivative of the partition function.
|
||||
* @pre Derived implementation supports (z, a) and T9 > 0.
|
||||
* @post No side effects; pure function.
|
||||
*/
|
||||
[[nodiscard]] virtual double evaluateDerivative(int z, int a, double T9) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if this partition function supports an isotope.
|
||||
*
|
||||
* @param z Proton number of the isotope.
|
||||
* @param a Mass number of the isotope.
|
||||
* @return true if evaluate and evaluateDerivative can be called for this isotope; false otherwise.
|
||||
* @post No side effects.
|
||||
*/
|
||||
[[nodiscard]] virtual bool supports(int z, int a) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the human-readable type of this partition function.
|
||||
*
|
||||
* @return String identifier for the partition function implementation.
|
||||
* @post No side effects.
|
||||
*/
|
||||
[[nodiscard]] virtual std::string type() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Create a deep copy of this PartitionFunction.
|
||||
*
|
||||
* @return Unique pointer to a new PartitionFunction instance with identical state.
|
||||
* @post The caller owns the returned object and must manage its lifetime.
|
||||
*/
|
||||
[[nodiscard]] virtual std::unique_ptr<PartitionFunction> clone() const = 0;
|
||||
};
|
||||
}
|
||||
@@ -10,33 +10,99 @@
|
||||
#include "quill/Logger.h"
|
||||
|
||||
namespace gridfire::partition {
|
||||
class GroundStatePartitionFunction final : public PartitionFunction {
|
||||
public:
|
||||
GroundStatePartitionFunction();
|
||||
double evaluate(
|
||||
const int z,
|
||||
const int a,
|
||||
const double T9
|
||||
) const override;
|
||||
double evaluateDerivative(
|
||||
const int z,
|
||||
const int a,
|
||||
const double T9
|
||||
) const override;
|
||||
bool supports(
|
||||
const int z,
|
||||
const int a
|
||||
) const override;
|
||||
std::string type() const override { return "GroundState"; }
|
||||
std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<GroundStatePartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
std::unordered_map<int, double> m_ground_state_spin;
|
||||
static constexpr int make_key(
|
||||
const int z,
|
||||
const int a);
|
||||
};
|
||||
/**
|
||||
* @class GroundStatePartitionFunction
|
||||
* @brief Partition function implementation for nuclear ground states.
|
||||
*
|
||||
* Computes the partition function as (2J + 1) based on the ground state spin J of each isotope.
|
||||
* The temperature derivative is always zero. Ground state spins are loaded from the
|
||||
* fourdst::atomic::species registry at construction.
|
||||
* @see partition_ground.cpp for implementation details.
|
||||
*/
|
||||
class GroundStatePartitionFunction final : public PartitionFunction {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct and populate the ground state spin map.
|
||||
+ *
|
||||
* Loads spins for all isotopes from the atomic species registry into m_ground_state_spin.
|
||||
* @pre atomic::species registry is initialized and non-empty.
|
||||
* @post m_ground_state_spin contains entries for each isotope.
|
||||
+ */
|
||||
GroundStatePartitionFunction();
|
||||
/**
|
||||
* @brief Evaluate the ground state partition function.
|
||||
+ *
|
||||
* @param z Proton number (atomic number) of the isotope; must be >= 1.
|
||||
* @param a Mass number of the isotope; must be >= z.
|
||||
* @param T9 Temperature in units of 10^9 K; unused for ground state.
|
||||
* @pre supports(z,a) returns true.
|
||||
* @post No side effects.
|
||||
* @return Dimensionless partition function value = 2*spin + 1.
|
||||
* @throws std::out_of_range If the isotope key is not found in m_ground_state_spin.
|
||||
+ */
|
||||
double evaluate(
|
||||
const int z,
|
||||
const int a,
|
||||
const double T9
|
||||
) const override;
|
||||
/**
|
||||
* @brief Evaluate the temperature derivative of the ground state partition function.
|
||||
+ *
|
||||
* Always returns zero as ground state has no temperature dependence.
|
||||
* @param z Proton number of the isotope; must be supported.
|
||||
* @param a Mass number of the isotope; must be supported.
|
||||
* @param T9 Temperature in units of 10^9 K; unused.
|
||||
* @pre supports(z,a) returns true.
|
||||
* @post No side effects.
|
||||
* @return Zero.
|
||||
* @throws std::out_of_range If the isotope key is not found.
|
||||
+ */
|
||||
double evaluateDerivative(
|
||||
const int z,
|
||||
const int a,
|
||||
const double T9
|
||||
) const override;
|
||||
/**
|
||||
* @brief Check if ground state data exists for the given isotope.
|
||||
+ *
|
||||
* @param z Proton number of the isotope.
|
||||
* @param a Mass number of the isotope.
|
||||
* @return True if m_ground_state_spin contains the key; false otherwise.
|
||||
* @post No side effects.
|
||||
+ */
|
||||
bool supports(
|
||||
const int z,
|
||||
const int a
|
||||
) const override;
|
||||
/**
|
||||
* @brief Get the type identifier of this partition function.
|
||||
* @return The string literal "GroundState".
|
||||
* @post No side effects.
|
||||
+ */
|
||||
std::string type() const override { return "GroundState"; }
|
||||
/**
|
||||
* @brief Create a deep copy of this partition function.
|
||||
* @return Unique_ptr to a new GroundStatePartitionFunction cloned from this object.
|
||||
* @post Caller owns the returned instance.
|
||||
+ */
|
||||
std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<GroundStatePartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
std::unordered_map<int, double> m_ground_state_spin;
|
||||
/**
|
||||
* @brief Generate a unique lookup key for an isotope.
|
||||
+ *
|
||||
* Combines atomic number z and mass number a into a single integer.
|
||||
* @param z Proton number of the isotope.
|
||||
* @param a Mass number of the isotope; should be < 1000 to avoid collisions.
|
||||
* @pre a < 1000.
|
||||
* @return Integer key = z * 1000 + a.
|
||||
+ */
|
||||
static constexpr int make_key(
|
||||
const int z,
|
||||
const int a);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,29 +12,95 @@
|
||||
#include <memory>
|
||||
|
||||
namespace gridfire::partition {
|
||||
|
||||
/**
|
||||
* @class RauscherThielemannPartitionFunction
|
||||
* @brief Partition function using Rauscher-Thielemann tabulated normalized G-values.
|
||||
*
|
||||
* Loads isotope partition data from embedded records and computes values by
|
||||
* selecting boundary data or interpolating between grid points on a fixed T9 grid.
|
||||
* Implementation in partition_rauscher_thielemann.cpp.
|
||||
*
|
||||
* @throws std::out_of_range If requested isotope data is missing.
|
||||
*/
|
||||
class RauscherThielemannPartitionFunction final : public PartitionFunction {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct and populate partition data.
|
||||
*
|
||||
* Reads embedded RT partition data records and fills m_partitionData.
|
||||
* @pre Embedded data arrays are available and non-empty.
|
||||
* @post m_partitionData contains entries for all isotopes in data.
|
||||
*/
|
||||
RauscherThielemannPartitionFunction();
|
||||
/**
|
||||
* @brief Evaluate partition function for isotope at temperature.
|
||||
*
|
||||
* Retrieves boundary or interpolated normalized G-value and scales by (2J+1).
|
||||
* @param z Atomic number of the isotope (>=1).
|
||||
* @param a Mass number of the isotope (>=z).
|
||||
* @param T9 Temperature in units of 10^9 K.
|
||||
* @return Dimensionless partition function.
|
||||
* @pre supports(z,a) returns true.
|
||||
* @post No side effects.
|
||||
* @throws std::out_of_range If isotope key not found in m_partitionData.
|
||||
*/
|
||||
double evaluate(int z, int a, double T9) const override;
|
||||
/**
|
||||
* @brief Evaluate temperature derivative of partition function.
|
||||
*
|
||||
* Zero at grid extremes; otherwise derivative of linear interpolation.
|
||||
* @param z Atomic number (>=1).
|
||||
* @param a Mass number (>=z).
|
||||
* @param T9 Temperature in 10^9 K.
|
||||
* @return d(PartitionFunction)/dT9.
|
||||
* @pre supports(z,a) returns true.
|
||||
* @post No side effects.
|
||||
* @throws std::out_of_range If isotope data is missing.
|
||||
*/
|
||||
double evaluateDerivative(int z, int a, double T9) const override;
|
||||
/**
|
||||
* @brief Check if partition data exists for given isotope.
|
||||
* @param z Atomic number.
|
||||
* @param a Mass number.
|
||||
* @return true if data available; false otherwise.
|
||||
* @post No side effects.
|
||||
*/
|
||||
bool supports(int z, int a) const override;
|
||||
/**
|
||||
* @brief Get type identifier for this partition function.
|
||||
* @return Literal string "RauscherThielemann".
|
||||
* @post No side effects.
|
||||
*/
|
||||
std::string type() const override { return "RauscherThielemann"; }
|
||||
/**
|
||||
* @brief Clone this partition function instance.
|
||||
* @return Unique pointer to a copy of this object.
|
||||
* @post Caller owns the returned object.
|
||||
*/
|
||||
std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<RauscherThielemannPartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* @enum Bounds
|
||||
* @brief Indicator for temperature grid bound position.
|
||||
*/
|
||||
enum Bounds {
|
||||
FRONT,
|
||||
BACK,
|
||||
MIDDLE
|
||||
FRONT, ///< Below first grid point
|
||||
BACK, ///< Above last grid point
|
||||
MIDDLE ///< Between grid points
|
||||
};
|
||||
private:
|
||||
struct IsotopeData {
|
||||
double ground_state_spin;
|
||||
std::array<double, 24> normalized_g_values;
|
||||
double ground_state_spin; ///< Spin of the isotope ground state
|
||||
std::array<double, 24> normalized_g_values; ///< Normalized G values on RT grid
|
||||
};
|
||||
struct InterpolationPoints {
|
||||
double T9_high;
|
||||
double G_norm_high;
|
||||
double T9_low;
|
||||
double G_norm_low;
|
||||
double T9_high; ///< Upper temperature bound
|
||||
double G_norm_high; ///< Normalized G at upper bound
|
||||
double T9_low; ///< Lower temperature bound
|
||||
double G_norm_low; ///< Normalized G at lower bound
|
||||
};
|
||||
struct IdentifiedIsotope {
|
||||
Bounds bound;
|
||||
@@ -42,19 +108,38 @@ namespace gridfire::partition {
|
||||
size_t upperIndex;
|
||||
size_t lowerIndex;
|
||||
};
|
||||
std::unique_ptr<PartitionFunction> clone() const override {
|
||||
return std::make_unique<RauscherThielemannPartitionFunction>(*this);
|
||||
}
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
std::unordered_map<int, IsotopeData> m_partitionData;
|
||||
std::unordered_map<int, IsotopeData> m_partitionData; ///< Map of isotope key to data
|
||||
private:
|
||||
/**
|
||||
* @brief Get interpolation points from normalized G array.
|
||||
* @param upper_index Index of upper grid point.
|
||||
* @param lower_index Index of lower grid point.
|
||||
* @param normalized_g_values Array of normalized G values.
|
||||
* @return InterpolationPoints containing bounds and G values.
|
||||
*/
|
||||
static InterpolationPoints get_interpolation_points(
|
||||
const size_t upper_index,
|
||||
const size_t lower_index,
|
||||
const std::array<double, 24>& normalized_g_values
|
||||
);
|
||||
/**
|
||||
* @brief Identify isotope entry and grid indices for given T9.
|
||||
* @param z Atomic number of isotope.
|
||||
* @param a Mass number of isotope.
|
||||
* @param T9 Temperature in 10^9 K.
|
||||
* @return IdentifiedIsotope with data reference and indices.
|
||||
* @throws std::out_of_range If isotope not found in m_partitionData.
|
||||
*/
|
||||
IdentifiedIsotope find(int z, int a, double T9) const;
|
||||
/**
|
||||
* @brief Generate integer key for isotope (z,a).
|
||||
* @param z Atomic number.
|
||||
* @param a Mass number (<1000).
|
||||
* @return Key computed as z*1000 + a.
|
||||
*/
|
||||
static constexpr int make_key(int z, int a);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,18 +4,44 @@
|
||||
#include <string>
|
||||
|
||||
namespace gridfire::partition {
|
||||
|
||||
/**
|
||||
* @enum BasePartitionType
|
||||
* @brief Enumerates available partition function implementations.
|
||||
*
|
||||
* RauscherThielemann: Uses tabulated normalized G-values and linear interpolation.
|
||||
* GroundState: Uses ground state spin (J) to compute partition function as 2J+1.
|
||||
*/
|
||||
enum BasePartitionType {
|
||||
RauscherThielemann, ///< Rauscher-Thielemann partition function
|
||||
GroundState, ///< Ground state partition function
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Mapping from BasePartitionType enum to human-readable string.
|
||||
*
|
||||
* Used for logging, reporting, or serialization. Ensure that all enum values
|
||||
* are represented in this map.
|
||||
* @pre Contains entries for all values of BasePartitionType.
|
||||
* @post Can convert BasePartitionType to corresponding string.
|
||||
*/
|
||||
inline std::unordered_map<BasePartitionType, std::string> basePartitionTypeToString = {
|
||||
{RauscherThielemann, "RauscherThielemann"},
|
||||
{GroundState, "GroundState"}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Mapping from string to BasePartitionType enum.
|
||||
*
|
||||
* Used for parsing configuration or user input. Strings must match exactly
|
||||
* to one of the defined partition types.
|
||||
* @pre Uses keys that exactly match the outputs of basePartitionTypeToString.
|
||||
* @post Can convert valid string identifiers back to BasePartitionType.
|
||||
* @throws std::out_of_range if accessed with a non-existing key via at().
|
||||
*/
|
||||
inline std::unordered_map<std::string, BasePartitionType> stringToBasePartitionType = {
|
||||
{"RauscherThielemann", RauscherThielemann},
|
||||
{"GroundState", GroundState}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -4,6 +4,16 @@
|
||||
|
||||
namespace gridfire::partition::record {
|
||||
#pragma pack(push, 1)
|
||||
/**
|
||||
* @struct RauscherThielemannPartitionDataRecord
|
||||
* @brief Packed binary record of Rauscher-Thielemann partition function data for an isotope.
|
||||
*
|
||||
* Each record stores the atomic number (Z), mass number (A), ground state spin J,
|
||||
* and an array of 24 normalized G-values corresponding to fixed temperature grid points.
|
||||
* This struct is read directly from embedded binary data and must remain tightly packed.
|
||||
*
|
||||
* @note Alignment is set to 1 byte to match the binary layout.
|
||||
*/
|
||||
struct RauscherThielemannPartitionDataRecord {
|
||||
uint32_t z; ///< Atomic number
|
||||
uint32_t a; ///< Mass number
|
||||
|
||||
@@ -667,20 +667,6 @@ namespace gridfire {
|
||||
}
|
||||
adInput[numSpecies] = T9; // T9
|
||||
adInput[numSpecies + 1] = rho; // rho
|
||||
// LOG_DEBUG(
|
||||
// m_logger,
|
||||
// "AD Input to jacobian {}",
|
||||
// [&]() -> std::string {
|
||||
// std::stringstream ss;
|
||||
// ss << std::scientific << std::setprecision(5);
|
||||
// for (size_t i = 0; i < adInput.size(); ++i) {
|
||||
// ss << adInput[i];
|
||||
// if (i < adInput.size() - 1) {
|
||||
// ss << ", ";
|
||||
// }
|
||||
// }
|
||||
// return ss.str();
|
||||
// }());
|
||||
|
||||
// 2. Calculate the full jacobian
|
||||
const std::vector<double> dotY = m_rhsADFun.Jacobian(adInput);
|
||||
@@ -695,31 +681,6 @@ namespace gridfire {
|
||||
}
|
||||
}
|
||||
}
|
||||
// LOG_DEBUG(
|
||||
// m_logger,
|
||||
// "Final Jacobian is:\n{}",
|
||||
// [&]() -> std::string {
|
||||
// std::stringstream ss;
|
||||
// ss << std::scientific << std::setprecision(5);
|
||||
// for (size_t i = 0; i < m_jacobianMatrix.size1(); ++i) {
|
||||
// ss << getNetworkSpecies()[i].name();
|
||||
// if (i < m_jacobianMatrix.size1() - 1) {
|
||||
// ss << ", ";
|
||||
// }
|
||||
// }
|
||||
// ss << "\n";
|
||||
// for (size_t i = 0; i < m_jacobianMatrix.size1(); ++i) {
|
||||
// ss << getNetworkSpecies()[i].name() << ": ";
|
||||
// for (size_t j = 0; j < m_jacobianMatrix.size2(); ++j) {
|
||||
// ss << m_jacobianMatrix(i, j);
|
||||
// if (j < m_jacobianMatrix.size2() - 1) {
|
||||
// ss << ", ";
|
||||
// }
|
||||
// }
|
||||
// ss << "\n";
|
||||
// }
|
||||
// return ss.str();
|
||||
// }());
|
||||
LOG_TRACE_L1_LIMIT_EVERY_N(1000, m_logger, "Jacobian matrix generated with dimensions: {} rows x {} columns.", m_jacobianMatrix.size1(), m_jacobianMatrix.size2());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user