Compute the derivative directly (not using epsilon parameter).
This commit is contained in:
parent
9c226c1b24
commit
49a53f1935
@ -74,12 +74,15 @@ namespace Opm
|
|||||||
const std::vector<T>& yv,
|
const std::vector<T>& yv,
|
||||||
double x)
|
double x)
|
||||||
{
|
{
|
||||||
double epsilon = 1e-4; // @@ Ad hoc, should choose based on xv.
|
std::vector<double>::const_iterator lb = std::lower_bound(xv.begin(), xv.end(), x);
|
||||||
double x_low = std::max(xv[0], x - epsilon);
|
int lb_ix = lb - xv.begin();
|
||||||
double x_high = std::min(xv.back(), x + epsilon);
|
if (lb_ix == 0) {
|
||||||
T low = linearInterpolation(xv, yv, x_low);
|
return 0.;
|
||||||
T high = linearInterpolation(xv, yv, x_high);
|
} else if (lb_ix == int(xv.size())) {
|
||||||
return (high - low)/(x_high - x_low);
|
return 0.;
|
||||||
|
} else {
|
||||||
|
return (yv[lb_ix] - yv[lb_ix - 1])/(xv[lb_ix] - xv[lb_ix - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user