Version: SMASH-1.7
boxmodus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2019
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include <cmath>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <list>
11 #include <map>
12 #include <utility>
13 #include <vector>
14 
15 #include "smash/algorithms.h"
16 #include "smash/angles.h"
17 #include "smash/boxmodus.h"
18 #include "smash/configuration.h"
19 #include "smash/constants.h"
20 #include "smash/cxx14compat.h"
21 #include "smash/distributions.h"
23 #include "smash/hadgas_eos.h"
24 #include "smash/logging.h"
25 #include "smash/macros.h"
26 #include "smash/outputinterface.h"
27 #include "smash/particles.h"
28 #include "smash/processbranch.h"
29 #include "smash/quantumnumbers.h"
30 #include "smash/random.h"
31 #include "smash/threevector.h"
33 
34 namespace smash {
35 
36 /* console output on startup of box specific parameters */
37 std::ostream &operator<<(std::ostream &out, const BoxModus &m) {
38  out << "-- Box Modus:\nSize of the box: (" << m.length_ << " fm)³\n";
39  if (m.use_thermal_) {
40  out << "Thermal multiplicities "
41  << "(T = " << m.temperature_ << " GeV, muB = " << m.mub_
42  << " GeV, muS = " << m.mus_ << " GeV)\n";
43  } else {
44  for (const auto &p : m.init_multipl_) {
45  ParticleTypePtr ptype = &ParticleType::find(p.first);
46  out << ptype->name() << " initial multiplicity " << p.second << '\n';
47  }
48  }
50  out << "All initial momenta = 3T = " << 3 * m.temperature_ << " GeV\n";
51  } else {
52  out << "Boltzmann momentum distribution with T = " << m.temperature_
53  << " GeV.\n";
54  }
55  if (m.insert_jet_) {
57  out << "Adding a " << ptype->name() << " as a jet in the middle "
58  << "of the box with " << m.jet_mom_ << " GeV initial momentum.\n";
59  }
60  return out;
61 }
62 
206  : initial_condition_(modus_config.take({"Box", "Initial_Condition"})),
207  length_(modus_config.take({"Box", "Length"})),
208  temperature_(modus_config.take({"Box", "Temperature"})),
209  start_time_(modus_config.take({"Box", "Start_Time"}, 0.)),
210  use_thermal_(
211  modus_config.take({"Box", "Use_Thermal_Multiplicities"}, false)),
212  mub_(modus_config.take({"Box", "Baryon_Chemical_Potential"}, 0.)),
213  mus_(modus_config.take({"Box", "Strange_Chemical_Potential"}, 0.)),
215  modus_config.take({"Box", "Account_Resonance_Widths"}, true)),
217  ? std::map<PdgCode, int>()
218  : modus_config.take({"Box", "Init_Multiplicities"})
219  .convert_for(init_multipl_)),
220  insert_jet_(modus_config.has_value({"Box", "Jet", "Jet_PDG"})),
221  jet_pdg_(insert_jet_ ? modus_config.take({"Box", "Jet", "Jet_PDG"})
222  .convert_for(jet_pdg_)
223  : pdg::p), // dummy default; never used
224  jet_mom_(modus_config.take({"Box", "Jet", "Jet_Momentum"}, 20.)) {}
225 
227  const ExperimentParameters &parameters) {
228  const auto &log = logger<LogArea::Box>();
229  double momentum_radial = 0, mass;
230  Angles phitheta;
231  FourVector momentum_total(0, 0, 0, 0);
232  auto uniform_length = random::make_uniform_distribution(0.0, this->length_);
233  const double T = this->temperature_;
234  /* Create NUMBER OF PARTICLES according to configuration, or thermal case */
235  if (use_thermal_) {
236  const double V = length_ * length_ * length_;
237  if (average_multipl_.empty()) {
238  for (const ParticleType &ptype : ParticleType::list_all()) {
239  if (HadronGasEos::is_eos_particle(ptype)) {
240  const double n = HadronGasEos::partial_density(
242  average_multipl_[ptype.pdgcode()] = n * V * parameters.testparticles;
243  }
244  }
245  }
246  double nb_init = 0.0, ns_init = 0.0;
247  for (const auto &mult : average_multipl_) {
248  const int thermal_mult_int = random::poisson(mult.second);
249  particles->create(thermal_mult_int, mult.first);
250  nb_init += mult.second * mult.first.baryon_number();
251  ns_init += mult.second * mult.first.strangeness();
252  log.debug(mult.first, " initial multiplicity ", thermal_mult_int);
253  }
254  log.info("Initial hadron gas baryon density ", nb_init);
255  log.info("Initial hadron gas strange density ", ns_init);
256  } else {
257  for (const auto &p : init_multipl_) {
258  particles->create(p.second * parameters.testparticles, p.first);
259  log.debug("Particle ", p.first, " initial multiplicity ", p.second);
260  }
261  }
262 
263  for (ParticleData &data : *particles) {
264  /* Set MOMENTUM SPACE distribution */
266  /* initial thermal momentum is the average 3T */
267  momentum_radial = 3.0 * T;
268  mass = data.pole_mass();
269  } else {
270  /* thermal momentum according Maxwell-Boltzmann distribution */
272  ? data.type().mass()
273  : HadronGasEos::sample_mass_thermal(data.type(), 1.0 / T);
274  momentum_radial = sample_momenta_from_thermal(T, mass);
275  }
276  phitheta.distribute_isotropically();
277  log.debug(data.type().name(), "(id ", data.id(), ") radial momentum ",
278  momentum_radial, ", direction", phitheta);
279  data.set_4momentum(mass, phitheta.threevec() * momentum_radial);
280  momentum_total += data.momentum();
281 
282  /* Set COORDINATE SPACE distribution */
283  ThreeVector pos{uniform_length(), uniform_length(), uniform_length()};
284  data.set_4position(FourVector(start_time_, pos));
286  data.set_formation_time(start_time_);
287  }
288 
289  /* Make total 3-momentum 0 */
290  for (ParticleData &data : *particles) {
291  data.set_4momentum(data.momentum().abs(),
292  data.momentum().threevec() -
293  momentum_total.threevec() / particles->size());
294  }
295 
296  /* Add a single highly energetic particle in the center of the box (jet) */
297  if (insert_jet_) {
298  auto &jet_particle = particles->create(jet_pdg_);
299  jet_particle.set_formation_time(start_time_);
300  jet_particle.set_4position(FourVector(start_time_, 0., 0., 0.));
301  jet_particle.set_4momentum(ParticleType::find(jet_pdg_).mass(),
302  ThreeVector(jet_mom_, 0., 0.));
303  }
304 
305  /* Recalculate total momentum */
306  momentum_total = FourVector(0, 0, 0, 0);
307  for (ParticleData &data : *particles) {
308  momentum_total += data.momentum();
309  /* IC: debug checks */
310  log.debug() << data;
311  }
312  /* allows to check energy conservation */
313  log.debug() << "Initial total 4-momentum [GeV]: " << momentum_total;
314  return start_time_;
315 }
316 
318  const OutputsList &output_list) {
319  const auto &log = logger<LogArea::Box>();
320  int wraps = 0;
321 
322  for (ParticleData &data : *particles) {
323  FourVector position = data.position();
324  bool wall_hit = enforce_periodic_boundaries(position.begin() + 1,
325  position.end(), length_);
326  if (wall_hit) {
327  const ParticleData incoming_particle(data);
328  data.set_4position(position);
329  ++wraps;
330  ActionPtr action =
331  make_unique<WallcrossingAction>(incoming_particle, data);
332  for (const auto &output : output_list) {
333  if (!output->is_dilepton_output() && !output->is_photon_output()) {
334  output->at_interaction(*action, 0.);
335  }
336  }
337  }
338  }
339  log.debug("Moved ", wraps, " particles back into the box.");
340  return wraps;
341 }
342 
343 } // namespace smash
const double start_time_
Initial time of the box.
Definition: boxmodus.h:136
const double length_
Length of the cube&#39;s edge in fm/c.
Definition: boxmodus.h:132
const std::map< PdgCode, int > init_multipl_
Particle multiplicities at initialization; required if use_thermal_ is false.
Definition: boxmodus.h:162
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
const bool use_thermal_
Whether to use a thermal initialization for all particles instead of specific numbers.
Definition: boxmodus.h:141
const double temperature_
Temperature of the Box in GeV.
Definition: boxmodus.h:134
const double jet_mom_
Initial momentum of the jet particle; only used if insert_jet_ is true.
Definition: boxmodus.h:182
const bool account_for_resonance_widths_
In case of thermal initialization: true – account for resonance spectral functions, while computing multiplicities and sampling masses, false – simply use pole masses.
Definition: boxmodus.h:157
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
Definition: particles.cc:66
const BoxInitialCondition initial_condition_
Initial momenta distribution: thermal or peaked momenta.
Definition: boxmodus.h:130
Collection of useful constants that are known at compile time.
iterator end()
Definition: fourvector.h:284
ThreeVector threevec() const
Definition: fourvector.h:319
const PdgCode jet_pdg_
Pdg of the particle to use as a jet; necessary if insert_jet_ is true, unused otherwise.
Definition: boxmodus.h:178
const double mus_
Strange chemical potential for thermal initialization; only used if use_thermal_ is true...
Definition: boxmodus.h:151
Interface to the SMASH configuration files.
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:308
const bool insert_jet_
Whether to insert a single high energy particle at the center of the box (0,0,0). ...
Definition: boxmodus.h:173
static double partial_density(const ParticleType &ptype, double T, double mub, double mus, bool account_for_resonance_widths=false)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:234
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
ThreeVector threevec() const
Definition: angles.h:268
static const ParticleTypeList & list_all()
Definition: particletype.cc:55
const std::string & name() const
Definition: particletype.h:141
Generic algorithms on containers and ranges.
Particle type contains the static properties of a particle species.
Definition: particletype.h:97
std::map< PdgCode, double > average_multipl_
Average multiplicities in case of thermal initialization.
Definition: boxmodus.h:167
double sample_momenta_from_thermal(const double temperature, const double mass)
Samples a momentum from the Maxwell-Boltzmann (thermal) distribution in a faster way, given by Scott Pratt (see Pratt:2014vja) APPENDIX: ALGORITHM FOR GENERATING PARTICLES math trick: for distribution, sample x by: where are uniform random numbers between [0,1) for : , where is used as rejection weight.
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:325
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:135
BoxModus: Provides a modus for infinite matter calculations.
Definition: boxmodus.h:46
constexpr int p
Proton.
BoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
Definition: boxmodus.cc:205
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to specified parameters: number of p...
Definition: boxmodus.cc:226
int poisson(const T &lam)
Returns a Poisson distributed random number.
Definition: random.h:226
int testparticles
Number of test particle.
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:654
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:188
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
constexpr int n
Neutron.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:463
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
Helper structure for Experiment.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
static bool enforce_periodic_boundaries(Iterator begin, const Iterator &end, typename std::iterator_traits< Iterator >::value_type length)
Enforces periodic boundaries on the given collection of values.
Definition: algorithms.h:53
Definition: action.h:24
int impose_boundary_conditions(Particles *particles, const OutputsList &output_list={})
Enforces that all particles are inside the box at the beginning of an event.
Definition: boxmodus.cc:317
iterator begin()
Definition: fourvector.h:281
const double mub_
Baryon chemical potential for thermal initialization; only used if use_thermal_ is true...
Definition: boxmodus.h:146