Version: SMASH-2.0
setup.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_TESTS_SETUP_H_
11 #define SRC_TESTS_SETUP_H_
12 
13 #include "../include/smash/cxx14compat.h"
14 #include "../include/smash/decaymodes.h"
15 #include "../include/smash/experiment.h"
16 #include "../include/smash/outputinterface.h"
17 #include "../include/smash/particledata.h"
18 #include "../include/smash/particles.h"
19 #include "../include/smash/particletype.h"
20 #include "../include/smash/random.h"
21 
22 #include <boost/filesystem.hpp>
23 
24 namespace smash {
25 namespace Test {
26 
37 #ifndef DOXYGEN
38 #include <particles.txt.h>
40 #endif
42 }
43 
48 inline void create_actual_decaymodes() {
49 #ifndef DOXYGEN
50 #include <decaymodes.txt.h>
52 #endif
54 }
55 
57 static constexpr double smashon_mass = 0.123;
59 static constexpr double smashon_width = 1.2;
61 static constexpr const char smashon_pdg_string[] = "661";
62 
68  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
69  "σ " +
70  std::to_string(smashon_mass) + " " + std::to_string(smashon_width) +
71  " + 661\n");
72 }
73 
75 struct Position : public FourVector {
77 };
79 struct Momentum : public FourVector {
81 };
82 
87 inline ParticleData smashon(int id = -1) {
88  ParticleData p{ParticleType::find(0x661), id};
89  return p;
90 }
95 inline ParticleData smashon(const Position &position, int id = -1) {
96  ParticleData p{ParticleType::find(0x661), id};
97  p.set_4position(position);
98  return p;
99 }
104 inline ParticleData smashon(const Momentum &momentum, int id = -1) {
105  ParticleData p{ParticleType::find(0x661), id};
106  p.set_4momentum(momentum);
107  return p;
108 }
113 inline ParticleData smashon(const Position &position, const Momentum &momentum,
114  int id = -1) {
115  ParticleData p{ParticleType::find(0x661), id};
116  p.set_4position(position);
117  p.set_4momentum(momentum);
118  return p;
119 }
127 inline ParticleData smashon(const Momentum &momentum, const Position &position,
128  int id = -1) {
129  ParticleData p{ParticleType::find(0x661), id};
130  p.set_4position(position);
131  p.set_4momentum(momentum);
132  return p;
133 }
138 inline ParticleData smashon_random(int id = -1) {
139  auto random_value = random::make_uniform_distribution(-15.0, +15.0);
140  ParticleData p{ParticleType::find(0x661), id};
141  p.set_4position(
142  {random_value(), random_value(), random_value(), random_value()});
143  p.set_4momentum(smashon_mass,
144  {random_value(), random_value(), random_value()});
145  return p;
146 }
147 
162 inline Configuration configuration(std::string overrides = {}) {
163  Configuration c{bf::path{TEST_CONFIG_PATH} / "input"};
164  if (!overrides.empty()) {
165  c.merge_yaml(overrides);
166  }
167  return c;
168 }
169 
176 inline std::unique_ptr<ExperimentBase> experiment(
177  const Configuration &c = configuration()) {
178  return ExperimentBase::create(c, ".");
179 }
180 
185 inline std::unique_ptr<ExperimentBase> experiment(const char *configOverrides) {
186  return ExperimentBase::create(configuration(configOverrides), ".");
187 }
188 
192 template <typename G>
193 inline ParticleList create_particle_list(std::size_t n, G &&generator) {
194  ParticleList list;
195  list.reserve(n);
196  for (auto i = n; i; --i) {
197  list.emplace_back(generator());
198  }
199  return list;
200 }
201 
203 using ParticlesPtr = std::unique_ptr<Particles>;
204 
209 template <typename G>
210 inline ParticlesPtr create_particles(int n, G &&generator) {
211  ParticlesPtr p = make_unique<Particles>();
212  for (auto i = n; i; --i) {
213  p->insert(generator());
214  }
215  return p;
216 }
217 
223  const std::initializer_list<ParticleData> &init) {
224  ParticlesPtr p = make_unique<Particles>();
225  for (const auto &data : init) {
226  p->insert(data);
227  }
228  return p;
229 }
230 
233  return ReactionsBitSet().set();
234 }
235 
238  return MultiParticleReactionsBitSet().reset();
239 }
240 
249  int testparticles = 1, double dt = 0.1,
251  return ExperimentParameters{
252  make_unique<UniformClock>(0., dt), // labclock
253  make_unique<UniformClock>(0., 1.), // outputclock
254  testparticles, // testparticles
255  1.0, // Gaussian smearing width
256  4.0, // Gaussian smearing cut-off
257  crit,
258  true, // two_to_one
261  false, // strings switch
262  false, // use_AQM
263  1.0,
264  false, // string_with_probability
266  0., // low energy sigma_NN cut-off
267  false, // potential_affect_threshold
268  -1.0, // box_length
269  200.0, // max. cross section
270  1.0, // cross section scaling
271  0.0 // additional elastic cross section
272  };
273 }
274 
276 inline EventInfo default_event_info(double impact_parameter = 0.0,
277  bool empty_event = false) {
278  return EventInfo{impact_parameter, 0.0, 0.0, 0.0, 0.0, 0.0, 1, empty_event};
279 }
280 
284 } // namespace Test
285 } // namespace smash
286 
287 #endif // SRC_TESTS_SETUP_H_
smash
Definition: action.h:24
smash::Test::smashon_random
ParticleData smashon_random(int id=-1)
Create a particle with random position and momentum vectors and optionally a given id.
Definition: setup.h:138
smash::DecayModes::load_decaymodes
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
Definition: decaymodes.cc:164
smash::Test::create_smashon_particletypes
void create_smashon_particletypes()
Creates a ParticleType list containing only the smashon test particle.
Definition: setup.h:66
smash::Test::create_actual_decaymodes
void create_actual_decaymodes()
Creates the DecayModes list containing the actual decay modes that SMASH uses.
Definition: setup.h:48
smash::Test::configuration
Configuration configuration(std::string overrides={})
Return a configuration object filled with data from src/config.yaml.
Definition: setup.h:162
smash::Test::create_particle_list
ParticleList create_particle_list(std::size_t n, G &&generator)
Generate a list of particles from the given generator function.
Definition: setup.h:193
smash::ParticleData
Definition: particledata.h:52
smash::Test::ParticlesPtr
std::unique_ptr< Particles > ParticlesPtr
A type alias for a unique_ptr of Particles.
Definition: setup.h:203
smash::Test::smashon
ParticleData smashon(int id=-1)
Create a particle with 0 position and momentum vectors and optionally a given id.
Definition: setup.h:87
smash::ParticleType::create_type_list
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
Definition: particletype.cc:199
smash::Test::default_event_info
EventInfo default_event_info(double impact_parameter=0.0, bool empty_event=false)
Creates default EventInfo object for testing purposes.
Definition: setup.h:276
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:35
smash::Test::no_multiparticle_reactions
MultiParticleReactionsBitSet no_multiparticle_reactions()
returns BitSet for multi-particle reactions, where everything is off
Definition: setup.h:237
smash::ParticleType::find
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
smash::Test::default_parameters
ExperimentParameters default_parameters(int testparticles=1, double dt=0.1, CollisionCriterion crit=CollisionCriterion::Geometric)
Creates a standard ExperimentParameters object which works for almost all testing purposes.
Definition: setup.h:248
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::Test::Momentum
A FourVector that is marked as a momentum vector.
Definition: setup.h:79
smash::Test::smashon_width
static constexpr double smashon_width
The decay width of the smashon particle.
Definition: setup.h:59
CollisionCriterion
CollisionCriterion
Criteria used to check collisions.
Definition: forwarddeclarations.h:195
smash::Test::smashon_pdg_string
static constexpr const char smashon_pdg_string[]
The PDG code of the smashon particle.
Definition: setup.h:61
smash::random::make_uniform_distribution
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:135
smash::Test::smashon_mass
static constexpr double smashon_mass
The mass of the smashon particle.
Definition: setup.h:57
smash::Configuration::merge_yaml
void merge_yaml(const std::string &yaml)
Merge the configuration in yaml into the existing tree.
Definition: configuration.cc:118
smash::Test::Position
A FourVector that is marked as a position vector.
Definition: setup.h:75
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:24
smash::FourVector
Definition: fourvector.h:33
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::pdg::n
constexpr int n
Neutron.
Definition: pdgcode_constants.h:30
NNbarTreatment::NoAnnihilation
No Annihilation.
CollisionCriterion::Geometric
(Default) geometric criterion.
smash::Test::create_actual_particletypes
void create_actual_particletypes()
Creates the ParticleType list containing the actual particles that SMASH uses.
Definition: setup.h:36
smash::Test::experiment
std::unique_ptr< ExperimentBase > experiment(const Configuration &c=configuration())
Create an experiment.
Definition: setup.h:176
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::Test::create_particles
ParticlesPtr create_particles(int n, G &&generator)
Creates a Particles object and fills it with n particles generated by the generator function.
Definition: setup.h:210
smash::Test::all_reactions_included
ReactionsBitSet all_reactions_included()
returns BitSet of 2->2 reactions, where everything is on
Definition: setup.h:232
smash::FourVector::FourVector
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36