Skip to content

Commit

Permalink
feat: Total mass summary
Browse files Browse the repository at this point in the history
Add a summary struct that computes the total mass on the grid.
  • Loading branch information
musoke committed May 9, 2022
1 parent 5b58c5f commit d7a189a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/summary.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Summary

using ..UltraDark
using ..UltraDark: AbstractGrids
import Dates
import MPI
using Statistics
Expand Down Expand Up @@ -340,4 +341,48 @@ function pool_summarystat(S1::RmsDensityContrast, S2::RmsDensityContrast)::RmsDe
RmsDensityContrast(δx_rms, n)
end

"""
TotalMass
Total mass on a grid
# Examples
```jldoctest
julia> using UltraDark
julia> g = Grids(1.0, 16);
julia> g.ρx .= 0.;
julia> g.ρx[1, 1, 1] = 1.;
julia> getfield(Summary.TotalMass(g), 1) == 1.0 * (1.0/16)^3
true
```
"""
struct TotalMass
mass::Float64
end

function TotalMass(grids, rho)
mass = sum(rho * dV(grids))

TotalMass(mass)
end

function TotalMass(grids::AbstractGrids)
TotalMass(grids, grids.ρx)
end

function TotalMass(sim_time, a, Δt, grids, constants)
ToalMass(grids)
end

function pool_summarystat(S1::TotalMass, S2::TotalMass)::TotalMass
mass = S1.mass + S2.mass
TotalMass(mass)
end

end # module

0 comments on commit d7a189a

Please sign in to comment.