14 #include "smash/config.h"
25 base_path_(std::move(path)),
26 is_thermodynamics_output_(name ==
"Thermodynamics") {
29 <<
"Creating VTK output: There is no extended VTK format.";
60 const int event_number,
const EventInfo &) {
79 const std::unique_ptr<Clock> &,
90 snprintf(filename,
sizeof(filename),
"pos_ev%05i_tstep%05i.vtk",
95 std::fprintf(file_.get(),
"# vtk DataFile Version 2.0\n");
96 std::fprintf(file_.get(),
"Generated from molecular-offset data %s\n",
98 std::fprintf(file_.get(),
"ASCII\n");
101 std::fprintf(file_.get(),
"DATASET UNSTRUCTURED_GRID\n");
102 std::fprintf(file_.get(),
"POINTS %zu double\n", particles.
size());
103 for (
const auto &
p : particles) {
104 std::fprintf(file_.get(),
"%g %g %g\n",
p.position().x1(),
105 p.position().x2(),
p.position().x3());
107 std::fprintf(file_.get(),
"CELLS %zu %zu\n", particles.size(),
108 particles.size() * 2);
109 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
110 std::fprintf(file_.get(),
"1 %zu\n", point_index);
112 std::fprintf(file_.get(),
"CELL_TYPES %zu\n", particles.size());
113 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
114 std::fprintf(file_.get(),
"1\n");
116 std::fprintf(file_.get(),
"POINT_DATA %zu\n", particles.size());
117 std::fprintf(file_.get(),
"SCALARS pdg_codes int 1\n");
118 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
119 for (
const auto &
p : particles) {
120 std::fprintf(file_.get(),
"%s\n",
p.pdgcode().string().c_str());
122 std::fprintf(file_.get(),
"SCALARS is_formed int 1\n");
123 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
124 double current_time = particles.time();
125 for (
const auto &
p : particles) {
126 std::fprintf(file_.get(),
"%s\n",
127 (
p.formation_time() > current_time) ?
"0" :
"1");
129 std::fprintf(file_.get(),
"SCALARS cross_section_scaling_factor double 1\n");
130 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
131 for (
const auto &
p : particles) {
132 std::fprintf(file_.get(),
"%g\n",
p.xsec_scaling_factor());
134 std::fprintf(file_.get(),
"SCALARS mass double 1\n");
135 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
136 for (
const auto &
p : particles) {
137 std::fprintf(file_.get(),
"%g\n",
p.effective_mass());
139 std::fprintf(file_.get(),
"SCALARS N_coll int 1\n");
140 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
141 for (
const auto &
p : particles) {
142 std::fprintf(file_.get(),
"%i\n",
p.get_history().collisions_per_particle);
144 std::fprintf(file_.get(),
"SCALARS particle_ID int 1\n");
145 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
146 for (
const auto &
p : particles) {
147 std::fprintf(file_.get(),
"%i\n",
p.id());
149 std::fprintf(file_.get(),
"SCALARS baryon_number int 1\n");
150 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
151 for (
const auto &
p : particles) {
152 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().baryon_number());
154 std::fprintf(file_.get(),
"SCALARS strangeness int 1\n");
155 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
156 for (
const auto &
p : particles) {
157 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().strangeness());
159 std::fprintf(file_.get(),
"VECTORS momentum double\n");
160 for (
const auto &
p : particles) {
161 std::fprintf(file_.get(),
"%g %g %g\n",
p.momentum().x1(),
162 p.momentum().x2(),
p.momentum().x3());
175 template <
typename T>
178 const std::string &description) {
181 const auto orig = lattice.
origin();
182 file <<
"# vtk DataFile Version 2.0\n"
183 << description <<
"\n"
185 <<
"DATASET STRUCTURED_POINTS\n"
186 <<
"DIMENSIONS " << dim[0] <<
" " << dim[1] <<
" " << dim[2] <<
"\n"
187 <<
"SPACING " << cs[0] <<
" " << cs[1] <<
" " << cs[2] <<
"\n"
188 <<
"ORIGIN " << orig[0] <<
" " << orig[1] <<
" " << orig[2] <<
"\n"
189 <<
"POINT_DATA " << lattice.
size() <<
"\n";
192 template <
typename T,
typename F>
195 const std::string &varname, F &&get_quantity) {
196 file <<
"SCALARS " << varname <<
" double 1\n"
197 <<
"LOOKUP_TABLE default\n";
198 file << std::setprecision(3);
202 const double f_from_node = get_quantity(node);
203 file << f_from_node <<
" ";
204 if (ix == dim[0] - 1) {
210 template <
typename T,
typename F>
213 const std::string &varname, F &&get_quantity) {
214 file <<
"VECTORS " << varname <<
" double\n";
215 file << std::setprecision(3);
220 file << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
226 snprintf(suffix,
sizeof(suffix),
"_%05i_tstep%05i.vtk",
current_event_,
228 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
233 return std::string(
to_string(dens_type)) + std::string(
"_") +
244 const std::string varname =
make_varname(tq, dens_type);
275 const std::string varname =
make_varname(tq, dens_type);
280 for (
int i = 0; i < 4; i++) {
281 for (
int j = i; j < 4; j++) {
283 varname + std::to_string(i) + std::to_string(j),
293 for (
int i = 0; i < 4; i++) {
294 for (
int j = i; j < 4; j++) {
296 varname + std::to_string(i) + std::to_string(j),