eos_had_tabulated.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file eos_had_tabulated.h
24  \brief File defining \ref o2scl::eos_had_tabulated
25 */
26 #ifndef O2SCL_TABULATED_EOS_H
27 #define O2SCL_TABULATED_EOS_H
28 
29 #include <cmath>
30 #include <o2scl/constants.h>
31 #include <o2scl/eos_had_base.h>
32 #include <o2scl/fermion.h>
33 #include <o2scl/eos_had_apr.h>
34 
35 #ifndef DOXYGEN_NO_O2NS
36 namespace o2scl {
37 #endif
38 
39  /** \brief Zero-temperature EOS from a table
40 
41  This assumes a symmetry energy which depends quadratically on
42  the isospin asymmetry in order to construct an EOS from
43  a table of baryon density and energy per baryon for both
44  nuclear and pure neutron matter.
45 
46  Note: If using a tabulated EOS to compute derivatives (like the
47  compressibility which effectively requires a second derivative),
48  it is important to tabulated the EOS precisely enough to ensure
49  that the derivatives are accurate. In the case of ensuring that
50  the compressibility at saturation density is reproduced to
51  within 3 significant figures, the EOS should be specified with
52  at least 6 digits of precision on a grid at least as small as
53  0.002 \f$ \mathrm{fm}^{-3} \f$.
54 
55  \future Storage in a \ref o2scl::table object isn't necessary, and
56  storing in a vector object is more efficient.
57  \future Allow the pressure to be specified to make the
58  EOS more accurate?
59  */
61 
62  protected:
63 
64  /// True if the table has been allocated
66 
67  /// \name The EOS tables
68  //@{
69  table<> *tnuc;
70  table<> *tneut;
71  //@}
72 
73  /// If true, then tnuc and tneut point to the same table
74  bool one_table;
75 
76  /// \name Strings for the column names
77  //@{
78  std::string srho_nuc, srho_neut, snuc, sneut;
79  //@}
80 
81  /// Free the table memory
82  void free_table() {
83  if (table_alloc) {
84  delete tnuc;
85  if (!one_table) delete tneut;
86  table_alloc=false;
87  }
88  return;
89  }
90 
91  public:
92 
94  table_alloc=false;
95  one_table=false;
96  }
97 
98  virtual ~eos_had_tabulated() {
99  if (table_alloc) {
100  delete tnuc;
101  if (!one_table) delete tneut;
102  }
103  }
104 
105  /** \brief Equation of state as a function of density
106  */
107  virtual int calc_e(fermion &ne, fermion &pr, thermo &th) {
108 
109  if (table_alloc==false) {
110  O2SCL_ERR("No EOS specified in eos_had_tabulated::calc_e().",
111  exc_einval);
112  }
113  double barn=ne.n+pr.n;
114  double xp=pr.n/barn;
115  double delta=(1.0-2.0*xp);
116 
117  // The energy density of nuclear matter
118  double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+
119  ne.m)*barn;
120  // The symmetry energy density
121  double edsym=(tneut->interp(srho_neut,barn,sneut)-
122  tnuc->interp(srho_nuc,barn,snuc))/
124  // The total energy density
125  th.ed=ednuc+delta*delta*edsym;
126 
127  // The derivatives of the energy densities wrt the baryon density
128  double dednucdn=tnuc->deriv(srho_nuc,barn,snuc)/
129  o2scl_const::hc_mev_fm*barn+ednuc/barn;
130  double dedsymdn=barn*(tneut->deriv(srho_neut,barn,sneut)-
131  tnuc->deriv(srho_nuc,barn,snuc))/
132  o2scl_const::hc_mev_fm+edsym/barn;
133 
134  // The chemical potentials
135  ne.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*xp/barn;
136  pr.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*(xp-1.0)/barn;
137 
138  // The pressure
139  th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu;
140 
141  return 0;
142  }
143 
144  /** \brief Set the EOS through vectors specifying the densities and
145  energies
146  */
147  template <class vec_t>
148  int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut) {
149 
150  free_table();
151 
152  tnuc=new table<>(n);
153  tnuc->line_of_names("rho nuc neut");
154  srho_nuc="rho";
155  srho_neut="rho";
156  snuc="nuc";
157  sneut="neut";
158  for(size_t i=0;i<n;i++) {
159  double line[3]={rho[i],Enuc[i],Eneut[i]};
160  tnuc->line_of_data(3,line);
161  }
162  tneut=tnuc;
163  table_alloc=true;
164  one_table=true;
165 
166  return 0;
167  }
168 
169  /** \brief Set the EOS through vectors specifying the densities and
170  energies
171  */
172  template<class vec_t>
173  int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc,
174  size_t n_neut, vec_t &rho_neut, vec_t &E_neut) {
175 
176  free_table();
177 
178  tnuc=new table<>(n_nuc);
179  tneut=new table<>(n_neut);
180  tnuc->line_of_names("rho nuc");
181  tneut->line_of_names("rho neut");
182  srho_nuc="rho";
183  srho_neut="rho";
184  snuc="nuc";
185  sneut="neut";
186  for(size_t i=0;i<n_nuc;i++) {
187  double line[2]={rho_nuc[i],E_nuc[i]};
188  tnuc->line_of_data(2,line);
189  }
190  for(size_t i=0;i<n_neut;i++) {
191  double line[2]={rho_neut[i],E_neut[i]};
192  tneut->line_of_data(2,line);
193  }
194  table_alloc=true;
195  return 0;
196  }
197 
198  /// Return the internal table
200  return *tnuc;
201  }
202 
203  /// Return the internal table
205  return *tneut;
206  }
207 
208  };
209 
210 #ifndef DOXYGEN_NO_O2NS
211 }
212 #endif
213 
214 #endif
void deriv(std::string x, std::string y, std::string yp)
bool table_alloc
True if the table has been allocated.
void free_table()
Free the table memory.
const double barn
exc_einval
const double hc_mev_fm
int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut)
Set the EOS through vectors specifying the densities and energies.
Zero-temperature EOS from a table.
int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc, size_t n_neut, vec_t &rho_neut, vec_t &E_neut)
Set the EOS through vectors specifying the densities and energies.
double interp(std::string sx, double x0, std::string sy)
void line_of_names(std::string newheads)
A hadronic EOS based on a function of the densities [abstract base].
Definition: eos_had_base.h:932
virtual int calc_e(fermion &ne, fermion &pr, thermo &th)
Equation of state as a function of density.
table & get_neut_table()
Return the internal table.
#define O2SCL_ERR(d, n)
void line_of_data(size_t nv, const vec2_t &v)
bool one_table
If true, then tnuc and tneut point to the same table.
table & get_nuc_table()
Return the internal table.

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).