|
gimme-alpha 0.1
|
#include <gsl/gsl_errno.h>#include <gsl/gsl_interp.h>#include <gsl/gsl_spline.h>#include <libcommon/density.h>#include <libcommon/gcc_hints.h>
Include dependency graph for density.c:Go to the source code of this file.
Functions | |
| double | get_density_within_range2 (double xmin, double xmax, double x[], double rho[], int len) |
| double | get_density_within_range2_stairstep (double xmin, double xmax, double x[], double rho[], int len) |
| double | get_density_within_range2_sum (double xmin, double xmax, double x[], double rho[], int len) |
| double | get_density_within_range (double xmin, double xmax, struct density_point *p, int len, short int type) |
| double get_density_within_range | ( | double | xmin, |
| double | xmax, | ||
| struct density_point * | p, | ||
| int | len, | ||
| short int | type | ||
| ) |
Definition at line 91 of file density.c.
References get_density_within_range2(), get_density_within_range2_stairstep(), get_density_within_range2_sum(), density_point::rho, and density_point::x.
Referenced by main().
{
int i;
double x[len];
double rho[len];
for(i=0; i<len; i++) {
x[i] = p[i].x;
rho[i] = p[i].rho;
//fprintf(stderr, "i=%d: x=%g rho=%g -> x=%g rho=%g\n", i, p[i].x, p[i].rho, x[i], rho[i]);
}
switch (type) {
case 1:
return get_density_within_range2_stairstep(xmin, xmax, x, rho, len);
break;
case 2:
return get_density_within_range2_sum(xmin, xmax, x, rho, len);
break;
default:
return get_density_within_range2(xmin, xmax, x, rho, len);
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| double get_density_within_range2 | ( | double | xmin, |
| double | xmax, | ||
| double | x[], | ||
| double | rho[], | ||
| int | len | ||
| ) |
Definition at line 32 of file density.c.
Referenced by get_density_within_range().
{
/*Use GSL to integrate using a spline interpolator*/
gsl_interp_accel *acc = gsl_interp_accel_alloc();
gsl_spline *spline = gsl_spline_alloc(gsl_interp_akima_periodic, len);
gsl_spline_init(spline, x, rho, len);
double density = gsl_spline_eval_integ(spline, xmin, xmax, acc);
gsl_spline_free(spline);
gsl_interp_accel_free(acc);
return density;
}
Here is the caller graph for this function:| double get_density_within_range2_stairstep | ( | double | xmin, |
| double | xmax, | ||
| double | x[], | ||
| double | rho[], | ||
| int | len | ||
| ) |
Definition at line 43 of file density.c.
References unlikely.
Referenced by get_density_within_range().
{
/*Use simple stair step (const interpolation) to calculate the density*/
double density=0;
int prev=0;
for(int i=1; i<len; i++) {
if((x[i] >= xmin) && (x[i] <= xmax)) {
if(unlikely((x[i-1] < xmin) && (x[i] != xmin))) {
/*If we stepped over xmin, we only have a partial distance*/
density+=rho[i-1]*(xmin-x[i]);
}else{
density+=rho[i-1]*(x[i]-x[i-1]);
}
}
if(x[i] > xmax) {
if(x[i-1] < xmax) {
density += rho[i-1]*(xmax-x[i-1]);
}
/*No point in continuing the loop past this exit point.*/
break;
}
}
return density;
}
Here is the caller graph for this function:| double get_density_within_range2_sum | ( | double | xmin, |
| double | xmax, | ||
| double | x[], | ||
| double | rho[], | ||
| int | len | ||
| ) |
Definition at line 67 of file density.c.
References unlikely.
Referenced by get_density_within_range().
{
/*Use simple stair step (const interpolation) to calculate the density*/
double density=0;
int prev=0;
for(int i=1; i<len; i++) {
if((x[i] >= xmin) && (x[i] <= xmax)) {
if(unlikely((x[i-1] < xmin) && (x[i] != xmin))) {
/*If we stepped over xmin, we only have a partial distance*/
density+=rho[i-1];
}else{
density+=rho[i-1];
}
}
if(x[i] > xmax) {
if(x[i-1] < xmax) {
density += rho[i-1];
}
/*No point in continuing the loop past this exit point.*/
break;
}
}
return density;
}
Here is the caller graph for this function: