Version: SMASH-1.5
hadgas_eos.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2016-
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 #ifndef SRC_INCLUDE_HADGAS_EOS_H_
10 #define SRC_INCLUDE_HADGAS_EOS_H_
11 
12 #include <gsl/gsl_multiroots.h>
13 #include <gsl/gsl_roots.h>
14 #include <gsl/gsl_vector.h>
15 
16 #include <array>
17 #include <string>
18 #include <vector>
19 
20 #include "constants.h"
21 #include "particletype.h"
22 
23 namespace smash {
24 
25 // Forward declaration of HadronGasEos - it is used in EosTable
26 class HadronGasEos;
27 
32 class EosTable {
33  public:
53  EosTable(double de, double dnb, size_t n_e, size_t n_b);
55  struct table_element {
57  double p;
59  double T;
61  double mub;
63  double mus;
64  };
73  void compile_table(HadronGasEos& eos,
74  const std::string& eos_savefile_name = "hadgas_eos.dat");
83  void get(table_element& res, double e, double nb) const;
84 
85  private:
87  size_t index(size_t ie, size_t inb) const { return ie * n_nb_ + inb; }
89  std::vector<table_element> table_;
91  double de_;
93  double dnb_;
95  size_t n_e_;
97  size_t n_nb_;
98 };
99 
113  public:
115  explicit HadronGasEos(const bool tabulate = false);
116  ~HadronGasEos();
117 
133  static double energy_density(double T, double mub, double mus);
134 
149  static double density(double T, double mub, double mus);
150 
159  static double pressure(double T, double mub, double mus) {
160  return T * density(T, mub, mus);
161  }
162 
177  static double net_baryon_density(double T, double mub, double mus);
178 
193  static double net_strange_density(double T, double mub, double mus);
194 
210  static double partial_density(const ParticleType& ptype, double T, double mub,
211  double mus);
222  static double sample_mass_thermal(const ParticleType& ptype, double beta);
235  std::array<double, 3> solve_eos(double e, double nb, double ns,
236  std::array<double, 3> initial_approximation);
237 
248  std::array<double, 3> solve_eos(double e, double nb, double ns) {
249  return solve_eos(e, nb, ns, solve_eos_initial_approximation(e, nb));
250  }
251 
260  std::array<double, 3> solve_eos_initial_approximation(double e, double nb);
261 
269  static double mus_net_strangeness0(double T, double mub);
270 
272  void from_table(EosTable::table_element& res, double e, double nb) const {
273  eos_table_.get(res, e, nb);
274  }
275 
277  static bool is_eos_particle(const ParticleType& ptype) {
278  return ptype.is_hadron() && ptype.pdgcode().charmness() == 0;
279  }
280 
282  bool is_tabulated() const { return tabulate_; }
283 
284  private:
286  struct rparams {
288  double e;
290  double nb;
292  double ns;
293  };
294 
296  struct eparams {
298  double edens;
299  };
300 
307  static double scaled_partial_density_auxiliary(double m_over_T,
308  double mu_over_T);
320  static double scaled_partial_density(const ParticleType& ptype, double beta,
321  double mub, double mus);
322 
324  static int set_eos_solver_equations(const gsl_vector* x, void* params,
325  gsl_vector* f);
326 
328  static double e_equation(double T, void* params);
329 
336  std::string print_solver_state(size_t iter) const;
337 
339  static constexpr double prefactor_ =
340  0.5 * M_1_PI * M_1_PI / (hbarc * hbarc * hbarc);
341 
343  static constexpr double tolerance_ = 1.e-8;
344 
346  static constexpr size_t n_equations_ = 3;
347 
349  EosTable eos_table_ = EosTable(1.e-2, 1.e-2, 900, 900);
350 
357  gsl_vector* x_;
358 
360  gsl_multiroot_fsolver* solver_;
361 
363  const bool tabulate_;
364 };
365 
366 } // namespace smash
367 
368 #endif // SRC_INCLUDE_HADGAS_EOS_H_
HadronGasEos(const bool tabulate=false)
Constructor of HadronGasEos.
Definition: hadgas_eos.cc:158
A class to hold, compute and access tabulated EoS.
Definition: hadgas_eos.h:32
void compile_table(HadronGasEos &eos, const std::string &eos_savefile_name="hadgas_eos.dat")
Computes the actual content of the table (for EosTable description see documentation of the construct...
Definition: hadgas_eos.cc:34
std::string print_solver_state(size_t iter) const
Helpful printout, useful for debugging if gnu equation solving goes crazy.
Definition: hadgas_eos.cc:534
double mub
Net baryochemical potential.
Definition: hadgas_eos.h:61
std::array< double, 3 > solve_eos(double e, double nb, double ns, std::array< double, 3 > initial_approximation)
Compute temperature and chemical potentials given energy-, net baryon-, net strangeness density and a...
Definition: hadgas_eos.cc:486
static double net_strange_density(double T, double mub, double mus)
Compute net strangeness density.
Definition: hadgas_eos.cc:289
Class to handle the equation of state (EoS) of the hadron gas, consisting of all hadrons included int...
Definition: hadgas_eos.h:112
Collection of useful constants that are known at compile time.
static int set_eos_solver_equations(const gsl_vector *x, void *params, gsl_vector *f)
Interface EoS equations to be solved to gnu library.
Definition: hadgas_eos.cc:401
static double scaled_partial_density(const ParticleType &ptype, double beta, double mub, double mus)
Compute (unnormalized) density of one hadron sort - helper functions used to reduce code duplication...
Definition: hadgas_eos.cc:187
double mus
Net strangeness potential.
Definition: hadgas_eos.h:63
double T
Temperature.
Definition: hadgas_eos.h:59
double dnb_
Step in net-baryon density.
Definition: hadgas_eos.h:93
static constexpr size_t n_equations_
Number of equations in the system of equations to be solved.
Definition: hadgas_eos.h:346
EosTable(double de, double dnb, size_t n_e, size_t n_b)
Sets up a table p/T/muB/mus versus (e, nb), where e is energy density, nb is net baryon density...
Definition: hadgas_eos.cc:29
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:277
constexpr double hbarc
GeV <-> fm conversion factor.
Definition: constants.h:25
double e
energy density
Definition: hadgas_eos.h:288
EosTable eos_table_
EOS Table to be used.
Definition: hadgas_eos.h:349
static constexpr double prefactor_
Constant factor, that appears in front of many thermodyn. expressions.
Definition: hadgas_eos.h:339
size_t n_nb_
Number of steos in net-baryon density.
Definition: hadgas_eos.h:97
static constexpr double tolerance_
Precision of equation solving.
Definition: hadgas_eos.h:343
size_t index(size_t ie, size_t inb) const
proper index in a 1d vector, where the 2d table is stored
Definition: hadgas_eos.h:87
size_t n_e_
Number of steps in energy density.
Definition: hadgas_eos.h:95
double edens
energy density
Definition: hadgas_eos.h:298
static double net_baryon_density(double T, double mub, double mus)
Compute net baryon density.
Definition: hadgas_eos.cc:272
gsl_multiroot_fsolver * solver_
Definition: hadgas_eos.h:360
bool is_tabulated() const
Create an EoS table or not?
Definition: hadgas_eos.h:282
Particle type contains the static properties of a particle species.
Definition: particletype.h:87
double nb
net baryon density
Definition: hadgas_eos.h:290
A structure for passing equation parameters to the gnu library.
Definition: hadgas_eos.h:286
void get(table_element &res, double e, double nb) const
Obtain interpolated p/T/muB/muS from the tabulated equation of state given energy density and net bar...
Definition: hadgas_eos.cc:133
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:305
Define the data structure for one element of the table.
Definition: hadgas_eos.h:55
static double density(double T, double mub, double mus)
Compute particle number density.
Definition: hadgas_eos.cc:256
std::array< double, 3 > solve_eos_initial_approximation(double e, double nb)
Compute a reasonable initial approximation for solve_eos.
Definition: hadgas_eos.cc:423
gsl_vector * x_
Variables used by gnu equation solver.
Definition: hadgas_eos.h:357
double ns
net strange density
Definition: hadgas_eos.h:292
static double partial_density(const ParticleType &ptype, double T, double mub, double mus)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:219
int charmness() const
Definition: pdgcode.h:453
const bool tabulate_
Create an EoS table or not?
Definition: hadgas_eos.h:363
Another structure for passing energy density to the gnu library.
Definition: hadgas_eos.h:296
static double mus_net_strangeness0(double T, double mub)
Compute strangeness chemical potential, requiring that net strangeness = 0.
Definition: hadgas_eos.cc:377
static double scaled_partial_density_auxiliary(double m_over_T, double mu_over_T)
Function used to avoid duplications in density calculations.
Definition: hadgas_eos.cc:173
double de_
Step in energy density.
Definition: hadgas_eos.h:91
bool is_hadron() const
Definition: particletype.h:184
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:89
std::array< double, 3 > solve_eos(double e, double nb, double ns)
Compute temperature and chemical potentials given energy-, net baryon- and net strangeness density wi...
Definition: hadgas_eos.h:248
static double e_equation(double T, void *params)
Definition: hadgas_eos.cc:418
PdgCode pdgcode() const
Definition: particletype.h:146
void from_table(EosTable::table_element &res, double e, double nb) const
Get the element of eos table.
Definition: hadgas_eos.h:272
T beta(T a, T b)
Draws a random number from a beta-distribution, where probability density of is .
Definition: random.h:326
static double pressure(double T, double mub, double mus)
Compute pressure .
Definition: hadgas_eos.h:159
Definition: action.h:24
static double energy_density(double T, double mub, double mus)
Compute energy density.
Definition: hadgas_eos.cc:228