Version: SMASH-1.6
thermodynamicoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2018
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
11 
12 #include <fstream>
13 #include <memory>
14 
15 #include <boost/filesystem.hpp>
16 
17 #include "smash/clock.h"
18 #include "smash/config.h"
19 #include "smash/density.h"
23 #include "smash/particles.h"
24 #include "smash/vtkoutput.h"
25 
26 namespace smash {
27 
110  const std::string &name,
111  const OutputParameters &out_par)
112  : OutputInterface(name),
113  file_{path / "thermodynamics.dat", "w"},
114  out_par_(out_par) {
115  std::fprintf(file_.get(), "# %s thermodynamics output\n", VERSION_MAJOR);
116  const ThreeVector r = out_par.td_position;
117  if (out_par_.td_smearing) {
118  std::fprintf(file_.get(), "# @ point (%6.2f, %6.2f, %6.2f) [fm]\n", r.x1(),
119  r.x2(), r.x3());
120  } else {
121  std::fprintf(file_.get(), "# averaged over the entire volume\n");
122  }
123  std::fprintf(file_.get(), "# %s\n", to_string(out_par.td_dens_type));
124  std::fprintf(file_.get(), "# time [fm/c], ");
125  if (out_par_.td_rho_eckart) {
126  std::fprintf(file_.get(), "%s [fm^-3], ",
128  }
129  if (out_par_.td_tmn) {
130  if (out_par_.td_smearing) {
131  std::fprintf(file_.get(), "%s [GeV/fm^3] 00 01 02 03 11 12 13 22 23 33, ",
133  } else {
134  std::fprintf(file_.get(), "%s [GeV] 00 01 02 03 11 12 13 22 23 33, ",
136  }
137  }
138  if (out_par_.td_tmn_landau) {
139  if (out_par_.td_smearing) {
140  std::fprintf(file_.get(), "%s [GeV/fm^3] 00 01 02 03 11 12 13 22 23 33, ",
142  } else {
143  std::fprintf(file_.get(), "%s [GeV] 00 01 02 03 11 12 13 22 23 33, ",
145  }
146  }
147  if (out_par_.td_v_landau) {
148  std::fprintf(file_.get(), "%s x y z, ",
150  }
151  if (out_par_.td_jQBS) {
152  if (out_par_.td_smearing) {
153  std::fprintf(file_.get(), "j_QBS [(Q,B,S)/fm^3] (0 1 2 3)x3");
154  } else {
155  std::fprintf(file_.get(), "j_QBS [(Q,B,S)] (0 1 2 3)x3");
156  }
157  }
158  std::fprintf(file_.get(), "\n");
159 }
160 
162 
164  const int event_number) {
165  std::fprintf(file_.get(), "# event %i\n", event_number);
166 }
167 
168 void ThermodynamicOutput::at_eventend(const Particles & /*particles*/,
169  const int /*event_number*/,
170  double /*impact_parameter*/) {
171  std::fflush(file_.get());
172 }
173 
175  const Particles &particles, const Clock &clock,
176  const DensityParameters &dens_param) {
177  std::fprintf(file_.get(), "%6.2f ", clock.current_time());
178  constexpr bool compute_gradient = false;
179  if (out_par_.td_rho_eckart) {
180  const double rho = std::get<0>(current_eckart(
181  out_par_.td_position, particles, dens_param, out_par_.td_dens_type,
182  compute_gradient, out_par_.td_smearing));
183  std::fprintf(file_.get(), "%7.4f ", rho);
184  }
187  for (const auto &p : particles) {
188  const double dens_factor =
190  if (std::abs(dens_factor) < really_small) {
191  continue;
192  }
193  if (out_par_.td_smearing) {
194  const auto sf =
196  p.position().threevec() - out_par_.td_position, p.momentum(),
197  1.0 / p.momentum().abs(), dens_param, compute_gradient)
198  .first;
199  if (sf < really_small) {
200  continue;
201  }
202  Tmn.add_particle(p, dens_factor * sf * dens_param.norm_factor_sf());
203  } else {
204  Tmn.add_particle(p, dens_factor);
205  }
206  }
207  const FourVector u = Tmn.landau_frame_4velocity();
208  const EnergyMomentumTensor Tmn_L = Tmn.boosted(u);
209  if (out_par_.td_tmn) {
210  for (int i = 0; i < 10; i++) {
211  std::fprintf(file_.get(), "%15.12f ", Tmn[i]);
212  }
213  }
214  if (out_par_.td_tmn_landau) {
215  for (int i = 0; i < 10; i++) {
216  std::fprintf(file_.get(), "%7.4f ", Tmn_L[i]);
217  }
218  }
219  if (out_par_.td_v_landau) {
220  std::fprintf(file_.get(), "%7.4f %7.4f %7.4f ", -u[1] / u[0],
221  -u[2] / u[0], -u[3] / u[0]);
222  }
223  }
224  if (out_par_.td_jQBS) {
225  FourVector jQ = std::get<1>(current_eckart(
226  out_par_.td_position, particles, dens_param, DensityType::Charge,
227  compute_gradient, out_par_.td_smearing));
228  FourVector jB = std::get<1>(current_eckart(
229  out_par_.td_position, particles, dens_param, DensityType::Baryon,
230  compute_gradient, out_par_.td_smearing));
231  FourVector jS = std::get<1>(current_eckart(
232  out_par_.td_position, particles, dens_param, DensityType::Strangeness,
233  compute_gradient, out_par_.td_smearing));
234  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jQ[0], jQ[1],
235  jQ[2], jQ[3]);
236  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jB[0], jB[1],
237  jB[2], jB[3]);
238  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jS[0], jS[1],
239  jS[2], jS[3]);
240  }
241  std::fprintf(file_.get(), "\n");
242 }
243 
245  const char *file_name, const ParticleList &plist,
246  const DensityParameters &param, DensityType dens_type,
247  const ThreeVector &line_start, const ThreeVector &line_end, int n_points) {
248  ThreeVector r;
249  std::ofstream a_file;
250  a_file.open(file_name, std::ios::out);
251  const bool compute_gradient = false;
252  const bool smearing = true;
253 
254  for (int i = 0; i <= n_points; i++) {
255  r = line_start + (line_end - line_start) * (1.0 * i / n_points);
256  double rho_eck = std::get<0>(
257  current_eckart(r, plist, param, dens_type, compute_gradient, smearing));
258  a_file << r.x1() << " " << r.x2() << " " << r.x3() << " " << rho_eck
259  << "\n";
260  }
261 }
262 
263 } // namespace smash
void at_eventend(const Particles &particles, const int event_number, double impact_parameter) override
only flushes the output the file
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:106
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
DensityType td_dens_type
Type (e.g., baryon/pion/hadron) of thermodynamic quantity.
double x3() const
Definition: threevector.h:163
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
ThreeVector td_position
Point, where thermodynamic quantities are calculated.
bool td_jQBS
Print out QBS 4-currents or not?
const OutputParameters out_par_
Structure that holds all the information about what to printout.
bool td_tmn_landau
Print out energy-momentum tensor in Landau rest frame (of type td_dens_type) or not?
EnergyMomentumTensor boosted(const FourVector &u) const
Boost to a given 4-velocity.
bool td_smearing
Whether smearing is on or off; WARNING : if smearing is off, then final result is in GeV instead of G...
void at_intermediate_time(const Particles &particles, const Clock &clock, const DensityParameters &dens_param) override
Writes thermodynamics every fixed time interval.
~ThermodynamicOutput()
Default destructor.
FourVector landau_frame_4velocity() const
Find the Landau frame 4-velocity from energy-momentum tensor.
ThermodynamicOutput(const bf::path &path, const std::string &name, const OutputParameters &out_par)
Construct Output param[in] path Path to output param[in] name Filename param[in] out_par Parameters o...
void at_eventstart(const Particles &particles, const int event_number) override
writes the event header
bool td_rho_eckart
Print out Eckart rest frame density of type td_dens_type or not?
Helper structure for Experiment to hold output options and parameters.
The EnergyMomentumTensor class represents a symmetric positive semi-definite energy-momentum tensor ...
Clock tracks the time in the simulation.
Definition: clock.h:75
double x1() const
Definition: threevector.h:155
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
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
constexpr int p
Proton.
void add_particle(const FourVector &mom)
Given momentum of the particle adds to the energy momentum tensor.
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
double x2() const
Definition: threevector.h:159
bool td_tmn
Print out energy-momentum tensor of type td_dens_type or not?
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.
double current_time() const
Definition: clock.h:110
double norm_factor_sf() const
Definition: density.h:141
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
bool td_v_landau
Print out Landau velocity of type td_dens_type or not?
DensityType
Allows to choose which kind of density to calculate.
Definition: density.h:34
void density_along_line(const char *file_name, const ParticleList &plist, const DensityParameters &param, DensityType dens_type, const ThreeVector &line_start, const ThreeVector &line_end, int n_points)
Prints density along the specified line.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
RenamingFilePtr file_
Pointer to output file.
Abstraction of generic output.
Definition: action.h:24