APIs
Batsrus
Batsrus.BATS — Type
Alias for backward compatibility and convenience.
Batsrus.Batl — Type
BATSRUS output high-level struct.
Batsrus.BatsHead — Type
Batsrus file head information.
Batsrus.BatsrusIDLStructured — Type
Batsrus structured data container, with Dim being the dimension of output.
Batsrus.BatsrusIDLUnstructured — Type
Batsrus unstructured data container, with Dim being the dimension of output.
Batsrus.FileList — Type
Type for Batsrus file information.
Batsrus.Head — Type
BATSRUS output standalone header information.
Batsrus._getfilesize_binary — Method
getfilesize(fileID::IOStream, lenstr::Int32, ::Val{FileType})Return the size in bytes for one snapshot.
Batsrus.adjust_plotrange! — Method
Adjust 2D plot ranges.
Batsrus.allocateBuffer — Method
Create buffer for x and w.
Batsrus.classify_particles — Method
classify_particles(data, region; vdim=3, bulk_vel=nothing, vth=nothing, nsigma=3.0)Classify particles in a spatial region into core Maxwellian and suprathermal populations.
Arguments
data::AMReXParticle: Particle data.region: Passed as kwargsx_range,y_range,z_range.vdim: Velocity dimension (1, 2, or 3).bulk_vel: Core bulk velocity. Ifnothing, estimated from peak density.vth: Core thermal velocity. Must be provided.nsigma: Threshold for classification in units of thermal velocity.
Returns
(core, suprathermal): Two matrices containing the classified particles.
Batsrus.cutdata — Method
cutdata(data, var; plotrange=[-Inf,Inf,-Inf,Inf], dir="x", sequence=1)Get 2D plane cut in orientation dir for var out of 3D box data within plotrange. The returned 2D data lies in the sequence plane from - to + in dir.
Batsrus.fillCellNeighbors! — Method
fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_P)Fill neighbor cell indexes for the given block. The faces, edges, and vertices are ordered from left (-) to right (+) in x-y-z sequentially.
Vertices: Edges: (10,11 ignored)
7 ----- 8 . --4-- .- . - . 7 . 8 . 5 ––- 6 . . –3– . 12 . . . . . . . . . 3 ––- 4 9 . –2– . . - . - . 5 . 6 1 ––- 2 . –1– .
Only tested for 3D.
Batsrus.fill_vector_from_scalars — Method
fill_vector_from_scalars(bd::BatsrusIDL, var)Construct vector of var from its scalar components. Alternatively, check get_vectors for returning vector components as separate arrays.
Batsrus.find_grid_block — Method
find_grid_block(batl, xyz_D)Return processor local block index that contains a point. Input location should be given in Cartesian coordinates.
Batsrus.find_neighbor_for_anynode — Method
Find neighbors for any node in the tree. Only for Cartesian now.
Batsrus.find_tree_node — Method
find_tree_node(batl, Coord_D)Find the node that contains a point. The point coordinates should be given in generalized coordinates normalized by the domain size.
Batsrus.findindex — Method
Find variable index in the BATSRUS data.
Batsrus.generate_mock_amrex_data — Method
generate_mock_amrex_data(output_dir::String; num_particles::Int=10,
real_component_names::Vector{String}=["u", "v"],
particle_gen::Function)Generate mock AMReX particle data for testing and benchmarking.
Arguments
output_dir::String: Directory to save the mock data.num_particles::Int: Number of particles to generate.real_component_names::Vector{String}: Names of the extra real components (beyond x, y, z).particle_gen::Function: A function(i, n_reals) -> tuplethat takes an indexi(1-based) and the total number of real componentsn_reals. It should return a tuple ofn_realsFloat64 values:(x, y, z, comp1, comp2, ...).
Batsrus.getConnectivity — Method
Get cell connectivity list.
Batsrus.getRotationMatrix — Method
getRotationMatrix(axis::AbstractVector, angle::Real) --> SMatrix{3,3}Create a rotation matrix for rotating a 3D vector around a unit axis by an angle in radians. Reference: Rotation matrix from axis and angle
Example
using LinearAlgebra
v = [-0.5, 1.0, 1.0]
v̂ = normalize(v)
θ = deg2rad(-74)
R = getRotationMatrix(v̂, θ)Batsrus.getSibling — Method
Return sibling index (1-8) for the given block node matrix.
Batsrus.get_anisotropy — Method
get_anisotropy(bd::BatsrusIDL, species=0)Calculate the pressure anisotropy for species, indexing from 0. The default method is based on the fact that the trace of the pressure tensor is a constant. The rotation method is based on rotating the tensor.
Batsrus.get_convection_E — Method
Return the convection electric field from PIC outputs.
Batsrus.get_core_population_mask — Method
get_core_population_mask(velocities, bulk_vel, vth, nsigma=3.0)Identify core population particles based on velocity distribution. Returns a BitVector where true indicates a core particle.
Batsrus.get_hall_E — Method
Return the Hall electric field from PIC outputs.
Batsrus.get_magnitude — Function
get_magnitude(bd::BatsrusIDL, var)Calculate the magnitude of vector var. See get_vectors for the options.
Batsrus.get_magnitude2 — Function
get_magnitude2(bd::BatsrusIDL, var)Calculate the magnitude square of vector var. See get_vectors for the options.
Batsrus.get_particle_field_aligned_transform — Function
get_particle_field_aligned_transform(b_field, e_field=nothing)Return a transformation function that converts particle data to a field-aligned coordinate system.
If only b_field is provided, the velocity components are decomposed into parallel and perpendicular to the magnetic field. If e_field is also provided, an orthonormal basis ($\hat{\mathbf{b}}$, $\hat{\mathbf{e}}$, $\hat{\mathbf{d}}$) is created, where $\hat{\mathbf{d}} \propto \mathbf{B} \times \mathbf{E}$ and $\hat{\mathbf{e}} = \hat{\mathbf{d}} \times \hat{\mathbf{b}}$.
The returned function takes (data, names) and returns (new_data, new_names).
Batsrus.get_range — Method
Return mesh range of bd.
Batsrus.get_timeseries — Method
get_timeseries(files::AbstractArray, loc; tstep = 1.0)Extract plasma moments and EM field from PIC output files at loc with nearest neighbor. Currently only works for 2D outputs. If a single point variable is needed, see interp1d.
Batsrus.get_var_range — Method
Return value range of var in bd.
Batsrus.get_vectors — Method
get_vectors(bd::BatsrusIDL, var)Return a tuple of vectors of var. var can be :B, :E, :U, or any :U followed by an index (e.g. :U0 for species 0, :U1 for species 1, etc.).
Batsrus.getascii! — Method
Read ascii format coordinates and data values.
Batsrus.getbinary! — Method
Read binary format coordinates and data values.
Batsrus.getfilehead — Method
getfilehead(fileID::IoStream, filelist::FileList) -> NameTupleObtain the header information from BATSRUS output file of type linked to fileID.
Input arguments
fileID::IOStream: file identifier.filelist::FileList: file information.
Batsrus.getfiletype — Method
Obtain file type.
Batsrus.getvar — Method
getvar(bd::BATS, var::AbstractString) -> ArrayReturn variable data from string var. This is also supported via direct indexing. Note that the query variable var must be in lowercase!
Examples
bd["rho"]Batsrus.getview — Method
Return view of variable var in bd.
Batsrus.ibits — Method
Logical shifts as the Fortran instrinsic function.
Batsrus.interp1d — Method
interp1d(bd::BatsrusIDLStructured, var::AbstractString, loc::AbstractVector{<:AbstractFloat})Interpolate var at spatial point loc in bd.
Batsrus.interp1d — Method
interp1d(bd::BatsrusIDLStructured, var::AbstractString, point1::Vector, point2::Vector)Interpolate var along a line from point1 to point2 in bd.
Batsrus.interp2d — Function
interp2d(bd::BatsrusIDL, var::AbstractString, plotrange=[-Inf, Inf, -Inf, Inf],
plotinterval=Inf; kwargs...)Return 2D interpolated slices of data var from bd. If plotrange is not set, output data resolution is the same as the original.
Keyword Arguments
innermask=false: Whether to mask the inner boundary with NaN.rbody=1.0: Radius of the inner mask. Used when the rbody parameter is not found in the header.useMatplotlib=true: Whether to Matplotlib (faster) or NaturalNeighbours for scattered interpolation. If true, a linear interpolation is performed on a constructed triangle mesh.
Batsrus.interpolate2d_generalized_coords — Method
Perform Triangle interpolation of 2D data W on grid X, Y.
Batsrus.load — Method
load(filename; npict=1, verbose=false)Read BATSRUS output files. Stores the npict snapshot from an ascii or binary data file into the arrays of coordinates x and data w.
Batsrus.meshgrid — Function
Return the axis range for 2D outputs. See interp2d.
Batsrus.meshgrid — Method
Generating consistent 2D arrays for passing to plotting functions.
Batsrus.nodeToGlobalBlock — Method
Return global block index for the node.
Batsrus.order_children! — Method
order_children!(batl::Batl, iNode, iMorton::Int, iNodeMorton_I::Vector{Int32})Recursively apply Morton ordering for nodes below a root block. Store result into iNodeMortonI and iMortonNodeA using the iMorton index.
Batsrus.order_tree — Method
order_tree(batl)Return maximum AMR level in the used block and the Morton curve order. Set iNodeMorton_I indirect index arrays according to
- root node order
- Morton ordering for each root node
Batsrus.readhead — Method
Return BATL header from info file. Currently only designed for 2D and 3D.
Batsrus.readlogdata — Method
Read information from log file.
Batsrus.readtecdata — Method
readtecdata(file; verbose=false)Return header, data and connectivity from BATSRUS Tecplot outputs. Both 2D and 3D binary and ASCII formats are supported.
Examples
file = "3d_ascii.dat"
head, data, connectivity = readtecdata(file)Batsrus.readtree — Method
Return BATL tree structure.
Batsrus.rotateTensorToVectorZ — Method
rotateTensorToVectorZ(tensor::AbstractMatrix, v::AbstractVector) -> SMatrix{3,3}Rotate tensor with a rotation matrix that aligns the 3rd direction with vector, which is equivalent to change the basis from (i,j,k) to (i′,j′,k′) where k′ ∥ vector. Reference: Tensor rotation
Batsrus.showhead — Function
showhead(file, head)
showhead(data)
showhead(io, data)Displaying file header information of BATSRUS data.
Batsrus.slice1d — Function
slice1d(bd, var, icut::Int=1, dir::Int=2)Return view of variable var in bd along 1D slice. icut is the index along axis dir. dir == 1 means align with the 2nd (y) axis, dir == 2 means align with the 1st (x) axis.
Batsrus.squeeze — Method
Squeeze singleton dimensions for an array A.
Batsrus.subsurface — Method
subsurface(x, y, data, limits)
subsurface(x, y, u, v, limits)Extract subset of 2D surface dataset in ndgrid format. See also: subvolume.
Batsrus.subvolume — Method
subvolume(x, y, z, data, limits)
subvolume(x, y, z, u, v, w, limits)Extract subset of 3D dataset in ndgrid format. See also: subsurface.
UnitfulBatsrus
HDF5 Extension
The HDF5 functionality is provided via a package extension. Load HDF5 alongside Batsrus to enable it:
using Batsrus, HDF5