Version: SMASH-3.0
listmodus.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2023
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_(std::filesystem::path filepath,
178  std::streampos last_position);
179 
188  std::filesystem::path file_path_(const int file_id);
189 
197  std::string next_event_();
198 
201 
204 
207 
209  const int shift_id_;
210 
213 
215  int file_id_;
216 
221 
223  std::streampos last_read_position_;
224 
231  friend std::ostream &operator<<(std::ostream &, const ListModus &);
232 };
233 
270 class ListBoxModus : public ListModus {
271  public:
282  explicit ListBoxModus(Configuration modus_config,
283  const ExperimentParameters &parameters);
284 
286  bool is_box() const { return true; }
287 
289  int impose_boundary_conditions(Particles *particles,
290  const OutputsList &output_list = {});
291 
294  const Particles &particles, double min_cell_length,
295  double timestep_duration, CollisionCriterion crit,
296  const bool include_unformed_particles,
297  CellSizeStrategy strategy = CellSizeStrategy::Optimal) const {
299  if (crit == CollisionCriterion::Stochastic) {
301  }
302  return {{{0, 0, 0}, {length_, length_, length_}},
303  particles,
304  min_cell_length,
305  timestep_duration,
306  limit,
307  include_unformed_particles,
308  strategy};
309  }
310 
311  private:
313  const int shift_id_;
314 
316  const double length_;
317 
319  int file_id_;
320 
323 
326 
329 };
330 
331 } // namespace smash
332 
333 #endif // SRC_INCLUDE_SMASH_LISTMODUS_H_
Interface to the SMASH configuration files.
ListBox: Provides a modus for running the SMASH Box with an external particle list,...
Definition: listmodus.h:270
const int shift_id_
shift_id is the start number of file_id_
Definition: listmodus.h:313
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:325
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:293
int event_id_
event_id_ = the unique id of the current event
Definition: listmodus.h:322
const double length_
Length of the cube's edge in fm.
Definition: listmodus.h:316
bool is_box() const
in the case of the ListBoxModus is_box has to be true
Definition: listmodus.h:286
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:280
ListBoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor (This is the same as for the ListModus)
Definition: listmodus.cc:256
std::string particle_list_file_prefix_
File prefix of the particle list.
Definition: listmodus.h:328
int file_id_
file_id_ is the id of the current file
Definition: listmodus.h:319
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:206
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:62
bool file_has_events_(std::filesystem::path filepath, std::streampos last_position)
Check if the file given by filepath has events left after streampos last_position.
Definition: listmodus.cc:223
bool is_list() const
Definition: listmodus.h:143
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:200
std::string particle_list_file_prefix_
File prefix of the particle list.
Definition: listmodus.h:203
int file_id_
file_id_ is the id of the current file
Definition: listmodus.h:215
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:99
std::filesystem::path file_path_(const int file_id)
Return the absolute file path based on given integer.
Definition: listmodus.cc:158
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:223
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
Definition: listmodus.h:218
const int shift_id_
shift_id is the start number of file_id_
Definition: listmodus.h:209
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
Definition: listmodus.h:220
std::string next_event_()
Read the next event.
Definition: listmodus.cc:185
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to a list.
Definition: listmodus.cc:120
int event_id_
event_id_ = the unique id of the current event
Definition: listmodus.h:212
void set_event_id(int event_id_inh)
set the event_id when ListBoxModus is used
Definition: listmodus.h:161
Base class for Modus classes that provides default function implementations.
Definition: modusdefault.h:43
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:110
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:56
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