31 #include <boost/numeric/ublas/vector.hpp>
32 #include <o2scl/eos_had_apr.h>
33 #include <o2scl/table.h>
34 #include <o2scl/constants.h>
35 #include <o2scl/fermion_nonrel.h>
36 #include <o2scl/tov_solve.h>
37 #include <o2scl/deriv_cern.h>
38 #include <o2scl/mroot_cern.h>
39 #include <o2scl/test_mgr.h>
40 #include <o2scl/hdf_io.h>
43 using namespace o2scl;
44 using namespace o2scl_hdf;
45 using namespace o2scl_const;
46 using namespace o2scl_cgs;
127 static const int low_phase=1;
128 static const int mixed_phase=2;
129 static const int high_phase=3;
148 if (x[0]<0.0 || x[1]<0.0 || x[2]<0.0 || x[3]<0.0)
return 1;
151 ap.pion=eos_had_apr::ldp;
156 fzt.calc_mu_zerot(e);
157 fzt.calc_mu_zerot(mu);
163 ap.pion=eos_had_apr::hdp;
164 ap.calc_e(n2,p2,hb2);
168 fzt.calc_mu_zerot(e2);
169 fzt.calc_mu_zerot(mu2);
181 y[3]=p2.n-e2.n-mu2.n;
194 ap.pion=eos_had_apr::ldp;
199 fzt.calc_mu_zerot(e);
200 fzt.calc_mu_zerot(mu);
205 ap.pion=eos_had_apr::hdp;
206 ap.calc_e(n2,p2,hb2);
210 fzt.calc_mu_zerot(e2);
211 fzt.calc_mu_zerot(mu2);
216 y[0]=nb-chi*(n.n+p.n)-(1.0-chi)*(n2.n+p2.n);
220 y[4]=p2.n-e2.n-mu2.n;
235 ap.pion=eos_had_apr::ldp;
238 ap.pion=eos_had_apr::hdp;
239 ap.calc_e(n2,p2,hb2);
252 if (n.n<0.0 || p.n<0.0) {
256 ap.pion=eos_had_apr::ldp;
261 fzt.calc_mu_zerot(e);
262 fzt.calc_mu_zerot(mu);
281 if (n2.n<0.0 || p2.n<0.0)
return 1;
283 ap.pion=eos_had_apr::hdp;
284 ap.calc_e(n2,p2,hb2);
288 fzt.calc_mu_zerot(e);
289 fzt.calc_mu_zerot(mu);
312 if (phase==low_phase) chi=1.0;
313 else if (phase==high_phase) chi=0.0;
316 if (n.n<0.0 || n2.n<0.0)
return 1;
317 if (p.n<0.0 || p2.n<0.0)
return 1;
319 ap.pion=eos_had_apr::ldp;
322 ap.pion=eos_had_apr::hdp;
323 ap.calc_e(n2,p2,hb2);
325 fzt.calc_mu_zerot(e);
326 fzt.calc_mu_zerot(mu);
331 y[0]=nb-chi*(n.n+p.n)-(1.0-chi)*(n2.n+p2.n);
332 y[1]=chi*p.n+(1.0-chi)*p2.n-e.n-mu.n;
337 if (phase==mixed_phase) y[5]=hb.pr-hb2.pr;
339 if (phase==low_phase) {
342 }
else if (phase==mixed_phase) {
344 tot.ed=hb.ed*chi+hb2.ed*(1.0-chi)+l.ed;
356 std::vector<double> line;
357 line.push_back(tot.ed);
358 line.push_back(tot.pr);
360 line.push_back((chi*n.n+(1.0-chi)*n2.n));
361 line.push_back((chi*p.n+(1.0-chi)*p2.n));
364 line.push_back(n2.n);
365 line.push_back(p2.n);
368 line.push_back(mu.n);
369 line.push_back(n.mu);
370 line.push_back(p.mu);
371 line.push_back(e.mu);
372 line.push_back(mu.mu);
373 line.push_back(n.ms);
374 line.push_back(p.ms);
375 line.push_back(n2.ms);
376 line.push_back(p2.ms);
377 line.push_back(n.kf);
378 line.push_back(p.kf);
379 line.push_back(n2.kf);
380 line.push_back(p2.kf);
381 line.push_back(e.kf);
382 line.push_back(mu.kf);
383 if (line.size()!=at.get_ncolumns()) {
387 at.line_of_data(line.size(),line);
397 if (phase==low_phase) chi=1.0;
398 else if (phase==high_phase) chi=0.0;
401 if (n.n<0.0 || n2.n<0.0)
return 1;
406 ap.pion=eos_had_apr::ldp;
409 ap.pion=eos_had_apr::hdp;
410 ap.calc_e(n2,p2,hb2);
413 y[1]=nb-chi*(n.n+p.n)-(1.0-chi)*(n2.n+p2.n);
415 if (phase==mixed_phase) y[2]=hb.pr-hb2.pr;
417 if (phase==low_phase) {
420 }
else if (phase==mixed_phase) {
422 tot.ed=hb.ed*chi+hb2.ed*(1.0-chi);
438 if (phase==low_phase) chi=1.0;
439 else if (phase==high_phase) chi=0.0;
442 if (n.n<0.0 || n2.n<0.0)
return 1;
447 ap.pion=eos_had_apr::ldp;
450 ap.pion=eos_had_apr::hdp;
451 ap.calc_e(n2,p2,hb2);
454 y[1]=nb-chi*(n.n+p.n)-(1.0-chi)*(n2.n+p2.n);
456 if (phase==mixed_phase) y[2]=hb.pr-hb2.pr;
458 if (phase==low_phase) {
461 }
else if (phase==mixed_phase) {
463 tot.ed=hb.ed*chi+hb2.ed*(1.0-chi);
475 double nn1,np1,mun1,mup1;
476 double nn2,np2,mun2,mup2;
482 ap.pion=eos_had_apr::ldp;
491 ap.pion=eos_had_apr::ldp;
499 fzt.calc_mu_zerot(e);
506 ey[0]=(mun1-mun2)/1.0;
507 ey[1]=(th1.
pr-th2.
pr)/1.0;
509 if (nv>3)ey[3]=
barn-u*(np1+nn1)-(1.0-u)*nn2;
512 hb.ed=u*th1.
ed+(1.0-u)*th2.
ed;
513 tot.ed=u*th1.
ed+(1.0-u)*th2.
ed+e.ed;
517 ap.pion=eos_had_apr::ldp;
526 double nn1,np1,mun1,mup1;
527 double nn2,np2,mun2,mup2;
531 if (ex[0]<0.0 || ex[1]<0.0 || ex[2]<0.0 || ex[3]<0.0) {
537 ap.pion=eos_had_apr::ldp;
546 ap.pion=eos_had_apr::ldp;
554 fzt.calc_mu_zerot(e);
561 ey[0]=(mun1-mun2)/1.0;
562 ey[1]=(th1.
pr-th2.
pr)/1.0;
563 ey[2]=e.n-u*np1-(1.0-u)*np2;
564 ey[3]=(mup1-mup2)/1.0;
565 if (nv>4) ey[4]=
barn-u*(np1+nn1)-(1.0-u)*(nn2+np2);
568 hb.ed=u*th1.
ed+(1.0-u)*th2.
ed;
569 tot.ed=u*th1.
ed+(1.0-u)*th2.
ed+e.ed;
573 ap.pion=eos_had_apr::ldp;
583 n.init(939.0/hc_mev_fm,2.0);
584 p.init(939.0/hc_mev_fm,2.0);
585 n2.init(939.0/hc_mev_fm,2.0);
586 p2.init(939.0/hc_mev_fm,2.0);
599 n.non_interacting=
false;
600 p.non_interacting=
false;
601 n2.non_interacting=
false;
602 p2.non_interacting=
false;
604 at.inc_maxlines(2000);
614 std::string prefix=
"ex_eos_had_apr_";
615 cout <<
"Set output prefix to '" << prefix <<
"' ." << endl;
619 double nbstart, nb_end, dnb;
640 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
644 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
648 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
652 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
656 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
660 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
664 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
668 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
680 solver.tol_abs=1.0e-10;
681 solver.tol_rel=1.0e-12;
682 solver_trans_density.tol_abs=1.0e-10;
683 solver_trans_density.tol_rel=1.0e-12;
686 at.line_of_names(((
string)(
"ed pr nb "))+
687 "nn np nn1 np1 nn2 np2 chi ne nmu "+
689 "msn msp msn2 msp2 kfn kfp kfn2 kfp2 kfe kfmu");
690 at.set_unit(
"ed",
"1/fm^4");
691 at.set_unit(
"pr",
"1/fm^4");
692 at.set_unit(
"nb",
"1/fm^3");
693 at.set_unit(
"nn",
"1/fm^3");
694 at.set_unit(
"np",
"1/fm^3");
695 at.set_unit(
"nn1",
"1/fm^3");
696 at.set_unit(
"np1",
"1/fm^3");
697 at.set_unit(
"nn2",
"1/fm^3");
698 at.set_unit(
"np2",
"1/fm^3");
699 at.set_unit(
"ne",
"1/fm^3");
700 at.set_unit(
"nmu",
"1/fm^3");
701 at.set_unit(
"mun",
"1/fm");
702 at.set_unit(
"mup",
"1/fm");
703 at.set_unit(
"mue",
"1/fm");
704 at.set_unit(
"mumu",
"1/fm");
705 at.set_unit(
"msn",
"1/fm");
706 at.set_unit(
"msp",
"1/fm");
707 at.set_unit(
"msn2",
"1/fm");
708 at.set_unit(
"msp2",
"1/fm");
709 at.set_unit(
"kfn",
"1/fm");
710 at.set_unit(
"kfp",
"1/fm");
711 at.set_unit(
"kfn2",
"1/fm");
712 at.set_unit(
"kfp2",
"1/fm");
713 at.set_unit(
"kfe",
"1/fm");
714 at.set_unit(
"kfmu",
"1/fm");
720 ap.set_mroot(solver);
724 cout <<
"--------- Saturation properties --------------------\n" << endl;
725 cout <<
"n_0: " << ap.n0 <<
" fm^{-3}\nE_B: " << ap.eoa*
hc_mev_fm
726 <<
" MeV\nK: " << ap.comp*
hc_mev_fm <<
" MeV\nS: "
727 << ap.esym*
hc_mev_fm <<
" MeV\nM^{*}/M: " << ap.msom << endl;
728 t.
test_rel(ap.n0,0.1598371,1.0e-5,
"n0");
746 cout <<
"--------- Nuclear matter ---------------------------\n" << endl;
752 ap.pion=eos_had_apr::ldp;
755 for(nb=nbstart;nb<nb_switch;nb+=dnb) {
760 ret=ap.calc_e(n,p,hb);
776 for(nb=nb_switch;nb<=nb_end;nb+=dnb) {
778 if (phase!=mixed_phase) ret=solver.msolve(2,x,f_nucmixed);
779 else ret=solver.msolve(3,x,f_nucmixed);
782 O2SCL_ERR(
"Solving nuclear matter failed.",
786 if (hb.pr<hb2.pr && phase==low_phase) {
787 cout <<
"Mixed phase begins near nb=" << nb <<
" fm^{-3}." << endl;
792 }
else if (phase==mixed_phase && x[2]<0.0) {
793 cout <<
"Mixed phase ends near nb=" << nb <<
" fm^{-3}." << endl;
801 string fn1=((string)prefix)+
"nuc.o2";
802 hf.open_or_create(fn1);
805 cout <<
"Generated file '" << fn1 <<
"'." << endl;
812 cout <<
"--------- Neutron matter ---------------------------\n" << endl;
814 ap.pion=eos_had_apr::ldp;
822 for(nb=nbstart;nb<nb_switch;nb+=dnb) {
827 ret=ap.calc_e(n,p,hb);
844 for(nb=nb_switch;nb<=nb_end;nb+=dnb) {
846 if (phase!=mixed_phase) {
847 ret=solver.msolve(2,x,f_neutmixed);
849 ret=solver.msolve(3,x,f_neutmixed);
853 O2SCL_ERR(
"Solving neutron matter failed.",
857 if (hb.pr<hb2.pr && phase==low_phase) {
858 cout <<
"Mixed phase begins near nb=" << nb <<
" fm^{-3}." << endl;
863 }
else if (phase==mixed_phase && x[2]<0.0) {
864 cout <<
"Mixed phase ends near nb=" << nb <<
" fm^{-3}." << endl;
872 string fn2=((string)prefix)+
"neut.o2";
873 hf.open_or_create(fn2);
876 cout <<
"Generated file '" << fn2 <<
"'." << endl;
883 cout <<
"--------- Neutron star matter ----------------------\n" << endl;
885 cout <<
"Maxwell construction." << endl;
890 filenm+=
"fig7.1.txt";
891 fout.open(filenm.c_str());
892 fout.setf(ios::scientific);
894 for(f7x=0.5;f7x>=-0.001;f7x-=0.025) {
895 ret=solver.msolve(1,x,f_fig7fun);
899 fout << f7x <<
" " << x[0] << endl;
902 cout <<
"Generated file '" << filenm <<
"'." << endl;
911 solver.msolve(4,x,f_maxwell_fig7);
913 double nb_low=x[0]+x[1], nb_high=x[2]+x[3];
914 cout <<
"Mixed phase begins at nb=" << nb_low <<
" fm^{-3}." << endl;
915 cout <<
"Mixed phase ends at nb=" << nb_high <<
" fm^{-3}." << endl;
919 filenm+=
"fig7.2.txt";
920 fout.open(filenm.c_str());
924 for(nb=0.02;nb<nb_low*1.00001;nb+=(nb_low-nbstart)/20.0) {
925 ret=solver.msolve(1,x,f_nstar_low);
929 cout << x[0] <<
" " << y[0] << endl;
930 O2SCL_ERR(
"Solving Maxwell construction failed.",
933 fout << p.n/nb <<
" " << nb << endl;
938 x[0]=(1.0-0.07)*nb_low;
940 x[2]=(1.0-0.06)*nb_high;
943 dnb=(nb_high-nb_low)/20.0;
944 for(nb=nb_low+dnb;nb<=nb_high*1.00001;nb+=dnb) {
945 ret=solver.msolve(5,x,f_mixedmaxwell);
948 O2SCL_ERR(
"Solving Maxwell construction (part 2) failed.",
951 fout << (chi*p.n+(1.0-chi)*p2.n)/nb <<
" " << nb << endl;
957 for(nb=nb_high;nb<nb_end;nb+=(nb_end-nb_high)/40.0) {
958 ret=solver.msolve(1,x,f_nstar_high);
961 O2SCL_ERR(
"Solving Maxwell construction (part 3) failed.",
964 fout << p2.n/nb <<
" " << nb << endl;
967 cout <<
"Generated file '" << filenm <<
"'." << endl;
972 cout <<
"\nGibbs construction." << endl;
975 ap.pion=eos_had_apr::ldp;
980 for(nb=nbstart;nb<=0.1701;nb+=dnb) {
981 ret=solver.msolve(1,x,f_nstar_low);
984 O2SCL_ERR(
"Solving Gibbs construction failed.",
998 for(nb=0.17;nb<=nb_end;nb+=dnb) {
1000 if (phase!=mixed_phase) {
1001 ret=solver.msolve(5,x,f_nstar_mixed);
1004 ret=solver.msolve(6,x,f_nstar_mixed);
1010 if (hb.pr<hb2.pr && phase==low_phase) {
1011 cout <<
"Mixed phase begins at nb=" << nb <<
" fm^{-3}." << endl;
1015 }
else if (phase==mixed_phase && x[5]<0.0) {
1016 cout <<
"Mixed phase ends at nb=" << nb <<
" fm^{-3}." << endl;
1027 cout <<
"\nEstimate of transition density." << endl;
1033 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
1037 std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
1039 solver_trans_density.tol_abs/=1.0e4;
1040 solver_trans_density.tol_rel/=1.0e4;
1045 ret=solver_trans_density.msolve(3,newx,nuclei_f);
1047 nucleimat(3,newx,newy);
1048 if (fabs(newy[0])>1.0e-8 || fabs(newy[1])>1.0e-8 ||
1049 fabs(newy[2])>1.0e-8) {
1051 cout <<
"Problem in transition density (1)." << endl;
1053 cout << newx[0] <<
" " << newy[0] << endl;
1054 cout << newx[1] <<
" " << newy[1] << endl;
1055 cout << newx[2] <<
" " << newy[2] << endl;
1059 cout <<
"Without proton drip: density: " << newx[0]+newx[1]
1060 <<
" fm^{-3},\n pressure: "
1061 << at.interp(
"nb",newx[0]+newx[1],
"pr") <<
" fm^{-4}." << endl;
1063 solver_trans_density.tol_abs=5.0e-8;
1064 solver_trans_density.tol_rel=5.0e-8;
1067 ret=solver_trans_density.msolve(4,newx,nucleip_f);
1069 nucleimat_pdrip(4,newx,newy);
1070 if (fabs(newy[0])>1.0e-8 || fabs(newy[1])>1.0e-8 ||
1071 fabs(newy[2])>1.0e-8 || fabs(newy[3])>1.0e-8) {
1073 cout <<
"Problem in transition density (2)." << endl;
1075 cout << newx[0] <<
" " << newy[0] << endl;
1076 cout << newx[1] <<
" " << newy[1] << endl;
1077 cout << newx[2] <<
" " << newy[2] << endl;
1078 cout << newx[3] <<
" " << newy[3] << endl;
1082 nucleimat_pdrip(4,newx,newy);
1083 cout << newx[0] <<
" " << newy[0] << endl;
1084 cout << newx[1] <<
" " << newy[1] << endl;
1085 cout << newx[2] <<
" " << newy[2] << endl;
1086 cout << newx[3] <<
" " << newy[3] << endl;
1087 cout <<
"With proton drip: density: " << newx[0]+newx[1]
1088 <<
" fm^{-3},\n pressure: "
1089 << at.interp(
"nb",newx[0]+newx[1],
"pr") <<
" fm^{-4}." << endl;
1092 solver_trans_density.tol_abs=1.0e-16;
1093 solver_trans_density.tol_rel=1.0e-16;
1097 string fn3=((string)prefix)+
"nstar.o2";
1098 hf.open_or_create(fn3);
1101 cout <<
"Generated file '" << fn3 <<
"'." << endl;
1108 cout <<
"--------- TOV solver, M vs. R. ---------------------\n" << endl;
1114 atov.
set_units(
"1/fm^4",
"1/fm^4",
"1/fm^3");
1124 cout <<
"Maximum mass is " << tov_tmp->max(
"gm")
1125 <<
" solar masses." << endl;
1126 t.
test_rel(tov_tmp->max(
"gm"),2.191338,5.0e-4,
"max mass.");
1130 string fn4=((string)prefix)+
"mvsr.o2";
1131 hf.open_or_create(fn4);
1134 cout <<
"Generated file '" << fn4 <<
"'." << endl;
1137 cout <<
"--------- TOV solver, 1.4 Msun ---------------------\n" << endl;
1141 cout <<
"Aprpoximate radius of a 1.4 solar mass neutron star is "
1142 << tov_tmp2->get(
"r",tov_tmp2->lookup(
"gm",1.4)) <<
" km." << endl;
1143 t.
test_rel(tov_tmp2->get(
"r",tov_tmp2->lookup(
"gm",1.4)),11.46630,
1146 string fn5=((string)prefix)+
"m14.o2";
1147 hf.open_or_create(fn5);
1150 cout <<
"Generated file '" << fn5 <<
"'." << endl;
1162 cout.setf(ios::scientific);
void set_eos(eos_tov &ter)
Set the EOS to use.
virtual int mvsr()
Calculate the mass vs. radius curve.
thermo hb
Baryon thermodynamics for low-density phase.
double chi
Volume fraction of low-density phase.
int nstar_mixed(size_t nv, const ubvector &x, ubvector &y)
Solve for neutron star matter (mixed phase)
int fig7fun(size_t nv, const ubvector &x, ubvector &y)
Function to construct Fig. 7.
bool calc_gpot
calculate the gravitational potential and the enclosed baryon mass (default false) ...
virtual int fixed(double target_mass, double pmax=1.0e20)
Calculate the profile of a star with fixed mass.
void default_low_dens_eos()
Default crust EOS from Negele73 and Baym71.
fermion e2
Electron for high-density phase.
void run()
Main driver, computing the APR EOS and the associated M vs. R curve.
int choice
Choice of model from APR.
fermion p2
Proton for high-density phase.
thermo l2
Leptonic thermodynamics for high-density phase.
virtual double convert(std::string from, std::string to, double val)
fermion mu
Muon for low-density phase.
fermion p
Proton for low-density phase.
int verbose
control for output (default 1)
lib_settings_class o2scl_settings
thermo tot
Total thermodynamics.
void store_data()
Write a line of data to the table.
double muq
Charge chemical potential.
std::function< int(size_t, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &) > mm_funct11
int nstar_low(size_t nv, const ubvector &x, ubvector &y)
Solve for neutron star matter (low-density phase)
void hdf_output(hdf_file &hf, o2scl::table3d &h, std::string name)
fermion mu2
Muon for high-density phase.
void set_units(double s_efactor=1.0, double s_pfactor=1.0, double s_nbfactor=1.0)
Set output units for the table.
eos_had_apr ap
Base APR EOS.
int nucmixed(size_t nv, const ubvector &x, ubvector &y)
Solve for nuclear matter (mixed phase)
o2_shared_ptr< table_units<> >::type get_results()
Return the results data table.
void read_table(table_units<> &eosat, std::string s_cole, std::string s_colp, std::string s_colnb="")
Specify the EOS through a table.
fermion n2
Neutron for high-density phase.
table_units at
Table for output.
fermion e
Electron for low-density phase.
fermion n
Neutron for low-density phase.
double f7x
Proton fraction for Fig. 7.
mroot_hybrids solver
General solver.
int nucleimat_pdrip(size_t nv, const ubvector &ex, ubvector &ey)
Solve for phase transition to nuclei with a proton drip.
int nucleimat(size_t nv, const ubvector &ex, ubvector &ey)
Solve for phase transition to nuclei.
virtual const char * get_str()=0
int mixedmaxwell(size_t nv, const ubvector &x, ubvector &y)
Maxwell construction of the nuclear matter mixed phase.
An EOS for the TOV solver using simple linear interpolation and an optional crust EOS...
convert_units & get_convert_units()
Compute the APR EOS with a Gibbs construction and the mass versus radius curve [Example class]...
int maxwell_fig7(size_t nv, const ubvector &x, ubvector &y)
Function for the Maxwell construction in Fig. 7.
thermo hb2
Baryon thermodynamics for high-density phase.
Class to solve the Tolman-Oppenheimer-Volkov equations.
thermo l
Leptonic thermodynamics for low-density phase.
int nstar_high(size_t nv, const ubvector &x, ubvector &y)
Solve for neutron star matter (high-density phase)
double mub
Baryon chemical potential.
int neutmixed(size_t nv, const ubvector &x, ubvector &y)
Solve for neutron matter (mixed phase)
mroot_hybrids solver_trans_density
Solver for transition densities (lower tolerances)
hdf_file hf
HDF file for output.
EOS from Akmal, Pandharipande, and Ravenhall.
void set_output_level(int l)
int verbose
Control for output (default 1)
const double mass_electron
fermion_zerot fzt
Compute zero-temperature thermodynamics.
bool test_rel(double result, double expected, double rel_error, std::string description)
deriv_cern cd
Derivative object.