Version: SMASH-3.1
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:
67  explicit ListModus(Configuration modus_config,
68  const ExperimentParameters &parameters);
69 
74  ListModus() = default;
75 
88  double initial_conditions(Particles *particles,
89  const ExperimentParameters &parameters);
100  void backpropagate_to_same_time(Particles &particles);
101 
136  void try_create_particle(Particles &particles, PdgCode pdgcode, double t,
137  double x, double y, double z, double mass, double E,
138  double px, double py, double pz);
139 
143  struct LoadFailure : public std::runtime_error {
144  using std::runtime_error::runtime_error;
145  };
146 
148  bool is_list() const { return true; }
149 
150  protected:
152  double start_time_ = 0.;
153 
154  private:
165  bool file_has_events_(std::filesystem::path filepath,
166  std::streampos last_position);
167 
180  std::filesystem::path file_path_(std::optional<int> file_id);
181 
190  std::string next_event_();
191 
194 
200 
202  std::optional<int> file_id_;
203 
206 
208  std::streampos last_read_position_ = 0;
209 
214 
221  friend std::ostream &operator<<(std::ostream &, const ListModus &);
222 };
223 
260 class ListBoxModus : public ListModus {
261  public:
272  explicit ListBoxModus(Configuration modus_config,
273  const ExperimentParameters &parameters);
274 
276  bool is_box() const { return true; }
277 
279  int impose_boundary_conditions(Particles *particles,
280  const OutputsList &output_list = {});
281 
284  const Particles &particles, double min_cell_length,
285  double timestep_duration, CollisionCriterion crit,
286  const bool include_unformed_particles,
287  CellSizeStrategy strategy = CellSizeStrategy::Optimal) const {
289  if (crit == CollisionCriterion::Stochastic) {
291  }
292  return {{{0, 0, 0}, {length_, length_, length_}},
293  particles,
294  min_cell_length,
295  timestep_duration,
296  limit,
297  include_unformed_particles,
298  strategy};
299  }
300 
301  private:
303  const double length_;
304 };
305 
306 } // namespace smash
307 
308 #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:260
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:283
const double length_
Length of the cube's edge in fm.
Definition: listmodus.h:303
bool is_box() const
in the case of the ListBoxModus is_box has to be true
Definition: listmodus.h:276
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:294
ListBoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor (This is the same as for the ListModus)
Definition: listmodus.cc:274
ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterbu...
Definition: listmodus.h:56
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:81
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:241
std::optional< int > file_id_
The id of the current file.
Definition: listmodus.h:202
bool is_list() const
Definition: listmodus.h:148
std::string particle_list_filename_or_prefix_
Prefix of the file(s) containing the particle list.
Definition: listmodus.h:199
std::filesystem::path file_path_(std::optional< int > file_id)
Return the absolute path of the data file.
Definition: listmodus.cc:173
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:193
double start_time_
Starting time for the List; changed to the earliest formation time.
Definition: listmodus.h:152
ListModus()=default
Construct an empty list.
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:118
std::streampos last_read_position_
Last read position in current file.
Definition: listmodus.h:208
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
Definition: listmodus.h:211
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
Definition: listmodus.h:213
std::string next_event_()
Read the next event.
Definition: listmodus.cc:198
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to a list.
Definition: listmodus.cc:135
int event_id_
The unique id of the current event.
Definition: listmodus.h:205
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:111
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:75
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:143