Skip to content

Commit

Permalink
Follow up on simplifying Boris pusher
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Apr 23, 2024
1 parent 400dad9 commit edfc263
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TestParticle"
uuid = "953b605b-f162-4481-8f7f-a191c2bb40e3"
authors = ["Hongyang Zhou <[email protected]>, and Tiancheng Liu <[email protected]>"]
version = "0.10.4"
version = "0.10.5"

[deps]
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"
Expand Down
16 changes: 8 additions & 8 deletions src/pusher.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ function solve(prob::TraceProblem, ensemblealg::BasicEnsembleAlgorithm=EnsembleS
end

function _solve(::EnsembleSerial, prob, trajectories, dt, savestepinterval, isoutofdomain)
sols, ttotal, nt, nout = _prepare(prob, trajectories, dt, savestepinterval)
sols, nt, nout = _prepare(prob, trajectories, dt, savestepinterval)
irange = 1:trajectories
_boris!(sols, prob, irange, savestepinterval, dt, ttotal, nt, nout, isoutofdomain)
_boris!(sols, prob, irange, savestepinterval, dt, nt, nout, isoutofdomain)

sols
end

function _solve(::EnsembleThreads, prob, trajectories, dt, savestepinterval, isoutofdomain)
sols, ttotal, nt, nout = _prepare(prob, trajectories, dt, savestepinterval)
sols, nt, nout = _prepare(prob, trajectories, dt, savestepinterval)

nchunks = Threads.nthreads()
Threads.@threads for (irange, ichunk) in chunks(1:trajectories, nchunks)
_boris!(sols, prob, irange, savestepinterval, dt, ttotal, nt, nout, isoutofdomain)
_boris!(sols, prob, irange, savestepinterval, dt, nt, nout, isoutofdomain)
end

sols
Expand All @@ -186,11 +186,11 @@ function _prepare(prob, trajectories, dt, savestepinterval)
nout = nt ÷ savestepinterval + 1
sols = Vector{TraceSolution}(undef, trajectories)

sols, ttotal, nt, nout
sols, nt, nout
end

"Apply Boris method for particles with index in `irange`."
function _boris!(sols, prob, irange, savestepinterval, dt, ttotal, nt, nout, isoutofdomain)
function _boris!(sols, prob, irange, savestepinterval, dt, nt, nout, isoutofdomain)
(; tspan, p, u0) = prob
paramBoris = BorisMethod()
xv = MVector{6, eltype(u0)}(undef)
Expand Down Expand Up @@ -218,10 +218,10 @@ function _boris!(sols, prob, irange, savestepinterval, dt, ttotal, nt, nout, iso

if iout == nout # regular termination
traj_save = copy(traj)
t = collect(tspan[1]:dt*savestepinterval:tspan[2])
t = range(tspan[1], step=dt*savestepinterval, length=nout) |> collect
else # early termination or savestepinterval != 1
traj_save = traj[1:iout]
t = collect(tspan[1]:dt*savestepinterval:tspan[1]+dt*savestepinterval*(iout-1))
t = tspan[1]:dt*savestepinterval:tspan[1]+dt*savestepinterval*(iout-1) |> collect
end

dense = false
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ end

@test sol.u[end] == [-0.00010199139098074829, 3.4634030517007745e-5, 0.0,
-62964.170425493256, -77688.56571355555, 0.0]
@test length(sol.t) == length(sol.u)

t = tspan[2] / 2
@test sol(t) == [-3.8587891411024776e-5, 5.3855910044312875e-5, 0.0,
Expand Down

2 comments on commit edfc263

@henry2004y
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105448

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.5 -m "<description of version>" edfc263440b06bfb690258f469534b921b49cdd4
git push origin v0.10.5

Please sign in to comment.