Version: SMASH-1.8
experiment.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/experiment.h"
11 
12 #include <cstdint>
13 
14 #include "smash/actions.h"
15 #include "smash/boxmodus.h"
16 #include "smash/collidermodus.h"
17 #include "smash/cxx14compat.h"
18 #include "smash/fourvector.h"
19 #include "smash/listmodus.h"
20 #include "smash/spheremodus.h"
21 
22 namespace smash {
23 
24 /* ExperimentBase carries everything that is needed for the evolution */
25 ExperimentPtr ExperimentBase::create(Configuration config,
26  const bf::path &output_path) {
27  logg[LExperiment].trace() << source_location;
49  const std::string modus_chooser = config.read({"General", "Modus"});
50  logg[LExperiment].debug() << "Modus for this calculation: " << modus_chooser;
51 
52  if (modus_chooser == "Box") {
53  return make_unique<Experiment<BoxModus>>(config, output_path);
54  } else if (modus_chooser == "List") {
55  return make_unique<Experiment<ListModus>>(config, output_path);
56  } else if (modus_chooser == "Collider") {
57  return make_unique<Experiment<ColliderModus>>(config, output_path);
58  } else if (modus_chooser == "Sphere") {
59  return make_unique<Experiment<SphereModus>>(config, output_path);
60  } else {
61  throw InvalidModusRequest("Invalid Modus (" + modus_chooser +
62  ") requested from ExperimentBase::create.");
63  }
64 }
65 
329  logg[LExperiment].trace() << source_location;
330 
331  const int ntest = config.take({"General", "Testparticles"}, 1);
332  if (ntest <= 0) {
333  throw std::invalid_argument("Testparticle number should be positive!");
334  }
335 
336  const std::string modus_chooser = config.take({"General", "Modus"});
337  // remove config maps of unused Modi
338  config["Modi"].remove_all_but(modus_chooser);
339 
340  /* If this Delta_Time option is absent (this can be for timestepless mode)
341  * just assign 1.0 fm/c, reasonable value will be set at event initialization
342  */
343  const double dt = config.take({"General", "Delta_Time"}, 1.);
344  const double t_end = config.read({"General", "End_Time"});
345 
346  // define output clock
347  std::unique_ptr<Clock> output_clock = nullptr;
348  if (config.has_value({"Output", "Output_Times"})) {
349  if (config.has_value({"Output", "Output_Interval"})) {
350  throw std::invalid_argument(
351  "Please specify either Output_Interval or Output_Times");
352  }
353  std::vector<double> output_times = config.take({"Output", "Output_Times"});
354  // Add an output time larger than the end time so that the next time is
355  // always defined during the time evolution
356  output_times.push_back(t_end + 1.);
357  output_clock = make_unique<CustomClock>(output_times);
358  } else {
359  const double output_dt = config.take({"Output", "Output_Interval"}, t_end);
360  output_clock = make_unique<UniformClock>(0.0, output_dt);
361  }
362 
363  // Add proper error messages if photons are not configured properly.
364  // 1) Missing Photon config section.
365  if (config["Output"].has_value({"Photons"}) &&
366  (!config.has_value({"Collision_Term", "Photons"}))) {
367  throw std::invalid_argument(
368  "Photon output is enabled although photon production is disabled. "
369  "Photon production can be configured in the \"Photon\" subsection "
370  "of the \"Collision_Term\".");
371  }
372 
373  // 2) Missing Photon output section.
374  bool missing_output_2to2 = false;
375  bool missing_output_brems = false;
376  if (!(config["Output"].has_value({"Photons"}))) {
377  if (config.has_value({"Collision_Term", "Photons", "2to2_Scatterings"})) {
378  missing_output_2to2 =
379  config.read({"Collision_Term", "Photons", "2to2_Scatterings"});
380  }
381  if (config.has_value({"Collision_Term", "Photons", "Bremsstrahlung"})) {
382  missing_output_brems =
383  config.read({"Collision_Term", "Photons", "Bremsstrahlung"});
384  }
385 
386  if (missing_output_2to2 || missing_output_brems) {
387  throw std::invalid_argument(
388  "Photon output is disabled although photon production is enabled. "
389  "Please enable the photon output.");
390  }
391  }
392 
393  // Add proper error messages if dileptons are not configured properly.
394  // 1) Missing Dilepton config section.
395  if (config["Output"].has_value({"Dileptons"}) &&
396  (!config.has_value({"Collision_Term", "Dileptons"}))) {
397  throw std::invalid_argument(
398  "Dilepton output is enabled although dilepton production is disabled. "
399  "Dilepton production can be configured in the \"Dileptons\" subsection "
400  "of the \"Collision_Term\".");
401  }
402 
403  // 2) Missing Dilepton output section.
404  bool missing_output_decays = false;
405  if (!(config["Output"].has_value({"Dileptons"}))) {
406  if (config.has_value({"Collision_Term", "Dileptons", "Decays"})) {
407  missing_output_decays =
408  config.read({"Collision_Term", "Dileptons", "Decays"});
409  }
410 
411  if (missing_output_decays) {
412  throw std::invalid_argument(
413  "Dilepton output is disabled although dilepton production is "
414  "enabled. "
415  "Please enable the dilepton output.");
416  }
417  }
418 
419  auto config_coll = config["Collision_Term"];
420  /* Elastic collisions between the nucleons with the square root s
421  * below low_snn_cut are excluded. */
422  const double low_snn_cut =
423  config_coll.take({"Elastic_NN_Cutoff_Sqrts"}, 1.98);
424  const auto proton = ParticleType::try_find(pdg::p);
425  const auto pion = ParticleType::try_find(pdg::pi_z);
426  if (proton && pion &&
427  low_snn_cut > proton->mass() + proton->mass() + pion->mass()) {
428  logg[LExperiment].warn("The cut-off should be below the threshold energy",
429  " of the process: NN to NNpi");
430  }
431  const bool potential_affect_threshold =
432  config.take({"Lattice", "Potentials_Affect_Thresholds"}, false);
433  return {make_unique<UniformClock>(0.0, dt),
434  std::move(output_clock),
435  ntest,
436  config.take({"General", "Gaussian_Sigma"}, 1.),
437  config.take({"General", "Gauss_Cutoff_In_Sigma"}, 4.),
438  config_coll.take({"Two_to_One"}, true),
439  config_coll.take({"Included_2to2"}, ReactionsBitSet().set()),
440  config_coll.take({"Strings"}, modus_chooser != "Box"),
441  config_coll.take({"Use_AQM"}, true),
442  config_coll.take({"Resonance_Lifetime_Modifier"}, 1.),
443  config_coll.take({"Strings_with_Probability"}, true),
444  config_coll.take({"NNbar_Treatment"}, NNbarTreatment::Strings),
445  low_snn_cut,
446  potential_affect_threshold};
447 }
448 
449 std::string format_measurements(const Particles &particles,
450  uint64_t scatterings_this_interval,
451  const QuantumNumbers &conserved_initial,
452  SystemTimePoint time_start, double time,
453  double E_mean_field,
454  double E_mean_field_initial) {
455  const SystemTimeSpan elapsed_seconds = SystemClock::now() - time_start;
456 
457  const QuantumNumbers current_values(particles);
458  const QuantumNumbers difference = current_values - conserved_initial;
459 
460  // Make sure there are no FPEs in case of IC output, were there will
461  // eventually be no more particles in the system
462  const double current_energy =
463  (particles.size() > 0) ? current_values.momentum().x0() : 0.0;
464  const double energy_per_part =
465  (particles.size() > 0)
466  ? (current_energy + E_mean_field - E_mean_field_initial) /
467  particles.size()
468  : 0.0;
469 
470  std::ostringstream ss;
471  // clang-format off
472  ss << field<7, 3> << time
473  // total kinetic energy in the system
474  << field<11, 3> << current_energy
475  // total mean field energy in the system
476  << field<11, 3> << E_mean_field
477  // total energy in the system
478  << field<12, 3> << current_energy + E_mean_field
479  // total energy per particle in the system
480  << field<12, 6> << energy_per_part;
481  // change in total energy per particle (unless IC output is enabled)
482  if (particles.size() == 0) {
483  ss << field<13, 6> << "N/A";
484  } else {
485  ss << field<13, 6> << (difference.momentum().x0()
486  + E_mean_field - E_mean_field_initial)
487  / particles.size();
488  }
489  ss << field<14, 3> << scatterings_this_interval
490  << field<10, 3> << particles.size()
491  << field<9, 3> << elapsed_seconds;
492  // clang-format on
493  return ss.str();
494 }
495 
497  const Potentials &potentials,
499  const ExperimentParameters &parameters) {
500  // basic parameters and variables
501  const double V_cell = (jmu_B_lat.cell_sizes())[0] *
502  (jmu_B_lat.cell_sizes())[1] *
503  (jmu_B_lat.cell_sizes())[2];
504 
505  double E_mean_field = 0.0;
506  double density_mean = 0.0;
507  double density_variance = 0.0;
508 
509  /*
510  * We anticipate having other options, like the vector DFT potentials, in the
511  * future, hence we include checking which potentials are used.
512  */
513  if (potentials.use_skyrme()) {
514  /*
515  * Calculating the symmetry energy contribution to the total mean field
516  * energy in the system is not implemented at this time.
517  */
518  if (potentials.use_symmetry() &&
519  parameters.outputclock->current_time() == 0.0) {
520  logg[LExperiment].warn()
521  << "Note:"
522  << "\nSymmetry energy is not included in the mean field calculation."
523  << "\n\n";
524  }
525 
526  /*
527  * Skyrme potential parameters:
528  * C1GeV are the Skyrme coefficients converted to GeV,
529  * b1 are the powers of the baryon number density entering the expression
530  * for the energy density of the system. Note that these exponents are
531  * larger by 1 than those for the energy of a particle (which are used in
532  * Potentials class). The formula for a total mean field energy due to a
533  * Skyrme potential is E_MF = \sum_i (C_i/b_i) ( n_B^b_i )/( n_0^(b_i - 1) )
534  * where nB is the local rest frame baryon number density and n_0 is the
535  * saturation density. Then the single particle potential follows from
536  * V = d E_MF / d n_B .
537  */
538  double C1GeV = (potentials.skyrme_a()) / 1000.0;
539  double C2GeV = (potentials.skyrme_b()) / 1000.0;
540  double b1 = 2.0;
541  double b2 = (potentials.skyrme_tau()) + 1.0;
542 
543  /*
544  * Note: calculating the mean field only works if lattice is used.
545  * We iterate over the nodes of the baryon density lattice to sum their
546  * contributions to the total mean field.
547  */
548  int number_of_nodes = 0;
549  double lattice_mean_field_total = 0.0;
550 
551  for (auto &node : jmu_B_lat) {
552  number_of_nodes++;
553  // the rest frame density
554  double nB = node.density();
555  // the computational frame density
556  const double j0 = node.jmu_net().x0();
557 
558  density_mean += j0;
559  density_variance += j0 * j0;
560 
561  /*
562  * The mean-field energy for the Skyrme potential. Note: this expression
563  * is only exact in the rest frame, and is expected to significantly
564  * deviate from the correct value for systems that are considerably
565  * relativistic. Note: symmetry energy is not taken into the account.
566  *
567  * TODO: Add symmetry energy.
568  */
569  double mean_field_contribution_1 =
570  (C1GeV / b1) * std::pow(nB, b1) / std::pow(nuclear_density, b1 - 1);
571  double mean_field_contribution_2 =
572  (C2GeV / b2) * std::pow(nB, b2) / std::pow(nuclear_density, b2 - 1);
573 
574  lattice_mean_field_total +=
575  V_cell * (mean_field_contribution_1 + mean_field_contribution_2);
576  }
577 
578  // logging statistical properties of the density calculation
579  density_mean = density_mean / number_of_nodes;
580  density_variance = density_variance / number_of_nodes;
581  double density_scaled_variance =
582  sqrt(density_variance - density_mean * density_mean) / density_mean;
583  logg[LExperiment].debug() << "\t\t\t\t\t";
584  logg[LExperiment].debug()
585  << "\n\t\t\t\t\t density mean = " << density_mean;
586  logg[LExperiment].debug()
587  << "\n\t\t\t\t\t density scaled variance = " << density_scaled_variance;
588  logg[LExperiment].debug()
589  << "\n\t\t\t\t\t total mean_field = "
590  << lattice_mean_field_total * parameters.testparticles << "\n";
591 
592  /*
593  * E_mean_field is multiplied by the number of testparticles because the
594  * total kinetic energy tracked is that of all particles, including
595  * testparticles, and so this is more consistent with the general paradigm.
596  */
597  E_mean_field = lattice_mean_field_total * parameters.testparticles;
598  }
599 
600  return E_mean_field;
601 }
602 
603 } // namespace smash
smash
Definition: action.h:24
smash::SystemTimePoint
std::chrono::time_point< std::chrono::system_clock > SystemTimePoint
Type (alias) that is used to store the current time.
Definition: chrono.h:22
smash::QuantumNumbers::momentum
FourVector momentum() const
Definition: quantumnumbers.h:131
smash::Potentials::skyrme_tau
double skyrme_tau() const
Definition: potentials.h:199
smash::Particles::size
size_t size() const
Definition: particles.h:87
smash::LExperiment
static constexpr int LExperiment
Definition: outputparameters.h:19
smash::Configuration::read
Value read(std::initializer_list< const char * > keys) const
Additional interface for SMASH to read configuration values without removing them.
Definition: configuration.cc:158
cxx14compat.h
NNbarTreatment::Strings
Use string fragmentation.
smash::format_measurements
std::string format_measurements(const Particles &particles, uint64_t scatterings_this_interval, const QuantumNumbers &conserved_initial, SystemTimePoint time_start, double time, double E_mean_field, double E_mean_field_initial)
Generate the tabulated string which will be printed to the screen when SMASH is running.
Definition: experiment.cc:449
smash::nuclear_density
constexpr double nuclear_density
Ground state density of symmetric nuclear matter [fm^-3].
Definition: constants.h:45
smash::Configuration::has_value
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
Definition: configuration.cc:181
smash::Potentials::use_symmetry
virtual bool use_symmetry() const
Definition: potentials.h:192
smash::Potentials::skyrme_b
double skyrme_b() const
Definition: potentials.h:197
smash::Potentials::use_skyrme
virtual bool use_skyrme() const
Definition: potentials.h:190
fourvector.h
smash::SystemTimeSpan
SystemClock::duration SystemTimeSpan
The time duration type (alias) used for measuring run times.
Definition: chrono.h:28
ReactionsBitSet
std::bitset< 10 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
Definition: forwarddeclarations.h:226
smash::pdg::pi_z
constexpr int pi_z
π⁰.
Definition: pdgcode_constants.h:64
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::Configuration
Interface to the SMASH configuration files.
Definition: configuration.h:464
source_location
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs.
Definition: logging.h:240
boxmodus.h
experiment.h
spheremodus.h
actions.h
smash::FourVector::x0
double x0() const
Definition: fourvector.h:303
smash::create_experiment_parameters
ExperimentParameters create_experiment_parameters(Configuration config)
Gathers all general Experiment parameters.
Definition: experiment.cc:328
smash::RectangularLattice
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:47
smash::Potentials
A class that stores parameters of potentials, calculates potentials and their gradients.
Definition: potentials.h:31
collidermodus.h
smash::ParticleType::try_find
static const ParticleTypePtr try_find(PdgCode pdgcode)
Returns the ParticleTypePtr for the given pdgcode.
Definition: particletype.cc:95
smash::Potentials::skyrme_a
double skyrme_a() const
Definition: potentials.h:195
smash::Particles
Definition: particles.h:33
smash::RectangularLattice::cell_sizes
const std::array< double, 3 > & cell_sizes() const
Definition: lattice.h:148
smash::ExperimentParameters::outputclock
std::unique_ptr< Clock > outputclock
Output clock to keep track of the next output time.
Definition: experimentparameters.h:28
smash::calculate_mean_field_energy
double calculate_mean_field_energy(const Potentials &potentials, RectangularLattice< smash::DensityOnLattice > &jmu_B_lat, const ExperimentParameters &parameters)
Calculate the total mean field energy of the system; this will be printed to the screen when SMASH is...
Definition: experiment.cc:496
smash::Configuration::take
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Definition: configuration.cc:140
listmodus.h
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:23
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::Configuration::remove_all_but
void remove_all_but(const std::string &key)
Removes all entries in the map except for key.
Definition: configuration.cc:163
smash::ExperimentParameters::testparticles
int testparticles
Number of test particle.
Definition: experimentparameters.h:31
smash::ExperimentBase::create
static std::unique_ptr< ExperimentBase > create(Configuration config, const bf::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
smash::QuantumNumbers
Definition: quantumnumbers.h:53