14 #include "smash/config.h" 25 base_path_(
std::move(path)),
26 is_thermodynamics_output_(name ==
"Thermodynamics") {
27 const auto &log = logger<LogArea::Output>();
29 log.warn() <<
"Creating VTK output: There is no extended VTK format.";
60 const int event_number) {
89 snprintf(filename,
sizeof(filename),
"pos_ev%05i_tstep%05i.vtk",
94 std::fprintf(file_.get(),
"# vtk DataFile Version 2.0\n");
95 std::fprintf(file_.get(),
"Generated from molecular-offset data %s\n",
97 std::fprintf(file_.get(),
"ASCII\n");
100 std::fprintf(file_.get(),
"DATASET UNSTRUCTURED_GRID\n");
101 std::fprintf(file_.get(),
"POINTS %zu double\n", particles.
size());
102 for (
const auto &
p : particles) {
103 std::fprintf(file_.get(),
"%g %g %g\n",
p.position().x1(),
104 p.position().x2(),
p.position().x3());
106 std::fprintf(file_.get(),
"CELLS %zu %zu\n", particles.size(),
107 particles.size() * 2);
108 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
109 std::fprintf(file_.get(),
"1 %zu\n", point_index);
111 std::fprintf(file_.get(),
"CELL_TYPES %zu\n", particles.size());
112 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
113 std::fprintf(file_.get(),
"1\n");
115 std::fprintf(file_.get(),
"POINT_DATA %zu\n", particles.size());
116 std::fprintf(file_.get(),
"SCALARS pdg_codes int 1\n");
117 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
118 for (
const auto &
p : particles) {
119 std::fprintf(file_.get(),
"%s\n",
p.pdgcode().string().c_str());
121 std::fprintf(file_.get(),
"SCALARS is_formed int 1\n");
122 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
123 double current_time = particles.time();
124 for (
const auto &
p : particles) {
125 std::fprintf(file_.get(),
"%s\n",
126 (
p.formation_time() > current_time) ?
"0" :
"1");
128 std::fprintf(file_.get(),
"SCALARS cross_section_scaling_factor double 1\n");
129 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
130 for (
const auto &
p : particles) {
131 std::fprintf(file_.get(),
"%g\n",
p.xsec_scaling_factor());
133 std::fprintf(file_.get(),
"SCALARS mass double 1\n");
134 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
135 for (
const auto &
p : particles) {
136 std::fprintf(file_.get(),
"%g\n",
p.effective_mass());
139 std::fprintf(file_.get(),
"VECTORS momentum double\n");
140 for (
const auto &
p : particles) {
141 std::fprintf(file_.get(),
"%g %g %g\n",
p.momentum().x1(),
142 p.momentum().x2(),
p.momentum().x3());
155 template <
typename T>
158 const std::string &description) {
161 const auto orig = lattice.
origin();
162 file <<
"# vtk DataFile Version 2.0\n" 163 << description <<
"\n" 165 <<
"DATASET STRUCTURED_POINTS\n" 166 <<
"DIMENSIONS " << dim[0] <<
" " << dim[1] <<
" " << dim[2] <<
"\n" 167 <<
"SPACING " << cs[0] <<
" " << cs[1] <<
" " << cs[2] <<
"\n" 168 <<
"ORIGIN " << orig[0] <<
" " << orig[1] <<
" " << orig[2] <<
"\n" 169 <<
"POINT_DATA " << lattice.
size() <<
"\n";
172 template <
typename T,
typename F>
175 const std::string &varname, F &&get_quantity) {
176 file <<
"SCALARS " << varname <<
" double 1\n" 177 <<
"LOOKUP_TABLE default\n";
178 file << std::setprecision(3);
182 const double f_from_node = get_quantity(node);
183 file << f_from_node <<
" ";
184 if (ix == dim[0] - 1) {
190 template <
typename T,
typename F>
193 const std::string &varname, F &&get_quantity) {
194 file <<
"VECTORS " << varname <<
" double\n";
195 file << std::setprecision(3);
200 file << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
206 snprintf(suffix,
sizeof(suffix),
"_%05i_tstep%05i.vtk",
current_event_,
208 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
213 return std::string(
to_string(dens_type)) + std::string(
"_") +
224 const std::string varname =
make_varname(tq, dens_type);
255 const std::string varname =
make_varname(tq, dens_type);
260 for (
int i = 0; i < 4; i++) {
261 for (
int j = i; j < 4; j++) {
263 varname + std::to_string(i) + std::to_string(j),
273 for (
int i = 0; i < 4; i++) {
274 for (
int j = i; j < 4; j++) {
276 varname + std::to_string(i) + std::to_string(j),
FilePtr fopen(const bf::path &filename, const std::string &mode)
Open a file with given mode.
A class to pre-calculate and store parameters relevant for density calculation.
A class for time-efficient (time-memory trade-off) calculation of density on the lattice.
The ThreeVector class represents a physical three-vector with the components .
void at_eventstart(const Particles &particles, const int event_number) override
Writes the initial particle information list of an event to the VTK output.
void write_vtk_vector(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK vector.
void write_vtk_header(std::ofstream &file, RectangularLattice< T > &lat, const std::string &description)
Write the VTK header.
static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu)
Access the index of component .
void at_eventend(const Particles &particles, const int event_number, double impact_parameter) override
Writes the final particle information list of an event to the VTK output.
void thermodynamics_output(const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice) override
Prints the density lattice in VTK format on a grid.
bool part_extended
Extended format for particles output.
int vtk_tmn_output_counter_
Number of energy-momentum tensor lattice vtk output in current event.
const std::array< int, 3 > & dimensions() const
EnergyMomentumTensor boosted(const FourVector &u) const
Boost to a given 4-velocity.
int vtk_v_landau_output_counter_
Number of Landau rest frame velocity vtk output in current event.
const bf::path base_path_
filesystem path for output
A container class to hold all the arrays on the lattice and access them.
ThreeVector threevec() const
int current_event_
Event number.
std::string make_filename(const std::string &description, int counter)
Make a file name given a description and a counter.
ThermodynamicQuantity
Represents thermodynamic quantities that can be printed out.
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 Clock &clock, const DensityParameters &dens_param) override
Writes out all current particles.
std::unique_ptr< std::FILE, FileDeleter > FilePtr
A RAII type to replace std::FILE *.
const std::array< double, 3 > & origin() const
const std::array< double, 3 > & cell_sizes() const
int vtk_output_counter_
Number of vtk output in current event.
void write_vtk_scalar(std::ofstream &file, RectangularLattice< T > &lat, const std::string &varname, F &&function)
Write a VTK scalar.
FourVector landau_frame_4velocity() const
Find the Landau frame 4-velocity from energy-momentum tensor.
Helper structure for Experiment to hold output options and parameters.
The GrandCanThermalizer class implements the following functionality:
The EnergyMomentumTensor class represents a symmetric positive semi-definite energy-momentum tensor ...
Clock tracks the time in the simulation.
int vtk_fluidization_counter_
Number of fluidization output.
bool is_thermodynamics_output_
Is the VTK output a thermodynamics output.
int vtk_density_output_counter_
Number of density lattice vtk output in current event.
RectangularLattice< ThermLatticeNode > & lattice() const
Getter function for the lattice.
The ThermLatticeNode class is intended to compute thermodynamical quantities in a cell given a set of...
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.
void write(const Particles &particles)
Write the given particles to the output.
The Particles class abstracts the storage and manipulation of particles.
DensityType
Allows to choose which kind of density to calculate.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
VtkOutput(const bf::path &path, const std::string &name, const OutputParameters &out_par)
Create a new VTK output.
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Make a variable name given quantity and density type.
double density(const double norm_factor=1.0)
Compute the net Eckart density on the local lattice.
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...
Abstraction of generic output.