Version: SMASH-3.1
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:
smash::OutputInterface

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 int, 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 int, const ThermodynamicQuantity, const DensityType)
 Output launched at event end. More...
 
virtual void at_eventend (const Particles &, const int, 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 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 184 of file thermodynamiclatticeoutput.cc.

188  : OutputInterface(name),
189  out_par_(out_par),
190  base_path_(std::move(path)),
191  enable_ascii_(enable_ascii),
192  enable_binary_(enable_binary) {
193  if (enable_ascii_ || enable_binary_) {
194  enable_output_ = true;
195  } else {
196  enable_output_ = false;
197  }
198  if (enable_ascii_) {
199  if (out_par_.td_rho_eckart) {
201  std::make_shared<std::ofstream>(nullptr);
202  }
203  if (out_par_.td_tmn_landau) {
205  std::make_shared<std::ofstream>(nullptr);
206  }
207  if (out_par_.td_tmn) {
209  std::make_shared<std::ofstream>(nullptr);
210  }
211  if (out_par_.td_v_landau) {
213  std::make_shared<std::ofstream>(nullptr);
214  }
215  if (out_par_.td_jQBS) {
217  std::make_shared<std::ofstream>(nullptr);
218  }
219  }
220  if (enable_binary_) {
221  if (out_par_.td_rho_eckart) {
223  std::make_shared<std::ofstream>(nullptr);
224  }
225  if (out_par_.td_tmn_landau) {
227  std::make_shared<std::ofstream>(nullptr);
228  }
229  if (out_par_.td_tmn) {
231  std::make_shared<std::ofstream>(nullptr);
232  }
233  if (out_par_.td_v_landau) {
235  std::make_shared<std::ofstream>(nullptr);
236  }
237  if (out_par_.td_jQBS) {
239  std::make_shared<std::ofstream>(nullptr);
240  }
241  }
242 }
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 244 of file thermodynamiclatticeoutput.cc.

244 {}

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

Reimplemented from smash::OutputInterface.

Definition at line 246 of file thermodynamiclatticeoutput.cc.

248  {
249  if (!enable_output_) {
250  return;
251  }
252  assert((tq == ThermodynamicQuantity::EckartDensity) ||
254  // at the next refactoring of the code,
255  // this piece should go in the constructor
256  const auto dim = lattice.n_cells();
257  const auto cs = lattice.cell_sizes();
258  const auto orig = lattice.origin();
259  for (int l = 0; l < 3; l++) {
260  nodes_[l] = dim[l];
261  sizes_[l] = cs[l];
262  origin_[l] = orig[l];
263  }
264  std::shared_ptr<std::ofstream> fp(nullptr);
265  std::string varname;
266  std::string filename;
267  varname = make_varname(tq, dens_type);
269  if (enable_ascii_) {
270  filename = make_filename(varname, event_number, 'a');
271  try {
273  filename, std::ios::out);
274  } catch (std::ofstream::failure &e) {
275  logg[LogArea::Main::id].fatal()
276  << "Error in opening " << filename << std::endl;
277  throw std::runtime_error(
278  "Not possible to write thermodynamic "
279  "lattice output to file.");
280  }
283  }
284  if (enable_binary_) {
285  filename = make_filename(varname, event_number, 'b');
286  try {
288  filename, std::ios::out | std::ios::binary);
289  } catch (std::ofstream::failure &e) {
290  logg[LogArea::Main::id].fatal()
291  << "Error in opening " << filename << std::endl;
292  throw std::runtime_error(
293  "Not possible to write thermodynamic "
294  "lattice output to file.");
295  }
298  }
299  } else {
300  if (enable_ascii_) {
301  filename = make_filename(varname, event_number, 'a');
302  try {
304  std::ios::out);
305  } catch (std::ofstream::failure &e) {
306  logg[LogArea::Main::id].fatal()
307  << "Error in opening " << filename << std::endl;
308  throw std::runtime_error(
309  "Not possible to write thermodynamic "
310  "lattice output to file.");
311  }
314  }
315  if (enable_binary_) {
316  filename = make_filename(varname, event_number, 'b');
317  try {
319  filename, std::ios::out | std::ios::binary);
320  } catch (std::ofstream::failure &e) {
321  logg[LogArea::Main::id].fatal()
322  << "Error in opening " << filename << std::endl;
323  throw std::runtime_error(
324  "Not possible to write thermodynamic "
325  "lattice output to file.");
326  }
329  }
330  }
331 }
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.cc:39

◆ 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

Reimplemented from smash::OutputInterface.

Definition at line 333 of file thermodynamiclatticeoutput.cc.

336  {
337  if (!enable_output_) {
338  return;
339  }
340  const auto dim = lattice.n_cells();
341  const auto cs = lattice.cell_sizes();
342  const auto orig = lattice.origin();
343  for (int l = 0; l < 3; l++) {
344  nodes_[l] = dim[l];
345  sizes_[l] = cs[l];
346  origin_[l] = orig[l];
347  }
348  std::shared_ptr<std::ofstream> fp(nullptr);
349  std::string varname;
350  std::string filename;
351  varname = make_varname(tq, dens_type);
352  if (enable_ascii_) {
353  filename = make_filename(varname, event_number, 'a');
355  try {
357  filename, std::ios::out);
358  } catch (std::ofstream::failure &e) {
359  logg[LogArea::Main::id].fatal()
360  << "Error in opening " << filename << std::endl;
361  throw std::runtime_error(
362  "Not possible to write thermodynamic "
363  "lattice output to file.");
364  }
366  } else if (tq == ThermodynamicQuantity::Tmn) {
367  try {
369  std::ios::out);
370  } catch (std::ofstream::failure &e) {
371  logg[LogArea::Main::id].fatal()
372  << "Error in opening " << filename << std::endl;
373  throw std::runtime_error(
374  "Not possible to write thermodynamic "
375  "lattice output to file.");
376  }
378  } else if (tq == ThermodynamicQuantity::LandauVelocity) {
379  try {
381  filename, std::ios::out);
382  } catch (std::ofstream::failure &e) {
383  logg[LogArea::Main::id].fatal()
384  << "Error in opening " << filename << std::endl;
385  throw std::runtime_error(
386  "Not possible to write thermodynamic "
387  "lattice output to file.");
388  }
390  } else {
391  try {
393  std::ios::out);
394  } catch (std::ofstream::failure &e) {
395  logg[LogArea::Main::id].fatal()
396  << "Error in opening " << filename << std::endl;
397  throw std::runtime_error(
398  "Not possible to write thermodynamic "
399  "lattice output to file.");
400  }
401  }
403  }
404  if (enable_binary_) {
405  filename = make_filename(varname, event_number, 'b');
407  try {
409  filename, std::ios::out | std::ios::binary);
410  } catch (std::ofstream::failure &e) {
411  logg[LogArea::Main::id].fatal()
412  << "Error in opening " << filename << std::endl;
413  throw std::runtime_error(
414  "Not possible to write thermodynamic "
415  "lattice output to file.");
416  }
418  } else if (tq == ThermodynamicQuantity::Tmn) {
419  try {
421  filename, std::ios::out | std::ios::binary);
422  } catch (std::ofstream::failure &e) {
423  logg[LogArea::Main::id].fatal()
424  << "Error in opening " << filename << std::endl;
425  throw std::runtime_error(
426  "Not possible to write thermodynamic "
427  "lattice output to file.");
428  }
430  } else if (tq == ThermodynamicQuantity::LandauVelocity) {
431  try {
433  filename, std::ios::out | std::ios::binary);
434  } catch (std::ofstream::failure &e) {
435  logg[LogArea::Main::id].fatal()
436  << "Error in opening " << filename << std::endl;
437  throw std::runtime_error(
438  "Not possible to write thermodynamic "
439  "lattice output to file.");
440  }
442  } else {
443  try {
445  std::ios::out);
446  } catch (std::ofstream::failure &e) {
447  logg[LogArea::Main::id].fatal()
448  << "Error in opening " << filename << std::endl;
449  throw std::runtime_error(
450  "Not possible to write thermodynamic "
451  "lattice output to file.");
452  }
453  }
455  }
456 }

◆ 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 458 of file thermodynamiclatticeoutput.cc.

458  {
459  if (!enable_output_) {
460  return;
461  }
463  if (enable_ascii_) {
465  }
466  if (enable_binary_) {
468  }
469  return;
470  }
471  if (tq == ThermodynamicQuantity::Tmn) {
472  if (enable_ascii_) {
474  }
475  if (enable_binary_) {
477  }
478  return;
479  }
481  if (enable_ascii_) {
483  }
484  if (enable_binary_) {
486  }
487  return;
488  }
490  if (enable_ascii_) {
492  }
493  if (enable_binary_) {
495  }
496  return;
497  }
498  if (tq == ThermodynamicQuantity::j_QBS) {
499  if (enable_ascii_) {
501  }
502  if (enable_binary_) {
504  }
505  return;
506  }
507 }

◆ 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 509 of file thermodynamiclatticeoutput.cc.

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

◆ 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 540 of file thermodynamiclatticeoutput.cc.

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

◆ 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 610 of file thermodynamiclatticeoutput.cc.

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

◆ 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 738 of file thermodynamiclatticeoutput.cc.

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

◆ 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 751 of file thermodynamiclatticeoutput.cc.

752  {
753  return std::string(to_string(dens_type)) + std::string("_") +
754  std::string(to_string(tq));
755 }
const char * to_string(const ThermodynamicQuantity tq)
Convert thermodynamic quantities to strings.

◆ 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 757 of file thermodynamiclatticeoutput.cc.

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

◆ 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 774 of file thermodynamiclatticeoutput.cc.

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

◆ 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 719 of file thermodynamiclatticeoutput.cc.

719  {
720  switch (tq) {
722  return 0;
724  return 1;
726  return 2;
728  return 3;
730  return 4;
731  default:
732  throw std::runtime_error(
733  "Error when converting a thermodynamic quantity "
734  "to an int, unknown quantity.");
735  }
736 }

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 134 of file thermodynamiclatticeoutput.h.

◆ base_path_

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

filesystem path for output

Definition at line 183 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 187 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 191 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 194 of file thermodynamiclatticeoutput.h.

◆ sizes_

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

lattice resolution along the three axes

Definition at line 197 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 202 of file thermodynamiclatticeoutput.h.

◆ enable_ascii_

bool smash::ThermodynamicLatticeOutput::enable_ascii_
private

enable output type ASCII

Definition at line 205 of file thermodynamiclatticeoutput.h.

◆ enable_binary_

bool smash::ThermodynamicLatticeOutput::enable_binary_
private

enable output type Binary

Definition at line 208 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 211 of file thermodynamiclatticeoutput.h.


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