The TCV Psi-Toolbox reference guide

Contents

  1. psitbxdcd
  2. psitbxdcd/intersect
  3. psitbxfun
  4. psitbxfun/cumsum
  5. psitbxfun/mean
  6. psitbxfun/psitbxf2f
  7. psitbxfun/sum
  8. psitbxfun Mathematical operators and functions
  9. psitbxgrid
  10. psitbxgrid/metric
  11. psitbxgrid/psitbxg2g
  12. psitbxpsi
  13. psitbxpsi/psitbxfsg
  14. psitbxpsi/psitbxp2p
  15. psitbxtcv


<< psitbxdcd


Purpose

Creates a psitbxdcd object containing the description of the geometry of the chords of a diagnostic.

Syntax

dcd = psitbxdcd(rd,zd,phid,pvd,tvd,nd,t)

Description

The function psitbxdcd is used to create a psitbxdcd object that contains the description of the geometry of the chords of a diagnostic. The fields of a psitbxdcd object and the corresponding input arguments have the following meaning:

rd
The radial position in cylindrical coordinate of a reference point along the chord, very often the pin-hole

zd
The vertical position of the same point

phid
The toroidal angle of the same point

pvd
The poloidal viewing angle, measured between the horizontal plane and the chord, positive if the chord is pointing above the plane

tvd
The toroidal viewing angle, measured between the vertical plane containing the machine axis and the chord reference point and the vertical plane containing the chord itself, positive if the chord is looking in the direction of increasing toroidal angle

nd
The number of points used to discretise the chord when building a psitbxgrid object of type 'Diagnostic-Chords'

t
The time base for moving chords

The size of rd,zd,phid,pvd,tvd follows the following rules:

Example

Example 1

Here is an example with two cameras with 20 detectors each, the first one with a poloidal coverage, the second one with a toroidal coverage:

rd = 1.2;
zd = 0;
phid = pi/8;
pvd = [linspace(-pi/3,pi/3,20);zeros(1,20)];
tvd = [zeros(1,20);linspace(-pi/3,pi/3,20)];
dcd = psitbxdcd(rd,zd,phid,pvd,tvd)
 dcd is a PsiTbx-Diagnostic-Chord-Description object =
      rd: [2x20 double]
      zd: [2x20 double]
    phid: [2x20 double]
     pvd: [2x20 double]
     tvd: [2x20 double]
      nd: 81
       t: []
plot(dcd)

Example 2: moving chord

The possibility to have real-time scaning diagnostic is included. In that case the last dimension of the fields of the psitbxdcd object represents the time base. Given as an example Le cauchemar du gyrotroniste:

td = linspace(0,1,73);
rd = 1.2;
zd = 0;
phid = pi/2;
pvd = pi/6*cos(pi*td);
tvd = pi/6*sin(2*pi*td);
LeCauchemarDuGyrotroniste = psitbxdcd(rd,zd,phid,pvd,tvd,[],td);
plot(LeCauchemarDuGyrotroniste)


<< psitbxdcd/intersect


Purpose

Computes the intersection between diagnostic chords described by a psitbxdcd object and a cylindrical coordinate grid contained in a psitbxgrid object.

Syntax

s = intersect(dcd,g)

Description

The method intersect applies to a psitbxdcd object and computes the intersection between the chords and a grid in cylindrical coordinates. It returns an array of linear coordinates along the chords of size [dcd.nd,size(dcd)]. The main purpose of intersect is to provide the coordinate of the points for building a psitbxgrid object of type 'Diagnostic-Chords'.

For those chords who do not cross the domain of the grid, NaN's are returned. For those chords who cross the domain twice, the first segment is considered.

Example

dcd = psitbxdcd('Demo');
s = intersect(dcd,psitbxgrid('Cylindrical','Grid','Default'));
gdc = psitbxgrid('Diagnostic-Chords','Points',{s},dcd)
 gdc is a PsiTbx-Grid object =
       type: 'Diagnostic-Chords'
      label: {1x1 cell  }
    storage: 'Points'
          x: {1x1 cell  }
          t: []
        par: [1x1 struct]
        csp: [1x1 struct]

Algorithm

Only awfull calculation of intersections between lines, planes and cylinders using analytical geometry.


<< psitbxfun


Purpose

Creates a psitbxfun object containing a function defined on a spatial grid.

Syntax

f = psitbxfun(x,g)

f = psitbxfun(x,g,t)

Description

The function psitbxfun is used to create a psitbxfun object that contains a function defined on a spatial grid. If this function does not depend on time, psitbxfun(x,g) is used with x containing the function value(s) defined on the psitbxgrid g. If the function varies in time, use the form psitbxfun(x,g,t).

The size of the matrix x must be [size(g)[,n1,...][,nt]]. The optional dimension n1,... can be used for multi-value functions (for example the wave length for spectroscopic measurements). If the time argument is given, then the last dimension of x, nt must correspond to length(t).

For degenerated coordinates, that have a size of one, the following rules apply:

Singleton dimension in x arising from degenerated coordinates can be omitted.

Example

Example 1

A fairly simple function defined on a cylindrical coordinate grid:

rzphi = {0.62:.02:0.7,-.05:.02:.05,pi/180*(-3:2:3)};
g = psitbxgrid('Orthogonal','Grid',rzphi);
[rzphi{:}] = ndgrid(rzphi{:});
x = exp(-300*(rzphi{1} - g.x{1}(1)).^2) .* exp(-3000*rzphi{2}.^2);
f = psitbxfun(x,g)
 f is a PsiTbx-Function object =
       x: [5x6x4 double    ]
    grid: [5x6x4 psitbxgrid]
       t: []
plot(f)

Example 2

A very common concept in Tokamak physics is the profile, that is a quantity constant on a flux surface and therefore depending only on the flux coordinate. Such a profile is trivialy represented by a function on a 1-D grid, here the canonical parabolic profile:

g = psitbxgrid('Flux','Grid',{linspace(0,1,41),NaN,NaN});
f = psitbxfun(1-linspace(0,1,41)'.^2,g)
 f is a PsiTbx-Function object =
       x: [41x1   double    ]
    grid: [41x1x1 psitbxgrid]
       t: []
plot(f)


<< psitbxfun/cumsum


Purpose

Method to compute the indefinite integral of a psitbxfun object over spatial coordinates

Syntax

f = cumsum(f,dim)

f = cumsum(f,dim,'metric')

Description

The method cumsum applies on a psitbxfun object defined on grid with 'Grid' storage and returns a psitbxfun containing its indefinite integral along the specified dimensions dim. For example if dim = 1, the integral is performed along the first coordinate, if dim = [2,3], the surface integral along coordinates 2 and 3 is returned, if dim = [1,2,3], the volume integral is returned.

By specifying the option 'metric', the appropriate metric will be taken into account; simply the function f.*metric(f.grid,dim) is integrated.

Algorithm

Uses a trapeze integration.


<< psitbxfun/mean


Purpose

Method to average a psitbxfun object over spatial coordinates

Syntax

f = mean(f,dim)

f = mean(f,dim,w)

f = mean(f,dim,'metric')

f = mean(f,dim,w,'metric')

Description

The method mean applies on a psitbxfun object defined on grid with 'Grid' storage and returns a psitbxfun containing the function averaged along the specified dimensions dim. For example if dim = 1, the average is performed along the first coordinate, if dim = [2,3], the surface average along coordinates 2 and 3 is returned, if dim = [1,2,3], the volume average is returned.

Note that the grid on which the returned function is defined will become degenerated in the dimension along which average is carried out.

In the call mean(f,dim,w), w is a psitbxfun object playing the role of a weight in the average.

By specifying the option 'metric', the appropriate metric will be taken into account; simply the function f.*metric(f.grid,dim) is average.

Example

Average plasma current density

jphi = psitbxtcv(10000,'JPHI');
jphiavg = mean(jphi,[1,2],'metric');
plot(jphiavg)

Algorithm

"mean(f,dim,w)
sum(f.*w,dim)./sum(w,dim)

mean(f,dim,w,'metric')
sum(f.*w.*metric(f.grid,dim),dim)./sum(w.*metric(f.grid,dim),dim)


<< psitbxfun/psitbxf2f


Purpose

Method to interpolate a psitbxfun object on a specified grid.

Syntax

f2 = psitbxf2f(f,g2)

f2 = psitbxf2f(f,g2,der)

f2 = psitbxf2f(f,der)

Description

The method psitbxf2f applies on a psitbxfun object to interpolate the embended function on new space points. In the call psitbxf2f(f,g2) the psitbxfun object represents a function defined on a psitbxgrid which must have 'Grid' storage. g2 is a psitbxgrid object specifying the new space points on which the function f must be interpolated. Those can be given in any coordinate systems. Points outside the definition domain of the function will be assigned a NaN. If any coordinate of g2 is a NaN, which means that any function defined on g2 is independant of this coordinate, then the function f must also be independant along the corresponding coordinate.

The optional argument der is a three element vector that specifies the spatial derivative order to apply along each spatial coordinate. Note that since functions are interpolated with cubic spline, any order bigger than 3 will results in a zero function.

Example

Example 1

How to compute the normalised flux coordinate along diagnostic chords:

dcd = psitbxdcd('Demo');
psi = psitbxtcv(10000,.5,'01');
gdc = psitbxgrid('Diagnostic-Chords','Points',{intersect(dcd,psi.grid)},dcd);
rho = sqrt(psitbxf2f(psi,gdc));
plot(rho)

Example 2

How to compute the radial derivative of the poloidal flux which is related to the vertical magnetic field:

psi = psitbxtcv(10000);
dpsidz = psitbxf2f(psi,[1,0,0]);
plot(dpsidz)

Algorithm

In a first step the points of g2 where the function f must be interpolated are transformed to compute their coordinates in the coordinate system on which the function f is defined, using the method psitbxg2g. Then the function f is interpolated in each spatial direction with cubic splines. The edge conditions are Not-A-Knot conditions except along angular coordinates which span 2×pi, in which case periodic edge conditions are used. Finaly this cubic spline interpolant is evaluated at the new positions, to the appropriate derivative order.

Note that interpolation requires the function to be smooth. For example interpolating the square-root of the poloidal flux defined in cylindrical coordinates yields problem on the magnetic axis where its first derivative is not continuous.


<< psitbxfun/sum


Purpose

Method to integrate a psitbxfun object over spatial coordinates

Syntax

f = sum(f,dim)

f = sum(f,dim,'metric')

Description

The method sum applies on a psitbxfun object defined on grid with 'Grid' storage and returns a psitbxfun containing the function integrated along the specified dimensions dim. For example if dim = 1, the integral is performed along the first coordinate, if dim = [2,3], the surface integral along coordinates 2 and 3 is returned, if dim = [1,2,3], the volume integral is returned.

Note that the grid on which the returned function is defined will become degenerated in the dimension along which integration is carried out.

By specifying the option 'metric', the appropriate metric will be taken into account; simply the function f.*metric(f.grid,dim) is integrated.

Example

A non trivial way to compute the plasma current

jphi = psitbxtcv(10000,'JPHI');
ip = sum(jphi,[1,2]);
plot(ip)

Algorithm

Uses a trapeze integration.


<< psitbxfun Mathematical operators and functions


Purpose

Methods for mathematical operations on psitbxfun objects

Syntax

f = f + a

f = f + g

f = f .* a

f = sqrt(f)

f = f > 0

Description

Most of the mathematical operators and functions have been overloaded for psitbxfun objects. For multi operand functions, the following rules apply:

Example

Express the current density in MA/m2

jphi = psitbxtcv(10000,'JPHI')/1e6;


<< psitbxgrid


Purpose

Creates a psitbxgrid object containing the definition of a spatial grid

Syntax

g = psitbxgrid(type,storage,x[,p1,...])

Description

The function psitbxgrid is used to create a psitbxgrid object that contains the description of a spatial grid. The usual call is psitbxgrid(type,storage,x).

type

The character argument type specifies which coordinate system is used. Possible choices are:

'Orhogonal'
This is the usual orthogonal cartesian coordinate system:
X
This axis lies on the midplane at toroidal position zero between sector #16 and #1, zero on machine axis
Y
This axis lies on the midplane at toroidal position pi/2, zero on machine axis
Z
This axis coincides with machine axis pointing upward, zero on the midplane

'Cylindrical'
The cylindrical coordinate system whose axis coincides with the main axis of the machine:
R
The radial coordinate
Z
The vertical coordinate, posivite upward, zero on the midplane
Phi
The azimutal coordinate, positive ccw seen from the top, zero between sector #16 and #1

'Toroidal'
The toroidal coordinate system whose main axis coincides with the main axis of the machine:
A
The minor radius measured from the axis whose cylindrical coordinates are (R0,Z0)
Theta
The poloidal angle, zero on the HFS midplane, positive cw (This strange definition to get a right handed system; this also corresponds to the magnetic probe ordering)
Phi
The toroidal angle, positive ccw seen from the top, zero between sector #16 and #1

'Flux-coordinate'
Rho
The flux coordinate, usually the square-root of the poloidal flux normalised such that it is zero on magnetic axis and one on the last close flux surface. But can also be for example the toroidal flux
Theta
The poloidal angle, zero on the HFS midplane, positive cw (strange definition to get a right handed system; this also corresponds to the magnetic probe ordering)
Phi
The toroidal angle, positive ccw seen from the top, zero between sector #16 and #1

'Diagnostic-Chords'
This one dimensional coordinate system allows to scan a chord of a diagnostic:
S
The linear distance along the chord measured from the chord reference point (see psitbxdcd)

storage

The character argument storage specifies the way the grid points are stored in the x field of the psitbxgrid object. This field and argument is a cell array containing three double arrays. Possible values for storage are:

'Grid'
In this case the grid is made of the points of a mesh specified by the three vectors of x. Note that this storage method can not be used with Diagnostic-Chords
'Points'
This storage method is used for points which does not align on a grid. In that case all the arrays of x must have the same size and the grid is made of the points whose coordinates by each triplet. Note that the shape of these arrays is free and can reflect the organisation of the problem
'Time-Points'
This form is used for points which move in time. All the arrays of x must also be of the same size but in addition their last dimension represents time samples

For 1-D or 2-D grids, the corresponding array in x can be replaced either by a constant, for example for things that lie entirely on a plane, or by a single NaN which means that the problem does not depend on this particular coordinate. A grid can also be extended to other dimension that the basic space and time coordinates. For example a fourth dimension can be added that would represents a frequency or a wave length if necessary.

There are some combinations of type and storage for which the x argument can be given as the string 'Default', which will returns a predefined grid, in particular psitbxgrid('Flux-Coordinate','Grid','Default')

Optional arguments

For its points to be absolutely positioned in space, some coordinate systems requires additional information. Such an information is given in a list of optional arguments to the function psitbxgrid. Here is a list of these pieces of information:

t
The time base for 'Time-Points' storage. It can be found in:

r0,z0
The position of the axis for a 'Toroidal' coordinate system or of the magnetic axis for a 'Flux-Coordinate' system. Note that this axis can move in time, in which case its size must be coherent with the time base. It can be found in:

psi
A psitbxpsi object containing the distribution in cylindrical coordinate of the normalised poloidal flux. This information can be optionaly given for a 'Flux-Coordinate' grid. It can be found in:

fsd
A psitbxpsi object containing the description of the constant poloidal flux contour in toroidal coordinates. This information can be optionaly given for a 'Flux-Coordinate' grid. It can be found in:

dcd
The description of diagnostic chords. This information is required for grid of type 'Diagnostic-Chords' and can be found in:

Example

Example 1

A 'Toroidal' grid with 'Grid' storage

x = {linspace(0,.2,6),linspace(-pi,pi,7),linspace(0,2*pi,25)};
r0z0 = {1,0};
g = psitbxgrid('Toroidal','Grid',x,r0z0)
 g is a PsiTbx-Grid object =
       type: 'Toroidal'
      label: {1x3 cell  }
    storage: 'Grid'
          x: {1x3 cell  }
          t: []
        par: [1x1 struct]
        csp: [1x1 struct]
plot(g)

Example 2

Two probes moving along the Z direction

t = linspace(0,.1,11);
x = {repmat([.6;.7],1,11),[t;t]-.75,pi/3};
g = psitbxgrid('Cylindrical','Time-Points',x,t)
 g is a PsiTbx-Grid object =
       type: 'Cylindrical'
      label: {1x3  cell  }
    storage: 'Time-Points'
          x: {1x3  cell  }
          t: [1x11 double]
        par: [1x1  struct]
        csp: [1x1  struct]
plot(g)


<< psitbxgrid/metric


Purpose

Method to compute the metric of a psitbxgrid object

Syntax

f = metric(g,dim)

Description

The method metric applies on a psitbxgrid object with 'Grid' storage and returns a psitbxfun containing the metric along the specified dimensions dim. For example if dim = 1, the metric along the first coordinate is returned, if dim = [2,3], the metric of the surface element along coordinates 2 and 3 is returned, if dim = [1,2,3], the volume element is returned. In addition if dim is negative, the norm of the gradient of the specified coordinate is returned.

Example

The very important gradient of rho entering the expression of the SEF (Shape Enhancement Factor)

fsd = psitbxtcv(10000,'FS');
grho = metric(fsd,-1);
plot(grho)

Algorithm

For the flux-coordinate system, the metric matrix is not diagonal; for the others it is trivial. Here are the formulae:


<< psitbxgrid/psitbxg2g


Purpose

Method to transform a psitbxgrid object on a different coordinate system

Syntax

g2 = psitbxg2g(g,type)

g2 = psitbxg2g(g,type,p1,...)

Description

The method psitbxg2g applies on a psitbxgrid object to transform the coordinates of its points in a new coordinate system. In the call psitbxg2g(g,type), g is a psitbxgrid object and type a character string that specifies the new coordinate system; it can take the value of the type argument of the psitbxgrid function. psitbxg2g returns a psitbxgrid object with the same spatial points but with coordinates expressed in the new system.

Note that the storage may be altered; in particular 'Grid' storage may be transformed in 'Points' or 'Time-Points' storage because points in the new system do not align on a grid anymore.

It is impossible to map points on a 'Diagnostic-Chords' system, since this system is discrete in space.

Some transformations require additional information that will be sought in the par field of the g argument or in additional optional arguments, following the same rules as for the psitbxgrid function. These transformations are:

Cylindrical to toroidal and toroidal to cylindrical
Requires r0 and z0

Cylindrical to Flux coordinate
Requires r0, z0 and a psitbxpsi of form '01'

Flux coordinate to toroidal
Requires a psitbxpsi of form 'FS'

Example

Position of the chord points in toroidal coordinates:

dcd = psitbxdcd('Demo');
s = intersect(dcd,psitbxgrid('Cylindrical','Grid','Default'));
gdc = psitbxgrid('Diagnostic-Chords','Points',{s},dcd);
g = psitbxg2g(gdc,'Toroidal',{.89,0});
plot(g)

Algorithm

There are a set of basic transformations defined. All the others are composed from the basic set, which is:


<< psitbxpsi


Purpose

Creates a psitbxpsi object containing the poloidal flux description or the flux surface description.

Syntax

psi = psitbxpsi(x,grid,t,form)

psi = psitbxpsi(x,grid,t,form,rmag,zmag)

psi = psitbxpsi(x,grid,t,form,rmag,zmag,iter,tol)

Description

The function psitbxpsi is used to create a psitbxpsi object, which is a child of the psitbxfun class that contains either the poloidal flux in cylindrical coordinates or the flux surface contours in toroidal coordinates. In the call psitbxpsi(x,grid,t,form) depending on the form argument:

'FS'
x is the minor radius in toroidal geometry of the surfaces of constant poloidal flux. x must be defined on the psitbxgrid object grid of type 'Flux-Coordinate' with storage 'Grid'. t is the time base.

'10','+0','-0','01'
x is the poloidal flux defined on the psitbxgrid object grid of type 'Cylindrical' with storage 'Grid'. The first character of form represents the value or the sign of the poloidal flux on the magnetic axis, the second on the last close flux surface. '+0' is the LIUQE representation, '01' the normalised flux used for flux coordinate.

Optional arguments allows to specify the position of the magnetic axis rmag and zmag and convergence parameters for the method psitbxp2p, iter and tol.


<< psitbxpsi/psitbxfsg


Purpose

Method to compute geometrical quantities from a psitbxpsi object

Syntax

fsg = psitbxfsg(fsd)

Description

The method psitbxfsg applies on a psitbxpsi object with format 'FS' and returns a structure with fields of class psitbxfun:

grho
flux surface average of the gradient of rho
surf
flux surface area
area
flux surface cross-section
vol
volume inside a flux surface
darea
cross-section between two flux surfaces divided by the flux coordinate increment
dvol
volume between two flux surfaces divided by the flux coordinate increment

Example

fsd = psitbxtcv(10000,'FS');
fsg = psitbxfsg(fsd);
plot(fsg.grho)

Algorithm

Uses the following definitions:

grho
mean(metric(g,-1),[2,3])
surf
sum(metric(g,[2,3]),[2,3])
area
cumsum(sum(metric(g,[1,2]),2),1)
vol
cumsum(sum(metric(g,[1,2,3]),[2,3]),1)
darea
sum(metric(g,[1,2]),2)
dvol
sum(metric(g,[1,2,3]),[2,3])


<< psitbxpsi/psitbxp2p


Purpose

Method to change the format of a psitbxpsi object

Syntax

psi = psitbxp2p(psi,'01')

fsd = psitbxp2p(psi,'FS')

fsd = psitbxp2p(psi,'FS',g)

Description

The method psitbxp2p applies on a psitbxpsi object and returns a psitbxpsi object with the specified form:

'01'
The poloidal flux contained in the psi argument wil be searched for its maximum, normalised and the location of the maximum stored in the rmag and zmag fields

'FS'
The contours of constant normalised poloidal flux will be searched. A third argument allows to specify the flux-coordinate grid on which these contours are to be sought.

Example

psi = psitbxtcv(10000,.5);
fsd = psitbxp2p(psi,'FS');
plot(fsd)

Algorithm

Uses Gauss-Newton iterations to locate either the maximum or the contour level. Iteration convergence is controlled by the iter and tol fields of the psitbxpsi object.


<< psitbxtcv


Purpose

Easy access to quantities relevant for the Psi-Toolbox directly from the TCV shot files

Syntax

psitbxtcv(shot,form)

psitbxtcv(shot,time,form)

Description

The function psitbxtcv builds object compatible with the Psi-Toolbox from the TCV shot files. Depending on the form argument it returns:

'+0'
A psitbxpsi object of form '+0' containing the poloidal flux from the equilibrium reconstruction by LIUQE

'01'
A psitbxpsi object of form '01' containing the poloidal flux from the equilibrium reconstruction by LIUQE normalised using the psitbxp2p method

'FS'
A psitbxpsi object of form 'FS' containing the flux surface description as precalculated by the Psi-Toolbox and stored in the shot file

'JPHI'
A psitbxfun object containing the toroidal current density from the equilibrium reconstruction by LIUQE

An optional time argument can be specified. Only the times for which a sample in the shot file at most 1e-6 second away exists are returned.

Example

psi = psitbxtcv(10000,'+0')
 psi is a PsiTbx-Poloidal-Flux object =
       format: '+0'
         rmag: []
         zmag: []
    psitbxfun: [28x65x46 psitbxfun]
         iter: 10
          tol: 1.0000e-04
plot(psi)