Appendix 5.5: Interpolation from User-Supplied Tables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A number of user-supplied tables are used in the |SAS| code.
These tables are of the form :math:`Y \left( i \right)` as a function of :math:`X \left( i \right)`. The
default option is to use linear interpolation between points in the
table to obtain :math:`Y` as a function of :math:`X`. If :math:`X` is between :math:`X \left( J \right)`
and :math:`X \left( J+1 \right)`, then linear interpolation gives

.. math::
	:label: A5.5‑1

	Y\left( X \right) = Y\left( J \right) + \frac{Z\left\lbrack Y \left( J + 1 \right) - Y\left( J \right) \right\rbrack}{\left\lbrack X \left( J + 1 \right) - X\left( J \right) \right\rbrack}

where

.. math::
	:label: A5.5‑2

	Z = X  -  X\left( J \right)

Linear interpolation has the advantages that it is simple to do and it
never exhibits the wild behavior and spurious oscillations that higher
order interpolation schemes can give. On the other hand, linear
interpolation has some disadvantages. One disadvantage is that if only a
few widely-spaced points are used for a table, linear interpolation may
not be very accurate between points. Another disadvantage is that linear
interpolation gives slope discontinuities at the table points. These
slope discontinuities can cause corresponding slope discontinuities in
plots of powers, temperatures, and flow rates calculated by the code.
Sometimes these slope discontinuities correspond to real physical
events, such as scramming the control rods or tripping the pumps; but
usually they are numerical artifacts of the interpolation scheme. In
order to address this problem, alternative interpolation schemes are
available for some of the tables used by the code. :numref:`table-A5.5-1` lists the
interpolation options.

For the third order fit,

.. math::
	:label: A5.5‑3

	Y\left( X \right) = C_{1\text{J}} + C_{2\text{J}}Z + C_{3\text{J}}Z^{2} + C_{4\text{J}} Z^{3}

where the coefficients C are picked such that:

a) :math:`Y` is continuous at :math:`X \left( J \right)` and :math:`X \left( J+1 \right)`.

b) The slope of :math:`Y` is continuous at internal points.

c) The value of :math:`F` is minimized, where

.. math::
	:label: A5.5‑4

	F = \int_{\text{X}_{\text{min}}}^{\text{X}_{\text{max}}}{\left( \frac{\text{d}^2 \text{y}}{\text{dx}^2} \right)^2 \text{dx}}

.. _table-A5.5-1:

.. list-table:: Table Interpolation Options for a Table of :math:`Y \left( i \right)` vs. :math:`X \left( i \right)`, as Determined by the User-Specified Parameter IFIT
    :header-rows: 0
    :align: center
    :widths: auto

    * - :math:`\text{IFIT} \left( K \right) = 0`
      - Use linear fits
    * - 1
      - 3rd order fits
    * - 2
      - 3rd order fits with slope discontinuities at points where :math:`X \left( i+1 \right) - X \left( i \right) < .001`
    * - 3
      - Linear fit to :math:`\log{\left( Y \right)}`
    * - 4
      - 3rd order fit to :math:`\log{\left( Y \right)}`
    * - 5
      - 3rd order fit to :math:`\log{\left( Y \right)}` with slope discontinuities
    * -
      -
    * - :math:`K = 1`
      - Power vs time or user specified reactivity vs time
    * - 2
      - PRIMAR-1 pump head vs time or channel flow vs time
    * - 3
      - PRIMAR-1 inlet temperature vs time
    * - 4
      - PRIMAR-4 pump head, motor torque, or pump speed vs time

Note: For all other tables, linear interpolation is used.

In this equation :math:`X_{\text{min}}` and :math:`X_{\text{max}}` are the first and
last points in the table if IFIT = 1 or 4. If IFIT = 2 or 5, then the
table is broken up into ranges, with the boundaries between ranges
occurring at the points where the slope discontinuities occur. In this
case, the fitting is done separately for each range; and :math:`X_{\text{min}}`
and :math:`X_{\text{max}}` are the points at the ends of the range. There are
some special cases or exceptions:

1. For all fitting options, if :math:`X` is less than the first entry in the
   table, then :math:`Y` is set equal to the first value of :math:`Y` in the table.
   Also, if :math:`X` is greater than the last entry in the table, then the
   last value of :math:`Y` is used.

2. For IFIT = 2 or 5, in an interval where a slope discontinuity occurs
   :math:`\left( X \left( i+1 \right) - X \left( i \right) < .001 \right)` linear interpolation is used
   from :math:`X \left( i \right)` to :math:`X \left( i+1 \right)`.

3. If there are only two points in a range, then linear interpolation is
   used.

4. For IFIT = 1, 2, 4 or 5, if there are only 3 points in a range, then
   a parabola is fitted to the 3 points to determine the values of C in
   the range. Third order fits are only used if there are at least 4
   points in a range.

Care should be taken when using third order fits, since they can result
in spurious wiggles. :numref:`figure-A5.5-1` shows the results of a third order fit
to the power level in the SHRT-17 test in EBR-II. In this case, the
third order fit to the power produces wiggles, whereas the third order
fit to the logarithm of the power produces a smooth curve.

.. _figure-A5.5-1:

..  figure:: media/image27.png
	:align: center
	:figclass: align-center

	Figure A5.5-1. Fit to SHRT-17 Normalized Total Power, Early Times.