Skip to content

Commit

Permalink
Switch position and momentum updates to make particle push symplectic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamslc committed Aug 30, 2024
1 parent 1fbd1b2 commit c5f7e5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/particle_updaters/electrostatic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/particle_updaters/electrostatic_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5f7e5f

Please sign in to comment.