12#include <gsl/gsl_interp2d.h>
61 Interp2D(
const double* x_,
const double* y_,
const double* z_,
62 const size_t nx_,
const size_t ny_,
67 const bool xLog_ =
false,
const bool yLog_ =
false,
68 const bool zLog_ =
false,
69 const double zXLo_ = 0.0,
const double zXHi_ = 0.0,
70 const double zYLo_ = 0.0,
const double zYHi_ = 0.0) :
90 interp = gsl_interp2d_alloc(gsl_interp2d_bilinear,
nx,
ny);
93 accX[i] = gsl_interp_accel_alloc();
94 accY[i] = gsl_interp_accel_alloc();
103 gsl_interp2d_free(
interp);
105 gsl_interp_accel_free(
accX[i]);
106 gsl_interp_accel_free(
accY[i]);
114 double xMin()
const {
return xLog ? std::pow(10.,
x[0]) :
x[0]; }
126 double yMin()
const {
return yLog ? std::pow(10.,
y[0]) :
y[0]; }
144 double x1 =
xLog ? std::log10(x_) : x_;
145 double y1 =
yLog ? std::log10(y_) : y_;
156 if (x1 <
x[0] &&
x[0] - x1 < 1.0e-10) x1 =
x[0];
157 else if (!(x1 <
x[
nx-1]) && x1 -
x[
nx-1] <
tol) x1 =
x[
nx-1];
160 if (y1 <
y[0] &&
y[0] - y1 < 1.0e-10) y1 =
y[0];
161 else if (!(y1 <
y[
ny-1]) && y1 -
y[
ny-1] <
tol) y1 =
y[
ny-1];
192 double mx = (
z[1] -
z[0]) / (
x[1] -
x[0]);
193 double my = (
z[
nx] -
z[0]) / (
y[1] -
y[0]);
194 z1 =
z[0] + mx * (x1 -
x[0]) + my * (y1 -
y[0]);
199 }
else if (y1 <
y[
ny-1]) {
204 double zx0 = gsl_interp2d_eval(
interp,
x,
y,
z,
206 double zx1 = gsl_interp2d_eval(
interp,
x,
y,
z,
208 double mx = (zx1 - zx0) / (
x[1] -
x[0]);
209 z1 = zx0 + mx * (x1 -
x[0]);
244 double mx = (
z[ (
ny-1) *
nx + 1] -
z[ (
ny-1) *
nx ]) /
246 double my = (
z[ (
ny-1) *
nx ] -
z[ (
ny-2) *
nx ])
248 z1 =
z[ (
ny-1) *
nx ] + mx * (x1 -
x[0]) + my * (y1 -
y[
ny-1]);
255 }
else if (x1 <
x[
nx-1]) {
263 double zy0 = gsl_interp2d_eval(
interp,
x,
y,
z,
265 double zy1 = gsl_interp2d_eval(
interp,
x,
y,
z,
267 double my = (zy1 - zy0) / (
y[1] -
y[0]);
268 z1 = zy0 + my * (y1 -
y[0]);
283 }
else if (y1 <
y[
ny-1]) {
294 double zy0 = gsl_interp2d_eval(
interp,
x,
y,
z,
296 double zy1 = gsl_interp2d_eval(
interp,
x,
y,
z,
298 double my = (zy1 - zy0) / (
y[
ny-1] -
y[
ny-2]);
299 z1 = zy1 + my * (y1 -
y[0]);
344 double my = (
z[
nx-1 +
nx] -
z[
nx-1]) / (
y[1] -
y[0]);
345 z1 =
z[
nx-1] + mx * (x1 -
x[
nx-1]) + my * (y1 -
y[0]);
350 }
else if (y1 <
y[
ny-1]) {
355 double zx0 = gsl_interp2d_eval(
interp,
x,
y,
z,
357 double zx1 = gsl_interp2d_eval(
interp,
x,
y,
z,
359 double mx = (zx1 - zx0) / (
x[
nx-1] -
x[
nx-2]);
360 z1 = zx1 + mx * (x1 -
x[
nx-1]);
400 mx * (x1 -
x[
nx-1]) + my * (y1 -
y[
ny-1]);
411 return std::pow(10., z1);
435 static constexpr double tol = 1.0e-8;
A file containing a set of enumerated error codes.
A utility class to handle 1D interpolation.
A class to hold objects where one copy is required per thread.
Basic integer and real types.
A class to handle interpolation on 2D tables.
Definition Interp2D.H:31
~Interp2D()
Destructor.
Definition Interp2D.H:101
const bool zLog
Definition Interp2D.H:430
double operator()(const Real &x_, const Real &y_) const
Caclulate an interpolated value from the table.
Definition Interp2D.H:141
const double zYHi
Definition Interp2D.H:434
const extrapType extrapXHi
Definition Interp2D.H:425
const bool xLog
Definition Interp2D.H:428
const extrapType extrapYHi
Definition Interp2D.H:427
double xMax() const
Return upper limit of table x.
Definition Interp2D.H:120
const extrapType extrapXLo
Definition Interp2D.H:424
const size_t ny
Definition Interp2D.H:423
const size_t nx
Definition Interp2D.H:422
static constexpr double tol
Definition Interp2D.H:435
const double * z
Definition Interp2D.H:421
double xMin() const
Return lower limit of table in x.
Definition Interp2D.H:114
Interp2D(const double *x_, const double *y_, const double *z_, const size_t nx_, const size_t ny_, const extrapType extrapXLo_=extrapError, const extrapType extrapXHi_=extrapError, const extrapType extrapYLo_=extrapError, const extrapType extrapYHi_=extrapError, const bool xLog_=false, const bool yLog_=false, const bool zLog_=false, const double zXLo_=0.0, const double zXHi_=0.0, const double zYLo_=0.0, const double zYHi_=0.0)
Constructor.
Definition Interp2D.H:61
const double zYLo
Definition Interp2D.H:433
double yMax() const
Return upper limit of table y.
Definition Interp2D.H:132
const double * x
Definition Interp2D.H:419
const double * y
Definition Interp2D.H:420
gsl_interp2d * interp
Definition Interp2D.H:439
const double zXLo
Definition Interp2D.H:431
const extrapType extrapYLo
Definition Interp2D.H:426
ThreadVec< gsl_interp_accel * > accY
Definition Interp2D.H:441
const double zXHi
Definition Interp2D.H:432
double yMin() const
Return lower limit of table in y.
Definition Interp2D.H:126
ThreadVec< gsl_interp_accel * > accX
Definition Interp2D.H:440
const bool yLog
Definition Interp2D.H:429
A class to automate private thread copies of objects.
Definition ThreadVec.H:35
IdxType size() const
Return the number of distinct objects stored.
Definition ThreadVec.H:59
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
extrapType
Enum describing different ways to handle extrapolation.
Definition Interp1D.H:22
@ extrapConst
Definition Interp1D.H:25
@ extrapLinear
Definition Interp1D.H:24
@ extrapError
Definition Interp1D.H:23
@ extrapFixedVal
Definition Interp1D.H:27
@ errBadYHiExtrapolation
Definition ErrCodes.H:34
@ errBadYLoExtrapolation
Definition ErrCodes.H:32
@ errBadXLoExtrapolation
Definition ErrCodes.H:28
@ errBadXYExtrapolation
Definition ErrCodes.H:36
@ errBadXHiExtrapolation
Definition ErrCodes.H:30
std::vector< Real >::size_type IdxType
Definition Types.H:45
double Real
Definition Types.H:38