Version: SMASH-3.1
boxmodus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2020,2022-2023
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include "smash/boxmodus.h"
8 
9 #include <cmath>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <list>
13 #include <map>
14 #include <utility>
15 #include <vector>
16 
17 #include "smash/algorithms.h"
18 #include "smash/angles.h"
19 #include "smash/constants.h"
20 #include "smash/cxx17compat.h"
22 #include "smash/logging.h"
23 #include "smash/quantumsampling.h"
24 #include "smash/random.h"
25 #include "smash/threevector.h"
27 
28 namespace smash {
29 static constexpr int LBox = LogArea::Box::id;
30 
31 /* console output on startup of box specific parameters */
32 std::ostream &operator<<(std::ostream &out, const BoxModus &m) {
33  out << "-- Box Modus:\nSize of the box: (" << m.length_ << " fm)³\n";
34  if (m.use_thermal_) {
35  out << "Thermal multiplicities "
36  << "(T = " << m.temperature_ << " GeV, muB = " << m.mub_
37  << " GeV, muS = " << m.mus_ << " GeV, muQ = " << m.muq_ << " GeV)\n";
38  } else {
39  for (const auto &p : m.init_multipl_) {
40  ParticleTypePtr ptype = &ParticleType::find(p.first);
41  out << ptype->name() << " initial multiplicity " << p.second << '\n';
42  }
43  }
44  switch (m.initial_condition_) {
46  out << "All initial momenta = 3T = " << 3 * m.temperature_ << " GeV\n";
47  break;
49  out << "Boltzmann momentum distribution with T = " << m.temperature_
50  << " GeV.\n";
51  break;
53  out << "Fermi/Bose momentum distribution with T = " << m.temperature_
54  << " GeV.\n";
55  break;
56  }
57  if (m.jet_pdg_) {
58  ParticleTypePtr ptype = &ParticleType::find(m.jet_pdg_.value());
59  out << "Adding a " << ptype->name() << " as a jet in the middle "
60  << "of the box with " << m.jet_mom_ << " GeV initial momentum.\n";
61  }
62  return out;
63 }
64 
66  const ExperimentParameters &parameters)
67  : initial_condition_(modus_config.take({"Box", "Initial_Condition"})),
68  length_(modus_config.take({"Box", "Length"})),
69  equilibration_time_(
70  modus_config.take({"Box", "Equilibration_Time"}, -1.)),
71  temperature_(modus_config.take({"Box", "Temperature"})),
72  start_time_(modus_config.take({"Box", "Start_Time"}, 0.)),
73  use_thermal_(
74  modus_config.take({"Box", "Use_Thermal_Multiplicities"}, false)),
75  mub_(modus_config.take({"Box", "Baryon_Chemical_Potential"}, 0.)),
76  mus_(modus_config.take({"Box", "Strange_Chemical_Potential"}, 0.)),
77  muq_(modus_config.take({"Box", "Charge_Chemical_Potential"}, 0.)),
78  account_for_resonance_widths_(
79  modus_config.take({"Box", "Account_Resonance_Widths"}, true)),
80  init_multipl_(use_thermal_
81  ? std::map<PdgCode, int>()
82  : modus_config.take({"Box", "Init_Multiplicities"})
83  .convert_for(init_multipl_)),
84  /* Note that it is crucial not to take other keys from the Jet section
85  * before Jet_PDG, since we want here the take to throw in case the user
86  * had a Jet section without the mandatory Jet_PDG key. If all other keys
87  * are taken first, the section is removed from modus_config, because
88  * empty, and that has_value({"Box", "Jet"}) method would return false.
89  */
90  jet_pdg_(modus_config.has_value({"Box", "Jet"})
91  ? make_optional<PdgCode>(
92  modus_config.take({"Box", "Jet", "Jet_PDG"}))
93  : std::nullopt),
94 
95  jet_mom_(modus_config.take({"Box", "Jet", "Jet_Momentum"}, 20.)) {
96  if (parameters.res_lifetime_factor < 0.) {
97  throw std::invalid_argument(
98  "Resonance lifetime modifier cannot be negative!");
99  }
100  // Check consistency, just in case
101  if (std::abs(length_ - parameters.box_length) > really_small) {
102  throw std::runtime_error("Box length inconsistency");
103  }
104 }
105 
107  const ExperimentParameters &parameters) {
108  double momentum_radial = 0.0, mass = 0.0;
109  Angles phitheta;
110  FourVector momentum_total(0, 0, 0, 0);
111  auto uniform_length = random::make_uniform_distribution(0.0, this->length_);
112  const double T = this->temperature_;
113  const double V = length_ * length_ * length_;
114  /* Create NUMBER OF PARTICLES according to configuration, or thermal case */
115  if (use_thermal_) {
116  if (average_multipl_.empty()) {
117  for (const ParticleType &ptype : ParticleType::list_all()) {
118  if (HadronGasEos::is_eos_particle(ptype)) {
119  const double lifetime_factor =
120  ptype.is_stable() ? 1. : parameters.res_lifetime_factor;
121  const double n = lifetime_factor * HadronGasEos::partial_density(
122  ptype, T, mub_, mus_, muq_,
124  average_multipl_[ptype.pdgcode()] = n * V * parameters.testparticles;
125  }
126  }
127  }
128  double nb_init = 0.0, ns_init = 0.0, nq_init = 0.0;
129  for (const auto &mult : average_multipl_) {
130  const int thermal_mult_int = random::poisson(mult.second);
131  particles->create(thermal_mult_int, mult.first);
132  nb_init += mult.second * mult.first.baryon_number();
133  ns_init += mult.second * mult.first.strangeness();
134  nq_init += mult.second * mult.first.charge();
135  logg[LBox].debug(mult.first, " initial multiplicity ", thermal_mult_int);
136  }
137  logg[LBox].info("Initial hadron gas baryon density ", nb_init);
138  logg[LBox].info("Initial hadron gas strange density ", ns_init);
139  logg[LBox].info("Initial hadron gas charge density ", nq_init);
140  } else {
141  for (const auto &p : init_multipl_) {
142  particles->create(p.second * parameters.testparticles, p.first);
143  logg[LBox].debug("Particle ", p.first, " initial multiplicity ",
144  p.second);
145  }
146  }
147  std::unique_ptr<QuantumSampling> quantum_sampling;
149  quantum_sampling = std::make_unique<QuantumSampling>(init_multipl_, V, T);
150  }
151  for (ParticleData &data : *particles) {
152  /* Set MOMENTUM SPACE distribution */
154  /* initial thermal momentum is the average 3T */
155  momentum_radial = 3.0 * T;
156  mass = data.pole_mass();
157  } else {
158  if (this->initial_condition_ ==
160  /* thermal momentum according Maxwell-Boltzmann distribution */
162  ? data.type().mass()
163  : HadronGasEos::sample_mass_thermal(data.type(), 1.0 / T);
164  momentum_radial = sample_momenta_from_thermal(T, mass);
165  } else if (this->initial_condition_ ==
167  /*
168  * Sampling the thermal momentum according Bose/Fermi/Boltzmann
169  * distribution.
170  * We take the pole mass as the mass.
171  */
172  mass = data.type().mass();
173  momentum_radial = quantum_sampling->sample(data.pdgcode());
174  }
175  }
176  phitheta.distribute_isotropically();
177  logg[LBox].debug(data.type().name(), "(id ", data.id(),
178  ") radial momentum ", momentum_radial, ", direction",
179  phitheta);
180  data.set_4momentum(mass, phitheta.threevec() * momentum_radial);
181  momentum_total += data.momentum();
182 
183  /* Set COORDINATE SPACE distribution */
184  ThreeVector pos{uniform_length(), uniform_length(), uniform_length()};
185  data.set_4position(FourVector(start_time_, pos));
187  data.set_formation_time(start_time_);
188  }
189 
190  /* Make total 3-momentum 0 */
191  for (ParticleData &data : *particles) {
192  data.set_4momentum(data.momentum().abs(),
193  data.momentum().threevec() -
194  momentum_total.threevec() / particles->size());
195  }
196 
197  /* Add a single highly energetic particle in the center of the box (jet) */
198  if (jet_pdg_) {
199  auto &jet_particle = particles->create(jet_pdg_.value());
200  jet_particle.set_formation_time(start_time_);
201  jet_particle.set_4position(FourVector(start_time_, 0., 0., 0.));
202  jet_particle.set_4momentum(ParticleType::find(jet_pdg_.value()).mass(),
203  ThreeVector(jet_mom_, 0., 0.));
204  }
205 
206  /* Recalculate total momentum */
207  momentum_total = FourVector(0, 0, 0, 0);
208  for (ParticleData &data : *particles) {
209  momentum_total += data.momentum();
210  /* IC: debug checks */
211  logg[LBox].debug() << data;
212  }
213  /* allows to check energy conservation */
214  logg[LBox].debug() << "Initial total 4-momentum [GeV]: " << momentum_total;
215  return start_time_;
216 }
217 
219  const OutputsList &output_list) {
220  int wraps = 0;
221 
222  for (ParticleData &data : *particles) {
223  FourVector position = data.position();
224  bool wall_hit = enforce_periodic_boundaries(position.begin() + 1,
225  position.end(), length_);
226  if (wall_hit) {
227  const ParticleData incoming_particle(data);
228  data.set_4position(position);
229  ++wraps;
230  ActionPtr action =
231  std::make_unique<WallcrossingAction>(incoming_particle, data);
232  for (const auto &output : output_list) {
233  if (!output->is_dilepton_output() && !output->is_photon_output()) {
234  output->at_interaction(*action, 0.);
235  }
236  }
237  }
238  }
239  logg[LBox].debug("Moved ", wraps, " particles back into the box.");
240  return wraps;
241 }
242 
243 } // namespace smash
Generic algorithms on containers and ranges.
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
ThreeVector threevec() const
Definition: angles.h:288
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:199
BoxModus: Provides a modus for infinite matter calculations.
Definition: boxmodus.h:46
const std::optional< PdgCode > jet_pdg_
Optional PDG code of the particle to use as a jet.
Definition: boxmodus.h:190
const double muq_
Charge chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: boxmodus.h:169
const double jet_mom_
Initial momentum of the jet particle; only used if insert_jet_ is true.
Definition: boxmodus.h:194
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:218
BoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
Definition: boxmodus.cc:65
const bool use_thermal_
Whether to use a thermal initialization for all particles instead of specific numbers.
Definition: boxmodus.h:154
const double mub_
Baryon chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: boxmodus.h:159
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:106
const BoxInitialCondition initial_condition_
Initial momenta distribution: thermal or peaked momenta.
Definition: boxmodus.h:141
const std::map< PdgCode, int > init_multipl_
Particle multiplicities at initialization; required if use_thermal_ is false.
Definition: boxmodus.h:180
const bool account_for_resonance_widths_
In case of thermal initialization: true – account for resonance spectral functions,...
Definition: boxmodus.h:175
const double temperature_
Temperature of the Box in GeV.
Definition: boxmodus.h:147
const double mus_
Strange chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: boxmodus.h:164
std::map< PdgCode, double > average_multipl_
Average multiplicities in case of thermal initialization.
Definition: boxmodus.h:185
const double start_time_
Initial time of the box.
Definition: boxmodus.h:149
const double length_
Length of the cube's edge in fm.
Definition: boxmodus.h:143
Interface to the SMASH configuration files.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
ThreeVector threevec() const
Definition: fourvector.h:329
iterator end()
Definition: fourvector.h:294
iterator begin()
Definition: fourvector.h:291
static double partial_density(const ParticleType &ptype, double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:270
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:385
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:355
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:676
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
const std::string & name() const
Definition: particletype.h:142
static const ParticleTypeList & list_all()
Definition: particletype.cc:51
double mass() const
Definition: particletype.h:145
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
size_t size() const
Definition: particles.h:87
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
Definition: particles.cc:66
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
Collection of useful constants that are known at compile time.
@ ThermalMomentaBoltzmann
A thermalized ensemble is generated, with momenta sampled from a Maxwell-Boltzmann distribution.
@ ThermalMomentaQuantum
A thermalized ensemble is generated, with momenta of baryons(mesons) sampled from a Fermi(Bose) distr...
@ PeakedMomenta
All particles have the same momentum with T being the temperature.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:547
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
constexpr int p
Proton.
constexpr int n
Neutron.
int poisson(const T &lam)
Returns a Poisson distributed random number.
Definition: random.h:226
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:135
Definition: action.h:24
double sample_momenta_from_thermal(const double temperature, const double mass)
Samples a momentum from the Maxwell-Boltzmann (thermal) distribution in a faster way,...
static constexpr int LBox
Definition: boxmodus.cc:29
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
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
Helper structure for Experiment.
int testparticles
Number of test-particles.
double res_lifetime_factor
Multiplicative factor to be applied to resonance lifetimes; in the case of thermal multiplicities thi...