Version: SMASH-3.1
hadgas_eos.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2016-2020,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 #ifndef SRC_INCLUDE_SMASH_HADGAS_EOS_H_
10 #define SRC_INCLUDE_SMASH_HADGAS_EOS_H_
11 
12 #include <array>
13 #include <string>
14 #include <vector>
15 
16 #include "gsl/gsl_multiroots.h"
17 #include "gsl/gsl_roots.h"
18 #include "gsl/gsl_vector.h"
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:
55  EosTable(double de, double dnb, double dq, size_t n_e, size_t n_b,
56  size_t n_q);
58  struct table_element {
60  double p;
62  double T;
64  double mub;
66  double mus;
68  double muq;
69  };
78  void compile_table(HadronGasEos& eos,
79  const std::string& eos_savefile_name = "hadgas_eos.dat");
89  void get(table_element& res, double e, double nb, double nq) const;
90 
91  private:
93  size_t index(size_t ie, size_t inb, size_t inq) const {
94  return n_q_ * (ie * n_nb_ + inb) + inq;
95  }
97  std::vector<table_element> table_;
99  double de_;
101  double dnb_;
103  double dq_;
105  size_t n_e_;
107  size_t n_nb_;
109  size_t n_q_;
110 };
111 
126  public:
144  HadronGasEos(bool tabulate, bool account_for_widths);
145  ~HadronGasEos();
146 
162  static double energy_density(double T, double mub, double mus, double muq);
163 
181  static double density(double T, double mub, double mus, double muq,
182  bool account_for_resonance_widths = false);
183 
195  static double pressure(double T, double mub, double mus, double muq,
196  bool account_for_resonance_widths = false) {
197  return T * density(T, mub, mus, muq, account_for_resonance_widths);
198  }
199 
217  static double net_baryon_density(double T, double mub, double mus, double muq,
218  bool account_for_resonance_widths = false);
219 
237  static double net_strange_density(double T, double mub, double mus,
238  double muq,
239  bool account_for_resonance_widths = false);
240 
258  static double net_charge_density(double T, double mub, double mus, double muq,
259  bool account_for_resonance_widths = false);
260 
279  static double partial_density(const ParticleType& ptype, double T, double mub,
280  double mus, double muq,
281  bool account_for_resonance_widths = false);
292  static double sample_mass_thermal(const ParticleType& ptype, double beta);
307  std::array<double, 4> solve_eos(double e, double nb, double ns, double nq,
308  std::array<double, 4> initial_approximation);
309 
322  std::array<double, 4> solve_eos(double e, double nb, double ns, double nq) {
323  return solve_eos(e, nb, ns, nq, solve_eos_initial_approximation(e, nb, nq));
324  }
325 
335  std::array<double, 4> solve_eos_initial_approximation(double e, double nb,
336  double nq);
337 
346  static double mus_net_strangeness0(double T, double mub, double muq);
347 
349  void from_table(EosTable::table_element& res, double e, double nb,
350  double nq) const {
351  eos_table_.get(res, e, nb, nq);
352  }
353 
355  static bool is_eos_particle(const ParticleType& ptype) {
356  return ptype.is_hadron() && ptype.pdgcode().charmness() == 0;
357  }
358 
360  bool is_tabulated() const { return tabulate_; }
361 
365  }
366 
367  private:
369  struct rparams {
371  double e;
373  double nb;
375  double ns;
377  double nq;
380  };
381 
383  struct eparams {
385  double edens;
386  };
387 
394  static double scaled_partial_density_auxiliary(double m_over_T,
395  double mu_over_T);
411  static double scaled_partial_density(const ParticleType& ptype, double beta,
412  double mub, double mus, double muq,
413  bool account_for_width = false);
414 
416  static int set_eos_solver_equations(const gsl_vector* x, void* params,
417  gsl_vector* f);
418 
420  static double e_equation(double T, void* params);
421 
428  std::string print_solver_state(size_t iter) const;
429 
431  static constexpr double prefactor_ =
432  0.5 * M_1_PI * M_1_PI / (hbarc * hbarc * hbarc);
433 
435  static constexpr double tolerance_ = 1.e-8;
436 
438  static constexpr size_t n_equations_ = 4;
439 
441  EosTable eos_table_ = EosTable(1.e-1, 1.e-1, 1.e-1, 90, 90, 90);
442 
449  gsl_vector* x_;
450 
452  gsl_multiroot_fsolver* solver_;
453 
455  const bool tabulate_;
456 
459 };
460 
461 } // namespace smash
462 
463 #endif // SRC_INCLUDE_SMASH_HADGAS_EOS_H_
A class to hold, compute and access tabulated EoS.
Definition: hadgas_eos.h:32
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:97
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
size_t index(size_t ie, size_t inb, size_t inq) const
proper index in a 1d vector, where the 3d table is stored
Definition: hadgas_eos.h:93
double dnb_
Step in net-baryon density.
Definition: hadgas_eos.h:101
size_t n_q_
Number of steps in net-charge density.
Definition: hadgas_eos.h:109
double de_
Step in energy density.
Definition: hadgas_eos.h:99
EosTable(double de, double dnb, double dq, size_t n_e, size_t n_b, size_t n_q)
Sets up a table p/T/muB/mus/muQ versus (e, nb, nq), where e - energy density, nb - net baryon density...
Definition: hadgas_eos.cc:28
size_t n_e_
Number of steps in energy density.
Definition: hadgas_eos.h:105
double dq_
Step in net-charge density.
Definition: hadgas_eos.h:103
void get(table_element &res, double e, double nb, double nq) const
Obtain interpolated p/T/muB/muS/muQ from the tabulated equation of state given energy density,...
Definition: hadgas_eos.cc:162
size_t n_nb_
Number of steps in net-baryon density.
Definition: hadgas_eos.h:107
Class to handle the equation of state (EoS) of the hadron gas, consisting of all hadrons included in ...
Definition: hadgas_eos.h:125
gsl_multiroot_fsolver * solver_
Definition: hadgas_eos.h:452
static double net_charge_density(double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute net charge density.
Definition: hadgas_eos.cc:366
static constexpr double prefactor_
Constant factor, that appears in front of many thermodyn. expressions.
Definition: hadgas_eos.h:431
static double partial_density(const ParticleType &ptype, double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:270
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:385
std::array< double, 4 > solve_eos(double e, double nb, double ns, double nq, std::array< double, 4 > initial_approximation)
Compute temperature and chemical potentials given energy-, net baryon-, net strangeness- and net char...
Definition: hadgas_eos.cc:586
std::array< double, 4 > solve_eos(double e, double nb, double ns, double nq)
Compute temperature and chemical potentials given energy-, net baryon-, net strangeness- and net char...
Definition: hadgas_eos.h:322
bool is_tabulated() const
Create an EoS table or not?
Definition: hadgas_eos.h:360
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:223
EosTable eos_table_
EOS Table to be used.
Definition: hadgas_eos.h:441
gsl_vector * x_
Variables used by gnu equation solver.
Definition: hadgas_eos.h:449
void from_table(EosTable::table_element &res, double e, double nb, double nq) const
Get the element of eos table.
Definition: hadgas_eos.h:349
static double mus_net_strangeness0(double T, double mub, double muq)
Compute strangeness chemical potential, requiring that net strangeness = 0.
Definition: hadgas_eos.cc:456
bool account_for_resonance_widths() const
If resonance spectral functions are taken into account.
Definition: hadgas_eos.h:363
static double density(double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute particle number density.
Definition: hadgas_eos.cc:310
const bool tabulate_
Create an EoS table or not?
Definition: hadgas_eos.h:455
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:355
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:480
std::string print_solver_state(size_t iter) const
Helpful printout, useful for debugging if gnu equation solving goes crazy.
Definition: hadgas_eos.cc:636
static double e_equation(double T, void *params)
Definition: hadgas_eos.cc:501
static double net_baryon_density(double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute net baryon density.
Definition: hadgas_eos.cc:328
static double energy_density(double T, double mub, double mus, double muq)
Compute energy density.
Definition: hadgas_eos.cc:281
static double net_strange_density(double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute net strangeness density.
Definition: hadgas_eos.cc:347
const bool account_for_resonance_widths_
Use pole masses of resonances or integrate over spectral functions.
Definition: hadgas_eos.h:458
std::array< double, 4 > solve_eos_initial_approximation(double e, double nb, double nq)
Compute a reasonable initial approximation for solve_eos.
Definition: hadgas_eos.cc:506
static constexpr size_t n_equations_
Number of equations in the system of equations to be solved.
Definition: hadgas_eos.h:438
HadronGasEos(bool tabulate, bool account_for_widths)
Constructor of HadronGasEos.
Definition: hadgas_eos.cc:197
static double pressure(double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute pressure .
Definition: hadgas_eos.h:195
static constexpr double tolerance_
Precision of equation solving.
Definition: hadgas_eos.h:435
static double scaled_partial_density(const ParticleType &ptype, double beta, double mub, double mus, double muq, bool account_for_width=false)
Compute (unnormalized) density of one hadron sort - helper functions used to reduce code duplication.
Definition: hadgas_eos.cc:237
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
PdgCode pdgcode() const
Definition: particletype.h:157
bool is_hadron() const
Definition: particletype.h:198
int charmness() const
Definition: pdgcode.h:550
Collection of useful constants that are known at compile time.
T beta(T a, T b)
Draws a random number from a beta-distribution, where probability density of is .
Definition: random.h:329
Definition: action.h:24
constexpr double hbarc
GeV <-> fm conversion factor.
Definition: constants.h:25
Define the data structure for one element of the table.
Definition: hadgas_eos.h:58
double mub
Net baryochemical potential.
Definition: hadgas_eos.h:64
double muq
Net charge chemical potential.
Definition: hadgas_eos.h:68
double T
Temperature.
Definition: hadgas_eos.h:62
double mus
Net strangeness potential.
Definition: hadgas_eos.h:66
Another structure for passing energy density to the gnu library.
Definition: hadgas_eos.h:383
double edens
energy density
Definition: hadgas_eos.h:385
A structure for passing equation parameters to the gnu library.
Definition: hadgas_eos.h:369
double e
energy density
Definition: hadgas_eos.h:371
double ns
net strange density
Definition: hadgas_eos.h:375
double nq
net charge density
Definition: hadgas_eos.h:377
double nb
net baryon density
Definition: hadgas_eos.h:373
bool account_for_width
use pole masses of resonances, or integrate over spectral functions
Definition: hadgas_eos.h:379