Module modpaleo

!                 >>>>>   N O T E   <<<<<
! {{{ and }}} are Vim folding markers. DO NOT REMOVE THEM.
! Vim is an improved version of the Vi text editor.

!----- DESCRIPTION -------------------------------------------------{{{
!
! This Fortran 90 module contains a subroutine called paleo, which
! provides the capability for computing approximate electron thermal
! diffusivity [m^2/s] caused by paleoclassical transport model.
!
! This module contains one user-callable subroutine:
!
!    * Subroutine paleo
!
! Detailed description can be found in the documentation [doc/plc_ref.pdf].
!
! Revision History
! ----------------
! July 15, 2011 - Lixiang Luo - Release as an revised NTCC module
!
!-------------------------------------------------------------------}}}

!----- MODULE SPECIFICATIONS ---------------------------------------{{{
Implicit None

Private

!.. Define a Real*8 type
Integer, Parameter :: R8 = SELECTED_REAL_KIND(12,100)

Real(R8), Parameter :: &
   zpi   = 3.1415926535898_R8 ,&! Pi
   zcc   = 299792458._R8      ,&! Speed of light [m/s]
   zcmu0 = 4e-7_R8 * zpi        ! Vacuum magnetic permeability [H/m]

Public :: paleo

!----- END OF MODULE SPECIFICATION ---------------------------------}}}

Contains

Subroutine paleo ( &
   te, ne, zeff, q, qprime, qdprime, rmajbnd, rminbnd, etanc, &
   xkePLC, helmul    )

!----- SPECIFICATIONS ----------------------------------------------{{{
Implicit None

!.. Input arguments
Real(R8), Intent(In) :: &
   te,      &! Electron temperature [KeV]
   ne,      &! Electron density [m^-3]
   zeff,    &! Z_effective
   q,       &! Magnetic q
   qprime,  &! Derivative of q w.r.t. rho
   qdprime, &! Second derivative of q w.r.t. rho
   rmajbnd, &! Major radius [m]
   rminbnd, &! Effective radius = sqrt(<R^-2>/<|gradrho|^2/R^2>) 
             ! approximately equal to minor radius [m] 
             ! [see e.g. Eq.(72) of J.D. Callen POP 12, 092512, 20005]
   etanc     ! Neoclassical resistivity [Ohm.m]

!.. Output arguments
Real(R8), Intent(Out) :: &
   xkePLC    ! Electron thermal diffusivity [m^2/s]
!
Real(R8), Intent(Out), Optional :: &
   helmul    ! Helical multiplier (M) caused by helically
             ! resonant radial diffusion

!.. Local variables
Real(R8), Parameter :: &
   z_scale = 1._R8 ! Scale factor

Real(R8) :: &
   zln_lambda, &! ln( \Lambda / 17)
   z_q_prime,  &! qprime
   zlambda_e,  &! v_{the} / \nu_e
   z_omegape,  &! plasma frequency
   z_deltae,   &! normalized electromagnetic skin depth
   z_n_max,    &! n_max = sqrt( pi * deltae * |q'| )
   n_max_lmt,  &! max{n_max} = 1/( pi^2 * deltae^2 * q'' )^(1/3)
   z_lmax,     &! length over which magnetic field diffuse radially
   z_L,        &! min ( zlambda_e, z_pi R q n_max )
   z_L_ratio,  &! L / ( pi * R * q )
   zlog         ! Coloumb logorithm

!----- END OF SPECIFICATIONS ---------------------------------------}}}

!.. Coloumb logorithm
If ( te < 0.05_R8 ) Then
   zlog=log(4.87e17_R8* te * sqrt(te/ne) / zeff)
Else
   zlog=log(1.09e17_R8* te / (zeff * sqrt(ne)))
End If

zln_lambda = zlog / 17._R8

z_q_prime = qprime

zlambda_e  = 1.2e16_R8 * ( 1.0e3_R8 * te )**2 / &
     ( ne * zeff * zln_lambda )

!.. Electron plasma frequency
z_omegape = 1.7835e11_R8 * sqrt( ne * 1e-19_R8 )

!.. Normalized EM skin depth
z_deltae = zcc / ( z_omegape * rminbnd )

z_q_prime = sign( max( 0.01_R8, abs(z_q_prime) ), z_q_prime )

z_n_max = 1._R8 / sqrt( zpi * z_deltae * abs(z_q_prime) )

!.. Upper bound of n_max provided by Eq.(122) of POP 12, 092512 (2005)
n_max_lmt = 1._R8 / ( (zpi * z_deltae)**2 * abs(qdprime) )**(1._R8/3._R8)

If ( z_n_max > n_max_lmt ) z_n_max = n_max_lmt

z_lmax = zpi * rmajbnd * z_n_max * q

z_L = zlambda_e * z_lmax / (zlambda_e + z_lmax)

z_L_ratio = z_L / ( q * zpi * rmajbnd )

xkePLC = z_scale * 1.5_R8 * (z_L_ratio + 1._R8) * etanc / zcmu0

If ( Present(helmul) ) helmul = z_L_ratio

End Subroutine paleo


End Module modpaleo
