17 #include "smash/config.h"
27 base_path_(std::move(path)),
28 is_thermodynamics_output_(name ==
"Thermodynamics"),
29 is_fields_output_(name ==
"Fields") {
32 <<
"Creating VTK output: There is no extended VTK format.";
63 const int event_number,
const EventInfo &) {
82 const std::unique_ptr<Clock> &,
93 snprintf(filename,
sizeof(filename),
"pos_ev%05i_tstep%05i.vtk",
98 std::fprintf(file_.get(),
"# vtk DataFile Version 2.0\n");
99 std::fprintf(file_.get(),
"Generated from molecular-offset data %s\n",
101 std::fprintf(file_.get(),
"ASCII\n");
104 std::fprintf(file_.get(),
"DATASET UNSTRUCTURED_GRID\n");
105 std::fprintf(file_.get(),
"POINTS %zu double\n", particles.
size());
106 for (
const auto &
p : particles) {
107 std::fprintf(file_.get(),
"%g %g %g\n",
p.position().x1(),
108 p.position().x2(),
p.position().x3());
110 std::fprintf(file_.get(),
"CELLS %zu %zu\n", particles.
size(),
111 particles.
size() * 2);
112 for (
size_t point_index = 0; point_index < particles.
size(); point_index++) {
113 std::fprintf(file_.get(),
"1 %zu\n", point_index);
115 std::fprintf(file_.get(),
"CELL_TYPES %zu\n", particles.
size());
116 for (
size_t point_index = 0; point_index < particles.
size(); point_index++) {
117 std::fprintf(file_.get(),
"1\n");
119 std::fprintf(file_.get(),
"POINT_DATA %zu\n", particles.
size());
120 std::fprintf(file_.get(),
"SCALARS pdg_codes int 1\n");
121 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
122 for (
const auto &
p : particles) {
123 std::fprintf(file_.get(),
"%s\n",
p.pdgcode().string().c_str());
125 std::fprintf(file_.get(),
"SCALARS is_formed int 1\n");
126 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
127 double current_time = particles.
time();
128 for (
const auto &
p : particles) {
129 std::fprintf(file_.get(),
"%s\n",
130 (
p.formation_time() > current_time) ?
"0" :
"1");
132 std::fprintf(file_.get(),
"SCALARS cross_section_scaling_factor double 1\n");
133 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
134 for (
const auto &
p : particles) {
135 std::fprintf(file_.get(),
"%g\n",
p.xsec_scaling_factor());
137 std::fprintf(file_.get(),
"SCALARS mass double 1\n");
138 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
139 for (
const auto &
p : particles) {
140 std::fprintf(file_.get(),
"%g\n",
p.effective_mass());
142 std::fprintf(file_.get(),
"SCALARS N_coll int 1\n");
143 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
144 for (
const auto &
p : particles) {
145 std::fprintf(file_.get(),
"%i\n",
p.get_history().collisions_per_particle);
147 std::fprintf(file_.get(),
"SCALARS particle_ID int 1\n");
148 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
149 for (
const auto &
p : particles) {
150 std::fprintf(file_.get(),
"%i\n",
p.id());
152 std::fprintf(file_.get(),
"SCALARS baryon_number int 1\n");
153 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
154 for (
const auto &
p : particles) {
155 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().baryon_number());
157 std::fprintf(file_.get(),
"SCALARS strangeness int 1\n");
158 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
159 for (
const auto &
p : particles) {
160 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().strangeness());
162 std::fprintf(file_.get(),
"VECTORS momentum double\n");
163 for (
const auto &
p : particles) {
164 std::fprintf(file_.get(),
"%g %g %g\n",
p.momentum().x1(),
165 p.momentum().x2(),
p.momentum().x3());
178 template <
typename T>
181 const std::string &description) {
182 const auto dim = lattice.
n_cells();
184 const auto orig = lattice.
origin();
185 file <<
"# vtk DataFile Version 2.0\n"
186 << description <<
"\n"
188 <<
"DATASET STRUCTURED_POINTS\n"
189 <<
"DIMENSIONS " << dim[0] <<
" " << dim[1] <<
" " << dim[2] <<
"\n"
190 <<
"SPACING " << cs[0] <<
" " << cs[1] <<
" " << cs[2] <<
"\n"
191 <<
"ORIGIN " << orig[0] <<
" " << orig[1] <<
" " << orig[2] <<
"\n"
192 <<
"POINT_DATA " << lattice.
size() <<
"\n";
195 template <
typename T,
typename F>
198 const std::string &varname, F &&get_quantity) {
199 file <<
"SCALARS " << varname <<
" double 1\n"
200 <<
"LOOKUP_TABLE default\n";
201 file << std::setprecision(3);
203 const auto dim = lattice.
n_cells();
205 const double f_from_node = get_quantity(node);
206 file << f_from_node <<
" ";
207 if (ix == dim[0] - 1) {
213 template <
typename T,
typename F>
216 const std::string &varname, F &&get_quantity) {
217 file <<
"VECTORS " << varname <<
" double\n";
218 file << std::setprecision(3);
220 const auto dim = lattice.
n_cells();
223 file << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
229 snprintf(suffix,
sizeof(suffix),
"_%05i_tstep%05i.vtk",
current_event_,
231 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
236 return std::string(
to_string(dens_type)) + std::string(
"_") +
247 const std::string varname =
make_varname(tq, dens_type);
278 const std::string varname =
make_varname(tq, dens_type);
283 for (
int i = 0; i < 4; i++) {
284 for (
int j = i; j < 4; j++) {
286 varname + std::to_string(i) + std::to_string(j),
296 for (
int i = 0; i < 4; i++) {
297 for (
int j = i; j < 4; j++) {
299 varname + std::to_string(i) + std::to_string(j),
320 const std::string name1,
const std::string name2,
330 [&](std::pair<ThreeVector, ThreeVector> &node) {
return node.first; });
336 [&](std::pair<ThreeVector, ThreeVector> &node) {
return node.second; });
A class for time-efficient (time-memory trade-off) calculation of density on the lattice.
double rho(const double norm_factor=1.0)
Compute the net Eckart density on the local lattice.
A class to pre-calculate and store parameters relevant for density calculation.
The EnergyMomentumTensor class represents a symmetric positive semi-definite energy-momentum tensor .
EnergyMomentumTensor boosted(const FourVector &u) const
Boost to a given 4-velocity.
FourVector landau_frame_4velocity() const
Find the Landau frame 4-velocity from energy-momentum tensor.
static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu)
Access the index of component .
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
ThreeVector velocity() const
Get the velocity (3-vector divided by zero component).
The GrandCanThermalizer class implements the following functionality:
RectangularLattice< ThermLatticeNode > & lattice() const
Getter function for the lattice.
Abstraction of generic output.
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.
The Particles class abstracts the storage and manipulation of particles.
double time() const
Returns the time of the computational frame.
A container class to hold all the arrays on the lattice and access them.
const std::array< double, 3 > & origin() const
const std::array< int, 3 > & n_cells() const
void iterate_sublattice(const std::array< int, 3 > &lower_bounds, const std::array< int, 3 > &upper_bounds, F &&func)
A sub-lattice iterator, which iterates in a 3D-structured manner and calls a function on every cell.
const std::array< double, 3 > & cell_sizes() const
The ThermLatticeNode class is intended to compute thermodynamical quantities in a cell given a set of...
The ThreeVector class represents a physical three-vector with the components .
void write_vtk_scalar(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK scalar.
void at_eventend(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the final particle information list of an event to the VTK output.
int vtk_density_output_counter_
Number of density lattice vtk output in current event.
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.
bool is_fields_output_
Is the VTK output an output for fields.
int vtk_output_counter_
Number of vtk output in current event.
void write(const Particles &particles)
Write the given particles to the output.
int vtk_fluidization_counter_
Number of fluidization output.
int current_event_
Event number.
VtkOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
Create a new VTK output.
void write_vtk_header(std::ofstream &file, RectangularLattice< T > &lat, const std::string &description)
Write the VTK header.
int vtk_fields_output_counter_
Number of fields output in current event.
void write_vtk_vector(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK vector.
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Make a variable name given quantity and density type.
bool is_thermodynamics_output_
Is the VTK output a thermodynamics output.
int vtk_tmn_landau_output_counter_
Number of Landau frame energy-momentum tensor vtk output in current event.
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &event) override
Writes out all current particles.
void thermodynamics_output(const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice) override
Prints the density lattice in VTK format on a grid.
int vtk_v_landau_output_counter_
Number of Landau rest frame velocity vtk output in current event.
void at_eventstart(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the initial particle information list of an event to the VTK output.
const std::filesystem::path base_path_
filesystem path for output
std::string make_filename(const std::string &description, int counter)
Make a file name given a description and a counter.
int vtk_tmn_output_counter_
Number of energy-momentum tensor lattice vtk output in current event.
ThermodynamicQuantity
Represents thermodynamic quantities that can be printed out See user guide description for more infor...
@ Tmn
Energy-momentum tensor in lab frame.
@ TmnLandau
Energy-momentum tensor in Landau rest frame.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
std::unique_ptr< std::FILE, FileDeleter > FilePtr
A RAII type to replace std::FILE *.
FilePtr fopen(const std::filesystem::path &filename, const std::string &mode)
Open a file with given mode.
static constexpr int LOutput
DensityType
Allows to choose which kind of density to calculate.
Structure to contain custom data for output.
Helper structure for Experiment to hold output options and parameters.
bool part_extended
Extended format for particles output.