SEVN
Loading...
Searching...
No Matches
utilities Namespace Reference

Classes

class  ListGenerator
 Class to handle the generation of a list of values. More...
 
struct  MassContainer
 

Typedefs

typedef unsigned int evolution
 
typedef unsigned int jump_convergence
 
typedef unsigned int sn_explosion
 
typedef unsigned int rlo
 
typedef bool bse_evolution
 

Functions

double maxwellian_cdf (double x, double sigma)
 
double maxwellian_pdf (double x, double sigma)
 
double R_Schwarzschild (double Mass)
 
template<typename T >
const std::string n2s (T val, const char *file_input, const int line_input, const unsigned int precision=6)
 
double roche_lobe_Eg (double Mass_primary, double Mass_secondary, double a)
 
double R_Alfven (Star *s, double dMdt, bool get0=false)
 
double Hfrac (Star *s)
 
double dMdt_Eddington_accretion (Star *donor, Star *accretor, double eddfact=1.0)
 
static double omega_crit (double Mass, double Rpolar)
 
void hardwait ()
 
template<typename T , typename... Tail>
void hardwait (T head, Tail... tail)
 
void wait ()
 
template<typename T , typename... Tail>
void wait (_UNUSED T head, _UNUSED Tail... tail)
 
std::string get_name (Star *s)
 
long get_ID (Star *s)
 
std::string get_name (Binstar *b)
 
long get_ID (Binstar *b)
 
double get_current_time (Star *s)
 
double get_current_time (Binstar *b)
 
template<typename T >
void _log_print_core (std::stringstream &ss, T t)
 
template<typename T , typename... ListP>
void _log_print_core (std::stringstream &ss, T t, ListP... args)
 
template<class System , typename... ListP>
std::string common_log_print (const std::string &label, System *system, ListP... args)
 
template<class System , typename... ListP>
std::string common_log_print (const std::string &label, System *system)
 
template<typename... ListP>
std::string log_print (const std::string &label, Star *star, ListP... args)
 
template<typename... ListP>
std::string log_print (const std::string &label, Binstar *binstar, ListP... args)
 
std::string log_star_info (Star *s, bool oldstep=false)
 
unsigned long gen_rseed ()
 
unsigned long gen_rseed (std::random_device &rd)
 
const std::string random_keygen (std::mt19937_64 *mtrand)
 
std::vector< std::string > split (const std::string &s, char delimiter)
 
template<class T >
bool isifstream ()
 
template<>
bool isifstream< std::ifstream > ()
 
template<typename T >
size_t binary_search (T *array, const size_t left, const size_t right, const T value)
 
template<typename T >
bool string_is_number (std::string str)
 
double kepler (const double &ecc, const double &m, const double tol=1e-6, const int maxit=50)
 
template<typename T >
const T s2n (std::string &str, const char *file_input, const int line_input)
 
template<typename T >
void _openfile (T &in, const std::string f, const char *file_input, const int line_input)
 
bool wayToSort (int i, int j)
 
template<typename T >
dirname2n (std::string str, const char *file_input, const int line_input)
 
template<typename T >
void print_vector (const std::vector< T > &v)
 
std::string gen_filename (const std::string &_folder, const std::string &_fname, bool print_threads=true)
 
std::string get_absolute_SEVN_path ()
 
int find_line (const double &x1, const double &x2, const double &y1, const double &y2, double &slope, double &intercept)
 
template<typename T >
double rel_difference (T val1, T val2)
 
void swap_stars (Star *&s1, Star *&s2)
 
std::string trim (const std::string &s)
 
template<typename T , typename Iter >
bool isinlist (T element, Iter it, Iter end)
 
std::string make_pfile_str (const double plife, const size_t Phase, const unsigned int min_precision=6)
 
template<typename T >
interpolate_1D (T xp, std::vector< T > &x_interp, std::vector< T > &y_interp, bool equispaced_interval=false, bool ext_raise=false)
 
std::string get_subpath (std::string path, std::string split_string, bool include_split_string=true)
 
template<typename T >
void transpose (std::vector< std::vector< T > > &MatrixT, std::vector< std::vector< T > > &Matrix)
 
template<typename T >
int findInVector (const std::vector< T > &vecOfElements, const T &element)
 
template<typename Key , typename Value >
std::map< Value, Key > flip_map (const std::map< Key, Value > &original_map)
 
bool areEqual (double x, double y)
 
double smallestSignificativeStep (double x)
 
template<typename T , typename... Args>
std::unique_ptr< T > make_unique (Args &&... args)
 

Variables

std::mt19937_64 mtrand
 
const std::string SEVN_NAME = "SEVN"
 
constexpr double G = 3.925125598496094e8
 Fundamental quantitis. More...
 
constexpr double yr_cgs = 3.1557600e7
 
constexpr double parsec_cgs = 3.085677581491367e+18
 
constexpr double Rsun_cgs = 6.95700e10
 
constexpr double Msun_cgs = 1.988409870698051e+33
 
constexpr double G_cgs = G*Rsun_cgs*Rsun_cgs*Rsun_cgs/(Msun_cgs*yr_cgs*yr_cgs)
 
constexpr double Sigma_StefBoltz = 7.1694165533435e-17
 
constexpr double Myr_to_yr = 1.0e6
 
constexpr double yr_to_Myr = 1.0e-6
 
constexpr double AU_to_RSun = 215.03215567054764
 
constexpr double kms_to_RSunyr = 45.360931435963785
 
constexpr double LSun_to_Solar = 12.500687924182579
 
constexpr double c = 1.3598865132357053e7
 
constexpr double km_to_RSun = 1.4374011786689665e-06
 
constexpr double parsec_to_Rsun = parsec_cgs/Rsun_cgs
 
constexpr double g_to_MSun = 5.029144215870041e-34
 
constexpr double G_over_c2 = G / (c*c)
 
constexpr double G3_over_c5 = (G*G*G)/(c*c*c*c*c)
 
constexpr double tH = 13.7*1e3
 
constexpr double Mchandra = 1.41
 
const std::string PLACEHOLDER ="xxx"
 
constexpr double NULL_DOUBLE = -9e30
 
constexpr int NULL_INT = -999999999
 
constexpr size_t NULL_SINT = 999999999
 
const std::string NULL_STR = "FORZAROMA"
 
constexpr double DIFF_TOLL = 1e-10
 
constexpr double LARGE = 1e30
 
constexpr double TINY = 1e-15
 
constexpr double DOUBLE_EPS = std::numeric_limits<double>::epsilon()
 
constexpr int SINGLE_STEP_EVOLUTION =0
 
constexpr int REPEATED_EVOLUTION =1
 
constexpr int JUMP_CONVERGE =0
 
constexpr int JUMP =1
 
constexpr int NO_JUMP =2
 
constexpr int SNIA_EXPLODE =1
 
constexpr int SNII_EXPLODE =2
 
constexpr int SN_NOT_EXPLODE =0
 
constexpr int RLO_FALSE =0
 
constexpr int RLO_TRUE =1
 
constexpr int BIN_EV_DONE = 1
 
constexpr int BIN_EV_NOT_DONE = 0
 
constexpr int BIN_EV_SETBROKEN = 2
 

Typedef Documentation

◆ bse_evolution

◆ evolution

typedef unsigned int utilities::evolution

◆ jump_convergence

typedef unsigned int utilities::jump_convergence

◆ rlo

typedef unsigned int utilities::rlo

◆ sn_explosion

typedef unsigned int utilities::sn_explosion

Function Documentation

◆ _log_print_core() [1/2]

template<typename T >
void utilities::_log_print_core ( std::stringstream &  ss,
t 
)

◆ _log_print_core() [2/2]

template<typename T , typename... ListP>
void utilities::_log_print_core ( std::stringstream &  ss,
t,
ListP...  args 
)

◆ _openfile()

template<typename T >
void utilities::_openfile ( T &  in,
const std::string  f,
const char *  file_input,
const int  line_input 
)

◆ areEqual()

bool utilities::areEqual ( double  x,
double  y 
)

Check if two values can be considered equal within the machine precision tolerance. This can be used as a robust alternative to the operator == for doubles Absolute tolerance works well for values<1, relative tolerance for larger values

Parameters
xFirst value to compare
ySecond value to compare
Returns
True if the |x-y|<=epsilon, where
  • epsilon=std::numeric_limits<double>::epsilon() if x<=1 and y<=1
  • epsilon=std::numeric_limits<double>::epsilon()*max(x,y) otherwise

◆ binary_search()

template<typename T >
size_t utilities::binary_search ( T *  array,
const size_t  left,
const size_t  right,
const T  value 
)

◆ common_log_print() [1/2]

template<class System , typename... ListP>
std::string utilities::common_log_print ( const std::string &  label,
System *  system 
)

◆ common_log_print() [2/2]

template<class System , typename... ListP>
std::string utilities::common_log_print ( const std::string &  label,
System *  system,
ListP...  args 
)

◆ dirname2n()

template<typename T >
T utilities::dirname2n ( std::string  str,
const char *  file_input,
const int  line_input 
)

◆ dMdt_Eddington_accretion()

double utilities::dMdt_Eddington_accretion ( Star donor,
Star accretor,
double  eddfact = 1.0 
)

Estimate the maximal accretion rate on an object due to the Eddington limit. It is estimated using Eq. 67 in Hurley+02. In addition it is multiplied by the factor eddfact (>0, default=1) to allow super-eddingont accretion NOTICE the return will be in units of Myr / YR, while SEVN usually assumes Myr as scale, be careful of conversion.

Parameters
donorPointer to the star that is donating mass
accretorPointer to the star that is accreting mass
eddfactMultiplicative factor to allow supereddington accretions
Returns
return the Eddington accretion rate multiuplied by eddfact in Msun/yr

◆ find_line()

int utilities::find_line ( const double &  x1,
const double &  x2,
const double &  y1,
const double &  y2,
double &  slope,
double &  intercept 
)
inline

Find the slope and the intercept of the line passing through (x1,y1), (x2,y2)

Parameters
x1x-value of the first point
x2x-value of the second point
y1y-value of the first point
y2y-value of the second point
slopethis value stores the estimated slope
interceptthis value store the estimated intercept
Returns

◆ findInVector()

template<typename T >
int utilities::findInVector ( const std::vector< T > &  vecOfElements,
const T &  element 
)

Generic function to find an element in vector and also its position.

Template Parameters
T
Parameters
vecOfElementsVector to look for the element
elementelement to find in the vector
Returns
It returns an integer int : Represents the index of element in vector if its found else -1

◆ flip_map()

template<typename Key , typename Value >
std::map< Value, Key > utilities::flip_map ( const std::map< Key, Value > &  original_map)

◆ gen_filename()

std::string utilities::gen_filename ( const std::string &  _folder,
const std::string &  _fname,
bool  print_threads = true 
)
inline

Functions to generate a complete filename path containing also the directory

Parameters
_folderA string containing the folder path
_fnameComplete filename including also the .extension if any (_fname=_fname_root . _fname_extension)
print_threadsIf true the number of threads will be added to the filename
Returns
a string with _folder/_fname_root_nthreads._fname_etension if print_threads=true otherwise _folder/_fname_root._fname_extension

◆ gen_rseed() [1/2]

unsigned long utilities::gen_rseed ( )

◆ gen_rseed() [2/2]

unsigned long utilities::gen_rseed ( std::random_device &  rd)

◆ get_absolute_SEVN_path()

std::string utilities::get_absolute_SEVN_path ( )
inline

Get the absolute path of this SEVN folder

Returns
The absolute SEVN path

◆ get_current_time() [1/2]

double utilities::get_current_time ( Binstar b)

◆ get_current_time() [2/2]

double utilities::get_current_time ( Star s)

◆ get_ID() [1/2]

long utilities::get_ID ( Binstar b)

◆ get_ID() [2/2]

long utilities::get_ID ( Star s)

◆ get_name() [1/2]

std::string utilities::get_name ( Binstar b)

◆ get_name() [2/2]

std::string utilities::get_name ( Star s)

◆ get_subpath()

std::string utilities::get_subpath ( std::string  path,
std::string  split_string,
bool  include_split_string = true 
)
inline

Get a portion of path name till the given split_string. The split_string is include.

Parameters
pathComplete path
split_stringstring patter where to cut the complete path
Returns
the substring from 0 to split_string

◆ hardwait() [1/2]

void utilities::hardwait ( )
inline

Like wait but it works also outside debug mode

◆ hardwait() [2/2]

template<typename T , typename... Tail>
void utilities::hardwait ( head,
Tail...  tail 
)

Like wait but it works also outside debug mode

◆ Hfrac()

double utilities::Hfrac ( Star s)

Estimate the Hydrogen mass fraction of the star. It is the one used in BSE/MOBSE

Parameters
sPointer to the star
Returns
Hydrogen mass fraction

◆ interpolate_1D()

template<typename T >
T utilities::interpolate_1D ( xp,
std::vector< T > &  x_interp,
std::vector< T > &  y_interp,
bool  equispaced_interval = false,
bool  ext_raise = false 
)

Estimate the y value using 1D linear interpolation

Template Parameters
Ttype of the of interpolated value
Parameters
xp
x_interp1D vector containing the x-value of the interpolating tables (in ascending order)
y_interp1D vector containing the y-value of the interpolating tables
equispaced_intervalif true the value in x_interp are equi-spaced
ext_raiseif true and xp is out of boundary raise an error otherwise return the extrema of yinterp
Returns
interpolated y value at xp.

◆ isifstream()

template<class T >
bool utilities::isifstream ( )
inline

◆ isifstream< std::ifstream >()

template<>
bool utilities::isifstream< std::ifstream > ( )
inline

◆ isinlist()

template<typename T , typename Iter >
bool utilities::isinlist ( element,
Iter  it,
Iter  end 
)

Template function to check if a given element is inside a container.

Template Parameters
Ttypename of the element to be checked
Itertypename of the iterator
Parameters
elementelement to be checked
ititerator to the begin of the container
enditeratore to the end of the container
Returns
true if the element is inside the list, otherwise false.

◆ kepler()

double utilities::kepler ( const double &  ecc,
const double &  m,
const double  tol = 1e-6,
const int  maxit = 50 
)
inline

Solve the Kepler equation to found the Eccentric anomaly starting from eccentricy and Mean anomaly. We use the generalized Newton Raphson’s method (Eq. 2.6, Nazeer 2016). If in some step we have numerical problem with the second derivative, we revert to a simple NR method for that step

Parameters
eccEccentricity
mMean anomaly
toltollerance
maxitmaximum number of iteration
Returns
Eccentric anomaly

◆ log_print() [1/2]

template<typename... ListP>
std::string utilities::log_print ( const std::string &  label,
Binstar binstar,
ListP...  args 
)

◆ log_print() [2/2]

template<typename... ListP>
std::string utilities::log_print ( const std::string &  label,
Star star,
ListP...  args 
)

◆ log_star_info()

std::string utilities::log_star_info ( Star s,
bool  oldstep = false 
)

Utility to write Star info in a log format

Parameters
sPointer to star
oldstepif true get the property of the last step
Returns
a string with ID:Mass:MHE:MCO:Phase:RemnanType

◆ make_pfile_str()

std::string utilities::make_pfile_str ( const double  plife,
const size_t  Phase,
const unsigned int  min_precision = 6 
)
inline

Make the string plife:phase

Parameters
plifeLife percentage at a given Phase
PhasePhase to consider
Returns
string plife:phase

◆ make_unique()

template<typename T , typename... Args>
std::unique_ptr< T > utilities::make_unique ( Args &&...  args)
inline

Define make_unique for pre-C++14. Notice this is the the same of the implementation of C++14 standard for single object, in the std there is also another implementation for arrays.

Template Parameters
TType of the unique ptr
Args
Parameters
argsarg to initialise the object pointed by the unique ptr
Returns
return the unique pointer to the element of type T.

◆ maxwellian_cdf()

double utilities::maxwellian_cdf ( double  x,
double  sigma 
)

◆ maxwellian_pdf()

double utilities::maxwellian_pdf ( double  x,
double  sigma 
)

◆ n2s()

template<typename T >
const std::string utilities::n2s ( val,
const char *  file_input,
const int  line_input,
const unsigned int  precision = 6 
)
Template Parameters
Ttemplate type. It should be able to accept anything that can be << to a stream obejct.
Parameters
valvalue of type T to be converted to a string
file_inputit should be set to
__FILE__
line_inputit should be set to
__LINE__
precisionset precision for the scientific format output of numbers
Returns
The val converted to a string. If val is a number the string is the scientific format with precision equal to precision.

◆ omega_crit()

static double utilities::omega_crit ( double  Mass,
double  Rpolar 
)
inlinestatic

Critical angular velocity

Parameters
Massmass in Msun
Rpolarpolar radius in Rsun
Returns
critical angular velocity in yr^-1

◆ print_vector()

template<typename T >
void utilities::print_vector ( const std::vector< T > &  v)

Functions to print all the elements of a vector in a Python numpy style (GI)

◆ R_Alfven()

double utilities::R_Alfven ( Star s,
double  dMdt,
bool  get0 = false 
)

Estimate the Alfven radius

Parameters
sPointer to the star for which we want to calculate the Alfven radius
dMdtAccreated mass rate in Msun/yr
get0AIf true use the stellar propertie at the beginning of the timestep
Returns
The Alfven radius in Rsun

◆ R_Schwarzschild()

double utilities::R_Schwarzschild ( double  Mass)
inline

◆ random_keygen()

const std::string utilities::random_keygen ( std::mt19937_64 *  mtrand)
inline

◆ rel_difference()

template<typename T >
double utilities::rel_difference ( val1,
val2 
)

◆ roche_lobe_Eg()

double utilities::roche_lobe_Eg ( double  Mass_primary,
double  Mass_secondary,
double  a 
)

Estimate the RL follwing the Eggleton formalism (Eq. 53 Hurley02)

Parameters
Mass_primaryMass of the primary in Msun (the star for which we are estimating the RL)
Mass_secondaryMass of the secondary in Msun.
aSemimajor axis in Rsun
Returns
Roche Lobe radius in Rsun

◆ s2n()

template<typename T >
const T utilities::s2n ( std::string &  str,
const char *  file_input,
const int  line_input 
)

◆ smallestSignificativeStep()

double utilities::smallestSignificativeStep ( double  x)

Estimate the smallest possible step given X so that X+step>X

Parameters
xnumber
Returns
the step is estimated as 1.01*std::numeric_limits<double>::epsilon()*maxXYOne where maxXYOne = std::max( 1.0, fabs(x));

◆ split()

std::vector< std::string > utilities::split ( const std::string &  s,
char  delimiter 
)

◆ string_is_number()

template<typename T >
bool utilities::string_is_number ( std::string  str)

◆ swap_stars()

void utilities::swap_stars ( Star *&  s1,
Star *&  s2 
)
inline

◆ transpose()

template<typename T >
void utilities::transpose ( std::vector< std::vector< T > > &  MatrixT,
std::vector< std::vector< T > > &  Matrix 
)

Transpose a matrix

Template Parameters
T
Parameters
MatrixTTransposed Matrix
MatrixMatrix to be transposed

◆ trim()

std::string utilities::trim ( const std::string &  s)
inline

Trim a string from all whitespaces

Parameters
s
Returns

◆ wait() [1/2]

void utilities::wait ( )
inline

Base class for the variadic function wait.

Parameters
_message

◆ wait() [2/2]

template<typename T , typename... Tail>
void utilities::wait ( _UNUSED head,
_UNUSED Tail...  tail 
)

Variadic function. It prints a message in std::cout (from an argument pack) and wait of a cin input from the user.

Template Parameters
Ttemplate param of the value to be written
Tailtemplate params of the pack of parameters to iterate over
Parameters
headvalue to be written
tailrest of the packs

◆ wayToSort()

bool utilities::wayToSort ( int  i,
int  j 
)
inline

Variable Documentation

◆ AU_to_RSun

constexpr double utilities::AU_to_RSun = 215.03215567054764
constexpr

◆ BIN_EV_DONE

constexpr int utilities::BIN_EV_DONE = 1
constexpr

◆ BIN_EV_NOT_DONE

constexpr int utilities::BIN_EV_NOT_DONE = 0
constexpr

◆ BIN_EV_SETBROKEN

constexpr int utilities::BIN_EV_SETBROKEN = 2
constexpr

◆ c

constexpr double utilities::c = 1.3598865132357053e7
constexpr

◆ DIFF_TOLL

constexpr double utilities::DIFF_TOLL = 1e-10
constexpr

◆ DOUBLE_EPS

constexpr double utilities::DOUBLE_EPS = std::numeric_limits<double>::epsilon()
constexpr

◆ G

constexpr double utilities::G = 3.925125598496094e8
constexpr

Fundamental quantitis.

◆ G3_over_c5

constexpr double utilities::G3_over_c5 = (G*G*G)/(c*c*c*c*c)
constexpr

◆ G_cgs

constexpr double utilities::G_cgs = G*Rsun_cgs*Rsun_cgs*Rsun_cgs/(Msun_cgs*yr_cgs*yr_cgs)
constexpr

◆ G_over_c2

constexpr double utilities::G_over_c2 = G / (c*c)
constexpr

◆ g_to_MSun

constexpr double utilities::g_to_MSun = 5.029144215870041e-34
constexpr

◆ JUMP

constexpr int utilities::JUMP =1
constexpr

◆ JUMP_CONVERGE

constexpr int utilities::JUMP_CONVERGE =0
constexpr

◆ km_to_RSun

constexpr double utilities::km_to_RSun = 1.4374011786689665e-06
constexpr

◆ kms_to_RSunyr

constexpr double utilities::kms_to_RSunyr = 45.360931435963785
constexpr

◆ LARGE

constexpr double utilities::LARGE = 1e30
constexpr

◆ LSun_to_Solar

constexpr double utilities::LSun_to_Solar = 12.500687924182579
constexpr

◆ Mchandra

constexpr double utilities::Mchandra = 1.41
constexpr

◆ Msun_cgs

constexpr double utilities::Msun_cgs = 1.988409870698051e+33
constexpr

◆ mtrand

std::mt19937_64 utilities::mtrand
extern

◆ Myr_to_yr

constexpr double utilities::Myr_to_yr = 1.0e6
constexpr

◆ NO_JUMP

constexpr int utilities::NO_JUMP =2
constexpr

◆ NULL_DOUBLE

constexpr double utilities::NULL_DOUBLE = -9e30
constexpr

◆ NULL_INT

constexpr int utilities::NULL_INT = -999999999
constexpr

◆ NULL_SINT

constexpr size_t utilities::NULL_SINT = 999999999
constexpr

◆ NULL_STR

const std::string utilities::NULL_STR = "FORZAROMA"

◆ parsec_cgs

constexpr double utilities::parsec_cgs = 3.085677581491367e+18
constexpr

◆ parsec_to_Rsun

constexpr double utilities::parsec_to_Rsun = parsec_cgs/Rsun_cgs
constexpr

◆ PLACEHOLDER

const std::string utilities::PLACEHOLDER ="xxx"

◆ REPEATED_EVOLUTION

constexpr int utilities::REPEATED_EVOLUTION =1
constexpr

◆ RLO_FALSE

constexpr int utilities::RLO_FALSE =0
constexpr

◆ RLO_TRUE

constexpr int utilities::RLO_TRUE =1
constexpr

◆ Rsun_cgs

constexpr double utilities::Rsun_cgs = 6.95700e10
constexpr

◆ SEVN_NAME

const std::string utilities::SEVN_NAME = "SEVN"

◆ Sigma_StefBoltz

constexpr double utilities::Sigma_StefBoltz = 7.1694165533435e-17
constexpr

◆ SINGLE_STEP_EVOLUTION

constexpr int utilities::SINGLE_STEP_EVOLUTION =0
constexpr

◆ SN_NOT_EXPLODE

constexpr int utilities::SN_NOT_EXPLODE =0
constexpr

◆ SNIA_EXPLODE

constexpr int utilities::SNIA_EXPLODE =1
constexpr

◆ SNII_EXPLODE

constexpr int utilities::SNII_EXPLODE =2
constexpr

◆ tH

constexpr double utilities::tH = 13.7*1e3
constexpr

◆ TINY

constexpr double utilities::TINY = 1e-15
constexpr

◆ yr_cgs

constexpr double utilities::yr_cgs = 3.1557600e7
constexpr

◆ yr_to_Myr

constexpr double utilities::yr_to_Myr = 1.0e-6
constexpr