Chebyshev polynomials#

Chebyshev polynomials are used in this program in order to express functions in the range [-1, 1].

This part of the code deals with part of calculating the magnetic field from the poloidal flux \(\psi(r, z)\) and current \( I(r, z)\)

\[ \vec{B} = \frac{1}{r}\left(\frac{\partial \psi}{\partial r} \hat{z} -\frac{\partial \psi}{\partial z} \hat{r} \right) + \frac{I}{r} \hat{\theta} \]

The magnetic field needs to have divergence zero \(\nabla \cdot \vec{B} = 0 \) in order to be compliant with Maxwell’s equations, but the numerical nature of the data attempts against it. In that regard, an expansion of the poloidal flux in the form \(\psi(r, z) = R(r)Z(z)\) will ensure the null divergence by construction (keeping in mind that \( d/d\theta \equiv 0 \) because of the ax-symmetry).

ChebyshevExpansion implements such an expansion using first kind Chebyshev polynomials

\[ \psi(r, z) = \sum_{i, j}^{n}a_{i, j}T_i(x(r))T_j(y(z)) \]
where
\[ a_{i, j} = \left(\frac{2 - \delta_{0k}}{N_x}\right) \left(\frac{2 - \delta_{0l}}{N_y} \right) \sum_{i}^{N_x}\sum_{j}^{N_y} \Psi(r_k, z_l)T_i(x_k)T_j(y_l) \]
and
\[\begin{split} \begin{align} x_k &= \cos\left((k + 1/2)\pi/N_x\right)\\ y_l &= \cos\left((l + 1/2)\pi/N_y\right) \end{align} \end{split}\]
where \( N_x\) and \( N_y\) are the dimensions of the matrix of experimental data.

Enums

enum Variable#

Enumeration of possible variables

Values:

enumerator x#
enumerator y#

Functions

double Chebyshev_T(size_t n, double x)#

Calculate Chebyshev polynomials of first kind of order n at x.

Parameters
  • n – order to which calculate the polynomials.

  • x – value to evaluate the polynomials.

double Chebyshev_U(size_t n, double x)#

Calculate Chebyshev polynomials of second kind of order n at x.

Parameters
  • n – order to which calculate the polynomials.

  • x – value to evaluate the polynomials.

bool Chebyshev_T(size_t n, double x, Array<double> &T)#

Calculate an array of Chebyshev polynomials of first kind from order 0 to order n at x.

Parameters
  • n – order to which calculate the polynomials.

  • x – value to evaluate the polynomials.

  • T – array with n spaces to be filled with the polynomials.

Returns

true if no error occurred.

bool Chebyshev_U(size_t n, double x, Array<double> &U)#

Calculate an array of Chebyshev polynomials of second kind from order 0 to order n at x.

Parameters
  • n – order to which calculate the polynomials.

  • x – value to evaluate the polynomials.

  • U – array with n spaces to be filled with the polynomials.

Returns

true if no error occurred.

bool derivative_Chebyshev_T(size_t n, double x, Array<double> &dT)#

Calculate an array of the derivatives of Chebyshev polynomials of first kind from order 0 to order n at x.

Parameters
  • n – order to which calculate the polynomials.

  • x – value to evaluate the polynomials.

  • dT – array with n spaces to be filled with the polynomials.

Returns

true if no errors occurred.

double Chebyshev_T_expansion_coefficient(size_t idx, size_t idy, ScalarField f, double x_min, double x_max, double y_min, double y_max)#

Calculate the singles coefficient of Chebyshev T expansion for a two variables function from a matrix of its values.

Parameters
  • M – the matrix of values.

  • idx – first index of coefficient.

  • idy – second index of coefficient.

  • x_min – minimum value of x represented in the matrix.

  • x_max – maximum value of x represented in the matrix.

  • y_min – minimum value of y represented in the matrix.

  • y_max – maximum value of y represented in the matrix.

Returns

the coefficient.

void Chebyshev_T_expansion(size_t n, Matrix2D<double> &a, ScalarField f, double x_min, double x_max, double y_min, double y_max)#

Calculate the coefficients of Chebyshev T expansion for a two variables function from a matrix of its values to order n.

Parameters
  • n – order of expansion.

  • a – matrix to store the coefficients.

  • M – the matrix of values.

  • x_min – minimum value of x represented in the matrix.

  • x_max – maximum value of x represented in the matrix.

  • y_min – minimum value of y represented in the matrix.

  • y_max – maximum value of y represented in the matrix.

double evaluate_Chebyshev_T_expansion(size_t n, const Matrix2D<double> &a, double x, double y, double x_min, double x_max, double y_min, double y_max)#

Evaluate a two variable function from its Chebyshev expansion coefficients

Parameters
  • n – order of expansion

  • a – matrix of coefficients.

  • x – first variable value.

  • y – second variable value.

  • x_min – minimum value of x represented in the matrix.

  • x_max – maximum value of x represented in the matrix.

  • y_min – minimum value of y represented in the matrix.

  • y_max – maximum value of y represented in the matrix.

Returns

the function evaluated at (x, y)

double evaluate_derivative_Chebyshev_T_expansion(size_t n, Variable var, const Matrix2D<double> &a, double x, double y, double x_min, double x_max, double y_min, double y_max)#

Evaluate a two variable function’s derivative from its Chebyshev expansion coefficients.

Parameters
  • n – order of expansion

  • var – variable with respect to which calculate the derivative

  • a – matrix of coefficients.

  • x – first variable value.

  • y – second variable value.

  • x_min – minimum value of x represented in the matrix.

  • x_max – maximum value of x represented in the matrix.

  • y_min – minimum value of y represented in the matrix.

  • y_max – maximum value of y represented in the matrix.

Returns

the function evaluated at (x, y)

class ChebyshevExpansion#
#include <chebyshev.hpp>

A class to encapsulate all Chebyshev expansion related functions

Public Functions

inline ChebyshevExpansion(size_t order, ScalarField f, double xmin, double xmax, double ymin, double ymax)#

Calculates the Chebyshev expansion of the scalar field up to order n in the given x, y region

Parameters
  • n – order of the expansion

  • f – scalar field to be expanded

  • x_min – minimum value of x of the expansion

  • x_max – maximum value of x of the expansion

  • y_min – minimum value of y of the expansion

  • y_max – maximum value of y of the expansion

inline double operator()(double x, double y)#

Evaluate the scalar field f from the expansion coefficients

Parameters
  • x – x

  • y – y

Returns

f(x, y)

inline double dx(double x, double y)#

Evaluate the derivative with respect to x of the scalar field f from the expansion coefficients

Parameters
  • x – x

  • y – y

Returns

df_dx(x, y)

inline double dy(double x, double y)#

Evaluate the derivative with respect to y of the scalar field f from the expansion coefficients

Parameters
  • x – x

  • y – y

Returns

df_dy(x, y)

Private Members

size_t n#
Matrix2D<double> a#
double x_min#
double x_max#
double y_min#
double y_max#