All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
eos_had_tabulated.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, 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 well reproduced, I
51  have needed the EOS to be specified with at least 6 digits of
52  precision on a grid at least as small as 0.002
53  \f$ \mathrm{fm}^{-3} \f$.
54  */
56 
57  protected:
58 
59  /// True if the table has been allocated
61 
62  /// \name The EOS tables
63  //@{
64  table<> *tnuc;
65  table<> *tneut;
66  //@}
67 
68  /// If true, then tnuc and tneut point to the same table
69  bool one_table;
70 
71  /// \name Strings for the column names
72  //@{
73  std::string srho_nuc, srho_neut, snuc, sneut;
74  //@}
75 
76  /// Free the table memory
77  void free_table() {
78  if (table_alloc) {
79  delete tnuc;
80  if (!one_table) delete tneut;
81  table_alloc=false;
82  }
83  return;
84  }
85 
86  public:
87 
89  table_alloc=false;
90  one_table=false;
91  }
92 
93  virtual ~eos_had_tabulated() {
94  if (table_alloc) {
95  delete tnuc;
96  if (!one_table) delete tneut;
97  }
98  }
99 
100  /** \brief Equation of state as a function of density
101  */
102  virtual int calc_e(fermion &ne, fermion &pr, thermo &th) {
103 
104  if (table_alloc==false) {
105  O2SCL_ERR("No EOS specified in eos_had_tabulated::calc_e().",
106  exc_einval);
107  }
108  double barn=ne.n+pr.n;
109  double xp=pr.n/barn;
110  double delta=(1.0-2.0*xp);
111 
112  // The energy density of nuclear matter
113  double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+
114  ne.m)*barn;
115  // The symmetry energy density
116  double edsym=(tneut->interp(srho_neut,barn,sneut)-
117  tnuc->interp(srho_nuc,barn,snuc))/
119  // The total energy density
120  th.ed=ednuc+delta*delta*edsym;
121 
122  // The derivatives of the energy densities wrt the baryon density
123  double dednucdn=tnuc->deriv(srho_nuc,barn,snuc)/
124  o2scl_const::hc_mev_fm*barn+ednuc/barn;
125  double dedsymdn=barn*(tneut->deriv(srho_neut,barn,sneut)-
126  tnuc->deriv(srho_nuc,barn,snuc))/
127  o2scl_const::hc_mev_fm+edsym/barn;
128 
129  // The chemical potentials
130  ne.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*xp/barn;
131  pr.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*(xp-1.0)/barn;
132 
133  // The pressure
134  th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu;
135 
136  return 0;
137  }
138 
139  /** \brief Set the EOS through vectors specifying the densities and
140  energies
141  */
142  template <class vec_t>
143  int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut) {
144 
145  free_table();
146 
147  tnuc=new table<>(n);
148  tnuc->line_of_names("rho nuc neut");
149  srho_nuc="rho";
150  srho_neut="rho";
151  snuc="nuc";
152  sneut="neut";
153  for(size_t i=0;i<n;i++) {
154  double line[3]={rho[i],Enuc[i],Eneut[i]};
155  tnuc->line_of_data(3,line);
156  }
157  tneut=tnuc;
158  table_alloc=true;
159  one_table=true;
160 
161  return 0;
162  }
163 
164  /** \brief Set the EOS through vectors specifying the densities and
165  energies
166  */
167  template<class vec_t>
168  int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc,
169  size_t n_neut, vec_t &rho_neut, vec_t &E_neut) {
170 
171  free_table();
172 
173  tnuc=new table<>(n_nuc);
174  tneut=new table<>(n_neut);
175  tnuc->line_of_names("rho nuc");
176  tneut->line_of_names("rho neut");
177  srho_nuc="rho";
178  srho_neut="rho";
179  snuc="nuc";
180  sneut="neut";
181  for(size_t i=0;i<n_nuc;i++) {
182  double line[2]={rho_nuc[i],E_nuc[i]};
183  tnuc->line_of_data(2,line);
184  }
185  for(size_t i=0;i<n_neut;i++) {
186  double line[2]={rho_neut[i],E_neut[i]};
187  tneut->line_of_data(2,line);
188  }
189  table_alloc=true;
190  return 0;
191  }
192 
193  /// Return the internal table
195  return *tnuc;
196  }
197 
198  /// Return the internal table
200  return *tneut;
201  }
202 
203  };
204 
205 #ifndef DOXYGEN_NO_O2NS
206 }
207 #endif
208 
209 #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
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:825
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).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..