Skip to content

Commit

Permalink
Use int division; improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Feb 4, 2021
1 parent 3e31655 commit 96abf3a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 87 deletions.
12 changes: 6 additions & 6 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays"]
git-tree-sha1 = "ff537e5a3cba92fb48f30fec46723510450f2c0e"
git-tree-sha1 = "50eabdace27aa27b143f65b65e762bb0112a7708"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.10.2"
version = "0.11.1"

[[FortranFiles]]
git-tree-sha1 = "f8cec967f151a65f03afd826650c6e91d8b1da16"
Expand All @@ -39,9 +39,9 @@ deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JLLWrappers]]
git-tree-sha1 = "04b49c556240b62d5a799e94c63d5fc14d3c07cd"
git-tree-sha1 = "a431f5f2ca3f4feef3bd7a5e94b8b8d4f2f647a0"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.1.4"
version = "1.2.0"

[[LibGit2]]
deps = ["Printf"]
Expand Down Expand Up @@ -121,9 +121,9 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[WriteVTK]]
deps = ["Base64", "CodecZlib", "FillArrays", "LightXML", "Random", "TranscodingStreams"]
git-tree-sha1 = "d2c54759e589ebaeeffa2744ce2f877f811dfe1b"
git-tree-sha1 = "0dbebacd41c038791cc701321a77b393277f7f9c"
uuid = "64499a7a-5c06-52f2-abe2-ccb03c286192"
version = "1.8.0"
version = "1.8.1"

[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Batsrus"
uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753"
authors = ["hyzhou <[email protected]>"]
version = "0.2.3"
version = "0.2.4"

[deps]
FortranFiles = "c58ffaec-ab22-586d-bfc5-781a99fd0b10"
Expand Down
48 changes: 24 additions & 24 deletions src/vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 1
iCell_G[1,j+1,k+1] = nIJK*(neiBlock-1) +
nI*(1 + floor(Int, (j-1)/2)) + nIJ*floor(Int, (k-1)/2)
nI*(1 + (j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 3
iCell_G[1,j+1,k+1] = nIJK*(neiBlock-1) +
nIJ/2 + nI*(1 + floor(Int, (j-1)/2)) + nIJ*floor(Int, (k-1)/2)
nIJ/2 + nI*(1 + (j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 5
iCell_G[1,j+1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nI*(1 + floor(Int, (j-1)/2)) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nI*(1 + (j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 7
iCell_G[1,j+1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nIJ/2 + nI*(1 + floor(Int, (j-1)/2)) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nIJ/2 + nI*(1 + (j-1)÷2) + nIJ*((k-1)÷2)
end
end
end
Expand All @@ -903,16 +903,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 2
iCell_G[end,j+1,k+1] = nIJK*(neiBlock-1) +
1 + nI*floor(Int, (j-1)/2) + nIJ*floor(Int, (k-1)/2)
1 + nI*((j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 4
iCell_G[end,j+1,k+1] = nIJK*(neiBlock-1) +
nIJ/2 + 1 + nI*floor(Int, (j-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJ/2 + 1 + nI*((j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 6
iCell_G[end,j+1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + 1 + nI*floor(Int, (j-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + 1 + nI*((j-1)÷2) + nIJ*((k-1)÷2)
elseif iSibling == 8
iCell_G[end,j+1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nIJ/2 + 1 + nI*floor(Int, (j-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nIJ/2 + 1 + nI*((j-1)÷2) + nIJ*((k-1)÷2)
end
end
end
Expand All @@ -926,16 +926,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 1
iCell_G[i+1,1,k+1] = nIJK*(neiBlock-1) +
nI*(nJ-1) + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nI*(nJ-1) + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 2
iCell_G[i+1,1,k+1] = nIJK*(neiBlock-1) +
nI*(nJ-1) + nI/2 + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nI*(nJ-1) + nI/2 + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 5
iCell_G[i+1,1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nI*(nJ-1) + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nI*(nJ-1) + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 6
iCell_G[i+1,1,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nI*(nJ-1) + nI/2 + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nI*(nJ-1) + nI/2 + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
end
end
end
Expand All @@ -955,16 +955,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 3
iCell_G[i+1,end,k+1] = nIJK*(neiBlock-1) +
1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 4
iCell_G[i+1,end,k+1] = nIJK*(neiBlock-1) +
nI/2 + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nI/2 + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 7
iCell_G[i+1,end,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
elseif iSibling == 8
iCell_G[i+1,end,k+1] = nIJK*(neiBlock-1) +
nIJK/2 + nI/2 + 1 + floor(Int, (i-1)/2) + nIJ*floor(Int, (k-1)/2)
nIJK/2 + nI/2 + 1 + (i-1)÷2 + nIJ*((k-1)÷2)
end
end
end
Expand All @@ -978,16 +978,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 1
iCell_G[i+1,j+1,1] = nIJK*neiBlock -
nIJ + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ + 1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 2
iCell_G[i+1,j+1,1] = nIJK*neiBlock -
nIJ + nI/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ + nI/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 3
iCell_G[i+1,j+1,1] = nIJK*neiBlock -
nIJ/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 4
iCell_G[i+1,j+1,1] = nIJK*neiBlock -
nIJ/2 + nI/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ/2 + nI/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
end
end
end
Expand All @@ -1007,16 +1007,16 @@ function fillCellNeighbors!(batl, iCell_G, DiLevelNei_III, iNodeNei_III, nBlock_

if iSibling == 5
iCell_G[i+1,j+1,end] = nIJK*(neiBlock-1) +
1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 6
iCell_G[i+1,j+1,end] = nIJK*(neiBlock-1) +
nI/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nI/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 7
iCell_G[i+1,j+1,end] = nIJK*(neiBlock-1) +
nIJ/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
elseif iSibling == 8
iCell_G[i+1,j+1,end] = nIJK*(neiBlock-1) +
nIJ/2 + nI/2 + 1 + floor(Int, (i-1)/2) + nI*floor(Int, (j-1)/2)
nIJ/2 + nI/2 + 1 + (i-1)÷2 + nI*((j-1)÷2)
end
end
end
Expand Down
112 changes: 56 additions & 56 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Test of BATSRUS data loader

ENV["MPLBACKEND"]="agg" # no GUI
# Tests of BATSRUS.jl

using Batsrus, Test, SHA

Expand All @@ -25,62 +23,64 @@ function filecmp(path1::AbstractString, path2::AbstractString)
end
end

@testset "reading 1D ascii" begin
filename = "1d__raw_2_t25.60000_n00000258.out"
data = readdata(filename, dir="data", verbose=true)
@test isa(data.head, NamedTuple)
@test extrema(data.x) == (-127.5, 127.5)
@test extrema(data.w) == (-0.79960780498, 1.9394335293)
end
@testset "Batsrus.jl" begin
@testset "reading 1D ascii" begin
filename = "1d__raw_2_t25.60000_n00000258.out"
data = readdata(filename, dir="data", verbose=true)
@test isa(data.head, NamedTuple)
@test extrema(data.x) == (-127.5, 127.5)
@test extrema(data.w) == (-0.79960780498, 1.9394335293)
end

@testset "reading 2D structured binary" begin
filename = "z=0_raw_1_t25.60000_n00000258.out"
data = readdata(filename, dir="data")
@test data.head.time == 25.6f0
@test extrema(data.x) == (-127.5f0, 127.5f0)
@test extrema(data.w) == (-0.79985905f0, 1.9399388f0)
end
@testset "reading 2D structured binary" begin
filename = "z=0_raw_1_t25.60000_n00000258.out"
data = readdata(filename, dir="data")
@test data.head.time == 25.6f0
@test extrema(data.x) == (-127.5f0, 127.5f0)
@test extrema(data.w) == (-0.79985905f0, 1.9399388f0)
end

@testset "reading 2D unstructured binary" begin
#filename = "z=0_raw_1_t25.60000_n00000258.out"
#data = readdata(filename)
end
@testset "reading 2D unstructured binary" begin
#filename = "z=0_raw_1_t25.60000_n00000258.out"
#data = readdata(filename)
end

@testset "reading 3D structured binary" begin
filename = "3d_raw.out"
data = readdata(filename, dir="data")
plotrange = [-50.0, 50.0, -0.5, 0.5]
X, Z, p = cutdata(data, "p", cut='y', cutPlaneIndex=1, plotrange=plotrange)
@test p[1] 0.560976f0
@test p[2] 0.53704995f0
vars = get_vars(data, ["p"])
@test size(vars.p) == (8,8,8)
end
@testset "reading 3D structured binary" begin
filename = "3d_raw.out"
data = readdata(filename, dir="data")
plotrange = [-50.0, 50.0, -0.5, 0.5]
X, Z, p = cutdata(data, "p", cut='y', cutPlaneIndex=1, plotrange=plotrange)
@test p[1] 0.560976f0
@test p[2] 0.53704995f0
vars = get_vars(data, ["p"])
@test size(vars.p) == (8,8,8)
end

@testset "log" begin
logfilename = "data/log_n000001.log"
head, data = readlogdata(logfilename)
@test isa(head, NamedTuple)
@test extrema(data) == (-0.105, 258.0)
end
@testset "log" begin
logfilename = "data/log_n000001.log"
head, data = readlogdata(logfilename)
@test isa(head, NamedTuple)
@test extrema(data) == (-0.105, 258.0)
end

@testset "VTK" begin
filename = "data/3d_bin.dat"
head, data, connectivity = readtecdata(filename)
@test maximum(connectivity) head[:nNode] # check if it's read correctly
convertTECtoVTU(head, data, connectivity)
sha_str = bytes2hex(open(sha1, "out.vtu"))
@test sha_str == "5b04747666542d802357dec183177f757754a254"
rm("out.vtu")
@testset "VTK" begin
filename = "data/3d_bin.dat"
head, data, connectivity = readtecdata(filename)
@test maximum(connectivity) head[:nNode] # check if it's read correctly
convertTECtoVTU(head, data, connectivity)
sha_str = bytes2hex(open(sha1, "out.vtu"))
@test sha_str == "5b04747666542d802357dec183177f757754a254"
rm("out.vtu")

filetag = "data/3d_mhd_amr/3d__mhd_1_t00000000_n00000000"
run(`tar -C data -zxf data/3d_mhd_amr.tar.gz`)
batl = Batl(readhead(filetag*".info"), readtree(filetag)...)
# local block index check
@test Batsrus.find_grid_block(batl, [1.0, 0.0, 0.0]) == 4
@test Batsrus.find_grid_block(batl, [100.0, 0.0, 0.0]) == -100
connectivity = getConnectivity(batl)
sha_str = bytes2hex(sha256(string(connectivity)))
@test sha_str == "c6c5a65a46d86a9ba4096228c1516f89275e45e295cd305eb70c281a770ede74"
rm("data/3d_mhd_amr", recursive=true)
end
filetag = "data/3d_mhd_amr/3d__mhd_1_t00000000_n00000000"
run(`tar -C data -zxf data/3d_mhd_amr.tar.gz`)
batl = Batl(readhead(filetag*".info"), readtree(filetag)...)
# local block index check
@test Batsrus.find_grid_block(batl, [1.0, 0.0, 0.0]) == 4
@test Batsrus.find_grid_block(batl, [100.0, 0.0, 0.0]) == -100
connectivity = getConnectivity(batl)
sha_str = bytes2hex(sha256(string(connectivity)))
@test sha_str == "c6c5a65a46d86a9ba4096228c1516f89275e45e295cd305eb70c281a770ede74"
rm("data/3d_mhd_amr", recursive=true)
end
end

0 comments on commit 96abf3a

Please sign in to comment.