Version: SMASH-1.8
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/particledata.h"
17 #include "../include/smash/particles.h"
18 #include "../include/smash/particletype.h"
19 #include "../include/smash/random.h"
20 
21 #include <boost/filesystem.hpp>
22 
23 namespace smash {
24 namespace Test {
25 
36 #ifndef DOXYGEN
37 #include <particles.txt.h>
39 #endif
41 }
42 
47 inline void create_actual_decaymodes() {
48 #ifndef DOXYGEN
49 #include <decaymodes.txt.h>
51 #endif
53 }
54 
56 static constexpr double smashon_mass = 0.123;
58 static constexpr double smashon_width = 1.2;
60 static constexpr const char smashon_pdg_string[] = "661";
61 
67  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
68  "σ " +
69  std::to_string(smashon_mass) + " " + std::to_string(smashon_width) +
70  " + 661\n");
71 }
72 
74 struct Position : public FourVector {
76 };
78 struct Momentum : public FourVector {
80 };
81 
86 inline ParticleData smashon(int id = -1) {
87  ParticleData p{ParticleType::find(0x661), id};
88  return p;
89 }
94 inline ParticleData smashon(const Position &position, int id = -1) {
95  ParticleData p{ParticleType::find(0x661), id};
96  p.set_4position(position);
97  return p;
98 }
103 inline ParticleData smashon(const Momentum &momentum, int id = -1) {
104  ParticleData p{ParticleType::find(0x661), id};
105  p.set_4momentum(momentum);
106  return p;
107 }
112 inline ParticleData smashon(const Position &position, const Momentum &momentum,
113  int id = -1) {
114  ParticleData p{ParticleType::find(0x661), id};
115  p.set_4position(position);
116  p.set_4momentum(momentum);
117  return p;
118 }
126 inline ParticleData smashon(const Momentum &momentum, const Position &position,
127  int id = -1) {
128  ParticleData p{ParticleType::find(0x661), id};
129  p.set_4position(position);
130  p.set_4momentum(momentum);
131  return p;
132 }
137 inline ParticleData smashon_random(int id = -1) {
138  auto random_value = random::make_uniform_distribution(-15.0, +15.0);
139  ParticleData p{ParticleType::find(0x661), id};
140  p.set_4position(
141  {random_value(), random_value(), random_value(), random_value()});
142  p.set_4momentum(smashon_mass,
143  {random_value(), random_value(), random_value()});
144  return p;
145 }
146 
161 inline Configuration configuration(std::string overrides = {}) {
162  Configuration c{bf::path{TEST_CONFIG_PATH} / "input"};
163  if (!overrides.empty()) {
164  c.merge_yaml(overrides);
165  }
166  return c;
167 }
168 
175 inline std::unique_ptr<ExperimentBase> experiment(
176  const Configuration &c = configuration()) {
177  return ExperimentBase::create(c, ".");
178 }
179 
184 inline std::unique_ptr<ExperimentBase> experiment(const char *configOverrides) {
185  return ExperimentBase::create(configuration(configOverrides), ".");
186 }
187 
191 template <typename G>
192 inline ParticleList create_particle_list(std::size_t n, G &&generator) {
193  ParticleList list;
194  list.reserve(n);
195  for (auto i = n; i; --i) {
196  list.emplace_back(generator());
197  }
198  return list;
199 }
200 
202 using ParticlesPtr = std::unique_ptr<Particles>;
203 
208 template <typename G>
209 inline ParticlesPtr create_particles(int n, G &&generator) {
210  ParticlesPtr p = make_unique<Particles>();
211  for (auto i = n; i; --i) {
212  p->insert(generator());
213  }
214  return p;
215 }
216 
222  const std::initializer_list<ParticleData> &init) {
223  ParticlesPtr p = make_unique<Particles>();
224  for (const auto &data : init) {
225  p->insert(data);
226  }
227  return p;
228 }
229 
232  return ReactionsBitSet().set();
233 }
234 
242 inline ExperimentParameters default_parameters(int testparticles = 1,
243  double dt = 0.1) {
244  return ExperimentParameters{make_unique<UniformClock>(0., dt), // labclock
245  make_unique<UniformClock>(0., 1.), // outputclock
246  testparticles, // testparticles
247  1.0, // Gaussian smearing width
248  4.0, // Gaussian smearing cut-off
249  true, // two_to_one
251  false, // strings switch
252  false, // use_AQM
253  1.0,
254  false, // string_with_probability
256  0., // low energy sigma_NN cut-off
257  false}; // potential_affect_threshold
258 }
259 
263 } // namespace Test
264 } // namespace smash
265 
266 #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:137
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:65
smash::Test::create_actual_decaymodes
void create_actual_decaymodes()
Creates the DecayModes list containing the actual decay modes that SMASH uses.
Definition: setup.h:47
smash::Test::configuration
Configuration configuration(std::string overrides={})
Return a configuration object filled with data from src/config.yaml.
Definition: setup.h:161
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:192
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:202
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:86
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:205
ReactionsBitSet
std::bitset< 10 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
Definition: forwarddeclarations.h:226
smash::ParticleType::find
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:105
smash::Configuration
Interface to the SMASH configuration files.
Definition: configuration.h:464
smash::Test::default_parameters
ExperimentParameters default_parameters(int testparticles=1, double dt=0.1)
Creates a standard ExperimentParameters object which works for almost all testing purposes.
Definition: setup.h:242
smash::Test::Momentum
A FourVector that is marked as a momentum vector.
Definition: setup.h:78
smash::Test::smashon_width
static constexpr double smashon_width
The decay width of the smashon particle.
Definition: setup.h:58
smash::Test::smashon_pdg_string
static constexpr const char smashon_pdg_string[]
The PDG code of the smashon particle.
Definition: setup.h:60
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:56
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:74
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:23
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.
smash::Test::create_actual_particletypes
void create_actual_particletypes()
Creates the ParticleType list containing the actual particles that SMASH uses.
Definition: setup.h:35
smash::Test::experiment
std::unique_ptr< ExperimentBase > experiment(const Configuration &c=configuration())
Create an experiment.
Definition: setup.h:175
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:209
smash::Test::all_reactions_included
ReactionsBitSet all_reactions_included()
returns BitSet of 2->2 reactions, where everything is on
Definition: setup.h:231
smash::FourVector::FourVector
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36