Version: SMASH-1.8
density.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2013-2019
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 #ifndef SRC_INCLUDE_DENSITY_H_
10 #define SRC_INCLUDE_DENSITY_H_
11 
12 #include <iostream>
13 #include <typeinfo>
14 #include <utility>
15 #include <vector>
16 
17 #include "energymomentumtensor.h"
18 #include "experimentparameters.h"
19 #include "forwarddeclarations.h"
20 #include "fourvector.h"
21 #include "lattice.h"
22 #include "particledata.h"
23 #include "particles.h"
24 #include "pdgcode.h"
25 #include "threevector.h"
26 
27 namespace smash {
28 static constexpr int LDensity = LogArea::Density::id;
29 
35 enum class DensityType {
36  None = 0,
37  Hadron = 1,
38  Baryon = 2,
39  BaryonicIsospin = 3,
40  Pion = 4,
41  Isospin3_tot = 5,
42  Charge = 6,
43  Strangeness = 7,
44 };
45 
53 std::ostream &operator<<(std::ostream &os, DensityType dt);
54 
67 double density_factor(const ParticleType &type, DensityType dens_type);
68 
76 inline double smearing_factor_norm(const double two_sigma_sqr) {
77  const double tmp = two_sigma_sqr * M_PI;
78  return tmp * std::sqrt(tmp);
79 }
80 
98 inline double smearing_factor_rcut_correction(const double rcut_in_sigma) {
99  const double x = rcut_in_sigma / std::sqrt(2.0);
100  return -2.0 / std::sqrt(M_PI) * x * std::exp(-x * x) + std::erf(x);
101 }
102 
108  public:
118  : sig_(par.gaussian_sigma),
119  r_cut_(par.gauss_cutoff_in_sigma * par.gaussian_sigma),
120  ntest_(par.testparticles) {
122  const double two_sig_sqr = 2 * sig_ * sig_;
123  two_sig_sqr_inv_ = 1. / two_sig_sqr;
124  const double norm = smearing_factor_norm(two_sig_sqr);
125  const double corr_factor =
127  norm_factor_sf_ = 1. / (norm * ntest_ * corr_factor);
128  }
130  int ntest() const { return ntest_; }
132  double r_cut() const { return r_cut_; }
134  double r_cut_sqr() const { return r_cut_sqr_; }
136  double two_sig_sqr_inv() const { return two_sig_sqr_inv_; }
142  double norm_factor_sf() const { return norm_factor_sf_; }
143 
144  private:
146  const double sig_;
148  const double r_cut_;
150  double r_cut_sqr_;
156  const int ntest_;
157 };
158 
176 std::pair<double, ThreeVector> unnormalized_smearing_factor(
177  const ThreeVector &r, const FourVector &p, const double m_inv,
178  const DensityParameters &dens_par, const bool compute_gradient = false);
179 
226 std::tuple<double, FourVector, ThreeVector, ThreeVector, ThreeVector>
227 current_eckart(const ThreeVector &r, const ParticleList &plist,
228  const DensityParameters &par, DensityType dens_type,
229  bool compute_gradient, bool smearing);
231 std::tuple<double, FourVector, ThreeVector, ThreeVector, ThreeVector>
232 current_eckart(const ThreeVector &r, const Particles &plist,
233  const DensityParameters &par, DensityType dens_type,
234  bool compute_gradient, bool smearing);
235 
258  public:
261  : jmu_pos_(FourVector()),
262  jmu_neg_(FourVector()),
264 
277  void add_particle(const ParticleData &part, double FactorTimesSf) {
278  const FourVector PartFourVelocity = FourVector(1.0, part.velocity());
279  if (FactorTimesSf > 0.0) {
280  jmu_pos_ += PartFourVelocity * FactorTimesSf;
281  } else {
282  jmu_neg_ += PartFourVelocity * FactorTimesSf;
283  }
284  }
285 
298  void add_particle_for_derivatives(const ParticleData &part, double factor,
299  ThreeVector sf_grad) {
300  const FourVector PartFourVelocity = FourVector(1.0, part.velocity());
301  for (int k = 1; k <= 3; k++) {
302  djmu_dx_[k] += factor * PartFourVelocity * sf_grad[k - 1];
303  djmu_dx_[0] -=
304  factor * PartFourVelocity * sf_grad[k - 1] * part.velocity()[k - 1];
305  }
306  }
307 
325  double density(const double norm_factor = 1.0) {
326  return (jmu_pos_.abs() - jmu_neg_.abs()) * norm_factor;
327  }
328 
335  ThreeVector rot_j(const double norm_factor = 1.0) {
336  ThreeVector j_rot = ThreeVector();
337  j_rot.set_x1(djmu_dx_[2].x3() - djmu_dx_[3].x2());
338  j_rot.set_x2(djmu_dx_[3].x1() - djmu_dx_[1].x3());
339  j_rot.set_x3(djmu_dx_[1].x2() - djmu_dx_[2].x1());
340  j_rot *= norm_factor;
341  return j_rot;
342  }
343 
350  ThreeVector grad_rho(const double norm_factor = 1.0) {
351  ThreeVector rho_grad = ThreeVector();
352  for (int i = 1; i < 4; i++) {
353  rho_grad[i - 1] = djmu_dx_[i].x0() * norm_factor;
354  }
355  return rho_grad;
356  }
357 
364  ThreeVector dj_dt(const double norm_factor = 1.0) {
365  return djmu_dx_[0].threevec() * norm_factor;
366  }
367 
374  FourVector jmu_net() const { return jmu_pos_ + jmu_neg_; }
375 
376  private:
382  std::array<FourVector, 4> djmu_dx_;
383 };
384 
387 
400 template <typename T>
402  const DensityType dens_type, const DensityParameters &par,
403  const Particles &particles,
404  const bool compute_gradient = false) {
405  // Do not proceed if lattice does not exists/update not required
406  if (lat == nullptr || lat->when_update() != update) {
407  return;
408  }
409  lat->reset();
410  const double norm_factor = par.norm_factor_sf();
411  for (const auto &part : particles) {
412  const double dens_factor = density_factor(part.type(), dens_type);
413  if (std::abs(dens_factor) < really_small) {
414  continue;
415  }
416  const FourVector p = part.momentum();
417  const double m = p.abs();
418  if (unlikely(m < really_small)) {
419  logg[LDensity].warn("Gaussian smearing is undefined for momentum ", p);
420  continue;
421  }
422  const double m_inv = 1.0 / m;
423 
424  const ThreeVector pos = part.position().threevec();
425  lat->iterate_in_radius(
426  pos, par.r_cut(), [&](T &node, int ix, int iy, int iz) {
427  const ThreeVector r = lat->cell_center(ix, iy, iz);
428  const auto sf = unnormalized_smearing_factor(pos - r, p, m_inv, par,
429  compute_gradient);
430  if (sf.first * norm_factor > really_small / par.ntest()) {
431  node.add_particle(part, sf.first * norm_factor * dens_factor);
432  }
433  if (compute_gradient) {
434  node.add_particle_for_derivatives(part, dens_factor,
435  sf.second * norm_factor);
436  }
437  });
438  }
439 }
440 
441 } // namespace smash
442 
443 #endif // SRC_INCLUDE_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:152
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:136
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:107
smash::DensityOnLattice::djmu_dx_
std::array< FourVector, 4 > djmu_dx_
Definition: density.h:382
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:98
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:380
smash::DensityOnLattice::add_particle
void add_particle(const ParticleData &part, double FactorTimesSf)
Adds particle to 4-current: .
Definition: density.h:277
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:278
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:463
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:335
experimentparameters.h
smash::DensityParameters::norm_factor_sf_
double norm_factor_sf_
Normalization for smearing factor.
Definition: density.h:154
smash::DensityParameters::r_cut_sqr_
double r_cut_sqr_
Squared cut-off radius [fm ].
Definition: density.h:150
smash::DensityOnLattice::jmu_net
FourVector jmu_net() const
Definition: density.h:374
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:38
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:257
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:156
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:17
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:119
lattice.h
smash::smearing_factor_norm
double smearing_factor_norm(const double two_sigma_sqr)
Norm of the Gaussian smearing function.
Definition: density.h:76
smash::LDensity
static constexpr int LDensity
Definition: density.h:28
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:298
smash::DensityParameters::r_cut
double r_cut() const
Definition: density.h:132
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:401
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:148
smash::DensityParameters::r_cut_sqr
double r_cut_sqr() const
Definition: density.h:134
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:149
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:378
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:37
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:260
smash::DensityOnLattice::density
double density(const double norm_factor=1.0)
Compute the net Eckart density on the local lattice.
Definition: density.h:325
smash::Particles
Definition: particles.h:33
smash::DensityType
DensityType
Allows to choose which kind of density to calculate.
Definition: density.h:35
smash::DensityParameters::DensityParameters
DensityParameters(const ExperimentParameters &par)
Constructor of DensityParameters.
Definition: density.h:117
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:364
pdgcode.h
smash::DensityParameters::norm_factor_sf
double norm_factor_sf() const
Definition: density.h:142
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:350
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:23
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:157
smash::DensityType::Hadron
smash::DensityParameters::ntest
int ntest() const
Definition: density.h:130
smash::DensityType::Baryon
smash::ParticleData::velocity
ThreeVector velocity() const
Get the velocity 3-vector.
Definition: particledata.h:285
smash::RectangularLattice::reset
void reset()
Sets all values on lattice to zeros.
Definition: lattice.h:92
smash::DensityLattice
RectangularLattice< DensityOnLattice > DensityLattice
Conveniency typedef for lattice of density.
Definition: density.h:386
smash::DensityParameters::sig_
const double sig_
Gaussian smearing width [fm].
Definition: density.h:146