From 96abf3a68d30f542a884f1edc6235eef39837d14 Mon Sep 17 00:00:00 2001 From: Hongyang Zhou Date: Thu, 4 Feb 2021 21:54:57 +0200 Subject: [PATCH] Use int division; improve tests --- Manifest.toml | 12 ++--- Project.toml | 2 +- src/vtk.jl | 48 ++++++++++---------- test/runtests.jl | 112 +++++++++++++++++++++++------------------------ 4 files changed, 87 insertions(+), 87 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 80916724..216167d6 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -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" @@ -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"] @@ -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"] diff --git a/Project.toml b/Project.toml index 30e37568..7f6c1170 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Batsrus" uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753" authors = ["hyzhou "] -version = "0.2.3" +version = "0.2.4" [deps] FortranFiles = "c58ffaec-ab22-586d-bfc5-781a99fd0b10" diff --git a/src/vtk.jl b/src/vtk.jl index 6c499e44..aed843f9 100644 --- a/src/vtk.jl +++ b/src/vtk.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5b9b06b5..31998fe3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,4 @@ -# Test of BATSRUS data loader - -ENV["MPLBACKEND"]="agg" # no GUI +# Tests of BATSRUS.jl using Batsrus, Test, SHA @@ -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 \ No newline at end of file