Version: SMASH-3.1
smash::EosTable Class Reference

#include <hadgas_eos.h>

A class to hold, compute and access tabulated EoS.

Definition at line 32 of file hadgas_eos.h.

Classes

struct  table_element
 Define the data structure for one element of the table. More...
 

Public Member Functions

 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, nq - net charge density, p - pressure, T. More...
 
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 constructor). More...
 
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, net baryon density and net charge density. More...
 

Private Member Functions

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 More...
 

Private Attributes

std::vector< table_elementtable_
 Storage for the tabulated equation of state. More...
 
double de_
 Step in energy density. More...
 
double dnb_
 Step in net-baryon density. More...
 
double dq_
 Step in net-charge density. More...
 
size_t n_e_
 Number of steps in energy density. More...
 
size_t n_nb_
 Number of steps in net-baryon density. More...
 
size_t n_q_
 Number of steps in net-charge density. More...
 

Constructor & Destructor Documentation

◆ EosTable()

smash::EosTable::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, nq - net charge density, p - pressure, T.

  • temperature, muB - net baryon chemical potential, muS - net strangeness potential, muQ - net charge chemical potential. Net strangeness density and isospin projection density are assumed to be 0 (Note that the corresponding chemical potential is still non-zero, because muB != 0).

After calling this constructor the table is allocated, but it is still empty. To compute values call compile_table.

Parameters
[in]destep in energy density [GeV/fm^4]
[in]dnbstep in net baryon density [GeV/fm^3]
[in]dqstep in net charge density [GeV/Gev^3]
[in]n_enumber of steps in energy density
[in]n_bnumber of steps in net baryon density
[in]n_qnumber of steps in net charge density

Entry at (ie, inb, inq) corresponds to energy density and net baryon density (e, nb, nq) = (ie*de, inb*dnb, inq*dnq) [GeV/fm^4, GeV/fm^3].

Definition at line 28 of file hadgas_eos.cc.

30  : de_(de), dnb_(dnb), dq_(dq), n_e_(n_e), n_nb_(n_nb), n_q_(n_q) {
31  table_.resize(n_e_ * n_nb_ * n_q_);
32 }
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:97
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
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
size_t n_nb_
Number of steps in net-baryon density.
Definition: hadgas_eos.h:107

Member Function Documentation

◆ compile_table()

void smash::EosTable::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 constructor).

Parameters
[in]eosequation of state
[in]eos_savefile_namename of the file to save tabulated equation of state

Definition at line 34 of file hadgas_eos.cc.

35  {
36  bool table_read_success = false, table_consistency = true;
37  if (std::filesystem::exists(eos_savefile_name)) {
38  std::cout << "Reading table from file " << eos_savefile_name << std::endl;
39  std::ifstream file;
40  file.open(eos_savefile_name, std::ios::in);
41  file >> de_ >> dnb_ >> dq_;
42  file >> n_e_ >> n_nb_ >> n_q_;
43  table_.resize(n_e_ * n_nb_ * n_q_);
44  for (size_t ie = 0; ie < n_e_; ie++) {
45  for (size_t inb = 0; inb < n_nb_; inb++) {
46  for (size_t iq = 0; iq < n_q_; iq++) {
47  double p, T, mub, mus, muq;
48  file >> p >> T >> mub >> mus >> muq;
49  table_[index(ie, inb, iq)] = {p, T, mub, mus, muq};
50  }
51  }
52  }
53  table_read_success = true;
54  std::cout << "Table consumed successfully." << std::endl;
55  }
56 
57  if (table_read_success) {
58  // Check if the saved table is consistent with the current particle table
59  std::cout << "Checking consistency of the table... " << std::endl;
60  constexpr size_t number_of_steps = 50;
61  const size_t ie_step = 1 + n_e_ / number_of_steps;
62  const size_t inb_step = 1 + n_nb_ / number_of_steps;
63  const size_t iq_step = 1 + n_q_ / number_of_steps;
64  for (size_t ie = 0; ie < n_e_; ie += ie_step) {
65  for (size_t inb = 0; inb < n_nb_; inb += inb_step) {
66  for (size_t iq = 0; iq < n_q_; iq += iq_step) {
67  const table_element x = table_[index(ie, inb, iq)];
68  const bool w = eos.account_for_resonance_widths();
69  const double e_comp = eos.energy_density(x.T, x.mub, x.mus, x.muq);
70  const double nb_comp =
71  eos.net_baryon_density(x.T, x.mub, x.mus, x.muq, w);
72  const double ns_comp =
73  eos.net_strange_density(x.T, x.mub, x.mus, x.muq, w);
74  const double p_comp = eos.pressure(x.T, x.mub, x.mus, x.muq, w);
75  const double nq_comp =
76  eos.net_charge_density(x.T, x.mub, x.mus, x.muq, w);
77  // Precision is just 10^-3, this is precision of saved data in the
78  // file
79  const double eps = 1.e-3;
80  // Only check the physical region, hence T > 0 condition
81  if ((std::abs(de_ * ie - e_comp) > eps ||
82  std::abs(dnb_ * inb - nb_comp) > eps ||
83  std::abs(ns_comp) > eps || std::abs(x.p - p_comp) > eps ||
84  std::abs(dq_ * iq - nq_comp) > eps) &&
85  (x.T > 0.0)) {
86  std::cout << "discrepancy: " << de_ * ie << " = " << e_comp << ", "
87  << dnb_ * inb << " = " << nb_comp << ", " << x.p << " = "
88  << p_comp << ", 0 = " << ns_comp << ", " << dq_ * iq
89  << " = " << nq_comp << std::endl;
90  table_consistency = false;
91  goto finish_consistency_check;
92  }
93  }
94  }
95  }
96  }
97 finish_consistency_check:
98 
99  if (!table_read_success || !table_consistency) {
100  std::cout << "Compiling an EoS table..." << std::endl;
101  const double ns = 0.0;
102  for (size_t ie = 0; ie < n_e_; ie++) {
103  std::cout << ie << "/" << n_e_ << "\r" << std::flush;
104  const double e = de_ * ie;
105  for (size_t inb = 0; inb < n_nb_; inb++) {
106  const double nb = dnb_ * inb;
107  for (size_t iq = 0; iq < n_q_; iq++) {
108  const double q = dq_ * iq;
109  // It is physically impossible to have energy density > nucleon
110  // mass*nb, therefore eqns have no solutions.
111  if (nb >= e || q >= e) {
112  table_[index(ie, inb, iq)] = {0.0, 0.0, 0.0, 0.0, 0.0};
113  continue;
114  }
115  // Take extrapolated (T, mub, mus, muq) as initial approximation
116  std::array<double, 4> init_approx;
117  if (inb >= 2) {
118  const table_element y = table_[index(ie, inb - 2, iq)];
119  const table_element x = table_[index(ie, inb - 1, iq)];
120  init_approx = {2.0 * x.T - y.T, 2.0 * x.mub - y.mub,
121  2.0 * x.mus - y.mus, 2.0 * x.muq - y.muq};
122  } else if (iq >= 2) {
123  const table_element y = table_[index(ie, inb, iq - 2)];
124  const table_element x = table_[index(ie, inb, iq - 1)];
125  init_approx = {2.0 * x.T - y.T, 2.0 * x.mub - y.mub,
126  2.0 * x.mus - y.mus, 2.0 * x.muq - y.muq};
127  } else {
128  init_approx = eos.solve_eos_initial_approximation(e, nb, q);
129  }
130  const std::array<double, 4> res =
131  eos.solve_eos(e, nb, ns, q, init_approx);
132  const double T = res[0];
133  const double mub = res[1];
134  const double mus = res[2];
135  const double muq = res[3];
136  const bool w = eos.account_for_resonance_widths();
137  table_[index(ie, inb, iq)] = {eos.pressure(T, mub, mus, muq, w), T,
138  mub, mus, muq};
139  }
140  }
141  }
142  // Save table to file
143  std::cout << "Saving table to file " << eos_savefile_name << std::endl;
144  std::ofstream file;
145  file.open(eos_savefile_name, std::ios::out);
146  file << de_ << " " << dnb_ << " " << dq_ << std::endl;
147  file << n_e_ << " " << n_nb_ << " " << n_q_ << std::endl;
148  file << std::setprecision(7);
149  file << std::fixed;
150  for (size_t ie = 0; ie < n_e_; ie++) {
151  for (size_t inb = 0; inb < n_nb_; inb++) {
152  for (size_t iq = 0; iq < n_q_; iq++) {
153  const EosTable::table_element x = table_[index(ie, inb, iq)];
154  file << x.p << " " << x.T << " " << x.mub << " " << x.mus << " "
155  << x.muq << std::endl;
156  }
157  }
158  }
159  }
160 }
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
constexpr int p
Proton.

◆ get()

void smash::EosTable::get ( EosTable::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, net baryon density and net charge density.

Parameters
[in]eenergy density
[in]nbnet baryon density
[in]nqnet charge density
[out]resstructure, that contains p/T/muB/muS/muQ

Definition at line 162 of file hadgas_eos.cc.

163  {
164  const size_t ie = static_cast<size_t>(std::floor(e / de_));
165  const size_t inb = static_cast<size_t>(std::floor(nb / dnb_));
166  const size_t iq = static_cast<size_t>(std::floor(q / dq_));
167 
168  if (ie >= n_e_ - 1 || inb >= n_nb_ - 1 || iq >= n_q_ - 1) {
169  res = {-1.0, -1.0, -1.0, -1.0, -1.0};
170  } else {
171  // 1st order interpolation
172  const double ae = e / de_ - ie;
173  const double an = nb / dnb_ - inb;
174  const double aq = q / dq_ - iq;
175  const EosTable::table_element s1 = table_[index(ie, inb, iq)];
176  const EosTable::table_element s2 = table_[index(ie + 1, inb, iq)];
177  const EosTable::table_element s3 = table_[index(ie, inb + 1, iq)];
178  const EosTable::table_element s4 = table_[index(ie + 1, inb + 1, iq)];
179  const EosTable::table_element s5 = table_[index(ie, inb, iq + 1)];
180  const EosTable::table_element s6 = table_[index(ie + 1, inb, iq + 1)];
181  const EosTable::table_element s7 = table_[index(ie, inb + 1, iq + 1)];
182  const EosTable::table_element s8 = table_[index(ie + 1, inb + 1, iq + 1)];
183 
184  res.p = interpolate_trilinear(ae, an, aq, s1.p, s2.p, s3.p, s4.p, s5.p,
185  s6.p, s7.p, s8.p);
186  res.T = interpolate_trilinear(ae, an, aq, s1.T, s2.T, s3.T, s4.T, s5.T,
187  s6.T, s7.T, s8.T);
188  res.mub = interpolate_trilinear(ae, an, aq, s1.mub, s2.mub, s3.mub, s4.mub,
189  s5.mub, s6.mub, s7.mub, s8.mub);
190  res.mus = interpolate_trilinear(ae, an, aq, s1.mus, s2.mus, s3.mus, s4.mus,
191  s5.mus, s6.mus, s7.mus, s8.mus);
192  res.muq = interpolate_trilinear(ae, an, aq, s1.muq, s2.muq, s3.muq, s4.muq,
193  s5.muq, s6.muq, s7.muq, s8.muq);
194  }
195 }
T interpolate_trilinear(T ax, T ay, T az, T f1, T f2, T f3, T f4, T f5, T f6, T f7, T f8)
Perform a trilinear 1st order interpolation.

◆ index()

size_t smash::EosTable::index ( size_t  ie,
size_t  inb,
size_t  inq 
) const
inlineprivate

proper index in a 1d vector, where the 3d table is stored

Definition at line 93 of file hadgas_eos.h.

93  {
94  return n_q_ * (ie * n_nb_ + inb) + inq;
95  }

Member Data Documentation

◆ table_

std::vector<table_element> smash::EosTable::table_
private

Storage for the tabulated equation of state.

Definition at line 97 of file hadgas_eos.h.

◆ de_

double smash::EosTable::de_
private

Step in energy density.

Definition at line 99 of file hadgas_eos.h.

◆ dnb_

double smash::EosTable::dnb_
private

Step in net-baryon density.

Definition at line 101 of file hadgas_eos.h.

◆ dq_

double smash::EosTable::dq_
private

Step in net-charge density.

Definition at line 103 of file hadgas_eos.h.

◆ n_e_

size_t smash::EosTable::n_e_
private

Number of steps in energy density.

Definition at line 105 of file hadgas_eos.h.

◆ n_nb_

size_t smash::EosTable::n_nb_
private

Number of steps in net-baryon density.

Definition at line 107 of file hadgas_eos.h.

◆ n_q_

size_t smash::EosTable::n_q_
private

Number of steps in net-charge density.

Definition at line 109 of file hadgas_eos.h.


The documentation for this class was generated from the following files: