Version: SMASH-1.5
grandcan_thermalizer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #ifndef SRC_INCLUDE_GRANDCAN_THERMALIZER_H_
8 #define SRC_INCLUDE_GRANDCAN_THERMALIZER_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "angles.h"
14 #include "clock.h"
15 #include "configuration.h"
16 #include "density.h"
17 #include "distributions.h"
18 #include "forwarddeclarations.h"
19 #include "hadgas_eos.h"
20 #include "lattice.h"
21 #include "particledata.h"
22 #include "quantumnumbers.h"
23 
24 namespace smash {
25 
49  public:
65  void add_particle(const ParticleData& p, double factor);
89  void set_rest_frame_quantities(double T0, double mub0, double mus0,
90  const ThreeVector v0);
92  FourVector Tmu0() const { return Tmu0_; }
94  double nb() const { return nb_; }
96  double ns() const { return ns_; }
98  double e() const { return e_; }
100  double p() const { return p_; }
102  ThreeVector v() const { return v_; }
104  double T() const { return T_; }
106  double mub() const { return mub_; }
108  double mus() const { return mus_; }
109 
110  private:
114  double nb_;
116  double ns_;
118  double e_;
120  double p_;
124  double T_;
126  double mub_;
128  double mus_;
129 };
130 
137 std::ostream& operator<<(std::ostream& s, const ThermLatticeNode& node);
138 
143 enum class HadronClass {
145  Baryon = 0,
147  Antibaryon = 1,
149  PositiveSMeson = 2,
151  NegativeSMeson = 3,
157  ZeroQZeroSMeson = 6,
158 };
159 
206  public:
221  GrandCanThermalizer(const std::array<double, 3> lat_sizes,
222  const std::array<int, 3> n_cells,
223  const std::array<double, 3> origin, bool periodicity,
224  double e_critical, double t_start, double delta_t,
228  const std::array<double, 3> lat_sizes,
229  const std::array<double, 3> origin, bool periodicity)
231  lat_sizes, conf.take({"Cell_Number"}), origin, periodicity,
232  conf.take({"Critical_Edens"}), conf.take({"Start_Time"}),
233  conf.take({"Timestep"}),
234  conf.take({"Algorithm"}, ThermalizationAlgorithm::BiasedBF)) {}
240  bool is_time_to_thermalize(const Clock& clock) const {
241  const double t = clock.current_time();
242  const int n = static_cast<int>(std::floor((t - t_start_) / period_));
243  return (t > t_start_ &&
244  t < t_start_ + n * period_ + clock.timestep_duration());
245  }
253  void update_thermalizer_lattice(const Particles& particles,
254  const DensityParameters& par,
255  bool ignore_cells_under_threshold = true);
265  void renormalize_momenta(ParticleList& plist,
266  const FourVector required_total_momentum);
267 
268  // Functions for BF-sampling algorithm
269 
278  void sample_multinomial(HadronClass particle_class, int N);
290  void sample_in_random_cell_BF_algo(ParticleList& plist, const double time,
291  size_t type_index);
304  void thermalize_BF_algo(QuantumNumbers& conserved_initial, double time,
305  int ntest);
306 
307  // Functions for mode-sampling algorithm
308 
313  template <typename F>
314  void compute_N_in_cells_mode_algo(F&& condition) {
315  N_in_cells_.clear();
316  N_total_in_cells_ = 0.0;
317  for (auto cell_index : cells_to_sample_) {
318  const ThermLatticeNode cell = (*lat_)[cell_index];
319  const double gamma = 1.0 / std::sqrt(1.0 - cell.v().sqr());
320  double N_tot = 0.0;
321  for (ParticleTypePtr i : eos_typelist_) {
322  if (condition(i->strangeness(), i->baryon_number(), i->charge())) {
323  // N_i = n u^mu dsigma_mu = (isochronous hypersurface) n * V * gamma
324  N_tot += cell_volume_ * gamma *
325  HadronGasEos::partial_density(*i, cell.T(), cell.mub(),
326  cell.mus());
327  }
328  }
329  N_in_cells_.push_back(N_tot);
330  N_total_in_cells_ += N_tot;
331  }
332  }
333 
344  template <typename F>
346  F&& condition) {
347  // Choose random cell, probability = N_in_cell/N_total
348  double r = random::uniform(0.0, N_total_in_cells_);
349  double partial_sum = 0.0;
350  int index_only_thermalized = -1;
351  while (partial_sum < r) {
352  index_only_thermalized++;
353  partial_sum += N_in_cells_[index_only_thermalized];
354  }
355  const int cell_index = cells_to_sample_[index_only_thermalized];
356  const ThermLatticeNode cell = (*lat_)[cell_index];
357  const ThreeVector cell_center = lat_->cell_center(cell_index);
358  const double gamma = 1.0 / std::sqrt(1.0 - cell.v().sqr());
359  const double N_in_cell = N_in_cells_[index_only_thermalized];
360  // Which sort to sample - probability N_i/N_tot
361  r = random::uniform(0.0, N_in_cell);
362  double N_sum = 0.0;
363  ParticleTypePtr type_to_sample;
364  for (ParticleTypePtr i : eos_typelist_) {
365  if (!condition(i->strangeness(), i->baryon_number(), i->charge())) {
366  continue;
367  }
368  N_sum +=
369  cell_volume_ * gamma *
370  HadronGasEos::partial_density(*i, cell.T(), cell.mub(), cell.mus());
371  if (N_sum >= r) {
372  type_to_sample = i;
373  break;
374  }
375  }
376  ParticleData particle(*type_to_sample);
377  // Note: it's pole mass for resonances!
378  const double m = type_to_sample->mass();
379  // Position
380  particle.set_4position(FourVector(time, cell_center + uniform_in_cell()));
381  // Momentum
382  double momentum_radial = sample_momenta_from_thermal(cell.T(), m);
383  Angles phitheta;
384  phitheta.distribute_isotropically();
385  particle.set_4momentum(m, phitheta.threevec() * momentum_radial);
386  particle.boost_momentum(-cell.v());
387  particle.set_formation_time(time);
388  return particle;
389  }
390 
399  void thermalize_mode_algo(QuantumNumbers& conserved_initial, double time);
407  void thermalize(const Particles& particles, double time, int ntest);
408 
415  void print_statistics(const Clock& clock) const;
419  double e_crit() const { return e_crit_; }
421  ParticleList particles_to_remove() const { return to_remove_; }
423  ParticleList particles_to_insert() const { return sampled_list_; }
424 
425  private:
430  ParticleTypePtrList list_eos_particles() const {
431  ParticleTypePtrList res;
432  for (const ParticleType& ptype : ParticleType::list_all()) {
433  if (HadronGasEos::is_eos_particle(ptype)) {
434  res.push_back(&ptype);
435  }
436  }
437  return res;
438  }
443  HadronClass get_class(size_t typelist_index) const {
444  const int B = eos_typelist_[typelist_index]->baryon_number();
445  const int S = eos_typelist_[typelist_index]->strangeness();
446  const int ch = eos_typelist_[typelist_index]->charge();
447  // clang-format off
448  return (B > 0) ? HadronClass::Baryon :
449  (B < 0) ? HadronClass::Antibaryon :
450  (S > 0) ? HadronClass::PositiveSMeson :
451  (S < 0) ? HadronClass::NegativeSMeson :
455  // clang-format on
456  }
458  double mult_class(const HadronClass cl) const {
459  return mult_classes_[static_cast<size_t>(cl)];
460  }
462  std::vector<double> N_in_cells_;
464  std::vector<size_t> cells_to_sample_;
468  std::unique_ptr<RectangularLattice<ThermLatticeNode>> lat_;
470  ParticleList to_remove_;
472  ParticleList sampled_list_;
481  const ParticleTypePtrList eos_typelist_;
483  const size_t N_sorts_;
485  std::vector<double> mult_sort_;
487  std::vector<int> mult_int_;
492  std::array<double, 7> mult_classes_;
499  double cell_volume_;
501  const double e_crit_;
503  const double t_start_;
505  const double period_;
508 };
509 
510 } // namespace smash
511 
512 #endif // SRC_INCLUDE_GRANDCAN_THERMALIZER_H_
double p() const
Get pressure in the rest frame.
const double e_crit_
Critical energy density above which cells are thermalized.
void add_particle(const ParticleData &p, double factor)
Add particle contribution to Tmu0, nb and ns May look like unused at first glance, but it is actually used by update_lattice, where the node type of the lattice is templated.
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:103
double mass() const
Definition: particletype.h:134
ThermalizationAlgorithm
Defines the algorithm used for the forced thermalization.
GrandCanThermalizer(const std::array< double, 3 > lat_sizes, const std::array< int, 3 > n_cells, const std::array< double, 3 > origin, bool periodicity, double e_critical, double t_start, double delta_t, ThermalizationAlgorithm algo)
Default constructor for the GranCanThermalizer to allocate the lattice.
const size_t N_sorts_
Number of different species to be sampled.
ParticleList particles_to_remove() const
List of particles to be removed from the simulation.
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:30
void sample_multinomial(HadronClass particle_class, int N)
The sample_multinomial function samples integer numbers n_i distributed according to the multinomial ...
ThermLatticeNode()
Default constructor of thermal quantities on the lattice returning thermodynamic quantities in comput...
double mub() const
Get the net baryon chemical potential.
Class to handle the equation of state (EoS) of the hadron gas, consisting of all hadrons included int...
Definition: hadgas_eos.h:112
FourVector Tmu0_
Four-momentum flow of the cell.
void thermalize(const Particles &particles, double time, int ntest)
Main thermalize function, that chooses the algorithm to follow (BF or mode sampling).
double timestep_duration() const
Definition: clock.h:128
bool is_time_to_thermalize(const Clock &clock) const
Check that the clock is close to n * period of thermalization, since the thermalization only happens ...
void add_particle_for_derivatives(const ParticleData &, double, ThreeVector)
dummy function for update_lattice
void thermalize_BF_algo(QuantumNumbers &conserved_initial, double time, int ntest)
Samples particles according to the BF algorithm by making use of the.
ParticleTypePtrList list_eos_particles() const
Extracts the particles in the hadron gas equation of state from the complete list of particle types i...
const double period_
Defines periodicity of the lattice in fm.
double ns() const
Get net strangeness density of the cell in the computational frame.
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:277
const ThermalizationAlgorithm algorithm_
Algorithm to choose for sampling of particles obeying conservation laws.
void set_formation_time(const double &form_time)
Set the absolute formation time.
Definition: particledata.h:232
double nb() const
Get net baryon density of the cell in the computational frame.
void print_statistics(const Clock &clock) const
Generates standard output with information about the thermodynamic properties of the lattice...
void set_rest_frame_quantities(double T0, double mub0, double mus0, const ThreeVector v0)
Set all the rest frame quantities to some values, this is useful for testing.
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:46
void update_thermalizer_lattice(const Particles &particles, const DensityParameters &par, bool ignore_cells_under_threshold=true)
Compute all the thermodynamical quantities on the lattice from particles.
ThreeVector v_
Velocity of the rest frame.
double p_
Pressure in the rest frame.
static const ParticleTypeList & list_all()
Definition: particletype.cc:55
HadronClass get_class(size_t typelist_index) const
Defines the class of hadrons by quantum numbers.
double ns_
Net strangeness density of the cell in the computational frame.
double mub_
Net baryon chemical potential.
GrandCanThermalizer(Configuration &conf, const std::array< double, 3 > lat_sizes, const std::array< double, 3 > origin, bool periodicity)
ParticleList sampled_list_
Newly generated particles by thermalizer.
Particle type contains the static properties of a particle species.
Definition: particletype.h:87
void set_4momentum(const FourVector &momentum_vector)
Set the particle&#39;s 4-momentum directly.
Definition: particledata.h:145
double sqr() const
Definition: threevector.h:249
Non-strange mesons (S = 0) with electric cherge Q < 0.
A container for storing conserved values.
void compute_rest_frame_quantities(HadronGasEos &eos)
Temperature, chemical potentials and rest frame velocity are calculated given the hadron gas equation...
double e() const
Get energy density in the rest frame.
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.
void compute_N_in_cells_mode_algo(F &&condition)
Computes average number of particles in each cell for the mode algorithm.
std::vector< size_t > cells_to_sample_
Cells above critical energy density.
Mesons with strangeness S < 0.
T uniform(T min, T max)
Definition: random.h:85
double N_total_in_cells_
Total number of particles over all cells in thermalization region.
void thermalize_mode_algo(QuantumNumbers &conserved_initial, double time)
Samples particles to the according to the mode algorithm.
The GrandCanThermalizer class implements the following functionality:
void renormalize_momenta(ParticleList &plist, const FourVector required_total_momentum)
Changes energy and momenta of the particles in plist to match the required_total_momentum.
Clock tracks the time in the simulation.
Definition: clock.h:75
Neutral non-strange mesons.
Non-strange mesons (S = 0) with electric cherge Q > 0.
ParticleData sample_in_random_cell_mode_algo(const double time, F &&condition)
Samples one particle and the species, cell, momentum and coordinate are chosen from the corresponding...
std::vector< double > mult_sort_
Real number multiplicity for each particle type.
ParticleList to_remove_
Particles to be removed after this thermalization step.
double e_crit() const
Get the critical energy density.
Mesons with strangeness S > 0.
std::vector< double > N_in_cells_
Number of particles to be sampled in one cell.
double nb_
Net baryon density of the cell in the computational frame.
ThreeVector uniform_in_cell() const
RectangularLattice< ThermLatticeNode > & lattice() const
Getter function for the lattice.
static double partial_density(const ParticleType &ptype, double T, double mub, double mus)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:219
FourVector Tmu0() const
Get Four-momentum flow of the cell.
void set_4position(const FourVector &pos)
Set the particle&#39;s 4-position directly.
Definition: particledata.h:190
double e_
Energy density in the rest frame.
The ThermLatticeNode class is intended to compute thermodynamical quantities in a cell given a set of...
HadronClass
Specifier to classify the different hadron species according to their quantum numbers.
std::vector< int > mult_int_
Integer multiplicity for each particle type.
double mus_
Net strangeness chemical potential.
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
void sample_in_random_cell_BF_algo(ParticleList &plist, const double time, size_t type_index)
The total number of particles of species type_index is defined by mult_int_ array that is returned by...
double T() const
Get the temperature.
double mus() const
Get the net strangeness chemical potential.
std::array< double, 7 > mult_classes_
The different hadron species according to the enum defined in.
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:660
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
std::unique_ptr< RectangularLattice< ThermLatticeNode > > lat_
The lattice on which the thermodynamic quantities are calculated.
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
double current_time() const
Definition: clock.h:110
constexpr int n
Neutron.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:457
ParticleList particles_to_insert() const
List of newly created particles to be inserted in the simulation.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
double cell_volume_
Volume of a single cell, necessary to convert thermal densities to actual particle numbers...
HadronGasEos eos_
Hadron gas equation of state.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
void boost_momentum(const ThreeVector &v)
Apply a Lorentz-boost to only the momentum.
Definition: particledata.h:313
const ParticleTypePtrList eos_typelist_
List of particle types from which equation of state is computed.
double mult_class(const HadronClass cl) const
const double t_start_
Starting time of the simulation.
Definition: action.h:24
ThreeVector v() const
Get 3-velocity of the rest frame.