Version: SMASH-3.4
setup.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015,2017-2026
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 <filesystem>
14 
15 #include "smash/decaymodes.h"
16 #include "smash/experiment.h"
17 #include "smash/outputinterface.h"
18 #include "smash/particledata.h"
19 #include "smash/particles.h"
20 #include "smash/particletype.h"
21 #include "smash/random.h"
23 
24 namespace smash {
25 namespace Test {
26 
27 /**
28  * \addtogroup unittest
29  * @{
30  */
31 
32 /**
33  * Creates the ParticleType list containing the actual particles that SMASH
34  * uses.
35  */
37 #ifndef DOXYGEN
38 /// not visible to doxygen, but compiled
39 #include <particles.txt.h>
40 #endif
42 }
43 
44 /**
45  * Creates the DecayModes list containing the actual decay modes that SMASH
46  * uses.
47  */
48 inline void create_actual_decaymodes() {
49 #ifndef DOXYGEN
50 /// not visible to doxygen, but compiled
51 #include <decaymodes.txt.h>
52 #endif
54 }
55 
56 /// The mass of the smashon particle.
57 static constexpr double smashon_mass = 0.123;
58 /// The decay width of the smashon particle.
59 static constexpr double smashon_width = 1.2;
60 /// The PDG code of the smashon particle.
61 static constexpr const char smashon_pdg_string[] = "661";
62 
63 /**
64  * Creates a ParticleType list containing only the smashon test particle.
65  */
68  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
69  "σ " +
71  " + 661\n");
72 }
73 
74 /**
75  * Creates a ParticleType list containing only the smashon test particle with
76  * width 0 (stable).
77  */
80  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
81  "σ " +
82  std::to_string(smashon_mass) + " 0.0 + 661\n");
83 }
84 
85 /// A FourVector that is marked as a position vector.
86 struct Position : public FourVector {
88 };
89 /// A FourVector that is marked as a momentum vector.
90 struct Momentum : public FourVector {
92 };
93 
94 /**
95  * Create a particle with 0 position and momentum vectors and optionally a given
96  * \p id.
97  */
98 inline ParticleData smashon(int id = -1) {
99  ParticleData p{ParticleType::find(0x661), id};
100  return p;
101 }
102 /**
103  * Create a particle with 0 momentum vector, the given \p position, and
104  * optionally a given \p id.
105  */
106 inline ParticleData smashon(const Position& position, int id = -1) {
107  ParticleData p{ParticleType::find(0x661), id};
108  p.set_4position(position);
109  p.set_formation_time(position[0]);
110  return p;
111 }
112 /**
113  * Create a particle with 0 position vector, the given \p momentum, and
114  * optionally a given \p id.
115  */
116 inline ParticleData smashon(const Momentum& momentum, int id = -1) {
117  ParticleData p{ParticleType::find(0x661), id};
118  p.set_4momentum(momentum);
119  return p;
120 }
121 /**
122  * Create a particle with the given \p position and \p momentum vectors, and
123  * optionally a given \p id.
124  */
125 inline ParticleData smashon(const Position& position, const Momentum& momentum,
126  int id = -1) {
127  ParticleData p{ParticleType::find(0x661), id};
128  p.set_4position(position);
129  p.set_4momentum(momentum);
130  p.set_formation_time(position[0]);
131  p.set_unpolarized_spin_vector();
132  return p;
133 }
134 /**
135  * Create a particle with the given \p position and \p momentum vectors, and
136  * optionally a given \p id.
137  *
138  * Convenience overload of the above to allow arbitrary order of momentum and
139  * position.
140  */
141 inline ParticleData smashon(const Momentum& momentum, const Position& position,
142  int id = -1) {
143  ParticleData p{ParticleType::find(0x661), id};
144  p.set_4position(position);
145  p.set_4momentum(momentum);
146  p.set_formation_time(position[0]);
147  p.set_unpolarized_spin_vector();
148  return p;
149 }
150 /**
151  * Create a particle with random position and momentum vectors and optionally a
152  * given \p id.
153  */
154 inline ParticleData smashon_random(int id = -1) {
155  auto random_value = random::make_uniform_distribution(-15.0, +15.0);
156  ParticleData p{ParticleType::find(0x661), id};
157  auto random_time = random_value();
158  p.set_formation_time(random_time);
159  p.set_4position(
160  {random_time, random_value(), random_value(), random_value()});
161  p.set_4momentum(smashon_mass,
162  {random_value(), random_value(), random_value()});
163  return p;
164 }
165 
166 /**
167  * Create an experiment given an input configuration.
168  */
169 inline std::unique_ptr<ExperimentBase> experiment(Configuration c) {
170  return ExperimentBase::create(c, ".");
171 }
172 
173 /**
174  * Generate a list of particles from the given generator function.
175  */
176 template <typename G>
177 inline ParticleList create_particle_list(std::size_t n, G&& generator) {
178  ParticleList list;
179  list.reserve(n);
180  for (auto i = n; i; --i) {
181  list.emplace_back(generator());
182  }
183  return list;
184 }
185 
186 /// A type alias for a unique_ptr of Particles.
187 using ParticlesPtr = std::unique_ptr<Particles>;
188 
189 /**
190  * Creates a Particles object and fills it with \p n particles generated by the
191  * \p generator function.
192  */
193 template <typename G>
194 inline ParticlesPtr create_particles(int n, G&& generator) {
195  ParticlesPtr p = std::make_unique<Particles>();
196  for (auto i = n; i; --i) {
197  p->insert(generator());
198  }
199  return p;
200 }
201 
202 /**
203  * Creates a Particles object and fills it with the particles passed as
204  * initializer_list to this function.
205  */
207  const std::initializer_list<ParticleData>& init) {
208  ParticlesPtr p = std::make_unique<Particles>();
209  for (const auto& data : init) {
210  p->insert(data);
211  }
212  return p;
213 }
214 
215 /// returns BitSet of 2->2 reactions, where everything is on
217  return ReactionsBitSet().set();
218 }
219 
220 /// returns BitSet for multi-particle reactions, where everything is off
222  return MultiParticleReactionsBitSet().reset();
223 }
224 
225 /**
226  * Creates a standard ExperimentParameters object which works for almost all
227  * testing purposes.
228  *
229  * If needed you can set the testparticles parameter to a different value than
230  * 1.
231  */
233  int testparticles = 1, double dt = 0.1,
235  bool strings = false,
237  ReactionsBitSet included_2to2 = all_reactions_included()) {
238  return ExperimentParameters{
239  std::make_unique<UniformClock>(0., dt, 300.0), // labclock
240  std::make_unique<UniformClock>(0., 1., 300.0), // outputclock
241  1, // ensembles
242  testparticles, // testparticles
243  DerivativesMode::CovariantGaussian, // derivatives mode
244  RestFrameDensityDerivativesMode::Off, // rest frame derivatives mode
245  FieldDerivativesMode::ChainRule, // field derivatives mode
246  SmearingMode::CovariantGaussian, // smearing mode
247  1.0, // Gaussian smearing width
248  4.0, // Gaussian smearing cut-off
249  0.333333, // discrete smearing weight
250  2.0, // triangular smearing range
251  criterion, // collision criterion
252  true, // two_to_one
253  included_2to2,
256  strings,
257  1.0,
258  nnbar_treatment,
259  0., // low energy sigma_NN cut-off
260  false, // potential_affect_threshold
261  -1.0, // box_length
262  200.0, // max. cross section
263  2.5, // fixed min. cell length
264  1.0, // cross section scaling
265  false, // in thermodynamics outputs spectators are included
266  false, // ignore unformed particles for thermodynamics
267  true, // force decays at the end
268  false, // do weak decays
269  true, // decay initial particles
270  DileptonBremsPionFormFactor::Off, // no form factor
271  SpinInteractionType::Off, // no spin interactions
272  };
273 }
274 
275 /**
276  * Creates a standard ScatterActionsFinderParameters object which works for
277  * almost all testing purposes.
278  *
279  * The selected arguments are changed between different tests, which requires
280  * setting the key by hand. This is not directly possible for enums, so one must
281  * do it case by case.
282  */
284  double elastic_parameter = 10,
286  ReactionsBitSet included_2to2 = all_reactions_included(),
287  bool strings_switch = true, bool use_AQM = false,
288  bool strings_with_probability = false,
289  TotalCrossSectionStrategy xs_strategy =
291  Configuration config{
292  R"(
293  Collision_Term:
294  Only_Warn_For_High_Probability: true
295  Pseudoresonance: None
296  )"};
297  config.set_value(InputKeys::collTerm_elasticCrossSection, elastic_parameter);
298  config.set_value(InputKeys::collTerm_useAQM, use_AQM);
300  strings_with_probability);
301 
302  if (xs_strategy == TotalCrossSectionStrategy::BottomUp) {
303  config.merge_yaml(InputKeys::collTerm_totXsStrategy.as_yaml("BottomUp"));
304  } else if (xs_strategy == TotalCrossSectionStrategy::TopDown) {
305  config.merge_yaml(InputKeys::collTerm_totXsStrategy.as_yaml("TopDown"));
306  } else if (xs_strategy == TotalCrossSectionStrategy::TopDownMeasured) {
307  config.merge_yaml(
308  InputKeys::collTerm_totXsStrategy.as_yaml("TopDownMeasured"));
309  }
311  config,
312  default_parameters(1, 0.1, CollisionCriterion::Geometric, strings_switch,
313  nnbar_treatment, included_2to2));
314 }
315 
316 /// Creates default EventInfo object for testing purposes
317 inline EventInfo default_event_info(double impact_parameter = 0.0,
318  bool empty_event = false) {
319  return EventInfo{impact_parameter, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1,
320  empty_event, false};
321 }
322 
323 /// Creates a default StringProcessInterface object for testing
324 inline std::unique_ptr<StringProcess> default_string_process_interface() {
325  Configuration config{""};
326  return std::make_unique<StringProcess>(config);
327 }
328 /// Creates default parameters for dynamic IC
329 inline InitialConditionParameters default_dynamic_IC_parameters() {
330  InitialConditionParameters parameters{};
331  parameters.type = FluidizationType::Dynamic;
332  parameters.fluidizable_processes = FluidizableProcessesBitSet{}.set();
333  parameters.energy_density_threshold = 0.5;
334  parameters.min_time = 0;
335  parameters.max_time = 100;
336  parameters.num_fluid_cells = 50;
337  parameters.formation_time_fraction = 1;
338  parameters.smearing_kernel_at_0 = std::pow(2 * M_PI, -1.5);
339  parameters.delay_initial_elastic = false;
340  return parameters;
341 }
342 
343 /**
344  * @}
345  */
346 } // namespace Test
347 } // namespace smash
348 
349 #endif // SRC_TESTS_SETUP_H_
Interface to the SMASH configuration files.
void set_value(Key< U > key, T &&value)
Overwrite the value of the YAML node corresponding to the specified key.
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
Definition: decaymodes.cc:163
static std::unique_ptr< ExperimentBase > create(Configuration &config, const std::filesystem::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
Definition: experiment.cc:22
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
Helper class for ScatterActionsFinder.
@ Off
Don't use form factors, i.e. multiply by 1.
@ Dynamic
Dynamic fluidization based on local densities.
NNbarTreatment
Treatment of N Nbar Annihilation.
@ NoAnnihilation
No Annihilation.
@ Resonances
Charm interactions via resonances.
std::bitset< 5 > FluidizableProcessesBitSet
TotalCrossSectionStrategy
Determine how total cross sections for collision finding should be computed.
@ TopDownMeasured
Mix the two above, using the parametrizations only for measured processes, and summing up partials fo...
@ TopDown
Use parametrizations based on existing data, rescaling with AQM for unmeasured processes.
@ BottomUp
Sum the existing partial contributions.
std::bitset< 4 > MultiParticleReactionsBitSet
Container for the n to m reactions in the code.
CollisionCriterion
Criteria used to check collisions.
@ Geometric
Geometric criterion.
std::bitset< 11 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
@ Off
No spin interactions.
ParticleList create_particle_list(std::size_t n, G &&generator)
Generate a list of particles from the given generator function.
Definition: setup.h:177
static constexpr double smashon_mass
The mass of the smashon particle.
Definition: setup.h:57
void create_actual_particletypes()
Creates the ParticleType list containing the actual particles that SMASH uses.
Definition: setup.h:36
static constexpr const char smashon_pdg_string[]
The PDG code of the smashon particle.
Definition: setup.h:61
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:194
std::unique_ptr< StringProcess > default_string_process_interface()
Creates a default StringProcessInterface object for testing.
Definition: setup.h:320
static constexpr double smashon_width
The decay width of the smashon particle.
Definition: setup.h:59
void create_actual_decaymodes()
Creates the DecayModes list containing the actual decay modes that SMASH uses.
Definition: setup.h:48
std::unique_ptr< Particles > ParticlesPtr
A type alias for a unique_ptr of Particles.
Definition: setup.h:187
std::unique_ptr< ExperimentBase > experiment(Configuration c)
Create an experiment given an input configuration.
Definition: setup.h:169
void create_smashon_particletypes()
Creates a ParticleType list containing only the smashon test particle.
Definition: setup.h:66
ParticleData smashon(int id=-1)
Create a particle with 0 position and momentum vectors and optionally a given id.
Definition: setup.h:98
MultiParticleReactionsBitSet no_multiparticle_reactions()
returns BitSet for multi-particle reactions, where everything is off
Definition: setup.h:221
ScatterActionsFinderParameters default_finder_parameters(double elastic_parameter=10, NNbarTreatment nnbar_treatment=NNbarTreatment::NoAnnihilation, ReactionsBitSet included_2to2=all_reactions_included(), bool strings_switch=true, bool use_AQM=false, bool strings_with_probability=false, TotalCrossSectionStrategy xs_strategy=TotalCrossSectionStrategy::BottomUp)
Creates a standard ScatterActionsFinderParameters object which works for almost all testing purposes.
Definition: setup.h:283
EventInfo default_event_info(double impact_parameter=0.0, bool empty_event=false)
Creates default EventInfo object for testing purposes.
Definition: setup.h:313
void create_stable_smashon_particletypes()
Creates a ParticleType list containing only the smashon test particle with width 0 (stable).
Definition: setup.h:78
ExperimentParameters default_parameters(int testparticles=1, double dt=0.1, CollisionCriterion criterion=CollisionCriterion::Geometric, bool strings=false, NNbarTreatment nnbar_treatment=NNbarTreatment::NoAnnihilation, ReactionsBitSet included_2to2=all_reactions_included())
Creates a standard ExperimentParameters object which works for almost all testing purposes.
Definition: setup.h:232
ParticleData smashon_random(int id=-1)
Create a particle with random position and momentum vectors and optionally a given id.
Definition: setup.h:154
InitialConditionParameters default_dynamic_IC_parameters()
Creates default parameters for dynamic IC.
Definition: setup.h:325
ReactionsBitSet all_reactions_included()
returns BitSet of 2->2 reactions, where everything is on
Definition: setup.h:216
constexpr int p
Proton.
constexpr int n
Neutron.
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:144
Definition: action.h:24
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:26
Structure to contain custom data for output.
Helper structure for Experiment.
FluidizationType type
Type of initialization.
Definition: icparameters.h:21
static const Key< bool > collTerm_stringsWithProbability
See user guide description for more information.
Definition: input_keys.h:3067
static const Key< bool > collTerm_useAQM
See user guide description for more information.
Definition: input_keys.h:3169
static const Key< TotalCrossSectionStrategy > collTerm_totXsStrategy
See user guide description for more information.
Definition: input_keys.h:3103
static const Key< double > collTerm_elasticCrossSection
See user guide description for more information.
Definition: input_keys.h:2597
A FourVector that is marked as a momentum vector.
Definition: setup.h:90
A FourVector that is marked as a position vector.
Definition: setup.h:86