| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| double precision, | intent(in) | :: | x(3) | |||
| integer, | intent(out) | :: | igrid_particle | |||
| integer, | intent(out) | :: | ipe_particle |
subroutine find_particle_ipe(x,igrid_particle,ipe_particle) use mod_forest, only: tree_node_ptr, tree_root use mod_slice, only: get_igslice use mod_global_parameters double precision, intent(in) :: x(3) integer, intent(out) :: igrid_particle, ipe_particle integer :: ig(ndir,nlevelshi), ig_lvl(nlevelshi) integer :: idim, ic(ndim) type(tree_node_ptr) :: branch ! first check if the particle is in the domain if (.not. particle_in_domain(x)) then igrid_particle = -1 ipe_particle = -1 return end if ! get the index on each level do idim = 1, ndim call get_igslice(idim,x(idim), ig_lvl) ig(idim,:) = ig_lvl end do ! traverse the tree until leaf is found branch=tree_root(ig(1,1),ig(2,1),ig(3,1)) do while (.not.branch%node%leaf) ic(1)=ig(1,branch%node%level+1) - 2 * branch%node%ig1 +2 ic(2)=ig(2,branch%node%level+1) - 2 * branch%node%ig2 +2 ic(3)=ig(3,branch%node%level+1) - 2 * branch%node%ig3 +2 branch%node => branch%node%child(ic(1),ic(2),ic(3))%node end do igrid_particle = branch%node%igrid ipe_particle = branch%node%ipe end subroutine find_particle_ipe