Version: SMASH-1.5
pauliblocking.cc
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 #include "smash/pauliblocking.h"
11 #include "smash/constants.h"
12 #include "smash/logging.h"
13 
14 namespace smash {
15 
16 PauliBlocker::PauliBlocker(Configuration conf,
17  const ExperimentParameters &param)
18  : sig_(param.gaussian_sigma),
19  rc_(conf.take({"Gaussian_Cutoff"}, 2.2)),
20  rr_(conf.take({"Spatial_Averaging_Radius"}, 1.86)),
21  rp_(conf.take({"Momentum_Averaging_Radius"}, 0.08)),
22  ntest_(param.testparticles) {
36  const auto &log = logger<LogArea::PauliBlocking>();
37 
38  if (ntest_ < 20) {
39  log.warn(
40  "Phase-space density calculation in Pauli blocking"
41  " will not work reasonably for a small number of testparticles."
42  " The recommended number of testparticles is 20.");
43  }
44 
45  if (rc_ < rr_ || rr_ < 0.0 || rp_ < 0) {
46  log.error(
47  "Please choose reasonable parameters for Pauli blocking:"
48  "All radii have to be positive and Gaussian_Cutoff should"
49  "be larger than Spatial_Averaging_Radius");
50  }
51 
52  init_weights_analytical();
53 }
54 
55 PauliBlocker::~PauliBlocker() {}
56 
57 double PauliBlocker::phasespace_dens(const ThreeVector &r, const ThreeVector &p,
58  const Particles &particles,
59  const PdgCode pdg,
60  const ParticleList &disregard) const {
61  double f = 0.0;
62 
63  /* TODO(oliiny): looping over all particles is inefficient,
64  * I need only particles within rp_ radius in momentum and
65  * within rr_+rc_ in coordinate space. Some search algorithm might help. */
66  for (const auto &part : particles) {
67  // Only consider identical particles
68  if (part.pdgcode() != pdg) {
69  continue;
70  }
71  // Only consider momenta in sphere of radius rp_ with center at p
72  const double pdist_sqr = (part.momentum().threevec() - p).sqr();
73  if (pdist_sqr > rp_ * rp_) {
74  continue;
75  }
76  const double rdist_sqr = (part.position().threevec() - r).sqr();
77  // Only consider coordinates in sphere of radius rr_+rc_ with center at r
78  if (rdist_sqr >= (rr_ + rc_) * (rr_ + rc_)) {
79  continue;
80  }
81  // Do not count particles that should be disregarded.
82  bool to_disregard = false;
83  for (const auto &disregard_part : disregard) {
84  if (part.id() == disregard_part.id()) {
85  to_disregard = true;
86  }
87  }
88  if (to_disregard) {
89  continue;
90  }
91  // 1st order interpolation using tabulated values
92  const double i_real = std::sqrt(rdist_sqr) / (rr_ + rc_) * weights_.size();
93  const size_t i = std::floor(i_real);
94  const double rest = i_real - i;
95  if (likely(i + 1 < weights_.size())) {
96  f += weights_[i] * rest + weights_[i + 1] * (1. - rest);
97  }
98  }
99  return f / ntest_;
100 }
101 
102 void PauliBlocker::init_weights_analytical() {
103  const auto &log = logger<LogArea::PauliBlocking>();
104 
105  const double pi = M_PI;
106  const double sqrt2 = std::sqrt(2.);
107  const double sqrt_2pi = std::sqrt(2. * pi);
108  // Volume of the phase-space area; Factor 2 stands for spin.
109  const double phase_volume =
110  2 * (4. / 3. * pi * rr_ * rr_ * rr_) * (4. / 3. * pi * rp_ * rp_ * rp_) /
111  ((2 * pi * hbarc) * (2 * pi * hbarc) * (2 * pi * hbarc));
112  // Analytical expression for integral in denominator
113  const double norm =
114  std::erf(rc_ / sqrt2 / sig_) -
115  rc_ * 2 / sqrt_2pi / sig_ * std::exp(-0.5 * rc_ * rc_ / sig_ / sig_);
116 
117  double integral;
118  // Step of the table for tabulated integral
119  const double d_pos = (rr_ + rc_) / static_cast<double>(weights_.size());
120 
121  for (size_t k = 0; k < weights_.size(); k++) {
122  // rdist = 0 ... rc_ (gauss cut) + rr_ (position cut)
123  const double rj = d_pos * k;
124  if (rj < really_small) {
125  // Assuming rc_ > rr_
126  const double A = rr_ / sqrt2 / sig_;
127  integral = sqrt_2pi * sig_ * std::erf(A) - 2 * rr_ * std::exp(-A * A);
128  integral *= sig_ * sig_;
129  } else if (rc_ > rj + rr_) {
130  const double A = (rj + rr_) / sqrt2 / sig_;
131  const double B = (rj - rr_) / sqrt2 / sig_;
132  integral = sig_ / rj * (std::exp(-A * A) - std::exp(-B * B)) +
133  0.5 * sqrt_2pi * (std::erf(A) - std::erf(B));
134  integral *= sig_ * sig_ * sig_;
135  } else {
136  const double A = rc_ / sqrt2 / sig_;
137  const double B = (rj - rr_) / sqrt2 / sig_;
138  const double C = (rc_ - rj) * (rc_ - rj) - rr_ * rr_ + 2 * sig_ * sig_;
139  integral =
140  (0.5 * std::exp(-A * A) * C - sig_ * sig_ * std::exp(-B * B)) / rj +
141  0.5 * sqrt_2pi * sig_ * (std::erf(A) - std::erf(B));
142  integral *= sig_ * sig_;
143  }
144  integral *= 2 * pi / std::pow(2 * pi * sig_ * sig_, 1.5);
145  weights_[k] = integral / norm / phase_volume;
146  log.debug("Analytical weights[", k, "] = ", weights_[k]);
147  }
148 }
149 
150 } // namespace smash
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:30
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:34
#define likely(x)
Tell the branch predictor that this expression is likely true.
Definition: macros.h:14
Collection of useful constants that are known at compile time.
PauliBlocker(Configuration conf, const ExperimentParameters &parameters)
PauliBlocker constructor.
constexpr double hbarc
GeV <-> fm conversion factor.
Definition: constants.h:25
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
constexpr int p
Proton.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
Definition: action.h:24