Particles and Nuclei Sub-Library: Version 0.910
Example Source Code

Example list

Particle example

/* Example: ex_part.cpp
   -------------------------------------------------------------------
*/

#include <cmath>
#include <o2scl/test_mgr.h>
#include <o2scl/constants.h>
#include <o2scl/eff_fermion.h>
#include <o2scl/rel_fermion.h>
#include <o2scl/classical.h>

using namespace std;
using namespace o2scl;
using namespace o2scl_const;

int main(void) {
  test_mgr t;
  t.set_output_level(1);

  // Compare the method from rel_fermion to the more approximate
  // scheme used in eff_fermion. We work in units of inverse Fermis,
  // so that energy density is fm^{-4}. We also use a classical
  // particle, to compare to the nondegenerate approximation.
  eff_fermion eff;
  rel_fermion relf;
  classical cla;
  
  fermion e(o2scl_fm::mass_electron,2.0);
  fermion e2(o2scl_fm::mass_electron,2.0);
  fermion e3(o2scl_fm::mass_electron,2.0);

  // Compute the pressure at a density of 0.0001 fm^{-3} and a
  // temperature of 10 MeV. At these temperatures, the electrons are
  // non-degenerate, and Boltzmann statistics nearly applies.
  e.n=0.0001;
  eff.calc_density(e,10.0/hc_mev_fm);
  e2.n=0.0001;
  relf.calc_density(e2,10.0/hc_mev_fm);
  e3.n=0.0001;
  cla.calc_density(e3,10.0/hc_mev_fm);

  cout << e.pr << " " << e2.pr << " " << e3.pr << " "
       << e.n*10.0/hc_mev_fm << endl;

  // Test
  t.test_rel(e.pr,e2.pr,1.0e-2,"EFF vs. exact");
  t.test_rel(e2.pr,e3.pr,4.0e-1,"classical vs. exact");
  t.test_rel(e.n*10.0/hc_mev_fm,e3.pr,1.0e-1,"classical vs. ideal gas law");

  // Compute the pressure at a density of 0.1 fm^{-3} and a
  // temperature of 1 MeV. At these temperatures, the electrons are
  // strongly degenerate
  e.n=0.0001;
  eff.calc_density(e,10.0/hc_mev_fm);
  e2.n=0.0001;
  relf.calc_density(e2,10.0/hc_mev_fm);
  cout << e.pr << " " << e2.pr << endl;

  // Test
  t.test_rel(e.pr,e2.pr,1.0e-2,"EFF vs. exact");

  // Now add the contribution to the pressure from positrons using the
  // implmentation of part::pair_density()
  e.n=0.0001;
  eff.pair_density(e,10.0/hc_mev_fm);
  e2.n=0.0001;
  relf.pair_density(e2,10.0/hc_mev_fm);
  cout << e.pr << " " << e2.pr << endl;

  // Test
  t.test_rel(e.pr,e2.pr,1.0e-2,"EFF vs. exact");

  t.report();
  return 0;
}
// End of example

Nuclear mass fit example

/* Example: ex_mass_fit.cpp
   -------------------------------------------------------------------
*/

#include <iostream>
#include <o2scl/test_mgr.h>
#include <o2scl/mass_fit.h>
#ifdef O2SCL_HDF_IN_EXAMPLES
#include <o2scl/hdf_file.h>
#include <o2scl/hdf_nucmass_io.h>
#endif

using namespace std;
using namespace o2scl;
using namespace o2scl_const;
using namespace o2scl_fm;


int main(void) {
  test_mgr t;
  t.set_output_level(1);
  
  cout.setf(ios::scientific);

#ifdef O2SCL_HDF_IN_EXAMPLES

  // The RMS deviation of the fit
  double res;
  // The mass formula to be fitted
  semi_empirical_mass sem;
  // The fitting class
  mass_fit mf;

  // Load the experimental data
  ame_mass ame;
  o2scl_hdf::ame_load(ame,"");
  mf.set_exp_mass(ame);

  // Perform the fit
  mf.fit(sem,res);

  // Output the results
  cout << sem.B << " " << sem.Sv << " " << sem.Ss << " " 
       << sem.Ec << " " << sem.Epair << endl;
  cout << res << endl;
  t.test_gen(res<4.0,"Successful fit.");

#else
  cout << "No fitting was performed because O2scl appears not to have been "
       << "compiled with HDF support." << endl;
#endif
  
  t.report();
  return 0;
}
// End of example

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Friends

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

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.