diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl new file mode 100644 index 0000000..6b074a7 --- /dev/null +++ b/test/forest/test_write_vtk.jl @@ -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 \ No newline at end of file diff --git a/test/test_all.jl b/test/test_all.jl index c093ac3..3add364 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -33,6 +33,7 @@ end @testset "forest" begin include("forest/test_element_volume.jl") + include("forest/test_write_vtk.jl") end end # module