Version: SMASH-1.7
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 
327  const auto &log = logger<LogArea::Experiment>();
328  log.trace() << source_location;
329 
330  const int ntest = config.take({"General", "Testparticles"}, 1);
331  if (ntest <= 0) {
332  throw std::invalid_argument("Testparticle number should be positive!");
333  }
334 
335  const std::string modus_chooser = config.take({"General", "Modus"});
336  // remove config maps of unused Modi
337  config["Modi"].remove_all_but(modus_chooser);
338 
339  /* If this Delta_Time option is absent (this can be for timestepless mode)
340  * just assign 1.0 fm/c, reasonable value will be set at event initialization
341  */
342  const double dt = config.take({"General", "Delta_Time"}, 1.);
343  const double t_end = config.read({"General", "End_Time"});
344 
345  // define output clock
346  std::unique_ptr<Clock> output_clock = nullptr;
347  if (config.has_value({"Output", "Output_Times"})) {
348  if (config.has_value({"Output", "Output_Interval"})) {
349  throw std::invalid_argument(
350  "Please specify either Output_Interval or Output_Times");
351  }
352  std::vector<double> output_times = config.take({"Output", "Output_Times"});
353  // Add an output time larger than the end time so that the next time is
354  // always defined during the time evolution
355  output_times.push_back(t_end + 1.);
356  output_clock = make_unique<CustomClock>(output_times);
357  } else {
358  const double output_dt = config.take({"Output", "Output_Interval"}, t_end);
359  output_clock = make_unique<UniformClock>(0.0, output_dt);
360  }
361 
362  auto config_coll = config["Collision_Term"];
363  /* Elastic collisions between the nucleons with the square root s
364  * below low_snn_cut are excluded. */
365  const double low_snn_cut =
366  config_coll.take({"Elastic_NN_Cutoff_Sqrts"}, 1.98);
367  const auto proton = ParticleType::try_find(pdg::p);
368  const auto pion = ParticleType::try_find(pdg::pi_z);
369  if (proton && pion &&
370  low_snn_cut > proton->mass() + proton->mass() + pion->mass()) {
371  log.warn("The cut-off should be below the threshold energy",
372  " of the process: NN to NNpi");
373  }
374  const bool potential_affect_threshold =
375  config.take({"Lattice", "Potentials_Affect_Thresholds"}, false);
376  return {make_unique<UniformClock>(0.0, dt),
377  std::move(output_clock),
378  ntest,
379  config.take({"General", "Gaussian_Sigma"}, 1.),
380  config.take({"General", "Gauss_Cutoff_In_Sigma"}, 4.),
381  config_coll.take({"Two_to_One"}, true),
382  config_coll.take({"Included_2to2"}, ReactionsBitSet().set()),
383  config_coll.take({"Strings"}, modus_chooser != "Box"),
384  config_coll.take({"Use_AQM"}, true),
385  config_coll.take({"Strings_with_Probability"}, true),
386  config_coll.take({"NNbar_Treatment"}, NNbarTreatment::Strings),
387  config.has_value({"Output", "Photons"}),
388  low_snn_cut,
389  potential_affect_threshold};
390 }
391 
392 std::string format_measurements(const Particles &particles,
393  uint64_t scatterings_this_interval,
394  const QuantumNumbers &conserved_initial,
395  SystemTimePoint time_start, double time) {
396  const SystemTimeSpan elapsed_seconds = SystemClock::now() - time_start;
397 
398  const QuantumNumbers current_values(particles);
399  const QuantumNumbers difference = conserved_initial - current_values;
400 
401  std::ostringstream ss;
402  // clang-format off
403  ss << field<8, 3> << time << field<13, 3> << difference.momentum().x0()
404  << field<16, 3> << scatterings_this_interval
405  << field<11, 3> << particles.size() << field<10, 3> << elapsed_seconds;
406  // clang-format on
407  return ss.str();
408 }
409 
410 } // 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:326
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:303
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:392
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs...
Definition: logging.h:253
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< 10 > 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