Version: SMASH-1.5
nucleus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include "smash/nucleus.h"
8 
9 #include <fstream>
10 #include <iostream>
11 #include <limits>
12 #include <map>
13 #include <string>
14 
15 #include "smash/angles.h"
16 #include "smash/constants.h"
17 #include "smash/fourvector.h"
18 #include "smash/logging.h"
19 #include "smash/numerics.h"
20 #include "smash/particles.h"
21 #include "smash/pdgcode.h"
22 #include "smash/random.h"
23 #include "smash/threevector.h"
24 
25 namespace smash {
26 
27 Nucleus::Nucleus(const std::map<PdgCode, int> &particle_list, int nTest) {
28  fill_from_list(particle_list, nTest);
30 }
31 
32 Nucleus::Nucleus(Configuration &config, int nTest) {
33  // Fill nuclei with particles.
34  std::map<PdgCode, int> part = config.take({"Particles"});
35  fill_from_list(part, nTest);
36  // Look for user-defined values or take the default parameters.
37  if (config.has_value({"Diffusiveness"}) && config.has_value({"Radius"}) &&
38  config.has_value({"Saturation_Density"})) {
40  } else if (!config.has_value({"Diffusiveness"}) &&
41  !config.has_value({"Radius"}) &&
42  !config.has_value({"Saturation_Density"})) {
44  } else {
45  throw std::invalid_argument(
46  "Diffussiveness, Radius and Saturation_Density "
47  "required to manually configure the Woods-Saxon"
48  " distribution. Only one/two were provided. \n"
49  "Providing none of the above mentioned "
50  "parameters automatically configures the "
51  "distribution based on the atomic number.");
52  }
53 }
54 
55 double Nucleus::mass() const {
56  double total_mass = 0.;
57  for (auto i = cbegin(); i != cend(); i++) {
58  total_mass += i->momentum().abs();
59  }
60  return total_mass / (testparticles_ + 0.0);
61 }
62 
216  // Get the solid angle of the nucleon.
217  Angles dir;
219  // diffusiveness_ zero or negative? Use hard sphere.
220  if (almost_equal(diffusiveness_, 0.)) {
221  return dir.threevec() * nuclear_radius_ * std::cbrt(random::canonical());
222  }
223  if (almost_equal(nuclear_radius_, 0.)) {
224  return smash::ThreeVector();
225  }
226  double radius_scaled = nuclear_radius_ / diffusiveness_;
227  double prob_range1 = 1.0;
228  double prob_range2 = 3. / radius_scaled;
229  double prob_range3 = 2. * prob_range2 / radius_scaled;
230  double prob_range4 = 1. * prob_range3 / radius_scaled;
231  double ranges234 = prob_range2 + prob_range3 + prob_range4;
232  double t;
234  do {
235  double which_range = random::uniform(-prob_range1, ranges234);
236  if (which_range < 0.0) {
237  t = radius_scaled * (std::cbrt(random::canonical()) - 1.);
238  } else {
239  t = -std::log(random::canonical());
240  if (which_range >= prob_range2) {
241  t -= std::log(random::canonical());
242  if (which_range >= prob_range2 + prob_range3) {
243  t -= std::log(random::canonical());
244  }
245  }
246  }
254  } while (random::canonical() > 1. / (1. + std::exp(-std::abs(t))));
256  double position_scaled = t + radius_scaled;
257  double position = position_scaled * diffusiveness_;
258  return dir.threevec() * position;
259 }
260 
261 double Nucleus::woods_saxon(double r) {
262  return r * r / (std::exp((r - nuclear_radius_) / diffusiveness_) + 1);
263 }
264 
266  for (auto i = begin(); i != end(); i++) {
267  // Initialize momentum
268  i->set_4momentum(i->pole_mass(), 0.0, 0.0, 0.0);
269  /* Sampling the Woods-Saxon, get the radial
270  * position and solid angle for the nucleon. */
272 
273  // Set the position of the nucleon.
274  i->set_4position(FourVector(0.0, pos));
275  }
276 
277  // Recenter and rotate
278  align_center();
279  rotate();
280 }
281 
284  switch (A) {
285  case 1: // single particle
286  /* In case of testparticles, an infinite reaction loop will be
287  * avoided by a small finite spread according to a single particles
288  * 'nucleus'. The proper solution will be to introduce parallel
289  * ensembles. */
291  ? 0.
292  : 1. - std::exp(-(testparticles_ - 1.) * 0.1));
293  set_diffusiveness(testparticles_ == 1 ? -1. : 0.02);
294  break;
295  case 238: // Uranium
296  // Default values.
297  set_diffusiveness(0.556);
298  set_nuclear_radius(6.86);
299  set_saturation_density(0.166);
300  break;
301  case 208: // Lead
302  // Default values.
303  set_diffusiveness(0.54);
304  set_nuclear_radius(6.67);
305  set_saturation_density(0.161);
306  break;
307  case 197: // Gold
308  // Default values.
309  set_diffusiveness(0.535);
310  set_nuclear_radius(6.38);
311  set_saturation_density(0.1695);
312  break;
313  case 63: // Copper
314  // Default values.
315  set_diffusiveness(0.5977);
316  set_nuclear_radius(4.20641);
317  set_saturation_density(0.1686);
318  break;
319  default:
320  if (A <= 16) {
321  // radius: rough guess for all nuclei not listed explicitly with A <= 16
322  // saturation density already has reasonable default
323  set_nuclear_radius(1.2 * std::cbrt(A));
324  set_diffusiveness(0.545);
325  } else {
326  // radius and diffusiveness taken from \iref{Rybczynski:2013yba}
327  set_diffusiveness(0.54);
328  set_nuclear_radius(1.12 * pow(std::cbrt(A), 1.0 / 3.0) -
329  0.86 * pow(std::cbrt(A), -1.0 / 3.0));
330  }
331  }
332 }
333 
335  set_diffusiveness(static_cast<double>(config.take({"Diffusiveness"})));
336  set_nuclear_radius(static_cast<double>(config.take({"Radius"})));
337  // Saturation density (normalization for accept/reject sampling)
339  static_cast<double>(config.take({"Saturation_Density"})));
340 }
341 
343  const int N_n = std::count_if(begin(), end(), [](const ParticleData i) {
344  return i.pdgcode() == pdg::n;
345  });
346  const int N_p = std::count_if(begin(), end(), [](const ParticleData i) {
347  return i.pdgcode() == pdg::p;
348  });
349  const FourVector nucleus_center = center();
350  const int A = N_n + N_p;
351  constexpr double pi2_3 = 3.0 * M_PI * M_PI;
352  const auto &log = logger<LogArea::Nucleus>();
353 
354  log.debug() << N_n << " neutrons, " << N_p << " protons.";
355 
356  ThreeVector ptot = ThreeVector(0.0, 0.0, 0.0);
357  for (auto i = begin(); i != end(); i++) {
358  // Only protons and neutrons get Fermi momenta
359  if (i->pdgcode() != pdg::p && i->pdgcode() != pdg::n) {
360  if (i->is_baryon()) {
361  log.warn() << "No rule to calculate Fermi momentum "
362  << "for particle " << i->pdgcode();
363  }
364  continue;
365  }
366  const double r = (i->position() - nucleus_center).abs3();
367  double rho = nuclear_density /
368  (std::exp((r - nuclear_radius_) / diffusiveness_) + 1.);
369  if (i->pdgcode() == pdg::p) {
370  rho = rho * N_p / A;
371  }
372  if (i->pdgcode() == pdg::n) {
373  rho = rho * N_n / A;
374  }
375  const double p =
376  hbarc * std::pow(pi2_3 * rho * random::uniform(0.0, 1.0), 1.0 / 3.0);
377  Angles phitheta;
378  phitheta.distribute_isotropically();
379  const ThreeVector ith_3momentum = phitheta.threevec() * p;
380  ptot += ith_3momentum;
381  i->set_3momentum(ith_3momentum);
382  log.debug() << "Particle: " << *i
383  << ", pF[GeV]: " << hbarc * std::pow(pi2_3 * rho, 1.0 / 3.0)
384  << " r[fm]: " << r
385  << " Nuclear radius[fm]: " << nuclear_radius_;
386  }
387  if (A == 0) {
388  // No Fermi momenta should be assigned
389  assert(ptot.x1() == 0.0 && ptot.x2() == 0.0 && ptot.x3() == 0.0);
390  } else {
391  /* Ensure zero total momentum of nucleus - redistribute ptot equally
392  * among protons and neutrons */
393  const ThreeVector centralizer = ptot / A;
394  for (auto i = begin(); i != end(); i++) {
395  if (i->pdgcode() == pdg::p || i->pdgcode() == pdg::n) {
396  i->set_4momentum(i->pole_mass(),
397  i->momentum().threevec() - centralizer);
398  }
399  }
400  }
401 }
402 
403 void Nucleus::boost(double beta_scalar) {
404  double beta_squared = beta_scalar * beta_scalar;
405  double one_over_gamma = std::sqrt(1.0 - beta_squared);
406  double gamma = 1.0 / one_over_gamma;
407  /* We are talking about a /passive/ lorentz transformation here, as
408  * far as I can see, so we need to boost in the direction opposite to
409  * where we want to go
410  * ( The vector we transform - p - stays unchanged, but we go into
411  * a system that moves with -beta. Now in this frame, it seems
412  * like p has been accelerated with +beta.
413  * ) */
414  for (auto i = begin(); i != end(); i++) {
415  /* a real Lorentz Transformation would leave the particles at
416  * different times here, which we would then have to propagate back
417  * to equal times. Since we know the result, we can simply multiply
418  * the z-value with 1/gamma. */
419  FourVector this_position = i->position();
420  this_position.set_x3(this_position.x3() * one_over_gamma);
421  i->set_4position(this_position);
422  /* The simple Lorentz transformation of momenta does not take into account
423  * that nucleus has binding energy. Here we apply the method used
424  * in the JAM code \iref{Nara:1999dz}: p' = p_beam + gamma*p_F.
425  * This formula is derived under assumption that all nucleons have
426  * the same binding energy. */
427  FourVector mom_i = i->momentum();
428  i->set_4momentum(i->pole_mass(), mom_i.x1(), mom_i.x2(),
429  gamma * (beta_scalar * mom_i.x0() + mom_i.x3()));
430  }
431 }
432 
433 void Nucleus::fill_from_list(const std::map<PdgCode, int> &particle_list,
434  int testparticles) {
435  testparticles_ = testparticles;
436  for (auto n = particle_list.cbegin(); n != particle_list.cend(); ++n) {
437  const ParticleType &current_type = ParticleType::find(n->first);
438  double current_mass = current_type.mass();
439  for (unsigned int i = 0; i < n->second * testparticles_; i++) {
440  // append particle to list and set its PDG code.
441  particles_.emplace_back(current_type);
442  particles_.back().set_4momentum(current_mass, 0.0, 0.0, 0.0);
443  }
444  }
445 }
446 
447 void Nucleus::shift(double z_offset, double x_offset, double simulation_time) {
448  // Move the nucleus in z and x directions, and set the time.
449  for (auto i = begin(); i != end(); i++) {
450  FourVector this_position = i->position();
451  this_position.set_x3(this_position.x3() + z_offset);
452  this_position.set_x1(this_position.x1() + x_offset);
453  this_position.set_x0(simulation_time);
454  i->set_4position(this_position);
455  i->set_formation_time(simulation_time);
456  }
457 }
458 
459 void Nucleus::copy_particles(Particles *external_particles) {
460  for (auto p = begin(); p != end(); p++) {
461  external_particles->insert(*p);
462  }
463 }
464 
466  FourVector centerpoint(0.0, 0.0, 0.0, 0.0);
467  for (auto p = cbegin(); p != cend(); p++) {
468  centerpoint += p->position();
469  }
470  centerpoint /= size();
471  return centerpoint;
472 }
473 
474 std::ostream &operator<<(std::ostream &out, const Nucleus &n) {
475  return out << " #particles #testparticles mass [GeV] "
476  "radius [fm] diffusiveness [fm]\n"
477  << format(n.number_of_particles(), nullptr, 12)
478  << format(n.size(), nullptr, 17) << format(n.mass(), nullptr, 13)
479  << format(n.get_nuclear_radius(), nullptr, 14)
480  << format(n.get_diffusiveness(), nullptr, 20);
481 }
482 
483 } // namespace smash
FormattingHelper< T > format(const T &value, const char *unit, int width=-1, int precision=-1)
Acts as a stream modifier for std::ostream to output an object with an optional suffix string and wit...
Definition: logging.h:310
double mass() const
Definition: particletype.h:134
size_t size() const
Number of numerical (=test-)particles in the nucleus:
Definition: nucleus.h:144
void set_diffusiveness(double diffuse)
Sets the diffusiveness of the nucleus.
Definition: nucleus.h:226
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:30
void shift(double z_offset, double x_offset, double simulation_time)
Shifts the nucleus to correct impact parameter and z displacement.
Definition: nucleus.cc:447
double x3() const
Definition: threevector.h:163
bool almost_equal(const N x, const N y)
Checks two numbers for relative approximate equality.
Definition: numerics.h:42
void set_nuclear_radius(double rad)
Sets the nuclear radius.
Definition: nucleus.h:256
FourVector center() const
Calculate geometrical center of the nucleus.
Definition: nucleus.cc:465
void set_3momentum(const ThreeVector &mom)
Set the momentum of the particle without modifying the energy.
Definition: particledata.h:177
double mass() const
Definition: nucleus.cc:55
Collection of useful constants that are known at compile time.
double pole_mass() const
Get the particle&#39;s pole mass ("on-shell").
Definition: particledata.h:96
A nucleus is a collection of particles that are initialized, before the beginning of the simulation a...
Definition: nucleus.h:27
ThreeVector threevec() const
Definition: angles.h:268
virtual void rotate()
Rotates the nucleus.
Definition: nucleus.h:134
double x1() const
Definition: threevector.h:155
double x3() const
Definition: fourvector.h:302
const FourVector & momentum() const
Get the particle&#39;s 4-momentum.
Definition: particledata.h:139
Interface to the SMASH configuration files.
constexpr double hbarc
GeV <-> fm conversion factor.
Definition: constants.h:25
Nucleus(Configuration &config, int nTest)
Constructor for Nucleus, that needs the configuration parameters from the inputfile and the number of...
Definition: nucleus.cc:32
double x0() const
Definition: fourvector.h:290
Generic numerical functions.
void boost(double beta_scalar)
Boosts the nuclei into the computational frame, such that the nucleons have the appropriate momentum ...
Definition: nucleus.cc:403
T canonical()
Definition: random.h:110
void set_x1(double x)
Definition: fourvector.h:296
virtual ThreeVector distribute_nucleon() const
The distribution of return values from this function is according to a spherically symmetric Woods-Sa...
Definition: nucleus.cc:215
bool has_value(std::initializer_list< const char *> keys) const
Returns whether there is a non-empty value behind the requested keys.
std::vector< ParticleData >::const_iterator cend() const
For const iterators over the particle list:
Definition: nucleus.h:219
void set_saturation_density(double density)
Sets the saturation density of the nucleus.
Definition: nucleus.h:236
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
void set_x3(double z)
Definition: fourvector.h:304
ThreeVector threevec() const
Definition: fourvector.h:306
double x1() const
Definition: fourvector.h:294
bool is_baryon() const
Definition: particledata.h:88
void set_x0(double t)
Definition: fourvector.h:292
const FourVector & position() const
Get the particle&#39;s position in Minkowski space.
Definition: particledata.h:185
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
virtual void generate_fermi_momenta()
Generates momenta according to Fermi motion for the nucleons.
Definition: nucleus.cc:342
double woods_saxon(double x)
Woods-Saxon distribution.
Definition: nucleus.cc:261
const ParticleData & insert(const ParticleData &p)
Inserts the particle into the list of particles.
Definition: particles.cc:50
std::vector< ParticleData >::const_iterator cbegin() const
For const iterators over the particle list:
Definition: nucleus.h:215
T uniform(T min, T max)
Definition: random.h:85
double x2() const
Definition: fourvector.h:298
double nuclear_radius_
Nuclear radius of this nucleus.
Definition: nucleus.h:196
double diffusiveness_
Diffusiveness of Woods-Saxon distribution of this nucleus in fm (for diffusiveness_ == 0...
Definition: nucleus.h:192
void fill_from_list(const std::map< PdgCode, int > &particle_list, int testparticles)
Adds particles from a map PDG code => Number_of_particles_with_that_PDG_code to the nucleus...
Definition: nucleus.cc:433
constexpr int p
Proton.
void arrange_nucleons()
Sets the positions of the nucleons inside a nucleus.
Definition: nucleus.cc:265
constexpr double nuclear_density
Ground state density of symmetric nuclear matter [fm^-3].
Definition: constants.h:42
PdgCode pdgcode() const
Get the pdgcode of the particle.
Definition: particledata.h:81
void copy_particles(Particles *particles)
Copies the particles from this nucleus into the particle list.
Definition: nucleus.cc:459
std::vector< ParticleData > particles_
Particles associated with this nucleus.
Definition: nucleus.h:205
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
std::vector< ParticleData >::iterator begin()
For iterators over the particle list:
Definition: nucleus.h:209
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:188
constexpr int n
Neutron.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:457
virtual void set_parameters_automatic()
Sets the deformation parameters of the Woods-Saxon distribution according to the current mass number...
Definition: nucleus.cc:282
size_t testparticles_
Number of testparticles per physical particle.
Definition: nucleus.h:203
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
void align_center()
Shifts the nucleus so that its center is at (0,0,0)
Definition: nucleus.h:175
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
double x2() const
Definition: threevector.h:159
Definition: action.h:24
std::vector< ParticleData >::iterator end()
For iterators over the particle list:
Definition: nucleus.h:213
size_t number_of_particles() const
Number of physical particles in the nucleus:
Definition: nucleus.h:152
virtual void set_parameters_from_config(Configuration &config)
Sets the parameters of the Woods-Saxon according to manually added values in the configuration file...
Definition: nucleus.cc:334