feat(GraphNetwork): started templating for auto diff
This commit is contained in:
@@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace serif::network {
|
namespace serif::network {
|
||||||
GraphNetwork::GraphNetwork(
|
template <typename GeneralScalarType>
|
||||||
|
GraphNetwork<GeneralScalarType>::GraphNetwork(
|
||||||
const serif::composition::Composition &composition
|
const serif::composition::Composition &composition
|
||||||
):
|
):
|
||||||
Network(REACLIB),
|
Network(REACLIB),
|
||||||
@@ -32,7 +33,8 @@ namespace serif::network {
|
|||||||
syncInternalMaps();
|
syncInternalMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphNetwork::GraphNetwork(
|
template <typename GeneralScalarType>
|
||||||
|
GraphNetwork<GeneralScalarType>::GraphNetwork(
|
||||||
const serif::composition::Composition &composition,
|
const serif::composition::Composition &composition,
|
||||||
const double cullingThreshold,
|
const double cullingThreshold,
|
||||||
const double T9
|
const double T9
|
||||||
@@ -46,14 +48,16 @@ namespace serif::network {
|
|||||||
syncInternalMaps();
|
syncInternalMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphNetwork::syncInternalMaps() {
|
template <typename GeneralScalarType>
|
||||||
|
void GraphNetwork<GeneralScalarType>::syncInternalMaps() {
|
||||||
collectNetworkSpecies();
|
collectNetworkSpecies();
|
||||||
populateReactionIDMap();
|
populateReactionIDMap();
|
||||||
populateSpeciesToIndexMap();
|
populateSpeciesToIndexMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Network Graph Construction Methods ---
|
// --- Network Graph Construction Methods ---
|
||||||
void GraphNetwork::collectNetworkSpecies() {
|
template <typename GeneralScalarType>
|
||||||
|
void GraphNetwork<GeneralScalarType>::collectNetworkSpecies() {
|
||||||
m_networkSpecies.clear();
|
m_networkSpecies.clear();
|
||||||
m_networkSpeciesMap.clear();
|
m_networkSpeciesMap.clear();
|
||||||
|
|
||||||
@@ -81,7 +85,8 @@ namespace serif::network {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphNetwork::populateReactionIDMap() {
|
template <typename GeneralScalarType>
|
||||||
|
void GraphNetwork<GeneralScalarType>::populateReactionIDMap() {
|
||||||
LOG_INFO(m_logger, "Populating reaction ID map for REACLIB graph network (serif::network::GraphNetwork)...");
|
LOG_INFO(m_logger, "Populating reaction ID map for REACLIB graph network (serif::network::GraphNetwork)...");
|
||||||
m_reactionIDMap.clear();
|
m_reactionIDMap.clear();
|
||||||
for (const auto& reaction: m_reactions) {
|
for (const auto& reaction: m_reactions) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
// REACLIBReactions are quite large data structures, so this could be a performance bottleneck.
|
// REACLIBReactions are quite large data structures, so this could be a performance bottleneck.
|
||||||
|
|
||||||
namespace serif::network {
|
namespace serif::network {
|
||||||
|
template <typename GeneralScalarType>
|
||||||
class GraphNetwork final : public Network {
|
class GraphNetwork final : public Network {
|
||||||
public:
|
public:
|
||||||
explicit GraphNetwork(const serif::composition::Composition &composition);
|
explicit GraphNetwork(const serif::composition::Composition &composition);
|
||||||
@@ -38,15 +39,15 @@ namespace serif::network {
|
|||||||
reaclib::REACLIBReactionSet m_reactions; ///< Set of REACLIB reactions for the network.
|
reaclib::REACLIBReactionSet m_reactions; ///< Set of REACLIB reactions for the network.
|
||||||
serif::composition::Composition m_initialComposition;
|
serif::composition::Composition m_initialComposition;
|
||||||
serif::composition::Composition m_currentComposition;
|
serif::composition::Composition m_currentComposition;
|
||||||
double m_cullingThreshold; ///< Threshold for culling reactions.
|
GeneralScalarType m_cullingThreshold; ///< Threshold for culling reactions.
|
||||||
double m_T9; ///< Temperature in T9 units to evaluate culling.
|
GeneralScalarType m_T9; ///< Temperature in T9 units to evaluate culling.
|
||||||
|
|
||||||
std::vector<serif::atomic::Species> m_networkSpecies; ///< The species in the network.
|
std::vector<serif::atomic::Species> m_networkSpecies; ///< The species in the network.
|
||||||
std::unordered_map<std::string_view, serif::atomic::Species> m_networkSpeciesMap;
|
std::unordered_map<std::string_view, serif::atomic::Species> m_networkSpeciesMap;
|
||||||
std::unordered_map<std::string_view, const reaclib::REACLIBReaction> m_reactionIDMap; ///< Map of reaction IDs to REACLIB reactions.
|
std::unordered_map<std::string_view, const reaclib::REACLIBReaction> m_reactionIDMap; ///< Map of reaction IDs to REACLIB reactions.
|
||||||
|
|
||||||
boost::numeric::ublas::compressed_matrix<int> m_stoichiometryMatrix; ///< Stoichiometry matrix for the network.
|
boost::numeric::ublas::compressed_matrix<int> m_stoichiometryMatrix; ///< Stoichiometry matrix for the network.
|
||||||
boost::numeric::ublas::compressed_matrix<double> m_jacobianMatrix; ///< Jacobian matrix for the network.
|
boost::numeric::ublas::compressed_matrix<GeneralScalarType> m_jacobianMatrix; ///< Jacobian matrix for the network.
|
||||||
std::unordered_map<serif::atomic::Species, size_t> m_speciesToIndexMap; ///< Map of species to their index in the stoichiometry matrix.
|
std::unordered_map<serif::atomic::Species, size_t> m_speciesToIndexMap; ///< Map of species to their index in the stoichiometry matrix.
|
||||||
|
|
||||||
|
|
||||||
@@ -62,8 +63,8 @@ namespace serif::network {
|
|||||||
void generateStoichiometryMatrix();
|
void generateStoichiometryMatrix();
|
||||||
void generateJacobianMatrix();
|
void generateJacobianMatrix();
|
||||||
|
|
||||||
std::vector<double> calculateRHS(const std::vector<double>& Y, const double T9, const double rho) const;
|
std::vector<GeneralScalarType> calculateRHS(const std::vector<GeneralScalarType>& Y, const GeneralScalarType T9, const GeneralScalarType rho) const;
|
||||||
double calculateReactionRate(const reaclib::REACLIBReaction &reaction, const std::vector<double>& Y, const double T9, const double rho) const;
|
GeneralScalarType calculateReactionRate(const reaclib::REACLIBReaction &reaction, const std::vector<GeneralScalarType>& Y, const GeneralScalarType T9, const GeneralScalarType rho) const;
|
||||||
|
|
||||||
void pruneNetworkGraph();
|
void pruneNetworkGraph();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user