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