feat(GridFire): Added a number of python hooks
python hooks to make getting base composition more reliable; further, a number of small changes made to aid in my analysis in response to ref report 1
This commit is contained in:
@@ -58,6 +58,8 @@ namespace gridfire::solver {
|
||||
const size_t currentNonlinearIterations; ///< Total number of non-linear iterations
|
||||
const std::map<fourdst::atomic::Species, std::unordered_map<std::string, double>>& reactionContributionMap; ///< Map of reaction contributions for the current step
|
||||
engine::scratch::StateBlob& state_ctx; ///< Reference to the engine scratch state blob
|
||||
double current_total_energy = 0.0; ///< Current energy generation rate [erg/g/s]
|
||||
double current_neutrino_energy_loss_rate = 0.0; ///< Current neutrino energy loss rate [erg/g/s]
|
||||
|
||||
PointSolverTimestepContext(
|
||||
double t,
|
||||
@@ -76,6 +78,8 @@ namespace gridfire::solver {
|
||||
);
|
||||
|
||||
[[nodiscard]] std::vector<std::tuple<std::string, std::string>> describe() const override;
|
||||
|
||||
[[nodiscard]] fourdst::composition::Composition getPhysicalComposition() const;
|
||||
};
|
||||
|
||||
using TimestepCallback = std::function<void(const PointSolverTimestepContext& context)>; ///< Type alias for a timestep callback function.
|
||||
@@ -169,6 +173,13 @@ namespace gridfire::solver {
|
||||
const engine::DynamicEngine& engine
|
||||
);
|
||||
|
||||
PointSolver(
|
||||
const engine::DynamicEngine& engine,
|
||||
const config::GridFireConfig& config
|
||||
);
|
||||
|
||||
|
||||
config::GridFireConfig getConfig() const { return *m_config; }
|
||||
/**
|
||||
* @brief Integrate from t=0 to netIn.tMax and return final composition and energy.
|
||||
*
|
||||
@@ -264,6 +275,17 @@ namespace gridfire::solver {
|
||||
*/
|
||||
static int cvode_jac_wrapper(sunrealtype t, N_Vector y, N_Vector ydot, SUNMatrix J, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
|
||||
|
||||
/**
|
||||
* @brief CVODE error handler that logs errors and warnings from SUNDIALS using the solver's logger.
|
||||
* @param line
|
||||
* @param func
|
||||
* @param file
|
||||
* @param msg
|
||||
* @param err_code
|
||||
* @param err_user_data
|
||||
* @param sunctx
|
||||
*/
|
||||
static void cvode_error_handler(int line, const char *func, const char *file, const char *msg, SUNErrCode err_code, void *err_user_data, SUNContext sunctx);
|
||||
/**
|
||||
* @brief Compute RHS into ydot at time t from the engine and current state y.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "gridfire/trigger/trigger_result.h"
|
||||
#include "gridfire/solver/strategies/PointSolver.h"
|
||||
#include "fourdst/logging/logging.h"
|
||||
#include "gridfire/config/config.h"
|
||||
|
||||
#include <string>
|
||||
#include <deque>
|
||||
@@ -316,6 +317,46 @@ namespace gridfire::trigger::solver::CVODE {
|
||||
bool rel_failure(const gridfire::solver::PointSolverTimestepContext& ctx) const;
|
||||
};
|
||||
|
||||
class BoundaryFluxTrigger final : public Trigger<gridfire::solver::PointSolverTimestepContext> {
|
||||
public:
|
||||
explicit BoundaryFluxTrigger(double relativeThreshold, double absoluteThreshold);
|
||||
bool check(const gridfire::solver::PointSolverTimestepContext &ctx) const override;
|
||||
void update(const gridfire::solver::PointSolverTimestepContext &ctx) override;
|
||||
void step(const gridfire::solver::PointSolverTimestepContext &ctx) override;
|
||||
void reset() override;
|
||||
|
||||
std::string name() const override;
|
||||
TriggerResult why(const gridfire::solver::PointSolverTimestepContext &ctx) const override;
|
||||
std::string describe() const override;
|
||||
size_t numTriggers() const override;
|
||||
size_t numMisses() const override;
|
||||
private:
|
||||
enum class ReactionSetType : uint8_t {
|
||||
ACTIVE,
|
||||
INACTIVE
|
||||
};
|
||||
|
||||
static double get_reaction_set_flow(
|
||||
const reaction::ReactionSet& reactions,
|
||||
const gridfire::solver::PointSolverTimestepContext& ctx,
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho,
|
||||
ReactionSetType type
|
||||
);
|
||||
private:
|
||||
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
|
||||
mutable size_t m_hits = 0;
|
||||
mutable size_t m_misses = 0;
|
||||
mutable size_t m_updates = 0;
|
||||
mutable size_t m_resets = 0;
|
||||
|
||||
double m_relativeThreshold;
|
||||
double m_absoluteThreshold;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Compose a trigger suitable for deciding engine re-partitioning during CVODE solves.
|
||||
*
|
||||
@@ -329,18 +370,9 @@ namespace gridfire::trigger::solver::CVODE {
|
||||
* See engine_partitioning_trigger.cpp for construction details using OrTrigger and
|
||||
* EveryNthTrigger from trigger_logical.h.
|
||||
*
|
||||
* @param simulationTimeInterval Interval used by SimulationTimeTrigger (> 0).
|
||||
* @param offDiagonalThreshold Off-diagonal Jacobian magnitude threshold (>= 0).
|
||||
* @param timestepCollapseRatio Threshold for timestep deviation (>= 0, and <= 1 when relative).
|
||||
* @param maxConvergenceFailures Window size for timestep averaging (>= 1 recommended).
|
||||
* @return A unique_ptr to a composed Trigger<TimestepContext> implementing the policy above.
|
||||
*
|
||||
* @note The exact policy is subject to change; this function centralizes that decision.
|
||||
*/
|
||||
std::unique_ptr<Trigger<gridfire::solver::PointSolverTimestepContext>> makeEnginePartitioningTrigger(
|
||||
double simulationTimeInterval,
|
||||
double offDiagonalThreshold,
|
||||
double timestepCollapseRatio,
|
||||
size_t maxConvergenceFailures
|
||||
);
|
||||
std::unique_ptr<Trigger<gridfire::solver::PointSolverTimestepContext>> makeEnginePartitioningTrigger(const config::TriggerConfig& cfg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user