Skip to content

Commit

Permalink
fix: Typo in gravitational energy
Browse files Browse the repository at this point in the history
9b17f30
(#152) introduced a bug in
the gravitational energy.
The arguments of E_gravity_density are reversed.  This doesn't show up in
tests because the psi used is real, so the incorrect energy density can
be coerced to be real.

Fix this and update the tests of summaries so that psi is complex.
  • Loading branch information
musoke committed Sep 8, 2023
1 parent a555b8f commit f1f6434
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 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.9.4"
version = "0.9.5"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
4 changes: 2 additions & 2 deletions src/grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ end
Gravitational energy density of field `psi` in gravitational potential `Phi`
"""
function E_gravity_density(psi::Number, Phi::Number)
function E_gravity_density(psi::Number, Phi::Real)::Real
Phi .* abs2.(psi) / 2.0
end

Expand All @@ -478,7 +478,7 @@ end
Gravitational potential energy
"""
function E_grav(grids, psi)
Folds.mapreduce(E_gravity_density, +, grids.Φx, psi) * dV(grids)
Folds.mapreduce(E_gravity_density, +, psi, grids.Φx) * dV(grids)
end

function E_grav(grids::AbstractGrids)
Expand Down
2 changes: 1 addition & 1 deletion test/summary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pencilgrids = PencilGrids(1.0, 8)
external_states = ()

for g in [grids, pencilgrids]
g.ψx .= 1.0
g.ψx .= 1.0 + im
@. g.ρx = abs2(g.ψx)
end

Expand Down

2 comments on commit f1f6434

@musoke
Copy link
Owner Author

@musoke musoke commented on f1f6434 Sep 8, 2023

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

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

Please sign in to comment.