CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
SwitchProcessSequence.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2018 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 
9 #pragma once
10 
17 #include <corsika/framework/process/BoundaryCrossingProcess.hpp>
18 #include <corsika/framework/process/ContinuousProcess.hpp>
19 #include <corsika/framework/process/ContinuousProcessIndex.hpp>
20 #include <corsika/framework/process/ContinuousProcessStepLength.hpp>
21 #include <corsika/framework/process/DecayProcess.hpp>
22 #include <corsika/framework/process/InteractionProcess.hpp>
24 #include <corsika/framework/process/SecondariesProcess.hpp>
25 #include <corsika/framework/process/StackProcess.hpp>
27 #include <corsika/framework/core/Step.hpp>
29 
30 #include <cmath>
31 #include <limits>
32 #include <type_traits>
33 
34 namespace corsika {
35 
76  template <typename TCondition, typename TSequence, typename USequence,
77  int IndexFirstProcess = 0,
78  int IndexOfProcess1 = count_processes<TSequence, IndexFirstProcess>::count,
79  int IndexOfProcess2 = count_processes<USequence, IndexOfProcess1>::count>
81  : public BaseProcess<SwitchProcessSequence<TCondition, TSequence, USequence>> {
82 
83  using process1_type = typename std::decay_t<TSequence>;
84  using process2_type = typename std::decay_t<USequence>;
85 
86  // make sure only BaseProcess types TSequence/2 are passed
87  static_assert(is_process_v<process1_type>,
88  "can only use process derived from BaseProcess in "
89  "SwitchProcessSequence, for Process 1");
90  static_assert(is_process_v<process2_type>,
91  "can only use process derived from BaseProcess in "
92  "SwitchProcessSequence, for Process 2");
93 
94  // make sure none of TSequence/2 is a StackProcess
95  static_assert(!std::is_base_of_v<StackProcess<process1_type>, process1_type>,
96  "cannot use StackProcess in SwitchProcessSequence, for Process 1");
97  static_assert(!std::is_base_of_v<StackProcess<process2_type>, process2_type>,
98  "cannot use StackProcess in SwitchProcessSequence, for Process 2");
99 
100  // if TSequence/2 are already ProcessSequences, make sure they do not contain
101  // any StackProcess
102  static_assert(!contains_stack_process_v<process1_type>,
103  "cannot use StackProcess in SwitchProcessSequence, remove from "
104  "ProcessSequence 1");
105  static_assert(!contains_stack_process_v<process2_type>,
106  "cannot use StackProcess in SwitchProcessSequence, remove from "
107  "ProcessSequence 2");
108 
109  public:
110  // resource management
111  SwitchProcessSequence() = delete; // only initialized objects
114  SwitchProcessSequence& operator=(SwitchProcessSequence const&) = default;
115  ~SwitchProcessSequence() = default;
116 
117  static bool const is_process_sequence = true;
118  static bool const is_switch_process_sequence = true;
119 
131  SwitchProcessSequence(TCondition sel, TSequence in_A, USequence in_B)
132  : select_(sel)
133  , A_(in_A)
134  , B_(in_B) {}
135 
136  template <typename TParticle>
137  ProcessReturn doBoundaryCrossing(TParticle& particle,
138  typename TParticle::node_type const& from,
139  typename TParticle::node_type const& to);
140 
141  template <typename TParticle>
142  ProcessReturn doContinuous(Step<TParticle>& particle,
143  ContinuousProcessIndex const limitId);
144 
145  template <typename TSecondaries>
146  void doSecondaries(TSecondaries& vS);
147 
148  template <typename TParticle, typename TTrack>
149  ContinuousProcessStepLength getMaxStepLength(TParticle& particle, TTrack& vTrack);
150 
151  template <typename TParticle>
152  CrossSectionType getCrossSection(TParticle const& projectile, Code const targetId,
153  FourMomentum const& targetP4) const;
154 
155  template <typename TSecondaryView, typename TRNG>
156  ProcessReturn selectInteraction(TSecondaryView& view,
157  FourMomentum const& projectileP4,
158  NuclearComposition const& composition, TRNG& rng,
159  CrossSectionType const cx_select,
161 
162  template <typename TParticle>
163  TimeType getLifetime(TParticle&& particle) {
164  return 1. / getInverseLifetime(particle);
165  }
166 
167  template <typename TParticle>
168  InverseTimeType getInverseLifetime(TParticle&& particle);
169 
170  // select decay process
171  template <typename TSecondaryView>
172  ProcessReturn selectDecay(
173  TSecondaryView& view, [[maybe_unused]] InverseTimeType decay_inv_select,
174  [[maybe_unused]] InverseTimeType decay_inv_sum = InverseTimeType::zero());
175 
179  static size_t constexpr getNumberOfProcesses() { return numberOfProcesses_; }
180 
181 #ifdef CORSIKA_UNIT_TESTING
182  TCondition getCondition() const { return select_; }
183  TSequence getSequence() const { return A_; }
184  USequence getAltSequence() const { return B_; }
185 #endif
186 
187  private:
188  TCondition select_;
189 
191  TSequence A_;
192  USequence B_;
193 
194  static unsigned int constexpr numberOfProcesses_ = IndexOfProcess2; // static counter
195  };
196 
207  template <typename TCondition, typename TSequence, typename USequence,
208  typename = std::enable_if_t<is_process_v<typename std::decay_t<TSequence>> &&
209  is_process_v<typename std::decay_t<USequence>>>>
211  TCondition&& selector, TSequence&& vA, USequence&& vB) {
213  }
214 
216 
217 } // namespace corsika
218 
219 #include <corsika/detail/framework/process/SwitchProcessSequence.inl>
static size_t constexpr getNumberOfProcesses()
static counter to uniquely index (count) all ContinuousProcess in switch sequence.
Import and extend the phys::units package.
Class to switch between two process branches.
Each process in C8 must derive from BaseProcess.
Definition: BaseProcess.hpp:34
SwitchProcessSequence(TCondition sel, TSequence in_A, USequence in_B)
Only valid user constructor will create fully initialized object.
To index individual processes (continuous processes) inside a ProcessSequence.
Description of physical four-vectors.
Definition: FourVector.hpp:51
`, since they are used everywhere as integral part of the framework.
static constexpr quantity zero()
We need a "zero" of each type – for comparisons, to initialize running totals, etc.
Definition: quantity.hpp:359
SwitchProcessSequence< TCondition, TSequence, USequence > make_select(TCondition &&selector, TSequence &&vA, USequence &&vB)
the functin make_select(select, proc1, proc1) assembles many BaseProcesses, and ProcessSequences into...
ProcessReturn
since in a process sequence many status updates can accumulate for a single particle, this enum should define only bit-flags that can be accumulated easily with "|="
Describes the composition of matter Allowes and handles the creation of custom matter compositions...
Process to act on the entire particle stack.
To store step length in LengthType and unique index in ProcessSequence of shortest step ContinuousPro...
General FourVector object.