15 #include "smash/config.h"
26 base_path_(std::move(path)),
27 is_thermodynamics_output_(name ==
"Thermodynamics"),
28 is_fields_output_(name ==
"Fields") {
31 <<
"Creating VTK output: There is no extended VTK format.";
62 const int event_number,
const EventInfo &) {
81 const std::unique_ptr<Clock> &,
92 snprintf(filename,
sizeof(filename),
"pos_ev%05i_tstep%05i.vtk",
97 std::fprintf(file_.get(),
"# vtk DataFile Version 2.0\n");
98 std::fprintf(file_.get(),
"Generated from molecular-offset data %s\n",
100 std::fprintf(file_.get(),
"ASCII\n");
103 std::fprintf(file_.get(),
"DATASET UNSTRUCTURED_GRID\n");
104 std::fprintf(file_.get(),
"POINTS %zu double\n", particles.
size());
105 for (
const auto &
p : particles) {
106 std::fprintf(file_.get(),
"%g %g %g\n",
p.position().x1(),
107 p.position().x2(),
p.position().x3());
109 std::fprintf(file_.get(),
"CELLS %zu %zu\n", particles.
size(),
110 particles.
size() * 2);
111 for (
size_t point_index = 0; point_index < particles.
size(); point_index++) {
112 std::fprintf(file_.get(),
"1 %zu\n", point_index);
114 std::fprintf(file_.get(),
"CELL_TYPES %zu\n", particles.
size());
115 for (
size_t point_index = 0; point_index < particles.
size(); point_index++) {
116 std::fprintf(file_.get(),
"1\n");
118 std::fprintf(file_.get(),
"POINT_DATA %zu\n", particles.
size());
119 std::fprintf(file_.get(),
"SCALARS pdg_codes int 1\n");
120 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
121 for (
const auto &
p : particles) {
122 std::fprintf(file_.get(),
"%s\n",
p.pdgcode().string().c_str());
124 std::fprintf(file_.get(),
"SCALARS is_formed int 1\n");
125 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
126 double current_time = particles.
time();
127 for (
const auto &
p : particles) {
128 std::fprintf(file_.get(),
"%s\n",
129 (
p.formation_time() > current_time) ?
"0" :
"1");
131 std::fprintf(file_.get(),
"SCALARS cross_section_scaling_factor double 1\n");
132 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
133 for (
const auto &
p : particles) {
134 std::fprintf(file_.get(),
"%g\n",
p.xsec_scaling_factor());
136 std::fprintf(file_.get(),
"SCALARS mass double 1\n");
137 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
138 for (
const auto &
p : particles) {
139 std::fprintf(file_.get(),
"%g\n",
p.effective_mass());
141 std::fprintf(file_.get(),
"SCALARS N_coll int 1\n");
142 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
143 for (
const auto &
p : particles) {
144 std::fprintf(file_.get(),
"%i\n",
p.get_history().collisions_per_particle);
146 std::fprintf(file_.get(),
"SCALARS particle_ID int 1\n");
147 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
148 for (
const auto &
p : particles) {
149 std::fprintf(file_.get(),
"%i\n",
p.id());
151 std::fprintf(file_.get(),
"SCALARS baryon_number int 1\n");
152 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
153 for (
const auto &
p : particles) {
154 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().baryon_number());
156 std::fprintf(file_.get(),
"SCALARS strangeness int 1\n");
157 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
158 for (
const auto &
p : particles) {
159 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().strangeness());
161 std::fprintf(file_.get(),
"VECTORS momentum double\n");
162 for (
const auto &
p : particles) {
163 std::fprintf(file_.get(),
"%g %g %g\n",
p.momentum().x1(),
164 p.momentum().x2(),
p.momentum().x3());
177 template <
typename T>
180 const std::string &description) {
181 const auto dim = lattice.
n_cells();
183 const auto orig = lattice.
origin();
184 file <<
"# vtk DataFile Version 2.0\n"
185 << description <<
"\n"
187 <<
"DATASET STRUCTURED_POINTS\n"
188 <<
"DIMENSIONS " << dim[0] <<
" " << dim[1] <<
" " << dim[2] <<
"\n"
189 <<
"SPACING " << cs[0] <<
" " << cs[1] <<
" " << cs[2] <<
"\n"
190 <<
"ORIGIN " << orig[0] <<
" " << orig[1] <<
" " << orig[2] <<
"\n"
191 <<
"POINT_DATA " << lattice.
size() <<
"\n";
194 template <
typename T,
typename F>
197 const std::string &varname, F &&get_quantity) {
198 file <<
"SCALARS " << varname <<
" double 1\n"
199 <<
"LOOKUP_TABLE default\n";
200 file << std::setprecision(3);
202 const auto dim = lattice.
n_cells();
204 const double f_from_node = get_quantity(node);
205 file << f_from_node <<
" ";
206 if (ix == dim[0] - 1) {
212 template <
typename T,
typename F>
215 const std::string &varname, F &&get_quantity) {
216 file <<
"VECTORS " << varname <<
" double\n";
217 file << std::setprecision(3);
219 const auto dim = lattice.
n_cells();
222 file << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
228 snprintf(suffix,
sizeof(suffix),
"_%05i_tstep%05i.vtk",
current_event_,
230 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
235 return std::string(
to_string(dens_type)) + std::string(
"_") +
246 const std::string varname =
make_varname(tq, dens_type);
277 const std::string varname =
make_varname(tq, dens_type);
282 for (
int i = 0; i < 4; i++) {
283 for (
int j = i; j < 4; j++) {
285 varname + std::to_string(i) + std::to_string(j),
295 for (
int i = 0; i < 4; i++) {
296 for (
int j = i; j < 4; j++) {
298 varname + std::to_string(i) + std::to_string(j),
319 const std::string name1,
const std::string name2,
329 [&](std::pair<ThreeVector, ThreeVector> &node) {
return node.first; });
335 [&](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.
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 bf::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.
const bf::path base_path_
filesystem path for output
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.
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.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
FilePtr fopen(const bf::path &filename, const std::string &mode)
Open a file with given mode.
std::unique_ptr< std::FILE, FileDeleter > FilePtr
A RAII type to replace std::FILE *.
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.