Version: SMASH-3.4
modusdefault.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2013-2022,2024
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_MODUSDEFAULT_H_
11 #define SRC_INCLUDE_SMASH_MODUSDEFAULT_H_
12 
13 #include <map>
14 #include <memory>
15 #include <vector>
16 
17 #include "configuration.h"
18 #include "forwarddeclarations.h"
19 #include "fourvector.h"
20 #include "grandcan_thermalizer.h"
21 #include "grid.h"
22 #include "icparameters.h"
23 #include "outputinterface.h"
24 #include "potentials.h"
25 
26 namespace smash {
27 /**
28  * \ingroup modus
29  * Base class for Modus classes that provides default function implementations.
30  *
31  * This is only a base class for actual Modus classes. Meaning there will never
32  * be objects, references, or pointers to ModusDefault. Therefore, it does not
33  * have - and will never need any virtual functions.
34  *
35  * The rules for adding functions to this class are as follows:
36  * - This class is empty per default.
37  * - You can add a function if you have a function that is different in at least
38  * one subclass.
39  * - Code that is common to all goes into ExperimentImplementation.
40  *
41  * \todo JB: many of these functions could/should be virtual (contradicts
42  * description given above, Vinzent says (in a nice way): does not make any
43  * sense whatsoever anyway)
44  */
45 class ModusDefault {
46  public:
47  // Never needs a virtual destructor.
48 
49  // Missing functions for concrete Modus implementations:
50  // \todo(JB): Why is the function below commented out?
51  // double initial_conditions(Particles *particles);
52 
53  /** Enforces sensible positions for the particles.
54  *
55  * Currently, this is only needed for BoxModus; the other Modi do
56  * nothing.
57  *
58  * \see BoxModus::impose_boundary_conditions
59  */
61  const OutputsList& /*out_list*/ = {}) {
62  return 0;
63  }
64 
65  /// \return Checks if modus is collider; overwritten in ColliderModus
66  bool is_collider() const { return false; }
67  /// \return Checks if modus is a box; overwritten in BoxModus
68  bool is_box() const { return false; }
69  /// \return Checks if modus is list modus; overwritten in ListModus
70  bool is_list() const { return false; }
71  /// \return Checks if modus is sphere modus; overwritten in SphereModus
72  bool is_sphere() const { return false; }
73  /// \return Center of mass energy per nucleon pair in ColliderModus
74  double sqrt_s_NN() const { return 0.; }
75  /// \return The impact parameter; overwritten in ColliderModus
76  double impact_parameter() const { return -1.; }
77  /// sample impact parameter for collider modus
78  void sample_impact() const {}
79  /** \return The beam velocity of the projectile required in the Collider
80  * modus. In the other modus, return zero. */
81  double velocity_projectile() const { return 0.0; }
82  /** \return The beam velocity of the target required in the Collider modus.
83  * In the other modus, return zero. */
84  double velocity_target() const { return 0.0; }
85  /** \return The type of Fermi motion required in the Collider modus. In the
86  * other modus, just return FermiMotion::Off. */
88  /// \return Maximal timestep accepted by this modus. Negative means infinity.
89  double max_timestep(double) const { return -1.; }
90  /// \return equilibration time of the box; overwritten in BoxModus
91  double equilibration_time() const { return -1.; }
92  /// \return length of the box; overwritten in BoxModus
93  double length() const { return -1.; }
94  /// \return radius of the sphere; overwritten in SphereModus
95  double radius() const { return -1.; }
96  /** \return Whether the calculation frame is fixed target;
97  * overwritten in ColliderModus */
98  bool calculation_frame_is_fixed_target() const { return false; }
99  /**
100  * Get the passing time of the two nuclei in a collision. This time
101  * corresponds to the moment when the nuclei have just passed entirely
102  * through each other and all primary collisions have occured.
103  * Formula taken from: Eq. (1) in \iref{Karpenko:2015xea}
104  *
105  * Only used in ColliderModus for IC output.
106  * \return passing_time
107  */
108  double nuclei_passing_time() const { return 0.0; }
109  /// \return Whether this is an initial condition for hydrodynamics
110  bool is_IC_for_hybrid() const { return false; }
111  /// \return IC parameters in ColliderModus
113  throw std::logic_error(
114  "Only ColliderModus has parameters for initial conditions.");
115  }
116  /// \return Background energy density map
117  const std::map<int32_t, double>& fluid_background() {
118  throw std::logic_error("Only ColliderModus has a fluid background.");
119  }
120  /// \return Lattice where fluidization is calculated
122  throw std::logic_error("Only ColliderModus has a fluid lattice.");
123  }
124 
125  /**
126  * Build lattice of energy momentum tensor. Currently only implemented in
127  * Collider modus.
128  * \param[in] t Current time.
129  * \param[in] ensembles Only the first Particles element is actually used.
130  * \param[in] dens_par Contains parameters for density smearing.
131  */
133  [[maybe_unused]] const double t,
134  [[maybe_unused]] const std::vector<Particles>& ensembles,
135  [[maybe_unused]] const DensityParameters& dens_par) {}
136  /**
137  * Creates the Grid with normal boundary conditions.
138  *
139  * \param[in] particles The Particles object containing all particles of the
140  * currently running Experiment.
141  * \param[in] min_cell_length The minimal length of the grid cells.
142  * \param[in] timestep_duration Duration of the timestep. It is necessary for
143  * formation times treatment: if particle is fully or partially formed before
144  * the end of the timestep, it has to be on the grid.
145  * \param[in] crit Collision criterion (decides if cell number can be limited)
146  * \param[in] include_unformed_particles include unformed particles from
147  the grid (worsens runtime, necessary
148  for IC output)
149  * \param[in] strategy The strategy to determine the cell size \return the
150  * Grid object
151  *
152  * \see Grid::Grid
153  */
155  const Particles& particles, double min_cell_length,
156  double timestep_duration, CollisionCriterion crit,
157  const bool include_unformed_particles,
158  CellSizeStrategy strategy = CellSizeStrategy::Optimal) const {
160  if (crit == CollisionCriterion::Stochastic) {
162  }
163  return {particles,
164  min_cell_length,
165  timestep_duration,
166  limit,
167  include_unformed_particles,
168  strategy};
169  }
170 
171  /**
172  * Creates GrandCanThermalizer
173  *
174  * \param[in] conf configuration object
175  * \return unique pointer to created thermalizer class
176  */
177  std::unique_ptr<GrandCanThermalizer> create_grandcan_thermalizer(
178  Configuration& conf) const {
179  /* Lattice is placed such that the center is 0,0,0.
180  If one wants to have a central cell with center at 0,0,0 then
181  number of cells should be odd (2k+1) in every direction.
182  */
183  const std::array<double, 3> l =
185  const std::array<double, 3> origin = {-0.5 * l[0], -0.5 * l[1],
186  -0.5 * l[2]};
187  const bool periodicity = false;
188  return std::make_unique<GrandCanThermalizer>(conf, l, origin, periodicity);
189  }
190 
191  /**
192  * \ingroup exception
193  * BadInput is an error to throw if the configuration options are invalid.
194  */
195  struct BadInput : public std::invalid_argument {
196  using std::invalid_argument::invalid_argument;
197  };
198  /**
199  * \ingroup exception
200  * Thrown when the requested energy is smaller than the masses
201  * of two particles.
202  */
203  struct InvalidEnergy : public BadInput {
204  using BadInput::BadInput;
205  };
206 };
207 
208 } // namespace smash
209 
210 #endif // SRC_INCLUDE_SMASH_MODUSDEFAULT_H_
Interface to the SMASH configuration files.
T take(const Key< T > &key)
The default interface for SMASH to read configuration values.
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
Abstracts a list of cells that partition the particles in the experiment into regions of space that c...
Definition: grid.h:96
Base class for Modus classes that provides default function implementations.
Definition: modusdefault.h:45
const RectangularLattice< EnergyMomentumTensor > & fluid_lattice()
Definition: modusdefault.h:121
bool calculation_frame_is_fixed_target() const
Definition: modusdefault.h:98
double radius() const
Definition: modusdefault.h:95
std::unique_ptr< GrandCanThermalizer > create_grandcan_thermalizer(Configuration &conf) const
Creates GrandCanThermalizer.
Definition: modusdefault.h:177
bool is_list() const
Definition: modusdefault.h:70
double velocity_target() const
Definition: modusdefault.h:84
int impose_boundary_conditions(Particles *, const OutputsList &={})
Enforces sensible positions for the particles.
Definition: modusdefault.h:60
double max_timestep(double) const
Definition: modusdefault.h:89
bool is_box() const
Definition: modusdefault.h:68
double nuclei_passing_time() const
Get the passing time of the two nuclei in a collision.
Definition: modusdefault.h:108
void build_fluidization_lattice([[maybe_unused]] const double t, [[maybe_unused]] const std::vector< Particles > &ensembles, [[maybe_unused]] const DensityParameters &dens_par)
Build lattice of energy momentum tensor.
Definition: modusdefault.h:132
FermiMotion fermi_motion() const
Definition: modusdefault.h:87
bool is_sphere() const
Definition: modusdefault.h:72
double velocity_projectile() const
Definition: modusdefault.h:81
bool is_IC_for_hybrid() const
Definition: modusdefault.h:110
double sqrt_s_NN() const
Definition: modusdefault.h:74
double impact_parameter() const
Definition: modusdefault.h:76
bool is_collider() const
Definition: modusdefault.h:66
void sample_impact() const
sample impact parameter for collider modus
Definition: modusdefault.h:78
double equilibration_time() const
Definition: modusdefault.h:91
const InitialConditionParameters & IC_parameters() const
Definition: modusdefault.h:112
const std::map< int32_t, double > & fluid_background()
Definition: modusdefault.h:117
Grid< GridOptions::Normal > 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: modusdefault.h:154
double length() const
Definition: modusdefault.h:93
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:49
FermiMotion
Option to use Fermi Motion.
@ Off
Don't use fermi motion.
CollisionCriterion
Criteria used to check collisions.
@ Stochastic
Stochastic Criteiron.
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.
The variables in this POD struct are of type std::optional<double> so that only the relevant paramete...
Definition: icparameters.h:19
static const Key< std::array< double, 3 > > forcedThermalization_latticeSizes
See user guide description for more information.
Definition: input_keys.h:7671
BadInput is an error to throw if the configuration options are invalid.
Definition: modusdefault.h:195
Thrown when the requested energy is smaller than the masses of two particles.
Definition: modusdefault.h:203