Stellarator-Tools
utilities Module Reference

This file contains utilities for converting the siesta grids. More...

Data Types

interface  to_full_mesh
 Interface to convert between half and full mesh using either to_full_mesh2 or to_full_mesh3. More...
 
interface  to_half_mesh
 Interface to convert between full and half mesh using either to_half_mesh or to_half_mesh_p. More...
 
interface  gradienthalf
 Interface to take the gradianet from full to half mesh using either GradientHalf or GradientHalf_p. More...
 
interface  curl_htof
 Interface to take the curl on a half mesh quantity and return a full mesh using either curl_htof or curl_htof_targ. More...
 
interface  set_bndy_fouier_m0
 Interface to set the fouier conditions on a quantity for either scalar set_bndy_fouier_m0 or vector set_bndy_fouier_m0_vec quantities. More...
 

Functions/Subroutines

subroutine gradienthalf (gradienth, vecf)
 Calculate the gradient to the half mesh from a full mesh quantity. More...
 
subroutine gradienthalf_p (gradienth, vecf)
 Calculate the gradient to the half mesh from a full mesh quantity. More...
 
subroutine gradientfull (gradientf, vech)
 Calculate the gradient to the full mesh from a half mesh quantity. More...
 
subroutine to_half_mesh (vecf, vech)
 Migrates a full mesh quantity to the half mesh. More...
 
subroutine to_half_mesh_p (vecf, vech)
 Migrates a full mesh quantity to the half mesh. More...
 
subroutine to_full_mesh3 (vech, vecf)
 Migrate a three dimensional quantity form the half mesh to the full mesh. More...
 
subroutine to_full_mesh2 (vech, vecf)
 Migrate a two dimensional quantity form the half mesh to the full mesh. More...
 
subroutine curl_ftoh (asubsmnf, asubumnf, asubvmnf,
 Compute curl of the full grid quantity a on the half grid. More...
 
subroutine curl_htof (bsubsmnh, bsubumnh, bsubvmnh,
 Compute curl of the half grid quantity a on the full grid. More...
 
subroutine curl_htof_targ (bsubsmnh, bsubumnh, bsubvmnh,
 Convert allocatable to pointer for use in curl_htof. More...
 
pure subroutine set_bndy_half_to_full (amnh, amnf, nsmin, parity, f
 Set fouier boundary conditions for full grid quantity converted from half grid. More...
 
pure subroutine set_bndy_half_to_full_ds (amnh, amnf_ds, nsmin, par
 Set fouier boundary conditions for full grid radial derivative quantity converted from half grid. More...
 
pure subroutine set_bndy_full_origin (amnsf, amnuf, amnvf, flags)
 Apply origin vector boundary conditions. More...
 
pure subroutine set_bndy_fouier_m0 (amn, parity)
 Set vector fourier conditions. More...
 
pure subroutine set_bndy_fouier_m0_vec (amns, amnu, amnv, parity)
 Set vector fourier conditions. More...
 
subroutine div_h (jbsupsmnh, jbsupumnh, jbsupvmnh,
 Compute the divergence of a half grid quantity. More...
 
logical function test_utilities ()
 Test utility routines. More...
 
logical function test_div (jbsupsmnh, jbsupumnh, jbsupvmnh, parity, nsmin,
 Test divergence of a half grid quantity. More...
 

Detailed Description

This file contains utilities for converting the siesta grids.

Function/Subroutine Documentation

◆ curl_ftoh()

subroutine utilities::curl_ftoh (   asubsmnf,
  asubumnf,
  asubvmnf 
)

Compute curl of the full grid quantity a on the half grid.

The contravariant components of jac*Curl A are equal to

sqrt(g)*B^k = dA_j/du^i - dA_i/du^j (j)

for cyclic permutations of i,j,k. This routine does not remove the jacobian factor. The arrays must be passed in as ALLOCATABLE or POINTER to preserve the array bounds.

Parameters
[in]asubsmnfCovariant vector in the s direction full grid.
[in]asubsmnfCovariant vector in the u direction full grid.
[in]asubsmnfCovariant vector in the v direction full grid.
[in,out]jbsubsmnhContravariant vector in the s direction with jacobian factor half grid.
[in,out]jbsubsmnhContravariant vector in the u direction with jacobian factor half grid.
[in,out]jbsubsmnhContravariant vector in the v direction with jacobian factor half grid.
[in]parityParity flag.
[in]nsminMinimum radial index.
[in]nsmaxMaximum radial index.

◆ curl_htof()

subroutine utilities::curl_htof ( real (dp), dimension(:,:,:), intent(in), allocatable  bsubsmnh,
real (dp), dimension(:,:,:), intent(in), allocatable  bsubumnh,
real (dp), dimension(:,:,:), intent(in), allocatable  bsubvmnh 
)

Compute curl of the half grid quantity a on the full grid.

The contravariant components of jac*Curl A are equal to

sqrt(g)*K^k = dB_j/du^i - dB_i/du^j (j)

for cyclic permutations of i,j,k. This routine does not remove the jacobian factor. The arrays must be passed in as ALLOCATABLE or POINTER to preserve the array bounds.

Parameters
[in]bsubsmnhCovariant vector in the s direction half grid.
[in]bsubsmnhCovariant vector in the u direction half grid.
[in]bsubsmnhCovariant vector in the v direction half grid.
[in,out]jKsubsmnfContravariant vector in the s direction with jacobian factor full grid.
[in,out]jKsubsmnfContravariant vector in the u direction with jacobian factor full grid.
[in,out]jKsubsmnfContravariant vector in the v direction with jacobian factor full grid.
[in]parityParity flag.
[in]nsminMinimum radial index.
[in]nsmaxMaximum radial index.
[in]nsendEnding row index.
[in,out]curtorCurrent enclosed at the boundary.

◆ curl_htof_targ()

subroutine utilities::curl_htof_targ ( real (dp), dimension(:,:,:), intent(in), allocatable  bsubsmnh,
real (dp), dimension(:,:,:), intent(in), allocatable  bsubumnh,
real (dp), dimension(:,:,:), intent(in), allocatable  bsubvmnh 
)

Convert allocatable to pointer for use in curl_htof.

Parameters
[in]AsubsmnhCovariant vector in the s direction half grid.
[in]AsubsmnhCovariant vector in the u direction half grid.
[in]AsubsmnhCovariant vector in the v direction half grid.
[in,out]jBsubsmnfContravariant vector in the s direction with jacobian factor full grid.
[in,out]jBsubsmnfContravariant vector in the u direction with jacobian factor full grid.
[in,out]jBsubsmnfContravariant vector in the v direction with jacobian factor full grid.
[in]parityParity flag.
[in]nsminMinimum radial index.
[in]nsmaxMaximum radial index.
[in]nsendEnding row index.
[in,out]curtorCurrent enclosed at the boundary.

◆ div_h()

subroutine utilities::div_h (   jbsupsmnh,
  jbsupumnh,
  jbsupvmnh 
)

Compute the divergence of a half grid quantity.

This operator is used for unit testing of the curl operator. Divergence is defined as

DIV(B) = 1/sqrt(g)d/dx (JB^x} for x = s,u,v (1)

Note for testing that divergence remains zero, add a 1/sqrt(g) term is not necessary to retain.

Parameters
[in]jasupsmnhContravariant vector in the s direction half grid.
[in]jasupsmnhContravariant vector in the u direction half grid.
[in]jasupsmnhContravariant vector in the v direction half grid.
[in,out]divmnfDiverence on the full grid.
[in]parityParity flag.
[in]nsminMinimum radial index.
[in]nsmaxMaximum radial index.

◆ gradientfull()

subroutine utilities::gradientfull (   gradientf,
real (dp), dimension(:,:,:), intent(in), allocatable  vech 
)

Calculate the gradient to the full mesh from a half mesh quantity.

The arrays must be passed in as ALLOCATABLE to preserve the array bounds. There are three scenarios we need to anticipate for the radial dimension. The easiest is when the upper bound of gradientf matches vech. Otherwise vech can be the full ns range of one more than the gradientf. To handle this an extra is calculated which can be a maximum of one.

Parameters
[in,out]gradientfGradient on the full grid.
[in]vechHalf grid quantity.

◆ gradienthalf()

subroutine utilities::gradienthalf (   gradienth,
real (dp), dimension(:,:,:), intent(in), allocatable  vecf 
)

Calculate the gradient to the half mesh from a full mesh quantity.

The arrays must be passed in as ALLOCATABLE to preserve the array bounds.

Parameters
[in,out]gradienthGradient on the half grid.
[in]vecfFull grid quantity.

◆ gradienthalf_p()

subroutine utilities::gradienthalf_p (   gradienth,
real (dp), dimension(:,:,:), pointer  vecf 
)

Calculate the gradient to the half mesh from a full mesh quantity.

The arrays must be passed in as ALLOCATABLE to preserve the array bounds. Full vector is passed in as a pointer.

Parameters
[in,out]gradienthGradient on the half grid.
[in]vecfFull grid quantity.

◆ set_bndy_fouier_m0()

pure subroutine utilities::set_bndy_fouier_m0 ( real (dp), dimension(:,:,:), intent(inout)  amn,
integer, intent(in)  parity 
)

Set vector fourier conditions.

For fouier modes for m=0 and for the negative n modes. The n=0 modes are zero for quantities with sin parity.

Parameters
[in,out]amnFourier quantity.
[in]parityFouier parity flag.

◆ set_bndy_fouier_m0_vec()

pure subroutine utilities::set_bndy_fouier_m0_vec ( real (dp), dimension(:,:,:), intent(inout)  amns,
real (dp), dimension(:,:,:), intent(inout)  amnu,
real (dp), dimension(:,:,:), intent(inout)  amnv,
integer, intent(in)  parity 
)

Set vector fourier conditions.

For fouier modes for m=0 and for the negative n modes. The n=0 modes are zero for quantities with sin parity.

Parameters
[in,out]amnsFourier quantity for s component.
[in,out]amnuFourier quantity for u component.
[in,out]amnvFourier quantity for v component.
[in]parityFouier parity flag.

◆ set_bndy_full_origin()

pure subroutine utilities::set_bndy_full_origin ( real (dp), dimension(:,:,:), intent(inout)  amnsf,
real (dp), dimension(:,:,:), intent(inout)  amnuf,
real (dp), dimension(:,:,:), intent(inout)  amnvf,
integer, intent(in)  flags 
)

Apply origin vector boundary conditions.

At the center of the grid, a vector quantity should have only m=1 modes in the s direction, no modes in the u direction and only m=0 modes in the v direction. See siesta_init::GetFields.

Parameters
[in,out]amnsfFull grid fourier quantity for s component.
[in,out]amnufFull grid fourier quantity for u component.
[in,out]amnvfFull grid fourier quantity for v component.
[in]flagsControl flags.

◆ set_bndy_half_to_full()

pure subroutine utilities::set_bndy_half_to_full ( real (dp), dimension(:,:,:), intent(in)  amnh,
real (dp), dimension(:,:,:), intent(inout)  amnf,
integer, intent(in)  nsmin,
integer, intent(in)  parity,
  f 
)

Set fouier boundary conditions for full grid quantity converted from half grid.

At the center of the grid, the quantity should not be a function of u so all m > 0 modes should be zero. For the m = 0 terms, use the value from the half grid.

Parameters
[in]amnhHalf grid fourier quantity.
[in,out]amnfFull grid fourier quantity.
[in]nsminMinimum radial index.
[in]parityParity flag.
[in]flagsControl flags.

◆ set_bndy_half_to_full_ds()

pure subroutine utilities::set_bndy_half_to_full_ds ( real (dp), dimension(:,:,:), intent(in)  amnh,
real (dp), dimension(:,:,:), intent(inout)  amnf_ds,
integer, intent(in)  nsmin,
  par 
)

Set fouier boundary conditions for full grid radial derivative quantity converted from half grid.

At the center of the grid the the m=1 quanity flips size across the s=0 point. The results in a doubling of the m=1 component for the first half grid.

Parameters
[in]amnhHalf grid fourier quantity.
[in,out]amnf_dsFull grid radial derivative fourier quantity.
[in]nsminMinimum radial index.
[in]parityParity flag.
[in]flagsControl flags.

◆ test_div()

logical function utilities::test_div ( real (dp), dimension(:,:,:), intent(in), allocatable  jbsupsmnh,
real (dp), dimension(:,:,:), intent(in), allocatable  jbsupumnh,
real (dp), dimension(:,:,:), intent(in), allocatable  jbsupvmnh,
integer, intent(in)  parity,
integer, intent(in)  nsmin 
)

Test divergence of a half grid quantity.

Parameters
[in]jbsupsmnhContravariant vector in the s direction half grid.
[in]jbsupumnhContravariant vector in the u direction half grid.
[in]jbsupvmnhContravariant vector in the v direction half grid.
[in]parityParity flag.
[in]nsminMinimum radial index.
[in]nsmaxMaximum radial index.

◆ test_utilities()

logical function utilities::test_utilities

Test utility routines.

Test the various operations of in the utilities module. Current tests check:

  • Check the div(curl(A)) is identially zero.

◆ to_full_mesh2()

subroutine utilities::to_full_mesh2 ( real (dp), dimension(:,:), intent(in), allocatable  vech,
real (dp), dimension(:,:), intent(inout), allocatable  vecf 
)

Migrate a two dimensional quantity form the half mesh to the full mesh.

First and last point are extrapolated linearly. The arrays must be passed in as ALLOCATABLE to preserve the array bounds.

Parameters
[in]vechHalf mesh qantity.
[in,out]vecfFull mesh quantity.

◆ to_full_mesh3()

subroutine utilities::to_full_mesh3 ( real (dp), dimension(:,:,:), intent(in), allocatable  vech,
real (dp), dimension(:,:,:), intent(inout), allocatable  vecf 
)

Migrate a three dimensional quantity form the half mesh to the full mesh.

First and last point are extrapolated linearly. The arrays must be passed in as ALLOCATABLE to preserve the array bounds.

Parameters
[in]vechHalf mesh qantity.
[in,out]vecfFull mesh quantity.

◆ to_half_mesh()

subroutine utilities::to_half_mesh ( real (dp), dimension(:,:,:), intent(in), allocatable  vecf,
real (dp), dimension(:,:,:), intent(inout), allocatable  vech 
)

Migrates a full mesh quantity to the half mesh.

The arrays must be passed in as ALLOCATABLE to preserve the array bounds.

Parameters
[in]vecfFull grid quantity.
[in,out]vechHalf grid quantity.

◆ to_half_mesh_p()

subroutine utilities::to_half_mesh_p ( real (dp), dimension(:,:,:), pointer  vecf,
real (dp), dimension(:,:,:), intent(inout), allocatable  vech 
)

Migrates a full mesh quantity to the half mesh.

The arrays must be passed in as ALLOCATABLE to preserve the array bounds. Full vector grid is passed in as pointer.

Parameters
[in]vecfFull grid quantity.
[in,out]vechHalf grid quantity.