function Lorentz_get_particle_dt(partp, end_time) result(dt_p)
use mod_global_parameters
use mod_geometry
type(particle_ptr), intent(in) :: partp
double precision, intent(in) :: end_time
double precision :: dt_p
integer :: ipart, iipart, nout
double precision,dimension(ndir) :: b,v
double precision :: lfac,absb,dt_cfl
double precision :: tout
double precision, parameter :: cfl = 0.5d0
if (const_dt_particles > 0) then
dt_p = const_dt_particles
return
end if
call get_vec(bp, partp%igrid,partp%self%x,partp%self%time,b)
absb = sqrt(sum(b(:)**2))
call get_lfac(partp%self%u,lfac)
! CFL timestep
! make sure we step only one cell at a time:
v(:) = abs(partp%self%u(:) / lfac)
! ! convert to angular velocity:
! if(coordinate ==cylindrical.and.phi_>0) then
! v(phi_) = abs(v(phi_)/partp%self%x(r_))
! end if
dt_cfl = min(bigdouble, rnode(rpdx1_,partp%igrid)/max(v(1), smalldouble),&
rnode(rpdx2_,partp%igrid)/max(v(2), smalldouble),rnode(rpdx3_,&
partp%igrid)/max(v(3), smalldouble))
if(coordinate ==cylindrical.and.phi_>0) then
! phi-momentum leads to radial velocity:
if(phi_ .gt. ndim) dt_cfl = min(dt_cfl, sqrt(rnode(rpdx1_,&
partp%igrid)/partp%self%x(r_)) / v(phi_))
! limit the delta phi of the orbit (just for aesthetic reasons):
dt_cfl = min(dt_cfl,0.1d0/max(v(phi_), smalldouble))
! take some care at the axis:
dt_cfl = min(dt_cfl,(partp%self%x(r_)+smalldouble)/max(v(r_),&
smalldouble))
end if
dt_cfl = dt_cfl * cfl
! bound by gyro-rotation:
dt_p = abs( dtheta * partp%self%m * lfac / (partp%self%q * absb) )
dt_p = min(dt_p, dt_cfl)
! Make sure we don't advance beyond end_time
call limit_dt_endtime(end_time - partp%self%time, dt_p)
end function Lorentz_get_particle_dt