BifrostTools.cgs_to_SI_conversion_factors — Constant
cgs_to_SI_conversion_factorsFactors for converting some physical quantities from cgs-units to SI-units.
BifrostTools.primary_vars — Constant
primary_varsThe primary variables and their order of storage for primary variables in a Bifrost .snap binary file.
BifrostTools.BifrostExperiment — Type
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::Int64BifrostTools.BifrostMesh — Type
BifrostMeshStores Bifrost grid information in struct
Base.Multimedia.display — Method
Base.display(xp::BifrostExperiment)Prints information about the BifrostExperiment.
BifrostTools.addtokwargs — Method
addtokwargs(;kwargs...)Add keyword-arguments to your Base.Pairs of kwargs.
BifrostTools.code_to_cgs — Method
code_to_cgs(
variable::String,
params ::Dict{String,String},
)Conversion factor of variable from code units to cgs units.
BifrostTools.convert_timeunits — Method
convert_timeunits!(
t ::AbstractArray,
params::Dict{String,String}
) ::Float64Converts snapshot time to seconds
BifrostTools.convert_units — Method
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.
BifrostTools.dxdn — Method
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
BifrostTools.dxup — Method
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
BifrostTools.dydn — Method
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
BifrostTools.dyup — Method
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
BifrostTools.dzdn — Method
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
BifrostTools.dzup — Method
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
BifrostTools.get_and_destagger_var — Method
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).
BifrostTools.get_aux — Function
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.
BifrostTools.get_axes — Method
get_axes(
xp::BifrostExperiment
;
units="code"
)Return a tuple containing the axis of the BifrostExperiment in the desired units.
BifrostTools.get_basename — Method
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.
BifrostTools.get_electron_density — Method
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"
BifrostTools.get_electron_density — Method
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}BifrostTools.get_numvars — Method
get_numvars(
params::Dict{String,String},
)Returns number of primary variables and number of auxiliary variables, given the snapshot-parameters.
BifrostTools.get_snap — Function
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 fieldWarning: variables in code units.ts
BifrostTools.get_snap — Function
get_snap(
file_name::String,
params ::Dict{String,String}
)BifrostTools.get_snap_numbers — Method
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.
BifrostTools.get_snapsize — Method
get_snapsize(
mesh::BifrostMesh,
)Returns snapsize (mx, my, mz) given a Bifrost-mesh.
BifrostTools.get_snapsize — Method
get_snapsize(
params::Dict{String,String},
)Returns snapsize (mx, my, mz) given the snapshot-parameters.
BifrostTools.get_snapsize_and_numvars — Method
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.
BifrostTools.get_var — Method
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])BifrostTools.get_var — Method
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.
BifrostTools.get_var — Method
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.
BifrostTools.get_variable_offset_in_file — Method
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.
BifrostTools.get_varnr_and_file_suffix — Method
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).
BifrostTools.read_params — Method
read_params(xp::BifrostExperiment, snap::Integer)BifrostTools.read_params — Method
read_params(expname::String, snap::Integer, expdir::String)BifrostTools.read_params — Method
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
BifrostTools.rotate — Method
rotate(
data ::AbstractArray,
variable ::String,
rotation_axis::String,
)Rotate the data about an rotation_axis.
BifrostTools.squeeze — Method
function squeeze(a::AbstractArray)Drop singleton dimensions of array a
BifrostTools.xdn — Method
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
BifrostTools.xup — Method
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
BifrostTools.xupyup — Method
xupyup(data, args...)For destagering variables at cell edges, in particular the z-axis.
BifrostTools.ydn — Method
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
BifrostTools.yup — Method
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
BifrostTools.yupzup — Method
yupzup(data, args...)For destagering variables at cell edges, in particular the x-axis.
BifrostTools.zdn — Method
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
BifrostTools.zup — Method
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
BifrostTools.zupxup — Method
zupxup(data, args...)For destagering variables at cell edges, in particular the y-axis.