FIXME : Add documentation
subroutine ginit_nl3r
use species, only: spec, has_electron_species
use theta_grid, only: ntgrid, theta
use kt_grids, only: naky, ntheta0, theta0, reality
use le_grids, only: forbid
use fields_arrays, only: apar
use fields_arrays, only: aparnew
use dist_fn_arrays, only: g, gnew, vpa, vperp2
use gs2_layouts, only: g_lo, ik_idx, it_idx, il_idx, is_idx
use constants, only: zi
use array_utils, only: copy, zero_array
implicit none
complex, dimension (-ntgrid:ntgrid,ntheta0,naky) :: phi, odd
real, dimension (-ntgrid:ntgrid) :: dfac, ufac, tparfac, tperpfac, ct, st, c2t, s2t
integer :: iglo
integer :: ig, ik, it, il, is, j
call zero_array(phi) ; call zero_array(odd)
do j = 1, 2
ik = ikk(j)
it = itt(j)
if (width0 > 0.) then
do ig = -ntgrid, ntgrid
phi(ig,it,ik) = exp(-((theta(ig)-theta0(it,ik))/width0)**2)*cmplx(refac, imfac)
end do
else
do ig = -ntgrid, ntgrid
phi(ig,it,ik) = cmplx(refac, imfac)
apar(ig,it,ik) = apar0*cmplx(refac, imfac)
end do
end if
if (chop_side) then
if (left) then
phi(:-1,it,ik) = 0.0
else
phi(1:,it,ik) = 0.0
end if
end if
end do
odd = zi * phi
! reality condition for k_theta = 0 component:
if (reality) then
do it = 1, ntheta0/2
apar(:,it+(ntheta0+1)/2,1) = conjg(apar(:,(ntheta0+1)/2+1-it,1))
phi(:,it+(ntheta0+1)/2,1) = conjg(phi(:,(ntheta0+1)/2+1-it,1))
odd(:,it+(ntheta0+1)/2,1) = conjg(odd(:,(ntheta0+1)/2+1-it,1))
enddo
end if
aparnew = apar
if (even) then
ct = cos(theta)
st = sin(theta)
c2t = cos(2.*theta)
s2t = sin(2.*theta)
else
ct = sin(theta)
st = cos(theta)
c2t = sin(2.*theta)
s2t = cos(2.*theta)
end if
dfac = den0 + den1 * ct + den2 * c2t
ufac = upar0 + upar1* st + upar2* s2t
tparfac = tpar0 + tpar1* ct + tpar2* c2t
tperpfac = tperp0 + tperp1*ct + tperp2*c2t
! charge dependence keeps initial Phi from being too small
do iglo = g_lo%llim_proc, g_lo%ulim_proc
ik = ik_idx(g_lo,iglo)
it = it_idx(g_lo,iglo)
il = il_idx(g_lo,iglo)
is = is_idx(g_lo,iglo)
g(:,1,iglo) = phiinit* &!spec(is)%z* &
( dfac*spec(is)%dens0 * phi(:,it,ik) &
+ 2.*ufac* vpa(:,1,iglo)*spec(is)%u0 * odd(:,it,ik) &
+ tparfac*(vpa(:,1,iglo)**2-0.5) * phi(:,it,ik) &
+tperpfac*(vperp2(:,iglo)-1.) * phi(:,it,ik))
where (forbid(:,il)) g(:,1,iglo) = 0.0
g(:,2,iglo) = phiinit* &!spec(is)%z* &
( dfac*spec(is)%dens0 * phi(:,it,ik) &
+ 2.*ufac* vpa(:,2,iglo)*spec(is)%u0 * odd(:,it,ik) &
+ tparfac*(vpa(:,2,iglo)**2-0.5) * phi(:,it,ik) &
+tperpfac*(vperp2(:,iglo)-1.) * phi(:,it,ik))
where (forbid(:,il)) g(:,2,iglo) = 0.0
! if (il == ng2+1) g(:,:,iglo) = 0.0
end do
! if (has_electron_species(spec)) then
! call flae (g, gnew)
! g = g - gnew
! end if
call copy(g, gnew)
end subroutine ginit_nl3r