Version: SMASH-3.1
nucleus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2023
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/random.h"
20 #include "smash/threevector.h"
21 
22 namespace smash {
23 static constexpr int LNucleus = LogArea::Nucleus::id;
24 
25 Nucleus::Nucleus(const std::map<PdgCode, int> &particle_list, int nTest) {
26  fill_from_list(particle_list, nTest);
29 }
30 
31 Nucleus::Nucleus(Configuration &config, int nTest) {
32  // Fill nuclei with particles.
33  std::map<PdgCode, int> part = config.take({"Particles"});
34  fill_from_list(part, nTest);
35  // Look for user-defined values or take the default parameters.
36  if (config.has_value({"Diffusiveness"}) && config.has_value({"Radius"}) &&
37  config.has_value({"Saturation_Density"})) {
39  } else if (!config.has_value({"Diffusiveness"}) &&
40  !config.has_value({"Radius"}) &&
41  !config.has_value({"Saturation_Density"})) {
44  } else {
45  throw std::invalid_argument(
46  "Diffusiveness, 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  int Z = Nucleus::number_of_protons();
285  if (A == 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  testparticles_ == 1 ? 0. : 1. - std::exp(-(testparticles_ - 1.) * 0.1));
292  set_diffusiveness(testparticles_ == 1 ? -1. : 0.02);
293  } else if ((A == 238) && (Z == 92)) { // Uranium
294  // Default values.
295  set_diffusiveness(0.556);
296  set_nuclear_radius(6.86);
297  } else if ((A == 208) && (Z == 82)) { // Lead
298  // Default values.
299  set_diffusiveness(0.54);
300  set_nuclear_radius(6.67);
301  } else if ((A == 197) && (Z == 79)) { // Gold
302  // Default values from \iref{Schopper:2004qco}
303  set_diffusiveness(0.523);
304  set_nuclear_radius(6.55);
305  } else if ((A == 129) && (Z == 54)) { // Xenon
306  // Default values.
307  set_diffusiveness(0.59);
308  set_nuclear_radius(5.36);
309  } else if ((A == 63) && (Z == 29)) { // Copper
310  // Default values.
311  set_diffusiveness(0.5977);
312  set_nuclear_radius(4.20641);
313  } else if (A == 96) {
314  if (Z == 40) { // Zirconium
315  // Default values.
316  set_diffusiveness(0.46);
317  set_nuclear_radius(5.02);
318  } else if (Z == 44) { // Ruthenium
319  // Default values.
320  set_diffusiveness(0.46);
321  set_nuclear_radius(5.085);
322  } else {
323  // radius and diffusiveness taken from \iref{Rybczynski:2013yba}
324  set_diffusiveness(0.54);
325  set_nuclear_radius(1.12 * std::pow(A, 1.0 / 3.0) -
326  0.86 * std::pow(A, -1.0 / 3.0));
327  }
328  } else {
329  // saturation density already has reasonable default
331  if (A <= 16) {
332  set_diffusiveness(0.545);
333  } else {
334  // diffusiveness taken from \iref{Rybczynski:2013yba}
335  set_diffusiveness(0.54);
336  }
337  }
338 }
339 
341  set_diffusiveness(static_cast<double>(config.take({"Diffusiveness"})));
342  set_nuclear_radius(static_cast<double>(config.take({"Radius"})));
343  // Saturation density (normalization for accept/reject sampling)
345  static_cast<double>(config.take({"Saturation_Density"})));
346 }
347 
349  const int N_n = std::count_if(begin(), end(), [](const ParticleData i) {
350  return i.pdgcode() == pdg::n;
351  });
352  const int N_p = std::count_if(begin(), end(), [](const ParticleData i) {
353  return i.pdgcode() == pdg::p;
354  });
355  const FourVector nucleus_center = center();
356  const int A = N_n + N_p;
357  constexpr double pi2_3 = 3.0 * M_PI * M_PI;
358  logg[LNucleus].debug() << N_n << " neutrons, " << N_p << " protons.";
359 
360  ThreeVector ptot = ThreeVector(0.0, 0.0, 0.0);
361  for (auto i = begin(); i != end(); i++) {
362  // Only protons and neutrons get Fermi momenta
363  if (i->pdgcode() != pdg::p && i->pdgcode() != pdg::n) {
364  if (i->is_baryon()) {
365  logg[LNucleus].warn() << "No rule to calculate Fermi momentum "
366  << "for particle " << i->pdgcode();
367  }
368  continue;
369  }
370  const double r = (i->position() - nucleus_center).abs3();
371  const double theta = (i->position().threevec().get_theta());
372  const double phi = (i->position().threevec().get_phi());
373  double rho = nucleon_density(r, std::cos(theta), phi);
374 
375  if (i->pdgcode() == pdg::p) {
376  rho = rho * N_p / A;
377  }
378  if (i->pdgcode() == pdg::n) {
379  rho = rho * N_n / A;
380  }
381  const double p =
382  hbarc * std::pow(pi2_3 * rho * random::uniform(0.0, 1.0), 1.0 / 3.0);
383  Angles phitheta;
384  phitheta.distribute_isotropically();
385  const ThreeVector ith_3momentum = phitheta.threevec() * p;
386  ptot += ith_3momentum;
387  i->set_3momentum(ith_3momentum);
388  logg[LNucleus].debug() << "Particle: " << *i << ", pF[GeV]: "
389  << hbarc * std::pow(pi2_3 * rho, 1.0 / 3.0)
390  << " r[fm]: " << r
391  << " Nuclear radius[fm]: " << nuclear_radius_;
392  }
393  if (A == 0) {
394  // No Fermi momenta should be assigned
395  assert(ptot.x1() == 0.0 && ptot.x2() == 0.0 && ptot.x3() == 0.0);
396  } else {
397  /* Ensure zero total momentum of nucleus - redistribute ptot equally
398  * among protons and neutrons */
399  const ThreeVector centralizer = ptot / A;
400  for (auto i = begin(); i != end(); i++) {
401  if (i->pdgcode() == pdg::p || i->pdgcode() == pdg::n) {
402  i->set_4momentum(i->pole_mass(),
403  i->momentum().threevec() - centralizer);
404  }
405  }
406  }
407 }
408 
409 void Nucleus::boost(double beta_scalar) {
410  double beta_squared = beta_scalar * beta_scalar;
411  double one_over_gamma = std::sqrt(1.0 - beta_squared);
412  double gamma = 1.0 / one_over_gamma;
413  /* We are talking about a /passive/ lorentz transformation here, as
414  * far as I can see, so we need to boost in the direction opposite to
415  * where we want to go
416  * ( The vector we transform - p - stays unchanged, but we go into
417  * a system that moves with -beta. Now in this frame, it seems
418  * like p has been accelerated with +beta.
419  * ) */
420  for (auto i = begin(); i != end(); i++) {
421  /* a real Lorentz Transformation would leave the particles at
422  * different times here, which we would then have to propagate back
423  * to equal times. Since we know the result, we can simply multiply
424  * the z-value with 1/gamma. */
425  FourVector this_position = i->position();
426  this_position.set_x3(this_position.x3() * one_over_gamma);
427  i->set_4position(this_position);
428  /* The simple Lorentz transformation of momenta does not take into account
429  * that nucleus has binding energy. Here we apply the method used
430  * in the JAM code \iref{Nara:1999dz}: p' = p_beam + gamma*p_F.
431  * This formula is derived under assumption that all nucleons have
432  * the same binding energy. */
433  FourVector mom_i = i->momentum();
434  i->set_4momentum(i->pole_mass(), mom_i.x1(), mom_i.x2(),
435  gamma * (beta_scalar * mom_i.x0() + mom_i.x3()));
436  }
437 }
438 
439 void Nucleus::fill_from_list(const std::map<PdgCode, int> &particle_list,
440  int testparticles) {
441  testparticles_ = testparticles;
442  for (auto n = particle_list.cbegin(); n != particle_list.cend(); ++n) {
443  const ParticleType &current_type = ParticleType::find(n->first);
444  double current_mass = current_type.mass();
445  for (unsigned int i = 0; i < n->second * testparticles_; i++) {
446  // append particle to list and set its PDG code.
447  particles_.emplace_back(current_type);
448  particles_.back().set_4momentum(current_mass, 0.0, 0.0, 0.0);
449  }
450  }
451 }
452 
453 void Nucleus::shift(double z_offset, double x_offset, double simulation_time) {
454  // Move the nucleus in z and x directions, and set the time.
455  for (auto i = begin(); i != end(); i++) {
456  FourVector this_position = i->position();
457  this_position.set_x3(this_position.x3() + z_offset);
458  this_position.set_x1(this_position.x1() + x_offset);
459  this_position.set_x0(simulation_time);
460  i->set_4position(this_position);
461  i->set_formation_time(simulation_time);
462  }
463 }
464 
465 void Nucleus::copy_particles(Particles *external_particles) {
466  for (auto p = begin(); p != end(); p++) {
467  external_particles->insert(*p);
468  }
469 }
470 
472  FourVector centerpoint(0.0, 0.0, 0.0, 0.0);
473  for (auto p = cbegin(); p != cend(); p++) {
474  centerpoint += p->position();
475  }
476  centerpoint /= size();
477  return centerpoint;
478 }
479 
481  // Sample euler_theta_ such that cos(theta) is uniform
482  euler_phi_ = twopi * random::uniform(0., 1.);
483  euler_theta_ = std::acos(2 * random::uniform(0., 1.) - 1);
484  euler_psi_ = twopi * random::uniform(0., 1.);
485 }
486 
487 double Nucleus::nucleon_density(double r, double, double) const {
488  return get_saturation_density() /
489  (std::exp((r - nuclear_radius_) / diffusiveness_) + 1.);
490 }
491 
492 double Nucleus::nucleon_density_unnormalized(double r, double, double) const {
493  return 1.0 / (std::exp((r - nuclear_radius_) / diffusiveness_) + 1.);
494 }
495 
498  // Transform integral from (0, oo) to (0, 1) via r = (1 - t) / t.
499  // To prevent overflow, the integration is only performed to t = 0.01 which
500  // corresponds to r = 99fm. Additionally the precision settings in the
501  // Integrator2d scheme are equally important. However both these point affect
502  // the result only after the seventh digit which should not be relevant here.
503  const auto result = integrate(0.01, 1, -1, 1, [&](double t, double cosx) {
504  const double r = (1 - t) / t;
505  return twopi * std::pow(r, 2.0) *
506  nucleon_density_unnormalized(r, cosx, 0.0) / std::pow(t, 2.0);
507  });
508  const auto rho0 = number_of_particles() / result.value();
509  return rho0;
510 }
511 
512 std::ostream &operator<<(std::ostream &out, const Nucleus &n) {
513  return out << " #particles #testparticles mass [GeV] "
514  "radius [fm] diffusiveness [fm]\n"
515  << format(n.number_of_particles(), nullptr, 12)
516  << format(n.size(), nullptr, 17) << format(n.mass(), nullptr, 13)
517  << format(n.get_nuclear_radius(), nullptr, 14)
518  << format(n.get_diffusiveness(), nullptr, 20);
519 }
520 
521 } // 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.
bool has_value(std::initializer_list< const char * > keys) const
Return whether there is a non-empty value behind the requested keys.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
double x3() const
Definition: fourvector.h:325
double x2() const
Definition: fourvector.h:321
ThreeVector threevec() const
Definition: fourvector.h:329
double x0() const
Definition: fourvector.h:313
void set_x3(double z)
Definition: fourvector.h:327
void set_x1(double x)
Definition: fourvector.h:319
double x1() const
Definition: fourvector.h:317
void set_x0(double t)
Definition: fourvector.h:315
A C++ interface for numerical integration in two dimensions with the Cuba Cuhre integration function.
Definition: integrate.h:219
A nucleus is a collection of particles that are initialized, before the beginning of the simulation a...
Definition: nucleus.h:27
Nucleus()=default
default constructor
double euler_theta_
Euler angel theta.
Definition: nucleus.h:303
std::vector< ParticleData >::const_iterator cbegin() const
For const iterators over the particle list:
Definition: nucleus.h:315
virtual double nucleon_density_unnormalized(double r, double, double) const
Return the unnormalized Woods-Saxon distribution for the given position without deformation.
Definition: nucleus.cc:492
void shift(double z_offset, double x_offset, double simulation_time)
Shifts the nucleus to correct impact parameter and z displacement.
Definition: nucleus.cc:453
double get_saturation_density() const
Definition: nucleus.h:336
double woods_saxon(double x)
Woods-Saxon distribution.
Definition: nucleus.cc:261
void random_euler_angles()
Randomly generate Euler angles.
Definition: nucleus.cc:480
virtual void arrange_nucleons()
Sets the positions of the nucleons inside a nucleus.
Definition: nucleus.cc:265
virtual double calculate_saturation_density() const
Definition: nucleus.cc:496
virtual void rotate()
Rotates the nucleus.
Definition: nucleus.h:147
double default_nuclear_radius()
Default nuclear radius calculated as:
Definition: nucleus.h:344
double diffusiveness_
Diffusiveness of Woods-Saxon distribution of this nucleus in fm (for diffusiveness_ == 0,...
Definition: nucleus.h:275
FourVector center() const
Calculate geometrical center of the nucleus.
Definition: nucleus.cc:471
virtual void generate_fermi_momenta()
Generates momenta according to Fermi motion for the nucleons.
Definition: nucleus.cc:348
virtual void set_parameters_automatic()
Sets the deformation parameters of the Woods-Saxon distribution according to the current mass number.
Definition: nucleus.cc:282
std::vector< ParticleData >::const_iterator cend() const
For const iterators over the particle list:
Definition: nucleus.h:319
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:340
size_t size() const
Number of numerical (=test-)particles in the nucleus:
Definition: nucleus.h:157
size_t testparticles_
Number of testparticles per physical particle.
Definition: nucleus.h:284
virtual double nucleon_density(double r, double, double) const
Return the Woods-Saxon probability density for the given position.
Definition: nucleus.cc:487
double euler_phi_
Euler angel phi.
Definition: nucleus.h:301
double nuclear_radius_
Nuclear radius of this nucleus.
Definition: nucleus.h:277
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:439
std::vector< ParticleData > particles_
Particles associated with this nucleus.
Definition: nucleus.h:288
double euler_psi_
Euler angel psi.
Definition: nucleus.h:305
double mass() const
Definition: nucleus.cc:55
void align_center()
Shifts the nucleus so that its center is at (0,0,0)
Definition: nucleus.h:223
void copy_particles(Particles *particles)
Copies the particles from this nucleus into the particle list.
Definition: nucleus.cc:465
virtual void set_saturation_density(double density)
Sets the saturation density of the nucleus.
Definition: nucleus.h:261
void set_nuclear_radius(double rad)
Sets the nuclear radius.
Definition: nucleus.h:359
void set_diffusiveness(double diffuse)
Sets the diffusiveness of the nucleus.
Definition: nucleus.h:326
std::vector< ParticleData >::iterator begin()
For iterators over the particle list:
Definition: nucleus.h:309
size_t number_of_protons() const
Number of physical protons in the nucleus:
Definition: nucleus.h:184
void boost(double beta_scalar)
Boosts the nuclei into the computational frame, such that the nucleons have the appropriate momentum ...
Definition: nucleus.cc:409
virtual ThreeVector distribute_nucleon()
The distribution of return values from this function is according to a spherically symmetric Woods-Sa...
Definition: nucleus.cc:215
size_t number_of_particles() const
Number of physical particles in the nucleus:
Definition: nucleus.h:165
std::vector< ParticleData >::iterator end()
For iterators over the particle list:
Definition: nucleus.h:313
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
PdgCode pdgcode() const
Get the pdgcode of the particle.
Definition: particledata.h:87
void set_4momentum(const FourVector &momentum_vector)
Set the particle's 4-momentum directly.
Definition: particledata.h:164
const FourVector & momentum() const
Get the particle's 4-momentum.
Definition: particledata.h:158
bool is_baryon() const
Definition: particledata.h:94
double pole_mass() const
Get the particle's pole mass ("on-shell").
Definition: particledata.h:115
void set_3momentum(const ThreeVector &mom)
Set the momentum of the particle without modifying the energy.
Definition: particledata.h:196
const FourVector & position() const
Get the particle's position in Minkowski space.
Definition: particledata.h:204
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
double mass() const
Definition: particletype.h:145
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
const ParticleData & insert(const ParticleData &p)
Inserts the particle into the list of particles.
Definition: particles.cc:50
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
double get_phi() const
Definition: threevector.h:270
double x3() const
Definition: threevector.h:185
double x2() const
Definition: threevector.h:181
double get_theta() const
Definition: threevector.h:278
double x1() const
Definition: threevector.h:177
Collection of useful constants that are known at compile time.
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
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:217
constexpr int p
Proton.
constexpr int n
Neutron.
T uniform(T min, T max)
Definition: random.h:88
T canonical()
Definition: random.h:113
Definition: action.h:24
static Integrator integrate
Definition: decaytype.cc:143
constexpr double twopi
.
Definition: constants.h:45
constexpr double hbarc
GeV <-> fm conversion factor.
Definition: constants.h:25
static constexpr int LNucleus
Definition: nucleus.cc:23
bool almost_equal(const N x, const N y)
Checks two numbers for relative approximate equality.
Definition: numerics.h:44