Skip to content

Commit

Permalink
fix: Only calculate the summary in inner loop
Browse files Browse the repository at this point in the history
Calculating the summary both inside and outside the loop in
`take_steps!` is inconsistent.
This shows up as discontinuities in quantities such as the energy
because the kinetic and gravitational energy are out of phase by half a
time step.

The fix: calculate summaries only in the inner loop.  Any summary
quantities that depend on the phase should be calculated carefully,
potentially with a temporary update to psi by half a time step.

BREAKING CHANGE: summary is calculated at slightly different times
  • Loading branch information
musoke committed Mar 17, 2022
1 parent 32bb707 commit eb972e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UltraDark"
uuid = "1c8d022d-dfc0-4b41-80ab-3fc7e88cdfea"
authors = ["Nathan Musoke <[email protected]>"]
version = "0.2.2"
version = "0.3.0"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
17 changes: 15 additions & 2 deletions src/UltraDark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import .Output: output_summary_row, output_summary_header, output_grids, output_
import .Output: SummaryStatistics, SummaryStatisticsMeanMaxRms
import .Config: SimulationConfig, constant_scale_factor, TimeStepOptions

"""
outer_step!(Δt, grids, constants; a=1.0)
Perform the "outer" time step in the symmetrized split-step Fourier method.
This step only updates the phase of ψ applying accelerations due to gravity,
the amplitude is not changed.
"""
function outer_step!(Δt, grids, constants; a=1.0)
psi_whole_step!(Δt, grids, constants)
end
Expand Down Expand Up @@ -53,6 +61,13 @@ function psi_whole_step!(Δt, grids, constants)
end
end

"""
inner_step!(Δt, grids, constants; a=1.0)
Perform the "inner" time step in the symmetrized split-step Fourier method.
This step applies the diffusion terms and updates the gravitational potential.
"""
function inner_step!(Δt, grids, constants; a=1.0)
phi_whole_step!(Δt, grids, constants; a=1.0)
end
Expand Down Expand Up @@ -145,8 +160,6 @@ function take_steps!(grids, t_start, Δt, n, output_config, a, constants)
outer_step!(Δt/2, grids, constants)
t += Δt / 2

output_summary_row(grids, output_config, t, a(t), Δt)

t
end

Expand Down

2 comments on commit eb972e4

@musoke
Copy link
Owner Author

@musoke musoke commented on eb972e4 Mar 17, 2022

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

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.3.0 -m "<description of version>" eb972e4cd07bf09970c0d8df36f6a48795644050
git push origin v0.3.0

Please sign in to comment.