Version: SMASH-3.1
spheremodus.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2023
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/spheremodus.h"
11 
12 #include <cmath>
13 #include <cstdio>
14 #include <cstdlib>
15 #include <list>
16 #include <map>
17 #include <utility>
18 #include <vector>
19 
20 #include "smash/angles.h"
22 #include "smash/configuration.h"
23 #include "smash/constants.h"
24 #include "smash/cxx17compat.h"
26 #include "smash/fourvector.h"
27 #include "smash/hadgas_eos.h"
28 #include "smash/logging.h"
29 #include "smash/particles.h"
30 #include "smash/quantumsampling.h"
31 #include "smash/random.h"
32 #include "smash/threevector.h"
33 
34 namespace smash {
35 static constexpr int LSphere = LogArea::Sphere::id;
36 
38  const ExperimentParameters &)
39  : radius_(modus_config.take({"Sphere", "Radius"})),
40  sphere_temperature_(modus_config.take({"Sphere", "Temperature"})),
41  start_time_(modus_config.take({"Sphere", "Start_Time"}, 0.)),
42  use_thermal_(
43  modus_config.take({"Sphere", "Use_Thermal_Multiplicities"}, false)),
44  mub_(modus_config.take({"Sphere", "Baryon_Chemical_Potential"}, 0.)),
45  mus_(modus_config.take({"Sphere", "Strange_Chemical_Potential"}, 0.)),
46  muq_(modus_config.take({"Sphere", "Charge_Chemical_Potential"}, 0.)),
47  account_for_resonance_widths_(
48  modus_config.take({"Sphere", "Account_Resonance_Widths"}, true)),
49  init_multipl_(use_thermal_
50  ? std::map<PdgCode, int>()
51  : modus_config.take({"Sphere", "Init_Multiplicities"})
52  .convert_for(init_multipl_)),
53  init_distr_(
54  modus_config.take({"Sphere", "Initial_Condition"},
56  radial_velocity_(
57  modus_config.take({"Sphere", "Add_Radial_Velocity"}, -1.)),
58  /* Note that it is crucial not to take other keys from the Jet section
59  * before Jet_PDG, since we want here the take to throw in case the user
60  * had a Jet section without the mandatory Jet_PDG key. If all other keys
61  * are taken first, the section is removed from modus_config, because
62  * empty, and that has_value({"Sphere", "Jet"}) method would return false.
63  */
64  jet_pdg_(modus_config.has_value({"Sphere", "Jet"})
65  ? make_optional<PdgCode>(
66  modus_config.take({"Sphere", "Jet", "Jet_PDG"}))
67  : std::nullopt),
68 
69  jet_mom_(modus_config.take({"Sphere", "Jet", "Jet_Momentum"}, 20.)) {}
70 
71 /* console output on startup of sphere specific parameters */
72 std::ostream &operator<<(std::ostream &out, const SphereModus &m) {
73  out << "-- Sphere Modus:\nRadius of the sphere: " << m.radius_ << " fm\n";
74  if (m.use_thermal_) {
75  out << "Thermal multiplicities (T = " << m.sphere_temperature_
76  << " GeV, muB = " << m.mub_ << " GeV, muS = " << m.mus_
77  << " GeV, muQ = " << m.muq_ << " GeV)\n";
78  } else {
79  for (const auto &p : m.init_multipl_) {
80  ParticleTypePtr ptype = &ParticleType::find(p.first);
81  out << ptype->name() << " initial multiplicity " << p.second << '\n';
82  }
83  }
84  switch (m.init_distr_) {
86  out << "Boltzmann momentum distribution with T = "
87  << m.sphere_temperature_ << " GeV.\n";
88  break;
90  out << "Fermi/Bose momentum distribution with T = "
91  << m.sphere_temperature_ << " GeV.\n";
92  break;
94  out << "Sphere Initial Condition is IC_ES";
95  break;
97  out << "Sphere Initial Condition is IC_1M";
98  break;
100  out << "Sphere Initial Condition is IC_2M";
101  break;
103  out << "Sphere Initial Condition is IC_Massive";
104  break;
105  }
106  if (m.jet_pdg_) {
107  ParticleTypePtr ptype = &ParticleType::find(m.jet_pdg_.value());
108  out << "Adding a " << ptype->name() << " as a jet in the middle "
109  << "of the sphere with " << m.jet_mom_ << " GeV initial momentum.\n";
110  }
111  return out;
112 }
113 
114 /* initial_conditions - sets particle data for @particles */
116  const ExperimentParameters &parameters) {
117  FourVector momentum_total(0, 0, 0, 0);
118  const double T = this->sphere_temperature_;
119  const double V = 4.0 / 3.0 * M_PI * radius_ * radius_ * radius_;
120  /* Create NUMBER OF PARTICLES according to configuration */
121  if (use_thermal_) {
122  if (average_multipl_.empty()) {
123  for (const ParticleType &ptype : ParticleType::list_all()) {
124  if (HadronGasEos::is_eos_particle(ptype)) {
125  const double n = HadronGasEos::partial_density(
127  average_multipl_[ptype.pdgcode()] = n * V * parameters.testparticles;
128  }
129  }
130  }
131  double nb_init = 0.0, ns_init = 0.0, nq_init = 0.0;
132  for (const auto &mult : average_multipl_) {
133  const int thermal_mult_int = random::poisson(mult.second);
134  particles->create(thermal_mult_int, mult.first);
135  nb_init += mult.second * mult.first.baryon_number();
136  ns_init += mult.second * mult.first.strangeness();
137  nq_init += mult.second * mult.first.charge();
138  logg[LSphere].debug(mult.first, " initial multiplicity ",
139  thermal_mult_int);
140  }
141  logg[LSphere].info("Initial hadron gas baryon density ", nb_init);
142  logg[LSphere].info("Initial hadron gas strange density ", ns_init);
143  logg[LSphere].info("Initial hadron gas charge density ", nq_init);
144  } else {
145  for (const auto &p : init_multipl_) {
146  particles->create(p.second * parameters.testparticles, p.first);
147  logg[LSphere].debug("Particle ", p.first, " initial multiplicity ",
148  p.second);
149  }
150  }
151  std::unique_ptr<QuantumSampling> quantum_sampling;
153  quantum_sampling = std::make_unique<QuantumSampling>(init_multipl_, V, T);
154  }
155  /* loop over particle data to fill in momentum and position information */
156  for (ParticleData &data : *particles) {
157  Angles phitheta;
158  /* thermal momentum according Maxwell-Boltzmann distribution */
159  double momentum_radial = 0.0, mass = data.pole_mass();
160  /* assign momentum_radial according to requested distribution */
161  switch (init_distr_) {
163  momentum_radial = sample_momenta_IC_ES(T);
164  break;
166  momentum_radial = sample_momenta_1M_IC(T, mass);
167  break;
169  momentum_radial = sample_momenta_2M_IC(T, mass);
170  break;
172  momentum_radial = sample_momenta_non_eq_mass(T, mass);
173  break;
175  default:
177  ? data.type().mass()
178  : HadronGasEos::sample_mass_thermal(data.type(), 1.0 / T);
179  momentum_radial = sample_momenta_from_thermal(T, mass);
180  break;
182  /*
183  * **********************************************************************
184  * Sampling the thermal momentum according Bose/Fermi/Boltzmann
185  * distribution.
186  * We take the pole mass as the mass.
187  * **********************************************************************
188  */
189  mass = data.type().mass();
190  momentum_radial = quantum_sampling->sample(data.pdgcode());
191  break;
192  }
193  phitheta.distribute_isotropically();
194  logg[LSphere].debug(data.type().name(), "(id ", data.id(),
195  ") radial momentum ", momentum_radial, ", direction",
196  phitheta);
197  data.set_4momentum(mass, phitheta.threevec() * momentum_radial);
198  momentum_total += data.momentum();
199  /* uniform sampling in a sphere with radius r */
200  double position_radial;
201  position_radial = std::cbrt(random::canonical()) * radius_;
202  Angles pos_phitheta;
203  pos_phitheta.distribute_isotropically();
204  data.set_4position(
205  FourVector(start_time_, pos_phitheta.threevec() * position_radial));
206  data.set_formation_time(start_time_);
207  }
208 
209  /* boost in radial direction with an underlying velocity field of the form u_r
210  * = u_0 * r / R */
211  if (radial_velocity_ > 0.0) {
212  if (radial_velocity_ > 1.0) {
213  throw std::invalid_argument(
214  "Additional velocity cannot be greater than 1!");
215  }
216  for (ParticleData &data : *particles) {
217  double particle_radius = std::sqrt(data.position().sqr3());
218  auto e_r = data.position().threevec() / particle_radius;
219  auto radial_velocity =
220  -1.0 * radial_velocity_ * e_r * particle_radius / radius_;
221  data.set_4momentum(data.momentum().lorentz_boost(radial_velocity));
222  momentum_total += data.momentum();
223  }
224  }
225 
226  /* Make total 3-momentum 0 */
227  for (ParticleData &data : *particles) {
228  data.set_4momentum(data.momentum().abs(),
229  data.momentum().threevec() -
230  momentum_total.threevec() / particles->size());
231  }
232 
233  /* Add a single highly energetic particle in the center of the sphere (jet) */
234  if (jet_pdg_) {
235  auto &jet_particle = particles->create(jet_pdg_.value());
236  jet_particle.set_formation_time(start_time_);
237  jet_particle.set_4position(FourVector(start_time_, 0., 0., 0.));
238  jet_particle.set_4momentum(ParticleType::find(jet_pdg_.value()).mass(),
239  ThreeVector(jet_mom_, 0., 0.));
240  }
241 
242  /* Recalculate total momentum */
243  momentum_total = FourVector(0, 0, 0, 0);
244  for (ParticleData &data : *particles) {
245  momentum_total += data.momentum();
246  /* IC: debug checks */
247  logg[LSphere].debug() << data;
248  }
249  /* allows to check energy conservation */
250  logg[LSphere].debug() << "Sphere initial total 4-momentum [GeV]: "
251  << momentum_total;
252  return start_time_;
253 }
254 } // namespace smash
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
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
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
SphereModus: Provides a modus for expanding matter calculations.
Definition: spheremodus.h:49
const bool account_for_resonance_widths_
In case of thermal initialization: true – account for resonance spectral functions,...
Definition: spheremodus.h:115
const bool use_thermal_
Whether to use a thermal initialization for all particles instead of specific numbers.
Definition: spheremodus.h:94
const double muq_
Charge chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:109
double sphere_temperature_
Temperature for momentum distribution (in GeV)
Definition: spheremodus.h:87
const double start_time_
Starting time for the Sphere.
Definition: spheremodus.h:89
const SphereInitialCondition init_distr_
Initialization scheme for momenta in the sphere; used for expanding metric setup.
Definition: spheremodus.h:130
const std::optional< PdgCode > jet_pdg_
Optional PDG code of the particle to use as a jet, i.e.
Definition: spheremodus.h:144
SphereModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
Definition: spheremodus.cc:37
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: spheremodus.cc:115
std::map< PdgCode, double > average_multipl_
Average multiplicities in case of thermal initialization.
Definition: spheremodus.h:125
const double mub_
Baryon chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:99
const double jet_mom_
Initial momentum of the jet particle; only used if jet_pdg_ is not nullopt.
Definition: spheremodus.h:148
const std::map< PdgCode, int > init_multipl_
Particle multiplicities at initialization; required if use_thermal_ is false.
Definition: spheremodus.h:120
const double mus_
Strange chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:104
const double radial_velocity_
Wether to add a constant radial velocity profile to the momenta of the particles in the sphere.
Definition: spheremodus.h:136
double radius_
Sphere radius (in fm)
Definition: spheremodus.h:85
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.
@ IC_ES
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
@ ThermalMomentaQuantum
A thermalized ensemble is generated, with momenta of baryons(mesons) sampled from a Fermi(Bose) distr...
@ IC_Massive
A generalization of IC_ES for the non-zero mass case; note that there is currently no analytical comp...
@ IC_2M
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
@ IC_1M
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
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
T canonical()
Definition: random.h:113
Definition: action.h:24
static constexpr int LSphere
Definition: spheremodus.cc:35
double sample_momenta_from_thermal(const double temperature, const double mass)
Samples a momentum from the Maxwell-Boltzmann (thermal) distribution in a faster way,...
double sample_momenta_IC_ES(const double temperature)
Sample momenta according to the momentum distribution in Bazow:2016oky .
double sample_momenta_non_eq_mass(const double temperature, const double mass)
Samples a momentum via rejection method from the non-equilibrium distribution.
double sample_momenta_1M_IC(const double temperature, const double mass)
Samples a momentum from the non-equilibrium distribution 1M_IC from Bazow:2016oky .
double sample_momenta_2M_IC(const double temperature, const double mass)
Samples a momentum from the non-equilibrium distribution 2M_IC from Bazow:2016oky .
Helper structure for Experiment.
int testparticles
Number of test-particles.