Thermal-FIST 1.6
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
ZeroTemperatureComparison.cpp
Go to the documentation of this file.
1/*
2 * Thermal-FIST package
3 *
4 * Copyright (c) 2026 Volodymyr Vovchenko
5 *
6 * GNU General Public License (GPLv3 or later)
7 */
8
20#include <cmath>
21#include <cstdlib>
22#include <functional>
23#include <iomanip>
24#include <iostream>
25#include <limits>
26#include <memory>
27#include <string>
28#include <vector>
29
30#include "HRGBase.h"
31#include "HRGEV.h"
32#include "HRGRealGas.h"
33#include "HRGVDW.h"
35#include "ThermalFISTConfig.h"
36
37using namespace std;
38
39#ifdef ThermalFIST_USENAMESPACE
40using namespace thermalfist;
41#endif
42
43// -------------------------------------------------------------------
44// Collect all quantities at one (T, muB) point
45// -------------------------------------------------------------------
46struct ThermoRow {
47 double T;
48 double P, e, s, rhoB, rhoQ;
49 double cs2_B, cT2_B;
50 double cs2_BQ, cT2_BQ;
51 double cMu; // C_mu = T ds/dT|_mu (heat capacity at fixed mu)
52 double dsdT_mu; // ds/dT|_mu (= C_mu/T for T>0, Sommerfeld for T=0)
53 double chi2BB; // baryon number susceptibility d^2P/dmuB^2 [GeV^-2]
54 double chi3BB; // baryon number susceptibility d^3P/dmuB^3 [GeV^-3]
55 double chi4BB; // baryon number susceptibility d^4P/dmuB^4 [GeV^-4]
56};
57
58static ThermoRow Evaluate(ThermalModelBase* model) {
59 ThermoRow r;
60 r.T = model->Parameters().T;
61
63 model->CalculateFluctuations();
65
66 r.P = model->Pressure();
67 r.e = model->EnergyDensity();
68 r.s = model->EntropyDensity();
69 r.rhoB = model->BaryonDensity();
70 r.rhoQ = model->ElectricChargeDensity();
71
72 auto safe = [](double v) { return std::isfinite(v) ? v : std::numeric_limits<double>::quiet_NaN(); };
73 r.cs2_B = safe(model->cs2(true, false, false, false));
74 r.cT2_B = safe(model->cT2(true, false, false, false));
75 r.cs2_BQ = safe(model->cs2(true, true, false, false));
76 r.cT2_BQ = safe(model->cT2(true, true, false, false));
77
78 r.cMu = model->HeatCapacityMu();
79
80 r.dsdT_mu = model->CalculateEntropyDensityDerivativeT();
81
84
85 // chi3BB via CalculateChargeFluctuations with dimensionfull=true
86 // Returns d^3P/dmuB^3 in [GeV^{-2}] units (natural units)
87 {
88 vector<double> chargesB(model->TPS()->ComponentsNumber());
89 for (int i = 0; i < model->TPS()->ComponentsNumber(); ++i)
90 chargesB[i] = model->TPS()->Particles()[i].BaryonCharge();
91
92 auto chis = model->CalculateChargeFluctuations(chargesB, 4, true);
93 r.chi3BB = chis[2] * xMath::GeVtoifm3();
94 r.chi4BB = chis[3] * xMath::GeVtoifm3();
95 }
96
97 return r;
98}
99
100
101// -------------------------------------------------------------------
102// Print table for one model
103// -------------------------------------------------------------------
104static void PrintTable(const string& modelName,
105 ThermalModelBase* model,
106 double muB,
107 const vector<double>& Tvals)
108{
109 model->SetBaryonChemicalPotential(muB);
112 model->SetCharmChemicalPotential(0.);
113
114 // Collect rows
115 vector<ThermoRow> rows;
116 for (double T : Tvals) {
117 model->SetTemperature(T);
118 rows.push_back(Evaluate(model));
119 }
120
121 // Print
122 const int w = 16;
123 const int wlab = 22;
124 cout << "\n";
125 cout << "================================================================\n";
126 cout << " " << modelName << " muB = " << muB << " GeV\n";
127 cout << "================================================================\n";
128
129 // Header
130 cout << setw(wlab) << left << "Quantity";
131 for (auto& r : rows)
132 cout << setw(w) << right << (r.T == 0. ? "T=0" :
133 r.T == 1.e-6 ? "T=0.001MeV" :
134 r.T == 1.e-5 ? "T=0.01MeV" :
135 r.T == 1.e-4 ? "T=0.1MeV" :
136 r.T == 1.e-3 ? "T=1MeV" :
137 r.T == 1.e-2 ? "T=10MeV" : "T=?");
138 cout << "\n";
139 cout << string(wlab + w * rows.size(), '-') << "\n";
140
141 typedef std::function<double(const ThermoRow&)> RowGetter;
142 auto line = [&](const char* label, RowGetter getter) {
143 cout << setw(wlab) << left << label;
144 for (size_t i = 0; i < rows.size(); ++i)
145 cout << setw(w) << right << scientific << setprecision(6) << getter(rows[i]);
146 cout << "\n";
147 };
148
149 line("P [GeV/fm3]", [](const ThermoRow& r){ return r.P; });
150 line("e [GeV/fm3]", [](const ThermoRow& r){ return r.e; });
151 line("s [fm-3]", [](const ThermoRow& r){ return r.s; });
152 line("rhoB [fm-3]", [](const ThermoRow& r){ return r.rhoB; });
153 line("rhoQ [fm-3]", [](const ThermoRow& r){ return r.rhoQ; });
154 line("chi2_BB [fm-3]", [](const ThermoRow& r){ return r.chi2BB; });
155 line("chi3_BB [fm-3GeV-1]",[](const ThermoRow& r){ return r.chi3BB; });
156 line("chi4_BB [fm-3GeV-2]",[](const ThermoRow& r){ return r.chi4BB; });
157 line("cs2(B)", [](const ThermoRow& r){ return r.cs2_B; });
158 line("cT2(B)", [](const ThermoRow& r){ return r.cT2_B; });
159 line("cs2(BQ)", [](const ThermoRow& r){ return r.cs2_BQ; });
160 line("cT2(BQ)", [](const ThermoRow& r){ return r.cT2_BQ; });
161 line("C_mu [fm-3]", [](const ThermoRow& r){ return r.cMu; });
162 line("ds/dT|mu [fm-3/GeV]", [](const ThermoRow& r){ return r.dsdT_mu; });
163
164 // Relative deviations from T=0
165 if (rows.size() > 1) {
166 const auto& ref = rows[0];
167 cout << "\n Relative deviations from T=0:\n";
168 cout << string(wlab + w * rows.size(), '-') << "\n";
169
170 auto relline = [&](const char* label, RowGetter getter) {
171 double refv = getter(ref);
172 cout << setw(wlab) << left << label;
173 for (size_t i = 0; i < rows.size(); ++i) {
174 if (i == 0) { cout << setw(w) << right << "---"; continue; }
175 double v = getter(rows[i]);
176 if (std::isfinite(v) && std::isfinite(refv) && std::abs(refv) > 1.e-30)
177 cout << setw(w) << right << scientific << setprecision(3) << (v - refv) / refv;
178 else
179 cout << setw(w) << right << "n/a";
180 }
181 cout << "\n";
182 };
183
184 relline("dP/P", [](const ThermoRow& r){ return r.P; });
185 relline("de/e", [](const ThermoRow& r){ return r.e; });
186 relline("drhoB/rhoB", [](const ThermoRow& r){ return r.rhoB; });
187 relline("dchi3/chi3(B)", [](const ThermoRow& r){ return r.chi3BB; });
188 relline("dchi4/chi4(B)", [](const ThermoRow& r){ return r.chi4BB; });
189 relline("dcs2/cs2(B)", [](const ThermoRow& r){ return r.cs2_B; });
190 relline("dcT2/cT2(B)", [](const ThermoRow& r){ return r.cT2_B; });
191 relline("d(dsdT)/dsdT", [](const ThermoRow& r){ return r.dsdT_mu; });
192 }
193
194 cout << "\n";
195}
196
197// -------------------------------------------------------------------
198// main
199// -------------------------------------------------------------------
200int main(int argc, char *argv[])
201{
202 double muB = 1.2;
203 if (argc > 1) muB = atof(argv[1]);
204
205 cout << "Zero-temperature comparison at muB = " << muB << " GeV\n";
206 cout << "Temperatures: 0, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2 GeV\n";
207
208 string inputDir = string(ThermalFIST_INPUT_FOLDER);
209 ThermalParticleSystem tps(inputDir + "/list/PDG2025/list.dat");
210
211 const vector<double> Tvals = {0., 1.e-6, 1.e-5, 1.e-4, 1.e-3, 1.e-2};
212
213 // --- 1) Ideal HRG ---
214 {
215 ThermalModelIdeal model(&tps);
216 model.SetStatistics(true);
217 model.SetUseWidth(false);
219 PrintTable("Ideal HRG", &model, muB, Tvals);
220 }
221
222 // --- 2) EV-Diagonal HRG ---
223 {
224 ThermalModelEVDiagonal model(&tps);
225 model.SetStatistics(true);
226 model.SetUseWidth(false);
228 double b = 1.0;
229 for (int i = 0; i < tps.ComponentsNumber(); ++i)
230 for (int j = 0; j < tps.ComponentsNumber(); ++j)
231 if (tps.Particle(i).BaryonCharge() != 0 && tps.Particle(j).BaryonCharge() != 0)
232 model.SetVirial(i, j, b);
233 PrintTable("EV-Diagonal HRG (b=1 fm3)", &model, muB, Tvals);
234 }
235
236 // --- 3) QvdW HRG ---
237 {
238 ThermalModelVDW model(&tps);
239 model.SetStatistics(true);
240 model.SetUseWidth(false);
242 SetVDWHRGInteractionParameters(&model, 0.329, 3.42);
243 PrintTable("QvdW HRG (a=0.329, b=3.42)", &model, muB, Tvals);
244 }
245
246 // --- 4) RealGas HRG (CS + VDW MF) ---
247 {
248 ThermalModelRealGas model(&tps);
249 model.SetStatistics(true);
250 model.SetUseWidth(false);
252
253 double a = 0.329, b = 3.42;
254 {
256 auto bij = GetBaryonBaryonInteractionMatrix(model.TPS(), b);
258 }
259 {
260 auto aij = GetBaryonBaryonInteractionMatrix(model.TPS(), a);
262 }
263 PrintTable("RealGas HRG (CS+VDW, a=0.329, b=3.42)", &model, muB, Tvals);
264 }
265
266 return 0;
267}
Contains some functions to deal with excluded volumes.
int main()
Base class implementing the ideal gas.
Class implementing auxiliary functions for the Carnahan-Starling excluded volume model.
Implementation of a crossterms generalized excluded volume model.
Implementation of the van der Waals mean field model for multiple components.
Abstract base class for an HRG model implementation.
virtual void SetTemperature(double T)
Set the temperature.
virtual void CalculateFluctuations()
Computes the fluctuation observables.
virtual std::vector< double > CalculateChargeFluctuations(const std::vector< double > &chgs, int order=4, bool dimensionfull=false)
Calculates fluctuations (diagonal susceptibilities) of an arbitrary "conserved" charge.
virtual void CalculateTemperatureDerivatives()
Computes the temperature derivatives of densities, shifted chemical potentials, and primordial hadron...
void SetUseWidth(bool useWidth)
Sets whether finite resonance widths are used. Deprecated.
virtual void SetBaryonChemicalPotential(double muB)
Set the baryon chemical potential.
virtual double SusceptibilityDimensionfull(ConservedCharge::Name i, ConservedCharge::Name j) const
A 2nd order susceptibility of conserved charges.
virtual void SetElectricChemicalPotential(double muQ)
Set the electric chemical potential.
int ComponentsNumber() const
Number of different particle species in the list.
virtual void CalculatePrimordialDensities()=0
Calculates the primordial densities of all species.
virtual void SetStrangenessChemicalPotential(double muS)
Set the strangeness chemical potential.
virtual void SetCalculationType(IdealGasFunctions::QStatsCalculationType type)
Sets the CalculationType() method to evaluate quantum statistics. Calls the corresponding method in T...
const ThermalModelParameters & Parameters() const
virtual void SetCharmChemicalPotential(double muC)
Set the charm chemical potential.
virtual void SetStatistics(bool stats)
Class implementing the diagonal excluded-volume model.
void SetVirial(int i, int j, double b)
Sets the eigenvolume parameter of particle species i.
Class implementing the Ideal HRG model.
Class implementing the quantum real gas HRG model.
void SetExcludedVolumeModel(ExcludedVolumeModelMultiBase *exvolmod)
Set the excluded volume model for the real gas HRG model.
void SetMeanFieldModel(MeanFieldModelMultiBase *mfmod)
Set the mean field model for the real gas HRG model.
Class implementing the quantum van der Waals HRG model.
int BaryonCharge() const
Particle's baryon number.
Class containing the particle list.
const ThermalParticle & Particle(int id) const
ThermalParticle object corresponding to particle species with a provided 0-based index.
int ComponentsNumber() const
Number of different particle species in the list.
constexpr double GeVtoifm3()
A constant to transform GeV into fm .
Definition xMath.h:31
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9
std::vector< std::vector< double > > GetBaryonBaryonInteractionMatrix(const ThermalParticleSystem *TPS, double param)
Returns the matrix of attraction and repulsion parameters for baryon-baryon and antibaryon-antibaryon...
void SetVDWHRGInteractionParameters(ThermalModelBase *model, double a, double b)
Sets vdW interactions for baryon-baryon and antibaryon-antibaryon pairs as in https://arxiv....