Version: SMASH-2.0.2
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/boxmodus.h"
15 #include "smash/collidermodus.h"
16 #include "smash/cxx14compat.h"
17 #include "smash/listmodus.h"
18 #include "smash/spheremodus.h"
19 
20 namespace smash {
21 
22 /* ExperimentBase carries everything that is needed for the evolution */
23 ExperimentPtr ExperimentBase::create(Configuration config,
24  const bf::path &output_path) {
47  const std::string modus_chooser = config.read({"General", "Modus"});
48  logg[LExperiment].debug() << "Modus for this calculation: " << modus_chooser;
49 
50  if (modus_chooser == "Box") {
51  return make_unique<Experiment<BoxModus>>(config, output_path);
52  } else if (modus_chooser == "List") {
53  return make_unique<Experiment<ListModus>>(config, output_path);
54  } else if (modus_chooser == "Collider") {
55  return make_unique<Experiment<ColliderModus>>(config, output_path);
56  } else if (modus_chooser == "Sphere") {
57  return make_unique<Experiment<SphereModus>>(config, output_path);
58  } else {
59  throw InvalidModusRequest("Invalid Modus (" + modus_chooser +
60  ") requested from ExperimentBase::create.");
61  }
62 }
63 
340 
341  const int ntest = config.take({"General", "Testparticles"}, 1);
342  if (ntest <= 0) {
343  throw std::invalid_argument("Testparticle number should be positive!");
344  }
345 
346  const std::string modus_chooser = config.take({"General", "Modus"});
347  // remove config maps of unused Modi
348  config["Modi"].remove_all_but(modus_chooser);
349 
350  double box_length = -1.0;
351  if (config.has_value({"Modi", "Box", "Length"})) {
352  box_length = config.read({"Modi", "Box", "Length"});
353  }
354 
355  /* If this Delta_Time option is absent (this can be for timestepless mode)
356  * just assign 1.0 fm/c, reasonable value will be set at event initialization
357  */
358  const double dt = config.take({"General", "Delta_Time"}, 1.);
359  const double t_end = config.read({"General", "End_Time"});
360 
361  // Enforce a small time step, if the box modus is used
362  if (box_length > 0.0 && dt > box_length / 10.0) {
363  throw std::invalid_argument(
364  "Please decrease the timestep size. "
365  "A value of (dt < l_box / 10) is recommended in the boxmodus.");
366  }
367 
368  // define output clock
369  std::unique_ptr<Clock> output_clock = nullptr;
370  if (config.has_value({"Output", "Output_Times"})) {
371  if (config.has_value({"Output", "Output_Interval"})) {
372  throw std::invalid_argument(
373  "Please specify either Output_Interval or Output_Times");
374  }
375  std::vector<double> output_times = config.take({"Output", "Output_Times"});
376  // Add an output time larger than the end time so that the next time is
377  // always defined during the time evolution
378  output_times.push_back(t_end + 1.);
379  output_clock = make_unique<CustomClock>(output_times);
380  } else {
381  const double output_dt = config.take({"Output", "Output_Interval"}, t_end);
382  output_clock = make_unique<UniformClock>(0.0, output_dt);
383  }
384 
385  // Add proper error messages if photons are not configured properly.
386  // 1) Missing Photon config section.
387  if (config["Output"].has_value({"Photons"}) &&
388  (!config.has_value({"Collision_Term", "Photons"}))) {
389  throw std::invalid_argument(
390  "Photon output is enabled although photon production is disabled. "
391  "Photon production can be configured in the \"Photon\" subsection "
392  "of the \"Collision_Term\".");
393  }
394 
395  // 2) Missing Photon output section.
396  bool missing_output_2to2 = false;
397  bool missing_output_brems = false;
398  if (!(config["Output"].has_value({"Photons"}))) {
399  if (config.has_value({"Collision_Term", "Photons", "2to2_Scatterings"})) {
400  missing_output_2to2 =
401  config.read({"Collision_Term", "Photons", "2to2_Scatterings"});
402  }
403  if (config.has_value({"Collision_Term", "Photons", "Bremsstrahlung"})) {
404  missing_output_brems =
405  config.read({"Collision_Term", "Photons", "Bremsstrahlung"});
406  }
407 
408  if (missing_output_2to2 || missing_output_brems) {
409  throw std::invalid_argument(
410  "Photon output is disabled although photon production is enabled. "
411  "Please enable the photon output.");
412  }
413  }
414 
415  // Add proper error messages if dileptons are not configured properly.
416  // 1) Missing Dilepton config section.
417  if (config["Output"].has_value({"Dileptons"}) &&
418  (!config.has_value({"Collision_Term", "Dileptons"}))) {
419  throw std::invalid_argument(
420  "Dilepton output is enabled although dilepton production is disabled. "
421  "Dilepton production can be configured in the \"Dileptons\" subsection "
422  "of the \"Collision_Term\".");
423  }
424 
425  // 2) Missing Dilepton output section.
426  bool missing_output_decays = false;
427  if (!(config["Output"].has_value({"Dileptons"}))) {
428  if (config.has_value({"Collision_Term", "Dileptons", "Decays"})) {
429  missing_output_decays =
430  config.read({"Collision_Term", "Dileptons", "Decays"});
431  }
432 
433  if (missing_output_decays) {
434  throw std::invalid_argument(
435  "Dilepton output is disabled although dilepton production is "
436  "enabled. "
437  "Please enable the dilepton output.");
438  }
439  }
440 
441  auto config_coll = config["Collision_Term"];
442  /* Elastic collisions between the nucleons with the square root s
443  * below low_snn_cut are excluded. */
444  const double low_snn_cut =
445  config_coll.take({"Elastic_NN_Cutoff_Sqrts"}, 1.98);
446  const auto proton = ParticleType::try_find(pdg::p);
447  const auto pion = ParticleType::try_find(pdg::pi_z);
448  if (proton && pion &&
449  low_snn_cut > proton->mass() + proton->mass() + pion->mass()) {
450  logg[LExperiment].warn("The cut-off should be below the threshold energy",
451  " of the process: NN to NNpi");
452  }
453  const bool potential_affect_threshold =
454  config.take({"Lattice", "Potentials_Affect_Thresholds"}, false);
455  const double scale_xs = config_coll.take({"Cross_Section_Scaling"}, 1.0);
464  const double maximum_cross_section_default =
465  ParticleType::exists("d'") ? 2000.0 : 200.0;
466  double maximum_cross_section = config_coll.take(
467  {"Maximum_Cross_Section"}, maximum_cross_section_default);
468  maximum_cross_section *= scale_xs;
469  return {
470  make_unique<UniformClock>(0.0, dt),
471  std::move(output_clock),
472  ntest,
473  config.take({"General", "Gaussian_Sigma"}, 1.),
474  config.take({"General", "Gauss_Cutoff_In_Sigma"}, 4.),
475  config_coll.take({"Collision_Criterion"}, CollisionCriterion::Covariant),
476  config_coll.take({"Two_to_One"}, true),
477  config_coll.take({"Included_2to2"}, ReactionsBitSet().set()),
478  config_coll.take({"Multi_Particle_Reactions"},
479  MultiParticleReactionsBitSet().reset()),
480  config_coll.take({"Strings"}, modus_chooser != "Box"),
481  config_coll.take({"Use_AQM"}, true),
482  config_coll.take({"Resonance_Lifetime_Modifier"}, 1.),
483  config_coll.take({"Strings_with_Probability"}, true),
484  config_coll.take({"NNbar_Treatment"}, NNbarTreatment::Strings),
485  low_snn_cut,
486  potential_affect_threshold,
487  box_length,
488  maximum_cross_section,
489  scale_xs,
490  config_coll.take({"Additional_Elastic_Cross_Section"}, 0.0)};
491 }
492 
493 std::string format_measurements(const Particles &particles,
494  uint64_t scatterings_this_interval,
495  const QuantumNumbers &conserved_initial,
496  SystemTimePoint time_start, double time,
497  double E_mean_field,
498  double E_mean_field_initial) {
499  const SystemTimeSpan elapsed_seconds = SystemClock::now() - time_start;
500 
501  const QuantumNumbers current_values(particles);
502  const QuantumNumbers difference = current_values - conserved_initial;
503 
504  // Make sure there are no FPEs in case of IC output, were there will
505  // eventually be no more particles in the system
506  const double current_energy =
507  (particles.size() > 0) ? current_values.momentum().x0() : 0.0;
508  const double energy_per_part =
509  (particles.size() > 0)
510  ? (current_energy + E_mean_field) / particles.size()
511  : 0.0;
512 
513  std::ostringstream ss;
514  // clang-format off
515  ss << field<7, 3> << time
516  // total kinetic energy in the system
517  << field<11, 3> << current_energy
518  // total mean field energy in the system
519  << field<11, 3> << E_mean_field
520  // total energy in the system
521  << field<12, 3> << current_energy + E_mean_field
522  // total energy per particle in the system
523  << field<12, 6> << energy_per_part;
524  // change in total energy per particle (unless IC output is enabled)
525  if (particles.size() == 0) {
526  ss << field<13, 6> << "N/A";
527  } else {
528  ss << field<13, 6> << (difference.momentum().x0()
529  + E_mean_field - E_mean_field_initial)
530  / particles.size();
531  }
532  ss << field<14, 3> << scatterings_this_interval
533  << field<10, 3> << particles.size()
534  << field<9, 3> << elapsed_seconds;
535  // clang-format on
536  return ss.str();
537 }
538 
540  const Potentials &potentials,
542  const ExperimentParameters &parameters) {
543  // basic parameters and variables
544  const double V_cell = (jmu_B_lat.cell_sizes())[0] *
545  (jmu_B_lat.cell_sizes())[1] *
546  (jmu_B_lat.cell_sizes())[2];
547 
548  double E_mean_field = 0.0;
549  double density_mean = 0.0;
550  double density_variance = 0.0;
551 
552  /*
553  * We anticipate having other options, like the vector DFT potentials, in the
554  * future, hence we include checking which potentials are used.
555  */
556  if (potentials.use_skyrme()) {
557  /*
558  * Calculating the symmetry energy contribution to the total mean field
559  * energy in the system is not implemented at this time.
560  */
561  if (potentials.use_symmetry() &&
562  parameters.outputclock->current_time() == 0.0) {
563  logg[LExperiment].warn()
564  << "Note:"
565  << "\nSymmetry energy is not included in the mean field calculation."
566  << "\n\n";
567  }
568 
569  /*
570  * Skyrme potential parameters:
571  * C1GeV are the Skyrme coefficients converted to GeV,
572  * b1 are the powers of the baryon number density entering the expression
573  * for the energy density of the system. Note that these exponents are
574  * larger by 1 than those for the energy of a particle (which are used in
575  * Potentials class). The formula for a total mean field energy due to a
576  * Skyrme potential is E_MF = \sum_i (C_i/b_i) ( n_B^b_i )/( n_0^(b_i - 1) )
577  * where nB is the local rest frame baryon number density and n_0 is the
578  * saturation density. Then the single particle potential follows from
579  * V = d E_MF / d n_B .
580  */
581  double C1GeV = (potentials.skyrme_a()) / 1000.0;
582  double C2GeV = (potentials.skyrme_b()) / 1000.0;
583  double b1 = 2.0;
584  double b2 = (potentials.skyrme_tau()) + 1.0;
585 
586  /*
587  * Note: calculating the mean field only works if lattice is used.
588  * We iterate over the nodes of the baryon density lattice to sum their
589  * contributions to the total mean field.
590  */
591  int number_of_nodes = 0;
592  double lattice_mean_field_total = 0.0;
593 
594  for (auto &node : jmu_B_lat) {
595  number_of_nodes++;
596  // the rest frame density
597  double nB = node.density();
598  // the computational frame density
599  const double j0 = node.jmu_net().x0();
600 
601  const double abs_nB = std::abs(nB);
602  if ((abs_nB < really_small) || (std::abs(j0) < really_small)) {
603  continue;
604  }
605  density_mean += j0;
606  density_variance += j0 * j0;
607 
608  /*
609  * The mean-field energy for the Skyrme potential. Note: this expression
610  * is only exact in the rest frame, and is expected to significantly
611  * deviate from the correct value for systems that are considerably
612  * relativistic. Note: symmetry energy is not taken into the account.
613  *
614  * TODO: Add symmetry energy.
615  */
616  double mean_field_contribution_1 = (C1GeV / b1) * std::pow(abs_nB, b1) /
617  std::pow(nuclear_density, b1 - 1);
618  double mean_field_contribution_2 = (C2GeV / b2) * std::pow(abs_nB, b2) /
619  std::pow(nuclear_density, b2 - 1);
620 
621  lattice_mean_field_total +=
622  V_cell * (mean_field_contribution_1 + mean_field_contribution_2);
623  }
624 
625  // logging statistical properties of the density calculation
626  density_mean = density_mean / number_of_nodes;
627  density_variance = density_variance / number_of_nodes;
628  double density_scaled_variance =
629  std::sqrt(density_variance - density_mean * density_mean) /
630  density_mean;
631  logg[LExperiment].debug() << "\t\t\t\t\t";
632  logg[LExperiment].debug()
633  << "\n\t\t\t\t\t density mean = " << density_mean;
634  logg[LExperiment].debug()
635  << "\n\t\t\t\t\t density scaled variance = " << density_scaled_variance;
636  logg[LExperiment].debug()
637  << "\n\t\t\t\t\t total mean_field = "
638  << lattice_mean_field_total * parameters.testparticles << "\n";
639 
640  /*
641  * E_mean_field is multiplied by the number of testparticles because the
642  * total kinetic energy tracked is that of all particles, including
643  * testparticles, and so this is more consistent with the general paradigm.
644  */
645  E_mean_field = lattice_mean_field_total * parameters.testparticles;
646  }
647 
648  return E_mean_field;
649 }
650 
651 EventInfo fill_event_info(const Particles &particles, double E_mean_field,
652  double modus_impact_parameter,
653  const ExperimentParameters &parameters,
654  bool projectile_target_interact) {
655  const QuantumNumbers current_values(particles);
656  const double E_kinetic_total = current_values.momentum().x0();
657  const double E_total = E_kinetic_total + E_mean_field;
658 
659  EventInfo event_info{modus_impact_parameter,
660  parameters.box_length,
661  parameters.outputclock->current_time(),
662  E_kinetic_total,
663  E_mean_field,
664  E_total,
665  parameters.testparticles,
666  !projectile_target_interact};
667  return event_info;
668 }
669 
670 } // 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::ParticleType::exists
static bool exists(PdgCode pdgcode)
Definition: particletype.cc:107
smash::QuantumNumbers::momentum
FourVector momentum() const
Definition: quantumnumbers.h:131
smash::Potentials::skyrme_tau
double skyrme_tau() const
Definition: potentials.h:200
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
@ 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:493
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:193
smash::Potentials::skyrme_b
double skyrme_b() const
Definition: potentials.h:198
smash::Potentials::use_skyrme
virtual bool use_skyrme() const
Definition: potentials.h:191
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:231
smash::EventInfo
Structure to contain custom data for output.
Definition: outputinterface.h:36
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::ExperimentParameters::box_length
double box_length
Length of the box in fm in case of box modus, otherwise -1.
Definition: experimentparameters.h:96
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
smash::Configuration
Interface to the SMASH configuration files.
Definition: configuration.h:464
MultiParticleReactionsBitSet
std::bitset< 2 > MultiParticleReactionsBitSet
Container for the 2 to 2 reactions in the code.
Definition: forwarddeclarations.h:240
smash::fill_event_info
EventInfo fill_event_info(const Particles &particles, double E_mean_field, double modus_impact_parameter, const ExperimentParameters &parameters, bool projectile_target_interact)
Generate the EventInfo object which is passed to outputs_.
Definition: experiment.cc:651
boxmodus.h
experiment.h
spheremodus.h
CollisionCriterion::Covariant
@ Covariant
Covariant Criterion.
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:338
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:32
collidermodus.h
smash::ParticleType::try_find
static const ParticleTypePtr try_find(PdgCode pdgcode)
Returns the ParticleTypePtr for the given pdgcode.
Definition: particletype.cc:89
smash::Potentials::skyrme_a
double skyrme_a() const
Definition: potentials.h:196
smash::Particles
Definition: particles.h:33
smash::RectangularLattice::cell_sizes
const std::array< double, 3 > & cell_sizes() const
Definition: lattice.h:158
smash::ExperimentParameters::outputclock
std::unique_ptr< Clock > outputclock
Output clock to keep track of the next output time.
Definition: experimentparameters.h:29
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:539
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:24
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_SOURCE_LOCATION
#define SMASH_SOURCE_LOCATION
Hackery that is required to output the location in the source code where the log statement occurs.
Definition: logging.h:243
smash::ExperimentParameters::testparticles
int testparticles
Number of test particle.
Definition: experimentparameters.h:32
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