5.2. Construction of FineContour objects

FineContour objects are created initially from PsiContour objects; this is largely for historical reasons, as PsiContour was introduced first, and FineContour added later to improve accuracy and robustness.

After the FineContour is created, or when it is modified (for example adding extra points beyond a boundary, or decreasing the length when a wall intersects the initial contour), it is then adjusted to ensure constant poloidal spacing of its points, using:

FineContour.equaliseSpacing(*, psi, reallocate=False)

Adjust the positions of points in this FineContour so they have a constant distance between them.

Algorithm:

  1. Refine all points using refine().

  2. Calculate the poloidal distances along the FineContour, and the spacings between adjacent points.

  3. Check if the spacings are constant, with an absolute tolerance given by the finecontour_atol setting. If so, stop iterating.

  4. Create an interpolation function for the R and Z positions of this FineContour as a function of poloidal distance, using interpFunction().

  5. Create a new set of points using the interpolation functions, with a uniform grid of poloidal distances as input.

  6. If the iteration count is greater than 8 and finecontour_overdamping_factor is not 1.0, ‘overdamp’ the iteration by setting the new points as a sum of the new interpolated values (weighted by finecontour_overdamping_factor) and the old values (weighted by (1-finecontour_overdamping_factor)).

  7. Return to 1.

As the interpolation is very accurate when the new points are very close to the old points (Taylor expansion around the old points is accurate because the displacement is small), this iteration usually converges fairly quickly.

If this method produces errors, setting finecontour_diagnose = True will produce some more output which may help diagnose them.

The FineContour objects only depend on the \(\psi\)-value of the contour and number of points (set by finecontour_Nfine), not on the poloidal spacing settings for the grid, etc. (the initial guess for the iteration may depend on these, but this dependence is eliminated by the iteration, up to the finecontour_atol tolerance). This independence should ensure the consistency of the calculated poloidal distances, metric coefficients, etc. when input parameters, e.g. resolution, are varied.