30 return static_cast<double>(type.
charge());
41 const double r_sqr = r.
sqr();
44 return std::make_pair(0.0,
ThreeVector(0.0, 0.0, 0.0));
48 const double u_r_scalar = r * u.
threevec();
49 const double r_rest_sqr = r_sqr + u_r_scalar * u_r_scalar;
53 return std::make_pair(0.0,
ThreeVector(0.0, 0.0, 0.0));
57 ? sf * (r + u.
threevec() * u_r_scalar) *
61 return std::make_pair(sf, sf_grad);
66 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
67 FourVector, FourVector>
70 bool compute_gradient,
bool smearing) {
84 std::array<FourVector, 4> djmu_dxnu;
86 for (
const auto &
p : plist) {
89 if (
p.get_history().collisions_per_particle == 0) {
98 const double m = mom.
abs();
102 const double m_inv = 1.0 / m;
104 p.position().threevec() - r, mom, m_inv, par, compute_gradient);
107 if (dens_factor > 0.) {
108 jmu_pos += tmp * sf_and_grad.first;
110 jmu_neg += tmp * sf_and_grad.first;
113 if (dens_factor > 0.) {
119 if (compute_gradient) {
120 for (
int k = 1; k <= 3; k++) {
121 djmu_dxnu[k] += tmp * sf_and_grad.second[k - 1];
122 djmu_dxnu[0] -= tmp * sf_and_grad.second[k - 1] *
123 tmp.
threevec()[k - 1] / dens_factor;
152 if (compute_gradient) {
153 curl_vecj.
set_x1(djmu_dxnu[2].x3() - djmu_dxnu[3].x2());
154 curl_vecj.
set_x2(djmu_dxnu[3].x1() - djmu_dxnu[1].x3());
155 curl_vecj.
set_x3(djmu_dxnu[1].x2() - djmu_dxnu[2].x1());
157 for (
int i = 1; i < 4; i++) {
165 return std::make_tuple(rho_eck, jmu_pos + jmu_neg, grad_j0, curl_vecj,
166 djmu_dt, djmu_dx, djmu_dy, djmu_dz);
169 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
170 FourVector, FourVector>
173 bool compute_gradient,
bool smearing) {
177 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
178 FourVector, FourVector>
181 bool compute_gradient,
bool smearing) {
193 const double time_step,
const bool compute_gradient) {
195 if (lat ==
nullptr || lat->
when_update() != update) {
198 const std::array<int, 3> lattice_n_cells = lat->
n_cells();
199 const int number_of_nodes =
200 lattice_n_cells[0] * lattice_n_cells[1] * lattice_n_cells[2];
211 for (
int i = 0; i < number_of_nodes; i++) {
216 update_lattice(lat, update, dens_type, par, ensembles, compute_gradient);
221 for (
int i = 0; i < number_of_nodes; i++) {
231 for (
auto &node : *lat) {
232 auto tmp = (*four_grad_lattice)[node_number];
233 node.overwrite_djmu_dxnu(tmp[0], tmp[1], tmp[2], tmp[3]);
240 for (
auto &node : *lat) {
242 double rho = node.rho();
243 const int sgn = rho > 0 ? 1 : -1;
251 const std::array<FourVector, 4> djmu_dxnu = node.djmu_dxnu();
253 const double drho_dt =
255 (jmu.
x0() * djmu_dxnu[0].x0() - jmu.
x1() * djmu_dxnu[0].x1() -
256 jmu.
x2() * djmu_dxnu[0].x2() - jmu.
x3() * djmu_dxnu[0].x3());
258 const double drho_dx =
260 (jmu.
x0() * djmu_dxnu[1].x0() - jmu.
x1() * djmu_dxnu[1].x1() -
261 jmu.
x2() * djmu_dxnu[1].x2() - jmu.
x3() * djmu_dxnu[1].x3());
263 const double drho_dy =
265 (jmu.
x0() * djmu_dxnu[2].x0() - jmu.
x1() * djmu_dxnu[2].x1() -
266 jmu.
x2() * djmu_dxnu[2].x2() - jmu.
x3() * djmu_dxnu[2].x3());
268 const double drho_dz =
270 (jmu.
x0() * djmu_dxnu[3].x0() - jmu.
x1() * djmu_dxnu[3].x1() -
271 jmu.
x2() * djmu_dxnu[3].x2() - jmu.
x3() * djmu_dxnu[3].x3());
273 const FourVector drho_dxnu = {drho_dt, drho_dx, drho_dy, drho_dz};
275 node.overwrite_drho_dxnu(drho_dxnu);
283 os <<
"hadron density";
286 os <<
"baryon density";
289 os <<
"baryonic isospin density";
292 os <<
"pion density";
295 os <<
"total isospin3 density";
301 os.setstate(std::ios_base::failbit);
A class to pre-calculate and store parameters relevant for density calculation.
RestFrameDensityDerivativesMode rho_derivatives() const
bool only_participants() const
DerivativesMode derivatives() const
double two_sig_sqr_inv() const
double norm_factor_sf() const
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
double abs() const
calculate the lorentz invariant absolute value
ThreeVector threevec() const
Particle type contains the static properties of a particle species.
int32_t charge() const
The charge of the particle.
double isospin3_rel() const
int baryon_number() const
The Particles class abstracts the storage and manipulation of particles.
A container class to hold all the arrays on the lattice and access them.
LatticeUpdate when_update() const
void compute_four_gradient_lattice(RectangularLattice< FourVector > &old_lat, double time_step, RectangularLattice< std::array< FourVector, 4 >> &grad_lat) const
Compute a fourgradient on a lattice of FourVectors jmu via the finite difference method.
const std::array< int, 3 > & n_cells() const
void assign_value(int lattice_index, T value)
Overwrite with a template value T at a given node.
The ThreeVector class represents a physical three-vector with the components .
void set_x1(double x)
set first component
void set_x3(double z)
set third component
void set_x2(double y)
set second component
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.
int sgn(T val)
Signum function.
void update_lattice(RectangularLattice< T > *lat, const LatticeUpdate update, const DensityType dens_type, const DensityParameters &par, const std::vector< Particles > &ensembles, const bool compute_gradient)
Updates the contents on the lattice.
std::tuple< double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector, FourVector, FourVector > 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...
constexpr double very_small_double
A very small double, used to avoid division by zero.
std::tuple< double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector, FourVector, FourVector > current_eckart_impl(const ThreeVector &r, const T &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...
LatticeUpdate
Enumerator option for lattice updates.
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.
constexpr double really_small
Numerical error tolerance.
DensityType
Allows to choose which kind of density to calculate.
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.