Version: SMASH-1.7
icoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2019-2019
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/icoutput.h"
11 
12 #include <fstream>
13 
14 #include <boost/filesystem.hpp>
15 
16 #include "smash/action.h"
17 
18 namespace smash {
19 
94 ICOutput::ICOutput(const bf::path &path, const std::string &name,
95  const OutputParameters &out_par)
96  : OutputInterface(name),
97  file_{path / "SMASH_IC.dat", "w"},
98  out_par_(out_par) {
99  std::fprintf(
100  file_.get(),
101  "# %s initial conditions: hypersurface of constant proper time\n",
102  VERSION_MAJOR);
103  std::fprintf(file_.get(), "# tau x y eta mt px py Rap ID charge\n");
104  std::fprintf(file_.get(), "# fm fm fm none GeV GeV GeV none none e\n");
105 }
106 
108 
109 void ICOutput::at_eventstart(const Particles &, const int event_number) {
110  std::fprintf(file_.get(), "# event %i start\n", event_number + 1);
111 }
112 
113 void ICOutput::at_eventend(const Particles &particles, const int event_number,
114  double, bool) {
115  const auto &log = logger<LogArea::HyperSurfaceCrossing>();
116  std::fprintf(file_.get(), "# event %i end\n", event_number + 1);
117 
118  // If the runtime is too short some particles might not yet have
119  // reached the hypersurface. Warning is printed.
120  if (particles.size() != 0) {
121  log.warn(
122  "End time might be too small for initial conditions output. "
123  "Hypersurface has not yet been crossed by ",
124  particles.size(), " particle(s).");
125  }
126 }
127 
129  const std::unique_ptr<Clock> &,
130  const DensityParameters &) {
131  // Dummy, but virtual function needs to be declared.
132 }
133 
134 void ICOutput::at_interaction(const Action &action, const double) {
135  assert(action.get_type() == ProcessType::HyperSurfaceCrossing);
136  assert(action.incoming_particles().size() == 1);
137 
138  ParticleData particle = action.incoming_particles()[0];
139 
140  // transverse mass
141  const double m_trans = sqrt(particle.type().mass() * particle.type().mass() +
142  particle.momentum()[1] * particle.momentum()[1] +
143  particle.momentum()[2] * particle.momentum()[2]);
144  // momentum space rapidity
145  const double rapidity =
146  0.5 * log((particle.momentum()[0] + particle.momentum()[3]) /
147  (particle.momentum()[0] - particle.momentum()[3]));
148 
149  // write particle data
150  std::fprintf(file_.get(), "%g %g %g %g %g %g %g %g %i %i \n",
151  particle.position().tau(), particle.position()[1],
152  particle.position()[2], particle.position().eta(), m_trans,
153  particle.momentum()[1], particle.momentum()[2], rapidity,
154  particle.id(), particle.type().charge());
155 
156  if (IC_proper_time_ < 0.0) {
157  // First particle that is removed, overwrite negative default
158  IC_proper_time_ = particle.position().tau();
159  } else {
160  // Verify that all other particles have the same proper time
161  const double next_proper_time = particle.position().tau();
162  if (!((next_proper_time - IC_proper_time_) < really_small))
163  throw std::runtime_error(
164  "Hypersurface proper time changed during evolution.");
165  }
166 }
167 
168 } // namespace smash
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:106
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
ICOutput(const bf::path &path, const std::string &name, const OutputParameters &out_par)
Create a new IC output.
Definition: icoutput.cc:94
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
void at_interaction(const Action &action, const double) override
Write particle data at the hypersurface crossing point to the IC output.
Definition: icoutput.cc:134
void at_eventstart(const Particles &, const int event_number) override
Write event start line.
Definition: icoutput.cc:109
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:130
Hypersurface crossing Particles are removed from the evolution and printed to a separate output to se...
void at_intermediate_time(const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &) override
Unused, but needed since virtually declared in mother class.
Definition: icoutput.cc:128
void at_eventend(const Particles &particles, const int event_number, double, bool) override
Write event end line.
Definition: icoutput.cc:113
size_t size() const
Definition: particles.h:87
const OutputParameters out_par_
Structure that holds all the information about what to printout.
Definition: icoutput.h:74
Helper structure for Experiment to hold output options and parameters.
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:34
double IC_proper_time_
Proper time of the particles removed when extracting initial conditions.
Definition: icoutput.h:85
RenamingFilePtr file_
Pointer to output file.
Definition: icoutput.h:72
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:58
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
Abstraction of generic output.
Definition: action.h:24