1 #ifndef __POLYNOMIAL_EVOLUTION_H 2 #define __POLYNOMIAL_EVOLUTION_H 4 #include "../Core/Functions.h" 5 #include "../StellarEvolution/EvolvingStellarQuantity.h" 6 #include "../StellarEvolution/Interpolator.h" 14 #include <gsl/gsl_roots.h> 17 #include <boost/archive/text_oarchive.hpp> 18 #include <boost/archive/text_iarchive.hpp> 54 const std::valarray<double> &coefficients,
63 double derivative_x=NaN
65 __poly_coef(coefficients),
68 __deriv_x(derivative_x)
71 void select_interpolation_region(
double)
const {}
110 double order(
unsigned deriv_order = 1)
const;
119 std::string
kind()
const {
return "PolynomialEvolutionQuantity";}
128 std::valarray< std::valarray<double> >
174 const std::valarray< std::valarray<double> > &
175 R = std::valarray< std::valarray<double> >(),
179 const std::valarray< std::valarray<double> > &
180 Iconv = std::valarray< std::valarray<double> >(),
184 const std::valarray< std::valarray<double> > &
185 Irad = std::valarray< std::valarray<double> >(),
189 const std::valarray< std::valarray<double> > &
190 Rcore = std::valarray< std::valarray<double> >(),
194 const std::valarray< std::valarray<double> > &
195 Mcore = std::valarray< std::valarray<double> >(),
199 const std::valarray< std::valarray<double> > &
200 Lum = std::valarray< std::valarray<double> >()
225 unsigned __num_stars_created;
241 PolynomialEvolutionTrack *Lrad_track,
244 std::valarray<double> evolution_masses,
256 std::valarray< std::valarray<double> > r_coef,
282 std::valarray<double> ages;
283 std::valarray<double> semis;
284 PlanetData() : star(NULL) {
285 sdata =
new StarData();
286 sdata->create_random_star(&star);
288 void create_random_planet(
Planet** planet);
289 double get_semi(
double age);
306 pdata =
new PlanetData();
307 pdata->create_random_planet(&planet);
309 sdata = pdata->sdata;
311 void create_random_system(StellarSystem** system) {
317 *system =
new StellarSystem(*star, *planet,
"");
329 const std::valarray< std::valarray<double> > &poly_coef,
335 double low_mass_age_scaling = 0,
338 double high_mass_age_scaling = 0,
341 double scale_mass = NaN
353 PolynomialStellarEvolution(
356 const std::valarray<double> &masses,
360 const std::valarray<double> &ages,
364 const std::valarray< std::valarray<double> > &r_coef,
368 const std::valarray< std::valarray<double> > &Iconv_coef,
372 const std::valarray< std::valarray<double> > &Itot_coef,
376 const std::valarray< std::valarray<double> > &Mrad_coef,
380 const std::valarray< std::valarray<double> > &Rcore_coef,
383 double low_mass_age_scaling,
386 double high_mass_age_scaling);
405 double deriv_x = Core::NaN) :
414 {
return (*__offset)(x) + __scale * std::exp(__rate * x);}
422 double order(
unsigned deriv_order = 1)
const;
441 const OneArgumentDiffFunction *__f1, *__f2;
446 const OneArgumentDiffFunction *f2,
447 double deriv_x = Core::NaN) :
448 __f1(f1), __f2(f2), __deriv_x(deriv_x)
452 double operator()(
double x)
const {
return (*__f1)(x) + (*__f2)(x);}
455 const FunctionDerivatives *
deriv(
double x)
const 459 double order(
unsigned deriv_order = 1)
const;
463 {
return std::min(__f1->range_high(), __f2->range_high());}
467 {
return std::max(__f1->range_low(), __f2->range_low());}
480 double __deriv_x, __range_low, __range_high;
481 std::list<const OneArgumentDiffFunction *> __pieces;
485 &pieces = std::list<const OneArgumentDiffFunction *>(),
486 double deriv_x = Core::NaN);
490 void add_piece(
const OneArgumentDiffFunction *piece);
496 const FunctionDerivatives *
deriv(
double x)
const 500 double order(
unsigned deriv_order=1)
const;
521 const OneArgumentDiffFunction *__f1, *__f2;
525 const OneArgumentDiffFunction *f2,
526 double deriv_x = Core::NaN) :
527 __deriv_x(deriv_x), __f1(f1), __f2(f2) {}
530 double operator()(
double x)
const {
return (*__f1)(x) / (*__f2)(x);}
533 const FunctionDerivatives *
deriv(
double x)
const 537 double order(
unsigned deriv_order=1)
const;
541 {
return std::min(__f1->range_high(), __f2->range_high());}
545 {
return std::max(__f1->range_low(), __f2->range_low());}
559 const OneArgumentDiffFunction *__f;
565 double deriv_x = Core::NaN) :
566 __f(f), __power(power), __deriv_x(deriv_x) {}
570 {
return std::pow((*__f)(x), __power);}
573 const FunctionDerivatives *
deriv(
double x)
const 577 double order(
unsigned deriv_order=1)
const;
597 const OneArgumentDiffFunction *__f;
603 double deriv_x = Core::NaN) :
604 __f(f), __scale(scale), __deriv_x(deriv_x) {}
608 {
return __scale*(*__f)(x);}
611 const FunctionDerivatives *
deriv(
double x)
const 615 double order(
unsigned deriv_order=1)
const;
635 const OneArgumentDiffFunction *__f;
640 double deriv_x = Core::NaN) :
641 __f(f), __deriv_x(deriv_x) {}
644 double operator()(
double x)
const {
return std::log((*__f)(x));}
647 const FunctionDerivatives *
deriv(
double x)
const 651 double order(
unsigned deriv_order=1)
const;
671 const OneArgumentDiffFunction *__f;
676 double deriv_x = Core::NaN) :
677 __f(f), __deriv_x(deriv_x) {}
680 double operator()(
double x)
const {
return std::cos((*__f)(x));}
683 const FunctionDerivatives *
deriv(
double x)
const 687 double order(
unsigned deriv_order=1)
const;
703 std::valarray<double> tabulate_track(PolynomialEvolutionTrack *track,
705 std::valarray<double> ages,
unsigned deriv_order=0);
709 double eval_poly(
const std::valarray< std::valarray<double> > &poly_coef,
710 double mass,
double age,
double low_mass_age_scaling=0,
711 double high_mass_age_scaling=0,
double scale_mass=NaN);
715 double solve(
double guess_x,
716 double abs_precision,
717 double rel_precision,
718 double (*f)(
double x,
void *params),
719 double (*df) (
double x,
void *params),
720 void (*fdf) (
double x,
void *params,
double *f,
double *df),
const Core::FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
Implements a StellarEvolution based on polynomial evolution quantities.
double range_high() const
The upper end of the range where the function is defined.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
double operator()(double x) const
Evaluates the function at the given x.
CosFunction(const OneArgumentDiffFunction *f, double deriv_x=Core::NaN)
Create the function.
double core_formation_age(const EvolvingStar *star)
The age at which the core of a star forms.
double operator()(double x) const
Evaluates the function at the given x.
double operator()(double x) const
Evaluates the function at the given x.
double range_high() const
The upper end of the range over which the function is defined.
Functions and classes of general use for all unit tests.
Core::InterpSolutionIterator crossings(double) const
Iterator over the points at which the function takes the given value.
virtual double previous_discontinuity() const
See StellarEvolution::EvolvingStellarQuantity::prevous_discontinuity()
double range_high() const
The upper end of the range over which the function is defined.
A function scaled by some constant.
virtual void enable_next_interpolation_region() const
Set up the interpolation over the next interpolation region (between consecutive discontinuities.)
std::vector< double > __empty_vector
An empty vector to serve as the list of discontinuities.
double range_high() const
The upper end of the range over which the function is defined.
friend std::ostream & operator<<(std::ostream &os, const PolynomialEvolutionQuantity &track)
Prints an expression of the polynomial that this track represents.
double operator()(double x) const
Evaluates the function at the given x.
double range_high() const
The upper end of the range over which the function is defined.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
double core_formation_age() const
The age in Gyr at which the core forms.
FuncPlusFunc(const OneArgumentDiffFunction *f1, const OneArgumentDiffFunction *f2, double deriv_x=Core::NaN)
Creates the function.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
A class representing a once differentiable function of a single argument.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
double operator()(double x) const
Evaluate the function at the given x.
const Core::FunctionDerivatives * deriv(double x) const
The derivatives.
ScaledFunction(const OneArgumentDiffFunction *f, double scale, double deriv_x=Core::NaN)
Create the function.
double __core_formation_age
The age in Gyr at which the core forms.
A class for stellar properties that depend on age.
An iterator over a set of solutions to an interpolating function.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
A class that interpolates among stellar evolution tracks.
Represents the sum of two functions and the derivative.
double range_high() const
The upper end of the range over which the function is defined.
FunctionToPower(const OneArgumentDiffFunction *f, double power, double deriv_x=Core::NaN)
Create the function.
The cosine of a function.
An EvolvingStellar quantity that uses a polynomial instead of interpolating.
double __xmax
The upper limit of the age at which this quantity can be evaluated.
The natural logarithm of a function.
double range_low() const
The lower end of the range over which the function is defined.
double order(unsigned deriv_order=1) const
The order-th derivative.
double range_low() const
The lower end of the range over which the function is defined.
std::valarray< std::valarray< double > > __Rcore
The polynomial coefficients of the core radius dependence on stellar mass and age.
A class representing arbitrary order derivatives of a function.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
double range_low() const
The lower end of the range over which the function is defined.
double operator()(double x) const
Evaluates the polynomial at the given age.
double range_low() const
The lower end of the range over which the function is defined.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
virtual const std::vector< double > & discontinuities() const
The ages at which the quantity may be discontinuous.
const FunctionDerivatives * deriv(double x) const
Returns the derivatives at the given x.
LogFunction(const OneArgumentDiffFunction *f, double deriv_x=Core::NaN)
Create the function.
virtual double next_discontinuity() const
See StellarEvolution::EvolvingStellarQuantity::next_discontinuity()
double __xmin
The lower limit of the age at which this quantity can be evaluated.
Core::InterpSolutionIterator crossings(double) const
Iterator over the x values where the function takes the given value.
std::valarray< double > __poly_coef
The coefficients of the polynomial giving the evolution.
double range_low() const
The lower end of the range where the function is defined.
Several functions stiched together.
double operator()(double x) const
Evaluates the function at the given x.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
QuantityID
Defines the quantities tracked by stellar evolution and their order.
double range_low() const
The lower end of the range where the function is defined.
double range_low() const
The lower end of the range over which the function is defined.
Represents a function of the form offset + scale*exp(rate*x) as well as its derivative.
double range_low() const
The lower end of the range over which the function is defined.
const FunctionDerivatives * deriv(double x) const
Returns the derivative.
double operator()(double x) const
Evaluates the function at the given x.
A function raised to some power.
std::string kind() const
A string identifying the type of quantity this is.
double range_high() const
The upper end of the range over which the function is defined.
Core::InterpSolutionIterator crossings(double) const
An iterator over the x values where the function takes the given value.
The ratio of two functions;.
PolynomialEvolutionQuantity(const std::valarray< double > &coefficients, double range_low, double range_high, double derivative_x=NaN)
Create an evolving quantity or its derivative.
ExponentialPlusFunc(Core::OneArgumentDiffFunction *offset, double scale, double rate, double deriv_x=Core::NaN)
Create the function with the given parameters.
double range_high() const
The upper end of the range where the function is defined.
virtual InputDataType range_high() const =0
The lower end of the range over which the function is defined.
double __deriv_x
The location at which the derivative has been requested.
double range_low() const
The lower end of the range over which the function is defined.
double range_high() const
The upper end of the range over which the function is defined.
virtual InputDataType range_low() const =0
The upper end of the range over which the function is defined.
struct LIB_PUBLIC EvolvingStar
Opaque struct to cast to/from Star::InterpolatedEvolutionStar.
FunctionRatio(const OneArgumentDiffFunction *f1, const OneArgumentDiffFunction *f2, double deriv_x=Core::NaN)
Create the function.