From c5f7e5fc4d552373afd1a035d6471d5ff40bc2fd Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Fri, 30 Aug 2024 09:28:56 -0600 Subject: [PATCH] Switch position and momentum updates to make particle push symplectic The momentum update needs to use fields that are consistant with the current particle locations. This requires updating the momentum first, and then using this new momentum to push the particles. Essentially, the update is now p_(n - 1/2) -> p_(n + 1/2) x_n -> x_(n + 1) I am currently being pretty sloppy with the half timestep momentums, but that should probably be fixed in the future. --- src/particle_updaters/electrostatic.jl | 16 ++++++++-------- src/particle_updaters/electrostatic_test.jl | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/particle_updaters/electrostatic.jl b/src/particle_updaters/electrostatic.jl index 9390798..a338fae 100644 --- a/src/particle_updaters/electrostatic.jl +++ b/src/particle_updaters/electrostatic.jl @@ -38,14 +38,6 @@ function step!(step::ElectrostaticParticlePush) species = step.species for n in eachindex(species) - # Push the particle based on its current velocity - particle_position!( - species, - n, - particle_position(species, n) .+ - (step.timestep / particle_mass(species, n)) .* particle_momentum(species, n), - ) - # Accelerate the particle according to E # Find which cell the particle is in, and create a CartesianIndices # object that extends +/- interpolation_width in all directions @@ -68,5 +60,13 @@ function step!(step::ElectrostaticParticlePush) step.E.values[I], ) end + + # Push the particle based on its current velocity + particle_position!( + species, + n, + particle_position(species, n) .+ + (step.timestep / particle_mass(species, n)) .* particle_momentum(species, n), + ) end end diff --git a/src/particle_updaters/electrostatic_test.jl b/src/particle_updaters/electrostatic_test.jl index 18d0495..2255702 100644 --- a/src/particle_updaters/electrostatic_test.jl +++ b/src/particle_updaters/electrostatic_test.jl @@ -15,6 +15,6 @@ dt = 1.0 step = ElectrostaticParticlePush(species, E, dt) step!(step) - @test species.positions[1][1] == 0.5 + @test species.positions[1][1] == 0.6 @test species.momentums[1][1] == 0.1 end