Version: SMASH-2.0
density.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2013-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 #ifndef SRC_INCLUDE_SMASH_DENSITY_H_
10 #define SRC_INCLUDE_SMASH_DENSITY_H_
11 
12 #include <iostream>
13 #include <tuple>
14 #include <typeinfo>
15 #include <utility>
16 #include <vector>
17 
18 #include "energymomentumtensor.h"
19 #include "experimentparameters.h"
20 #include "forwarddeclarations.h"
21 #include "fourvector.h"
22 #include "lattice.h"
23 #include "particledata.h"
24 #include "particles.h"
25 #include "pdgcode.h"
26 #include "threevector.h"
27 
28 namespace smash {
29 static constexpr int LDensity = LogArea::Density::id;
30 
36 enum class DensityType {
37  None = 0,
38  Hadron = 1,
39  Baryon = 2,
40  BaryonicIsospin = 3,
41  Pion = 4,
42  Isospin3_tot = 5,
43  Charge = 6,
44  Strangeness = 7,
45 };
46 
54 std::ostream &operator<<(std::ostream &os, DensityType dt);
55 
68 double density_factor(const ParticleType &type, DensityType dens_type);
69 
77 inline double smearing_factor_norm(const double two_sigma_sqr) {
78  const double tmp = two_sigma_sqr * M_PI;
79  return tmp * std::sqrt(tmp);
80 }
81 
99 inline double smearing_factor_rcut_correction(const double rcut_in_sigma) {
100  const double x = rcut_in_sigma / std::sqrt(2.0);
101  return -2.0 / std::sqrt(M_PI) * x * std::exp(-x * x) + std::erf(x);
102 }
103 
109  public:
119  : sig_(par.gaussian_sigma),
120  r_cut_(par.gauss_cutoff_in_sigma * par.gaussian_sigma),
121  ntest_(par.testparticles) {
123  const double two_sig_sqr = 2 * sig_ * sig_;
124  two_sig_sqr_inv_ = 1. / two_sig_sqr;
125  const double norm = smearing_factor_norm(two_sig_sqr);
126  const double corr_factor =
128  norm_factor_sf_ = 1. / (norm * ntest_ * corr_factor);
129  }
131  int ntest() const { return ntest_; }
133  double r_cut() const { return r_cut_; }
135  double r_cut_sqr() const { return r_cut_sqr_; }
137  double two_sig_sqr_inv() const { return two_sig_sqr_inv_; }
143  double norm_factor_sf() const { return norm_factor_sf_; }
144 
145  private:
147  const double sig_;
149  const double r_cut_;
151  double r_cut_sqr_;
157  const int ntest_;
158 };
159 
177 std::pair<double, ThreeVector> unnormalized_smearing_factor(
178  const ThreeVector &r, const FourVector &p, const double m_inv,
179  const DensityParameters &dens_par, const bool compute_gradient = false);
180 
227 std::tuple<double, FourVector, ThreeVector, ThreeVector, ThreeVector>
228 current_eckart(const ThreeVector &r, const ParticleList &plist,
229  const DensityParameters &par, DensityType dens_type,
230  bool compute_gradient, bool smearing);
232 std::tuple<double, FourVector, ThreeVector, ThreeVector, ThreeVector>
233 current_eckart(const ThreeVector &r, const Particles &plist,
234  const DensityParameters &par, DensityType dens_type,
235  bool compute_gradient, bool smearing);
236 
259  public:
262  : jmu_pos_(FourVector()),
263  jmu_neg_(FourVector()),
265 
278  void add_particle(const ParticleData &part, double FactorTimesSf) {
279  const FourVector PartFourVelocity = FourVector(1.0, part.velocity());
280  if (FactorTimesSf > 0.0) {
281  jmu_pos_ += PartFourVelocity * FactorTimesSf;
282  } else {
283  jmu_neg_ += PartFourVelocity * FactorTimesSf;
284  }
285  }
286 
299  void add_particle_for_derivatives(const ParticleData &part, double factor,
300  ThreeVector sf_grad) {
301  const FourVector PartFourVelocity = FourVector(1.0, part.velocity());
302  for (int k = 1; k <= 3; k++) {
303  djmu_dx_[k] += factor * PartFourVelocity * sf_grad[k - 1];
304  djmu_dx_[0] -=
305  factor * PartFourVelocity * sf_grad[k - 1] * part.velocity()[k - 1];
306  }
307  }
308 
326  double density(const double norm_factor = 1.0) {
327  return (jmu_pos_.abs() - jmu_neg_.abs()) * norm_factor;
328  }
329 
336  ThreeVector rot_j(const double norm_factor = 1.0) {
337  ThreeVector j_rot = ThreeVector();
338  j_rot.set_x1(djmu_dx_[2].x3() - djmu_dx_[3].x2());
339  j_rot.set_x2(djmu_dx_[3].x1() - djmu_dx_[1].x3());
340  j_rot.set_x3(djmu_dx_[1].x2() - djmu_dx_[2].x1());
341  j_rot *= norm_factor;
342  return j_rot;
343  }
344 
351  ThreeVector grad_rho(const double norm_factor = 1.0) {
352  ThreeVector rho_grad = ThreeVector();
353  for (int i = 1; i < 4; i++) {
354  rho_grad[i - 1] = djmu_dx_[i].x0() * norm_factor;
355  }
356  return rho_grad;
357  }
358 
365  ThreeVector dj_dt(const double norm_factor = 1.0) {
366  return djmu_dx_[0].threevec() * norm_factor;
367  }
368 
375  FourVector jmu_net() const { return jmu_pos_ + jmu_neg_; }
376 
377  private:
383  std::array<FourVector, 4> djmu_dx_;
384 };
385 
388 
401 template <typename T>
403  const DensityType dens_type, const DensityParameters &par,
404  const Particles &particles,
405  const bool compute_gradient = false) {
406  // Do not proceed if lattice does not exists/update not required
407  if (lat == nullptr || lat->when_update() != update) {
408  return;
409  }
410  lat->reset();
411  const double norm_factor = par.norm_factor_sf();
412  for (const auto &part : particles) {
413  const double dens_factor = density_factor(part.type(), dens_type);
414  if (std::abs(dens_factor) < really_small) {
415  continue;
416  }
417  const FourVector p = part.momentum();
418  const double m = p.abs();
419  if (unlikely(m < really_small)) {
420  logg[LDensity].warn("Gaussian smearing is undefined for momentum ", p);
421  continue;
422  }
423  const double m_inv = 1.0 / m;
424 
425  const ThreeVector pos = part.position().threevec();
426  lat->iterate_in_radius(
427  pos, par.r_cut(), [&](T &node, int ix, int iy, int iz) {
428  const ThreeVector r = lat->cell_center(ix, iy, iz);
429  const auto sf = unnormalized_smearing_factor(pos - r, p, m_inv, par,
430  compute_gradient);
431  if (sf.first * norm_factor > really_small / par.ntest()) {
432  node.add_particle(part, sf.first * norm_factor * dens_factor);
433  }
434  if (compute_gradient) {
435  node.add_particle_for_derivatives(part, dens_factor,
436  sf.second * norm_factor);
437  }
438  });
439  }
440 }
441 
442 } // namespace smash
443 
444 #endif // SRC_INCLUDE_SMASH_DENSITY_H_
smash::DensityType::Strangeness
smash::LatticeUpdate
LatticeUpdate
Enumerator option for lattice updates.
Definition: lattice.h:36
smash
Definition: action.h:24
smash::DensityParameters::two_sig_sqr_inv_
double two_sig_sqr_inv_
[fm ]
Definition: density.h:153
smash::ThreeVector::set_x2
void set_x2(double y)
set second component
Definition: threevector.h:171
particledata.h
smash::DensityParameters::two_sig_sqr_inv
double two_sig_sqr_inv() const
Definition: density.h:137
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:108
smash::DensityOnLattice::djmu_dx_
std::array< FourVector, 4 > djmu_dx_
Definition: density.h:383
smash::ParticleData
Definition: particledata.h:52
smash::DensityType::BaryonicIsospin
smash::ThreeVector::set_x3
void set_x3(double z)
set third component
Definition: threevector.h:175
smash::smearing_factor_rcut_correction
double smearing_factor_rcut_correction(const double rcut_in_sigma)
Gaussians used for smearing are cut at radius for calculation speed-up.
Definition: density.h:99
unlikely
#define unlikely(x)
Tell the branch predictor that this expression is likely false.
Definition: macros.h:16
smash::DensityOnLattice::jmu_neg_
FourVector jmu_neg_
Four-current density of the negatively charged particle.
Definition: density.h:381
smash::DensityOnLattice::add_particle
void add_particle(const ParticleData &part, double FactorTimesSf)
Adds particle to 4-current: .
Definition: density.h:278
smash::RectangularLattice::iterate_in_radius
void iterate_in_radius(const ThreeVector &point, const double r_cut, F &&func)
Iterates only nodes, whose cell centers lie not further than r_cut in x, y, z directions from the giv...
Definition: lattice.h:288
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:518
energymomentumtensor.h
smash::DensityOnLattice::rot_j
ThreeVector rot_j(const double norm_factor=1.0)
Compute curl of the current on the local lattice.
Definition: density.h:336
experimentparameters.h
smash::DensityParameters::norm_factor_sf_
double norm_factor_sf_
Normalization for smearing factor.
Definition: density.h:155
smash::DensityParameters::r_cut_sqr_
double r_cut_sqr_
Squared cut-off radius [fm ].
Definition: density.h:151
smash::DensityOnLattice::jmu_net
FourVector jmu_net() const
Definition: density.h:375
smash::unnormalized_smearing_factor
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:37
fourvector.h
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::DensityOnLattice
A class for time-efficient (time-memory trade-off) calculation of density on the lattice.
Definition: density.h:258
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
smash::DensityParameters::ntest_
const int ntest_
Testparticle number.
Definition: density.h:157
smash::density_factor
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:16
forwarddeclarations.h
smash::ThreeVector
Definition: threevector.h:31
smash::RectangularLattice::cell_center
ThreeVector cell_center(int ix, int iy, int iz) const
Find the coordinates of a given cell.
Definition: lattice.h:129
lattice.h
smash::smearing_factor_norm
double smearing_factor_norm(const double two_sigma_sqr)
Norm of the Gaussian smearing function.
Definition: density.h:77
smash::LDensity
static constexpr int LDensity
Definition: density.h:29
smash::DensityType::Charge
smash::DensityOnLattice::add_particle_for_derivatives
void add_particle_for_derivatives(const ParticleData &part, double factor, ThreeVector sf_grad)
Adds particle to the time and spatial derivatives of the 4-current.
Definition: density.h:299
smash::DensityParameters::r_cut
double r_cut() const
Definition: density.h:133
smash::update_lattice
void update_lattice(RectangularLattice< T > *lat, const LatticeUpdate update, const DensityType dens_type, const DensityParameters &par, const Particles &particles, const bool compute_gradient=false)
Updates the contents on the lattice.
Definition: density.h:402
smash::RectangularLattice
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:47
threevector.h
smash::DensityParameters::r_cut_
const double r_cut_
Cut-off radius [fm].
Definition: density.h:149
smash::DensityParameters::r_cut_sqr
double r_cut_sqr() const
Definition: density.h:135
smash::DensityType::Pion
smash::current_eckart
std::tuple< double, FourVector, ThreeVector, ThreeVector, ThreeVector > current_eckart(const ThreeVector &r, const ParticleList &plist, const DensityParameters &par, DensityType dens_type, bool compute_gradient, bool smearing)
Calculates Eckart rest frame density and 4-current of a given density type and optionally the gradien...
Definition: density.cc:148
smash::ThreeVector::set_x1
void set_x1(double x)
set first component
Definition: threevector.h:167
smash::DensityOnLattice::jmu_pos_
FourVector jmu_pos_
Four-current density of the positively charged particle.
Definition: density.h:379
smash::ExperimentParameters::gauss_cutoff_in_sigma
double gauss_cutoff_in_sigma
Distance at which gaussian is cut, i.e. set to zero, IN SIGMA (not fm)
Definition: experimentparameters.h:38
smash::FourVector::abs
double abs() const
calculate the lorentz invariant absolute value
Definition: fourvector.h:454
particles.h
smash::DensityOnLattice::DensityOnLattice
DensityOnLattice()
Default constructor.
Definition: density.h:261
smash::DensityOnLattice::density
double density(const double norm_factor=1.0)
Compute the net Eckart density on the local lattice.
Definition: density.h:326
smash::Particles
Definition: particles.h:33
smash::DensityType
DensityType
Allows to choose which kind of density to calculate.
Definition: density.h:36
smash::DensityParameters::DensityParameters
DensityParameters(const ExperimentParameters &par)
Constructor of DensityParameters.
Definition: density.h:118
smash::DensityOnLattice::dj_dt
ThreeVector dj_dt(const double norm_factor=1.0)
Compute time derivative of the current density on the local lattice.
Definition: density.h:365
pdgcode.h
smash::DensityParameters::norm_factor_sf
double norm_factor_sf() const
Definition: density.h:143
smash::DensityOnLattice::grad_rho
ThreeVector grad_rho(const double norm_factor=1.0)
Compute gradient of the density on the local lattice.
Definition: density.h:351
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:24
smash::DensityType::None
smash::FourVector
Definition: fourvector.h:33
smash::DensityType::Isospin3_tot
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::RectangularLattice::when_update
LatticeUpdate when_update() const
Definition: lattice.h:167
smash::DensityType::Hadron
smash::DensityParameters::ntest
int ntest() const
Definition: density.h:131
smash::DensityType::Baryon
smash::ParticleData::velocity
ThreeVector velocity() const
Get the velocity 3-vector.
Definition: particledata.h:295
smash::RectangularLattice::reset
void reset()
Sets all values on lattice to zeros.
Definition: lattice.h:102
smash::DensityLattice
RectangularLattice< DensityOnLattice > DensityLattice
Conveniency typedef for lattice of density.
Definition: density.h:387
smash::DensityParameters::sig_
const double sig_
Gaussian smearing width [fm].
Definition: density.h:147