14 #include "smash/config.h"
21 static constexpr
int LOutput = LogArea::Output::id;
26 base_path_(std::move(path)),
27 is_thermodynamics_output_(name ==
"Thermodynamics") {
30 <<
"Creating VTK output: There is no extended VTK format.";
61 const int event_number,
const EventInfo &) {
80 const std::unique_ptr<Clock> &,
91 snprintf(filename,
sizeof(filename),
"pos_ev%05i_tstep%05i.vtk",
96 std::fprintf(file_.get(),
"# vtk DataFile Version 2.0\n");
97 std::fprintf(file_.get(),
"Generated from molecular-offset data %s\n",
99 std::fprintf(file_.get(),
"ASCII\n");
102 std::fprintf(file_.get(),
"DATASET UNSTRUCTURED_GRID\n");
103 std::fprintf(file_.get(),
"POINTS %zu double\n", particles.
size());
104 for (
const auto &
p : particles) {
105 std::fprintf(file_.get(),
"%g %g %g\n",
p.position().x1(),
106 p.position().x2(),
p.position().x3());
108 std::fprintf(file_.get(),
"CELLS %zu %zu\n", particles.size(),
109 particles.size() * 2);
110 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
111 std::fprintf(file_.get(),
"1 %zu\n", point_index);
113 std::fprintf(file_.get(),
"CELL_TYPES %zu\n", particles.size());
114 for (
size_t point_index = 0; point_index < particles.size(); point_index++) {
115 std::fprintf(file_.get(),
"1\n");
117 std::fprintf(file_.get(),
"POINT_DATA %zu\n", particles.size());
118 std::fprintf(file_.get(),
"SCALARS pdg_codes int 1\n");
119 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
120 for (
const auto &
p : particles) {
121 std::fprintf(file_.get(),
"%s\n",
p.pdgcode().string().c_str());
123 std::fprintf(file_.get(),
"SCALARS is_formed int 1\n");
124 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
125 double current_time = particles.time();
126 for (
const auto &
p : particles) {
127 std::fprintf(file_.get(),
"%s\n",
128 (
p.formation_time() > current_time) ?
"0" :
"1");
130 std::fprintf(file_.get(),
"SCALARS cross_section_scaling_factor double 1\n");
131 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
132 for (
const auto &
p : particles) {
133 std::fprintf(file_.get(),
"%g\n",
p.xsec_scaling_factor());
135 std::fprintf(file_.get(),
"SCALARS mass double 1\n");
136 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
137 for (
const auto &
p : particles) {
138 std::fprintf(file_.get(),
"%g\n",
p.effective_mass());
140 std::fprintf(file_.get(),
"SCALARS N_coll int 1\n");
141 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
142 for (
const auto &
p : particles) {
143 std::fprintf(file_.get(),
"%i\n",
p.get_history().collisions_per_particle);
145 std::fprintf(file_.get(),
"SCALARS particle_ID int 1\n");
146 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
147 for (
const auto &
p : particles) {
148 std::fprintf(file_.get(),
"%i\n",
p.id());
150 std::fprintf(file_.get(),
"SCALARS baryon_number int 1\n");
151 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
152 for (
const auto &
p : particles) {
153 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().baryon_number());
155 std::fprintf(file_.get(),
"SCALARS strangeness int 1\n");
156 std::fprintf(file_.get(),
"LOOKUP_TABLE default\n");
157 for (
const auto &
p : particles) {
158 std::fprintf(file_.get(),
"%i\n",
p.pdgcode().strangeness());
160 std::fprintf(file_.get(),
"VECTORS momentum double\n");
161 for (
const auto &
p : particles) {
162 std::fprintf(file_.get(),
"%g %g %g\n",
p.momentum().x1(),
163 p.momentum().x2(),
p.momentum().x3());
176 template <
typename T>
179 const std::string &description) {
182 const auto orig = lattice.
origin();
183 file <<
"# vtk DataFile Version 2.0\n"
184 << description <<
"\n"
186 <<
"DATASET STRUCTURED_POINTS\n"
187 <<
"DIMENSIONS " << dim[0] <<
" " << dim[1] <<
" " << dim[2] <<
"\n"
188 <<
"SPACING " << cs[0] <<
" " << cs[1] <<
" " << cs[2] <<
"\n"
189 <<
"ORIGIN " << orig[0] <<
" " << orig[1] <<
" " << orig[2] <<
"\n"
190 <<
"POINT_DATA " << lattice.
size() <<
"\n";
193 template <
typename T,
typename F>
196 const std::string &varname, F &&get_quantity) {
197 file <<
"SCALARS " << varname <<
" double 1\n"
198 <<
"LOOKUP_TABLE default\n";
199 file << std::setprecision(3);
203 const double f_from_node = get_quantity(node);
204 file << f_from_node <<
" ";
205 if (ix == dim[0] - 1) {
211 template <
typename T,
typename F>
214 const std::string &varname, F &&get_quantity) {
215 file <<
"VECTORS " << varname <<
" double\n";
216 file << std::setprecision(3);
221 file << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
227 snprintf(suffix,
sizeof(suffix),
"_%05i_tstep%05i.vtk",
current_event_,
229 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
234 return std::string(
to_string(dens_type)) + std::string(
"_") +
245 const std::string varname =
make_varname(tq, dens_type);
276 const std::string varname =
make_varname(tq, dens_type);
281 for (
int i = 0; i < 4; i++) {
282 for (
int j = i; j < 4; j++) {
284 varname + std::to_string(i) + std::to_string(j),
294 for (
int i = 0; i < 4; i++) {
295 for (
int j = i; j < 4; j++) {
297 varname + std::to_string(i) + std::to_string(j),