Version: SMASH-3.4
smash::ThermodynamicLatticeOutput Class Reference

#include <thermodynamiclatticeoutput.h>

Writes the thermodynamic quantities at lattice points versus time.

This class is a temporary solution to write thermodynamic quantities out. Calculations are called directly inside the output functions. In future it should be substituted by some more general output.

Definition at line 42 of file thermodynamiclatticeoutput.h.

Inheritance diagram for smash::ThermodynamicLatticeOutput:
[legend]
Collaboration diagram for smash::ThermodynamicLatticeOutput:
[legend]

Public Member Functions

 ThermodynamicLatticeOutput (const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par, const bool enable_ascii, const bool enable_binary)
 Construct Output. More...
 
 ~ThermodynamicLatticeOutput ()
 Default destructor. More...
 
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 propagated. More...
 
void at_eventstart (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, const RectangularLattice< EnergyMomentumTensor > lattice) override
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
void at_eventend (const ThermodynamicQuantity tq) override
 Final actions at the end of each event (it closes the output files). More...
 
void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &lattice, double current_time) override
 Prints the density lattice on a grid. More...
 
void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &lattice, const double current_time, const std::vector< Particles > &ensembles, const DensityParameters &dens_param) override
 Prints the density lattice on a grid. More...
 
void thermodynamics_lattice_output (const ThermodynamicQuantity tq, RectangularLattice< EnergyMomentumTensor > &lattice, double current_time) override
 Prints the energy-momentum-tensor lattice on a grid. More...
 
- Public Member Functions inherited from smash::OutputInterface
 OutputInterface (std::string name)
 Construct output interface. More...
 
virtual ~OutputInterface ()=0
 Pure virtual destructor to make class abstract and prevent its instantiation. More...
 
virtual void at_eventstart (const Particles &, const EventLabel &, const EventInfo &)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const std::vector< Particles > &, int)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventend (const Particles &, const EventLabel &, const EventInfo &)
 Output launched at event end. More...
 
virtual void at_eventend (const std::vector< Particles > &, const int)
 Output launched at event end. More...
 
virtual void at_interaction (const Action &, const double)
 Called whenever an action modified one or more particles. More...
 
virtual void at_intermediate_time (const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventLabel &, const EventInfo &)
 Output launched after every N'th time-step. More...
 
virtual void at_intermediate_time (const std::vector< Particles > &, const std::unique_ptr< Clock > &, const DensityParameters &)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice > &)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor > &)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
virtual void fields_output (const std::string, const std::string, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &)
 Write fields in vtk output Fields are a pair of threevectors for example electric and magnetic field. More...
 
bool is_dilepton_output () const
 Get, whether this is the dilepton output? More...
 
bool is_photon_output () const
 Get, whether this is the photon output? More...
 
bool is_IC_output () const
 Get, whether this is the IC output? More...
 
const char * to_string (const ThermodynamicQuantity tq)
 Convert thermodynamic quantities to strings. More...
 
const char * to_string (const DensityType dens_type)
 Convert density types to strings. More...
 

Static Public Attributes

static const double_t version = 1.0
 Version of the thermodynamic lattice output. More...
 

Private Member Functions

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. More...
 
std::string make_varname (const ThermodynamicQuantity tq, const DensityType dens_type)
 Makes a variable name given quantity and density type. More...
 
void write_therm_lattice_ascii_header (std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
 Writes the header for the ASCII output files. More...
 
void write_therm_lattice_binary_header (std::shared_ptr< std::ofstream > file, const ThermodynamicQuantity &tq)
 Writes the header for the binary output files. More...
 
int to_int (const ThermodynamicQuantity &tq)
 Convert a ThermodynamicQuantity into an int. More...
 

Private Attributes

const OutputParameters out_par_
 Structure that holds all the information about what to printout. More...
 
const std::filesystem::path base_path_
 filesystem path for output More...
 
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_ascii_files_
 map of output file handlers for ASCII format More...
 
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_binary_files_
 map of output file handlers for binary format More...
 
std::array< int, 3 > nodes_
 number of nodes in the lattice along the three axes More...
 
std::array< double, 3 > sizes_
 lattice resolution along the three axes More...
 
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,5,5 More...
 
bool enable_ascii_
 enable output type ASCII More...
 
bool enable_binary_
 enable output type Binary More...
 
bool enable_output_
 enable output, of any kind (if False, the object does nothing) More...
 

Additional Inherited Members

- Protected Attributes inherited from smash::OutputInterface
const bool is_dilepton_output_
 Is this the dilepton output? More...
 
const bool is_photon_output_
 Is this the photon output? More...
 
const bool is_IC_output_
 Is this the IC output? More...
 

Constructor & Destructor Documentation

◆ ThermodynamicLatticeOutput()

smash::ThermodynamicLatticeOutput::ThermodynamicLatticeOutput ( const std::filesystem::path &  path,
const std::string &  name,
const OutputParameters out_par,
const bool  enable_ascii,
const bool  enable_binary 
)

Construct Output.

Parameters
[in]pathPath to output
[in]nameFilename
[in]out_parParameters of output
[in]enable_asciiBool (True or False) to enable ASCII format
[in]enable_binaryBool (True or False) to enable binary format

Definition at line 185 of file thermodynamiclatticeoutput.cc.

189  : OutputInterface(name),
190  out_par_(out_par),
191  base_path_(std::move(path)),
192  enable_ascii_(enable_ascii),
193  enable_binary_(enable_binary) {
194  if (enable_ascii_ || enable_binary_) {
195  enable_output_ = true;
196  } else {
197  enable_output_ = false;
198  }
199  if (enable_ascii_) {
200  if (out_par_.td_rho_eckart) {
202  std::make_shared<std::ofstream>(nullptr);
203  }
204  if (out_par_.td_tmn_landau) {
206  std::make_shared<std::ofstream>(nullptr);
207  }
208  if (out_par_.td_tmn) {
210  std::make_shared<std::ofstream>(nullptr);
211  }
212  if (out_par_.td_v_landau) {
214  std::make_shared<std::ofstream>(nullptr);
215  }
216  if (out_par_.td_jQBS) {
218  std::make_shared<std::ofstream>(nullptr);
219  }
220  }
221  if (enable_binary_) {
222  if (out_par_.td_rho_eckart) {
224  std::make_shared<std::ofstream>(nullptr);
225  }
226  if (out_par_.td_tmn_landau) {
228  std::make_shared<std::ofstream>(nullptr);
229  }
230  if (out_par_.td_tmn) {
232  std::make_shared<std::ofstream>(nullptr);
233  }
234  if (out_par_.td_v_landau) {
236  std::make_shared<std::ofstream>(nullptr);
237  }
238  if (out_par_.td_jQBS) {
240  std::make_shared<std::ofstream>(nullptr);
241  }
242  }
243 }
OutputInterface(std::string name)
Construct output interface.
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
std::map< ThermodynamicQuantity, std::shared_ptr< std::ofstream > > output_binary_files_
map of output file handlers for binary format
const std::filesystem::path base_path_
filesystem path for output
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)
bool enable_ascii_
enable output type ASCII
@ EckartDensity
Density in the Eckart frame.
@ Tmn
Energy-momentum tensor in lab frame.
@ LandauVelocity
Velocity of the Landau rest frame.
@ j_QBS
Electric (Q), baryonic (B) and strange (S) currents.
@ TmnLandau
Energy-momentum tensor in Landau rest frame.
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_rho_eckart
Print out Eckart rest frame density of type td_dens_type or not?

◆ ~ThermodynamicLatticeOutput()

smash::ThermodynamicLatticeOutput::~ThermodynamicLatticeOutput ( )

Default destructor.

Definition at line 245 of file thermodynamiclatticeoutput.cc.

245 {}

Member Function Documentation

◆ at_eventstart() [1/2]

void smash::ThermodynamicLatticeOutput::at_eventstart ( const int  event_number,
const ThermodynamicQuantity  tq,
const DensityType  dens_type,
const RectangularLattice< DensityOnLattice lattice 
)
overridevirtual

Output launched at event start after initialization, when particles are generated but not yet propagated.

Parameters
[in]event_numberNumber of the current event.
[in]tqThermodynamic quantity to deal with
[in]dens_typeDensity type for the reference frame.
[in]latticeSpecialized Lattice for DensityOnLattice
Note
This method takes the event number and not the ensemble number as the lattice is meant to contain an average over ensembles if multiple ensembles are used.

Reimplemented from smash::OutputInterface.

Definition at line 247 of file thermodynamiclatticeoutput.cc.

249  {
250  if (!enable_output_) {
251  return;
252  }
253  assert((tq == ThermodynamicQuantity::EckartDensity) ||
255  // at the next refactoring of the code,
256  // this piece should go in the constructor
257  const auto dim = lattice.n_cells();
258  const auto cs = lattice.cell_sizes();
259  const auto orig = lattice.origin();
260  for (int l = 0; l < 3; l++) {
261  nodes_[l] = dim[l];
262  sizes_[l] = cs[l];
263  origin_[l] = orig[l];
264  }
265  std::shared_ptr<std::ofstream> fp(nullptr);
266  std::string varname;
267  std::string filename;
268  varname = make_varname(tq, dens_type);
270  if (enable_ascii_) {
271  filename = make_filename(varname, event_number, 'a');
272  try {
274  filename, std::ios::out);
275  } catch (std::ofstream::failure &e) {
276  logg[LogArea::Main::id].fatal()
277  << "Error in opening " << filename << std::endl;
278  throw std::runtime_error(
279  "Not possible to write thermodynamic "
280  "lattice output to file.");
281  }
284  }
285  if (enable_binary_) {
286  filename = make_filename(varname, event_number, 'b');
287  try {
289  filename, std::ios::out | std::ios::binary);
290  } catch (std::ofstream::failure &e) {
291  logg[LogArea::Main::id].fatal()
292  << "Error in opening " << filename << std::endl;
293  throw std::runtime_error(
294  "Not possible to write thermodynamic "
295  "lattice output to file.");
296  }
299  }
300  } else {
301  if (enable_ascii_) {
302  filename = make_filename(varname, event_number, 'a');
303  try {
305  std::ios::out);
306  } catch (std::ofstream::failure &e) {
307  logg[LogArea::Main::id].fatal()
308  << "Error in opening " << filename << std::endl;
309  throw std::runtime_error(
310  "Not possible to write thermodynamic "
311  "lattice output to file.");
312  }
315  }
316  if (enable_binary_) {
317  filename = make_filename(varname, event_number, 'b');
318  try {
320  filename, std::ios::out | std::ios::binary);
321  } catch (std::ofstream::failure &e) {
322  logg[LogArea::Main::id].fatal()
323  << "Error in opening " << filename << std::endl;
324  throw std::runtime_error(
325  "Not possible to write thermodynamic "
326  "lattice output to file.");
327  }
330  }
331  }
332 }
std::array< int, 3 > nodes_
number of nodes in the lattice along the three axes
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.
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.
std::string make_varname(const ThermodynamicQuantity tq, const DensityType dens_type)
Makes a variable name given quantity and density type.
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,...
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > & logg
An array that stores all pre-configured Logger objects.
Definition: logging.h:245
constexpr Section lattice
Section for the lattice.
Definition: input_keys.h:149
Here is the call graph for this function:

◆ at_eventstart() [2/2]

void smash::ThermodynamicLatticeOutput::at_eventstart ( const int  event_number,
const ThermodynamicQuantity  tq,
const DensityType  dens_type,
const RectangularLattice< EnergyMomentumTensor lattice 
)
overridevirtual

Output launched at event start after initialization, when particles are generated but not yet propagated.

Parameters
[in]event_numberNumber of the current event.
[in]tqThermodynamic quantity to deal with.
[in]dens_typeDensity type for the reference frame.
[in]latticeSpecialized Lattice for EnergyMomentumTensor
Note
This method takes the event number and not the ensemble number as the lattice is meant to contain an average over ensembles if multiple ensembles are used.

Reimplemented from smash::OutputInterface.

Definition at line 334 of file thermodynamiclatticeoutput.cc.

337  {
338  if (!enable_output_) {
339  return;
340  }
341  const auto dim = lattice.n_cells();
342  const auto cs = lattice.cell_sizes();
343  const auto orig = lattice.origin();
344  for (int l = 0; l < 3; l++) {
345  nodes_[l] = dim[l];
346  sizes_[l] = cs[l];
347  origin_[l] = orig[l];
348  }
349  std::shared_ptr<std::ofstream> fp(nullptr);
350  std::string varname;
351  std::string filename;
352  varname = make_varname(tq, dens_type);
353  if (enable_ascii_) {
354  filename = make_filename(varname, event_number, 'a');
356  try {
358  filename, std::ios::out);
359  } catch (std::ofstream::failure &e) {
360  logg[LogArea::Main::id].fatal()
361  << "Error in opening " << filename << std::endl;
362  throw std::runtime_error(
363  "Not possible to write thermodynamic "
364  "lattice output to file.");
365  }
367  } else if (tq == ThermodynamicQuantity::Tmn) {
368  try {
370  std::ios::out);
371  } catch (std::ofstream::failure &e) {
372  logg[LogArea::Main::id].fatal()
373  << "Error in opening " << filename << std::endl;
374  throw std::runtime_error(
375  "Not possible to write thermodynamic "
376  "lattice output to file.");
377  }
379  } else if (tq == ThermodynamicQuantity::LandauVelocity) {
380  try {
382  filename, std::ios::out);
383  } catch (std::ofstream::failure &e) {
384  logg[LogArea::Main::id].fatal()
385  << "Error in opening " << filename << std::endl;
386  throw std::runtime_error(
387  "Not possible to write thermodynamic "
388  "lattice output to file.");
389  }
391  } else {
392  try {
394  std::ios::out);
395  } catch (std::ofstream::failure &e) {
396  logg[LogArea::Main::id].fatal()
397  << "Error in opening " << filename << std::endl;
398  throw std::runtime_error(
399  "Not possible to write thermodynamic "
400  "lattice output to file.");
401  }
402  }
404  }
405  if (enable_binary_) {
406  filename = make_filename(varname, event_number, 'b');
408  try {
410  filename, std::ios::out | std::ios::binary);
411  } catch (std::ofstream::failure &e) {
412  logg[LogArea::Main::id].fatal()
413  << "Error in opening " << filename << std::endl;
414  throw std::runtime_error(
415  "Not possible to write thermodynamic "
416  "lattice output to file.");
417  }
419  } else if (tq == ThermodynamicQuantity::Tmn) {
420  try {
422  filename, std::ios::out | std::ios::binary);
423  } catch (std::ofstream::failure &e) {
424  logg[LogArea::Main::id].fatal()
425  << "Error in opening " << filename << std::endl;
426  throw std::runtime_error(
427  "Not possible to write thermodynamic "
428  "lattice output to file.");
429  }
431  } else if (tq == ThermodynamicQuantity::LandauVelocity) {
432  try {
434  filename, std::ios::out | std::ios::binary);
435  } catch (std::ofstream::failure &e) {
436  logg[LogArea::Main::id].fatal()
437  << "Error in opening " << filename << std::endl;
438  throw std::runtime_error(
439  "Not possible to write thermodynamic "
440  "lattice output to file.");
441  }
443  } else {
444  try {
446  std::ios::out);
447  } catch (std::ofstream::failure &e) {
448  logg[LogArea::Main::id].fatal()
449  << "Error in opening " << filename << std::endl;
450  throw std::runtime_error(
451  "Not possible to write thermodynamic "
452  "lattice output to file.");
453  }
454  }
456  }
457 }
Here is the call graph for this function:

◆ at_eventend()

void smash::ThermodynamicLatticeOutput::at_eventend ( const ThermodynamicQuantity  tq)
overridevirtual

Final actions at the end of each event (it closes the output files).

Parameters
[in]tqThe quantity that has been written in the output file, see ThermodynamicQuantity.

Reimplemented from smash::OutputInterface.

Definition at line 459 of file thermodynamiclatticeoutput.cc.

459  {
460  if (!enable_output_) {
461  return;
462  }
464  if (enable_ascii_) {
466  }
467  if (enable_binary_) {
469  }
470  return;
471  }
472  if (tq == ThermodynamicQuantity::Tmn) {
473  if (enable_ascii_) {
475  }
476  if (enable_binary_) {
478  }
479  return;
480  }
482  if (enable_ascii_) {
484  }
485  if (enable_binary_) {
487  }
488  return;
489  }
491  if (enable_ascii_) {
493  }
494  if (enable_binary_) {
496  }
497  return;
498  }
499  if (tq == ThermodynamicQuantity::j_QBS) {
500  if (enable_ascii_) {
502  }
503  if (enable_binary_) {
505  }
506  return;
507  }
508 }

◆ thermodynamics_lattice_output() [1/3]

void smash::ThermodynamicLatticeOutput::thermodynamics_lattice_output ( RectangularLattice< DensityOnLattice > &  lattice,
double  current_time 
)
overridevirtual

Prints the density lattice on a grid.

  • Parameters
    [in]latticeDensityOnLattice lattice to use.
    [in]current_timeThe output time in the computational frame

Reimplemented from smash::OutputInterface.

Definition at line 510 of file thermodynamiclatticeoutput.cc.

511  {
512  double result;
513  const auto dim = lattice.n_cells();
514  std::shared_ptr<std::ofstream> fp(nullptr);
515  if (enable_ascii_) {
517  *fp << std::setprecision(14);
518  *fp << std::scientific;
519  *fp << ctime << std::endl;
520  }
521  if (enable_binary_) {
523  assert(sizeof(ctime) == sizeof(double));
524  fp->write(reinterpret_cast<char *>(&ctime), sizeof(ctime));
525  }
526  lattice.iterate_sublattice(
527  {0, 0, 0}, dim, [&](DensityOnLattice &node, int ix, int, int) {
528  if (enable_ascii_) {
529  *fp << node.rho() << " ";
530  if (ix == dim[0] - 1) {
531  *fp << "\n";
532  }
533  }
534  if (enable_binary_) {
535  result = node.rho();
536  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
537  }
538  });
539 }

◆ thermodynamics_lattice_output() [2/3]

void smash::ThermodynamicLatticeOutput::thermodynamics_lattice_output ( RectangularLattice< DensityOnLattice > &  lattice,
const double  current_time,
const std::vector< Particles > &  ensembles,
const DensityParameters dens_param 
)
overridevirtual

Prints the density lattice on a grid.

Parameters
[in]latticeDensityOnLattice lattice to use.
[in]current_timeThe output time in the computational frame
[in]ensemblesParticles, from which the 4-currents j_{Q,B,S} are computed
[in]dens_paramset of parameters, defining smearing. For more info about smearing see ASCII thermodynamics output.

Reimplemented from smash::OutputInterface.

Definition at line 541 of file thermodynamiclatticeoutput.cc.

544  {
545  if (!enable_output_) {
546  return;
547  }
548  double result;
549  const auto dim = lattice.n_cells();
550  std::shared_ptr<std::ofstream> fp(nullptr);
551  FourVector jQ = FourVector(), jB = FourVector(), jS = FourVector();
552  constexpr bool compute_gradient = false;
553  if (enable_ascii_) {
555  *fp << std::setprecision(14);
556  *fp << std::scientific;
557  *fp << ctime << std::endl;
558  }
559  if (enable_binary_) {
561  assert(sizeof(ctime) == sizeof(double));
562  fp->write(reinterpret_cast<char *>(&ctime), sizeof(ctime));
563  }
564  lattice.iterate_sublattice(
565  {0, 0, 0}, dim, [&](DensityOnLattice &, int ix, int iy, int iz) {
566  const ThreeVector position = lattice.cell_center(ix, iy, iz);
567  jQ.reset();
568  jB.reset();
569  jS.reset();
570  for (const Particles &particles : ensembles) {
571  jQ += std::get<1>(current_eckart(
572  position, particles, dens_param, DensityType::Charge,
573  compute_gradient, out_par_.td_smearing));
574  jB += std::get<1>(current_eckart(
575  position, particles, dens_param, DensityType::Baryon,
576  compute_gradient, out_par_.td_smearing));
577  jS += std::get<1>(current_eckart(
578  position, particles, dens_param, DensityType::Strangeness,
579  compute_gradient, out_par_.td_smearing));
580  }
581  if (enable_ascii_) {
582  *fp << jQ[0];
583  for (int l = 1; l < 4; l++) {
584  *fp << " " << jQ[l];
585  }
586  for (int l = 0; l < 4; l++) {
587  *fp << " " << jB[l];
588  }
589  for (int l = 0; l < 4; l++) {
590  *fp << " " << jS[l];
591  }
592  *fp << "\n";
593  }
594  if (enable_binary_) {
595  for (int l = 0; l < 4; l++) {
596  result = jQ[l];
597  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
598  }
599  for (int l = 0; l < 4; l++) {
600  result = jB[l];
601  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
602  }
603  for (int l = 0; l < 4; l++) {
604  result = jS[l];
605  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
606  }
607  }
608  });
609 }
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)
Calculates Eckart rest frame density and 4-current of a given density type and optionally the gradien...
Definition: density.cc:176
bool td_smearing
Whether smearing is on or off; WARNING : if smearing is off, then final result is in GeV instead of G...
Here is the call graph for this function:

◆ thermodynamics_lattice_output() [3/3]

void smash::ThermodynamicLatticeOutput::thermodynamics_lattice_output ( const ThermodynamicQuantity  tq,
RectangularLattice< EnergyMomentumTensor > &  lattice,
double  current_time 
)
overridevirtual

Prints the energy-momentum-tensor lattice on a grid.

Parameters
[in]tqThe quantity whose energy-momentum tensor should be written, see ThermodynamicQuantity.
[in]latticeEnergyMomentumTensor lattice to use.
[in]current_timeThe output time in the computational frame

Reimplemented from smash::OutputInterface.

Definition at line 611 of file thermodynamiclatticeoutput.cc.

613  {
614  if (!enable_output_) {
615  return;
616  }
617  double result;
618  const auto dim = lattice.n_cells();
619  std::shared_ptr<std::ofstream> fp(nullptr);
620  if (enable_ascii_) {
621  switch (tq) {
624  break;
627  break;
630  break;
631  default:
632  return;
633  }
634  *fp << std::setprecision(14);
635  *fp << std::scientific;
636  *fp << ctime << std::endl;
637  }
638  if (enable_binary_) {
639  switch (tq) {
642  break;
645  break;
648  break;
649  default:
650  return;
651  }
652  assert(sizeof(ctime) == sizeof(double));
653  fp->write(reinterpret_cast<char *>(&ctime), sizeof(double));
654  }
655  switch (tq) {
657  for (int i = 0; i < 4; i++) {
658  for (int j = i; j < 4; j++) {
659  lattice.iterate_sublattice(
660  {0, 0, 0}, dim,
661  [&](EnergyMomentumTensor &node, int ix, int, int) {
662  if (enable_ascii_) {
663  *fp << node[EnergyMomentumTensor::tmn_index(i, j)] << " ";
664  if (ix == dim[0] - 1) {
665  *fp << "\n";
666  }
667  }
668  if (enable_binary_) {
669  result = node[EnergyMomentumTensor::tmn_index(i, j)];
670  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
671  }
672  });
673  }
674  }
675  break;
677  for (int i = 0; i < 4; i++) {
678  for (int j = i; j < 4; j++) {
679  lattice.iterate_sublattice(
680  {0, 0, 0}, dim,
681  [&](EnergyMomentumTensor &node, int ix, int, int) {
682  if (enable_ascii_) {
683  const FourVector u = node.landau_frame_4velocity();
684  const EnergyMomentumTensor Tmn_L = node.boosted(u);
685  *fp << Tmn_L[EnergyMomentumTensor::tmn_index(i, j)] << " ";
686  if (ix == dim[0] - 1) {
687  *fp << "\n";
688  }
689  }
690  if (enable_binary_) {
691  const FourVector u = node.landau_frame_4velocity();
692  const EnergyMomentumTensor Tmn_L = node.boosted(u);
693  result = Tmn_L[EnergyMomentumTensor::tmn_index(i, j)];
694  fp->write(reinterpret_cast<char *>(&result), sizeof(double));
695  }
696  });
697  }
698  }
699  break;
701  lattice.iterate_sublattice(
702  {0, 0, 0}, dim, [&](EnergyMomentumTensor &node, int, int, int) {
703  if (enable_ascii_) {
704  const FourVector u = node.landau_frame_4velocity();
705  const ThreeVector v = -u.velocity();
706  *fp << v.x1() << " " << v.x2() << " " << v.x3() << "\n";
707  }
708  if (enable_binary_) {
709  const FourVector u = node.landau_frame_4velocity();
710  ThreeVector v = -u.velocity();
711  fp->write(reinterpret_cast<char *>(&v), 3 * sizeof(double));
712  }
713  });
714  break;
715  default:
716  return;
717  }
718 }
static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu)
Access the index of component .
Here is the call graph for this function:

◆ make_filename()

std::string smash::ThermodynamicLatticeOutput::make_filename ( const std::string &  description,
const int  event_number,
const char  type 
)
private

Makes a file name given a description and a counter.

Parameters
[in]descriptionThe description.
[in]event_numberThe event number.
[in]typeFlag for the file type: 'a' for ASCII, 'b' for Binary

Definition at line 739 of file thermodynamiclatticeoutput.cc.

741  {
742  char suffix[13];
743  assert((type == 'a') || (type == 'b'));
744  if (type == 'a') {
745  snprintf(suffix, sizeof(suffix), "_%07i.dat", event_number);
746  } else {
747  snprintf(suffix, sizeof(suffix), "_%07i.bin", event_number);
748  }
749  return base_path_.string() + std::string("/") + descr + std::string(suffix);
750 }
Here is the caller graph for this function:

◆ make_varname()

std::string smash::ThermodynamicLatticeOutput::make_varname ( const ThermodynamicQuantity  tq,
const DensityType  dens_type 
)
private

Makes a variable name given quantity and density type.

Parameters
[in]tqThe quantity.
[in]dens_typeThe density type.

Definition at line 752 of file thermodynamiclatticeoutput.cc.

753  {
754  return std::string(to_string(dens_type)) + std::string("_") +
755  std::string(to_string(tq));
756 }
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_therm_lattice_ascii_header()

void smash::ThermodynamicLatticeOutput::write_therm_lattice_ascii_header ( std::shared_ptr< std::ofstream >  file,
const ThermodynamicQuantity tq 
)
private

Writes the header for the ASCII output files.

Parameters
fileOutput file.
[in]tqThe quantity to be written, see ThermodynamicQuantity.

Definition at line 758 of file thermodynamiclatticeoutput.cc.

759  {
760  *fp << std::setprecision(2);
761  *fp << std::fixed;
762  *fp << "#Thermodynamic Lattice Output version: "
763  << ThermodynamicLatticeOutput::version << std::endl;
764  *fp << std::setprecision(6);
765  *fp << "#Quantity:"
766  << " " << std::string(to_string(tq)) << std::endl;
767  *fp << "#Grid dimensions: " << nodes_[0] << " " << nodes_[1] << " "
768  << nodes_[2] << std::endl;
769  *fp << "#Grid spacing: " << sizes_[0] << " " << sizes_[1] << " " << sizes_[2]
770  << std::endl;
771  *fp << "#Grid origin: " << origin_[0] << " " << origin_[1] << " "
772  << origin_[2] << std::endl;
773 }
static const double_t version
Version of the thermodynamic lattice output.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_therm_lattice_binary_header()

void smash::ThermodynamicLatticeOutput::write_therm_lattice_binary_header ( std::shared_ptr< std::ofstream >  file,
const ThermodynamicQuantity tq 
)
private

Writes the header for the binary output files.

Parameters
[in]fileOutput file.
[in]tqThe quantity to be written, see ThermodynamicQuantity.

Definition at line 775 of file thermodynamiclatticeoutput.cc.

776  {
777  auto variable_id = to_int(tq);
778  fp->write(
779  reinterpret_cast<const char *>(&ThermodynamicLatticeOutput::version),
780  sizeof(double));
781  fp->write(reinterpret_cast<char *>(&variable_id), sizeof(int));
782  fp->write(reinterpret_cast<char *>(&nodes_), sizeof(nodes_));
783  fp->write(reinterpret_cast<char *>(&sizes_), sizeof(sizes_));
784  fp->write(reinterpret_cast<char *>(&origin_), sizeof(origin_));
785 }
int to_int(const ThermodynamicQuantity &tq)
Convert a ThermodynamicQuantity into an int.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_int()

int smash::ThermodynamicLatticeOutput::to_int ( const ThermodynamicQuantity tq)
private

Convert a ThermodynamicQuantity into an int.

Parameters
[in]tqThe quantity to be converted, see ThermodynamicQuantity.
Returns
An int corresponding to ThermodynamicQuantity.

Definition at line 720 of file thermodynamiclatticeoutput.cc.

720  {
721  switch (tq) {
723  return 0;
725  return 1;
727  return 2;
729  return 3;
731  return 4;
732  default:
733  throw std::runtime_error(
734  "Error when converting a thermodynamic quantity "
735  "to an int, unknown quantity.");
736  }
737 }
Here is the caller graph for this function:

Member Data Documentation

◆ version

const double_t smash::ThermodynamicLatticeOutput::version = 1.0
static

Version of the thermodynamic lattice output.

Definition at line 45 of file thermodynamiclatticeoutput.h.

◆ out_par_

const OutputParameters smash::ThermodynamicLatticeOutput::out_par_
private

Structure that holds all the information about what to printout.

Definition at line 142 of file thermodynamiclatticeoutput.h.

◆ base_path_

const std::filesystem::path smash::ThermodynamicLatticeOutput::base_path_
private

filesystem path for output

Definition at line 191 of file thermodynamiclatticeoutput.h.

◆ output_ascii_files_

std::map<ThermodynamicQuantity, std::shared_ptr<std::ofstream> > smash::ThermodynamicLatticeOutput::output_ascii_files_
private

map of output file handlers for ASCII format

Definition at line 195 of file thermodynamiclatticeoutput.h.

◆ output_binary_files_

std::map<ThermodynamicQuantity, std::shared_ptr<std::ofstream> > smash::ThermodynamicLatticeOutput::output_binary_files_
private

map of output file handlers for binary format

Definition at line 199 of file thermodynamiclatticeoutput.h.

◆ nodes_

std::array<int, 3> smash::ThermodynamicLatticeOutput::nodes_
private

number of nodes in the lattice along the three axes

Definition at line 202 of file thermodynamiclatticeoutput.h.

◆ sizes_

std::array<double, 3> smash::ThermodynamicLatticeOutput::sizes_
private

lattice resolution along the three axes

Definition at line 205 of file thermodynamiclatticeoutput.h.

◆ origin_

std::array<double, 3> smash::ThermodynamicLatticeOutput::origin_
private

lattice origin orientation: if 0,0,0 is the origin of a cube with face widths 10, the center is at 5,5,5

Definition at line 210 of file thermodynamiclatticeoutput.h.

◆ enable_ascii_

bool smash::ThermodynamicLatticeOutput::enable_ascii_
private

enable output type ASCII

Definition at line 213 of file thermodynamiclatticeoutput.h.

◆ enable_binary_

bool smash::ThermodynamicLatticeOutput::enable_binary_
private

enable output type Binary

Definition at line 216 of file thermodynamiclatticeoutput.h.

◆ enable_output_

bool smash::ThermodynamicLatticeOutput::enable_output_
private

enable output, of any kind (if False, the object does nothing)

Definition at line 219 of file thermodynamiclatticeoutput.h.


The documentation for this class was generated from the following files: