Version: SMASH-1.5
density.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2013-2018
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/density.h"
11 #include "smash/constants.h"
12 #include "smash/logging.h"
13 #include "smash/particles.h"
14 
15 namespace smash {
16 
17 double density_factor(const ParticleType &type, DensityType dens_type) {
18  switch (dens_type) {
20  return type.is_hadron() ? 1. : 0.;
22  return static_cast<double>(type.baryon_number());
24  return type.is_baryon() ? type.isospin3_rel() : 0.;
25  case DensityType::Pion:
26  return type.pdgcode().is_pion() ? 1. : 0.;
27  default:
28  return 0.;
29  }
30 }
31 
32 std::pair<double, ThreeVector> unnormalized_smearing_factor(
33  const ThreeVector &r, const FourVector &p, const double m_inv,
34  const DensityParameters &dens_par, const bool compute_gradient) {
35  const double r_sqr = r.sqr();
36  // Distance from particle to point of interest > r_cut
37  if (r_sqr > dens_par.r_cut_sqr()) {
38  return std::make_pair(0.0, ThreeVector(0.0, 0.0, 0.0));
39  }
40 
41  const FourVector u = p * m_inv;
42  const double u_r_scalar = r * u.threevec();
43  const double r_rest_sqr = r_sqr + u_r_scalar * u_r_scalar;
44 
45  // Lorentz contracted distance from particle to point of interest > r_cut
46  if (r_rest_sqr > dens_par.r_cut_sqr()) {
47  return std::make_pair(0.0, ThreeVector(0.0, 0.0, 0.0));
48  }
49  const double sf = std::exp(-r_rest_sqr * dens_par.two_sig_sqr_inv()) * u.x0();
50  const ThreeVector sf_grad = compute_gradient
51  ? sf * (r + u.threevec() * u_r_scalar) *
52  dens_par.two_sig_sqr_inv() * 2.0
53  : ThreeVector(0.0, 0.0, 0.0);
54 
55  return std::make_pair(sf, sf_grad);
56 }
57 
59 template <typename /*ParticlesContainer*/ T>
60 std::tuple<double, ThreeVector, ThreeVector, ThreeVector> rho_eckart_impl(
61  const ThreeVector &r, const T &plist, const DensityParameters &par,
62  DensityType dens_type, bool compute_gradient) {
63  /* The current density of the positively and negatively charged particles.
64  * Division into positive and negative charges is necessary to avoid
65  * problems with the Eckart frame definition. Example of problem:
66  * get Eckart frame for two identical oppositely flying bunches of
67  * electrons and positrons. For this case jmu = (0, 0, 0, non-zero),
68  * so jmu.abs does not exist and Eckart frame is not defined.
69  * If one takes rho = jmu_pos.abs - jmu_neg.abs, it is still Lorentz-
70  * invariant and gives the right limit in non-relativistic case, but
71  * it gives no such problem. */
72  FourVector jmu_pos, jmu_neg;
73  /* The array of the derivatives of the current density.
74  * The zeroth component is the time derivative,
75  * while the next 3 ones are spacial derivatives. */
76  std::array<FourVector, 4> djmu_dx;
77 
78  for (const auto &p : plist) {
79  const double dens_factor = density_factor(p.type(), dens_type);
80  if (std::abs(dens_factor) < really_small) {
81  continue;
82  }
83  const FourVector mom = p.momentum();
84  const double m = mom.abs();
85  if (m < really_small) {
86  continue;
87  }
88  const double m_inv = 1.0 / m;
89  const auto sf_and_grad = unnormalized_smearing_factor(
90  p.position().threevec() - r, mom, m_inv, par, compute_gradient);
91  if (sf_and_grad.first < really_small) {
92  continue;
93  }
94  const FourVector tmp = mom * (dens_factor / mom.x0());
95  if (dens_factor > 0.) {
96  jmu_pos += tmp * sf_and_grad.first;
97  } else {
98  jmu_neg += tmp * sf_and_grad.first;
99  }
100  if (compute_gradient) {
101  for (int k = 1; k <= 3; k++) {
102  djmu_dx[k] += tmp * sf_and_grad.second[k - 1];
103  djmu_dx[0] -= tmp * sf_and_grad.second[k - 1] * tmp.threevec()[k - 1] /
104  dens_factor;
105  }
106  }
107  }
108 
109  // Eckart density
110  const double rho_eck = (jmu_pos.abs() - jmu_neg.abs()) * par.norm_factor_sf();
111 
112  // $\partial_t \vec j$
113  const ThreeVector dj_dt = compute_gradient
114  ? djmu_dx[0].threevec() * par.norm_factor_sf()
115  : ThreeVector(0.0, 0.0, 0.0);
116 
117  // Gradient of density
118  ThreeVector rho_grad;
119  // Curl of current density
120  ThreeVector j_rot;
121  if (compute_gradient) {
122  j_rot.set_x1(djmu_dx[2].x3() - djmu_dx[3].x2());
123  j_rot.set_x2(djmu_dx[3].x1() - djmu_dx[1].x3());
124  j_rot.set_x3(djmu_dx[1].x2() - djmu_dx[2].x1());
125  j_rot *= par.norm_factor_sf();
126  for (int i = 1; i < 4; i++) {
127  rho_grad[i - 1] += djmu_dx[i].x0() * par.norm_factor_sf();
128  }
129  }
130  return std::make_tuple(rho_eck, rho_grad, dj_dt, j_rot);
131 }
132 
133 std::tuple<double, ThreeVector, ThreeVector, ThreeVector> rho_eckart(
134  const ThreeVector &r, const ParticleList &plist,
135  const DensityParameters &par, DensityType dens_type,
136  bool compute_gradient) {
137  return rho_eckart_impl(r, plist, par, dens_type, compute_gradient);
138 }
139 std::tuple<double, ThreeVector, ThreeVector, ThreeVector> rho_eckart(
140  const ThreeVector &r, const Particles &plist, const DensityParameters &par,
141  DensityType dens_type, bool compute_gradient) {
142  return rho_eckart_impl(r, plist, par, dens_type, compute_gradient);
143 }
144 
145 std::ostream &operator<<(std::ostream &os, DensityType dens_type) {
146  switch (dens_type) {
147  case DensityType::Hadron:
148  os << "hadron density";
149  break;
150  case DensityType::Baryon:
151  os << "baryon density";
152  break;
154  os << "baryonic isospin density";
155  break;
156  case DensityType::Pion:
157  os << "pion density";
158  break;
159  case DensityType::None:
160  os << "none";
161  break;
162  default:
163  os.setstate(std::ios_base::failbit);
164  }
165  return os;
166 }
167 
168 } // namespace smash
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:103
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
double norm_factor_sf() const
Definition: density.h:138
Collection of useful constants that are known at compile time.
std::tuple< double, ThreeVector, ThreeVector, ThreeVector > rho_eckart(const ThreeVector &r, const ParticleList &plist, const DensityParameters &par, DensityType dens_type, bool compute_gradient)
Calculates Eckart rest frame density and optionally the gradient of the density in an arbitary frame...
Definition: density.cc:133
bool is_baryon() const
Definition: particletype.h:190
double two_sig_sqr_inv() const
Definition: density.h:132
double x0() const
Definition: fourvector.h:290
bool is_pion() const
Definition: pdgcode.h:372
void set_x1(double x)
set first component
Definition: threevector.h:157
double isospin3_rel() const
Definition: particletype.h:169
ThreeVector threevec() const
Definition: fourvector.h:306
int baryon_number() const
Definition: particletype.h:196
Particle type contains the static properties of a particle species.
Definition: particletype.h:87
double sqr() const
Definition: threevector.h:249
std::tuple< double, ThreeVector, ThreeVector, ThreeVector > rho_eckart_impl(const ThreeVector &r, const T &plist, const DensityParameters &par, DensityType dens_type, bool compute_gradient)
Calculates Eckart rest frame density and optionally the gradient of the density in an arbitary frame...
Definition: density.cc:60
double density_factor(const ParticleType &type, DensityType dens_type)
Get the factor that determines how much a particle contributes to the density type that is computed...
Definition: density.cc:17
void set_x3(double z)
set third component
Definition: threevector.h:165
constexpr int p
Proton.
std::pair< double, ThreeVector > unnormalized_smearing_factor(const ThreeVector &r, const FourVector &p, const double m_inv, const DensityParameters &dens_par, const bool compute_gradient=false)
Implements gaussian smearing for any quantity.
Definition: density.cc:32
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
DensityType
Allows to choose which kind of density to calculate.
Definition: density.h:34
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:457
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
double abs() const
calculate the lorentz invariant absolute value
Definition: fourvector.h:441
bool is_hadron() const
Definition: particletype.h:184
PdgCode pdgcode() const
Definition: particletype.h:146
double r_cut_sqr() const
Definition: density.h:130
void set_x2(double y)
set second component
Definition: threevector.h:161
Definition: action.h:24