Methods
Index
AstroNbodySim.LogInfo
AstroNbodySim.QUMOND
AstroNbodySim.QUMOND_PDM_density
AstroNbodySim.QUMOND_acc
AstroNbodySim.QUMOND_phi
AstroNbodySim.alter_line
AstroNbodySim.alter_param
AstroNbodySim.crosstime
AstroNbodySim.diff_mat
AstroNbodySim.dynamicaltime
AstroNbodySim.eccentricity
AstroNbodySim.ellipticPeriod
AstroNbodySim.ellipticSemiMajor
AstroNbodySim.freefalltime
AstroNbodySim.hubbletime
AstroNbodySim.interactiontime
AstroNbodySim.meandensity
AstroNbodySim.mond_Milgrom1983
AstroNbodySim.nu
AstroNbodySim.nu1
AstroNbodySim.nu2
AstroNbodySim.orbitaltime
AstroNbodySim.pseudoNewtonianAcc
AstroNbodySim.pseudoNewtonianPotential
AstroNbodySim.r_g
AstroNbodySim.radius_gravity
AstroNbodySim.radius_schwarzschild
AstroNbodySim.relaxtime
AstroNbodySim.smooth_coef
AstroNbodySim.softlen
AstroNbodySim.suggest_softlen
AstroNbodySim.suggest_softlen!
AstroNbodySim.total_angular_momentum
AstroNbodySim.total_energy
AstroNbodySim.total_kinetic
AstroNbodySim.total_momentum
AstroNbodySim.total_potential
AstroNbodySim.traitstring
AstroNbodySim.typicalvelocity
AstroNbodySim.write_gadget2_param
Base.run
Public
Main functions
Base.run
— Functionfunction run(sim::Simulation)
This function does all the work for you:
prepare
sim environment and preprocess data- evaluate force, initialize timesteps, output
mainloop
Missing docstring for step
. Check Documenter's build log for details.
Missing docstring for preprocessdata
. Check Documenter's build log for details.
Missing docstring for compute_force
. Check Documenter's build log for details.
Missing docstring for compute_potential
. Check Documenter's build log for details.
Missing docstring for output
. Check Documenter's build log for details.
Missing docstring for restart
. Check Documenter's build log for details.
Missing docstring for saverestart
. Check Documenter's build log for details.
Missing docstring for loadrestart
. Check Documenter's build log for details.
AstroNbodySim.softlen
— Functionsoftlen(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
— Functionsuggest_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.suggest_softlen!
— Functionsuggest_softlen!(sim::Simulation)
Set all softening lengths to suggested value.
Missing docstring for set_softlen!
. Check Documenter's build log for details.
Particle-Mesh
AstroNbodySim.smooth_coef
— Functionsmooth_coef(x_coord, fitting_order, diff_order)
Fit the data with fitting_order
polynomial and calculate the diff_order
differential at x=0
. Input the x coordinates of data. Return the coefficients for calculating the result from data.
Suppose the data is [u,v,w]
, we want to smooth v
by fitting a line (1 order polynomial) and use it estimate a better v
. Then set the x coordinates of [u,v,w]
be [-1,0,1]
, fit it and calculate the result (0 order differential) at x=0, the result will be (u+v+w)/3
. So smooth_coef([-1,0,1],1,0)
will return [1/3,1/3/1/3]
.
Using Rational
type or Sym
type of SymPy
can get the exact coefficients. For example, smooth_coef(Sym[0,1,2],2,1)
get Sym[-3/2, 2, -1/2]
, which means the first order differential of [u,v,w]
at u
is -1.5u+2v-0.5w
. Using this way can generate all data in https://en.wikipedia.org/wiki/Finite_difference_coefficient
Examples
- Linear extrapolation:
smooth_coef([1,2],1,0)
get[2, -1]
, so the left linear extrapolation of[u,v]
is2u-v
. - Quadratic extrapolation:
smooth_coef([-3,-2,-1],2,0)
get[1, -3, 3]
, so the right Quadratic extrapolation of[u,v,w]
isu-3v+3w
. - First order central differential:
smooth_coef(Rational[-1,0,1],2,1)
get[-1//2, 0//1, 1//2]
, so the first order differential of[u,v,w]
at v is(w-u)/2
- Second order central differential:
smooth_coef([-1,0,1],2,2)
get[1, -2, 1]
, so the second order differential of[u,v,w]
at v isu+w-2v
- Five points quadratic smoothing:
smooth_coef([-2,-1,0,1,2],2,0)
get[-3/35, 12/35, 17/35, 12/35, -3/35]
, so[-3/35 12/35 17/35 12/35 -3/35]*[a,b,c,d,e]
get the smoothedc
. - Four points quadratic interpolation:
smooth_coef([-3,-1,1,3],2,0)
get[-1/16, 9/16, 9/16, -1/16]
, sosmooth_coef([-3,-1,1,3],2,0)'*[a,b,c,d]
get the estimated value at the middle ofb
andc
.
AstroNbodySim.diff_mat
— Functiondiff_mat(n, order=1; T=Float64, dt=one(T), points=2*div(order+1,2)+1, lpoints=div(points,2), rpoints=points-lpoints-1, fitting_order=lpoints+rpoints, boundary=:Extrapolation, boundary_points=lpoints+rpoints+1, boundary_order=boundary_points-1, sparse=false)
Generate differential matrix.
Arguments
n
: Matrix size. Ifv
is lengthn
vector, diff_mat(n)*v calculate the differential ofv
.order
: Differential order.T
: Matrix element type. If setT=Rational
orusing SymPy
and setT=Sym
,diff_mat
will return the exact value.dt
: Numerical differential step size.points
: Number of points for fitting polynomial to estimate differential. This argument is only for convenience. The real number of points is alwayslpoints+rpoints+1
.lpoints
: Number of points at left to the target point, which differential is calculated by the fitted polynomial.rpoints
: Number of points at right to the target point. Iflpoints==rpoints
, then the differential is estimated as central finite difference. Iflpoints==0
, then it is normal forward finite difference. Ifrpoints==0
, then it is backward finite difference.fitting_order
: The order of the fitted polynomial for estimating differential.boundary
: Boundary condition. Can beDirichlet()
(boundary value is zero),Periodic
(assume data is periodic),:Extrapolation
(boundary value is extrapolated according toboundary_points
andboundary_order
),:None
(not deal with boundary, will return non-square matrix).boundary_points
: Number of points for fitting polynomial to estimate differential at boundary. Normally it should not be much less thanpoints
, otherwise sometimes the current point may not be used to estimate the differential.boundary_order
: The order of the fitted polynomial for points determined byboundary_points
.sparse
: If true, return sparse matrix instead of dense one.
Examples
k=5; x=rand(k);
diff_mat(k,1;points=3)*x #do 3 points 1st order central differential ((x[n+1]-x[n-1])/2).
diff_mat(k,2;points=3)*x #do 3 points 2nd order central differential (x[n+1]+x[n-1]-2x[n]).
diff_mat(k,1;points=2,lpoints=0)*x #do the normal 1st order forward differential (x[n+1]-x[n]).
diff_mat(k,1;lpoints=1,rpoints=0)*x #do the 1st order backward differential (x[n-1]-x[n]).
Missing docstring for diff_vec
. Check Documenter's build log for details.
Missing docstring for delta_mat2
. Check Documenter's build log for details.
Missing docstring for delta_mat3
. Check Documenter's build log for details.
Missing docstring for laplace_conv_op
. Check Documenter's build log for details.
Missing docstring for laplace_conv
. Check Documenter's build log for details.
Missing docstring for fft_poisson
. Check Documenter's build log for details.
Missing docstring for fft_poisson!
. Check Documenter's build log for details.
Missing docstring for fdm_poisson
. Check Documenter's build log for details.
Machine Learning
Missing docstring for train_cnn_poisson2d
. Check Documenter's build log for details.
Missing docstring for train_cnn_poisson3d
. Check Documenter's build log for details.
Missing docstring for cnn_poisson
. Check Documenter's build log for details.
Timestep
Missing docstring for ConstantTimestep
. Check Documenter's build log for details.
Missing docstring for AdaptiveTimestep
. Check Documenter's build log for details.
Missing docstring for init_timesteps
. Check Documenter's build log for details.
Missing docstring for find_next_sync_point_and_drift
. Check Documenter's build log for details.
Missing docstring for advance_and_find_timestep
. Check Documenter's build log for details.
Energy
AstroNbodySim.total_angular_momentum
— Functiontotal_angular_momentum(sim::Simulation) -> Any
Compute total angular momentum vector of the system
AstroNbodySim.total_potential
— Functiontotal_potential(data::StructArray) -> Any
Sum potential energy of particles in data
. Potentials need to be computed in advance.
Return nothing
if empty.
AstroNbodySim.total_momentum
— Functiontotal_momentum(sim::Simulation, axis::Symbol) -> Any
Compute momentum of the system in the direction of axis
total_momentum(sim::Simulation) -> Any
Compute total momentum vector of the system
AstroNbodySim.total_kinetic
— Functiontotal_kinetic(data::StructArray) -> Any
Sum kinetic energy: 0.5 * data.Mass[i] * data.Vel[i] * data.Vel[i]
total_kinetic(sim::Simulation) -> Any
Compute kinetic energy of particles on workers and return the sum
AstroNbodySim.total_energy
— Functiontotal_energy(sim::Simulation) -> Any
Total energy (kinetic + potential) of sim data
Data processing
Missing docstring for find_particle
. Check Documenter's build log for details.
Missing docstring for substract_by_id
. Check Documenter's build log for details.
Missing docstring for diff_by_id
. Check Documenter's build log for details.
MOND
AstroNbodySim.nu
— Functionnu(y::Number, n::Number = 2)
Generalized MOND (MOdified Newtonian Dynamics) interpolation function. See also nu1
, nu2
AstroNbodySim.nu1
— Functionnu1(y::Number)
MOND (MOdified Newtonian Dynamics) interpolation function with index = 1. See also nu
, nu2
AstroNbodySim.nu2
— Functionnu1(y::Number)
MOND (MOdified Newtonian Dynamics) interpolation function with index = 2. See also nu
, nu1
AstroNbodySim.mond_Milgrom1983
— Functionmond_Milgrom1983(sim::Simulation, data::StructArray)
Apply Milgrom 1983 formula of MOND (MOdified Newtonian Dynamics) to accelerations
AstroNbodySim.QUMOND_PDM_density
— FunctionQUMOND_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_phi
— FunctionQUMOND_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.QUMOND_acc
— FunctionQUMOND_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
— TypeQUasi-linear MOdified Newtonian Dynamics
Black Hole
AstroNbodySim.r_g
— Functionr_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.radius_gravity
— Functionr_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.radius_schwarzschild
— Functionr_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.pseudoNewtonianPotential
— FunctionpseudoNewtonianPotential(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
.
pseudoNewtonianPotential(G, M, rg)
pot = - G * M / (R - rg)
Pseudo-Newtonian potential around a compat central object. Diverge at gravity radius r_g
.
AstroNbodySim.pseudoNewtonianAcc
— FunctionpseudoNewtonianAcc(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
.
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
.
Elliptic Orbit
AstroNbodySim.ellipticSemiMajor
— FunctionellipticSemiMajor(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.ellipticPeriod
— FunctionellipticPeriod(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.eccentricity
— Functioneccentricity(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
eccentricity(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
Time scales
AstroNbodySim.typicalvelocity
— Functiontypicalvelocity(G, M, R)
v = sqrt(G*M/R)
Typical velocity of a spherical system.
AstroNbodySim.meandensity
— Functionmeandensity(M, R)
ρ = 3*M/(4πR^3)
Mean density of a spherical system.
AstroNbodySim.crosstime
— Functioncrosstime(R, v)
t_cross = R / v
The typical time needed to cross the system.
AstroNbodySim.hubbletime
— Functionhubbletime(H0)
t_hubble = 1/H0
The age of the universe.
AstroNbodySim.relaxtime
— Functionrelaxtime(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.interactiontime
— Functioninteractiontime(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.dynamicaltime
— Functiondynamicaltime(ρ, G)
t_dyn = sqrt(3 * π / (16 * G * ρ))
The time required to travel halfway across the system.
AstroNbodySim.freefalltime
— Functionfreefalltime(ρ, G)
t_ff = sqrt(3 * π / (32 * G * ρ))
The time it takes a sphere with zero pressure to collapse to a point.
AstroNbodySim.orbitaltime
— Functionorbitaltime(ρ, G)
t_orb = sqrt(3π/(Gρ))
The time it takes to complete a (circular) orbit.
Output and Logging
Missing docstring for outputparallel
. Check Documenter's build log for details.
Missing docstring for setuploggers
. Check Documenter's build log for details.
AstroNbodySim.LogInfo
— Typestruct LogInfo
timers::Symbol
Timer enum names to access timing (continuously starting from 1)
timing::Vector{UInt64}
Timings defined by timer enums
analysers::Dict{String, Function}
Analyse on the whole simulation
Examples #TODO
Use uppercase letters to avoid
Missing docstring for DefaultTimer
. Check Documenter's build log for details.
Missing docstring for mkpathIfNotExist
. Check Documenter's build log for details.
AstroNbodySim.traitstring
— FunctionBetter printing of trait types
Tools
Missing docstring for write_gadget2_makefile
. Check Documenter's build log for details.
AstroNbodySim.write_gadget2_param
— Functionfunction writegadget2param(filename::String, ICfilename::String)
Params
- filename : name of param file
- ICfilename : name of initial conditions
AstroNbodySim.alter_param
— Functionalter_param(filename::String, param::String, value)
alter all lines containing param
to param value
AstroNbodySim.alter_line
— Functionalter_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
Missing docstring for add_line
. Check Documenter's build log for details.