AstroNbodySim.CoarseMesh
— TypeConstruct a coarse mesh to overlap all particles for non-periodic boundary conditions
AstroNbodySim.DS
— TypeCompute forces using direct summation method if the particles run out of the non-periodic simulation box
AstroNbodySim.Delete
— TypeDelete outbound particles if they run out of the non-periodic simulation box
AstroNbodySim.DeviceConfig
— Typestruct DeviceConfig{Device, GA}
type::Any
: Supported:CPU
,GPU
GPU_NumThreads::Int64
GPU_Algorithm::Any
:::GPUAlgorithm
. Supported:AllPairs
,Tiled
. Default:AllPairs
AstroNbodySim.DeviceConfig
— MethodDeviceConfig(
;
type,
GPU_NumThreads,
GPU_Algorithm
) -> AstroNbodySim.DeviceConfig{CPU, AllPairs}
AstroNbodySim.DirectSum
— TypeDirect Summation Method
AstroNbodySim.FDM
— TypeFinite Differencing Method
AstroNbodySim.FEM
— TypeFinite Element Method
AstroNbodySim.FFT
— TypeFast Fourier Transform
AstroNbodySim.FVM
— TypeFinite Volume Method
AstroNbodySim.GravityConfig
— TypeGravityConfig(
;
...
) -> AstroNbodySim.GravityConfig{_A, Newton, DS, Vacuum} where _A
GravityConfig(
units;
ForceSofteningTable,
MOND_nuIndex,
GravityModel,
OutboundLimiter,
EnlargeMesh,
BoundaryCondition,
sparse,
model,
outbound,
enlarge,
boundary
) -> AstroNbodySim.GravityConfig{_A, Newton, DS, Vacuum} where _A
AstroNbodySim.GravityConfig
— Typestruct GravityConfig{Len, GM, OBL, BC}
ForceSofteningTable::StaticArraysCore.MVector{6}
: Gravitational softening lengths for different type of particlesmodel::Any
: Gravity model. Supported:Newton
,MOND1983Milgrom
,QUMOND
MOND_nuIndex::Float64
: Index of Mondian interpolation functionoutbound::Any
:::OutboundLimiter
. Choose how to handle particles out of the non-periodic simulation box. Supported: -Delete
: delete outbound particles -DS
: use direct summation method to compute forces -CoarseMesh
: Construct a coarse mesh to overlap all particles Default isDS
.
enlarge::Float64
: Enlarge the simulation box byenlarge
compared to the extent of system. Default is3.0
boundary::Any
: Boundary condition. Supported:Vacuum
,Periodic
,Dirichlet
. Default isVacuum
sparse::Bool
: Use sparse matrix to improve performance
Example
GravityConfig(uAstro)
GravityConfig(nothing)
GravityConfig(;ForceSofteningTable=[0.01u"kpc" for i in 1:6])
AstroNbodySim.LogInfo
— Typestruct LogInfo
timers::Dict{String, Int64}
: Timer enum names to access timing (continuously starting from 1)timing::Vector{UInt64}
: Timings defined by timer enumsanalysers::Dict{String, Function}
: Analyse on the whole simulation
Examples #TODO
Use uppercase letters to avoid
AstroNbodySim.LogInfo
— MethodLogInfo(; timers, analysers) -> LogInfo
AstroNbodySim.MHD
— TypeMagnetohydrodynamics
AstroNbodySim.ML
— TypeMachine Learning
AstroNbodySim.OutboundLimiter
— Type`::OutboundLimiter`. Choose how to handle particles out of the non-periodic simulation box.
Supported:
- `Delete`: delete outbound particles
- `DS`: use direct summation method to compute forces
- `CoarseMesh`: Construct a coarse mesh to overlap all particles
AstroNbodySim.OutputConfig
— Typestruct OutputConfig{OT}
dir::String
: Output directory. Default:joinpath(pwd(), "output")
func::Function
: Output function. Default:AstroNbodySim.output
type::Any
: Output Type: traits ofgadget2
,hdf5
,jld2
defined inAstroIO
. Default:gadget2()
format2::Bool
: Iftrue
, write in format2 mode for Gadget2 format. Default:true
acc::Bool
: Iftrue
, output acceleration in snapshots. Default:false
pot::Bool
: Iftrue
, output potential in snapshots. Default:false
SaveRestart::Bool
: Iftrue
, save restart files regularly. Default:true
SaveRestartFreq::Float64
: Regularly after every fraction of the whole simulation time, save restart files. Default:1.0
Notes on Keywords
- Keywords are compatible with
SimConfig
, and can also be overrided by field names of OutputConfig
Example
OutputConfig(; dir = "test", type = jld2(), format2 = false, acc = true, pot = true, SaveRestart = true, SaveRestartFreq = 0.33)
AstroNbodySim.OutputConfig
— MethodOutputConfig(
;
OutputDir,
OutputFunction,
OutputType,
format2,
acc,
pot,
SaveRestart,
SaveRestartFreq,
dir,
func,
type
) -> AstroNbodySim.OutputConfig{gadget2}
AstroNbodySim.OutputInfo
— Typemutable struct OutputInfo
snapshotcount::Int64
syncflag::Bool
AstroNbodySim.OutputInfo
— MethodOutputInfo(; snapshotcount) -> OutputInfo
AstroNbodySim.PhysicsInfo
— Typemutable struct PhysicsInfo
NumForceUpdateSinceLast::Int64
AstroNbodySim.PhysicsInfo
— MethodPhysicsInfo() -> PhysicsInfo
AstroNbodySim.SPH
— TypeSmoothed Particle Hydrodynamics
AstroNbodySim.SimConfig
— Typestruct SimConfig{F, U}
name::String
author::String
daytime::Dates.DateTime
floattype::Any
: Numeric type of float numbersunits::Any
: Prefered units in simulation. Default isuAstro
. SeePhysicalParticles
:uAstro
,uSI
,uGadget2
,uCGS
. To run without units, usenothing
ZeroValues::Any
:ZeroValue
. Pre-constructed zero values for different types to simplify function argumentsconstants::Any
:Constant
. Physical constantsloggingmode::Any
: Choose how to display status of simulation. Supported:NormalMode
,ProgressMode
,SilentMode
. Default isProgressMode
displaying progress barstime::Any
:TimeConfig
output::Any
:OutputConfig
solver::Any
:SolverConfig
grav::Any
:GravityConfig
device::Any
:DeviceConfig
Examples
SimConfig(; GravitySolver = Tree())
SimConfig(; device = GPU(), TimeStep = 1.0e-5u"Gyr")
SimConfig(; units = uGadget2)
SimConfig(; units = nothing, ForceSofteningTable = [0.01 for i in 1:6])
SimConfig(; TimeEnd = 1.0u"Gyr", OutputDir = "Test/Dir")
AstroNbodySim.SimConfig
— MethodSimConfig(
;
name,
author,
daytime,
floattype,
units,
ZeroValues,
constants,
loggingmode,
TimeBegin,
TimeEnd,
TimeBetweenSnapshots,
TimeStep,
TimeBase,
ErrTolTimestep,
MinStep,
MaxStep,
TimeIntegrationAlgorithm,
OutputDir,
OutputFunction,
OutputType,
format2,
acc,
pot,
SaveRestart,
SaveRestartFreq,
GravitySolver,
ForceSofteningTable,
MOND_nuIndex,
GravityModel,
device,
GPU_NumThreads,
GPU_Algorithm,
OutboundLimiter,
EnlargeMesh,
BoundaryCondition,
sparse
) -> SimConfig{DataType, Vector{Unitful.FreeUnits{N, D, nothing} where {N, D}}}
AstroNbodySim.Simulation
— Typestruct Simulation{D}
config::Any
id::Pair{Int64, Int64}
pids::Vector{Int64}
simdata::Any
timeinfo::Any
:::TimeInfo
outputinfo::Any
:::OutputInfo
loginfo::Any
:::LogInfo
physics::Any
:::PhysicsInfo
stream::Any
:::StreamInfo
visinfo::Any
:::VisualizationInfo
buffer::Any
:::Buffer
bgforce::Vector{Function}
bgpotential::Vector{Function}
AstroNbodySim.Simulation
— MethodSimulation(
d;
floattype,
units,
pids,
timers,
analysers,
Realtime,
RenderTime,
resolution,
xlims,
ylims,
zlims,
markersize,
bgforce,
bgpotential,
TreeOpenAngle,
ErrTolAcc,
ToptreeAllocFactor,
MaxTopnode,
TopnodeFactor,
TreeAllocFactor,
MaxTreenode,
ExtentMargin,
PeanoBits3D,
PeanoBits2D,
epsilon,
meshmode,
assignment,
Nx,
Ny,
Nz,
NG,
xMin,
xMax,
yMin,
yMax,
zMin,
zMax,
device,
EnlargeMesh,
BoundaryCondition,
kw...
) -> Any
AstroNbodySim.SolverConfig
— Typestruct SolverConfig{SolverG}
grav::Any
: Gravitational force solver. Supported:DirectSum
,Tree
,FDM
,FFT
,ML
. Default isDirectSum
AstroNbodySim.SolverConfig
— MethodSolverConfig(
;
GravitySolver,
grav
) -> AstroNbodySim.SolverConfig{DirectSum}
AstroNbodySim.StreamInfo
— Typemutable struct StreamInfo
loggingio::IOStream
timerio::IOStream
analyserio::IOStream
AstroNbodySim.TimeConfig
— Typestruct TimeConfig{Time, Step, I, TIA}
Begin::Any
: Physical time at the beginning of the simulationEnd::Any
: Physical time at the end of the simulationBetweenSnapshots::Any
: Time interval between snapshotsBetweenSnapshotsInt::Any
: Integer time interval between snapshotsstep::Any
: Timestep config. Controled by keywordTimeStep
. IfTimeStep
is zero, useAdaptiveTimestep
; otherwise useConstantTimestep
algorithm::Any
: Time integration algorithm. Supported:Euler
,Leapfrog
redshift::Float64
: Redshift at startscalefactor::Float64
: Scale factor at start
Notes on Keywords
- Keywords are compatible with
SimConfig
, and can also be overrided by field names of TimeConfig - If timestep is non-zero, use
ConstantTimestep
; otherwiseAdaptiveTimesteps
TimeBase
is the length of integer timeline. Default is1<<30
ErrTolTimestep
controls the accuracy of adaptive time integration
Examples
TimeConfig(; TimeEnd = 1.0u"Gyr") # Keyword `End = TimeEnd` by default
TimeConfig(; End = 2.0u"Gyr") # Override keyword from `SimConfig`
AstroNbodySim.TimeConfig
— MethodTimeConfig(
;
TimeBegin,
TimeEnd,
TimeBetweenSnapshots,
TimeStep,
TimeBase,
ErrTolTimestep,
MinStep,
MaxStep,
TimeIntegrationAlgorithm,
redshift,
scalefactor,
Begin,
End,
BetweenSnapshots,
Step,
algorithm
) -> Union{AstroNbodySim.TimeConfig{Unitful.Quantity{Float64, 𝐓, Unitful.FreeUnits{(Gyr,), 𝐓, nothing}}, AdaptiveTimestep{Unitful.Quantity{Float64, 𝐓, Unitful.FreeUnits{(Gyr,), 𝐓, nothing}}, Float64}, Int64, Leapfrog}, AstroNbodySim.TimeConfig{Unitful.Quantity{Float64, 𝐓, Unitful.FreeUnits{(Gyr,), 𝐓, nothing}}, ConstantTimestep{Unitful.Quantity{Float64, 𝐓, Unitful.FreeUnits{(Gyr,), 𝐓, nothing}}}, Int64, Leapfrog}}
AstroNbodySim.TimeInfo
— Typemutable struct TimeInfo{T<:Number, I<:Integer}
dt::Number
: Time interval between neighbor time stepssystem_time_int::Integer
system_time_float::Number
last_system_time_int::Integer
last_system_time_float::Number
next_output_time_int::Integer
next_output_time_float::Number
redshift::Float64
scalefactor::Float64
min_endstep::Integer
stepcount::Integer
AstroNbodySim.TimeInfo
— MethodTimeInfo(
config::SimConfig
) -> TimeInfo{T, Int64} where T<:Number
AstroNbodySim.Tree
— TypePeano-Hilbert Space Filling Octree Method
AstroNbodySim.TreeSimConfig
— Typestruct TreeSimConfig
Controls accuracy of tree method
TreeOpenAngle::Float64
: If the view angle of tree node that relative to the sink point is too large, open this node. In radian unit. Default is0.1
ErrTolAcc::Float64
: While opening the tree node, take the last acceleration into account. Improves accuracy at high redshift cosmology. Default is0.025
AstroNbodySim.VisualizationInfo
— Typemutable struct VisualizationInfo
progress::ProgressMeter.Progress
PlotData::Any
resolution::Any
fig::Any
Realtime::Bool
RenderTime::Float64
last_plot_time::Float64
xlims::Any
ylims::Any
zlims::Any
markersize::Float64
AstroNbodySim.VisualizationInfo
— MethodVisualizationInfo(
;
Realtime,
RenderTime,
resolution,
xlims,
ylims,
zlims,
markersize
) -> VisualizationInfo
AstroNbodySim.QUMOND_PDM_density
— MethodQUMOND_PDM_density(m::MeshCartesianStatic, ACC0::Number)
Compute ρPDM on the RHS (right hand side) of QUMOND (QUasi-linear MOdified Newtonian Dynamics). Return ρPDM
AstroNbodySim.QUMOND_acc!
— MethodQUMOND(m::MeshCartesianStatic, ACC0::Number, G::Number)
Apply QUMOND (QUasi-linear MOdified Newtonian Dynamics) formula to accelerations
AstroNbodySim.QUMOND_acc
— MethodQUMOND_acc(m::MeshCartesianStatic, ACC0::Number, G::Number)
- Compute ρ_PDM
- Solve modified potential on the mesh
- Compute acceleration by finite differencing the potential
Return acceleration
AstroNbodySim.QUMOND_phi
— MethodQUMOND_phi(m::MeshCartesianStatic, ACC0::Number, G::Number)
First compute ρ_PDM, then solve QUMOND (QUasi-linear MOdified Newtonian Dynamics) equation on the mesh. Return modified potential
AstroNbodySim.add_timer
— Methodadd_timer(
sim::Simulation,
name::String,
t_start::UInt64,
t_end::UInt64
) -> Any
Add time t_end - t_start
to the named timer. This is useful for procedures distributed over several functions.
AstroNbodySim.add_timer
— Methodadd_timer(sim::Simulation, name::String, t::UInt64) -> Any
Add time t
to the named timer. This is useful for procedures distributed over several functions.
AstroNbodySim.alter_line
— Methodalter_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
tonewline
AstroNbodySim.alter_param
— Methodalter_param(filename::String, param::String, value)
alter all lines containing param
to param value
AstroNbodySim.apply_background_force
— Methodapply_background_force(f::Function, data::StructArray)
Apply f
to all particles in data by calling data.Acc[i] += f(data[i])
. f
must return a PVector
in the unit of physical acceleration.
AstroNbodySim.begin_timer
— Methodbegin_timer(sim::Simulation, name::String) -> UInt64
Begin the named timer, save time_ns()
` to it
AstroNbodySim.clear
— Functionfunction clear(pids = procs())
Clear distributed memories in AstroNbodySim.registry
, AstroNbodySim.PhysicalTrees.registry
AstroNbodySim.compute_OldAcc
— Methodcompute_OldAcc(data::StructArray)
data.OldAcc[i] = norm(data.Acc[i])
AstroNbodySim.compute_acc
— Methodcompute_acc(
m::MeshCartesianStatic,
dim::Val{3},
mode::VertexMode
)
Compute accelerations by second-order central differencing of potential on the mesh. Results are stored in acc
and return nothing
.
AstroNbodySim.compute_force_pairwise
— Methodfunction computeforcepairwise(p1::AbstractParticle, p2::AbstractParticle, G::Number, h::Number)
return acc of p1 and p2 in a Tuple
AstroNbodySim.compute_kinetic
— Methodcompute_kinetic(p::AbstractParticle) -> Any
Compute kinetic energy of particle: 0.5 * p.Mass * p.Vel * p.Vel
AstroNbodySim.crosstime
— Methodcrosstime(R, v)
t_cross = R / v
The typical time needed to cross the system.
AstroNbodySim.dynamicaltime
— Methoddynamicaltime(ρ, G)
t_dyn = sqrt(3 * π / (16 * G * ρ))
The time required to travel halfway across the system.
AstroNbodySim.eccentricity
— Methodeccentricity(
G::Number,
M::Number,
v::Number,
h::Number
) -> Any
Eccentricity of elliptic orbit
G
: gravitational constantM
: mass of central objectv
: velocity at radiusr
h
: specific relative angular momentum at radiusr
AstroNbodySim.eccentricity
— Methodeccentricity(
G::Number,
M::Number,
r::AbstractPoint,
v::AbstractPoint
) -> Any
Eccentricity vector of elliptic orbit
G
: gravitational constantM
: mass of central objectr
: position at specific timev
: velocity vector at positionr
AstroNbodySim.ellipticPeriod
— MethodellipticPeriod(G::Number, M::Number, a::Number) -> Any
Orbital period of elliptic orbit
G
: gravitational constantM
: mass of central objecta
: length of semi-major axis
AstroNbodySim.ellipticSemiMajor
— MethodellipticSemiMajor(
G::Number,
M::Number,
r::Number,
v::Number
) -> Any
Length of semi-major axis of elliptic orbit
G
: gravitational constantM
: mass of central objectr
: orbit radius at specific timev
: velocity at radiusr
AstroNbodySim.freefalltime
— Methodfreefalltime(ρ, G)
t_ff = sqrt(3 * π / (32 * G * ρ))
The time it takes a sphere with zero pressure to collapse to a point.
AstroNbodySim.get_all_data
— MethodCopy data to CPU
AstroNbodySim.get_all_data
— MethodCopy data to CPU
AstroNbodySim.get_local_data
— MethodAccess data on GPU
AstroNbodySim.hubbletime
— Methodhubbletime(H0)
t_hubble = 1/H0
The age of the universe.
AstroNbodySim.interactiontime
— Methodinteractiontime(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
AstroNbodySim.meandensity
— Methodmeandensity(M, R)
ρ = 3*M/(4πR^3)
Mean density of a spherical system.
AstroNbodySim.mond_Milgrom1983
— Methodmond_Milgrom1983(sim::Simulation, data::StructArray)
Apply Milgrom 1983 formula of MOND (MOdified Newtonian Dynamics) to accelerations
AstroNbodySim.next_simulationid
— Functionnext_simulationid()
Produces an incrementing ID that will be used for simulations.
AstroNbodySim.nu
— Functionnu(y::Number, n::Number = 2)
Generalized MOND (MOdified Newtonian Dynamics) interpolation function. See also nu1
, nu2
AstroNbodySim.nu1
— Methodnu1(y::Number)
MOND (MOdified Newtonian Dynamics) interpolation function with index = 1. See also nu
, nu2
AstroNbodySim.nu2
— Methodnu1(y::Number)
MOND (MOdified Newtonian Dynamics) interpolation function with index = 2. See also nu
, nu1
AstroNbodySim.orbitaltime
— Methodorbitaltime(ρ, G)
t_orb = sqrt(3π/(Gρ))
The time it takes to complete a (circular) orbit.
AstroNbodySim.pseudoNewtonianAcc
— MethodpseudoNewtonianAcc(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
.
AstroNbodySim.pseudoNewtonianAcc
— MethodpseudoNewtonianAcc(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
.
AstroNbodySim.pseudoNewtonianPotential
— MethodpseudoNewtonianPotential(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
.
AstroNbodySim.pseudoNewtonianPotential
— MethodpseudoNewtonianPotential(G, M, rg)
pot = - G * M / (R - rg)
Pseudo-Newtonian potential around a compat central object. Diverge at gravity radius r_g
.
AstroNbodySim.r_g
— Methodr_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.
AstroNbodySim.relaxtime
— Methodrelaxtime(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.
AstroNbodySim.set_softlen_local!
— Methodset_softlen_local!(sim::Simulation, c::Collection, h::Number)
Set softening length of collection c
to h
.
AstroNbodySim.set_softlen_local!
— Methodset_softlen_local!(sim::Simulation, h::Number)
Set all softening lengths to h
AstroNbodySim.softlen
— Methodsoftlen(c::Collection, table::MVector)
softlen(p::AbstractParticle, table::MVector)
softlen(p::AbstractParticle, sim::Simulation)
softlen(c::Collection, sim::Simulation)
Retrive softening length from table
AstroNbodySim.suggest_softlen!
— Methodsuggest_softlen!(sim::Simulation)
Set all softening lengths to suggested value.
AstroNbodySim.suggest_softlen
— Methodsuggest_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!
AstroNbodySim.tabstring
— Functiontabstring(s::String, tab::String = " ")
Retract all lines in string s
by tab
AstroNbodySim.total_angular_momentum
— Methodtotal_angular_momentum(sim::Simulation) -> Any
Compute total angular momentum vector of the system
AstroNbodySim.total_energy
— Methodtotal_energy(sim::Simulation) -> Any
Total energy (kinetic + potential) of sim data
AstroNbodySim.total_kinetic
— Methodtotal_kinetic(sim::Simulation) -> Any
Compute kinetic energy of particles on workers and return the sum
AstroNbodySim.total_kinetic
— Methodtotal_kinetic(data::StructArray) -> Any
Sum kinetic energy: 0.5 * data.Mass[i] * data.Vel[i] * data.Vel[i]
AstroNbodySim.total_kinetic_local
— Methodtotal_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.
AstroNbodySim.total_momentum
— Methodtotal_momentum(sim::Simulation, axis::Symbol) -> Any
Compute momentum of the system in the direction of axis
AstroNbodySim.total_momentum
— Methodtotal_momentum(sim::Simulation) -> Any
Compute total momentum vector of the system
AstroNbodySim.total_potential
— Methodtotal_potential(data::StructArray) -> Any
Sum potential energy of particles in data
. Potentials need to be computed in advance.
Return nothing
if empty.
AstroNbodySim.typicalvelocity
— Methodtypicalvelocity(G, M, R)
v = sqrt(G*M/R)
Typical velocity of a spherical system.
AstroNbodySim.write_gadget2_param
— Methodfunction writegadget2param(filename::String, ICfilename::String)
Params
- filename : name of param file
- ICfilename : name of initial conditions
AstroNbodySim.write_timing
— Methodwrite_timing(sim::Simulation) -> Any
Save the timings to file
Base.run
— Methodrun(sim::Simulation) -> Any
This function does all the work for you:
prepare
sim environment and preprocess data- evaluate force, initialize timesteps, output
mainloop
Base.setproperty!
— MethodBase.setproperty!(x::LogInfo, symbol::Symbol, d::Dict)
Modify the memories of Dict rather than modifing the pointer of Dict