diff --git a/code/open_spacecharge_mod.f90 b/code/open_spacecharge_mod.f90 index fab1de5..798f413 100644 --- a/code/open_spacecharge_mod.f90 +++ b/code/open_spacecharge_mod.f90 @@ -176,13 +176,13 @@ subroutine deposit_particles(xa, ya, za, mesh3d, qa, total_charge, resize_mesh) if (resize) then min = [minval(xa), minval(ya), minval(za)] max = [maxval(xa), maxval(ya), maxval(za)] - delta =(max(:) - min(:) ) / (mesh3d%nhi(:) - mesh3d%nlo(:) + 1) - ! Pad by by 1.1 bins - pad = delta*1.1 - min = min !- pad - max = max + pad - delta =(max(:) - min(:) ) / (mesh3d%nhi(:) - mesh3d%nlo(:) + 1) - + delta =(max(:) - min(:) ) / (mesh3d%nhi(:) - mesh3d%nlo(:) ) + + ! Small padding to protect against indexing errors + min = min - 1.0e-6_dp*delta + max = max + 1.0e-6_dp*delta + delta =(max(:) - min(:) ) / (mesh3d%nhi(:) - mesh3d%nlo(:) ) + mesh3d%min = min mesh3d%max = max mesh3d%delta = delta