Version: SMASH-2.2
listmodus.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2022
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #ifndef SRC_INCLUDE_SMASH_LISTMODUS_H_
8 #define SRC_INCLUDE_SMASH_LISTMODUS_H_
9 
10 #include <cmath>
11 #include <cstdint>
12 #include <list>
13 #include <string>
14 #include <utility>
15 
16 #include "forwarddeclarations.h"
17 #include "modusdefault.h"
18 
19 namespace smash {
20 
56 class ListModus : public ModusDefault {
57  public:
68  explicit ListModus(Configuration modus_config,
69  const ExperimentParameters &parameters);
70 
72  ListModus() : shift_id_(0) {}
73 
86  double initial_conditions(Particles *particles,
87  const ExperimentParameters &parameters);
98  void backpropagate_to_same_time(Particles &particles);
99 
131  void try_create_particle(Particles &particles, PdgCode pdgcode, double t,
132  double x, double y, double z, double mass, double E,
133  double px, double py, double pz);
134 
138  struct LoadFailure : public std::runtime_error {
139  using std::runtime_error::runtime_error;
140  };
141 
143  bool is_list() const { return true; }
144 
146  void set_file_id(const double file_id_inh) { file_id_ = file_id_inh; }
147 
150  std::string particle_list_file_directory_inh) {
151  particle_list_file_directory_ = particle_list_file_directory_inh;
152  }
153 
156  std::string particle_list_file_prefix_inh) {
157  particle_list_file_prefix_ = particle_list_file_prefix_inh;
158  }
159 
161  void set_event_id(int event_id_inh) { event_id_ = event_id_inh; }
162 
163  protected:
165  double start_time_ = 0.;
166 
167  private:
177  bool file_has_events_(bf::path filepath, std::streampos last_position);
178 
187  bf::path file_path_(const int file_id);
188 
196  std::string next_event_();
197 
200 
203 
206 
208  const int shift_id_;
209 
212 
214  int file_id_;
215 
220 
222  std::streampos last_read_position_;
223 
230  friend std::ostream &operator<<(std::ostream &, const ListModus &);
231 };
232 
269 class ListBoxModus : public ListModus {
270  public:
281  explicit ListBoxModus(Configuration modus_config,
282  const ExperimentParameters &parameters);
283 
285  bool is_box() const { return true; }
286 
288  int impose_boundary_conditions(Particles *particles,
289  const OutputsList &output_list = {});
290 
293  const Particles &particles, double min_cell_length,
294  double timestep_duration, CollisionCriterion crit,
295  const bool include_unformed_particles,
296  CellSizeStrategy strategy = CellSizeStrategy::Optimal) const {
298  if (crit == CollisionCriterion::Stochastic) {
300  }
301  return {{{0, 0, 0}, {length_, length_, length_}},
302  particles,
303  min_cell_length,
304  timestep_duration,
305  limit,
306  include_unformed_particles,
307  strategy};
308  }
309 
310  private:
312  const int shift_id_;
313 
315  const double length_;
316 
318  int file_id_;
319 
322 
325 
328 };
329 
330 } // namespace smash
331 
332 #endif // SRC_INCLUDE_SMASH_LISTMODUS_H_
Interface to the SMASH configuration files.
Abstracts a list of cells that partition the particles in the experiment into regions of space that c...
Definition: grid.h:96
ListBox: Provides a modus for running the SMASH Box with an external particle list,...
Definition: listmodus.h:269
const int shift_id_
shift_id is the start number of file_id_
Definition: listmodus.h:312
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:324
Grid< GridOptions::PeriodicBoundaries > create_grid(const Particles &particles, double min_cell_length, double timestep_duration, CollisionCriterion crit, const bool include_unformed_particles, CellSizeStrategy strategy=CellSizeStrategy::Optimal) const
Creates the Grid with normal boundary conditions.
Definition: listmodus.h:292
int event_id_
event_id_ = the unique id of the current event
Definition: listmodus.h:321
const double length_
Length of the cube's edge in fm/c.
Definition: listmodus.h:315
bool is_box() const
in the case of the ListBoxModus is_box has to be true
Definition: listmodus.h:285
int impose_boundary_conditions(Particles *particles, const OutputsList &output_list={})
Enforces that all particles are inside the box at the beginning of an event.
Definition: listmodus.cc:413
ListBoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor (This is the same as for the ListModus)
Definition: listmodus.cc:389
std::string particle_list_file_prefix_
File prefix of the particle list.
Definition: listmodus.h:327
int file_id_
file_id_ is the id of the current file
Definition: listmodus.h:318
ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterbu...
Definition: listmodus.h:56
void set_particle_list_file_directory(std::string particle_list_file_directory_inh)
set the particle_list_directory when ListBoxModus is used
Definition: listmodus.h:149
std::string current_particle_list_file_
File name of current file.
Definition: listmodus.h:205
void backpropagate_to_same_time(Particles &particles)
Judge whether formation times are the same for all the particles; Don't do anti-freestreaming if all ...
Definition: listmodus.cc:162
bool is_list() const
Definition: listmodus.h:143
bf::path file_path_(const int file_id)
Return the absolute file path based on given integer.
Definition: listmodus.cc:292
void set_file_id(const double file_id_inh)
set the file id when ListBoxModus is used
Definition: listmodus.h:146
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:199
std::string particle_list_file_prefix_
File prefix of the particle list.
Definition: listmodus.h:202
int file_id_
file_id_ is the id of the current file
Definition: listmodus.h:214
ListModus()
Construct an empty list. Useful for convenient JetScape connection.
Definition: listmodus.h:72
double start_time_
Starting time for the List; changed to the earliest formation time.
Definition: listmodus.h:165
void try_create_particle(Particles &particles, PdgCode pdgcode, double t, double x, double y, double z, double mass, double E, double px, double py, double pz)
Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal a...
Definition: listmodus.cc:199
void set_particle_list_file_prefix(std::string particle_list_file_prefix_inh)
set the particle_list_prefix when ListBoxModus is used
Definition: listmodus.h:155
std::streampos last_read_position_
last read position in current file
Definition: listmodus.h:222
const int shift_id_
shift_id is the start number of file_id_
Definition: listmodus.h:208
bool file_has_events_(bf::path filepath, std::streampos last_position)
Check if the file given by filepath has events left after streampos last_position.
Definition: listmodus.cc:356
std::string next_event_()
Read the next event.
Definition: listmodus.cc:318
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to a list.
Definition: listmodus.cc:254
int event_id_
event_id_ = the unique id of the current event
Definition: listmodus.h:211
void set_event_id(int event_id_inh)
set the event_id when ListBoxModus is used
Definition: listmodus.h:161
int n_warns_precision_
Counter for mass-check warnings to avoid spamming.
Definition: listmodus.h:217
int n_warns_mass_consistency_
Counter for energy-momentum conservation warnings to avoid spamming.
Definition: listmodus.h:219
Base class for Modus classes that provides default function implementations.
Definition: modusdefault.h:44
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
CollisionCriterion
Criteria used to check collisions.
@ Stochastic
Stochastic Criteiron.
friend std::ostream & operator<<(std::ostream &, const ListModus &)
Writes the initial state for the List to the output stream.
Definition: listmodus.cc:156
Definition: action.h:24
CellNumberLimitation
Identifies whether the number of cells should be limited.
Definition: grid.h:55
@ ParticleNumber
Limit the number of cells to the number of particles.
@ None
No cell number limitation.
CellSizeStrategy
Indentifies the strategy of determining the cell size.
Definition: grid.h:33
@ Optimal
Look for optimal cell size.
Helper structure for Experiment.
Used when external particle list cannot be found.
Definition: listmodus.h:138