From 76e6d7d8241d7c47c04ac950e0e457e5fdf313a7 Mon Sep 17 00:00:00 2001 From: ChristopherMayes <31023527+ChristopherMayes@users.noreply.github.com> Date: Sat, 10 Apr 2021 17:35:42 -0700 Subject: [PATCH] Add a little padding --- code/open_spacecharge_mod.f90 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/code/open_spacecharge_mod.f90 b/code/open_spacecharge_mod.f90 index 6f8e32d..798f413 100644 --- a/code/open_spacecharge_mod.f90 +++ b/code/open_spacecharge_mod.f90 @@ -178,6 +178,11 @@ subroutine deposit_particles(xa, ya, za, mesh3d, qa, total_charge, resize_mesh) max = [maxval(xa), maxval(ya), maxval(za)] 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 @@ -234,6 +239,8 @@ subroutine deposit_particles(xa, ya, za, mesh3d, qa, total_charge, resize_mesh) n_particles = size(xa) + + if (present(qa)) then mesh3d%charge = sum(qa) elseif (present(total_charge) .and. .not. present(qa)) then