Version: SMASH-1.5
action.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2018
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_ACTION_H_
11 #define SRC_INCLUDE_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 
34 class Action {
35  public:
43  Action(const ParticleList &in_part, double time)
44  : incoming_particles_(in_part),
45  time_of_execution_(time + in_part[0].position().x0()) {}
46 
57  Action(const ParticleData &in_part, const ParticleData &out_part, double time,
58  ProcessType type)
59  : incoming_particles_({in_part}),
60  outgoing_particles_({out_part}),
61  time_of_execution_(time + in_part.position().x0()),
62  process_type_(type) {}
63 
74  Action(const ParticleList &in_part, const ParticleList &out_part,
75  double absolute_execution_time, ProcessType type)
76  : incoming_particles_(std::move(in_part)),
77  outgoing_particles_(std::move(out_part)),
78  time_of_execution_(absolute_execution_time),
79  process_type_(type) {}
80 
82  Action(const Action &) = delete;
83 
88  virtual ~Action();
89 
95  bool operator<(const Action &rhs) const {
97  }
98 
111  virtual double get_total_weight() const = 0;
112 
123  virtual double get_partial_weight() const = 0;
124 
130  virtual ProcessType get_type() const { return process_type_; }
131 
139  template <typename Branch>
140  void add_process(ProcessBranchPtr<Branch> &p,
141  ProcessBranchList<Branch> &subprocesses,
142  double &total_weight) {
143  if (p->weight() > 0) {
144  total_weight += p->weight();
145  subprocesses.emplace_back(std::move(p));
146  }
147  }
148 
156  template <typename Branch>
157  void add_processes(ProcessBranchList<Branch> pv,
158  ProcessBranchList<Branch> &subprocesses,
159  double &total_weight) {
160  subprocesses.reserve(subprocesses.size() + pv.size());
161  for (auto &proc : pv) {
162  if (proc->weight() > 0) {
163  total_weight += proc->weight();
164  subprocesses.emplace_back(std::move(proc));
165  }
166  }
167  }
168 
175  virtual void generate_final_state() = 0;
176 
192  virtual void perform(Particles *particles, uint32_t id_process);
193 
205  bool is_valid(const Particles &particles) const;
206 
221  bool is_pauli_blocked(const Particles &particles,
222  const PauliBlocker &p_bl) const;
223 
229  const ParticleList &incoming_particles() const;
230 
237  void update_incoming(const Particles &particles);
238 
244  const ParticleList &outgoing_particles() const { return outgoing_particles_; }
245 
251  double time_of_execution() const { return time_of_execution_; }
252 
258  void check_conservation(const uint32_t id_process) const;
259 
265  double sqrt_s() const { return total_momentum().abs(); }
266 
276 
283 
289  std::pair<FourVector, FourVector> get_potential_at_interaction_point() const;
290 
297  class InvalidResonanceFormation : public std::invalid_argument {
298  using std::invalid_argument::invalid_argument;
299  };
300 
301  protected:
303  ParticleList incoming_particles_;
304 
311  ParticleList outgoing_particles_;
312 
317  const double time_of_execution_;
318 
321 
324  FourVector mom(0.0, 0.0, 0.0, 0.0);
325  for (const auto &p : incoming_particles_) {
326  mom += p.momentum();
327  }
328  return mom;
329  }
330 
340  template <typename Branch>
341  const Branch *choose_channel(const ProcessBranchList<Branch> &subprocesses,
342  double total_weight) {
343  const auto &log = logger<LogArea::Action>();
344  double random_weight = random::uniform(0., total_weight);
345  double weight_sum = 0.;
346  /* Loop through all subprocesses and select one by Monte Carlo, based on
347  * their weights. */
348  for (const auto &proc : subprocesses) {
349  weight_sum += proc->weight();
350  if (random_weight <= weight_sum) {
351  /* Return the full process information. */
352  return proc.get();
353  }
354  }
355  /* Should never get here. */
356  log.fatal(source_location,
357  "Problem in choose_channel: ", subprocesses.size(), " ",
358  weight_sum, " ", total_weight, " ",
359  // random_weight, "\n", *this);
360  random_weight, "\n");
361  abort();
362  }
363 
374  virtual std::pair<double, double> sample_masses(
375  double kinetic_energy_cm) const;
376 
386  virtual void sample_angles(std::pair<double, double> masses,
387  double kinetic_energy_cm);
388 
394 
401  virtual void format_debug_output(std::ostream &out) const = 0;
402 
407  friend std::ostream &operator<<(std::ostream &out, const Action &action) {
408  action.format_debug_output(out);
409  return out;
410  }
411 
412  private:
419  const ParticleType &type_of_pout(const ParticleData &p_out) const {
420  return p_out.type();
421  }
430  const ParticleType &type_of_pout(const ParticleTypePtr &p_out) const {
431  return *p_out;
432  }
433 };
434 
442 inline std::vector<ActionPtr> &operator+=(std::vector<ActionPtr> &lhs,
443  std::vector<ActionPtr> &&rhs) {
444  if (lhs.size() == 0) {
445  lhs = std::move(rhs);
446  } else {
447  lhs.insert(lhs.end(), std::make_move_iterator(rhs.begin()),
448  std::make_move_iterator(rhs.end()));
449  }
450  return lhs;
451 }
452 
457 inline std::ostream &operator<<(std::ostream &out, const ActionPtr &action) {
458  return out << *action;
459 }
460 
465 std::ostream &operator<<(std::ostream &out, const ActionList &actions);
466 
467 } // namespace smash
468 
469 #endif // SRC_INCLUDE_ACTION_H_
friend std::ostream & operator<<(std::ostream &out, const Action &action)
Dispatches formatting to the virtual Action::format_debug_output function.
Definition: action.h:407
virtual void format_debug_output(std::ostream &out) const =0
Writes information about this action to the out stream.
virtual void generate_final_state()=0
Generate the final state for this action.
FourVector get_interaction_point() const
Get the interaction point.
Definition: action.cc:68
ProcessType
Process Types are used to identify the type of the process.
Definition: processbranch.h:25
bool operator<(const Action &rhs) const
Determine whether one action takes place before another in time.
Definition: action.h:95
ProcessType process_type_
type of process
Definition: action.h:320
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:74
Action(const ParticleList &in_part, double time)
Construct an action object with incoming particles and relative time.
Definition: action.h:43
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:323
STL namespace.
virtual double get_partial_weight() const =0
Return the specific weight for the chosen outgoing channel, which is mainly used for the partial weig...
bool is_valid(const Particles &particles) const
Check whether the action still applies.
Definition: action.cc:29
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:57
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:62
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:183
double time_of_execution() const
Get the time at which the action is supposed to be performed.
Definition: action.h:251
Thrown for example when ScatterAction is called to perform with a wrong number of final-state particl...
Definition: action.h:297
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:311
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs...
Definition: logging.h:246
const ParticleList & outgoing_particles() const
Get the list of particles that resulted from the action.
Definition: action.h:244
Particle type contains the static properties of a particle species.
Definition: particletype.h:87
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:303
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:58
void add_process(ProcessBranchPtr< Branch > &p, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add a new subprocess.
Definition: action.h:140
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:78
const ParticleType & type_of_pout(const ParticleData &p_out) const
Get the type of a given particle.
Definition: action.h:419
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:123
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:130
T uniform(T min, T max)
Definition: random.h:85
A class that stores parameters needed for Pauli blocking, tabulates necessary integrals and computes ...
Definition: pauliblocking.h:36
void add_processes(ProcessBranchList< Branch > pv, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add several new subprocesses at once.
Definition: action.h:157
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:154
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:34
virtual double get_total_weight() const =0
Return the total weight value, which is mainly used for the weight output entry.
std::vector< ActionPtr > & operator+=(std::vector< ActionPtr > &lhs, std::vector< ActionPtr > &&rhs)
Append vector of action pointers.
Definition: action.h:442
constexpr int p
Proton.
const ParticleType & type() const
Get the type of the particle.
Definition: particledata.h:109
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:208
const ParticleType & type_of_pout(const ParticleTypePtr &p_out) const
Get the particle type for given pointer to a particle type.
Definition: action.h:430
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:341
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:660
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
bool is_pauli_blocked(const Particles &particles, const PauliBlocker &p_bl) const
Check if the action is Pauli-blocked.
Definition: action.cc:35
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:457
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
double abs() const
calculate the lorentz invariant absolute value
Definition: fourvector.h:441
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
void check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:219
virtual ~Action()
Virtual Destructor.
Definition: action.h:24
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:317
virtual void perform(Particles *particles, uint32_t id_process)
Actually perform the action, e.g.
Definition: action.cc:94
double sqrt_s() const
Determine the total energy in the center-of-mass frame [GeV].
Definition: action.h:265