From 4d6d2ca1ab40ecee1577f7eabd5d70a040848bbb Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu> Date: Mon, 13 Jun 2022 14:28:58 +0200 Subject: [PATCH] made sibyll::NuclearInteractionModel less dependent on environment template --- .../sibyll/NuclearInteractionModel.inl | 42 +++++++++---------- corsika/modules/Sibyll.hpp | 9 ++-- .../sibyll/NuclearInteractionModel.hpp | 9 ++-- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/corsika/detail/modules/sibyll/NuclearInteractionModel.inl b/corsika/detail/modules/sibyll/NuclearInteractionModel.inl index cc12434f2..478e375e1 100644 --- a/corsika/detail/modules/sibyll/NuclearInteractionModel.inl +++ b/corsika/detail/modules/sibyll/NuclearInteractionModel.inl @@ -19,28 +19,27 @@ namespace corsika::sibyll { - template <typename TEnvironment, typename TNucleonModel> - inline NuclearInteractionModel<TEnvironment, TNucleonModel>::NuclearInteractionModel( + template <typename TNucleonModel> + template <typename TEnvironment> + inline NuclearInteractionModel<TNucleonModel>::NuclearInteractionModel( TNucleonModel& hadint, TEnvironment const& env) - : environment_(env) - , hadronicInteraction_(hadint) { + : hadronicInteraction_(hadint) { // initialize nuclib // TODO: make sure this does not overlap with sibyll nuc_nuc_ini_(); // initialize cross sections - initializeNuclearCrossSections(); + initializeNuclearCrossSections(env); } - template <typename TEnvironment, typename TNucleonModel> - inline NuclearInteractionModel<TEnvironment, - TNucleonModel>::~NuclearInteractionModel() { + template <typename TNucleonModel> + inline NuclearInteractionModel<TNucleonModel>::~NuclearInteractionModel() { CORSIKA_LOG_DEBUG("Nuclib::NuclearInteractionModel n={} Nnuc={}", count_, nucCount_); } - template <typename TEnvironment, typename TNucleonModel> - inline bool constexpr NuclearInteractionModel<TEnvironment, TNucleonModel>::isValid( + template <typename TNucleonModel> + inline bool constexpr NuclearInteractionModel<TNucleonModel>::isValid( Code const projectileId, Code const targetId, HEPEnergyType const sqrtSnn) const { // also depends on underlying model, for Proton/Neutron projectile @@ -53,9 +52,9 @@ namespace corsika::sibyll { return true; } // namespace corsika::sibyll - template <typename TEnvironment, typename TNucleonModel> + template <typename TNucleonModel> inline void - NuclearInteractionModel<TEnvironment, TNucleonModel>::printCrossSectionTable( + NuclearInteractionModel<TNucleonModel>::printCrossSectionTable( Code const pCode) const { if (!hadronicInteraction_.isValid(Code::Proton, pCode, 100_GeV)) { // LCOV_EXCL_START CORSIKA_LOG_ERROR("Invalid target type {} for hadron interaction model.", pCode); @@ -85,11 +84,12 @@ namespace corsika::sibyll { CORSIKA_LOG_DEBUG(table.str()); } - template <typename TEnvironment, typename TNucleonModel> + template <typename TNucleonModel> + template <typename TEnvironment> inline void - NuclearInteractionModel<TEnvironment, TNucleonModel>::initializeNuclearCrossSections() { + NuclearInteractionModel<TNucleonModel>::initializeNuclearCrossSections(TEnvironment const& environment) { - auto& universe = *(environment_.getUniverse()); + auto const& universe = *(environment.getUniverse()); // generate complete list of all nuclei types in universe auto const allElementsInUniverse = std::invoke([&]() { @@ -157,9 +157,9 @@ namespace corsika::sibyll { for (auto& ptarg : allElementsInUniverse) { printCrossSectionTable(ptarg); } } - template <typename TEnvironment, typename TNucleonModel> + template <typename TNucleonModel> inline CrossSectionType - NuclearInteractionModel<TEnvironment, TNucleonModel>::readCrossSectionTable( + NuclearInteractionModel<TNucleonModel>::readCrossSectionTable( int const ia, Code const pTarget, HEPEnergyType const elabnuc) const { int const ib = targetComponentsIndex_.at(pTarget) + 1; // table index in fortran @@ -175,9 +175,9 @@ namespace corsika::sibyll { return sig * 1_mb; } - template <typename TEnvironment, typename TNucleonModel> + template <typename TNucleonModel> CrossSectionType inline NuclearInteractionModel< - TEnvironment, TNucleonModel>::getCrossSection(Code const projectileId, + TNucleonModel>::getCrossSection(Code const projectileId, Code const targetId, FourMomentum const& projectileP4, FourMomentum const& targetP4) const { @@ -192,9 +192,9 @@ namespace corsika::sibyll { return sigProd; } - template <typename TEnvironment, typename TNucleonModel> + template <typename TNucleonModel> template <typename TSecondaryView> - inline void NuclearInteractionModel<TEnvironment, TNucleonModel>::doInteraction( + inline void NuclearInteractionModel<TNucleonModel>::doInteraction( TSecondaryView& view, Code const projectileId, Code const targetId, FourMomentum const& projectileP4, FourMomentum const& targetP4) { diff --git a/corsika/modules/Sibyll.hpp b/corsika/modules/Sibyll.hpp index d01692871..19f22170f 100644 --- a/corsika/modules/Sibyll.hpp +++ b/corsika/modules/Sibyll.hpp @@ -41,13 +41,14 @@ namespace corsika::sibyll { * The sibyll::NuclearInteractionModel is wrapped as an InteractionProcess here in order * to provide all the functions for ProcessSequence. */ - template <class TEnvironment, class TNucleonModel> + template <class TNucleonModel> class NuclearInteraction - : public NuclearInteractionModel<TEnvironment, TNucleonModel>, - public InteractionProcess<NuclearInteraction<TEnvironment, TNucleonModel>> { + : public NuclearInteractionModel<TNucleonModel>, + public InteractionProcess<NuclearInteraction<TNucleonModel>> { public: + template <typename TEnvironment> NuclearInteraction(TNucleonModel& model, TEnvironment const& env) - : NuclearInteractionModel<TEnvironment, TNucleonModel>(model, env) {} + : NuclearInteractionModel<TNucleonModel>{model, env} {} }; } // namespace corsika::sibyll diff --git a/corsika/modules/sibyll/NuclearInteractionModel.hpp b/corsika/modules/sibyll/NuclearInteractionModel.hpp index 2d7d81c2c..6b6f46b3b 100644 --- a/corsika/modules/sibyll/NuclearInteractionModel.hpp +++ b/corsika/modules/sibyll/NuclearInteractionModel.hpp @@ -22,17 +22,21 @@ namespace corsika::sibyll { * * @tparam TNucleonModel */ - template <class TEnvironment, class TNucleonModel> + template <class TNucleonModel> class NuclearInteractionModel { public: + template <class TEnvironment> NuclearInteractionModel(TNucleonModel&, TEnvironment const&); + ~NuclearInteractionModel(); bool constexpr isValid(Code const projectileId, Code const targetId, HEPEnergyType const sqrtSnn) const; - void initializeNuclearCrossSections(); + template <class TEnvironment> + void initializeNuclearCrossSections(TEnvironment const&); + void printCrossSectionTable(Code) const; CrossSectionType readCrossSectionTable(int const, Code const, HEPEnergyType const) const; @@ -56,7 +60,6 @@ namespace corsika::sibyll { int count_ = 0; int nucCount_ = 0; - TEnvironment const& environment_; TNucleonModel& hadronicInteraction_; std::map<Code, int> targetComponentsIndex_; default_prng_type& RNG_ = RNGManager<>::getInstance().getRandomStream("sibyll"); -- GitLab