Version: SMASH-2.0
action.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_ACTION_H_
11 #define SRC_INCLUDE_SMASH_ACTION_H_
12 
13 #include <stdexcept>
14 #include <utility>
15 #include <vector>
16 
17 #include "lattice.h"
18 #include "particles.h"
19 #include "pauliblocking.h"
20 #include "potentials.h"
21 #include "processbranch.h"
22 #include "random.h"
23 
24 namespace smash {
25 static constexpr int LAction = LogArea::Action::id;
26 
35 class Action {
36  public:
44  Action(const ParticleList &in_part, double time)
45  : incoming_particles_(in_part),
46  time_of_execution_(time + in_part[0].position().x0()) {}
47 
58  Action(const ParticleData &in_part, const ParticleData &out_part, double time,
59  ProcessType type)
60  : incoming_particles_({in_part}),
61  outgoing_particles_({out_part}),
62  time_of_execution_(time + in_part.position().x0()),
63  process_type_(type) {}
64 
75  Action(const ParticleList &in_part, const ParticleList &out_part,
76  double absolute_execution_time, ProcessType type)
77  : incoming_particles_(std::move(in_part)),
78  outgoing_particles_(std::move(out_part)),
79  time_of_execution_(absolute_execution_time),
80  process_type_(type) {}
81 
83  Action(const Action &) = delete;
84 
89  virtual ~Action();
90 
96  bool operator<(const Action &rhs) const {
98  }
99 
112  virtual double get_total_weight() const = 0;
113 
124  virtual double get_partial_weight() const = 0;
125 
131  virtual ProcessType get_type() const { return process_type_; }
132 
140  template <typename Branch>
141  void add_process(ProcessBranchPtr<Branch> &p,
142  ProcessBranchList<Branch> &subprocesses,
143  double &total_weight) {
144  if (p->weight() > 0) {
145  total_weight += p->weight();
146  subprocesses.emplace_back(std::move(p));
147  }
148  }
149 
157  template <typename Branch>
158  void add_processes(ProcessBranchList<Branch> pv,
159  ProcessBranchList<Branch> &subprocesses,
160  double &total_weight) {
161  subprocesses.reserve(subprocesses.size() + pv.size());
162  for (auto &proc : pv) {
163  if (proc->weight() > 0) {
164  total_weight += proc->weight();
165  subprocesses.emplace_back(std::move(proc));
166  }
167  }
168  }
169 
176  virtual void generate_final_state() = 0;
177 
193  virtual void perform(Particles *particles, uint32_t id_process);
194 
206  bool is_valid(const Particles &particles) const;
207 
222  bool is_pauli_blocked(const Particles &particles,
223  const PauliBlocker &p_bl) const;
224 
230  const ParticleList &incoming_particles() const;
231 
238  void update_incoming(const Particles &particles);
239 
245  const ParticleList &outgoing_particles() const { return outgoing_particles_; }
246 
252  double time_of_execution() const { return time_of_execution_; }
253 
259  virtual void check_conservation(const uint32_t id_process) const;
260 
266  double sqrt_s() const { return total_momentum().abs(); }
267 
279 
286 
292  std::pair<FourVector, FourVector> get_potential_at_interaction_point() const;
293 
299  const int max_inc_idx = incoming_particles_.size() - 1;
301  }
302 
310  static double lambda_tilde(double a, double b, double c) {
311  return (a - b - c) * (a - b - c) - 4. * b * c;
312  }
313 
320  class InvalidResonanceFormation : public std::invalid_argument {
321  using std::invalid_argument::invalid_argument;
322  };
323 
324  protected:
326  ParticleList incoming_particles_;
327 
334  ParticleList outgoing_particles_;
335 
340  const double time_of_execution_;
341 
344 
350  double box_length_ = -1.0;
351 
358 
361  FourVector mom(0.0, 0.0, 0.0, 0.0);
362  for (const auto &p : incoming_particles_) {
363  mom += p.momentum();
364  }
365  return mom;
366  }
367 
377  template <typename Branch>
378  const Branch *choose_channel(const ProcessBranchList<Branch> &subprocesses,
379  double total_weight) {
380  double random_weight = random::uniform(0., total_weight);
381  double weight_sum = 0.;
382  /* Loop through all subprocesses and select one by Monte Carlo, based on
383  * their weights. */
384  for (const auto &proc : subprocesses) {
385  weight_sum += proc->weight();
386  if (random_weight <= weight_sum) {
387  /* Return the full process information. */
388  return proc.get();
389  }
390  }
391  /* Should never get here. */
393  "Problem in choose_channel: ", subprocesses.size(), " ",
394  weight_sum, " ", total_weight, " ",
395  // random_weight, "\n", *this);
396  random_weight, "\n");
397  std::abort();
398  }
399 
410  virtual std::pair<double, double> sample_masses(
411  double kinetic_energy_cm) const;
412 
422  virtual void sample_angles(std::pair<double, double> masses,
423  double kinetic_energy_cm);
424 
430 
437  virtual void sample_3body_phasespace();
438 
455 
462  virtual void format_debug_output(std::ostream &out) const = 0;
463 
468  friend std::ostream &operator<<(std::ostream &out, const Action &action) {
469  action.format_debug_output(out);
470  return out;
471  }
472 
473  private:
480  const ParticleType &type_of_pout(const ParticleData &p_out) const {
481  return p_out.type();
482  }
491  const ParticleType &type_of_pout(const ParticleTypePtr &p_out) const {
492  return *p_out;
493  }
494 };
495 
503 inline std::vector<ActionPtr> &operator+=(std::vector<ActionPtr> &lhs,
504  std::vector<ActionPtr> &&rhs) {
505  if (lhs.size() == 0) {
506  lhs = std::move(rhs);
507  } else {
508  lhs.insert(lhs.end(), std::make_move_iterator(rhs.begin()),
509  std::make_move_iterator(rhs.end()));
510  }
511  return lhs;
512 }
513 
518 inline std::ostream &operator<<(std::ostream &out, const ActionPtr &action) {
519  return out << *action;
520 }
521 
526 std::ostream &operator<<(std::ostream &out, const ActionList &actions);
527 
528 } // namespace smash
529 
530 #endif // SRC_INCLUDE_SMASH_ACTION_H_
smash::Action::sample_angles
virtual void sample_angles(std::pair< double, double > masses, double kinetic_energy_cm)
Sample final-state momenta in general X->2 processes (here: using an isotropical angular distribution...
Definition: action.cc:274
smash::Action::get_type
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:131
smash
Definition: action.h:24
smash::Action::lambda_tilde
static double lambda_tilde(double a, double b, double c)
Little helper function that calculates the lambda function (sometimes written with a tilde to better ...
Definition: action.h:310
smash::Action::incoming_particles_
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:326
smash::Action::~Action
virtual ~Action()
Virtual Destructor.
processbranch.h
smash::Action::total_momentum
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:360
smash::Action::time_of_execution_
const double time_of_execution_
Time at which the action is supposed to be performed (absolute time in the lab frame in fm/c).
Definition: action.h:340
smash::Action::generate_final_state
virtual void generate_final_state()=0
Generate the final state for this action.
smash::Action::assign_formation_time_to_outgoing_particles
void assign_formation_time_to_outgoing_particles()
Assign the formation time to the outgoing particles.
Definition: action.cc:183
smash::ParticleData
Definition: particledata.h:52
smash::Action::sample_2body_phasespace
void sample_2body_phasespace()
Sample the full 2-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:297
smash::Action::Action
Action(const ParticleList &in_part, const ParticleList &out_part, double absolute_execution_time, ProcessType type)
Construct an action object with the incoming particles, absolute time, and the already known outgoing...
Definition: action.h:75
smash::Action::is_pauli_blocked
bool is_pauli_blocked(const Particles &particles, const PauliBlocker &p_bl) const
Check if the action is Pauli-blocked.
Definition: action.cc:34
smash::Action::check_conservation
virtual void check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:345
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:518
smash::Action::format_debug_output
virtual void format_debug_output(std::ostream &out) const =0
smash::Action::type_of_pout
const ParticleType & type_of_pout(const ParticleTypePtr &p_out) const
Get the particle type for given pointer to a particle type.
Definition: action.h:491
smash::Action::get_partial_weight
virtual double get_partial_weight() const =0
Return the specific weight for the chosen outgoing channel, which is mainly used for the partial weig...
smash::random::uniform_int
T uniform_int(T min, T max)
Definition: random.h:100
smash::Action::operator<
bool operator<(const Action &rhs) const
Determine whether one action takes place before another in time.
Definition: action.h:96
smash::Action::update_incoming
void update_incoming(const Particles &particles)
Update the incoming particles that are stored in this action to the state they have in the global par...
Definition: action.cc:61
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::Action::add_processes
void add_processes(ProcessBranchList< Branch > pv, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add several new subprocesses at once.
Definition: action.h:158
smash::Action::outgoing_particles
const ParticleList & outgoing_particles() const
Get the list of particles that resulted from the action.
Definition: action.h:245
pauliblocking.h
random.h
smash::ParticleTypePtr
Definition: particletype.h:665
source_location
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs.
Definition: logging.h:243
lattice.h
smash::PauliBlocker
A class that stores parameters needed for Pauli blocking, tabulates necessary integrals and computes ...
Definition: pauliblocking.h:36
smash::Action::operator<<
friend std::ostream & operator<<(std::ostream &out, const Action &action)
Definition: action.h:468
smash::Action::box_length_
double box_length_
Box length: needed to determine coordinates of collision correctly in case of collision through the w...
Definition: action.h:350
smash::Action::type_of_pout
const ParticleType & type_of_pout(const ParticleData &p_out) const
Get the type of a given particle.
Definition: action.h:480
smash::Action::process_type_
ProcessType process_type_
type of process
Definition: action.h:343
smash::ParticleType
Definition: particletype.h:97
smash::Action::is_valid
bool is_valid(const Particles &particles) const
Check whether the action still applies.
Definition: action.cc:28
smash::Action::get_total_weight
virtual double get_total_weight() const =0
Return the total weight value, which is mainly used for the weight output entry.
smash::LAction
static constexpr int LAction
Definition: action.h:25
smash::Action::get_potential_at_interaction_point
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:108
smash::Action::stochastic_position_idx_
int stochastic_position_idx_
This stores a randomly-chosen index to an incoming particle.
Definition: action.h:357
smash::Action::add_process
void add_process(ProcessBranchPtr< Branch > &p, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add a new subprocess.
Definition: action.h:141
smash::Action::perform
virtual void perform(Particles *particles, uint32_t id_process)
Actually perform the action, e.g.
Definition: action.cc:124
smash::Action::total_momentum_of_outgoing_particles
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:152
smash::Action::choose_channel
const Branch * choose_channel(const ProcessBranchList< Branch > &subprocesses, double total_weight)
Decide for a particular final-state channel via Monte-Carlo and return it as a ProcessBranch.
Definition: action.h:378
smash::Action::outgoing_particles_
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:334
smash::FourVector::abs
double abs() const
calculate the lorentz invariant absolute value
Definition: fourvector.h:454
particles.h
smash::Action::sample_3body_phasespace
virtual void sample_3body_phasespace()
Sample the full 3-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:308
smash::Action::sqrt_s
double sqrt_s() const
Determine the total energy in the center-of-mass frame [GeV].
Definition: action.h:266
smash::Particles
Definition: particles.h:33
smash::operator+=
std::vector< ActionPtr > & operator+=(std::vector< ActionPtr > &lhs, std::vector< ActionPtr > &&rhs)
Append vector of action pointers.
Definition: action.h:503
smash::Action
Definition: action.h:35
smash::Action::Action
Action(const ParticleList &in_part, double time)
Construct an action object with incoming particles and relative time.
Definition: action.h:44
smash::Action::time_of_execution
double time_of_execution() const
Get the time at which the action is supposed to be performed.
Definition: action.h:252
smash::FourVector
Definition: fourvector.h:33
smash::Action::get_interaction_point
FourVector get_interaction_point() const
Get the interaction point.
Definition: action.cc:67
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::random::uniform
T uniform(T min, T max)
Definition: random.h:88
smash::Action::Action
Action(const ParticleData &in_part, const ParticleData &out_part, double time, ProcessType type)
Construct an action object with the incoming particles, relative time, and the already known outgoing...
Definition: action.h:58
smash::Action::incoming_particles
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:57
smash::Action::set_stochastic_pos_idx
void set_stochastic_pos_idx()
Setter function that stores a random incoming particle index latter used to determine the interaction...
Definition: action.h:298
smash::ParticleData::type
const ParticleType & type() const
Get the type of the particle.
Definition: particledata.h:122
smash::Action::sample_masses
virtual std::pair< double, double > sample_masses(double kinetic_energy_cm) const
Sample final-state masses in general X->2 processes (thus also fixing the absolute c....
Definition: action.cc:245
smash::Action::InvalidResonanceFormation
Definition: action.h:320
smash::ProcessType
ProcessType
Process Types are used to identify the type of the process.
Definition: processbranch.h:25
potentials.h