classical.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2020, 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 #ifndef O2SCL_CLASSICAL_H
24 #define O2SCL_CLASSICAL_H
25 
26 /** \file classical.h
27  \brief File defining \ref o2scl::classical_thermo_tl
28 */
29 
30 #include <string>
31 #include <iostream>
32 #include <fstream>
33 #include <cmath>
34 
35 #include <boost/math/constants/constants.hpp>
36 
37 #include <o2scl/constants.h>
38 #include <o2scl/mroot.h>
39 #include <o2scl/inte.h>
40 #include <o2scl/part.h>
41 
42 #ifndef DOXYGEN_NO_O2NS
43 namespace o2scl {
44 #endif
45 
46  /** \brief Classical particle class
47 
48  \note Note that it makes no sense to include
49  \f$ T=0 \f$ functions here
50  */
51  template<class fp_t=double> class classical_thermo_tl {
52 
53  protected:
54 
55  /// Desc
56  fp_t pi;
57 
58  public:
59 
60  /** \brief Create a classical particle with mass \c m
61  and degeneracy \c g
62 
63  \note This class attempts to handle zero temperature limit
64  somewhat gracefully, even though the classical limit doesn't
65  necessarily make physical sense there.
66  */
68  pi=boost::math::constants::pi<fp_t>();
69  }
70 
71  virtual ~classical_thermo_tl() {
72  }
73 
74  /** \brief Calculate properties as function of chemical potential
75 
76  If the temperature is less than zero, the error handler will
77  be called.
78  */
79  virtual void calc_mu(part_tl<fp_t> &p, fp_t temper) {
80 
81  if (temper<0.0) {
82  O2SCL_ERR2("Temperature less than zero in ",
83  "classical_thermo::calc_mu().",exc_einval);
84  }
85 
86  if (p.non_interacting==true) { p.nu=p.mu; p.ms=p.m; }
87 
88  // Handle zero temperature case
89  if (temper==0.0) {
90  if (p.inc_rest_mass) {
91  p.n=0.0;
92  p.ed=p.n*p.m;
93  } else {
94  p.n=0.0;
95  p.ed=0.0;
96  }
97  p.pr=0.0;
98  p.en=0.0;
99  return;
100  }
101 
102  if (p.inc_rest_mass) {
103  if ((p.nu-p.m)/temper<std::numeric_limits<fp_t>::min_exponent10) {
104  p.n=0.0;
105  } else {
106  p.n=exp((p.nu-p.m)/temper)*p.g*pow(p.ms*temper/o2scl_const::pi/2.0,1.5);
107  }
108  p.ed=1.5*temper*p.n+p.n*p.m;
109  } else {
110  if (p.nu/temper<std::numeric_limits<fp_t>::min_exponent10) {
111  p.n=0.0;
112  } else {
113  p.n=exp(p.nu/temper)*p.g*pow(p.ms*temper/o2scl_const::pi/2.0,1.5);
114  }
115  p.ed=1.5*temper*p.n;
116  }
117  p.pr=p.n*temper;
118  p.en=(p.ed+p.pr-p.n*p.nu)/temper;
119  return;
120  }
121 
122 
123  /** \brief Calculate properties as function of density
124 
125  If the density or the temperature is less than zero, the error
126  handler will be called. In the case of zero density, the
127  chemical potential is set to the mass and the energy density,
128  pressure, and entropy are set to zero.
129  */
130  virtual void calc_density(part_tl<fp_t> &p, fp_t temper) {
131 
132  if (p.n<0.0 || temper<0.0) {
133  O2SCL_ERR2("Density or temperature less than zero in ",
134  "classical_thermo::calc_density().",exc_einval);
135  }
136 
137  if (p.non_interacting==true) { p.ms=p.m; }
138 
139  // Handle zero density first
140  if (p.n==0.0) {
141  if (p.inc_rest_mass) {
142  p.nu=p.m;
143  } else {
144  p.nu=0.0;
145  }
146  if (p.non_interacting==true) { p.mu=p.nu; }
147  p.ed=0.0;
148  p.pr=0.0;
149  p.en=0.0;
150  return;
151  }
152 
153  // Handle the zero temperature case
154  if (temper==0.0) {
155  if (p.inc_rest_mass) {
156  p.nu=p.m;
157  p.ed=p.n*p.m;
158  } else {
159  p.nu=0.0;
160  p.ed=0.0;
161  }
162  p.pr=0.0;
163  p.en=0.0;
164  return;
165  }
166 
167  if (p.inc_rest_mass) {
168  p.nu=p.m+temper*log(p.n/p.g*pow(2.0*o2scl_const::pi/p.ms/temper,1.5));
169  p.ed=1.5*temper*p.n+p.n*p.m;
170  } else {
171  p.nu=temper*log(p.n/p.g*pow(2.0*o2scl_const::pi/p.ms/temper,1.5));
172  p.ed=1.5*temper*p.n;
173  }
174 
175  if (p.non_interacting==true) { p.mu=p.nu; }
176 
177  p.pr=p.n*temper;
178  p.en=(p.ed+p.pr-p.n*p.nu)/temper;
179 
180  return;
181  }
182 
183 
184  /// Return string denoting type ("classical_thermo")
185  virtual const char *type() { return "classical_thermo"; }
186 
187  };
188 
189  /** \brief Double-precision version of \ref o2scl::classical_thermo_tl
190  */
192 
193 #ifndef DOXYGEN_NO_O2NS
194 }
195 #endif
196 
197 #endif
o2scl::part_tl
Particle base class.
Definition: part.h:103
o2scl::classical_thermo_tl::calc_density
virtual void calc_density(part_tl< fp_t > &p, fp_t temper)
Calculate properties as function of density.
Definition: classical.h:130
o2scl::classical_thermo_tl::classical_thermo_tl
classical_thermo_tl()
Create a classical particle with mass m and degeneracy g.
Definition: classical.h:67
o2scl::part_tl::mu
fp_t mu
Chemical potential.
Definition: part.h:118
o2scl::part_tl::ms
fp_t ms
Effective mass (Dirac unless otherwise specified)
Definition: part.h:122
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
o2scl::part_tl::n
fp_t n
Number density.
Definition: part.h:112
o2scl_const::pi
const double pi
o2scl::part_tl::non_interacting
bool non_interacting
True if the particle is non-interacting (default true)
Definition: part.h:130
o2scl::part_tl::en
fp_t en
Entropy density.
Definition: part.h:120
o2scl::part_tl::g
fp_t g
Degeneracy (e.g. spin and color if applicable)
Definition: part.h:108
o2scl::part_tl::ed
fp_t ed
Energy density.
Definition: part.h:114
exc_einval
exc_einval
o2scl::part_tl::inc_rest_mass
bool inc_rest_mass
If true, include the mass in the energy density and chemical potential (default true)
Definition: part.h:128
o2scl::classical_thermo_tl::type
virtual const char * type()
Return string denoting type ("classical_thermo")
Definition: classical.h:185
o2scl::part_tl::m
fp_t m
Mass.
Definition: part.h:110
o2scl::part_tl::pr
fp_t pr
Pressure.
Definition: part.h:116
o2scl::classical_thermo_tl::calc_mu
virtual void calc_mu(part_tl< fp_t > &p, fp_t temper)
Calculate properties as function of chemical potential.
Definition: classical.h:79
o2scl::classical_thermo_tl
Classical particle class.
Definition: classical.h:51
o2scl::classical_thermo_tl::pi
fp_t pi
Desc.
Definition: classical.h:56
o2scl::part_tl::nu
fp_t nu
Effective chemical potential.
Definition: part.h:124

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