Version: SMASH-3.4
vtkoutput.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_VTKOUTPUT_H_
11 #define SRC_INCLUDE_SMASH_VTKOUTPUT_H_
12 
13 #include <filesystem>
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <utility>
18 
19 #include "density.h"
20 #include "forwarddeclarations.h"
21 #include "outputinterface.h"
22 #include "outputparameters.h"
23 
24 namespace smash {
25 
26 /**
27  * \ingroup output
28  * Output format processible by <a href="http://paraview.org">ParaView
29  * </a>, intended for simple visualization.
30  */
31 class VtkOutput : public OutputInterface {
32  public:
33  /**
34  * Create a new VTK output.
35  *
36  * \param path Path to the output file.
37  * \param name Name of the output.
38  * \param out_par Additional information on the configured output.
39  */
40  VtkOutput(const std::filesystem::path &path, const std::string &name,
41  const OutputParameters &out_par);
42  ~VtkOutput();
43 
44  /**
45  * Writes the initial particle information list of an event to the VTK
46  * output.
47  *
48  * \param particles Current list of all particles.
49  * \param event_label Numbers of the current event and ensemble.
50  * \param event Event info, see \ref event_info
51  */
52  void at_eventstart(const Particles &particles, const EventLabel &event_label,
53  const EventInfo &event) override;
54 
55  /**
56  * Writes the final particle information list of an event to the VTK
57  * output. This currently does not do anything, because it is not
58  * required for the VTK output.
59  *
60  * \param particles Unused, needed since inherited.
61  * \param event_label Unused, needed since inherited.
62  * \param[in] event Event info, see \ref event_info
63  */
64  void at_eventend(const Particles &particles, const EventLabel &event_label,
65  const EventInfo &event) override;
66 
67  /**
68  * Writes out all current particles.
69  *
70  * \param particles Current list of particles.
71  * \param clock Unused, needed since inherited.
72  * \param dens_param Unused, needed since inherited.
73  * \param event_label Numbers of the current event and ensemble.
74  * \param event Event info, see \ref event_info
75  */
76  void at_intermediate_time(const Particles &particles,
77  const std::unique_ptr<Clock> &clock,
78  const DensityParameters &dens_param,
79  const EventLabel &event_label,
80  const EventInfo &event) override;
81 
82  /**
83  * Prints the density lattice in VTK format on a grid.
84  *
85  * \param tq The quantity whose density should be written,
86  * see ThermodynamicQuantity.
87  * \param dt The type of the density, see DensityType.
88  * \param lattice The lattice from which the quantity is taken.
89  */
91  const ThermodynamicQuantity tq, const DensityType dt,
93 
94  /**
95  * Prints the energy-momentum-tensor lattice in VTK format on a grid.
96  *
97  * \param tq The quantity whose density should be written,
98  see ThermodynamicQuantity.
99  * \param dt The type of the density, see DensityType
100  * \param lattice The lattice from which the quantity is taken.
101  */
103  const ThermodynamicQuantity tq, const DensityType dt,
105 
106  /**
107  * Printout of all thermodynamic quantities from the thermalizer class.
108  *
109  * \param gct Grand-canonical thermalizer from which the quantities are
110  * taken.
111  */
112  void thermodynamics_output(const GrandCanThermalizer &gct) override;
113 
114  /// \copydoc OutputInterface::fields_output
115  void fields_output(
116  const std::string name1, const std::string name2,
117  RectangularLattice<std::pair<ThreeVector, ThreeVector>> &lat) override;
118 
119  private:
120  /**
121  * Write the given particles to the output.
122  *
123  * \param particles The particles.
124  */
125  void write(const Particles &particles);
126 
127  /**
128  * Make a file name given a description and a counter.
129  *
130  * \param description The description.
131  * \param counter The counter enumerating the outputs.
132  */
133  std::string make_filename(const std::string &description, int counter);
134 
135  /**
136  * Make a variable name given quantity and density type.
137  *
138  * \param tq The quantity.
139  * \param dens_type The density type.
140  */
141  std::string make_varname(const ThermodynamicQuantity tq,
142  const DensityType dens_type);
143 
144  /**
145  * Write the VTK header.
146  *
147  * \param file Output file.
148  * \param lat Lattice corresponding to output.
149  * \param description Description of the output.
150  */
151  template <typename T>
152  void write_vtk_header(std::ofstream &file, RectangularLattice<T> &lat,
153  const std::string &description);
154 
155  /**
156  * Write a VTK scalar.
157  *
158  * \param file Output file.
159  * \param lat Lattice corresponding to output.
160  * \param varname Name of the output variable.
161  * \param function Function that gets the scalar given a lattice node.
162  */
163  template <typename T, typename F>
164  void write_vtk_scalar(std::ofstream &file, RectangularLattice<T> &lat,
165  const std::string &varname, F &&function);
166 
167  /**
168  * Write a VTK vector.
169  *
170  * \param file Output file.
171  * \param lat Lattice corresponding to output.
172  * \param varname Name of the output variable.
173  * \param function Function that gets the vector given a lattice node.
174  */
175  template <typename T, typename F>
176  void write_vtk_vector(std::ofstream &file, RectangularLattice<T> &lat,
177  const std::string &varname, F &&function);
178 
179  /**
180  * Create the key to access the \c vtk_output_counter_ map.
181  *
182  * \return std::pair<int, int> The key to access the map.
183  */
184  std::pair<int, int> counter_key() {
186  }
187 
188  /// filesystem path for output
189  const std::filesystem::path base_path_;
190 
191  /// Event number
192  int current_event_ = 0;
193  /// Ensemble number
195  /**
196  * Counters to keep track of time steps per event and per ensemble. The first
197  * pair index runs over events and the second one over ensembles, but this is
198  * encapsulated in the \c counter_key method which is used to change this map.
199  */
200  std::map<std::pair<int, int>, int> vtk_output_counter_{};
201 
202  /// Number of density lattice vtk output in current event
204  /// Number of energy-momentum tensor lattice vtk output in current event
206  /// Number of Landau frame energy-momentum tensor vtk output in current event
208  /// Number of Landau rest frame velocity vtk output in current event
210  /// Number of fluidization output
212  /// Number of fields output in current event
214  /// Is the VTK output a thermodynamics output
216  /// Is the VTK output an output for fields
218 };
219 
220 } // namespace smash
221 
222 #endif // SRC_INCLUDE_SMASH_VTKOUTPUT_H_
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.
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
Output format processible by ParaView , intended for simple visualization.
Definition: vtkoutput.h:31
void write_vtk_scalar(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK scalar.
Definition: vtkoutput.cc:225
int vtk_density_output_counter_
Number of density lattice vtk output in current event.
Definition: vtkoutput.h:203
void fields_output(const std::string name1, const std::string name2, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &lat) override
Write fields in vtk output Fields are a pair of threevectors for example electric and magnetic field.
Definition: vtkoutput.cc:332
bool is_fields_output_
Is the VTK output an output for fields.
Definition: vtkoutput.h:217
std::pair< int, int > counter_key()
Create the key to access the vtk_output_counter_ map.
Definition: vtkoutput.h:184
void write(const Particles &particles)
Write the given particles to the output.
Definition: vtkoutput.cc:128
int vtk_fluidization_counter_
Number of fluidization output.
Definition: vtkoutput.h:211
int current_event_
Event number.
Definition: vtkoutput.h:192
VtkOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
Create a new VTK output.
Definition: vtkoutput.cc:24
int current_ensemble_
Ensemble number.
Definition: vtkoutput.h:194
void write_vtk_header(std::ofstream &file, RectangularLattice< T > &lat, const std::string &description)
Write the VTK header.
Definition: vtkoutput.cc:208
int vtk_fields_output_counter_
Number of fields output in current event.
Definition: vtkoutput.h:213
void write_vtk_vector(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK vector.
Definition: vtkoutput.cc:243
std::map< std::pair< int, int >, int > vtk_output_counter_
Counters to keep track of time steps per event and per ensemble.
Definition: vtkoutput.h:200
void at_eventend(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Writes the final particle information list of an event to the VTK output.
Definition: vtkoutput.cc:111
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Make a variable name given quantity and density type.
Definition: vtkoutput.cc:263
bool is_thermodynamics_output_
Is the VTK output a thermodynamics output.
Definition: vtkoutput.h:215
int vtk_tmn_landau_output_counter_
Number of Landau frame energy-momentum tensor vtk output in current event.
Definition: vtkoutput.h:207
void thermodynamics_output(const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice) override
Prints the density lattice in VTK format on a grid.
Definition: vtkoutput.cc:269
int vtk_v_landau_output_counter_
Number of Landau rest frame velocity vtk output in current event.
Definition: vtkoutput.h:209
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventLabel &event_label, const EventInfo &event) override
Writes out all current particles.
Definition: vtkoutput.cc:115
const std::filesystem::path base_path_
filesystem path for output
Definition: vtkoutput.h:189
void at_eventstart(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Writes the initial particle information list of an event to the VTK output.
Definition: vtkoutput.cc:93
std::string make_filename(const std::string &description, int counter)
Make a file name given a description and a counter.
Definition: vtkoutput.cc:256
int vtk_tmn_output_counter_
Number of energy-momentum tensor lattice vtk output in current event.
Definition: vtkoutput.h:205
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
Structure to contain custom data for output.
Structure to contain information about the event and ensemble numbers.
Helper structure for Experiment to hold output options and parameters.