29 return static_cast<double>(type.
charge());
40 const double r_sqr = r.
sqr();
43 return std::make_pair(0.0,
ThreeVector(0.0, 0.0, 0.0));
47 const double u_r_scalar = r * u.
threevec();
48 const double r_rest_sqr = r_sqr + u_r_scalar * u_r_scalar;
52 return std::make_pair(0.0,
ThreeVector(0.0, 0.0, 0.0));
56 ? sf * (r + u.
threevec() * u_r_scalar) *
60 return std::make_pair(sf, sf_grad);
65 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
66 FourVector, FourVector>
69 bool compute_gradient,
bool smearing) {
83 std::array<FourVector, 4> djmu_dxnu;
85 for (
const auto &
p : plist) {
88 if (
p.get_history().collisions_per_particle == 0) {
97 const double m = mom.
abs();
101 const double m_inv = 1.0 / m;
103 p.position().threevec() - r, mom, m_inv, par, compute_gradient);
106 if (dens_factor > 0.) {
107 jmu_pos += tmp * sf_and_grad.first;
109 jmu_neg += tmp * sf_and_grad.first;
112 if (dens_factor > 0.) {
118 if (compute_gradient) {
119 for (
int k = 1; k <= 3; k++) {
120 djmu_dxnu[k] += tmp * sf_and_grad.second[k - 1];
121 djmu_dxnu[0] -= tmp * sf_and_grad.second[k - 1] *
122 tmp.
threevec()[k - 1] / dens_factor;
151 if (compute_gradient) {
152 curl_vecj.
set_x1(djmu_dxnu[2].x3() - djmu_dxnu[3].x2());
153 curl_vecj.
set_x2(djmu_dxnu[3].x1() - djmu_dxnu[1].x3());
154 curl_vecj.
set_x3(djmu_dxnu[1].x2() - djmu_dxnu[2].x1());
156 for (
int i = 1; i < 4; i++) {
160 return std::make_tuple(rho_eck, (jmu_pos + jmu_neg) * par.
norm_factor_sf(),
161 grad_j0, curl_vecj, djmu_dt, djmu_dx, djmu_dy,
165 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
166 FourVector, FourVector>
169 bool compute_gradient,
bool smearing) {
173 std::tuple<double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector,
174 FourVector, FourVector>
177 bool compute_gradient,
bool smearing) {
189 const double time_step,
const bool compute_gradient) {
191 if (lat ==
nullptr || lat->
when_update() != update) {
194 const std::array<int, 3> lattice_n_cells = lat->
n_cells();
195 const int number_of_nodes =
196 lattice_n_cells[0] * lattice_n_cells[1] * lattice_n_cells[2];
207 for (
int i = 0; i < number_of_nodes; i++) {
212 update_lattice(lat, update, dens_type, par, ensembles, compute_gradient);
217 for (
int i = 0; i < number_of_nodes; i++) {
227 for (
auto &node : *lat) {
228 auto tmp = (*four_grad_lattice)[node_number];
229 node.overwrite_djmu_dxnu(tmp[0], tmp[1], tmp[2], tmp[3]);
236 for (
auto &node : *lat) {
238 double rho = node.rho();
239 const int sgn = rho > 0 ? 1 : -1;
247 const std::array<FourVector, 4> djmu_dxnu = node.djmu_dxnu();
249 const double drho_dt =
251 (jmu.
x0() * djmu_dxnu[0].x0() - jmu.
x1() * djmu_dxnu[0].x1() -
252 jmu.
x2() * djmu_dxnu[0].x2() - jmu.
x3() * djmu_dxnu[0].x3());
254 const double drho_dx =
256 (jmu.
x0() * djmu_dxnu[1].x0() - jmu.
x1() * djmu_dxnu[1].x1() -
257 jmu.
x2() * djmu_dxnu[1].x2() - jmu.
x3() * djmu_dxnu[1].x3());
259 const double drho_dy =
261 (jmu.
x0() * djmu_dxnu[2].x0() - jmu.
x1() * djmu_dxnu[2].x1() -
262 jmu.
x2() * djmu_dxnu[2].x2() - jmu.
x3() * djmu_dxnu[2].x3());
264 const double drho_dz =
266 (jmu.
x0() * djmu_dxnu[3].x0() - jmu.
x1() * djmu_dxnu[3].x1() -
267 jmu.
x2() * djmu_dxnu[3].x2() - jmu.
x3() * djmu_dxnu[3].x3());
269 const FourVector drho_dxnu = {drho_dt, drho_dx, drho_dy, drho_dz};
271 node.overwrite_drho_dxnu(drho_dxnu);
279 os <<
"hadron density";
282 os <<
"baryon density";
285 os <<
"baryonic isospin density";
288 os <<
"pion density";
291 os <<
"total isospin3 density";
297 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.