Version: SMASH-3.3
listmodus.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2025
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 #include <vector>
16 
17 #include "forwarddeclarations.h"
18 #include "modusdefault.h"
19 
20 namespace smash {
21 
57 class ListModus : public ModusDefault {
58  public:
71  explicit ListModus(Configuration modus_config,
72  const ExperimentParameters &parameters);
73 
78  ListModus() = default;
79 
90  double initial_conditions(Particles *particles,
91  const ExperimentParameters &parameters);
92 
128  void try_create_particle(
129  Particles &particles, PdgCode pdgcode, double t, double x, double y,
130  double z, double mass, double E, double px, double py, double pz,
131  const std::vector<std::string> &optional_quantities = {});
132 
136  struct LoadFailure : public std::runtime_error {
137  using std::runtime_error::runtime_error;
138  };
139 
143  struct InvalidEvents : public std::invalid_argument {
144  using std::invalid_argument::invalid_argument;
145  };
146 
148  bool is_list() const { return true; }
149 
150  protected:
152  double start_time_ = 0.;
153 
154  private:
166 
177  bool file_has_events_(std::filesystem::path filepath,
178  std::streampos last_position);
179 
192  std::filesystem::path file_path_(std::optional<int> file_id);
193 
201  std::string next_event_();
202 
212 
219  void validate_optional_fields_() const;
220 
231 
246  ParticleData &p,
247  const std::vector<std::string> &optional_quantities) const;
248 
251 
257 
259  std::optional<int> file_id_;
260 
262  std::vector<std::string> optional_fields_{};
265 
267  std::streampos last_read_position_ = 0;
268 
273 
276 
283  bool verbose_ = true;
284 
292  friend std::ostream &operator<<(std::ostream &out, const ListModus &m);
293 };
294 
331 class ListBoxModus : public ListModus {
332  public:
343  explicit ListBoxModus(Configuration modus_config,
344  const ExperimentParameters &parameters);
345 
347  bool is_box() const { return true; }
348 
350  int impose_boundary_conditions(Particles *particles,
351  const OutputsList &output_list = {});
352 
355  const Particles &particles, double min_cell_length,
356  double timestep_duration, CollisionCriterion crit,
357  const bool include_unformed_particles,
358  CellSizeStrategy strategy = CellSizeStrategy::Optimal) const {
360  if (crit == CollisionCriterion::Stochastic) {
362  }
363  return {{{0, 0, 0}, {length_, length_, length_}},
364  particles,
365  min_cell_length,
366  timestep_duration,
367  limit,
368  include_unformed_particles,
369  strategy};
370  }
371 
372  private:
374  const double length_;
375 };
376 
377 } // namespace smash
378 
379 #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:331
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:354
const double length_
Length of the cube's edge in fm.
Definition: listmodus.h:374
bool is_box() const
in the case of the ListBoxModus is_box has to be true
Definition: listmodus.h:347
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:502
ListBoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor (This is the same as for the ListModus)
Definition: listmodus.cc:482
ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterbu...
Definition: listmodus.h:57
bool file_has_events_(std::filesystem::path filepath, std::streampos last_position)
Check if the given file has events left after the given position.
Definition: listmodus.cc:390
std::optional< int > file_id_
The id of the current file.
Definition: listmodus.h:259
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:256
void backpropagate_to_same_time_if_needed_(Particles &particles)
Judge whether times are the same for all the particles; don't do anti-freestreaming if all particles ...
Definition: listmodus.cc:107
void validate_optional_fields_() const
Validate the optional fields.
Definition: listmodus.cc:456
std::filesystem::path file_path_(std::optional< int > file_id)
Return the absolute path of the data file.
Definition: listmodus.cc:317
SpinInteractionType spin_interaction_type_
Auxiliary flag to indicate the type of spin interaction used.
Definition: listmodus.h:275
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:250
void validate_list_of_particles_of_all_events_() const
Read and validate all events particles.
Definition: listmodus.cc:431
void read_particles_from_next_event_(Particles &particles)
Read the next event from file.
Definition: listmodus.cc:279
double start_time_
Starting time for the List; changed to the earliest formation time.
Definition: listmodus.h:152
ListModus()=default
Construct an empty list.
bool verbose_
Flag to suppress some error messages.
Definition: listmodus.h:283
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, const std::vector< std::string > &optional_quantities={})
Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal a...
Definition: listmodus.cc:135
std::streampos last_read_position_
Last read position in current file.
Definition: listmodus.h:267
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
Definition: listmodus.h:270
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
Definition: listmodus.h:272
std::string next_event_()
Read the next event.
Definition: listmodus.cc:344
std::vector< std::string > optional_fields_
Fields with optional quantities to be read.
Definition: listmodus.h:262
void insert_optional_quantities_to_(ParticleData &p, const std::vector< std::string > &optional_quantities) const
Sets the optional fields given in the input list into a particle.
Definition: listmodus.cc:152
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to a list.
Definition: listmodus.cc:266
int event_id_
The unique id of the current event.
Definition: listmodus.h:264
Base class for Modus classes that provides default function implementations.
Definition: modusdefault.h:45
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
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.
SpinInteractionType
Possible spin interaction types.
@ Off
No spin interactions.
friend std::ostream & operator<<(std::ostream &out, const ListModus &m)
Writes the initial state for the List to the output stream.
Definition: listmodus.cc:101
constexpr int p
Proton.
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 is invalid.
Definition: listmodus.h:143
Used when external particle list cannot be found.
Definition: listmodus.h:136