CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
ProcessSequence.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2020 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>
26 #include <corsika/framework/process/NullModel.hpp>
28 
29 namespace corsika {
30 
35  template <typename TProcess, int N>
37  TProcess, N,
38  typename std::enable_if_t<is_process_v<std::decay_t<TProcess>> &&
39  std::decay_t<TProcess>::is_process_sequence>> {
40  static unsigned int constexpr count =
41  N + std::decay_t<TProcess>::getNumberOfProcesses();
42  };
43 
150  template <typename TProcess1, typename TProcess2 = NullModel,
151  int ProcessIndexOffset = 0,
152  int IndexOfProcess1 = corsika::count_processes<
153  TProcess1,
155  int IndexOfProcess2 =
157  class ProcessSequence : public BaseProcess<ProcessSequence<TProcess1, TProcess2>> {
158 
159  using process1_type = typename std::decay_t<TProcess1>;
160  using process2_type = typename std::decay_t<TProcess2>;
161 
162  public:
163  // resource management
164  ProcessSequence() = delete; // only initialized objects
165  ProcessSequence(ProcessSequence const&) = default;
166  ProcessSequence(ProcessSequence&&) = default;
167  ProcessSequence& operator=(ProcessSequence const&) = default;
168  ~ProcessSequence() = default;
169 
170  static bool const is_process_sequence = true;
171 
182  ProcessSequence(TProcess1 in_A, TProcess2 in_B);
183 
184  template <typename TParticle>
185  ProcessReturn doBoundaryCrossing(TParticle& particle,
186  typename TParticle::node_type const& from,
187  typename TParticle::node_type const& to);
188 
189  template <typename TParticle, typename TTrack>
190  ProcessReturn doContinuous(TParticle& particle, TTrack& vT,
191  ContinuousProcessIndex const limitID);
192 
193  template <typename TSecondaries>
194  void doSecondaries(TSecondaries& vS);
195 
204  bool checkStep();
205 
209  template <typename TStack>
210  void doStack(TStack& stack);
211 
223  template <typename TParticle, typename TTrack>
224  ContinuousProcessStepLength getMaxStepLength(TParticle& particle, TTrack& vTrack);
225 
226  template <typename TParticle>
227  GrammageType getInteractionLength(TParticle&& particle) {
228  return 1. / getInverseInteractionLength(particle);
229  }
230 
231  template <typename TParticle>
232  InverseGrammageType getInverseInteractionLength(TParticle&& particle);
233 
234  template <typename TSecondaryView>
235  ProcessReturn selectInteraction(
236  TSecondaryView& view, [[maybe_unused]] InverseGrammageType lambda_inv_select,
237  [[maybe_unused]] InverseGrammageType lambda_inv_sum =
239 
240  template <typename TParticle>
241  TimeType getLifetime(TParticle& particle) {
242  return 1. / getInverseLifetime(particle);
243  }
244 
245  template <typename TParticle>
246  InverseTimeType getInverseLifetime(TParticle&& particle);
247 
248  // select decay process
249  template <typename TSecondaryView>
250  ProcessReturn selectDecay(
251  TSecondaryView& view, [[maybe_unused]] InverseTimeType decay_inv_select,
252  [[maybe_unused]] InverseTimeType decay_inv_sum = InverseTimeType::zero());
253 
257  static unsigned int constexpr getNumberOfProcesses() { return numberOfProcesses_; }
258 
259 #ifdef CORSIKA_UNIT_TESTING
260  TProcess1 getProcess1() const { return A_; }
261  TProcess2 getProcess2() const { return B_; }
262 #endif
263 
264  private:
265  TProcess1 A_;
266  TProcess2 B_;
267 
268  static unsigned int constexpr numberOfProcesses_ = IndexOfProcess1; // static counter
269  };
270 
300  template <typename... TProcesses, typename TProcess1>
302  make_sequence(TProcess1&& vA, TProcesses&&... vBs) {
303  return ProcessSequence<TProcess1,
304  decltype(make_sequence(std::declval<TProcesses>()...))>(
305  vA, make_sequence(std::forward<TProcesses>(vBs)...));
306  }
307 
321  template <typename TProcess1, typename TProcess2>
322  ProcessSequence<TProcess1, TProcess2> make_sequence(TProcess1&& vA, TProcess2&& vB) {
324  }
325 
338  template <typename TProcess>
339  ProcessSequence<TProcess, NullModel> make_sequence(TProcess&& vA) {
341  }
342 
343 } // namespace corsika
344 
345 #include <corsika/detail/framework/process/ProcessSequence.inl>
traits class to count any type of Process, general version
Import and extend the phys::units package.
Definition of a static process list/sequence
STL namespace.
Each process in C8 must derive from BaseProcess.
Definition: BaseProcess.hpp:33
static unsigned int constexpr getNumberOfProcesses()
static counter to uniquely index (count) all ContinuousProcess in switch sequence.
To index individual processes (continuous processes) inside a ProcessSequence.
class "quantity" is the heart of the library.
Definition: quantity.hpp:54
The cascade namespace assembles all objects needed to simulate full particles cascades.
Process that does nothing.
Definition: NullModel.hpp:24
static constexpr quantity zero()
We need a "zero" of each type – for comparisons, to initialize running totals, etc.
Definition: quantity.hpp:359
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 "|="
To store step length in LengthType and unique index in ProcessSequence of shortest step ContinuousPro...