Version: SMASH-3.3
icoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2019-2020,2022-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/icoutput.h"
11 
12 #include <filesystem>
13 #include <fstream>
14 
15 #include "smash/action.h"
16 
17 namespace smash {
18 
102 ICOutput::ICOutput(const std::filesystem::path &path, const std::string &name,
103  const OutputParameters &out_par)
104  : OutputInterface(name),
105  file_{path / "SMASH_IC_For_vHLLE.dat", "w"},
106  out_par_(out_par),
107  formatter_{OutputDefaultQuantities::ic_For_vHLLE} {
108  std::fprintf(
109  file_.get(),
110  "# %s initial conditions: hypersurface of constant proper time\n",
111  SMASH_VERSION);
112  std::fprintf(file_.get(), "# %s", formatter_.quantities_line().c_str());
113  std::fprintf(file_.get(), "# %s", formatter_.unit_line().c_str());
114 }
115 
117 
118 void ICOutput::at_eventstart(const Particles &, const EventLabel &event_label,
119  const EventInfo &event) {
120  if (event.n_ensembles != 1) {
121  throw std::logic_error(
122  "ICOutput shouldn't be used with multiple parallel ensembles.");
123  }
124  std::fprintf(file_.get(), "# event %i ensemble %i start\n",
125  event_label.event_number, event_label.ensemble_number);
126 }
127 
128 void ICOutput::at_eventend([[maybe_unused]] const Particles &particles,
129  const EventLabel &event_label,
130  const EventInfo &event) {
131  if (event.n_ensembles != 1) {
132  throw std::logic_error(
133  "ICOutput shouldn't be used with multiple parallel ensembles.");
134  }
135  std::fprintf(file_.get(), "# event %i ensemble %i end\n",
136  event_label.event_number, event_label.ensemble_number);
137 }
138 
140  const std::unique_ptr<Clock> &,
141  const DensityParameters &,
142  const EventLabel &, const EventInfo &) {
143  // Dummy, but virtual function needs to be declared.
144 }
145 
146 void ICOutput::at_interaction(const Action &action, const double) {
147  assert(action.get_type() == ProcessType::Fluidization ||
149  assert(action.incoming_particles().size() == 1);
150 
151  const ParticleData &particle = action.incoming_particles()[0];
152 
153  // Determine if particle is spectator:
154  // Fulfilled if particle is initial nucleon, aka has no prior interactions
155  bool is_spectator = particle.get_history().collisions_per_particle == 0;
156 
157  // write particle data excluding spectators
158  if (!is_spectator) {
159  std::fprintf(file_.get(), "%s",
160  formatter_.single_particle_data(particle).c_str());
161  }
162 
163  if (IC_proper_time_ < 0.0) {
164  // First particle that is removed, overwrite negative default
165  IC_proper_time_ = particle.hyperbolic_time();
166  } else {
167  // Verify that all other particles have the same proper time
168  const double next_proper_time = particle.hyperbolic_time();
169  if (!((next_proper_time - IC_proper_time_) < really_small))
170  throw std::runtime_error(
171  "Hypersurface proper time changed during evolution.");
172  }
173 }
174 
175 } // namespace smash
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:131
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:58
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
void at_eventstart(const Particles &, const EventLabel &event_label, const EventInfo &event) override
Write event start line.
Definition: icoutput.cc:118
void at_intermediate_time(const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventLabel &, const EventInfo &) override
Unused, but needed since virtually declared in mother class.
Definition: icoutput.cc:139
RenamingFilePtr file_
Pointer to output file.
Definition: icoutput.h:76
ICOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
Create a new IC output.
Definition: icoutput.cc:102
double IC_proper_time_
Proper time of the particles removed when extracting initial conditions.
Definition: icoutput.h:89
void at_interaction(const Action &action, const double) override
Write particle data at the hypersurface crossing point to the IC output.
Definition: icoutput.cc:146
void at_eventend(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Write event end line.
Definition: icoutput.cc:128
OutputFormatter< ToASCII > formatter_
Formatter of the output.
Definition: icoutput.h:92
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
double hyperbolic_time() const
Particle (hyperbolic time)
Definition: particledata.h:404
HistoryData get_history() const
Get history information.
Definition: particledata.h:143
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
Definition: action.h:24
@ FluidizationNoRemoval
See here for a short description.
@ Fluidization
See here for a short description.
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:41
Structure to contain custom data for output.
int n_ensembles
Number of ensembles.
Structure to contain information about the event and ensemble numbers.
int32_t ensemble_number
The number of the ensemble.
int32_t event_number
The number of the event.
int32_t collisions_per_particle
Collision counter per particle, zero only for initially present particles.
Definition: particledata.h:33
Struct that holds quantities required by default output standards.
Helper structure for Experiment to hold output options and parameters.