Version: SMASH-1.5
experiment.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2018
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 
270  const auto &log = logger<LogArea::Experiment>();
271  log.trace() << source_location;
272 
273  const int ntest = config.take({"General", "Testparticles"}, 1);
274  if (ntest <= 0) {
275  throw std::invalid_argument("Testparticle number should be positive!");
276  }
277 
278  const std::string modus_chooser = config.take({"General", "Modus"});
279  // remove config maps of unused Modi
280  config["Modi"].remove_all_but(modus_chooser);
281 
282  /* If this Delta_Time option is absent (this can be for timestepless mode)
283  * just assign 1.0 fm/c, reasonable value will be set at event initialization
284  */
285  const double dt = config.take({"General", "Delta_Time"}, 1.);
286  const double t_end = config.read({"General", "End_Time"});
287  const double output_dt = config.take({"Output", "Output_Interval"}, t_end);
288  auto config_coll = config["Collision_Term"];
289  /* Elastic collisions between the nucleons with the square root s
290  * below low_snn_cut are excluded. */
291  const double low_snn_cut =
292  config_coll.take({"Elastic_NN_Cutoff_Sqrts"}, 1.98);
293  const auto proton = ParticleType::try_find(pdg::p);
294  const auto pion = ParticleType::try_find(pdg::pi_z);
295  if (proton && pion &&
296  low_snn_cut > proton->mass() + proton->mass() + pion->mass()) {
297  log.warn("The cut-off should be below the threshold energy",
298  " of the process: NN to NNpi");
299  }
300  const bool potential_affect_threshold =
301  config.take({"Lattice", "Potentials_Affect_Thresholds"}, false);
302  return {{0., dt},
303  {0.0, output_dt},
304  ntest,
305  config.take({"General", "Gaussian_Sigma"}, 1.),
306  config.take({"General", "Gauss_Cutoff_In_Sigma"}, 4.),
307  config_coll.take({"Two_to_One"}, true),
308  config_coll.take({"Included_2to2"}, ReactionsBitSet().set()),
309  config_coll.take({"Strings"}, modus_chooser != "Box"),
310  config_coll.take({"Use_AQM"}, true),
311  config_coll.take({"Strings_with_Probability"}, true),
312  config_coll.take({"NNbar_Treatment"}, NNbarTreatment::Strings),
313  config.has_value({"Output", "Photons"}),
314  low_snn_cut,
315  potential_affect_threshold};
316 }
317 
318 std::string format_measurements(const Particles &particles,
319  uint64_t scatterings_this_interval,
320  const QuantumNumbers &conserved_initial,
321  SystemTimePoint time_start, double time) {
322  const SystemTimeSpan elapsed_seconds = SystemClock::now() - time_start;
323 
324  const QuantumNumbers current_values(particles);
325  const QuantumNumbers difference = conserved_initial - current_values;
326 
327  std::ostringstream ss;
328  // clang-format off
329  ss << field<5> << time << field<11, 3> << difference.momentum().x0()
330  << field<14, 3> << scatterings_this_interval
331  << field<14, 3> << particles.size() << field<12, 3> << elapsed_seconds;
332  // clang-format on
333  return ss.str();
334 }
335 
336 } // namespace smash
Value read(std::initializer_list< const char *> keys) const
Additional interface for SMASH to read configuration values without removing them.
static std::unique_ptr< ExperimentBase > create(Configuration config, const bf::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
Interface to the SMASH configuration files.
ExperimentParameters create_experiment_parameters(Configuration config)
Gathers all general Experiment parameters.
Definition: experiment.cc:269
double x0() const
Definition: fourvector.h:290
bool has_value(std::initializer_list< const char *> keys) const
Returns whether there is a non-empty value behind the requested keys.
constexpr int pi_z
π⁰.
size_t size() const
Definition: particles.h:87
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:318
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs...
Definition: logging.h:246
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.
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
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
FourVector momentum() const
Helper structure for Experiment.
Definition: action.h:24