Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9 #62

Merged
merged 4 commits into from
Dec 1, 2021
Merged

v0.9 #62

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Vlasiator"
uuid = "7d2ba682-ad6e-4e20-80d9-3f2d4a610bb4"
authors = ["Hongyang Zhou <hongyang.zhou@helsinki.fi>"]
version = "0.8.30"
version = "0.9.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -16,7 +16,6 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
Expand All @@ -27,9 +26,8 @@ PyPlot = "2.9"
RecipesBase = "1.1"
Requires = "1.1"
StaticArrays = "1.2"
UnPack = "1.0"
WriteVTK = "1.9"
julia = "1.6"
julia = "1.7"

[extras]
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SUITE["read"]["DCCRG_select_large"] =
SUITE["read"]["FG"] = @benchmarkable readvariable($meta, "fg_b")
file = joinpath(directory, files[1])
meta = load(file)
SUITE["read"]["VDF"] = @benchmarkable readvcells($meta, 2; species="proton")
SUITE["read"]["VDF"] = @benchmarkable readvcells($meta, 5; species="proton")

SUITE["VTK"] = BenchmarkGroup(["conversion"])
file = joinpath(directory, files[3])
Expand Down
1 change: 0 additions & 1 deletion src/Vlasiator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Vlasiator
using Requires
using StaticArrays
using Printf: @sprintf
using UnPack
using LinearAlgebra: ×, dot, ⋅, norm, normalize!
using Statistics: mean
using EzXML
Expand Down
4 changes: 2 additions & 2 deletions src/plot/plots.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Using user recipes from Plots.

using RecipesBase, Printf, UnPack
using RecipesBase, Printf

# Build a recipe which acts on a custom type.
@recipe function f(meta::MetaVLSV, var::AbstractString; op=:mag, axisunit=RE, normal=:y)
@unpack ncells, coordmin, coordmax = meta
(;ncells, coordmin, coordmax) = meta
if ndims(meta) == 1
data = readvariable(meta, var)

Expand Down
8 changes: 4 additions & 4 deletions src/plot/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function PyPlot.quiver(meta::MetaVLSV, var::AbstractString, ax=nothing;
end

function set_vector(meta::MetaVLSV, var, comp, axisunit::AxisUnit)
@unpack ncells, coordmin, coordmax = meta
(;ncells, coordmin, coordmax) = meta
if occursin("x", comp)
v1_ = 1
if occursin("y", comp)
Expand Down Expand Up @@ -145,7 +145,7 @@ function PyPlot.pcolormesh(meta::MetaVLSV, var::AbstractString, ax=nothing; op=:
# check if origin and normal exist in kwargs
normal = haskey(kwargs, :normal) ? kwargs.data.normal : :y
origin = haskey(kwargs, :origin) ? kwargs.data.origin : 0.0
kwargs = Base.structdiff(kwargs.data, (normal = normal, origin = origin))
kwargs = Base.structdiff(values(kwargs), (normal = normal, origin = origin))
c = pcolormeshslice(meta, var, ax; op, axisunit, colorscale, addcolorbar, vmin, vmax,
normal, origin, kwargs...)
return c
Expand Down Expand Up @@ -261,7 +261,7 @@ end

"Configure customized plot."
function set_plot(c, ax, pArgs::PlotArgs, cticks, addcolorbar)
@unpack str_title, strx, stry, cb_title = pArgs
(;str_title, strx, stry, cb_title) = pArgs

if addcolorbar
cb = colorbar(c; ax, ticks=cticks, fraction=0.04, pad=0.02)
Expand Down Expand Up @@ -353,7 +353,7 @@ Plot mesh cell centers from axis view `projection`. `projection` should be eithe
"""
function plotmesh(meta::MetaVLSV, ax=nothing; projection="3d", origin=0.0, marker="+",
kwargs...)
@unpack coordmin, coordmax, cellid = meta
(;coordmin, coordmax, cellid) = meta
if projection in ("x", "y", "z")
dirp, dir1, dir2 =
if projection == "x"
Expand Down
4 changes: 2 additions & 2 deletions src/utility/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

"Set plot-related arguments of `var` in `axisunit`."
function set_args(meta::MetaVLSV, var, axisunit::AxisUnit; normal::Symbol=:none, origin=0.0)
@unpack ncells, coordmin, coordmax = meta
(;ncells, coordmin, coordmax) = meta

if normal == :x
seq = @SVector [2,3]
Expand Down Expand Up @@ -124,7 +124,7 @@ end

"Return `data` of `var` on a uniform 2D mesh on the finest AMR level."
function prep2dslice(meta::MetaVLSV, var, normal, op, pArgs::PlotArgs)
@unpack idlist, indexlist = pArgs
(;idlist, indexlist) = pArgs

data3D = readvariable(meta, var)

Expand Down
8 changes: 4 additions & 4 deletions src/vlsv/vlsvreader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Return variable value of `var` from the vlsv file. By default `sorted=true`, whi
that for DCCRG grid the variables are sorted by cell ID.
"""
function readvariable(meta::MetaVLSV, var, sorted::Bool=true)
@unpack fid, footer, cellindex = meta
(;fid, footer, cellindex) = meta
if (local symvar = Symbol(var)) in keys(variables_predefined)
data = variables_predefined[symvar](meta)
return data
Expand Down Expand Up @@ -359,7 +359,7 @@ Read a variable `var` in a collection of cells `ids`.
"""
function readvariable(meta::MetaVLSV, var, ids)
startswith(var, "fg_") && error("Currently does not support reading fsgrid!")
@unpack fid, footer, cellid, cellindex = meta
(;fid, footer, cellid, cellindex) = meta

if (local symvar = Symbol(var)) in keys(variables_predefined)
data = variables_predefined[symvar](meta, ids)
Expand Down Expand Up @@ -548,8 +548,8 @@ Read velocity cells from a spatial cell of ID `cid`, and return a map of velocit
ids and corresponding value.
"""
function readvcells(meta::MetaVLSV, cid; species="proton")
@unpack fid, footer = meta
@unpack vblock_size = meta.meshes[species]
(;fid, footer) = meta
(;vblock_size) = meta.meshes[species]
bsize = prod(vblock_size)

local offset::Int, nblocks::Int
Expand Down
32 changes: 16 additions & 16 deletions src/vlsv/vlsvutility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Return cell ID containing the given spatial `location`, excluding domain boundar
Only accept 3D location.
"""
function getcell(meta::MetaVLSV, loc)
@unpack coordmin, coordmax, dcoord, ncells, cellid, maxamr = meta
(;coordmin, coordmax, dcoord, ncells, cellid, maxamr) = meta

coordmin[1] < loc[1] < coordmax[1] || error("x coordinate out of bound!")
coordmin[2] < loc[2] < coordmax[2] || error("y coordinate out of bound!")
Expand Down Expand Up @@ -202,7 +202,7 @@ end
Return a given cell's coordinates.
"""
function getcellcoordinates(meta::MetaVLSV, cid::Integer)
@unpack ncells, coordmin, coordmax = meta
(;ncells, coordmin, coordmax) = meta
cid -= 1 # for easy divisions

xcell, ycell, zcell = ncells
Expand Down Expand Up @@ -237,7 +237,7 @@ end
Return velocity cells' coordinates of `species` and `vcellids`.
"""
function getvcellcoordinates(meta::MetaVLSV, vcellids; species="proton")
@unpack vblocks, vblock_size, dv, vmin = meta.meshes[species]
(;vblocks, vblock_size, dv, vmin) = meta.meshes[species]

bsize = prod(vblock_size)
blockid = @. vcellids ÷ bsize
Expand Down Expand Up @@ -278,7 +278,7 @@ end
Get density from VDF, n = ∫ f(r,v) dV.
"""
function getdensity(meta::MetaVLSV, VDF; species="proton")
@unpack dv = meta.meshes[species]
(;dv) = meta.meshes[species]
n = zero(eltype(VDF))

@inbounds @simd for f in VDF
Expand All @@ -288,7 +288,7 @@ function getdensity(meta::MetaVLSV, VDF; species="proton")
end

function getdensity(meta::MetaVLSV, vcellids, vcellf; species="proton")
@unpack dv = meta.meshes[species]
(;dv) = meta.meshes[species]

n = zero(eltype(vcellf))

Expand All @@ -305,7 +305,7 @@ end
Get bulk velocity from VDF, u = ∫ v * f(r,v) dV / n.
"""
function getvelocity(meta::MetaVLSV, VDF; species="proton")
@unpack dv, vmin = meta.meshes[species]
(;dv, vmin) = meta.meshes[species]
u = zeros(eltype(VDF), 3)

@inbounds for k in axes(VDF,3), j in axes(VDF,2), i in axes(VDF,1)
Expand All @@ -326,7 +326,7 @@ function getvelocity(meta::MetaVLSV, VDF; species="proton")
end

function getvelocity(meta::MetaVLSV, vcellids, vcellf; species="proton")
@unpack dv, vmin = meta.meshes[species]
(;dv, vmin) = meta.meshes[species]

VDF = flatten(meta.meshes[species], vcellids, vcellf)

Expand All @@ -339,7 +339,7 @@ end
Get pressure tensor from VDF, pᵢⱼ = m/3 * ∫ (v - u)ᵢ(v - u)ⱼ * f(r,v) dV.
"""
function getpressure(meta::MetaVLSV, VDF; species="proton")
@unpack dv, vmin = meta.meshes[species]
(;dv, vmin) = meta.meshes[species]
p = zeros(eltype(VDF), 6)

u = getvelocity(meta, VDF; species)
Expand Down Expand Up @@ -415,7 +415,7 @@ density as `f`. The value ranges from [0, +∞], with 0 meaning not Maxwellian-d
all, and +∞ a perfect Maxwellian distribution.
"""
function getmaxwellianity(meta, VDF; species="proton")
@unpack dv, vmin = meta.meshes[species]
(;dv, vmin) = meta.meshes[species]

n = getdensity(meta, VDF)
u = getvelocity(meta, VDF)
Expand All @@ -440,7 +440,7 @@ function getmaxwellianity(meta, VDF; species="proton")
end

function isInsideDomain(meta::MetaVLSV, point)
@unpack coordmin, coordmax = meta
(;coordmin, coordmax) = meta

if coordmin[1] < point[1] ≤ coordmax[1] &&
coordmin[2] < point[2] ≤ coordmax[2] &&
Expand All @@ -458,7 +458,7 @@ Returns cell IDs, distances and coordinates for every cell in a line between two
points `point1` and `point2`. May be improved later with preallocation!
"""
function getcellinline(meta::MetaVLSV, point1, point2)
@unpack coordmin, coordmax, ncells = meta
(;coordmin, coordmax, ncells) = meta

if !isInsideDomain(meta, point1)
throw(DomainError(point1, "point location outside simulation domain!"))
Expand Down Expand Up @@ -531,7 +531,7 @@ order to the cut plane and can be used to select data onto the plane.
"""
function getslicecell(meta::MetaVLSV, sliceoffset, idim, minCoord, maxCoord)
idim ∉ (1,2,3) && @error "Unknown slice direction $idim"
@unpack ncells, maxamr, cellid, cellindex = meta
(;ncells, maxamr, cellid, cellindex) = meta

nsize = ncells[idim]
sliceratio = sliceoffset / (maxCoord - minCoord)
Expand Down Expand Up @@ -582,7 +582,7 @@ Generate scalar data on the finest refinement level given cellids `idlist` and v
`data` on the slice perpendicular to `normal`.
"""
function refineslice(meta::MetaVLSV, idlist, data, normal)
@unpack ncells, maxamr = meta
(;ncells, maxamr) = meta

dims = let ratio = 2^maxamr
if normal == :x
Expand Down Expand Up @@ -718,7 +718,7 @@ Fill the DCCRG mesh with quantity of `vars` on all refinement levels.
- `vtkGhostType::Array{UInt8}`: cell status (to be completed!).
"""
function fillmesh(meta::MetaVLSV, vars; verbose=false)
@unpack maxamr, fid, footer, ncells, cellid, cellindex = meta
(;maxamr, fid, footer, ncells, cellid, cellindex) = meta

nvarvg = findall(!startswith("fg_"), vars)
nv = length(vars)
Expand Down Expand Up @@ -837,7 +837,7 @@ Convert VLSV file to VTK format.
- `verbose=false`: display logs during conversion.
"""
function write_vtk(meta::MetaVLSV; vars=[""], ascii=false, maxamronly=false, verbose=false)
@unpack ncells, maxamr, dcoord, coordmin = meta
(;ncells, maxamr, dcoord, coordmin) = meta

append = ascii ? false : true

Expand Down Expand Up @@ -918,7 +918,7 @@ Save `data` of name `vars` at AMR `level` into VTK image file of name `file`.
"""
function save_image(meta::MetaVLSV, file, vars, data, vtkGhostType, level, ascii=false,
append=true)
@unpack coordmin, dcoord, ncells = meta
(;coordmin, dcoord, ncells) = meta
origin = (coordmin[1], coordmin[2], coordmin[3])
ratio = 2^level
spacing = (dcoord[1] / ratio, dcoord[2] / ratio, dcoord[3] / ratio)
Expand Down