Skip to content

Commit

Permalink
Add test for vtk writing
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Jan 31, 2025
1 parent 314f3a1 commit acb0220
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/forest/test_write_vtk.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file tests the writing of data to vtk files.
# All t8code eclasses are tested with a basic forest with elements of level 0 to 3.
@testset "test_write_vtk" begin
outdir = "out_test"
mkdir(outdir)
for eclass in T8_ECLASS_ZERO:t8_eclass(T8_ECLASS_COUNT - 1)
for level in 0:3
scheme = t8_scheme_new_default_cxx()
cmesh = t8_cmesh_new_hypercube(t8_eclass(eclass), comm, 0, 0, 0)
forest = t8_forest_new_uniform(cmesh, scheme, level, 0, comm)

num_elements = t8_forest_get_local_num_elements(forest)

data = rand(num_elements)

vtk_data = t8_vtk_data_field_t(T8_VTK_SCALAR,
NTuple{8192, Cchar}(rpad("data_1)\0", 8192, ' ')),
pointer(data))

# The number of user defined data fields to write.
num_data = 1

# Write user defined data to vtu file.
write_treeid = 1
write_mpirank = 1
write_level = 1
write_element_id = 1
write_ghosts = 0
file = joinpath(outdir, "data_" * string(eclass) * "_" * string(level))
t8_forest_write_vtk_ext(forest, file, write_treeid, write_mpirank,
write_level, write_element_id, write_ghosts,
0, 0, num_data, Ref(vtk_data))

@test isfile(file * "_0000.vtu") && isfile(file * ".pvtu")

t8_forest_unref(Ref(forest))
end
end

rm(outdir, recursive = true)
end
1 change: 1 addition & 0 deletions test/test_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ end

@testset "forest" begin
include("forest/test_element_volume.jl")
include("forest/test_write_vtk.jl")
end

end # module

0 comments on commit acb0220

Please sign in to comment.