Particles
A set of objects with different properties are represented by subtypes of AbstractParticles. While not absolutely necessary, these kind of objects generally have IDs, positions, and velocity as properties. In the context of cosmological simulations, this applies to particle and galaxy data.
For an example implementation of a concrete subtype of AbstractParticles, see the source code of Particles.
CosmoParticles.AbstractParticles — Typeabstract type AbstractParticles endAbstract supertype for storing particle data efficiently in arrays.
Particles generally have IDs, positions, and velocities as properties. The properties are expected to be stored in a Dict{Symbol,Any} as vectors of length $N$, matrices of size $m×N$, or as scalars (when the property is equal for all particles).
The inbuilt functionality of AbstractParticles includes accessing and setting properties via the following syntax:
p.id = [1, 2, 3]
p[:id] === p.idIf the struct has additional fields, these can also be accessed by p.field, but not by p[:field]. The latter syntax can only be used to access the particle properties.
Property keys
:id: vector of IDs:pos: $2×N$ or $3×N$ matrix with positions:vel: $2×N$ or $3×N$ matrix with velocities
Any arrays may be of the type AbstractArray, provided the arrays are 1-indexed.
Methods
The methods Base.keys, Base.values, Base.haskey, Base.empty, Base.empty!, Base.isempty, and Base.copy! are forwarded to the property Dict.
Concrete types of AbstractParticles should have the following methods implemented (also see the implementation of Particles):
Base.copy: returns new object containing a copy of theDictBase.empty: returns an identical object, but with an emptyDictBase.:(==): should callBase.isequalto prevent obtainingmissingresults for properties with missing values (relevant forAllParticles)CosmoParticles.particle_name: returns the name of the struct to be printed viaBase.showBase.propertynames: implement this if there are additional struct fieldsBase.show(io, mime, p)
CosmoParticles.Particles — Typestruct Particles <: AbstractParticles
type::Symbol
props::Dict{Symbol,Any}
endParticles of a certain type (typically something like :dm or :gas in the cosmological context) with their properties.
The following naming convention is to be used for specific properties:
:id: vector of IDs:pos: $2×N$ or $3×N$ matrix with positions:vel: $2×N$ or $3×N$ matrix with velocities:mass: vector of masses or a scalar if all particles have the same mass:temp: vector of temperatures
CosmoParticles.Particles — MethodParticles(type[, pairs::Pair...])Create a Particles object with the given type and pairs of Symbol to the property values. These are passed to the underlying Dict. If no pairs are passed to the method, an empty Dict is created.
CosmoParticles.Particles — TypeParticles(p::AllParticles, props=nothing)Materializes the particle properties in a new particle object of type :all.
To only copy certain properties, props can be passed as a tuple of Symbols.
CosmoParticles.get_props — FunctionCosmoParticles.get_props(p::AbstractParticles)Return the property Dict belonging to the particles.
This returns p.props by default if not overridden.
This is not exported and should not be used outside of the defining files for particle types.
CosmoParticles.particle_name — FunctionCosmoParticles.particle_name(p::AbstractParticles)Returns the name of the particle type, which is used when printing an object of this type via Base.show.
This is not exported.
CosmoParticles.particle_number — FunctionCosmoParticles.particle_number(p::AbstractParticles)Returns the number of particles by determining the length of one of the property arrays.
This is not exported.
CosmoParticles.show_properties — MethodCosmoParticles.show_properties(io::IO, mime, p::AbstractParticles)Prints the number of particles, the name of the type, and the property names.
Should be used internally when overriding Base.show for concrete implementations of AbstractParticles.
This is not exported.