15 #include <boost/filesystem.hpp>
18 #include "smash/config.h"
184 const bf::path &path,
const std::string &name,
186 const bool enable_binary)
189 base_path_(std::move(path)),
190 enable_ascii_(enable_ascii),
191 enable_binary_(enable_binary) {
200 std::make_shared<std::ofstream>(
nullptr);
204 std::make_shared<std::ofstream>(
nullptr);
208 std::make_shared<std::ofstream>(
nullptr);
212 std::make_shared<std::ofstream>(
nullptr);
216 std::make_shared<std::ofstream>(
nullptr);
222 std::make_shared<std::ofstream>(
nullptr);
226 std::make_shared<std::ofstream>(
nullptr);
230 std::make_shared<std::ofstream>(
nullptr);
234 std::make_shared<std::ofstream>(
nullptr);
238 std::make_shared<std::ofstream>(
nullptr);
255 const auto dim = lattice.
n_cells();
257 const auto orig = lattice.
origin();
258 for (
int l = 0; l < 3; l++) {
263 std::shared_ptr<std::ofstream> fp(
nullptr);
265 std::string filename;
272 filename, std::ios::out);
273 }
catch (std::ofstream::failure &e) {
274 logg[LogArea::Main::id].fatal()
275 <<
"Error in opening " << filename << std::endl;
276 throw std::runtime_error(
277 "Not possible to write thermodynamic "
278 "lattice output to file.");
287 filename, std::ios::out | std::ios::binary);
288 }
catch (std::ofstream::failure &e) {
289 logg[LogArea::Main::id].fatal()
290 <<
"Error in opening " << filename << std::endl;
291 throw std::runtime_error(
292 "Not possible to write thermodynamic "
293 "lattice output to file.");
304 }
catch (std::ofstream::failure &e) {
305 logg[LogArea::Main::id].fatal()
306 <<
"Error in opening " << filename << std::endl;
307 throw std::runtime_error(
308 "Not possible to write thermodynamic "
309 "lattice output to file.");
318 filename, std::ios::out | std::ios::binary);
319 }
catch (std::ofstream::failure &e) {
320 logg[LogArea::Main::id].fatal()
321 <<
"Error in opening " << filename << std::endl;
322 throw std::runtime_error(
323 "Not possible to write thermodynamic "
324 "lattice output to file.");
339 const auto dim = lattice.
n_cells();
341 const auto orig = lattice.
origin();
342 for (
int l = 0; l < 3; l++) {
347 std::shared_ptr<std::ofstream> fp(
nullptr);
349 std::string filename;
356 filename, std::ios::out);
357 }
catch (std::ofstream::failure &e) {
358 logg[LogArea::Main::id].fatal()
359 <<
"Error in opening " << filename << std::endl;
360 throw std::runtime_error(
361 "Not possible to write thermodynamic "
362 "lattice output to file.");
369 }
catch (std::ofstream::failure &e) {
370 logg[LogArea::Main::id].fatal()
371 <<
"Error in opening " << filename << std::endl;
372 throw std::runtime_error(
373 "Not possible to write thermodynamic "
374 "lattice output to file.");
380 filename, std::ios::out);
381 }
catch (std::ofstream::failure &e) {
382 logg[LogArea::Main::id].fatal()
383 <<
"Error in opening " << filename << std::endl;
384 throw std::runtime_error(
385 "Not possible to write thermodynamic "
386 "lattice output to file.");
393 }
catch (std::ofstream::failure &e) {
394 logg[LogArea::Main::id].fatal()
395 <<
"Error in opening " << filename << std::endl;
396 throw std::runtime_error(
397 "Not possible to write thermodynamic "
398 "lattice output to file.");
408 filename, std::ios::out | std::ios::binary);
409 }
catch (std::ofstream::failure &e) {
410 logg[LogArea::Main::id].fatal()
411 <<
"Error in opening " << filename << std::endl;
412 throw std::runtime_error(
413 "Not possible to write thermodynamic "
414 "lattice output to file.");
420 filename, std::ios::out | std::ios::binary);
421 }
catch (std::ofstream::failure &e) {
422 logg[LogArea::Main::id].fatal()
423 <<
"Error in opening " << filename << std::endl;
424 throw std::runtime_error(
425 "Not possible to write thermodynamic "
426 "lattice output to file.");
432 filename, std::ios::out | std::ios::binary);
433 }
catch (std::ofstream::failure &e) {
434 logg[LogArea::Main::id].fatal()
435 <<
"Error in opening " << filename << std::endl;
436 throw std::runtime_error(
437 "Not possible to write thermodynamic "
438 "lattice output to file.");
445 }
catch (std::ofstream::failure &e) {
446 logg[LogArea::Main::id].fatal()
447 <<
"Error in opening " << filename << std::endl;
448 throw std::runtime_error(
449 "Not possible to write thermodynamic "
450 "lattice output to file.");
511 const auto dim = lattice.
n_cells();
512 std::shared_ptr<std::ofstream> fp(
nullptr);
515 *fp << std::setprecision(14);
516 *fp << std::scientific;
517 *fp << ctime << std::endl;
521 assert(
sizeof(ctime) ==
sizeof(
double));
522 fp->write(
reinterpret_cast<char *
>(&ctime),
sizeof(ctime));
527 *fp << node.rho() <<
" ";
528 if (ix == dim[0] - 1) {
534 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
541 const std::vector<Particles> &ensembles,
547 const auto dim = lattice.
n_cells();
548 std::shared_ptr<std::ofstream> fp(
nullptr);
550 constexpr
bool compute_gradient =
false;
553 *fp << std::setprecision(14);
554 *fp << std::scientific;
555 *fp << ctime << std::endl;
559 assert(
sizeof(ctime) ==
sizeof(
double));
560 fp->write(
reinterpret_cast<char *
>(&ctime),
sizeof(ctime));
568 for (
const Particles &particles : ensembles) {
581 for (
int l = 1; l < 4; l++) {
584 for (
int l = 0; l < 4; l++) {
587 for (
int l = 0; l < 4; l++) {
593 for (
int l = 0; l < 4; l++) {
595 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
597 for (
int l = 0; l < 4; l++) {
599 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
601 for (
int l = 0; l < 4; l++) {
603 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
616 const auto dim = lattice.
n_cells();
617 std::shared_ptr<std::ofstream> fp(
nullptr);
632 *fp << std::setprecision(14);
633 *fp << std::scientific;
634 *fp << ctime << std::endl;
650 assert(
sizeof(ctime) ==
sizeof(
double));
651 fp->write(
reinterpret_cast<char *
>(&ctime),
sizeof(
double));
655 for (
int i = 0; i < 4; i++) {
656 for (
int j = i; j < 4; j++) {
662 if (ix == dim[0] - 1) {
668 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
675 for (
int i = 0; i < 4; i++) {
676 for (
int j = i; j < 4; j++) {
681 const FourVector u = node.landau_frame_4velocity();
684 if (ix == dim[0] - 1) {
689 const FourVector u = node.landau_frame_4velocity();
692 fp->write(
reinterpret_cast<char *
>(&result),
sizeof(
double));
702 const FourVector u = node.landau_frame_4velocity();
704 *fp << v.
x1() <<
" " << v.
x2() <<
" " << v.
x3() <<
"\n";
707 const FourVector u = node.landau_frame_4velocity();
709 fp->write(
reinterpret_cast<char *
>(&v), 3 *
sizeof(double));
731 throw std::runtime_error(
732 "Error when converting a thermodynamic quantity "
733 "to an int, unknown quantity.");
738 const int event_number,
741 assert((type ==
'a') || (type ==
'b'));
743 snprintf(suffix,
sizeof(suffix),
"_%07i.dat", event_number);
745 snprintf(suffix,
sizeof(suffix),
"_%07i.bin", event_number);
747 return base_path_.string() + std::string(
"/") + descr + std::string(suffix);
752 return std::string(
to_string(dens_type)) + std::string(
"_") +
758 *fp << std::setprecision(2);
760 *fp <<
"#Thermodynamic Lattice Output version: "
762 *fp << std::setprecision(6);
764 <<
" " << std::string(
to_string(tq)) << std::endl;
765 *fp <<
"#Grid dimensions: " <<
nodes_[0] <<
" " <<
nodes_[1] <<
" "
766 <<
nodes_[2] << std::endl;
775 auto variable_id =
to_int(tq);
779 fp->write(
reinterpret_cast<char *
>(&variable_id),
sizeof(
int));
780 fp->write(
reinterpret_cast<char *
>(&
nodes_),
sizeof(
nodes_));
781 fp->write(
reinterpret_cast<char *
>(&
sizes_),
sizeof(
sizes_));
A class for time-efficient (time-memory trade-off) calculation of density on the 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.
static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu)
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
void reset()
Set all the 4-vector components to 0.
ThreeVector velocity() const
Get the velocity (3-vector divided by zero component).
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.
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.
ThreeVector cell_center(int ix, int iy, int iz) const
Find the coordinates of a given cell.
const std::array< double, 3 > & cell_sizes() const
const bf::path base_path_
filesystem path for output
std::array< int, 3 > nodes_
number of nodes in the lattice along the three axes
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_ascii_files_
map of output file handlers for ASCII format
bool enable_binary_
enable output type Binary
void at_eventstart(const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, const RectangularLattice< DensityOnLattice > lattice) override
Output launched at event start after initialization, when particles are generated but not yet propaga...
std::string make_filename(const std::string &description, const int event_number, const char type)
Makes a file name given a description and a counter.
static const double_t version
Version of the thermodynamic lattice output.
~ThermodynamicLatticeOutput()
Default destructor.
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_binary_files_
map of output file handlers for binary format
int to_int(const ThermodynamicQuantity &tq)
Convert a ThermodynamicQuantity into an int.
void write_therm_lattice_binary_header(std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
Writes the header for the binary output files.
void write_therm_lattice_ascii_header(std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
Writes the header for the ASCII output files.
void thermodynamics_lattice_output(RectangularLattice< DensityOnLattice > &lattice, double current_time) override
Prints the density lattice on a grid.
void at_eventend(const ThermodynamicQuantity tq) override
Final actions at the end of each event (it closes the output files).
const OutputParameters out_par_
Structure that holds all the information about what to printout.
bool enable_output_
enable output, of any kind (if False, the object does nothing)
ThermodynamicLatticeOutput(const bf::path &path, const std::string &name, const OutputParameters &out_par, const bool enable_ascii, const bool enable_binary)
Construct Output.
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Makes a variable name given quantity and density type.
bool enable_ascii_
enable output type ASCII
std::array< double, 3 > sizes_
lattice resolution along the three axes
std::array< double, 3 > origin_
lattice origin orientation: if 0,0,0 is the origin of a cube with face widths 10, the center is at 5,...
The ThreeVector class represents a physical three-vector with the components .
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
std::tuple< double, FourVector, ThreeVector, ThreeVector, FourVector, FourVector, FourVector, FourVector > current_eckart(const ThreeVector &r, const ParticleList &plist, const DensityParameters &par, DensityType dens_type, bool compute_gradient, bool smearing)
DensityType
Allows to choose which kind of density to calculate.
Helper structure for Experiment to hold output options and parameters.
bool td_v_landau
Print out Landau velocity of type td_dens_type or not?
bool td_tmn_landau
Print out energy-momentum tensor in Landau rest frame (of type td_dens_type) or not?
bool td_jQBS
Print out QBS 4-currents or not?
bool td_tmn
Print out energy-momentum tensor of type td_dens_type or not?
bool td_smearing
Whether smearing is on or off; WARNING : if smearing is off, then final result is in GeV instead of G...
bool td_rho_eckart
Print out Eckart rest frame density of type td_dens_type or not?