Version: SMASH-3.4
outputinterface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_OUTPUTINTERFACE_H_
11 #define SRC_INCLUDE_SMASH_OUTPUTINTERFACE_H_
12 
13 #include <memory>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 #include "density.h"
19 #include "energymomentumtensor.h"
20 #include "forwarddeclarations.h"
21 #include "grandcan_thermalizer.h"
22 #include "lattice.h"
23 #include "macros.h"
24 
25 namespace smash {
26 static constexpr int LOutput = LogArea::Output::id;
27 
28 /**
29  * \ingroup output
30  *
31  * \brief Structure to contain custom data for output
32  *
33  * \anchor event_info
34  * This structure is intended to hold and conveniently pass information about
35  * event such as impact parameter, total potential energy, and similar
36  * auxiliary info.
37  */
38 struct EventInfo {
39  /// Impact parameter for collider modus, otherwise dummy
41  /// Box length in case of box simulation, otherwise dummy
42  double modus_length;
43  /// Time in fm
44  double current_time;
45  /// Sum of kinetic energies of all particles
47  /// Total energy in the mean field
49  /// Kinetic + mean field energy
50  double total_energy;
51  /// Testparticle number, see Testparticles in \ref doxypage_input_conf_general
53  /// Number of ensembles
55  /// True if no collisions happened
57  /// Whether or not kinematic cuts are employed for SMASH IC
59 };
60 
61 /**
62  * \ingroup output
63  *
64  * \brief Structure to contain information about the event and ensemble numbers
65  *
66  * \anchor event_label
67  * This structure is intended to hold and conveniently pass information to
68  * create a unique label for each block of output about a given ensemble of a
69  * given event.
70  */
71 struct EventLabel {
72  /// The number of the event
73  int32_t event_number;
74  /// The number of the ensemble
75  int32_t ensemble_number;
76 };
77 
78 /**
79  * \ingroup output
80  *
81  * \brief Abstraction of generic output
82  *
83  * Any output should inherit this class. It provides virtual methods that will
84  * be called at predefined moments:
85  * 1) At event start and event end: at_eventstart, at_eventend
86  * 2) After every fixed time period: at_intermediate_time, thermodynamics_output
87  * 3) At each interaction: at_interaction
88  *
89  * \attention This class provides more virtual methods than those needed in
90  * different children classes. Although this is against the inheritance "is-a"
91  * relationship, it somehow simplifies here the hierarchy, because we avoid
92  * having many more interfaces. Furthermore all base virtual methods are
93  * implemented as no-operations, i.e. empty. This implies that they can and will
94  * be called if the interface is used polymorphically but the child does not
95  * implement the called method. This happens e.g. in the Experiment class where
96  * an array of pointers to the base class is initialized with different children
97  * and then different methods are called on all array entries (some will do what
98  * has to be done, but most will just do nothing).
99  *
100  * \note The parameters of most methods in this base class are not documented,
101  * as irrelevant for the empty implementation. However, every child class which
102  * overrides some methods documents them in detail. Refer to them for further
103  * information.
104  *
105  * \attention Some methods take an \c EventLabel parameter and some just an
106  * integer. The former contains both the number of event and the number of
107  * ensemble while the latter is meant to be the number of the event, only.
108  * Passing the number of event only is meant to emphasise that the method will
109  * combine input from different ensembles, when multiple are used.
110  */
112  public:
113  /**
114  * Construct output interface.
115  * \param[in] name (File)name of output.
116  */
117  explicit OutputInterface(std::string name)
118  : is_dilepton_output_(name == "Dileptons"),
119  is_photon_output_(name == "Photons"),
120  is_IC_output_(name.substr(0, 8) == "SMASH_IC") {}
121  /**
122  * Pure virtual destructor to make class abstract and prevent its
123  * instantiation. It needs a definition which is done outside the class.
124  */
125  virtual ~OutputInterface() = 0;
126 
127  /**
128  * Output launched at event start after initialization, when particles are
129  * generated but not yet propagated.
130  */
131  virtual void at_eventstart(const Particles &, const EventLabel &,
132  const EventInfo &) {}
133 
134  /**
135  * Output launched at event start after initialization, when particles are
136  * generated but not yet propagated.
137  */
138  virtual void at_eventstart(const std::vector<Particles> &, int) {}
139 
140  /**
141  * Output launched at event start after initialization, when particles are
142  * generated but not yet propagated.
143  */
144  virtual void at_eventstart(const int, const ThermodynamicQuantity,
145  const DensityType,
147 
148  /**
149  * Output launched at event start after initialization, when particles are
150  * generated but not yet propagated.
151  */
152  virtual void at_eventstart(const int, const ThermodynamicQuantity,
153  const DensityType,
155 
156  /**
157  * Output launched at event end. Event end is determined by maximal time-step
158  * option.
159  */
160  virtual void at_eventend(const ThermodynamicQuantity) {}
161 
162  /**
163  * Output launched at event end. Event end is determined by maximal time-step
164  * option.
165  */
166  virtual void at_eventend(const Particles &, const EventLabel &,
167  const EventInfo &) {}
168  /**
169  * Output launched at event end. Event end is determined by maximal time-step
170  * option.
171  */
172  virtual void at_eventend(const std::vector<Particles> &, const int) {}
173 
174  /**
175  * Called whenever an action modified one or more particles.
176  */
177  virtual void at_interaction(const Action &, const double) {}
178 
179  /**
180  * Output launched after every N'th time-step. N is controlled by an option.
181  */
182  virtual void at_intermediate_time(const Particles &,
183  const std::unique_ptr<Clock> &,
184  const DensityParameters &,
185  const EventLabel &, const EventInfo &) {}
186  /**
187  * Output launched after every N'th timestep. N is controlled by an option.
188  */
189  virtual void at_intermediate_time(const std::vector<Particles> &,
190  const std::unique_ptr<Clock> &,
191  const DensityParameters &) {}
192 
193  /**
194  * Output to write thermodynamics from the lattice.
195  * Used for vtk output.
196  */
198  const DensityType,
200 
201  /**
202  * Output to write energy-momentum tensor and related quantities from the
203  * lattice. Used for vtk output.
204  */
205  virtual void thermodynamics_output(
206  const ThermodynamicQuantity, const DensityType,
208 
209  /**
210  * Output to write thermodynamics from the lattice.
211  * Used for thermodynamic lattice output.
212  */
214  RectangularLattice<DensityOnLattice> &, const double) {}
215 
216  /**
217  * Output to write thermodynamics from the lattice.
218  * Used for thermodynamic lattice output.
219  */
221  RectangularLattice<DensityOnLattice> &, const double,
222  const std::vector<Particles> &, const DensityParameters &) {}
223 
224  /**
225  * Output to write energy-momentum tensor and related quantities from the
226  * lattice. Used for thermodynamic lattice output.
227  */
230  const double) {}
231 
232  /**
233  * Output to write energy-momentum tensor and related quantities from the
234  * thermalizer class.
235  * Only used for vtk output. Not connected to ThermodynamicOutput.
236  */
238 
239  /**
240  * Write fields in vtk output
241  * Fields are a pair of threevectors for example electric and magnetic field
242  */
243  virtual void fields_output(
244  const std::string, const std::string,
245  RectangularLattice<std::pair<ThreeVector, ThreeVector>> &) {}
246 
247  /// Get, whether this is the dilepton output?
248  bool is_dilepton_output() const { return is_dilepton_output_; }
249 
250  /// Get, whether this is the photon output?
251  bool is_photon_output() const { return is_photon_output_; }
252 
253  /// Get, whether this is the IC output?
254  bool is_IC_output() const { return is_IC_output_; }
255 
256  /**
257  * Convert thermodynamic quantities to strings.
258  * \param[in] tq Enum value of the thermodynamic quantity.
259  * \return String description of the enumerator.
260  */
261  const char *to_string(const ThermodynamicQuantity tq) {
262  switch (tq) {
264  return "rho_eckart";
266  return "tmn";
268  return "tmn_landau";
270  return "v_landau";
272  return "j_QBS";
273  }
274  throw std::invalid_argument("Unknown thermodynamic quantity.");
275  }
276 
277  /**
278  * Convert density types to strings.
279  * \param[in] dens_type enum value of the density type
280  * \return String description of the enumerator.
281  */
282  const char *to_string(const DensityType dens_type) {
283  switch (dens_type) {
284  case DensityType::Hadron:
285  return "hadron";
286  case DensityType::Baryon:
287  return "net_baryon";
289  return "net_baryonI3";
290  case DensityType::Pion:
291  return "pion";
293  return "tot_isospin3";
294  case DensityType::Charge:
295  return "charge";
297  return "strangeness";
298  case DensityType::None:
299  return "none";
300  }
301  throw std::invalid_argument("Unknown density type.");
302  }
303 
304  protected:
305  /// Is this the dilepton output?
307 
308  /// Is this the photon output?
309  const bool is_photon_output_;
310 
311  /// Is this the IC output?
312  const bool is_IC_output_;
313 };
314 
315 inline OutputInterface::~OutputInterface() = default;
316 
317 } // namespace smash
318 
319 #endif // SRC_INCLUDE_SMASH_OUTPUTINTERFACE_H_
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
The GrandCanThermalizer class implements the following functionality:
Abstraction of generic output.
virtual void at_eventstart(const std::vector< Particles > &, int)
Output launched at event start after initialization, when particles are generated but not yet propaga...
const bool is_photon_output_
Is this the photon output?
bool is_photon_output() const
Get, whether this is the photon output?
virtual void thermodynamics_lattice_output(RectangularLattice< DensityOnLattice > &, const double, const std::vector< Particles > &, const DensityParameters &)
Output to write thermodynamics from the lattice.
const bool is_dilepton_output_
Is this the dilepton output?
virtual void at_eventstart(const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice >)
Output launched at event start after initialization, when particles are generated but not yet propaga...
virtual void at_interaction(const Action &, const double)
Called whenever an action modified one or more particles.
virtual void at_eventend(const ThermodynamicQuantity)
Output launched at event end.
virtual void at_eventend(const std::vector< Particles > &, const int)
Output launched at event end.
const bool is_IC_output_
Is this the IC output?
OutputInterface(std::string name)
Construct output interface.
virtual void at_intermediate_time(const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventLabel &, const EventInfo &)
Output launched after every N'th time-step.
virtual void at_eventstart(const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor >)
Output launched at event start after initialization, when particles are generated but not yet propaga...
virtual void thermodynamics_lattice_output(RectangularLattice< DensityOnLattice > &, const double)
Output to write thermodynamics from the lattice.
const char * to_string(const DensityType dens_type)
Convert density types to strings.
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.
virtual void at_intermediate_time(const std::vector< Particles > &, const std::unique_ptr< Clock > &, const DensityParameters &)
Output launched after every N'th timestep.
virtual void thermodynamics_output(const GrandCanThermalizer &)
Output to write energy-momentum tensor and related quantities from the thermalizer class.
virtual void at_eventend(const Particles &, const EventLabel &, const EventInfo &)
Output launched at event end.
virtual ~OutputInterface()=0
Pure virtual destructor to make class abstract and prevent its instantiation.
virtual void fields_output(const std::string, const std::string, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &)
Write fields in vtk output Fields are a pair of threevectors for example electric and magnetic field.
virtual void at_eventstart(const Particles &, const EventLabel &, const EventInfo &)
Output launched at event start after initialization, when particles are generated but not yet propaga...
bool is_dilepton_output() const
Get, whether this is the dilepton output?
virtual void thermodynamics_lattice_output(const ThermodynamicQuantity, RectangularLattice< EnergyMomentumTensor > &, const double)
Output to write energy-momentum tensor and related quantities from the lattice.
virtual void thermodynamics_output(const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice > &)
Output to write thermodynamics from the lattice.
bool is_IC_output() const
Get, whether this is the IC output?
virtual void thermodynamics_output(const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor > &)
Output to write energy-momentum tensor and related quantities from the lattice.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:49
ThermodynamicQuantity
Represents thermodynamic quantities that can be printed out See user guide description for more infor...
@ EckartDensity
Density in the Eckart frame.
@ Tmn
Energy-momentum tensor in lab frame.
@ LandauVelocity
Velocity of the Landau rest frame.
@ j_QBS
Electric (Q), baryonic (B) and strange (S) currents.
@ TmnLandau
Energy-momentum tensor in Landau rest frame.
DensityType
Allows to choose which kind of density to calculate.
Definition: action.h:24
static constexpr int LOutput
Structure to contain custom data for output.
double total_kinetic_energy
Sum of kinetic energies of all particles.
bool empty_event
True if no collisions happened.
double modus_length
Box length in case of box simulation, otherwise dummy.
double total_energy
Kinetic + mean field energy.
int n_ensembles
Number of ensembles.
double total_mean_field_energy
Total energy in the mean field.
bool impose_kinematic_cut_for_SMASH_IC
Whether or not kinematic cuts are employed for SMASH IC.
double impact_parameter
Impact parameter for collider modus, otherwise dummy.
double current_time
Time in fm.
int test_particles
Testparticle number, see Testparticles in General.
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.