Skip to content

Commit

Permalink
Merge pull request #28 from dpad/fix/thread-safe-state-callbacks
Browse files Browse the repository at this point in the history
Better thread safety for callbacks when solving for Trajectories.
  • Loading branch information
dpad authored May 4, 2021
2 parents 628b33a + 15bd62f commit 1ce6e96
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/dynamics/orbital_trajectories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,19 @@ DiffEqBase.solve(state::State, args...; reltol=1e-10, abstol=1e-10, kwargs...) =
DiffEqBase.__solve(state::State; kwargs...) = DiffEqBase.__solve(state, DEFAULT_ALG; kwargs...)

# The __solve() method does the actual heavy lifting, including converting to a Trajectory.
function DiffEqBase.__solve(state::State, alg::DiffEqBase.DEAlgorithm; userdata=Dict(), kwargs...)
function DiffEqBase.__solve(state::State, alg::DiffEqBase.DEAlgorithm; userdata=Dict(), callback=nothing, kwargs...)
default_frame = default_reference_frame(state.model)
real_state = convert_to_frame(state, default_frame)

# Pass the default state into the underlying solver
# TODO: Remove the need for this in DiffCorrectAxisymmetric
userdata_new = deepcopy(userdata)
userdata_new[:real_state] = real_state
userdata = deepcopy(userdata)
userdata[:real_state] = real_state

# Copy the callbacks (for thread-safety)
callback = deepcopy(callback)

# Call the underlying solver
raw_sol = solve(real_state.prob, alg; userdata=userdata_new, kwargs...)
raw_sol = solve(real_state.prob, alg; userdata, callback, kwargs...)
return Trajectory(state.model, default_frame, raw_sol)
end

2 comments on commit 1ce6e96

@dpad
Copy link
Owner Author

@dpad dpad commented on 1ce6e96 May 4, 2021

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/36023

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.1.11 -m "<description of version>" 1ce6e960381dada038ebbb53297b5e3546ef26bc
git push origin v0.1.11

Please sign in to comment.