subroutine get_efield(igrid,x,tloc,e)
use mod_global_parameters
use mod_usr_methods, only: usr_particle_analytic, usr_particle_fields
use mod_geometry
integer,intent(in) :: igrid
double precision,dimension(3), intent(in) :: x
double precision, intent(in) :: tloc
double precision,dimension(ndir), intent(out) :: e
double precision,dimension(ndir) :: vec1, vec2, vec
double precision,dimension(ndir) :: vfluid, b
double precision,dimension(ndir) :: current
double precision :: rho = 1.d0,&
rho2 = 1.d0
double precision :: td
integer :: ic1,ic2,ic3,idir
current(:) = 0.d0
if (associated(usr_particle_analytic)) then
call usr_particle_analytic(ep, x, tloc, vec)
else if (associated(usr_particle_fields)) then
call get_vec(ep, igrid, x, tloc, vec)
else
call get_bfield(igrid, x, tloc, b)
call get_vec(vp, igrid, x, tloc, vfluid)
if (particles_eta > zero) then
call get_vec(jp, igrid, x, tloc, current)
end if
if (particles_etah > zero) then
call interpolate_var(igrid,ixGlo1,ixGlo2,ixGlo3,ixGhi1,ixGhi2,ixGhi3,&
ixMlo1,ixMlo2,ixMlo3,ixMhi1,ixMhi2,ixMhi3,&
gridvars(igrid)%w(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,rhop),&
ps(igrid)%x(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,1:ndim),x,&
rho)
if (time_advance) then
call interpolate_var(igrid,ixGlo1,ixGlo2,ixGlo3,ixGhi1,ixGhi2,ixGhi3,&
ixMlo1,ixMlo2,ixMlo3,ixMhi1,ixMhi2,ixMhi3,&
gridvars(igrid)%wold(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
rhop),ps(igrid)%x(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
1:ndim),x,rho2)
td = (tloc - global_time) / dt
rho = rho * (1.0d0 - td) + rho2 * td
end if
end if
! Build E
select case (coordinate)
case (Cartesian,Cartesian_stretched,spherical)
vec(1) = -vfluid(2)*b(3)+vfluid(3)*b(2) + particles_eta*current(1) + &
particles_etah/rho*(current(2)*b(3) - current(3)*b(2))
vec(2) = vfluid(1)*b(3)-vfluid(3)*b(1) + particles_eta*current(2) + &
particles_etah/rho*(-current(1)*b(3) + current(3)*b(1))
vec(3) = -vfluid(1)*b(2)+vfluid(2)*b(1) + particles_eta*current(3) + &
particles_etah/rho*(current(1)*b(2) - current(2)*b(1))
case (cylindrical)
vec(r_) = -vfluid(phi_)*b(z_)+vfluid(z_)*b(phi_) + &
particles_eta*current(r_) + &
particles_etah/rho*(current(phi_)*b(z_) - current(z_)*b(phi_))
vec(phi_) = vfluid(r_)*b(z_)-vfluid(z_)*b(r_) + &
particles_eta*current(phi_) + &
particles_etah/rho*(-current(r_)*b(z_) + current(z_)*b(r_))
vec(z_) = -vfluid(r_)*b(phi_)+vfluid(phi_)*b(r_) + &
particles_eta*current(z_) + &
particles_etah/rho*(current(r_)*b(phi_) - current(phi_)*b(r_))
end select
end if
e(:) = vec(:)
end subroutine get_efield