xhorizon.shell_junction.interpolators module

Functions used to interpolate and extrapolate coord transformations from reference arrays.

xhorizon.shell_junction.interpolators.interp_with_smooth_extrap(x, x_ref, y_ref, mu=0.0)

Interpolate with smooth extrapolation from the reference endpoints, approaching a line of unit slope as mu*x goes to infinity.

A wrapper for numpy.interp allowing:
  1. custom handling of x values outside the x_ref domain,

  2. scrubbing nan values and sorting ref arrays.

The smooth continuation and decay to unit slope line uses the function

f1(x) = x + (mu/b)*(s0-1.)*(1.-np.exp(-x*b/mu)).

We are specifically working with monotonic functions, which allows us to know whether to approach a slope of +1 or -1. The algorithm is basically tailored to monotonic increasing functions. Monotonic decreasing functions are handled by vertically flipping the reference y_ref array, then proceeding with the monotonic increasing routine. The final result y is then flipped back at the end.

Output y(x) is continuous and once differentiable.

Parameter mu multiplies the decay length for exponentally approaching unit slope line. When mu=0 the extrapolation is not differentiable, the line of extrapolation is just y=x. As mu goes to infinity, the line of extrapolation becomes linear, and this function approaches interp_with_linear_extrap.

xhorizon.shell_junction.interpolators.f1(x, s0=1.0, mu=0.0, b=1.0)

Monotonic function f(x) passing through origin with slope s0, such that slope decays to 1 as mu*x goes to infinity. Inputs:

x = An array of x values to evaluate. s0 = Slope at the origin, used for differentiable matching. mu = Exponential decay length is mu/b. Typically use mu as overall user controlled multiplier. b = Exponential decay length is mu/b. Typically use b to set an algorithmic length scale control.

e.g. setting b = |ln(s0)| causes a stronger exponential decay when s0>>1 or s0<<1.

Parameters mu and b are separate only for convenience and implementation.

Returns:

y = Array of values f(x).

xhorizon.shell_junction.interpolators.get_dy0(x, y)

Find initial slope by iterating until finite. Avoids issues with repeated initial point.

xhorizon.shell_junction.interpolators.get_dy1(x, y)

Find final slope by iterating until finite. Avoids issues with repeated final point.

xhorizon.shell_junction.interpolators.test2()

Test interp_with_smooth_extrap.

xhorizon.shell_junction.interpolators.test3()

Test interp_with_smooth_extrap. Decreasing functions now work.