Initialise the field objects
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(fieldmat_type), | intent(inout) | :: | self |
subroutine fm_init(self)
use kt_grids, only: get_leftmost_it, naky, ntheta0, n_supercells
use run_parameters, only: has_phi, has_apar, has_bpar
use theta_grid, only: ntgrid
implicit none
class(fieldmat_type), intent(inout) :: self
integer :: it, cur_id, it_start, is_count, ik
integer, dimension(:), allocatable :: tmp_supercell_ids
integer, dimension(:,:), allocatable :: supercell_ids
integer, dimension(:,:), allocatable :: is_to_itmin
!Count the fields
self%nfield = count([has_phi, has_apar, has_bpar])
!Allocate temp arrays
allocate(supercell_ids(ntheta0, naky))
! Here the first dimension is allocated as ntheta0
! but for each ky we only use the first nsupercell(ik)
! entries.
allocate(is_to_itmin(ntheta0, naky))
!Initialise arrays
is_to_itmin = 0
supercell_ids = -1
!Find the leftmost it for each supercell and use this to label the
!supercell. Note that this is different from the supercell_label
!from dist_fn.
do ik = 1, naky
do it = 1, ntheta0
supercell_ids(it, ik) = get_leftmost_it(it, ik)
end do
end do
!Now work out how many supercells there are for each
!ik and what their properties are.
do ik = 1, naky
!Store the leftmost it values for current ik
tmp_supercell_ids = supercell_ids(:, ik)
!Now loop over all it values and count how many
!have which it as the leftmost one.
it_start = 0
is_count = 0
do while (any(tmp_supercell_ids >= 0))
!Increase the it value
it_start = it_start + 1
!Get the leftmost it for supercell with it_start in it
cur_id = tmp_supercell_ids(it_start)
!If we've seen this supercell then cycle
if (cur_id == -1) cycle
!Increase supercell counter
is_count = is_count + 1
!Store the leftmost it value
is_to_itmin(is_count, ik) = cur_id
!Set all matching entries to -1 so we know to skip
!this supercell again
do it = it_start, ntheta0
if (tmp_supercell_ids(it) == cur_id) then
tmp_supercell_ids(it) = -1
end if
end do
end do
end do
!Free memory
deallocate(tmp_supercell_ids)
!Now we want to allocate the basic field structure
!Store the basic properties
self%naky = naky
self%ntheta0 = ntheta0
self%npts = naky * ntheta0 * (2 * ntgrid + 1)
self%nbound = 0 !Calculated whilst we create objects
allocate(self%kyb(naky))
!/Make the kyb objects
do ik = 1, naky
call self%kyb(ik)%init(ik, is_to_itmin(:, ik), n_supercells(ik), self%nfield, self%nbound)
end do
!Free memory
deallocate(supercell_ids, is_to_itmin)
end subroutine fm_init