Version: SMASH-1.5
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.

Collaboration diagram for smash::EosTable:
[legend]

Classes

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

Public Member Functions

 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, p - pressure, T - temperature, muB - net baryon chemical potential, muS - net strangeness potential. 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) const
 Obtain interpolated p/T/muB/muS from the tabulated equation of state given energy density and net baryon density. More...
 

Private Member Functions

size_t index (size_t ie, size_t inb) const
 proper index in a 1d vector, where the 2d 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...
 
size_t n_e_
 Number of steps in energy density. More...
 
size_t n_nb_
 Number of steos in net-baryon density. More...
 

Constructor & Destructor Documentation

◆ EosTable()

smash::EosTable::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, p - pressure, T - temperature, muB - net baryon chemical potential, muS - net strangeness potential.

Net strangeness density and isospin projection density are assumed to be 0 (Note that corresponding chemical potentials are 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]n_enumber of steps in energy density
[in]n_bnumber of steps in net baryon density

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

Definition at line 29 of file hadgas_eos.cc.

30  : de_(de), dnb_(dnb), n_e_(n_e), n_nb_(n_nb) {
31  table_.resize(n_e_ * n_nb_);
32 }
double dnb_
Step in net-baryon density.
Definition: hadgas_eos.h:93
size_t n_nb_
Number of steos in net-baryon density.
Definition: hadgas_eos.h:97
size_t n_e_
Number of steps in energy density.
Definition: hadgas_eos.h:95
double de_
Step in energy density.
Definition: hadgas_eos.h:91
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:89

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 (boost::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_;
42  file >> n_e_ >> n_nb_;
43  table_.resize(n_e_ * n_nb_);
44  for (size_t ie = 0; ie < n_e_; ie++) {
45  for (size_t inb = 0; inb < n_nb_; inb++) {
46  double p, T, mub, mus;
47  file >> p >> T >> mub >> mus;
48  table_[index(ie, inb)] = {p, T, mub, mus};
49  }
50  }
51  table_read_success = true;
52  std::cout << "Table consumed successfully." << std::endl;
53  }
54 
55  if (table_read_success) {
56  // Check if the saved table is consistent with the current particle table
57  std::cout << "Checking consistency of the table... " << std::endl;
58  constexpr size_t number_of_steps = 50;
59  const size_t ie_step = 1 + n_e_ / number_of_steps;
60  const size_t inb_step = 1 + n_nb_ / number_of_steps;
61  for (size_t ie = 0; ie < n_e_; ie += ie_step) {
62  for (size_t inb = 0; inb < n_nb_; inb += inb_step) {
63  const table_element x = table_[index(ie, inb)];
64  const double e_comp = eos.energy_density(x.T, x.mub, x.mus);
65  const double nb_comp = eos.net_baryon_density(x.T, x.mub, x.mus);
66  const double ns_comp = eos.net_strange_density(x.T, x.mub, x.mus);
67  const double p_comp = eos.pressure(x.T, x.mub, x.mus);
68  // Precision is just 10^-3, this is precision of saved data in the file
69  const double eps = 1.e-3;
70  // Only check the physical region, hence T > 0 condition
71  if ((std::abs(de_ * ie - e_comp) > eps ||
72  std::abs(dnb_ * inb - nb_comp) > eps || std::abs(ns_comp) > eps ||
73  std::abs(x.p - p_comp) > eps) &&
74  (x.T > 0.0)) {
75  std::cout << "discrepancy: " << de_ * ie << " = " << e_comp << ", "
76  << dnb_ * inb << " = " << nb_comp << ", " << x.p << " = "
77  << p_comp << ", 0 = " << ns_comp << std::endl;
78  table_consistency = false;
79  goto finish_consistency_check;
80  }
81  }
82  }
83  }
84 finish_consistency_check:
85 
86  if (!table_read_success || !table_consistency) {
87  std::cout << "Compiling an EoS table..." << std::endl;
88  const double ns = 0.0;
89  for (size_t ie = 0; ie < n_e_; ie++) {
90  const double e = de_ * ie;
91  for (size_t inb = 0; inb < n_nb_; inb++) {
92  const double nb = dnb_ * inb;
93  // It is physically impossible to have energy density > nucleon mass*nb,
94  // therefore eqns have no solutions.
95  if (nb >= e) {
96  table_[index(ie, inb)] = {0.0, 0.0, 0.0, 0.0};
97  continue;
98  }
99  // Take extrapolated (T, mub, mus) as initial approximation
100  std::array<double, 3> init_approx;
101  if (inb >= 2) {
102  const table_element y = table_[index(ie, inb - 2)];
103  const table_element x = table_[index(ie, inb - 1)];
104  init_approx = {2.0 * x.T - y.T, 2.0 * x.mub - y.mub,
105  2.0 * x.mus - y.mus};
106  } else {
107  init_approx = eos.solve_eos_initial_approximation(e, nb);
108  }
109  const std::array<double, 3> res = eos.solve_eos(e, nb, ns, init_approx);
110  const double T = res[0];
111  const double mub = res[1];
112  const double mus = res[2];
113  table_[index(ie, inb)] = {eos.pressure(T, mub, mus), T, mub, mus};
114  }
115  }
116  // Save table to file
117  std::cout << "Saving table to file " << eos_savefile_name << std::endl;
118  std::ofstream file;
119  file.open(eos_savefile_name, std::ios::out);
120  file << de_ << " " << dnb_ << std::endl;
121  file << n_e_ << " " << n_nb_ << std::endl;
122  file << std::setprecision(7);
123  file << std::fixed;
124  for (size_t ie = 0; ie < n_e_; ie++) {
125  for (size_t inb = 0; inb < n_nb_; inb++) {
126  const EosTable::table_element x = table_[index(ie, inb)];
127  file << x.p << " " << x.T << " " << x.mub << " " << x.mus << std::endl;
128  }
129  }
130  }
131 }
double dnb_
Step in net-baryon density.
Definition: hadgas_eos.h:93
size_t n_nb_
Number of steos in net-baryon density.
Definition: hadgas_eos.h:97
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
constexpr int p
Proton.
double de_
Step in energy density.
Definition: hadgas_eos.h:91
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

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

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

Definition at line 133 of file hadgas_eos.cc.

133  {
134  const size_t ie = static_cast<size_t>(std::floor(e / de_));
135  const size_t inb = static_cast<size_t>(std::floor(nb / dnb_));
136 
137  if (ie >= n_e_ - 1 || inb >= n_nb_ - 1) {
138  res = {-1.0, -1.0, -1.0, -1.0};
139  } else {
140  // 1st order interpolation
141  const double ae = e / de_ - ie;
142  const double an = nb / dnb_ - inb;
143  const EosTable::table_element s1 = table_[index(ie, inb)];
144  const EosTable::table_element s2 = table_[index(ie + 1, inb)];
145  const EosTable::table_element s3 = table_[index(ie, inb + 1)];
146  const EosTable::table_element s4 = table_[index(ie + 1, inb + 1)];
147  res.p = ae * (an * s4.p + (1.0 - an) * s2.p) +
148  (1.0 - ae) * (an * s3.p + (1.0 - an) * s1.p);
149  res.T = ae * (an * s4.T + (1.0 - an) * s2.T) +
150  (1.0 - ae) * (an * s3.T + (1.0 - an) * s1.T);
151  res.mub = ae * (an * s4.mub + (1.0 - an) * s2.mub) +
152  (1.0 - ae) * (an * s3.mub + (1.0 - an) * s1.mub);
153  res.mus = ae * (an * s4.mus + (1.0 - an) * s2.mus) +
154  (1.0 - ae) * (an * s3.mus + (1.0 - an) * s1.mus);
155  }
156 }
double dnb_
Step in net-baryon density.
Definition: hadgas_eos.h:93
size_t n_nb_
Number of steos in net-baryon density.
Definition: hadgas_eos.h:97
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 de_
Step in energy density.
Definition: hadgas_eos.h:91
std::vector< table_element > table_
Storage for the tabulated equation of state.
Definition: hadgas_eos.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ index()

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

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

Definition at line 87 of file hadgas_eos.h.

87 { return ie * n_nb_ + inb; }
size_t n_nb_
Number of steos in net-baryon density.
Definition: hadgas_eos.h:97
Here is the caller graph for this function:

Member Data Documentation

◆ table_

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

Storage for the tabulated equation of state.

Definition at line 89 of file hadgas_eos.h.

◆ de_

double smash::EosTable::de_
private

Step in energy density.

Definition at line 91 of file hadgas_eos.h.

◆ dnb_

double smash::EosTable::dnb_
private

Step in net-baryon density.

Definition at line 93 of file hadgas_eos.h.

◆ n_e_

size_t smash::EosTable::n_e_
private

Number of steps in energy density.

Definition at line 95 of file hadgas_eos.h.

◆ n_nb_

size_t smash::EosTable::n_nb_
private

Number of steos in net-baryon density.

Definition at line 97 of file hadgas_eos.h.


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