8 #ifndef __COMMON_DEFINITIONS_H 9 #define __COMMON_DEFINITIONS_H 17 #include <gsl/gsl_vector.h> 18 #include <gsl/gsl_matrix.h> 19 #include <gsl/gsl_linalg.h> 20 #include <gsl/gsl_blas.h> 21 #include "gsl/gsl_poly.h" 24 #include "../Core/SharedLibraryExportMacros.h" 27 #include "IncludeEigen.h" 33 const double NaN = std::numeric_limits<double>::quiet_NaN();
36 const double Inf = std::numeric_limits<double>::infinity();
59 template<
typename ITERATOR_TYPE>
63 std::valarray<double> result(size);
64 double *dest=&result[0];
65 for(; size>0; --size) {
75 const std::list<double> &inlist
79 LIB_LOCAL std::valarray<double>
solve_cubic(
double c0,
126 double x1,
double y1,
127 double x2,
double y2,
128 double require_range_low = NaN,
129 double require_range_high = NaN);
136 double x1,
double y1,
137 double x2,
double y2,
138 double x3,
double y3,
139 double require_range_low = NaN,
140 double require_range_high = NaN);
176 double *extremum_y = NULL);
187 double x1,
double y1,
188 double x2,
double y2,
189 double *extremum_y = NULL);
202 double x1,
double y1,
203 double x2,
double y2,
204 double x3,
double y3,
205 double *extremum_y = NULL,
206 double require_range_low = NaN,
207 double require_range_high = NaN);
220 double x1,
double y1,
221 double x2,
double y2,
222 double x3,
double y3);
232 template<
class ITERATOR>
237 Eigen::VectorXd y_vec(num_points);
238 Eigen::MatrixXd xpowers(num_points, num_points);
239 for(
size_t i=0; i<num_points; i++) {
240 double x=*x_i, xpow=1.0;
242 for(
size_t pow=0; pow<num_points; pow++) {
248 static Eigen::JacobiSVD<Eigen::MatrixXd,
249 Eigen::FullPivHouseholderQRPreconditioner>
250 svd(num_points, num_points,
251 Eigen::ComputeFullU | Eigen::ComputeFullV);
252 svd.compute(xpowers);
253 Eigen::VectorXd solution=svd.solve(y_vec);
254 gsl_vector *result=gsl_vector_alloc(num_points);
255 for(
size_t i=0; i<num_points; ++i)
256 gsl_vector_set(result, i, solution(i));
290 LIB_LOCAL std::ostream &
operator<<(std::ostream &os,
297 LIB_LOCAL std::ostream &
operator<<(std::ostream &os,
298 const std::valarray<double> &arr);
301 LIB_LOCAL std::ostream &
operator<<(std::ostream &os,
302 const std::list<double> &l);
Defines various astronomical constants.
std::valarray< double > valarray_from_iterator(ITERATOR_TYPE values, unsigned size)
Creates a valarray from an iterator.
const double Inf
Infinity.
LIB_LOCAL std::valarray< double > list_to_valarray(const std::list< double > &inlist)
Creates a valarray containing the values in the given list.
gsl_vector * cubic_coefficients(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
Returns the polynomial coefficients of the cubic going through four points.
double estimate_zerocrossing(double x0, double y0, double x1, double y1, double dy0, double dy1)
Finds a zero of a smooth curve defined by the given points and derivatives.
std::valarray< double > solve_cubic(double c0, double c1, double c2, double c3)
Solves the cubic equation .
double cubic_zerocrossing(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double require_range_low, double require_range_high)
Finds the abscissa of a zero of a cubic defined by four points.
Defines the exception hierarchy used by this code.
double estimate_extremum(double x0, double y0, double x1, double y1, double dy0, double dy1, double *extremum_y)
Finds an extremum of a cubic defined by two points and derivatives.
The surface rotation of one of the bodies is locked to a prescribed value.
gsl_vector * polynomial_coefficients(ITERATOR x_i, ITERATOR y_i, size_t num_points)
Finds the polynomial that goes through the points iterated over by x_i and y_i.
There is only one body in the system (only its rotation evolves).
double quadratic_extremum(double x0, double y0, double x1, double y1, double x2, double y2, double *extremum_y)
Finds the abscissa of the extremum of the quadratic function passing through three points...
double cubic_extremum(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *extremum_y, double require_range_low, double require_range_high)
Finds the abscissa of an extremum of the cubic function passing through four points.
EvolModeType
The various evolution modes.
Two bodies orbiting each other.
double quadratic_zerocrossing(double x0, double y0, double x1, double y1, double x2, double y2, double require_range_low, double require_range_high)
Finds the abscissa of a zero of a quadratic defined by three points.
std::ostream & operator<<(std::ostream &os, const std::valarray< std::valarray< double > > &poly_coef)
Create a string with a description of the given stop info.