Added a functor to interface with newton
This commit is contained in:
parent
bf1e581ce9
commit
5b3bef64b1
@ -1,3 +1,4 @@
|
|||||||
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "interpolate.hpp"
|
#include "interpolate.hpp"
|
||||||
@ -48,6 +49,31 @@ double Interpolate::compute(double x)
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Interpolate::derivative(double x)
|
||||||
|
throw (InvalidRangeException)
|
||||||
|
{
|
||||||
|
double y, dy, x0 = x;
|
||||||
|
|
||||||
|
if (logx)
|
||||||
|
x0 = log(x0);
|
||||||
|
|
||||||
|
int err = gsl_spline_eval_deriv_e(spline, x0, accel_interp, &dy);
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
throw InvalidRangeException("Interpolate argument outside range");
|
||||||
|
|
||||||
|
if (logy)
|
||||||
|
{
|
||||||
|
int err = gsl_spline_eval_e(spline, x0, accel_interp, &y);
|
||||||
|
|
||||||
|
assert(err == 0);
|
||||||
|
|
||||||
|
return dy*exp(y)/x0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return dy;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t Interpolate::getNumPoints() const
|
uint32_t Interpolate::getNumPoints() const
|
||||||
{
|
{
|
||||||
return spline->size;
|
return spline->size;
|
||||||
|
@ -21,6 +21,9 @@ namespace CosmoTool
|
|||||||
|
|
||||||
double compute(double x)
|
double compute(double x)
|
||||||
throw (InvalidRangeException);
|
throw (InvalidRangeException);
|
||||||
|
double derivative(double x)
|
||||||
|
throw (InvalidRangeException);
|
||||||
|
|
||||||
const Interpolate& operator=(const Interpolate& a);
|
const Interpolate& operator=(const Interpolate& a);
|
||||||
|
|
||||||
uint32_t getNumPoints() const;
|
uint32_t getNumPoints() const;
|
||||||
@ -41,6 +44,18 @@ namespace CosmoTool
|
|||||||
Interpolate buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx = false, bool logy = false)
|
Interpolate buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx = false, bool logy = false)
|
||||||
throw (NoSuchFileException,InvalidRangeException);
|
throw (NoSuchFileException,InvalidRangeException);
|
||||||
Interpolate buildFromVector(const InterpolatePairs& v);
|
Interpolate buildFromVector(const InterpolatePairs& v);
|
||||||
|
|
||||||
|
|
||||||
|
class FunctorInterpolate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FunctorInterpolate(Interpolate& i) : m_i(i) {}
|
||||||
|
|
||||||
|
double eval(double x) { return m_i.compute(x); }
|
||||||
|
double derivative(double x) { return m_i.derivative(x); }
|
||||||
|
private:
|
||||||
|
Interpolate& m_i;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user