BifrostTools.primary_varsConstant
primary_vars

The primary variables and their order of storage for primary variables in a Bifrost .snap binary file.

source
BifrostTools.BifrostExperimentType
BifrostExperiment(
    expname::String="none",
    expdir::String=pwd()
    ;
    mesh_file=nothing
    )

A struct for your Bifrost-experiment.

Fields:

    expname         ::String
    expdir          ::String
    snaps           ::Vector{Int64}
    snapsize        ::Tuple{Int64, Int64, Int64}
    num_snaps       ::Int64
    num_primary_vars::Int64

source
BifrostTools.code_to_cgsMethod
code_to_cgs(
    variable::String,
    params  ::Dict{String,String},
)

Conversion factor of variable from code units to cgs units.

source
BifrostTools.convert_unitsMethod
convert_units(
    data    ::AbstractArray,
    variable::String,
    params  ::Dict{String,String},
    units   ::String,
    )

Convert the data from code units to cgs or SI. Conversion factor depends on variable and snapshot params.

source
BifrostTools.dxdnMethod
dxdn(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the x-direction of every entry in arr shifted a half grid point downwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.dxupMethod
dxup(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the x-direction of every entry in arr shifted a half grid point upwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.dydnMethod
dydn(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the y-direction of every entry in arr shifted a half grid point downwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.dyupMethod
dyup(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the y-direction of every entry in arr shifted a half grid point upwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.dzdnMethod
dzdn(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the z-direction of every entry in arr shifted a half grid point downwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.dzupMethod
dzup(
	arr::Array{T,3},
	dz::Vector{T}, 
	periodic::Bool=false, 
	order::Int=6
	)

Computes the spatial derivative in the z-direction of every entry in arr shifted a half grid point upwards. Defaults to the 6th order accurate Bifrost derivative with order=6, optional 2nd order accurate derivative with keyword order=2

source
BifrostTools.get_and_destagger_varMethod
function get_and_destagger_var(expname::String,
    filename::String,
    params::Dict{String,String},
    varnr::Integer,
    ;
    destaggeroperation::Function,
    units::String="none",
    periodic::Bool=false,
    order::Int=6,
    slicex::AbstractVector{<:Integer}=Int[],
    slicey::AbstractVector{<:Integer}=Int[],
    slicez::AbstractVector{<:Integer}=Int[],
    kwargs...
    )

Function to load a staggered variable and interpolate it to cell center. The staggered variables that typically need to be interpolated are the velocity and magnetic field components. Normally you need to use destaggeroperation=zup for vz and bz with periodic=false, and destaggeroperation=xup for vx and bx with periodic=true (same for y direction).

source
BifrostTools.get_auxFunction
get_aux(
    file_name::String,
    params   ::Dict{String,String}
)

Reads Bifrost *.aux binary file using memory-mapping. The returned auxdata array will have dimensions (mx,my,mz,nvars) where nvars is the number of aux-variables. Assumes single floating point precision by default.

source
BifrostTools.get_axesMethod
get_axes(
    xp::BifrostExperiment
    ;
    units="code"
    )

Return a tuple containing the axis of the BifrostExperiment in the desired units.

source
BifrostTools.get_basenameMethod
get_basename(
    expname ::String,
    snap    ::Union{<:Integer, AbstractVector{<:Integer}},
    expdir  ::String,
    )

Return the basename of snapshots in the experiment expname, located in the directory expdir. Also return the filename (withou file extension) of the first snapshot of the experiment.

source
BifrostTools.get_electron_densityMethod
function get_electron_density(
    xp::BifrostExperiment,
    snap::Integer,
    kwargs...)

Function to calculate the electron density from a snapshot snap. Supports slicing. Gas density rho and internal energy e are optional arguments and can be passed (but they MUST be in cgs units). If these quantities already exist, passing them will speed up the calculation of electron density.

kwargs: units::String="si", slicex::AbstractVector{<:Integer}=Int[], slicey::AbstractVector{<:Integer}=Int[], slicez::AbstractVector{<:Integer}=Int[], rho::Array{AbstractFloat,3}=Float32[;;;], e::Array{AbstractFloat,3}=Float32[;;;], tabfile::String="tabparam.in"

source
BifrostTools.get_electron_densityMethod
function get_electron_density(
    expname::String,
    snap::Integer,
    expdir::String;
    units::String="si",
    slicex::AbstractVector{<:Integer}=Int[],
    slicey::AbstractVector{<:Integer}=Int[],
    slicez::AbstractVector{<:Integer}=Int[],
    rho::Array{T,3}=Float32[;;;],
    e::Array{T,3}=Float32[;;;],
    tabfile::String="tabparam.in"
    ) where {T<:AbstractFloat}
source
BifrostTools.get_numvarsMethod
get_numvars(
    params::Dict{String,String},
)

Returns number of primary variables and number of auxiliary variables, given the snapshot-parameters.

source
BifrostTools.get_snapFunction
get_snap(
    expname::String,
    snap   ::Int,
    expdir ::String,
    )

Reads Bifrost *.snap binary file as an Array in dimension: (mx,my,mz,nvar). Takes experiment name, experiment directory, and snap number as arguments. Returns snapdata (the data) and params (the snap parameters). Assumes single floating point precision by default.

Variables of snapdata:

    snapdata[:,:,:,1] : r, density
    snapdata[:,:,:,2] : px, x-component of momentum
    snapdata[:,:,:,3] : py, y-component of momentum
    snapdata[:,:,:,4] : pz, z-component of momentum
    snapdata[:,:,:,5] : e, energy

    if params["do_mhd"] == 1 # numvars = 8, otherwise numvars = 5
        snapdata[:,:,:,6] : bx, x-component of magnetic field
        snapdata[:,:,:,7] : by, y-component of magnetic field
        snapdata[:,:,:,8] : bz, z-component of magnetic field

Warning: variables in code units.ts

source
BifrostTools.get_snap_numbersMethod
get_snap_numbers(
    expdir::String,
    expname::String="none"
    ;
    findall::Bool=false,
    filenames::Vector{String}=String[]
    )

Finds all files in the format 'expnameXXX.snap' in the experiment directory `expdir, and returns a vector of the snapshots XXX. Ifexpname` is not given, is is assumed that the directory of the simulation matches the experiment name.

source
BifrostTools.get_snapsize_and_numvarsMethod
get_snapsize_and_numvars(
    params::Dict{String,String},
)

Returns snapsize (mx, my, mz), number of primary variables and number of auxiliary variables, given the snapshot-parameters.

source
BifrostTools.get_varMethod
get_var(
    xp::BifrostExperiment,
    snap::Union{<:Integer, AbstractVector{<:Integer}},
    variable::String,
    args...
    ;
    kwargs...
    )

Load a variable from one or multiple snapshots of xp.

Available variables

The primary variables:

  • "r": density
  • "px": x-component of momentum
  • "py": y-component of momentum
  • "pz": z-component of momentum
  • "e": energy

if params["do_mhd"] == true

  • "bx": x-component of magnetic field
  • "by": y-component of magnetic field
  • "bz": z-component of magnetic field

auxilliary variables (variables in params["aux"]):

  • "p": pressure
  • "tg": gas temperature ...

Optional keyword-arguments

Converts variables to "si" or "cgs" units: units="si" or units="cgs".

To load a slice of the variable, give e.g. slicex=[32, 410] or slicey=40:90

Example usage:

exp_name = "cb24oi"
exp_dir = "/mn/stornext/d21/RoCS/matsc/3d/run/cb24oi"
snap = 700

xp = BifrostExperiment(expname, expdir)

# Load pressude for the full cube in si units
pressure = get_var(xp, snap, "p"; units="si")

# Load gas density in a slize along the xy-plane in cgs units
rho = get_var(xp, snap, "r"; units="cgs", slicez=[100])
source
BifrostTools.get_varMethod
get_var(
    filename       ::String,
    params         ::Dict{String,String},
    varnr          ::Integer,
    precision      ::DataType=Float32;
    slicex         ::AbstractVector{<:Integer}=Int[],
    slicey         ::AbstractVector{<:Integer}=Int[],
    slicez         ::AbstractVector{<:Integer}=Int[]
    )

Load variable nr. varnr from filename. The variable could be either primary or auxiliary. Slicing the snapshot is optional. Assumes single precision snapshot by default.

source
BifrostTools.get_varMethod
get_var(
    expname ::String,
    snap    ::Union{<:Integer, AbstractVector{<:Integer}},
    expdir  ::String,
    variable::String,
    args...
    ;
    kwargs...
)

Load a variable from one or multiple snapshots of a Bifrost experiment with experiment directory expdir and experiment name expname.

source
BifrostTools.get_variable_offset_in_fileMethod
get_variable_offset_in_file(
    precision::DataType,
    snapsize::Tuple{Integer, Integer, Integer},
    varnr   ::Integer
    )

Given the precision and size of a snapshot, find the offset for reading the variable with index varnr directly from file. Offset given in number of bytes.

source
BifrostTools.get_varnr_and_file_suffixMethod
get_varnr_and_file_suffix(
    params::Dict{String,String},
    variable::String
    )

Given the snapshot params and desired variable, return its index in the binary file, as well as the suffix of this file. (A format string where the snapshot number is to be inserted).

source
BifrostTools.read_paramsMethod
read_params(file_name::String)

Reads and returns parameters params of a Bifrost simulation snapshot given the path file_name to the simulation snapshot. The input file should have the format 'name_xxx.idl' where 'name' is the simulation name and 'xxx' is the snapshot number

source
BifrostTools.rotateMethod
rotate(
    data         ::AbstractArray,
    variable     ::String,
    rotation_axis::String,
    )

Rotate the data about an rotation_axis.

source
BifrostTools.xdnMethod
function xdn(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point downwards in the x-direction

source
BifrostTools.xupMethod
function xup(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point upwards in the x-direction

source
BifrostTools.ydnMethod
function ydn(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point downwards in the y-direction

source
BifrostTools.yupMethod
function yup(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point upwards in the y-direction

source
BifrostTools.zdnMethod
function zdn(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point downwards in the z-direction

source
BifrostTools.zupMethod
function zup(
    arr::Array{T,3},
    periodic::Bool=true,
    order::Int=6
) where {T<:AbstractFloat}

Stagger operation on arr by a 5th order polynomial interpolation, shifting the variable half a grid point upwards in the z-direction

source