Methods

Main functions

Base.run — Function
run(sim::Simulation)

This function does all the work for you:

  1. prepare sim environment and preprocess data
  2. evaluate force, initialize timesteps, output
  3. mainloop
source
AstroNbodySim.mainloop — Function
mainloop(sim::Simulation) -> Any

Main integration loop: drift → force → kick → analyse → output → repeat until timeinfo.system_time_float >= config.time.End or the user creates a stop file inside config.output.dir.

Returns a Matrix of analyser values if any analysers were registered, otherwise nothing.

source

Force / potential

AstroNbodySim.compute_force — Function
compute_force(sim::Simulation)
compute_force(sim::Simulation, pos, SoftLength)

Compute gravitational accelerations using the solver and device stored in sim.config. The in-place form updates data.Acc; the position-based form returns the accelerations evaluated at pos with the given softening length.

source
AstroNbodySim.compute_acc — Function
compute_acc(
    m::PhysicalMeshes.MeshCartesianStatic,
    dim::Val{3},
    mode::PhysicalMeshes.VertexMode
)

Compute accelerations by second-order central differencing of potential on the mesh. Results are stored in acc and return nothing.

source
AstroNbodySim.softlen — Function
softlen(c::Collection, table::MVector)
softlen(p::AbstractParticle, table::MVector)
softlen(p::AbstractParticle, sim::Simulation)
softlen(c::Collection, sim::Simulation)

Retrive softening length from table

source
AstroNbodySim.suggest_softlen — Function
suggest_softlen(V::Number, N::Int64)
suggest_softlen(data::Union{Array, StructArray})
suggest_softlen(data::Union{Array, StructArray}, collection::Collection)
suggest_softlen(sim::Simulation)

return recommended softening length

See also suggest_softlen! and set_softlen!

source
AstroNbodySim.set_softlen! — Function
set_softlen!(sim::Simulation, h)
set_softlen!(sim::Simulation, h, solver, device)

Set all entries of sim.config.grav.ForceSofteningTable to h. For distributed particle solvers the new value is broadcast to every worker.

source
AstroNbodySim.set_softlen_local! — Function
set_softlen_local!(sim::Simulation, c::Collection, h::Number)

Set softening length of collection c to h.

source
set_softlen_local!(sim::Simulation, h::Number)

Set all softening lengths to h

source
AstroNbodySim.compute_kinetic — Function
compute_kinetic(
    p::PhysicalParticles.AbstractParticle
) -> Any

Compute kinetic energy of particle: 0.5 * p.Mass * p.Vel * p.Vel

source

Restart / output

saverestart, loadrestart, restart, check_restartable and redistribute_data are part of the restart machinery driven by run / Simulation; they are internal helpers without user-facing docstrings in this release.

Particle-Mesh

The Poisson solvers are provided by PhysicalFFT.jl and PhysicalFDM.jl (no separate docstrings are attached in this package):

  • fft_poisson(Δ, Len, rho, boundary, device) and fft_poisson(mesh, G).
  • fft_poisson!(mesh, rho, boundary).
  • fdm_poisson(mesh, Val(dim), G, mode, device, boundary, sparse).

Machine-Learning solver

The ML solver is experimental; see the ML manual page. No stable training API is exposed in this release.

Timestep

AstroNbodySim.AdaptiveTimestep — Type
AdaptiveTimestep

Adaptive timestep configuration. The raw step is sqrt(2 * ErrTolTimestep * SofteningLength / |a|), quantised on an integer timeline of length TimeBase and bounded by MinStep and MaxStep.

source
AstroNbodySim.init_timesteps — Function
init_timesteps(sim::Simulation)

Initialise Ti_endstep for every particle from the current acceleration and softening length, using the configured constant or adaptive timestep.

source
AstroNbodySim.find_next_sync_point_and_drift — Function
find_next_sync_point_and_drift(sim::Simulation, timestep_config, solver, device)

Drift particles to the next synchronisation point and update the simulation time. The synchronisation point is determined by the constant or adaptive timestep configuration.

source
AstroNbodySim.advance_and_find_timestep — Function
advance_and_find_timestep(sim::Simulation, solver, device)

Apply the second half of the leapfrog kick and advance Ti_endstep to the next step for every active particle.

source

Energy & orbits

AstroNbodySim.total_potential — Function
total_potential(data::StructArrays.StructArray) -> Any

Sum potential energy of particles in data. Potentials need to be computed in advance.

Return nothing if empty.

source
AstroNbodySim.total_momentum — Function
total_momentum(sim::Simulation, axis::Symbol) -> Any

Compute momentum of the system in the direction of axis

source
total_momentum(sim::Simulation) -> Any

Compute total momentum vector of the system

source
AstroNbodySim.total_kinetic — Function
total_kinetic(data::StructArrays.StructArray) -> Any

Sum kinetic energy: 0.5 * data.Mass[i] * data.Vel[i] * data.Vel[i]

source
total_kinetic(sim::Simulation) -> Any

Compute kinetic energy of particles on workers and return the sum

source
AstroNbodySim.total_kinetic_local — Function
total_kinetic_local(sim::Simulation) -> Any

Compute and sum kinetic energy of particles in data. Potentials need to be computed in advance.

Return nothing if empty.

source
AstroNbodySim.ellipticSemiMajor — Function
ellipticSemiMajor(
    G::Number,
    M::Number,
    r::Number,
    v::Number
) -> Any

Length of semi-major axis of elliptic orbit

  • G: gravitational constant
  • M: mass of central object
  • r: orbit radius at specific time
  • v: velocity at radius r
source
AstroNbodySim.ellipticPeriod — Function
ellipticPeriod(G::Number, M::Number, a::Number) -> Any

Orbital period of elliptic orbit

  • G: gravitational constant
  • M: mass of central object
  • a: length of semi-major axis
source
AstroNbodySim.eccentricity — Function
eccentricity(
    G::Number,
    M::Number,
    v::Number,
    h::Number
) -> Any

Eccentricity of elliptic orbit

  • G: gravitational constant
  • M: mass of central object
  • v: velocity at radius r
  • h: specific relative angular momentum at radius r
source
eccentricity(
    G::Number,
    M::Number,
    r::PhysicalParticles.AbstractPoint,
    v::PhysicalParticles.AbstractPoint
) -> Any

Eccentricity vector of elliptic orbit

  • G: gravitational constant
  • M: mass of central object
  • r: position at specific time
  • v: velocity vector at position r
source

Time scales

AstroNbodySim.relaxtime — Function
relaxtime(R, v, N)

trelax = N/(10 lnN) tcross

Relaxation time: The time over which the change in kinetic energy due to the long-range collisions has accumulated to a value that is comparable to the intrinsic kinetic energy of the particle.

source
AstroNbodySim.interactiontime — Function

interactiontime(R, v, N)

The typical time between two short-range interactions that cause a change in kinetic energy comparable to the intrinsic kinetic energy of the particle.

tinteraction = N * tcross

source
AstroNbodySim.freefalltime — Function
freefalltime(ρ, G)

t_ff = sqrt(3 * π / (32 * G * ρ))

The time it takes a sphere with zero pressure to collapse to a point.

source

Data processing

MOND / QUMOND / MOG

AstroNbodySim.nu — Function
nu(y::Number, n::Number = 2)

Generalized MOND (MOdified Newtonian Dynamics) interpolation function. See also nu1, nu2

source
AstroNbodySim.nu1 — Function
nu1(y::Number)

MOND (MOdified Newtonian Dynamics) interpolation function with index = 1. See also nu, nu2

source
AstroNbodySim.nu2 — Function
nu1(y::Number)

MOND (MOdified Newtonian Dynamics) interpolation function with index = 2. See also nu, nu1

source
AstroNbodySim.mond_Milgrom1983 — Function
mond_Milgrom1983(sim::Simulation, data::StructArray)

Apply Milgrom 1983 formula of MOND (MOdified Newtonian Dynamics) to accelerations

source
AstroNbodySim.QUMOND_PDM_density — Function
QUMOND_PDM_density(
    m::PhysicalMeshes.MeshCartesianStatic,
    ACC0::Number,
    G::Number
) -> Any

Compute ρPDM on the RHS (right hand side) of QUMOND (QUasi-linear MOdified Newtonian Dynamics). Return ρPDM

source
AstroNbodySim.QUMOND_phi — Function
QUMOND_phi(
    m::PhysicalMeshes.MeshCartesianStatic,
    ACC0::Number,
    G::Number
) -> Any

First compute ρ_PDM, then solve QUMOND (QUasi-linear MOdified Newtonian Dynamics) equation on the mesh. Return modified potential

Warning: Currently the Poisson equation is solved with periodic boundary conditions

source
AstroNbodySim.QUMOND_acc — Function
QUMOND_acc(
    m::PhysicalMeshes.MeshCartesianStatic,
    ACC0::Number,
    G::Number
) -> Any
  1. Compute ρ_PDM
  2. Solve modified potential on the mesh
  3. Compute acceleration by finite differencing the potential

Return acceleration

source
AstroNbodySim.QUMOND_acc! — Function
QUMOND_acc!(
    m::PhysicalMeshes.MeshCartesianStatic,
    ACC0::Number,
    G::Number
)

Apply QUMOND (QUasi-linear MOdified Newtonian Dynamics) formula to accelerations

source

Pseudo-Newtonian (black-hole) potentials

AstroNbodySim.r_g — Function
r_g(G, M, c)

r_g = 2 * G * M / c^2

where G is the gravity constant, M is the mass of the central object, c is light speed.

Schwarzchild radius.

source
AstroNbodySim.pseudoNewtonianPotential — Function
pseudoNewtonianPotential(G, M, c, R)

pot = - G * M / (R - r_g(G, M, c))

Pseudo-Newtonian potential around a compat central object. Diverge at gravity radius r_g.

source

pseudoNewtonianPotential(G, M, rg)

pot = - G * M / (R - rg)

Pseudo-Newtonian potential around a compat central object. Diverge at gravity radius r_g.

source
AstroNbodySim.pseudoNewtonianAcc — Function
pseudoNewtonianAcc(G, M, c, R, n::AbstractPoint)

acc = - G * M / (R - r_g(G, M, c))^2 * n

Pseudo-Newtonian acceleration around a compat central object. Diverge at gravity radius r_g.

source
pseudoNewtonianAcc(G, M, c, R, n::AbstractPoint)

acc = - G * M / (R - rg)^2 * n

Pseudo-Newtonian acceleration around a compat central object. Diverge at gravity radius r_g.

source

Output & logging

outputparallel, setuploggers, DefaultTimer, mkpathIfNotExist and traitstring are internal plumbing around the output/logging pipeline and are not part of the stable public API in this release (LogInfo is documented on the Types page).

Utilities

AstroNbodySim.alter_line — Function

alter_line(filename::String, match::String, newline::String; all = false)

alter the first line containing match to newline

Keywords

  • all::Bool = false : If true, alter all lines containing match to newline
source