CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
DynamicInteractionProcess.hpp
1 /*
2  * (c) Copyright 2023 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
13 #include <corsika/framework/process/InteractionProcess.hpp>
15 
16 #include <boost/type_index.hpp>
17 
18 #include <memory>
19 
20 namespace corsika {
21 
30  template <typename TStack>
32  : InteractionProcess<DynamicInteractionProcess<TStack>> {
33  public:
34  using stack_view_type = typename TStack::stack_view_type;
35 
36  DynamicInteractionProcess() = default;
37 
44  template <typename TInteractionProcess>
45  DynamicInteractionProcess(std::shared_ptr<TInteractionProcess> obj)
46  : concept_{std::make_unique<ConcreteModel<TInteractionProcess>>(std::move(obj))} {
47  CORSIKA_LOG_DEBUG("creating DynamicInteractionProcess from {}",
48  boost::typeindex::type_id<TInteractionProcess>().pretty_name());
49 
50  // poor man's check while we don't have C++20 concepts
51  static_assert(is_interaction_process_v<TInteractionProcess>);
52 
53  // since we only forward interaction process API, all other types of corsika
54  // processes are prohibited
55  static_assert(!is_continuous_process_v<TInteractionProcess>);
56  static_assert(!is_decay_process_v<TInteractionProcess>);
57  static_assert(!is_stack_process_v<TInteractionProcess>);
58  static_assert(!is_cascade_equations_process_v<TInteractionProcess>);
59  static_assert(!is_secondaries_process_v<TInteractionProcess>);
60  static_assert(!is_boundary_process_v<TInteractionProcess>);
61  static_assert(!is_cascade_equations_process_v<TInteractionProcess>);
62  }
63 
65  void doInteraction(stack_view_type& view, Code projectileId, Code targetId,
66  FourMomentum const& projectileP4, FourMomentum const& targetP4) {
67  return concept_->doInteraction(view, projectileId, targetId, projectileP4,
68  targetP4);
69  }
70 
72  CrossSectionType getCrossSection(Code projectileId, Code targetId,
73  FourMomentum const& projectileP4,
74  FourMomentum const& targetP4) const {
75  return concept_->getCrossSection(projectileId, targetId, projectileP4, targetP4);
76  }
77 
78  private:
79  struct IInteractionModel {
80  virtual ~IInteractionModel() = default;
81  virtual void doInteraction(stack_view_type&, Code, Code, FourMomentum const&,
82  FourMomentum const&) = 0;
83  virtual CrossSectionType getCrossSection(Code, Code, FourMomentum const&,
84  FourMomentum const&) const = 0;
85  };
86 
87  template <typename TModel>
88  struct ConcreteModel final : IInteractionModel {
89  ConcreteModel(std::shared_ptr<TModel> obj) noexcept
90  : model_{std::move(obj)} {}
91 
92  void doInteraction(stack_view_type& view, Code projectileId, Code targetId,
93  FourMomentum const& projectileP4,
94  FourMomentum const& targetP4) override {
95  return model_->doInteraction(view, projectileId, targetId, projectileP4,
96  targetP4);
97  }
98 
99  CrossSectionType getCrossSection(Code projectileId, Code targetId,
100  FourMomentum const& projectileP4,
101  FourMomentum const& targetP4) const override {
102  return model_->getCrossSection(projectileId, targetId, projectileP4, targetP4);
103  }
104 
105  private:
106  std::shared_ptr<TModel> model_;
107  };
108 
109  std::unique_ptr<IInteractionModel> concept_;
110  };
111 } // namespace corsika
Import and extend the phys::units package.
DynamicInteractionProcess(std::shared_ptr< TInteractionProcess > obj)
Create new DynamicInteractionProcess.
This class allows selecting/using different InteractionProcesses at runtime without recompiling the p...
CORSIKA8 logging utilities.
Description of physical four-vectors.
Definition: FourVector.hpp:51
`, since they are used everywhere as integral part of the framework.
CrossSectionType getCrossSection(Code projectileId, Code targetId, FourMomentum const &projectileP4, FourMomentum const &targetP4) const
forwards arguments to getCrossSection() of wrapped instance
Interface to particle properties.
void doInteraction(stack_view_type &view, Code projectileId, Code targetId, FourMomentum const &projectileP4, FourMomentum const &targetP4)
forwards arguments to doInteraction() of wrapped instance
Process describing the interaction of particles.
General FourVector object.