Version: SMASH-3.4
thermodynamiclatticeoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2022,2024,2026
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_THERMODYNAMICLATTICEOUTPUT_H_
11 #define SRC_INCLUDE_SMASH_THERMODYNAMICLATTICEOUTPUT_H_
12 
13 #include <filesystem>
14 #include <map>
15 #include <memory>
16 #include <set>
17 #include <string>
18 #include <vector>
19 
20 #include "density.h"
21 #include "experimentparameters.h"
22 #include "file.h"
23 #include "forwarddeclarations.h"
24 #include "logging.h"
25 #include "outputinterface.h"
26 #include "outputparameters.h"
27 #include "threevector.h"
28 
29 namespace smash {
30 
31 /**
32  * \ingroup output
33  *
34  * \brief Writes the thermodynamic quantities at lattice points versus time
35  *
36  * This class is a temporary solution to write thermodynamic
37  * quantities out. Calculations are called directly inside the
38  * output functions. In future it should be substituted by some
39  * more general output.
40  *
41  */
43  public:
44  /// Version of the thermodynamic lattice output
45  static const double_t version;
46 
47  /**
48  * Construct Output
49  * \param[in] path Path to output
50  * \param[in] name Filename
51  * \param[in] out_par Parameters of output
52  * \param[in] enable_ascii Bool (True or False) to enable ASCII format
53  * \param[in] enable_binary Bool (True or False) to enable binary format
54  */
55  ThermodynamicLatticeOutput(const std::filesystem::path &path,
56  const std::string &name,
57  const OutputParameters &out_par,
58  const bool enable_ascii, const bool enable_binary);
59  /// Default destructor
61  /**
62  * Output launched at event start after initialization, when particles are
63  * generated but not yet propagated.
64  * \param[in] event_number Number of the current event.
65  * \param[in] tq Thermodynamic quantity to deal with
66  * \param[in] dens_type Density type for the reference frame.
67  * \param[in] lattice Specialized Lattice for DensityOnLattice
68  *
69  * \note This method takes the event number and not the ensemble number as the
70  * lattice is meant to contain an average over ensembles if multiple ensembles
71  * are used.
72  */
73  void at_eventstart(
74  const int event_number, const ThermodynamicQuantity tq,
75  const DensityType dens_type,
77  /**
78  * Output launched at event start after initialization, when particles are
79  * generated but not yet propagated.
80  * \param[in] event_number Number of the current event.
81  * \param[in] tq Thermodynamic quantity to deal with.
82  * \param[in] dens_type Density type for the reference frame.
83  * \param[in] lattice Specialized Lattice for EnergyMomentumTensor
84  *
85  * \note This method takes the event number and not the ensemble number as the
86  * lattice is meant to contain an average over ensembles if multiple ensembles
87  * are used.
88  */
89  void at_eventstart(
90  const int event_number, const ThermodynamicQuantity tq,
91  const DensityType dens_type,
93 
94  /**
95  * Final actions at the end of each event (it closes the output files).
96  * \param[in] tq The quantity that has been written in the output file,
97  * see ThermodynamicQuantity.
98  */
99  void at_eventend(const ThermodynamicQuantity tq) override;
100 
101  /**
102  * Prints the density lattice on a grid. *
103  * \param[in] lattice DensityOnLattice lattice to use.
104  * \param[in] current_time The output time in the computational frame
105  */
108  double current_time) override;
109 
110  /**
111  * Prints the density lattice on a grid.
112  *
113  * \param[in] lattice DensityOnLattice lattice to use.
114  * \param[in] current_time The output time in the computational frame
115  * \param[in] ensembles Particles, from which the 4-currents j_{Q,B,S} are
116  * computed
117  * * \param[in] dens_param set of parameters, defining smearing.
118  * For more info about
119  * smearing see \ref doxypage_output_thermodyn.
120  */
122  RectangularLattice<DensityOnLattice> &lattice, const double current_time,
123  const std::vector<Particles> &ensembles,
124  const DensityParameters &dens_param) override;
125 
126  /**
127  * Prints the energy-momentum-tensor lattice on a grid.
128  *
129  * \param[in] tq The quantity whose energy-momentum tensor should be written,
130  * see ThermodynamicQuantity.
131  * \param[in] lattice EnergyMomentumTensor lattice to use.
132  * \param[in] current_time The output time in the computational frame
133  *
134  */
136  const ThermodynamicQuantity tq,
138  double current_time) override;
139 
140  private:
141  /// Structure that holds all the information about what to printout
143 
144  /**
145  * Makes a file name given a description and a counter.
146  *
147  * \param[in] description The description.
148  * \param[in] event_number The event number.
149  * \param[in] type Flag for the file type: 'a' for ASCII, 'b' for Binary
150  */
151  std::string make_filename(const std::string &description,
152  const int event_number, const char type);
153 
154  /**
155  * Makes a variable name given quantity and density type.
156  *
157  * \param[in] tq The quantity.
158  * \param[in] dens_type The density type.
159  */
160  std::string make_varname(const ThermodynamicQuantity tq,
161  const DensityType dens_type);
162 
163  /**
164  * Writes the header for the ASCII output files
165  *
166  * \param file Output file.
167  * \param[in] tq The quantity to be written,
168  * see ThermodynamicQuantity.
169  */
170  void write_therm_lattice_ascii_header(std::shared_ptr<std::ofstream> file,
171  const ThermodynamicQuantity &tq);
172 
173  /**
174  * Writes the header for the binary output files
175  *
176  * \param[in] file Output file.
177  * \param[in] tq The quantity to be written,
178  * see ThermodynamicQuantity.
179  */
180  void write_therm_lattice_binary_header(std::shared_ptr<std::ofstream> file,
181  const ThermodynamicQuantity &tq);
182 
183  /**
184  * Convert a ThermodynamicQuantity into an int
185  * \param[in] tq The quantity to be converted, see ThermodynamicQuantity.
186  * \return An int corresponding to ThermodynamicQuantity.
187  */
188  int to_int(const ThermodynamicQuantity &tq);
189 
190  /// filesystem path for output
191  const std::filesystem::path base_path_;
192 
193  /// map of output file handlers for ASCII format
194  std::map<ThermodynamicQuantity, std::shared_ptr<std::ofstream>>
196 
197  /// map of output file handlers for binary format
198  std::map<ThermodynamicQuantity, std::shared_ptr<std::ofstream>>
200 
201  /// number of nodes in the lattice along the three axes
202  std::array<int, 3> nodes_;
203 
204  /// lattice resolution along the three axes
205  std::array<double, 3> sizes_;
206 
207  /// lattice origin
208  /// orientation: if 0,0,0 is the origin of a cube with face widths 10,
209  /// the center is at 5,5,5
210  std::array<double, 3> origin_;
211 
212  /// enable output type ASCII
214 
215  /// enable output type Binary
217 
218  /// enable output, of any kind (if False, the object does nothing)
220 };
221 
222 } // namespace smash
223 
224 #endif // SRC_INCLUDE_SMASH_THERMODYNAMICLATTICEOUTPUT_H_
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
Abstraction of generic output.
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:49
Writes the thermodynamic quantities at lattice points versus time.
std::array< int, 3 > nodes_
number of nodes in the lattice along the three axes
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_ascii_files_
map of output file handlers for ASCII format
bool enable_binary_
enable output type Binary
void at_eventstart(const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, const RectangularLattice< DensityOnLattice > lattice) override
Output launched at event start after initialization, when particles are generated but not yet propaga...
std::string make_filename(const std::string &description, const int event_number, const char type)
Makes a file name given a description and a counter.
static const double_t version
Version of the thermodynamic lattice output.
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_binary_files_
map of output file handlers for binary format
int to_int(const ThermodynamicQuantity &tq)
Convert a ThermodynamicQuantity into an int.
void write_therm_lattice_binary_header(std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
Writes the header for the binary output files.
void write_therm_lattice_ascii_header(std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
Writes the header for the ASCII output files.
const std::filesystem::path base_path_
filesystem path for output
void thermodynamics_lattice_output(RectangularLattice< DensityOnLattice > &lattice, double current_time) override
Prints the density lattice on a grid.
void at_eventend(const ThermodynamicQuantity tq) override
Final actions at the end of each event (it closes the output files).
const OutputParameters out_par_
Structure that holds all the information about what to printout.
bool enable_output_
enable output, of any kind (if False, the object does nothing)
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Makes a variable name given quantity and density type.
bool enable_ascii_
enable output type ASCII
std::array< double, 3 > sizes_
lattice resolution along the three axes
ThermodynamicLatticeOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par, const bool enable_ascii, const bool enable_binary)
Construct Output.
std::array< double, 3 > origin_
lattice origin orientation: if 0,0,0 is the origin of a cube with face widths 10, the center is at 5,...
ThermodynamicQuantity
Represents thermodynamic quantities that can be printed out See user guide description for more infor...
DensityType
Allows to choose which kind of density to calculate.
constexpr Section lattice
Section for the lattice.
Definition: input_keys.h:149
Definition: action.h:24
Helper structure for Experiment to hold output options and parameters.