Version: SMASH-2.0
thermodynamicoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020
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"
22 #include "smash/vtkoutput.h"
23 
24 namespace smash {
25 
115  const std::string &name,
116  const OutputParameters &out_par)
117  : OutputInterface(name),
118  file_{path / "thermodynamics.dat", "w"},
119  out_par_(out_par) {
120  std::fprintf(file_.get(), "# %s thermodynamics output\n", VERSION_MAJOR);
121  const ThreeVector r = out_par.td_position;
122  if (out_par_.td_smearing) {
123  std::fprintf(file_.get(), "# @ point (%6.2f, %6.2f, %6.2f) [fm]\n", r.x1(),
124  r.x2(), r.x3());
125  } else {
126  std::fprintf(file_.get(), "# averaged over the entire volume\n");
127  }
128  std::fprintf(file_.get(), "# %s\n", to_string(out_par.td_dens_type));
129  std::fprintf(file_.get(), "# time [fm/c], ");
130  if (out_par_.td_rho_eckart) {
131  std::fprintf(file_.get(), "%s [fm^-3], ",
133  }
134  if (out_par_.td_tmn) {
135  if (out_par_.td_smearing) {
136  std::fprintf(file_.get(), "%s [GeV/fm^3] 00 01 02 03 11 12 13 22 23 33, ",
137  to_string(ThermodynamicQuantity::Tmn));
138  } else {
139  std::fprintf(file_.get(), "%s [GeV] 00 01 02 03 11 12 13 22 23 33, ",
140  to_string(ThermodynamicQuantity::Tmn));
141  }
142  }
143  if (out_par_.td_tmn_landau) {
144  if (out_par_.td_smearing) {
145  std::fprintf(file_.get(), "%s [GeV/fm^3] 00 01 02 03 11 12 13 22 23 33, ",
147  } else {
148  std::fprintf(file_.get(), "%s [GeV] 00 01 02 03 11 12 13 22 23 33, ",
150  }
151  }
152  if (out_par_.td_v_landau) {
153  std::fprintf(file_.get(), "%s x y z, ",
155  }
156  if (out_par_.td_jQBS) {
157  if (out_par_.td_smearing) {
158  std::fprintf(file_.get(), "j_QBS [(Q,B,S)/fm^3] (0 1 2 3)x3");
159  } else {
160  std::fprintf(file_.get(), "j_QBS [(Q,B,S)] (0 1 2 3)x3");
161  }
162  }
163  std::fprintf(file_.get(), "\n");
164 }
165 
167 
169  const int event_number,
170  const EventInfo &) {
171  std::fprintf(file_.get(), "# event %i\n", event_number);
172 }
173 
174 void ThermodynamicOutput::at_eventend(const Particles & /*particles*/,
175  const int /*event_number*/,
176  const EventInfo &) {
177  std::fflush(file_.get());
178 }
179 
181  const Particles &particles, const std::unique_ptr<Clock> &clock,
182  const DensityParameters &dens_param, const EventInfo &) {
183  std::fprintf(file_.get(), "%6.2f ", clock->current_time());
184  constexpr bool compute_gradient = false;
185  if (out_par_.td_rho_eckart) {
186  const double rho = std::get<0>(current_eckart(
187  out_par_.td_position, particles, dens_param, out_par_.td_dens_type,
188  compute_gradient, out_par_.td_smearing));
189  std::fprintf(file_.get(), "%7.4f ", rho);
190  }
193  for (const auto &p : particles) {
194  const double dens_factor =
196  if (std::abs(dens_factor) < really_small) {
197  continue;
198  }
199  if (out_par_.td_smearing) {
200  const auto sf =
202  p.position().threevec() - out_par_.td_position, p.momentum(),
203  1.0 / p.momentum().abs(), dens_param, compute_gradient)
204  .first;
205  if (sf < really_small) {
206  continue;
207  }
208  Tmn.add_particle(p, dens_factor * sf * dens_param.norm_factor_sf());
209  } else {
210  Tmn.add_particle(p, dens_factor);
211  }
212  }
213  const FourVector u = Tmn.landau_frame_4velocity();
214  const EnergyMomentumTensor Tmn_L = Tmn.boosted(u);
215  if (out_par_.td_tmn) {
216  for (int i = 0; i < 10; i++) {
217  std::fprintf(file_.get(), "%15.12f ", Tmn[i]);
218  }
219  }
220  if (out_par_.td_tmn_landau) {
221  for (int i = 0; i < 10; i++) {
222  std::fprintf(file_.get(), "%7.4f ", Tmn_L[i]);
223  }
224  }
225  if (out_par_.td_v_landau) {
226  std::fprintf(file_.get(), "%7.4f %7.4f %7.4f ", -u[1] / u[0],
227  -u[2] / u[0], -u[3] / u[0]);
228  }
229  }
230  if (out_par_.td_jQBS) {
231  FourVector jQ = std::get<1>(current_eckart(
232  out_par_.td_position, particles, dens_param, DensityType::Charge,
233  compute_gradient, out_par_.td_smearing));
234  FourVector jB = std::get<1>(current_eckart(
235  out_par_.td_position, particles, dens_param, DensityType::Baryon,
236  compute_gradient, out_par_.td_smearing));
237  FourVector jS = std::get<1>(current_eckart(
238  out_par_.td_position, particles, dens_param, DensityType::Strangeness,
239  compute_gradient, out_par_.td_smearing));
240  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jQ[0], jQ[1],
241  jQ[2], jQ[3]);
242  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jB[0], jB[1],
243  jB[2], jB[3]);
244  std::fprintf(file_.get(), "%15.12f %15.12f %15.12f %15.12f ", jS[0], jS[1],
245  jS[2], jS[3]);
246  }
247  std::fprintf(file_.get(), "\n");
248 }
249 
251  const char *file_name, const ParticleList &plist,
252  const DensityParameters &param, DensityType dens_type,
253  const ThreeVector &line_start, const ThreeVector &line_end, int n_points) {
254  ThreeVector r;
255  std::ofstream a_file;
256  a_file.open(file_name, std::ios::out);
257  const bool compute_gradient = false;
258  const bool smearing = true;
259 
260  for (int i = 0; i <= n_points; i++) {
261  r = line_start + (line_end - line_start) * (1.0 * i / n_points);
262  double rho_eck = std::get<0>(
263  current_eckart(r, plist, param, dens_type, compute_gradient, smearing));
264  a_file << r.x1() << " " << r.x2() << " " << r.x3() << " " << rho_eck
265  << "\n";
266  }
267 }
268 
269 } // namespace smash
smash::DensityType::Strangeness
smash
Definition: action.h:24
smash::ThermodynamicOutput::density_along_line
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.
Definition: thermodynamicoutput.cc:250
smash::ThermodynamicOutput::ThermodynamicOutput
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...
Definition: thermodynamicoutput.cc:114
ThermodynamicQuantity::TmnLandau
smash::ThermodynamicOutput::file_
RenamingFilePtr file_
Pointer to output file.
Definition: thermodynamicoutput.h:103
ThermodynamicQuantity::LandauVelocity
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:108
smash::ThreeVector::x3
double x3() const
Definition: threevector.h:173
smash::OutputParameters::td_jQBS
bool td_jQBS
Print out QBS 4-currents or not?
Definition: outputparameters.h:133
smash::OutputParameters::td_v_landau
bool td_v_landau
Print out Landau velocity of type td_dens_type or not?
Definition: outputparameters.h:130
energymomentumtensor.h
experimentparameters.h
smash::ThermodynamicOutput::at_eventstart
void at_eventstart(const Particles &particles, const int event_number, const EventInfo &event) override
writes the event header
Definition: thermodynamicoutput.cc:168
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
smash::ThermodynamicOutput::out_par_
const OutputParameters out_par_
Structure that holds all the information about what to printout.
Definition: thermodynamicoutput.h:105
smash::EventInfo
Structure to contain custom data for output.
Definition: outputinterface.h:35
clock.h
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
smash::RenamingFilePtr::get
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
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
smash::ThreeVector
Definition: threevector.h:31
smash::OutputParameters::td_position
ThreeVector td_position
Point, where thermodynamic quantities are calculated.
Definition: outputparameters.h:112
smash::OutputParameters
Helper structure for Experiment to hold output options and parameters.
Definition: outputparameters.h:25
smash::DensityType::Charge
ThermodynamicQuantity::Tmn
smash::OutputParameters::td_rho_eckart
bool td_rho_eckart
Print out Eckart rest frame density of type td_dens_type or not?
Definition: outputparameters.h:118
smash::OutputInterface
Abstraction of generic output.
Definition: outputinterface.h:65
smash::ThermodynamicOutput::at_eventend
void at_eventend(const Particles &particles, const int event_number, const EventInfo &event) override
only flushes the output the file
Definition: thermodynamicoutput.cc:174
smash::ThreeVector::x1
double x1() const
Definition: threevector.h:165
density.h
smash::OutputParameters::td_tmn
bool td_tmn
Print out energy-momentum tensor of type td_dens_type or not?
Definition: outputparameters.h:121
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
ThermodynamicQuantity::EckartDensity
vtkoutput.h
smash::EnergyMomentumTensor
Definition: energymomentumtensor.h:29
smash::Particles
Definition: particles.h:33
smash::DensityType
DensityType
Allows to choose which kind of density to calculate.
Definition: density.h:36
smash::DensityParameters::norm_factor_sf
double norm_factor_sf() const
Definition: density.h:143
smash::ThermodynamicOutput::~ThermodynamicOutput
~ThermodynamicOutput()
Default destructor.
Definition: thermodynamicoutput.cc:166
smash::OutputParameters::td_dens_type
DensityType td_dens_type
Type (e.g., baryon/pion/hadron) of thermodynamic quantity.
Definition: outputparameters.h:115
smash::FourVector
Definition: fourvector.h:33
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::DensityType::Baryon
thermodynamicoutput.h
smash::ThermodynamicOutput::at_intermediate_time
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &event) override
Writes thermodynamics every fixed time interval.
Definition: thermodynamicoutput.cc:180
smash::OutputParameters::td_smearing
bool td_smearing
Whether smearing is on or off; WARNING : if smearing is off, then final result is in GeV instead of G...
Definition: outputparameters.h:139
smash::ThreeVector::x2
double x2() const
Definition: threevector.h:169
smash::OutputParameters::td_tmn_landau
bool td_tmn_landau
Print out energy-momentum tensor in Landau rest frame (of type td_dens_type) or not?
Definition: outputparameters.h:127