Version: SMASH-1.5
setup.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2018
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{{0., dt},
245  {0., 1.},
246  testparticles,
247  1.0,
248  4.0,
249  true,
251  false,
252  false,
253  false,
255  false,
256  0.,
257  false};
258 }
259 
263 } // namespace Test
264 } // namespace smash
265 
266 #endif // SRC_TESTS_SETUP_H_
ReactionsBitSet all_reactions_included()
returns BitSet of 2->2 reactions, where everything is on
Definition: setup.h:231
Configuration configuration(std::string overrides={})
Return a configuration object filled with data from src/config.yaml.
Definition: setup.h:161
A FourVector that is marked as a position vector.
Definition: setup.h:74
ParticleList create_particle_list(std::size_t n, G &&generator)
Generate a list of particles from the given generator function.
Definition: setup.h:192
A FourVector that is marked as a momentum vector.
Definition: setup.h:78
static std::unique_ptr< ExperimentBase > create(Configuration config, const bf::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
Definition: decaymodes.cc:163
std::unique_ptr< Particles > ParticlesPtr
A type alias for a unique_ptr of Particles.
Definition: setup.h:202
Interface to the SMASH configuration files.
ParticleData smashon(int id=-1)
Create a particle with 0 position and momentum vectors and optionally a given id. ...
Definition: setup.h:86
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
static constexpr double smashon_width
The decay width of the smashon particle.
Definition: setup.h:58
void merge_yaml(const std::string &yaml)
Merge the configuration in yaml into the existing tree.
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
static constexpr const char smashon_pdg_string[]
The PDG code of the smashon particle.
Definition: setup.h:60
static constexpr double smashon_mass
The mass of the smashon particle.
Definition: setup.h:56
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:132
std::bitset< 6 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
constexpr int p
Proton.
void create_actual_particletypes()
Creates the ParticleType list containing the actual particles that SMASH uses.
Definition: setup.h:35
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
constexpr int n
Neutron.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:35
std::unique_ptr< ExperimentBase > experiment(const Configuration &c=configuration())
Create an experiment.
Definition: setup.h:175
Helper structure for Experiment.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
ParticleData smashon_random(int id=-1)
Create a particle with random position and momentum vectors and optionally a given id...
Definition: setup.h:137
Definition: action.h:24
void create_smashon_particletypes()
Creates a ParticleType list containing only the smashon test particle.
Definition: setup.h:65
void create_actual_decaymodes()
Creates the DecayModes list containing the actual decay modes that SMASH uses.
Definition: setup.h:47