Version: SMASH-1.6
experiment.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2019
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  const auto &log = logger<LogArea::Experiment>();
28  log.trace() << source_location;
50  const std::string modus_chooser = config.read({"General", "Modus"});
51  log.debug() << "Modus for this calculation: " << modus_chooser;
52 
53  if (modus_chooser == "Box") {
54  return make_unique<Experiment<BoxModus>>(config, output_path);
55  } else if (modus_chooser == "List") {
56  return make_unique<Experiment<ListModus>>(config, output_path);
57  } else if (modus_chooser == "Collider") {
58  return make_unique<Experiment<ColliderModus>>(config, output_path);
59  } else if (modus_chooser == "Sphere") {
60  return make_unique<Experiment<SphereModus>>(config, output_path);
61  } else {
62  throw InvalidModusRequest("Invalid Modus (" + modus_chooser +
63  ") requested from ExperimentBase::create.");
64  }
65 }
66 
282  const auto &log = logger<LogArea::Experiment>();
283  log.trace() << source_location;
284 
285  const int ntest = config.take({"General", "Testparticles"}, 1);
286  if (ntest <= 0) {
287  throw std::invalid_argument("Testparticle number should be positive!");
288  }
289 
290  const std::string modus_chooser = config.take({"General", "Modus"});
291  // remove config maps of unused Modi
292  config["Modi"].remove_all_but(modus_chooser);
293 
294  /* If this Delta_Time option is absent (this can be for timestepless mode)
295  * just assign 1.0 fm/c, reasonable value will be set at event initialization
296  */
297  const double dt = config.take({"General", "Delta_Time"}, 1.);
298  const double t_end = config.read({"General", "End_Time"});
299  const double output_dt = config.take({"Output", "Output_Interval"}, t_end);
300  auto config_coll = config["Collision_Term"];
301  /* Elastic collisions between the nucleons with the square root s
302  * below low_snn_cut are excluded. */
303  const double low_snn_cut =
304  config_coll.take({"Elastic_NN_Cutoff_Sqrts"}, 1.98);
305  const auto proton = ParticleType::try_find(pdg::p);
306  const auto pion = ParticleType::try_find(pdg::pi_z);
307  if (proton && pion &&
308  low_snn_cut > proton->mass() + proton->mass() + pion->mass()) {
309  log.warn("The cut-off should be below the threshold energy",
310  " of the process: NN to NNpi");
311  }
312  const bool potential_affect_threshold =
313  config.take({"Lattice", "Potentials_Affect_Thresholds"}, false);
314  return {{0., dt},
315  {0.0, output_dt},
316  ntest,
317  config.take({"General", "Gaussian_Sigma"}, 1.),
318  config.take({"General", "Gauss_Cutoff_In_Sigma"}, 4.),
319  config_coll.take({"Two_to_One"}, true),
320  config_coll.take({"Included_2to2"}, ReactionsBitSet().set()),
321  config_coll.take({"Strings"}, modus_chooser != "Box"),
322  config_coll.take({"Use_AQM"}, true),
323  config_coll.take({"Strings_with_Probability"}, true),
324  config_coll.take({"NNbar_Treatment"}, NNbarTreatment::Strings),
325  config.has_value({"Output", "Photons"}),
326  low_snn_cut,
327  potential_affect_threshold};
328 }
329 
330 std::string format_measurements(const Particles &particles,
331  uint64_t scatterings_this_interval,
332  const QuantumNumbers &conserved_initial,
333  SystemTimePoint time_start, double time) {
334  const SystemTimeSpan elapsed_seconds = SystemClock::now() - time_start;
335 
336  const QuantumNumbers current_values(particles);
337  const QuantumNumbers difference = conserved_initial - current_values;
338 
339  std::ostringstream ss;
340  // clang-format off
341  ss << field<8, 3> << time << field<13, 3> << difference.momentum().x0()
342  << field<16, 3> << scatterings_this_interval
343  << field<11, 3> << particles.size() << field<10, 3> << elapsed_seconds;
344  // clang-format on
345  return ss.str();
346 }
347 
348 } // namespace smash
static std::unique_ptr< ExperimentBase > create(Configuration config, const bf::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
Value read(std::initializer_list< const char * > keys) const
Additional interface for SMASH to read configuration values without removing them.
Interface to the SMASH configuration files.
ExperimentParameters create_experiment_parameters(Configuration config)
Gathers all general Experiment parameters.
Definition: experiment.cc:281
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
double x0() const
Definition: fourvector.h:290
constexpr int pi_z
π⁰.
std::string format_measurements(const Particles &particles, uint64_t scatterings_this_interval, const QuantumNumbers &conserved_initial, SystemTimePoint time_start, double time)
Generate the tabulated string which will be printed to the screen when SMASH is running.
Definition: experiment.cc:330
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs...
Definition: logging.h:246
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
size_t size() const
Definition: particles.h:87
A container for storing conserved values.
SystemClock::duration SystemTimeSpan
The time duration type (alias) used for measuring run times.
Definition: chrono.h:28
void remove_all_but(const std::string &key)
Removes all entries in the map except for key.
std::bitset< 6 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
FourVector momentum() const
Use string fragmentation.
std::chrono::time_point< std::chrono::system_clock > SystemTimePoint
Type (alias) that is used to store the current time.
Definition: chrono.h:22
constexpr int p
Proton.
static const ParticleTypePtr try_find(PdgCode pdgcode)
Returns the ParticleTypePtr for the given pdgcode.
Definition: particletype.cc:93
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
Helper structure for Experiment.
Definition: action.h:24